import { defineComponent as k, resolveComponent as P, openBlock as d, createElementBlock as c, Fragment as x, renderList as A, withModifiers as p, normalizeClass as L, createElementVNode as C, toDisplayString as I, createCommentVNode as v, createBlock as O, computed as S, normalizeStyle as U, createVNode as D, render as w } from "vue";
import { _ as b } from "./lib-Dg5Oz41t.js";
import { t as G } from "./tippy.esm-Dos-q4Dz.js";
const R = { class: "menu-content" }, X = ["onClick"], V = { class: "text" }, W = {
  key: 0,
  class: "sub-text"
}, $ = /* @__PURE__ */ k({
  __name: "MenuContent",
  props: {
    menus: {},
    handleClickMenuItem: { type: Function }
  },
  setup(e) {
    return (n, o) => {
      const s = P("menu-content", !0);
      return d(), c("ul", R, [
        (d(!0), c(x, null, A(e.menus, (t, i) => (d(), c(x, {
          key: t.text || i
        }, [
          t.hide ? v("", !0) : (d(), c("li", {
            key: 0,
            class: L(["menu-item", { divider: t.divider, disable: t.disable }]),
            onClick: p((r) => e.handleClickMenuItem(t), ["stop"])
          }, [
            t.divider ? v("", !0) : (d(), c("div", {
              key: 0,
              class: L(["menu-item-content", {
                "has-children": t.children,
                "has-handler": t.handler
              }])
            }, [
              C("span", V, I(t.text), 1),
              t.subText && !t.children ? (d(), c("span", W, I(t.subText), 1)) : v("", !0),
              t.children && t.children.length ? (d(), O(s, {
                key: 1,
                class: "sub-menu",
                menus: t.children,
                handleClickMenuItem: e.handleClickMenuItem
              }, null, 8, ["menus", "handleClickMenuItem"])) : v("", !0)
            ], 2))
          ], 10, X))
        ], 64))), 128))
      ]);
    };
  }
}), z = /* @__PURE__ */ b($, [["__scopeId", "data-v-124d579c"]]), B = /* @__PURE__ */ k({
  __name: "index",
  props: {
    axis: {},
    el: {},
    menus: {},
    removeContextmenu: { type: Function }
  },
  setup(e) {
    const n = e, o = S(() => {
      const { x: f, y } = n.axis, N = n.menus.filter((m) => !(m.divider || m.hide)).length, g = n.menus.filter((m) => m.divider).length, _ = 180, E = N * 30 + g * 11 + 5 * 2, H = document.body.clientWidth, M = document.body.clientHeight;
      return {
        left: H <= f + _ ? f - _ : f,
        top: M <= y + E ? y - E : y
      };
    }), s = (t) => {
      t.disable || t.children && !t.handler || (t.handler && t.handler(n.el), n.removeContextmenu());
    };
    return (t, i) => (d(), c(x, null, [
      C("div", {
        class: "pptist-contextmenu-mask",
        onContextmenu: i[0] || (i[0] = p((r) => e.removeContextmenu(), ["prevent"])),
        onMousedown: i[1] || (i[1] = p((r) => e.removeContextmenu(), ["left"]))
      }, null, 32),
      C("div", {
        class: "pptist-contextmenu",
        style: U({
          left: o.value.left + "px",
          top: o.value.top + "px"
        }),
        onContextmenu: i[2] || (i[2] = p(() => {
        }, ["prevent"]))
      }, [
        D(z, {
          menus: e.menus,
          handleClickMenuItem: s
        }, null, 8, ["menus"])
      ], 36)
    ], 64));
  }
}), l = "CTX_CONTEXTMENU_HANDLER", F = (e, n, o) => {
  n.stopPropagation(), n.preventDefault();
  const s = o.value(e);
  if (!s) return;
  let t = null;
  const i = () => {
    t && (document.body.removeChild(t), t = null), e.classList.remove("contextmenu-active"), document.body.removeEventListener("scroll", i), window.removeEventListener("resize", i);
  }, r = {
    axis: { x: n.x, y: n.y },
    el: e,
    menus: s,
    removeContextmenu: i
  };
  t = document.createElement("div");
  const h = D(B, r, null);
  w(h, t), document.body.appendChild(t), e.classList.add("contextmenu-active"), document.body.addEventListener("scroll", i), window.addEventListener("resize", i);
}, q = {
  mounted(e, n) {
    e[l] = (o) => F(e, o, n), e.addEventListener("contextmenu", e[l]);
  },
  unmounted(e) {
    e && e[l] && (e.removeEventListener("contextmenu", e[l]), delete e[l]);
  }
}, a = "CTX_CLICK_OUTSIDE_HANDLER", K = (e, n, o) => {
  const s = o.value, t = n.composedPath();
  (t ? t.indexOf(e) < 0 : !e.contains(n.target)) && s(n);
}, j = {
  mounted(e, n) {
    e[a] = (o) => K(e, o, n), setTimeout(() => {
      document.addEventListener("click", e[a]);
    }, 0);
  },
  unmounted(e) {
    e[a] && (document.removeEventListener("click", e[a]), delete e[a]);
  }
}, u = "TOOLTIP_INSTANCE", J = {
  mounted(e, n) {
    let o = "", s = "top", t = [300, 0];
    typeof n.value == "string" ? o = n.value : (o = n.value.content, n.value.placement !== void 0 && (s = n.value.placement), n.value.delay !== void 0 && (t = n.value.delay)), e[u] = G(e, {
      content: o,
      theme: "pptist-tooltip",
      duration: 100,
      animation: "scale",
      allowHTML: !0,
      placement: s,
      delay: t
    });
  },
  updated(e, n) {
    let o = "";
    typeof n.value == "string" ? o = n.value : o = n.value.content, e[u] && e[u].setContent(o);
  },
  unmounted(e) {
    e[u] && e[u].destroy();
  }
}, Q = {
  mounted(e, n) {
    T(e, n.value);
  },
  updated(e, n) {
    T(e, n.value);
  },
  unmounted(e) {
    Y(e);
  }
}, Y = (e) => {
  const n = e.querySelector(".directive-loading-overlay");
  n && n.remove(), e._vLoadingAddedPosition && (e.style.removeProperty("position"), delete e._vLoadingAddedPosition);
}, T = (e, n) => {
  let o = !1, s = "";
  typeof n == "boolean" ? o = n : (n.text && (s = n.text), o = n.state);
  let t = e.querySelector(".directive-loading-overlay");
  o ? (getComputedStyle(e).position === "static" && (e.style.position = "relative", e._vLoadingAddedPosition = !0), t || (t = document.createElement("div"), t.className = "directive-loading-overlay", e.appendChild(t)), s ? (t.classList.add("has-text"), t.style.setProperty("--directive-loading-text", `"${s}"`)) : (t.classList.remove("has-text"), t.style.removeProperty("--directive-loading-text"))) : (t && t.remove(), e._vLoadingAddedPosition && (e.style.removeProperty("position"), delete e._vLoadingAddedPosition));
}, ne = {
  install(e) {
    e.directive("contextmenu", q), e.directive("click-outside", j), e.directive("tooltip", J), e.directive("loading", Q);
  }
};
export {
  ne as default
};
