5
5
* LICENSE file in the root directory of this source tree.
6
6
*/
7
7
8
+ /// <reference types="@docusaurus/module-type-aliases" />
9
+
8
10
declare module '@docusaurus/plugin-ideal-image' {
9
11
export type PluginOptions = {
10
12
/**
@@ -51,17 +53,6 @@ declare module '@docusaurus/plugin-ideal-image' {
51
53
export type Options = Partial < PluginOptions > ;
52
54
}
53
55
54
- declare module '@theme/IdealImageLegacy' {
55
- import type { ReactNode } from 'react' ;
56
- import type { ImageProps } from './theme/IdealImageLegacy/types' ;
57
-
58
- export type { IconKey , State } from './theme/IdealImageLegacy/types' ;
59
-
60
- export interface Props extends ImageProps { }
61
-
62
- export default function IdealImageLegacy ( props : ImageProps ) : ReactNode ;
63
- }
64
-
65
56
declare module '@theme/IdealImage' {
66
57
import type { ComponentProps , ReactNode } from 'react' ;
67
58
@@ -85,3 +76,122 @@ declare module '@theme/IdealImage' {
85
76
}
86
77
export default function IdealImage ( props : Props ) : ReactNode ;
87
78
}
79
+
80
+ declare module '@theme/IdealImageLegacy' {
81
+ /**
82
+ * @see https://github.com/endiliey/react-ideal-image/blob/master/index.d.ts
83
+ * Note: the original type definition is WRONG. getIcon & getMessage receive
84
+ * full state object.
85
+ */
86
+
87
+ import type {
88
+ ComponentProps ,
89
+ ComponentType ,
90
+ CSSProperties ,
91
+ ReactNode ,
92
+ } from 'react' ;
93
+
94
+ export type LoadingState = 'initial' | 'loading' | 'loaded' | 'error' ;
95
+
96
+ export type State = {
97
+ pickedSrc : {
98
+ size : number ;
99
+ } ;
100
+ loadInfo : 404 | null ;
101
+ loadState : LoadingState ;
102
+ } ;
103
+
104
+ export type IconKey =
105
+ | 'load'
106
+ | 'loading'
107
+ | 'loaded'
108
+ | 'error'
109
+ | 'noicon'
110
+ | 'offline' ;
111
+
112
+ export type SrcType = {
113
+ width : number ;
114
+ src ?: string ;
115
+ size ?: number ;
116
+ format ?: 'webp' | 'jpeg' | 'png' | 'gif' ;
117
+ } ;
118
+
119
+ type ThemeKey = 'placeholder' | 'img' | 'icon' | 'noscript' ;
120
+
121
+ export interface ImageProps
122
+ extends Omit < ComponentProps < 'img' > , 'srcSet' | 'placeholder' > {
123
+ /**
124
+ * This function decides what icon to show based on the current state of the
125
+ * component.
126
+ */
127
+ getIcon ?: ( state : State ) => IconKey ;
128
+ /**
129
+ * This function decides what message to show based on the icon (returned
130
+ * from `getIcon` prop) and the current state of the component.
131
+ */
132
+ getMessage ?: ( icon : IconKey , state : State ) => string | null ;
133
+ /**
134
+ * This function is called as soon as the component enters the viewport and
135
+ * is used to generate urls based on width and format if `props.srcSet`
136
+ * doesn't provide `src` field.
137
+ */
138
+ getUrl ?: ( srcType : SrcType ) => string ;
139
+ /**
140
+ * The Height of the image in px.
141
+ */
142
+ height : number ;
143
+ /**
144
+ * This provides a map of the icons. By default, the component uses icons
145
+ * from material design, Implemented as React components with the SVG
146
+ * element. You can customize icons
147
+ */
148
+ icons ?: Partial < { [ icon in IconKey ] : ComponentType } > ;
149
+ /**
150
+ * This prop takes one of the 2 options, xhr and image.
151
+ * Read more about it:
152
+ * https://github.com/stereobooster/react-ideal-image/blob/master/introduction.md#cancel-download
153
+ */
154
+ loader ?: 'xhr' | 'image' ;
155
+ /**
156
+ * https://github.com/stereobooster/react-ideal-image/blob/master/introduction.md#lqip
157
+ */
158
+ placeholder : { color : string } | { lqip : string } ;
159
+ /**
160
+ * This function decides if image should be downloaded automatically. The
161
+ * default function returns false for a 2g network, for a 3g network it
162
+ * decides based on `props.threshold` and for a 4g network it returns true
163
+ * by default.
164
+ */
165
+ shouldAutoDownload ?: ( options : {
166
+ connection ?: 'slow-2g' | '2g' | '3g' | '4g' ;
167
+ size ?: number ;
168
+ threshold ?: number ;
169
+ possiblySlowNetwork ?: boolean ;
170
+ } ) => boolean ;
171
+ /**
172
+ * This provides an array of sources of different format and size of the
173
+ * image. Read more about it:
174
+ * https://github.com/stereobooster/react-ideal-image/blob/master/introduction.md#srcset
175
+ */
176
+ srcSet : SrcType [ ] ;
177
+ /**
178
+ * This provides a theme to the component. By default, the component uses
179
+ * inline styles, but it is also possible to use CSS modules and override
180
+ * all styles.
181
+ */
182
+ theme ?: Partial < { [ key in ThemeKey ] : string | CSSProperties } > ;
183
+ /**
184
+ * Tells how much to wait in milliseconds until consider the download to be
185
+ * slow.
186
+ */
187
+ threshold ?: number ;
188
+ /**
189
+ * Width of the image in px.
190
+ */
191
+ width : number ;
192
+ }
193
+
194
+ export interface Props extends ImageProps { }
195
+
196
+ export default function IdealImageLegacy ( props : ImageProps ) : ReactNode ;
197
+ }
0 commit comments