import { useState as k, useRef as a, useCallback as d, useLayoutEffect as v } from "react";
const c = (e) => {
  const t = e?.borderBoxSize?.at(0);
  return {
    blockSize: t?.blockSize ?? e?.contentRect.height,
    inlineSize: t?.inlineSize ?? e?.contentRect.width
  };
}, g = (e) => {
  const [t, f] = k(null), s = a(null), o = a(null), r = d(() => o.current?.disconnect(), []), l = d(() => {
    o.current = new ResizeObserver(([n]) => {
      f((i) => {
        if (!i)
          return n;
        const b = c(i), u = c(n);
        return i.target === n.target && b.blockSize === u.blockSize && b.inlineSize === u.inlineSize ? i : n;
      });
    });
    const S = e ?? s.current;
    S && o.current.observe(S);
  }, [e]);
  v(() => (r(), l(), () => r()), [r, l]);
  const z = c(t);
  return [
    s,
    t,
    {
      blockSize: z.blockSize,
      inlineSize: z.inlineSize
    }
  ];
};
export {
  g as default
};
//# sourceMappingURL=useResizeObserver.js.map
