react-spring-carousel 3.0.0-beta003 → 3.0.0-beta006

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
@@ -6,11 +6,11 @@ var react = require('react');
6
6
  var react$1 = require('@use-gesture/react');
7
7
  var screenfull = require('screenfull');
8
8
 
9
- const eventLabel = "RSC::Event";
9
+ const eventLabel = 'RSC::Event';
10
10
  function useEventsModule() {
11
11
  const targetEvent = react.useRef(null);
12
12
  react.useEffect(() => {
13
- targetEvent.current = document.createElement("div");
13
+ targetEvent.current = document.createElement('div');
14
14
  }, []);
15
15
  function useListenToCustomEvent(eventHandler) {
16
16
  react.useEffect(() => {
@@ -49,7 +49,7 @@ function useFullscreenModule({ mainCarouselWrapperRef, emitEvent, handleResize,
49
49
  if (document.fullscreenElement) {
50
50
  setIsFullscreen(true);
51
51
  emitEvent({
52
- eventName: "onFullscreenChange",
52
+ eventName: 'onFullscreenChange',
53
53
  isFullscreen: true,
54
54
  });
55
55
  handleResize && handleResize();
@@ -57,17 +57,17 @@ function useFullscreenModule({ mainCarouselWrapperRef, emitEvent, handleResize,
57
57
  if (!document.fullscreenElement) {
58
58
  setIsFullscreen(false);
59
59
  emitEvent({
60
- eventName: "onFullscreenChange",
60
+ eventName: 'onFullscreenChange',
61
61
  isFullscreen: false,
62
62
  });
63
63
  handleResize && handleResize();
64
64
  }
65
65
  }
66
66
  if (screenfull.isEnabled) {
67
- screenfull.on("change", handleFullscreenChange);
67
+ screenfull.on('change', handleFullscreenChange);
68
68
  return () => {
69
69
  if (screenfull.isEnabled) {
70
- screenfull.off("change", handleFullscreenChange);
70
+ screenfull.off('change', handleFullscreenChange);
71
71
  }
72
72
  };
73
73
  }
@@ -97,19 +97,18 @@ function isInViewport(el) {
97
97
  const rect = el.getBoundingClientRect();
98
98
  return (rect.top >= 0 &&
99
99
  rect.left >= 0 &&
100
- rect.bottom <=
101
- (window.innerHeight || document.documentElement.clientHeight) &&
100
+ rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
102
101
  rect.right <= (window.innerWidth || document.documentElement.clientWidth));
103
102
  }
104
- function useThumbsModule({ thumbsSlideAxis = "x", withThumbs = false, prepareThumbsData, items, }) {
103
+ function useThumbsModule({ thumbsSlideAxis = 'x', withThumbs = false, prepareThumbsData, items, }) {
105
104
  const wrapperRef = react.useRef(null);
106
105
  const [spring, setSpring] = web.useSpring(() => ({
107
106
  val: 0,
108
107
  }));
109
108
  function getTotalScrollValue() {
110
109
  var _a;
111
- return Math.round(Number((_a = wrapperRef.current) === null || _a === void 0 ? void 0 : _a[thumbsSlideAxis === "x" ? "scrollWidth" : "scrollHeight"]) -
112
- wrapperRef.current.getBoundingClientRect()[thumbsSlideAxis === "x" ? "width" : "height"]);
110
+ return Math.round(Number((_a = wrapperRef.current) === null || _a === void 0 ? void 0 : _a[thumbsSlideAxis === 'x' ? 'scrollWidth' : 'scrollHeight']) -
111
+ wrapperRef.current.getBoundingClientRect()[thumbsSlideAxis === 'x' ? 'width' : 'height']);
113
112
  }
114
113
  function handleScroll(activeItem) {
115
114
  var _a, _b;
@@ -126,14 +125,15 @@ function useThumbsModule({ thumbsSlideAxis = "x", withThumbs = false, prepareThu
126
125
  const val = offset > getTotalScrollValue() ? getTotalScrollValue() : offset;
127
126
  setSpring.start({
128
127
  from: {
129
- val: (_b = (_a = wrapperRef.current) === null || _a === void 0 ? void 0 : _a[thumbsSlideAxis === "x" ? "scrollLeft" : "scrollTop"]) !== null && _b !== void 0 ? _b : 0,
128
+ val: (_b = (_a = wrapperRef.current) === null || _a === void 0 ? void 0 : _a[thumbsSlideAxis === 'x' ? 'scrollLeft' : 'scrollTop']) !== null && _b !== void 0 ? _b : 0,
130
129
  },
131
130
  to: {
132
131
  val,
133
132
  },
134
133
  onChange: ({ value }) => {
135
134
  if (wrapperRef.current) {
136
- wrapperRef.current[thumbsSlideAxis === "x" ? "scrollLeft" : "scrollTop"] = Math.abs(value.val);
135
+ wrapperRef.current[thumbsSlideAxis === 'x' ? 'scrollLeft' : 'scrollTop'] =
136
+ Math.abs(value.val);
137
137
  }
138
138
  },
139
139
  });
@@ -142,7 +142,7 @@ function useThumbsModule({ thumbsSlideAxis = "x", withThumbs = false, prepareThu
142
142
  }
143
143
  function handlePrepareThumbsData() {
144
144
  function getPreparedItems(_items) {
145
- return _items.map((i) => ({
145
+ return _items.map(i => ({
146
146
  id: i.id,
147
147
  renderThumb: i.renderThumb,
148
148
  }));
@@ -152,11 +152,11 @@ function useThumbsModule({ thumbsSlideAxis = "x", withThumbs = false, prepareThu
152
152
  }
153
153
  return getPreparedItems(items);
154
154
  }
155
- const thumbsFragment = withThumbs ? (jsxRuntime.jsx("div", Object.assign({ className: "use-spring-carousel-thumbs-wrapper", ref: wrapperRef, onWheel: () => spring.val.stop(), style: Object.assign({ display: "flex", flex: "1", position: "relative", width: "100%", height: "100%", flexDirection: thumbsSlideAxis === "x" ? "row" : "column" }, (thumbsSlideAxis === "x"
156
- ? { overflowX: "auto" }
155
+ const thumbsFragment = withThumbs ? (jsxRuntime.jsx("div", Object.assign({ className: "use-spring-carousel-thumbs-wrapper", ref: wrapperRef, onWheel: () => spring.val.stop(), style: Object.assign({ display: 'flex', flex: '1', position: 'relative', width: '100%', height: '100%', flexDirection: thumbsSlideAxis === 'x' ? 'row' : 'column' }, (thumbsSlideAxis === 'x'
156
+ ? { overflowX: 'auto' }
157
157
  : {
158
- overflowY: "auto",
159
- maxHeight: "100%",
158
+ overflowY: 'auto',
159
+ maxHeight: '100%',
160
160
  })) }, { children: handlePrepareThumbsData().map(({ id, renderThumb }) => {
161
161
  const thumbId = `thumb-item-${id}`;
162
162
  return (jsxRuntime.jsx("div", Object.assign({ id: thumbId, className: "thumb-item" }, { children: renderThumb }), thumbId));
@@ -167,11 +167,11 @@ function useThumbsModule({ thumbsSlideAxis = "x", withThumbs = false, prepareThu
167
167
  };
168
168
  }
169
169
 
170
- function useSpringCarousel({ items, init = true, withThumbs, thumbsSlideAxis = "x", itemsPerSlide = 1, slideType = "fixed", gutter = 0, withLoop = false, startEndGutter = 0, carouselSlideAxis = "x", disableGestures = false, draggingSlideTreshold: _draggingSlideTreshold, slideWhenThresholdIsReached = false, freeScroll, enableFreeScrollDrag, initialStartingPosition, prepareThumbsData, initialActiveItem = 0, }) {
170
+ function useSpringCarousel({ items, init = true, withThumbs, thumbsSlideAxis = 'x', itemsPerSlide = 1, slideType = 'fixed', gutter = 0, withLoop = false, startEndGutter = 0, carouselSlideAxis = 'x', disableGestures = false, draggingSlideTreshold: _draggingSlideTreshold, slideWhenThresholdIsReached = false, freeScroll, enableFreeScrollDrag, initialStartingPosition, prepareThumbsData, initialActiveItem = 0, }) {
171
171
  const prevWindowWidth = react.useRef(0);
172
172
  const draggingSlideTreshold = react.useRef(_draggingSlideTreshold !== null && _draggingSlideTreshold !== void 0 ? _draggingSlideTreshold : 0);
173
- const slideActionType = react.useRef("initial");
174
- const slideModeType = react.useRef("initial");
173
+ const slideActionType = react.useRef('initial');
174
+ const slideModeType = react.useRef('initial');
175
175
  const prevSlidedValue = react.useRef(0);
176
176
  const [spring, setSpring] = web.useSpring(() => ({
177
177
  val: 0,
@@ -179,7 +179,7 @@ function useSpringCarousel({ items, init = true, withThumbs, thumbsSlideAxis = "
179
179
  onChange({ value }) {
180
180
  if (freeScroll && mainCarouselWrapperRef.current) {
181
181
  setStartEndItemReachedOnFreeScroll();
182
- if (carouselSlideAxis === "x") {
182
+ if (carouselSlideAxis === 'x') {
183
183
  mainCarouselWrapperRef.current.scrollLeft = Math.abs(value.val);
184
184
  }
185
185
  else {
@@ -187,7 +187,7 @@ function useSpringCarousel({ items, init = true, withThumbs, thumbsSlideAxis = "
187
187
  }
188
188
  }
189
189
  else if (carouselTrackWrapperRef.current) {
190
- if (carouselSlideAxis === "x") {
190
+ if (carouselSlideAxis === 'x') {
191
191
  carouselTrackWrapperRef.current.style.transform = `translate3d(${value.val}px, 0px,0px)`;
192
192
  }
193
193
  else {
@@ -204,9 +204,9 @@ function useSpringCarousel({ items, init = true, withThumbs, thumbsSlideAxis = "
204
204
  const getItems = react.useCallback(() => {
205
205
  if (withLoop) {
206
206
  return [
207
- ...items.map((i) => (Object.assign(Object.assign({}, i), { id: `prev-repeated-item-${i.id}` }))),
207
+ ...items.map(i => (Object.assign(Object.assign({}, i), { id: `prev-repeated-item-${i.id}` }))),
208
208
  ...items,
209
- ...items.map((i) => (Object.assign(Object.assign({}, i), { id: `next-repeated-item-${i.id}` }))),
209
+ ...items.map(i => (Object.assign(Object.assign({}, i), { id: `next-repeated-item-${i.id}` }))),
210
210
  ];
211
211
  }
212
212
  return [...items];
@@ -225,7 +225,7 @@ function useSpringCarousel({ items, init = true, withThumbs, thumbsSlideAxis = "
225
225
  handleResize: () => adjustCarouselWrapperPosition(),
226
226
  });
227
227
  function getItemStyles() {
228
- if (slideType === "fixed" && !freeScroll) {
228
+ if (slideType === 'fixed' && !freeScroll) {
229
229
  return {
230
230
  marginRight: `${gutter}px`,
231
231
  flex: `1 0 calc(100% / ${itemsPerSlide} - ${(gutter * (itemsPerSlide - 1)) / itemsPerSlide}px)`,
@@ -235,27 +235,27 @@ function useSpringCarousel({ items, init = true, withThumbs, thumbsSlideAxis = "
235
235
  }
236
236
  function getSlideValue() {
237
237
  var _a;
238
- const carouselItem = (_a = mainCarouselWrapperRef.current) === null || _a === void 0 ? void 0 : _a.querySelector(".use-spring-carousel-item");
238
+ const carouselItem = (_a = mainCarouselWrapperRef.current) === null || _a === void 0 ? void 0 : _a.querySelector('.use-spring-carousel-item');
239
239
  if (!carouselItem) {
240
- throw Error("No carousel items available!");
240
+ throw Error('No carousel items available!');
241
241
  }
242
- return (carouselItem.getBoundingClientRect()[carouselSlideAxis === "x" ? "width" : "height"] + gutter);
242
+ return (carouselItem.getBoundingClientRect()[carouselSlideAxis === 'x' ? 'width' : 'height'] + gutter);
243
243
  }
244
244
  function slideToItem({ from, to, nextActiveItem, immediate = false, slideMode, }) {
245
245
  slideModeType.current = slideMode;
246
- if (typeof nextActiveItem === "number") {
246
+ if (typeof nextActiveItem === 'number') {
247
247
  if (!freeScroll) {
248
248
  activeItem.current = nextActiveItem;
249
249
  }
250
250
  emitEvent({
251
- eventName: "onSlideStartChange",
251
+ eventName: 'onSlideStartChange',
252
252
  slideActionType: slideActionType.current,
253
253
  slideMode: slideModeType.current,
254
254
  nextItem: {
255
255
  startReached: firstItemReached.current,
256
256
  endReached: lastItemReached.current,
257
257
  index: freeScroll ? -1 : activeItem.current,
258
- id: freeScroll ? "" : items[activeItem.current].id,
258
+ id: freeScroll ? '' : items[activeItem.current].id,
259
259
  },
260
260
  });
261
261
  }
@@ -272,14 +272,14 @@ function useSpringCarousel({ items, init = true, withThumbs, thumbsSlideAxis = "
272
272
  onRest(value) {
273
273
  if (!immediate && value.finished) {
274
274
  emitEvent({
275
- eventName: "onSlideChange",
275
+ eventName: 'onSlideChange',
276
276
  slideActionType: slideActionType.current,
277
277
  slideMode: slideModeType.current,
278
278
  currentItem: {
279
279
  startReached: firstItemReached.current,
280
280
  endReached: lastItemReached.current,
281
281
  index: freeScroll ? -1 : activeItem.current,
282
- id: freeScroll ? "" : items[activeItem.current].id,
282
+ id: freeScroll ? '' : items[activeItem.current].id,
283
283
  },
284
284
  });
285
285
  }
@@ -294,38 +294,38 @@ function useSpringCarousel({ items, init = true, withThumbs, thumbsSlideAxis = "
294
294
  if (withLoop) {
295
295
  return getSlideValue() * items.length;
296
296
  }
297
- return Math.round(Number((_a = carouselTrackWrapperRef.current) === null || _a === void 0 ? void 0 : _a[carouselSlideAxis === "x" ? "scrollWidth" : "scrollHeight"]) -
298
- carouselTrackWrapperRef.current.getBoundingClientRect()[carouselSlideAxis === "x" ? "width" : "height"]);
297
+ return Math.round(Number((_a = carouselTrackWrapperRef.current) === null || _a === void 0 ? void 0 : _a[carouselSlideAxis === 'x' ? 'scrollWidth' : 'scrollHeight']) -
298
+ carouselTrackWrapperRef.current.getBoundingClientRect()[carouselSlideAxis === 'x' ? 'width' : 'height']);
299
299
  }
300
300
  function getAnimatedWrapperStyles() {
301
301
  const percentValue = `calc(100% - ${startEndGutter * 2}px)`;
302
302
  return {
303
- width: carouselSlideAxis === "x" ? percentValue : "100%",
304
- height: carouselSlideAxis === "y" ? percentValue : "100%",
303
+ width: carouselSlideAxis === 'x' ? percentValue : '100%',
304
+ height: carouselSlideAxis === 'y' ? percentValue : '100%',
305
305
  };
306
306
  }
307
307
  function getCarouselItemWidth() {
308
308
  var _a;
309
- const carouselItem = (_a = carouselTrackWrapperRef.current) === null || _a === void 0 ? void 0 : _a.querySelector(".use-spring-carousel-item");
309
+ const carouselItem = (_a = carouselTrackWrapperRef.current) === null || _a === void 0 ? void 0 : _a.querySelector('.use-spring-carousel-item');
310
310
  if (!carouselItem) {
311
- throw Error("No carousel items available!");
311
+ throw Error('No carousel items available!');
312
312
  }
313
- return (carouselItem.getBoundingClientRect()[carouselSlideAxis === "x" ? "width" : "height"] + gutter);
313
+ return (carouselItem.getBoundingClientRect()[carouselSlideAxis === 'x' ? 'width' : 'height'] + gutter);
314
314
  }
315
315
  function adjustCarouselWrapperPosition() {
316
- const positionProperty = carouselSlideAxis === "x" ? "left" : "top";
316
+ const positionProperty = carouselSlideAxis === 'x' ? 'left' : 'top';
317
317
  function setPosition(v) {
318
318
  const ref = carouselTrackWrapperRef.current;
319
319
  if (!ref)
320
320
  return;
321
321
  if (withLoop) {
322
- ref.style.top = "0px";
323
- ref.style.left = "0px";
322
+ ref.style.top = '0px';
323
+ ref.style.left = '0px';
324
324
  ref.style[positionProperty] = `-${v - startEndGutter}px`;
325
325
  }
326
326
  else {
327
- ref.style.left = "0px";
328
- ref.style.top = "0px";
327
+ ref.style.left = '0px';
328
+ ref.style.top = '0px';
329
329
  }
330
330
  }
331
331
  const currentFromValue = Math.abs(getFromValue());
@@ -342,18 +342,18 @@ function useSpringCarousel({ items, init = true, withThumbs, thumbsSlideAxis = "
342
342
  });
343
343
  return;
344
344
  }
345
- if (initialStartingPosition === "center") {
345
+ if (initialStartingPosition === 'center') {
346
346
  setPosition(getCarouselItemWidth() * items.length -
347
347
  getSlideValue() * Math.round((itemsPerSlide - 1) / 2));
348
348
  }
349
- else if (initialStartingPosition === "end") {
349
+ else if (initialStartingPosition === 'end') {
350
350
  setPosition(getCarouselItemWidth() * items.length -
351
351
  getSlideValue() * Math.round(itemsPerSlide - 1));
352
352
  }
353
353
  else {
354
354
  setPosition(getCarouselItemWidth() * items.length);
355
355
  }
356
- if (!freeScroll && slideType === "fixed") {
356
+ if (!freeScroll && slideType === 'fixed') {
357
357
  const val = -(getSlideValue() * activeItem.current);
358
358
  prevSlidedValue.current = val;
359
359
  setSpring.start({
@@ -364,26 +364,26 @@ function useSpringCarousel({ items, init = true, withThumbs, thumbsSlideAxis = "
364
364
  }
365
365
  function getFromValue() {
366
366
  if (freeScroll && mainCarouselWrapperRef.current) {
367
- return mainCarouselWrapperRef.current[carouselSlideAxis === "x" ? "scrollLeft" : "scrollTop"];
367
+ return mainCarouselWrapperRef.current[carouselSlideAxis === 'x' ? 'scrollLeft' : 'scrollTop'];
368
368
  }
369
369
  return spring.val.get();
370
370
  }
371
371
  function getToValue(type, index) {
372
- if (freeScroll && type === "next") {
372
+ if (freeScroll && type === 'next') {
373
373
  const next = prevSlidedValue.current + getSlideValue();
374
374
  if (next > getTotalScrollValue()) {
375
375
  return getTotalScrollValue();
376
376
  }
377
377
  return next;
378
378
  }
379
- if (freeScroll && type === "prev") {
379
+ if (freeScroll && type === 'prev') {
380
380
  const next = prevSlidedValue.current - getSlideValue();
381
381
  if (next < 0) {
382
382
  return 0;
383
383
  }
384
384
  return next;
385
385
  }
386
- if (type === "next") {
386
+ if (type === 'next') {
387
387
  if (index) {
388
388
  return -(index * getSlideValue());
389
389
  }
@@ -394,14 +394,14 @@ function useSpringCarousel({ items, init = true, withThumbs, thumbsSlideAxis = "
394
394
  }
395
395
  return prevSlidedValue.current + getSlideValue();
396
396
  }
397
- function slideToPrevItem(type = "click", index) {
397
+ function slideToPrevItem(type = 'click', index) {
398
398
  if (!init || (firstItemReached.current && !withLoop))
399
399
  return;
400
- slideActionType.current = "prev";
400
+ slideActionType.current = 'prev';
401
401
  lastItemReached.current = false;
402
402
  const nextItem = index || activeItem.current - 1;
403
403
  if (!withLoop) {
404
- const nextItemWillExceed = getToValue("prev", index) + getSlideValue() / 3 > 0;
404
+ const nextItemWillExceed = getToValue('prev', index) + getSlideValue() / 3 > 0;
405
405
  if (firstItemReached.current)
406
406
  return;
407
407
  if (nextItemWillExceed) {
@@ -436,19 +436,18 @@ function useSpringCarousel({ items, init = true, withThumbs, thumbsSlideAxis = "
436
436
  slideToItem({
437
437
  slideMode: type,
438
438
  from: getFromValue(),
439
- to: getToValue("prev", index),
439
+ to: getToValue('prev', index),
440
440
  nextActiveItem: nextItem,
441
441
  });
442
442
  }
443
- function slideToNextItem(type = "click", index) {
443
+ function slideToNextItem(type = 'click', index) {
444
444
  if (!init || (lastItemReached.current && !withLoop))
445
445
  return;
446
- slideActionType.current = "next";
446
+ slideActionType.current = 'next';
447
447
  firstItemReached.current = false;
448
448
  const nextItem = index || activeItem.current + 1;
449
449
  if (!withLoop) {
450
- const nextItemWillExceed = Math.abs(getToValue("next", index)) >
451
- getTotalScrollValue() - getSlideValue() / 3;
450
+ const nextItemWillExceed = Math.abs(getToValue('next', index)) > getTotalScrollValue() - getSlideValue() / 3;
452
451
  if (lastItemReached.current)
453
452
  return;
454
453
  if (nextItemWillExceed) {
@@ -483,7 +482,7 @@ function useSpringCarousel({ items, init = true, withThumbs, thumbsSlideAxis = "
483
482
  slideToItem({
484
483
  slideMode: type,
485
484
  from: getFromValue(),
486
- to: getToValue("next", index),
485
+ to: getToValue('next', index),
487
486
  nextActiveItem: nextItem,
488
487
  });
489
488
  }
@@ -525,28 +524,28 @@ function useSpringCarousel({ items, init = true, withThumbs, thumbsSlideAxis = "
525
524
  prevWindowWidth.current = window.innerWidth;
526
525
  adjustCarouselWrapperPosition();
527
526
  }
528
- window.addEventListener("resize", handleResize);
527
+ window.addEventListener('resize', handleResize);
529
528
  return () => {
530
- window.removeEventListener("resize", handleResize);
529
+ window.removeEventListener('resize', handleResize);
531
530
  };
532
531
  }, []);
533
- const bindDrag = react$1.useDrag((state) => {
532
+ const bindDrag = react$1.useDrag(state => {
534
533
  const isDragging = state.dragging;
535
- const movement = state.offset[carouselSlideAxis === "x" ? 0 : 1];
536
- const currentMovement = state.movement[carouselSlideAxis === "x" ? 0 : 1];
537
- const direction = state.direction[carouselSlideAxis === "x" ? 0 : 1];
534
+ const movement = state.offset[carouselSlideAxis === 'x' ? 0 : 1];
535
+ const currentMovement = state.movement[carouselSlideAxis === 'x' ? 0 : 1];
536
+ const direction = state.direction[carouselSlideAxis === 'x' ? 0 : 1];
538
537
  const prevItemTreshold = currentMovement > draggingSlideTreshold.current;
539
538
  const nextItemTreshold = currentMovement < -draggingSlideTreshold.current;
540
539
  if (isDragging) {
541
540
  if (direction > 0) {
542
- slideActionType.current = "prev";
541
+ slideActionType.current = 'prev';
543
542
  }
544
543
  else {
545
- slideActionType.current = "next";
544
+ slideActionType.current = 'next';
546
545
  }
547
- emitEvent(Object.assign(Object.assign({}, state), { eventName: "onDrag", slideActionType: slideActionType.current }));
546
+ emitEvent(Object.assign(Object.assign({}, state), { eventName: 'onDrag', slideActionType: slideActionType.current }));
548
547
  if (freeScroll) {
549
- if (slideActionType.current === "prev" && movement > 0) {
548
+ if (slideActionType.current === 'prev' && movement > 0) {
550
549
  state.cancel();
551
550
  setSpring.start({
552
551
  from: {
@@ -587,21 +586,21 @@ function useSpringCarousel({ items, init = true, withThumbs, thumbsSlideAxis = "
587
586
  },
588
587
  });
589
588
  if (slideWhenThresholdIsReached && nextItemTreshold) {
590
- slideToNextItem("drag");
589
+ slideToNextItem('drag');
591
590
  state.cancel();
592
591
  }
593
592
  else if (slideWhenThresholdIsReached && prevItemTreshold) {
594
- slideToPrevItem("drag");
593
+ slideToPrevItem('drag');
595
594
  state.cancel();
596
595
  }
597
596
  return;
598
597
  }
599
598
  if (state.last && !state.canceled && freeScroll) {
600
- if (slideActionType.current === "prev") {
601
- slideToPrevItem("drag");
599
+ if (slideActionType.current === 'prev') {
600
+ slideToPrevItem('drag');
602
601
  }
603
- if (slideActionType.current === "next") {
604
- slideToNextItem("drag");
602
+ if (slideActionType.current === 'next') {
603
+ slideToNextItem('drag');
605
604
  }
606
605
  }
607
606
  if (state.last && !state.canceled && !freeScroll) {
@@ -613,7 +612,7 @@ function useSpringCarousel({ items, init = true, withThumbs, thumbsSlideAxis = "
613
612
  });
614
613
  }
615
614
  else {
616
- slideToNextItem("drag");
615
+ slideToNextItem('drag');
617
616
  }
618
617
  }
619
618
  else if (prevItemTreshold) {
@@ -624,7 +623,7 @@ function useSpringCarousel({ items, init = true, withThumbs, thumbsSlideAxis = "
624
623
  });
625
624
  }
626
625
  else {
627
- slideToPrevItem("drag");
626
+ slideToPrevItem('drag');
628
627
  }
629
628
  }
630
629
  else {
@@ -645,7 +644,7 @@ function useSpringCarousel({ items, init = true, withThumbs, thumbsSlideAxis = "
645
644
  -mainCarouselWrapperRef.current.scrollTop,
646
645
  ];
647
646
  }
648
- if (carouselSlideAxis === "x") {
647
+ if (carouselSlideAxis === 'x') {
649
648
  return [spring.val.get(), spring.val.get()];
650
649
  }
651
650
  return [spring.val.get(), spring.val.get()];
@@ -653,13 +652,13 @@ function useSpringCarousel({ items, init = true, withThumbs, thumbsSlideAxis = "
653
652
  });
654
653
  function getWrapperOverflowStyles() {
655
654
  if (freeScroll) {
656
- if (carouselSlideAxis === "x") {
655
+ if (carouselSlideAxis === 'x') {
657
656
  return {
658
- overflowX: "auto",
657
+ overflowX: 'auto',
659
658
  };
660
659
  }
661
660
  return {
662
- overflowY: "auto",
661
+ overflowY: 'auto',
663
662
  };
664
663
  }
665
664
  return {};
@@ -667,17 +666,17 @@ function useSpringCarousel({ items, init = true, withThumbs, thumbsSlideAxis = "
667
666
  function setStartEndItemReachedOnFreeScroll() {
668
667
  if (mainCarouselWrapperRef.current) {
669
668
  prevSlidedValue.current =
670
- mainCarouselWrapperRef.current[carouselSlideAxis === "x" ? "scrollLeft" : "scrollTop"];
671
- if (mainCarouselWrapperRef.current[carouselSlideAxis === "x" ? "scrollLeft" : "scrollTop"] === 0) {
669
+ mainCarouselWrapperRef.current[carouselSlideAxis === 'x' ? 'scrollLeft' : 'scrollTop'];
670
+ if (mainCarouselWrapperRef.current[carouselSlideAxis === 'x' ? 'scrollLeft' : 'scrollTop'] === 0) {
672
671
  firstItemReached.current = true;
673
672
  lastItemReached.current = false;
674
673
  }
675
- if (mainCarouselWrapperRef.current[carouselSlideAxis === "x" ? "scrollLeft" : "scrollTop"] > 0 &&
676
- mainCarouselWrapperRef.current[carouselSlideAxis === "x" ? "scrollLeft" : "scrollTop"] < getTotalScrollValue()) {
674
+ if (mainCarouselWrapperRef.current[carouselSlideAxis === 'x' ? 'scrollLeft' : 'scrollTop'] > 0 &&
675
+ mainCarouselWrapperRef.current[carouselSlideAxis === 'x' ? 'scrollLeft' : 'scrollTop'] < getTotalScrollValue()) {
677
676
  firstItemReached.current = false;
678
677
  lastItemReached.current = false;
679
678
  }
680
- if (mainCarouselWrapperRef.current[carouselSlideAxis === "x" ? "scrollLeft" : "scrollTop"] === getTotalScrollValue()) {
679
+ if (mainCarouselWrapperRef.current[carouselSlideAxis === 'x' ? 'scrollLeft' : 'scrollTop'] === getTotalScrollValue()) {
681
680
  firstItemReached.current = false;
682
681
  lastItemReached.current = true;
683
682
  }
@@ -695,12 +694,12 @@ function useSpringCarousel({ items, init = true, withThumbs, thumbsSlideAxis = "
695
694
  return {};
696
695
  }
697
696
  function findItemIndex(id) {
698
- return items.findIndex((item) => item.id === id);
697
+ return items.findIndex(item => item.id === id);
699
698
  }
700
699
  function findItemIndexById(id, error) {
701
700
  let itemIndex = 0;
702
- if (typeof id === "string") {
703
- itemIndex = items.findIndex((_item) => _item.id === id);
701
+ if (typeof id === 'string') {
702
+ itemIndex = items.findIndex(_item => _item.id === id);
704
703
  }
705
704
  else {
706
705
  itemIndex = id;
@@ -722,10 +721,10 @@ function useSpringCarousel({ items, init = true, withThumbs, thumbsSlideAxis = "
722
721
  const currentItem = findItemIndex(items[activeItem.current].id);
723
722
  const newActiveItem = findItemIndex(items[itemIndex].id);
724
723
  if (newActiveItem > currentItem) {
725
- slideToNextItem("click", newActiveItem);
724
+ slideToNextItem('click', newActiveItem);
726
725
  }
727
726
  else {
728
- slideToPrevItem("click", newActiveItem);
727
+ slideToPrevItem('click', newActiveItem);
729
728
  }
730
729
  }
731
730
  function getIsNextItem(id) {
@@ -744,8 +743,8 @@ function useSpringCarousel({ items, init = true, withThumbs, thumbsSlideAxis = "
744
743
  }
745
744
  return itemIndex === _activeItem - 1;
746
745
  }
747
- const carouselFragment = (jsxRuntime.jsx("div", Object.assign({ ref: mainCarouselWrapperRef }, getScrollHandlers(), { style: Object.assign({ display: "flex", position: "relative", width: "100%", height: "100%" }, getWrapperOverflowStyles()) }, { children: jsxRuntime.jsx("div", Object.assign({ ref: carouselTrackWrapperRef }, bindDrag(), { style: Object.assign({ position: "relative", display: "flex", flexDirection: carouselSlideAxis === "x" ? "row" : "column", touchAction: "none" }, getAnimatedWrapperStyles()) }, { children: internalItems.map((item, index) => {
748
- 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", flex: "1" }, getItemStyles()) }, { children: item.renderItem }), `${item.id}-${index}`));
746
+ const carouselFragment = (jsxRuntime.jsx("div", Object.assign({ ref: mainCarouselWrapperRef }, getScrollHandlers(), { style: Object.assign({ display: 'flex', position: 'relative', width: '100%', height: '100%' }, getWrapperOverflowStyles()) }, { children: jsxRuntime.jsx("div", Object.assign({ ref: carouselTrackWrapperRef }, bindDrag(), { style: Object.assign({ position: 'relative', display: 'flex', flexDirection: carouselSlideAxis === 'x' ? 'row' : 'column', touchAction: 'none' }, getAnimatedWrapperStyles()) }, { children: internalItems.map((item, index) => {
747
+ 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', flex: '1' }, getItemStyles()) }, { children: item.renderItem }), `${item.id}-${index}`));
749
748
  }) })) })));
750
749
  return {
751
750
  useListenToCustomEvent,
@@ -769,7 +768,7 @@ const Context = react.createContext(undefined);
769
768
  function useSpringCarouselContext() {
770
769
  const context = react.useContext(Context);
771
770
  if (!context) {
772
- throw new Error("useSpringCarouselContext must be used within the carousel.");
771
+ throw new Error('useSpringCarouselContext must be used within the carousel.');
773
772
  }
774
773
  return context;
775
774
  }