-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Expand file tree
/
Copy pathplugin-ideal-image.d.ts
More file actions
197 lines (180 loc) · 5.59 KB
/
plugin-ideal-image.d.ts
File metadata and controls
197 lines (180 loc) · 5.59 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/// <reference types="@docusaurus/module-type-aliases" />
declare module '@docusaurus/plugin-ideal-image' {
export type PluginOptions = {
/**
* Filename template for output files.
*/
name?: string;
/**
* Specify all widths you want to use; if a specified size exceeds the
* original image's width, the latter will be used (i.e. images won't be
* scaled up).
*/
sizes?: number[];
/**
* Specify one width you want to use; if the specified size exceeds the
* original image's width, the latter will be used (i.e. images won't be
* scaled up)
*/
size?: number;
/**
* As an alternative to manually specifying `sizes`, you can specify `min`,
* `max` and `steps`, and the `sizes` will be generated for you.
*/
min?: number;
/**
* @see {@link PluginOptions.min}
*/
max?: number;
/**
* Configure the number of images generated between `min` and `max`
* (inclusive)
*/
steps?: number;
/**
* JPEG compression quality
*/
quality?: number;
/**
* You can test ideal image behavior in dev mode by setting this to `false`.
* Tip: use network throttling in your browser to simulate slow networks.
*/
disableInDev?: boolean;
};
export type Options = Partial<PluginOptions>;
}
declare module '@theme/IdealImage' {
import type {ComponentProps, ReactNode} from 'react';
export type SrcType = {
width: number;
path?: string;
size?: number;
format?: 'webp' | 'jpeg' | 'png' | 'gif';
};
export type SrcImage = {
height?: number;
width?: number;
preSrc: string;
src: string;
images: SrcType[];
};
export interface Props extends ComponentProps<'img'> {
readonly img: {default: string} | {src: SrcImage; preSrc: string} | string;
}
export default function IdealImage(props: Props): ReactNode;
}
declare module '@theme/IdealImageLegacy' {
/**
* @see https://github.com/endiliey/react-ideal-image/blob/master/index.d.ts
* Note: the original type definition is WRONG. getIcon & getMessage receive
* full state object.
*/
import type {
ComponentProps,
ComponentType,
CSSProperties,
ReactNode,
} from 'react';
export type LoadingState = 'initial' | 'loading' | 'loaded' | 'error';
export type State = {
pickedSrc: {
size: number;
};
loadInfo: 404 | null;
loadState: LoadingState;
};
export type IconKey =
| 'load'
| 'loading'
| 'loaded'
| 'error'
| 'noicon'
| 'offline';
export type SrcType = {
width: number;
src?: string;
size?: number;
format?: 'webp' | 'jpeg' | 'png' | 'gif';
};
type ThemeKey = 'placeholder' | 'img' | 'icon' | 'noscript';
export interface ImageProps
extends Omit<ComponentProps<'img'>, 'srcSet' | 'placeholder'> {
/**
* This function decides what icon to show based on the current state of the
* component.
*/
getIcon?: (state: State) => IconKey;
/**
* This function decides what message to show based on the icon (returned
* from `getIcon` prop) and the current state of the component.
*/
getMessage?: (icon: IconKey, state: State) => string | null;
/**
* This function is called as soon as the component enters the viewport and
* is used to generate urls based on width and format if `props.srcSet`
* doesn't provide `src` field.
*/
getUrl?: (srcType: SrcType) => string;
/**
* The Height of the image in px.
*/
height: number;
/**
* This provides a map of the icons. By default, the component uses icons
* from material design, Implemented as React components with the SVG
* element. You can customize icons
*/
icons?: Partial<{[icon in IconKey]: ComponentType}>;
/**
* This prop takes one of the 2 options, xhr and image.
* Read more about it:
* https://github.com/stereobooster/react-ideal-image/blob/master/introduction.md#cancel-download
*/
loader?: 'xhr' | 'image';
/**
* https://github.com/stereobooster/react-ideal-image/blob/master/introduction.md#lqip
*/
placeholder: {color: string} | {lqip: string};
/**
* This function decides if image should be downloaded automatically. The
* default function returns false for a 2g network, for a 3g network it
* decides based on `props.threshold` and for a 4g network it returns true
* by default.
*/
shouldAutoDownload?: (options: {
connection?: 'slow-2g' | '2g' | '3g' | '4g';
size?: number;
threshold?: number;
possiblySlowNetwork?: boolean;
}) => boolean;
/**
* This provides an array of sources of different format and size of the
* image. Read more about it:
* https://github.com/stereobooster/react-ideal-image/blob/master/introduction.md#srcset
*/
srcSet: SrcType[];
/**
* This provides a theme to the component. By default, the component uses
* inline styles, but it is also possible to use CSS modules and override
* all styles.
*/
theme?: Partial<{[key in ThemeKey]: string | CSSProperties}>;
/**
* Tells how much to wait in milliseconds until consider the download to be
* slow.
*/
threshold?: number;
/**
* Width of the image in px.
*/
width: number;
}
export interface Props extends ImageProps {}
export default function IdealImageLegacy(props: ImageProps): ReactNode;
}