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