-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathtypes.ts
More file actions
98 lines (90 loc) · 2.29 KB
/
Copy pathtypes.ts
File metadata and controls
98 lines (90 loc) · 2.29 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/**
* Options to transform an image URL
*/
export interface UrlTransformerOptions {
/** The original URL of the image */
url: string | URL;
/** The desired width of the image */
width?: number;
/** The desired height of the image */
height?: number;
/** The desired format of the image. Default is auto-detect */
format?: string;
/** Recursively find the the canonical CDN for a source image. Default is true */
recursive?: boolean;
/** Specify a CDN rather than auto-detecting */
cdn?: ImageCdn;
/** CDN-specific options. */
cdnOptions?: CdnOptions;
}
export interface CanonicalCdnUrl {
/** The source image URL */
url: string | URL;
/** The CDN to use */
cdn: ImageCdn;
}
/**
* Asks a CDN if there is a different canonical CDN for the given URL
* @param url The URL to check
* @returns The canonical CDN URL, or false if the given CDN will handle it itself
*/
export interface ShouldDelegateUrl {
(url: string | URL): CanonicalCdnUrl | false;
}
export type CdnOptions = {
[key in ImageCdn]: Record<string, unknown>;
};
export interface UrlGeneratorOptions<TParams = Record<string, string>> {
base: string | URL;
width?: number;
height?: number;
format?: string;
params?: TParams;
}
export interface UrlGenerator<TParams = Record<string, string>> {
(options: UrlGeneratorOptions<TParams>): URL | string;
}
export interface ParsedUrl<TParams = Record<string, string>> {
/** The URL of the image with no transforms */
base: string;
/** The width of the image */
width?: number;
/** The height of the image */
height?: number;
/** The format of the image */
format?: string;
/** Other CDN-specific parameters */
params?: TParams;
cdn: ImageCdn;
}
/**
* Parse an image URL into its components
*/
export interface UrlTransformer {
(options: UrlTransformerOptions): string | URL | undefined;
}
export interface UrlParser<
TParams = Record<string, unknown>,
> {
(url: string | URL): ParsedUrl<TParams>;
}
export type ImageCdn =
| "contentful"
| "builder.io"
| "cloudinary"
| "cloudflare"
| "imgix"
| "shopify"
| "wordpress"
| "bunny"
| "storyblok"
| "kontent.ai"
| "vercel"
| "nextjs"
| "scene7"
| "keycdn"
| "directus"
| "imageengine"
| "contentstack"
| "cloudflare_images";
export type SupportedImageCdn = ImageCdn;