2023-03-27 05:53:35 +02:00
|
|
|
<script lang="ts">
|
2023-07-01 00:50:47 -04:00
|
|
|
import { imageLoad } from '$lib/utils/image-load';
|
|
|
|
|
import { fade } from 'svelte/transition';
|
|
|
|
|
import { thumbHashToDataURL } from 'thumbhash';
|
|
|
|
|
import { Buffer } from 'buffer';
|
2023-07-18 20:09:43 +02:00
|
|
|
import EyeOffOutline from 'svelte-material-icons/EyeOffOutline.svelte';
|
2023-05-17 13:07:17 -04:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
export let url: string;
|
|
|
|
|
export let altText: string;
|
|
|
|
|
export let heightStyle: string | undefined = undefined;
|
|
|
|
|
export let widthStyle: string;
|
|
|
|
|
export let thumbhash: string | null = null;
|
|
|
|
|
export let curve = false;
|
|
|
|
|
export let shadow = false;
|
|
|
|
|
export let circle = false;
|
2023-07-18 20:09:43 +02:00
|
|
|
export let hidden = false;
|
2023-07-01 00:50:47 -04:00
|
|
|
let complete = false;
|
2023-03-27 05:53:35 +02:00
|
|
|
</script>
|
|
|
|
|
|
2023-06-19 22:21:06 +01:00
|
|
|
<img
|
2023-07-01 00:50:47 -04:00
|
|
|
style:width={widthStyle}
|
|
|
|
|
style:height={heightStyle}
|
2023-07-18 20:09:43 +02:00
|
|
|
style:filter={hidden ? 'grayscale(75%)' : 'none'}
|
2023-07-01 00:50:47 -04:00
|
|
|
src={url}
|
|
|
|
|
alt={altText}
|
2023-07-18 20:09:43 +02:00
|
|
|
class="object-cover transition duration-300"
|
2023-07-01 00:50:47 -04:00
|
|
|
class:rounded-lg={curve}
|
|
|
|
|
class:shadow-lg={shadow}
|
|
|
|
|
class:rounded-full={circle}
|
|
|
|
|
class:opacity-0={!thumbhash && !complete}
|
|
|
|
|
draggable="false"
|
|
|
|
|
use:imageLoad
|
|
|
|
|
on:image-load|once={() => (complete = true)}
|
2023-06-19 22:21:06 +01:00
|
|
|
/>
|
2023-07-18 20:09:43 +02:00
|
|
|
{#if hidden}
|
|
|
|
|
<div class="absolute top-1/2 left-1/2 transform translate-x-[-50%] translate-y-[-50%]">
|
|
|
|
|
<EyeOffOutline size="2em" />
|
|
|
|
|
</div>
|
|
|
|
|
{/if}
|
2023-06-17 23:22:31 -04:00
|
|
|
|
2023-06-19 22:21:06 +01:00
|
|
|
{#if thumbhash && !complete}
|
2023-07-01 00:50:47 -04:00
|
|
|
<img
|
|
|
|
|
style:width={widthStyle}
|
|
|
|
|
style:height={heightStyle}
|
|
|
|
|
src={thumbHashToDataURL(Buffer.from(thumbhash, 'base64'))}
|
|
|
|
|
alt={altText}
|
|
|
|
|
class="absolute object-cover top-0"
|
|
|
|
|
class:rounded-lg={curve}
|
|
|
|
|
class:shadow-lg={shadow}
|
|
|
|
|
class:rounded-full={circle}
|
|
|
|
|
draggable="false"
|
|
|
|
|
out:fade={{ duration: 300 }}
|
|
|
|
|
/>
|
2023-06-17 23:22:31 -04:00
|
|
|
{/if}
|