import{s as S}from"./chunk-LvLJmgfZ.js";import{t as m}from"./react-Bj1aDYRI.js";var n=S(m());function k(e,u){var r=(0,n.useRef)(null),c=(0,n.useRef)(null);c.current=u;var t=(0,n.useRef)(null);(0,n.useEffect)(function(){f()});var f=(0,n.useCallback)(function(){var i=t.current,s=c.current,o=i||(s?s instanceof Element?s:s.current:null);r.current&&r.current.element===o&&r.current.subscriber===e||(r.current&&r.current.cleanup&&r.current.cleanup(),r.current={element:o,subscriber:e,cleanup:o?e(o):void 0})},[e]);return(0,n.useEffect)(function(){return function(){r.current&&r.current.cleanup&&(r.current.cleanup(),r.current=null)}},[]),(0,n.useCallback)(function(i){t.current=i,f()},[f])}function g(e,u,r){return e[u]?e[u][0]?e[u][0][r]:e[u][r]:u==="contentBoxSize"?e.contentRect[r==="inlineSize"?"width":"height"]:void 0}function B(e){e===void 0&&(e={});var u=e.onResize,r=(0,n.useRef)(void 0);r.current=u;var c=e.round||Math.round,t=(0,n.useRef)(),f=(0,n.useState)({width:void 0,height:void 0}),i=f[0],s=f[1],o=(0,n.useRef)(!1);(0,n.useEffect)(function(){return o.current=!1,function(){o.current=!0}},[]);var a=(0,n.useRef)({width:void 0,height:void 0}),h=k((0,n.useCallback)(function(v){return(!t.current||t.current.box!==e.box||t.current.round!==c)&&(t.current={box:e.box,round:c,instance:new ResizeObserver(function(z){var b=z[0],x=e.box==="border-box"?"borderBoxSize":e.box==="device-pixel-content-box"?"devicePixelContentBoxSize":"contentBoxSize",p=g(b,x,"inlineSize"),w=g(b,x,"blockSize"),l=p?c(p):void 0,d=w?c(w):void 0;if(a.current.width!==l||a.current.height!==d){var R={width:l,height:d};a.current.width=l,a.current.height=d,r.current?r.current(R):o.current||s(R)}})}),t.current.instance.observe(v,{box:e.box}),function(){t.current&&t.current.instance.unobserve(v)}},[e.box,c]),e.ref);return(0,n.useMemo)(function(){return{ref:h,width:i.width,height:i.height}},[h,i.width,i.height])}export{B as t};
