UNPKG

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