const v = ".rte-content, .editora-content", fe = "[data-editora-editor], .rte-editor, .editora-editor, editora-editor", ye = "__editoraCommandEditorRoot", he = "rte-blocks-library-styles", u = "rte-blocks-library-panel", E = "blocks-library", C = "blocksLibrary", $ = ':is([data-theme="dark"], .dark, .editora-theme-dark, .rte-theme-dark)';
const Be = /* @__PURE__ */ new Set(["script", "style", "meta", "link", "object", "embed", "iframe"]), De = /^(https?:|mailto:|tel:|#|\/)/i, Oe = /^data:image\/(?:png|gif|jpeg|jpg|webp);base64,/i, Ke = {
  panelTitle: "Blocks Library",
  panelAriaLabel: "Blocks library panel",
  searchLabel: "Search blocks",
  searchPlaceholder: "Search by name, category, or keyword",
  categoryLabel: "Category",
  allCategoriesText: "All categories",
  recentHeading: "Recent inserts",
  insertText: "Insert Selected",
  closeText: "Close",
  noResultsText: "No matching blocks found.",
  summaryPrefix: "Blocks",
  loadingText: "Loading blocks...",
  loadErrorText: "Unable to load blocks right now.",
  readonlyMessage: "Editor is read-only. Block insertion is disabled.",
  shortcutText: "Shortcuts: Ctrl/Cmd+Alt+Shift+B (panel), Ctrl/Cmd+Alt+Shift+L (insert last)",
  helperText: "Use Arrow keys to move through blocks, Enter to insert, Esc to close.",
  lastInsertedPrefix: "Last inserted",
  resultsListLabel: "Block results"
}, b = /* @__PURE__ */ new WeakMap(), J = /* @__PURE__ */ new WeakMap(), w = /* @__PURE__ */ new WeakMap(), I = /* @__PURE__ */ new WeakMap(), O = /* @__PURE__ */ new WeakMap(), j = /* @__PURE__ */ new WeakMap(), W = /* @__PURE__ */ new WeakMap(), z = /* @__PURE__ */ new WeakMap(), q = /* @__PURE__ */ new WeakMap(), te = /* @__PURE__ */ new WeakMap(), x = /* @__PURE__ */ new Map(), U = /* @__PURE__ */ new WeakMap(), oe = /* @__PURE__ */ new Set();
let X = 0, Ne = 0, ke = 0, M = null, y = null, _ = null, P = null, A = null, D = null;
function m(e) {
  return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
}
function je(e) {
  return e.replace(/\u00A0/g, " ").replace(/\s+/g, " ").trim();
}
function We(e) {
  return e.toLowerCase().replace(/[^a-z0-9_-]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 80);
}
function ce(e) {
  const t = e.trim();
  return t && (De.test(t) || Oe.test(t)) ? t : "";
}
function xe(e) {
  let t = e;
  return Be.forEach((r) => {
    const o = new RegExp(`<${r}[\\s\\S]*?>[\\s\\S]*?<\\/${r}>`, "gi"), l = new RegExp(`<${r}\\b[^>]*\\/?>`, "gi");
    t = t.replace(o, "").replace(l, "");
  }), t = t.replace(/\son\w+=(\"[^\"]*\"|'[^']*'|[^\s>]+)/gi, "").replace(/\s(xmlns|xml:[^=\s>]+)\s*=\s*(\"[^\"]*\"|'[^']*'|[^\s>]+)/gi, "").replace(
    /\s(href|src|xlink:href)\s*=\s*("|\')\s*(?:javascript:|vbscript:|data:text\/html)[^"']*\2/gi,
    ""
  ).replace(/\s(href|src|xlink:href)\s*=\s*(?:javascript:|vbscript:|data:text\/html)[^\s>]*/gi, "").replace(
    /\s(href|src|xlink:href)\s*=\s*("([^"]*)"|'([^']*)')/gi,
    (r, o, l, n, a) => {
      const s = typeof n == "string" && n.length > 0 ? n : a || "", i = ce(s);
      if (!i) return "";
      const c = l.startsWith('"') ? '"' : "'";
      return ` ${o}=${c}${i}${c}`;
    }
  ).replace(/\s(href|src|xlink:href)\s*=\s*([^\s>]+)/gi, (r, o, l) => {
    const n = ce(l);
    return n ? ` ${o}="${n}"` : "";
  }).replace(/\sstyle\s*=\s*("([^"]*)"|'([^']*)')/gi, (r, o, l, n) => {
    const a = typeof l == "string" && l.length > 0 ? l : n || "";
    if (/expression\s*\(|javascript\s*:|vbscript\s*:|url\s*\(/i.test(a))
      return "";
    const s = o.startsWith('"') ? '"' : "'";
    return ` style=${s}${a}${s}`;
  }).trim(), t;
}
function Fe(e) {
  if (!e) return "";
  if (typeof document > "u")
    return xe(e);
  const t = document.createElement("template");
  t.innerHTML = e;
  const r = t.content;
  return !r || typeof r.querySelectorAll != "function" ? xe(e) : (Array.from(r.querySelectorAll("*")).forEach((l) => {
    const n = l.tagName.toLowerCase();
    if (Be.has(n)) {
      l.remove();
      return;
    }
    Array.from(l.attributes).forEach((s) => {
      const i = s.name.toLowerCase(), c = s.value;
      if (i.startsWith("on")) {
        l.removeAttribute(s.name);
        return;
      }
      if (i === "style") {
        /expression\s*\(|javascript\s*:|vbscript\s*:|url\s*\(/i.test(c) && l.removeAttribute(s.name);
        return;
      }
      if (i === "href" || i === "src" || i === "xlink:href") {
        const d = ce(c);
        if (!d) {
          l.removeAttribute(s.name);
          return;
        }
        d !== c && l.setAttribute(s.name, d);
      }
    });
  }), t.innerHTML.trim());
}
function ne(e) {
  return e.trim().toLowerCase();
}
function Ge(e) {
  if (!e) return "";
  if (typeof document > "u")
    return e.replace(/<[^>]*>/g, " ").replace(/\s+/g, " ").trim();
  const t = document.createElement("template");
  t.innerHTML = e;
  const r = t.content;
  return !r || typeof r.textContent != "string" ? e.replace(/<[^>]*>/g, " ").replace(/\s+/g, " ").trim() : r.textContent.replace(/\s+/g, " ").trim();
}
function Ce(e, t) {
  if (!Array.isArray(e) || e.length === 0) return [];
  const r = /* @__PURE__ */ new Set(), o = [];
  return e.forEach((l) => {
    const n = t.normalizeText(l.label || ""), a = t.sanitizeBlockHtml(l.html || "", l).trim();
    if (!n || !a) return;
    const s = t.normalizeText(l.category || "General") || "General", i = ne(s);
    let d = We(t.normalizeText(l.id || n)) || `block-${ke++}`;
    for (; r.has(d); )
      d = `${d}-${ke++}`;
    r.add(d);
    const f = (l.tags || []).map((H) => t.normalizeText(H)).filter(Boolean), g = (l.keywords || []).map((H) => t.normalizeText(H)).filter(Boolean), h = t.normalizeText(l.description || ""), R = Ge(a), V = [n, h, s, ...f, ...g, R].join(" ").toLowerCase();
    o.push({
      id: d,
      label: n,
      html: a,
      description: h,
      category: s,
      categoryKey: i,
      tags: f,
      keywords: g,
      previewText: R,
      searchBlob: V
    });
  }), o;
}
function Q(e = {}) {
  const t = e.normalizeText || je, r = e.sanitizeBlockHtml || Fe, o = {
    blocks: [],
    defaultCategory: t(e.defaultCategory || ""),
    maxResults: Math.max(4, Math.min(300, Number(e.maxResults ?? 80))),
    maxRecentBlocks: Math.max(1, Math.min(20, Number(e.maxRecentBlocks ?? 6))),
    debounceMs: Math.max(0, Math.min(700, Number(e.debounceMs ?? 90))),
    cacheTtlMs: Math.max(0, Number(e.cacheTtlMs ?? 6e4)),
    labels: {
      ...Ke,
      ...e.labels || {}
    },
    normalizeText: t,
    sanitizeBlockHtml: r,
    getBlocks: typeof e.getBlocks == "function" ? e.getBlocks : void 0
  };
  return o.blocks = Ce(e.blocks, o), o;
}
function Ue(e) {
  return {
    blocks: e.blocks.map((t) => ({
      id: t.id,
      label: t.label,
      html: t.html,
      description: t.description || void 0,
      category: t.category || void 0,
      tags: t.tags.length ? [...t.tags] : void 0,
      keywords: t.keywords.length ? [...t.keywords] : void 0
    })),
    defaultCategory: e.defaultCategory,
    maxResults: e.maxResults,
    maxRecentBlocks: e.maxRecentBlocks,
    debounceMs: e.debounceMs,
    cacheTtlMs: e.cacheTtlMs,
    labels: { ...e.labels },
    normalizeText: e.normalizeText,
    sanitizeBlockHtml: e.sanitizeBlockHtml,
    getBlocks: e.getBlocks
  };
}
function le(e) {
  return e.closest(fe) || e;
}
function G(e) {
  if (!e) return null;
  if (e.matches(v)) return e;
  const t = e.querySelector(v);
  return t instanceof HTMLElement ? t : null;
}
function Ve() {
  if (typeof window > "u") return null;
  const e = window[ye];
  if (!(e instanceof HTMLElement)) return null;
  window[ye] = null;
  const t = G(e);
  if (t) return t;
  const r = e.closest(fe);
  if (r) {
    const l = G(r);
    if (l) return l;
  }
  const o = e.closest(v);
  return o instanceof HTMLElement ? o : null;
}
function Ye(e) {
  const t = e.closest("[data-editora-editor]");
  if (t && G(t) === e)
    return t;
  let r = e;
  for (; r; ) {
    if (r.matches(fe) && (r === e || G(r) === e))
      return r;
    r = r.parentElement;
  }
  return le(e);
}
function $e(e) {
  return e ? e.nodeType === Node.ELEMENT_NODE ? e : e.parentElement : null;
}
function ee() {
  Array.from(oe).forEach((t) => {
    t.isConnected || ge(t);
  });
}
function T(e, t = !0, r = !0) {
  if (ee(), e?.contentElement instanceof HTMLElement) return e.contentElement;
  if (e?.editorElement instanceof HTMLElement) {
    const a = G(e.editorElement);
    if (a) return a;
  }
  const o = Ve();
  if (o) return o;
  const l = window.getSelection();
  if (l && l.rangeCount > 0) {
    const s = $e(l.getRangeAt(0).startContainer)?.closest(v);
    if (s) return s;
  }
  const n = document.activeElement;
  if (n) {
    if (n.matches(v)) return n;
    const a = n.closest(v);
    if (a) return a;
  }
  if (r) {
    if (y && y.isConnected) return y;
    y && !y.isConnected && (y = null);
  }
  return t ? document.querySelector(v) : null;
}
function Xe(e) {
  const t = e.target;
  if (t) {
    const o = t.closest(v);
    if (o) return o;
  }
  const r = window.getSelection();
  if (r && r.rangeCount > 0) {
    const l = $e(r.getRangeAt(0).startContainer)?.closest(v);
    if (l) return l;
  }
  return null;
}
function Z(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 Ze(e) {
  const t = le(e);
  if (Z(t)) return !0;
  const r = t.closest("[data-theme], [theme], .dark, .editora-theme-dark, .rte-theme-dark");
  return Z(r) ? !0 : Z(document.documentElement) || Z(document.body);
}
function re(e, t) {
  e.classList.remove("rte-blocks-library-theme-dark"), Ze(t) && e.classList.add("rte-blocks-library-theme-dark");
}
function Te(e) {
  return e.getAttribute("contenteditable") === "false" || e.getAttribute("data-readonly") === "true";
}
function we(e, t, r) {
  const o = Ye(e);
  Array.from(
    o.querySelectorAll(
      `.rte-toolbar-button[data-command="${t}"], .editora-toolbar-button[data-command="${t}"]`
    )
  ).forEach((n) => {
    n.classList.toggle("active", r), n.setAttribute("data-active", r ? "true" : "false"), n.setAttribute("aria-pressed", r ? "true" : "false");
  });
}
function Ee(e, t) {
  const r = e.querySelector(".rte-blocks-library-live");
  r && (r.textContent = t);
}
function se(e) {
  const t = Re(e);
  if (t)
    try {
      q.set(e, t.cloneRange());
    } catch {
    }
}
function Se(e) {
  const t = q.get(e);
  if (!t) return null;
  if (!e.isConnected)
    return q.delete(e), null;
  try {
    const r = t.cloneRange();
    return e.contains(r.commonAncestorContainer) ? r : (q.delete(e), null);
  } catch {
    return q.delete(e), null;
  }
}
function Je(e) {
  const t = Se(e);
  return t ? (He(e, t), !0) : !1;
}
function Qe(e) {
  if (te.has(e)) return;
  const t = () => {
    const r = window.getSelection();
    if (!r || r.rangeCount === 0) return;
    const o = r.getRangeAt(0);
    e.contains(o.commonAncestorContainer) && se(e);
  };
  e.addEventListener("keyup", t), e.addEventListener("mouseup", t), e.addEventListener("touchend", t), te.set(e, t);
}
function et(e) {
  const t = te.get(e);
  t && (e.removeEventListener("keyup", t), e.removeEventListener("mouseup", t), e.removeEventListener("touchend", t), te.delete(e));
}
function k(e, t) {
  b.has(e) || b.set(e, t), I.has(e) || (I.set(e, t.blocks), O.set(e, Date.now()));
  let r = w.get(e);
  return r || (r = {
    query: "",
    category: t.defaultCategory ? ne(t.defaultCategory) : "all",
    selectedBlockId: null,
    recentBlockIds: [],
    lastInsertedBlockId: null,
    loading: !1,
    loadError: null,
    totalMatches: 0,
    visibleMatches: 0,
    filterCache: /* @__PURE__ */ new Map(),
    debounceTimer: null
  }, w.set(e, r)), oe.add(e), Qe(e), r;
}
function Me(e) {
  const t = w.get(e);
  !t || t.debounceTimer === null || (window.clearTimeout(t.debounceTimer), t.debounceTimer = null);
}
function ge(e) {
  Me(e), et(e), q.delete(e);
  const t = W.get(e);
  t && (t.abort(), W.delete(e)), j.delete(e), z.delete(e), x.get(e)?.remove(), x.delete(e), U.delete(e), b.delete(e), J.delete(e), w.delete(e), I.delete(e), O.delete(e), oe.delete(e), y === e && (y = null);
}
function tt(e) {
  for (let t = 0; t < e.length; t += 1) {
    const r = e[t];
    if (!(r.type !== "childList" || r.removedNodes.length === 0))
      for (let o = 0; o < r.removedNodes.length; o += 1) {
        const l = r.removedNodes[o];
        if (l.nodeType !== Node.ELEMENT_NODE) continue;
        const n = l;
        if (n.matches?.(v) || n.matches?.(`.${u}`) || n.querySelector?.(v) || n.querySelector?.(`.${u}`))
          return !0;
      }
  }
  return !1;
}
function pe(e) {
  return U.get(e) === !0;
}
function de(e, t) {
  if (!t.classList.contains("show")) return;
  const r = le(e).getBoundingClientRect(), o = Math.min(window.innerWidth - 20, 420), l = Math.max(10, window.innerWidth - o - 10), n = Math.min(Math.max(10, r.right - o), l), a = Math.max(10, Math.min(window.innerHeight - 10, r.top + 12));
  t.style.width = `${o}px`, t.style.left = `${n}px`, t.style.top = `${a}px`, t.style.maxHeight = `${Math.max(260, window.innerHeight - 20)}px`;
}
function ae(e) {
  return I.get(e) || b.get(e)?.blocks || [];
}
function rt(e, t) {
  const r = /* @__PURE__ */ new Map();
  ae(e).forEach((l) => {
    r.has(l.categoryKey) || r.set(l.categoryKey, l.category);
  });
  const o = Array.from(r.entries()).sort((l, n) => l[1].localeCompare(n[1])).map(([l, n]) => ({ value: l, label: n }));
  return [{ value: "all", label: t.labels.allCategoriesText }, ...o];
}
function Ae(e, t) {
  const r = k(e, t), o = ae(e), l = r.query.trim().toLowerCase(), n = r.category || "all", a = `${l}|${n}|${t.maxResults}`, s = r.filterCache.get(a);
  if (s) {
    const d = new Map(o.map((g) => [g.id, g])), f = s.ids.map((g) => d.get(g)).filter(Boolean);
    return r.totalMatches = s.total, r.visibleMatches = f.length, f;
  }
  const i = [];
  let c = 0;
  for (let d = 0; d < o.length; d += 1) {
    const f = o[d];
    n !== "all" && f.categoryKey !== n || l && !f.searchBlob.includes(l) || (c += 1, i.length < t.maxResults && i.push(f));
  }
  if (r.totalMatches = c, r.visibleMatches = i.length, r.filterCache.set(a, {
    ids: i.map((d) => d.id),
    total: c
  }), r.filterCache.size > 80) {
    const d = r.filterCache.keys().next().value;
    typeof d == "string" && r.filterCache.delete(d);
  }
  return i;
}
function ot(e, t) {
  const r = w.get(e);
  if (!r) return;
  if (t.length === 0) {
    r.selectedBlockId = null;
    return;
  }
  t.some((l) => l.id === r.selectedBlockId) || (r.selectedBlockId = t[0].id);
}
function K(e) {
  const t = w.get(e);
  we(e, "toggleBlocksLibraryPanel", pe(e)), we(e, "insertLastBlockSnippet", !!t?.lastInsertedBlockId);
}
function L(e) {
  const t = x.get(e), r = b.get(e) || M, o = w.get(e);
  if (!t || !r || !o) return;
  re(t, e);
  const l = t.querySelector(".rte-blocks-library-title");
  l && (l.textContent = r.labels.panelTitle);
  const n = t.querySelector('[data-action="close"]');
  n && (n.setAttribute("aria-label", r.labels.closeText), n.textContent = "✕");
  const a = t.querySelector(".rte-blocks-library-search-label");
  a && (a.textContent = r.labels.searchLabel);
  const s = t.querySelector('[data-field="query"]');
  s && (s.setAttribute("placeholder", r.labels.searchPlaceholder), s.value !== o.query && (s.value = o.query));
  const i = t.querySelector(".rte-blocks-library-category-label");
  i && (i.textContent = r.labels.categoryLabel);
  const c = t.querySelector('[data-field="category"]');
  if (c) {
    const B = rt(e, r);
    c.innerHTML = B.map((p) => `<option value="${m(p.value)}">${m(p.label)}</option>`).join(""), B.some((p) => p.value === o.category) || (o.category = "all"), c.value = o.category;
  }
  const d = t.querySelector(".rte-blocks-library-helper");
  d && (d.textContent = r.labels.helperText);
  const f = t.querySelector('.rte-blocks-library-list[role="listbox"]');
  f && f.setAttribute("aria-label", r.labels.resultsListLabel);
  const g = t.querySelector(".rte-blocks-library-shortcut");
  g && (g.textContent = r.labels.shortcutText);
  const h = t.querySelector('[data-action="insert-selected"]');
  if (h) {
    h.textContent = r.labels.insertText;
    const B = !Te(e) && !!o.selectedBlockId;
    h.disabled = !B, h.setAttribute("aria-disabled", B ? "false" : "true");
  }
  const R = t.querySelector(".rte-blocks-library-empty"), V = t.querySelector(".rte-blocks-library-list"), H = Ae(e, r);
  ot(e, H);
  const Y = t.querySelector(".rte-blocks-library-status");
  if (Y && (o.loading ? Y.textContent = r.labels.loadingText : o.loadError ? Y.textContent = o.loadError : Y.textContent = `${r.labels.summaryPrefix}: ${o.visibleMatches}/${o.totalMatches}`), V) {
    const B = new Set(o.recentBlockIds);
    V.innerHTML = H.map((p) => {
      const ie = o.selectedBlockId === p.id, _e = p.tags.length ? ` • ${p.tags.join(", ")}` : "", Pe = B.has(p.id), me = p.previewText.slice(0, 180);
      return `
          <li class="rte-blocks-library-item-wrapper" role="presentation">
            <button
              type="button"
              class="rte-blocks-library-item${ie ? " active" : ""}"
              data-block-id="${m(p.id)}"
              role="option"
              aria-selected="${ie ? "true" : "false"}"
              aria-label="${m(p.label)}"
              tabindex="${ie ? "0" : "-1"}"
            >
              <span class="rte-blocks-library-item-head">
                <span class="rte-blocks-library-item-label">${m(p.label)}</span>
                ${Pe ? `<span class="rte-blocks-library-recent-pill">${m(r.labels.recentHeading)}</span>` : ""}
              </span>
              <span class="rte-blocks-library-item-meta">${m(p.category)}${m(_e)}</span>
              ${p.description ? `<span class="rte-blocks-library-item-description">${m(p.description)}</span>` : ""}
              ${me ? `<span class="rte-blocks-library-item-preview">${m(me)}</span>` : ""}
            </button>
          </li>
        `;
    }).join("");
  }
  R && (R.hidden = H.length > 0, R.textContent = r.labels.noResultsText);
  const N = t.querySelector(".rte-blocks-library-last-inserted");
  if (N)
    if (o.lastInsertedBlockId) {
      const B = ae(e).find((p) => p.id === o.lastInsertedBlockId);
      B ? (N.hidden = !1, N.textContent = `${r.labels.lastInsertedPrefix}: ${B.label}`) : N.hidden = !0;
    } else
      N.hidden = !0;
  t.setAttribute("aria-label", r.labels.panelAriaLabel);
}
function S(e, t = !1) {
  const r = x.get(e);
  r && (r.classList.remove("show"), U.set(e, !1), K(e), t && (e.focus({ preventScroll: !0 }), Je(e)));
}
function nt(e) {
  e.querySelector(".rte-blocks-library-item.active")?.focus();
}
function ve(e, t) {
  const r = b.get(e) || M;
  if (!r) return;
  const o = w.get(e);
  if (!o) return;
  const l = Ae(e, r);
  if (l.length === 0) return;
  const a = (Math.max(
    0,
    l.findIndex((i) => i.id === o.selectedBlockId)
  ) + t + l.length) % l.length;
  o.selectedBlockId = l[a].id, L(e);
  const s = x.get(e);
  s && nt(s);
}
function ue(e) {
  const t = ct(e);
  se(e), x.forEach((o, l) => {
    l !== e && S(l, !1);
  }), t.classList.add("show"), U.set(e, !0), L(e), de(e, t), K(e), t.querySelector('[data-field="query"]')?.focus(), be(e, !1);
}
function Ie(e, t) {
  const r = pe(e);
  return (typeof t == "boolean" ? t : !r) ? ue(e) : S(e, !1), !0;
}
function Re(e) {
  const t = window.getSelection();
  if (!t || t.rangeCount === 0) return null;
  const r = t.getRangeAt(0);
  return e.contains(r.commonAncestorContainer) ? r : null;
}
function He(e, t) {
  if (!e.isConnected) return;
  const r = window.getSelection();
  r && (r.removeAllRanges(), r.addRange(t));
}
function Le(e, t, r) {
  const o = t.cloneRange();
  if (!e.contains(o.commonAncestorContainer)) return !1;
  o.deleteContents();
  const l = document.createElement("template");
  l.innerHTML = r;
  const n = l.content;
  if (!n) return !1;
  const a = n.lastChild;
  if (o.insertNode(n), a) {
    const s = document.createRange();
    s.setStartAfter(a), s.collapse(!0), He(e, s);
  }
  return se(e), !0;
}
function lt(e, t) {
  e.focus({ preventScroll: !0 });
  const r = Se(e);
  if (r && Le(e, r, t))
    return !0;
  try {
    if (document.execCommand("insertHTML", !1, t))
      return se(e), !0;
  } catch {
  }
  const o = Re(e);
  return o ? Le(e, o, t) : !1;
}
function st(e, t) {
  if (t === e.innerHTML) return;
  const r = window.execEditorCommand || window.executeEditorCommand;
  if (typeof r == "function")
    try {
      r("recordDomTransaction", e, t, e.innerHTML);
    } catch {
    }
}
function at(e) {
  e.dispatchEvent(new Event("input", { bubbles: !0 }));
}
function F(e, t) {
  const r = b.get(e) || M;
  if (!r) return !1;
  const o = k(e, r), l = x.get(e);
  if (Te(e))
    return l && Ee(l, r.labels.readonlyMessage), !1;
  const n = ae(e).find((i) => i.id === t);
  if (!n) return !1;
  const a = e.innerHTML;
  return lt(e, n.html) ? (o.lastInsertedBlockId = n.id, o.selectedBlockId = n.id, o.recentBlockIds = [n.id, ...o.recentBlockIds.filter((i) => i !== n.id)].slice(
    0,
    r.maxRecentBlocks
  ), st(e, a), at(e), K(e), e.dispatchEvent(
    new CustomEvent("editora:blocks-library-insert", {
      bubbles: !0,
      detail: {
        blockId: n.id,
        label: n.label,
        category: n.category
      }
    })
  ), L(e), l && Ee(l, `${r.labels.lastInsertedPrefix}: ${n.label}`), !0) : !1;
}
function ze(e) {
  const t = w.get(e);
  return t?.lastInsertedBlockId ? F(e, t.lastInsertedBlockId) : !1;
}
function it(e) {
  const t = b.get(e) || M;
  if (!t) return;
  const r = w.get(e);
  if (!r) return;
  Me(e);
  const o = () => {
    r.debounceTimer = null, r.filterCache.clear(), L(e);
  };
  if (t.debounceMs <= 0) {
    o();
    return;
  }
  r.debounceTimer = window.setTimeout(o, t.debounceMs);
}
function ct(e) {
  const t = x.get(e);
  if (t) return t;
  const r = b.get(e) || M || Q(), o = k(e, r), l = `rte-blocks-library-panel-${Ne++}`, n = `${l}-query`, a = `${l}-category`, s = document.createElement("section");
  return s.className = u, s.id = l, s.setAttribute("role", "dialog"), s.setAttribute("aria-modal", "false"), s.setAttribute("aria-label", r.labels.panelAriaLabel), s.innerHTML = `
    <header class="rte-blocks-library-header">
      <h2 class="rte-blocks-library-title">${m(r.labels.panelTitle)}</h2>
      <button type="button" class="rte-blocks-library-icon-btn" data-action="close" aria-label="${m(r.labels.closeText)}">✕</button>
    </header>
    <div class="rte-blocks-library-body">
      <label class="rte-blocks-library-search-label" for="${m(n)}"></label>
      <input id="${m(n)}" class="rte-blocks-library-input" type="text" data-field="query" autocomplete="off" />
      <label class="rte-blocks-library-category-label" for="${m(a)}"></label>
      <select id="${m(a)}" class="rte-blocks-library-select" data-field="category"></select>
      <p class="rte-blocks-library-status" aria-live="polite"></p>
      <p class="rte-blocks-library-helper"></p>
      <p class="rte-blocks-library-last-inserted" hidden></p>
      <div class="rte-blocks-library-list-wrap">
        <ul class="rte-blocks-library-list" role="listbox" aria-label="${m(r.labels.resultsListLabel)}"></ul>
        <p class="rte-blocks-library-empty" hidden></p>
      </div>
      <div class="rte-blocks-library-actions">
        <button type="button" class="rte-blocks-library-btn rte-blocks-library-btn-primary" data-action="insert-selected"></button>
      </div>
      <p class="rte-blocks-library-shortcut"></p>
    </div>
    <div class="rte-blocks-library-live" aria-live="polite" aria-atomic="true"></div>
  `, s.addEventListener("click", (i) => {
    const c = i.target, d = c?.closest("[data-action]");
    if (d) {
      const h = d.getAttribute("data-action");
      if (h === "close") {
        S(e, !0);
        return;
      }
      if (h === "insert-selected") {
        if (!o.selectedBlockId) return;
        F(e, o.selectedBlockId) && S(e, !0);
      }
      return;
    }
    const f = c?.closest("[data-block-id]");
    if (!f) return;
    const g = f.getAttribute("data-block-id");
    g && (o.selectedBlockId = g, L(e), i.detail >= 2 && F(e, g) && S(e, !0));
  }), s.addEventListener("input", (i) => {
    const c = i.target;
    !(c instanceof HTMLInputElement) || c.getAttribute("data-field") !== "query" || (o.query = r.normalizeText(c.value).toLowerCase(), o.filterCache.clear(), it(e));
  }), s.addEventListener("change", (i) => {
    const c = i.target;
    !(c instanceof HTMLSelectElement) || c.getAttribute("data-field") !== "category" || (o.category = ne(c.value || "all") || "all", o.filterCache.clear(), L(e));
  }), s.addEventListener("keydown", (i) => {
    if (i.key === "Escape") {
      i.preventDefault(), S(e, !0);
      return;
    }
    if (i.key === "ArrowDown") {
      i.preventDefault(), ve(e, 1);
      return;
    }
    if (i.key === "ArrowUp") {
      i.preventDefault(), ve(e, -1);
      return;
    }
    if (i.key === "Enter") {
      if (!i.target?.matches('[data-field="query"], [data-field="category"], [data-block-id]') || !o.selectedBlockId) return;
      i.preventDefault(), F(e, o.selectedBlockId) && S(e, !0);
    }
  }), re(s, e), document.body.appendChild(s), x.set(e, s), U.set(e, !1), L(e), s;
}
function dt(e) {
  const t = w.get(e);
  return {
    query: t?.query || "",
    category: t?.category || "all",
    selectedBlockId: t?.selectedBlockId || null,
    totalMatches: t?.totalMatches || 0,
    visibleMatches: t?.visibleMatches || 0,
    recentBlockIds: t?.recentBlockIds ? [...t.recentBlockIds] : [],
    lastInsertedBlockId: t?.lastInsertedBlockId || null,
    loading: t?.loading === !0,
    loadError: t?.loadError || null
  };
}
async function be(e, t) {
  const r = b.get(e) || M;
  if (!r || typeof r.getBlocks != "function") return;
  const o = k(e, r), l = O.get(e) || 0;
  if (!t && r.cacheTtlMs > 0 && Date.now() - l < r.cacheTtlMs)
    return;
  const n = j.get(e);
  if (n && !t)
    return n;
  const a = W.get(e);
  a && a.abort(), t && n && j.delete(e);
  const s = new AbortController();
  W.set(e, s);
  const i = (z.get(e) || 0) + 1;
  z.set(e, i), o.loading = !0, o.loadError = null, L(e);
  const c = Promise.resolve().then(async () => {
    const d = {
      editor: e,
      editorRoot: le(e),
      signal: s.signal
    }, f = await r.getBlocks?.(d);
    if (s.signal.aborted || z.get(e) !== i) return;
    const g = Ce(f || [], r);
    I.set(e, g), O.set(e, Date.now());
    const h = w.get(e);
    h && (h.loading = !1, h.loadError = null, h.filterCache.clear());
  }).catch(() => {
    if (s.signal.aborted || z.get(e) !== i) return;
    const d = w.get(e);
    d && (d.loading = !1, d.loadError = r.labels.loadErrorText);
  }).finally(() => {
    z.get(e) === i && (j.delete(e), W.delete(e)), L(e);
  });
  return j.set(e, c), c;
}
function qe(e) {
  return typeof e.key == "string" ? e.key.toLowerCase() : "";
}
function ut(e) {
  const t = qe(e);
  return (e.metaKey || e.ctrlKey) && e.altKey && e.shiftKey && t === "b";
}
function bt(e) {
  const t = qe(e);
  return (e.metaKey || e.ctrlKey) && e.altKey && e.shiftKey && t === "l";
}
function ft(e) {
  M = e, _ || (_ = (t) => {
    ee();
    const o = t.target?.closest(v);
    if (!o) return;
    const l = b.get(o) || e;
    k(o, l), b.set(o, l), y = o, K(o);
    const n = x.get(o);
    n && (re(n, o), de(o, n), L(o));
  }, document.addEventListener("focusin", _, !0)), P || (P = (t) => {
    if (t.defaultPrevented) return;
    const r = `.${u} input, .${u} textarea, .${u} select`, o = t.target;
    if (o?.closest(r)) {
      if (t.key === "Escape") {
        const a = o.closest(`.${u}`), s = Array.from(x.entries()).find(([, i]) => i === a);
        s && (t.preventDefault(), S(s[0], !0));
      }
      return;
    }
    const l = Xe(t);
    if (!l) return;
    const n = b.get(l) || M || e;
    if (k(l, n), b.set(l, n), y = l, t.key === "Escape" && pe(l)) {
      t.preventDefault(), S(l, !0);
      return;
    }
    if (ut(t)) {
      t.preventDefault(), t.stopPropagation(), Ie(l);
      return;
    }
    bt(t) && (t.preventDefault(), t.stopPropagation(), ze(l));
  }, document.addEventListener("keydown", P, !0)), A || (A = () => {
    ee(), x.forEach((t, r) => {
      !r.isConnected || !t.isConnected || (re(t, r), de(r, t));
    });
  }, window.addEventListener("scroll", A, !0), window.addEventListener("resize", A)), !D && typeof MutationObserver < "u" && document.body && (D = new MutationObserver((t) => {
    tt(t) && ee();
  }), D.observe(document.body, {
    childList: !0,
    subtree: !0
  }));
}
function gt() {
  _ && (document.removeEventListener("focusin", _, !0), _ = null), P && (document.removeEventListener("keydown", P, !0), P = null), A && (window.removeEventListener("scroll", A, !0), window.removeEventListener("resize", A), A = null), D && (D.disconnect(), D = null), x.forEach((t) => t.remove()), x.clear(), Array.from(oe).forEach((t) => ge(t)), M = null, y = null;
}
function pt() {
  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.${C},
    .editora-toolbar-group-items.${C} {
      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.${C} .rte-toolbar-button,
    .editora-toolbar-group-items.${C} .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.${C} .rte-toolbar-item:last-child .rte-toolbar-button,
    .editora-toolbar-group-items.${C} .editora-toolbar-item:last-child .editora-toolbar-button {
      border-right: none;
    }

    .rte-toolbar-button[data-command="insertLastBlockSnippet"].active,
    .editora-toolbar-button[data-command="insertLastBlockSnippet"].active {
      background: rgba(15, 118, 110, 0.12);
    }

    ${$} .rte-toolbar-group-items.${E},
    ${$} .editora-toolbar-group-items.${E},
    ${$} .rte-toolbar-group-items.${C},
    ${$} .editora-toolbar-group-items.${C} {
      border-color: #566275;
    }
    ${$} .rte-toolbar-group-items.${E} .rte-toolbar-button svg,
    ${$} .editora-toolbar-group-items.${E} .editora-toolbar-button svg,
    ${$} .rte-toolbar-group-items.${C} .rte-toolbar-button svg,
    ${$} .editora-toolbar-group-items.${C} .editora-toolbar-button svg
    {
      fill: none;
    }
    ${$} .rte-toolbar-group-items.${E} .rte-toolbar-button,
    ${$} .editora-toolbar-group-items.${E} .editora-toolbar-button
    {
      border-color: #566275;
    }
    .${u} {
      position: fixed;
      z-index: 12000;
      display: none;
      width: min(420px, 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;
    }

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

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

    .rte-blocks-library-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%);
    }

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

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

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

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

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

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

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

    .rte-blocks-library-search-label,
    .rte-blocks-library-category-label {
      font-size: 12px;
      line-height: 1.3;
      font-weight: 700;
      color: #334155;
    }

    .${u}.rte-blocks-library-theme-dark .rte-blocks-library-search-label,
    .${u}.rte-blocks-library-theme-dark .rte-blocks-library-category-label {
      color: #cbd5e1;
    }

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

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

    .${u}.rte-blocks-library-theme-dark .rte-blocks-library-input,
    .${u}.rte-blocks-library-theme-dark .rte-blocks-library-select {
      border-color: #334155;
      background: #0b1220;
      color: #e2e8f0;
    }

    .rte-blocks-library-status,
    .rte-blocks-library-helper,
    .rte-blocks-library-shortcut,
    .rte-blocks-library-last-inserted {
      margin: 0;
      font-size: 12px;
      line-height: 1.35;
      color: #475569;
    }

    .rte-blocks-library-last-inserted {
      font-weight: 600;
      color: #0f766e;
    }

    .${u}.rte-blocks-library-theme-dark .rte-blocks-library-status,
    .${u}.rte-blocks-library-theme-dark .rte-blocks-library-helper,
    .${u}.rte-blocks-library-theme-dark .rte-blocks-library-shortcut {
      color: #94a3b8;
    }

    .${u}.rte-blocks-library-theme-dark .rte-blocks-library-last-inserted {
      color: #5eead4;
    }

    .rte-blocks-library-list-wrap {
      border: 1px solid #e2e8f0;
      border-radius: 10px;
      padding: 6px;
      background: #f8fafc;
      max-height: min(44vh, 360px);
      overflow: auto;
    }

    .${u}.rte-blocks-library-theme-dark .rte-blocks-library-list-wrap {
      border-color: #334155;
      background: #0b1220;
    }

    .rte-blocks-library-list {
      margin: 0;
      padding: 0;
      list-style: none;
      display: grid;
      gap: 6px;
    }

    .rte-blocks-library-item-wrapper {
      margin: 0;
      padding: 0;
    }

    .rte-blocks-library-item {
      width: 100%;
      border: 1px solid #cbd5e1;
      border-radius: 8px;
      background: #ffffff;
      color: inherit;
      text-align: left;
      padding: 8px;
      display: grid;
      gap: 3px;
      cursor: pointer;
    }

    .rte-blocks-library-item:hover,
    .rte-blocks-library-item:focus-visible {
      border-color: #0f766e;
      outline: none;
    }

    .rte-blocks-library-item.active {
      border-color: #0f766e;
      background: rgba(15, 118, 110, 0.12);
    }

    .${u}.rte-blocks-library-theme-dark .rte-blocks-library-item {
      border-color: #334155;
      background: #111827;
      color: #e2e8f0;
    }

    .${u}.rte-blocks-library-theme-dark .rte-blocks-library-item.active {
      border-color: #2dd4bf;
      background: rgba(45, 212, 191, 0.15);
    }

    .rte-blocks-library-item-head {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 8px;
    }

    .rte-blocks-library-item-label {
      font-size: 13px;
      line-height: 1.3;
      font-weight: 700;
    }

    .rte-blocks-library-recent-pill {
      font-size: 10px;
      line-height: 1;
      font-weight: 700;
      text-transform: uppercase;
      letter-spacing: 0.02em;
      color: #0f766e;
      border: 1px solid rgba(15, 118, 110, 0.38);
      border-radius: 999px;
      padding: 2px 6px;
    }

    .${u}.rte-blocks-library-theme-dark .rte-blocks-library-recent-pill {
      color: #5eead4;
      border-color: rgba(94, 234, 212, 0.45);
    }

    .rte-blocks-library-item-meta,
    .rte-blocks-library-item-description,
    .rte-blocks-library-item-preview {
      font-size: 11px;
      line-height: 1.3;
      color: #64748b;
    }

    .rte-blocks-library-item-preview {
      color: #334155;
      display: -webkit-box;
      -webkit-line-clamp: 2;
      line-clamp: 2;
      -webkit-box-orient: vertical;
      overflow: hidden;
    }

    .${u}.rte-blocks-library-theme-dark .rte-blocks-library-item-meta,
    .${u}.rte-blocks-library-theme-dark .rte-blocks-library-item-description {
      color: #94a3b8;
    }

    .${u}.rte-blocks-library-theme-dark .rte-blocks-library-item-preview {
      color: #cbd5e1;
    }

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

    .rte-blocks-library-actions {
      display: flex;
      gap: 8px;
    }

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

    .rte-blocks-library-btn:disabled {
      opacity: 0.6;
      cursor: not-allowed;
    }

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

    .rte-blocks-library-btn-primary:hover,
    .rte-blocks-library-btn-primary:focus-visible {
      border-color: #115e59;
      background: #115e59;
      outline: none;
    }

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

    .${u}.rte-blocks-library-theme-dark .rte-blocks-library-btn-primary {
      border-color: #14b8a6;
      background: #0f766e;
      color: #f0fdfa;
    }

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

    @media (max-width: 768px) {
      .${u} {
        left: 10px !important;
        right: 10px;
        top: 10px !important;
        width: auto !important;
        max-height: calc(100vh - 20px);
      }
    }
  `, document.head.appendChild(e);
}
const mt = (e = {}) => {
  const t = Q(e), r = /* @__PURE__ */ new Set();
  return pt(), {
    name: "blocksLibrary",
    toolbar: [
      {
        id: "blocksLibraryGroup",
        label: "Blocks Library",
        type: "group",
        command: "blocksLibrary",
        items: [
          {
            id: "blocksLibraryPanel",
            label: "Blocks Library Panel",
            command: "toggleBlocksLibraryPanel",
            shortcut: "Mod-Alt-Shift-b",
            icon: '<svg width="24" height="24" viewBox="0 0 24 24" fill="none" focusable="false" aria-hidden="true"><rect x="4" y="5" width="7" height="6" rx="1.5" stroke="currentColor" stroke-width="1.6"/><rect x="13" y="5" width="7" height="6" rx="1.5" stroke="currentColor" stroke-width="1.6"/><rect x="4" y="13" width="7" height="6" rx="1.5" stroke="currentColor" stroke-width="1.6"/><rect x="13" y="13" width="7" height="6" rx="1.5" stroke="currentColor" stroke-width="1.6"/></svg>'
          },
          {
            id: "insertLastBlockSnippet",
            label: "Insert Last Block",
            command: "insertLastBlockSnippet",
            shortcut: "Mod-Alt-Shift-l",
            icon: '<svg width="24" height="24" viewBox="0 0 24 24" fill="none" focusable="false" aria-hidden="true"><path d="M7 5.5h10a1.5 1.5 0 0 1 1.5 1.5v10A1.5 1.5 0 0 1 17 18.5H7A1.5 1.5 0 0 1 5.5 17V7A1.5 1.5 0 0 1 7 5.5Z" stroke="currentColor" stroke-width="1.6"/><path d="M12 8.5v7" stroke="currentColor" stroke-width="1.6" stroke-linecap="round"/><path d="M8.5 12h7" stroke="currentColor" stroke-width="1.6" stroke-linecap="round"/></svg>'
          }
        ]
      }
    ],
    commands: {
      blocksLibrary: (o, l) => {
        const n = T(l, !1, !1);
        if (!n) return !1;
        const a = b.get(n) || t;
        return k(n, a), b.set(n, a), y = n, ue(n), !0;
      },
      openBlocksLibraryPanel: (o, l) => {
        const n = T(l, !1, !1);
        if (!n) return !1;
        const a = b.get(n) || t;
        return k(n, a), b.set(n, a), y = n, ue(n), !0;
      },
      toggleBlocksLibraryPanel: (o, l) => {
        const n = T(l, !1, !1);
        if (!n) return !1;
        const a = b.get(n) || t;
        return k(n, a), b.set(n, a), y = n, Ie(n, typeof o == "boolean" ? o : void 0);
      },
      insertBlockSnippet: (o, l) => {
        const n = T(l, !1, !1);
        if (!n) return !1;
        const a = b.get(n) || t;
        k(n, a), b.set(n, a);
        const s = typeof o == "string" ? o : o?.id;
        return s ? (y = n, F(n, s)) : !1;
      },
      insertLastBlockSnippet: (o, l) => {
        const n = T(l, !1, !1);
        if (!n) return !1;
        const a = b.get(n) || t;
        return k(n, a), b.set(n, a), y = n, ze(n);
      },
      refreshBlocksLibraryData: (o, l) => {
        const n = T(l, !1, !1);
        if (!n) return !1;
        const a = b.get(n) || t;
        return k(n, a), b.set(n, a), be(n, !0), !0;
      },
      setBlocksLibraryOptions: (o, l) => {
        const n = T(l, !1, !1);
        if (!n || !o || typeof o != "object") return !1;
        const a = b.get(n) || t, s = J.get(n) || Ue(a), i = {
          ...s,
          ...o,
          labels: {
            ...s.labels || {},
            ...o.labels || {}
          },
          blocks: Array.isArray(o.blocks) ? o.blocks : s.blocks,
          normalizeText: o.normalizeText || a.normalizeText,
          sanitizeBlockHtml: o.sanitizeBlockHtml || a.sanitizeBlockHtml,
          getBlocks: o.getBlocks || a.getBlocks
        }, c = Q(i), d = Array.isArray(o.blocks), f = o.getBlocks !== void 0;
        b.set(n, c), J.set(n, i), (d || f || !I.has(n)) && (I.set(n, c.blocks), O.set(n, f ? 0 : Date.now()));
        const g = k(n, c);
        return g.filterCache.clear(), typeof o.defaultCategory == "string" && (g.category = ne(c.defaultCategory) || "all"), L(n), K(n), f && be(n, !0), !0;
      },
      getBlocksLibraryState: (o, l) => {
        const n = T(l, !1, !1);
        if (!n) return !1;
        const a = b.get(n) || t;
        k(n, a);
        const s = dt(n);
        if (typeof o == "function")
          try {
            o(s);
          } catch {
          }
        return n.__blocksLibraryState = s, n.dispatchEvent(
          new CustomEvent("editora:blocks-library-state", {
            bubbles: !0,
            detail: s
          })
        ), !0;
      }
    },
    keymap: {
      "Mod-Alt-Shift-b": "toggleBlocksLibraryPanel",
      "Mod-Alt-Shift-B": "toggleBlocksLibraryPanel",
      "Mod-Alt-Shift-l": "insertLastBlockSnippet",
      "Mod-Alt-Shift-L": "insertLastBlockSnippet"
    },
    init: function(l) {
      X += 1;
      const n = this && typeof this.__pluginConfig == "object" ? { ...e, ...this.__pluginConfig } : e, a = Q(n);
      ft(a);
      const s = T(
        l?.editorElement ? { editorElement: l.editorElement } : void 0,
        !1,
        !1
      );
      s && (y = s, r.add(s), k(s, a), b.set(s, a), J.set(s, n), I.set(s, a.blocks), O.set(s, Date.now()), K(s));
    },
    destroy: () => {
      r.forEach((o) => ge(o)), r.clear(), X = Math.max(0, X - 1), !(X > 0) && gt();
    }
  };
};
export {
  mt as BlocksLibraryPlugin
};
