lazyload.d.ts
10.2 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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
interface ILazyLoadOptions {
/**
* The CSS selector of the elements to load lazily,
* which will be selected as descendants of the container object.
* @default ".lazy"
*/
elements_selector?: string;
/**
* The scrolling container of the elements in the `elements_selector` option.
*
* @default document
*/
container?: HTMLElement;
/**
* A number of pixels representing the outer distance off the scrolling area
* from which to start loading the elements.
*
* @default "300 0"
*/
threshold?: number;
/**
*
* Similar to threshold, but accepting multiple values and both px and % units.
* It maps directly to the rootMargin property of IntersectionObserver (read more),
* so it must be a string with a syntax similar to the CSS margin property.
* You can use it when you need to have different thresholds for the scrolling area.
* It overrides threshold when passed.
*
* @default null
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserver/rootMargin
*/
thresholds?: string;
/**
* The name of the data attribute containing the element URL to load,
* excluding the `"data-"` part.
* E.g. if your data attribute is named `"data-src"`,
* just pass `"src"`
*
* @default "src"
*/
data_src?: string;
/**
* The name of the data attribute containing the image URL set to load,
* in either img and source tags,
* excluding the "data-" part.
* E.g. if your data attribute is named `"data-srcset"`,
* just pass `"srcset"`
*
* @default "srcset"
*/
data_srcset?: string;
/**
* The name of the data attribute containing the sizes attribute to use, excluding the `"data-"` part.
* E.g. if your data attribute is named `"data-sizes"`, just pass `"sizes"`
*
* @default sizes
*/
data_sizes?: string;
/**
* The name of the data attribute containing the URL of `background-image` to load lazily,
* excluding the `"data-"` part.
* E.g. if your data attribute is named `"data-bg"`, just pass `"bg"`.
* The attribute value must be a valid value for `background-image`,
* including the `url()` part of the CSS instruction.
*
*
* @default "bg"
*/
data_bg?: string;
/**
* The name of the data attribute containing the URL of `background-image`
* to load lazily on HiDPI screens, excluding the `"data-"` part.
* E.g. if your data attribute is named `"data-bg-hidpi"`, just pass `"bg-hidpi"`.
* The attribute value must be a valid value for `background-image`,
* including the `url()` part of the CSS instruction.
*
* @default "bg-hidpi"
*/
data_bg_hidpi?: string;
/**
* The name of the data attribute containing the value of multiple `background-image`
* to load lazily, excluding the `"data-"` part.
* E.g. if your data attribute is named `"data-bg-multi"`, just pass `"bg-multi"`.
* The attribute value must be a valid value for `background-image`,
* including the `url()` part of the CSS instruction.
*
* @default "bg-multi"
*/
data_bg_multi?: string;
/**
* The name of the data attribute containing the value of multiple `background-image`
* to load lazily on HiDPI screens, excluding the `"data-"` part.
* E.g. if your data attribute is named `"data-bg-multi-hidpi"`, just pass `"bg-multi-hidpi"`.
* The attribute value must be a valid value for `background-image`,
* including the `url()` part of the CSS instruction.
*
* @default "bg-multi-hidpi"
*/
data_bg_multi_hidpi?: string;
/**
* The name of the data attribute containing the value of poster to load lazily,
* excluding the `"data-"` part.
* E.g. if your data attribute is named `"data-poster"`, just pass `"poster"`.
*
* @default "poster"
*/
data_poster?: string;
/**
* The class applied to the multiple background elements after the multiple background was applied
*
* @default "applied"
*/
class_applied?: string;
/**
* The class applied to the elements while the loading is in progress.
*
* @default "loading"
*/
class_loading?: string;
/**
* The class applied to the elements when the loading is complete.
*
* @default "loaded"
*/
class_loaded?: string;
/**
* The class applied to the elements when the element causes an error.
*
* @default "error"
*/
class_error?: string;
/**
* DEPRECATED
*
* You should change `load_delay: ___` with `cancel_on_exit: true`.
*
* @deprecated
*/
load_delay?: number;
/**
* A boolean that defines whether or not to cancel the download of the images
* that exit the viewport while they are still loading,
* eventually restoring the original attributes.
* It applies only to images so to the `img` (and `picture`) tags,
* so it doesn't apply to background images, `iframes` nor `videos`.
*
* @default true
*/
cancel_on_exit?: boolean;
/**
* A boolean that defines whether or not to automatically unobserve elements once they entered the viewport
*
* @default false
*/
unobserve_entered?: boolean;
/**
* A boolean that defines whether or not to automatically unobserve elements once they've loaded or throwed an error
*
* @default true
*/
unobserve_completed?: boolean;
/**
* DEPRECATED
*
* You should replace `auto_unobserve` with `unobserve_completed`
*
* @deprecated
*/
auto_unobserve?: boolean;
/**
* A callback function which is called whenever a multiple background element starts loading.
* Arguments: `DOM element`, `lazyload instance`.
*/
callback_applied?: (elt: HTMLElement, instance: ILazyLoadInstance) => void;
/**
* A callback function which is called whenever an element loading is
* canceled while loading, as for `cancel_on_exit: true`
*/
callback_cancel?: (
elt: HTMLElement,
entry: IntersectionObserverEntry,
instance: ILazyLoadInstance
) => void;
/**
* A callback function which is called whenever an element enters the viewport.
* Arguments: DOM element, intersection observer entry, lazyload instance.
*/
callback_enter?: (
elt: HTMLElement,
entry: IntersectionObserverEntry,
instance: ILazyLoadInstance
) => void;
/**
* A callback function which is called whenever an element exits the viewport.
* Arguments: `DOM element`, `intersection observer entry`, `lazyload instance`.
*/
callback_exit?: (
elt: HTMLElement,
entry: IntersectionObserverEntry,
instance: ILazyLoadInstance
) => void;
/**
* A callback function which is called whenever an element starts loading.
* Arguments: `DOM element`, `lazyload instance`.
*/
callback_loading?: (elt: HTMLElement, instance: ILazyLoadInstance) => void;
/**
* A callback function which is called whenever an element finishes loading.
* Note that, in version older than 11.0.0, this option went under the name `callback_load`.
* Arguments: `DOM element`, `lazyload instance`.
*/
callback_loaded?: (elt: HTMLElement, instance: ILazyLoadInstance) => void;
/**
* A callback function which is called whenever an element triggers an error.
* Arguments: `DOM element`, `lazyload instance`.
*/
callback_error?: (elt: HTMLElement, instance: ILazyLoadInstance) => void;
/**
*
*/
/**
* A callback function which is called when there are no more elements to load and all elements have been downloaded.
* Arguments: `lazyload instance`.
*/
callback_finish?: () => void;
/**
* This boolean sets whether or not to use [native lazy loading](https://addyosmani.com/blog/lazy-loading/)
* to do [hybrid lazy loading](https://www.smashingmagazine.com/2019/05/hybrid-lazy-loading-progressive-migration-native/).
* On browsers that support it, LazyLoad will set the `loading="lazy"` attribute on `images` and `iframes`,
* and delegate their loading to the browser.
*
* @default false
*/
use_native?: boolean;
/**
* DEPRECATED, WILL BE REMOVED IN V. 15
*
* @deprecated
*/
callback_reveal?: (elt: HTMLElement) => void;
}
interface ILazyLoadInstance {
/**
* Make LazyLoad to re-check the DOM for `elements_selector` elements inside its `container`.
*
* ### Use case
*
* Update LazyLoad after you added or removed DOM elements to the page.
*/
update: (elements?: NodeListOf<HTMLElement>) => void;
/**
* Destroys the instance, unsetting instance variables and removing listeners.
*
* ### Use case
*
* Free up some memory. Especially useful for Single Page Applications.
*/
destroy: () => void;
load: (element: HTMLElement, force?: boolean) => void;
/**
* Loads all the lazy elements right away and stop observing them,
* no matter if they are inside or outside the viewport,
* no matter if they are hidden or visible.
*
* ### Use case
*
* To load all the remaining elements in advance
*/
loadAll: () => void;
/**
* The number of elements that are currently downloading from the network
* (limitedly to the ones managed by the instance of LazyLoad).
* This is particularly useful to understand whether
* or not is safe to destroy this instance of LazyLoad.
*/
loadingCount: number;
/**
* The number of elements that haven't been lazyloaded yet
* (limitedly to the ones managed by the instance of LazyLoad)
*/
toLoadCount: number;
}
interface ILazyLoad {
new (
options?: ILazyLoadOptions,
elements?: NodeListOf<HTMLElement>
): ILazyLoadInstance;
/**
* Immediately loads the lazy `element`.
* You can pass your custom options in the settings parameter.
* Note that the `elements_selector` option has no effect,
* since you are passing the element as a parameter.
* Also note that this method has effect only once on a specific `element`.
*
* ### Use case
*
* To load an `element` at mouseover or at any other event different than "entering the viewport"
*/
load(element: HTMLElement, settings: ILazyLoadOptions): void;
/**
* Resets the internal status of the given element.
*
* ### Use case
*
* To tell LazyLoad to consider this `element` again, for example if you changed
* the `data-src` attribute after the previous `data-src` was loaded,
* call this method, then call `update()`.
*/
resetStatus(element: HTMLElement): void;
}
declare var LazyLoad: ILazyLoad;