/** * Next highlighted menu index: skips unselectable entries and wraps. From -1 * (nothing highlighted yet), down lands on the first selectable entry and up * on the LAST — stepping up from -1 directly would land one short of it. * Returns `from` unchanged when nothing is selectable. */ export function stepIndex(selectable: boolean[], from: number, delta: 1 | -1): number { const count = selectable.length; let index = from < 0 && delta < 0 ? 0 : from; for (let hops = 0; hops < count; hops++) { index = (index + delta + count) % count; if (selectable[index]) return index; } return from; }