"use strict";const r=require("vue");function k(x,S={x:0,y:0,width:100,height:100},b=1,Z){const a=r.ref({...S}),l=r.ref(1),y=r.ref(!1),c=r.ref({x:0,y:0});let u={x:0,y:0},E=null,v=null;function m(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 d(e){y.value=!0;const t=m(e.touches?e.touches[0]:e);c.value={x:t.x,y:t.y},u={x:0,y:0}}function f(e){if(!y.value)return;const t=m(e.touches?e.touches[0]:e);let n=t.x-c.value.x,o=t.y-c.value.y;Math.abs(n)<.3&&Math.abs(o)<.3||(u.x=n*.8+u.x*.2,u.y=o*.8+u.y*.2,c.value=t,E||(E=requestAnimationFrame(z)))}function z(){a.value.x-=u.x,a.value.y-=u.y,E=null}function i(){y.value=!1}function w(e){e.preventDefault();const t=e.deltaY>0?.9:1.1;P(t,m(e))}function g(e){e.preventDefault();const t=m(e),n=1.02*(1+b/100);A(n,t)}function A(e,t){v&&cancelAnimationFrame(v);let n=l.value,o=n*e,s=0;const h=()=>{s+=.02;let p=n+(o-n)*D(s);if(s>=1){l.value=o,v=null;return}P(p/n,t),v=requestAnimationFrame(h)};h()}const D=e=>e<.5?2*e*e:-1+(4-2*e)*e;function P(e,t){const n=l.value*e,o=n/l.value,s=a.value.width/o,h=a.value.height/o,p=(t.x-a.value.x)*(1-1/o),M=(t.y-a.value.y)*(1-1/o);a.value.x+=p,a.value.y+=M,a.value.width=s,a.value.height=h,l.value=n}r.onMounted(F),r.onUnmounted(L);function F(){const e=x.value;e&&(e.addEventListener("mousedown",d),e.addEventListener("mousemove",f),e.addEventListener("mouseup",i),e.addEventListener("mouseleave",i),e.addEventListener("wheel",w,{passive:!1}),e.addEventListener("dblclick",g),e.addEventListener("touchstart",t=>{t.preventDefault(),d(t)},{passive:!1}),e.addEventListener("touchmove",t=>{t.preventDefault(),f(t)},{passive:!1}),e.addEventListener("touchend",i))}function L(){const e=x.value;e&&(e.removeEventListener("mousedown",d),e.removeEventListener("mousemove",f),e.removeEventListener("mouseup",i),e.removeEventListener("mouseleave",i),e.removeEventListener("wheel",w),e.removeEventListener("dblclick",g),e.removeEventListener("touchstart",d),e.removeEventListener("touchmove",f),e.removeEventListener("touchend",i))}return r.watchEffect(()=>(Z.value?F():L(),()=>{L()})),{viewBox:a}}exports.usePanZoom=k;
