2023-03-27 05:53:35 +02:00
|
|
|
<script lang="ts">
|
2023-06-17 23:22:31 -04:00
|
|
|
import { onMount } from 'svelte';
|
|
|
|
|
import { lazyLoad } from 'unlazy';
|
2023-05-17 13:07:17 -04:00
|
|
|
import { imageLoad } from '$lib/utils/image-load';
|
|
|
|
|
|
2023-03-27 05:53:35 +02:00
|
|
|
export let url: string;
|
|
|
|
|
export let altText: string;
|
2023-05-17 13:07:17 -04:00
|
|
|
export let heightStyle: string | undefined = undefined;
|
2023-03-27 05:53:35 +02:00
|
|
|
export let widthStyle: string;
|
2023-06-17 23:22:31 -04:00
|
|
|
export let thumbhash: string | null = null;
|
2023-05-17 13:07:17 -04:00
|
|
|
export let curve = false;
|
|
|
|
|
export let shadow = false;
|
|
|
|
|
export let circle = false;
|
2023-03-27 05:53:35 +02:00
|
|
|
let loading = true;
|
2023-06-17 23:22:31 -04:00
|
|
|
|
|
|
|
|
let imageElement: HTMLImageElement;
|
|
|
|
|
|
|
|
|
|
onMount(() => {
|
|
|
|
|
if (thumbhash) {
|
|
|
|
|
lazyLoad(imageElement, {
|
|
|
|
|
hash: thumbhash,
|
|
|
|
|
hashType: 'thumbhash'
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
2023-03-27 05:53:35 +02:00
|
|
|
</script>
|
|
|
|
|
|
2023-06-17 23:22:31 -04:00
|
|
|
{#if thumbhash}
|
|
|
|
|
<img
|
|
|
|
|
style:width={widthStyle}
|
|
|
|
|
style:height={heightStyle}
|
|
|
|
|
data-src={url}
|
|
|
|
|
alt={altText}
|
|
|
|
|
class="object-cover"
|
|
|
|
|
class:rounded-lg={curve}
|
|
|
|
|
class:shadow-lg={shadow}
|
|
|
|
|
class:rounded-full={circle}
|
|
|
|
|
draggable="false"
|
|
|
|
|
bind:this={imageElement}
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
<!-- not everthing yet has thumbhash support so the old method is kept -->
|
|
|
|
|
{:else}
|
|
|
|
|
<img
|
|
|
|
|
style:width={widthStyle}
|
|
|
|
|
style:height={heightStyle}
|
|
|
|
|
src={url}
|
|
|
|
|
alt={altText}
|
|
|
|
|
class="object-cover transition-opacity duration-300"
|
|
|
|
|
class:rounded-lg={curve}
|
|
|
|
|
class:shadow-lg={shadow}
|
|
|
|
|
class:rounded-full={circle}
|
|
|
|
|
class:opacity-0={loading}
|
|
|
|
|
draggable="false"
|
|
|
|
|
use:imageLoad
|
|
|
|
|
on:image-load|once={() => (loading = false)}
|
|
|
|
|
/>
|
|
|
|
|
{/if}
|