export const clamp = (value: number, min = 0, max = 1) => Math.max(min, Math.min(max, value)); export const between = (min: number, max: number) => min + Math.random() * (max - min); export const ease = (elapsed: number, duration: number) => 1 - Math.exp(-elapsed / duration); export function fitSize(width: number, height: number, edge: number, upscale = false) { const ratio = edge / Math.max(width, height); const scale = upscale ? ratio : Math.min(1, ratio); return { width: Math.max(1, Math.round(width * scale)), height: Math.max(1, Math.round(height * scale)), }; }