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.
- package/dist/index.cjs.js +1 -239
- package/dist/index.cjs2.js +1 -0
- package/dist/index.cjs3.js +5 -0
- package/dist/index.cjs4.js +1 -0
- package/dist/index.es.js +12 -0
- package/dist/index.es2.js +6 -0
- package/dist/index.es3.js +1087 -0
- package/dist/index.es4.js +254 -0
- package/dist/use-gesture-react.esm-662f7bb4.cjs +1 -0
- package/dist/use-gesture-react.esm-9eb8841a.js +1004 -0
- package/dist/useThumbsModule-08e90459.js +723 -0
- package/dist/useThumbsModule-f2f898fc.cjs +27 -0
- package/package.json +4 -4
- package/dist/index.cjs.js.map +0 -1
- package/dist/index.esm.js +0 -25598
- package/dist/index.esm.js.map +0 -1
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import { u as K, j as x } from "./useThumbsModule-08e90459.js";
|
|
2
|
+
import { useTransition as O, a as Q, config as U } from "@react-spring/web";
|
|
3
|
+
import { createContext as V, useRef as y, useState as X, useEffect as Y, useContext as Z } from "react";
|
|
4
|
+
import { u as P, a as L } from "./use-gesture-react.esm-9eb8841a.js";
|
|
5
|
+
const o = {
|
|
6
|
+
initial: {
|
|
7
|
+
opacity: 1,
|
|
8
|
+
position: "relative"
|
|
9
|
+
},
|
|
10
|
+
from: {
|
|
11
|
+
opacity: 0,
|
|
12
|
+
position: "relative"
|
|
13
|
+
},
|
|
14
|
+
enter: {
|
|
15
|
+
position: "relative",
|
|
16
|
+
opacity: 1
|
|
17
|
+
},
|
|
18
|
+
leave: {
|
|
19
|
+
opacity: 1,
|
|
20
|
+
position: "absolute"
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
function re({
|
|
24
|
+
init: c = !0,
|
|
25
|
+
disableGestures: w = !1,
|
|
26
|
+
items: r,
|
|
27
|
+
springConfig: N = U.default,
|
|
28
|
+
exitBeforeEnter: _ = !1,
|
|
29
|
+
trail: M,
|
|
30
|
+
withLoop: s = !1,
|
|
31
|
+
activeItem: a,
|
|
32
|
+
toPrevItemSpringProps: f = o,
|
|
33
|
+
toNextItemSpringProps: m = o,
|
|
34
|
+
draggingSlideTreshold: C = 50,
|
|
35
|
+
thumbsSlideAxis: $ = "x"
|
|
36
|
+
}) {
|
|
37
|
+
const l = y("next"), p = y("initial"), A = y(null), [n, b] = X(a ?? 0), { emitEvent: h, useListenToCustomEvent: T } = P(), { handleScroll: D, thumbsFragment: S } = K({
|
|
38
|
+
thumbsSlideAxis: $,
|
|
39
|
+
items: r,
|
|
40
|
+
renderThumbFnProps: {
|
|
41
|
+
getIsNextItem: j,
|
|
42
|
+
getIsPrevItem: k,
|
|
43
|
+
useListenToCustomEvent: T,
|
|
44
|
+
activeItem: {
|
|
45
|
+
index: n,
|
|
46
|
+
id: r[n].id
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
function W() {
|
|
51
|
+
return l.current === "prev" ? {
|
|
52
|
+
initial: {
|
|
53
|
+
...f.initial
|
|
54
|
+
},
|
|
55
|
+
from: {
|
|
56
|
+
...f.from
|
|
57
|
+
},
|
|
58
|
+
enter: {
|
|
59
|
+
...f.enter
|
|
60
|
+
},
|
|
61
|
+
leave: {
|
|
62
|
+
...f.leave
|
|
63
|
+
}
|
|
64
|
+
} : l.current === "next" ? {
|
|
65
|
+
initial: {
|
|
66
|
+
...m.initial
|
|
67
|
+
},
|
|
68
|
+
from: {
|
|
69
|
+
...m.from
|
|
70
|
+
},
|
|
71
|
+
enter: {
|
|
72
|
+
...m.enter
|
|
73
|
+
},
|
|
74
|
+
leave: {
|
|
75
|
+
...m.leave
|
|
76
|
+
}
|
|
77
|
+
} : {
|
|
78
|
+
initial: {
|
|
79
|
+
...o.initial
|
|
80
|
+
},
|
|
81
|
+
from: {
|
|
82
|
+
...o.from
|
|
83
|
+
},
|
|
84
|
+
enter: {
|
|
85
|
+
...o.enter
|
|
86
|
+
},
|
|
87
|
+
leave: {
|
|
88
|
+
...o.leave
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
Y(() => {
|
|
93
|
+
typeof a == "number" && a !== n && b(a);
|
|
94
|
+
}, [a]);
|
|
95
|
+
function v({ to: e, slideType: t, slideMode: i }) {
|
|
96
|
+
l.current = t, p.current = i, h({
|
|
97
|
+
eventName: "onSlideStartChange",
|
|
98
|
+
slideActionType: l.current,
|
|
99
|
+
slideMode: p.current,
|
|
100
|
+
nextItem: {
|
|
101
|
+
index: e,
|
|
102
|
+
id: r[e].id,
|
|
103
|
+
startReached: e === 0,
|
|
104
|
+
endReached: e === r.length - 1
|
|
105
|
+
}
|
|
106
|
+
}), b(e), D(n);
|
|
107
|
+
}
|
|
108
|
+
function R(e) {
|
|
109
|
+
if (!c)
|
|
110
|
+
return;
|
|
111
|
+
const t = n === 0;
|
|
112
|
+
!s && t || v(s && t ? {
|
|
113
|
+
to: r.length - 1,
|
|
114
|
+
slideType: "prev",
|
|
115
|
+
slideMode: e
|
|
116
|
+
} : {
|
|
117
|
+
to: n - 1,
|
|
118
|
+
slideType: "prev",
|
|
119
|
+
slideMode: e
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
function F(e) {
|
|
123
|
+
if (!c)
|
|
124
|
+
return;
|
|
125
|
+
const t = n === r.length - 1;
|
|
126
|
+
!s && t || v(s && t ? {
|
|
127
|
+
to: 0,
|
|
128
|
+
slideType: "next",
|
|
129
|
+
slideMode: e
|
|
130
|
+
} : {
|
|
131
|
+
to: n + 1,
|
|
132
|
+
slideType: "next",
|
|
133
|
+
slideMode: e
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
const q = O(n, {
|
|
137
|
+
config: N,
|
|
138
|
+
key: null,
|
|
139
|
+
trail: M,
|
|
140
|
+
exitBeforeEnter: _,
|
|
141
|
+
...W(),
|
|
142
|
+
onRest(e, t, i) {
|
|
143
|
+
e.finished && i === n && h({
|
|
144
|
+
eventName: "onSlideChange",
|
|
145
|
+
slideActionType: l.current,
|
|
146
|
+
slideMode: p.current,
|
|
147
|
+
currentItem: {
|
|
148
|
+
index: n,
|
|
149
|
+
id: r[n].id,
|
|
150
|
+
startReached: n === 0,
|
|
151
|
+
endReached: n === r.length - 1
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
}), z = L(
|
|
156
|
+
({ last: e, movement: [t] }) => {
|
|
157
|
+
if (e) {
|
|
158
|
+
const i = t > C, u = t < -C, d = n === 0, J = n === r.length - 1;
|
|
159
|
+
if (u) {
|
|
160
|
+
if (!s && J)
|
|
161
|
+
return;
|
|
162
|
+
h({
|
|
163
|
+
eventName: "onLeftSwipe"
|
|
164
|
+
}), F("swipe");
|
|
165
|
+
} else if (i) {
|
|
166
|
+
if (!s && d)
|
|
167
|
+
return;
|
|
168
|
+
h({
|
|
169
|
+
eventName: "onRightSwipe"
|
|
170
|
+
}), R("swipe");
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
enabled: !w
|
|
176
|
+
}
|
|
177
|
+
);
|
|
178
|
+
function E(e, t) {
|
|
179
|
+
let i = 0;
|
|
180
|
+
if (typeof e == "string" ? i = r.findIndex((u) => u.id === e) : i = e, i < 0 || i >= r.length) {
|
|
181
|
+
if (t)
|
|
182
|
+
throw new Error(t);
|
|
183
|
+
console.error(`The item doesn't exist; check that the id provided - ${e} - is correct.`), i = -1;
|
|
184
|
+
}
|
|
185
|
+
return i;
|
|
186
|
+
}
|
|
187
|
+
function j(e) {
|
|
188
|
+
const t = E(e, "The item doesn't exist; check the provided id."), i = n;
|
|
189
|
+
return s && i === r.length - 1 ? t === 0 : t === i + 1;
|
|
190
|
+
}
|
|
191
|
+
function k(e) {
|
|
192
|
+
const t = E(e, "The item doesn't exist; check the provided id."), i = n;
|
|
193
|
+
return s && i === 0 ? t === r.length - 1 : t === i - 1;
|
|
194
|
+
}
|
|
195
|
+
const B = q((e, t, i, u) => {
|
|
196
|
+
const d = r[t].renderItem;
|
|
197
|
+
return /* @__PURE__ */ x.jsx(
|
|
198
|
+
Q.div,
|
|
199
|
+
{
|
|
200
|
+
id: `use-transition-carousel-item-${u}`,
|
|
201
|
+
className: "use-transition-carousel-item",
|
|
202
|
+
style: {
|
|
203
|
+
...e,
|
|
204
|
+
flex: "1 0 100%",
|
|
205
|
+
width: "100%",
|
|
206
|
+
height: "100%"
|
|
207
|
+
},
|
|
208
|
+
children: typeof d == "function" ? d({
|
|
209
|
+
useListenToCustomEvent: T,
|
|
210
|
+
getIsNextItem: j,
|
|
211
|
+
getIsPrevItem: k,
|
|
212
|
+
activeItem: {
|
|
213
|
+
index: n,
|
|
214
|
+
id: r[n].id
|
|
215
|
+
}
|
|
216
|
+
}) : d
|
|
217
|
+
}
|
|
218
|
+
);
|
|
219
|
+
}), I = {
|
|
220
|
+
useListenToCustomEvent: T,
|
|
221
|
+
slideToPrevItem: () => R("click"),
|
|
222
|
+
slideToNextItem: () => F("click")
|
|
223
|
+
}, G = /* @__PURE__ */ x.jsx(g.Provider, { value: I, children: S }), H = /* @__PURE__ */ x.jsx(g.Provider, { value: I, children: /* @__PURE__ */ x.jsx(
|
|
224
|
+
"div",
|
|
225
|
+
{
|
|
226
|
+
ref: A,
|
|
227
|
+
...z(),
|
|
228
|
+
style: {
|
|
229
|
+
display: "flex",
|
|
230
|
+
position: "relative",
|
|
231
|
+
width: "100%",
|
|
232
|
+
height: "100%",
|
|
233
|
+
overflow: "hidden"
|
|
234
|
+
},
|
|
235
|
+
children: B
|
|
236
|
+
}
|
|
237
|
+
) });
|
|
238
|
+
return {
|
|
239
|
+
...I,
|
|
240
|
+
carouselFragment: H,
|
|
241
|
+
thumbsFragment: G
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
const g = V(void 0);
|
|
245
|
+
function se() {
|
|
246
|
+
const c = Z(g);
|
|
247
|
+
if (!c)
|
|
248
|
+
throw new Error("useTransitionCarouselContext must be used within the carousel.");
|
|
249
|
+
return c;
|
|
250
|
+
}
|
|
251
|
+
export {
|
|
252
|
+
re as useTransitionCarousel,
|
|
253
|
+
se as useTransitionCarouselContext
|
|
254
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const v=require("react"),P="RSC::Event";function nt(){const s=v.useRef(null);function t(n){v.useEffect(()=>{s.current||(s.current=document.createElement("div"));function r(i){n(i.detail)}if(s.current)return s.current.addEventListener(P,r,!1),()=>{var i;(i=s.current)==null||i.removeEventListener(P,r,!1)}},[n])}function e(n){if(s.current){const r=new CustomEvent(P,{detail:n});s.current.dispatchEvent(r)}}return{useListenToCustomEvent:t,emitEvent:e}}function rt(s,t,e){return Math.max(t,Math.min(s,e))}const d={toVector(s,t){return s===void 0&&(s=t),Array.isArray(s)?s:[s,s]},add(s,t){return[s[0]+t[0],s[1]+t[1]]},sub(s,t){return[s[0]-t[0],s[1]-t[1]]},addTo(s,t){s[0]+=t[0],s[1]+=t[1]},subTo(s,t){s[0]-=t[0],s[1]-=t[1]}};function M(s,t,e){return t===0||Math.abs(t)===1/0?Math.pow(s,e*5):s*t*e/(t+e*s)}function N(s,t,e,n=.15){return n===0?rt(s,t,e):s<t?-M(t-s,e-t,n)+t:s>e?+M(s-e,e-t,n)+e:s}function it(s,[t,e],[n,r]){const[[i,o],[c,f]]=s;return[N(t,i,o,n),N(e,c,f,r)]}function ot(s,t){if(typeof s!="object"||s===null)return s;var e=s[Symbol.toPrimitive];if(e!==void 0){var n=e.call(s,t||"default");if(typeof n!="object")return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(s)}function at(s){var t=ot(s,"string");return typeof t=="symbol"?t:String(t)}function l(s,t,e){return t=at(t),t in s?Object.defineProperty(s,t,{value:e,enumerable:!0,configurable:!0,writable:!0}):s[t]=e,s}function U(s,t){var e=Object.keys(s);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(s);t&&(n=n.filter(function(r){return Object.getOwnPropertyDescriptor(s,r).enumerable})),e.push.apply(e,n)}return e}function u(s){for(var t=1;t<arguments.length;t++){var e=arguments[t]!=null?arguments[t]:{};t%2?U(Object(e),!0).forEach(function(n){l(s,n,e[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(s,Object.getOwnPropertyDescriptors(e)):U(Object(e)).forEach(function(n){Object.defineProperty(s,n,Object.getOwnPropertyDescriptor(e,n))})}return s}const H={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 K(s){return s?s[0].toUpperCase()+s.slice(1):""}const ct=["enter","leave"];function ut(s=!1,t){return s&&!ct.includes(t)}function ft(s,t="",e=!1){const n=H[s],r=n&&n[t]||t;return"on"+K(s)+K(r)+(ut(e,r)?"Capture":"")}const ht=["gotpointercapture","lostpointercapture"];function dt(s){let t=s.substring(2).toLowerCase();const e=!!~t.indexOf("passive");e&&(t=t.replace("passive",""));const n=ht.includes(t)?"capturecapture":"capture",r=!!~t.indexOf(n);return r&&(t=t.replace("capture","")),{device:t,capture:r,passive:e}}function lt(s,t=""){const e=H[s],n=e&&e[t]||t;return s+n}function A(s){return"touches"in s}function G(s){return A(s)?"touch":"pointerType"in s?s.pointerType:"mouse"}function pt(s){return Array.from(s.touches).filter(t=>{var e,n;return t.target===s.currentTarget||((e=s.currentTarget)===null||e===void 0||(n=e.contains)===null||n===void 0?void 0:n.call(e,t.target))})}function mt(s){return s.type==="touchend"||s.type==="touchcancel"?s.changedTouches:s.targetTouches}function X(s){return A(s)?mt(s)[0]:s}function gt(s){return pt(s).map(t=>t.identifier)}function x(s){const t=X(s);return A(s)?t.identifier:t.pointerId}function R(s){const t=X(s);return[t.clientX,t.clientY]}function _t(s){const t={};if("buttons"in s&&(t.buttons=s.buttons),"shiftKey"in s){const{shiftKey:e,altKey:n,metaKey:r,ctrlKey:i}=s;Object.assign(t,{shiftKey:e,altKey:n,metaKey:r,ctrlKey:i})}return t}function O(s,...t){return typeof s=="function"?s(...t):s}function yt(){}function vt(...s){return s.length===0?yt:s.length===1?s[0]:function(){let t;for(const e of s)t=e.apply(this,arguments)||t;return t}}function V(s,t){return Object.assign({},t,s||{})}const bt=32;class wt{constructor(t,e,n){this.ctrl=t,this.args=e,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(t){this.ctrl.state[this.key]=t}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:t,shared:e,ingKey:n,args:r}=this;e[n]=t._active=t.active=t._blocked=t._force=!1,t._step=[!1,!1],t.intentional=!1,t._movement=[0,0],t._distance=[0,0],t._direction=[0,0],t._delta=[0,0],t._bounds=[[-1/0,1/0],[-1/0,1/0]],t.args=r,t.axis=void 0,t.memo=void 0,t.elapsedTime=t.timeDelta=0,t.direction=[0,0],t.distance=[0,0],t.overflow=[0,0],t._movementBound=[!1,!1],t.velocity=[0,0],t.movement=[0,0],t.delta=[0,0],t.timeStamp=0}start(t){const e=this.state,n=this.config;e._active||(this.reset(),this.computeInitial(),e._active=!0,e.target=t.target,e.currentTarget=t.currentTarget,e.lastOffset=n.from?O(n.from,e):e.offset,e.offset=e.lastOffset,e.startTime=e.timeStamp=t.timeStamp)}computeValues(t){const e=this.state;e._values=t,e.values=this.config.transform(t)}computeInitial(){const t=this.state;t._initial=t._values,t.initial=t.values}compute(t){const{state:e,config:n,shared:r}=this;e.args=this.args;let i=0;if(t&&(e.event=t,n.preventDefault&&t.cancelable&&e.event.preventDefault(),e.type=t.type,r.touches=this.ctrl.pointerIds.size||this.ctrl.touchIds.size,r.locked=!!document.pointerLockElement,Object.assign(r,_t(t)),r.down=r.pressed=r.buttons%2===1||r.touches>0,i=t.timeStamp-e.timeStamp,e.timeStamp=t.timeStamp,e.elapsedTime=e.timeStamp-e.startTime),e._active){const _=e._delta.map(Math.abs);d.addTo(e._distance,_)}this.axisIntent&&this.axisIntent(t);const[o,c]=e._movement,[f,h]=n.threshold,{_step:a,values:g}=e;if(n.hasCustomTransform?(a[0]===!1&&(a[0]=Math.abs(o)>=f&&g[0]),a[1]===!1&&(a[1]=Math.abs(c)>=h&&g[1])):(a[0]===!1&&(a[0]=Math.abs(o)>=f&&Math.sign(o)*f),a[1]===!1&&(a[1]=Math.abs(c)>=h&&Math.sign(c)*h)),e.intentional=a[0]!==!1||a[1]!==!1,!e.intentional)return;const p=[0,0];if(n.hasCustomTransform){const[_,st]=g;p[0]=a[0]!==!1?_-a[0]:0,p[1]=a[1]!==!1?st-a[1]:0}else p[0]=a[0]!==!1?o-a[0]:0,p[1]=a[1]!==!1?c-a[1]:0;this.restrictToAxis&&!e._blocked&&this.restrictToAxis(p);const E=e.offset,T=e._active&&!e._blocked||e.active;T&&(e.first=e._active&&!e.active,e.last=!e._active&&e.active,e.active=r[this.ingKey]=e._active,t&&(e.first&&("bounds"in n&&(e._bounds=O(n.bounds,e)),this.setup&&this.setup()),e.movement=p,this.computeOffset()));const[D,S]=e.offset,[[I,Q],[Z,tt]]=e._bounds;e.overflow=[D<I?-1:D>Q?1:0,S<Z?-1:S>tt?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;const et=e._active?n.rubberband||[0,0]:[0,0];if(e.offset=it(e._bounds,e.offset,et),e.delta=d.sub(e.offset,E),this.computeMovement(),T&&(!e.last||i>bt)){e.delta=d.sub(e.offset,E);const _=e.delta.map(Math.abs);d.addTo(e.distance,_),e.direction=e.delta.map(Math.sign),e._direction=e._delta.map(Math.sign),!e.first&&i>0&&(e.velocity=[_[0]/i,_[1]/i],e.timeDelta=i)}}emit(){const t=this.state,e=this.shared,n=this.config;if(t._active||this.clean(),(t._blocked||!t.intentional)&&!t._force&&!n.triggerAllEvents)return;const r=this.handler(u(u(u({},e),t),{},{[this.aliasKey]:t.values}));r!==void 0&&(t.memo=r)}clean(){this.eventStore.clean(),this.timeoutStore.clean()}}function Et([s,t],e){const n=Math.abs(s),r=Math.abs(t);if(n>r&&n>e)return"x";if(r>n&&r>e)return"y"}class Tt extends wt{constructor(...t){super(...t),l(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=d.add(this.state.lastOffset,this.state.movement)}computeMovement(){this.state.movement=d.sub(this.state.offset,this.state.lastOffset)}axisIntent(t){const e=this.state,n=this.config;if(!e.axis&&t){const r=typeof n.axisThreshold=="object"?n.axisThreshold[G(t)]:n.axisThreshold;e.axis=Et(e._movement,r)}e._blocked=(n.lockDirection||!!n.axis)&&!e.axis||!!n.axis&&n.axis!==e.axis}restrictToAxis(t){if(this.config.axis||this.config.lockDirection)switch(this.state.axis){case"x":t[1]=0;break;case"y":t[0]=0;break}}}const j=s=>s,B=.15,L={enabled(s=!0){return s},eventOptions(s,t,e){return u(u({},e.shared.eventOptions),s)},preventDefault(s=!1){return s},triggerAllEvents(s=!1){return s},rubberband(s=0){switch(s){case!0:return[B,B];case!1:return[0,0];default:return d.toVector(s)}},from(s){if(typeof s=="function")return s;if(s!=null)return d.toVector(s)},transform(s,t,e){const n=s||e.shared.transform;if(this.hasCustomTransform=!!n,process.env.NODE_ENV==="development"){const r=n||j;return i=>{const o=r(i);return(!isFinite(o[0])||!isFinite(o[1]))&&console.warn(`[@use-gesture]: config.transform() must produce a valid result, but it was: [${o[0]},${[1]}]`),o}}return n||j},threshold(s){return d.toVector(s,0)}};process.env.NODE_ENV==="development"&&Object.assign(L,{domTarget(s){if(s!==void 0)throw Error("[@use-gesture]: `domTarget` option has been renamed to `target`.");return NaN},lockDirection(s){if(s!==void 0)throw Error("[@use-gesture]: `lockDirection` option has been merged with `axis`. Use it as in `{ axis: 'lock' }`");return NaN},initial(s){if(s!==void 0)throw Error("[@use-gesture]: `initial` option has been renamed to `from`.");return NaN}});const Dt=0,b=u(u({},L),{},{axis(s,t,{axis:e}){if(this.lockDirection=e==="lock",!this.lockDirection)return e},axisThreshold(s=Dt){return s},bounds(s={}){if(typeof s=="function")return i=>b.bounds(s(i));if("current"in s)return()=>s.current;if(typeof HTMLElement=="function"&&s instanceof HTMLElement)return s;const{left:t=-1/0,right:e=1/0,top:n=-1/0,bottom:r=1/0}=s;return[[t,e],[n,r]]}}),Y={ArrowRight:(s,t=1)=>[s*t,0],ArrowLeft:(s,t=1)=>[-1*s*t,0],ArrowUp:(s,t=1)=>[0,-1*s*t],ArrowDown:(s,t=1)=>[0,s*t]};class St extends Tt{constructor(...t){super(...t),l(this,"ingKey","dragging")}reset(){super.reset();const t=this.state;t._pointerId=void 0,t._pointerActive=!1,t._keyboardActive=!1,t._preventScroll=!1,t._delayed=!1,t.swipe=[0,0],t.tap=!1,t.canceled=!1,t.cancel=this.cancel.bind(this)}setup(){const t=this.state;if(t._bounds instanceof HTMLElement){const e=t._bounds.getBoundingClientRect(),n=t.currentTarget.getBoundingClientRect(),r={left:e.left-n.left+t.offset[0],right:e.right-n.right+t.offset[0],top:e.top-n.top+t.offset[1],bottom:e.bottom-n.bottom+t.offset[1]};t._bounds=b.bounds(r)}}cancel(){const t=this.state;t.canceled||(t.canceled=!0,t._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(t){const e=this.config,n=this.state;if(t.buttons!=null&&(Array.isArray(e.pointerButtons)?!e.pointerButtons.includes(t.buttons):e.pointerButtons!==-1&&e.pointerButtons!==t.buttons))return;const r=this.ctrl.setEventIds(t);e.pointerCapture&&t.target.setPointerCapture(t.pointerId),!(r&&r.size>1&&n._pointerActive)&&(this.start(t),this.setupPointer(t),n._pointerId=x(t),n._pointerActive=!0,this.computeValues(R(t)),this.computeInitial(),e.preventScrollAxis&&G(t)!=="mouse"?(n._active=!1,this.setupScrollPrevention(t)):e.delay>0?(this.setupDelayTrigger(t),e.triggerAllEvents&&(this.compute(t),this.emit())):this.startPointerDrag(t))}startPointerDrag(t){const e=this.state;e._active=!0,e._preventScroll=!0,e._delayed=!1,this.compute(t),this.emit()}pointerMove(t){const e=this.state,n=this.config;if(!e._pointerActive||e.type===t.type&&t.timeStamp===e.timeStamp)return;const r=x(t);if(e._pointerId!==void 0&&r!==e._pointerId)return;const i=R(t);if(document.pointerLockElement===t.target?e._delta=[t.movementX,t.movementY]:(e._delta=d.sub(i,e._values),this.computeValues(i)),d.addTo(e._movement,e._delta),this.compute(t),e._delayed&&e.intentional){this.timeoutStore.remove("dragDelay"),e.active=!1,this.startPointerDrag(t);return}if(n.preventScrollAxis&&!e._preventScroll)if(e.axis)if(e.axis===n.preventScrollAxis||n.preventScrollAxis==="xy"){e._active=!1,this.clean();return}else{this.timeoutStore.remove("startPointerDrag"),this.startPointerDrag(t);return}else return;this.emit()}pointerUp(t){this.ctrl.setEventIds(t);try{this.config.pointerCapture&&t.target.hasPointerCapture(t.pointerId)&&t.target.releasePointerCapture(t.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 e=this.state,n=this.config;if(!e._active||!e._pointerActive)return;const r=x(t);if(e._pointerId!==void 0&&r!==e._pointerId)return;this.state._pointerActive=!1,this.setActive(),this.compute(t);const[i,o]=e._distance;if(e.tap=i<=n.tapsThreshold&&o<=n.tapsThreshold,e.tap&&n.filterTaps)e._force=!0;else{const[c,f]=e._delta,[h,a]=e._movement,[g,p]=n.swipe.velocity,[E,T]=n.swipe.distance,D=n.swipe.duration;if(e.elapsedTime<D){const S=Math.abs(c/e.timeDelta),I=Math.abs(f/e.timeDelta);S>g&&Math.abs(h)>E&&(e.swipe[0]=Math.sign(c)),I>p&&Math.abs(a)>T&&(e.swipe[1]=Math.sign(f))}}this.emit()}pointerClick(t){!this.state.tap&&t.detail>0&&(t.preventDefault(),t.stopPropagation())}setupPointer(t){const e=this.config,n=e.device;if(process.env.NODE_ENV==="development")try{if(n==="pointer"&&e.preventScrollDelay===void 0){const r="uv"in t?t.sourceEvent.currentTarget:t.currentTarget;window.getComputedStyle(r).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.",r)}}catch{}e.pointerLock&&t.currentTarget.requestPointerLock(),e.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(t){this.state._preventScroll&&t.cancelable&&t.preventDefault()}setupScrollPrevention(t){this.state._preventScroll=!1,kt(t);const e=this.eventStore.add(this.sharedConfig.window,"touch","change",this.preventScroll.bind(this),{passive:!1});this.eventStore.add(this.sharedConfig.window,"touch","end",e),this.eventStore.add(this.sharedConfig.window,"touch","cancel",e),this.timeoutStore.add("startPointerDrag",this.startPointerDrag.bind(this),this.config.preventScrollDelay,t)}setupDelayTrigger(t){this.state._delayed=!0,this.timeoutStore.add("dragDelay",()=>{this.state._step=[0,0],this.startPointerDrag(t)},this.config.delay)}keyDown(t){const e=Y[t.key];if(e){const n=this.state,r=t.shiftKey?10:t.altKey?.1:1;this.start(t),n._delta=e(this.config.keyboardDisplacement,r),n._keyboardActive=!0,d.addTo(n._movement,n._delta),this.compute(t),this.emit()}}keyUp(t){t.key in Y&&(this.state._keyboardActive=!1,this.setActive(),this.compute(t),this.emit())}bind(t){const e=this.config.device;t(e,"start",this.pointerDown.bind(this)),this.config.pointerCapture&&(t(e,"change",this.pointerMove.bind(this)),t(e,"end",this.pointerUp.bind(this)),t(e,"cancel",this.pointerUp.bind(this)),t("lostPointerCapture","",this.pointerUp.bind(this))),this.config.keys&&(t("key","down",this.keyDown.bind(this)),t("key","up",this.keyUp.bind(this))),this.config.filterTaps&&t("click","",this.pointerClick.bind(this),{capture:!0,passive:!1})}}function kt(s){"persist"in s&&typeof s.persist=="function"&&s.persist()}const w=typeof window<"u"&&window.document&&window.document.createElement;function Ot(){return w&&"ontouchstart"in window}function W(){return Ot()||w&&window.navigator.maxTouchPoints>1}function At(){return w&&"onpointerdown"in window}function It(){return w&&"exitPointerLock"in window.document}function Pt(){try{return"constructor"in GestureEvent}catch{return!1}}const m={isBrowser:w,gesture:Pt(),touch:W(),touchscreen:W(),pointer:At(),pointerLock:It()},xt=250,Ct=180,Lt=.5,Mt=50,Nt=250,Ut=10,F={mouse:0,touch:0,pen:8},z=u(u({},b),{},{device(s,t,{pointer:{touch:e=!1,lock:n=!1,mouse:r=!1}={}}){return this.pointerLock=n&&m.pointerLock,m.touch&&e?"touch":this.pointerLock?"mouse":m.pointer&&!r?"pointer":m.touch?"touch":"mouse"},preventScrollAxis(s,t,{preventScroll:e}){if(this.preventScrollDelay=typeof e=="number"?e:e||e===void 0&&s?xt:void 0,!(!m.touchscreen||e===!1))return s||(e!==void 0?"y":void 0)},pointerCapture(s,t,{pointer:{capture:e=!0,buttons:n=1,keys:r=!0}={}}){return this.pointerButtons=n,this.keys=r,!this.pointerLock&&this.device==="pointer"&&e},threshold(s,t,{filterTaps:e=!1,tapsThreshold:n=3,axis:r=void 0}){const i=d.toVector(s,e?n:r?1:0);return this.filterTaps=e,this.tapsThreshold=n,i},swipe({velocity:s=Lt,distance:t=Mt,duration:e=Nt}={}){return{velocity:this.transform(d.toVector(s)),distance:this.transform(d.toVector(t)),duration:e}},delay(s=0){switch(s){case!0:return Ct;case!1:return 0;default:return s}},axisThreshold(s){return s?u(u({},F),s):F},keyboardDisplacement(s=Ut){return s}});process.env.NODE_ENV==="development"&&Object.assign(z,{useTouch(s){if(s!==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(s){if(s!==void 0)throw Error("[@use-gesture]: `experimental_preventWindowScrollY` option has been renamed to `preventScroll`.");return NaN},swipeVelocity(s){if(s!==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(s){if(s!==void 0)throw Error("[@use-gesture]: `swipeDistance` option has been renamed to `swipe.distance`. Use it as in `{ swipe: { distance: 50 } }`.");return NaN},swipeDuration(s){if(s!==void 0)throw Error("[@use-gesture]: `swipeDuration` option has been renamed to `swipe.duration`. Use it as in `{ swipe: { duration: 250 } }`.");return NaN}});u(u({},L),{},{device(s,t,{shared:e,pointer:{touch:n=!1}={}}){if(e.target&&!m.touch&&m.gesture)return"gesture";if(m.touch&&n)return"touch";if(m.touchscreen){if(m.pointer)return"pointer";if(m.touch)return"touch"}},bounds(s,t,{scaleBounds:e={},angleBounds:n={}}){const r=o=>{const c=V(O(e,o),{min:-1/0,max:1/0});return[c.min,c.max]},i=o=>{const c=V(O(n,o),{min:-1/0,max:1/0});return[c.min,c.max]};return typeof e!="function"&&typeof n!="function"?[r(),i()]:o=>[r(o),i(o)]},threshold(s,t,e){return this.lockDirection=e.axis==="lock",d.toVector(s,this.lockDirection?[.1,3]:0)},modifierKey(s){return s===void 0?"ctrlKey":s},pinchOnWheel(s=!0){return s}});u(u({},b),{},{mouseOnly:(s=!0)=>s});u(u({},b),{},{mouseOnly:(s=!0)=>s});const q=new Map,C=new Map;function Kt(s){q.set(s.key,s.engine),C.set(s.key,s.resolver)}const Rt={key:"drag",engine:St,resolver:z};function Vt(s,t){if(s==null)return{};var e={},n=Object.keys(s),r,i;for(i=0;i<n.length;i++)r=n[i],!(t.indexOf(r)>=0)&&(e[r]=s[r]);return e}function jt(s,t){if(s==null)return{};var e=Vt(s,t),n,r;if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(s);for(r=0;r<i.length;r++)n=i[r],!(t.indexOf(n)>=0)&&Object.prototype.propertyIsEnumerable.call(s,n)&&(e[n]=s[n])}return e}const Bt={target(s){if(s)return()=>"current"in s?s.current:s},enabled(s=!0){return s},window(s=m.isBrowser?window:void 0){return s},eventOptions({passive:s=!0,capture:t=!1}={}){return{passive:s,capture:t}},transform(s){return s}},Yt=["target","eventOptions","window","enabled","transform"];function k(s={},t){const e={};for(const[n,r]of Object.entries(t))switch(typeof r){case"function":if(process.env.NODE_ENV==="development"){const i=r.call(e,s[n],n,s);Number.isNaN(i)||(e[n]=i)}else e[n]=r.call(e,s[n],n,s);break;case"object":e[n]=k(s[n],r);break;case"boolean":r&&(e[n]=s[n]);break}return e}function Wt(s,t,e={}){const n=s,{target:r,eventOptions:i,window:o,enabled:c,transform:f}=n,h=jt(n,Yt);if(e.shared=k({target:r,eventOptions:i,window:o,enabled:c,transform:f},Bt),t){const a=C.get(t);e[t]=k(u({shared:e.shared},h),a)}else for(const a in h){const g=C.get(a);if(g)e[a]=k(u({shared:e.shared},h[a]),g);else if(process.env.NODE_ENV==="development"&&!["drag","pinch","scroll","wheel","move","hover"].includes(a)){if(a==="domTarget")throw Error("[@use-gesture]: `domTarget` option has been renamed to `target`.");console.warn(`[@use-gesture]: Unknown config key \`${a}\` was used. Please read the documentation for further information.`)}}return e}class J{constructor(t,e){l(this,"_listeners",new Set),this._ctrl=t,this._gestureKey=e}add(t,e,n,r,i){const o=this._listeners,c=lt(e,n),f=this._gestureKey?this._ctrl.config[this._gestureKey].eventOptions:{},h=u(u({},f),i);t.addEventListener(c,r,h);const a=()=>{t.removeEventListener(c,r,h),o.delete(a)};return o.add(a),a}clean(){this._listeners.forEach(t=>t()),this._listeners.clear()}}class Ft{constructor(){l(this,"_timeouts",new Map)}add(t,e,n=140,...r){this.remove(t),this._timeouts.set(t,window.setTimeout(e,n,...r))}remove(t){const e=this._timeouts.get(t);e&&window.clearTimeout(e)}clean(){this._timeouts.forEach(t=>void window.clearTimeout(t)),this._timeouts.clear()}}class $t{constructor(t){l(this,"gestures",new Set),l(this,"_targetEventStore",new J(this)),l(this,"gestureEventStores",{}),l(this,"gestureTimeoutStores",{}),l(this,"handlers",{}),l(this,"config",{}),l(this,"pointerIds",new Set),l(this,"touchIds",new Set),l(this,"state",{shared:{shiftKey:!1,metaKey:!1,ctrlKey:!1,altKey:!1}}),Ht(this,t)}setEventIds(t){if(A(t))return this.touchIds=new Set(gt(t)),this.touchIds;if("pointerId"in t)return t.type==="pointerup"||t.type==="pointercancel"?this.pointerIds.delete(t.pointerId):t.type==="pointerdown"&&this.pointerIds.add(t.pointerId),this.pointerIds}applyHandlers(t,e){this.handlers=t,this.nativeHandlers=e}applyConfig(t,e){this.config=Wt(t,e,this.config)}clean(){this._targetEventStore.clean();for(const t of this.gestures)this.gestureEventStores[t].clean(),this.gestureTimeoutStores[t].clean()}effect(){return this.config.shared.target&&this.bind(),()=>this._targetEventStore.clean()}bind(...t){const e=this.config.shared,n={};let r;if(!(e.target&&(r=e.target(),!r))){if(e.enabled){for(const o of this.gestures){const c=this.config[o],f=$(n,c.eventOptions,!!r);if(c.enabled){const h=q.get(o);new h(this,t,o).bind(f)}}const i=$(n,e.eventOptions,!!r);for(const o in this.nativeHandlers)i(o,"",c=>this.nativeHandlers[o](u(u({},this.state.shared),{},{event:c,args:t})),void 0,!0)}for(const i in n)n[i]=vt(...n[i]);if(!r)return n;for(const i in n){const{device:o,capture:c,passive:f}=dt(i);this._targetEventStore.add(r,o,"",n[i],{capture:c,passive:f})}}}}function y(s,t){s.gestures.add(t),s.gestureEventStores[t]=new J(s,t),s.gestureTimeoutStores[t]=new Ft}function Ht(s,t){t.drag&&y(s,"drag"),t.wheel&&y(s,"wheel"),t.scroll&&y(s,"scroll"),t.move&&y(s,"move"),t.pinch&&y(s,"pinch"),t.hover&&y(s,"hover")}const $=(s,t,e)=>(n,r,i,o={},c=!1)=>{var f,h;const a=(f=o.capture)!==null&&f!==void 0?f:t.capture,g=(h=o.passive)!==null&&h!==void 0?h:t.passive;let p=c?n:ft(n,r,a);e&&g&&(p+="Passive"),s[p]=s[p]||[],s[p].push(i)};function Gt(s,t={},e,n){const r=v.useMemo(()=>new $t(s),[]);if(r.applyHandlers(s,n),r.applyConfig(t,e),v.useEffect(r.effect.bind(r)),v.useEffect(()=>r.clean.bind(r),[]),t.target===void 0)return r.bind.bind(r)}function Xt(s,t){return Kt(Rt),Gt({drag:s},t||{},"drag")}exports.useDrag=Xt;exports.useEventsModule=nt;
|