koel/resources/assets/js/components/ui/LyricsPane.vue

67 lines
2 KiB
Vue
Raw Normal View History

2022-04-15 14:24:30 +00:00
<template>
2024-04-04 22:20:42 +00:00
<article>
<main class="relative">
2022-04-15 14:24:30 +00:00
<template v-if="song">
<div v-show="song.lyrics">
2024-04-04 22:20:42 +00:00
<pre class="font-sans whitespace-pre-wrap leading-relaxed">{{ lyrics }}</pre>
<span class="magnifier-wrapper opacity-0 absolute top-0 right-0 hover:!opacity-100">
<Magnifier @in="zoomIn" @out="zoomOut" />
</span>
2022-04-15 14:24:30 +00:00
</div>
2024-04-04 22:20:42 +00:00
<p v-if="song.id && !song.lyrics" class="text-k-text-secondary">
<template v-if="canUpdateLyrics">
2022-04-15 14:24:30 +00:00
No lyrics found.
2024-04-04 22:20:42 +00:00
<a role="button" @click.prevent="showEditSongForm">
2022-04-15 14:24:30 +00:00
Click here
2024-04-04 22:20:42 +00:00
</a>
2022-04-15 14:24:30 +00:00
to add lyrics.
</template>
<span v-else>No lyrics available. Are you listening to Bach?</span>
</p>
</template>
2024-04-04 22:20:42 +00:00
</main>
2022-04-15 14:24:30 +00:00
</article>
</template>
2022-04-15 17:00:08 +00:00
<script lang="ts" setup>
2024-04-04 22:20:42 +00:00
import { computed, defineAsyncComponent, ref, toRefs, watch } from 'vue'
import { cr2lf, eventBus } from '@/utils'
import { usePolicies } from '@/composables'
import { preferenceStore as preferences } from '@/stores'
2022-04-15 14:24:30 +00:00
2022-07-21 10:45:23 +00:00
const Magnifier = defineAsyncComponent(() => import('@/components/ui/Magnifier.vue'))
2022-04-15 14:24:30 +00:00
2022-04-29 13:32:12 +00:00
const props = defineProps<{ song: Song }>()
2022-04-15 17:00:08 +00:00
const { song } = toRefs(props)
2022-04-15 14:24:30 +00:00
2024-04-04 22:20:42 +00:00
const { currentUserCan } = usePolicies()
2024-04-04 22:20:42 +00:00
const canUpdateLyrics = currentUserCan.editSong(song.value)
const zoomLevel = ref(preferences.lyrics_zoom_level || 1)
2022-04-15 14:24:30 +00:00
2024-04-04 22:20:42 +00:00
const lyrics = computed(() => cr2lf(song.value.lyrics))
const fontSize = computed(() => `${1 + (zoomLevel.value - 1) * 0.2}rem`)
2024-04-04 22:20:42 +00:00
const zoomIn = () => (zoomLevel.value = Math.min(zoomLevel.value + 1, 8))
const zoomOut = () => (zoomLevel.value = Math.max(zoomLevel.value - 1, -2))
const showEditSongForm = () => eventBus.emit('MODAL_SHOW_EDIT_SONG_FORM', song.value, 'lyrics')
2024-04-04 22:20:42 +00:00
watch(zoomLevel, level => (preferences.lyrics_zoom_level = level), { immediate: true })
2022-04-15 14:24:30 +00:00
</script>
2024-04-04 20:13:35 +00:00
<style lang="postcss" scoped>
2024-04-04 22:20:42 +00:00
main {
.magnifier-wrapper {
@apply no-hover:opacity-100;
2022-04-15 14:24:30 +00:00
}
2024-04-04 22:20:42 +00:00
&:hover .magnifier-wrapper {
@apply opacity-50;
2022-04-15 14:24:30 +00:00
}
}
2022-06-10 10:47:46 +00:00
pre {
2024-04-04 22:20:42 +00:00
font-size: v-bind(fontSize);
2022-06-10 10:47:46 +00:00
}
2022-04-15 14:24:30 +00:00
</style>