import { ref as h, onMounted as k, onUnmounted as q, watchEffect as C } from "vue";
function Y(x, S = { x: 0, y: 0, width: 100, height: 100 }, b = 1, z) {
  const a = h({ ...S }), i = h(1), y = h(!1), l = h({ x: 0, y: 0 });
  let u = { x: 0, y: 0 }, E = null, c = null;
  function v(e) {
    var s;
    const t = x.value;
    if (!t) return { x: 0, y: 0 };
    const n = t.createSVGPoint();
    n.x = e.clientX, n.y = e.clientY;
    const o = (s = t.getScreenCTM()) == null ? void 0 : s.inverse();
    return o ? n.matrixTransform(o) : { x: 0, y: 0 };
  }
  function m(e) {
    y.value = !0;
    const t = v(e.touches ? e.touches[0] : e);
    l.value = { x: t.x, y: t.y }, u = { x: 0, y: 0 };
  }
  function d(e) {
    if (!y.value) return;
    const t = v(e.touches ? e.touches[0] : e);
    let n = t.x - l.value.x, o = t.y - l.value.y;
    Math.abs(n) < 0.3 && Math.abs(o) < 0.3 || (u.x = n * 0.8 + u.x * 0.2, u.y = o * 0.8 + u.y * 0.2, l.value = t, E || (E = requestAnimationFrame(A)));
  }
  function A() {
    a.value.x -= u.x, a.value.y -= u.y, E = null;
  }
  function r() {
    y.value = !1;
  }
  function w(e) {
    e.preventDefault();
    const t = e.deltaY > 0 ? 0.9 : 1.1;
    P(t, v(e));
  }
  function g(e) {
    e.preventDefault();
    const t = v(e), n = 1.02 * (1 + b / 100);
    D(n, t);
  }
  function D(e, t) {
    c && cancelAnimationFrame(c);
    let n = i.value, o = n * e, s = 0;
    const f = () => {
      s += 0.02;
      let p = n + (o - n) * M(s);
      if (s >= 1) {
        i.value = o, c = null;
        return;
      }
      P(p / n, t), c = requestAnimationFrame(f);
    };
    f();
  }
  const M = (e) => e < 0.5 ? 2 * e * e : -1 + (4 - 2 * e) * e;
  function P(e, t) {
    const n = i.value * e, o = n / i.value, s = a.value.width / o, f = a.value.height / o, p = (t.x - a.value.x) * (1 - 1 / o), Z = (t.y - a.value.y) * (1 - 1 / o);
    a.value.x += p, a.value.y += Z, a.value.width = s, a.value.height = f, i.value = n;
  }
  k(F), q(L);
  function F() {
    const e = x.value;
    e && (e.addEventListener("mousedown", m), e.addEventListener("mousemove", d), e.addEventListener("mouseup", r), e.addEventListener("mouseleave", r), e.addEventListener("wheel", w, { passive: !1 }), e.addEventListener("dblclick", g), e.addEventListener("touchstart", (t) => {
      t.preventDefault(), m(t);
    }, { passive: !1 }), e.addEventListener("touchmove", (t) => {
      t.preventDefault(), d(t);
    }, { passive: !1 }), e.addEventListener("touchend", r));
  }
  function L() {
    const e = x.value;
    e && (e.removeEventListener("mousedown", m), e.removeEventListener("mousemove", d), e.removeEventListener("mouseup", r), e.removeEventListener("mouseleave", r), e.removeEventListener("wheel", w), e.removeEventListener("dblclick", g), e.removeEventListener("touchstart", m), e.removeEventListener("touchmove", d), e.removeEventListener("touchend", r));
  }
  return C(() => (z.value ? F() : L(), () => {
    L();
  })), { viewBox: a };
}
export {
  Y as u
};
