2023-03-11 16:52:48 +01:00
|
|
|
<script lang="ts">
|
2023-03-12 04:25:53 +01:00
|
|
|
export let urls: string[];
|
2023-03-11 16:52:48 +01:00
|
|
|
export let alt: string;
|
2023-03-12 04:25:53 +01:00
|
|
|
export let width = 300;
|
2023-03-11 16:52:48 +01:00
|
|
|
|
|
|
|
|
const contentTypeFor = (url: string) => {
|
|
|
|
|
if (url.endsWith(".webp")) {
|
|
|
|
|
return "image/webp";
|
|
|
|
|
} else if (url.endsWith(".jpg") || url.endsWith(".jpeg")) {
|
|
|
|
|
return "image/jpeg";
|
|
|
|
|
} else if (url.endsWith(".png")) {
|
|
|
|
|
return "image/png";
|
|
|
|
|
} else {
|
|
|
|
|
return "application/octet-stream";
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
</script>
|
|
|
|
|
|
2023-03-12 04:25:53 +01:00
|
|
|
{#if urls.length > 0}
|
2023-03-11 16:52:48 +01:00
|
|
|
<picture class="rounded-circle img-fluid">
|
|
|
|
|
{#each urls as url}
|
2023-03-12 04:25:53 +01:00
|
|
|
<source {width} srcSet={url} type={contentTypeFor(url)} />
|
2023-03-11 16:52:48 +01:00
|
|
|
{/each}
|
2023-03-12 04:25:53 +01:00
|
|
|
<img {width} src={urls[0]} {alt} class="rounded-circle img-fluid" />
|
2023-03-11 16:52:48 +01:00
|
|
|
</picture>
|
|
|
|
|
{:else}
|
|
|
|
|
<!-- TODO: actual placeholder that isn't a cat -->
|
2023-03-12 04:25:53 +01:00
|
|
|
<img {width} class="rounded-circle img-fluid" src="https://placekitten.com/512/512" {alt} />
|
2023-03-11 16:52:48 +01:00
|
|
|
{/if}
|