astro/packages/integrations/image/components/Picture.astro

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

46 lines
836 B
Text
Raw Normal View History

---
import { getPicture } from '../dist/index.js';
import { warnForMissingAlt } from './index.js';
import type { PictureComponentLocalImageProps, PictureComponentRemoteImageProps } from './index.js';
export type Props = PictureComponentLocalImageProps | PictureComponentRemoteImageProps;
2022-08-06 04:39:26 +00:00
const {
src,
alt,
sizes,
widths,
aspectRatio,
fit,
background,
position,
2022-08-06 04:39:26 +00:00
formats = ['avif', 'webp'],
loading = 'lazy',
decoding = 'async',
...attrs
} = Astro.props;
if (alt === undefined || alt === null) {
warnForMissingAlt();
}
const { image, sources } = await getPicture({
src,
widths,
formats,
aspectRatio,
fit,
background,
position,
alt,
});
delete image.width;
delete image.height;
---
<picture>
2022-08-06 04:39:26 +00:00
{sources.map((attrs) => <source {...attrs} {sizes} />)}
<img {...image} {loading} {decoding} {...attrs} />
</picture>