react-spring-carousel 3.0.0-beta078 → 3.0.0-beta080

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.
@@ -0,0 +1,1087 @@
1
+ import { u as Se, j as N } from "./useThumbsModule-08e90459.js";
2
+ import { useSpring as Xe, useIsomorphicLayoutEffect as Je, config as G } from "@react-spring/web";
3
+ import { useRef as x, useEffect as z, createContext as Qe, useCallback as Ue, useContext as Ze } from "react";
4
+ import { u as et, a as tt } from "./use-gesture-react.esm-9eb8841a.js";
5
+ var Te = function() {
6
+ if (typeof Map < "u")
7
+ return Map;
8
+ function e(t, r) {
9
+ var i = -1;
10
+ return t.some(function(u, f) {
11
+ return u[0] === r ? (i = f, !0) : !1;
12
+ }), i;
13
+ }
14
+ return (
15
+ /** @class */
16
+ function() {
17
+ function t() {
18
+ this.__entries__ = [];
19
+ }
20
+ return Object.defineProperty(t.prototype, "size", {
21
+ /**
22
+ * @returns {boolean}
23
+ */
24
+ get: function() {
25
+ return this.__entries__.length;
26
+ },
27
+ enumerable: !0,
28
+ configurable: !0
29
+ }), t.prototype.get = function(r) {
30
+ var i = e(this.__entries__, r), u = this.__entries__[i];
31
+ return u && u[1];
32
+ }, t.prototype.set = function(r, i) {
33
+ var u = e(this.__entries__, r);
34
+ ~u ? this.__entries__[u][1] = i : this.__entries__.push([r, i]);
35
+ }, t.prototype.delete = function(r) {
36
+ var i = this.__entries__, u = e(i, r);
37
+ ~u && i.splice(u, 1);
38
+ }, t.prototype.has = function(r) {
39
+ return !!~e(this.__entries__, r);
40
+ }, t.prototype.clear = function() {
41
+ this.__entries__.splice(0);
42
+ }, t.prototype.forEach = function(r, i) {
43
+ i === void 0 && (i = null);
44
+ for (var u = 0, f = this.__entries__; u < f.length; u++) {
45
+ var a = f[u];
46
+ r.call(i, a[1], a[0]);
47
+ }
48
+ }, t;
49
+ }()
50
+ );
51
+ }(), me = typeof window < "u" && typeof document < "u" && window.document === document, ee = function() {
52
+ return typeof global < "u" && global.Math === Math ? global : typeof self < "u" && self.Math === Math ? self : typeof window < "u" && window.Math === Math ? window : Function("return this")();
53
+ }(), nt = function() {
54
+ return typeof requestAnimationFrame == "function" ? requestAnimationFrame.bind(ee) : function(e) {
55
+ return setTimeout(function() {
56
+ return e(Date.now());
57
+ }, 1e3 / 60);
58
+ };
59
+ }(), rt = 2;
60
+ function it(e, t) {
61
+ var r = !1, i = !1, u = 0;
62
+ function f() {
63
+ r && (r = !1, e()), i && s();
64
+ }
65
+ function a() {
66
+ nt(f);
67
+ }
68
+ function s() {
69
+ var l = Date.now();
70
+ if (r) {
71
+ if (l - u < rt)
72
+ return;
73
+ i = !0;
74
+ } else
75
+ r = !0, i = !1, setTimeout(a, t);
76
+ u = l;
77
+ }
78
+ return s;
79
+ }
80
+ var ot = 20, ct = ["top", "right", "bottom", "left", "width", "height", "size", "weight"], st = typeof MutationObserver < "u", ut = (
81
+ /** @class */
82
+ function() {
83
+ function e() {
84
+ this.connected_ = !1, this.mutationEventsAdded_ = !1, this.mutationsObserver_ = null, this.observers_ = [], this.onTransitionEnd_ = this.onTransitionEnd_.bind(this), this.refresh = it(this.refresh.bind(this), ot);
85
+ }
86
+ return e.prototype.addObserver = function(t) {
87
+ ~this.observers_.indexOf(t) || this.observers_.push(t), this.connected_ || this.connect_();
88
+ }, e.prototype.removeObserver = function(t) {
89
+ var r = this.observers_, i = r.indexOf(t);
90
+ ~i && r.splice(i, 1), !r.length && this.connected_ && this.disconnect_();
91
+ }, e.prototype.refresh = function() {
92
+ var t = this.updateObservers_();
93
+ t && this.refresh();
94
+ }, e.prototype.updateObservers_ = function() {
95
+ var t = this.observers_.filter(function(r) {
96
+ return r.gatherActive(), r.hasActive();
97
+ });
98
+ return t.forEach(function(r) {
99
+ return r.broadcastActive();
100
+ }), t.length > 0;
101
+ }, e.prototype.connect_ = function() {
102
+ !me || this.connected_ || (document.addEventListener("transitionend", this.onTransitionEnd_), window.addEventListener("resize", this.refresh), st ? (this.mutationsObserver_ = new MutationObserver(this.refresh), this.mutationsObserver_.observe(document, {
103
+ attributes: !0,
104
+ childList: !0,
105
+ characterData: !0,
106
+ subtree: !0
107
+ })) : (document.addEventListener("DOMSubtreeModified", this.refresh), this.mutationEventsAdded_ = !0), this.connected_ = !0);
108
+ }, e.prototype.disconnect_ = function() {
109
+ !me || !this.connected_ || (document.removeEventListener("transitionend", this.onTransitionEnd_), window.removeEventListener("resize", this.refresh), this.mutationsObserver_ && this.mutationsObserver_.disconnect(), this.mutationEventsAdded_ && document.removeEventListener("DOMSubtreeModified", this.refresh), this.mutationsObserver_ = null, this.mutationEventsAdded_ = !1, this.connected_ = !1);
110
+ }, e.prototype.onTransitionEnd_ = function(t) {
111
+ var r = t.propertyName, i = r === void 0 ? "" : r, u = ct.some(function(f) {
112
+ return !!~i.indexOf(f);
113
+ });
114
+ u && this.refresh();
115
+ }, e.getInstance = function() {
116
+ return this.instance_ || (this.instance_ = new e()), this.instance_;
117
+ }, e.instance_ = null, e;
118
+ }()
119
+ ), Fe = function(e, t) {
120
+ for (var r = 0, i = Object.keys(t); r < i.length; r++) {
121
+ var u = i[r];
122
+ Object.defineProperty(e, u, {
123
+ value: t[u],
124
+ enumerable: !1,
125
+ writable: !1,
126
+ configurable: !0
127
+ });
128
+ }
129
+ return e;
130
+ }, L = function(e) {
131
+ var t = e && e.ownerDocument && e.ownerDocument.defaultView;
132
+ return t || ee;
133
+ }, Me = ne(0, 0, 0, 0);
134
+ function te(e) {
135
+ return parseFloat(e) || 0;
136
+ }
137
+ function Ie(e) {
138
+ for (var t = [], r = 1; r < arguments.length; r++)
139
+ t[r - 1] = arguments[r];
140
+ return t.reduce(function(i, u) {
141
+ var f = e["border-" + u + "-width"];
142
+ return i + te(f);
143
+ }, 0);
144
+ }
145
+ function at(e) {
146
+ for (var t = ["top", "right", "bottom", "left"], r = {}, i = 0, u = t; i < u.length; i++) {
147
+ var f = u[i], a = e["padding-" + f];
148
+ r[f] = te(a);
149
+ }
150
+ return r;
151
+ }
152
+ function lt(e) {
153
+ var t = e.getBBox();
154
+ return ne(0, 0, t.width, t.height);
155
+ }
156
+ function ft(e) {
157
+ var t = e.clientWidth, r = e.clientHeight;
158
+ if (!t && !r)
159
+ return Me;
160
+ var i = L(e).getComputedStyle(e), u = at(i), f = u.left + u.right, a = u.top + u.bottom, s = te(i.width), l = te(i.height);
161
+ if (i.boxSizing === "border-box" && (Math.round(s + f) !== t && (s -= Ie(i, "left", "right") + f), Math.round(l + a) !== r && (l -= Ie(i, "top", "bottom") + a)), !ht(e)) {
162
+ var d = Math.round(s + f) - t, T = Math.round(l + a) - r;
163
+ Math.abs(d) !== 1 && (s -= d), Math.abs(T) !== 1 && (l -= T);
164
+ }
165
+ return ne(u.left, u.top, s, l);
166
+ }
167
+ var dt = function() {
168
+ return typeof SVGGraphicsElement < "u" ? function(e) {
169
+ return e instanceof L(e).SVGGraphicsElement;
170
+ } : function(e) {
171
+ return e instanceof L(e).SVGElement && typeof e.getBBox == "function";
172
+ };
173
+ }();
174
+ function ht(e) {
175
+ return e === L(e).document.documentElement;
176
+ }
177
+ function vt(e) {
178
+ return me ? dt(e) ? lt(e) : ft(e) : Me;
179
+ }
180
+ function pt(e) {
181
+ var t = e.x, r = e.y, i = e.width, u = e.height, f = typeof DOMRectReadOnly < "u" ? DOMRectReadOnly : Object, a = Object.create(f.prototype);
182
+ return Fe(a, {
183
+ x: t,
184
+ y: r,
185
+ width: i,
186
+ height: u,
187
+ top: r,
188
+ right: t + i,
189
+ bottom: u + r,
190
+ left: t
191
+ }), a;
192
+ }
193
+ function ne(e, t, r, i) {
194
+ return { x: e, y: t, width: r, height: i };
195
+ }
196
+ var mt = (
197
+ /** @class */
198
+ function() {
199
+ function e(t) {
200
+ this.broadcastWidth = 0, this.broadcastHeight = 0, this.contentRect_ = ne(0, 0, 0, 0), this.target = t;
201
+ }
202
+ return e.prototype.isActive = function() {
203
+ var t = vt(this.target);
204
+ return this.contentRect_ = t, t.width !== this.broadcastWidth || t.height !== this.broadcastHeight;
205
+ }, e.prototype.broadcastRect = function() {
206
+ var t = this.contentRect_;
207
+ return this.broadcastWidth = t.width, this.broadcastHeight = t.height, t;
208
+ }, e;
209
+ }()
210
+ ), gt = (
211
+ /** @class */
212
+ function() {
213
+ function e(t, r) {
214
+ var i = pt(r);
215
+ Fe(this, { target: t, contentRect: i });
216
+ }
217
+ return e;
218
+ }()
219
+ ), bt = (
220
+ /** @class */
221
+ function() {
222
+ function e(t, r, i) {
223
+ if (this.activeObservations_ = [], this.observations_ = new Te(), typeof t != "function")
224
+ throw new TypeError("The callback provided as parameter 1 is not a function.");
225
+ this.callback_ = t, this.controller_ = r, this.callbackCtx_ = i;
226
+ }
227
+ return e.prototype.observe = function(t) {
228
+ if (!arguments.length)
229
+ throw new TypeError("1 argument required, but only 0 present.");
230
+ if (!(typeof Element > "u" || !(Element instanceof Object))) {
231
+ if (!(t instanceof L(t).Element))
232
+ throw new TypeError('parameter 1 is not of type "Element".');
233
+ var r = this.observations_;
234
+ r.has(t) || (r.set(t, new mt(t)), this.controller_.addObserver(this), this.controller_.refresh());
235
+ }
236
+ }, e.prototype.unobserve = function(t) {
237
+ if (!arguments.length)
238
+ throw new TypeError("1 argument required, but only 0 present.");
239
+ if (!(typeof Element > "u" || !(Element instanceof Object))) {
240
+ if (!(t instanceof L(t).Element))
241
+ throw new TypeError('parameter 1 is not of type "Element".');
242
+ var r = this.observations_;
243
+ r.has(t) && (r.delete(t), r.size || this.controller_.removeObserver(this));
244
+ }
245
+ }, e.prototype.disconnect = function() {
246
+ this.clearActive(), this.observations_.clear(), this.controller_.removeObserver(this);
247
+ }, e.prototype.gatherActive = function() {
248
+ var t = this;
249
+ this.clearActive(), this.observations_.forEach(function(r) {
250
+ r.isActive() && t.activeObservations_.push(r);
251
+ });
252
+ }, e.prototype.broadcastActive = function() {
253
+ if (this.hasActive()) {
254
+ var t = this.callbackCtx_, r = this.activeObservations_.map(function(i) {
255
+ return new gt(i.target, i.broadcastRect());
256
+ });
257
+ this.callback_.call(t, r, t), this.clearActive();
258
+ }
259
+ }, e.prototype.clearActive = function() {
260
+ this.activeObservations_.splice(0);
261
+ }, e.prototype.hasActive = function() {
262
+ return this.activeObservations_.length > 0;
263
+ }, e;
264
+ }()
265
+ ), Oe = typeof WeakMap < "u" ? /* @__PURE__ */ new WeakMap() : new Te(), Re = (
266
+ /** @class */
267
+ function() {
268
+ function e(t) {
269
+ if (!(this instanceof e))
270
+ throw new TypeError("Cannot call a class as a function.");
271
+ if (!arguments.length)
272
+ throw new TypeError("1 argument required, but only 0 present.");
273
+ var r = ut.getInstance(), i = new bt(t, r, this);
274
+ Oe.set(this, i);
275
+ }
276
+ return e;
277
+ }()
278
+ );
279
+ [
280
+ "observe",
281
+ "unobserve",
282
+ "disconnect"
283
+ ].forEach(function(e) {
284
+ Re.prototype[e] = function() {
285
+ var t;
286
+ return (t = Oe.get(this))[e].apply(t, arguments);
287
+ };
288
+ });
289
+ var yt = function() {
290
+ return typeof ee.ResizeObserver < "u" ? ee.ResizeObserver : Re;
291
+ }(), ge = {}, xt = {
292
+ get exports() {
293
+ return ge;
294
+ },
295
+ set exports(e) {
296
+ ge = e;
297
+ }
298
+ };
299
+ /*!
300
+ * screenfull
301
+ * v5.2.0 - 2021-11-03
302
+ * (c) Sindre Sorhus; MIT License
303
+ */
304
+ (function(e) {
305
+ (function() {
306
+ var t = typeof window < "u" && typeof window.document < "u" ? window.document : {}, r = e.exports, i = function() {
307
+ for (var a, s = [
308
+ [
309
+ "requestFullscreen",
310
+ "exitFullscreen",
311
+ "fullscreenElement",
312
+ "fullscreenEnabled",
313
+ "fullscreenchange",
314
+ "fullscreenerror"
315
+ ],
316
+ // New WebKit
317
+ [
318
+ "webkitRequestFullscreen",
319
+ "webkitExitFullscreen",
320
+ "webkitFullscreenElement",
321
+ "webkitFullscreenEnabled",
322
+ "webkitfullscreenchange",
323
+ "webkitfullscreenerror"
324
+ ],
325
+ // Old WebKit
326
+ [
327
+ "webkitRequestFullScreen",
328
+ "webkitCancelFullScreen",
329
+ "webkitCurrentFullScreenElement",
330
+ "webkitCancelFullScreen",
331
+ "webkitfullscreenchange",
332
+ "webkitfullscreenerror"
333
+ ],
334
+ [
335
+ "mozRequestFullScreen",
336
+ "mozCancelFullScreen",
337
+ "mozFullScreenElement",
338
+ "mozFullScreenEnabled",
339
+ "mozfullscreenchange",
340
+ "mozfullscreenerror"
341
+ ],
342
+ [
343
+ "msRequestFullscreen",
344
+ "msExitFullscreen",
345
+ "msFullscreenElement",
346
+ "msFullscreenEnabled",
347
+ "MSFullscreenChange",
348
+ "MSFullscreenError"
349
+ ]
350
+ ], l = 0, d = s.length, T = {}; l < d; l++)
351
+ if (a = s[l], a && a[1] in t) {
352
+ for (l = 0; l < a.length; l++)
353
+ T[s[0][l]] = a[l];
354
+ return T;
355
+ }
356
+ return !1;
357
+ }(), u = {
358
+ change: i.fullscreenchange,
359
+ error: i.fullscreenerror
360
+ }, f = {
361
+ request: function(a, s) {
362
+ return new Promise(function(l, d) {
363
+ var T = function() {
364
+ this.off("change", T), l();
365
+ }.bind(this);
366
+ this.on("change", T), a = a || t.documentElement;
367
+ var $ = a[i.requestFullscreen](s);
368
+ $ instanceof Promise && $.then(T).catch(d);
369
+ }.bind(this));
370
+ },
371
+ exit: function() {
372
+ return new Promise(function(a, s) {
373
+ if (!this.isFullscreen) {
374
+ a();
375
+ return;
376
+ }
377
+ var l = function() {
378
+ this.off("change", l), a();
379
+ }.bind(this);
380
+ this.on("change", l);
381
+ var d = t[i.exitFullscreen]();
382
+ d instanceof Promise && d.then(l).catch(s);
383
+ }.bind(this));
384
+ },
385
+ toggle: function(a, s) {
386
+ return this.isFullscreen ? this.exit() : this.request(a, s);
387
+ },
388
+ onchange: function(a) {
389
+ this.on("change", a);
390
+ },
391
+ onerror: function(a) {
392
+ this.on("error", a);
393
+ },
394
+ on: function(a, s) {
395
+ var l = u[a];
396
+ l && t.addEventListener(l, s, !1);
397
+ },
398
+ off: function(a, s) {
399
+ var l = u[a];
400
+ l && t.removeEventListener(l, s, !1);
401
+ },
402
+ raw: i
403
+ };
404
+ if (!i) {
405
+ r ? e.exports = { isEnabled: !1 } : window.screenfull = { isEnabled: !1 };
406
+ return;
407
+ }
408
+ Object.defineProperties(f, {
409
+ isFullscreen: {
410
+ get: function() {
411
+ return !!t[i.fullscreenElement];
412
+ }
413
+ },
414
+ element: {
415
+ enumerable: !0,
416
+ get: function() {
417
+ return t[i.fullscreenElement];
418
+ }
419
+ },
420
+ isEnabled: {
421
+ enumerable: !0,
422
+ get: function() {
423
+ return !!t[i.fullscreenEnabled];
424
+ }
425
+ }
426
+ }), r ? e.exports = f : window.screenfull = f;
427
+ })();
428
+ })(xt);
429
+ const P = ge;
430
+ function wt({
431
+ mainCarouselWrapperRef: e,
432
+ onFullScreenChange: t,
433
+ handleResize: r
434
+ }) {
435
+ const i = x(!1);
436
+ z(() => {
437
+ function l() {
438
+ document.fullscreenElement && (u(!0), t(!0), r && r()), document.fullscreenElement || (u(!1), t(!1), r && r());
439
+ }
440
+ if (P.isEnabled)
441
+ return P.on("change", l), () => {
442
+ P.isEnabled && P.off("change", l);
443
+ };
444
+ }, []);
445
+ function u(l) {
446
+ i.current = l;
447
+ }
448
+ function f() {
449
+ return i.current;
450
+ }
451
+ function a(l) {
452
+ P.isEnabled && P.request(l || e.current);
453
+ }
454
+ function s() {
455
+ P.isEnabled && P.exit();
456
+ }
457
+ return {
458
+ enterFullscreen: a,
459
+ exitFullscreen: s,
460
+ getIsFullscreen: f
461
+ };
462
+ }
463
+ function Rt({
464
+ items: e,
465
+ init: t = !0,
466
+ withThumbs: r,
467
+ thumbsSlideAxis: i = "x",
468
+ itemsPerSlide: u = 1,
469
+ slideType: f = "fixed",
470
+ gutter: a = 0,
471
+ withLoop: s = !1,
472
+ startEndGutter: l = 0,
473
+ carouselSlideAxis: d = "x",
474
+ disableGestures: T = !1,
475
+ draggingSlideTreshold: $,
476
+ slideWhenThresholdIsReached: ye = !1,
477
+ freeScroll: h,
478
+ enableFreeScrollDrag: Ce,
479
+ initialStartingPosition: re,
480
+ prepareThumbsData: ke,
481
+ initialActiveItem: O = 0,
482
+ animateWhenActiveItemChange: Pe = !0,
483
+ getControllerRef: ie
484
+ }) {
485
+ const R = u > e.length ? e.length : u, K = x(!1), S = x($ ?? 0), C = x("initial"), oe = x("initial"), ce = x("initial"), _ = x(O), m = x(O === 0), p = x(f === "fixed" && O === e.length - 1), g = x(null), E = x(null), se = x(!0), ue = x(0), ae = x(0), b = x(0), ze = x(s), We = x(f), Ne = x(h), D = x(!1), X = Ue(() => s ? [
486
+ ...e.map((n) => ({
487
+ ...n,
488
+ id: `prev-repeated-item-${n.id}`
489
+ })),
490
+ ...e,
491
+ ...e.map((n) => ({
492
+ ...n,
493
+ id: `next-repeated-item-${n.id}`
494
+ }))
495
+ ] : [...e], [e, s])(), [W, I] = Xe(
496
+ () => ({
497
+ val: 0,
498
+ pause: !t,
499
+ onChange: ({ value: n }) => {
500
+ h && g.current ? (d === "x" ? g.current.scrollLeft = Math.abs(n.val) : g.current.scrollTop = Math.abs(n.val), Z()) : E.current && (d === "x" ? E.current.style.transform = `translate3d(${n.val}px, 0px,0px)` : E.current.style.transform = `translate3d(0px,${n.val}px,0px)`);
501
+ }
502
+ }),
503
+ [h]
504
+ ), { emitEvent: J, useListenToCustomEvent: Q } = et(), { thumbsFragment: $e, handleScroll: De } = Se({
505
+ withThumbs: !!r,
506
+ thumbsSlideAxis: i,
507
+ prepareThumbsData: ke,
508
+ items: e,
509
+ renderThumbFnProps: {
510
+ getIsActiveItem: pe,
511
+ getIsPrevItem: ve,
512
+ useListenToCustomEvent: Q,
513
+ getIsNextItem: he
514
+ }
515
+ }), { enterFullscreen: xe, exitFullscreen: we, getIsFullscreen: _e } = wt({
516
+ mainCarouselWrapperRef: g,
517
+ handleResize: () => U(),
518
+ onFullScreenChange: (n) => {
519
+ J({
520
+ eventName: "onFullscreenChange",
521
+ isFullscreen: n
522
+ });
523
+ }
524
+ });
525
+ function je(n) {
526
+ return f === "fixed" && !h ? {
527
+ marginRight: `${n ? 0 : a}px`,
528
+ flex: `1 0 calc(100% / ${R} - ${a * (R - 1) / R}px)`
529
+ } : {
530
+ marginRight: `${n ? 0 : a}px`
531
+ };
532
+ }
533
+ function y() {
534
+ var c;
535
+ const n = (c = g.current) == null ? void 0 : c.querySelector(".use-spring-carousel-item");
536
+ if (!n)
537
+ throw Error("No carousel items available!");
538
+ return n.getBoundingClientRect()[d === "x" ? "width" : "height"] + a;
539
+ }
540
+ function j({ from: n, to: c, nextActiveItem: o, immediate: v = !1, slideMode: M }) {
541
+ oe.current = M, typeof o == "number" && (h || (_.current = o), J({
542
+ eventName: "onSlideStartChange",
543
+ slideActionType: C.current,
544
+ slideMode: oe.current,
545
+ nextItem: {
546
+ startReached: m.current,
547
+ endReached: p.current,
548
+ index: h ? -1 : _.current,
549
+ id: h ? "" : e[_.current].id
550
+ }
551
+ })), b.current = c, I.start({
552
+ immediate: v,
553
+ from: {
554
+ val: n
555
+ },
556
+ to: {
557
+ val: c
558
+ },
559
+ config: {
560
+ ...G.default,
561
+ velocity: W.val.velocity
562
+ },
563
+ onRest(H) {
564
+ !v && H.finished && J({
565
+ eventName: "onSlideChange",
566
+ slideActionType: C.current,
567
+ slideMode: oe.current,
568
+ currentItem: {
569
+ startReached: m.current,
570
+ endReached: p.current,
571
+ index: h ? -1 : _.current,
572
+ id: h ? "" : e[_.current].id
573
+ }
574
+ });
575
+ }
576
+ }), r && !v && De(_.current);
577
+ }
578
+ function w() {
579
+ var n;
580
+ return s ? y() * e.length : Math.round(
581
+ Number(
582
+ (n = E.current) == null ? void 0 : n[d === "x" ? "scrollWidth" : "scrollHeight"]
583
+ ) - E.current.getBoundingClientRect()[d === "x" ? "width" : "height"] - l * 2
584
+ );
585
+ }
586
+ function qe() {
587
+ const n = `calc(100% - ${l * 2}px)`;
588
+ return {
589
+ width: d === "x" ? n : "100%",
590
+ height: d === "y" ? n : "100%"
591
+ };
592
+ }
593
+ function le() {
594
+ var c;
595
+ const n = (c = E.current) == null ? void 0 : c.querySelector(".use-spring-carousel-item");
596
+ if (!n)
597
+ throw Error("No carousel items available!");
598
+ return n.getBoundingClientRect()[d === "x" ? "width" : "height"] + a;
599
+ }
600
+ function fe(n) {
601
+ const c = d === "x" ? "left" : "top", o = E.current;
602
+ o && (s ? (o.style.top = "0px", o.style.left = "0px", o.style[c] = `-${n - l}px`, m.current = !1, p.current = !1) : (o.style.left = "0px", o.style.top = "0px"));
603
+ }
604
+ function U(n = !1) {
605
+ if (E.current && n && (E.current.style.transform = "translate3d(0px, 0px,0px)", E.current.style.left = "0", E.current.style.top = "0"), f === "fixed" && fe(
606
+ re === "center" ? le() * e.length - y() * Math.round((R - 1) / 2) : re === "end" ? le() * e.length - y() * Math.round(R - 1) : le() * e.length
607
+ ), f === "fluid") {
608
+ if (p.current && w() !== Math.abs(b.current) && !s) {
609
+ const c = -w();
610
+ b.current = c, I.start({
611
+ immediate: !0,
612
+ val: b.current
613
+ });
614
+ return;
615
+ }
616
+ if (Math.abs(b.current) > 0 && w() !== Math.abs(b.current) && !s && !h && ce.current === "backward") {
617
+ const c = ue.current - w(), o = b.current + c;
618
+ return I.start({
619
+ immediate: !0,
620
+ val: o
621
+ }), () => {
622
+ b.current = o;
623
+ };
624
+ }
625
+ return;
626
+ }
627
+ if (!h && f === "fixed") {
628
+ const c = -(y() * _.current);
629
+ if (Math.abs(c) > w() && !s) {
630
+ const o = -w();
631
+ p.current = !0, b.current = o, I.start({
632
+ immediate: !0,
633
+ val: b.current
634
+ });
635
+ } else
636
+ b.current = c, I.start({
637
+ immediate: !0,
638
+ val: c
639
+ });
640
+ setTimeout(() => {
641
+ K.current = !1;
642
+ }, 0);
643
+ }
644
+ }
645
+ function k() {
646
+ return h && g.current ? g.current[d === "x" ? "scrollLeft" : "scrollTop"] : W.val.get();
647
+ }
648
+ function Y(n, c) {
649
+ if (h && n === "next") {
650
+ const o = b.current + y();
651
+ return o > w() ? w() : o;
652
+ }
653
+ if (h && n === "prev") {
654
+ const o = b.current - y();
655
+ return o < 0 ? 0 : o;
656
+ }
657
+ return n === "next" ? typeof c == "number" ? -(c * y()) : b.current - y() : typeof c == "number" ? -(c * y()) : b.current + y();
658
+ }
659
+ function q({ type: n, index: c, immediate: o }) {
660
+ if (!t || D.current || m.current && !s)
661
+ return;
662
+ p.current && (ce.current = "backward"), C.current = "prev", p.current = !1;
663
+ const v = typeof c == "number" ? c : _.current - 1;
664
+ if (h && Z(), !s) {
665
+ const M = h ? Y("prev", c) - y() / 3 < 0 : Y("prev", c) + y() / 3 > 0;
666
+ if (m.current)
667
+ return;
668
+ if (M) {
669
+ m.current = !0, p.current = !1, j({
670
+ slideMode: n,
671
+ from: k(),
672
+ to: 0,
673
+ nextActiveItem: 0,
674
+ immediate: o
675
+ });
676
+ return;
677
+ }
678
+ }
679
+ if (s && (m.current || v < 0)) {
680
+ m.current = !1, p.current = !0, j({
681
+ slideMode: n,
682
+ from: k() - y() * e.length,
683
+ to: -(y() * e.length) + y(),
684
+ nextActiveItem: e.length - 1,
685
+ immediate: o
686
+ });
687
+ return;
688
+ }
689
+ v === 0 && (m.current = !0), (v === e.length - 1 || v === -1) && (p.current = !0), j({
690
+ slideMode: n,
691
+ from: k(),
692
+ to: Y("prev", c),
693
+ nextActiveItem: v,
694
+ immediate: o
695
+ });
696
+ }
697
+ function V({ type: n, index: c, immediate: o }) {
698
+ if (!t || D.current || p.current && !s)
699
+ return;
700
+ m.current && (ce.current = "forward"), C.current = "next", m.current = !1;
701
+ const v = c || _.current + 1;
702
+ if (h && Z(), !s) {
703
+ const M = Math.abs(Y("next", c)) > w() - y() / 3;
704
+ if (p.current)
705
+ return;
706
+ if (M) {
707
+ m.current = !1, p.current = !0, j({
708
+ slideMode: n,
709
+ from: k(),
710
+ to: h ? w() : -w(),
711
+ nextActiveItem: v,
712
+ immediate: o
713
+ });
714
+ return;
715
+ }
716
+ }
717
+ if (s && (p.current || v > e.length - 1)) {
718
+ p.current = !1, m.current = !0, j({
719
+ slideMode: n,
720
+ from: k() + y() * e.length,
721
+ to: 0,
722
+ nextActiveItem: 0,
723
+ immediate: o
724
+ });
725
+ return;
726
+ }
727
+ v === 0 && (m.current = !0), v === e.length - 1 && (p.current = !0), j({
728
+ slideMode: n,
729
+ from: k(),
730
+ to: Y("next", c),
731
+ nextActiveItem: v,
732
+ immediate: o
733
+ });
734
+ }
735
+ function Ve() {
736
+ $ ? S.current = $ : S.current = Math.floor(y() / 2 / 2);
737
+ }
738
+ function Ee() {
739
+ !se.current && E.current && (ue.current = w(), ze.current = s, We.current = f, Ne.current = h, ae.current = window.innerWidth, b.current = 0, de({ id: 0, immediate: !0, shouldReset: !0 }), Ve(), U());
740
+ }
741
+ const Be = tt(
742
+ (n) => {
743
+ const c = n.dragging, o = n.offset[d === "x" ? 0 : 1], v = n.movement[d === "x" ? 0 : 1], M = n.direction[d === "x" ? 0 : 1], H = v > S.current, A = v < -S.current, Ke = w();
744
+ if (c) {
745
+ if (M > 0 ? C.current = "prev" : C.current = "next", J({
746
+ ...n,
747
+ eventName: "onDrag",
748
+ slideActionType: C.current
749
+ }), h) {
750
+ if (o > 0) {
751
+ I.start({
752
+ from: {
753
+ val: k()
754
+ },
755
+ to: {
756
+ val: 0
757
+ },
758
+ config: {
759
+ velocity: n.velocity,
760
+ friction: 50,
761
+ tension: 1e3
762
+ }
763
+ }), n.cancel();
764
+ return;
765
+ }
766
+ I.start({
767
+ from: {
768
+ val: k()
769
+ },
770
+ to: {
771
+ val: -o
772
+ },
773
+ config: {
774
+ velocity: n.velocity,
775
+ friction: 50,
776
+ tension: 1e3
777
+ }
778
+ });
779
+ return;
780
+ }
781
+ I.start({
782
+ val: o,
783
+ config: {
784
+ velocity: n.velocity,
785
+ friction: 50,
786
+ tension: 1e3
787
+ }
788
+ }), ye && A ? (V({ type: "drag" }), n.cancel()) : ye && H && (q({ type: "drag" }), n.cancel()), Ke - Math.abs(o) < -(y() * 2) && n.cancel();
789
+ return;
790
+ }
791
+ if (n.last && h && o > 0) {
792
+ I.start({
793
+ from: {
794
+ val: k()
795
+ },
796
+ to: {
797
+ val: 0
798
+ },
799
+ config: {
800
+ velocity: n.velocity,
801
+ friction: 50,
802
+ tension: 1e3
803
+ }
804
+ });
805
+ return;
806
+ }
807
+ n.last && !n.canceled && h && (C.current === "prev" && q({ type: "drag" }), C.current === "next" && V({ type: "drag" })), n.last && !n.canceled && !h && (A ? !s && p.current ? I.start({
808
+ val: -w(),
809
+ config: {
810
+ ...G.default,
811
+ velocity: n.velocity
812
+ }
813
+ }) : V({ type: "drag" }) : H ? !s && m.current ? I.start({
814
+ val: 0,
815
+ config: {
816
+ ...G.default,
817
+ velocity: n.velocity
818
+ }
819
+ }) : q({ type: "drag" }) : I.start({
820
+ val: b.current,
821
+ config: {
822
+ ...G.default,
823
+ velocity: n.velocity
824
+ }
825
+ })), n.last && n.canceled && I.start({
826
+ val: b.current,
827
+ config: {
828
+ ...G.default,
829
+ velocity: n.velocity
830
+ }
831
+ });
832
+ },
833
+ {
834
+ enabled: t && !T && !h || !!h && !!Ce,
835
+ axis: d,
836
+ from: () => h && g.current ? [
837
+ -g.current.scrollLeft,
838
+ -g.current.scrollTop
839
+ ] : d === "x" ? [W.val.get(), W.val.get()] : [W.val.get(), W.val.get()]
840
+ }
841
+ );
842
+ function He() {
843
+ return h ? d === "x" ? {
844
+ overflowX: "auto"
845
+ } : {
846
+ overflowY: "auto"
847
+ } : {};
848
+ }
849
+ function Z() {
850
+ g.current && (b.current = g.current[d === "x" ? "scrollLeft" : "scrollTop"], g.current[d === "x" ? "scrollLeft" : "scrollTop"] === 0 && (m.current = !0, p.current = !1), g.current[d === "x" ? "scrollLeft" : "scrollTop"] > 0 && g.current[d === "x" ? "scrollLeft" : "scrollTop"] < w() && (m.current = !1, p.current = !1), g.current[d === "x" ? "scrollLeft" : "scrollTop"] === w() && (m.current = !1, p.current = !0));
851
+ }
852
+ function Ae() {
853
+ return h ? {
854
+ onWheel() {
855
+ W.val.stop(), Z();
856
+ }
857
+ } : {};
858
+ }
859
+ function B(n, c) {
860
+ let o = 0;
861
+ if (typeof n == "string" ? o = e.findIndex((v) => v.id === n) : o = n, o < 0 || o >= e.length) {
862
+ if (c)
863
+ throw new Error(c);
864
+ console.error(`The item doesn't exist; check that the id provided - ${n} - is correct.`), o = -1;
865
+ }
866
+ return o;
867
+ }
868
+ function de({ id: n, immediate: c, shouldReset: o, type: v }) {
869
+ if (!t || D.current)
870
+ return;
871
+ m.current = !1, p.current = !1;
872
+ const M = B(
873
+ n,
874
+ "The item you want to slide to doesn't exist; check the provided id."
875
+ );
876
+ if (M === _.current && !o)
877
+ return;
878
+ const H = B(e[_.current].id), A = B(e[M].id);
879
+ A > H ? V({
880
+ type: v || o ? "initial" : "click",
881
+ index: A,
882
+ immediate: c
883
+ }) : q({
884
+ type: v || o ? "initial" : "click",
885
+ index: A,
886
+ immediate: c
887
+ });
888
+ }
889
+ function he(n) {
890
+ const c = B(n, "The item doesn't exist; check the provided id."), o = _.current;
891
+ return s && o === e.length - 1 ? c === 0 : c === o + 1;
892
+ }
893
+ function ve(n) {
894
+ const c = B(n, "The item doesn't exist; check the provided id."), o = _.current;
895
+ return s && o === 0 ? c === e.length - 1 : c === o - 1;
896
+ }
897
+ function pe(n) {
898
+ return B(n, "The item you want to check doesn't exist; check the provided id.") === _.current;
899
+ }
900
+ function Le() {
901
+ return T ? "unset" : d === "x" ? "pan-y" : "pan-x";
902
+ }
903
+ const F = h ? {
904
+ useListenToCustomEvent: Q,
905
+ enterFullscreen: xe,
906
+ exitFullscreen: we,
907
+ getIsFullscreen: _e,
908
+ slideToPrevItem: (n = !0) => {
909
+ q({
910
+ type: "click",
911
+ immediate: !n
912
+ });
913
+ },
914
+ slideToNextItem: (n = !0) => {
915
+ V({
916
+ type: "click",
917
+ immediate: !n
918
+ });
919
+ }
920
+ } : {
921
+ useListenToCustomEvent: Q,
922
+ enterFullscreen: xe,
923
+ exitFullscreen: we,
924
+ getIsFullscreen: _e,
925
+ slideToPrevItem: (n = !0) => {
926
+ q({
927
+ type: "click",
928
+ immediate: !n
929
+ });
930
+ },
931
+ slideToNextItem: (n = !0) => {
932
+ V({
933
+ type: "click",
934
+ immediate: !n
935
+ });
936
+ },
937
+ slideToItem: (n, c = !0) => {
938
+ de({ id: n, immediate: !c });
939
+ },
940
+ getIsNextItem: he,
941
+ getIsPrevItem: ve,
942
+ getIsActiveItem: pe
943
+ };
944
+ Je(() => {
945
+ E.current && t && (K.current = !0, Ee());
946
+ }, [t]), z(() => {
947
+ _.current !== O && de({
948
+ id: O,
949
+ immediate: !Pe
950
+ });
951
+ }, [O]), z(() => {
952
+ if (t) {
953
+ if (O > e.length - 1)
954
+ throw new Error(
955
+ `initialActiveItem (${O}) is greater than the total quantity available items (${e.length}).`
956
+ );
957
+ R > e.length && console.warn(
958
+ `itemsPerSlide (${R}) is greater than the total quantity available items (${e.length}). Fallback to ${e.length})`
959
+ );
960
+ }
961
+ }, [O, e.length, R, t]), z(() => {
962
+ ae.current = window.innerWidth;
963
+ }, []), z(() => {
964
+ t && (K.current = !0, Ee());
965
+ }, [re, R, l, a, t, s]), z(() => {
966
+ if (!t)
967
+ return;
968
+ function n() {
969
+ document.hidden ? D.current = !0 : D.current = !1;
970
+ }
971
+ return document.addEventListener("visibilitychange", n), () => {
972
+ document.removeEventListener("visibilitychange", n);
973
+ };
974
+ }, [t]), z(() => {
975
+ if (g.current) {
976
+ let n;
977
+ const c = new yt(() => {
978
+ if (se.current) {
979
+ se.current = !1;
980
+ return;
981
+ }
982
+ if (!D.current && !K.current) {
983
+ ae.current = window.innerWidth;
984
+ const o = U();
985
+ window.clearTimeout(n), n = setTimeout(() => {
986
+ ue.current = w(), typeof o == "function" && o();
987
+ }, 100);
988
+ }
989
+ });
990
+ return c.observe(g.current), () => {
991
+ c.disconnect();
992
+ };
993
+ }
994
+ }, [U, w]), z(() => {
995
+ ie && ie({
996
+ slideToNextItem: F.slideToNextItem,
997
+ slideToPrevItem: F.slideToPrevItem,
998
+ slideToItem: F == null ? void 0 : F.slideToItem
999
+ });
1000
+ }, [ie, F.slideToItem, F.slideToNextItem, F.slideToPrevItem]);
1001
+ const Ye = /* @__PURE__ */ N.jsx(be.Provider, { value: F, children: $e }), Ge = /* @__PURE__ */ N.jsx(be.Provider, { value: F, children: /* @__PURE__ */ N.jsx(
1002
+ "div",
1003
+ {
1004
+ className: "use-spring-carousel-main-wrapper",
1005
+ ref: g,
1006
+ ...Ae(),
1007
+ style: {
1008
+ display: "flex",
1009
+ position: "relative",
1010
+ width: "100%",
1011
+ height: "100%",
1012
+ ...He()
1013
+ },
1014
+ children: /* @__PURE__ */ N.jsxs(
1015
+ "div",
1016
+ {
1017
+ className: "use-spring-carousel-track-wrapper",
1018
+ ref: E,
1019
+ ...Be(),
1020
+ style: {
1021
+ position: "relative",
1022
+ display: "flex",
1023
+ flexDirection: d === "x" ? "row" : "column",
1024
+ touchAction: Le(),
1025
+ ...qe()
1026
+ },
1027
+ children: [
1028
+ (h || !s) && l ? /* @__PURE__ */ N.jsx(
1029
+ "div",
1030
+ {
1031
+ style: {
1032
+ flexShrink: 0,
1033
+ width: l
1034
+ }
1035
+ }
1036
+ ) : null,
1037
+ X.map((n, c) => /* @__PURE__ */ N.jsx(
1038
+ "div",
1039
+ {
1040
+ className: "use-spring-carousel-item",
1041
+ "data-testid": "use-spring-carousel-item-wrapper",
1042
+ style: {
1043
+ display: "flex",
1044
+ position: "relative",
1045
+ flex: "1",
1046
+ ...je(
1047
+ c === X.findIndex(
1048
+ (o) => o.id === X[X.length - 1].id
1049
+ )
1050
+ )
1051
+ },
1052
+ children: typeof n.renderItem == "function" ? n.renderItem({
1053
+ getIsActiveItem: pe,
1054
+ getIsNextItem: he,
1055
+ getIsPrevItem: ve,
1056
+ useListenToCustomEvent: Q
1057
+ }) : n.renderItem
1058
+ },
1059
+ `${n.id}-${c}`
1060
+ )),
1061
+ (h || !s) && l ? /* @__PURE__ */ N.jsx(
1062
+ "div",
1063
+ {
1064
+ style: {
1065
+ flexShrink: 0,
1066
+ width: l
1067
+ }
1068
+ }
1069
+ ) : null
1070
+ ]
1071
+ }
1072
+ )
1073
+ }
1074
+ ) });
1075
+ return { ...F, carouselFragment: Ge, thumbsFragment: Ye };
1076
+ }
1077
+ const be = Qe(void 0);
1078
+ function Ct() {
1079
+ const e = Ze(be);
1080
+ if (!e)
1081
+ throw new Error("useSpringCarouselContext must be used within the carousel.");
1082
+ return e;
1083
+ }
1084
+ export {
1085
+ Rt as useSpringCarousel,
1086
+ Ct as useSpringCarouselContext
1087
+ };