Skip to main content

max / makenotwork

677 B · 16 lines History Blame Raw
1 // Pure logic for a region showing one child at a time (no DOM), imported by
2 // `showing.ts`, the carousel island and its own test.
3 //
4 // It was `islands/carousel.logic.ts` until the library tab strip needed the same
5 // arithmetic (`6b24f2df`). Moved rather than imported across, because core
6 // reaching up into islands is the layering backwards.
7
8 /**
9 * Wrap `next` into `[0, len)`. Negative values wrap from the end (advancing
10 * "previous" past the first child lands on the last), matching the original
11 * `(next + len) % len` but correct for any negative magnitude.
12 */
13 export function wrapIndex(next: number, len: number): number {
14 return ((next % len) + len) % len;
15 }
16