Refactor App into TS modules; add tsc typecheck
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
// Spritz ORP algorithm - position where the eye naturally fixates.
|
||||
// Based on Optimal Viewing Position research (20-35% from left).
|
||||
export function getORPIndex(wordLength: number): number {
|
||||
if (wordLength <= 0) return 0;
|
||||
if (wordLength === 1) return 0; // 1 char: 1st letter
|
||||
if (wordLength <= 5) return 1; // 2-5 chars: 2nd letter
|
||||
if (wordLength <= 9) return 2; // 6-9 chars: 3rd letter
|
||||
if (wordLength <= 13) return 3; // 10-13 chars: 4th letter
|
||||
return 4; // 14+ chars: 5th letter
|
||||
}
|
||||
|
||||
export function getWordDelay(word: string, baseDelayMs: number): number {
|
||||
let multiplier = 1;
|
||||
multiplier += Math.sqrt(word.length) * 0.04;
|
||||
if (/[.!?]$/.test(word)) {
|
||||
multiplier = 2.5;
|
||||
} else if (/[,;:]$/.test(word)) {
|
||||
multiplier = 1.8;
|
||||
}
|
||||
return baseDelayMs * multiplier;
|
||||
}
|
||||
|
||||
export function formatReadingTime(minutes: number): string {
|
||||
if (minutes < 1) return "< 1 min";
|
||||
if (minutes < 60) return `${Math.round(minutes)} min`;
|
||||
const hours = Math.floor(minutes / 60);
|
||||
const mins = Math.round(minutes % 60);
|
||||
if (mins === 0) return `${hours}h`;
|
||||
return `${hours}h ${mins}m`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user