Skip to content

A self-hosted media server and file management system

2.9 KB
Raw Blame
<script setup lang="ts">
import type { HTMLAttributes } from 'vue';

import { handleStorageURL } from '@/service/util';
import { inject } from 'vue';
import { cn } from '@aminnausin/cedar-ui';

import LazyImage from '@/components/lazy/LazyImage.vue';

const isAudio = inject<boolean>('isAudio');

const props = defineProps<{
    isNormalView: boolean;
    isTheatreView: boolean;
    isShowingLyrics?: boolean;
    isVisible?: boolean;
    isPlayerSizeConstrained?: boolean; // (isAudio OR isPortrait) AND isNormalView
    aspectRatio: {
        isPortrait: boolean;
        isAspectVideo: boolean;
    };
    posterUrl?: string;
}>();

const generatePosterStyle = (url?: string): HTMLAttributes['style'] => {
    if (!url) return {};

    return {
        backgroundImage: `url("${url}")`,
        backgroundPosition: 'center',
        backgroundSize: 'cover',
        backgroundRepeat: 'no-repeat',
    };
};
</script>

<template>
    <Transition leave-from-class="opacity-100" leave-to-class="opacity-0" leave-active-class="absolute! inset-0 duration-700 transition-opacity ease-in-out">
        <div v-if="isVisible" :class="cn('pointer-events-none z-3 size-full', { 'aspect-video': !isPlayerSizeConstrained, relative: isVisible })">
            <template v-if="isAudio">
                <div
                    id="audio-poster"
                    :class="['transition-scale absolute inset-0 -z-1 scale-105 blur-sm ease-in-out', { 'dark:scale-100': isPlayerSizeConstrained }]"
                    :style="generatePosterStyle(posterUrl)"
                ></div>
                <LazyImage
                    :src="posterUrl"
                    alt="album art"
                    wrapper-class="flex items-center justify-center"
                    :class="[
                        'mx-auto min-h-64 object-contain select-none md:h-screen',
                        { 'max-h-[71vh]': isPlayerSizeConstrained, 'max-h-screen': isTheatreView, 'aspect-square md:aspect-auto': isAudio && isNormalView && isShowingLyrics },
                    ]"
                    loading="eager"
                    fetchpriority="high"
                />
            </template>
            <div v-else class="contents">
                <div id="thumbnail-blocker" class="absolute inset-0 -z-1 scale-105 blur-sm" :style="generatePosterStyle(posterUrl)" fetchpriority="high"></div>
                <LazyImage
                    :src="handleStorageURL(posterUrl) ?? ''"
                    alt="thumbnail"
                    :class="['mx-auto h-full object-contain', { 'max-h-[71vh]': isPlayerSizeConstrained }]"
                    :animate="true"
                    loading="eager"
                    fetchpriority="high"
                />
            </div>
        </div>
    </Transition>
</template>
<style lang="css" scoped>
.transition-scale {
    transition-property: scale;
    transition-duration: 100ms;
    will-change: transform;
}
</style>