Files
continuwuity/packages/website/src/lib/htmlComponents/img.svelte
T

62 lines
1.5 KiB
Svelte
Raw Normal View History

2024-07-19 15:34:55 +01:00
<script lang="ts">
2024-07-16 20:24:04 +01:00
export let src;
export let alt;
2024-07-16 20:53:09 +01:00
export let title;
2024-07-16 21:50:00 +01:00
export let thumb;
2024-07-19 15:34:55 +01:00
// export let align
// export let small: boolean;
2024-07-16 22:01:35 +01:00
// console.log("imgcmp", thumb);
2024-07-16 21:50:00 +01:00
let className = "";
2024-07-16 20:43:43 +01:00
export { className as class };
2024-07-16 22:12:06 +01:00
let loaded = false
2024-07-20 14:59:59 +01:00
// console.log(thumb)
2024-07-16 20:24:04 +01:00
// import _PastedImage20240716123726Png from "./Pasted%20image%2020240716123726.png?meta";
2024-07-16 20:43:43 +01:00
</script>
2024-07-16 20:24:04 +01:00
2024-07-16 20:43:43 +01:00
<figure class={className}>
2024-07-16 21:50:00 +01:00
<img
{src}
{alt}
{title}
width={thumb?.originalWidth}
height={thumb?.originalHeight}
2024-07-16 22:12:06 +01:00
style:background-image={loaded ? "none" : `url('${thumb?.thumbSrc}')`}
on:load={() => loaded = true}
2024-09-02 19:32:34 +01:00
decoding="async"
2024-09-02 19:32:02 +01:00
style:--aspect-ratio={thumb?.originalWidth / thumb?.originalHeight}
2024-07-16 21:50:00 +01:00
/>
2024-07-16 20:53:09 +01:00
{#if title}
<figcaption>{title}</figcaption>
2024-07-16 20:43:43 +01:00
{/if}
</figure>
2024-07-19 15:34:55 +01:00
<!-- {:else}
<img
{src}
{alt}
{title}
style:float={align}
width={thumb?.originalWidth}
height={thumb?.originalHeight}
style:background-image={loaded ? "none" : `url('${thumb?.thumbSrc}')`}
on:load={() => loaded = true}
/>
{/if} -->
2024-07-16 20:43:43 +01:00
<style>
img {
2024-09-01 16:48:17 +01:00
height: 100%;
2024-07-16 21:50:00 +01:00
background-size: cover;
2024-07-16 22:12:06 +01:00
background-repeat: no-repeat;
2024-07-16 20:43:43 +01:00
display: block;
margin-inline: auto;
2024-09-02 19:32:02 +01:00
max-width: calc(min(100%, 60vh * var(--aspect-ratio)));
2024-07-16 20:43:43 +01:00
}
figure {
text-align: center;
}
figcaption {
font-size: 0.95em;
2024-07-16 21:50:00 +01:00
margin-block: calc(var(--spacing) / 2);
2024-07-16 20:43:43 +01:00
}
</style>