elk/components/status/StatusAttachment.vue

71 lines
1.7 KiB
Vue
Raw Normal View History

2022-11-14 04:33:09 +01:00
<script setup lang="ts">
2022-11-21 14:38:10 +01:00
import { clamp } from '@vueuse/core'
2022-11-14 04:33:09 +01:00
import type { Attachment } from 'masto'
const { attachment } = defineProps<{
attachment: Attachment
}>()
2022-11-21 14:21:53 +01:00
2022-11-21 14:38:10 +01:00
const rawAspectRatio = computed(() => {
2022-11-21 14:21:53 +01:00
if (attachment.meta?.original?.aspect)
return attachment.meta.original.aspect
if (attachment.meta?.small?.aspect)
return attachment.meta.small.aspect
return undefined
})
2022-11-21 14:38:10 +01:00
const aspectRatio = computed(() => {
if (rawAspectRatio.value)
return clamp(rawAspectRatio.value, 0.5, 2)
return undefined
})
2022-11-14 04:33:09 +01:00
</script>
<template>
2022-11-25 15:31:33 +01:00
<template v-if="attachment.type === 'video'">
2022-11-21 14:38:10 +01:00
<video
:poster="attachment.previewUrl"
controls
2022-11-23 03:16:31 +01:00
border="~ base"
2022-11-21 14:38:10 +01:00
object-cover
:style="{
aspectRatio,
}"
>
<source :src="attachment.url || attachment.previewUrl" type="video/mp4">
</video>
</template>
2022-11-24 05:05:13 +01:00
<template v-else-if="attachment.type === 'gifv'">
<video
:poster="attachment.previewUrl"
loop
autoplay
border="~ base"
object-cover
:style="{
aspectRatio,
}"
>
<source :src="attachment.url || attachment.previewUrl" type="video/mp4">
</video>
</template>
<template v-else-if="attachment.type === 'audio'">
<audio controls border="~ base">
<source :src="attachment.url || attachment.previewUrl" type="audio/mp3">
</audio>
</template>
2022-11-14 04:33:09 +01:00
<template v-else>
2022-11-25 15:31:33 +01:00
<CommonBlurhash
:blurhash="attachment.blurhash"
class="status-attachment-image"
:src="attachment.url || attachment.previewUrl!"
:alt="attachment.description!"
:style="{
aspectRatio,
}"
border="~ base"
object-cover rounded-lg
/>
2022-11-14 04:33:09 +01:00
</template>
</template>