// @bun
var{defineProperty:_,getOwnPropertyNames:w,getOwnPropertyDescriptor:D}=Object,O=Object.prototype.hasOwnProperty;function U(x){return this[x]}var Y=(x)=>{var z=(k??=new WeakMap).get(x),B;if(z)return z;if(z=_({},"__esModule",{value:!0}),x&&typeof x==="object"||typeof x==="function"){for(var H of w(x))if(!O.call(z,H))_(z,H,{get:U.bind(x,H),enumerable:!(B=D(x,H))||B.enumerable})}return k.set(x,z),z},k;var g=(x)=>x;function X(x,z){this[x]=g.bind(null,z)}var E=(x,z)=>{for(var B in z)_(x,B,{get:z[B],enumerable:!0,configurable:!0,set:X.bind(z,B)})};var P=(x,z)=>()=>(x&&(z=x(x=0)),z);var L=import.meta.require;function m(x={}){let{target:z=typeof window<"u"?window:null,touch:B=!0,resetOnLeave:H=!1}=x,q={x:0,y:0,pageX:0,pageY:0,clientX:0,clientY:0,movementX:0,movementY:0,buttons:0,isPressed:!1,isInside:!1},C=[],G=null,J=()=>{C.forEach((b)=>b(q))},K=(b,A=!1)=>{let F=b;q={x:F.pageX??F.clientX,y:F.pageY??F.clientY,pageX:F.pageX??0,pageY:F.pageY??0,clientX:F.clientX??0,clientY:F.clientY??0,movementX:A?0:F.movementX??0,movementY:A?0:F.movementY??0,buttons:A?1:F.buttons??0,isPressed:A||(F.buttons??0)>0,isInside:!0},J()},Q=(b)=>K(b),j=(b)=>{if(b.touches.length>0)K(b.touches[0],!0)},N=(b)=>{q={...q,buttons:b.buttons,isPressed:!0},J()},S=(b)=>{q={...q,buttons:b.buttons,isPressed:!1},J()},V=()=>{q={...q,isInside:!0},J()},R=()=>{q={...q,isInside:!1,...H?{x:0,y:0,pageX:0,pageY:0,clientX:0,clientY:0}:{}},J()},I=()=>{if(!z)return;let b=z;if(b.addEventListener("mousemove",Q),b.addEventListener("mousedown",N),b.addEventListener("mouseup",S),b.addEventListener("mouseenter",V),b.addEventListener("mouseleave",R),B)b.addEventListener("touchmove",j),b.addEventListener("touchstart",V),b.addEventListener("touchend",R);G=()=>{if(b.removeEventListener("mousemove",Q),b.removeEventListener("mousedown",N),b.removeEventListener("mouseup",S),b.removeEventListener("mouseenter",V),b.removeEventListener("mouseleave",R),B)b.removeEventListener("touchmove",j),b.removeEventListener("touchstart",V),b.removeEventListener("touchend",R)}};return{get:()=>q,subscribe:(b)=>{if(C.length===0)I();return C.push(b),b(q),()=>{if(C=C.filter((A)=>A!==b),C.length===0&&G)G(),G=null}},stop:()=>{if(G)G(),G=null;C=[]}}}function T(x,z={}){let{touch:B=!0,resetOnLeave:H=!0}=z,q={x:0,y:0,pageX:0,pageY:0,clientX:0,clientY:0,movementX:0,movementY:0,buttons:0,isPressed:!1,isInside:!1,elementX:0,elementY:0,elementWidth:0,elementHeight:0,isOutside:!0},C=[],G=null,J=()=>{C.forEach((I)=>I(q))},K=()=>{if(typeof x==="function")return x();return x},Q=(I,b)=>{let A=K();if(!A)return;let F=A.getBoundingClientRect(),W=I-F.left,Z=b-F.top,$=W<0||Z<0||W>F.width||Z>F.height;q={...q,elementX:W,elementY:Z,elementWidth:F.width,elementHeight:F.height,isOutside:$,isInside:!$}},j=(I,b=!1)=>{let A=I;q={...q,x:A.pageX??A.clientX,y:A.pageY??A.clientY,pageX:A.pageX??0,pageY:A.pageY??0,clientX:A.clientX??0,clientY:A.clientY??0,movementX:b?0:A.movementX??0,movementY:b?0:A.movementY??0,buttons:b?1:A.buttons??0,isPressed:b||(A.buttons??0)>0},Q(A.clientX,A.clientY),J()},N=(I)=>j(I),S=(I)=>{if(I.touches.length>0)j(I.touches[0],!0)},V=()=>{q={...q,isInside:!1,isOutside:!0,...H?{elementX:0,elementY:0}:{}},J()},R=()=>{if(typeof window>"u")return;if(window.addEventListener("mousemove",N),B)window.addEventListener("touchmove",S);G=()=>{if(window.removeEventListener("mousemove",N),B)window.removeEventListener("touchmove",S)}};return{get:()=>q,subscribe:(I)=>{if(C.length===0)R();return C.push(I),I(q),()=>{if(C=C.filter((b)=>b!==I),C.length===0&&G)G(),G=null}},stop:()=>{if(G)G(),G=null;C=[]}}}function M(x={}){let{target:z=typeof window<"u"?window:null}=x,B={x:0,y:0,pageX:0,pageY:0,clientX:0,clientY:0,movementX:0,movementY:0,buttons:0,isPressed:!1,isInside:!1},H=[],q=null,C=()=>{H.forEach((j)=>j(B))},G=(j)=>{B={x:j.pageX,y:j.pageY,pageX:j.pageX,pageY:j.pageY,clientX:j.clientX,clientY:j.clientY,movementX:j.movementX,movementY:j.movementY,buttons:j.buttons,isPressed:j.buttons>0||j.pressure>0,isInside:!0},C()},J=(j)=>{B={...B,buttons:j.buttons,isPressed:!0},C()},K=(j)=>{B={...B,buttons:j.buttons,isPressed:!1},C()},Q=()=>{if(!z)return;let j=z;j.addEventListener("pointermove",G),j.addEventListener("pointerdown",J),j.addEventListener("pointerup",K),q=()=>{j.removeEventListener("pointermove",G),j.removeEventListener("pointerdown",J),j.removeEventListener("pointerup",K)}};return{get:()=>B,subscribe:(j)=>{if(H.length===0)Q();return H.push(j),j(B),()=>{if(H=H.filter((N)=>N!==j),H.length===0&&q)q(),q=null}},stop:()=>{if(q)q(),q=null;H=[]}}}export{M as usePointer,T as useMouseInElement,m as useMouse};
