import{G as P,a1 as T,H as W,y as z,am as L}from"./index-BKKvzUDD.js";import{c as w}from"./clamp-CbbY8h6F.js";const $=(n,c,M,d)=>{const o={offsetX:0,offsetY:0},u=z(!1),v=(t,e)=>{if(n.value){const{offsetX:f,offsetY:l}=o,s=n.value.getBoundingClientRect(),a=Math.max(s.left,0),i=Math.max(s.top,0),m=s.width,g=s.height,x=document.documentElement.clientWidth,E=document.documentElement.clientHeight,D=-a+f,H=-i+l,b=x-a-m+f,y=E-i-(g<E?g:0)+l;d!=null&&d.value||(t=w(t,D,b),e=w(e,H,y)),o.offsetX=t,o.offsetY=e,n.value.style.transform=`translate(${L(t)}, ${L(e)})`}},h=t=>{const e=t.clientX,f=t.clientY,{offsetX:l,offsetY:s}=o,a=m=>{u.value||(u.value=!0),v(l+m.clientX-e,s+m.clientY-f)},i=()=>{u.value=!1,document.removeEventListener("mousemove",a),document.removeEventListener("mouseup",i)};document.addEventListener("mousemove",a),document.addEventListener("mouseup",i)},X=()=>{c.value&&n.value&&(c.value.addEventListener("mousedown",h),window.addEventListener("resize",r))},p=()=>{c.value&&n.value&&(c.value.removeEventListener("mousedown",h),window.removeEventListener("resize",r))},Y=()=>{o.offsetX=0,o.offsetY=0,n.value&&(n.value.style.transform="")},r=()=>{const{offsetX:t,offsetY:e}=o;v(t,e)};return P(()=>{T(()=>{M.value?X():p()})}),W(()=>{p()}),{isDragging:u,resetPosition:Y,updatePosition:r}};export{$ as u};
