react-spring-carousel 3.0.0-beta090 → 3.0.0-beta090.10

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