1
0
mirror of https://github.com/elk-zone/elk synced 2024-11-24 07:06:08 +09:00
elk/components/status/StatusAttachment.vue
2022-11-23 10:16:31 +08:00

57 lines
1.3 KiB
Vue

<script setup lang="ts">
import { clamp } from '@vueuse/core'
import type { Attachment } from 'masto'
const { attachment } = defineProps<{
attachment: Attachment
}>()
const rawAspectRatio = computed(() => {
if (attachment.meta?.original?.aspect)
return attachment.meta.original.aspect
if (attachment.meta?.small?.aspect)
return attachment.meta.small.aspect
return undefined
})
const aspectRatio = computed(() => {
if (rawAspectRatio.value)
return clamp(rawAspectRatio.value, 0.5, 2)
return undefined
})
</script>
<template>
<template v-if="attachment.type === 'image' || attachment.type === 'gifv'">
<CommonBlurhash
:blurhash="attachment.blurhash"
class="status-attachment-image"
:src="attachment.previewUrl!"
:alt="attachment.description!"
:style="{
aspectRatio,
}"
border="~ base"
object-cover rounded-lg
/>
</template>
<template v-else-if="attachment.type === 'video'">
<video
:poster="attachment.previewUrl"
controls
border="~ base"
object-cover
:style="{
aspectRatio,
}"
>
<source :src="attachment.url || attachment.previewUrl" type="video/mp4">
</video>
</template>
<template v-else>
TODO:
<pre>{{ attachment }}
</pre>
</template>
</template>