A self-hosted media server and file management system
Vue ffmpegfile-serverjellyfinlaravelmediamedia-playermedia-servermediabrowsermediaservermusicmusic-librarymusic-playermusicplayerself-hostedvuejs
feat: focus and blur lyrics based on distance to active line
aminnausindfbb66f2f7f9
diff --git a/resources/js/components/video/plugins/lyrics/VideoLyricItem.vue b/resources/js/components/video/plugins/lyrics/VideoLyricItem.vueindex 509ecb89..522da702 100644--- a/resources/js/components/video/plugins/lyrics/VideoLyricItem.vue+++ b/resources/js/components/video/plugins/lyrics/VideoLyricItem.vue@@ -1,13 +1,18 @@<script setup lang="ts">import type { RawLyricItem } from '@/types/types';+import { computed } from 'vue';+import { cn } from '@aminnausin/cedar-ui';+const emit = defineEmits<(e: 'clicked') => void>();-withDefaults(+const props = withDefaults(defineProps<{index: number;- isActive: boolean;lyric: RawLyricItem;+ isActive: boolean;+ distance?: number;+ isBlurEnabled?: boolean;}>(),{index: 0,@@ -21,18 +26,56 @@ function onClick() {emit('clicked');}++const distanceClasses = computed(() => {+ if (!props.isBlurEnabled) {+ return 'opacity-65';+ }++ switch (props.distance) {+ case 0:+ return 'opacity-100 blur-none';+ case 1:+ return 'opacity-80 blur-none';+ case 2:+ return 'opacity-65 blur-[0.5px]';+ case 3:+ return 'opacity-50 blur-[1px]';+ case undefined:+ return 'opacity-85 blur-none';+ default:+ return 'opacity-40 blur-[2px]';+ }+});</script><template>- <div- :class="['w-full transition-all ease-in hover:bg-neutral-800/30', isActive ? 'bg-neutral-800/40 text-yellow-400 opacity-100 duration-300' : 'opacity-85']"- :id="`lyric-${lyric?.time ?? index}`"- >+ <div :class="cn('w-full transition-colors duration-300 ease-out', { 'bg-neutral-800/40': isActive })" :id="`lyric-${lyric?.time ?? index}`" :data-lyric-row="index"><button- :class="['pointer-events-auto px-4 py-1 break-normal select-text sm:mx-auto sm:w-4/5 sm:px-0', lyric.time !== undefined ? 'cursor-pointer' : 'cursor-default']"+ :class="+ cn(+ 'pointer-events-auto px-4 py-1 break-normal select-text sm:mx-auto sm:w-4/5 sm:px-0',+ 'drop-shadow-sm transition-[color,opacity,filter,scale] duration-300 ease-out',+ distanceClasses,+ { 'cursor-pointer': lyric.time !== undefined },+ { 'text-yellow-400 opacity-100 drop-shadow-none': isActive },+ )+ "@click="onClick"><span>{{ lyric?.text || '-' }}</span></button></div></template>++<style lang="css" scoped>+@media (hover: hover) and (pointer: fine) {+ div:hover {+ background-color: color-mix(in oklab, var(--color-neutral-800) /* oklch(26.9% 0 0) = #262626 */ 30%, transparent);+ }+ button:hover {+ opacity: 100%;+ filter: blur(0);+ }+}+</style>diff --git a/resources/js/components/video/plugins/lyrics/VideoLyrics.vue b/resources/js/components/video/plugins/lyrics/VideoLyrics.vueindex 511d4290..d2a4f270 100644--- a/resources/js/components/video/plugins/lyrics/VideoLyrics.vue+++ b/resources/js/components/video/plugins/lyrics/VideoLyrics.vue@@ -21,6 +21,18 @@ const { stateVideo } = storeToRefs(useContentStore());const emit = defineEmits<{ seek: [value: number] }>();const props = defineProps<{ rawLyrics: string; player: HTMLVideoElement | null; timeDuration: number; isPaused: boolean; isShowingLyrics: boolean }>();+const activeLyricElement = ref<HTMLElement | null>(null);+const lyricsContainer = useTemplateRef<HTMLElement | null>('lyrics-container');+const lyricObserver = ref<IntersectionObserver>();++const activeTime = ref(0);+const activeIndex = ref(-1);+const isActiveLyricVisible = ref(false);+const isContainerVisible = ref(false);++const isProgrammaticScroll = ref(false);+const isFocusedScroll = ref(false);+const lyrics = computed(() => {const availableLyrics = stateLyrics.value;if (!availableLyrics) return [{ text: 'No lyrics yet...' }];@@ -43,14 +55,6 @@ const lyricItems = computed(() => {}) as LyricItem[];});-const activeLyricElement = ref<HTMLElement | null>(null);-const lyricsContainer = useTemplateRef<HTMLElement | null>('lyrics-container');-const lyricObserver = ref<IntersectionObserver>();--const activeTime = ref(0);-const isActiveLyricVisible = ref(false);-const isContainerVisible = ref(false);-const toPercentageTime = (seconds: number): number => {seconds = Math.min(Math.max(seconds, 0), props.timeDuration);@@ -58,7 +62,7 @@ const toPercentageTime = (seconds: number): number => {};const handleClick = (id: string, seconds: number) => {- document.getElementById(id)?.scrollIntoView({ behavior: 'smooth', block: 'center' });+ if (seconds === activeTime.value) document.getElementById(id)?.scrollIntoView({ behavior: 'smooth', block: 'center' });if (!Number.isNaN(seconds)) emit('seek', seconds);};@@ -113,13 +117,12 @@ const handleUpdate = async (scrollOverride: boolean = false) => {if (!current || current.time === undefined || (current.time === activeTime.value && isActiveLyricVisible.value)) return;activeTime.value = current.time;+ activeIndex.value = lyrics.value.findIndex((lyric) => lyric.time === current.time);const target = document.getElementById(`lyric-${current.time}`);if (!target) return;- if (props.isPaused || scrollOverride || (isContainerVisible.value && isActiveLyricVisible.value)) {- target.scrollIntoView({ behavior: 'smooth', block: 'center' });- }+ if (scrollOverride || props.isPaused || (isContainerVisible.value && isActiveLyricVisible.value)) focusScroll(target);observeLyricElement(target);};@@ -127,6 +130,9 @@ const handleUpdate = async (scrollOverride: boolean = false) => {// Resets scroll position and active lyric / lineconst resetComponent = () => {activeTime.value = 0;+ activeIndex.value = -1;+ isFocusedScroll.value = false;+if (activeLyricElement.value && lyricObserver.value) {lyricObserver.value.unobserve(activeLyricElement.value);}@@ -135,7 +141,15 @@ const resetComponent = () => {nextTick(() => {lyricsContainer.value?.scrollTo({ top: 0, behavior: 'smooth' });- if (lyrics.value?.[0]?.percentage) activeTime.value = lyrics.value[0].percentage;+ if (lyrics.value?.[0]?.percentage) {+ activeTime.value = lyrics.value[0].percentage;+ }++ if (!!lyricItems.value.at(0)?.percentage) {+ isFocusedScroll.value = true;+ activeIndex.value = 0;+ }+const modal = useModalStore();modal.close();});@@ -149,8 +163,7 @@ const handleForceScroll = (seconds: number) => {const target = document.getElementById(`lyric-${current.time}`);if (!target) return;- target.scrollIntoView({ behavior: 'smooth', block: 'center' });-+ focusScroll(target);observeLyricElement(target);};@@ -167,6 +180,22 @@ const observeLyricElement = (target: HTMLElement) => {});};+const focusScroll = (target?: HTMLElement | null) => {+ if (!target) return;+ isProgrammaticScroll.value = true;+ isFocusedScroll.value = true;++ target?.scrollIntoView({ behavior: 'smooth', block: 'center' });+};++const handleUserScroll = () => {+ if (!isProgrammaticScroll.value) isFocusedScroll.value = false;+};++const handleScrollEnd = () => {+ isProgrammaticScroll.value = false;+};+onMounted(() => {if (!lyricsContainer.value) return;@@ -228,16 +257,24 @@ watch(defineExpose({ scrollToCurrent });</script><template>- <section class="fade-mask scrollbar-hide flex h-full w-full flex-col overflow-y-scroll text-center text-sm sm:text-xl" ref="lyrics-container" v-show="lyrics.length > 0">+ <section+ class="fade-mask scrollbar-hide flex h-full w-full flex-col overflow-y-scroll text-center text-sm sm:text-xl"+ ref="lyrics-container"+ v-show="lyrics.length > 0"+ @scroll="handleUserScroll"+ @scrollend="handleScrollEnd"+ ><div class="shrink-0" style="height: 45%"></div><VideoLyricItemv-for="(lyric, index) in lyrics"- :key="index"v-show="lyric.time || lyric.text.trim().length != 0"+ :key="index":lyric="lyric":index="index":is-active="lyric.time === activeTime"+ :distance="lyrics.length === 1 && lyrics[0].text === 'No lyrics yet...' ? undefined : activeIndex < 0 ? Infinity : Math.abs(index - activeIndex)":title="lyric.time ? toFormattedDuration(lyric.time) : ''"+ :is-blur-enabled="isFocusedScroll && activeIndex >= 0"@clicked="lyric.time !== undefined ? handleClick(`lyric-${lyric.time}`, lyric.time) : null"/><VideoLyricItem