fix(ui): use small images + srcsets (#254)

This commit is contained in:
Daniel Roe 2022-11-30 17:19:35 +00:00 committed by GitHub
parent 4ed1816806
commit e76127651a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -7,7 +7,11 @@ const { attachment } = defineProps<{
attachments?: Attachment[] attachments?: Attachment[]
}>() }>()
const src = $computed(() => attachment.remoteUrl || attachment.url || attachment.previewUrl!) 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(', '))
const rawAspectRatio = computed(() => { const rawAspectRatio = computed(() => {
if (attachment.meta?.original?.aspect) if (attachment.meta?.original?.aspect)
@ -31,6 +35,8 @@ const aspectRatio = computed(() => {
controls controls
border="~ base" border="~ base"
object-cover object-cover
:width="attachment.meta?.original?.width"
:height="attachment.meta?.original?.height"
:style="{ :style="{
aspectRatio, aspectRatio,
}" }"
@ -45,6 +51,8 @@ const aspectRatio = computed(() => {
autoplay autoplay
border="~ base" border="~ base"
object-cover object-cover
:width="attachment.meta?.original?.width"
:height="attachment.meta?.original?.height"
:style="{ :style="{
aspectRatio, aspectRatio,
}" }"
@ -69,6 +77,9 @@ const aspectRatio = computed(() => {
:blurhash="attachment.blurhash" :blurhash="attachment.blurhash"
class="status-attachment-image" class="status-attachment-image"
:src="src" :src="src"
:srcset="srcset"
:width="attachment.meta?.original?.width"
:height="attachment.meta?.original?.height"
:alt="attachment.description!" :alt="attachment.description!"
:style="{ :style="{
aspectRatio, aspectRatio,