2020-07-18 17:24:07 +02:00
|
|
|
<template>
|
2023-05-28 05:24:38 +02:00
|
|
|
<canvas
|
|
|
|
v-if="!loaded"
|
|
|
|
ref="canvas"
|
|
|
|
:width="size"
|
|
|
|
:height="size"
|
2023-07-14 04:06:57 +02:00
|
|
|
:title="title"
|
2023-05-28 05:24:38 +02:00
|
|
|
/>
|
|
|
|
<img
|
|
|
|
v-if="src"
|
|
|
|
:src="src"
|
2023-07-14 04:06:57 +02:00
|
|
|
:title="title"
|
2023-05-28 05:24:38 +02:00
|
|
|
:type="type"
|
|
|
|
:alt="alt"
|
2023-07-21 18:05:45 +02:00
|
|
|
:class="{
|
2023-07-28 20:35:58 +02:00
|
|
|
cover,
|
|
|
|
wide: largestDimension === 'width',
|
|
|
|
tall: largestDimension === 'height',
|
|
|
|
}"
|
2023-05-28 05:24:38 +02:00
|
|
|
:style="{ 'object-fit': cover ? 'cover' : null }"
|
|
|
|
loading="lazy"
|
|
|
|
@load="onLoad"
|
|
|
|
/>
|
2024-03-25 05:29:06 +01:00
|
|
|
<i
|
|
|
|
class="alt-indicator"
|
|
|
|
:class="icon('ph-subtitles')"
|
2024-03-25 15:32:20 +01:00
|
|
|
v-if="alt && showAltIndicator"
|
2024-03-25 05:43:08 +01:00
|
|
|
v-tooltip.noLabel="
|
|
|
|
`${i18n.ts.alt}: ${
|
2024-03-28 06:26:09 +01:00
|
|
|
alt.length > 200 ? alt.trim().slice(0, 200) + '...' : alt.trim()
|
2024-03-25 05:43:08 +01:00
|
|
|
}`
|
|
|
|
"
|
2024-03-25 05:29:06 +01:00
|
|
|
></i>
|
2020-07-18 17:24:07 +02:00
|
|
|
</template>
|
|
|
|
|
2022-01-15 22:59:35 +01:00
|
|
|
<script lang="ts" setup>
|
2023-08-12 02:44:46 +02:00
|
|
|
import { onMounted, ref } from "vue";
|
2023-07-14 04:06:57 +02:00
|
|
|
import { decodeBlurHash } from "fast-blurhash";
|
2024-03-25 05:29:06 +01:00
|
|
|
import icon from "@/scripts/icon";
|
2024-03-25 05:43:08 +01:00
|
|
|
import { i18n } from "@/i18n";
|
2020-07-18 17:24:07 +02:00
|
|
|
|
2023-04-08 02:01:42 +02:00
|
|
|
const props = withDefaults(
|
|
|
|
defineProps<{
|
|
|
|
src?: string | null;
|
|
|
|
hash?: string;
|
2024-03-25 05:29:06 +01:00
|
|
|
alt?: string | null;
|
2023-04-08 02:01:42 +02:00
|
|
|
type?: string | null;
|
|
|
|
title?: string | null;
|
|
|
|
size?: number;
|
|
|
|
cover?: boolean;
|
2023-07-28 20:35:58 +02:00
|
|
|
largestDimension?: "width" | "height";
|
2024-03-28 06:26:09 +01:00
|
|
|
showAltIndicator?: boolean;
|
2023-04-08 02:01:42 +02:00
|
|
|
}>(),
|
|
|
|
{
|
|
|
|
src: null,
|
|
|
|
type: null,
|
2024-03-25 05:29:06 +01:00
|
|
|
alt: null,
|
2023-04-08 02:01:42 +02:00
|
|
|
title: null,
|
|
|
|
size: 64,
|
|
|
|
cover: true,
|
2024-03-28 06:26:09 +01:00
|
|
|
showAltIndicator: false,
|
2023-07-06 03:28:27 +02:00
|
|
|
},
|
2023-04-08 02:01:42 +02:00
|
|
|
);
|
2020-07-18 17:24:07 +02:00
|
|
|
|
2023-08-12 02:44:46 +02:00
|
|
|
const canvas = ref<HTMLCanvasElement>();
|
2023-09-02 01:27:33 +02:00
|
|
|
const loaded = ref(false);
|
2020-07-18 17:24:07 +02:00
|
|
|
|
2023-07-14 04:06:57 +02:00
|
|
|
function draw() {
|
2023-08-12 02:44:46 +02:00
|
|
|
if (props.hash == null || canvas.value == null) return;
|
2023-07-14 04:06:57 +02:00
|
|
|
const pixels = decodeBlurHash(props.hash, props.size, props.size);
|
2023-08-12 02:44:46 +02:00
|
|
|
const ctx = canvas.value.getContext("2d");
|
2022-01-15 22:59:35 +01:00
|
|
|
const imageData = ctx!.createImageData(props.size, props.size);
|
|
|
|
imageData.data.set(pixels);
|
|
|
|
ctx!.putImageData(imageData, 0, 0);
|
|
|
|
}
|
2020-07-18 17:24:07 +02:00
|
|
|
|
2022-01-15 22:59:35 +01:00
|
|
|
function onLoad() {
|
2023-08-12 02:44:46 +02:00
|
|
|
loaded.value = true;
|
2022-01-15 22:59:35 +01:00
|
|
|
}
|
2020-07-18 17:24:07 +02:00
|
|
|
|
2022-01-15 22:59:35 +01:00
|
|
|
onMounted(() => {
|
|
|
|
draw();
|
2020-07-18 17:24:07 +02:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
2023-05-28 05:24:38 +02:00
|
|
|
canvas,
|
|
|
|
img {
|
|
|
|
display: block;
|
2023-07-21 16:06:24 +02:00
|
|
|
max-width: 100%;
|
|
|
|
max-height: 100%;
|
2023-05-28 05:24:38 +02:00
|
|
|
}
|
2020-07-18 17:24:07 +02:00
|
|
|
|
2023-05-28 05:24:38 +02:00
|
|
|
canvas {
|
|
|
|
position: absolute;
|
|
|
|
inset: 0;
|
|
|
|
object-fit: cover;
|
2023-07-21 16:06:24 +02:00
|
|
|
width: 100%;
|
|
|
|
height: 100%;
|
2023-05-28 05:24:38 +02:00
|
|
|
}
|
2020-10-17 13:12:00 +02:00
|
|
|
|
2023-05-28 05:24:38 +02:00
|
|
|
img {
|
|
|
|
object-fit: contain;
|
2023-07-21 18:05:45 +02:00
|
|
|
|
2023-07-28 20:35:58 +02:00
|
|
|
&.wide {
|
|
|
|
width: 100%;
|
|
|
|
}
|
2023-07-21 18:05:45 +02:00
|
|
|
|
2023-07-28 20:35:58 +02:00
|
|
|
&.tall {
|
|
|
|
height: 100%;
|
|
|
|
}
|
2020-07-18 17:24:07 +02:00
|
|
|
}
|
2024-03-25 05:29:06 +01:00
|
|
|
|
|
|
|
i.alt-indicator {
|
|
|
|
display: flex;
|
|
|
|
gap: 4px;
|
|
|
|
position: absolute;
|
|
|
|
border-radius: 6px;
|
|
|
|
overflow: hidden;
|
|
|
|
top: 0;
|
|
|
|
right: 0;
|
|
|
|
background-color: var(--accentedBg);
|
|
|
|
-webkit-backdrop-filter: var(--blur, blur(15px));
|
|
|
|
backdrop-filter: var(--blur, blur(15px));
|
|
|
|
color: var(--accent);
|
2024-03-25 05:43:08 +01:00
|
|
|
font-size: 1em;
|
2024-03-25 05:29:06 +01:00
|
|
|
padding: 6px 8px;
|
|
|
|
text-align: center;
|
|
|
|
}
|
2020-07-18 17:24:07 +02:00
|
|
|
</style>
|