2022-07-01 15:47:48 +00:00
---
// @ts-ignore
2022-07-22 23:01:56 +00:00
import { getImage } from '../dist/index.js';
2022-09-01 21:24:07 +00:00
import { warnForMissingAlt } from './index.js';
2022-07-27 15:39:05 +00:00
import type { ImgHTMLAttributes } from './index.js';
import type { ImageMetadata, TransformOptions, OutputFormat } from '../dist/index.js';
2022-07-01 15:47:48 +00:00
2022-08-06 04:39:26 +00:00
interface LocalImageProps
extends Omit<TransformOptions, 'src'>,
Omit<ImgHTMLAttributes, 'src' | 'width' | 'height'> {
2022-07-01 15:47:48 +00:00
src: ImageMetadata | Promise<{ default: ImageMetadata }>;
2022-09-01 21:24:07 +00:00
/** Defines an alternative text description of the image. Set to an empty string (alt="") if the image is not a key part of the content (it's decoration or a tracking pixel). */
alt: string;
2022-07-01 15:47:48 +00:00
}
2022-07-27 15:39:05 +00:00
interface RemoteImageProps extends TransformOptions, astroHTML.JSX.ImgHTMLAttributes {
2022-07-01 15:47:48 +00:00
src: string;
2022-09-01 21:24:07 +00:00
/** Defines an alternative text description of the image. Set to an empty string (alt="") if the image is not a key part of the content (it's decoration or a tracking pixel). */
alt: string;
2022-09-07 13:56:07 +00:00
format?: OutputFormat;
2022-07-01 15:47:48 +00:00
width: number;
height: number;
}
export type Props = LocalImageProps | RemoteImageProps;
2022-08-06 04:39:26 +00:00
const { loading = 'lazy', decoding = 'async', ...props } = Astro.props as Props;
2022-07-01 15:47:48 +00:00
2022-09-01 21:24:07 +00:00
if (props.alt === undefined || props.alt === null) {
warnForMissingAlt();
}
2022-07-22 23:01:56 +00:00
const attrs = await getImage(props);
2022-07-08 21:37:55 +00:00
---
2022-07-01 15:47:48 +00:00
2022-07-08 21:37:55 +00:00
<img {...attrs} {loading} {decoding} />
2022-07-01 15:47:48 +00:00
2022-07-08 21:37:55 +00:00
<style>
img {
content-visibility: auto;
2022-07-01 15:47:48 +00:00
}
2022-07-08 21:37:55 +00:00
</style>