1
0
elk/components/status/StatusPreviewCard.vue

83 lines
2.2 KiB
Vue
Raw Normal View History

<script setup lang="ts">
2023-01-08 15:21:09 +09:00
import type { mastodon } from 'masto'
const props = defineProps<{
2023-01-08 15:21:09 +09:00
card: mastodon.v1.PreviewCard
/** For the preview image, only the small image mode is displayed */
smallPictureOnly?: boolean
/** When it is root card in the list, not appear as a child card */
root?: boolean
}>()
// mastodon's default max og image width
const ogImageWidth = 400
const alt = $computed(() => `${props.card.title} - ${props.card.title}`)
const isSquare = $computed(() => (
props.smallPictureOnly
|| props.card.width === props.card.height
|| Number(props.card.width || 0) < ogImageWidth
|| Number(props.card.height || 0) < ogImageWidth / 2
))
2022-12-11 19:52:36 +09:00
const providerName = $computed(() => props.card.providerName ? props.card.providerName : new URL(props.card.url).hostname)
const gitHubCards = $(useFeatureFlag('experimentalGitHubCards'))
2022-12-20 00:52:32 +09:00
// TODO: handle card.type: 'photo' | 'video' | 'rich';
2023-01-08 15:21:09 +09:00
const cardTypeIconMap: Record<mastodon.v1.PreviewCardType, string> = {
2022-12-20 00:52:32 +09:00
link: 'i-ri:profile-line',
photo: 'i-ri:image-line',
video: 'i-ri:play-line',
rich: 'i-ri:profile-line',
}
</script>
<template>
<StatusPreviewGitHub v-if="gitHubCards && providerName === 'GitHub'" :card="card" />
<NuxtLink
v-else
block
of-hidden
:to="card.url"
2023-01-10 18:05:59 +09:00
bg-card
hover:bg-active
:class="{
'flex': isSquare,
'p-4': root,
2023-01-10 18:05:59 +09:00
'rounded-lg': !root,
}"
target="_blank"
external
>
<div
v-if="card.image"
flex flex-col
display-block of-hidden
:class="{
2023-01-10 18:05:59 +09:00
'sm:(min-w-32 w-32 h-32) min-w-22 w-22 h-22': isSquare,
'w-full aspect-[1.91]': !isSquare,
'rounded-lg': root,
}"
>
<CommonBlurhash
:blurhash="card.blurhash"
:src="card.image"
:width="card.width"
:height="card.height"
:alt="alt"
w-full h-full object-cover
/>
</div>
2022-12-11 19:52:36 +09:00
<div
v-else
min-w-22 w-22 h-22 sm="min-w-32 w-32 h-32" bg="slate-500/10" flex justify-center items-center
:class="[
root ? 'rounded-lg' : '',
]"
>
2022-12-20 00:52:32 +09:00
<div :class="cardTypeIconMap[card.type]" w="30%" h="30%" text-secondary />
</div>
<StatusPreviewCardInfo :root="root" :card="card" :provider="providerName" />
</NuxtLink>
</template>