import { t as e } from "../../chunks/resize-observer.js";
import { useCallback as t, useEffect as n, useMemo as r, useRef as i, useState as a } from "react";
//#region lib/ui/hooks/useResizeObserver.ts
typeof window < "u" && !window.ResizeObserver && (window.ResizeObserver = e);
function o(e, t, n) {
	return e[t] ? e[t][0] ? e[t][0][n] : e[t][n] : t === "contentBoxSize" ? e.contentRect[n === "inlineSize" ? "width" : "height"] : void 0;
}
function s(e, r) {
	let a = i(null), o = i(null);
	o.current = r;
	let s = i(null);
	n(() => {
		c();
	});
	let c = t(() => {
		let t = s.current, n = o.current, r = t || (n ? n instanceof Element ? n : n.current : null);
		a.current && a.current.element === r && a.current.subscriber === e || (a.current && a.current.cleanup && a.current.cleanup(), a.current = {
			element: r,
			subscriber: e,
			cleanup: r ? e(r) : void 0
		});
	}, [e]);
	return n(() => () => {
		a.current && a.current.cleanup && (a.current.cleanup(), a.current = null);
	}, []), t((e) => {
		s.current = e, c();
	}, [c]);
}
function c(c = {}) {
	let l = c.onResize, u = i(void 0);
	u.current = l;
	let d = c.round || Math.round, f = i(void 0), [p, m] = a({
		width: void 0,
		height: void 0
	}), h = i(!1);
	n(() => (h.current = !1, () => {
		h.current = !0;
	}), []);
	let g = i({
		width: void 0,
		height: void 0
	}), _ = s(t((t) => ((!f.current || f.current.box !== c.box || f.current.round !== d) && (f.current = {
		box: c.box,
		round: d,
		instance: new e((e) => {
			let t = e[0], n = c.box === "border-box" ? "borderBoxSize" : c.box === "device-pixel-content-box" ? "devicePixelContentBoxSize" : "contentBoxSize", r = o(t, n, "inlineSize"), i = o(t, n, "blockSize"), a = r ? d(r) : void 0, s = i ? d(i) : void 0;
			if (g.current.width !== a || g.current.height !== s) {
				let e = {
					width: a,
					height: s
				};
				g.current.width = a, g.current.height = s, u.current ? u.current(e) : h.current || m(e);
			}
		})
	}), f.current.instance.observe(t, { box: c.box }), () => {
		f.current && f.current.instance.unobserve(t);
	}), [c.box, d]), c.ref);
	return r(() => ({
		ref: _,
		width: p.width,
		height: p.height
	}), [
		_,
		p.width,
		p.height
	]);
}
//#endregion
export { c as default, c as useResizeObserver, s as useResolvedElement };

//# sourceMappingURL=useResizeObserver.js.map