"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useElementRect = void 0;
const react_1 = require("react");
function useElementRect(element) {
    const [rect, setRect] = (0, react_1.useState)(() => element === null || element === void 0 ? void 0 : element.getBoundingClientRect());
    (0, react_1.useEffect)(() => {
        if (!element)
            return;
        const observer = new ResizeObserver(entries => {
            const el = entries.find(entry => entry.target === element);
            if (!el) {
                throw new Error('Element is not found in observed entries');
            }
            setRect(el.target.getBoundingClientRect());
        });
        observer.observe(element);
        return () => {
            observer.unobserve(element);
            observer.disconnect();
        };
    }, [element]);
    return rect;
}
exports.useElementRect = useElementRect;
