//#region src/elements/easingUtils.ts
/**
* Evaluates a CSS easing function at a given progress (0-1)
* Supports standard CSS easing functions and cubic-bezier
*/
function evaluateEasing(easing, progress) {
	progress = Math.max(0, Math.min(1, progress));
	switch (easing.trim().toLowerCase()) {
		case "linear": return progress;
		case "ease": return cubicBezier(.25, .1, .25, 1, progress);
		case "ease-in": return cubicBezier(.42, 0, 1, 1, progress);
		case "ease-out": return cubicBezier(0, 0, .58, 1, progress);
		case "ease-in-out": return cubicBezier(.42, 0, .58, 1, progress);
		default: {
			const cubicBezierMatch = easing.match(/cubic-bezier\s*\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)\s*\)/i);
			if (cubicBezierMatch?.[1] && cubicBezierMatch[2] && cubicBezierMatch[3] && cubicBezierMatch[4]) return cubicBezier(Number.parseFloat(cubicBezierMatch[1]), Number.parseFloat(cubicBezierMatch[2]), Number.parseFloat(cubicBezierMatch[3]), Number.parseFloat(cubicBezierMatch[4]), progress);
			return progress;
		}
	}
}
/**
* Evaluates a cubic-bezier curve at a given progress (0-1)
* Uses binary search to find the t value that corresponds to the given x
*/
function cubicBezier(x1, y1, x2, y2, x) {
	x = Math.max(0, Math.min(1, x));
	if (x === 0) return 0;
	if (x === 1) return 1;
	let t = .5;
	let minT = 0;
	let maxT = 1;
	for (let i = 0; i < 20; i++) {
		const diff = bezierX(t, x1, x2) - x;
		if (Math.abs(diff) < 1e-4) break;
		if (diff > 0) maxT = t;
		else minT = t;
		t = (minT + maxT) / 2;
	}
	return bezierY(t, y1, y2);
}
/**
* Calculates the x coordinate of a cubic bezier curve at parameter t
*/
function bezierX(t, x1, x2) {
	const t2 = t * t;
	const t3 = t2 * t;
	const mt = 1 - t;
	return 3 * (mt * mt) * t * x1 + 3 * mt * t2 * x2 + t3;
}
/**
* Calculates the y coordinate of a cubic bezier curve at parameter t
*/
function bezierY(t, y1, y2) {
	const t2 = t * t;
	const t3 = t2 * t;
	const mt = 1 - t;
	return 3 * (mt * mt) * t * y1 + 3 * mt * t2 * y2 + t3;
}

//#endregion
export { evaluateEasing };
//# sourceMappingURL=easingUtils.js.map