const o = /* @__PURE__ */ new WeakMap(), a = "rte-fullscreen-active", t = (s) => (o.has(s) || o.set(s, {
  isFullscreen: !1,
  fullscreenButton: null
}), o.get(s)), y = (s, e) => {
  if (s.classList.add(a), s.style.position = "fixed", s.style.top = "0", s.style.left = "0", s.style.right = "0", s.style.bottom = "0", s.style.width = "100%", s.style.height = "100%", s.style.maxWidth = "100%", s.style.maxHeight = "100%", s.style.borderRadius = "0", s.style.zIndex = "9999", s.style.margin = "0", s.style.padding = "0", s.style.boxShadow = "none", s.style.display = "flex", s.style.flexDirection = "column", s.style.background = "white", document.body.style.overflow = "hidden", document.body.classList.add("fullscreen-active"), e.fullscreenButton) {
    e.fullscreenButton.setAttribute("data-active", "true"), e.fullscreenButton.style.backgroundColor = "var(--rte-color-primary, #007bff)", e.fullscreenButton.style.color = "white";
    const l = e.fullscreenButton.querySelector("svg");
    l && (l.style.fill = "white", l.style.stroke = "white");
  }
}, c = (s, e) => {
  if (s.classList.remove(a), s.style.position = "", s.style.top = "", s.style.left = "", s.style.right = "", s.style.bottom = "", s.style.width = "", s.style.height = "", s.style.maxWidth = "", s.style.maxHeight = "", s.style.borderRadius = "", s.style.zIndex = "", s.style.margin = "", s.style.padding = "", s.style.boxShadow = "", s.style.display = "", s.style.flexDirection = "", s.style.background = "", document.body.style.overflow = "", document.body.classList.remove("fullscreen-active"), e.fullscreenButton) {
    e.fullscreenButton.setAttribute("data-active", "false"), e.fullscreenButton.style.backgroundColor = "", e.fullscreenButton.style.color = "";
    const l = e.fullscreenButton.querySelector("svg");
    l && (l.style.fill = "", l.style.stroke = "");
  }
}, i = (s) => {
  try {
    if (!s) {
      const l = document.activeElement;
      l && l.closest("[data-editora-editor]") && (s = l.closest("[data-editora-editor]"));
    }
    if (s || (s = document.querySelector("[data-editora-editor]")), !s)
      return console.warn("Editor element not found"), !1;
    const e = t(s);
    return e.fullscreenButton || (e.fullscreenButton = s.querySelector('[data-command="toggleFullscreen"]')), e.isFullscreen = !e.isFullscreen, e.isFullscreen ? y(s, e) : c(s, e), !0;
  } catch (e) {
    return console.error("Fullscreen toggle failed:", e), !1;
  }
}, f = (s) => {
  if (!s) {
    document.querySelectorAll("[data-editora-editor]").forEach((l) => {
      const u = l, n = t(u);
      n.isFullscreen && (n.isFullscreen = !1, c(u, n));
    });
    return;
  }
  const e = t(s);
  e.isFullscreen && (e.isFullscreen = !1, c(s, e));
}, d = (s) => t(s).isFullscreen, r = () => {
  const s = (e) => {
    e.key === "Escape" && f();
  };
  return typeof window < "u" && window.addEventListener("keydown", s), () => {
    typeof window < "u" && window.removeEventListener("keydown", s);
  };
};
typeof window < "u" && (document.readyState === "loading" ? document.addEventListener("DOMContentLoaded", r) : r());
const g = () => ({
  name: "fullscreen",
  toolbar: [
    {
      label: "Fullscreen",
      command: "toggleFullscreen",
      type: "button",
      icon: '<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M8 3H5a2 2 0 0 0-2 2v3m18 0V5a2 2 0 0 0-2-2h-3m0 18h3a2 2 0 0 0 2-2v-3M3 16v3a2 2 0 0 0 2 2h3"></path></svg>'
    }
  ],
  commands: {
    toggleFullscreen: i
  },
  keymap: {
    Escape: () => {
      const s = document.querySelectorAll("[data-editora-editor]");
      for (const e of s)
        if (d(e))
          return f(e), !0;
      return !1;
    }
  }
});
export {
  g as FullscreenPlugin
};
