2022-07-01 10:47:48 -05:00
---
// @ts-ignore
2022-07-22 18:01:56 -05:00
import { getImage } from '../dist/index.js';
2022-09-01 16:24:07 -05:00
import { warnForMissingAlt } from './index.js';
2022-07-27 10:39:05 -05:00
import type { ImgHTMLAttributes } from './index.js';
import type { ImageMetadata, TransformOptions, OutputFormat } from '../dist/index.js';
2022-07-01 10:47:48 -05:00
2022-08-05 23:39:26 -05:00
interface LocalImageProps
extends Omit<TransformOptions, 'src'>,
Omit<ImgHTMLAttributes, 'src' | 'width' | 'height'> {
2022-07-01 10:47:48 -05:00
src: ImageMetadata | Promise<{ default: ImageMetadata }>;
2022-09-01 16:24:07 -05: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 10:47:48 -05:00
}
2022-07-27 10:39:05 -05:00
interface RemoteImageProps extends TransformOptions, astroHTML.JSX.ImgHTMLAttributes {
2022-07-01 10:47:48 -05:00
src: string;
2022-09-01 16:24:07 -05: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 08:56:07 -05:00
format?: OutputFormat;
2022-07-01 10:47:48 -05:00
width: number;
height: number;
}
export type Props = LocalImageProps | RemoteImageProps;
2022-08-05 23:39:26 -05:00
const { loading = 'lazy', decoding = 'async', ...props } = Astro.props as Props;
2022-07-01 10:47:48 -05:00
2022-09-01 16:24:07 -05:00
if (props.alt === undefined || props.alt === null) {
warnForMissingAlt();
}
2022-07-22 18:01:56 -05:00
const attrs = await getImage(props);
2022-07-08 16:37:55 -05:00
---
2022-07-01 10:47:48 -05:00
2022-07-08 16:37:55 -05:00
<img {...attrs} {loading} {decoding} />
2022-07-01 10:47:48 -05:00
2022-07-08 16:37:55 -05:00
<style>
img {
content-visibility: auto;
2022-07-01 10:47:48 -05:00
}
2022-07-08 16:37:55 -05:00
</style>