summaryrefslogtreecommitdiff
path: root/packages/integrations/image/components/Image.astro
blob: 326c1bc6c21ca6da613488be6cc0f3d21e467b72 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
---
// @ts-ignore
import loader from 'virtual:image-loader';
import { getImage } from '../src/index.js';
import type { ImageAttributes, ImageMetadata, TransformOptions, OutputFormat } from '../src/types.js';

export interface LocalImageProps extends Omit<TransformOptions, 'src'>, Omit<ImageAttributes, 'src' | 'width' | 'height'> {
	src: ImageMetadata | Promise<{ default: ImageMetadata }>;
}

export interface RemoteImageProps extends TransformOptions, ImageAttributes {
	src: string;
	format: OutputFormat;
	width: number;
	height: number;
}

export type Props = LocalImageProps | RemoteImageProps;

const { loading = "lazy", decoding = "async", ...props } = Astro.props as Props;

const attrs = await getImage(loader, props);
---

<img {...attrs} {loading} {decoding} />

<style>
	img {
		content-visibility: auto;
	}
</style>