Skip to main content

max / makenotwork

408 B · 11 lines History Blame Raw
1 // Pure carousel logic (no DOM) — imported by both the element and its test.
2
3 /**
4 * Wrap `next` into `[0, len)`. Negative values wrap from the end (advancing
5 * "previous" past the first frame lands on the last), matching the original
6 * `(next + len) % len` but correct for any negative magnitude.
7 */
8 export function wrapIndex(next: number, len: number): number {
9 return ((next % len) + len) % len;
10 }
11