finally synced

This commit is contained in:
2026-02-06 04:09:58 -08:00
parent 291b8d5d21
commit 2839417ee9
2 changed files with 238 additions and 231 deletions

View File

@@ -34,6 +34,7 @@
type PlayerSnapshot, type PlayerSnapshot,
} from "$lib/player/player.svelte"; } from "$lib/player/player.svelte";
import { createMediaSessionBindings } from "$lib/player/media-session"; import { createMediaSessionBindings } from "$lib/player/media-session";
import Portal from "$lib/components/util/Portal.svelte";
import { import {
ChevronsUpDown, ChevronsUpDown,
@@ -453,247 +454,253 @@
{/if} {/if}
</svelte:head> </svelte:head>
<!-- Mobile UI is allowed to render as an overlay even if this component is mounted <!-- Mobile UI is portaled to document.body so the GlobalPlayer can be mounted
inside the desktop sidebar column. We hide it on lg+ via CSS, not by unmounting. --> in the desktop sidebar column while still showing the mobile overlay.
<div Hidden on lg+ via CSS. -->
class="lg:hidden fixed bottom-0 left-0 right-0 z-50 border-t bg-background/95 backdrop-blur shadow-2xl" <Portal>
> <div
<div class="mx-auto flex max-w-4xl items-center gap-2 px-3 py-2"> class="lg:hidden fixed bottom-0 left-0 right-0 z-50 border-t bg-background/95 backdrop-blur shadow-2xl"
<button >
class="inline-flex h-8 w-8 items-center justify-center rounded border" <div class="mx-auto flex max-w-4xl items-center gap-2 px-3 py-2">
type="button" <button
onclick={() => toggleUiOpen()} class="inline-flex h-8 w-8 items-center justify-center rounded border"
aria-label={snap.uiOpen ? "Close player" : "Open player"} type="button"
title={snap.uiOpen ? "Close player" : "Open player"} onclick={() => toggleUiOpen()}
> aria-label={snap.uiOpen ? "Close player" : "Open player"}
{#if snap.uiOpen} title={snap.uiOpen ? "Close player" : "Open player"}
<X class="h-4 w-4" /> >
{:else} {#if snap.uiOpen}
<ChevronsUpDown class="h-4 w-4" /> <X class="h-4 w-4" />
{/if} {:else}
</button> <ChevronsUpDown class="h-4 w-4" />
{/if}
</button>
<div <div
class="min-w-0 flex-1" class="min-w-0 flex-1"
role="button" role="button"
tabindex="0" tabindex="0"
aria-label={snap.uiOpen ? "Close player" : "Open player"} aria-label={snap.uiOpen ? "Close player" : "Open player"}
onclick={(e) => { onclick={(e) => {
const t = e.target as HTMLElement | null; const t = e.target as HTMLElement | null;
// Only toggle when tapping the track info area. Avoid toggling from // Only toggle when tapping the track info area. Avoid toggling from
// the button zones (above/below/side) by not attaching handlers to the // the button zones (above/below/side) by not attaching handlers to the
// whole bar. // whole bar.
if (t?.closest("button,input,label,a")) return; if (t?.closest("button,input,label,a")) return;
toggleUiOpen(); toggleUiOpen();
}} }}
onkeydown={(e) => { onkeydown={(e) => {
if (e.key !== "Enter" && e.key !== " ") return; if (e.key !== "Enter" && e.key !== " ") return;
const t = e.target as HTMLElement | null; const t = e.target as HTMLElement | null;
if (t?.closest("button,input,label,a")) return; if (t?.closest("button,input,label,a")) return;
e.preventDefault(); e.preventDefault();
toggleUiOpen(); toggleUiOpen();
}} }}
> >
{#if snap.currentTrack} {#if snap.currentTrack}
<div class="flex flex-wrap items-baseline gap-x-2 gap-y-1"> <div class="flex flex-wrap items-baseline gap-x-2 gap-y-1">
{#if typeNumberLabel(snap.currentTrack)} {#if typeNumberLabel(snap.currentTrack)}
<span <span
class="rounded bg-muted px-2 py-0.5 text-sm text-muted-foreground" class="rounded bg-muted px-2 py-0.5 text-sm text-muted-foreground"
>
{typeNumberLabel(snap.currentTrack)}
</span>
{/if}
<span class="truncate">
{(
snap.currentTrack.animeName ??
snap.currentTrack.album ??
""
).trim()}
</span>
</div>
<div class="mt-1 text-foreground/80">
{(snap.currentTrack.title ?? "").trim() || "Unknown title"}
<span class="text-sm text-muted-foreground">
{(snap.currentTrack.artist ?? "").trim() || "Unknown Artist"}
</span>
</div>
{:else}
<div class="truncate text-sm font-medium">{nowPlayingLabel()}</div>
{/if}
<div class="text-xs text-muted-foreground">
{formatTime(currentTime)} / {formatTime(duration)}
</div>
<label class="mt-2 block">
<span class="sr-only">Seek</span>
<input
class="w-full"
type="range"
min="0"
max={Math.max(0, duration)}
step="0.1"
bind:value={currentTime}
disabled={!snap.currentTrack || duration <= 0}
/>
</label>
</div>
<button
class="inline-flex h-8 w-8 items-center justify-center rounded border"
type="button"
disabled={!canPrev}
aria-label="Previous"
title="Previous"
onclick={() => {
prev(currentTime);
void syncAndAutoplay();
}}
>
<SkipBack class="h-4 w-4" />
</button>
<button
class="inline-flex h-8 w-8 items-center justify-center rounded border"
type="button"
aria-label={isPlaying ? "Pause" : "Play"}
title={isPlaying ? "Pause" : "Play"}
onclick={() => {
if (!audioEl) return;
if (audioEl.paused) void audioEl.play();
else audioEl.pause();
}}
disabled={!snap.currentTrack}
>
{#if isPlaying}
<PauseIcon class="h-4 w-4" />
{:else}
<PlayIcon class="h-4 w-4" />
{/if}
</button>
<button
class="inline-flex h-8 w-8 items-center justify-center rounded border"
type="button"
disabled={!canNext}
aria-label="Next"
title="Next"
onclick={() => {
next();
void syncAndAutoplay();
}}
>
<SkipForward class="h-4 w-4" />
</button>
</div>
{#if snap.uiOpen}
<div class="max-h-[65dvh] overflow-y-auto border-t px-3 py-3">
<div class="mx-auto max-w-4xl space-y-3">
<div class="flex flex-wrap items-center gap-2">
<button
class="inline-flex h-8 w-8 items-center justify-center rounded border"
type="button"
onclick={() => toggleShuffle()}
aria-label={snap.shuffleEnabled ? "Shuffle on" : "Shuffle off"}
title={snap.shuffleEnabled ? "Shuffle on" : "Shuffle off"}
> >
{typeNumberLabel(snap.currentTrack)} <Shuffle class="h-4 w-4" />
</span> </button>
{/if} <button
<span class="truncate"> class="inline-flex h-8 w-8 items-center justify-center rounded border"
{( type="button"
snap.currentTrack.animeName ?? onclick={() => toggleWrap()}
snap.currentTrack.album ?? aria-label={snap.wrapEnabled ? "Wrap on" : "Wrap off"}
"" title={snap.wrapEnabled ? "Wrap on" : "Wrap off"}
).trim()} >
</span> <Repeat class="h-4 w-4" />
</div> </button>
<div class="mt-1 text-foreground/80"> <label class="ml-auto flex items-center gap-2 text-sm">
{(snap.currentTrack.title ?? "").trim() || "Unknown title"} <span class="text-muted-foreground" aria-hidden="true">
<span class="text-sm text-muted-foreground"> <Volume2 class="h-4 w-4" />
{(snap.currentTrack.artist ?? "").trim() || "Unknown Artist"} </span>
</span> <span class="sr-only">Volume</span>
</div> <input
{:else} type="range"
<div class="truncate text-sm font-medium">{nowPlayingLabel()}</div> min="0"
{/if} max="1"
step="0.01"
value={snap.volume}
oninput={(e) =>
setVolume(
Number((e.currentTarget as HTMLInputElement).value),
)}
/>
</label>
</div>
<div class="text-xs text-muted-foreground"> <div class="space-y-1">
{formatTime(currentTime)} / {formatTime(duration)} <div class="text-sm font-semibold">Queue ({snap.queue.length})</div>
</div>
<label class="mt-2 block"> {#if snap.queue.length === 0}
<span class="sr-only">Seek</span> <p class="text-sm text-muted-foreground">Queue is empty.</p>
<input {:else}
class="w-full" <ul class="overflow-auto rounded border">
type="range" {#each queueDisplay as item (item.track.id)}
min="0" <li
max={Math.max(0, duration)} class="flex items-center gap-2 border-b px-2 py-2 last:border-b-0"
step="0.1"
bind:value={currentTime}
disabled={!snap.currentTrack || duration <= 0}
/>
</label>
</div>
<button
class="inline-flex h-8 w-8 items-center justify-center rounded border"
type="button"
disabled={!canPrev}
aria-label="Previous"
title="Previous"
onclick={() => {
prev(currentTime);
void syncAndAutoplay();
}}
>
<SkipBack class="h-4 w-4" />
</button>
<button
class="inline-flex h-8 w-8 items-center justify-center rounded border"
type="button"
aria-label={isPlaying ? "Pause" : "Play"}
title={isPlaying ? "Pause" : "Play"}
onclick={() => {
if (!audioEl) return;
if (audioEl.paused) void audioEl.play();
else audioEl.pause();
}}
disabled={!snap.currentTrack}
>
{#if isPlaying}
<PauseIcon class="h-4 w-4" />
{:else}
<PlayIcon class="h-4 w-4" />
{/if}
</button>
<button
class="inline-flex h-8 w-8 items-center justify-center rounded border"
type="button"
disabled={!canNext}
aria-label="Next"
title="Next"
onclick={() => {
next();
void syncAndAutoplay();
}}
>
<SkipForward class="h-4 w-4" />
</button>
</div>
{#if snap.uiOpen}
<div class="max-h-[65dvh] overflow-y-auto border-t px-3 py-3">
<div class="mx-auto max-w-4xl space-y-3">
<div class="flex flex-wrap items-center gap-2">
<button
class="inline-flex h-8 w-8 items-center justify-center rounded border"
type="button"
onclick={() => toggleShuffle()}
aria-label={snap.shuffleEnabled ? "Shuffle on" : "Shuffle off"}
title={snap.shuffleEnabled ? "Shuffle on" : "Shuffle off"}
>
<Shuffle class="h-4 w-4" />
</button>
<button
class="inline-flex h-8 w-8 items-center justify-center rounded border"
type="button"
onclick={() => toggleWrap()}
aria-label={snap.wrapEnabled ? "Wrap on" : "Wrap off"}
title={snap.wrapEnabled ? "Wrap on" : "Wrap off"}
>
<Repeat class="h-4 w-4" />
</button>
<label class="ml-auto flex items-center gap-2 text-sm">
<span class="text-muted-foreground" aria-hidden="true">
<Volume2 class="h-4 w-4" />
</span>
<span class="sr-only">Volume</span>
<input
type="range"
min="0"
max="1"
step="0.01"
value={snap.volume}
oninput={(e) =>
setVolume(Number((e.currentTarget as HTMLInputElement).value))}
/>
</label>
</div>
<div class="space-y-1">
<div class="text-sm font-semibold">Queue ({snap.queue.length})</div>
{#if snap.queue.length === 0}
<p class="text-sm text-muted-foreground">Queue is empty.</p>
{:else}
<ul class="overflow-auto rounded border">
{#each queueDisplay as item (item.track.id)}
<li
class="flex items-center gap-2 border-b px-2 py-2 last:border-b-0"
>
<button
class="min-w-0 flex-1 truncate text-left text-sm hover:underline"
type="button"
onclick={() => {
jumpToTrack(item.track.id);
void syncAndAutoplay();
}}
> >
{#if item.isCurrent} <button
<span class="text-muted-foreground"></span> class="min-w-0 flex-1 truncate text-left text-sm hover:underline"
{/if} type="button"
<div class="min-w-0 flex-1"> onclick={() => {
<div jumpToTrack(item.track.id);
class="flex flex-wrap items-baseline gap-x-2 gap-y-1" void syncAndAutoplay();
> }}
{#if typeNumberLabel(item.track)} >
<span {#if item.isCurrent}
class="rounded bg-muted px-2 py-0.5 text-sm text-muted-foreground" <span class="text-muted-foreground"></span>
> {/if}
{typeNumberLabel(item.track)} <div class="min-w-0 flex-1">
</span> <div
{/if} class="flex flex-wrap items-baseline gap-x-2 gap-y-1"
<span class="truncate text-sm"
>{animeLabel(item.track)}</span
> >
</div> {#if typeNumberLabel(item.track)}
<span
class="rounded bg-muted px-2 py-0.5 text-sm text-muted-foreground"
>
{typeNumberLabel(item.track)}
</span>
{/if}
<span class="truncate text-sm"
>{animeLabel(item.track)}</span
>
</div>
<div class="mt-1 text-foreground/80"> <div class="mt-1 text-foreground/80">
{(item.track.title ?? "").trim() || "Unknown title"} {(item.track.title ?? "").trim() || "Unknown title"}
<span class="text-sm text-muted-foreground"> <span class="text-sm text-muted-foreground">
{(item.track.artist ?? "").trim() || {(item.track.artist ?? "").trim() ||
"Unknown Artist"} "Unknown Artist"}
</span> </span>
</div>
</div> </div>
</div> </button>
</button>
<button <button
class="inline-flex h-8 w-8 items-center justify-center rounded border" class="inline-flex h-8 w-8 items-center justify-center rounded border"
type="button" type="button"
onclick={() => removeTrack(item.track.id)} onclick={() => removeTrack(item.track.id)}
aria-label="Remove from queue" aria-label="Remove from queue"
title="Remove from queue" title="Remove from queue"
> >
<ListX class="h-4 w-4" /> <ListX class="h-4 w-4" />
</button> </button>
</li> </li>
{/each} {/each}
</ul> </ul>
{/if} {/if}
</div>
</div> </div>
</div> </div>
</div> {/if}
{/if} </div>
</div> </Portal>
<!-- Desktop UI stays in-flow in the right grid column. Hide on small screens via CSS. --> <!-- Desktop UI stays in-flow in the right grid column. Hide on small screens via CSS. -->
<aside <aside
class="hidden lg:flex sticky top-4 h-[calc(100dvh-2rem)] overflow-hidden bg-background flex-col" class="hidden lg:flex sticky top-4 h-[calc(100dvh-2rem)] overflow-hidden bg-background flex-col"

View File

@@ -31,5 +31,5 @@
</aside> </aside>
</div> </div>
<!-- Mobile player is rendered by the same GlobalPlayer instance above. <!-- Mobile player UI is rendered via a portal from the single GlobalPlayer instance
On small screens, it uses fixed positioning internally so it can overlay. --> mounted in the desktop sidebar column above. -->