astro/packages/integrations/image/components/Image.astro
Tony Sullivan ef9345767b
WIP: [image] Fixing SSR support and improving error validation (#4013)
* fix: SSR builds were hitting an undefined error and skipping the step for copying original assets

* chore: update lockfile

* chore: adding better error validation to getImage and getPicture

* refactor: cleaning up index.ts

* refactor: moving SSG build generation logic out of the integration

* splitting build to ssg & ssr helpers, re-enabling SSR image build tests

* sharp should automatically rotate based on EXIF

* cleaning up how static images are tracked for SSG builds

* undo unrelated mod.d.ts change

* chore: add changeset
2022-07-22 23:01:56 +00:00

30 lines
779 B
Text

---
// @ts-ignore
import { getImage } from '../dist/index.js';
import type { ImageAttributes, ImageMetadata, TransformOptions, OutputFormat } from '../dist/types';
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(props);
---
<img {...attrs} {loading} {decoding} />
<style>
img {
content-visibility: auto;
}
</style>