export type CountdownState = "idle" | "running" | "paused" | "stopped"; /** Live snapshot of countdown progress — passed to `onTick` and `snapshot()`. */ export interface CountdownSnapshot { /** Milliseconds remaining. */ readonly remaining: number; /** Milliseconds elapsed since the current run began. */ readonly elapsed: number; /** Completion ratio from 0 (not started) to 1 (finished). */ readonly progress: number; readonly state: CountdownState; } export interface CountdownOptions { /** * Called periodically while running. Not invoked while paused. * Defaults to a 50 ms interval when set. */ onTick?: (snapshot: CountdownSnapshot) => void; /** Ms between `onTick` calls. Defaults to 50 when `onTick` is set. */ tickInterval?: number; } export interface Countdown { /** * Begin counting down from the full duration. * Only valid from `idle` or `stopped` (after `stop()`). No-op while `running`. * While `paused`, use `resume()` instead — `start()` is a no-op. */ start(): void; /** * Reset to the full duration and begin counting down immediately. * Cancels any in-progress countdown (running or paused). */ restart(): void; /** * Pause the timer. The remaining time is frozen at the current value. * No-op if already paused, idle, or stopped. */ pause(): void; /** * Resume a paused timer. Restarts a `setTimeout` for the remaining duration. * No-op if already running, idle, or stopped. */ resume(): void; /** * Stop and reset the timer. The callback will never fire. * Remaining time is reset to the full duration. * Calling `start()` after `stop()` begins a fresh countdown. */ stop(): void; /** Alias for `stop()`. */ dispose(): void; /** Current state of the timer. */ readonly state: CountdownState; /** * Milliseconds remaining. * - While `running`: live value computed from wall-clock elapsed. * - While `paused` / `idle` / `stopped`: last frozen snapshot. */ readonly remaining: number; /** Milliseconds elapsed in the current run (0 after `stop()` or before `start()`). */ readonly elapsed: number; /** Completion ratio from 0 to 1. */ readonly progress: number; /** Full progress snapshot for observers and tick callbacks. */ snapshot(): CountdownSnapshot; } /** Inert countdown for SSR — all methods are no-ops. */ export declare function noopCountdown(duration?: number): Countdown; /** * `countdown` — precise pausable countdown timer. * * @param callback Called once when the full duration has elapsed. * @param duration Total countdown duration in milliseconds. * @param options Optional tick callback and tick interval. * * @example * const t = countdown(() => dismiss(id), 6000); * t.start(); * * @example * // Progress bar driven by onTick * countdown(onDone, 6000, { * onTick: ({ progress }) => { bar.style.width = `${progress * 100}%`; }, * }).start(); */ export declare function countdown(callback: () => void, duration: number, options?: CountdownOptions): Countdown; //# sourceMappingURL=countdown.d.ts.map