UNPKG

@konstructio/ui

Version:

A set of reusable and customizable React components built for konstruct.io

33 lines (32 loc) 980 B
import * as f from "react"; import { u as a } from "./index-Cva-e5M4.js"; function h(r) { const e = f.useRef({ value: r, previous: r }); return f.useMemo(() => (e.current.value !== r && (e.current.previous = e.current.value, e.current.value = r), e.current.previous), [r]); } function z(r) { const [e, i] = f.useState(void 0); return a(() => { if (r) { i({ width: r.offsetWidth, height: r.offsetHeight }); const n = new ResizeObserver((o) => { if (!Array.isArray(o) || !o.length) return; const c = o[0]; let t, s; if ("borderBoxSize" in c) { const u = c.borderBoxSize, b = Array.isArray(u) ? u[0] : u; t = b.inlineSize, s = b.blockSize; } else t = r.offsetWidth, s = r.offsetHeight; i({ width: t, height: s }); }); return n.observe(r, { box: "border-box" }), () => n.unobserve(r); } else i(void 0); }, [r]), e; } export { z as a, h as u };