/** * Clamps `val` into the inclusive range `[min, max]`. Defaults match the * React source: `Number.MIN_SAFE_INTEGER` / `Number.MAX_SAFE_INTEGER`, which * make the function a no-op when a bound is omitted. */ export function clamp( val: number, min: number = Number.MIN_SAFE_INTEGER, max: number = Number.MAX_SAFE_INTEGER, ): number { return Math.max(min, Math.min(val, max)); }