@kolserdav/swiper 2.1.0-beta → 2.2.0-alfa
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.
- package/dist/index.js +126 -46
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +128 -48
- package/dist/index.modern.js.map +1 -1
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -3,6 +3,7 @@ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'defau
|
|
|
3
3
|
var React = require('react');
|
|
4
4
|
var React__default = _interopDefault(React);
|
|
5
5
|
var material = require('@mui/material');
|
|
6
|
+
var styles = require('@mui/styles');
|
|
6
7
|
var clsx = _interopDefault(require('clsx'));
|
|
7
8
|
var StopIcon = _interopDefault(require('@mui/icons-material/StopScreenShare'));
|
|
8
9
|
var NavigateNextIcon = _interopDefault(require('@mui/icons-material/NavigateNext'));
|
|
@@ -200,8 +201,64 @@ function _switch(discriminant, cases) {
|
|
|
200
201
|
}
|
|
201
202
|
}
|
|
202
203
|
|
|
203
|
-
var
|
|
204
|
-
|
|
204
|
+
var useStyles = styles.makeStyles(function () {
|
|
205
|
+
return {
|
|
206
|
+
go: {
|
|
207
|
+
transition: 'left 0.4s ease-out 0s'
|
|
208
|
+
},
|
|
209
|
+
back: {
|
|
210
|
+
transition: 'left 0.4s ease-in 0s'
|
|
211
|
+
},
|
|
212
|
+
container: {
|
|
213
|
+
position: 'relative',
|
|
214
|
+
overflow: 'hidden',
|
|
215
|
+
minWidth: '320px',
|
|
216
|
+
width: '100%',
|
|
217
|
+
height: '100%',
|
|
218
|
+
minHeight: '80vh',
|
|
219
|
+
maxWidth: '100vw',
|
|
220
|
+
display: 'flex',
|
|
221
|
+
alignItems: 'center',
|
|
222
|
+
justifyContent: 'center'
|
|
223
|
+
},
|
|
224
|
+
button: {
|
|
225
|
+
cursor: 'pointer',
|
|
226
|
+
position: 'absolute',
|
|
227
|
+
width: 'auto',
|
|
228
|
+
height: 'auto',
|
|
229
|
+
display: 'flex',
|
|
230
|
+
alignItems: 'center',
|
|
231
|
+
zIndex: '12'
|
|
232
|
+
},
|
|
233
|
+
button__prev: {
|
|
234
|
+
left: 0,
|
|
235
|
+
transform: 'rotate(180deg)'
|
|
236
|
+
},
|
|
237
|
+
button__next: {
|
|
238
|
+
right: 0
|
|
239
|
+
},
|
|
240
|
+
content: {
|
|
241
|
+
position: 'relative',
|
|
242
|
+
width: 'calc(100% - 48px)',
|
|
243
|
+
height: 'calc(100% - 48px)'
|
|
244
|
+
},
|
|
245
|
+
card: {
|
|
246
|
+
position: 'absolute',
|
|
247
|
+
maxWidth: 'inherit',
|
|
248
|
+
top: 0,
|
|
249
|
+
left: 0,
|
|
250
|
+
display: 'flex',
|
|
251
|
+
alignItems: 'center',
|
|
252
|
+
justifyContent: 'center'
|
|
253
|
+
},
|
|
254
|
+
card__prev: {
|
|
255
|
+
left: '-100%'
|
|
256
|
+
},
|
|
257
|
+
card__next: {
|
|
258
|
+
left: '100%'
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
});
|
|
205
262
|
var SWIPE_TRANSITION_TIMEOUT = 400;
|
|
206
263
|
|
|
207
264
|
var getSwipes = function getSwipes(prev, current, next, swipes) {
|
|
@@ -242,6 +299,18 @@ var Swiper = function Swiper(props) {
|
|
|
242
299
|
className = props.className,
|
|
243
300
|
invitationAnimation = props.invitationAnimation;
|
|
244
301
|
|
|
302
|
+
var _useStyles = useStyles(),
|
|
303
|
+
go = _useStyles.go,
|
|
304
|
+
card = _useStyles.card,
|
|
305
|
+
card__next = _useStyles.card__next,
|
|
306
|
+
card__prev = _useStyles.card__prev,
|
|
307
|
+
button = _useStyles.button,
|
|
308
|
+
button__next = _useStyles.button__next,
|
|
309
|
+
button__prev = _useStyles.button__prev,
|
|
310
|
+
back = _useStyles.back,
|
|
311
|
+
container = _useStyles.container,
|
|
312
|
+
content = _useStyles.content;
|
|
313
|
+
|
|
245
314
|
var _useState = React.useState(),
|
|
246
315
|
current = _useState[0],
|
|
247
316
|
setCurrent = _useState[1];
|
|
@@ -278,11 +347,11 @@ var Swiper = function Swiper(props) {
|
|
|
278
347
|
isMobile = _useState9[0],
|
|
279
348
|
setIsMobile = _useState9[1];
|
|
280
349
|
|
|
281
|
-
var
|
|
350
|
+
var _useState10 = React.useState(true),
|
|
351
|
+
load = _useState10[0],
|
|
352
|
+
setLoad = _useState10[1];
|
|
282
353
|
|
|
283
|
-
var
|
|
284
|
-
|
|
285
|
-
var _buttonNextRef = React.useRef(null);
|
|
354
|
+
var containerRef = React.useRef(null);
|
|
286
355
|
|
|
287
356
|
if (typeof _defaultCurrent === 'undefined') {
|
|
288
357
|
_defaultCurrent = defaultCurrent;
|
|
@@ -298,33 +367,33 @@ var Swiper = function Swiper(props) {
|
|
|
298
367
|
return refs[id];
|
|
299
368
|
};
|
|
300
369
|
|
|
301
|
-
var
|
|
370
|
+
var setGoClassHandler = function setGoClassHandler() {
|
|
302
371
|
var _getRef$current, _getRef$current2, _getRef$current3;
|
|
303
372
|
|
|
304
|
-
(_getRef$current = getRef((next === null || next === void 0 ? void 0 : next.id) || 0).current) === null || _getRef$current === void 0 ? void 0 : _getRef$current.classList.add(
|
|
305
|
-
(_getRef$current2 = getRef((prev === null || prev === void 0 ? void 0 : prev.id) || 0).current) === null || _getRef$current2 === void 0 ? void 0 : _getRef$current2.classList.add(
|
|
306
|
-
(_getRef$current3 = getRef((current === null || current === void 0 ? void 0 : current.id) || 0).current) === null || _getRef$current3 === void 0 ? void 0 : _getRef$current3.classList.add(
|
|
373
|
+
(_getRef$current = getRef((next === null || next === void 0 ? void 0 : next.id) || 0).current) === null || _getRef$current === void 0 ? void 0 : _getRef$current.classList.add(go);
|
|
374
|
+
(_getRef$current2 = getRef((prev === null || prev === void 0 ? void 0 : prev.id) || 0).current) === null || _getRef$current2 === void 0 ? void 0 : _getRef$current2.classList.add(go);
|
|
375
|
+
(_getRef$current3 = getRef((current === null || current === void 0 ? void 0 : current.id) || 0).current) === null || _getRef$current3 === void 0 ? void 0 : _getRef$current3.classList.add(go);
|
|
307
376
|
setTimeout(function () {
|
|
308
377
|
var _getRef$current4, _getRef$current5, _getRef$current6;
|
|
309
378
|
|
|
310
|
-
(_getRef$current4 = getRef((next === null || next === void 0 ? void 0 : next.id) || 0).current) === null || _getRef$current4 === void 0 ? void 0 : _getRef$current4.classList.remove(
|
|
311
|
-
(_getRef$current5 = getRef((prev === null || prev === void 0 ? void 0 : prev.id) || 0).current) === null || _getRef$current5 === void 0 ? void 0 : _getRef$current5.classList.remove(
|
|
312
|
-
(_getRef$current6 = getRef((current === null || current === void 0 ? void 0 : current.id) || 0).current) === null || _getRef$current6 === void 0 ? void 0 : _getRef$current6.classList.remove(
|
|
379
|
+
(_getRef$current4 = getRef((next === null || next === void 0 ? void 0 : next.id) || 0).current) === null || _getRef$current4 === void 0 ? void 0 : _getRef$current4.classList.remove(go);
|
|
380
|
+
(_getRef$current5 = getRef((prev === null || prev === void 0 ? void 0 : prev.id) || 0).current) === null || _getRef$current5 === void 0 ? void 0 : _getRef$current5.classList.remove(go);
|
|
381
|
+
(_getRef$current6 = getRef((current === null || current === void 0 ? void 0 : current.id) || 0).current) === null || _getRef$current6 === void 0 ? void 0 : _getRef$current6.classList.remove(go);
|
|
313
382
|
}, SWIPE_TRANSITION_TIMEOUT);
|
|
314
383
|
};
|
|
315
384
|
|
|
316
|
-
var
|
|
385
|
+
var setBackClassHandler = function setBackClassHandler() {
|
|
317
386
|
var _getRef$current7, _getRef$current8, _getRef$current9;
|
|
318
387
|
|
|
319
|
-
(_getRef$current7 = getRef((next === null || next === void 0 ? void 0 : next.id) || 0).current) === null || _getRef$current7 === void 0 ? void 0 : _getRef$current7.classList.add(
|
|
320
|
-
(_getRef$current8 = getRef((prev === null || prev === void 0 ? void 0 : prev.id) || 0).current) === null || _getRef$current8 === void 0 ? void 0 : _getRef$current8.classList.add(
|
|
321
|
-
(_getRef$current9 = getRef((current === null || current === void 0 ? void 0 : current.id) || 0).current) === null || _getRef$current9 === void 0 ? void 0 : _getRef$current9.classList.add(
|
|
388
|
+
(_getRef$current7 = getRef((next === null || next === void 0 ? void 0 : next.id) || 0).current) === null || _getRef$current7 === void 0 ? void 0 : _getRef$current7.classList.add(back);
|
|
389
|
+
(_getRef$current8 = getRef((prev === null || prev === void 0 ? void 0 : prev.id) || 0).current) === null || _getRef$current8 === void 0 ? void 0 : _getRef$current8.classList.add(back);
|
|
390
|
+
(_getRef$current9 = getRef((current === null || current === void 0 ? void 0 : current.id) || 0).current) === null || _getRef$current9 === void 0 ? void 0 : _getRef$current9.classList.add(back);
|
|
322
391
|
setTimeout(function () {
|
|
323
392
|
var _getRef$current10, _getRef$current11, _getRef$current12;
|
|
324
393
|
|
|
325
|
-
(_getRef$current10 = getRef((next === null || next === void 0 ? void 0 : next.id) || 0).current) === null || _getRef$current10 === void 0 ? void 0 : _getRef$current10.classList.remove(
|
|
326
|
-
(_getRef$current11 = getRef((prev === null || prev === void 0 ? void 0 : prev.id) || 0).current) === null || _getRef$current11 === void 0 ? void 0 : _getRef$current11.classList.remove(
|
|
327
|
-
(_getRef$current12 = getRef((current === null || current === void 0 ? void 0 : current.id) || 0).current) === null || _getRef$current12 === void 0 ? void 0 : _getRef$current12.classList.remove(
|
|
394
|
+
(_getRef$current10 = getRef((next === null || next === void 0 ? void 0 : next.id) || 0).current) === null || _getRef$current10 === void 0 ? void 0 : _getRef$current10.classList.remove(back);
|
|
395
|
+
(_getRef$current11 = getRef((prev === null || prev === void 0 ? void 0 : prev.id) || 0).current) === null || _getRef$current11 === void 0 ? void 0 : _getRef$current11.classList.remove(back);
|
|
396
|
+
(_getRef$current12 = getRef((current === null || current === void 0 ? void 0 : current.id) || 0).current) === null || _getRef$current12 === void 0 ? void 0 : _getRef$current12.classList.remove(back);
|
|
328
397
|
}, SWIPE_TRANSITION_TIMEOUT);
|
|
329
398
|
};
|
|
330
399
|
|
|
@@ -363,10 +432,12 @@ var Swiper = function Swiper(props) {
|
|
|
363
432
|
onSwipe(currentId);
|
|
364
433
|
}
|
|
365
434
|
|
|
435
|
+
setLoad(false);
|
|
366
436
|
return 0;
|
|
367
437
|
};
|
|
368
438
|
|
|
369
439
|
var _exit2 = false;
|
|
440
|
+
setLoad(true);
|
|
370
441
|
var startTime;
|
|
371
442
|
var currentId = 0;
|
|
372
443
|
|
|
@@ -385,13 +456,14 @@ var Swiper = function Swiper(props) {
|
|
|
385
456
|
};
|
|
386
457
|
|
|
387
458
|
if (!(next !== null && next !== void 0 && next.id)) {
|
|
388
|
-
|
|
459
|
+
setBackClassHandler();
|
|
389
460
|
setLeft(0);
|
|
461
|
+
setLoad(false);
|
|
390
462
|
_exit2 = true;
|
|
391
463
|
return 1;
|
|
392
464
|
}
|
|
393
465
|
|
|
394
|
-
|
|
466
|
+
setGoClassHandler();
|
|
395
467
|
setLeft(windowWidth * -1);
|
|
396
468
|
startTime = new Date().getTime();
|
|
397
469
|
|
|
@@ -425,13 +497,14 @@ var Swiper = function Swiper(props) {
|
|
|
425
497
|
};
|
|
426
498
|
|
|
427
499
|
if (!(prev !== null && prev !== void 0 && prev.id)) {
|
|
428
|
-
|
|
500
|
+
setBackClassHandler();
|
|
429
501
|
setLeft(0);
|
|
502
|
+
setLoad(false);
|
|
430
503
|
_exit2 = true;
|
|
431
504
|
return 1;
|
|
432
505
|
}
|
|
433
506
|
|
|
434
|
-
|
|
507
|
+
setGoClassHandler();
|
|
435
508
|
setLeft(windowWidth);
|
|
436
509
|
startTime = new Date().getTime();
|
|
437
510
|
|
|
@@ -456,8 +529,9 @@ var Swiper = function Swiper(props) {
|
|
|
456
529
|
}
|
|
457
530
|
}();
|
|
458
531
|
} else {
|
|
459
|
-
|
|
532
|
+
setBackClassHandler();
|
|
460
533
|
setLeft(0);
|
|
534
|
+
setLoad(false);
|
|
461
535
|
_exit2 = true;
|
|
462
536
|
return 1;
|
|
463
537
|
}
|
|
@@ -513,18 +587,23 @@ var Swiper = function Swiper(props) {
|
|
|
513
587
|
var isNext = origin === 'next';
|
|
514
588
|
return function () {
|
|
515
589
|
try {
|
|
590
|
+
if (load) {
|
|
591
|
+
return Promise.resolve(1);
|
|
592
|
+
}
|
|
593
|
+
|
|
516
594
|
var coeff = isNext ? -1 : 1;
|
|
517
595
|
var leftVal = width * coeff;
|
|
518
596
|
|
|
519
597
|
if (isNext) {
|
|
520
|
-
|
|
598
|
+
setGoClassHandler();
|
|
521
599
|
} else {
|
|
522
|
-
|
|
600
|
+
setBackClassHandler();
|
|
523
601
|
}
|
|
524
602
|
|
|
525
|
-
setLeft(leftVal);
|
|
526
603
|
return Promise.resolve(wait(SWIPE_TRANSITION_TIMEOUT / 2)).then(function () {
|
|
527
|
-
return Promise.resolve(swipe(leftVal)).then(function () {
|
|
604
|
+
return Promise.resolve(swipe(leftVal)).then(function () {
|
|
605
|
+
return 0;
|
|
606
|
+
});
|
|
528
607
|
});
|
|
529
608
|
} catch (e) {
|
|
530
609
|
return Promise.reject(e);
|
|
@@ -563,20 +642,21 @@ var Swiper = function Swiper(props) {
|
|
|
563
642
|
var infitationAnimationHandler = function infitationAnimationHandler(shift) {
|
|
564
643
|
try {
|
|
565
644
|
if (shift < 0) {
|
|
566
|
-
|
|
645
|
+
setGoClassHandler();
|
|
567
646
|
} else {
|
|
568
|
-
|
|
647
|
+
setBackClassHandler();
|
|
569
648
|
}
|
|
570
649
|
|
|
571
650
|
setLeft(shift);
|
|
572
651
|
return Promise.resolve(wait(SWIPE_TRANSITION_TIMEOUT)).then(function () {
|
|
573
652
|
if (shift < 0) {
|
|
574
|
-
|
|
653
|
+
setBackClassHandler();
|
|
575
654
|
} else {
|
|
576
|
-
|
|
655
|
+
setGoClassHandler();
|
|
577
656
|
}
|
|
578
657
|
|
|
579
658
|
setLeft(0);
|
|
659
|
+
return Promise.resolve(wait(SWIPE_TRANSITION_TIMEOUT)).then(function () {});
|
|
580
660
|
});
|
|
581
661
|
} catch (e) {
|
|
582
662
|
return Promise.reject(e);
|
|
@@ -614,12 +694,12 @@ var Swiper = function Swiper(props) {
|
|
|
614
694
|
setCurrent(defaultCurrent);
|
|
615
695
|
setPrev(_p);
|
|
616
696
|
setNext(_n);
|
|
617
|
-
setLeft(_left);
|
|
618
697
|
return Promise.resolve(getPrev(_p.id || 0)).then(function (_getPrev) {
|
|
619
698
|
prePrev = _getPrev;
|
|
620
699
|
return Promise.resolve(getNext(_n.id || 0)).then(function (_getNext) {
|
|
621
700
|
postNext = _getNext;
|
|
622
701
|
_defaultCurrent = defaultCurrent;
|
|
702
|
+
setLoad(false);
|
|
623
703
|
});
|
|
624
704
|
});
|
|
625
705
|
});
|
|
@@ -637,7 +717,7 @@ var Swiper = function Swiper(props) {
|
|
|
637
717
|
var _temp18 = function _temp18() {
|
|
638
718
|
var _temp15 = function () {
|
|
639
719
|
if (next !== null && next !== void 0 && next.id) {
|
|
640
|
-
return Promise.resolve(infitationAnimationHandler(-
|
|
720
|
+
return Promise.resolve(infitationAnimationHandler(windowWidth / 5.5 * -1)).then(function () {});
|
|
641
721
|
}
|
|
642
722
|
}();
|
|
643
723
|
|
|
@@ -646,7 +726,7 @@ var Swiper = function Swiper(props) {
|
|
|
646
726
|
|
|
647
727
|
var _temp19 = function () {
|
|
648
728
|
if (prev !== null && prev !== void 0 && prev.id) {
|
|
649
|
-
return Promise.resolve(infitationAnimationHandler(
|
|
729
|
+
return Promise.resolve(infitationAnimationHandler(windowWidth / 5.5)).then(function () {});
|
|
650
730
|
}
|
|
651
731
|
}();
|
|
652
732
|
|
|
@@ -668,14 +748,14 @@ var Swiper = function Swiper(props) {
|
|
|
668
748
|
};
|
|
669
749
|
}, [next, defaultCurrent]);
|
|
670
750
|
return React__default.createElement("div", {
|
|
671
|
-
className:
|
|
751
|
+
className: container,
|
|
672
752
|
ref: containerRef
|
|
673
753
|
}, swipes.map(function (item) {
|
|
674
754
|
var _item$id;
|
|
675
755
|
|
|
676
756
|
return React__default.createElement("div", {
|
|
677
757
|
key: item.id
|
|
678
|
-
}, React__default.createElement(
|
|
758
|
+
}, React__default.createElement(React.Fragment, null, item.id && width && React__default.createElement("div", {
|
|
679
759
|
onTouchMove: onTouchWrapper('onTouchMove'),
|
|
680
760
|
onTouchStart: onTouchWrapper('onTouchStart'),
|
|
681
761
|
onTouchEnd: onTouchWrapper('onTouchEnd'),
|
|
@@ -693,10 +773,10 @@ var Swiper = function Swiper(props) {
|
|
|
693
773
|
height: height,
|
|
694
774
|
left: left + windowWidth
|
|
695
775
|
},
|
|
696
|
-
className: clsx(
|
|
776
|
+
className: clsx(card, item.type === 'prev' ? card__prev : item.type === 'next' ? card__next : ''),
|
|
697
777
|
ref: getRef(item.id)
|
|
698
|
-
}, React__default.createElement(
|
|
699
|
-
className: clsx(
|
|
778
|
+
}, React__default.createElement(material.Paper, {
|
|
779
|
+
className: clsx(content, className)
|
|
700
780
|
}, item.children)), !item.id && React__default.createElement("div", {
|
|
701
781
|
style: item.type === 'current' ? {
|
|
702
782
|
width: width,
|
|
@@ -711,19 +791,19 @@ var Swiper = function Swiper(props) {
|
|
|
711
791
|
height: height,
|
|
712
792
|
left: left + windowWidth
|
|
713
793
|
},
|
|
714
|
-
className: clsx(
|
|
794
|
+
className: clsx(card, item.type === 'prev' ? card__prev : item.type === 'next' ? card__next : '')
|
|
715
795
|
}, React__default.createElement(material.IconButton, {
|
|
716
796
|
disabled: true
|
|
717
797
|
}, React__default.createElement(StopIcon, null)))));
|
|
718
798
|
}), typeof isMobile !== 'undefined' && !isMobile && (prev === null || prev === void 0 ? void 0 : prev.id) && React__default.createElement("div", {
|
|
719
|
-
className: clsx(
|
|
720
|
-
ref: _buttonPrevRef
|
|
799
|
+
className: clsx(button, button__prev)
|
|
721
800
|
}, React__default.createElement(material.IconButton, {
|
|
801
|
+
disabled: load,
|
|
722
802
|
onClick: clickPrevHandler
|
|
723
803
|
}, React__default.createElement(NavigateNextIcon, null))), typeof isMobile !== 'undefined' && !isMobile && (next === null || next === void 0 ? void 0 : next.id) && React__default.createElement("div", {
|
|
724
|
-
className: clsx(
|
|
725
|
-
ref: _buttonNextRef
|
|
804
|
+
className: clsx(button, button__next)
|
|
726
805
|
}, React__default.createElement(material.IconButton, {
|
|
806
|
+
disabled: load,
|
|
727
807
|
onClick: clickNextHandler
|
|
728
808
|
}, React__default.createElement(NavigateNextIcon, null))));
|
|
729
809
|
};
|