fix: improve lyrics display with theme colors and karaoke effect
- Use theme CSS variables instead of hardcoded Cider colors - Add distance-based opacity fading for non-active lines - Fix scroll to center active line with proper reactivity - Add spacers to allow first/last lines to scroll to center - Add karaoke progress gradient on active line - Prefetch lyrics on track start instead of button click - Remove provider badge (will add to About modal later) - Add loading spinner animation
This commit is contained in:
1 parent
80ff8afa3a
commit
78522b99ac
6 files changed
+194
-137
No files matched your search
@@ -13,7 +13,6 @@
|
||||
title?: string;
|
||||
artist?: string;
|
||||
artwork?: string;
|
||||
backgroundUrl?: string;
|
||||
}
|
||||
|
||||
let {
|
||||
@@ -23,22 +22,17 @@
|
||||
align = 'center',
|
||||
title = '',
|
||||
artist = '',
|
||||
artwork,
|
||||
backgroundUrl
|
||||
artwork
|
||||
}: Props = $props();
|
||||
|
||||
const isCenter = $derived(align === 'center');
|
||||
const hasArtwork = $derived(!!artwork);
|
||||
const backgroundStyle = $derived(
|
||||
backgroundUrl ? `--lyrics-artwork-bg: url('${backgroundUrl}')` : undefined
|
||||
);
|
||||
</script>
|
||||
|
||||
<section
|
||||
class="lyrics-immersive"
|
||||
class:center={isCenter}
|
||||
class:no-artwork={!hasArtwork}
|
||||
style={backgroundStyle}
|
||||
>
|
||||
{#if hasArtwork}
|
||||
<div class="artwork-pane">
|
||||
@@ -75,18 +69,7 @@
|
||||
width: 100%;
|
||||
padding: 48px;
|
||||
color: var(--text-primary);
|
||||
background-image:
|
||||
radial-gradient(circle at top right, rgba(148, 92, 48, 0.35), transparent 55%),
|
||||
linear-gradient(120deg, rgba(12, 10, 9, 0.92), rgba(44, 30, 20, 0.9)),
|
||||
var(--lyrics-artwork-bg, none);
|
||||
background-size: cover;
|
||||
background-position: center;
|
||||
--lyrics-font-size: 20px;
|
||||
--lyrics-active-size: 28px;
|
||||
--lyrics-line-gap: 18px;
|
||||
--lyrics-line-height: 1.5;
|
||||
--lyrics-dimmed-opacity: 0.38;
|
||||
--lyrics-highlight-muted: rgba(255, 255, 255, 0.2);
|
||||
background: var(--bg-primary);
|
||||
}
|
||||
|
||||
.lyrics-immersive.no-artwork {
|
||||
@@ -106,10 +89,10 @@
|
||||
.artwork-frame {
|
||||
width: min(420px, 100%);
|
||||
aspect-ratio: 1 / 1;
|
||||
border-radius: 18px;
|
||||
border-radius: 12px;
|
||||
overflow: hidden;
|
||||
box-shadow: 0 28px 60px rgba(0, 0, 0, 0.55);
|
||||
border: 1px solid rgba(255, 255, 255, 0.08);
|
||||
box-shadow: 0 24px 48px rgba(0, 0, 0, 0.4);
|
||||
border: 1px solid var(--bg-tertiary);
|
||||
}
|
||||
|
||||
.artwork-frame img {
|
||||
@@ -129,9 +112,9 @@
|
||||
}
|
||||
|
||||
.title {
|
||||
font-size: 14px;
|
||||
font-size: 12px;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.16em;
|
||||
letter-spacing: 0.1em;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from 'svelte';
|
||||
import { tick } from 'svelte';
|
||||
|
||||
interface LyricsLine {
|
||||
text: string;
|
||||
@@ -26,22 +26,59 @@
|
||||
}: Props = $props();
|
||||
|
||||
let container: HTMLDivElement | null = null;
|
||||
let lastScrolledIndex = -1;
|
||||
|
||||
function scrollActiveIntoView() {
|
||||
if (!container || activeIndex < 0) return;
|
||||
const target = container.querySelector<HTMLElement>(`[data-line-index=\"${activeIndex}\"]`);
|
||||
if (!target) return;
|
||||
target.scrollIntoView({ block: 'center', behavior: 'smooth' });
|
||||
// Calculate opacity based on distance from active line
|
||||
function getLineOpacity(index: number, active: number): number {
|
||||
if (!dimInactive || active < 0) return 1;
|
||||
if (index === active) return 1;
|
||||
|
||||
const distance = Math.abs(index - active);
|
||||
// Fade out based on distance: 1 line away = 0.6, 2 = 0.4, 3+ = 0.25
|
||||
if (distance === 1) return 0.6;
|
||||
if (distance === 2) return 0.4;
|
||||
if (distance === 3) return 0.3;
|
||||
return 0.2;
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
if (scrollToActive) {
|
||||
scrollActiveIntoView();
|
||||
}
|
||||
});
|
||||
// Calculate blur based on distance (subtle effect)
|
||||
function getLineBlur(index: number, active: number): number {
|
||||
if (!dimInactive || active < 0) return 0;
|
||||
if (index === active) return 0;
|
||||
|
||||
const distance = Math.abs(index - active);
|
||||
if (distance <= 2) return 0;
|
||||
if (distance <= 4) return 0.5;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Scroll active line into view
|
||||
async function scrollActiveIntoView() {
|
||||
if (!container || activeIndex < 0 || activeIndex === lastScrolledIndex) return;
|
||||
|
||||
await tick(); // Wait for DOM update
|
||||
|
||||
const target = container.querySelector<HTMLElement>(`[data-line-index="${activeIndex}"]`);
|
||||
if (!target) return;
|
||||
|
||||
lastScrolledIndex = activeIndex;
|
||||
|
||||
// Calculate scroll position to center the active line
|
||||
const containerRect = container.getBoundingClientRect();
|
||||
const targetRect = target.getBoundingClientRect();
|
||||
const targetCenter = targetRect.top + targetRect.height / 2;
|
||||
const containerCenter = containerRect.top + containerRect.height / 2;
|
||||
const scrollOffset = targetCenter - containerCenter;
|
||||
|
||||
container.scrollBy({
|
||||
top: scrollOffset,
|
||||
behavior: 'smooth'
|
||||
});
|
||||
}
|
||||
|
||||
// React to activeIndex changes
|
||||
$effect(() => {
|
||||
if (scrollToActive) {
|
||||
if (scrollToActive && activeIndex >= 0) {
|
||||
scrollActiveIntoView();
|
||||
}
|
||||
});
|
||||
@@ -49,24 +86,38 @@
|
||||
|
||||
<div
|
||||
class="lyrics-lines"
|
||||
class:compact={compact}
|
||||
class:center={center}
|
||||
class:compact
|
||||
class:center
|
||||
bind:this={container}
|
||||
>
|
||||
{#if lines.length === 0}
|
||||
<div class="lyrics-empty">No lyrics available</div>
|
||||
{:else}
|
||||
<!-- Spacer at top to allow first lines to scroll to center -->
|
||||
<div class="lyrics-spacer"></div>
|
||||
|
||||
{#each lines as line, index}
|
||||
{@const isActive = index === activeIndex}
|
||||
{@const isPast = index < activeIndex}
|
||||
{@const opacity = getLineOpacity(index, activeIndex)}
|
||||
{@const blur = getLineBlur(index, activeIndex)}
|
||||
<div
|
||||
class="lyrics-line"
|
||||
class:active={index === activeIndex}
|
||||
class:dimmed={dimInactive && index !== activeIndex}
|
||||
style={index === activeIndex ? `--line-progress: ${Math.max(0, Math.min(1, activeProgress))}` : undefined}
|
||||
class:active={isActive}
|
||||
class:past={isPast}
|
||||
style="
|
||||
--line-opacity: {opacity};
|
||||
--line-blur: {blur}px;
|
||||
{isActive ? `--line-progress: ${Math.max(0, Math.min(1, activeProgress))}` : ''}
|
||||
"
|
||||
data-line-index={index}
|
||||
>
|
||||
<span class="line-text">{line.text}</span>
|
||||
</div>
|
||||
{/each}
|
||||
|
||||
<!-- Spacer at bottom to allow last lines to scroll to center -->
|
||||
<div class="lyrics-spacer"></div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
@@ -74,11 +125,31 @@
|
||||
.lyrics-lines {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--lyrics-line-gap, 16px);
|
||||
padding: 12px 16px 24px 16px;
|
||||
gap: var(--lyrics-line-gap, 20px);
|
||||
padding: 16px 20px;
|
||||
overflow-y: auto;
|
||||
height: 100%;
|
||||
scroll-behavior: smooth;
|
||||
scrollbar-width: thin;
|
||||
scrollbar-color: var(--bg-tertiary) transparent;
|
||||
}
|
||||
|
||||
.lyrics-lines::-webkit-scrollbar {
|
||||
width: 6px;
|
||||
}
|
||||
|
||||
.lyrics-lines::-webkit-scrollbar-track {
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.lyrics-lines::-webkit-scrollbar-thumb {
|
||||
background: var(--bg-tertiary);
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
.lyrics-spacer {
|
||||
min-height: 40vh;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.lyrics-lines.center {
|
||||
@@ -86,38 +157,49 @@
|
||||
}
|
||||
|
||||
.lyrics-lines.compact {
|
||||
gap: 10px;
|
||||
gap: 14px;
|
||||
}
|
||||
|
||||
.lyrics-line {
|
||||
color: var(--lyrics-color, var(--text-muted));
|
||||
font-family: var(--lyrics-font-family, var(--font-sans));
|
||||
font-size: var(--lyrics-font-size, 18px);
|
||||
line-height: var(--lyrics-line-height, 1.45);
|
||||
color: var(--text-secondary);
|
||||
font-family: var(--font-sans);
|
||||
font-size: 16px;
|
||||
line-height: 1.5;
|
||||
letter-spacing: 0.01em;
|
||||
transition: color 180ms ease, opacity 180ms ease, transform 180ms ease, filter 180ms ease;
|
||||
position: relative;
|
||||
opacity: var(--line-opacity, 1);
|
||||
filter: blur(var(--line-blur, 0));
|
||||
transition:
|
||||
opacity 300ms ease-out,
|
||||
filter 300ms ease-out,
|
||||
transform 300ms ease-out,
|
||||
font-size 200ms ease-out,
|
||||
color 200ms ease-out;
|
||||
transform-origin: left center;
|
||||
}
|
||||
|
||||
.lyrics-line.dimmed {
|
||||
opacity: var(--lyrics-dimmed-opacity, 0.4);
|
||||
filter: blur(var(--lyrics-dimmed-blur, 0px));
|
||||
.lyrics-lines.center .lyrics-line {
|
||||
transform-origin: center center;
|
||||
}
|
||||
|
||||
.lyrics-line.past {
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.lyrics-line.active {
|
||||
color: var(--lyrics-active-color, var(--text-primary));
|
||||
font-size: var(--lyrics-active-size, 24px);
|
||||
color: var(--text-primary);
|
||||
font-size: 22px;
|
||||
font-weight: 600;
|
||||
opacity: 1;
|
||||
transform: translateX(0);
|
||||
text-shadow: var(--lyrics-shadow, 0 10px 30px rgba(0, 0, 0, 0.45));
|
||||
filter: blur(0);
|
||||
transform: scale(1.02);
|
||||
}
|
||||
|
||||
/* Karaoke progress effect on active line */
|
||||
.lyrics-line.active .line-text {
|
||||
background: linear-gradient(
|
||||
90deg,
|
||||
var(--lyrics-active-color, var(--text-primary)) calc(var(--line-progress, 0) * 100%),
|
||||
var(--lyrics-highlight-muted, rgba(255, 255, 255, 0.25)) calc(var(--line-progress, 0) * 100%)
|
||||
var(--accent-primary) calc(var(--line-progress, 0) * 100%),
|
||||
var(--text-primary) calc(var(--line-progress, 0) * 100%)
|
||||
);
|
||||
-webkit-background-clip: text;
|
||||
background-clip: text;
|
||||
@@ -128,6 +210,6 @@
|
||||
color: var(--text-muted);
|
||||
font-size: 14px;
|
||||
text-align: center;
|
||||
padding: 24px 0;
|
||||
padding: 48px 0;
|
||||
}
|
||||
</style>
|
||||
@@ -87,16 +87,10 @@
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
background: linear-gradient(160deg, rgba(69, 46, 26, 0.95), rgba(30, 20, 12, 0.98));
|
||||
background: var(--bg-secondary);
|
||||
color: var(--text-primary);
|
||||
border-radius: 18px;
|
||||
border-radius: 12px;
|
||||
overflow: hidden;
|
||||
--lyrics-font-size: 16px;
|
||||
--lyrics-active-size: 22px;
|
||||
--lyrics-line-gap: 12px;
|
||||
--lyrics-line-height: 1.4;
|
||||
--lyrics-dimmed-opacity: 0.35;
|
||||
--lyrics-highlight-muted: rgba(255, 255, 255, 0.22);
|
||||
}
|
||||
|
||||
.lyrics-mini-body {
|
||||
@@ -116,9 +110,8 @@
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
padding: 12px 16px;
|
||||
background: rgba(0, 0, 0, 0.35);
|
||||
border-top: 1px solid rgba(255, 255, 255, 0.08);
|
||||
backdrop-filter: blur(12px);
|
||||
background: var(--bg-primary);
|
||||
border-top: 1px solid var(--bg-tertiary);
|
||||
}
|
||||
|
||||
.track-info {
|
||||
@@ -131,9 +124,9 @@
|
||||
.artwork {
|
||||
width: 44px;
|
||||
height: 44px;
|
||||
border-radius: 10px;
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
background: rgba(255, 255, 255, 0.08);
|
||||
background: var(--bg-tertiary);
|
||||
display: grid;
|
||||
place-items: center;
|
||||
}
|
||||
@@ -147,8 +140,8 @@
|
||||
.artwork-placeholder {
|
||||
width: 60%;
|
||||
height: 60%;
|
||||
border-radius: 8px;
|
||||
background: rgba(255, 255, 255, 0.12);
|
||||
border-radius: 6px;
|
||||
background: var(--bg-secondary);
|
||||
}
|
||||
|
||||
.meta {
|
||||
@@ -161,11 +154,12 @@
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.track-artist {
|
||||
font-size: 12px;
|
||||
color: rgba(255, 255, 255, 0.7);
|
||||
color: var(--text-muted);
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
@@ -183,15 +177,16 @@
|
||||
display: grid;
|
||||
place-items: center;
|
||||
border: none;
|
||||
border-radius: 10px;
|
||||
background: rgba(255, 255, 255, 0.08);
|
||||
border-radius: 8px;
|
||||
background: var(--bg-tertiary);
|
||||
color: var(--text-primary);
|
||||
cursor: pointer;
|
||||
transition: background 160ms ease, transform 160ms ease, opacity 160ms ease;
|
||||
transition: background 150ms ease, transform 150ms ease, opacity 150ms ease;
|
||||
}
|
||||
|
||||
.control-btn.primary {
|
||||
background: rgba(255, 255, 255, 0.2);
|
||||
background: var(--accent-primary);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.control-btn:disabled {
|
||||
@@ -200,7 +195,11 @@
|
||||
}
|
||||
|
||||
.control-btn:not(:disabled):hover {
|
||||
background: rgba(255, 255, 255, 0.2);
|
||||
background: var(--bg-tertiary);
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
|
||||
.control-btn.primary:not(:disabled):hover {
|
||||
filter: brightness(1.1);
|
||||
}
|
||||
</style>
|
||||
@@ -9,7 +9,6 @@
|
||||
interface Props {
|
||||
title?: string;
|
||||
artist?: string;
|
||||
provider?: string;
|
||||
lines: LyricsLine[];
|
||||
activeIndex?: number;
|
||||
activeProgress?: number;
|
||||
@@ -20,7 +19,6 @@
|
||||
let {
|
||||
title = '',
|
||||
artist = '',
|
||||
provider,
|
||||
lines,
|
||||
activeIndex = -1,
|
||||
activeProgress = 0,
|
||||
@@ -29,7 +27,7 @@
|
||||
}: Props = $props();
|
||||
</script>
|
||||
|
||||
<aside class="lyrics-sidebar">
|
||||
<aside class="lyrics-sidebar">
|
||||
<div class="header">
|
||||
<div class="header-icon">
|
||||
<Mic2 size={18} />
|
||||
@@ -37,17 +35,17 @@
|
||||
<div class="header-text">
|
||||
<div class="header-title">Lyrics</div>
|
||||
{#if title || artist}
|
||||
<div class="header-meta">{title}{title && artist ? ' - ' : ''}{artist}</div>
|
||||
<div class="header-meta">{title}{title && artist ? ' - ' : ''}{artist}</div>
|
||||
{/if}
|
||||
</div>
|
||||
{#if provider}
|
||||
<div class="header-provider">{provider}</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<div class="panel">
|
||||
{#if isLoading}
|
||||
<div class="state">Loading lyrics...</div>
|
||||
<div class="state">
|
||||
<div class="loading-spinner"></div>
|
||||
<span>Loading lyrics...</span>
|
||||
</div>
|
||||
{:else if error}
|
||||
<div class="state error">{error}</div>
|
||||
{:else}
|
||||
@@ -64,39 +62,32 @@
|
||||
|
||||
<style>
|
||||
.lyrics-sidebar {
|
||||
width: var(--lyrics-sidebar-width, 320px);
|
||||
min-width: var(--lyrics-sidebar-width, 320px);
|
||||
width: 340px;
|
||||
min-width: 340px;
|
||||
height: calc(100vh - 80px);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
border-left: 1px solid rgba(255, 255, 255, 0.06);
|
||||
background: linear-gradient(160deg, rgba(52, 38, 26, 0.92), rgba(22, 17, 12, 0.95));
|
||||
border-left: 1px solid var(--bg-tertiary);
|
||||
background: var(--bg-secondary);
|
||||
color: var(--text-primary);
|
||||
backdrop-filter: blur(14px);
|
||||
--lyrics-font-size: 15px;
|
||||
--lyrics-active-size: 20px;
|
||||
--lyrics-line-gap: 12px;
|
||||
--lyrics-line-height: 1.5;
|
||||
--lyrics-dimmed-opacity: 0.35;
|
||||
--lyrics-highlight-muted: rgba(255, 255, 255, 0.22);
|
||||
--lyrics-shadow: 0 10px 24px rgba(0, 0, 0, 0.45);
|
||||
}
|
||||
|
||||
.header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
padding: 18px 16px 12px 16px;
|
||||
border-bottom: 1px solid rgba(255, 255, 255, 0.05);
|
||||
padding: 16px;
|
||||
border-bottom: 1px solid var(--bg-tertiary);
|
||||
background: var(--bg-primary);
|
||||
}
|
||||
|
||||
.header-icon {
|
||||
width: 34px;
|
||||
height: 34px;
|
||||
width: 36px;
|
||||
height: 36px;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
background: rgba(255, 255, 255, 0.08);
|
||||
border-radius: 10px;
|
||||
background: var(--bg-tertiary);
|
||||
border-radius: 8px;
|
||||
color: var(--accent-primary);
|
||||
}
|
||||
|
||||
@@ -106,10 +97,10 @@
|
||||
}
|
||||
|
||||
.header-title {
|
||||
font-size: 14px;
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.16em;
|
||||
letter-spacing: 0.1em;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
@@ -119,31 +110,43 @@
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.header-provider {
|
||||
font-size: 11px;
|
||||
font-weight: 600;
|
||||
color: var(--text-muted);
|
||||
border: 1px solid rgba(255, 255, 255, 0.1);
|
||||
padding: 4px 8px;
|
||||
border-radius: 999px;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.08em;
|
||||
margin-top: 2px;
|
||||
}
|
||||
|
||||
.panel {
|
||||
flex: 1;
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.state {
|
||||
padding: 24px 16px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 12px;
|
||||
padding: 48px 16px;
|
||||
font-size: 14px;
|
||||
color: var(--text-muted);
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.state.error {
|
||||
color: #f4a1a1;
|
||||
color: var(--error, #e57373);
|
||||
}
|
||||
|
||||
.loading-spinner {
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
border: 2px solid var(--bg-tertiary);
|
||||
border-top-color: var(--accent-primary);
|
||||
border-radius: 50%;
|
||||
animation: spin 0.8s linear infinite;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
Reference in new issue
Block a user