react-spring-carousel 3.0.0-beta090.3 → 3.0.0-beta090.5

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.es2.js CHANGED
@@ -1,65 +1,66 @@
1
- import { u as De, a as qe, j as P } from "./useThumbsModule-4e4b7969.js";
2
- import { useSpring as Be, config as Q, useIsomorphicLayoutEffect as He } from "@react-spring/web";
1
+ import { u as qe, a as Be, j as P } from "./useThumbsModule-4e4b7969.js";
2
+ import { useSpring as He, config as Q, useIsomorphicLayoutEffect as ze } from "@react-spring/web";
3
3
  import { useDrag as Oe } from "@use-gesture/react";
4
- import { useRef as m, useEffect as N, createContext as ze, useCallback as O, useContext as Xe } from "react";
5
- import Ye from "resize-observer-polyfill";
6
- import $ from "screenfull";
7
- function Je({
4
+ import { useRef as h, useEffect as $, createContext as Xe, useCallback as z, useContext as Ye } from "react";
5
+ import Je from "resize-observer-polyfill";
6
+ import E from "screenfull";
7
+ function Ke({
8
8
  mainCarouselWrapperRef: n,
9
- onFullScreenChange: h,
10
- handleResize: W
9
+ onFullScreenChange: v,
10
+ handleResize: N
11
11
  }) {
12
- const U = m(!1);
13
- N(() => {
14
- function v() {
15
- document.fullscreenElement && (z(!0), h(!0), W && W()), document.fullscreenElement || (z(!1), h(!1), W && W());
12
+ const U = h(!1);
13
+ $(() => {
14
+ function m() {
15
+ document.fullscreenElement && (O(!0), v(!0), N && N()), document.fullscreenElement || (O(!1), v(!1), N && N());
16
16
  }
17
- if ($.isEnabled)
18
- return $.on("change", v), () => {
19
- $.isEnabled && $.off("change", v);
17
+ if (E.isEnabled)
18
+ return E.on("change", m), () => {
19
+ E.isEnabled && E.off("change", m);
20
20
  };
21
21
  }, []);
22
- function z(v) {
23
- U.current = v;
22
+ function O(m) {
23
+ U.current = m;
24
24
  }
25
25
  function I() {
26
26
  return U.current;
27
27
  }
28
- function b(v) {
29
- $.isEnabled && $.request(v || n.current);
28
+ function T(m) {
29
+ E.isEnabled && E.request(m || n.current);
30
30
  }
31
31
  function u() {
32
- $.isEnabled && $.exit();
32
+ E.isEnabled && E.exit();
33
33
  }
34
34
  return {
35
- enterFullscreen: b,
35
+ enterFullscreen: T,
36
36
  exitFullscreen: u,
37
37
  getIsFullscreen: I
38
38
  };
39
39
  }
40
- function et({
40
+ function tt({
41
41
  items: n,
42
- init: h = !0,
43
- withThumbs: W,
42
+ init: v = !0,
43
+ withThumbs: N,
44
44
  thumbsSlideAxis: U = "x",
45
- itemsPerSlide: z = 1,
45
+ itemsPerSlide: O = 1,
46
46
  slideType: I = "fixed",
47
- gutter: b = 0,
47
+ gutter: T = 0,
48
48
  withLoop: u = !1,
49
- startEndGutter: v = 0,
49
+ startEndGutter: m = 0,
50
50
  carouselSlideAxis: o = "x",
51
- disableGestures: de = !1,
52
- draggingSlideTreshold: te,
53
- slideWhenThresholdIsReached: ge = !1,
51
+ disableGestures: he = !1,
52
+ draggingSlideTreshold: re,
53
+ slideWhenThresholdIsReached: me = !1,
54
54
  freeScroll: c,
55
- enableFreeScrollDrag: xe,
55
+ enableFreeScrollDrag: ne,
56
56
  initialStartingPosition: Z,
57
- prepareThumbsData: ye,
58
- initialActiveItem: F = 0,
59
- animateWhenActiveItemChange: Ie = !0,
60
- getControllerRef: re
57
+ prepareThumbsData: Ie,
58
+ initialActiveItem: C = 0,
59
+ animateWhenActiveItemChange: be = !0,
60
+ getControllerRef: ce,
61
+ slideGroupOfItems: _ = !1
61
62
  }) {
62
- const M = z > n.length ? n.length : z, X = m(!1), _ = m(te ?? 0), k = m("initial"), ne = m("initial"), ce = m("initial"), p = m(F), f = m(F === 0), l = m(I === "fixed" && F === n.length - 1), a = m(null), x = m(null), ue = m(0), oe = m(0), d = m(0), Te = m(u), be = m(I), Me = m(c), R = m(!1), G = O(() => u ? [
63
+ const w = O > n.length ? n.length : O, X = h(!1), G = h(re ?? 0), k = h("initial"), ue = h("initial"), oe = h("initial"), p = h(C), a = h(C === 0), l = h(I === "fixed" && C === n.length - 1), f = h(null), x = h(null), ie = h(0), le = h(0), d = h(0), Te = h(u), we = h(I), Me = h(c), R = h(!1), L = z(() => u ? [
63
64
  ...n.map((e) => ({
64
65
  ...e,
65
66
  id: `prev-repeated-item-${e.id}`
@@ -69,58 +70,58 @@ function et({
69
70
  ...e,
70
71
  id: `next-repeated-item-${e.id}`
71
72
  }))
72
- ] : [...n], [n, u])(), [E, y] = Be(
73
+ ] : [...n], [n, u])(), [W, y] = He(
73
74
  () => ({
74
75
  val: 0,
75
- pause: !h,
76
+ pause: !v,
76
77
  onChange: ({ value: e }) => {
77
- c && a.current ? (o === "x" ? a.current.scrollLeft = Math.abs(e.val) : a.current.scrollTop = Math.abs(e.val), ee()) : x.current && (o === "x" ? x.current.style.transform = `translate3d(${e.val}px, 0px,0px)` : x.current.style.transform = `translate3d(0px,${e.val}px,0px)`);
78
+ c && f.current ? (o === "x" ? f.current.scrollLeft = Math.abs(e.val) : f.current.scrollTop = Math.abs(e.val), te()) : x.current && (o === "x" ? x.current.style.transform = `translate3d(${e.val}px, 0px,0px)` : x.current.style.transform = `translate3d(0px,${e.val}px,0px)`);
78
79
  }
79
80
  }),
80
81
  [c]
81
- ), { emitEvent: L, useListenToCustomEvent: A } = De(), { thumbsFragment: Ce, handleScroll: Fe } = qe({
82
- withThumbs: !!W,
82
+ ), { emitEvent: A, useListenToCustomEvent: S } = qe(), { thumbsFragment: Ce, handleScroll: ke } = Be({
83
+ withThumbs: !!N,
83
84
  thumbsSlideAxis: U,
84
- prepareThumbsData: ye,
85
+ prepareThumbsData: Ie,
85
86
  items: n,
86
87
  renderThumbFnProps: {
87
- getIsActiveItem: fe,
88
- getIsPrevItem: se,
89
- useListenToCustomEvent: A,
90
- getIsNextItem: le
88
+ getIsActiveItem: de,
89
+ getIsPrevItem: ae,
90
+ useListenToCustomEvent: S,
91
+ getIsNextItem: fe
91
92
  }
92
- }), { enterFullscreen: me, exitFullscreen: ve, getIsFullscreen: he } = Je({
93
- mainCarouselWrapperRef: a,
94
- handleResize: () => S(),
93
+ }), { enterFullscreen: ve, exitFullscreen: pe, getIsFullscreen: xe } = Ke({
94
+ mainCarouselWrapperRef: f,
95
+ handleResize: () => ee(),
95
96
  onFullScreenChange: (e) => {
96
- L({
97
+ A({
97
98
  eventName: "onFullscreenChange",
98
99
  isFullscreen: e
99
100
  });
100
101
  }
101
102
  });
102
- function ke(e) {
103
+ function Fe(e) {
103
104
  return I === "fixed" && !c ? {
104
- marginRight: `${e ? 0 : b}px`,
105
- flex: `1 0 calc(100% / ${M} - ${b * (M - 1) / M}px)`
105
+ marginRight: `${e ? 0 : T}px`,
106
+ flex: `1 0 calc(100% / ${w} - ${T * (w - 1) / w}px)`
106
107
  } : {
107
- marginRight: `${e ? 0 : b}px`
108
+ marginRight: `${e ? 0 : T}px`
108
109
  };
109
110
  }
110
- const s = O(() => {
111
+ const s = z(() => {
111
112
  var r;
112
- const e = (r = a.current) == null ? void 0 : r.querySelector(".use-spring-carousel-item");
113
+ const e = _ ? f.current : (r = f.current) == null ? void 0 : r.querySelector(".use-spring-carousel-item");
113
114
  if (!e)
114
115
  throw Error("No carousel items available!");
115
- return e.getBoundingClientRect()[o === "x" ? "width" : "height"] + b;
116
- }, [o, b]);
117
- function j({ from: e, to: r, nextActiveItem: t, immediate: i = !1, slideMode: C }) {
118
- ne.current = C, typeof t == "number" && (c || (p.current = t), L({
116
+ return e.getBoundingClientRect()[o === "x" ? "width" : "height"] + T;
117
+ }, [o, T, _]);
118
+ function j({ from: e, to: r, nextActiveItem: t, immediate: i = !1, slideMode: M }) {
119
+ ue.current = M, typeof t == "number" && (c || (p.current = t), A({
119
120
  eventName: "onSlideStartChange",
120
121
  slideActionType: k.current,
121
- slideMode: ne.current,
122
+ slideMode: ue.current,
122
123
  nextItem: {
123
- startReached: f.current,
124
+ startReached: a.current,
124
125
  endReached: l.current,
125
126
  index: c ? -1 : p.current,
126
127
  id: c ? "" : n[p.current].id
@@ -135,54 +136,54 @@ function et({
135
136
  },
136
137
  config: {
137
138
  ...Q.default,
138
- velocity: E.val.velocity
139
+ velocity: W.val.velocity
139
140
  },
140
141
  onRest(B) {
141
- !i && B.finished && L({
142
+ !i && B.finished && A({
142
143
  eventName: "onSlideChange",
143
144
  slideActionType: k.current,
144
- slideMode: ne.current,
145
+ slideMode: ue.current,
145
146
  currentItem: {
146
- startReached: f.current,
147
+ startReached: a.current,
147
148
  endReached: l.current,
148
149
  index: c ? -1 : p.current,
149
150
  id: c ? "" : n[p.current].id
150
151
  }
151
152
  });
152
153
  }
153
- }), W && !i && Fe(p.current);
154
+ }), N && !i && ke(p.current);
154
155
  }
155
- const g = O(() => {
156
+ const g = z(() => {
156
157
  var e;
157
158
  return x.current ? u ? s() * n.length : Math.round(
158
159
  Number(
159
160
  (e = x.current) == null ? void 0 : e[o === "x" ? "scrollWidth" : "scrollHeight"]
160
- ) - x.current.getBoundingClientRect()[o === "x" ? "width" : "height"] - v * 2
161
+ ) - x.current.getBoundingClientRect()[o === "x" ? "width" : "height"] - m * 2
161
162
  ) : 0;
162
- }, [o, s, n.length, v, u]);
163
- function we() {
164
- const e = `calc(100% - ${v * 2}px)`;
163
+ }, [o, s, n.length, m, u]);
164
+ function Ee() {
165
+ const e = `calc(100% - ${m * 2}px)`;
165
166
  return {
166
167
  width: o === "x" ? e : "100%",
167
168
  height: o === "y" ? e : "100%"
168
169
  };
169
170
  }
170
- const Y = O(() => {
171
+ const Y = z(() => {
171
172
  var r;
172
173
  const e = (r = x.current) == null ? void 0 : r.querySelector(".use-spring-carousel-item");
173
174
  if (!e)
174
175
  throw Error("No carousel items available!");
175
- return e.getBoundingClientRect()[o === "x" ? "width" : "height"] + b;
176
- }, [o, b]), J = O(
176
+ return e.getBoundingClientRect()[o === "x" ? "width" : "height"] + T;
177
+ }, [o, T]), J = z(
177
178
  (e) => {
178
179
  const r = o === "x" ? "left" : "top", t = x.current;
179
- t && (u ? (t.style.top = "0px", t.style.left = "0px", t.style[r] = `-${e - v}px`, f.current = !1, l.current = !1) : (t.style.left = "0px", t.style.top = "0px"));
180
+ t && (u ? (t.style.top = "0px", t.style.left = "0px", t.style[r] = `-${e - m}px`, a.current = !1, l.current = !1) : (t.style.left = "0px", t.style.top = "0px"));
180
181
  },
181
- [o, v, u]
182
- ), S = O(
182
+ [o, m, u]
183
+ ), ee = z(
183
184
  (e = !1) => {
184
185
  if (x.current && e && (x.current.style.transform = "translate3d(0px, 0px,0px)", x.current.style.left = "0", x.current.style.top = "0"), I === "fixed" && J(
185
- Z === "center" ? Y() * n.length - s() * Math.round((M - 1) / 2) : Z === "end" ? Y() * n.length - s() * Math.round(M - 1) : Y() * n.length
186
+ Z === "center" ? Y() * n.length - s() * Math.round((w - 1) / 2) : Z === "end" ? Y() * n.length - s() * Math.round(w - 1) : Y() * n.length
186
187
  ), I === "fluid") {
187
188
  if (J(Y() * n.length), l.current && g() !== Math.abs(d.current) && !u) {
188
189
  const r = -g();
@@ -192,8 +193,8 @@ function et({
192
193
  });
193
194
  return;
194
195
  }
195
- if (Math.abs(d.current) > 0 && g() !== Math.abs(d.current) && !u && !c && ce.current === "backward") {
196
- const r = ue.current - g(), t = d.current + r;
196
+ if (Math.abs(d.current) > 0 && g() !== Math.abs(d.current) && !u && !c && oe.current === "backward") {
197
+ const r = ie.current - g(), t = d.current + r;
197
198
  return y.start({
198
199
  immediate: !0,
199
200
  val: t
@@ -229,15 +230,15 @@ function et({
229
230
  g,
230
231
  Z,
231
232
  n.length,
232
- M,
233
+ w,
233
234
  J,
234
235
  y,
235
236
  I,
236
237
  u
237
238
  ]
238
239
  );
239
- function w() {
240
- return c && a.current ? a.current[o === "x" ? "scrollLeft" : "scrollTop"] : E.val.get();
240
+ function F() {
241
+ return c && f.current ? f.current[o === "x" ? "scrollLeft" : "scrollTop"] : W.val.get();
241
242
  }
242
243
  function K(e, r) {
243
244
  if (c && e === "next") {
@@ -251,18 +252,18 @@ function et({
251
252
  return e === "next" ? typeof r == "number" ? -(r * s()) : d.current - s() : typeof r == "number" ? -(r * s()) : d.current + s();
252
253
  }
253
254
  function V({ type: e, index: r, immediate: t }) {
254
- if (!h || R.current || f.current && !u)
255
+ if (!v || R.current || a.current && !u)
255
256
  return;
256
- l.current && (ce.current = "backward"), k.current = "prev", l.current = !1;
257
+ l.current && (oe.current = "backward"), k.current = "prev", l.current = !1;
257
258
  const i = typeof r == "number" ? r : p.current - 1;
258
- if (c && ee(), !u) {
259
- const C = c ? K("prev", r) - s() / 3 < 0 : K("prev", r) + s() / 3 > 0;
260
- if (f.current)
259
+ if (c && te(), !u) {
260
+ const M = c ? K("prev", r) - s() / 3 < 0 : K("prev", r) + s() / 3 > 0;
261
+ if (a.current)
261
262
  return;
262
- if (C) {
263
- f.current = !0, l.current = !1, j({
263
+ if (M) {
264
+ a.current = !0, l.current = !1, j({
264
265
  slideMode: e,
265
- from: w(),
266
+ from: F(),
266
267
  to: 0,
267
268
  nextActiveItem: 0,
268
269
  immediate: t
@@ -270,37 +271,37 @@ function et({
270
271
  return;
271
272
  }
272
273
  }
273
- if (u && (f.current || i < 0)) {
274
- f.current = !1, l.current = !0, j({
274
+ if (u && (a.current || i < 0)) {
275
+ a.current = !1, l.current = !0, j({
275
276
  slideMode: e,
276
- from: w() - s() * n.length,
277
+ from: F() - s() * n.length,
277
278
  to: -(s() * n.length) + s(),
278
279
  nextActiveItem: n.length - 1,
279
280
  immediate: t
280
281
  });
281
282
  return;
282
283
  }
283
- i === 0 && (f.current = !0), (i === n.length - 1 || i === -1) && (l.current = !0), j({
284
+ i === 0 && (a.current = !0), (i === n.length - 1 || i === -1) && (l.current = !0), j({
284
285
  slideMode: e,
285
- from: w(),
286
+ from: F(),
286
287
  to: K("prev", r),
287
288
  nextActiveItem: i,
288
289
  immediate: t
289
290
  });
290
291
  }
291
292
  function D({ type: e, index: r, immediate: t }) {
292
- if (!h || R.current || l.current && !u)
293
+ if (!v || R.current || l.current && !u)
293
294
  return;
294
- f.current && (ce.current = "forward"), k.current = "next", f.current = !1;
295
+ a.current && (oe.current = "forward"), k.current = "next", a.current = !1;
295
296
  const i = r || p.current + 1;
296
- if (c && ee(), !u) {
297
- const C = Math.abs(K("next", r)) > g() - s() / 3;
297
+ if (c && te(), !u) {
298
+ const M = Math.abs(K("next", r)) > g() - s() / 3;
298
299
  if (l.current)
299
300
  return;
300
- if (C) {
301
- f.current = !1, l.current = !0, j({
301
+ if (M) {
302
+ a.current = !1, l.current = !0, j({
302
303
  slideMode: e,
303
- from: w(),
304
+ from: F(),
304
305
  to: c ? g() : -g(),
305
306
  nextActiveItem: i,
306
307
  immediate: t
@@ -309,34 +310,34 @@ function et({
309
310
  }
310
311
  }
311
312
  if (u && (l.current || i > n.length - 1)) {
312
- l.current = !1, f.current = !0, j({
313
+ l.current = !1, a.current = !0, j({
313
314
  slideMode: e,
314
- from: w() + s() * n.length,
315
+ from: F() + s() * n.length,
315
316
  to: 0,
316
317
  nextActiveItem: 0,
317
318
  immediate: t
318
319
  });
319
320
  return;
320
321
  }
321
- i === 0 && (f.current = !0), i === n.length - 1 && (l.current = !0), j({
322
+ i === 0 && (a.current = !0), i === n.length - 1 && (l.current = !0), j({
322
323
  slideMode: e,
323
- from: w(),
324
+ from: F(),
324
325
  to: K("next", r),
325
326
  nextActiveItem: i,
326
327
  immediate: t
327
328
  });
328
329
  }
329
330
  function $e() {
330
- te ? _.current = te : _.current = Math.floor(s() / 2 / 2);
331
+ re ? G.current = re : G.current = Math.floor(s() / 2 / 2);
331
332
  }
332
- function pe() {
333
- x.current && (ue.current = g(), Te.current = u, be.current = I, Me.current = c, oe.current = window.innerWidth, d.current = 0, ie({ id: 0, immediate: !0, shouldReset: !0 }), $e(), S());
333
+ function ye() {
334
+ x.current && (ie.current = g(), Te.current = u, we.current = I, Me.current = c, le.current = window.innerWidth, d.current = 0, se({ id: 0, immediate: !0, shouldReset: !0 }), $e(), ee());
334
335
  }
335
336
  const Ne = Oe(
336
337
  (e) => {
337
- const r = e.dragging, t = e.offset[o === "x" ? 0 : 1], i = e.movement[o === "x" ? 0 : 1], C = e.direction[o === "x" ? 0 : 1], B = i > _.current, H = i < -_.current, Ve = g();
338
+ const r = e.dragging, t = e.offset[o === "x" ? 0 : 1], i = e.movement[o === "x" ? 0 : 1], M = e.direction[o === "x" ? 0 : 1], B = i > G.current, H = i < -G.current, De = g();
338
339
  if (r) {
339
- if (C > 0 ? k.current = "prev" : k.current = "next", L({
340
+ if (M > 0 ? k.current = "prev" : k.current = "next", A({
340
341
  ...e,
341
342
  eventName: "onDrag",
342
343
  slideActionType: k.current
@@ -344,7 +345,7 @@ function et({
344
345
  if (t > 0) {
345
346
  y.start({
346
347
  from: {
347
- val: w()
348
+ val: F()
348
349
  },
349
350
  to: {
350
351
  val: 0
@@ -359,7 +360,7 @@ function et({
359
360
  }
360
361
  y.start({
361
362
  from: {
362
- val: w()
363
+ val: F()
363
364
  },
364
365
  to: {
365
366
  val: -t
@@ -379,13 +380,13 @@ function et({
379
380
  friction: 50,
380
381
  tension: 1e3
381
382
  }
382
- }), ge && H ? (D({ type: "drag" }), e.cancel()) : ge && B && (V({ type: "drag" }), e.cancel()), Ve - Math.abs(t) < -(s() * 2) && e.cancel();
383
+ }), me && H ? (D({ type: "drag" }), e.cancel()) : me && B && (V({ type: "drag" }), e.cancel()), De - Math.abs(t) < -(s() * 2) && e.cancel();
383
384
  return;
384
385
  }
385
386
  if (e.last && c && t > 0) {
386
387
  y.start({
387
388
  from: {
388
- val: w()
389
+ val: F()
389
390
  },
390
391
  to: {
391
392
  val: 0
@@ -404,7 +405,7 @@ function et({
404
405
  ...Q.default,
405
406
  velocity: e.velocity
406
407
  }
407
- }) : D({ type: "drag" }) : B ? !u && f.current ? y.start({
408
+ }) : D({ type: "drag" }) : B ? !u && a.current ? y.start({
408
409
  val: 0,
409
410
  config: {
410
411
  ...Q.default,
@@ -425,12 +426,12 @@ function et({
425
426
  });
426
427
  },
427
428
  {
428
- enabled: h && !de && !c || !!c && !!xe,
429
+ enabled: v && !he && !c || !!c && !!ne,
429
430
  axis: o,
430
- from: () => c && a.current ? [
431
- -a.current.scrollLeft,
432
- -a.current.scrollTop
433
- ] : o === "x" ? [E.val.get(), E.val.get()] : [E.val.get(), E.val.get()]
431
+ from: () => c && f.current ? [
432
+ -f.current.scrollLeft,
433
+ -f.current.scrollTop
434
+ ] : o === "x" ? [W.val.get(), W.val.get()] : [W.val.get(), W.val.get()]
434
435
  }
435
436
  );
436
437
  function We() {
@@ -440,13 +441,13 @@ function et({
440
441
  overflowY: "auto"
441
442
  } : {};
442
443
  }
443
- function ee() {
444
- a.current && (d.current = a.current[o === "x" ? "scrollLeft" : "scrollTop"], a.current[o === "x" ? "scrollLeft" : "scrollTop"] === 0 && (f.current = !0, l.current = !1), a.current[o === "x" ? "scrollLeft" : "scrollTop"] > 0 && a.current[o === "x" ? "scrollLeft" : "scrollTop"] < g() && (f.current = !1, l.current = !1), a.current[o === "x" ? "scrollLeft" : "scrollTop"] === g() && (f.current = !1, l.current = !0));
444
+ function te() {
445
+ f.current && (d.current = f.current[o === "x" ? "scrollLeft" : "scrollTop"], f.current[o === "x" ? "scrollLeft" : "scrollTop"] === 0 && (a.current = !0, l.current = !1), f.current[o === "x" ? "scrollLeft" : "scrollTop"] > 0 && f.current[o === "x" ? "scrollLeft" : "scrollTop"] < g() && (a.current = !1, l.current = !1), f.current[o === "x" ? "scrollLeft" : "scrollTop"] === g() && (a.current = !1, l.current = !0));
445
446
  }
446
- function Ee() {
447
+ function Pe() {
447
448
  return c ? {
448
449
  onWheel() {
449
- E.val.stop(), ee();
450
+ W.val.stop(), te();
450
451
  }
451
452
  } : {};
452
453
  }
@@ -459,17 +460,17 @@ function et({
459
460
  }
460
461
  return t;
461
462
  }
462
- function ie({ id: e, immediate: r, shouldReset: t, type: i }) {
463
- if (!h || R.current)
463
+ function se({ id: e, immediate: r, shouldReset: t, type: i }) {
464
+ if (!v || R.current)
464
465
  return;
465
- f.current = !1, l.current = !1;
466
- const C = q(
466
+ a.current = !1, l.current = !1;
467
+ const M = q(
467
468
  e,
468
469
  "The item you want to slide to doesn't exist; check the provided id."
469
470
  );
470
- if (C === p.current && !t)
471
+ if (M === p.current && !t)
471
472
  return;
472
- const B = q(n[p.current].id), H = q(n[C].id);
473
+ const B = q(n[p.current].id), H = q(n[M].id);
473
474
  H > B ? D({
474
475
  type: i || t ? "initial" : "click",
475
476
  index: H,
@@ -480,25 +481,25 @@ function et({
480
481
  immediate: r
481
482
  });
482
483
  }
483
- function le(e) {
484
+ function fe(e) {
484
485
  const r = q(e, "The item doesn't exist; check the provided id."), t = p.current;
485
486
  return u && t === n.length - 1 ? r === 0 : r === t + 1;
486
487
  }
487
- function se(e) {
488
+ function ae(e) {
488
489
  const r = q(e, "The item doesn't exist; check the provided id."), t = p.current;
489
490
  return u && t === 0 ? r === n.length - 1 : r === t - 1;
490
491
  }
491
- function fe(e) {
492
+ function de(e) {
492
493
  return q(e, "The item you want to check doesn't exist; check the provided id.") === p.current;
493
494
  }
494
- function Pe() {
495
- return de ? "unset" : o === "x" ? "pan-y" : "pan-x";
495
+ function Re() {
496
+ return he ? "unset" : o === "x" ? "pan-y" : "pan-x";
496
497
  }
497
- const T = c ? {
498
- useListenToCustomEvent: A,
499
- enterFullscreen: me,
500
- exitFullscreen: ve,
501
- getIsFullscreen: he,
498
+ const b = c ? {
499
+ useListenToCustomEvent: S,
500
+ enterFullscreen: ve,
501
+ exitFullscreen: pe,
502
+ getIsFullscreen: xe,
502
503
  slideToPrevItem: (e = !0) => {
503
504
  V({
504
505
  type: "click",
@@ -512,10 +513,10 @@ function et({
512
513
  });
513
514
  }
514
515
  } : {
515
- useListenToCustomEvent: A,
516
- enterFullscreen: me,
517
- exitFullscreen: ve,
518
- getIsFullscreen: he,
516
+ useListenToCustomEvent: S,
517
+ enterFullscreen: ve,
518
+ exitFullscreen: pe,
519
+ getIsFullscreen: xe,
519
520
  slideToPrevItem: (e = !0) => {
520
521
  V({
521
522
  type: "click",
@@ -529,35 +530,58 @@ function et({
529
530
  });
530
531
  },
531
532
  slideToItem: (e, r = !0) => {
532
- ie({ id: e, immediate: !r });
533
+ se({ id: e, immediate: !r });
533
534
  },
534
- getIsNextItem: le,
535
- getIsPrevItem: se,
536
- getIsActiveItem: fe
535
+ getIsNextItem: fe,
536
+ getIsPrevItem: ae,
537
+ getIsActiveItem: de
537
538
  };
538
- He(() => {
539
- x.current && h && (X.current = !0, pe());
540
- }, [h]), N(() => {
541
- p.current !== F && (X.current = !0, ie({
542
- id: F,
543
- immediate: !Ie
539
+ ze(() => {
540
+ x.current && v && (X.current = !0, ye());
541
+ }, [v]), $(() => {
542
+ p.current !== C && (X.current = !0, se({
543
+ id: C,
544
+ immediate: !be
544
545
  }));
545
- }, [F]), N(() => {
546
- if (h) {
547
- if (F > n.length - 1)
546
+ }, [C]), $(() => {
547
+ if (v) {
548
+ if (C > n.length - 1)
548
549
  throw new Error(
549
- `initialActiveItem (${F}) is greater than the total quantity available items (${n.length}).`
550
+ `initialActiveItem (${C}) is greater than the total quantity available items (${n.length}).`
550
551
  );
551
- M > n.length && console.warn(
552
- `itemsPerSlide (${M}) is greater than the total quantity available items (${n.length}). Fallback to ${n.length})`
552
+ w > n.length && console.warn(
553
+ `itemsPerSlide (${w}) is greater than the total quantity available items (${n.length}). Fallback to ${n.length})`
553
554
  );
554
555
  }
555
- }, [F, n.length, M, h]), N(() => {
556
- oe.current = window.innerWidth;
557
- }, []), N(() => {
558
- h && (X.current = !0, pe());
559
- }, [Z, M, v, b, h, u, I]), N(() => {
560
- if (!h)
556
+ }, [C, n.length, w, v]), $(() => {
557
+ le.current = window.innerWidth;
558
+ }, []), $(() => {
559
+ if (v) {
560
+ if (u && c)
561
+ throw new Error("`withLoop` and `freeScroll` can't be used together.");
562
+ if (c && I === "fixed")
563
+ throw new Error("`freeScroll` can't be used when `scrollType=fixed`.");
564
+ if (ne && (I !== "fluid" || !c))
565
+ throw new Error(
566
+ "`enableFreeScrollDrag` must be used with `slideType=fluid` and `freeScroll=true`"
567
+ );
568
+ if (_ && c)
569
+ throw new Error("`slideGroupOfItems` and `freeScroll` can't be used together.");
570
+ X.current = !0, ye();
571
+ }
572
+ }, [
573
+ Z,
574
+ w,
575
+ m,
576
+ T,
577
+ v,
578
+ u,
579
+ I,
580
+ c,
581
+ ne,
582
+ _
583
+ ]), $(() => {
584
+ if (!v)
561
585
  return;
562
586
  function e() {
563
587
  document.hidden ? R.current = !0 : R.current = !1;
@@ -565,35 +589,35 @@ function et({
565
589
  return document.addEventListener("visibilitychange", e), () => {
566
590
  document.removeEventListener("visibilitychange", e);
567
591
  };
568
- }, [h]), N(() => {
569
- if (a.current) {
592
+ }, [v]), $(() => {
593
+ if (f.current) {
570
594
  let e;
571
- const r = new Ye(() => {
595
+ const r = new Je(() => {
572
596
  if (!R.current && !X.current) {
573
- oe.current = window.innerWidth;
574
- const t = S();
597
+ le.current = window.innerWidth;
598
+ const t = ee();
575
599
  window.clearTimeout(e), e = setTimeout(() => {
576
- ue.current = g(), typeof t == "function" && t();
600
+ ie.current = g(), typeof t == "function" && t();
577
601
  }, 100);
578
602
  }
579
603
  });
580
- return r.observe(a.current), () => {
604
+ return r.observe(f.current), () => {
581
605
  r.disconnect();
582
606
  };
583
607
  }
584
- }, [S, g]), N(() => {
585
- re && re({
586
- slideToNextItem: T.slideToNextItem,
587
- slideToPrevItem: T.slideToPrevItem,
588
- slideToItem: T == null ? void 0 : T.slideToItem
608
+ }, [ee, g]), $(() => {
609
+ ce && ce({
610
+ slideToNextItem: b.slideToNextItem,
611
+ slideToPrevItem: b.slideToPrevItem,
612
+ slideToItem: b == null ? void 0 : b.slideToItem
589
613
  });
590
- }, [re, T.slideToItem, T.slideToNextItem, T.slideToPrevItem]);
591
- const Re = /* @__PURE__ */ P.jsx(ae.Provider, { value: T, children: Ce }), je = /* @__PURE__ */ P.jsx(ae.Provider, { value: T, children: /* @__PURE__ */ P.jsx(
614
+ }, [ce, b.slideToItem, b.slideToNextItem, b.slideToPrevItem]);
615
+ const je = /* @__PURE__ */ P.jsx(ge.Provider, { value: b, children: Ce }), Ve = /* @__PURE__ */ P.jsx(ge.Provider, { value: b, children: /* @__PURE__ */ P.jsx(
592
616
  "div",
593
617
  {
594
618
  className: "use-spring-carousel-main-wrapper",
595
- ref: a,
596
- ...Ee(),
619
+ ref: f,
620
+ ...Pe(),
597
621
  style: {
598
622
  display: "flex",
599
623
  position: "relative",
@@ -611,20 +635,20 @@ function et({
611
635
  position: "relative",
612
636
  display: "flex",
613
637
  flexDirection: o === "x" ? "row" : "column",
614
- touchAction: Pe(),
615
- ...we()
638
+ touchAction: Re(),
639
+ ...Ee()
616
640
  },
617
641
  children: [
618
- (c || !u) && v ? /* @__PURE__ */ P.jsx(
642
+ (c || !u) && m ? /* @__PURE__ */ P.jsx(
619
643
  "div",
620
644
  {
621
645
  style: {
622
646
  flexShrink: 0,
623
- width: v
647
+ width: m
624
648
  }
625
649
  }
626
650
  ) : null,
627
- G.map((e, r) => /* @__PURE__ */ P.jsx(
651
+ L.map((e, r) => /* @__PURE__ */ P.jsx(
628
652
  "div",
629
653
  {
630
654
  className: "use-spring-carousel-item",
@@ -633,27 +657,27 @@ function et({
633
657
  display: "flex",
634
658
  position: "relative",
635
659
  flex: "1",
636
- ...ke(
637
- r === G.findIndex(
638
- (t) => t.id === G[G.length - 1].id
660
+ ...Fe(
661
+ r === L.findIndex(
662
+ (t) => t.id === L[L.length - 1].id
639
663
  )
640
664
  )
641
665
  },
642
666
  children: typeof e.renderItem == "function" ? e.renderItem({
643
- getIsActiveItem: fe,
644
- getIsNextItem: le,
645
- getIsPrevItem: se,
646
- useListenToCustomEvent: A
667
+ getIsActiveItem: de,
668
+ getIsNextItem: fe,
669
+ getIsPrevItem: ae,
670
+ useListenToCustomEvent: S
647
671
  }) : e.renderItem
648
672
  },
649
673
  `${e.id}-${r}`
650
674
  )),
651
- (c || !u) && v ? /* @__PURE__ */ P.jsx(
675
+ (c || !u) && m ? /* @__PURE__ */ P.jsx(
652
676
  "div",
653
677
  {
654
678
  style: {
655
679
  flexShrink: 0,
656
- width: v
680
+ width: m
657
681
  }
658
682
  }
659
683
  ) : null
@@ -662,17 +686,17 @@ function et({
662
686
  )
663
687
  }
664
688
  ) });
665
- return { ...T, carouselFragment: je, thumbsFragment: Re };
689
+ return { ...b, carouselFragment: Ve, thumbsFragment: je };
666
690
  }
667
- const ae = ze(void 0);
668
- function tt() {
669
- const n = Xe(ae);
691
+ const ge = Xe(void 0);
692
+ function rt() {
693
+ const n = Ye(ge);
670
694
  if (!n)
671
695
  throw new Error("useSpringCarouselContext must be used within the carousel.");
672
696
  return n;
673
697
  }
674
698
  export {
675
- et as useSpringCarousel,
676
- tt as useSpringCarouselContext
699
+ tt as useSpringCarousel,
700
+ rt as useSpringCarouselContext
677
701
  };
678
702
  //# sourceMappingURL=index.es2.js.map