"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const Vue = require("vue");
const index$1 = require("../../../../../@vueuse/core/index.js");
const constants = require("./constants.js");
const util = require("./util.js");
const thumb = require("./thumb.js");
const pluginVue_exportHelper = require("../../../_virtual/plugin-vue_export-helper.js");
const index = require("../../../hooks/use-namespace/index.js");
const error = require("../../../utils/error.js");
const index$2 = require("../../../../../@vueuse/shared/index.js");
const Z = "Thumb", $ = /* @__PURE__ */ Vue.defineComponent({
  __name: "thumb",
  props: thumb.thumbProps,
  setup(k) {
    const u = k, o = Vue.inject(constants.scrollbarContextKey), c = index.useNamespace("scrollbar");
    o || error.throwError(Z, "can not inject scrollbar context");
    const l = Vue.ref(), a = Vue.ref(), f = Vue.ref({}), i = Vue.ref(false);
    let m = false, d = false, p = index$2.isClient ? document.onselectstart : null;
    const e = Vue.computed(() => util.BAR_MAP[u.vertical ? "vertical" : "horizontal"]), z = Vue.computed(() => util.renderThumbStyle({
      size: u.size,
      move: u.move,
      bar: e.value
    })), g = Vue.computed(() => l.value[e.value.offset] ** 2 / o.wrapElement[e.value.scrollSize] / u.ratio / a.value[e.value.offset]), x = (t) => {
      var n;
      if (t.stopPropagation(), t.ctrlKey || [1, 2].includes(t.button))
        return;
      (n = window.getSelection()) == null || n.removeAllRanges(), M(t);
      const r = t.currentTarget;
      r && (f.value[e.value.axis] = r[e.value.offset] - (t[e.value.client] - r.getBoundingClientRect()[e.value.direction]));
    }, L = (t) => {
      if (!a.value || !l.value || !o.wrapElement)
        return;
      const n = Math.abs(t.target.getBoundingClientRect()[e.value.direction] - t[e.value.client]), r = a.value[e.value.offset] / 2, h = (n - r) * 100 * g.value / l.value[e.value.offset];
      o.wrapElement[e.value.scroll] = h * o.wrapElement[e.value.scrollSize] / 100;
    }, M = (t) => {
      t.stopImmediatePropagation(), m = true, document.addEventListener("mousemove", w), document.addEventListener("mouseup", b), p = document.onselectstart, document.onselectstart = () => false;
    }, w = (t) => {
      if (!l.value || !a.value || m === false)
        return;
      const n = f.value[e.value.axis];
      if (!n)
        return;
      const r = (l.value.getBoundingClientRect()[e.value.direction] - t[e.value.client]) * -1, h = a.value[e.value.offset] - n, H = (r - h) * 100 * g.value / l.value[e.value.offset];
      o.wrapElement[e.value.scroll] = H * o.wrapElement[e.value.scrollSize] / 100;
    }, b = () => {
      m = false, f.value[e.value.axis] = 0, document.removeEventListener("mousemove", w), document.removeEventListener("mouseup", b), _(), d && (i.value = false);
    }, T = () => {
      d = false, i.value = !!u.size;
    }, B = () => {
      d = true, i.value = m;
    };
    Vue.onBeforeUnmount(() => {
      _(), document.removeEventListener("mouseup", b);
    });
    const _ = () => {
      document.onselectstart !== p && (document.onselectstart = p);
    };
    return index$1.useEventListener(Vue.toRef(o, "scrollbarElement"), "mousemove", T), index$1.useEventListener(Vue.toRef(o, "scrollbarElement"), "mouseleave", B), (t, n) => (Vue.openBlock(), Vue.createBlock(Vue.Transition, {
      name: Vue.unref(c).b("fade"),
      persisted: ""
    }, {
      default: Vue.withCtx(() => [
        Vue.withDirectives(Vue.createElementVNode("div", {
          ref_key: "instance",
          ref: l,
          class: Vue.normalizeClass([Vue.unref(c).e("bar"), Vue.unref(c).is(Vue.unref(e).key)]),
          onMousedown: L
        }, [
          Vue.createElementVNode("div", {
            ref_key: "thumb",
            ref: a,
            class: Vue.normalizeClass(Vue.unref(c).e("thumb")),
            style: Vue.normalizeStyle(Vue.unref(z)),
            onMousedown: x
          }, null, 38)
        ], 34), [
          [Vue.vShow, t.always || i.value]
        ])
      ]),
      _: 1
    }, 8, ["name"]));
  }
});
var ce = /* @__PURE__ */ pluginVue_exportHelper.default($, [["__file", "thumb.vue"]]);
exports.default = ce;
