import{a as e,o as t,U as n,b as o,by as s}from"./index-ip5gDR6L.js";const a=(a,u,i,l)=>{const v={offsetX:0,offsetY:0},m=e(!1),f=(e,t)=>{if(a.value){const{offsetX:n,offsetY:o}=v,u=a.value.getBoundingClientRect(),i=u.left,m=u.top,f=u.width,d=u.height,r=document.documentElement.clientWidth,c=document.documentElement.clientHeight,E=-i+n,h=-m+o,L=r-i-f+n,X=c-m-(d<c?d:0)+o;(null==l?void 0:l.value)||(e=Math.min(Math.max(e,E),L),t=Math.min(Math.max(t,h),X)),v.offsetX=e,v.offsetY=t,a.value.style.transform=`translate(${s(e)}, ${s(t)})`}},d=e=>{const t=e.clientX,n=e.clientY,{offsetX:o,offsetY:s}=v,a=e=>{m.value||(m.value=!0);const a=o+e.clientX-t,u=s+e.clientY-n;f(a,u)},u=()=>{m.value=!1,document.removeEventListener("mousemove",a),document.removeEventListener("mouseup",u)};document.addEventListener("mousemove",a),document.addEventListener("mouseup",u)},r=()=>{u.value&&a.value&&(u.value.removeEventListener("mousedown",d),window.removeEventListener("resize",c))},c=()=>{const{offsetX:e,offsetY:t}=v;f(e,t)};return t(()=>{n(()=>{i.value?u.value&&a.value&&(u.value.addEventListener("mousedown",d),window.addEventListener("resize",c)):r()})}),o(()=>{r()}),{isDragging:m,resetPosition:()=>{v.offsetX=0,v.offsetY=0,a.value&&(a.value.style.transform="")},updatePosition:c}};export{a as u};
