{"version":3,"file":"use-dimensions.mjs","names":[],"sources":["../../../src/components/OverflowList/use-dimensions.tsx"],"sourcesContent":["import React, { useEffect, useRef, useState } from 'react';\n\ninterface ResizeObserverDimensions {\n  width: number;\n  height: number;\n  contentWidth: number;\n  contentHeight: number;\n}\nexport function useDimensions<T extends HTMLElement | null>(\n  elementRef: React.RefObject<T>\n): ResizeObserverDimensions | null {\n  const resizeObserverRef = useRef<ResizeObserver | null>(null);\n  const [dimensions, setDimensions] = useState<ResizeObserverDimensions | null>(null);\n\n  useEffect(() => {\n    if (!elementRef.current) {\n      return;\n    }\n\n    // The observer watches the same element that the measuring cycle resizes.\n    // Updating dimensions synchronously inside the callback resizes an element\n    // whose notification is being delivered, which browsers report as\n    // \"ResizeObserver loop completed with undelivered notifications\"\n    // (a window `error` event). Defer the update to the next frame instead.\n    let frame = 0;\n\n    resizeObserverRef.current = new ResizeObserver((entries) => {\n      if (entries[0]) {\n        const entry = entries[0];\n        const nextDimensions = {\n          width: entry.borderBoxSize[0]?.inlineSize ?? entry.target.clientWidth,\n          height: entry.borderBoxSize[0]?.blockSize ?? entry.target.clientHeight,\n          contentWidth: entry.contentRect.width,\n          contentHeight: entry.contentRect.height,\n        };\n\n        cancelAnimationFrame(frame);\n        frame = requestAnimationFrame(() => setDimensions(nextDimensions));\n      }\n    });\n\n    resizeObserverRef.current.observe(elementRef.current);\n\n    return () => {\n      cancelAnimationFrame(frame);\n      if (resizeObserverRef.current) {\n        resizeObserverRef.current.disconnect();\n        resizeObserverRef.current = null;\n      }\n    };\n  }, [elementRef.current]);\n\n  return dimensions;\n}\n"],"mappings":";;;AAQA,SAAgB,cACd,YACiC;CACjC,MAAM,oBAAoB,OAA8B,IAAI;CAC5D,MAAM,CAAC,YAAY,iBAAiB,SAA0C,IAAI;CAElF,gBAAgB;EACd,IAAI,CAAC,WAAW,SACd;EAQF,IAAI,QAAQ;EAEZ,kBAAkB,UAAU,IAAI,gBAAgB,YAAY;GAC1D,IAAI,QAAQ,IAAI;IACd,MAAM,QAAQ,QAAQ;IACtB,MAAM,iBAAiB;KACrB,OAAO,MAAM,cAAc,EAAE,EAAE,cAAc,MAAM,OAAO;KAC1D,QAAQ,MAAM,cAAc,EAAE,EAAE,aAAa,MAAM,OAAO;KAC1D,cAAc,MAAM,YAAY;KAChC,eAAe,MAAM,YAAY;IACnC;IAEA,qBAAqB,KAAK;IAC1B,QAAQ,4BAA4B,cAAc,cAAc,CAAC;GACnE;EACF,CAAC;EAED,kBAAkB,QAAQ,QAAQ,WAAW,OAAO;EAEpD,aAAa;GACX,qBAAqB,KAAK;GAC1B,IAAI,kBAAkB,SAAS;IAC7B,kBAAkB,QAAQ,WAAW;IACrC,kBAAkB,UAAU;GAC9B;EACF;CACF,GAAG,CAAC,WAAW,OAAO,CAAC;CAEvB,OAAO;AACT"}