react-spring-carousel 1.9.29-beta46 → 1.9.29-beta47
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/cjs/index.js +85 -139
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +85 -139
- package/dist/esm/index.js.map +1 -1
- package/package.json +1 -1
package/dist/esm/index.js
CHANGED
|
@@ -73,6 +73,33 @@ function useFullscreenModule({ mainCarouselWrapperRef, emitObservable, handleRes
|
|
|
73
73
|
};
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
+
/*! *****************************************************************************
|
|
77
|
+
Copyright (c) Microsoft Corporation.
|
|
78
|
+
|
|
79
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
80
|
+
purpose with or without fee is hereby granted.
|
|
81
|
+
|
|
82
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
83
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
84
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
85
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
86
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
87
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
88
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
89
|
+
***************************************************************************** */
|
|
90
|
+
|
|
91
|
+
function __rest(s, e) {
|
|
92
|
+
var t = {};
|
|
93
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
94
|
+
t[p] = s[p];
|
|
95
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
96
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
97
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
98
|
+
t[p[i]] = s[p[i]];
|
|
99
|
+
}
|
|
100
|
+
return t;
|
|
101
|
+
}
|
|
102
|
+
|
|
76
103
|
function useMount(callback) {
|
|
77
104
|
const isMounted = useRef(false);
|
|
78
105
|
useEffect(() => {
|
|
@@ -90,7 +117,8 @@ function getIsBrowser() {
|
|
|
90
117
|
return typeof window !== 'undefined';
|
|
91
118
|
}
|
|
92
119
|
|
|
93
|
-
const InternalWrapper = forwardRef((
|
|
120
|
+
const InternalWrapper = forwardRef((_a, ref) => {
|
|
121
|
+
var { children } = _a, rest = __rest(_a, ["children"]);
|
|
94
122
|
return (jsx(animated.div, Object.assign({}, rest, { ref: ref }, { children: children }), void 0));
|
|
95
123
|
});
|
|
96
124
|
function useThumbsModule({ items, withThumbs, thumbsSlideAxis = 'x', springConfig, prepareThumbsData, itemsPerSlide, getFluidWrapperScrollValue = () => 0, getSlideValue = () => 0, CustomThumbsWrapperComponent, }) {
|
|
@@ -114,7 +142,8 @@ function useThumbsModule({ items, withThumbs, thumbsSlideAxis = 'x', springConfi
|
|
|
114
142
|
return internalThumbsWrapperRef.current[thumbsSlideAxis === 'x' ? 'scrollLeft' : 'scrollTop'];
|
|
115
143
|
}
|
|
116
144
|
function getThumbsTotalScrollableValue() {
|
|
117
|
-
|
|
145
|
+
var _a;
|
|
146
|
+
return Math.round(Number((_a = internalThumbsWrapperRef.current) === null || _a === void 0 ? void 0 : _a[thumbsSlideAxis === 'x' ? 'scrollWidth' : 'scrollHeight']) -
|
|
118
147
|
internalThumbsWrapperRef.current.getBoundingClientRect()[thumbsSlideAxis === 'x' ? 'width' : 'height']);
|
|
119
148
|
}
|
|
120
149
|
function getThumbSlideValue() {
|
|
@@ -243,18 +272,12 @@ function useThumbsModule({ items, withThumbs, thumbsSlideAxis = 'x', springConfi
|
|
|
243
272
|
: InternalWrapper;
|
|
244
273
|
const thumbsFragment = withThumbs ? (jsx(Wrapper, Object.assign({ ref: internalThumbsWrapperRef, className: "use-spring-carousel-thumbs-wrapper", onWheel: () => {
|
|
245
274
|
thumbListStyles[thumbsSlideAxis].stop();
|
|
246
|
-
}, style: {
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
? { overflowX: 'auto' }
|
|
253
|
-
: {
|
|
254
|
-
overflowY: 'auto',
|
|
255
|
-
maxHeight: '100%',
|
|
256
|
-
}),
|
|
257
|
-
} }, { children: handlePrepareThumbsDate().map(({ id, renderThumb }) => {
|
|
275
|
+
}, style: Object.assign({ display: 'flex', flex: 1, position: 'relative', flexDirection: thumbsSlideAxis === 'x' ? 'row' : 'column' }, (thumbsSlideAxis === 'x'
|
|
276
|
+
? { overflowX: 'auto' }
|
|
277
|
+
: {
|
|
278
|
+
overflowY: 'auto',
|
|
279
|
+
maxHeight: '100%',
|
|
280
|
+
})) }, { children: handlePrepareThumbsDate().map(({ id, renderThumb }) => {
|
|
258
281
|
const thumbId = `thumb-${id}`;
|
|
259
282
|
return (jsx("div", Object.assign({ id: thumbId }, { children: renderThumb }), thumbId));
|
|
260
283
|
}) }), void 0)) : null;
|
|
@@ -298,7 +321,8 @@ function useSpringCarousel({ itemsPerSlide = 1, items, withLoop = false, draggin
|
|
|
298
321
|
},
|
|
299
322
|
}));
|
|
300
323
|
function getCarouselItem() {
|
|
301
|
-
|
|
324
|
+
var _a;
|
|
325
|
+
return (_a = carouselTrackWrapperRef.current) === null || _a === void 0 ? void 0 : _a.querySelector('.use-spring-carousel-item');
|
|
302
326
|
}
|
|
303
327
|
const getMainCarouselWrapperWidth = useCallback(() => {
|
|
304
328
|
if (!mainCarouselWrapperRef.current) {
|
|
@@ -320,7 +344,8 @@ function useSpringCarousel({ itemsPerSlide = 1, items, withLoop = false, draggin
|
|
|
320
344
|
return getCarouselItemWidth() * items.length < getMainCarouselWrapperWidth();
|
|
321
345
|
}, [getCarouselItemWidth, getMainCarouselWrapperWidth, items.length]);
|
|
322
346
|
const getFluidWrapperScrollValue = useCallback(() => {
|
|
323
|
-
|
|
347
|
+
var _a;
|
|
348
|
+
return Math.round(Number((_a = carouselTrackWrapperRef.current) === null || _a === void 0 ? void 0 : _a[carouselSlideAxis === 'x' ? 'scrollWidth' : 'scrollHeight']) -
|
|
324
349
|
carouselTrackWrapperRef.current.getBoundingClientRect()[carouselSlideAxis === 'x' ? 'width' : 'height']);
|
|
325
350
|
}, [carouselSlideAxis]);
|
|
326
351
|
const getIsFirstItem = useCallback(() => {
|
|
@@ -509,11 +534,7 @@ function useSpringCarousel({ itemsPerSlide = 1, items, withLoop = false, draggin
|
|
|
509
534
|
}
|
|
510
535
|
if (isDragging) {
|
|
511
536
|
setIsDragging(true);
|
|
512
|
-
emitObservable({
|
|
513
|
-
eventName: 'onDrag',
|
|
514
|
-
slideActionType: getSlideActionType(),
|
|
515
|
-
...props,
|
|
516
|
-
});
|
|
537
|
+
emitObservable(Object.assign({ eventName: 'onDrag', slideActionType: getSlideActionType() }, props));
|
|
517
538
|
const direction = props.direction[carouselSlideAxis === 'x' ? 0 : 1];
|
|
518
539
|
if (direction > 0) {
|
|
519
540
|
setSlideActionType('prev');
|
|
@@ -586,11 +607,7 @@ function useSpringCarousel({ itemsPerSlide = 1, items, withLoop = false, draggin
|
|
|
586
607
|
}
|
|
587
608
|
if (props.last && !props.pressed && !freeScroll) {
|
|
588
609
|
resetAnimation();
|
|
589
|
-
emitObservable({
|
|
590
|
-
eventName: 'onDrag',
|
|
591
|
-
slideActionType: getSlideActionType(),
|
|
592
|
-
...props,
|
|
593
|
-
});
|
|
610
|
+
emitObservable(Object.assign({ eventName: 'onDrag', slideActionType: getSlideActionType() }, props));
|
|
594
611
|
}
|
|
595
612
|
}, {
|
|
596
613
|
enabled: !disableGestures,
|
|
@@ -758,11 +775,7 @@ function useSpringCarousel({ itemsPerSlide = 1, items, withLoop = false, draggin
|
|
|
758
775
|
[carouselSlideAxis]: -(getSlideValue() * to),
|
|
759
776
|
};
|
|
760
777
|
}
|
|
761
|
-
setCarouselStyles.start({
|
|
762
|
-
...getFromValue(),
|
|
763
|
-
to: getToValue(),
|
|
764
|
-
immediate,
|
|
765
|
-
onRest: val => {
|
|
778
|
+
setCarouselStyles.start(Object.assign(Object.assign({}, getFromValue()), { to: getToValue(), immediate, onRest: val => {
|
|
766
779
|
if (val.finished) {
|
|
767
780
|
setIsDragging(false);
|
|
768
781
|
setIsAnimating(false);
|
|
@@ -778,8 +791,7 @@ function useSpringCarousel({ itemsPerSlide = 1, items, withLoop = false, draggin
|
|
|
778
791
|
});
|
|
779
792
|
}
|
|
780
793
|
}
|
|
781
|
-
}
|
|
782
|
-
});
|
|
794
|
+
} }));
|
|
783
795
|
if (enableThumbsWrapperScroll && withThumbs && !immediate) {
|
|
784
796
|
handleThumbsScroll(to, getSlideActionType());
|
|
785
797
|
}
|
|
@@ -925,8 +937,7 @@ function useSpringCarousel({ itemsPerSlide = 1, items, withLoop = false, draggin
|
|
|
925
937
|
to: itemIndex,
|
|
926
938
|
});
|
|
927
939
|
}
|
|
928
|
-
const contextProps = {
|
|
929
|
-
useListenToCustomEvent,
|
|
940
|
+
const contextProps = Object.assign({ useListenToCustomEvent,
|
|
930
941
|
getIsFullscreen,
|
|
931
942
|
enterFullscreen,
|
|
932
943
|
exitFullscreen,
|
|
@@ -935,34 +946,27 @@ function useSpringCarousel({ itemsPerSlide = 1, items, withLoop = false, draggin
|
|
|
935
946
|
getIsNextItem,
|
|
936
947
|
getIsPrevItem,
|
|
937
948
|
slideToPrevItem,
|
|
938
|
-
slideToNextItem,
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
: {}),
|
|
951
|
-
};
|
|
949
|
+
slideToNextItem }, (typeof itemsPerSlide === 'number'
|
|
950
|
+
? {
|
|
951
|
+
slideToItem: _slideToItem,
|
|
952
|
+
getIsActiveItem: (id) => {
|
|
953
|
+
return findItemIndex(id) === getCurrentActiveItem();
|
|
954
|
+
},
|
|
955
|
+
getCurrentActiveItem: () => ({
|
|
956
|
+
id: items[getCurrentActiveItem()].id,
|
|
957
|
+
index: getCurrentActiveItem(),
|
|
958
|
+
}),
|
|
959
|
+
}
|
|
960
|
+
: {}));
|
|
952
961
|
function getItemStyles() {
|
|
953
962
|
if (typeof itemsPerSlide === 'number') {
|
|
954
|
-
return {
|
|
955
|
-
...(carouselSlideAxis === 'x'
|
|
956
|
-
? { marginRight: `${gutter}px` }
|
|
957
|
-
: { marginBottom: `${gutter}px` }),
|
|
958
|
-
flex: `1 0 calc(100% / ${itemsPerSlide} - ${(gutter * (itemsPerSlide - 1)) / itemsPerSlide}px)`,
|
|
959
|
-
};
|
|
960
|
-
}
|
|
961
|
-
return {
|
|
962
|
-
...(carouselSlideAxis === 'x'
|
|
963
|
+
return Object.assign(Object.assign({}, (carouselSlideAxis === 'x'
|
|
963
964
|
? { marginRight: `${gutter}px` }
|
|
964
|
-
: { marginBottom: `${gutter}px` }),
|
|
965
|
-
}
|
|
965
|
+
: { marginBottom: `${gutter}px` })), { flex: `1 0 calc(100% / ${itemsPerSlide} - ${(gutter * (itemsPerSlide - 1)) / itemsPerSlide}px)` });
|
|
966
|
+
}
|
|
967
|
+
return Object.assign({}, (carouselSlideAxis === 'x'
|
|
968
|
+
? { marginRight: `${gutter}px` }
|
|
969
|
+
: { marginBottom: `${gutter}px` }));
|
|
966
970
|
}
|
|
967
971
|
function getAnimatedWrapperStyles() {
|
|
968
972
|
const percentValue = `calc(100% - ${startEndGutter * 2}px)`;
|
|
@@ -1011,32 +1015,12 @@ function useSpringCarousel({ itemsPerSlide = 1, items, withLoop = false, draggin
|
|
|
1011
1015
|
}
|
|
1012
1016
|
const carouselFragment = (jsx(UseSpringCarouselContext.Provider, Object.assign({ value: contextProps }, { children: jsx("div", Object.assign({ ref: mainCarouselWrapperRef, className: "use-spring-carousel-main-wrapper", "data-testid": "use-spring-carousel-wrapper" }, getWheelEvent(), {
|
|
1013
1017
|
// @ts-ignore
|
|
1014
|
-
style: {
|
|
1015
|
-
|
|
1016
|
-
position: 'relative',
|
|
1017
|
-
width: '100%',
|
|
1018
|
-
height: '100%',
|
|
1019
|
-
...getOverflowStyles(),
|
|
1020
|
-
} }, { children: jsx(animated.div, Object.assign({}, bindDrag(), { className: "use-spring-carousel-track-wrapper", "data-testid": "use-spring-carousel-animated-wrapper", ref: handleCarouselFragmentRef, style: {
|
|
1021
|
-
display: 'flex',
|
|
1022
|
-
position: 'relative',
|
|
1023
|
-
touchAction: getTouchAction(),
|
|
1024
|
-
flexDirection: carouselSlideAxis === 'x' ? 'row' : 'column',
|
|
1025
|
-
...getAnimatedWrapperStyles(),
|
|
1026
|
-
...(freeScroll ? {} : carouselStyles),
|
|
1027
|
-
} }, { children: internalItems.map(({ id, renderItem }, index) => {
|
|
1028
|
-
return (jsx("div", Object.assign({ className: "use-spring-carousel-item", "data-testid": "use-spring-carousel-item-wrapper", style: {
|
|
1029
|
-
display: 'flex',
|
|
1030
|
-
position: 'relative',
|
|
1031
|
-
...getItemStyles(),
|
|
1032
|
-
} }, { children: renderItem }), `${id}-${index}`));
|
|
1018
|
+
style: Object.assign({ display: 'flex', position: 'relative', width: '100%', height: '100%' }, getOverflowStyles()) }, { children: jsx(animated.div, Object.assign({}, bindDrag(), { className: "use-spring-carousel-track-wrapper", "data-testid": "use-spring-carousel-animated-wrapper", ref: handleCarouselFragmentRef, style: Object.assign(Object.assign({ display: 'flex', position: 'relative', touchAction: getTouchAction(), flexDirection: carouselSlideAxis === 'x' ? 'row' : 'column' }, getAnimatedWrapperStyles()), (freeScroll ? {} : carouselStyles)) }, { children: internalItems.map(({ id, renderItem }, index) => {
|
|
1019
|
+
return (jsx("div", Object.assign({ className: "use-spring-carousel-item", "data-testid": "use-spring-carousel-item-wrapper", style: Object.assign({ display: 'flex', position: 'relative' }, getItemStyles()) }, { children: renderItem }), `${id}-${index}`));
|
|
1033
1020
|
}) }), void 0) }), void 0) }), void 0));
|
|
1034
1021
|
const thumbsFragment = (jsx(UseSpringCarouselContext.Provider, Object.assign({ value: contextProps }, { children: _thumbsFragment }), void 0));
|
|
1035
|
-
return {
|
|
1036
|
-
|
|
1037
|
-
carouselFragment,
|
|
1038
|
-
thumbsFragment,
|
|
1039
|
-
};
|
|
1022
|
+
return Object.assign(Object.assign({}, contextProps), { carouselFragment,
|
|
1023
|
+
thumbsFragment });
|
|
1040
1024
|
}
|
|
1041
1025
|
function useSpringCarouselContext() {
|
|
1042
1026
|
const context = useContext(UseSpringCarouselContext);
|
|
@@ -1125,57 +1109,28 @@ function useTransitionCarousel({ items, withLoop = false, withThumbs = false, sp
|
|
|
1125
1109
|
const slideActionType = getSlideActionType();
|
|
1126
1110
|
if (slideActionType === 'prev' && toPrevItemSpringProps) {
|
|
1127
1111
|
return {
|
|
1128
|
-
initial: {
|
|
1129
|
-
|
|
1130
|
-
},
|
|
1131
|
-
|
|
1132
|
-
...toPrevItemSpringProps.from,
|
|
1133
|
-
},
|
|
1134
|
-
enter: {
|
|
1135
|
-
...toPrevItemSpringProps.enter,
|
|
1136
|
-
},
|
|
1137
|
-
leave: {
|
|
1138
|
-
...toPrevItemSpringProps.leave,
|
|
1139
|
-
},
|
|
1112
|
+
initial: Object.assign({}, springAnimationProps.initial),
|
|
1113
|
+
from: Object.assign({}, toPrevItemSpringProps.from),
|
|
1114
|
+
enter: Object.assign({}, toPrevItemSpringProps.enter),
|
|
1115
|
+
leave: Object.assign({}, toPrevItemSpringProps.leave),
|
|
1140
1116
|
};
|
|
1141
1117
|
}
|
|
1142
1118
|
if (slideActionType === 'next' && toNextItemSpringProps) {
|
|
1143
1119
|
return {
|
|
1144
|
-
initial: {
|
|
1145
|
-
|
|
1146
|
-
},
|
|
1147
|
-
|
|
1148
|
-
...toNextItemSpringProps.from,
|
|
1149
|
-
},
|
|
1150
|
-
enter: {
|
|
1151
|
-
...toNextItemSpringProps.enter,
|
|
1152
|
-
},
|
|
1153
|
-
leave: {
|
|
1154
|
-
...toNextItemSpringProps.leave,
|
|
1155
|
-
},
|
|
1120
|
+
initial: Object.assign({}, springAnimationProps.initial),
|
|
1121
|
+
from: Object.assign({}, toNextItemSpringProps.from),
|
|
1122
|
+
enter: Object.assign({}, toNextItemSpringProps.enter),
|
|
1123
|
+
leave: Object.assign({}, toNextItemSpringProps.leave),
|
|
1156
1124
|
};
|
|
1157
1125
|
}
|
|
1158
1126
|
return {
|
|
1159
|
-
initial: {
|
|
1160
|
-
|
|
1161
|
-
},
|
|
1162
|
-
|
|
1163
|
-
...springAnimationProps.from,
|
|
1164
|
-
},
|
|
1165
|
-
enter: {
|
|
1166
|
-
...springAnimationProps.enter,
|
|
1167
|
-
},
|
|
1168
|
-
leave: {
|
|
1169
|
-
...springAnimationProps.leave,
|
|
1170
|
-
},
|
|
1127
|
+
initial: Object.assign({}, springAnimationProps.initial),
|
|
1128
|
+
from: Object.assign({}, springAnimationProps.from),
|
|
1129
|
+
enter: Object.assign({}, springAnimationProps.enter),
|
|
1130
|
+
leave: Object.assign({}, springAnimationProps.leave),
|
|
1171
1131
|
};
|
|
1172
1132
|
}
|
|
1173
|
-
const transitions = useTransition(activeItem, {
|
|
1174
|
-
config: springConfig,
|
|
1175
|
-
...getTransitionConfig(),
|
|
1176
|
-
onStart: () => setIsAnimating(true),
|
|
1177
|
-
keys: null,
|
|
1178
|
-
onRest: val => {
|
|
1133
|
+
const transitions = useTransition(activeItem, Object.assign(Object.assign({ config: springConfig }, getTransitionConfig()), { onStart: () => setIsAnimating(true), keys: null, onRest: val => {
|
|
1179
1134
|
if (val.finished) {
|
|
1180
1135
|
setIsAnimating(false);
|
|
1181
1136
|
emitObservable({
|
|
@@ -1187,14 +1142,8 @@ function useTransitionCarousel({ items, withLoop = false, withThumbs = false, sp
|
|
|
1187
1142
|
},
|
|
1188
1143
|
});
|
|
1189
1144
|
}
|
|
1190
|
-
}
|
|
1191
|
-
});
|
|
1192
|
-
const itemsFragment = transitions((styles, item) => (jsx(animated.div, Object.assign({ style: {
|
|
1193
|
-
...styles,
|
|
1194
|
-
flex: '1 0 100%',
|
|
1195
|
-
width: '100%',
|
|
1196
|
-
height: '100%',
|
|
1197
|
-
} }, { children: items[item].renderItem }), void 0)));
|
|
1145
|
+
} }));
|
|
1146
|
+
const itemsFragment = transitions((styles, item) => (jsx(animated.div, Object.assign({ style: Object.assign(Object.assign({}, styles), { flex: '1 0 100%', width: '100%', height: '100%' }) }, { children: items[item].renderItem }), void 0)));
|
|
1198
1147
|
function getIsAnimating() {
|
|
1199
1148
|
return isAnimating.current;
|
|
1200
1149
|
}
|
|
@@ -1372,11 +1321,8 @@ function useTransitionCarousel({ items, withLoop = false, withThumbs = false, sp
|
|
|
1372
1321
|
overflow: 'hidden',
|
|
1373
1322
|
} }, { children: itemsFragment }), void 0) }), void 0));
|
|
1374
1323
|
const thumbsFragment = (jsx(UseTransitionCarouselContext.Provider, Object.assign({ value: contextProps }, { children: _thumbsFragment }), void 0));
|
|
1375
|
-
return {
|
|
1376
|
-
|
|
1377
|
-
thumbsFragment,
|
|
1378
|
-
...contextProps,
|
|
1379
|
-
};
|
|
1324
|
+
return Object.assign({ carouselFragment,
|
|
1325
|
+
thumbsFragment }, contextProps);
|
|
1380
1326
|
}
|
|
1381
1327
|
|
|
1382
1328
|
export { useSpringCarousel, useSpringCarouselContext, useTransitionCarousel, useTransitionCarouselContext };
|