Browse code

Refactor and rewrite as contao bundle

Benjamin Roth authored on04/11/2022 22:32:32
Showing1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,445 @@
1
+import * as React from 'react';
2
+
3
+import { SwiperOptions } from './types/swiper-options';
4
+import SwiperClass from './types/swiper-class';
5
+
6
+interface Swiper extends SwiperOptions {
7
+  /**
8
+   * Swiper container tag
9
+   *
10
+   * @default 'div'
11
+   */
12
+  tag?: string;
13
+
14
+  /**
15
+   * Swiper wrapper tag
16
+   *
17
+   * @default 'div'
18
+   */
19
+  wrapperTag?: string;
20
+
21
+  /**
22
+   * Get Swiper instance
23
+   */
24
+  onSwiper?: (swiper: SwiperClass) => void;
25
+
26
+  
27
+  /**
28
+   * Fired right after Swiper initialization.
29
+   * @note Note that with `swiper.on('init')` syntax it will
30
+   * work only in case you set `init: false` parameter.
31
+   *
32
+   * @example
33
+   * ```js
34
+   * const swiper = new Swiper('.swiper-container', {
35
+   *   init: false,
36
+   *   // other parameters
37
+   * });
38
+   * swiper.on('init', function() {
39
+   *  // do something
40
+   * });
41
+   * // init Swiper
42
+   * swiper.init();
43
+   * ```
44
+   *
45
+   * @example
46
+   * ```js
47
+   * // Otherwise use it as the parameter:
48
+   * const swiper = new Swiper('.swiper-container', {
49
+   *   // other parameters
50
+   *   on: {
51
+   *     init: function () {
52
+   *       // do something
53
+   *     },
54
+   *   }
55
+   * });
56
+   * ```
57
+   */
58
+  onInit?: (swiper: SwiperClass) => any;
59
+
60
+  /**
61
+   * Event will be fired right before Swiper destroyed
62
+   */
63
+  onBeforeDestroy?: (swiper: SwiperClass) => void;
64
+
65
+  /**
66
+   * Event will be fired when currently active slide is changed
67
+   */
68
+  onSlideChange?: (swiper: SwiperClass) => void;
69
+
70
+  /**
71
+   * Event will be fired in the beginning of animation to other slide (next or previous).
72
+   */
73
+  onSlideChangeTransitionStart?: (swiper: SwiperClass) => void;
74
+
75
+  /**
76
+   * Event will be fired after animation to other slide (next or previous).
77
+   */
78
+  onSlideChangeTransitionEnd?: (swiper: SwiperClass) => void;
79
+
80
+  /**
81
+   * Same as "slideChangeTransitionStart" but for "forward" direction only
82
+   */
83
+  onSlideNextTransitionStart?: (swiper: SwiperClass) => void;
84
+
85
+  /**
86
+   * Same as "slideChangeTransitionEnd" but for "forward" direction only
87
+   */
88
+  onSlideNextTransitionEnd?: (swiper: SwiperClass) => void;
89
+
90
+  /**
91
+   * Same as "slideChangeTransitionStart" but for "backward" direction only
92
+   */
93
+  onSlidePrevTransitionStart?: (swiper: SwiperClass) => void;
94
+
95
+  /**
96
+   * Same as "slideChangeTransitionEnd" but for "backward" direction only
97
+   */
98
+  onSlidePrevTransitionEnd?: (swiper: SwiperClass) => void;
99
+
100
+  /**
101
+   * Event will be fired in the beginning of transition.
102
+   */
103
+  onTransitionStart?: (swiper: SwiperClass) => void;
104
+
105
+  /**
106
+   * Event will be fired after transition.
107
+   */
108
+  onTransitionEnd?: (swiper: SwiperClass) => void;
109
+
110
+  /**
111
+   * Event will be fired when user touch Swiper. Receives `touchstart` event as an arguments.
112
+   */
113
+  onTouchStart?: (swiper: SwiperClass, event: MouseEvent | TouchEvent | PointerEvent) => void;
114
+
115
+  /**
116
+   * Event will be fired when user touch and move finger over Swiper. Receives `touchmove` event as an arguments.
117
+   */
118
+  onTouchMove?: (swiper: SwiperClass, event: MouseEvent | TouchEvent | PointerEvent) => void;
119
+
120
+  /**
121
+   * Event will be fired when user touch and move finger over Swiper in direction opposite to direction parameter. Receives `touchmove` event as an arguments.
122
+   */
123
+  onTouchMoveOpposite?: (swiper: SwiperClass, event: MouseEvent | TouchEvent | PointerEvent) => void;
124
+
125
+  /**
126
+   * Event will be fired when user touch and move finger over Swiper and move it. Receives `touchmove` event as an arguments.
127
+   */
128
+  onSliderMove?: (swiper: SwiperClass, event: MouseEvent | TouchEvent | PointerEvent) => void;
129
+
130
+  /**
131
+   * Event will be fired when user release Swiper. Receives `touchend` event as an arguments.
132
+   */
133
+  onTouchEnd?: (swiper: SwiperClass, event: MouseEvent | TouchEvent | PointerEvent) => void;
134
+
135
+  /**
136
+   * Event will be fired when user click/tap on Swiper. Receives `touchend` event as an arguments.
137
+   */
138
+  onClick?: (swiper: SwiperClass, event: MouseEvent | TouchEvent | PointerEvent) => void;
139
+
140
+  /**
141
+   * Event will be fired when user click/tap on Swiper. Receives `touchend` event as an arguments.
142
+   */
143
+  onTap?: (swiper: SwiperClass, event: MouseEvent | TouchEvent | PointerEvent) => void;
144
+
145
+  /**
146
+   * Event will be fired when user double tap on Swiper's container. Receives `touchend` event as an arguments
147
+   */
148
+  onDoubleTap?: (swiper: SwiperClass, event: MouseEvent | TouchEvent | PointerEvent) => void;
149
+
150
+  /**
151
+   * Event will be fired right after all inner images are loaded. updateOnImagesReady should be also enabled
152
+   */
153
+  onImagesReady?: (swiper: SwiperClass) => void;
154
+
155
+  /**
156
+   * Event will be fired when Swiper progress is changed, as an arguments it receives progress that is always from 0 to 1
157
+   */
158
+  onProgress?: (swiper: SwiperClass, progress: number) => void;
159
+
160
+  /**
161
+   * Event will be fired when Swiper reach its beginning (initial position)
162
+   */
163
+  onReachBeginning?: (swiper: SwiperClass) => void;
164
+
165
+  /**
166
+   * Event will be fired when Swiper reach last slide
167
+   */
168
+  onReachEnd?: (swiper: SwiperClass) => void;
169
+
170
+  /**
171
+   * Event will be fired when Swiper goes to beginning or end position
172
+   */
173
+  onToEdge?: (swiper: SwiperClass) => void;
174
+
175
+  /**
176
+   * Event will be fired when Swiper goes from beginning or end position
177
+   */
178
+  onFromEdge?: (swiper: SwiperClass) => void;
179
+
180
+  /**
181
+   * Event will be fired when swiper's wrapper change its position. Receives current translate value as an arguments
182
+   */
183
+  onSetTranslate?: (swiper: SwiperClass, translate: number) => void;
184
+
185
+  /**
186
+   * Event will be fired everytime when swiper starts animation. Receives current transition duration (in ms) as an arguments
187
+   */
188
+  onSetTransition?: (swiper: SwiperClass, transition: number) => void;
189
+
190
+  /**
191
+   * Event will be fired on window resize right before swiper's onresize manipulation
192
+   */
193
+  onResize?: (swiper: SwiperClass) => void;
194
+
195
+  /**
196
+   * Event will be fired if observer is enabled and it detects DOM mutations
197
+   */
198
+  onObserverUpdate?: (swiper: SwiperClass) => void;
199
+
200
+  /**
201
+   * Event will be fired right before "loop fix"
202
+   */
203
+  onBeforeLoopFix?: (swiper: SwiperClass) => void;
204
+
205
+  /**
206
+   * Event will be fired after "loop fix"
207
+   */
208
+  onLoopFix?: (swiper: SwiperClass) => void;
209
+
210
+  /**
211
+   * Event will be fired on breakpoint change
212
+   */
213
+  onBreakpoint?: (swiper: SwiperClass, breakpointParams: SwiperOptions) => void;
214
+
215
+  /**
216
+   * !INTERNAL: Event will fired right before breakpoint change
217
+   */
218
+  _beforeBreakpoint?: (swiper: SwiperClass, breakpointParams: SwiperOptions) => void;
219
+
220
+  /**
221
+   * !INTERNAL: Event will fired after setting CSS classes on swiper container element
222
+   */
223
+  _containerClasses?: (swiper: SwiperClass, classNames: string) => void;
224
+
225
+  /**
226
+   * !INTERNAL: Event will fired after setting CSS classes on swiper slide element
227
+   */
228
+  _slideClass?: (swiper: SwiperClass, el: HTMLElement, classNames: string) => void;
229
+
230
+  /**
231
+   * !INTERNAL: Event will fired after setting CSS classes on all swiper slides
232
+   */
233
+  _slideClasses?: (
234
+    swiper: SwiperClass,
235
+    slides: { el: HTMLElement; classNames: string; index: number }[],
236
+  ) => void;
237
+
238
+  /**
239
+   * !INTERNAL: Event will fired as soon as swiper instance available (before init)
240
+   */
241
+  _swiper?: (swiper: SwiperClass) => void;
242
+
243
+  /**
244
+   * !INTERNAL: Event will be fired on free mode touch end (release) and there will no be momentum
245
+   */
246
+  _freeModeNoMomentumRelease?: (swiper: SwiperClass) => void;
247
+
248
+  /**
249
+   * Event will fired on active index change
250
+   */
251
+  onActiveIndexChange?: (swiper: SwiperClass) => void;
252
+  /**
253
+   * Event will fired on snap index change
254
+   */
255
+  onSnapIndexChange?: (swiper: SwiperClass) => void;
256
+  /**
257
+   * Event will fired on real index change
258
+   */
259
+  onRealIndexChange?: (swiper: SwiperClass) => void;
260
+  /**
261
+   * Event will fired right after initialization
262
+   */
263
+  onAfterInit?: (swiper: SwiperClass) => void;
264
+  /**
265
+   * Event will fired right before initialization
266
+   */
267
+  onBeforeInit?: (swiper: SwiperClass) => void;
268
+  /**
269
+   * Event will fired before resize handler
270
+   */
271
+  onBeforeResize?: (swiper: SwiperClass) => void;
272
+  /**
273
+   * Event will fired before slide change transition start
274
+   */
275
+  onBeforeSlideChangeStart?: (swiper: SwiperClass) => void;
276
+  /**
277
+   * Event will fired before transition start
278
+   */
279
+  onBeforeTransitionStart?: (swiper: SwiperClass, speed: number, internal: any) => void; // what is internal?
280
+  /**
281
+   * Event will fired on direction change
282
+   */
283
+  onChangeDirection?: (swiper: SwiperClass) => void;
284
+  /**
285
+   * Event will be fired when user double click/tap on Swiper
286
+   */
287
+  onDoubleClick?: (swiper: SwiperClass, event: MouseEvent | TouchEvent | PointerEvent) => void;
288
+  /**
289
+   * Event will be fired on swiper destroy
290
+   */
291
+  onDestroy?: (swiper: SwiperClass) => void;
292
+  /**
293
+   * Event will be fired on momentum bounce
294
+   */
295
+  onMomentumBounce?: (swiper: SwiperClass) => void;
296
+  /**
297
+   * Event will be fired on orientation change (e.g. landscape -> portrait)
298
+   */
299
+  onOrientationchange?: (swiper: SwiperClass) => void;
300
+  /**
301
+   * Event will be fired in the beginning of animation of resetting slide to current one
302
+   */
303
+  onSlideResetTransitionStart?: (swiper: SwiperClass) => void;
304
+  /**
305
+   * Event will be fired in the end of animation of resetting slide to current one
306
+   */
307
+  onSlideResetTransitionEnd?: (swiper: SwiperClass) => void;
308
+  /**
309
+   * Event will be fired with first touch/drag move
310
+   */
311
+  onSliderFirstMove?: (swiper: SwiperClass, event: TouchEvent) => void;
312
+  /**
313
+   * Event will be fired when number of slides has changed
314
+   */
315
+  onSlidesLengthChange?: (swiper: SwiperClass) => void;
316
+  /**
317
+   * Event will be fired when slides grid has changed
318
+   */
319
+  onSlidesGridLengthChange?: (swiper: SwiperClass) => void;
320
+  /**
321
+   * Event will be fired when snap grid has changed
322
+   */
323
+  onSnapGridLengthChange?: (swiper: SwiperClass) => void;
324
+  /**
325
+   * Event will be fired after swiper.update() call
326
+   */
327
+  onUpdate?: (swiper: SwiperClass) => void;
328
+  
329
+  /**
330
+   * Event will be fired in when autoplay started
331
+   */
332
+  onAutoplayStart?: (swiper: SwiperClass) => void;
333
+  /**
334
+   * Event will be fired when autoplay stopped
335
+   */
336
+  onAutoplayStop?: (swiper: SwiperClass) => void;
337
+  /**
338
+   * Event will be fired when slide changed with autoplay
339
+   */
340
+  onAutoplay?: (swiper: SwiperClass) => void;/**
341
+   * Event will be fired on window hash change
342
+   */
343
+  onHashChange?: (swiper: SwiperClass) => void;
344
+  /**
345
+   * Event will be fired when swiper updates the hash
346
+   */
347
+  onHashSet?: (swiper: SwiperClass) => void;/**
348
+   * Event will be fired on key press
349
+   */
350
+  onKeyPress?: (swiper: SwiperClass, keyCode: string) => void;/**
351
+   * Event will be fired in the beginning of lazy loading of image
352
+   */
353
+  onLazyImageLoad?: (swiper: SwiperClass, slideEl: HTMLElement, imageEl: HTMLElement) => void;
354
+  /**
355
+   * Event will be fired when lazy loading image will be loaded
356
+   */
357
+  onLazyImageReady?: (swiper: SwiperClass, slideEl: HTMLElement, imageEl: HTMLElement) => void;/**
358
+   * Event will be fired on mousewheel scroll
359
+   */
360
+  onScroll?: (swiper: SwiperClass, event: WheelEvent) => void;/**
361
+   * Event will be fired on navigation hide
362
+   */
363
+  onNavigationHide?: (swiper: SwiperClass) => void;
364
+  /**
365
+   * Event will be fired on navigation show
366
+   */
367
+  onNavigationShow?: (swiper: SwiperClass) => void;/**
368
+   * Event will be fired after pagination rendered
369
+   */
370
+  onPaginationRender?: (swiper: SwiperClass, paginationEl: HTMLElement) => void;
371
+
372
+  /**
373
+   * Event will be fired when pagination updated
374
+   */
375
+  onPaginationUpdate?: (swiper: SwiperClass, paginationEl: HTMLElement) => void;
376
+
377
+  /**
378
+   * Event will be fired on pagination hide
379
+   */
380
+  onPaginationHide?: (swiper: SwiperClass) => void;
381
+
382
+  /**
383
+   * Event will be fired on pagination show
384
+   */
385
+  onPaginationShow?: (swiper: SwiperClass) => void;/**
386
+   * Event will be fired on draggable scrollbar drag start
387
+   */
388
+  onScrollbarDragStart?: (swiper: SwiperClass, event: MouseEvent | TouchEvent | PointerEvent) => void;
389
+
390
+  /**
391
+   * Event will be fired on draggable scrollbar drag move
392
+   */
393
+  onScrollbarDragMove?: (swiper: SwiperClass, event: MouseEvent | TouchEvent | PointerEvent) => void;
394
+
395
+  /**
396
+   * Event will be fired on draggable scrollbar drag end
397
+   */
398
+  onScrollbarDragEnd?: (swiper: SwiperClass, event: MouseEvent | TouchEvent | PointerEvent) => void;/**
399
+   * Event will be fired on zoom change
400
+   */
401
+  onZoomChange?: (swiper: SwiperClass, scale: number, imageEl: HTMLElement, slideEl: HTMLElement) => void;
402
+}
403
+
404
+interface SwiperSlide {
405
+  /**
406
+   * Slide tag
407
+   *
408
+   * @default 'div'
409
+   */
410
+  tag?: string;
411
+
412
+  /**
413
+   * Enables additional wrapper required for zoom mode
414
+   *
415
+   * @default false
416
+   */
417
+  zoom?: boolean;
418
+
419
+  /**
420
+   * Slide's index in slides array/collection
421
+   *
422
+   * @default false
423
+   */
424
+  virtualIndex?: number;
425
+}
426
+
427
+interface Swiper
428
+  extends Omit<
429
+    React.HTMLAttributes<HTMLElement>,
430
+    | 'onProgress'
431
+    | 'onClick'
432
+    | 'onTouchEnd'
433
+    | 'onTouchMove'
434
+    | 'onTouchStart'
435
+    | 'onTransitionEnd'
436
+    | 'onKeyPress'
437
+    | 'onDoubleClick'
438
+    | 'onScroll'
439
+  > {}
440
+interface SwiperSlide extends React.HTMLAttributes<HTMLElement> {}
441
+
442
+declare const Swiper: React.FunctionComponent<Swiper>;
443
+declare const SwiperSlide: React.FunctionComponent<SwiperSlide>;
444
+
445
+export { Swiper, SwiperSlide };