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