react-slideshow-image 3.7.4 → 4.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,775 @@
1
+ import React, { useState, useRef, useMemo, useCallback, useEffect, useImperativeHandle } from 'react';
2
+ import ResizeObserver from 'resize-observer-polyfill';
3
+ import TWEEN from '@tweenjs/tween.js';
4
+
5
+ function _extends() {
6
+ _extends = Object.assign ? Object.assign.bind() : function (target) {
7
+ for (var i = 1; i < arguments.length; i++) {
8
+ var source = arguments[i];
9
+
10
+ for (var key in source) {
11
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
12
+ target[key] = source[key];
13
+ }
14
+ }
15
+ }
16
+
17
+ return target;
18
+ };
19
+ return _extends.apply(this, arguments);
20
+ }
21
+
22
+ var getStartingIndex = function getStartingIndex(children, defaultIndex) {
23
+ if (defaultIndex && defaultIndex < React.Children.count(children)) {
24
+ return defaultIndex;
25
+ }
26
+
27
+ return 0;
28
+ };
29
+ var EASING_METHODS = {
30
+ linear: TWEEN.Easing.Linear.None,
31
+ ease: TWEEN.Easing.Quadratic.InOut,
32
+ 'ease-in': TWEEN.Easing.Quadratic.In,
33
+ 'ease-out': TWEEN.Easing.Quadratic.Out,
34
+ cubic: TWEEN.Easing.Cubic.InOut,
35
+ 'cubic-in': TWEEN.Easing.Cubic.In,
36
+ 'cubic-out': TWEEN.Easing.Cubic.Out
37
+ };
38
+ var getEasing = function getEasing(easeMethod) {
39
+ if (easeMethod) {
40
+ return EASING_METHODS[easeMethod];
41
+ }
42
+
43
+ return EASING_METHODS.linear;
44
+ };
45
+ var showPreviousArrow = function showPreviousArrow(_ref, currentIndex, moveSlides) {
46
+ var prevArrow = _ref.prevArrow,
47
+ infinite = _ref.infinite;
48
+ var isDisabled = currentIndex <= 0 && !infinite;
49
+ var props = {
50
+ 'data-type': 'prev',
51
+ 'aria-label': 'Previous Slide',
52
+ disabled: isDisabled,
53
+ onClick: moveSlides
54
+ };
55
+
56
+ if (prevArrow) {
57
+ return /*#__PURE__*/React.cloneElement(prevArrow, _extends({
58
+ className: (prevArrow.props.className || '') + " nav " + (isDisabled ? 'disabled' : '')
59
+ }, props));
60
+ }
61
+
62
+ var className = "nav default-nav " + (isDisabled ? 'disabled' : '');
63
+ return /*#__PURE__*/React.createElement("button", Object.assign({
64
+ className: className
65
+ }, props), /*#__PURE__*/React.createElement("svg", {
66
+ width: "24",
67
+ height: "24",
68
+ viewBox: "0 0 24 24"
69
+ }, /*#__PURE__*/React.createElement("path", {
70
+ d: "M16.67 0l2.83 2.829-9.339 9.175 9.339 9.167-2.83 2.829-12.17-11.996z"
71
+ })));
72
+ };
73
+ var showNextArrow = function showNextArrow(properties, currentIndex, moveSlides) {
74
+ var nextArrow = properties.nextArrow,
75
+ infinite = properties.infinite,
76
+ children = properties.children;
77
+ var slidesToScroll = 1;
78
+
79
+ if ('slidesToScroll' in properties) {
80
+ slidesToScroll = properties.slidesToScroll || 1;
81
+ }
82
+
83
+ var isDisabled = currentIndex >= React.Children.count(children) - slidesToScroll && !infinite;
84
+ var props = {
85
+ 'data-type': 'next',
86
+ 'aria-label': 'Next Slide',
87
+ disabled: isDisabled,
88
+ onClick: moveSlides
89
+ };
90
+
91
+ if (nextArrow) {
92
+ return /*#__PURE__*/React.cloneElement(nextArrow, _extends({
93
+ className: (nextArrow.props.className || '') + " nav " + (isDisabled ? 'disabled' : '')
94
+ }, props));
95
+ }
96
+
97
+ var className = "nav default-nav " + (isDisabled ? 'disabled' : '');
98
+ return /*#__PURE__*/React.createElement("button", Object.assign({
99
+ className: className
100
+ }, props), /*#__PURE__*/React.createElement("svg", {
101
+ width: "24",
102
+ height: "24",
103
+ viewBox: "0 0 24 24"
104
+ }, /*#__PURE__*/React.createElement("path", {
105
+ d: "M5 3l3.057-3 11.943 12-11.943 12-3.057-3 9-9z"
106
+ })));
107
+ };
108
+
109
+ var showDefaultIndicator = function showDefaultIndicator(isCurrentPageActive, key, indicatorProps) {
110
+ return /*#__PURE__*/React.createElement("li", {
111
+ key: key
112
+ }, /*#__PURE__*/React.createElement("button", Object.assign({
113
+ className: "each-slideshow-indicator " + (isCurrentPageActive ? 'active' : '')
114
+ }, indicatorProps)));
115
+ };
116
+
117
+ var showCustomIndicator = function showCustomIndicator(isCurrentPageActive, key, indicatorProps, eachIndicator) {
118
+ return /*#__PURE__*/React.cloneElement(eachIndicator, _extends({
119
+ className: eachIndicator.props.className + " " + (isCurrentPageActive ? 'active' : ''),
120
+ key: key
121
+ }, indicatorProps));
122
+ };
123
+
124
+ var showIndicators = function showIndicators(props, currentIndex, navigate) {
125
+ var children = props.children,
126
+ indicators = props.indicators;
127
+ var slidesToScroll = 1;
128
+
129
+ if ('slidesToScroll' in props) {
130
+ slidesToScroll = props.slidesToScroll || 1;
131
+ }
132
+
133
+ var pages = Math.ceil(React.Children.count(children) / slidesToScroll);
134
+ return /*#__PURE__*/React.createElement("ul", {
135
+ className: "indicators"
136
+ }, Array.from({
137
+ length: pages
138
+ }, function (_, key) {
139
+ var indicatorProps = {
140
+ 'data-key': key,
141
+ 'aria-label': "Go to slide " + (key + 1),
142
+ onClick: navigate
143
+ };
144
+ var isCurrentPageActive = Math.floor((currentIndex + slidesToScroll - 1) / slidesToScroll) === key;
145
+
146
+ if (typeof indicators === 'function') {
147
+ return showCustomIndicator(isCurrentPageActive, key, indicatorProps, indicators(key));
148
+ }
149
+
150
+ return showDefaultIndicator(isCurrentPageActive, key, indicatorProps);
151
+ }));
152
+ };
153
+
154
+ var defaultProps = {
155
+ duration: 5000,
156
+ transitionDuration: 1000,
157
+ defaultIndex: 0,
158
+ infinite: true,
159
+ autoplay: true,
160
+ indicators: false,
161
+ arrows: true,
162
+ pauseOnHover: true,
163
+ easing: 'linear',
164
+ canSwipe: true,
165
+ cssClass: '',
166
+ responsive: []
167
+ };
168
+
169
+ var FadeZoom = /*#__PURE__*/React.forwardRef(function (props, ref) {
170
+ var _useState = useState(getStartingIndex(props.children, props.defaultIndex)),
171
+ index = _useState[0],
172
+ setIndex = _useState[1];
173
+
174
+ var wrapperRef = useRef(null);
175
+ var innerWrapperRef = useRef(null);
176
+ var tweenGroup = new TWEEN.Group();
177
+ var timeout = useRef();
178
+ var resizeObserver = useRef();
179
+ var childrenCount = useMemo(function () {
180
+ return React.Children.count(props.children);
181
+ }, [props.children]);
182
+ var applyStyle = useCallback(function () {
183
+ if (innerWrapperRef.current && wrapperRef.current) {
184
+ var wrapperWidth = wrapperRef.current.clientWidth;
185
+ var fullwidth = wrapperWidth * childrenCount;
186
+ innerWrapperRef.current.style.width = fullwidth + "px";
187
+
188
+ for (var _index = 0; _index < innerWrapperRef.current.children.length; _index++) {
189
+ var eachDiv = innerWrapperRef.current.children[_index];
190
+
191
+ if (eachDiv) {
192
+ eachDiv.style.width = wrapperWidth + "px";
193
+ eachDiv.style.left = _index * -wrapperWidth + "px";
194
+ eachDiv.style.display = "block";
195
+ }
196
+ }
197
+ }
198
+ }, [wrapperRef, innerWrapperRef, childrenCount]);
199
+ var initResizeObserver = useCallback(function () {
200
+ if (wrapperRef.current) {
201
+ resizeObserver.current = new ResizeObserver(function (entries) {
202
+ if (!entries) return;
203
+ applyStyle();
204
+ });
205
+ resizeObserver.current.observe(wrapperRef.current);
206
+ }
207
+ }, [wrapperRef, applyStyle]);
208
+ var play = useCallback(function () {
209
+ var autoplay = props.autoplay,
210
+ children = props.children,
211
+ duration = props.duration,
212
+ infinite = props.infinite;
213
+
214
+ if (autoplay && React.Children.count(children) > 1 && (infinite || index < React.Children.count(children) - 1)) {
215
+ timeout.current = setTimeout(moveNext, duration);
216
+ } // eslint-disable-next-line react-hooks/exhaustive-deps
217
+
218
+ }, [props, index]);
219
+ useEffect(function () {
220
+ initResizeObserver();
221
+ return function () {
222
+ tweenGroup.removeAll();
223
+ clearTimeout(timeout.current);
224
+ removeResizeObserver();
225
+ };
226
+ }, [initResizeObserver, tweenGroup]);
227
+ useEffect(function () {
228
+ clearTimeout(timeout.current);
229
+ play();
230
+ }, [index, props.autoplay, play]);
231
+ useEffect(function () {
232
+ applyStyle();
233
+ }, [childrenCount, applyStyle]);
234
+ useImperativeHandle(ref, function () {
235
+ return {
236
+ goNext: function goNext() {
237
+ moveNext();
238
+ },
239
+ goBack: function goBack() {
240
+ moveBack();
241
+ },
242
+ goTo: function goTo(index) {
243
+ moveTo(index);
244
+ }
245
+ };
246
+ });
247
+
248
+ var removeResizeObserver = function removeResizeObserver() {
249
+ if (resizeObserver.current && wrapperRef.current) {
250
+ resizeObserver.current.unobserve(wrapperRef.current);
251
+ }
252
+ };
253
+
254
+ var pauseSlides = function pauseSlides() {
255
+ if (props.pauseOnHover) {
256
+ clearTimeout(timeout.current);
257
+ }
258
+ };
259
+
260
+ var startSlides = function startSlides() {
261
+ var pauseOnHover = props.pauseOnHover,
262
+ autoplay = props.autoplay,
263
+ duration = props.duration;
264
+
265
+ if (pauseOnHover && autoplay) {
266
+ timeout.current = setTimeout(function () {
267
+ return moveNext();
268
+ }, duration);
269
+ }
270
+ };
271
+
272
+ var moveNext = function moveNext() {
273
+ var children = props.children,
274
+ infinite = props.infinite;
275
+
276
+ if (!infinite && index === React.Children.count(children) - 1) {
277
+ return;
278
+ }
279
+
280
+ transitionSlide((index + 1) % React.Children.count(children));
281
+ };
282
+
283
+ var moveBack = function moveBack() {
284
+ var children = props.children,
285
+ infinite = props.infinite;
286
+
287
+ if (!infinite && index === 0) {
288
+ return;
289
+ }
290
+
291
+ transitionSlide(index === 0 ? React.Children.count(children) - 1 : index - 1);
292
+ };
293
+
294
+ var preTransition = function preTransition(event) {
295
+ var currentTarget = event.currentTarget;
296
+
297
+ if (currentTarget.dataset.type === 'prev') {
298
+ moveBack();
299
+ } else {
300
+ moveNext();
301
+ }
302
+ };
303
+
304
+ var transitionSlide = function transitionSlide(newIndex) {
305
+ var existingTweens = tweenGroup.getAll();
306
+
307
+ if (!existingTweens.length) {
308
+ var _innerWrapperRef$curr;
309
+
310
+ if (!((_innerWrapperRef$curr = innerWrapperRef.current) != null && _innerWrapperRef$curr.children[newIndex])) {
311
+ newIndex = 0;
312
+ }
313
+
314
+ clearTimeout(timeout.current);
315
+ var value = {
316
+ opacity: 0,
317
+ scale: 1
318
+ };
319
+
320
+ var animate = function animate() {
321
+ requestAnimationFrame(animate);
322
+ tweenGroup.update();
323
+ };
324
+
325
+ animate();
326
+ var tween = new TWEEN.Tween(value, tweenGroup).to({
327
+ opacity: 1,
328
+ scale: props.scale
329
+ }, props.transitionDuration).onUpdate(function (value) {
330
+ if (!innerWrapperRef.current) {
331
+ return;
332
+ }
333
+
334
+ innerWrapperRef.current.children[newIndex].style.opacity = value.opacity;
335
+ innerWrapperRef.current.children[index].style.opacity = 1 - value.opacity;
336
+ innerWrapperRef.current.children[index].style.transform = "scale(" + value.scale + ")";
337
+ }).start();
338
+ tween.easing(getEasing(props.easing));
339
+ tween.onComplete(function () {
340
+ if (innerWrapperRef.current) {
341
+ setIndex(newIndex);
342
+ innerWrapperRef.current.children[index].style.transform = "scale(1)";
343
+ }
344
+
345
+ if (typeof props.onChange === 'function') {
346
+ props.onChange(index, newIndex);
347
+ }
348
+ });
349
+ }
350
+ };
351
+
352
+ var moveTo = function moveTo(index) {
353
+ transitionSlide(index);
354
+ };
355
+
356
+ var navigate = function navigate(event) {
357
+ var currentTarget = event.currentTarget;
358
+
359
+ if (!currentTarget.dataset.key) {
360
+ return;
361
+ }
362
+
363
+ if (parseInt(currentTarget.dataset.key) !== index) {
364
+ moveTo(parseInt(currentTarget.dataset.key));
365
+ }
366
+ };
367
+
368
+ return /*#__PURE__*/React.createElement("div", {
369
+ dir: "ltr",
370
+ "aria-roledescription": "carousel"
371
+ }, /*#__PURE__*/React.createElement("div", {
372
+ className: "react-slideshow-container " + (props.cssClass || ''),
373
+ onMouseEnter: pauseSlides,
374
+ onMouseOver: pauseSlides,
375
+ onMouseLeave: startSlides,
376
+ ref: props.ref
377
+ }, props.arrows && showPreviousArrow(props, index, preTransition), /*#__PURE__*/React.createElement("div", {
378
+ className: "react-slideshow-fadezoom-wrapper " + props.cssClass,
379
+ ref: wrapperRef
380
+ }, /*#__PURE__*/React.createElement("div", {
381
+ className: "react-slideshow-fadezoom-images-wrap",
382
+ ref: innerWrapperRef
383
+ }, (React.Children.map(props.children, function (thisArg) {
384
+ return thisArg;
385
+ }) || []).map(function (each, key) {
386
+ return /*#__PURE__*/React.createElement("div", {
387
+ style: {
388
+ opacity: key === index ? '1' : '0',
389
+ zIndex: key === index ? '1' : '0'
390
+ },
391
+ "data-index": key,
392
+ key: key,
393
+ "aria-roledescription": "slide",
394
+ "aria-hidden": key === index ? 'false' : 'true'
395
+ }, each);
396
+ }))), props.arrows && showNextArrow(props, index, preTransition)), props.indicators && showIndicators(props, index, navigate));
397
+ });
398
+ FadeZoom.defaultProps = defaultProps;
399
+
400
+ var Fade = /*#__PURE__*/React.forwardRef(function (props, ref) {
401
+ return /*#__PURE__*/React.createElement(FadeZoom, Object.assign({}, props, {
402
+ scale: 1,
403
+ ref: ref
404
+ }));
405
+ });
406
+ Fade.defaultProps = defaultProps;
407
+
408
+ var Zoom = /*#__PURE__*/React.forwardRef(function (props, ref) {
409
+ return /*#__PURE__*/React.createElement(FadeZoom, Object.assign({}, props, {
410
+ ref: ref
411
+ }));
412
+ });
413
+ Zoom.defaultProps = defaultProps;
414
+
415
+ var Slide = /*#__PURE__*/React.forwardRef(function (props, ref) {
416
+ var _useState = useState(getStartingIndex(props.children, props.defaultIndex)),
417
+ index = _useState[0],
418
+ setIndex = _useState[1];
419
+
420
+ var _useState2 = useState(0),
421
+ wrapperWidth = _useState2[0],
422
+ setWrapperWidth = _useState2[1];
423
+
424
+ var wrapperRef = useRef(null);
425
+ var innerWrapperRef = useRef(null);
426
+ var tweenGroup = new TWEEN.Group();
427
+ var slidesToScroll = useMemo(function () {
428
+ return props.slidesToScroll || 1;
429
+ }, [props.slidesToScroll]);
430
+ var slidesToShow = useMemo(function () {
431
+ return props.slidesToShow || 1;
432
+ }, [props.slidesToShow]);
433
+ var childrenCount = useMemo(function () {
434
+ return React.Children.count(props.children);
435
+ }, [props.children]);
436
+ var eachChildWidth = useMemo(function () {
437
+ return wrapperWidth / slidesToShow;
438
+ }, [wrapperWidth, slidesToShow]);
439
+ var timeout = useRef();
440
+ var resizeObserver = useRef();
441
+ var startingClientX;
442
+ var dragging = false;
443
+ var distanceSwiped = 0;
444
+ var applyStyle = useCallback(function () {
445
+ if (innerWrapperRef.current) {
446
+ var fullwidth = wrapperWidth * innerWrapperRef.current.children.length;
447
+ innerWrapperRef.current.style.width = fullwidth + "px";
448
+
449
+ for (var _index = 0; _index < innerWrapperRef.current.children.length; _index++) {
450
+ var eachDiv = innerWrapperRef.current.children[_index];
451
+
452
+ if (eachDiv) {
453
+ eachDiv.style.width = eachChildWidth + "px";
454
+ eachDiv.style.display = "block";
455
+ }
456
+ }
457
+ }
458
+ }, [wrapperWidth, eachChildWidth]);
459
+ var initResizeObserver = useCallback(function () {
460
+ if (wrapperRef.current) {
461
+ resizeObserver.current = new ResizeObserver(function (entries) {
462
+ if (!entries) return;
463
+ setWidth();
464
+ });
465
+ resizeObserver.current.observe(wrapperRef.current);
466
+ }
467
+ }, [wrapperRef]);
468
+ var play = useCallback(function () {
469
+ var autoplay = props.autoplay,
470
+ infinite = props.infinite,
471
+ duration = props.duration;
472
+
473
+ if (autoplay && (infinite || index < childrenCount - 1)) {
474
+ timeout.current = setTimeout(moveNext, duration);
475
+ } // eslint-disable-next-line react-hooks/exhaustive-deps
476
+
477
+ }, [props, childrenCount, index]);
478
+ useEffect(function () {
479
+ applyStyle();
480
+ }, [wrapperWidth, applyStyle]);
481
+ useEffect(function () {
482
+ initResizeObserver();
483
+ return function () {
484
+ tweenGroup.removeAll();
485
+ clearTimeout(timeout.current);
486
+ removeResizeObserver();
487
+ };
488
+ }, [wrapperRef, initResizeObserver, tweenGroup]);
489
+ useEffect(function () {
490
+ clearTimeout(timeout.current);
491
+ play();
492
+ }, [index, wrapperWidth, props.autoplay, play]);
493
+ useImperativeHandle(ref, function () {
494
+ return {
495
+ goNext: function goNext() {
496
+ moveNext();
497
+ },
498
+ goBack: function goBack() {
499
+ moveBack();
500
+ },
501
+ goTo: function goTo(index) {
502
+ moveTo(index);
503
+ }
504
+ };
505
+ });
506
+
507
+ var removeResizeObserver = function removeResizeObserver() {
508
+ if (resizeObserver && wrapperRef.current) {
509
+ resizeObserver.current.unobserve(wrapperRef.current);
510
+ }
511
+ };
512
+
513
+ var pauseSlides = function pauseSlides() {
514
+ if (props.pauseOnHover) {
515
+ clearTimeout(timeout.current);
516
+ }
517
+ };
518
+
519
+ var swipe = function swipe(event) {
520
+ if (props.canSwipe) {
521
+ var clientX = event.nativeEvent instanceof TouchEvent ? event.nativeEvent.touches[0].pageX : event.nativeEvent.clientX;
522
+
523
+ if (dragging) {
524
+ var translateValue = eachChildWidth * (index + getOffset());
525
+ var distance = clientX - startingClientX;
526
+
527
+ if (!props.infinite && index === childrenCount - slidesToScroll && distance < 0) {
528
+ // if it is the last and infinite is false and you're swiping left
529
+ // then nothing happens
530
+ return;
531
+ }
532
+
533
+ if (!props.infinite && index === 0 && distance > 0) {
534
+ // if it is the first and infinite is false and you're swiping right
535
+ // then nothing happens
536
+ return;
537
+ }
538
+
539
+ distanceSwiped = distance;
540
+ translateValue -= distanceSwiped;
541
+ innerWrapperRef.current.style.transform = "translate(-" + translateValue + "px)";
542
+ }
543
+ }
544
+ };
545
+
546
+ var moveNext = function moveNext() {
547
+ if (!props.infinite && index === childrenCount - slidesToScroll) {
548
+ return;
549
+ }
550
+
551
+ var nextIndex = calculateIndex(index + slidesToScroll);
552
+ transitionSlide(nextIndex);
553
+ };
554
+
555
+ var moveBack = function moveBack() {
556
+ if (!props.infinite && index === 0) {
557
+ return;
558
+ }
559
+
560
+ var previousIndex = index - slidesToScroll;
561
+
562
+ if (previousIndex % slidesToScroll) {
563
+ previousIndex = Math.ceil(previousIndex / slidesToScroll) * slidesToScroll;
564
+ }
565
+
566
+ transitionSlide(previousIndex);
567
+ };
568
+
569
+ var goToSlide = function goToSlide(_ref) {
570
+ var currentTarget = _ref.currentTarget;
571
+
572
+ if (!currentTarget.dataset.key) {
573
+ return;
574
+ }
575
+
576
+ var datasetKey = parseInt(currentTarget.dataset.key);
577
+ moveTo(datasetKey * slidesToScroll);
578
+ };
579
+
580
+ var moveTo = function moveTo(index) {
581
+ transitionSlide(calculateIndex(index));
582
+ };
583
+
584
+ var calculateIndex = function calculateIndex(nextIndex) {
585
+ if (nextIndex < childrenCount && nextIndex + slidesToScroll > childrenCount) {
586
+ if ((childrenCount - slidesToScroll) % slidesToScroll) {
587
+ return childrenCount - slidesToScroll;
588
+ }
589
+
590
+ return nextIndex;
591
+ }
592
+
593
+ return nextIndex;
594
+ };
595
+
596
+ var startSlides = function startSlides() {
597
+ if (dragging) {
598
+ endSwipe();
599
+ } else if (props.pauseOnHover && props.autoplay) {
600
+ timeout.current = setTimeout(moveNext, props.duration);
601
+ }
602
+ };
603
+
604
+ var moveSlides = function moveSlides(_ref2) {
605
+ var dataset = _ref2.currentTarget.dataset;
606
+
607
+ if (dataset.type === 'next') {
608
+ moveNext();
609
+ } else {
610
+ moveBack();
611
+ }
612
+ };
613
+
614
+ var renderPreceedingSlides = function renderPreceedingSlides() {
615
+ return React.Children.toArray(props.children).slice(-slidesToShow).map(function (each, index) {
616
+ return /*#__PURE__*/React.createElement("div", {
617
+ "data-index": index - slidesToShow,
618
+ "aria-roledescription": "slide",
619
+ "aria-hidden": "true",
620
+ key: index - slidesToShow
621
+ }, each);
622
+ });
623
+ };
624
+
625
+ var renderTrailingSlides = function renderTrailingSlides() {
626
+ if (!props.infinite && slidesToShow === slidesToScroll) {
627
+ return;
628
+ }
629
+
630
+ return React.Children.toArray(props.children).slice(0, slidesToShow).map(function (each, index) {
631
+ return /*#__PURE__*/React.createElement("div", {
632
+ "data-index": childrenCount + index,
633
+ "aria-roledescription": "slide",
634
+ "aria-hidden": "true",
635
+ key: childrenCount + index
636
+ }, each);
637
+ });
638
+ };
639
+
640
+ var setWidth = function setWidth() {
641
+ if (wrapperRef.current) {
642
+ setWrapperWidth(wrapperRef.current.clientWidth);
643
+ }
644
+ };
645
+
646
+ var startSwipe = function startSwipe(event) {
647
+ if (props.canSwipe) {
648
+ startingClientX = event.nativeEvent instanceof TouchEvent ? event.nativeEvent.touches[0].pageX : event.nativeEvent.clientX;
649
+ clearTimeout(timeout.current);
650
+ dragging = true;
651
+ }
652
+ };
653
+
654
+ var endSwipe = function endSwipe() {
655
+ if (props.canSwipe) {
656
+ dragging = false;
657
+
658
+ if (Math.abs(distanceSwiped) / wrapperWidth > 0.2) {
659
+ if (distanceSwiped < 0) {
660
+ moveNext();
661
+ } else {
662
+ moveBack();
663
+ }
664
+ } else {
665
+ if (Math.abs(distanceSwiped) > 0) {
666
+ transitionSlide(index, 300);
667
+ }
668
+ }
669
+ }
670
+ };
671
+
672
+ var transitionSlide = function transitionSlide(toIndex, animationDuration) {
673
+ var transitionDuration = animationDuration || props.transitionDuration;
674
+ var currentIndex = index;
675
+ var existingTweens = tweenGroup.getAll();
676
+
677
+ if (!wrapperRef.current) {
678
+ return;
679
+ }
680
+
681
+ var childWidth = wrapperRef.current.clientWidth / slidesToShow;
682
+
683
+ if (!existingTweens.length) {
684
+ clearTimeout(timeout.current);
685
+ var value = {
686
+ margin: -childWidth * (currentIndex + getOffset()) + distanceSwiped
687
+ };
688
+ var tween = new TWEEN.Tween(value, tweenGroup).to({
689
+ margin: -childWidth * (toIndex + getOffset())
690
+ }, transitionDuration).onUpdate(function (value) {
691
+ if (innerWrapperRef.current) {
692
+ innerWrapperRef.current.style.transform = "translate(" + value.margin + "px)";
693
+ }
694
+ }).start();
695
+ tween.easing(getEasing(props.easing));
696
+
697
+ var animate = function animate() {
698
+ requestAnimationFrame(animate);
699
+ tweenGroup.update();
700
+ };
701
+
702
+ animate();
703
+ tween.onComplete(function () {
704
+ distanceSwiped = 0;
705
+ var newIndex = toIndex;
706
+
707
+ if (newIndex < 0) {
708
+ newIndex = childrenCount - slidesToScroll;
709
+ } else if (newIndex >= childrenCount) {
710
+ newIndex = 0;
711
+ }
712
+
713
+ if (typeof props.onChange === 'function') {
714
+ props.onChange(index, newIndex);
715
+ }
716
+
717
+ setIndex(newIndex);
718
+ });
719
+ }
720
+ };
721
+
722
+ var isSlideActive = function isSlideActive(key) {
723
+ return key < index + slidesToShow && key >= index;
724
+ };
725
+
726
+ var getOffset = function getOffset() {
727
+ if (!props.infinite) {
728
+ return 0;
729
+ }
730
+
731
+ return slidesToShow;
732
+ };
733
+
734
+ var style = {
735
+ transform: "translate(-" + (index + getOffset()) * eachChildWidth + "px)"
736
+ };
737
+ return /*#__PURE__*/React.createElement("div", {
738
+ dir: "ltr",
739
+ "aria-roledescription": "carousel"
740
+ }, /*#__PURE__*/React.createElement("div", {
741
+ className: "react-slideshow-container",
742
+ onMouseEnter: pauseSlides,
743
+ onMouseOver: pauseSlides,
744
+ onMouseLeave: startSlides,
745
+ onMouseDown: startSwipe,
746
+ onMouseUp: endSwipe,
747
+ onMouseMove: swipe,
748
+ onTouchStart: startSwipe,
749
+ onTouchEnd: endSwipe,
750
+ onTouchCancel: endSwipe,
751
+ onTouchMove: swipe
752
+ }, props.arrows && showPreviousArrow(props, index, moveSlides), /*#__PURE__*/React.createElement("div", {
753
+ className: "react-slideshow-wrapper slide " + (props.cssClass || ''),
754
+ ref: wrapperRef
755
+ }, /*#__PURE__*/React.createElement("div", {
756
+ className: "images-wrap",
757
+ style: style,
758
+ ref: innerWrapperRef
759
+ }, props.infinite && renderPreceedingSlides(), (React.Children.map(props.children, function (thisArg) {
760
+ return thisArg;
761
+ }) || []).map(function (each, key) {
762
+ var isThisSlideActive = isSlideActive(key);
763
+ return /*#__PURE__*/React.createElement("div", {
764
+ "data-index": key,
765
+ key: key,
766
+ className: isThisSlideActive ? 'active' : '',
767
+ "aria-roledescription": "slide",
768
+ "aria-hidden": isThisSlideActive ? 'false' : 'true'
769
+ }, each);
770
+ }), renderTrailingSlides())), props.arrows && showNextArrow(props, index, moveSlides)), props.indicators && showIndicators(props, index, goToSlide));
771
+ });
772
+ Slide.defaultProps = defaultProps;
773
+
774
+ export { Fade, Slide, Zoom };
775
+ //# sourceMappingURL=react-slideshow-image.esm.js.map