react-spring-carousel 3.0.0-beta070 → 3.0.0-beta072

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