import { useReducer as u, useMemo as o } from "react";
import { useIsoMorphicEffect as s } from "./use-iso-morphic-effect.js";
function f(e) {
  if (e === null) return { width: 0, height: 0 };
  let { width: t, height: i } = e.getBoundingClientRect();
  return { width: t, height: i };
}
function l(e, t = !1) {
  let [i, h] = u(() => ({}), {}), r = o(() => f(e), [e, i]);
  return s(() => {
    if (!e) return;
    let n = new ResizeObserver(h);
    return n.observe(e), () => {
      n.disconnect();
    };
  }, [e]), t ? { width: `${r.width}px`, height: `${r.height}px` } : r;
}
export {
  l as useElementSize
};
