@@ -2,34 +2,38 @@ import type { ImgHTMLAttributes } from '@astrojs/image/components';
2
2
import type { OutputFormat , TransformOptions } from '@astrojs/image/dist/loaders' ;
3
3
import type { ImageMetadata } from '@astrojs/image/dist/vite-plugin-astro-image' ;
4
4
5
- type AspectRatio = TransformOptions [ 'aspectRatio' ] ;
5
+ export type { ImageMetadata } ;
6
6
7
- interface ImageProps
7
+ export type AspectRatio = TransformOptions [ 'aspectRatio' ] ;
8
+ export type Background = TransformOptions [ 'background' ] ;
9
+ export type Decoding = HTMLImageElement [ 'decoding' ] ;
10
+ export type Fit = TransformOptions [ 'fit' ] ;
11
+ export type Format = TransformOptions [ 'format' ] ;
12
+ export type Loading = HTMLImageElement [ 'loading' ] ;
13
+ export type Position = TransformOptions [ 'position' ] ;
14
+
15
+ export interface ImageProps
8
16
extends Omit < TransformOptions , 'src' > ,
9
17
Omit < ImgHTMLAttributes , 'slot' | 'alt' | 'src' | 'width' | 'height' > {
10
18
/** 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). */
11
19
alt : string ;
12
20
src : string | ImageMetadata | Promise < { default : ImageMetadata } > ;
13
21
}
14
22
15
- interface BasePictureProps extends Omit < ImageProps , 'format' > {
23
+ /**
24
+ * The Picture environment tries to resolve the src and calls a user callback,
25
+ * allowing to transform the props, before optimizing the image according to
26
+ * the transformed properties.
27
+ */
28
+ export interface PictureProps extends Omit < ImageProps , 'format' > {
16
29
widths ?: number [ ] ;
17
30
formats ?: OutputFormat [ ] ;
31
+ callback ?: ( props : CallbackProps ) => void | Promise < void > ;
18
32
}
19
33
20
- interface CallbackProps extends Omit < BasePictureProps , 'src' > {
34
+ /**
35
+ * We guarantee, that src is resolved before any callback is called.
36
+ */
37
+ export interface CallbackProps extends Omit < PictureProps , 'src' | 'callback' > {
21
38
src : ImageMetadata ;
22
39
}
23
-
24
- interface PictureProps extends BasePictureProps {
25
- callback ?: ( props : CallbackProps ) => void | Promise < void > ;
26
- }
27
-
28
- export type {
29
- //
30
- AspectRatio ,
31
- CallbackProps ,
32
- ImageMetadata ,
33
- ImageProps ,
34
- PictureProps ,
35
- } ;
0 commit comments