react-slideshow-image 3.7.5 → 4.0.2

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