Files
Resonant/src/lib/playback.ts
T
cyph3rasi a4b66954bd Make shuffle reorder and restore the play queue, add off/all/one repeat playback, and remove Resonant Radio UI.
Hop-State: A_06FNNZKG8MKNEJA6QXQ1ZER
Hop-Proposal: R_06FNNZJMKS1Z9RBS9ADD3ER
Hop-Task: T_06FNNXTJEGA5TEAZ2GA55X0
Hop-Attempt: AT_06FNNXTJEHPH9SQPGKC0P9G
2026-07-13 03:20:52 -07:00

19 lines
566 B
TypeScript

export type RepeatMode = "off" | "all" | "one";
export function nextRepeatMode(mode: RepeatMode): RepeatMode {
if (mode === "off") return "all";
if (mode === "all") return "one";
return "off";
}
export function shuffleTracks<T>(items: readonly T[], random: () => number = Math.random): T[] {
const shuffled = [...items];
for (let index = shuffled.length - 1; index > 0; index -= 1) {
const swapIndex = Math.floor(random() * (index + 1));
[shuffled[index], shuffled[swapIndex]] = [shuffled[swapIndex], shuffled[index]];
}
return shuffled;
}