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-30 12:27:19 +09:00
|
|
|
attachments?: Attachment[]
|
2022-11-14 12:33:09 +09:00
|
|
|
}>()
|
2022-11-21 22:21:53 +09:00
|
|
|
|
2022-12-01 02:19:35 +09:00
|
|
|
const src = $computed(() => attachment.previewUrl || attachment.url || attachment.remoteUrl!)
|
|
|
|
const srcset = $computed(() => [
|
|
|
|
[src, attachment.meta?.original?.width],
|
|
|
|
[attachment.previewUrl, attachment.meta?.small?.width],
|
|
|
|
].filter(([url]) => url).map(([url, size]) => `${url} ${size}w`).join(', '))
|
2022-11-29 14:01:51 +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-12-01 03:22:15 +09:00
|
|
|
|
|
|
|
const objectPosition = computed(() => {
|
|
|
|
return [attachment.meta?.focus?.x, attachment.meta?.focus?.y]
|
|
|
|
.map(v => v ? `${v * 100}%` : '50%')
|
|
|
|
.join(' ')
|
|
|
|
})
|
2022-11-14 12:33:09 +09:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2022-11-25 23:31:33 +09:00
|
|
|
<template v-if="attachment.type === 'video'">
|
2022-11-21 22:38:10 +09:00
|
|
|
<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
|
2022-12-01 02:19:35 +09:00
|
|
|
:width="attachment.meta?.original?.width"
|
|
|
|
:height="attachment.meta?.original?.height"
|
2022-11-21 22:38:10 +09:00
|
|
|
:style="{
|
|
|
|
aspectRatio,
|
2022-12-01 03:22:15 +09:00
|
|
|
objectPosition,
|
2022-11-21 22:38:10 +09:00
|
|
|
}"
|
|
|
|
>
|
|
|
|
<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
|
2022-12-01 02:19:35 +09:00
|
|
|
:width="attachment.meta?.original?.width"
|
|
|
|
:height="attachment.meta?.original?.height"
|
2022-11-24 13:05:13 +09:00
|
|
|
:style="{
|
|
|
|
aspectRatio,
|
2022-12-01 03:22:15 +09:00
|
|
|
objectPosition,
|
2022-11-24 13:05:13 +09:00
|
|
|
}"
|
|
|
|
>
|
|
|
|
<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>
|
2022-11-26 08:46:25 +09:00
|
|
|
<button
|
|
|
|
focus:outline-none
|
|
|
|
focus:ring="2 primary inset"
|
2022-11-26 03:13:44 +09:00
|
|
|
rounded-lg
|
2022-11-30 06:24:26 +09:00
|
|
|
aria-label="Open image preview dialog"
|
2022-11-30 12:27:19 +09:00
|
|
|
@click="openMediaPreview(attachments ? attachments : [attachment], attachments?.indexOf(attachment) || 0)"
|
2022-11-26 08:46:25 +09:00
|
|
|
>
|
|
|
|
<CommonBlurhash
|
|
|
|
:blurhash="attachment.blurhash"
|
|
|
|
class="status-attachment-image"
|
2022-11-29 14:01:51 +09:00
|
|
|
:src="src"
|
2022-12-01 02:19:35 +09:00
|
|
|
:srcset="srcset"
|
|
|
|
:width="attachment.meta?.original?.width"
|
|
|
|
:height="attachment.meta?.original?.height"
|
2022-11-26 08:46:25 +09:00
|
|
|
:alt="attachment.description!"
|
|
|
|
:style="{
|
|
|
|
aspectRatio,
|
2022-12-01 03:22:15 +09:00
|
|
|
objectPosition,
|
2022-11-26 08:46:25 +09:00
|
|
|
}"
|
|
|
|
border="~ base"
|
|
|
|
rounded-lg
|
|
|
|
h-full
|
|
|
|
w-full
|
|
|
|
object-cover
|
|
|
|
/>
|
|
|
|
</button>
|
2022-11-14 12:33:09 +09:00
|
|
|
</template>
|
|
|
|
</template>
|