460f9e7329
* Fix duplicate alt attribute on Picture component. * Create tidy-buses-mate.md --------- Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com>
45 lines
836 B
Text
45 lines
836 B
Text
---
|
|
import { getPicture } from '../dist/index.js';
|
|
import { warnForMissingAlt } from './index.js';
|
|
import type { PictureComponentLocalImageProps, PictureComponentRemoteImageProps } from './index.js';
|
|
|
|
export type Props = PictureComponentLocalImageProps | PictureComponentRemoteImageProps;
|
|
|
|
const {
|
|
src,
|
|
alt,
|
|
sizes,
|
|
widths,
|
|
aspectRatio,
|
|
fit,
|
|
background,
|
|
position,
|
|
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>
|
|
{sources.map((attrs) => <source {...attrs} {sizes} />)}
|
|
<img {...image} {loading} {decoding} {...attrs} />
|
|
</picture>
|