Squash merge audio-player-component into main

This commit is contained in:
2026-02-13 20:39:23 -06:00
parent 9b7cfd5bd1
commit d78c0584e2
122 changed files with 11750 additions and 1175 deletions
@@ -0,0 +1,113 @@
import type { ReactiveController, ReactiveControllerHost } from 'lit';
import type { QueueState, QueueTrack, RepeatMode } from '../queue-store';
import { queueStore } from '../queue-store';
/**
* QueueController connects a Lit component to the QueueStore.
*
* Usage in a component:
*
* private queue = new QueueController(this);
*
* render() {
* return html`
* <span>Tracks: ${this.queue.tracks.length}</span>
* <button @click=${() => this.queue.next()}>Next</button>
* `;
* }
*/
export class QueueController implements ReactiveController {
private host: ReactiveControllerHost;
private unsubscribe?: () => void;
constructor(host: ReactiveControllerHost) {
this.host = host;
host.addController(this);
}
// ===================================================================
// LIFECYCLE HOOKS
// ===================================================================
hostConnected(): void {
this.unsubscribe = queueStore.subscribe(() => {
this.host.requestUpdate();
});
}
hostDisconnected(): void {
this.unsubscribe?.();
}
// ===================================================================
// STATE ACCESSORS
// ===================================================================
get state(): Readonly<QueueState> {
return queueStore.getState();
}
get tracks(): QueueTrack[] {
return this.state.tracks;
}
get currentIndex(): number {
return this.state.currentIndex;
}
get currentTrack(): QueueTrack | undefined {
return this.state.tracks[this.state.currentIndex];
}
get shuffleMode(): boolean {
return this.state.shuffleMode;
}
get repeatMode(): RepeatMode {
return this.state.repeatMode;
}
// ===================================================================
// ACTIONS
// ===================================================================
next(): void {
queueStore.next();
}
previous(): void {
queueStore.previous();
}
setQueue(filePaths: string[], startIndex: number): void {
queueStore.setQueue(filePaths, startIndex);
}
addToQueue(filePath: string): void {
queueStore.addToQueue(filePath);
}
playNext(filePath: string): void {
queueStore.playNext(filePath);
}
removeFromQueue(position: number): void {
queueStore.removeFromQueue(position);
}
addTracksToQueue(filePaths: string[]): void {
queueStore.addTracksToQueue(filePaths);
}
playTracksNext(filePaths: string[]): void {
queueStore.playTracksNext(filePaths);
}
toggleShuffle(): void {
queueStore.toggleShuffle();
}
cycleRepeat(): void {
queueStore.cycleRepeat();
}
}