/*! © 2026 Yahoo, Inc. UDS v0.0.0-development */
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
//#region src/utils/svgFloatingContentUtils.ts
/**
* Returns the side of the element where the arrow should appear.
* The arrow points *toward* the trigger, so it lives on the opposite
* side of the placement direction.
*/
function getArrowSide(placement) {
	switch (placement.split("-")[0]) {
		case "bottom": return "top";
		case "top": return "bottom";
		case "left": return "right";
		case "right": return "left";
		default: return "top";
	}
}
/**
* Generates an SVG `<path>` string for a rounded rectangle with an arrow
* pointing toward the trigger element.
*
* The path is traced clockwise, inserting the arrow triangle on the
* appropriate edge.  The arrow extends *outside* the 0,0 → width,height
* rectangle so the host `<svg>` must use `overflow: visible`.
*/
function generateSvgFloatingContentPath({ width, height, placement, borderRadius, arrowWidth, arrowHeight, arrowTipRadiusFraction, arrowCenter, offsetX: ox = 0, offsetY: oy = 0 }) {
	const aw = arrowWidth / 2;
	const ah = arrowHeight;
	const arrowSide = getArrowSide(placement);
	const arrowEdge = arrowSide === "top" || arrowSide === "bottom" ? width : height;
	const maxRadius = Math.min((arrowSide === "top" || arrowSide === "bottom" ? height : width) / 2, (arrowEdge - arrowWidth) / 2);
	const r = Math.max(0, Math.min(borderRadius, maxRadius));
	const minAc = r + aw;
	const edgeLength = arrowSide === "top" || arrowSide === "bottom" ? width : height;
	let ac = arrowCenter ?? edgeLength / 2;
	ac = Math.max(minAc, Math.min(edgeLength - minAc, ac));
	const edgeLen = Math.sqrt(aw * aw + ah * ah);
	const tipR = r > 0 && edgeLen > 0 ? Math.min(r * arrowTipRadiusFraction, edgeLen / 2) : 0;
	const daw = edgeLen > 0 ? aw / edgeLen : 0;
	const dah = edgeLen > 0 ? ah / edgeLen : 0;
	const d = [];
	d.push(`M ${r + ox} ${oy}`);
	if (arrowSide === "top") {
		d.push(`L ${ac - aw + ox} ${oy}`);
		if (tipR > 0) {
			d.push(`L ${ac - tipR * daw + ox} ${-ah + tipR * dah + oy}`);
			d.push(`Q ${ac + ox} ${-ah + oy} ${ac + tipR * daw + ox} ${-ah + tipR * dah + oy}`);
		} else d.push(`L ${ac + ox} ${-ah + oy}`);
		d.push(`L ${ac + aw + ox} ${oy}`);
	}
	d.push(`L ${width - r + ox} ${oy}`);
	d.push(`A ${r} ${r} 0 0 1 ${width + ox} ${r + oy}`);
	if (arrowSide === "right") {
		d.push(`L ${width + ox} ${ac - aw + oy}`);
		if (tipR > 0) {
			d.push(`L ${width + ah - tipR * dah + ox} ${ac - tipR * daw + oy}`);
			d.push(`Q ${width + ah + ox} ${ac + oy} ${width + ah - tipR * dah + ox} ${ac + tipR * daw + oy}`);
		} else d.push(`L ${width + ah + ox} ${ac + oy}`);
		d.push(`L ${width + ox} ${ac + aw + oy}`);
	}
	d.push(`L ${width + ox} ${height - r + oy}`);
	d.push(`A ${r} ${r} 0 0 1 ${width - r + ox} ${height + oy}`);
	if (arrowSide === "bottom") {
		d.push(`L ${ac + aw + ox} ${height + oy}`);
		if (tipR > 0) {
			d.push(`L ${ac + tipR * daw + ox} ${height + ah - tipR * dah + oy}`);
			d.push(`Q ${ac + ox} ${height + ah + oy} ${ac - tipR * daw + ox} ${height + ah - tipR * dah + oy}`);
		} else d.push(`L ${ac + ox} ${height + ah + oy}`);
		d.push(`L ${ac - aw + ox} ${height + oy}`);
	}
	d.push(`L ${r + ox} ${height + oy}`);
	d.push(`A ${r} ${r} 0 0 1 ${ox} ${height - r + oy}`);
	if (arrowSide === "left") {
		d.push(`L ${ox} ${ac + aw + oy}`);
		if (tipR > 0) {
			d.push(`L ${-ah + tipR * dah + ox} ${ac + tipR * daw + oy}`);
			d.push(`Q ${-ah + ox} ${ac + oy} ${-ah + tipR * dah + ox} ${ac - tipR * daw + oy}`);
		} else d.push(`L ${-ah + ox} ${ac + oy}`);
		d.push(`L ${ox} ${ac - aw + oy}`);
	}
	d.push(`L ${ox} ${r + oy}`);
	d.push(`A ${r} ${r} 0 0 1 ${r + ox} ${oy}`);
	d.push("Z");
	return d.join(" ");
}
/**
* Computes the pixel offset the tooltip must shift so that the SVG arrow
* (after clamping) visually aligns with the Ariakit arrow's actual position.
*
* When the desired `arrowCenter` falls inside the safe zone the delta is 0.
* When it falls outside (e.g. a tiny trigger near a rounded corner), the
* returned delta tells the caller how far to translate the tooltip element
* so the clamped arrow ends up over the trigger center.
*/
function getArrowClampDelta({ width, height, placement, borderRadius, arrowCenter, arrowWidth }) {
	const aw = arrowWidth / 2;
	const side = getArrowSide(placement);
	const arrowEdge = side === "top" || side === "bottom" ? width : height;
	const maxRadius = Math.min((side === "top" || side === "bottom" ? height : width) / 2, (arrowEdge - arrowWidth) / 2);
	const minAc = Math.max(0, Math.min(borderRadius, maxRadius)) + aw;
	const maxAc = arrowEdge - minAc;
	let delta = 0;
	if (arrowCenter < minAc) delta = arrowCenter - minAc;
	else if (arrowCenter > maxAc) delta = arrowCenter - maxAc;
	if (side === "top" || side === "bottom") return {
		x: delta,
		y: 0
	};
	return {
		x: 0,
		y: delta
	};
}
//#endregion
exports.generateSvgFloatingContentPath = generateSvgFloatingContentPath;
exports.getArrowClampDelta = getArrowClampDelta;
exports.getArrowSide = getArrowSide;
