// Panel content is scaled with CSS `zoom` (see PanelSlot), and that splits measurement into two units.
// Layout — percentages, `transform: translateY(Npx)`, anything you write into a style — is in *layout*
// px, which zoom leaves alone. `getBoundingClientRect()` is in *rendered* px, already multiplied by the
// zoom. Feed one into the other and every offset is wrong by the zoom factor: at 0.7 a virtualiser
// measures each row as 70% of the height it will actually occupy, places the next row that much too
// early, and the list collapses into itself.
//
// `offsetHeight` is in layout px and would also fix it, but it rounds to whole pixels, which a
// virtualiser accumulates into visible drift. So keep the subpixel rect and divide the zoom back out.
// `currentCSSZoom` is the element's effective zoom including every zoomed ancestor; it is absent on
// older engines, where zoom is not applied either, so 1 is the right fallback.

const effectiveZoom = (element: Element) => (element as Element & { currentCSSZoom?: number }).currentCSSZoom || 1;

/** An element's height in layout px — the unit its own positioning styles are written in. */
export const measureHeight = (element: Element) => element.getBoundingClientRect().height / effectiveZoom(element);

/** An element's width in layout px. */
export const measureWidth = (element: Element) => element.getBoundingClientRect().width / effectiveZoom(element);
