// Direction is the next tab (+1) or previous tab (-1). Vertical scrolling wins // unless a gesture has a clear horizontal intent; small jitter never navigates. export function swipeStep(dx, dy, elapsed, width) { if (Math.abs(dx) < Math.abs(dy) * 1.4) return 0; const distance = Math.abs(dx); const deliberate = distance >= Math.min(90, Math.max(55, width * 0.18)); const flick = distance >= 36 && distance / Math.max(1, elapsed) >= 0.5; return deliberate || flick ? (dx < 0 ? 1 : -1) : 0; } // The settle curve's initial slope (y1 / x1 of the cubic-bezier) lets a // released swipe continue at the finger's speed instead of braking or lurching. export const SETTLE_EASING = "cubic-bezier(0.25, 0.8, 0.25, 1)"; const SETTLE_SLOPE = 0.8 / 0.25; // Distance and velocity share a sign convention: px, and px/ms toward "to". export function settleDuration(distance, width, velocity = 0) { const remaining = Math.abs(distance); const base = Math.min(340, Math.max(220, (remaining / Math.max(1, width)) * 340)); // Only a release moving toward the destination carries its momentum. if (!velocity || Math.sign(velocity) !== Math.sign(distance)) return base; return Math.min(base, Math.max(160, (SETTLE_SLOPE * remaining) / Math.abs(velocity))); }