All files / src/lib subtitle-delay.ts

100% Statements 16/16
100% Branches 12/12
100% Functions 2/2
100% Lines 10/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24              2x 23x 22x 20x 18x           2x 13x 12x 11x 10x    
// SPDX-License-Identifier: GPL-3.0-only
// Copyright (C) 2026 Max Boksem. See NOTICE for additional terms under GPLv3 section 7.
 
/**
 * Returns the delay step size (seconds) based on how long the button has been held.
 * elapsed is in milliseconds.
 */
export const getDelayStep = (elapsed: number): number => {
	if (elapsed >= 3000) return 5.0;
	if (elapsed >= 1500) return 1.0;
	if (elapsed >= 600) return 0.5;
	return 0.1;
};
 
/**
 * Returns the repeat interval (ms) for the hold-to-accelerate timer.
 */
export const getDelayInterval = (elapsed: number): number => {
	if (elapsed >= 3000) return 50;
	if (elapsed >= 1500) return 80;
	if (elapsed >= 600) return 120;
	return 200;
};