/*! © 2026 Yahoo, Inc. UDS v0.0.0-development */
//#region src/utils/getUnscaledAnchorRect.ts
/**
* Returns the anchor element's bounding rect with CSS transform scale
* factored out. This keeps tooltips and popovers stable when their
* trigger element scales on hover (e.g. a Button with a scale effect).
*
* Assumes the default `transform-origin: center`.
*/
function getUnscaledAnchorRect(anchor) {
	if (!anchor) return null;
	const rect = anchor.getBoundingClientRect();
	const { transform } = getComputedStyle(anchor);
	if (!transform || transform === "none") return rect;
	const matrix = new DOMMatrix(transform);
	const scaleX = Math.hypot(matrix.a, matrix.b);
	const scaleY = Math.hypot(matrix.c, matrix.d);
	if (Math.abs(scaleX - 1) < .001 && Math.abs(scaleY - 1) < .001) return rect;
	const unscaledWidth = rect.width / scaleX;
	const unscaledHeight = rect.height / scaleY;
	const cx = rect.x + rect.width / 2;
	const cy = rect.y + rect.height / 2;
	return {
		x: cx - unscaledWidth / 2,
		y: cy - unscaledHeight / 2,
		width: unscaledWidth,
		height: unscaledHeight
	};
}
//#endregion
export { getUnscaledAnchorRect };
