diff --git a/src/routes/_api/player/audio.scss b/src/routes/_api/player/audio.scss index 4e2bdba..61a5272 100644 --- a/src/routes/_api/player/audio.scss +++ b/src/routes/_api/player/audio.scss @@ -105,6 +105,7 @@ &-art { + position: relative; width: clamp(200px, min(48vh, 34vw), 430px); aspect-ratio: 1; overflow: hidden; @@ -115,18 +116,46 @@ place-items: center; img { + position: absolute; + inset: 0; display: block; width: 100%; height: 100%; object-fit: cover; } + // Both layers melt under the same turbulence filter while the old + // sleeve fades out over the new one. + &.is-melting { + filter: url(#music-liquid-filter); + + img { + transform: scale(1.02); + } + } + + &-prev { + z-index: 2; + animation: cover-melt-out 0.8s ease forwards; + } + + &-current { + z-index: 1; + animation: cover-melt-in 0.8s cubic-bezier(0.22, 1, 0.36, 1); + } + > .material-symbols-rounded { font-size: 5rem; color: rgb(255 255 255 / 0.4); } } + &-liquid { + position: absolute; + width: 0; + height: 0; + } + &-meta { width: min(560px, 100%); margin-top: clamp(1.2rem, 3vh, 2rem); @@ -636,3 +665,25 @@ html.is-macos .music-player-chrome { } } + +@keyframes cover-melt-in { + from { + opacity: 0; + transform: scale(1.015); + } + to { + opacity: 1; + transform: scale(1); + } +} + +@keyframes cover-melt-out { + from { + opacity: 1; + } + to { + opacity: 0; + } +} + + diff --git a/src/routes/_api/player/audio.tsx b/src/routes/_api/player/audio.tsx index 987a58c..9510799 100644 --- a/src/routes/_api/player/audio.tsx +++ b/src/routes/_api/player/audio.tsx @@ -13,7 +13,7 @@ import { import { useQuery } from "@tanstack/react-query"; import { createFileRoute, Link, useNavigate } from "@tanstack/react-router"; import { AnimatePresence, motion } from "motion/react"; -import React, { useEffect, useMemo, useState } from "react"; +import React, { useEffect, useMemo, useRef, useState } from "react"; import CastButton from "@/components/buttons/castButton"; import LikeButton from "@/components/buttons/likeButton"; import LyricsPanel, { @@ -123,6 +123,136 @@ const QueueRow = ({ ); +const MELT_MS = 800; + +/** + * Sleeve that melts into the next track: the previous cover stays on top while + * a turbulence + displacement filter ripples both layers, then fades away. + */ +const LiquidCover = ({ src, alt }: { src?: string; alt: string }) => { + const [current, setCurrent] = useState(src); + const [previous, setPrevious] = useState(); + const [melting, setMelting] = useState(false); + const currentRef = useRef(src); + const turbRef = useRef(null); + const dispRef = useRef(null); + const rafRef = useRef(0); + const timerRef = useRef | null>(null); + + useEffect(() => { + if (!src || src === currentRef.current) return; + let cancelled = false; + let begun = false; + + const start = () => { + if (cancelled || begun) return; + begun = true; + setPrevious(currentRef.current); + currentRef.current = src; + setCurrent(src); + setMelting(true); + + const started = performance.now(); + const step = (now: number) => { + const t = Math.min((now - started) / MELT_MS, 1); + const wave = Math.sin(Math.PI * t); + dispRef.current?.setAttribute( + "scale", + String(Math.round(wave * 10)), + ); + turbRef.current?.setAttribute( + "baseFrequency", + String(0.005 + wave * 0.003), + ); + if (t < 1) { + rafRef.current = requestAnimationFrame(step); + } else { + dispRef.current?.setAttribute("scale", "0"); + setMelting(false); + } + }; + cancelAnimationFrame(rafRef.current); + rafRef.current = requestAnimationFrame(step); + if (timerRef.current) clearTimeout(timerRef.current); + timerRef.current = setTimeout( + () => setPrevious(undefined), + MELT_MS + 60, + ); + }; + + const image = new Image(); + image.onload = start; + image.onerror = start; + image.src = src; + if (image.complete && image.naturalWidth > 0) start(); + + return () => { + cancelled = true; + cancelAnimationFrame(rafRef.current); + if (timerRef.current) clearTimeout(timerRef.current); + }; + }, [src]); + + useEffect( + () => () => { + cancelAnimationFrame(rafRef.current); + if (timerRef.current) clearTimeout(timerRef.current); + }, + [], + ); + + return ( +
+ + {previous && ( + + )} + {current ? ( + {alt} + ) : ( + music_note + )} +
+ ); +}; + function AudioPlayerRoute() { const api = useApiInContext((s) => s.api); const user = useCentralStore((s) => s.currentUser); @@ -273,19 +403,10 @@ function AudioPlayerRoute() {
- - {imageUrl ? ( - {item?.Name - ) : ( - music_note - )} - +

{item?.Name}