2023-03-27 05:53:35 +02:00
|
|
|
<script lang="ts">
|
2023-11-29 15:09:22 +00:00
|
|
|
import { onMount, tick } from 'svelte';
|
2023-07-01 00:50:47 -04:00
|
|
|
import { fade } from 'svelte/transition';
|
|
|
|
|
import { thumbHashToDataURL } from 'thumbhash';
|
2024-02-02 04:18:00 +01:00
|
|
|
// eslint-disable-next-line unicorn/prefer-node-protocol
|
2023-07-01 00:50:47 -04:00
|
|
|
import { Buffer } from 'buffer';
|
2023-10-25 09:48:25 -04:00
|
|
|
import { mdiEyeOffOutline } from '@mdi/js';
|
|
|
|
|
import Icon from '$lib/components/elements/icon.svelte';
|
2023-05-17 13:07:17 -04:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
export let url: string;
|
2024-03-03 16:42:17 -05:00
|
|
|
export let altText: string | undefined;
|
2023-09-01 01:25:13 +02:00
|
|
|
export let title: string | null = null;
|
2023-07-01 00:50:47 -04:00
|
|
|
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-28 05:04:20 +02:00
|
|
|
export let border = false;
|
2023-11-28 21:23:27 +01:00
|
|
|
export let preload = true;
|
2023-11-29 15:09:22 +00:00
|
|
|
export let eyeColor: 'black' | 'white' = 'white';
|
|
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
let complete = false;
|
2023-11-29 15:09:22 +00:00
|
|
|
let img: HTMLImageElement;
|
2023-07-23 05:00:43 +02:00
|
|
|
|
2023-11-29 15:09:22 +00:00
|
|
|
onMount(async () => {
|
|
|
|
|
await img.decode();
|
|
|
|
|
await tick();
|
|
|
|
|
complete = true;
|
|
|
|
|
});
|
2023-03-27 05:53:35 +02:00
|
|
|
</script>
|
|
|
|
|
|
2023-06-19 22:21:06 +01:00
|
|
|
<img
|
2023-11-29 15:09:22 +00:00
|
|
|
bind:this={img}
|
2023-11-28 21:23:27 +01:00
|
|
|
loading={preload ? 'eager' : 'lazy'}
|
2023-07-01 00:50:47 -04:00
|
|
|
style:width={widthStyle}
|
|
|
|
|
style:height={heightStyle}
|
2023-07-23 05:00:43 +02:00
|
|
|
style:filter={hidden ? 'grayscale(50%)' : 'none'}
|
|
|
|
|
style:opacity={hidden ? '0.5' : '1'}
|
2023-07-01 00:50:47 -04:00
|
|
|
src={url}
|
|
|
|
|
alt={altText}
|
2023-09-01 01:25:13 +02:00
|
|
|
{title}
|
2023-07-28 05:04:20 +02:00
|
|
|
class="object-cover transition duration-300 {border
|
|
|
|
|
? 'border-[3px] border-immich-dark-primary/80 hover:border-immich-primary'
|
|
|
|
|
: ''}"
|
2023-08-03 16:11:21 +02:00
|
|
|
class:rounded-xl={curve}
|
2023-07-01 00:50:47 -04:00
|
|
|
class:shadow-lg={shadow}
|
|
|
|
|
class:rounded-full={circle}
|
2024-02-08 05:15:51 +01:00
|
|
|
class:aspect-square={circle || !heightStyle}
|
2023-07-01 00:50:47 -04:00
|
|
|
class:opacity-0={!thumbhash && !complete}
|
|
|
|
|
draggable="false"
|
2023-06-19 22:21:06 +01:00
|
|
|
/>
|
2023-07-23 05:00:43 +02:00
|
|
|
|
2023-07-18 20:09:43 +02:00
|
|
|
{#if hidden}
|
2023-07-18 13:19:39 -05:00
|
|
|
<div class="absolute left-1/2 top-1/2 translate-x-[-50%] translate-y-[-50%] transform">
|
2023-12-05 16:43:15 +01:00
|
|
|
<Icon {title} path={mdiEyeOffOutline} size="2em" class="text-{eyeColor}" />
|
2023-07-18 20:09:43 +02:00
|
|
|
</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}
|
2023-09-01 01:25:13 +02:00
|
|
|
{title}
|
2023-07-18 13:19:39 -05:00
|
|
|
class="absolute top-0 object-cover"
|
2023-08-03 16:11:21 +02:00
|
|
|
class:rounded-xl={curve}
|
2023-07-01 00:50:47 -04:00
|
|
|
class:shadow-lg={shadow}
|
|
|
|
|
class:rounded-full={circle}
|
|
|
|
|
draggable="false"
|
|
|
|
|
out:fade={{ duration: 300 }}
|
|
|
|
|
/>
|
2023-06-17 23:22:31 -04:00
|
|
|
{/if}
|