You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
svelte/sites/svelte.dev/src/routes/_components/Image.svelte

32 lines
536 B

<script>
/** @type {ImageToolsPictureData} */
export let src;
/** @type {string} */
export let alt;
export let lazy = false;
</script>
<picture>
{#each Object.entries(src.sources) as [format, images]}
<source srcset={images.map((i) => `${i.src} ${i.w}w`).join(', ')} type="image/{format}" />
{/each}
<img
loading={lazy ? 'lazy' : 'eager'}
height={src.img.h}
width={src.img.w}
src={src.img.src}
{alt}
/>
</picture>
<style>
img {
display: block;
width: 100%;
height: auto;
object-fit: cover;
}
</style>