react-spring-carousel 3.0.0-beta-2.1.3 → 3.0.0-beta-2.1.4
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.es.js +61 -61
- package/dist/index.umd.js +2 -2
- package/package.json +1 -1
package/dist/index.es.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsxs as ee, jsx as q } from "react/jsx-runtime";
|
|
2
2
|
import { useSpringRef as re, useSpring as Mt } from "@react-spring/web";
|
|
3
|
-
import at, { useRef as _, useEffect as
|
|
3
|
+
import at, { useRef as _, useEffect as F, useState as xt, useCallback as ne, useMemo as ct } from "react";
|
|
4
4
|
function se(r, t, e) {
|
|
5
5
|
return Math.max(t, Math.min(r, e));
|
|
6
6
|
}
|
|
@@ -261,13 +261,13 @@ class we {
|
|
|
261
261
|
} else
|
|
262
262
|
d[0] = f[0] !== !1 ? a - f[0] : 0, d[1] = f[1] !== !1 ? u - f[1] : 0;
|
|
263
263
|
this.restrictToAxis && !e._blocked && this.restrictToAxis(d);
|
|
264
|
-
const
|
|
264
|
+
const x = e.offset, I = e._active && !e._blocked || e.active;
|
|
265
265
|
I && (e.first = e._active && !e.active, e.last = !e._active && e.active, e.active = s[this.ingKey] = e._active, t && (e.first && ("bounds" in n && (e._bounds = Z(n.bounds, e)), this.setup && this.setup()), e.movement = d, this.computeOffset()));
|
|
266
266
|
const [L, P] = e.offset, [[A, O], [D, V]] = e._bounds;
|
|
267
267
|
e.overflow = [L < A ? -1 : L > O ? 1 : 0, P < D ? -1 : P > V ? 1 : 0], e._movementBound[0] = e.overflow[0] ? e._movementBound[0] === !1 ? e._movement[0] : e._movementBound[0] : !1, e._movementBound[1] = e.overflow[1] ? e._movementBound[1] === !1 ? e._movement[1] : e._movementBound[1] : !1;
|
|
268
268
|
const B = e._active ? n.rubberband || [0, 0] : [0, 0];
|
|
269
|
-
if (e.offset = ie(e._bounds, e.offset, B), e.delta = E.sub(e.offset,
|
|
270
|
-
e.delta = E.sub(e.offset,
|
|
269
|
+
if (e.offset = ie(e._bounds, e.offset, B), e.delta = E.sub(e.offset, x), this.computeMovement(), I && (!e.last || o > _e)) {
|
|
270
|
+
e.delta = E.sub(e.offset, x);
|
|
271
271
|
const S = e.delta.map(Math.abs);
|
|
272
272
|
E.addTo(e.distance, S), e.direction = e.delta.map(Math.sign), e._direction = e._delta.map(Math.sign), !e.first && o > 0 && (e.velocity = [S[0] / o, S[1] / o], e.timeDelta = o);
|
|
273
273
|
}
|
|
@@ -284,14 +284,14 @@ class we {
|
|
|
284
284
|
this.eventStore.clean(), this.timeoutStore.clean();
|
|
285
285
|
}
|
|
286
286
|
}
|
|
287
|
-
function
|
|
287
|
+
function Te([r, t], e) {
|
|
288
288
|
const n = Math.abs(r), s = Math.abs(t);
|
|
289
289
|
if (n > s && n > e)
|
|
290
290
|
return "x";
|
|
291
291
|
if (s > n && s > e)
|
|
292
292
|
return "y";
|
|
293
293
|
}
|
|
294
|
-
class
|
|
294
|
+
class xe extends we {
|
|
295
295
|
constructor(...t) {
|
|
296
296
|
super(...t), C(this, "aliasKey", "xy");
|
|
297
297
|
}
|
|
@@ -311,7 +311,7 @@ class Te extends we {
|
|
|
311
311
|
const e = this.state, n = this.config;
|
|
312
312
|
if (!e.axis && t) {
|
|
313
313
|
const s = typeof n.axisThreshold == "object" ? n.axisThreshold[Vt(t)] : n.axisThreshold;
|
|
314
|
-
e.axis =
|
|
314
|
+
e.axis = Te(e._movement, s);
|
|
315
315
|
}
|
|
316
316
|
e._blocked = (n.lockDirection || !!n.axis) && !e.axis || !!n.axis && n.axis !== e.axis;
|
|
317
317
|
}
|
|
@@ -416,7 +416,7 @@ const Ie = 0, Y = y(y({}, dt), {}, {
|
|
|
416
416
|
ArrowUp: (r, t = 1) => [0, -1 * r * t],
|
|
417
417
|
ArrowDown: (r, t = 1) => [0, r * t]
|
|
418
418
|
};
|
|
419
|
-
class Ee extends
|
|
419
|
+
class Ee extends xe {
|
|
420
420
|
constructor(...t) {
|
|
421
421
|
super(...t), C(this, "ingKey", "dragging");
|
|
422
422
|
}
|
|
@@ -498,10 +498,10 @@ class Ee extends Te {
|
|
|
498
498
|
if (e.tap = o <= n.tapsThreshold && a <= n.tapsThreshold, e.tap && n.filterTaps)
|
|
499
499
|
e._force = !0;
|
|
500
500
|
else {
|
|
501
|
-
const [u, c] = e._delta, [h, f] = e._movement, [b, d] = n.swipe.velocity, [
|
|
501
|
+
const [u, c] = e._delta, [h, f] = e._movement, [b, d] = n.swipe.velocity, [x, I] = n.swipe.distance, L = n.swipe.duration;
|
|
502
502
|
if (e.elapsedTime < L) {
|
|
503
503
|
const P = Math.abs(u / e.timeDelta), A = Math.abs(c / e.timeDelta);
|
|
504
|
-
P > b && Math.abs(h) >
|
|
504
|
+
P > b && Math.abs(h) > x && (e.swipe[0] = Math.sign(u)), A > d && Math.abs(f) > I && (e.swipe[1] = Math.sign(c));
|
|
505
505
|
}
|
|
506
506
|
}
|
|
507
507
|
this.emit();
|
|
@@ -848,7 +848,7 @@ class zt {
|
|
|
848
848
|
this._listeners.forEach((t) => t()), this._listeners.clear();
|
|
849
849
|
}
|
|
850
850
|
}
|
|
851
|
-
class
|
|
851
|
+
class Ge {
|
|
852
852
|
constructor() {
|
|
853
853
|
C(this, "_timeouts", /* @__PURE__ */ new Map());
|
|
854
854
|
}
|
|
@@ -863,7 +863,7 @@ class Fe {
|
|
|
863
863
|
this._timeouts.forEach((t) => void window.clearTimeout(t)), this._timeouts.clear();
|
|
864
864
|
}
|
|
865
865
|
}
|
|
866
|
-
class
|
|
866
|
+
class Fe {
|
|
867
867
|
constructor(t) {
|
|
868
868
|
C(this, "gestures", /* @__PURE__ */ new Set()), C(this, "_targetEventStore", new zt(this)), C(this, "gestureEventStores", {}), C(this, "gestureTimeoutStores", {}), C(this, "handlers", {}), C(this, "config", {}), C(this, "pointerIds", /* @__PURE__ */ new Set()), C(this, "touchIds", /* @__PURE__ */ new Set()), C(this, "state", {
|
|
869
869
|
shared: {
|
|
@@ -930,11 +930,11 @@ class Ge {
|
|
|
930
930
|
}
|
|
931
931
|
}
|
|
932
932
|
}
|
|
933
|
-
function
|
|
934
|
-
r.gestures.add(t), r.gestureEventStores[t] = new zt(r, t), r.gestureTimeoutStores[t] = new
|
|
933
|
+
function G(r, t) {
|
|
934
|
+
r.gestures.add(t), r.gestureEventStores[t] = new zt(r, t), r.gestureTimeoutStores[t] = new Ge();
|
|
935
935
|
}
|
|
936
936
|
function We(r, t) {
|
|
937
|
-
t.drag &&
|
|
937
|
+
t.drag && G(r, "drag"), t.wheel && G(r, "wheel"), t.scroll && G(r, "scroll"), t.move && G(r, "move"), t.pinch && G(r, "pinch"), t.hover && G(r, "hover");
|
|
938
938
|
}
|
|
939
939
|
const Rt = (r, t, e) => (n, s, o, a = {}, u = !1) => {
|
|
940
940
|
var c, h;
|
|
@@ -943,7 +943,7 @@ const Rt = (r, t, e) => (n, s, o, a = {}, u = !1) => {
|
|
|
943
943
|
e && b && (d += "Passive"), r[d] = r[d] || [], r[d].push(o);
|
|
944
944
|
};
|
|
945
945
|
function Ye(r, t = {}, e, n) {
|
|
946
|
-
const s = at.useMemo(() => new
|
|
946
|
+
const s = at.useMemo(() => new Fe(r), []);
|
|
947
947
|
if (s.applyHandlers(r, n), s.applyConfig(t, e), at.useEffect(s.effect.bind(s)), at.useEffect(() => s.clean.bind(s), []), t.target === void 0)
|
|
948
948
|
return s.bind.bind(s);
|
|
949
949
|
}
|
|
@@ -966,14 +966,14 @@ function Xe(r) {
|
|
|
966
966
|
t === "next" && (c += 1), t === "prev" && (c = c === 0 ? s - 1 : c - 1), n !== void 0 && (c = n);
|
|
967
967
|
let d = 0;
|
|
968
968
|
t === "next" && (d = -(c * a), o && c === s && (c = 0, h = h + a * s, d = 0), !o && (Math.abs(d) >= u || c === s - 1) && (b = !0, d = -u)), t === "prev" && (d = -(c * a), c === s - 1 && (h = h - s * a), !o && d >= 0 && (f = !0, d = 0)), e === "resize" && (d = -(c * a), o || (c === 0 && (f = !0), (c === s - 1 || Math.abs(d) >= u) && (b = !0, Math.abs(d) >= u && u > 0 && (d = -u))));
|
|
969
|
-
const
|
|
969
|
+
const x = o ? c % s : c, I = o ? s + c % s : c;
|
|
970
970
|
return {
|
|
971
971
|
newActive: c,
|
|
972
972
|
fromValue: h,
|
|
973
973
|
toValue: d,
|
|
974
974
|
startReached: f,
|
|
975
975
|
endReached: b,
|
|
976
|
-
logicalIndex:
|
|
976
|
+
logicalIndex: x,
|
|
977
977
|
realTrackIndex: I
|
|
978
978
|
};
|
|
979
979
|
}
|
|
@@ -988,7 +988,7 @@ function qe() {
|
|
|
988
988
|
const t = _(null);
|
|
989
989
|
return t.current === null && (t.current = {
|
|
990
990
|
useListenToCustomEvent(e) {
|
|
991
|
-
|
|
991
|
+
F(() => {
|
|
992
992
|
const n = r.current;
|
|
993
993
|
return n.add(e), () => {
|
|
994
994
|
n.delete(e);
|
|
@@ -1015,9 +1015,9 @@ function rr({
|
|
|
1015
1015
|
slideType: f = "item",
|
|
1016
1016
|
initialActiveItem: b = 0,
|
|
1017
1017
|
renderWindow: d,
|
|
1018
|
-
renderPlaceholder:
|
|
1018
|
+
renderPlaceholder: x
|
|
1019
1019
|
}) {
|
|
1020
|
-
const [I, L] =
|
|
1020
|
+
const [I, L] = xt(!1), [, P] = xt(0), A = _(r), O = _(null), D = _(null), V = _(0), B = _(0), S = _(!e), R = _(!1), et = _(0), w = _(0), ht = _(t);
|
|
1021
1021
|
ht.current = t;
|
|
1022
1022
|
const pt = _(e);
|
|
1023
1023
|
pt.current = e;
|
|
@@ -1041,7 +1041,7 @@ function rr({
|
|
|
1041
1041
|
n
|
|
1042
1042
|
);
|
|
1043
1043
|
}
|
|
1044
|
-
}),
|
|
1044
|
+
}), Gt = e ? t.length * 3 : t.length, { useListenToCustomEvent: vt, emitEvent: K } = qe();
|
|
1045
1045
|
function yt(i) {
|
|
1046
1046
|
if (!i || i.length === 0) return null;
|
|
1047
1047
|
let l = null, m = -1 / 0;
|
|
@@ -1053,7 +1053,7 @@ function rr({
|
|
|
1053
1053
|
const { totalGutterCssVar: i } = _t();
|
|
1054
1054
|
return i;
|
|
1055
1055
|
}
|
|
1056
|
-
function
|
|
1056
|
+
function Ft() {
|
|
1057
1057
|
const i = yt(o);
|
|
1058
1058
|
return (i == null ? void 0 : i.itemsPerSlide) || 1;
|
|
1059
1059
|
}
|
|
@@ -1077,7 +1077,7 @@ function rr({
|
|
|
1077
1077
|
toIndex: m,
|
|
1078
1078
|
actionType: p
|
|
1079
1079
|
}) {
|
|
1080
|
-
var
|
|
1080
|
+
var T, g;
|
|
1081
1081
|
const k = !l;
|
|
1082
1082
|
S.current = !1, R.current = !1;
|
|
1083
1083
|
const v = Xe({
|
|
@@ -1098,7 +1098,7 @@ function rr({
|
|
|
1098
1098
|
sliceActionType: p,
|
|
1099
1099
|
slideDirection: i,
|
|
1100
1100
|
currentItem: {
|
|
1101
|
-
id: ((
|
|
1101
|
+
id: ((T = t.at(v.logicalIndex)) == null ? void 0 : T.id) ?? "",
|
|
1102
1102
|
index: v.logicalIndex,
|
|
1103
1103
|
trackIndex: v.realTrackIndex,
|
|
1104
1104
|
startReached: S.current,
|
|
@@ -1129,14 +1129,14 @@ function rr({
|
|
|
1129
1129
|
onRest({ finished: M }) {
|
|
1130
1130
|
var wt;
|
|
1131
1131
|
if (M) {
|
|
1132
|
-
const
|
|
1132
|
+
const Tt = e ? w.current % t.length : w.current, te = e ? t.length + w.current % t.length : w.current;
|
|
1133
1133
|
K({
|
|
1134
1134
|
eventName: "onSlideChangeComplete",
|
|
1135
1135
|
sliceActionType: p,
|
|
1136
1136
|
slideDirection: i,
|
|
1137
1137
|
currentItem: {
|
|
1138
|
-
index:
|
|
1139
|
-
id: ((wt = t.at(
|
|
1138
|
+
index: Tt,
|
|
1139
|
+
id: ((wt = t.at(Tt)) == null ? void 0 : wt.id) ?? "",
|
|
1140
1140
|
trackIndex: te,
|
|
1141
1141
|
startReached: S.current,
|
|
1142
1142
|
endReached: R.current
|
|
@@ -1162,10 +1162,10 @@ function rr({
|
|
|
1162
1162
|
totalStartEndGutterCssVar: ((i == null ? void 0 : i.startEndGutter) || 0) * 2
|
|
1163
1163
|
};
|
|
1164
1164
|
}
|
|
1165
|
-
|
|
1166
|
-
function i(
|
|
1167
|
-
const g =
|
|
1168
|
-
switch (
|
|
1165
|
+
F(() => {
|
|
1166
|
+
function i(T) {
|
|
1167
|
+
const g = Ft();
|
|
1168
|
+
switch (T) {
|
|
1169
1169
|
case "start":
|
|
1170
1170
|
return 0;
|
|
1171
1171
|
case "middle-start":
|
|
@@ -1182,15 +1182,15 @@ function rr({
|
|
|
1182
1182
|
}
|
|
1183
1183
|
function l() {
|
|
1184
1184
|
B.current = Wt(), et.current = B.current / 4;
|
|
1185
|
-
const { totalStartEndGutterCssVar:
|
|
1185
|
+
const { totalStartEndGutterCssVar: T } = _t();
|
|
1186
1186
|
let g = 0;
|
|
1187
|
-
e && (g = B.current * t.length), g -= B.current * i(u), g -=
|
|
1187
|
+
e && (g = B.current * t.length), g -= B.current * i(u), g -= T / 2, O.current.style.setProperty(
|
|
1188
1188
|
`--${n}-offset-modifier`,
|
|
1189
1189
|
`${-g}px`
|
|
1190
1190
|
);
|
|
1191
1191
|
}
|
|
1192
|
-
function m(
|
|
1193
|
-
if (O.current && (l(), L(!0),
|
|
1192
|
+
function m(T) {
|
|
1193
|
+
if (O.current && (l(), L(!0), T)) {
|
|
1194
1194
|
const g = mt(b), M = e ? t.length + g % t.length : g;
|
|
1195
1195
|
K({ eventName: "onInit", index: g, trackIndex: M });
|
|
1196
1196
|
}
|
|
@@ -1204,16 +1204,16 @@ function rr({
|
|
|
1204
1204
|
});
|
|
1205
1205
|
}
|
|
1206
1206
|
function k() {
|
|
1207
|
-
U.current
|
|
1207
|
+
U.current !== null && clearTimeout(U.current), U.current = window.setTimeout(() => {
|
|
1208
1208
|
U.current = null;
|
|
1209
|
-
const
|
|
1210
|
-
if (!
|
|
1211
|
-
const g =
|
|
1209
|
+
const T = O.current;
|
|
1210
|
+
if (!T) return;
|
|
1211
|
+
const g = T.getBoundingClientRect();
|
|
1212
1212
|
(g.width !== W.current.width || g.height !== W.current.height) && (W.current = {
|
|
1213
1213
|
width: g.width,
|
|
1214
1214
|
height: g.height
|
|
1215
1215
|
}, p());
|
|
1216
|
-
})
|
|
1216
|
+
}, 100);
|
|
1217
1217
|
}
|
|
1218
1218
|
function v() {
|
|
1219
1219
|
setTimeout(() => {
|
|
@@ -1230,15 +1230,15 @@ function rr({
|
|
|
1230
1230
|
height: g.height
|
|
1231
1231
|
};
|
|
1232
1232
|
}
|
|
1233
|
-
const
|
|
1234
|
-
return
|
|
1235
|
-
|
|
1233
|
+
const T = window.visualViewport ?? window;
|
|
1234
|
+
return T.addEventListener("resize", k), window.addEventListener("orientationchange", v), () => {
|
|
1235
|
+
T.removeEventListener("resize", k), window.removeEventListener(
|
|
1236
1236
|
"orientationchange",
|
|
1237
1237
|
v
|
|
1238
|
-
), U.current !== null && (
|
|
1238
|
+
), U.current !== null && (clearTimeout(U.current), U.current = null);
|
|
1239
1239
|
};
|
|
1240
1240
|
}
|
|
1241
|
-
}, [r, n, a, e]),
|
|
1241
|
+
}, [r, n, a, e]), F(() => {
|
|
1242
1242
|
const i = mt(b);
|
|
1243
1243
|
r && i !== w.current && z({
|
|
1244
1244
|
type: "next",
|
|
@@ -1261,7 +1261,7 @@ function rr({
|
|
|
1261
1261
|
j.current = null, l && K(l);
|
|
1262
1262
|
}));
|
|
1263
1263
|
}
|
|
1264
|
-
|
|
1264
|
+
F(
|
|
1265
1265
|
() => () => {
|
|
1266
1266
|
N.current !== null && (cancelAnimationFrame(N.current), N.current = null), j.current = null;
|
|
1267
1267
|
},
|
|
@@ -1271,7 +1271,7 @@ function rr({
|
|
|
1271
1271
|
(i) => {
|
|
1272
1272
|
if (!A.current)
|
|
1273
1273
|
return;
|
|
1274
|
-
const l = i.dragging, m = i.offset[a === "x" ? 0 : 1], p = i.movement[a === "x" ? 0 : 1], k = p > et.current, v = p < -et.current,
|
|
1274
|
+
const l = i.dragging, m = i.offset[a === "x" ? 0 : 1], p = i.movement[a === "x" ? 0 : 1], k = p > et.current, v = p < -et.current, T = i.velocity;
|
|
1275
1275
|
l && (Ht({
|
|
1276
1276
|
...i,
|
|
1277
1277
|
eventName: "onDrag",
|
|
@@ -1280,7 +1280,7 @@ function rr({
|
|
|
1280
1280
|
value: m,
|
|
1281
1281
|
immediate: !0,
|
|
1282
1282
|
config: {
|
|
1283
|
-
velocity:
|
|
1283
|
+
velocity: T
|
|
1284
1284
|
},
|
|
1285
1285
|
onChange({ value: g }) {
|
|
1286
1286
|
D.current.style.transform = J(
|
|
@@ -1298,7 +1298,7 @@ function rr({
|
|
|
1298
1298
|
}), i.cancel()) : (X.start({
|
|
1299
1299
|
value: V.current,
|
|
1300
1300
|
config: {
|
|
1301
|
-
velocity:
|
|
1301
|
+
velocity: T
|
|
1302
1302
|
},
|
|
1303
1303
|
onChange({ value: g }) {
|
|
1304
1304
|
D.current.style.transform = J(
|
|
@@ -1425,7 +1425,7 @@ function rr({
|
|
|
1425
1425
|
onScroll: () => {
|
|
1426
1426
|
S.current = !1, R.current = !1;
|
|
1427
1427
|
},
|
|
1428
|
-
children: Array.from({ length:
|
|
1428
|
+
children: Array.from({ length: Gt }, (i, l) => {
|
|
1429
1429
|
const m = e ? l % t.length : l, p = t[m], k = e && (l < t.length || l >= t.length * 2);
|
|
1430
1430
|
if (d !== void 0) {
|
|
1431
1431
|
const g = e ? t.length + w.current % t.length : w.current;
|
|
@@ -1438,12 +1438,12 @@ function rr({
|
|
|
1438
1438
|
"data-part-internal": `${n}-Item`,
|
|
1439
1439
|
"data-id": p.id,
|
|
1440
1440
|
"aria-hidden": "true",
|
|
1441
|
-
children:
|
|
1441
|
+
children: x == null ? void 0 : x({ item: p, index: l, isClonedItem: k })
|
|
1442
1442
|
},
|
|
1443
1443
|
`${p.id}-${l}`
|
|
1444
1444
|
);
|
|
1445
1445
|
}
|
|
1446
|
-
const v = Jt[m],
|
|
1446
|
+
const v = Jt[m], T = Qt[m];
|
|
1447
1447
|
return /* @__PURE__ */ q(
|
|
1448
1448
|
"div",
|
|
1449
1449
|
{
|
|
@@ -1457,7 +1457,7 @@ function rr({
|
|
|
1457
1457
|
isClonedItem: k,
|
|
1458
1458
|
isActiveItem: qt,
|
|
1459
1459
|
isNextItem: v,
|
|
1460
|
-
isPrevItem:
|
|
1460
|
+
isPrevItem: T
|
|
1461
1461
|
}) : p.renderItem
|
|
1462
1462
|
},
|
|
1463
1463
|
`${p.id}-${l}`
|
|
@@ -1533,13 +1533,13 @@ function nr({ container: r, onReach: t }) {
|
|
|
1533
1533
|
}
|
|
1534
1534
|
u === "prev" && c <= 0 && (e.current = "start", n.current = 0, c = 0, t && t("start")), o(c);
|
|
1535
1535
|
}
|
|
1536
|
-
return
|
|
1536
|
+
return F(() => {
|
|
1537
1537
|
function u() {
|
|
1538
1538
|
var O;
|
|
1539
|
-
const
|
|
1539
|
+
const x = lt(r.current), I = ((O = [...r.current.children].at(0)) == null ? void 0 : O.getBoundingClientRect().width) || 0, L = Array(r.current.childElementCount).fill(0).map((D, V) => ({
|
|
1540
1540
|
index: V,
|
|
1541
|
-
start:
|
|
1542
|
-
end:
|
|
1541
|
+
start: x * V,
|
|
1542
|
+
end: x * (V + 1)
|
|
1543
1543
|
})), P = r.current.scrollLeft + I, A = L.find(
|
|
1544
1544
|
(D) => P >= D.start && P < D.end
|
|
1545
1545
|
);
|
|
@@ -1548,8 +1548,8 @@ function nr({ container: r, onReach: t }) {
|
|
|
1548
1548
|
function c() {
|
|
1549
1549
|
s.stop();
|
|
1550
1550
|
}
|
|
1551
|
-
function h(
|
|
1552
|
-
const I =
|
|
1551
|
+
function h(x) {
|
|
1552
|
+
const I = x.target;
|
|
1553
1553
|
I.scrollLeft === 0 ? (n.current = 0, e.current = "start", t && t("start")) : I.scrollLeft >= Nt(I) ? (e.current = "end", t && t("end")) : e.current !== "idle" && (e.current = "idle", t && t("idle"));
|
|
1554
1554
|
}
|
|
1555
1555
|
let f, b = 0;
|
|
@@ -1564,7 +1564,7 @@ function nr({ container: r, onReach: t }) {
|
|
|
1564
1564
|
}), r.current.addEventListener("scroll", h), r.current.addEventListener("scroll", d), () => {
|
|
1565
1565
|
r.current && (r.current.removeEventListener("scroll", d), r.current.removeEventListener("scroll", h), r.current.removeEventListener("wheel", c));
|
|
1566
1566
|
};
|
|
1567
|
-
}, [r, t]),
|
|
1567
|
+
}, [r, t]), F(() => {
|
|
1568
1568
|
if (r.current) {
|
|
1569
1569
|
const u = new ResizeObserver(() => {
|
|
1570
1570
|
o(n.current * lt(r.current));
|
package/dist/index.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(P,M){typeof exports=="object"&&typeof module<"u"?M(exports,require("react/jsx-runtime"),require("@react-spring/web"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","@react-spring/web","react"],M):(P=typeof globalThis<"u"?globalThis:P||self,M(P["react-spring-carousel"]={},P["react/jsx-runtime"],P["@react-spring/web"],P.React))})(this,function(P,M,te,d){"use strict";function Ue(r,e,t){return Math.max(e,Math.min(r,t))}const T={toVector(r,e){return r===void 0&&(r=e),Array.isArray(r)?r:[r,r]},add(r,e){return[r[0]+e[0],r[1]+e[1]]},sub(r,e){return[r[0]-e[0],r[1]-e[1]]},addTo(r,e){r[0]+=e[0],r[1]+=e[1]},subTo(r,e){r[0]-=e[0],r[1]-=e[1]}};function de(r,e,t){return e===0||Math.abs(e)===1/0?Math.pow(r,t*5):r*e*t/(e+t*r)}function he(r,e,t,n=.15){return n===0?Ue(r,e,t):r<e?-de(e-r,t-e,n)+e:r>t?+de(r-t,t-e,n)+t:r}function Ke(r,[e,t],[n,s]){const[[o,a],[u,c]]=r;return[he(e,o,a,n),he(t,u,c,s)]}function ze(r,e){if(typeof r!="object"||r===null)return r;var t=r[Symbol.toPrimitive];if(t!==void 0){var n=t.call(r,e);if(typeof n!="object")return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return(e==="string"?String:Number)(r)}function Fe(r){var e=ze(r,"string");return typeof e=="symbol"?e:String(e)}function k(r,e,t){return e=Fe(e),e in r?Object.defineProperty(r,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):r[e]=t,r}function pe(r,e){var t=Object.keys(r);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(r);e&&(n=n.filter(function(s){return Object.getOwnPropertyDescriptor(r,s).enumerable})),t.push.apply(t,n)}return t}function y(r){for(var e=1;e<arguments.length;e++){var t=arguments[e]!=null?arguments[e]:{};e%2?pe(Object(t),!0).forEach(function(n){k(r,n,t[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(t)):pe(Object(t)).forEach(function(n){Object.defineProperty(r,n,Object.getOwnPropertyDescriptor(t,n))})}return r}const ge={pointer:{start:"down",change:"move",end:"up"},mouse:{start:"down",change:"move",end:"up"},touch:{start:"start",change:"move",end:"end"},gesture:{start:"start",change:"change",end:"end"}};function me(r){return r?r[0].toUpperCase()+r.slice(1):""}const Ge=["enter","leave"];function We(r=!1,e){return r&&!Ge.includes(e)}function Ye(r,e="",t=!1){const n=ge[r],s=n&&n[e]||e;return"on"+me(r)+me(s)+(We(t,s)?"Capture":"")}const He=["gotpointercapture","lostpointercapture"];function qe(r){let e=r.substring(2).toLowerCase();const t=!!~e.indexOf("passive");t&&(e=e.replace("passive",""));const n=He.includes(e)?"capturecapture":"capture",s=!!~e.indexOf(n);return s&&(e=e.replace("capture","")),{device:e,capture:s,passive:t}}function Xe(r,e=""){const t=ge[r],n=t&&t[e]||e;return r+n}function X(r){return"touches"in r}function ve(r){return X(r)?"touch":"pointerType"in r?r.pointerType:"mouse"}function Je(r){return Array.from(r.touches).filter(e=>{var t,n;return e.target===r.currentTarget||((t=r.currentTarget)===null||t===void 0||(n=t.contains)===null||n===void 0?void 0:n.call(t,e.target))})}function Qe(r){return r.type==="touchend"||r.type==="touchcancel"?r.changedTouches:r.targetTouches}function ye(r){return X(r)?Qe(r)[0]:r}function Ze(r){return Je(r).map(e=>e.identifier)}function re(r){const e=ye(r);return X(r)?e.identifier:e.pointerId}function be(r){const e=ye(r);return[e.clientX,e.clientY]}function et(r){const e={};if("buttons"in r&&(e.buttons=r.buttons),"shiftKey"in r){const{shiftKey:t,altKey:n,metaKey:s,ctrlKey:o}=r;Object.assign(e,{shiftKey:t,altKey:n,metaKey:s,ctrlKey:o})}return e}function J(r,...e){return typeof r=="function"?r(...e):r}function tt(){}function rt(...r){return r.length===0?tt:r.length===1?r[0]:function(){let e;for(const t of r)e=t.apply(this,arguments)||e;return e}}function _e(r,e){return Object.assign({},e,r||{})}const nt=32;class st{constructor(e,t,n){this.ctrl=e,this.args=t,this.key=n,this.state||(this.state={},this.computeValues([0,0]),this.computeInitial(),this.init&&this.init(),this.reset())}get state(){return this.ctrl.state[this.key]}set state(e){this.ctrl.state[this.key]=e}get shared(){return this.ctrl.state.shared}get eventStore(){return this.ctrl.gestureEventStores[this.key]}get timeoutStore(){return this.ctrl.gestureTimeoutStores[this.key]}get config(){return this.ctrl.config[this.key]}get sharedConfig(){return this.ctrl.config.shared}get handler(){return this.ctrl.handlers[this.key]}reset(){const{state:e,shared:t,ingKey:n,args:s}=this;t[n]=e._active=e.active=e._blocked=e._force=!1,e._step=[!1,!1],e.intentional=!1,e._movement=[0,0],e._distance=[0,0],e._direction=[0,0],e._delta=[0,0],e._bounds=[[-1/0,1/0],[-1/0,1/0]],e.args=s,e.axis=void 0,e.memo=void 0,e.elapsedTime=e.timeDelta=0,e.direction=[0,0],e.distance=[0,0],e.overflow=[0,0],e._movementBound=[!1,!1],e.velocity=[0,0],e.movement=[0,0],e.delta=[0,0],e.timeStamp=0}start(e){const t=this.state,n=this.config;t._active||(this.reset(),this.computeInitial(),t._active=!0,t.target=e.target,t.currentTarget=e.currentTarget,t.lastOffset=n.from?J(n.from,t):t.offset,t.offset=t.lastOffset,t.startTime=t.timeStamp=e.timeStamp)}computeValues(e){const t=this.state;t._values=e,t.values=this.config.transform(e)}computeInitial(){const e=this.state;e._initial=e._values,e.initial=e.values}compute(e){const{state:t,config:n,shared:s}=this;t.args=this.args;let o=0;if(e&&(t.event=e,n.preventDefault&&e.cancelable&&t.event.preventDefault(),t.type=e.type,s.touches=this.ctrl.pointerIds.size||this.ctrl.touchIds.size,s.locked=!!document.pointerLockElement,Object.assign(s,et(e)),s.down=s.pressed=s.buttons%2===1||s.touches>0,o=e.timeStamp-t.timeStamp,t.timeStamp=e.timeStamp,t.elapsedTime=t.timeStamp-t.startTime),t._active){const S=t._delta.map(Math.abs);T.addTo(t._distance,S)}this.axisIntent&&this.axisIntent(e);const[a,u]=t._movement,[c,p]=n.threshold,{_step:f,values:_}=t;if(n.hasCustomTransform?(f[0]===!1&&(f[0]=Math.abs(a)>=c&&_[0]),f[1]===!1&&(f[1]=Math.abs(u)>=p&&_[1])):(f[0]===!1&&(f[0]=Math.abs(a)>=c&&Math.sign(a)*c),f[1]===!1&&(f[1]=Math.abs(u)>=p&&Math.sign(u)*p)),t.intentional=f[0]!==!1||f[1]!==!1,!t.intentional)return;const h=[0,0];if(n.hasCustomTransform){const[S,L]=_;h[0]=f[0]!==!1?S-f[0]:0,h[1]=f[1]!==!1?L-f[1]:0}else h[0]=f[0]!==!1?a-f[0]:0,h[1]=f[1]!==!1?u-f[1]:0;this.restrictToAxis&&!t._blocked&&this.restrictToAxis(h);const E=t.offset,I=t._active&&!t._blocked||t.active;I&&(t.first=t._active&&!t.active,t.last=!t._active&&t.active,t.active=s[this.ingKey]=t._active,e&&(t.first&&("bounds"in n&&(t._bounds=J(n.bounds,t)),this.setup&&this.setup()),t.movement=h,this.computeOffset()));const[j,N]=t.offset,[[$,O],[D,B]]=t._bounds;t.overflow=[j<$?-1:j>O?1:0,N<D?-1:N>B?1:0],t._movementBound[0]=t.overflow[0]?t._movementBound[0]===!1?t._movement[0]:t._movementBound[0]:!1,t._movementBound[1]=t.overflow[1]?t._movementBound[1]===!1?t._movement[1]:t._movementBound[1]:!1;const U=t._active?n.rubberband||[0,0]:[0,0];if(t.offset=Ke(t._bounds,t.offset,U),t.delta=T.sub(t.offset,E),this.computeMovement(),I&&(!t.last||o>nt)){t.delta=T.sub(t.offset,E);const S=t.delta.map(Math.abs);T.addTo(t.distance,S),t.direction=t.delta.map(Math.sign),t._direction=t._delta.map(Math.sign),!t.first&&o>0&&(t.velocity=[S[0]/o,S[1]/o],t.timeDelta=o)}}emit(){const e=this.state,t=this.shared,n=this.config;if(e._active||this.clean(),(e._blocked||!e.intentional)&&!e._force&&!n.triggerAllEvents)return;const s=this.handler(y(y(y({},t),e),{},{[this.aliasKey]:e.values}));s!==void 0&&(e.memo=s)}clean(){this.eventStore.clean(),this.timeoutStore.clean()}}function it([r,e],t){const n=Math.abs(r),s=Math.abs(e);if(n>s&&n>t)return"x";if(s>n&&s>t)return"y"}class ot extends st{constructor(...e){super(...e),k(this,"aliasKey","xy")}reset(){super.reset(),this.state.axis=void 0}init(){this.state.offset=[0,0],this.state.lastOffset=[0,0]}computeOffset(){this.state.offset=T.add(this.state.lastOffset,this.state.movement)}computeMovement(){this.state.movement=T.sub(this.state.offset,this.state.lastOffset)}axisIntent(e){const t=this.state,n=this.config;if(!t.axis&&e){const s=typeof n.axisThreshold=="object"?n.axisThreshold[ve(e)]:n.axisThreshold;t.axis=it(t._movement,s)}t._blocked=(n.lockDirection||!!n.axis)&&!t.axis||!!n.axis&&n.axis!==t.axis}restrictToAxis(e){if(this.config.axis||this.config.lockDirection)switch(this.state.axis){case"x":e[1]=0;break;case"y":e[0]=0;break}}}const we=r=>r,xe=.15,ne={enabled(r=!0){return r},eventOptions(r,e,t){return y(y({},t.shared.eventOptions),r)},preventDefault(r=!1){return r},triggerAllEvents(r=!1){return r},rubberband(r=0){switch(r){case!0:return[xe,xe];case!1:return[0,0];default:return T.toVector(r)}},from(r){if(typeof r=="function")return r;if(r!=null)return T.toVector(r)},transform(r,e,t){const n=r||t.shared.transform;if(this.hasCustomTransform=!!n,process.env.NODE_ENV==="development"){const s=n||we;return o=>{const a=s(o);return(!isFinite(a[0])||!isFinite(a[1]))&&console.warn(`[@use-gesture]: config.transform() must produce a valid result, but it was: [${a[0]},${[1]}]`),a}}return n||we},threshold(r){return T.toVector(r,0)}};process.env.NODE_ENV==="development"&&Object.assign(ne,{domTarget(r){if(r!==void 0)throw Error("[@use-gesture]: `domTarget` option has been renamed to `target`.");return NaN},lockDirection(r){if(r!==void 0)throw Error("[@use-gesture]: `lockDirection` option has been merged with `axis`. Use it as in `{ axis: 'lock' }`");return NaN},initial(r){if(r!==void 0)throw Error("[@use-gesture]: `initial` option has been renamed to `from`.");return NaN}});const at=0,Y=y(y({},ne),{},{axis(r,e,{axis:t}){if(this.lockDirection=t==="lock",!this.lockDirection)return t},axisThreshold(r=at){return r},bounds(r={}){if(typeof r=="function")return o=>Y.bounds(r(o));if("current"in r)return()=>r.current;if(typeof HTMLElement=="function"&&r instanceof HTMLElement)return r;const{left:e=-1/0,right:t=1/0,top:n=-1/0,bottom:s=1/0}=r;return[[e,t],[n,s]]}}),Te={ArrowRight:(r,e=1)=>[r*e,0],ArrowLeft:(r,e=1)=>[-1*r*e,0],ArrowUp:(r,e=1)=>[0,-1*r*e],ArrowDown:(r,e=1)=>[0,r*e]};class ct extends ot{constructor(...e){super(...e),k(this,"ingKey","dragging")}reset(){super.reset();const e=this.state;e._pointerId=void 0,e._pointerActive=!1,e._keyboardActive=!1,e._preventScroll=!1,e._delayed=!1,e.swipe=[0,0],e.tap=!1,e.canceled=!1,e.cancel=this.cancel.bind(this)}setup(){const e=this.state;if(e._bounds instanceof HTMLElement){const t=e._bounds.getBoundingClientRect(),n=e.currentTarget.getBoundingClientRect(),s={left:t.left-n.left+e.offset[0],right:t.right-n.right+e.offset[0],top:t.top-n.top+e.offset[1],bottom:t.bottom-n.bottom+e.offset[1]};e._bounds=Y.bounds(s)}}cancel(){const e=this.state;e.canceled||(e.canceled=!0,e._active=!1,setTimeout(()=>{this.compute(),this.emit()},0))}setActive(){this.state._active=this.state._pointerActive||this.state._keyboardActive}clean(){this.pointerClean(),this.state._pointerActive=!1,this.state._keyboardActive=!1,super.clean()}pointerDown(e){const t=this.config,n=this.state;if(e.buttons!=null&&(Array.isArray(t.pointerButtons)?!t.pointerButtons.includes(e.buttons):t.pointerButtons!==-1&&t.pointerButtons!==e.buttons))return;const s=this.ctrl.setEventIds(e);t.pointerCapture&&e.target.setPointerCapture(e.pointerId),!(s&&s.size>1&&n._pointerActive)&&(this.start(e),this.setupPointer(e),n._pointerId=re(e),n._pointerActive=!0,this.computeValues(be(e)),this.computeInitial(),t.preventScrollAxis&&ve(e)!=="mouse"?(n._active=!1,this.setupScrollPrevention(e)):t.delay>0?(this.setupDelayTrigger(e),t.triggerAllEvents&&(this.compute(e),this.emit())):this.startPointerDrag(e))}startPointerDrag(e){const t=this.state;t._active=!0,t._preventScroll=!0,t._delayed=!1,this.compute(e),this.emit()}pointerMove(e){const t=this.state,n=this.config;if(!t._pointerActive)return;const s=re(e);if(t._pointerId!==void 0&&s!==t._pointerId)return;const o=be(e);if(document.pointerLockElement===e.target?t._delta=[e.movementX,e.movementY]:(t._delta=T.sub(o,t._values),this.computeValues(o)),T.addTo(t._movement,t._delta),this.compute(e),t._delayed&&t.intentional){this.timeoutStore.remove("dragDelay"),t.active=!1,this.startPointerDrag(e);return}if(n.preventScrollAxis&&!t._preventScroll)if(t.axis)if(t.axis===n.preventScrollAxis||n.preventScrollAxis==="xy"){t._active=!1,this.clean();return}else{this.timeoutStore.remove("startPointerDrag"),this.startPointerDrag(e);return}else return;this.emit()}pointerUp(e){this.ctrl.setEventIds(e);try{this.config.pointerCapture&&e.target.hasPointerCapture(e.pointerId)&&e.target.releasePointerCapture(e.pointerId)}catch{process.env.NODE_ENV==="development"&&console.warn("[@use-gesture]: If you see this message, it's likely that you're using an outdated version of `@react-three/fiber`. \n\nPlease upgrade to the latest version.")}const t=this.state,n=this.config;if(!t._active||!t._pointerActive)return;const s=re(e);if(t._pointerId!==void 0&&s!==t._pointerId)return;this.state._pointerActive=!1,this.setActive(),this.compute(e);const[o,a]=t._distance;if(t.tap=o<=n.tapsThreshold&&a<=n.tapsThreshold,t.tap&&n.filterTaps)t._force=!0;else{const[u,c]=t._delta,[p,f]=t._movement,[_,h]=n.swipe.velocity,[E,I]=n.swipe.distance,j=n.swipe.duration;if(t.elapsedTime<j){const N=Math.abs(u/t.timeDelta),$=Math.abs(c/t.timeDelta);N>_&&Math.abs(p)>E&&(t.swipe[0]=Math.sign(u)),$>h&&Math.abs(f)>I&&(t.swipe[1]=Math.sign(c))}}this.emit()}pointerClick(e){!this.state.tap&&e.detail>0&&(e.preventDefault(),e.stopPropagation())}setupPointer(e){const t=this.config,n=t.device;if(process.env.NODE_ENV==="development")try{if(n==="pointer"&&t.preventScrollDelay===void 0){const s="uv"in e?e.sourceEvent.currentTarget:e.currentTarget;window.getComputedStyle(s).touchAction==="auto"&&console.warn("[@use-gesture]: The drag target has its `touch-action` style property set to `auto`. It is recommended to add `touch-action: 'none'` so that the drag gesture behaves correctly on touch-enabled devices. For more information read this: https://use-gesture.netlify.app/docs/extras/#touch-action.\n\nThis message will only show in development mode. It won't appear in production. If this is intended, you can ignore it.",s)}}catch{}t.pointerLock&&e.currentTarget.requestPointerLock(),t.pointerCapture||(this.eventStore.add(this.sharedConfig.window,n,"change",this.pointerMove.bind(this)),this.eventStore.add(this.sharedConfig.window,n,"end",this.pointerUp.bind(this)),this.eventStore.add(this.sharedConfig.window,n,"cancel",this.pointerUp.bind(this)))}pointerClean(){this.config.pointerLock&&document.pointerLockElement===this.state.currentTarget&&document.exitPointerLock()}preventScroll(e){this.state._preventScroll&&e.cancelable&&e.preventDefault()}setupScrollPrevention(e){this.state._preventScroll=!1,ut(e);const t=this.eventStore.add(this.sharedConfig.window,"touch","change",this.preventScroll.bind(this),{passive:!1});this.eventStore.add(this.sharedConfig.window,"touch","end",t),this.eventStore.add(this.sharedConfig.window,"touch","cancel",t),this.timeoutStore.add("startPointerDrag",this.startPointerDrag.bind(this),this.config.preventScrollDelay,e)}setupDelayTrigger(e){this.state._delayed=!0,this.timeoutStore.add("dragDelay",()=>{this.state._step=[0,0],this.startPointerDrag(e)},this.config.delay)}keyDown(e){const t=Te[e.key];if(t){const n=this.state,s=e.shiftKey?10:e.altKey?.1:1;this.start(e),n._delta=t(this.config.keyboardDisplacement,s),n._keyboardActive=!0,T.addTo(n._movement,n._delta),this.compute(e),this.emit()}}keyUp(e){e.key in Te&&(this.state._keyboardActive=!1,this.setActive(),this.compute(e),this.emit())}bind(e){const t=this.config.device;e(t,"start",this.pointerDown.bind(this)),this.config.pointerCapture&&(e(t,"change",this.pointerMove.bind(this)),e(t,"end",this.pointerUp.bind(this)),e(t,"cancel",this.pointerUp.bind(this)),e("lostPointerCapture","",this.pointerUp.bind(this))),this.config.keys&&(e("key","down",this.keyDown.bind(this)),e("key","up",this.keyUp.bind(this))),this.config.filterTaps&&e("click","",this.pointerClick.bind(this),{capture:!0,passive:!1})}}function ut(r){"persist"in r&&typeof r.persist=="function"&&r.persist()}const H=typeof window<"u"&&window.document&&window.document.createElement;function Ee(){return H&&"ontouchstart"in window}function lt(){return Ee()||H&&window.navigator.maxTouchPoints>1}function ft(){return H&&"onpointerdown"in window}function dt(){return H&&"exitPointerLock"in window.document}function ht(){try{return"constructor"in GestureEvent}catch{return!1}}const A={isBrowser:H,gesture:ht(),touch:Ee(),touchscreen:lt(),pointer:ft(),pointerLock:dt()},pt=250,gt=180,mt=.5,vt=50,yt=250,bt=10,Ie={mouse:0,touch:0,pen:8},Se=y(y({},Y),{},{device(r,e,{pointer:{touch:t=!1,lock:n=!1,mouse:s=!1}={}}){return this.pointerLock=n&&A.pointerLock,A.touch&&t?"touch":this.pointerLock?"mouse":A.pointer&&!s?"pointer":A.touch?"touch":"mouse"},preventScrollAxis(r,e,{preventScroll:t}){if(this.preventScrollDelay=typeof t=="number"?t:t||t===void 0&&r?pt:void 0,!(!A.touchscreen||t===!1))return r||(t!==void 0?"y":void 0)},pointerCapture(r,e,{pointer:{capture:t=!0,buttons:n=1,keys:s=!0}={}}){return this.pointerButtons=n,this.keys=s,!this.pointerLock&&this.device==="pointer"&&t},threshold(r,e,{filterTaps:t=!1,tapsThreshold:n=3,axis:s=void 0}){const o=T.toVector(r,t?n:s?1:0);return this.filterTaps=t,this.tapsThreshold=n,o},swipe({velocity:r=mt,distance:e=vt,duration:t=yt}={}){return{velocity:this.transform(T.toVector(r)),distance:this.transform(T.toVector(e)),duration:t}},delay(r=0){switch(r){case!0:return gt;case!1:return 0;default:return r}},axisThreshold(r){return r?y(y({},Ie),r):Ie},keyboardDisplacement(r=bt){return r}});process.env.NODE_ENV==="development"&&Object.assign(Se,{useTouch(r){if(r!==void 0)throw Error("[@use-gesture]: `useTouch` option has been renamed to `pointer.touch`. Use it as in `{ pointer: { touch: true } }`.");return NaN},experimental_preventWindowScrollY(r){if(r!==void 0)throw Error("[@use-gesture]: `experimental_preventWindowScrollY` option has been renamed to `preventScroll`.");return NaN},swipeVelocity(r){if(r!==void 0)throw Error("[@use-gesture]: `swipeVelocity` option has been renamed to `swipe.velocity`. Use it as in `{ swipe: { velocity: 0.5 } }`.");return NaN},swipeDistance(r){if(r!==void 0)throw Error("[@use-gesture]: `swipeDistance` option has been renamed to `swipe.distance`. Use it as in `{ swipe: { distance: 50 } }`.");return NaN},swipeDuration(r){if(r!==void 0)throw Error("[@use-gesture]: `swipeDuration` option has been renamed to `swipe.duration`. Use it as in `{ swipe: { duration: 250 } }`.");return NaN}}),y(y({},ne),{},{device(r,e,{shared:t,pointer:{touch:n=!1}={}}){if(t.target&&!A.touch&&A.gesture)return"gesture";if(A.touch&&n)return"touch";if(A.touchscreen){if(A.pointer)return"pointer";if(A.touch)return"touch"}},bounds(r,e,{scaleBounds:t={},angleBounds:n={}}){const s=a=>{const u=_e(J(t,a),{min:-1/0,max:1/0});return[u.min,u.max]},o=a=>{const u=_e(J(n,a),{min:-1/0,max:1/0});return[u.min,u.max]};return typeof t!="function"&&typeof n!="function"?[s(),o()]:a=>[s(a),o(a)]},threshold(r,e,t){return this.lockDirection=t.axis==="lock",T.toVector(r,this.lockDirection?[.1,3]:0)},modifierKey(r){return r===void 0?"ctrlKey":r},pinchOnWheel(r=!0){return r}}),y(y({},Y),{},{mouseOnly:(r=!0)=>r}),y(y({},Y),{},{mouseOnly:(r=!0)=>r});const ke=new Map,se=new Map;function _t(r){ke.set(r.key,r.engine),se.set(r.key,r.resolver)}const wt={key:"drag",engine:ct,resolver:Se};function xt(r,e){if(r==null)return{};var t={},n=Object.keys(r),s,o;for(o=0;o<n.length;o++)s=n[o],!(e.indexOf(s)>=0)&&(t[s]=r[s]);return t}function Tt(r,e){if(r==null)return{};var t=xt(r,e),n,s;if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(r);for(s=0;s<o.length;s++)n=o[s],!(e.indexOf(n)>=0)&&Object.prototype.propertyIsEnumerable.call(r,n)&&(t[n]=r[n])}return t}const Et={target(r){if(r)return()=>"current"in r?r.current:r},enabled(r=!0){return r},window(r=A.isBrowser?window:void 0){return r},eventOptions({passive:r=!0,capture:e=!1}={}){return{passive:r,capture:e}},transform(r){return r}},It=["target","eventOptions","window","enabled","transform"];function Q(r={},e){const t={};for(const[n,s]of Object.entries(e))switch(typeof s){case"function":if(process.env.NODE_ENV==="development"){const o=s.call(t,r[n],n,r);Number.isNaN(o)||(t[n]=o)}else t[n]=s.call(t,r[n],n,r);break;case"object":t[n]=Q(r[n],s);break;case"boolean":s&&(t[n]=r[n]);break}return t}function St(r,e,t={}){const n=r,{target:s,eventOptions:o,window:a,enabled:u,transform:c}=n,p=Tt(n,It);if(t.shared=Q({target:s,eventOptions:o,window:a,enabled:u,transform:c},Et),e){const f=se.get(e);t[e]=Q(y({shared:t.shared},p),f)}else for(const f in p){const _=se.get(f);if(_)t[f]=Q(y({shared:t.shared},p[f]),_);else if(process.env.NODE_ENV==="development"&&!["drag","pinch","scroll","wheel","move","hover"].includes(f)){if(f==="domTarget")throw Error("[@use-gesture]: `domTarget` option has been renamed to `target`.");console.warn(`[@use-gesture]: Unknown config key \`${f}\` was used. Please read the documentation for further information.`)}}return t}class Ce{constructor(e,t){k(this,"_listeners",new Set),this._ctrl=e,this._gestureKey=t}add(e,t,n,s,o){const a=this._listeners,u=Xe(t,n),c=this._gestureKey?this._ctrl.config[this._gestureKey].eventOptions:{},p=y(y({},c),o);e.addEventListener(u,s,p);const f=()=>{e.removeEventListener(u,s,p),a.delete(f)};return a.add(f),f}clean(){this._listeners.forEach(e=>e()),this._listeners.clear()}}class kt{constructor(){k(this,"_timeouts",new Map)}add(e,t,n=140,...s){this.remove(e),this._timeouts.set(e,window.setTimeout(t,n,...s))}remove(e){const t=this._timeouts.get(e);t&&window.clearTimeout(t)}clean(){this._timeouts.forEach(e=>void window.clearTimeout(e)),this._timeouts.clear()}}class Ct{constructor(e){k(this,"gestures",new Set),k(this,"_targetEventStore",new Ce(this)),k(this,"gestureEventStores",{}),k(this,"gestureTimeoutStores",{}),k(this,"handlers",{}),k(this,"config",{}),k(this,"pointerIds",new Set),k(this,"touchIds",new Set),k(this,"state",{shared:{shiftKey:!1,metaKey:!1,ctrlKey:!1,altKey:!1}}),Dt(this,e)}setEventIds(e){if(X(e))return this.touchIds=new Set(Ze(e)),this.touchIds;if("pointerId"in e)return e.type==="pointerup"||e.type==="pointercancel"?this.pointerIds.delete(e.pointerId):e.type==="pointerdown"&&this.pointerIds.add(e.pointerId),this.pointerIds}applyHandlers(e,t){this.handlers=e,this.nativeHandlers=t}applyConfig(e,t){this.config=St(e,t,this.config)}clean(){this._targetEventStore.clean();for(const e of this.gestures)this.gestureEventStores[e].clean(),this.gestureTimeoutStores[e].clean()}effect(){return this.config.shared.target&&this.bind(),()=>this._targetEventStore.clean()}bind(...e){const t=this.config.shared,n={};let s;if(!(t.target&&(s=t.target(),!s))){if(t.enabled){for(const a of this.gestures){const u=this.config[a],c=De(n,u.eventOptions,!!s);if(u.enabled){const p=ke.get(a);new p(this,e,a).bind(c)}}const o=De(n,t.eventOptions,!!s);for(const a in this.nativeHandlers)o(a,"",u=>this.nativeHandlers[a](y(y({},this.state.shared),{},{event:u,args:e})),void 0,!0)}for(const o in n)n[o]=rt(...n[o]);if(!s)return n;for(const o in n){const{device:a,capture:u,passive:c}=qe(o);this._targetEventStore.add(s,a,"",n[o],{capture:u,passive:c})}}}}function z(r,e){r.gestures.add(e),r.gestureEventStores[e]=new Ce(r,e),r.gestureTimeoutStores[e]=new kt}function Dt(r,e){e.drag&&z(r,"drag"),e.wheel&&z(r,"wheel"),e.scroll&&z(r,"scroll"),e.move&&z(r,"move"),e.pinch&&z(r,"pinch"),e.hover&&z(r,"hover")}const De=(r,e,t)=>(n,s,o,a={},u=!1)=>{var c,p;const f=(c=a.capture)!==null&&c!==void 0?c:e.capture,_=(p=a.passive)!==null&&p!==void 0?p:e.passive;let h=u?n:Ye(n,s,f);t&&_&&(h+="Passive"),r[h]=r[h]||[],r[h].push(o)};function At(r,e={},t,n){const s=d.useMemo(()=>new Ct(r),[]);if(s.applyHandlers(r,n),s.applyConfig(e,t),d.useEffect(s.effect.bind(s)),d.useEffect(()=>s.clean.bind(s),[]),e.target===void 0)return s.bind.bind(s)}function $t(r,e){return _t(wt),At({drag:r},e||{},"drag")}function Ot(r){const{type:e,actionType:t,toIndex:n,itemsLength:s,withLoop:o,scrollAmount:a,totalAvailable:u}=r;let c=r.currentActive,p=r.fromValueRaw,f=!1,_=!1;e==="next"&&(c+=1),e==="prev"&&(c=c===0?s-1:c-1),n!==void 0&&(c=n);let h=0;e==="next"&&(h=-(c*a),o&&c===s&&(c=0,p=p+a*s,h=0),!o&&(Math.abs(h)>=u||c===s-1)&&(_=!0,h=-u)),e==="prev"&&(h=-(c*a),c===s-1&&(p=p-s*a),!o&&h>=0&&(f=!0,h=0)),t==="resize"&&(h=-(c*a),o||(c===0&&(f=!0),(c===s-1||Math.abs(h)>=u)&&(_=!0,Math.abs(h)>=u&&u>0&&(h=-u))));const E=o?c%s:c,I=o?s+c%s:c;return{newActive:c,fromValue:p,toValue:h,startReached:f,endReached:_,logicalIndex:E,realTrackIndex:I}}function Z(r,e,t){return e==="x"?`translate3d(calc(${r}px + var(--${t}-offset-modifier)), 0px, 0px)`:`translate3d(0px, calc(${r}px + var(--${t}-offset-modifier)), 0px)`}function Pt(){const r=d.useRef(null);r.current===null&&(r.current=new Set);const e=d.useRef(null);return e.current===null&&(e.current={useListenToCustomEvent(t){d.useEffect(()=>{const n=r.current;return n.add(t),()=>{n.delete(t)}},[t])},emitEvent(t){const n=r.current;!n||n.size===0||n.forEach(s=>s(t))}}),e.current}function Mt({init:r=!0,items:e,withLoop:t=!1,id:n,gutter:s=[{breakpoint:0,gutter:0,startEndGutter:0}],itemsPerSlide:o=[{breakpoint:0,itemsPerSlide:1}],carouselAxis:a="x",startingPosition:u="start",enableGestures:c=!0,slideWhenDragThresholdIsReached:p=!0,slideType:f="item",initialActiveItem:_=0,renderWindow:h,renderPlaceholder:E}){const[I,j]=d.useState(!1),[,N]=d.useState(0),$=d.useRef(r),O=d.useRef(null),D=d.useRef(null),B=d.useRef(0),U=d.useRef(0),S=d.useRef(!t),L=d.useRef(!1),oe=d.useRef(0),w=d.useRef(0),$e=d.useRef(e);$e.current=e;const Oe=d.useRef(t);Oe.current=t;const Pe=d.useRef(!1),K=d.useRef(null),V=d.useRef(null),F=d.useRef(null),q=d.useRef({width:0,height:0});function Me(i){if(i===void 0)return 0;if(typeof i=="number")return e[i]?i:(console.warn(`initialActiveItem: item at index ${i} doesn't exist.`),0);const l=e.findIndex(v=>v.id===i);return l<0?(console.warn(`initialActiveItem: item with id "${i}" doesn't exist.`),0):l}const ee=te.useSpringRef(),ae=te.useSpring({value:0,ref:ee,onChange({value:i}){D.current.style.transform=Z(i.value,a,n)}}),Vt=t?e.length*3:e.length,{useListenToCustomEvent:Ne,emitEvent:G}=Pt();function Le(i){if(!i||i.length===0)return null;let l=null,v=-1/0;for(const g of i)(g.media?window.matchMedia(g.media).matches:window.innerWidth>=g.breakpoint)&&g.breakpoint>=v&&(l=g,v=g.breakpoint);return l}function Ve(){const{totalGutterCssVar:i}=Re();return i}function Rt(){const i=Le(o);return(i==null?void 0:i.itemsPerSlide)||1}function ce(i){$.current&&(L.current||W({type:"next",toIndex:i,actionType:"click"}))}function ue(i){$.current&&(S.current||W({type:"prev",toIndex:i,actionType:"click"}))}function W({type:i,shouldAnimate:l=!0,toIndex:v,actionType:g}){var x,m;const C=!l;S.current=!1,L.current=!1;const b=Ot({type:i,actionType:g,toIndex:v,currentActive:w.current,itemsLength:e.length,withLoop:t,scrollAmount:U.current,totalAvailable:i==="next"||g==="resize"?le(t?U.current*(e.length*2):0):0,fromValueRaw:ae.value.get()});w.current=b.newActive,S.current=b.startReached,L.current=b.endReached,B.current=b.toValue,h!==void 0&&N(R=>R+1),G(g==="resize"?{eventName:"onResize",sliceActionType:g,slideDirection:i,currentItem:{id:((x=e.at(b.logicalIndex))==null?void 0:x.id)??"",index:b.logicalIndex,trackIndex:b.realTrackIndex,startReached:S.current,endReached:L.current}}:{eventName:"onSlideStartChange",sliceActionType:g,slideDirection:i,nextItem:{index:b.logicalIndex,id:((m=e.at(b.logicalIndex))==null?void 0:m.id)??"",trackIndex:b.realTrackIndex,startReached:S.current,endReached:L.current}}),ee.start({immediate:C,from:{value:b.fromValue},to:{value:b.toValue},onChange({value:R}){D.current.style.transform=Z(R.value,a,n)},onRest({finished:R}){var je;if(R){const Be=t?w.current%e.length:w.current,Yt=t?e.length+w.current%e.length:w.current;G({eventName:"onSlideChangeComplete",sliceActionType:g,slideDirection:i,currentItem:{index:Be,id:((je=e.at(Be))==null?void 0:je.id)??"",trackIndex:Yt,startReached:S.current,endReached:L.current}})}}})}function jt(){const i=D.current;let l=0;return f==="item"?l=i.children[0].getBoundingClientRect()[a==="x"?"width":"height"]+Ve():l=i.getBoundingClientRect()[a==="x"?"width":"height"]+Ve(),l}function le(i){const l=D.current;return l[a==="x"?"scrollWidth":"scrollHeight"]-l.getBoundingClientRect()[a==="x"?"width":"height"]-i}function Re(){const i=Le(s);return{totalGutterCssVar:(i==null?void 0:i.gutter)||0,totalStartEndGutterCssVar:((i==null?void 0:i.startEndGutter)||0)*2}}d.useEffect(()=>{function i(x){const m=Rt();switch(x){case"start":return 0;case"middle-start":return Math.floor((m-1)*.25);case"center":return Math.floor((m-1)*.5);case"middle-end":return Math.floor((m-1)*.75);case"end":return m-1;default:return 0}}function l(){U.current=jt(),oe.current=U.current/4;const{totalStartEndGutterCssVar:x}=Re();let m=0;t&&(m=U.current*e.length),m-=U.current*i(u),m-=x/2,O.current.style.setProperty(`--${n}-offset-modifier`,`${-m}px`)}function v(x){if(O.current&&(l(),j(!0),x)){const m=Me(_),R=t?e.length+m%e.length:m;G({eventName:"onInit",index:m,trackIndex:R})}}function g(){v(),W({type:"resize",toIndex:w.current,shouldAnimate:!1,actionType:"resize"})}function C(){F.current===null&&(F.current=requestAnimationFrame(()=>{F.current=null;const x=O.current;if(!x)return;const m=x.getBoundingClientRect();(m.width!==q.current.width||m.height!==q.current.height)&&(q.current={width:m.width,height:m.height},g())}))}function b(){setTimeout(()=>{q.current={width:0,height:0},C()},250)}if(r){if($.current=!0,Pe.current)g();else if(v(!0),Pe.current=!0,O.current){const m=O.current.getBoundingClientRect();q.current={width:m.width,height:m.height}}const x=window.visualViewport??window;return x.addEventListener("resize",C),window.addEventListener("orientationchange",b),()=>{x.removeEventListener("resize",C),window.removeEventListener("orientationchange",b),F.current!==null&&(cancelAnimationFrame(F.current),F.current=null)}}},[r,n,a,t]),d.useEffect(()=>{const i=Me(_);r&&i!==w.current&&W({type:"next",toIndex:i,actionType:"resize",shouldAnimate:!1})},[r,_]);const fe=c;function Bt(){if(V.current!==null&&(cancelAnimationFrame(V.current),V.current=null),K.current){const i=K.current;K.current=null,G(i)}}function Ut(i){K.current=i,V.current===null&&(V.current=requestAnimationFrame(()=>{V.current=null;const l=K.current;K.current=null,l&&G(l)}))}d.useEffect(()=>()=>{V.current!==null&&(cancelAnimationFrame(V.current),V.current=null),K.current=null},[]);const Kt=$t(i=>{if(!$.current)return;const l=i.dragging,v=i.offset[a==="x"?0:1],g=i.movement[a==="x"?0:1],C=g>oe.current,b=g<-oe.current,x=i.velocity;l&&(Ut({...i,eventName:"onDrag",slideActionType:"drag"}),ee.start({value:v,immediate:!0,config:{velocity:x},onChange({value:m}){D.current.style.transform=Z(m.value,a,n)}}),p&&(C||b)&&i.cancel()),i.last&&(Bt(),C?(W({actionType:"drag",type:"prev"}),i.cancel()):b?(W({actionType:"drag",type:"next"}),i.cancel()):(ee.start({value:B.current,config:{velocity:x},onChange({value:m}){D.current.style.transform=Z(m.value,a,n)}}),i.cancel()))},{enabled:fe,axis:a,rubberband:!t,...t?{}:{bounds:()=>({right:0,left:-le(0),top:-le(0),bottom:0})},from:()=>[ae.value.get(),ae.value.get()]}),zt=d.useCallback(i=>{var b;const l=$e.current,g=Oe.current?l.length+w.current%l.length:w.current;if(typeof i=="number")return g===i;const C=w.current%l.length;return i===((b=l[C])==null?void 0:b.id)},[]),Ft=d.useMemo(()=>Array.from({length:e.length},(i,l)=>()=>{const v=t?w.current%e.length:w.current;return t?l===(v+1)%e.length:v+1>=e.length?!1:l===v+1}),[e.length,t]),Gt=d.useMemo(()=>Array.from({length:e.length},(i,l)=>()=>{const v=t?w.current%e.length:w.current;return t?l===(v-1+e.length)%e.length:v-1<0?!1:l===v-1}),[e.length,t]),Wt=d.useMemo(()=>`
|
|
1
|
+
(function(P,M){typeof exports=="object"&&typeof module<"u"?M(exports,require("react/jsx-runtime"),require("@react-spring/web"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","@react-spring/web","react"],M):(P=typeof globalThis<"u"?globalThis:P||self,M(P["react-spring-carousel"]={},P["react/jsx-runtime"],P["@react-spring/web"],P.React))})(this,function(P,M,te,d){"use strict";function Ue(r,e,t){return Math.max(e,Math.min(r,t))}const x={toVector(r,e){return r===void 0&&(r=e),Array.isArray(r)?r:[r,r]},add(r,e){return[r[0]+e[0],r[1]+e[1]]},sub(r,e){return[r[0]-e[0],r[1]-e[1]]},addTo(r,e){r[0]+=e[0],r[1]+=e[1]},subTo(r,e){r[0]-=e[0],r[1]-=e[1]}};function de(r,e,t){return e===0||Math.abs(e)===1/0?Math.pow(r,t*5):r*e*t/(e+t*r)}function he(r,e,t,n=.15){return n===0?Ue(r,e,t):r<e?-de(e-r,t-e,n)+e:r>t?+de(r-t,t-e,n)+t:r}function Ke(r,[e,t],[n,s]){const[[o,a],[u,c]]=r;return[he(e,o,a,n),he(t,u,c,s)]}function ze(r,e){if(typeof r!="object"||r===null)return r;var t=r[Symbol.toPrimitive];if(t!==void 0){var n=t.call(r,e);if(typeof n!="object")return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return(e==="string"?String:Number)(r)}function Ge(r){var e=ze(r,"string");return typeof e=="symbol"?e:String(e)}function k(r,e,t){return e=Ge(e),e in r?Object.defineProperty(r,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):r[e]=t,r}function pe(r,e){var t=Object.keys(r);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(r);e&&(n=n.filter(function(s){return Object.getOwnPropertyDescriptor(r,s).enumerable})),t.push.apply(t,n)}return t}function y(r){for(var e=1;e<arguments.length;e++){var t=arguments[e]!=null?arguments[e]:{};e%2?pe(Object(t),!0).forEach(function(n){k(r,n,t[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(t)):pe(Object(t)).forEach(function(n){Object.defineProperty(r,n,Object.getOwnPropertyDescriptor(t,n))})}return r}const ge={pointer:{start:"down",change:"move",end:"up"},mouse:{start:"down",change:"move",end:"up"},touch:{start:"start",change:"move",end:"end"},gesture:{start:"start",change:"change",end:"end"}};function me(r){return r?r[0].toUpperCase()+r.slice(1):""}const Fe=["enter","leave"];function We(r=!1,e){return r&&!Fe.includes(e)}function Ye(r,e="",t=!1){const n=ge[r],s=n&&n[e]||e;return"on"+me(r)+me(s)+(We(t,s)?"Capture":"")}const He=["gotpointercapture","lostpointercapture"];function Xe(r){let e=r.substring(2).toLowerCase();const t=!!~e.indexOf("passive");t&&(e=e.replace("passive",""));const n=He.includes(e)?"capturecapture":"capture",s=!!~e.indexOf(n);return s&&(e=e.replace("capture","")),{device:e,capture:s,passive:t}}function qe(r,e=""){const t=ge[r],n=t&&t[e]||e;return r+n}function q(r){return"touches"in r}function ve(r){return q(r)?"touch":"pointerType"in r?r.pointerType:"mouse"}function Je(r){return Array.from(r.touches).filter(e=>{var t,n;return e.target===r.currentTarget||((t=r.currentTarget)===null||t===void 0||(n=t.contains)===null||n===void 0?void 0:n.call(t,e.target))})}function Qe(r){return r.type==="touchend"||r.type==="touchcancel"?r.changedTouches:r.targetTouches}function ye(r){return q(r)?Qe(r)[0]:r}function Ze(r){return Je(r).map(e=>e.identifier)}function re(r){const e=ye(r);return q(r)?e.identifier:e.pointerId}function be(r){const e=ye(r);return[e.clientX,e.clientY]}function et(r){const e={};if("buttons"in r&&(e.buttons=r.buttons),"shiftKey"in r){const{shiftKey:t,altKey:n,metaKey:s,ctrlKey:o}=r;Object.assign(e,{shiftKey:t,altKey:n,metaKey:s,ctrlKey:o})}return e}function J(r,...e){return typeof r=="function"?r(...e):r}function tt(){}function rt(...r){return r.length===0?tt:r.length===1?r[0]:function(){let e;for(const t of r)e=t.apply(this,arguments)||e;return e}}function _e(r,e){return Object.assign({},e,r||{})}const nt=32;class st{constructor(e,t,n){this.ctrl=e,this.args=t,this.key=n,this.state||(this.state={},this.computeValues([0,0]),this.computeInitial(),this.init&&this.init(),this.reset())}get state(){return this.ctrl.state[this.key]}set state(e){this.ctrl.state[this.key]=e}get shared(){return this.ctrl.state.shared}get eventStore(){return this.ctrl.gestureEventStores[this.key]}get timeoutStore(){return this.ctrl.gestureTimeoutStores[this.key]}get config(){return this.ctrl.config[this.key]}get sharedConfig(){return this.ctrl.config.shared}get handler(){return this.ctrl.handlers[this.key]}reset(){const{state:e,shared:t,ingKey:n,args:s}=this;t[n]=e._active=e.active=e._blocked=e._force=!1,e._step=[!1,!1],e.intentional=!1,e._movement=[0,0],e._distance=[0,0],e._direction=[0,0],e._delta=[0,0],e._bounds=[[-1/0,1/0],[-1/0,1/0]],e.args=s,e.axis=void 0,e.memo=void 0,e.elapsedTime=e.timeDelta=0,e.direction=[0,0],e.distance=[0,0],e.overflow=[0,0],e._movementBound=[!1,!1],e.velocity=[0,0],e.movement=[0,0],e.delta=[0,0],e.timeStamp=0}start(e){const t=this.state,n=this.config;t._active||(this.reset(),this.computeInitial(),t._active=!0,t.target=e.target,t.currentTarget=e.currentTarget,t.lastOffset=n.from?J(n.from,t):t.offset,t.offset=t.lastOffset,t.startTime=t.timeStamp=e.timeStamp)}computeValues(e){const t=this.state;t._values=e,t.values=this.config.transform(e)}computeInitial(){const e=this.state;e._initial=e._values,e.initial=e.values}compute(e){const{state:t,config:n,shared:s}=this;t.args=this.args;let o=0;if(e&&(t.event=e,n.preventDefault&&e.cancelable&&t.event.preventDefault(),t.type=e.type,s.touches=this.ctrl.pointerIds.size||this.ctrl.touchIds.size,s.locked=!!document.pointerLockElement,Object.assign(s,et(e)),s.down=s.pressed=s.buttons%2===1||s.touches>0,o=e.timeStamp-t.timeStamp,t.timeStamp=e.timeStamp,t.elapsedTime=t.timeStamp-t.startTime),t._active){const S=t._delta.map(Math.abs);x.addTo(t._distance,S)}this.axisIntent&&this.axisIntent(e);const[a,u]=t._movement,[c,p]=n.threshold,{_step:f,values:_}=t;if(n.hasCustomTransform?(f[0]===!1&&(f[0]=Math.abs(a)>=c&&_[0]),f[1]===!1&&(f[1]=Math.abs(u)>=p&&_[1])):(f[0]===!1&&(f[0]=Math.abs(a)>=c&&Math.sign(a)*c),f[1]===!1&&(f[1]=Math.abs(u)>=p&&Math.sign(u)*p)),t.intentional=f[0]!==!1||f[1]!==!1,!t.intentional)return;const h=[0,0];if(n.hasCustomTransform){const[S,L]=_;h[0]=f[0]!==!1?S-f[0]:0,h[1]=f[1]!==!1?L-f[1]:0}else h[0]=f[0]!==!1?a-f[0]:0,h[1]=f[1]!==!1?u-f[1]:0;this.restrictToAxis&&!t._blocked&&this.restrictToAxis(h);const E=t.offset,I=t._active&&!t._blocked||t.active;I&&(t.first=t._active&&!t.active,t.last=!t._active&&t.active,t.active=s[this.ingKey]=t._active,e&&(t.first&&("bounds"in n&&(t._bounds=J(n.bounds,t)),this.setup&&this.setup()),t.movement=h,this.computeOffset()));const[j,N]=t.offset,[[$,O],[D,B]]=t._bounds;t.overflow=[j<$?-1:j>O?1:0,N<D?-1:N>B?1:0],t._movementBound[0]=t.overflow[0]?t._movementBound[0]===!1?t._movement[0]:t._movementBound[0]:!1,t._movementBound[1]=t.overflow[1]?t._movementBound[1]===!1?t._movement[1]:t._movementBound[1]:!1;const U=t._active?n.rubberband||[0,0]:[0,0];if(t.offset=Ke(t._bounds,t.offset,U),t.delta=x.sub(t.offset,E),this.computeMovement(),I&&(!t.last||o>nt)){t.delta=x.sub(t.offset,E);const S=t.delta.map(Math.abs);x.addTo(t.distance,S),t.direction=t.delta.map(Math.sign),t._direction=t._delta.map(Math.sign),!t.first&&o>0&&(t.velocity=[S[0]/o,S[1]/o],t.timeDelta=o)}}emit(){const e=this.state,t=this.shared,n=this.config;if(e._active||this.clean(),(e._blocked||!e.intentional)&&!e._force&&!n.triggerAllEvents)return;const s=this.handler(y(y(y({},t),e),{},{[this.aliasKey]:e.values}));s!==void 0&&(e.memo=s)}clean(){this.eventStore.clean(),this.timeoutStore.clean()}}function it([r,e],t){const n=Math.abs(r),s=Math.abs(e);if(n>s&&n>t)return"x";if(s>n&&s>t)return"y"}class ot extends st{constructor(...e){super(...e),k(this,"aliasKey","xy")}reset(){super.reset(),this.state.axis=void 0}init(){this.state.offset=[0,0],this.state.lastOffset=[0,0]}computeOffset(){this.state.offset=x.add(this.state.lastOffset,this.state.movement)}computeMovement(){this.state.movement=x.sub(this.state.offset,this.state.lastOffset)}axisIntent(e){const t=this.state,n=this.config;if(!t.axis&&e){const s=typeof n.axisThreshold=="object"?n.axisThreshold[ve(e)]:n.axisThreshold;t.axis=it(t._movement,s)}t._blocked=(n.lockDirection||!!n.axis)&&!t.axis||!!n.axis&&n.axis!==t.axis}restrictToAxis(e){if(this.config.axis||this.config.lockDirection)switch(this.state.axis){case"x":e[1]=0;break;case"y":e[0]=0;break}}}const we=r=>r,Te=.15,ne={enabled(r=!0){return r},eventOptions(r,e,t){return y(y({},t.shared.eventOptions),r)},preventDefault(r=!1){return r},triggerAllEvents(r=!1){return r},rubberband(r=0){switch(r){case!0:return[Te,Te];case!1:return[0,0];default:return x.toVector(r)}},from(r){if(typeof r=="function")return r;if(r!=null)return x.toVector(r)},transform(r,e,t){const n=r||t.shared.transform;if(this.hasCustomTransform=!!n,process.env.NODE_ENV==="development"){const s=n||we;return o=>{const a=s(o);return(!isFinite(a[0])||!isFinite(a[1]))&&console.warn(`[@use-gesture]: config.transform() must produce a valid result, but it was: [${a[0]},${[1]}]`),a}}return n||we},threshold(r){return x.toVector(r,0)}};process.env.NODE_ENV==="development"&&Object.assign(ne,{domTarget(r){if(r!==void 0)throw Error("[@use-gesture]: `domTarget` option has been renamed to `target`.");return NaN},lockDirection(r){if(r!==void 0)throw Error("[@use-gesture]: `lockDirection` option has been merged with `axis`. Use it as in `{ axis: 'lock' }`");return NaN},initial(r){if(r!==void 0)throw Error("[@use-gesture]: `initial` option has been renamed to `from`.");return NaN}});const at=0,Y=y(y({},ne),{},{axis(r,e,{axis:t}){if(this.lockDirection=t==="lock",!this.lockDirection)return t},axisThreshold(r=at){return r},bounds(r={}){if(typeof r=="function")return o=>Y.bounds(r(o));if("current"in r)return()=>r.current;if(typeof HTMLElement=="function"&&r instanceof HTMLElement)return r;const{left:e=-1/0,right:t=1/0,top:n=-1/0,bottom:s=1/0}=r;return[[e,t],[n,s]]}}),xe={ArrowRight:(r,e=1)=>[r*e,0],ArrowLeft:(r,e=1)=>[-1*r*e,0],ArrowUp:(r,e=1)=>[0,-1*r*e],ArrowDown:(r,e=1)=>[0,r*e]};class ct extends ot{constructor(...e){super(...e),k(this,"ingKey","dragging")}reset(){super.reset();const e=this.state;e._pointerId=void 0,e._pointerActive=!1,e._keyboardActive=!1,e._preventScroll=!1,e._delayed=!1,e.swipe=[0,0],e.tap=!1,e.canceled=!1,e.cancel=this.cancel.bind(this)}setup(){const e=this.state;if(e._bounds instanceof HTMLElement){const t=e._bounds.getBoundingClientRect(),n=e.currentTarget.getBoundingClientRect(),s={left:t.left-n.left+e.offset[0],right:t.right-n.right+e.offset[0],top:t.top-n.top+e.offset[1],bottom:t.bottom-n.bottom+e.offset[1]};e._bounds=Y.bounds(s)}}cancel(){const e=this.state;e.canceled||(e.canceled=!0,e._active=!1,setTimeout(()=>{this.compute(),this.emit()},0))}setActive(){this.state._active=this.state._pointerActive||this.state._keyboardActive}clean(){this.pointerClean(),this.state._pointerActive=!1,this.state._keyboardActive=!1,super.clean()}pointerDown(e){const t=this.config,n=this.state;if(e.buttons!=null&&(Array.isArray(t.pointerButtons)?!t.pointerButtons.includes(e.buttons):t.pointerButtons!==-1&&t.pointerButtons!==e.buttons))return;const s=this.ctrl.setEventIds(e);t.pointerCapture&&e.target.setPointerCapture(e.pointerId),!(s&&s.size>1&&n._pointerActive)&&(this.start(e),this.setupPointer(e),n._pointerId=re(e),n._pointerActive=!0,this.computeValues(be(e)),this.computeInitial(),t.preventScrollAxis&&ve(e)!=="mouse"?(n._active=!1,this.setupScrollPrevention(e)):t.delay>0?(this.setupDelayTrigger(e),t.triggerAllEvents&&(this.compute(e),this.emit())):this.startPointerDrag(e))}startPointerDrag(e){const t=this.state;t._active=!0,t._preventScroll=!0,t._delayed=!1,this.compute(e),this.emit()}pointerMove(e){const t=this.state,n=this.config;if(!t._pointerActive)return;const s=re(e);if(t._pointerId!==void 0&&s!==t._pointerId)return;const o=be(e);if(document.pointerLockElement===e.target?t._delta=[e.movementX,e.movementY]:(t._delta=x.sub(o,t._values),this.computeValues(o)),x.addTo(t._movement,t._delta),this.compute(e),t._delayed&&t.intentional){this.timeoutStore.remove("dragDelay"),t.active=!1,this.startPointerDrag(e);return}if(n.preventScrollAxis&&!t._preventScroll)if(t.axis)if(t.axis===n.preventScrollAxis||n.preventScrollAxis==="xy"){t._active=!1,this.clean();return}else{this.timeoutStore.remove("startPointerDrag"),this.startPointerDrag(e);return}else return;this.emit()}pointerUp(e){this.ctrl.setEventIds(e);try{this.config.pointerCapture&&e.target.hasPointerCapture(e.pointerId)&&e.target.releasePointerCapture(e.pointerId)}catch{process.env.NODE_ENV==="development"&&console.warn("[@use-gesture]: If you see this message, it's likely that you're using an outdated version of `@react-three/fiber`. \n\nPlease upgrade to the latest version.")}const t=this.state,n=this.config;if(!t._active||!t._pointerActive)return;const s=re(e);if(t._pointerId!==void 0&&s!==t._pointerId)return;this.state._pointerActive=!1,this.setActive(),this.compute(e);const[o,a]=t._distance;if(t.tap=o<=n.tapsThreshold&&a<=n.tapsThreshold,t.tap&&n.filterTaps)t._force=!0;else{const[u,c]=t._delta,[p,f]=t._movement,[_,h]=n.swipe.velocity,[E,I]=n.swipe.distance,j=n.swipe.duration;if(t.elapsedTime<j){const N=Math.abs(u/t.timeDelta),$=Math.abs(c/t.timeDelta);N>_&&Math.abs(p)>E&&(t.swipe[0]=Math.sign(u)),$>h&&Math.abs(f)>I&&(t.swipe[1]=Math.sign(c))}}this.emit()}pointerClick(e){!this.state.tap&&e.detail>0&&(e.preventDefault(),e.stopPropagation())}setupPointer(e){const t=this.config,n=t.device;if(process.env.NODE_ENV==="development")try{if(n==="pointer"&&t.preventScrollDelay===void 0){const s="uv"in e?e.sourceEvent.currentTarget:e.currentTarget;window.getComputedStyle(s).touchAction==="auto"&&console.warn("[@use-gesture]: The drag target has its `touch-action` style property set to `auto`. It is recommended to add `touch-action: 'none'` so that the drag gesture behaves correctly on touch-enabled devices. For more information read this: https://use-gesture.netlify.app/docs/extras/#touch-action.\n\nThis message will only show in development mode. It won't appear in production. If this is intended, you can ignore it.",s)}}catch{}t.pointerLock&&e.currentTarget.requestPointerLock(),t.pointerCapture||(this.eventStore.add(this.sharedConfig.window,n,"change",this.pointerMove.bind(this)),this.eventStore.add(this.sharedConfig.window,n,"end",this.pointerUp.bind(this)),this.eventStore.add(this.sharedConfig.window,n,"cancel",this.pointerUp.bind(this)))}pointerClean(){this.config.pointerLock&&document.pointerLockElement===this.state.currentTarget&&document.exitPointerLock()}preventScroll(e){this.state._preventScroll&&e.cancelable&&e.preventDefault()}setupScrollPrevention(e){this.state._preventScroll=!1,ut(e);const t=this.eventStore.add(this.sharedConfig.window,"touch","change",this.preventScroll.bind(this),{passive:!1});this.eventStore.add(this.sharedConfig.window,"touch","end",t),this.eventStore.add(this.sharedConfig.window,"touch","cancel",t),this.timeoutStore.add("startPointerDrag",this.startPointerDrag.bind(this),this.config.preventScrollDelay,e)}setupDelayTrigger(e){this.state._delayed=!0,this.timeoutStore.add("dragDelay",()=>{this.state._step=[0,0],this.startPointerDrag(e)},this.config.delay)}keyDown(e){const t=xe[e.key];if(t){const n=this.state,s=e.shiftKey?10:e.altKey?.1:1;this.start(e),n._delta=t(this.config.keyboardDisplacement,s),n._keyboardActive=!0,x.addTo(n._movement,n._delta),this.compute(e),this.emit()}}keyUp(e){e.key in xe&&(this.state._keyboardActive=!1,this.setActive(),this.compute(e),this.emit())}bind(e){const t=this.config.device;e(t,"start",this.pointerDown.bind(this)),this.config.pointerCapture&&(e(t,"change",this.pointerMove.bind(this)),e(t,"end",this.pointerUp.bind(this)),e(t,"cancel",this.pointerUp.bind(this)),e("lostPointerCapture","",this.pointerUp.bind(this))),this.config.keys&&(e("key","down",this.keyDown.bind(this)),e("key","up",this.keyUp.bind(this))),this.config.filterTaps&&e("click","",this.pointerClick.bind(this),{capture:!0,passive:!1})}}function ut(r){"persist"in r&&typeof r.persist=="function"&&r.persist()}const H=typeof window<"u"&&window.document&&window.document.createElement;function Ee(){return H&&"ontouchstart"in window}function lt(){return Ee()||H&&window.navigator.maxTouchPoints>1}function ft(){return H&&"onpointerdown"in window}function dt(){return H&&"exitPointerLock"in window.document}function ht(){try{return"constructor"in GestureEvent}catch{return!1}}const A={isBrowser:H,gesture:ht(),touch:Ee(),touchscreen:lt(),pointer:ft(),pointerLock:dt()},pt=250,gt=180,mt=.5,vt=50,yt=250,bt=10,Ie={mouse:0,touch:0,pen:8},Se=y(y({},Y),{},{device(r,e,{pointer:{touch:t=!1,lock:n=!1,mouse:s=!1}={}}){return this.pointerLock=n&&A.pointerLock,A.touch&&t?"touch":this.pointerLock?"mouse":A.pointer&&!s?"pointer":A.touch?"touch":"mouse"},preventScrollAxis(r,e,{preventScroll:t}){if(this.preventScrollDelay=typeof t=="number"?t:t||t===void 0&&r?pt:void 0,!(!A.touchscreen||t===!1))return r||(t!==void 0?"y":void 0)},pointerCapture(r,e,{pointer:{capture:t=!0,buttons:n=1,keys:s=!0}={}}){return this.pointerButtons=n,this.keys=s,!this.pointerLock&&this.device==="pointer"&&t},threshold(r,e,{filterTaps:t=!1,tapsThreshold:n=3,axis:s=void 0}){const o=x.toVector(r,t?n:s?1:0);return this.filterTaps=t,this.tapsThreshold=n,o},swipe({velocity:r=mt,distance:e=vt,duration:t=yt}={}){return{velocity:this.transform(x.toVector(r)),distance:this.transform(x.toVector(e)),duration:t}},delay(r=0){switch(r){case!0:return gt;case!1:return 0;default:return r}},axisThreshold(r){return r?y(y({},Ie),r):Ie},keyboardDisplacement(r=bt){return r}});process.env.NODE_ENV==="development"&&Object.assign(Se,{useTouch(r){if(r!==void 0)throw Error("[@use-gesture]: `useTouch` option has been renamed to `pointer.touch`. Use it as in `{ pointer: { touch: true } }`.");return NaN},experimental_preventWindowScrollY(r){if(r!==void 0)throw Error("[@use-gesture]: `experimental_preventWindowScrollY` option has been renamed to `preventScroll`.");return NaN},swipeVelocity(r){if(r!==void 0)throw Error("[@use-gesture]: `swipeVelocity` option has been renamed to `swipe.velocity`. Use it as in `{ swipe: { velocity: 0.5 } }`.");return NaN},swipeDistance(r){if(r!==void 0)throw Error("[@use-gesture]: `swipeDistance` option has been renamed to `swipe.distance`. Use it as in `{ swipe: { distance: 50 } }`.");return NaN},swipeDuration(r){if(r!==void 0)throw Error("[@use-gesture]: `swipeDuration` option has been renamed to `swipe.duration`. Use it as in `{ swipe: { duration: 250 } }`.");return NaN}}),y(y({},ne),{},{device(r,e,{shared:t,pointer:{touch:n=!1}={}}){if(t.target&&!A.touch&&A.gesture)return"gesture";if(A.touch&&n)return"touch";if(A.touchscreen){if(A.pointer)return"pointer";if(A.touch)return"touch"}},bounds(r,e,{scaleBounds:t={},angleBounds:n={}}){const s=a=>{const u=_e(J(t,a),{min:-1/0,max:1/0});return[u.min,u.max]},o=a=>{const u=_e(J(n,a),{min:-1/0,max:1/0});return[u.min,u.max]};return typeof t!="function"&&typeof n!="function"?[s(),o()]:a=>[s(a),o(a)]},threshold(r,e,t){return this.lockDirection=t.axis==="lock",x.toVector(r,this.lockDirection?[.1,3]:0)},modifierKey(r){return r===void 0?"ctrlKey":r},pinchOnWheel(r=!0){return r}}),y(y({},Y),{},{mouseOnly:(r=!0)=>r}),y(y({},Y),{},{mouseOnly:(r=!0)=>r});const ke=new Map,se=new Map;function _t(r){ke.set(r.key,r.engine),se.set(r.key,r.resolver)}const wt={key:"drag",engine:ct,resolver:Se};function Tt(r,e){if(r==null)return{};var t={},n=Object.keys(r),s,o;for(o=0;o<n.length;o++)s=n[o],!(e.indexOf(s)>=0)&&(t[s]=r[s]);return t}function xt(r,e){if(r==null)return{};var t=Tt(r,e),n,s;if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(r);for(s=0;s<o.length;s++)n=o[s],!(e.indexOf(n)>=0)&&Object.prototype.propertyIsEnumerable.call(r,n)&&(t[n]=r[n])}return t}const Et={target(r){if(r)return()=>"current"in r?r.current:r},enabled(r=!0){return r},window(r=A.isBrowser?window:void 0){return r},eventOptions({passive:r=!0,capture:e=!1}={}){return{passive:r,capture:e}},transform(r){return r}},It=["target","eventOptions","window","enabled","transform"];function Q(r={},e){const t={};for(const[n,s]of Object.entries(e))switch(typeof s){case"function":if(process.env.NODE_ENV==="development"){const o=s.call(t,r[n],n,r);Number.isNaN(o)||(t[n]=o)}else t[n]=s.call(t,r[n],n,r);break;case"object":t[n]=Q(r[n],s);break;case"boolean":s&&(t[n]=r[n]);break}return t}function St(r,e,t={}){const n=r,{target:s,eventOptions:o,window:a,enabled:u,transform:c}=n,p=xt(n,It);if(t.shared=Q({target:s,eventOptions:o,window:a,enabled:u,transform:c},Et),e){const f=se.get(e);t[e]=Q(y({shared:t.shared},p),f)}else for(const f in p){const _=se.get(f);if(_)t[f]=Q(y({shared:t.shared},p[f]),_);else if(process.env.NODE_ENV==="development"&&!["drag","pinch","scroll","wheel","move","hover"].includes(f)){if(f==="domTarget")throw Error("[@use-gesture]: `domTarget` option has been renamed to `target`.");console.warn(`[@use-gesture]: Unknown config key \`${f}\` was used. Please read the documentation for further information.`)}}return t}class Ce{constructor(e,t){k(this,"_listeners",new Set),this._ctrl=e,this._gestureKey=t}add(e,t,n,s,o){const a=this._listeners,u=qe(t,n),c=this._gestureKey?this._ctrl.config[this._gestureKey].eventOptions:{},p=y(y({},c),o);e.addEventListener(u,s,p);const f=()=>{e.removeEventListener(u,s,p),a.delete(f)};return a.add(f),f}clean(){this._listeners.forEach(e=>e()),this._listeners.clear()}}class kt{constructor(){k(this,"_timeouts",new Map)}add(e,t,n=140,...s){this.remove(e),this._timeouts.set(e,window.setTimeout(t,n,...s))}remove(e){const t=this._timeouts.get(e);t&&window.clearTimeout(t)}clean(){this._timeouts.forEach(e=>void window.clearTimeout(e)),this._timeouts.clear()}}class Ct{constructor(e){k(this,"gestures",new Set),k(this,"_targetEventStore",new Ce(this)),k(this,"gestureEventStores",{}),k(this,"gestureTimeoutStores",{}),k(this,"handlers",{}),k(this,"config",{}),k(this,"pointerIds",new Set),k(this,"touchIds",new Set),k(this,"state",{shared:{shiftKey:!1,metaKey:!1,ctrlKey:!1,altKey:!1}}),Dt(this,e)}setEventIds(e){if(q(e))return this.touchIds=new Set(Ze(e)),this.touchIds;if("pointerId"in e)return e.type==="pointerup"||e.type==="pointercancel"?this.pointerIds.delete(e.pointerId):e.type==="pointerdown"&&this.pointerIds.add(e.pointerId),this.pointerIds}applyHandlers(e,t){this.handlers=e,this.nativeHandlers=t}applyConfig(e,t){this.config=St(e,t,this.config)}clean(){this._targetEventStore.clean();for(const e of this.gestures)this.gestureEventStores[e].clean(),this.gestureTimeoutStores[e].clean()}effect(){return this.config.shared.target&&this.bind(),()=>this._targetEventStore.clean()}bind(...e){const t=this.config.shared,n={};let s;if(!(t.target&&(s=t.target(),!s))){if(t.enabled){for(const a of this.gestures){const u=this.config[a],c=De(n,u.eventOptions,!!s);if(u.enabled){const p=ke.get(a);new p(this,e,a).bind(c)}}const o=De(n,t.eventOptions,!!s);for(const a in this.nativeHandlers)o(a,"",u=>this.nativeHandlers[a](y(y({},this.state.shared),{},{event:u,args:e})),void 0,!0)}for(const o in n)n[o]=rt(...n[o]);if(!s)return n;for(const o in n){const{device:a,capture:u,passive:c}=Xe(o);this._targetEventStore.add(s,a,"",n[o],{capture:u,passive:c})}}}}function G(r,e){r.gestures.add(e),r.gestureEventStores[e]=new Ce(r,e),r.gestureTimeoutStores[e]=new kt}function Dt(r,e){e.drag&&G(r,"drag"),e.wheel&&G(r,"wheel"),e.scroll&&G(r,"scroll"),e.move&&G(r,"move"),e.pinch&&G(r,"pinch"),e.hover&&G(r,"hover")}const De=(r,e,t)=>(n,s,o,a={},u=!1)=>{var c,p;const f=(c=a.capture)!==null&&c!==void 0?c:e.capture,_=(p=a.passive)!==null&&p!==void 0?p:e.passive;let h=u?n:Ye(n,s,f);t&&_&&(h+="Passive"),r[h]=r[h]||[],r[h].push(o)};function At(r,e={},t,n){const s=d.useMemo(()=>new Ct(r),[]);if(s.applyHandlers(r,n),s.applyConfig(e,t),d.useEffect(s.effect.bind(s)),d.useEffect(()=>s.clean.bind(s),[]),e.target===void 0)return s.bind.bind(s)}function $t(r,e){return _t(wt),At({drag:r},e||{},"drag")}function Ot(r){const{type:e,actionType:t,toIndex:n,itemsLength:s,withLoop:o,scrollAmount:a,totalAvailable:u}=r;let c=r.currentActive,p=r.fromValueRaw,f=!1,_=!1;e==="next"&&(c+=1),e==="prev"&&(c=c===0?s-1:c-1),n!==void 0&&(c=n);let h=0;e==="next"&&(h=-(c*a),o&&c===s&&(c=0,p=p+a*s,h=0),!o&&(Math.abs(h)>=u||c===s-1)&&(_=!0,h=-u)),e==="prev"&&(h=-(c*a),c===s-1&&(p=p-s*a),!o&&h>=0&&(f=!0,h=0)),t==="resize"&&(h=-(c*a),o||(c===0&&(f=!0),(c===s-1||Math.abs(h)>=u)&&(_=!0,Math.abs(h)>=u&&u>0&&(h=-u))));const E=o?c%s:c,I=o?s+c%s:c;return{newActive:c,fromValue:p,toValue:h,startReached:f,endReached:_,logicalIndex:E,realTrackIndex:I}}function Z(r,e,t){return e==="x"?`translate3d(calc(${r}px + var(--${t}-offset-modifier)), 0px, 0px)`:`translate3d(0px, calc(${r}px + var(--${t}-offset-modifier)), 0px)`}function Pt(){const r=d.useRef(null);r.current===null&&(r.current=new Set);const e=d.useRef(null);return e.current===null&&(e.current={useListenToCustomEvent(t){d.useEffect(()=>{const n=r.current;return n.add(t),()=>{n.delete(t)}},[t])},emitEvent(t){const n=r.current;!n||n.size===0||n.forEach(s=>s(t))}}),e.current}function Mt({init:r=!0,items:e,withLoop:t=!1,id:n,gutter:s=[{breakpoint:0,gutter:0,startEndGutter:0}],itemsPerSlide:o=[{breakpoint:0,itemsPerSlide:1}],carouselAxis:a="x",startingPosition:u="start",enableGestures:c=!0,slideWhenDragThresholdIsReached:p=!0,slideType:f="item",initialActiveItem:_=0,renderWindow:h,renderPlaceholder:E}){const[I,j]=d.useState(!1),[,N]=d.useState(0),$=d.useRef(r),O=d.useRef(null),D=d.useRef(null),B=d.useRef(0),U=d.useRef(0),S=d.useRef(!t),L=d.useRef(!1),oe=d.useRef(0),w=d.useRef(0),$e=d.useRef(e);$e.current=e;const Oe=d.useRef(t);Oe.current=t;const Pe=d.useRef(!1),K=d.useRef(null),V=d.useRef(null),z=d.useRef(null),X=d.useRef({width:0,height:0});function Me(i){if(i===void 0)return 0;if(typeof i=="number")return e[i]?i:(console.warn(`initialActiveItem: item at index ${i} doesn't exist.`),0);const l=e.findIndex(v=>v.id===i);return l<0?(console.warn(`initialActiveItem: item with id "${i}" doesn't exist.`),0):l}const ee=te.useSpringRef(),ae=te.useSpring({value:0,ref:ee,onChange({value:i}){D.current.style.transform=Z(i.value,a,n)}}),Vt=t?e.length*3:e.length,{useListenToCustomEvent:Ne,emitEvent:F}=Pt();function Le(i){if(!i||i.length===0)return null;let l=null,v=-1/0;for(const g of i)(g.media?window.matchMedia(g.media).matches:window.innerWidth>=g.breakpoint)&&g.breakpoint>=v&&(l=g,v=g.breakpoint);return l}function Ve(){const{totalGutterCssVar:i}=Re();return i}function Rt(){const i=Le(o);return(i==null?void 0:i.itemsPerSlide)||1}function ce(i){$.current&&(L.current||W({type:"next",toIndex:i,actionType:"click"}))}function ue(i){$.current&&(S.current||W({type:"prev",toIndex:i,actionType:"click"}))}function W({type:i,shouldAnimate:l=!0,toIndex:v,actionType:g}){var T,m;const C=!l;S.current=!1,L.current=!1;const b=Ot({type:i,actionType:g,toIndex:v,currentActive:w.current,itemsLength:e.length,withLoop:t,scrollAmount:U.current,totalAvailable:i==="next"||g==="resize"?le(t?U.current*(e.length*2):0):0,fromValueRaw:ae.value.get()});w.current=b.newActive,S.current=b.startReached,L.current=b.endReached,B.current=b.toValue,h!==void 0&&N(R=>R+1),F(g==="resize"?{eventName:"onResize",sliceActionType:g,slideDirection:i,currentItem:{id:((T=e.at(b.logicalIndex))==null?void 0:T.id)??"",index:b.logicalIndex,trackIndex:b.realTrackIndex,startReached:S.current,endReached:L.current}}:{eventName:"onSlideStartChange",sliceActionType:g,slideDirection:i,nextItem:{index:b.logicalIndex,id:((m=e.at(b.logicalIndex))==null?void 0:m.id)??"",trackIndex:b.realTrackIndex,startReached:S.current,endReached:L.current}}),ee.start({immediate:C,from:{value:b.fromValue},to:{value:b.toValue},onChange({value:R}){D.current.style.transform=Z(R.value,a,n)},onRest({finished:R}){var je;if(R){const Be=t?w.current%e.length:w.current,Yt=t?e.length+w.current%e.length:w.current;F({eventName:"onSlideChangeComplete",sliceActionType:g,slideDirection:i,currentItem:{index:Be,id:((je=e.at(Be))==null?void 0:je.id)??"",trackIndex:Yt,startReached:S.current,endReached:L.current}})}}})}function jt(){const i=D.current;let l=0;return f==="item"?l=i.children[0].getBoundingClientRect()[a==="x"?"width":"height"]+Ve():l=i.getBoundingClientRect()[a==="x"?"width":"height"]+Ve(),l}function le(i){const l=D.current;return l[a==="x"?"scrollWidth":"scrollHeight"]-l.getBoundingClientRect()[a==="x"?"width":"height"]-i}function Re(){const i=Le(s);return{totalGutterCssVar:(i==null?void 0:i.gutter)||0,totalStartEndGutterCssVar:((i==null?void 0:i.startEndGutter)||0)*2}}d.useEffect(()=>{function i(T){const m=Rt();switch(T){case"start":return 0;case"middle-start":return Math.floor((m-1)*.25);case"center":return Math.floor((m-1)*.5);case"middle-end":return Math.floor((m-1)*.75);case"end":return m-1;default:return 0}}function l(){U.current=jt(),oe.current=U.current/4;const{totalStartEndGutterCssVar:T}=Re();let m=0;t&&(m=U.current*e.length),m-=U.current*i(u),m-=T/2,O.current.style.setProperty(`--${n}-offset-modifier`,`${-m}px`)}function v(T){if(O.current&&(l(),j(!0),T)){const m=Me(_),R=t?e.length+m%e.length:m;F({eventName:"onInit",index:m,trackIndex:R})}}function g(){v(),W({type:"resize",toIndex:w.current,shouldAnimate:!1,actionType:"resize"})}function C(){z.current!==null&&clearTimeout(z.current),z.current=window.setTimeout(()=>{z.current=null;const T=O.current;if(!T)return;const m=T.getBoundingClientRect();(m.width!==X.current.width||m.height!==X.current.height)&&(X.current={width:m.width,height:m.height},g())},100)}function b(){setTimeout(()=>{X.current={width:0,height:0},C()},250)}if(r){if($.current=!0,Pe.current)g();else if(v(!0),Pe.current=!0,O.current){const m=O.current.getBoundingClientRect();X.current={width:m.width,height:m.height}}const T=window.visualViewport??window;return T.addEventListener("resize",C),window.addEventListener("orientationchange",b),()=>{T.removeEventListener("resize",C),window.removeEventListener("orientationchange",b),z.current!==null&&(clearTimeout(z.current),z.current=null)}}},[r,n,a,t]),d.useEffect(()=>{const i=Me(_);r&&i!==w.current&&W({type:"next",toIndex:i,actionType:"resize",shouldAnimate:!1})},[r,_]);const fe=c;function Bt(){if(V.current!==null&&(cancelAnimationFrame(V.current),V.current=null),K.current){const i=K.current;K.current=null,F(i)}}function Ut(i){K.current=i,V.current===null&&(V.current=requestAnimationFrame(()=>{V.current=null;const l=K.current;K.current=null,l&&F(l)}))}d.useEffect(()=>()=>{V.current!==null&&(cancelAnimationFrame(V.current),V.current=null),K.current=null},[]);const Kt=$t(i=>{if(!$.current)return;const l=i.dragging,v=i.offset[a==="x"?0:1],g=i.movement[a==="x"?0:1],C=g>oe.current,b=g<-oe.current,T=i.velocity;l&&(Ut({...i,eventName:"onDrag",slideActionType:"drag"}),ee.start({value:v,immediate:!0,config:{velocity:T},onChange({value:m}){D.current.style.transform=Z(m.value,a,n)}}),p&&(C||b)&&i.cancel()),i.last&&(Bt(),C?(W({actionType:"drag",type:"prev"}),i.cancel()):b?(W({actionType:"drag",type:"next"}),i.cancel()):(ee.start({value:B.current,config:{velocity:T},onChange({value:m}){D.current.style.transform=Z(m.value,a,n)}}),i.cancel()))},{enabled:fe,axis:a,rubberband:!t,...t?{}:{bounds:()=>({right:0,left:-le(0),top:-le(0),bottom:0})},from:()=>[ae.value.get(),ae.value.get()]}),zt=d.useCallback(i=>{var b;const l=$e.current,g=Oe.current?l.length+w.current%l.length:w.current;if(typeof i=="number")return g===i;const C=w.current%l.length;return i===((b=l[C])==null?void 0:b.id)},[]),Gt=d.useMemo(()=>Array.from({length:e.length},(i,l)=>()=>{const v=t?w.current%e.length:w.current;return t?l===(v+1)%e.length:v+1>=e.length?!1:l===v+1}),[e.length,t]),Ft=d.useMemo(()=>Array.from({length:e.length},(i,l)=>()=>{const v=t?w.current%e.length:w.current;return t?l===(v-1+e.length)%e.length:v-1<0?!1:l===v-1}),[e.length,t]),Wt=d.useMemo(()=>`
|
|
2
2
|
[data-part-internal="${n}-Container"] {
|
|
3
3
|
display: flex;
|
|
4
4
|
width: 100%;
|
|
@@ -44,4 +44,4 @@
|
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
`).join(""):""}
|
|
47
|
-
`,[n,a,fe,e.length,t,I,s,o]);return{carouselFragment:M.jsxs("div",{ref:O,className:"ReactSpringCarouselContainer","data-part":"Container","data-part-internal":`${n}-Container`,...Kt(),children:[M.jsx("style",{dangerouslySetInnerHTML:{__html:Wt}}),M.jsx("div",{ref:D,className:"ReactSpringCarouselTrack","data-part":"Track","data-part-internal":`${n}-Track`,onScroll:()=>{S.current=!1,L.current=!1},children:Array.from({length:Vt},(i,l)=>{const v=t?l%e.length:l,g=e[v],C=t&&(l<e.length||l>=e.length*2);if(h!==void 0){const m=t?e.length+w.current%e.length:w.current;if(Math.abs(l-m)>h)return M.jsx("div",{className:"ReactSpringCarouselItem","data-part":"Item","data-part-internal":`${n}-Item`,"data-id":g.id,"aria-hidden":"true",children:E==null?void 0:E({item:g,index:l,isClonedItem:C})},`${g.id}-${l}`)}const b=
|
|
47
|
+
`,[n,a,fe,e.length,t,I,s,o]);return{carouselFragment:M.jsxs("div",{ref:O,className:"ReactSpringCarouselContainer","data-part":"Container","data-part-internal":`${n}-Container`,...Kt(),children:[M.jsx("style",{dangerouslySetInnerHTML:{__html:Wt}}),M.jsx("div",{ref:D,className:"ReactSpringCarouselTrack","data-part":"Track","data-part-internal":`${n}-Track`,onScroll:()=>{S.current=!1,L.current=!1},children:Array.from({length:Vt},(i,l)=>{const v=t?l%e.length:l,g=e[v],C=t&&(l<e.length||l>=e.length*2);if(h!==void 0){const m=t?e.length+w.current%e.length:w.current;if(Math.abs(l-m)>h)return M.jsx("div",{className:"ReactSpringCarouselItem","data-part":"Item","data-part-internal":`${n}-Item`,"data-id":g.id,"aria-hidden":"true",children:E==null?void 0:E({item:g,index:l,isClonedItem:C})},`${g.id}-${l}`)}const b=Gt[v],T=Ft[v];return M.jsx("div",{className:"ReactSpringCarouselItem","data-part":"Item","data-part-internal":`${n}-Item`,"data-id":g.id,children:typeof g.renderItem=="function"?g.renderItem({useListenToCustomEvent:Ne,index:l,isClonedItem:C,isActiveItem:zt,isNextItem:b,isPrevItem:T}):g.renderItem},`${g.id}-${l}`)})})]}),useListenToCustomEvent:Ne,slideToNextItem:()=>ce(),slideToPrevItem:()=>ue(),slideToItem:i=>{if(typeof i=="number"){if(!e[i]){console.warn(`The item you're trying to slide doesn't exist. index: ${i}`);return}i>w.current?ce(i):ue(i)}if(typeof i=="string"){const l=e.findIndex(v=>v.id===i);if(l<0){console.warn(`The item you're trying to slide doesn't exist. id: ${i}`);return}l>w.current?ce(l):ue(l)}}}}function Nt(r){let e=0;const t=getComputedStyle(r).getPropertyValue("gap");return t.includes("px")&&(e=Number(t.replace("px",""))),e}function Ae(r){return r.scrollWidth-r.clientWidth}function ie(r){const e=r.children[0],t=Nt(r);return e.getBoundingClientRect().width+t}function Lt({container:r,onReach:e}){const t=d.useRef("start"),n=d.useRef(0),[,s]=te.useSpring(()=>({x:0}));function o(u){s.start({from:{x:r.current.scrollLeft},to:{x:u},onChange({value:c}){r.current&&(r.current.scrollLeft=c.x)}})}function a(u){if(!r.current||u==="next"&&t.current==="end"||u==="prev"&&t.current==="start")return;let c=0;if(u==="next"&&(n.current+=1),u==="prev"&&(n.current-=1),c=n.current*ie(r.current),u==="next"){const p=Ae(r.current);c>p&&(t.current="end",c=p,e&&e("end"))}u==="prev"&&c<=0&&(t.current="start",n.current=0,c=0,e&&e("start")),o(c)}return d.useEffect(()=>{function u(){var O;const E=ie(r.current),I=((O=[...r.current.children].at(0))==null?void 0:O.getBoundingClientRect().width)||0,j=Array(r.current.childElementCount).fill(0).map((D,B)=>({index:B,start:E*B,end:E*(B+1)})),N=r.current.scrollLeft+I,$=j.find(D=>N>=D.start&&N<D.end);n.current=($==null?void 0:$.index)||0}function c(){s.stop()}function p(E){const I=E.target;I.scrollLeft===0?(n.current=0,t.current="start",e&&e("start")):I.scrollLeft>=Ae(I)?(t.current="end",e&&e("end")):t.current!=="idle"&&(t.current="idle",e&&e("idle"))}let f,_=0;function h(){_=r.current.scrollLeft,clearTimeout(f),f=setTimeout(function(){r.current.scrollLeft===_&&u()},200)}if(r.current)return r.current.addEventListener("wheel",c,{passive:!0}),r.current.addEventListener("scroll",p),r.current.addEventListener("scroll",h),()=>{r.current&&(r.current.removeEventListener("scroll",h),r.current.removeEventListener("scroll",p),r.current.removeEventListener("wheel",c))}},[r,e]),d.useEffect(()=>{if(r.current){const u=new ResizeObserver(()=>{o(n.current*ie(r.current))});return u.observe(r.current),()=>{u.disconnect()}}},[]),{scrollToNext(){a("next")},scrollToPrev(){a("prev")}}}P.useSpringCarousel=Mt,P.useSpringScroll=Lt,Object.defineProperty(P,Symbol.toStringTag,{value:"Module"})});
|