Merge branch 'feat/player-fullscreen'

This commit is contained in:
lucast committed 2026-03-07 19:49:18 +01:00
commit b48db8bb37
8 files changed
+551 -5

No files matched your search

+138
View File
@@ -0,0 +1,138 @@
<script setup lang="ts">
import LyricsDisplay from "./Fullscreen/LyricsDisplay.vue"
const fullscreen = useFullscreen()
const song = useSong()
const mouseMovedRecently = ref(true)
onMounted(() => {
let timeoutId: NodeJS.Timeout
const handleMouseMove = () => {
mouseMovedRecently.value = true
clearTimeout(timeoutId)
timeoutId = setTimeout(() => {
mouseMovedRecently.value = false
}, 2000)
}
window.addEventListener("mousemove", handleMouseMove)
onUnmounted(() => {
window.removeEventListener("mousemove", handleMouseMove)
})
})
</script>
<template>
<section
class="fullscreen"
:class="{ showCursor: mouseMovedRecently }"
v-show="fullscreen"
>
<template v-if="song">
<NuxtImg
:src="GET_FILE(song.album.file)"
:alt="song.name"
width="500"
height="500"
class="background"
/>
</template>
<section class="screen-container">
<Icon
name="lucide:x"
class="close-btn"
:class="{ show: mouseMovedRecently }"
@click="fullscreen = false"
/>
<div class="content-container">
<PlayerFullscreenTrackDisplay
:show-buttons="mouseMovedRecently"
/>
<LyricsDisplay
:animation-duration="0.2"
:offset="150"
:show-scroll-bar="mouseMovedRecently"
/>
</div>
</section>
</section>
</template>
<style lang="scss" scoped>
.fullscreen {
position: fixed;
top: 0;
left: 0;
width: 200vw;
height: 200vh;
z-index: 150;
cursor: none;
&.showCursor {
cursor: auto;
}
}
.background {
position: absolute;
top: -25%;
left: -25%;
width: 100%;
height: 100%;
object-fit: cover;
filter: blur(40px);
}
.screen-container {
position: fixed;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
background-color: rgba(0, 0, 0, 0.45);
}
.close-btn {
position: absolute;
top: 1rem;
right: 1rem;
cursor: pointer;
font-size: 24px;
transition: opacity 0.2s ease;
opacity: 0;
&.show {
opacity: 1;
}
}
.content-container {
/* TODO: A lot of magic numbers... should be variables */
max-width: 1280px;
width: 100%;
height: 100%;
margin: 0 auto;
display: grid;
grid-template-columns: 500px 1fr;
gap: 110px;
align-items: center;
& > * {
max-height: 675px;
}
}
</style>
@@ -0,0 +1,226 @@
<script setup lang="ts">
const { animationDuration, offset, showScrollBar } = defineProps<{
animationDuration: number
offset: number
showScrollBar: boolean
}>()
const song = useSong()
const { secondsPlayed } = usePlayer()
const parsedLyrics = computed(() => {
if (!song.value || !song.value.lyrics.synced) return
if (song.value.lyrics.synced) return parseLyrics(song.value.lyrics.text)
})
const lyricsRefs = useTemplateRef("lyrics")
const activeIndex = computed(() => {
if (!parsedLyrics.value) return -1
const time = secondsPlayed.value
return parsedLyrics.value.findIndex(
(lyric, i) =>
lyric.time <= time &&
(!parsedLyrics.value![i + 1] ||
parsedLyrics.value![i + 1]!.time > time),
)
})
const scrollActiveIndex = computed(() => {
if (!parsedLyrics.value) return -1
const time = secondsPlayed.value + animationDuration
let index = parsedLyrics.value.findIndex(
(lyric, i) =>
lyric.time <= time &&
(!parsedLyrics.value![i + 1] ||
parsedLyrics.value![i + 1]!.time > time),
)
if (index >= parsedLyrics.value.length - 1)
index = parsedLyrics.value.length - 2
return index
})
const height = ref(0)
watch(song, () => {
const trackDisplay = document.querySelector(".track-display")
if (!trackDisplay) return
const resizeObserver = new ResizeObserver((entries) => {
height.value = entries[0]!.target.clientHeight
})
resizeObserver.observe(trackDisplay)
})
const transformY = computed(() => {
if (activeIndex.value < 0) return 0
let accumulatedHeight = 0
if (!lyricsRefs.value) return 0
for (let i = 0; i < scrollActiveIndex.value; i++) {
const el = lyricsRefs.value[i]
if (el) accumulatedHeight += el.getBoundingClientRect().height
}
return -accumulatedHeight
})
const containerRef = useTemplateRef("container-ref")
const outerRef = useTemplateRef("outer-ref")
const manualOffset = ref(0)
const isScrolling = ref(false)
let scrollingTimeout: any = null
const onWheel = (event: WheelEvent) => {
if (!containerRef.value || !outerRef.value) return
isScrolling.value = true
clearTimeout(scrollingTimeout)
const delta = event.deltaY
manualOffset.value -= delta
const maxTranslate = offset
const minTranslate =
-containerRef.value.scrollHeight + outerRef.value.offsetHeight
manualOffset.value = Math.min(
maxTranslate,
Math.max(minTranslate, manualOffset.value),
)
scrollingTimeout = setTimeout(() => (isScrolling.value = false), 3000)
}
const finalTransform = computed(() => {
if (isScrolling.value) return manualOffset.value
return transformY.value + offset
})
</script>
<template>
<div
ref="outer-ref"
v-if="song && song.lyrics.synced"
class="synced-lyrics-container"
:style="{
height: `${height}px`,
}"
@wheel.prevent="onWheel"
>
<div
ref="container-ref"
class="synced-lyrics"
:style="{
transform: `translateY(${finalTransform}px)`,
transition: `transform ${animationDuration}s ease`,
}"
>
<p
v-for="(lyric, i) in parsedLyrics"
:key="lyric.time"
:class="{ active: i == activeIndex }"
ref="lyrics"
@click="() => (secondsPlayed = lyric.time)"
>
{{ lyric.text }}
</p>
</div>
</div>
<div
v-else-if="song"
class="lyrics"
:style="{
height: `${height}px`,
}"
:class="{ show: showScrollBar }"
>
<p>{{ song.lyrics.text }}</p>
</div>
</template>
<style lang="scss" scoped>
@use "@/styles/util" as *;
@use "@/styles/variables" as *;
.synced-lyrics-container {
position: relative;
overflow: hidden;
mask-image: linear-gradient(
transparent 0%,
#000 15%,
#000,
#000,
95%,
transparent 100%
);
}
.synced-lyrics {
position: absolute;
scrollbar-width: none;
will-change: transform;
top: 0;
& > p {
@include fontSize(40px);
font-weight: 600;
color: white;
opacity: 0.4;
padding: 10px 0;
transition:
opacity 0.1s ease,
filter 0.1s ease;
filter: blur(1.5px);
&.active {
opacity: 1;
filter: initial;
}
&:hover {
cursor: pointer;
opacity: 1;
filter: initial;
}
}
}
.lyrics {
overflow: hidden;
& > p {
height: 100%;
overflow-y: scroll;
white-space: pre-wrap;
&::-webkit-scrollbar {
width: 10px;
}
&::-webkit-scrollbar-thumb {
background-color: transparent;
border-radius: 5px;
}
}
&.show > p::-webkit-scrollbar-thumb {
background-color: $color-secondary-background;
}
}
</style>
@@ -0,0 +1,144 @@
<script setup lang="ts">
const { showButtons } = defineProps<{ showButtons: boolean }>()
const song = useSong()
const {
isPlaying,
play,
pause,
next,
prev,
shuffle,
repeat,
secondsPlayed,
duration,
} = usePlayer()
const secondsPlayedFormatted = computed(() =>
new Date(secondsPlayed.value * 1000).toISOString().slice(14, 19),
)
const durationFormatted = computed(() =>
new Date((duration.value - secondsPlayed.value) * 1000)
.toISOString()
.slice(14, 19),
)
</script>
<template>
<article class="track-display" v-if="song">
<NuxtImg
class="cover"
:src="GET_FILE(song.album.file)"
:alt="song.name"
width="512"
height="512"
/>
<div class="track">
<p class="name">{{ song.name }}</p>
<ArtistName :artists="song.artists" />
</div>
<div class="slider">
<RangeSlider
:model-value="secondsPlayed"
@update:model-value="(v) => (secondsPlayed = v ?? 0)"
:max="duration"
dont-update-immediately
monochrome
/>
<div class="time">
<p>{{ secondsPlayedFormatted }}</p>
<p>{{ durationFormatted }}</p>
</div>
</div>
<div class="btns" :class="{ hidden: !showButtons }">
<Icon name="lucide:shuffle" @click="shuffle()" />
<Icon name="lucide:skip-back" @click="prev()" />
<Icon name="lucide:pause" v-if="isPlaying" @click="pause()" />
<Icon name="lucide:play" v-else @click="play()" />
<Icon name="lucide:skip-forward" @click="next()" />
<Icon
name="lucide:repeat"
:class="{ repeating: repeat }"
@click="repeat = !repeat"
/>
</div>
</article>
</template>
<style lang="scss" scoped>
@use "@/styles/util" as *;
@use "@/styles/variables" as *;
.track-display {
display: flex;
flex-direction: column;
align-items: center;
gap: 1rem;
}
.cover {
width: 100%;
aspect-ratio: 1;
object-fit: cover;
border-radius: $border-radius-standard;
}
.track {
@include fontSize(16px);
width: 100%;
line-height: 1.3;
.name {
@include fontSize(17px);
font-weight: bold;
}
}
.slider {
display: flex;
flex-direction: column;
width: 100%;
gap: 4px;
.time {
width: 100%;
display: flex;
justify-content: space-between;
opacity: 0.5;
& p {
@include fontSize(15px);
}
}
}
.btns {
cursor: pointer;
font-size: 30px;
display: flex;
justify-content: center;
width: 100%;
gap: 1rem;
overflow: hidden;
max-height: 30px;
transition: max-height 0.2s ease-in-out;
&.hidden {
max-height: 0;
}
& > * {
transition: color 0.2s ease;
}
.repeating {
color: $color-accent;
}
}
</style>
+3 -4
View File
@@ -39,6 +39,7 @@ const durationFormatted = computed(() =>
) )
const toast = useToast() const toast = useToast()
const fullscreen = useFullscreen()
</script> </script>
<template> <template>
@@ -106,13 +107,11 @@ const toast = useToast()
name="lucide:list" name="lucide:list"
@click="toast.show('Not yet implemented')" @click="toast.show('Not yet implemented')"
/> />
<Icon <Icon name="lucide:expand" @click="fullscreen = true" />
name="lucide:expand"
@click="toast.show('Not yet implemented')"
/>
</div> </div>
</template> </template>
</article> </article>
<PlayerFullscreen />
</template> </template>
<style lang="scss" scoped> <style lang="scss" scoped>
+1
View File
@@ -0,0 +1 @@
export const useFullscreen = () => useState<boolean>("fullscreen", () => false)
+1
View File
@@ -7,6 +7,7 @@ $color-border: rgba(255, 255, 255, 0.16);
$color-button: rgba(255, 255, 255, 0.08); $color-button: rgba(255, 255, 255, 0.08);
$color-button-hover: rgba(255, 255, 255, 0.16); $color-button-hover: rgba(255, 255, 255, 0.16);
$color-attention: #fc8181; $color-attention: #fc8181;
$color-slider-monochrome: white;
$border-radius-standard: 0.3rem; $border-radius-standard: 0.3rem;
$border-radius-lg: 0.6rem; $border-radius-lg: 0.6rem;
+11 -1
View File
@@ -4,6 +4,7 @@ interface SliderProps {
max?: number max?: number
step?: number step?: number
dontUpdateImmediately?: boolean dontUpdateImmediately?: boolean
monochrome?: boolean
} }
const props = withDefaults(defineProps<SliderProps>(), { const props = withDefaults(defineProps<SliderProps>(), {
@@ -11,6 +12,7 @@ const props = withDefaults(defineProps<SliderProps>(), {
max: 100, max: 100,
step: 1, step: 1,
dontUpdateImmediately: false, dontUpdateImmediately: false,
monochrome: false,
}) })
const value = defineModel<number>() const value = defineModel<number>()
@@ -67,7 +69,11 @@ const onMouseDown = (event: MouseEvent) => {
<template> <template>
<div ref="slider-ref" class="slider" @mousedown="onMouseDown"> <div ref="slider-ref" class="slider" @mousedown="onMouseDown">
<div class="track"> <div class="track">
<div class="fill" :style="{ width: percentage + '%' }" /> <div
class="fill"
:class="{ monochrome }"
:style="{ width: percentage + '%' }"
/>
</div> </div>
</div> </div>
</template> </template>
@@ -98,4 +104,8 @@ const onMouseDown = (event: MouseEvent) => {
background: $color-accent; background: $color-accent;
border-radius: 999px; border-radius: 999px;
} }
.slider .monochrome {
background-color: $color-slider-monochrome;
}
</style> </style>
+27
View File
@@ -0,0 +1,27 @@
export const parseLyrics = (lrc: string) => {
const regex = /^\[(\d{2}:\d{2}(.\d{2,3})?)\](.*)/
const lines = lrc.split("\n")
const output: { time: number; text: any }[] = []
const parseTime = (time: any) => {
const minsec = time.split(":")
const min = parseInt(minsec[0]) * 60
const sec = parseFloat(minsec[1])
return min + sec
}
lines.forEach((line: any) => {
const match = line.match(regex)
if (match == null) return
const time = match[1]
const text = match[3]
output.push({
time: parseTime(time),
text: text.trim(),
})
})
return output
}