(function(u,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],t):(u=typeof globalThis<"u"?globalThis:u||self,t(u.usepos={},u.React))})(this,function(u,t){"use strict";var S=Object.defineProperty;var C=(u,t,l)=>t in u?S(u,t,{enumerable:!0,configurable:!0,writable:!0,value:l}):u[t]=l;var g=(u,t,l)=>(C(u,typeof t!="symbol"?t+"":t,l),l);function l(e){const n=window.innerWidth,i=window.innerHeight,f=e.width*e.height;function o(a,s,c){return Math.min(c,Math.max(s,a))}return(o(e.right,0,n)-o(e.left,0,n))*(o(e.bottom,0,i)-o(e.top,0,i))/f}function M(e){const n=e.getBoundingClientRect(),i=typeof(n==null?void 0:n.toJSON)=="function"?n.toJSON():n;return typeof i=="string"?JSON.parse(i):i}function R(e,n){return e.top!==n.top||e.left!==n.left}function p(){const e=Math.floor(Math.random()*100%100+10),n=Date.now();return`id-${e.toString(16)}-${n.toString(10)}`}class W{constructor(n){g(this,"isBrowser",function(){return typeof window<"u"}());g(this,"clients");this.clients=n}register(n){this.clients.push(n)}unregister(n){const i=this.clients.indexOf(n);this.clients.splice(i,i===-1?0:1)}}const b={callOnResize:!0},v=[],h=new W(v);(function(){if(!h.isBrowser)return;let e=window.innerWidth,n=window.innerHeight,i=0;const f=o=>{if(o-i<100){window.requestAnimationFrame(f);return}i=o;const d=window.innerWidth,r=window.innerHeight,a=e!==d||n!==r;v.forEach(s=>{if(!s.ref||!s.callback)return;const c=M(s.ref),w={windowResize:a,screenWidth:d,screenHeight:r,visible:l(c)};if(!s.prevVal){s.prevVal=c,s.callback(c,w);return}if(!R(s.prevVal,c)){if(s.config.callOnResize&&a){s.callback(c,w);return}s.depsChange&&(s.depsChange=!1,s.callback(c,w));return}s.prevVal=c,s.callback(c,w)}),a&&(e=d,n=r),window.requestAnimationFrame(f)};window.requestAnimationFrame(o=>{i=o,f(o)})})();function O(e,n){const i=t.useRef(),[f,o]=t.useState(void 0);return t.useEffect(()=>{if(typeof window>"u")return;const r={id:p(),callback:(a,s)=>{const c={...a,...s};o(c)},ref:e==null?void 0:e.current,config:b};return i.current=r,h.register(r),()=>{h.unregister(r),i.current=void 0}},[]),t.useEffect(()=>{if(i.current){const d=i.current;d.ref=(e==null?void 0:e.current)||void 0,d.config=n||b}},[e,n]),f}const m={callOnResize:!0};function y(e,n,i,f){const o=t.useRef(),d=t.useRef(0);t.useEffect(()=>{if(typeof window>"u")return;const a={id:p(),ref:e.current||void 0,config:m};return o.current=a,h.register(a),()=>{h.unregister(a),o.current=void 0}},[]),t.useEffect(()=>{if(o.current){const r=o.current;r.callback=n,r.ref=(e==null?void 0:e.current)||void 0,r.config=i||m}},[e,n,i,f]),t.useEffect(()=>{if(d.current+=1,d.current!=1&&o.current){const r=o.current;r.depsChange=!0}},f||[])}u.__usePosition=y,u.usePosition=O,Object.defineProperties(u,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});