2022-07-08 16:37:55 -05:00
|
|
|
---
|
2022-07-22 18:01:56 -05:00
|
|
|
import { getPicture } from '../dist/index.js';
|
2022-09-01 16:24:07 -05:00
|
|
|
import { warnForMissingAlt } from './index.js';
|
2023-01-17 21:41:50 -05:00
|
|
|
import type { PictureComponentLocalImageProps, PictureComponentRemoteImageProps } from './index.js';
|
2022-07-08 16:37:55 -05:00
|
|
|
|
2023-01-17 21:41:50 -05:00
|
|
|
export type Props = PictureComponentLocalImageProps | PictureComponentRemoteImageProps;
|
2022-07-08 16:37:55 -05:00
|
|
|
|
2022-08-05 23:39:26 -05:00
|
|
|
const {
|
|
|
|
src,
|
|
|
|
alt,
|
|
|
|
sizes,
|
|
|
|
widths,
|
|
|
|
aspectRatio,
|
2022-09-09 15:13:59 -05:00
|
|
|
fit,
|
2022-09-07 12:22:11 -05:00
|
|
|
background,
|
2022-09-09 15:13:59 -05:00
|
|
|
position,
|
2022-08-05 23:39:26 -05:00
|
|
|
formats = ['avif', 'webp'],
|
|
|
|
loading = 'lazy',
|
|
|
|
decoding = 'async',
|
|
|
|
...attrs
|
2023-01-17 21:41:50 -05:00
|
|
|
} = Astro.props;
|
2022-07-08 16:37:55 -05:00
|
|
|
|
2022-09-01 16:24:07 -05:00
|
|
|
if (alt === undefined || alt === null) {
|
|
|
|
warnForMissingAlt();
|
|
|
|
}
|
|
|
|
|
2022-09-09 15:13:59 -05:00
|
|
|
const { image, sources } = await getPicture({
|
|
|
|
src,
|
|
|
|
widths,
|
|
|
|
formats,
|
|
|
|
aspectRatio,
|
|
|
|
fit,
|
|
|
|
background,
|
|
|
|
position,
|
2023-01-17 21:41:50 -05:00
|
|
|
alt,
|
2022-09-09 15:13:59 -05:00
|
|
|
});
|
2022-09-22 16:01:38 -05:00
|
|
|
|
|
|
|
delete image.width;
|
|
|
|
delete image.height;
|
2022-07-08 16:37:55 -05:00
|
|
|
---
|
|
|
|
|
2022-10-20 14:42:36 -05:00
|
|
|
<picture>
|
2022-08-05 23:39:26 -05:00
|
|
|
{sources.map((attrs) => <source {...attrs} {sizes} />)}
|
2022-10-20 14:42:36 -05:00
|
|
|
<img {...image} {loading} {decoding} {alt} {...attrs} />
|
2022-07-08 16:37:55 -05:00
|
|
|
</picture>
|