react-spring-carousel 3.0.0-beta090.4 → 3.0.0-beta090.6

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