// Auto-rotation timer for the home-screen hero banner. // // Extracted from HeroBanner.svelte so it can be unit-tested: a manual swipe or // dot/arrow click must restart the countdown from that moment. The old code // installed one bare setInterval and left it running, so swiping late in an // interval made the banner jump to the next item almost immediately. // // TRACES: UR-034 | DR-038 | UT-207 export interface RotationTimer { /** (Re)start the countdown from now, replacing any pending tick. */ restart(): void; /** Cancel the countdown. */ stop(): void; isRunning(): boolean; } /** * Create a repeating timer that calls `onElapse` every `interval` ms once * started. Restarting is idempotent — there is never more than one live timer. */ export function createRotationTimer(interval: number, onElapse: () => void): RotationTimer { let handle: ReturnType | null = null; function stop() { if (handle !== null) { clearInterval(handle); handle = null; } } return { restart() { stop(); handle = setInterval(onElapse, interval); }, stop, isRunning: () => handle !== null, }; }