1
0
elk/components/status/StatusAttachment.vue

78 lines
1.8 KiB
Vue
Raw Normal View History

2022-11-14 12:33:09 +09:00
<script setup lang="ts">
2022-11-21 22:38:10 +09:00
import { clamp } from '@vueuse/core'
2022-11-14 12:33:09 +09:00
import type { Attachment } from 'masto'
const { attachment } = defineProps<{
attachment: Attachment
}>()
2022-11-21 22:21:53 +09:00
2022-11-21 22:38:10 +09:00
const rawAspectRatio = computed(() => {
2022-11-21 22:21:53 +09: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 22:38:10 +09:00
const aspectRatio = computed(() => {
if (rawAspectRatio.value)
return clamp(rawAspectRatio.value, 0.5, 2)
return undefined
})
2022-11-14 12:33:09 +09:00
</script>
<template>
2022-11-24 13:05:13 +09:00
<template v-if="attachment.type === 'image' ">
2022-11-21 22:21:53 +09:00
<CommonBlurhash
:blurhash="attachment.blurhash"
2022-11-14 12:33:09 +09:00
class="status-attachment-image"
2022-11-23 17:33:18 +09:00
:src="attachment.url || attachment.previewUrl!"
2022-11-14 12:33:09 +09:00
:alt="attachment.description!"
2022-11-21 22:21:53 +09:00
:style="{
aspectRatio,
}"
2022-11-23 11:16:31 +09:00
border="~ base"
2022-11-14 12:33:09 +09:00
object-cover rounded-lg
2022-11-21 22:21:53 +09:00
/>
2022-11-14 12:33:09 +09:00
</template>
2022-11-21 22:38:10 +09:00
<template v-else-if="attachment.type === 'video'">
<video
:poster="attachment.previewUrl"
controls
2022-11-23 11:16:31 +09:00
border="~ base"
2022-11-21 22:38:10 +09:00
object-cover
:style="{
aspectRatio,
}"
>
<source :src="attachment.url || attachment.previewUrl" type="video/mp4">
</video>
</template>
2022-11-24 13:05:13 +09: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 12:33:09 +09:00
<template v-else>
<div>
TODO:
<pre>{{ attachment }}
</pre>
</div>
2022-11-14 12:33:09 +09:00
</template>
</template>