1 | import { Dom7Array } from 'dom7';
|
2 | import { SwiperOptions } from './swiper-options';
|
3 | import { CSSSelector, SwiperComponent } from './shared';
|
4 | import { SwiperEvents } from './swiper-events';
|
5 |
|
6 | import { A11yMethods } from './components/a11y';
|
7 | import { AutoplayMethods } from './components/autoplay';
|
8 | import { ControllerMethods } from './components/controller';
|
9 | import { CoverflowEffectMethods } from './components/effect-coverflow';
|
10 | import { CubeEffectMethods } from './components/effect-cube';
|
11 | import { FadeEffectMethods } from './components/effect-fade';
|
12 | import { FlipEffectMethods } from './components/effect-flip';
|
13 | import { HashNavigationMethods } from './components/hash-navigation';
|
14 | import { HistoryMethods } from './components/history';
|
15 | import { KeyboardMethods } from './components/keyboard';
|
16 | import { LazyMethods } from './components/lazy';
|
17 | import { MousewheelMethods } from './components/mousewheel';
|
18 | import { NavigationMethods } from './components/navigation';
|
19 | import { PaginationMethods } from './components/pagination';
|
20 | import { ParallaxMethods } from './components/parallax';
|
21 | import { ScrollbarMethods } from './components/scrollbar';
|
22 | import { ThumbsMethods } from './components/thumbs';
|
23 | import { VirtualMethods } from './components/virtual';
|
24 | import { ZoomMethods } from './components/zoom';
|
25 |
|
26 | interface SwiperClass<Events> {
|
27 | /** Add event handler */
|
28 | on<E extends keyof Events>(event: E, handler: Events[E]): void;
|
29 | /** Add event handler that will be removed after it was fired */
|
30 | once<E extends keyof Events>(event: E, handler: Events[E]): void;
|
31 | /** Remove event handler */
|
32 | off<E extends keyof Events>(event: E, handler: Events[E]): void;
|
33 | /** Remove all handlers for specified event */
|
34 | off<E extends keyof Events>(event: E): void;
|
35 | /** Fire event on instance */
|
36 | emit<E extends keyof Events>(event: E, ...args: any[]): void;
|
37 | }
|
38 |
|
39 | interface Swiper extends SwiperClass<SwiperEvents> {
|
40 | /**
|
41 | * Object with passed initialization parameters
|
42 | */
|
43 | params: SwiperOptions;
|
44 |
|
45 | /**
|
46 | * Dom7 element with slider container HTML element. To get vanilla HTMLElement use `swiper.el`
|
47 | */
|
48 | $el: Dom7Array;
|
49 |
|
50 | /**
|
51 | * Slider container HTML element
|
52 | */
|
53 | el: HTMLElement;
|
54 |
|
55 | /**
|
56 | * Dom7 element with slider wrapper HTML element. To get vanilla HTMLElement use `swiper.wrapperEl`
|
57 | */
|
58 | $wrapperEl: Dom7Array;
|
59 |
|
60 | /**
|
61 | * Wrapper HTML element
|
62 | */
|
63 | wrapperEl: HTMLElement;
|
64 |
|
65 | /**
|
66 | * Dom7 array-like collection of slides HTML elements. To get specific slide HTMLElement use `swiper.slides[1]`
|
67 | */
|
68 | slides: Dom7Array;
|
69 |
|
70 | /**
|
71 | * Width of container
|
72 | */
|
73 | width: number;
|
74 |
|
75 | /**
|
76 | * Height of container
|
77 | */
|
78 | height: number;
|
79 |
|
80 | /**
|
81 | * Current value of wrapper translate
|
82 | */
|
83 | translate: number;
|
84 |
|
85 | /**
|
86 | * Current progress of wrapper translate (from 0 to 1)
|
87 | */
|
88 | progress: number;
|
89 |
|
90 | /**
|
91 | * Index number of currently active slide
|
92 | *
|
93 | * @note Note, that in loop mode active index value will be always shifted on a number of looped/duplicated slides
|
94 | */
|
95 | activeIndex: number;
|
96 |
|
97 | /**
|
98 | * Index number of currently active slide considering duplicated slides in loop mode
|
99 | */
|
100 | realIndex: number;
|
101 |
|
102 | /**
|
103 | * Index number of previously active slide
|
104 | */
|
105 | previousIndex: number;
|
106 |
|
107 | /**
|
108 | * `true` if slider on most "left"/"top" position
|
109 | */
|
110 | isBeginning: boolean;
|
111 |
|
112 | /**
|
113 | * `true` if slider on most "right"/"bottom" position
|
114 | */
|
115 | isEnd: boolean;
|
116 |
|
117 | /**
|
118 | * `true` if swiper is in transition
|
119 | */
|
120 | animating: boolean;
|
121 |
|
122 | /**
|
123 | * Object with the following touch event properties:
|
124 | *
|
125 | * - `swiper.touches.startX`
|
126 | * - `swiper.touches.startY`
|
127 | * - `swiper.touches.currentX`
|
128 | * - `swiper.touches.currentY`
|
129 | * - `swiper.touches.diff`
|
130 | */
|
131 | touches: {
|
132 | startX: number;
|
133 | startY: number;
|
134 | currentX: number;
|
135 | currentY: number;
|
136 | diff: number;
|
137 | };
|
138 |
|
139 | /**
|
140 | * Index number of last clicked slide
|
141 | */
|
142 | clickedIndex: number;
|
143 |
|
144 | /**
|
145 | * Link to last clicked slide (HTMLElement)
|
146 | */
|
147 | clickedSlide: HTMLElement;
|
148 |
|
149 | /**
|
150 | * Disable / enable ability to slide to the next slides by assigning `false` / `true` to this property
|
151 | */
|
152 | allowSlideNext: boolean;
|
153 |
|
154 | /**
|
155 | * Disable / enable ability to slide to the previous slides by assigning `false` / `true` to this property
|
156 | */
|
157 | allowSlidePrev: boolean;
|
158 |
|
159 | /**
|
160 | * Disable / enable ability move slider by grabbing it with mouse or by touching it with finger (on touch screens) by assigning `false` / `true` to this property
|
161 | */
|
162 | allowTouchMove: boolean;
|
163 |
|
164 | rtlTranslate: boolean;
|
165 |
|
166 | /**
|
167 | * Run transition to next slide.
|
168 | *
|
169 | * @param speed Transition duration (in ms).
|
170 | * @param runCallbacks Set it to false (by default it is true) and transition will
|
171 | * not produce transition events.
|
172 | */
|
173 | slideNext(speed?: number, runCallbacks?: boolean): void;
|
174 |
|
175 | /**
|
176 | * Run transition to previous slide.
|
177 | *
|
178 | * @param speed Transition duration (in ms).
|
179 | * @param runCallbacks Set it to false (by default it is true) and transition will
|
180 | * not produce transition events.
|
181 | */
|
182 | slidePrev(speed?: number, runCallbacks?: boolean): void;
|
183 |
|
184 | /**
|
185 | * Run transition to the slide with index number equal to 'index' parameter for the
|
186 | * duration equal to 'speed' parameter.
|
187 | *
|
188 | * @param index Index number of slide.
|
189 | * @param speed Transition duration (in ms).
|
190 | * @param runCallbacks Set it to false (by default it is true) and transition will
|
191 | * not produce transition events.
|
192 | */
|
193 | slideTo(index: number, speed?: number, runCallbacks?: boolean): void;
|
194 |
|
195 | /**
|
196 | * Does the same as .slideTo but for the case when used with enabled loop. So this
|
197 | * method will slide to slides with realIndex matching to passed index
|
198 | *
|
199 | * @param index Index number of slide.
|
200 | * @param speed Transition duration (in ms).
|
201 | * @param runCallbacks Set it to false (by default it is true) and transition will
|
202 | * not produce transition events.
|
203 | */
|
204 | slideToLoop(index: number, speed?: number, runCallbacks?: boolean): void;
|
205 |
|
206 | /**
|
207 | * Reset swiper position to currently active slide for the duration equal to 'speed'
|
208 | * parameter.
|
209 | *
|
210 | * @param speed Transition duration (in ms).
|
211 | * @param runCallbacks Set it to false (by default it is true) and transition will
|
212 | * not produce transition events.
|
213 | */
|
214 | slideReset(speed?: number, runCallbacks?: boolean): void;
|
215 |
|
216 | /**
|
217 | * Reset swiper position to closest slide/snap point for the duration equal to 'speed' parameter.
|
218 | *
|
219 | * @param speed Transition duration (in ms).
|
220 | * @param runCallbacks Set it to false (by default it is true) and transition will
|
221 | * not produce transition events.
|
222 | */
|
223 | slideToClosest(speed?: number, runCallbacks?: boolean): void;
|
224 |
|
225 | /**
|
226 | * Force swiper to update its height (when autoHeight enabled) for the duration equal to
|
227 | * 'speed' parameter
|
228 | *
|
229 | * @param speed Transition duration (in ms).
|
230 | */
|
231 | updateAutoHeight(speed?: number): void;
|
232 |
|
233 | /**
|
234 | * You should call it after you add/remove slides
|
235 | * manually, or after you hide/show it, or do any
|
236 | * custom DOM modifications with Swiper
|
237 | * This method also includes subcall of the following
|
238 | * methods which you can use separately:
|
239 | */
|
240 | update(): void;
|
241 |
|
242 | /**
|
243 | * recalculate size of swiper container
|
244 | */
|
245 | updateSize(): void;
|
246 |
|
247 | /**
|
248 | * recalculate number of slides and their offsets. Useful after you add/remove slides with JavaScript
|
249 | */
|
250 | updateSlides(): void;
|
251 |
|
252 | /**
|
253 | * recalculate swiper progress
|
254 | */
|
255 | updateProgress(): void;
|
256 |
|
257 | /**
|
258 | * update active/prev/next classes on slides and bullets
|
259 | */
|
260 | updateSlidesClasses(): void;
|
261 |
|
262 | /**
|
263 | * Changes slider direction from horizontal to vertical and back.
|
264 | *
|
265 | * @param direction New direction. If not specified, then will automatically changed to opposite direction
|
266 | * @param needUpdate Will call swiper.update(). Default true
|
267 | */
|
268 | changeDirection(direction?: 'horizontal' | 'vertical', needUpdate?: boolean): void;
|
269 |
|
270 | /**
|
271 | * Detach all events listeners
|
272 | */
|
273 | detachEvents(): void;
|
274 |
|
275 | /**
|
276 | * Attach all events listeners again
|
277 | */
|
278 | attachEvents(): void;
|
279 |
|
280 | /**
|
281 | * Initialize slider
|
282 | */
|
283 | init(): void;
|
284 |
|
285 | /**
|
286 | * Destroy slider instance and detach all events listeners
|
287 | *
|
288 | * @param deleteInstance Set it to false (by default it is true) to not to delete Swiper instance
|
289 | * @param cleanStyles Set it to true (by default it is true) and all custom styles will be removed from slides, wrapper and container.
|
290 | * Useful if you need to destroy Swiper and to init again with new options or in different direction
|
291 | */
|
292 | destroy(deleteInstance?: boolean, cleanStyles?: boolean): void;
|
293 |
|
294 | /**
|
295 | * Add new slides to the end. slides could be
|
296 | * HTMLElement or HTML string with new slide or
|
297 | * array with such slides, for example:
|
298 | *
|
299 | * @example
|
300 | * ```js
|
301 | * appendSlide('<div class="swiper-slide">Slide 10"</div>')
|
302 | *
|
303 | * appendSlide([
|
304 | * '<div class="swiper-slide">Slide 10"</div>',
|
305 | * '<div class="swiper-slide">Slide 11"</div>'
|
306 | * ]);
|
307 | * ```
|
308 | */
|
309 | appendSlide(slides: HTMLElement | string | string[] | HTMLElement[]): void;
|
310 |
|
311 | /**
|
312 | * Add new slides to the beginning. slides could be
|
313 | * HTMLElement or HTML string with new slide or array with such slides, for example:
|
314 | *
|
315 | * @example
|
316 | * ```js
|
317 | * prependSlide('<div class="swiper-slide">Slide 0"</div>')
|
318 | *
|
319 | * prependSlide([
|
320 | * '<div class="swiper-slide">Slide 1"</div>',
|
321 | * '<div class="swiper-slide">Slide 2"</div>'
|
322 | * ]);
|
323 | * ```
|
324 | */
|
325 | prependSlide(slides: HTMLElement | string | string[] | HTMLElement[]): void;
|
326 |
|
327 | /**
|
328 | * Add new slides to the required index. slides could be HTMLElement or HTML string with new slide or array with such slides, for example:
|
329 | *
|
330 | * @example
|
331 | * ```js
|
332 | * addSlide(1, '<div class="swiper-slide">Slide 10"</div>')
|
333 | *
|
334 | * addSlide(1, [
|
335 | * '<div class="swiper-slide">Slide 10"</div>',
|
336 | * '<div class="swiper-slide">Slide 11"</div>'
|
337 | * ]);
|
338 | * ```
|
339 | */
|
340 | addSlide(index: number, slides: HTMLElement | string | string[] | HTMLElement[]): void;
|
341 |
|
342 | /**
|
343 | * Remove selected slides. slideIndex could be a number with slide index to remove or array with indexes.
|
344 | *
|
345 | * @example
|
346 | * ```js
|
347 | * removeSlide(0); // remove first slide
|
348 | * removeSlide([0, 1]); // remove first and second slides
|
349 | * removeAllSlides(); // Remove all slides
|
350 | * ```
|
351 | */
|
352 | removeSlide(slideIndex: number | number[]): void;
|
353 |
|
354 | /**
|
355 | * Remove all slides
|
356 | */
|
357 | removeAllSlides(): void;
|
358 |
|
359 | /**
|
360 | * Set custom css3 transform's translate value for swiper wrapper
|
361 | */
|
362 | setTranslate(translate: any): void;
|
363 |
|
364 | /**
|
365 | * Get current value of swiper wrapper css3 transform translate
|
366 | */
|
367 | getTranslate(): any;
|
368 |
|
369 | /**
|
370 | * Animate custom css3 transform's translate value for swiper wrapper
|
371 | *
|
372 | * @param translate Translate value (in px)
|
373 | * @param speed Transition duration (in ms)
|
374 | * @param runCallbacks Set it to false (by default it is true) and transition will not produce transition events
|
375 | * @param translateBounds Set it to false (by default it is true) and transition value can extend beyond min and max translate
|
376 | *
|
377 | */
|
378 | translateTo(
|
379 | translate: number,
|
380 | speed: number,
|
381 | runCallbacks?: boolean,
|
382 | translateBounds?: boolean,
|
383 | ): any;
|
384 |
|
385 | /**
|
386 | * Unset grab cursor
|
387 | */
|
388 | unsetGrabCursor(): void;
|
389 |
|
390 | /**
|
391 | * Set grab cursor
|
392 | */
|
393 | setGrabCursor(): void;
|
394 |
|
395 | /**
|
396 | * Add event listener that will be fired on all events
|
397 | */
|
398 | onAny(handler: (eventName: string, ...args: any[]) => void): void;
|
399 |
|
400 | /**
|
401 | * Remove event listener that will be fired on all events
|
402 | */
|
403 | offAny(handler: (eventName: string, ...args: any[]) => void): void;
|
404 |
|
405 | isHorizontal(): boolean;
|
406 |
|
407 | getBreakpoint(breakpoints: SwiperOptions['breakpoints']): string;
|
408 |
|
409 | setBreakpoint(): void;
|
410 |
|
411 | currentBreakpoint: any;
|
412 |
|
413 | destroyed: boolean;
|
414 | modules: Array<any>; //TODO: add typing
|
415 | a11y: A11yMethods;
|
416 | autoplay: AutoplayMethods;
|
417 | controller: ControllerMethods;
|
418 | coverflowEffect: CoverflowEffectMethods;
|
419 | cubeEffect: CubeEffectMethods;
|
420 | fadeEffect: FadeEffectMethods;
|
421 | flipEffect: FlipEffectMethods;
|
422 | hashNavigation: HashNavigationMethods;
|
423 | history: HistoryMethods;
|
424 | keyboard: KeyboardMethods;
|
425 | lazy: LazyMethods;
|
426 | mousewheel: MousewheelMethods;
|
427 | navigation: NavigationMethods;
|
428 | pagination: PaginationMethods;
|
429 | parallax: ParallaxMethods;
|
430 | scrollbar: ScrollbarMethods;
|
431 | thumbs: ThumbsMethods;
|
432 | virtual: VirtualMethods;
|
433 | zoom: ZoomMethods;
|
434 | }
|
435 |
|
436 | declare class Swiper implements Swiper {
|
437 | /**
|
438 | * Constructs a new Swiper instance.
|
439 | *
|
440 | * @param container Where Swiper applies to.
|
441 | * @param options Instance options.
|
442 | */
|
443 | constructor(container: CSSSelector | HTMLElement, options?: SwiperOptions);
|
444 | /**
|
445 | * Installs modules on Swiper in runtime.
|
446 | */
|
447 | static use(modules: SwiperComponent[]): void;
|
448 |
|
449 | /**
|
450 | * Swiper default options
|
451 | */
|
452 | static defaults: SwiperOptions;
|
453 |
|
454 | /**
|
455 | * Extend global Swiper defaults
|
456 | */
|
457 | static extendDefaults(options: SwiperOptions): void;
|
458 |
|
459 | /**
|
460 | * Object with global Swiper exntended options
|
461 | */
|
462 | static extendedDefaults: SwiperOptions;
|
463 | }
|
464 |
|
465 | export default Swiper;
|