react-spring-carousel 1.9.29-beta45 → 1.9.29-beta49

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 CHANGED
@@ -81,6 +81,33 @@ function useFullscreenModule({ mainCarouselWrapperRef, emitObservable, handleRes
81
81
  };
82
82
  }
83
83
 
84
+ /*! *****************************************************************************
85
+ Copyright (c) Microsoft Corporation.
86
+
87
+ Permission to use, copy, modify, and/or distribute this software for any
88
+ purpose with or without fee is hereby granted.
89
+
90
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
91
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
92
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
93
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
94
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
95
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
96
+ PERFORMANCE OF THIS SOFTWARE.
97
+ ***************************************************************************** */
98
+
99
+ function __rest(s, e) {
100
+ var t = {};
101
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
102
+ t[p] = s[p];
103
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
104
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
105
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
106
+ t[p[i]] = s[p[i]];
107
+ }
108
+ return t;
109
+ }
110
+
84
111
  function useMount(callback) {
85
112
  const isMounted = react.useRef(false);
86
113
  react.useEffect(() => {
@@ -98,7 +125,8 @@ function getIsBrowser() {
98
125
  return typeof window !== 'undefined';
99
126
  }
100
127
 
101
- const InternalWrapper = react.forwardRef(({ children, ...rest }, ref) => {
128
+ const InternalWrapper = react.forwardRef((_a, ref) => {
129
+ var { children } = _a, rest = __rest(_a, ["children"]);
102
130
  return (jsxRuntime.jsx(reactSpring.animated.div, Object.assign({}, rest, { ref: ref }, { children: children }), void 0));
103
131
  });
104
132
  function useThumbsModule({ items, withThumbs, thumbsSlideAxis = 'x', springConfig, prepareThumbsData, itemsPerSlide, getFluidWrapperScrollValue = () => 0, getSlideValue = () => 0, CustomThumbsWrapperComponent, }) {
@@ -122,7 +150,8 @@ function useThumbsModule({ items, withThumbs, thumbsSlideAxis = 'x', springConfi
122
150
  return internalThumbsWrapperRef.current[thumbsSlideAxis === 'x' ? 'scrollLeft' : 'scrollTop'];
123
151
  }
124
152
  function getThumbsTotalScrollableValue() {
125
- return Math.round(Number(internalThumbsWrapperRef.current?.[thumbsSlideAxis === 'x' ? 'scrollWidth' : 'scrollHeight']) -
153
+ var _a;
154
+ return Math.round(Number((_a = internalThumbsWrapperRef.current) === null || _a === void 0 ? void 0 : _a[thumbsSlideAxis === 'x' ? 'scrollWidth' : 'scrollHeight']) -
126
155
  internalThumbsWrapperRef.current.getBoundingClientRect()[thumbsSlideAxis === 'x' ? 'width' : 'height']);
127
156
  }
128
157
  function getThumbSlideValue() {
@@ -251,18 +280,12 @@ function useThumbsModule({ items, withThumbs, thumbsSlideAxis = 'x', springConfi
251
280
  : InternalWrapper;
252
281
  const thumbsFragment = withThumbs ? (jsxRuntime.jsx(Wrapper, Object.assign({ ref: internalThumbsWrapperRef, className: "use-spring-carousel-thumbs-wrapper", onWheel: () => {
253
282
  thumbListStyles[thumbsSlideAxis].stop();
254
- }, style: {
255
- display: 'flex',
256
- flex: 1,
257
- position: 'relative',
258
- flexDirection: thumbsSlideAxis === 'x' ? 'row' : 'column',
259
- ...(thumbsSlideAxis === 'x'
260
- ? { overflowX: 'auto' }
261
- : {
262
- overflowY: 'auto',
263
- maxHeight: '100%',
264
- }),
265
- } }, { children: handlePrepareThumbsDate().map(({ id, renderThumb }) => {
283
+ }, style: Object.assign({ display: 'flex', flex: 1, position: 'relative', flexDirection: thumbsSlideAxis === 'x' ? 'row' : 'column' }, (thumbsSlideAxis === 'x'
284
+ ? { overflowX: 'auto' }
285
+ : {
286
+ overflowY: 'auto',
287
+ maxHeight: '100%',
288
+ })) }, { children: handlePrepareThumbsDate().map(({ id, renderThumb }) => {
266
289
  const thumbId = `thumb-${id}`;
267
290
  return (jsxRuntime.jsx("div", Object.assign({ id: thumbId }, { children: renderThumb }), thumbId));
268
291
  }) }), void 0)) : null;
@@ -306,7 +329,8 @@ function useSpringCarousel({ itemsPerSlide = 1, items, withLoop = false, draggin
306
329
  },
307
330
  }));
308
331
  function getCarouselItem() {
309
- return carouselTrackWrapperRef.current?.querySelector('.use-spring-carousel-item');
332
+ var _a;
333
+ return (_a = carouselTrackWrapperRef.current) === null || _a === void 0 ? void 0 : _a.querySelector('.use-spring-carousel-item');
310
334
  }
311
335
  const getMainCarouselWrapperWidth = react.useCallback(() => {
312
336
  if (!mainCarouselWrapperRef.current) {
@@ -328,7 +352,8 @@ function useSpringCarousel({ itemsPerSlide = 1, items, withLoop = false, draggin
328
352
  return getCarouselItemWidth() * items.length < getMainCarouselWrapperWidth();
329
353
  }, [getCarouselItemWidth, getMainCarouselWrapperWidth, items.length]);
330
354
  const getFluidWrapperScrollValue = react.useCallback(() => {
331
- return Math.round(Number(carouselTrackWrapperRef.current?.[carouselSlideAxis === 'x' ? 'scrollWidth' : 'scrollHeight']) -
355
+ var _a;
356
+ return Math.round(Number((_a = carouselTrackWrapperRef.current) === null || _a === void 0 ? void 0 : _a[carouselSlideAxis === 'x' ? 'scrollWidth' : 'scrollHeight']) -
332
357
  carouselTrackWrapperRef.current.getBoundingClientRect()[carouselSlideAxis === 'x' ? 'width' : 'height']);
333
358
  }, [carouselSlideAxis]);
334
359
  const getIsFirstItem = react.useCallback(() => {
@@ -517,11 +542,7 @@ function useSpringCarousel({ itemsPerSlide = 1, items, withLoop = false, draggin
517
542
  }
518
543
  if (isDragging) {
519
544
  setIsDragging(true);
520
- emitObservable({
521
- eventName: 'onDrag',
522
- slideActionType: getSlideActionType(),
523
- ...props,
524
- });
545
+ emitObservable(Object.assign({ eventName: 'onDrag', slideActionType: getSlideActionType() }, props));
525
546
  const direction = props.direction[carouselSlideAxis === 'x' ? 0 : 1];
526
547
  if (direction > 0) {
527
548
  setSlideActionType('prev');
@@ -594,11 +615,7 @@ function useSpringCarousel({ itemsPerSlide = 1, items, withLoop = false, draggin
594
615
  }
595
616
  if (props.last && !props.pressed && !freeScroll) {
596
617
  resetAnimation();
597
- emitObservable({
598
- eventName: 'onDrag',
599
- slideActionType: getSlideActionType(),
600
- ...props,
601
- });
618
+ emitObservable(Object.assign({ eventName: 'onDrag', slideActionType: getSlideActionType() }, props));
602
619
  }
603
620
  }, {
604
621
  enabled: !disableGestures,
@@ -766,11 +783,7 @@ function useSpringCarousel({ itemsPerSlide = 1, items, withLoop = false, draggin
766
783
  [carouselSlideAxis]: -(getSlideValue() * to),
767
784
  };
768
785
  }
769
- setCarouselStyles.start({
770
- ...getFromValue(),
771
- to: getToValue(),
772
- immediate,
773
- onRest: val => {
786
+ setCarouselStyles.start(Object.assign(Object.assign({}, getFromValue()), { to: getToValue(), immediate, onRest: val => {
774
787
  if (val.finished) {
775
788
  setIsDragging(false);
776
789
  setIsAnimating(false);
@@ -786,8 +799,7 @@ function useSpringCarousel({ itemsPerSlide = 1, items, withLoop = false, draggin
786
799
  });
787
800
  }
788
801
  }
789
- },
790
- });
802
+ } }));
791
803
  if (enableThumbsWrapperScroll && withThumbs && !immediate) {
792
804
  handleThumbsScroll(to, getSlideActionType());
793
805
  }
@@ -933,8 +945,7 @@ function useSpringCarousel({ itemsPerSlide = 1, items, withLoop = false, draggin
933
945
  to: itemIndex,
934
946
  });
935
947
  }
936
- const contextProps = {
937
- useListenToCustomEvent,
948
+ const contextProps = Object.assign({ useListenToCustomEvent,
938
949
  getIsFullscreen,
939
950
  enterFullscreen,
940
951
  exitFullscreen,
@@ -943,34 +954,27 @@ function useSpringCarousel({ itemsPerSlide = 1, items, withLoop = false, draggin
943
954
  getIsNextItem,
944
955
  getIsPrevItem,
945
956
  slideToPrevItem,
946
- slideToNextItem,
947
- ...(typeof itemsPerSlide === 'number'
948
- ? {
949
- slideToItem: _slideToItem,
950
- getIsActiveItem: (id) => {
951
- return findItemIndex(id) === getCurrentActiveItem();
952
- },
953
- getCurrentActiveItem: () => ({
954
- id: items[getCurrentActiveItem()].id,
955
- index: getCurrentActiveItem(),
956
- }),
957
- }
958
- : {}),
959
- };
957
+ slideToNextItem }, (typeof itemsPerSlide === 'number'
958
+ ? {
959
+ slideToItem: _slideToItem,
960
+ getIsActiveItem: (id) => {
961
+ return findItemIndex(id) === getCurrentActiveItem();
962
+ },
963
+ getCurrentActiveItem: () => ({
964
+ id: items[getCurrentActiveItem()].id,
965
+ index: getCurrentActiveItem(),
966
+ }),
967
+ }
968
+ : {}));
960
969
  function getItemStyles() {
961
970
  if (typeof itemsPerSlide === 'number') {
962
- return {
963
- ...(carouselSlideAxis === 'x'
964
- ? { marginRight: `${gutter}px` }
965
- : { marginBottom: `${gutter}px` }),
966
- flex: `1 0 calc(100% / ${itemsPerSlide} - ${(gutter * (itemsPerSlide - 1)) / itemsPerSlide}px)`,
967
- };
968
- }
969
- return {
970
- ...(carouselSlideAxis === 'x'
971
+ return Object.assign(Object.assign({}, (carouselSlideAxis === 'x'
971
972
  ? { marginRight: `${gutter}px` }
972
- : { marginBottom: `${gutter}px` }),
973
- };
973
+ : { marginBottom: `${gutter}px` })), { flex: `1 0 calc(100% / ${itemsPerSlide} - ${(gutter * (itemsPerSlide - 1)) / itemsPerSlide}px)` });
974
+ }
975
+ return Object.assign({}, (carouselSlideAxis === 'x'
976
+ ? { marginRight: `${gutter}px` }
977
+ : { marginBottom: `${gutter}px` }));
974
978
  }
975
979
  function getAnimatedWrapperStyles() {
976
980
  const percentValue = `calc(100% - ${startEndGutter * 2}px)`;
@@ -1019,32 +1023,12 @@ function useSpringCarousel({ itemsPerSlide = 1, items, withLoop = false, draggin
1019
1023
  }
1020
1024
  const carouselFragment = (jsxRuntime.jsx(UseSpringCarouselContext.Provider, Object.assign({ value: contextProps }, { children: jsxRuntime.jsx("div", Object.assign({ ref: mainCarouselWrapperRef, className: "use-spring-carousel-main-wrapper", "data-testid": "use-spring-carousel-wrapper" }, getWheelEvent(), {
1021
1025
  // @ts-ignore
1022
- style: {
1023
- display: 'flex',
1024
- position: 'relative',
1025
- width: '100%',
1026
- height: '100%',
1027
- ...getOverflowStyles(),
1028
- } }, { children: jsxRuntime.jsx(reactSpring.animated.div, Object.assign({}, bindDrag(), { className: "use-spring-carousel-track-wrapper", "data-testid": "use-spring-carousel-animated-wrapper", ref: handleCarouselFragmentRef, style: {
1029
- display: 'flex',
1030
- position: 'relative',
1031
- touchAction: getTouchAction(),
1032
- flexDirection: carouselSlideAxis === 'x' ? 'row' : 'column',
1033
- ...getAnimatedWrapperStyles(),
1034
- ...(freeScroll ? {} : carouselStyles),
1035
- } }, { children: internalItems.map(({ id, renderItem }, index) => {
1036
- return (jsxRuntime.jsx("div", Object.assign({ className: "use-spring-carousel-item", "data-testid": "use-spring-carousel-item-wrapper", style: {
1037
- display: 'flex',
1038
- position: 'relative',
1039
- ...getItemStyles(),
1040
- } }, { children: renderItem }), `${id}-${index}`));
1026
+ style: Object.assign({ display: 'flex', position: 'relative', width: '100%', height: '100%' }, getOverflowStyles()) }, { children: jsxRuntime.jsx(reactSpring.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) => {
1027
+ return (jsxRuntime.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}`));
1041
1028
  }) }), void 0) }), void 0) }), void 0));
1042
1029
  const thumbsFragment = (jsxRuntime.jsx(UseSpringCarouselContext.Provider, Object.assign({ value: contextProps }, { children: _thumbsFragment }), void 0));
1043
- return {
1044
- ...contextProps,
1045
- carouselFragment,
1046
- thumbsFragment,
1047
- };
1030
+ return Object.assign(Object.assign({}, contextProps), { carouselFragment,
1031
+ thumbsFragment });
1048
1032
  }
1049
1033
  function useSpringCarouselContext() {
1050
1034
  const context = react.useContext(UseSpringCarouselContext);
@@ -1133,57 +1117,28 @@ function useTransitionCarousel({ items, withLoop = false, withThumbs = false, sp
1133
1117
  const slideActionType = getSlideActionType();
1134
1118
  if (slideActionType === 'prev' && toPrevItemSpringProps) {
1135
1119
  return {
1136
- initial: {
1137
- ...springAnimationProps.initial,
1138
- },
1139
- from: {
1140
- ...toPrevItemSpringProps.from,
1141
- },
1142
- enter: {
1143
- ...toPrevItemSpringProps.enter,
1144
- },
1145
- leave: {
1146
- ...toPrevItemSpringProps.leave,
1147
- },
1120
+ initial: Object.assign({}, springAnimationProps.initial),
1121
+ from: Object.assign({}, toPrevItemSpringProps.from),
1122
+ enter: Object.assign({}, toPrevItemSpringProps.enter),
1123
+ leave: Object.assign({}, toPrevItemSpringProps.leave),
1148
1124
  };
1149
1125
  }
1150
1126
  if (slideActionType === 'next' && toNextItemSpringProps) {
1151
1127
  return {
1152
- initial: {
1153
- ...springAnimationProps.initial,
1154
- },
1155
- from: {
1156
- ...toNextItemSpringProps.from,
1157
- },
1158
- enter: {
1159
- ...toNextItemSpringProps.enter,
1160
- },
1161
- leave: {
1162
- ...toNextItemSpringProps.leave,
1163
- },
1128
+ initial: Object.assign({}, springAnimationProps.initial),
1129
+ from: Object.assign({}, toNextItemSpringProps.from),
1130
+ enter: Object.assign({}, toNextItemSpringProps.enter),
1131
+ leave: Object.assign({}, toNextItemSpringProps.leave),
1164
1132
  };
1165
1133
  }
1166
1134
  return {
1167
- initial: {
1168
- ...springAnimationProps.initial,
1169
- },
1170
- from: {
1171
- ...springAnimationProps.from,
1172
- },
1173
- enter: {
1174
- ...springAnimationProps.enter,
1175
- },
1176
- leave: {
1177
- ...springAnimationProps.leave,
1178
- },
1135
+ initial: Object.assign({}, springAnimationProps.initial),
1136
+ from: Object.assign({}, springAnimationProps.from),
1137
+ enter: Object.assign({}, springAnimationProps.enter),
1138
+ leave: Object.assign({}, springAnimationProps.leave),
1179
1139
  };
1180
1140
  }
1181
- const transitions = reactSpring.useTransition(activeItem, {
1182
- config: springConfig,
1183
- ...getTransitionConfig(),
1184
- onStart: () => setIsAnimating(true),
1185
- keys: null,
1186
- onRest: val => {
1141
+ const transitions = reactSpring.useTransition(activeItem, Object.assign(Object.assign({ config: springConfig }, getTransitionConfig()), { onStart: () => setIsAnimating(true), keys: null, onRest: val => {
1187
1142
  if (val.finished) {
1188
1143
  setIsAnimating(false);
1189
1144
  emitObservable({
@@ -1195,14 +1150,8 @@ function useTransitionCarousel({ items, withLoop = false, withThumbs = false, sp
1195
1150
  },
1196
1151
  });
1197
1152
  }
1198
- },
1199
- });
1200
- const itemsFragment = transitions((styles, item) => (jsxRuntime.jsx(reactSpring.animated.div, Object.assign({ style: {
1201
- ...styles,
1202
- flex: '1 0 100%',
1203
- width: '100%',
1204
- height: '100%',
1205
- } }, { children: items[item].renderItem }), void 0)));
1153
+ } }));
1154
+ const itemsFragment = transitions((styles, item) => (jsxRuntime.jsx(reactSpring.animated.div, Object.assign({ style: Object.assign(Object.assign({}, styles), { flex: '1 0 100%', width: '100%', height: '100%' }) }, { children: items[item].renderItem }), void 0)));
1206
1155
  function getIsAnimating() {
1207
1156
  return isAnimating.current;
1208
1157
  }
@@ -1380,11 +1329,8 @@ function useTransitionCarousel({ items, withLoop = false, withThumbs = false, sp
1380
1329
  overflow: 'hidden',
1381
1330
  } }, { children: itemsFragment }), void 0) }), void 0));
1382
1331
  const thumbsFragment = (jsxRuntime.jsx(UseTransitionCarouselContext.Provider, Object.assign({ value: contextProps }, { children: _thumbsFragment }), void 0));
1383
- return {
1384
- carouselFragment,
1385
- thumbsFragment,
1386
- ...contextProps,
1387
- };
1332
+ return Object.assign({ carouselFragment,
1333
+ thumbsFragment }, contextProps);
1388
1334
  }
1389
1335
 
1390
1336
  exports.useSpringCarousel = useSpringCarousel;