import{o as e}from"./rolldown-runtime.C0FnF6B9.js";import{r as t}from"./emotion-is-prop-valid.esm.CuYlOKOk.js";import{t as n}from"./useTimeout.DgWF0Nme.js";var r=e(t(),1);function i(e,t){let i=(0,r.useRef)(null),a=(0,r.useRef)(!1),o=(0,r.useRef)(e),s=(0,r.useRef)(null);(0,r.useEffect)(()=>{o.current=e},[e]);let c=(0,r.useCallback)(()=>{if(a.current=!1,i.current!==null){let e=i.current;i.current=null,o.current(...e),a.current=!0,s.current?.()}},[]),{clear:l,restart:u}=n(c,t,{autoStart:!1});(0,r.useEffect)(()=>{s.current=u},[u]);let d=(0,r.useCallback)(()=>{l(),i.current=null,a.current=!1},[l]);return{throttledCallback:(0,r.useCallback)((...e)=>{a.current?i.current=e:(o.current(...e),a.current=!0,u())},[u]),cancel:d}}var a=(e,t=[],n=0)=>{let a=(0,r.useRef)(null),[o,s]=(0,r.useState)([]),c=(0,r.useCallback)(()=>{if(!a.current)return[];let t=a.current.getBoundingClientRect();return e.map(e=>t[e])},[e]),{throttledCallback:l,cancel:u}=i((0,r.useCallback)(()=>{s(c())},[c]),Math.max(n,1));return(0,r.useEffect)(()=>{if(!a.current)return;s(c());let e,t=new ResizeObserver(()=>{e&&cancelAnimationFrame(e),e=window.requestAnimationFrame(()=>{n>0?l():s(c())})});return t.observe(a.current),()=>{t.disconnect(),e&&cancelAnimationFrame(e),u()}},[e,c,n,l,u,...t]),{values:o,elementRef:a}};export{i as n,a as t};