@react-three/drei 11.0.0-alpha.1 → 11.0.0-alpha.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.
Files changed (119) hide show
  1. package/core/index.d.mts +1858 -0
  2. package/core/index.d.ts +1858 -0
  3. package/core/index.mjs +8559 -0
  4. package/experimental/index.d.mts +222 -0
  5. package/experimental/index.d.ts +222 -0
  6. package/experimental/index.mjs +353 -0
  7. package/external/index.d.mts +464 -0
  8. package/external/index.d.ts +464 -0
  9. package/external/index.mjs +5079 -0
  10. package/index.d.mts +1746 -2147
  11. package/index.d.ts +2166 -0
  12. package/index.mjs +12940 -19766
  13. package/legacy/index.d.mts +2350 -0
  14. package/legacy/index.d.ts +2350 -0
  15. package/legacy/index.mjs +12325 -0
  16. package/native/index.d.mts +2515 -0
  17. package/native/index.d.ts +2515 -0
  18. package/native/index.mjs +12383 -0
  19. package/package.json +18 -15
  20. package/webgpu/index.d.mts +2514 -0
  21. package/webgpu/index.d.ts +2514 -0
  22. package/webgpu/index.mjs +12547 -0
  23. package/_chunks/hls.mjs +0 -3
  24. package/_chunks/libs/@mediapipe/tasks-vision.mjs +0 -4781
  25. package/_chunks/libs/@monogrid/gainmap-js.mjs +0 -1137
  26. package/_chunks/libs/@use-gesture/core.mjs +0 -1650
  27. package/_chunks/libs/@use-gesture/react.mjs +0 -207
  28. package/_chunks/libs/camera-controls.mjs +0 -2207
  29. package/_chunks/libs/detect-gpu.mjs +0 -515
  30. package/_chunks/libs/hls.js.mjs +0 -21925
  31. package/_chunks/libs/maath.mjs +0 -5200
  32. package/_chunks/libs/stats-gl.mjs +0 -301
  33. package/_chunks/libs/stats.js.mjs +0 -90
  34. package/_chunks/libs/suspend-react.mjs +0 -60
  35. package/_chunks/libs/three.mjs +0 -23169
  36. package/_chunks/libs/tunnel-rat.mjs +0 -458
  37. package/_chunks/libs/zustand.mjs +0 -104
  38. package/_chunks/rolldown-runtime.mjs +0 -47
  39. package/_chunks/vision_bundle.mjs +0 -3
  40. package/core/_chunks/hls.mjs +0 -3
  41. package/core/_chunks/libs/@monogrid/gainmap-js.mjs +0 -1137
  42. package/core/_chunks/libs/@use-gesture/core.mjs +0 -1650
  43. package/core/_chunks/libs/@use-gesture/react.mjs +0 -207
  44. package/core/_chunks/libs/detect-gpu.mjs +0 -515
  45. package/core/_chunks/libs/hls.js.mjs +0 -21925
  46. package/core/_chunks/libs/maath.mjs +0 -5200
  47. package/core/_chunks/libs/stats-gl.mjs +0 -301
  48. package/core/_chunks/libs/stats.js.mjs +0 -90
  49. package/core/_chunks/libs/suspend-react.mjs +0 -60
  50. package/core/_chunks/libs/three.mjs +0 -22457
  51. package/core/_chunks/libs/tunnel-rat.mjs +0 -458
  52. package/core/_chunks/libs/zustand.mjs +0 -104
  53. package/core/_chunks/rolldown-runtime.mjs +0 -47
  54. package/core/core/index.d.mts +0 -2232
  55. package/core/core/index.mjs +0 -11082
  56. package/experimental/_chunks/libs/three.mjs +0 -15386
  57. package/experimental/experimental/index.d.mts +0 -253
  58. package/experimental/experimental/index.mjs +0 -434
  59. package/external/_chunks/hls.mjs +0 -3
  60. package/external/_chunks/libs/@mediapipe/tasks-vision.mjs +0 -4781
  61. package/external/_chunks/libs/camera-controls.mjs +0 -2207
  62. package/external/_chunks/libs/hls.js.mjs +0 -21925
  63. package/external/_chunks/libs/maath.mjs +0 -5200
  64. package/external/_chunks/libs/suspend-react.mjs +0 -58
  65. package/external/_chunks/libs/three.mjs +0 -15387
  66. package/external/_chunks/rolldown-runtime.mjs +0 -32
  67. package/external/_chunks/vision_bundle.mjs +0 -3
  68. package/external/external/index.d.mts +0 -499
  69. package/external/external/index.mjs +0 -9422
  70. package/legacy/_chunks/hls.mjs +0 -3
  71. package/legacy/_chunks/libs/@monogrid/gainmap-js.mjs +0 -1137
  72. package/legacy/_chunks/libs/@use-gesture/core.mjs +0 -1650
  73. package/legacy/_chunks/libs/@use-gesture/react.mjs +0 -207
  74. package/legacy/_chunks/libs/bidi-js.mjs +0 -675
  75. package/legacy/_chunks/libs/detect-gpu.mjs +0 -515
  76. package/legacy/_chunks/libs/hls.js.mjs +0 -21925
  77. package/legacy/_chunks/libs/maath.mjs +0 -5200
  78. package/legacy/_chunks/libs/stats-gl.mjs +0 -301
  79. package/legacy/_chunks/libs/stats.js.mjs +0 -90
  80. package/legacy/_chunks/libs/suspend-react.mjs +0 -60
  81. package/legacy/_chunks/libs/three.mjs +0 -26062
  82. package/legacy/_chunks/libs/troika-three-text.mjs +0 -6494
  83. package/legacy/_chunks/libs/tunnel-rat.mjs +0 -458
  84. package/legacy/_chunks/libs/zustand.mjs +0 -104
  85. package/legacy/_chunks/rolldown-runtime.mjs +0 -47
  86. package/legacy/legacy/index.d.mts +0 -2788
  87. package/legacy/legacy/index.mjs +0 -14984
  88. package/native/_chunks/hls.mjs +0 -3
  89. package/native/_chunks/libs/@monogrid/gainmap-js.mjs +0 -1137
  90. package/native/_chunks/libs/@use-gesture/core.mjs +0 -1650
  91. package/native/_chunks/libs/@use-gesture/react.mjs +0 -207
  92. package/native/_chunks/libs/detect-gpu.mjs +0 -515
  93. package/native/_chunks/libs/hls.js.mjs +0 -21925
  94. package/native/_chunks/libs/maath.mjs +0 -5200
  95. package/native/_chunks/libs/stats-gl.mjs +0 -301
  96. package/native/_chunks/libs/stats.js.mjs +0 -90
  97. package/native/_chunks/libs/suspend-react.mjs +0 -60
  98. package/native/_chunks/libs/three.mjs +0 -22592
  99. package/native/_chunks/libs/tunnel-rat.mjs +0 -458
  100. package/native/_chunks/libs/zustand.mjs +0 -104
  101. package/native/_chunks/rolldown-runtime.mjs +0 -47
  102. package/native/native/index.d.mts +0 -3168
  103. package/native/native/index.mjs +0 -14863
  104. package/webgpu/_chunks/hls.mjs +0 -3
  105. package/webgpu/_chunks/libs/@monogrid/gainmap-js.mjs +0 -1137
  106. package/webgpu/_chunks/libs/@use-gesture/core.mjs +0 -1650
  107. package/webgpu/_chunks/libs/@use-gesture/react.mjs +0 -207
  108. package/webgpu/_chunks/libs/detect-gpu.mjs +0 -515
  109. package/webgpu/_chunks/libs/hls.js.mjs +0 -21925
  110. package/webgpu/_chunks/libs/maath.mjs +0 -5200
  111. package/webgpu/_chunks/libs/stats-gl.mjs +0 -301
  112. package/webgpu/_chunks/libs/stats.js.mjs +0 -90
  113. package/webgpu/_chunks/libs/suspend-react.mjs +0 -60
  114. package/webgpu/_chunks/libs/three.mjs +0 -22592
  115. package/webgpu/_chunks/libs/tunnel-rat.mjs +0 -458
  116. package/webgpu/_chunks/libs/zustand.mjs +0 -104
  117. package/webgpu/_chunks/rolldown-runtime.mjs +0 -47
  118. package/webgpu/webgpu/index.d.mts +0 -3166
  119. package/webgpu/webgpu/index.mjs +0 -15015
@@ -1,1650 +0,0 @@
1
- import { n as __esmMin, r as __export, t as __commonJSMin } from "../../rolldown-runtime.mjs";
2
-
3
- //#region node_modules/@use-gesture/core/dist/maths-0ab39ae9.esm.js
4
- function clamp(v, min, max) {
5
- return Math.max(min, Math.min(v, max));
6
- }
7
- function rubberband(distance, dimension, constant) {
8
- if (dimension === 0 || Math.abs(dimension) === Infinity) return Math.pow(distance, constant * 5);
9
- return distance * dimension * constant / (dimension + constant * distance);
10
- }
11
- function rubberbandIfOutOfBounds(position, min, max, constant = .15) {
12
- if (constant === 0) return clamp(position, min, max);
13
- if (position < min) return -rubberband(min - position, max - min, constant) + min;
14
- if (position > max) return +rubberband(position - max, max - min, constant) + max;
15
- return position;
16
- }
17
- function computeRubberband(bounds, [Vx, Vy], [Rx, Ry]) {
18
- const [[X0, X1], [Y0, Y1]] = bounds;
19
- return [rubberbandIfOutOfBounds(Vx, X0, X1, Rx), rubberbandIfOutOfBounds(Vy, Y0, Y1, Ry)];
20
- }
21
- var V;
22
- var init_maths_0ab39ae9_esm = __esmMin((() => {
23
- V = {
24
- toVector(v, fallback) {
25
- if (v === void 0) v = fallback;
26
- return Array.isArray(v) ? v : [v, v];
27
- },
28
- add(v1, v2) {
29
- return [v1[0] + v2[0], v1[1] + v2[1]];
30
- },
31
- sub(v1, v2) {
32
- return [v1[0] - v2[0], v1[1] - v2[1]];
33
- },
34
- addTo(v1, v2) {
35
- v1[0] += v2[0];
36
- v1[1] += v2[1];
37
- },
38
- subTo(v1, v2) {
39
- v1[0] -= v2[0];
40
- v1[1] -= v2[1];
41
- }
42
- };
43
- }));
44
-
45
- //#endregion
46
- //#region node_modules/@use-gesture/core/dist/actions-fe213e88.esm.js
47
- function _toPrimitive(input, hint) {
48
- if (typeof input !== "object" || input === null) return input;
49
- var prim = input[Symbol.toPrimitive];
50
- if (prim !== void 0) {
51
- var res = prim.call(input, hint || "default");
52
- if (typeof res !== "object") return res;
53
- throw new TypeError("@@toPrimitive must return a primitive value.");
54
- }
55
- return (hint === "string" ? String : Number)(input);
56
- }
57
- function _toPropertyKey(arg) {
58
- var key = _toPrimitive(arg, "string");
59
- return typeof key === "symbol" ? key : String(key);
60
- }
61
- function _defineProperty(obj, key, value) {
62
- key = _toPropertyKey(key);
63
- if (key in obj) Object.defineProperty(obj, key, {
64
- value,
65
- enumerable: true,
66
- configurable: true,
67
- writable: true
68
- });
69
- else obj[key] = value;
70
- return obj;
71
- }
72
- function ownKeys(e, r) {
73
- var t = Object.keys(e);
74
- if (Object.getOwnPropertySymbols) {
75
- var o = Object.getOwnPropertySymbols(e);
76
- r && (o = o.filter(function(r$1) {
77
- return Object.getOwnPropertyDescriptor(e, r$1).enumerable;
78
- })), t.push.apply(t, o);
79
- }
80
- return t;
81
- }
82
- function _objectSpread2(e) {
83
- for (var r = 1; r < arguments.length; r++) {
84
- var t = null != arguments[r] ? arguments[r] : {};
85
- r % 2 ? ownKeys(Object(t), !0).forEach(function(r$1) {
86
- _defineProperty(e, r$1, t[r$1]);
87
- }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r$1) {
88
- Object.defineProperty(e, r$1, Object.getOwnPropertyDescriptor(t, r$1));
89
- });
90
- }
91
- return e;
92
- }
93
- function capitalize(string) {
94
- if (!string) return "";
95
- return string[0].toUpperCase() + string.slice(1);
96
- }
97
- function hasCapture(capture = false, actionKey) {
98
- return capture && !actionsWithoutCaptureSupported.includes(actionKey);
99
- }
100
- function toHandlerProp(device, action = "", capture = false) {
101
- const deviceProps = EVENT_TYPE_MAP[device];
102
- const actionKey = deviceProps ? deviceProps[action] || action : action;
103
- return "on" + capitalize(device) + capitalize(actionKey) + (hasCapture(capture, actionKey) ? "Capture" : "");
104
- }
105
- function parseProp(prop) {
106
- let eventKey = prop.substring(2).toLowerCase();
107
- const passive = !!~eventKey.indexOf("passive");
108
- if (passive) eventKey = eventKey.replace("passive", "");
109
- const captureKey = pointerCaptureEvents.includes(eventKey) ? "capturecapture" : "capture";
110
- const capture = !!~eventKey.indexOf(captureKey);
111
- if (capture) eventKey = eventKey.replace("capture", "");
112
- return {
113
- device: eventKey,
114
- capture,
115
- passive
116
- };
117
- }
118
- function toDomEventType(device, action = "") {
119
- const deviceProps = EVENT_TYPE_MAP[device];
120
- return device + (deviceProps ? deviceProps[action] || action : action);
121
- }
122
- function isTouch(event) {
123
- return "touches" in event;
124
- }
125
- function getPointerType(event) {
126
- if (isTouch(event)) return "touch";
127
- if ("pointerType" in event) return event.pointerType;
128
- return "mouse";
129
- }
130
- function getCurrentTargetTouchList(event) {
131
- return Array.from(event.touches).filter((e) => {
132
- var _event$currentTarget, _event$currentTarget$;
133
- return e.target === event.currentTarget || ((_event$currentTarget = event.currentTarget) === null || _event$currentTarget === void 0 || (_event$currentTarget$ = _event$currentTarget.contains) === null || _event$currentTarget$ === void 0 ? void 0 : _event$currentTarget$.call(_event$currentTarget, e.target));
134
- });
135
- }
136
- function getTouchList(event) {
137
- return event.type === "touchend" || event.type === "touchcancel" ? event.changedTouches : event.targetTouches;
138
- }
139
- function getValueEvent(event) {
140
- return isTouch(event) ? getTouchList(event)[0] : event;
141
- }
142
- function distanceAngle(P1, P2) {
143
- try {
144
- const dx = P2.clientX - P1.clientX;
145
- const dy = P2.clientY - P1.clientY;
146
- const cx = (P2.clientX + P1.clientX) / 2;
147
- const cy = (P2.clientY + P1.clientY) / 2;
148
- const distance = Math.hypot(dx, dy);
149
- return {
150
- angle: -(Math.atan2(dx, dy) * 180) / Math.PI,
151
- distance,
152
- origin: [cx, cy]
153
- };
154
- } catch (_unused) {}
155
- return null;
156
- }
157
- function touchIds(event) {
158
- return getCurrentTargetTouchList(event).map((touch) => touch.identifier);
159
- }
160
- function touchDistanceAngle(event, ids) {
161
- const [P1, P2] = Array.from(event.touches).filter((touch) => ids.includes(touch.identifier));
162
- return distanceAngle(P1, P2);
163
- }
164
- function pointerId(event) {
165
- const valueEvent = getValueEvent(event);
166
- return isTouch(event) ? valueEvent.identifier : valueEvent.pointerId;
167
- }
168
- function pointerValues(event) {
169
- const valueEvent = getValueEvent(event);
170
- return [valueEvent.clientX, valueEvent.clientY];
171
- }
172
- function wheelValues(event) {
173
- let { deltaX, deltaY, deltaMode } = event;
174
- if (deltaMode === 1) {
175
- deltaX *= LINE_HEIGHT;
176
- deltaY *= LINE_HEIGHT;
177
- } else if (deltaMode === 2) {
178
- deltaX *= PAGE_HEIGHT;
179
- deltaY *= PAGE_HEIGHT;
180
- }
181
- return [deltaX, deltaY];
182
- }
183
- function scrollValues(event) {
184
- var _ref, _ref2;
185
- const { scrollX, scrollY, scrollLeft, scrollTop } = event.currentTarget;
186
- return [(_ref = scrollX !== null && scrollX !== void 0 ? scrollX : scrollLeft) !== null && _ref !== void 0 ? _ref : 0, (_ref2 = scrollY !== null && scrollY !== void 0 ? scrollY : scrollTop) !== null && _ref2 !== void 0 ? _ref2 : 0];
187
- }
188
- function getEventDetails(event) {
189
- const payload = {};
190
- if ("buttons" in event) payload.buttons = event.buttons;
191
- if ("shiftKey" in event) {
192
- const { shiftKey, altKey, metaKey, ctrlKey } = event;
193
- Object.assign(payload, {
194
- shiftKey,
195
- altKey,
196
- metaKey,
197
- ctrlKey
198
- });
199
- }
200
- return payload;
201
- }
202
- function call(v, ...args) {
203
- if (typeof v === "function") return v(...args);
204
- else return v;
205
- }
206
- function noop() {}
207
- function chain(...fns) {
208
- if (fns.length === 0) return noop;
209
- if (fns.length === 1) return fns[0];
210
- return function() {
211
- let result;
212
- for (const fn of fns) result = fn.apply(this, arguments) || result;
213
- return result;
214
- };
215
- }
216
- function assignDefault(value, fallback) {
217
- return Object.assign({}, fallback, value || {});
218
- }
219
- function selectAxis([dx, dy], threshold) {
220
- const absDx = Math.abs(dx);
221
- const absDy = Math.abs(dy);
222
- if (absDx > absDy && absDx > threshold) return "x";
223
- if (absDy > absDx && absDy > threshold) return "y";
224
- }
225
- function persistEvent(event) {
226
- "persist" in event && typeof event.persist === "function" && event.persist();
227
- }
228
- function supportsTouchEvents() {
229
- return isBrowser && "ontouchstart" in window;
230
- }
231
- function isTouchScreen() {
232
- return supportsTouchEvents() || isBrowser && window.navigator.maxTouchPoints > 1;
233
- }
234
- function supportsPointerEvents() {
235
- return isBrowser && "onpointerdown" in window;
236
- }
237
- function supportsPointerLock() {
238
- return isBrowser && "exitPointerLock" in window.document;
239
- }
240
- function supportsGestureEvents() {
241
- try {
242
- return "constructor" in GestureEvent;
243
- } catch (e) {
244
- return false;
245
- }
246
- }
247
- function clampStateInternalMovementToBounds(state) {
248
- const [ox, oy] = state.overflow;
249
- const [dx, dy] = state._delta;
250
- const [dirx, diry] = state._direction;
251
- if (ox < 0 && dx > 0 && dirx < 0 || ox > 0 && dx < 0 && dirx > 0) state._movement[0] = state._movementBound[0];
252
- if (oy < 0 && dy > 0 && diry < 0 || oy > 0 && dy < 0 && diry > 0) state._movement[1] = state._movementBound[1];
253
- }
254
- function registerAction(action) {
255
- EngineMap.set(action.key, action.engine);
256
- ConfigResolverMap.set(action.key, action.resolver);
257
- }
258
- var EVENT_TYPE_MAP, actionsWithoutCaptureSupported, pointerCaptureEvents, LINE_HEIGHT, PAGE_HEIGHT, BEFORE_LAST_KINEMATICS_DELAY, Engine, CoordinatesEngine, identity, DEFAULT_RUBBERBAND, commonConfigResolver, DEFAULT_AXIS_THRESHOLD, coordinatesConfigResolver, KEYS_DELTA_MAP, DragEngine, isBrowser, SUPPORT, DEFAULT_PREVENT_SCROLL_DELAY, DEFAULT_DRAG_DELAY, DEFAULT_SWIPE_VELOCITY, DEFAULT_SWIPE_DISTANCE, DEFAULT_SWIPE_DURATION, DEFAULT_KEYBOARD_DISPLACEMENT, DEFAULT_DRAG_AXIS_THRESHOLD, dragConfigResolver, SCALE_ANGLE_RATIO_INTENT_DEG, PINCH_WHEEL_RATIO, PinchEngine, pinchConfigResolver, MoveEngine, moveConfigResolver, ScrollEngine, scrollConfigResolver, WheelEngine, wheelConfigResolver, HoverEngine, hoverConfigResolver, EngineMap, ConfigResolverMap, dragAction, hoverAction, moveAction, pinchAction, scrollAction, wheelAction;
259
- var init_actions_fe213e88_esm = __esmMin((() => {
260
- init_maths_0ab39ae9_esm();
261
- EVENT_TYPE_MAP = {
262
- pointer: {
263
- start: "down",
264
- change: "move",
265
- end: "up"
266
- },
267
- mouse: {
268
- start: "down",
269
- change: "move",
270
- end: "up"
271
- },
272
- touch: {
273
- start: "start",
274
- change: "move",
275
- end: "end"
276
- },
277
- gesture: {
278
- start: "start",
279
- change: "change",
280
- end: "end"
281
- }
282
- };
283
- actionsWithoutCaptureSupported = ["enter", "leave"];
284
- pointerCaptureEvents = ["gotpointercapture", "lostpointercapture"];
285
- LINE_HEIGHT = 40;
286
- PAGE_HEIGHT = 800;
287
- BEFORE_LAST_KINEMATICS_DELAY = 32;
288
- Engine = class {
289
- constructor(ctrl, args, key) {
290
- this.ctrl = ctrl;
291
- this.args = args;
292
- this.key = key;
293
- if (!this.state) {
294
- this.state = {};
295
- this.computeValues([0, 0]);
296
- this.computeInitial();
297
- if (this.init) this.init();
298
- this.reset();
299
- }
300
- }
301
- get state() {
302
- return this.ctrl.state[this.key];
303
- }
304
- set state(state) {
305
- this.ctrl.state[this.key] = state;
306
- }
307
- get shared() {
308
- return this.ctrl.state.shared;
309
- }
310
- get eventStore() {
311
- return this.ctrl.gestureEventStores[this.key];
312
- }
313
- get timeoutStore() {
314
- return this.ctrl.gestureTimeoutStores[this.key];
315
- }
316
- get config() {
317
- return this.ctrl.config[this.key];
318
- }
319
- get sharedConfig() {
320
- return this.ctrl.config.shared;
321
- }
322
- get handler() {
323
- return this.ctrl.handlers[this.key];
324
- }
325
- reset() {
326
- const { state, shared, ingKey, args } = this;
327
- shared[ingKey] = state._active = state.active = state._blocked = state._force = false;
328
- state._step = [false, false];
329
- state.intentional = false;
330
- state._movement = [0, 0];
331
- state._distance = [0, 0];
332
- state._direction = [0, 0];
333
- state._delta = [0, 0];
334
- state._bounds = [[-Infinity, Infinity], [-Infinity, Infinity]];
335
- state.args = args;
336
- state.axis = void 0;
337
- state.memo = void 0;
338
- state.elapsedTime = state.timeDelta = 0;
339
- state.direction = [0, 0];
340
- state.distance = [0, 0];
341
- state.overflow = [0, 0];
342
- state._movementBound = [false, false];
343
- state.velocity = [0, 0];
344
- state.movement = [0, 0];
345
- state.delta = [0, 0];
346
- state.timeStamp = 0;
347
- }
348
- start(event) {
349
- const state = this.state;
350
- const config = this.config;
351
- if (!state._active) {
352
- this.reset();
353
- this.computeInitial();
354
- state._active = true;
355
- state.target = event.target;
356
- state.currentTarget = event.currentTarget;
357
- state.lastOffset = config.from ? call(config.from, state) : state.offset;
358
- state.offset = state.lastOffset;
359
- state.startTime = state.timeStamp = event.timeStamp;
360
- }
361
- }
362
- computeValues(values) {
363
- const state = this.state;
364
- state._values = values;
365
- state.values = this.config.transform(values);
366
- }
367
- computeInitial() {
368
- const state = this.state;
369
- state._initial = state._values;
370
- state.initial = state.values;
371
- }
372
- compute(event) {
373
- const { state, config, shared } = this;
374
- state.args = this.args;
375
- let dt = 0;
376
- if (event) {
377
- state.event = event;
378
- if (config.preventDefault && event.cancelable) state.event.preventDefault();
379
- state.type = event.type;
380
- shared.touches = this.ctrl.pointerIds.size || this.ctrl.touchIds.size;
381
- shared.locked = !!document.pointerLockElement;
382
- Object.assign(shared, getEventDetails(event));
383
- shared.down = shared.pressed = shared.buttons % 2 === 1 || shared.touches > 0;
384
- dt = event.timeStamp - state.timeStamp;
385
- state.timeStamp = event.timeStamp;
386
- state.elapsedTime = state.timeStamp - state.startTime;
387
- }
388
- if (state._active) {
389
- const _absoluteDelta = state._delta.map(Math.abs);
390
- V.addTo(state._distance, _absoluteDelta);
391
- }
392
- if (this.axisIntent) this.axisIntent(event);
393
- const [_m0, _m1] = state._movement;
394
- const [t0, t1] = config.threshold;
395
- const { _step, values } = state;
396
- if (config.hasCustomTransform) {
397
- if (_step[0] === false) _step[0] = Math.abs(_m0) >= t0 && values[0];
398
- if (_step[1] === false) _step[1] = Math.abs(_m1) >= t1 && values[1];
399
- } else {
400
- if (_step[0] === false) _step[0] = Math.abs(_m0) >= t0 && Math.sign(_m0) * t0;
401
- if (_step[1] === false) _step[1] = Math.abs(_m1) >= t1 && Math.sign(_m1) * t1;
402
- }
403
- state.intentional = _step[0] !== false || _step[1] !== false;
404
- if (!state.intentional) return;
405
- const movement = [0, 0];
406
- if (config.hasCustomTransform) {
407
- const [v0, v1] = values;
408
- movement[0] = _step[0] !== false ? v0 - _step[0] : 0;
409
- movement[1] = _step[1] !== false ? v1 - _step[1] : 0;
410
- } else {
411
- movement[0] = _step[0] !== false ? _m0 - _step[0] : 0;
412
- movement[1] = _step[1] !== false ? _m1 - _step[1] : 0;
413
- }
414
- if (this.restrictToAxis && !state._blocked) this.restrictToAxis(movement);
415
- const previousOffset = state.offset;
416
- const gestureIsActive = state._active && !state._blocked || state.active;
417
- if (gestureIsActive) {
418
- state.first = state._active && !state.active;
419
- state.last = !state._active && state.active;
420
- state.active = shared[this.ingKey] = state._active;
421
- if (event) {
422
- if (state.first) {
423
- if ("bounds" in config) state._bounds = call(config.bounds, state);
424
- if (this.setup) this.setup();
425
- }
426
- state.movement = movement;
427
- this.computeOffset();
428
- }
429
- }
430
- const [ox, oy] = state.offset;
431
- const [[x0, x1], [y0, y1]] = state._bounds;
432
- state.overflow = [ox < x0 ? -1 : ox > x1 ? 1 : 0, oy < y0 ? -1 : oy > y1 ? 1 : 0];
433
- state._movementBound[0] = state.overflow[0] ? state._movementBound[0] === false ? state._movement[0] : state._movementBound[0] : false;
434
- state._movementBound[1] = state.overflow[1] ? state._movementBound[1] === false ? state._movement[1] : state._movementBound[1] : false;
435
- const rubberband$1 = state._active ? config.rubberband || [0, 0] : [0, 0];
436
- state.offset = computeRubberband(state._bounds, state.offset, rubberband$1);
437
- state.delta = V.sub(state.offset, previousOffset);
438
- this.computeMovement();
439
- if (gestureIsActive && (!state.last || dt > BEFORE_LAST_KINEMATICS_DELAY)) {
440
- state.delta = V.sub(state.offset, previousOffset);
441
- const absoluteDelta = state.delta.map(Math.abs);
442
- V.addTo(state.distance, absoluteDelta);
443
- state.direction = state.delta.map(Math.sign);
444
- state._direction = state._delta.map(Math.sign);
445
- if (!state.first && dt > 0) {
446
- state.velocity = [absoluteDelta[0] / dt, absoluteDelta[1] / dt];
447
- state.timeDelta = dt;
448
- }
449
- }
450
- }
451
- emit() {
452
- const state = this.state;
453
- const shared = this.shared;
454
- const config = this.config;
455
- if (!state._active) this.clean();
456
- if ((state._blocked || !state.intentional) && !state._force && !config.triggerAllEvents) return;
457
- const memo = this.handler(_objectSpread2(_objectSpread2(_objectSpread2({}, shared), state), {}, { [this.aliasKey]: state.values }));
458
- if (memo !== void 0) state.memo = memo;
459
- }
460
- clean() {
461
- this.eventStore.clean();
462
- this.timeoutStore.clean();
463
- }
464
- };
465
- CoordinatesEngine = class extends Engine {
466
- constructor(...args) {
467
- super(...args);
468
- _defineProperty(this, "aliasKey", "xy");
469
- }
470
- reset() {
471
- super.reset();
472
- this.state.axis = void 0;
473
- }
474
- init() {
475
- this.state.offset = [0, 0];
476
- this.state.lastOffset = [0, 0];
477
- }
478
- computeOffset() {
479
- this.state.offset = V.add(this.state.lastOffset, this.state.movement);
480
- }
481
- computeMovement() {
482
- this.state.movement = V.sub(this.state.offset, this.state.lastOffset);
483
- }
484
- axisIntent(event) {
485
- const state = this.state;
486
- const config = this.config;
487
- if (!state.axis && event) {
488
- const threshold = typeof config.axisThreshold === "object" ? config.axisThreshold[getPointerType(event)] : config.axisThreshold;
489
- state.axis = selectAxis(state._movement, threshold);
490
- }
491
- state._blocked = (config.lockDirection || !!config.axis) && !state.axis || !!config.axis && config.axis !== state.axis;
492
- }
493
- restrictToAxis(v) {
494
- if (this.config.axis || this.config.lockDirection) switch (this.state.axis) {
495
- case "x":
496
- v[1] = 0;
497
- break;
498
- case "y":
499
- v[0] = 0;
500
- break;
501
- }
502
- }
503
- };
504
- identity = (v) => v;
505
- DEFAULT_RUBBERBAND = .15;
506
- commonConfigResolver = {
507
- enabled(value = true) {
508
- return value;
509
- },
510
- eventOptions(value, _k, config) {
511
- return _objectSpread2(_objectSpread2({}, config.shared.eventOptions), value);
512
- },
513
- preventDefault(value = false) {
514
- return value;
515
- },
516
- triggerAllEvents(value = false) {
517
- return value;
518
- },
519
- rubberband(value = 0) {
520
- switch (value) {
521
- case true: return [DEFAULT_RUBBERBAND, DEFAULT_RUBBERBAND];
522
- case false: return [0, 0];
523
- default: return V.toVector(value);
524
- }
525
- },
526
- from(value) {
527
- if (typeof value === "function") return value;
528
- if (value != null) return V.toVector(value);
529
- },
530
- transform(value, _k, config) {
531
- const transform = value || config.shared.transform;
532
- this.hasCustomTransform = !!transform;
533
- if (process.env.NODE_ENV === "development") {
534
- const originalTransform = transform || identity;
535
- return (v) => {
536
- const r = originalTransform(v);
537
- if (!isFinite(r[0]) || !isFinite(r[1])) console.warn(`[@use-gesture]: config.transform() must produce a valid result, but it was: [${r[0]},1]`);
538
- return r;
539
- };
540
- }
541
- return transform || identity;
542
- },
543
- threshold(value) {
544
- return V.toVector(value, 0);
545
- }
546
- };
547
- if (process.env.NODE_ENV === "development") Object.assign(commonConfigResolver, {
548
- domTarget(value) {
549
- if (value !== void 0) throw Error(`[@use-gesture]: \`domTarget\` option has been renamed to \`target\`.`);
550
- return NaN;
551
- },
552
- lockDirection(value) {
553
- if (value !== void 0) throw Error(`[@use-gesture]: \`lockDirection\` option has been merged with \`axis\`. Use it as in \`{ axis: 'lock' }\``);
554
- return NaN;
555
- },
556
- initial(value) {
557
- if (value !== void 0) throw Error(`[@use-gesture]: \`initial\` option has been renamed to \`from\`.`);
558
- return NaN;
559
- }
560
- });
561
- DEFAULT_AXIS_THRESHOLD = 0;
562
- coordinatesConfigResolver = _objectSpread2(_objectSpread2({}, commonConfigResolver), {}, {
563
- axis(_v, _k, { axis }) {
564
- this.lockDirection = axis === "lock";
565
- if (!this.lockDirection) return axis;
566
- },
567
- axisThreshold(value = DEFAULT_AXIS_THRESHOLD) {
568
- return value;
569
- },
570
- bounds(value = {}) {
571
- if (typeof value === "function") return (state) => coordinatesConfigResolver.bounds(value(state));
572
- if ("current" in value) return () => value.current;
573
- if (typeof HTMLElement === "function" && value instanceof HTMLElement) return value;
574
- const { left = -Infinity, right = Infinity, top = -Infinity, bottom = Infinity } = value;
575
- return [[left, right], [top, bottom]];
576
- }
577
- });
578
- KEYS_DELTA_MAP = {
579
- ArrowRight: (displacement, factor = 1) => [displacement * factor, 0],
580
- ArrowLeft: (displacement, factor = 1) => [-1 * displacement * factor, 0],
581
- ArrowUp: (displacement, factor = 1) => [0, -1 * displacement * factor],
582
- ArrowDown: (displacement, factor = 1) => [0, displacement * factor]
583
- };
584
- DragEngine = class extends CoordinatesEngine {
585
- constructor(...args) {
586
- super(...args);
587
- _defineProperty(this, "ingKey", "dragging");
588
- }
589
- reset() {
590
- super.reset();
591
- const state = this.state;
592
- state._pointerId = void 0;
593
- state._pointerActive = false;
594
- state._keyboardActive = false;
595
- state._preventScroll = false;
596
- state._delayed = false;
597
- state.swipe = [0, 0];
598
- state.tap = false;
599
- state.canceled = false;
600
- state.cancel = this.cancel.bind(this);
601
- }
602
- setup() {
603
- const state = this.state;
604
- if (state._bounds instanceof HTMLElement) {
605
- const boundRect = state._bounds.getBoundingClientRect();
606
- const targetRect = state.currentTarget.getBoundingClientRect();
607
- const _bounds = {
608
- left: boundRect.left - targetRect.left + state.offset[0],
609
- right: boundRect.right - targetRect.right + state.offset[0],
610
- top: boundRect.top - targetRect.top + state.offset[1],
611
- bottom: boundRect.bottom - targetRect.bottom + state.offset[1]
612
- };
613
- state._bounds = coordinatesConfigResolver.bounds(_bounds);
614
- }
615
- }
616
- cancel() {
617
- const state = this.state;
618
- if (state.canceled) return;
619
- state.canceled = true;
620
- state._active = false;
621
- setTimeout(() => {
622
- this.compute();
623
- this.emit();
624
- }, 0);
625
- }
626
- setActive() {
627
- this.state._active = this.state._pointerActive || this.state._keyboardActive;
628
- }
629
- clean() {
630
- this.pointerClean();
631
- this.state._pointerActive = false;
632
- this.state._keyboardActive = false;
633
- super.clean();
634
- }
635
- pointerDown(event) {
636
- const config = this.config;
637
- const state = this.state;
638
- if (event.buttons != null && (Array.isArray(config.pointerButtons) ? !config.pointerButtons.includes(event.buttons) : config.pointerButtons !== -1 && config.pointerButtons !== event.buttons)) return;
639
- const ctrlIds = this.ctrl.setEventIds(event);
640
- if (config.pointerCapture) event.target.setPointerCapture(event.pointerId);
641
- if (ctrlIds && ctrlIds.size > 1 && state._pointerActive) return;
642
- this.start(event);
643
- this.setupPointer(event);
644
- state._pointerId = pointerId(event);
645
- state._pointerActive = true;
646
- this.computeValues(pointerValues(event));
647
- this.computeInitial();
648
- if (config.preventScrollAxis && getPointerType(event) !== "mouse") {
649
- state._active = false;
650
- this.setupScrollPrevention(event);
651
- } else if (config.delay > 0) {
652
- this.setupDelayTrigger(event);
653
- if (config.triggerAllEvents) {
654
- this.compute(event);
655
- this.emit();
656
- }
657
- } else this.startPointerDrag(event);
658
- }
659
- startPointerDrag(event) {
660
- const state = this.state;
661
- state._active = true;
662
- state._preventScroll = true;
663
- state._delayed = false;
664
- this.compute(event);
665
- this.emit();
666
- }
667
- pointerMove(event) {
668
- const state = this.state;
669
- const config = this.config;
670
- if (!state._pointerActive) return;
671
- const id = pointerId(event);
672
- if (state._pointerId !== void 0 && id !== state._pointerId) return;
673
- const _values = pointerValues(event);
674
- if (document.pointerLockElement === event.target) state._delta = [event.movementX, event.movementY];
675
- else {
676
- state._delta = V.sub(_values, state._values);
677
- this.computeValues(_values);
678
- }
679
- V.addTo(state._movement, state._delta);
680
- this.compute(event);
681
- if (state._delayed && state.intentional) {
682
- this.timeoutStore.remove("dragDelay");
683
- state.active = false;
684
- this.startPointerDrag(event);
685
- return;
686
- }
687
- if (config.preventScrollAxis && !state._preventScroll) if (state.axis) if (state.axis === config.preventScrollAxis || config.preventScrollAxis === "xy") {
688
- state._active = false;
689
- this.clean();
690
- return;
691
- } else {
692
- this.timeoutStore.remove("startPointerDrag");
693
- this.startPointerDrag(event);
694
- return;
695
- }
696
- else return;
697
- this.emit();
698
- }
699
- pointerUp(event) {
700
- this.ctrl.setEventIds(event);
701
- try {
702
- if (this.config.pointerCapture && event.target.hasPointerCapture(event.pointerId)) event.target.releasePointerCapture(event.pointerId);
703
- } catch (_unused) {
704
- if (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.`);
705
- }
706
- const state = this.state;
707
- const config = this.config;
708
- if (!state._active || !state._pointerActive) return;
709
- const id = pointerId(event);
710
- if (state._pointerId !== void 0 && id !== state._pointerId) return;
711
- this.state._pointerActive = false;
712
- this.setActive();
713
- this.compute(event);
714
- const [dx, dy] = state._distance;
715
- state.tap = dx <= config.tapsThreshold && dy <= config.tapsThreshold;
716
- if (state.tap && config.filterTaps) state._force = true;
717
- else {
718
- const [_dx, _dy] = state._delta;
719
- const [_mx, _my] = state._movement;
720
- const [svx, svy] = config.swipe.velocity;
721
- const [sx, sy] = config.swipe.distance;
722
- const sdt = config.swipe.duration;
723
- if (state.elapsedTime < sdt) {
724
- const _vx = Math.abs(_dx / state.timeDelta);
725
- const _vy = Math.abs(_dy / state.timeDelta);
726
- if (_vx > svx && Math.abs(_mx) > sx) state.swipe[0] = Math.sign(_dx);
727
- if (_vy > svy && Math.abs(_my) > sy) state.swipe[1] = Math.sign(_dy);
728
- }
729
- }
730
- this.emit();
731
- }
732
- pointerClick(event) {
733
- if (!this.state.tap && event.detail > 0) {
734
- event.preventDefault();
735
- event.stopPropagation();
736
- }
737
- }
738
- setupPointer(event) {
739
- const config = this.config;
740
- const device = config.device;
741
- if (process.env.NODE_ENV === "development") try {
742
- if (device === "pointer" && config.preventScrollDelay === void 0) {
743
- const currentTarget = "uv" in event ? event.sourceEvent.currentTarget : event.currentTarget;
744
- if (window.getComputedStyle(currentTarget).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.`, currentTarget);
745
- }
746
- } catch (_unused2) {}
747
- if (config.pointerLock) event.currentTarget.requestPointerLock();
748
- if (!config.pointerCapture) {
749
- this.eventStore.add(this.sharedConfig.window, device, "change", this.pointerMove.bind(this));
750
- this.eventStore.add(this.sharedConfig.window, device, "end", this.pointerUp.bind(this));
751
- this.eventStore.add(this.sharedConfig.window, device, "cancel", this.pointerUp.bind(this));
752
- }
753
- }
754
- pointerClean() {
755
- if (this.config.pointerLock && document.pointerLockElement === this.state.currentTarget) document.exitPointerLock();
756
- }
757
- preventScroll(event) {
758
- if (this.state._preventScroll && event.cancelable) event.preventDefault();
759
- }
760
- setupScrollPrevention(event) {
761
- this.state._preventScroll = false;
762
- persistEvent(event);
763
- const remove = this.eventStore.add(this.sharedConfig.window, "touch", "change", this.preventScroll.bind(this), { passive: false });
764
- this.eventStore.add(this.sharedConfig.window, "touch", "end", remove);
765
- this.eventStore.add(this.sharedConfig.window, "touch", "cancel", remove);
766
- this.timeoutStore.add("startPointerDrag", this.startPointerDrag.bind(this), this.config.preventScrollDelay, event);
767
- }
768
- setupDelayTrigger(event) {
769
- this.state._delayed = true;
770
- this.timeoutStore.add("dragDelay", () => {
771
- this.state._step = [0, 0];
772
- this.startPointerDrag(event);
773
- }, this.config.delay);
774
- }
775
- keyDown(event) {
776
- const deltaFn = KEYS_DELTA_MAP[event.key];
777
- if (deltaFn) {
778
- const state = this.state;
779
- const factor = event.shiftKey ? 10 : event.altKey ? .1 : 1;
780
- this.start(event);
781
- state._delta = deltaFn(this.config.keyboardDisplacement, factor);
782
- state._keyboardActive = true;
783
- V.addTo(state._movement, state._delta);
784
- this.compute(event);
785
- this.emit();
786
- }
787
- }
788
- keyUp(event) {
789
- if (!(event.key in KEYS_DELTA_MAP)) return;
790
- this.state._keyboardActive = false;
791
- this.setActive();
792
- this.compute(event);
793
- this.emit();
794
- }
795
- bind(bindFunction) {
796
- const device = this.config.device;
797
- bindFunction(device, "start", this.pointerDown.bind(this));
798
- if (this.config.pointerCapture) {
799
- bindFunction(device, "change", this.pointerMove.bind(this));
800
- bindFunction(device, "end", this.pointerUp.bind(this));
801
- bindFunction(device, "cancel", this.pointerUp.bind(this));
802
- bindFunction("lostPointerCapture", "", this.pointerUp.bind(this));
803
- }
804
- if (this.config.keys) {
805
- bindFunction("key", "down", this.keyDown.bind(this));
806
- bindFunction("key", "up", this.keyUp.bind(this));
807
- }
808
- if (this.config.filterTaps) bindFunction("click", "", this.pointerClick.bind(this), {
809
- capture: true,
810
- passive: false
811
- });
812
- }
813
- };
814
- isBrowser = typeof window !== "undefined" && window.document && window.document.createElement;
815
- SUPPORT = {
816
- isBrowser,
817
- gesture: supportsGestureEvents(),
818
- touch: supportsTouchEvents(),
819
- touchscreen: isTouchScreen(),
820
- pointer: supportsPointerEvents(),
821
- pointerLock: supportsPointerLock()
822
- };
823
- DEFAULT_PREVENT_SCROLL_DELAY = 250;
824
- DEFAULT_DRAG_DELAY = 180;
825
- DEFAULT_SWIPE_VELOCITY = .5;
826
- DEFAULT_SWIPE_DISTANCE = 50;
827
- DEFAULT_SWIPE_DURATION = 250;
828
- DEFAULT_KEYBOARD_DISPLACEMENT = 10;
829
- DEFAULT_DRAG_AXIS_THRESHOLD = {
830
- mouse: 0,
831
- touch: 0,
832
- pen: 8
833
- };
834
- dragConfigResolver = _objectSpread2(_objectSpread2({}, coordinatesConfigResolver), {}, {
835
- device(_v, _k, { pointer: { touch = false, lock = false, mouse = false } = {} }) {
836
- this.pointerLock = lock && SUPPORT.pointerLock;
837
- if (SUPPORT.touch && touch) return "touch";
838
- if (this.pointerLock) return "mouse";
839
- if (SUPPORT.pointer && !mouse) return "pointer";
840
- if (SUPPORT.touch) return "touch";
841
- return "mouse";
842
- },
843
- preventScrollAxis(value, _k, { preventScroll }) {
844
- this.preventScrollDelay = typeof preventScroll === "number" ? preventScroll : preventScroll || preventScroll === void 0 && value ? DEFAULT_PREVENT_SCROLL_DELAY : void 0;
845
- if (!SUPPORT.touchscreen || preventScroll === false) return void 0;
846
- return value ? value : preventScroll !== void 0 ? "y" : void 0;
847
- },
848
- pointerCapture(_v, _k, { pointer: { capture = true, buttons = 1, keys = true } = {} }) {
849
- this.pointerButtons = buttons;
850
- this.keys = keys;
851
- return !this.pointerLock && this.device === "pointer" && capture;
852
- },
853
- threshold(value, _k, { filterTaps = false, tapsThreshold = 3, axis = void 0 }) {
854
- const threshold = V.toVector(value, filterTaps ? tapsThreshold : axis ? 1 : 0);
855
- this.filterTaps = filterTaps;
856
- this.tapsThreshold = tapsThreshold;
857
- return threshold;
858
- },
859
- swipe({ velocity = DEFAULT_SWIPE_VELOCITY, distance = DEFAULT_SWIPE_DISTANCE, duration = DEFAULT_SWIPE_DURATION } = {}) {
860
- return {
861
- velocity: this.transform(V.toVector(velocity)),
862
- distance: this.transform(V.toVector(distance)),
863
- duration
864
- };
865
- },
866
- delay(value = 0) {
867
- switch (value) {
868
- case true: return DEFAULT_DRAG_DELAY;
869
- case false: return 0;
870
- default: return value;
871
- }
872
- },
873
- axisThreshold(value) {
874
- if (!value) return DEFAULT_DRAG_AXIS_THRESHOLD;
875
- return _objectSpread2(_objectSpread2({}, DEFAULT_DRAG_AXIS_THRESHOLD), value);
876
- },
877
- keyboardDisplacement(value = DEFAULT_KEYBOARD_DISPLACEMENT) {
878
- return value;
879
- }
880
- });
881
- if (process.env.NODE_ENV === "development") Object.assign(dragConfigResolver, {
882
- useTouch(value) {
883
- if (value !== void 0) throw Error(`[@use-gesture]: \`useTouch\` option has been renamed to \`pointer.touch\`. Use it as in \`{ pointer: { touch: true } }\`.`);
884
- return NaN;
885
- },
886
- experimental_preventWindowScrollY(value) {
887
- if (value !== void 0) throw Error(`[@use-gesture]: \`experimental_preventWindowScrollY\` option has been renamed to \`preventScroll\`.`);
888
- return NaN;
889
- },
890
- swipeVelocity(value) {
891
- if (value !== void 0) throw Error(`[@use-gesture]: \`swipeVelocity\` option has been renamed to \`swipe.velocity\`. Use it as in \`{ swipe: { velocity: 0.5 } }\`.`);
892
- return NaN;
893
- },
894
- swipeDistance(value) {
895
- if (value !== void 0) throw Error(`[@use-gesture]: \`swipeDistance\` option has been renamed to \`swipe.distance\`. Use it as in \`{ swipe: { distance: 50 } }\`.`);
896
- return NaN;
897
- },
898
- swipeDuration(value) {
899
- if (value !== void 0) throw Error(`[@use-gesture]: \`swipeDuration\` option has been renamed to \`swipe.duration\`. Use it as in \`{ swipe: { duration: 250 } }\`.`);
900
- return NaN;
901
- }
902
- });
903
- SCALE_ANGLE_RATIO_INTENT_DEG = 30;
904
- PINCH_WHEEL_RATIO = 100;
905
- PinchEngine = class extends Engine {
906
- constructor(...args) {
907
- super(...args);
908
- _defineProperty(this, "ingKey", "pinching");
909
- _defineProperty(this, "aliasKey", "da");
910
- }
911
- init() {
912
- this.state.offset = [1, 0];
913
- this.state.lastOffset = [1, 0];
914
- this.state._pointerEvents = /* @__PURE__ */ new Map();
915
- }
916
- reset() {
917
- super.reset();
918
- const state = this.state;
919
- state._touchIds = [];
920
- state.canceled = false;
921
- state.cancel = this.cancel.bind(this);
922
- state.turns = 0;
923
- }
924
- computeOffset() {
925
- const { type, movement, lastOffset } = this.state;
926
- if (type === "wheel") this.state.offset = V.add(movement, lastOffset);
927
- else this.state.offset = [(1 + movement[0]) * lastOffset[0], movement[1] + lastOffset[1]];
928
- }
929
- computeMovement() {
930
- const { offset, lastOffset } = this.state;
931
- this.state.movement = [offset[0] / lastOffset[0], offset[1] - lastOffset[1]];
932
- }
933
- axisIntent() {
934
- const state = this.state;
935
- const [_m0, _m1] = state._movement;
936
- if (!state.axis) {
937
- const axisMovementDifference = Math.abs(_m0) * SCALE_ANGLE_RATIO_INTENT_DEG - Math.abs(_m1);
938
- if (axisMovementDifference < 0) state.axis = "angle";
939
- else if (axisMovementDifference > 0) state.axis = "scale";
940
- }
941
- }
942
- restrictToAxis(v) {
943
- if (this.config.lockDirection) {
944
- if (this.state.axis === "scale") v[1] = 0;
945
- else if (this.state.axis === "angle") v[0] = 0;
946
- }
947
- }
948
- cancel() {
949
- const state = this.state;
950
- if (state.canceled) return;
951
- setTimeout(() => {
952
- state.canceled = true;
953
- state._active = false;
954
- this.compute();
955
- this.emit();
956
- }, 0);
957
- }
958
- touchStart(event) {
959
- this.ctrl.setEventIds(event);
960
- const state = this.state;
961
- const ctrlTouchIds = this.ctrl.touchIds;
962
- if (state._active) {
963
- if (state._touchIds.every((id) => ctrlTouchIds.has(id))) return;
964
- }
965
- if (ctrlTouchIds.size < 2) return;
966
- this.start(event);
967
- state._touchIds = Array.from(ctrlTouchIds).slice(0, 2);
968
- const payload = touchDistanceAngle(event, state._touchIds);
969
- if (!payload) return;
970
- this.pinchStart(event, payload);
971
- }
972
- pointerStart(event) {
973
- if (event.buttons != null && event.buttons % 2 !== 1) return;
974
- this.ctrl.setEventIds(event);
975
- event.target.setPointerCapture(event.pointerId);
976
- const state = this.state;
977
- const _pointerEvents = state._pointerEvents;
978
- const ctrlPointerIds = this.ctrl.pointerIds;
979
- if (state._active) {
980
- if (Array.from(_pointerEvents.keys()).every((id) => ctrlPointerIds.has(id))) return;
981
- }
982
- if (_pointerEvents.size < 2) _pointerEvents.set(event.pointerId, event);
983
- if (state._pointerEvents.size < 2) return;
984
- this.start(event);
985
- const payload = distanceAngle(...Array.from(_pointerEvents.values()));
986
- if (!payload) return;
987
- this.pinchStart(event, payload);
988
- }
989
- pinchStart(event, payload) {
990
- const state = this.state;
991
- state.origin = payload.origin;
992
- this.computeValues([payload.distance, payload.angle]);
993
- this.computeInitial();
994
- this.compute(event);
995
- this.emit();
996
- }
997
- touchMove(event) {
998
- if (!this.state._active) return;
999
- const payload = touchDistanceAngle(event, this.state._touchIds);
1000
- if (!payload) return;
1001
- this.pinchMove(event, payload);
1002
- }
1003
- pointerMove(event) {
1004
- const _pointerEvents = this.state._pointerEvents;
1005
- if (_pointerEvents.has(event.pointerId)) _pointerEvents.set(event.pointerId, event);
1006
- if (!this.state._active) return;
1007
- const payload = distanceAngle(...Array.from(_pointerEvents.values()));
1008
- if (!payload) return;
1009
- this.pinchMove(event, payload);
1010
- }
1011
- pinchMove(event, payload) {
1012
- const state = this.state;
1013
- const prev_a = state._values[1];
1014
- const delta_a = payload.angle - prev_a;
1015
- let delta_turns = 0;
1016
- if (Math.abs(delta_a) > 270) delta_turns += Math.sign(delta_a);
1017
- this.computeValues([payload.distance, payload.angle - 360 * delta_turns]);
1018
- state.origin = payload.origin;
1019
- state.turns = delta_turns;
1020
- state._movement = [state._values[0] / state._initial[0] - 1, state._values[1] - state._initial[1]];
1021
- this.compute(event);
1022
- this.emit();
1023
- }
1024
- touchEnd(event) {
1025
- this.ctrl.setEventIds(event);
1026
- if (!this.state._active) return;
1027
- if (this.state._touchIds.some((id) => !this.ctrl.touchIds.has(id))) {
1028
- this.state._active = false;
1029
- this.compute(event);
1030
- this.emit();
1031
- }
1032
- }
1033
- pointerEnd(event) {
1034
- const state = this.state;
1035
- this.ctrl.setEventIds(event);
1036
- try {
1037
- event.target.releasePointerCapture(event.pointerId);
1038
- } catch (_unused) {}
1039
- if (state._pointerEvents.has(event.pointerId)) state._pointerEvents.delete(event.pointerId);
1040
- if (!state._active) return;
1041
- if (state._pointerEvents.size < 2) {
1042
- state._active = false;
1043
- this.compute(event);
1044
- this.emit();
1045
- }
1046
- }
1047
- gestureStart(event) {
1048
- if (event.cancelable) event.preventDefault();
1049
- const state = this.state;
1050
- if (state._active) return;
1051
- this.start(event);
1052
- this.computeValues([event.scale, event.rotation]);
1053
- state.origin = [event.clientX, event.clientY];
1054
- this.compute(event);
1055
- this.emit();
1056
- }
1057
- gestureMove(event) {
1058
- if (event.cancelable) event.preventDefault();
1059
- if (!this.state._active) return;
1060
- const state = this.state;
1061
- this.computeValues([event.scale, event.rotation]);
1062
- state.origin = [event.clientX, event.clientY];
1063
- const _previousMovement = state._movement;
1064
- state._movement = [event.scale - 1, event.rotation];
1065
- state._delta = V.sub(state._movement, _previousMovement);
1066
- this.compute(event);
1067
- this.emit();
1068
- }
1069
- gestureEnd(event) {
1070
- if (!this.state._active) return;
1071
- this.state._active = false;
1072
- this.compute(event);
1073
- this.emit();
1074
- }
1075
- wheel(event) {
1076
- const modifierKey = this.config.modifierKey;
1077
- if (modifierKey && (Array.isArray(modifierKey) ? !modifierKey.find((k) => event[k]) : !event[modifierKey])) return;
1078
- if (!this.state._active) this.wheelStart(event);
1079
- else this.wheelChange(event);
1080
- this.timeoutStore.add("wheelEnd", this.wheelEnd.bind(this));
1081
- }
1082
- wheelStart(event) {
1083
- this.start(event);
1084
- this.wheelChange(event);
1085
- }
1086
- wheelChange(event) {
1087
- if (!("uv" in event)) {
1088
- if (event.cancelable) event.preventDefault();
1089
- if (process.env.NODE_ENV === "development" && !event.defaultPrevented) console.warn(`[@use-gesture]: To properly support zoom on trackpads, try using the \`target\` option.\n\nThis message will only appear in development mode.`);
1090
- }
1091
- const state = this.state;
1092
- state._delta = [-wheelValues(event)[1] / PINCH_WHEEL_RATIO * state.offset[0], 0];
1093
- V.addTo(state._movement, state._delta);
1094
- clampStateInternalMovementToBounds(state);
1095
- this.state.origin = [event.clientX, event.clientY];
1096
- this.compute(event);
1097
- this.emit();
1098
- }
1099
- wheelEnd() {
1100
- if (!this.state._active) return;
1101
- this.state._active = false;
1102
- this.compute();
1103
- this.emit();
1104
- }
1105
- bind(bindFunction) {
1106
- const device = this.config.device;
1107
- if (!!device) {
1108
- bindFunction(device, "start", this[device + "Start"].bind(this));
1109
- bindFunction(device, "change", this[device + "Move"].bind(this));
1110
- bindFunction(device, "end", this[device + "End"].bind(this));
1111
- bindFunction(device, "cancel", this[device + "End"].bind(this));
1112
- bindFunction("lostPointerCapture", "", this[device + "End"].bind(this));
1113
- }
1114
- if (this.config.pinchOnWheel) bindFunction("wheel", "", this.wheel.bind(this), { passive: false });
1115
- }
1116
- };
1117
- pinchConfigResolver = _objectSpread2(_objectSpread2({}, commonConfigResolver), {}, {
1118
- device(_v, _k, { shared, pointer: { touch = false } = {} }) {
1119
- if (shared.target && !SUPPORT.touch && SUPPORT.gesture) return "gesture";
1120
- if (SUPPORT.touch && touch) return "touch";
1121
- if (SUPPORT.touchscreen) {
1122
- if (SUPPORT.pointer) return "pointer";
1123
- if (SUPPORT.touch) return "touch";
1124
- }
1125
- },
1126
- bounds(_v, _k, { scaleBounds = {}, angleBounds = {} }) {
1127
- const _scaleBounds = (state) => {
1128
- const D = assignDefault(call(scaleBounds, state), {
1129
- min: -Infinity,
1130
- max: Infinity
1131
- });
1132
- return [D.min, D.max];
1133
- };
1134
- const _angleBounds = (state) => {
1135
- const A = assignDefault(call(angleBounds, state), {
1136
- min: -Infinity,
1137
- max: Infinity
1138
- });
1139
- return [A.min, A.max];
1140
- };
1141
- if (typeof scaleBounds !== "function" && typeof angleBounds !== "function") return [_scaleBounds(), _angleBounds()];
1142
- return (state) => [_scaleBounds(state), _angleBounds(state)];
1143
- },
1144
- threshold(value, _k, config) {
1145
- this.lockDirection = config.axis === "lock";
1146
- return V.toVector(value, this.lockDirection ? [.1, 3] : 0);
1147
- },
1148
- modifierKey(value) {
1149
- if (value === void 0) return "ctrlKey";
1150
- return value;
1151
- },
1152
- pinchOnWheel(value = true) {
1153
- return value;
1154
- }
1155
- });
1156
- MoveEngine = class extends CoordinatesEngine {
1157
- constructor(...args) {
1158
- super(...args);
1159
- _defineProperty(this, "ingKey", "moving");
1160
- }
1161
- move(event) {
1162
- if (this.config.mouseOnly && event.pointerType !== "mouse") return;
1163
- if (!this.state._active) this.moveStart(event);
1164
- else this.moveChange(event);
1165
- this.timeoutStore.add("moveEnd", this.moveEnd.bind(this));
1166
- }
1167
- moveStart(event) {
1168
- this.start(event);
1169
- this.computeValues(pointerValues(event));
1170
- this.compute(event);
1171
- this.computeInitial();
1172
- this.emit();
1173
- }
1174
- moveChange(event) {
1175
- if (!this.state._active) return;
1176
- const values = pointerValues(event);
1177
- const state = this.state;
1178
- state._delta = V.sub(values, state._values);
1179
- V.addTo(state._movement, state._delta);
1180
- this.computeValues(values);
1181
- this.compute(event);
1182
- this.emit();
1183
- }
1184
- moveEnd(event) {
1185
- if (!this.state._active) return;
1186
- this.state._active = false;
1187
- this.compute(event);
1188
- this.emit();
1189
- }
1190
- bind(bindFunction) {
1191
- bindFunction("pointer", "change", this.move.bind(this));
1192
- bindFunction("pointer", "leave", this.moveEnd.bind(this));
1193
- }
1194
- };
1195
- moveConfigResolver = _objectSpread2(_objectSpread2({}, coordinatesConfigResolver), {}, { mouseOnly: (value = true) => value });
1196
- ScrollEngine = class extends CoordinatesEngine {
1197
- constructor(...args) {
1198
- super(...args);
1199
- _defineProperty(this, "ingKey", "scrolling");
1200
- }
1201
- scroll(event) {
1202
- if (!this.state._active) this.start(event);
1203
- this.scrollChange(event);
1204
- this.timeoutStore.add("scrollEnd", this.scrollEnd.bind(this));
1205
- }
1206
- scrollChange(event) {
1207
- if (event.cancelable) event.preventDefault();
1208
- const state = this.state;
1209
- const values = scrollValues(event);
1210
- state._delta = V.sub(values, state._values);
1211
- V.addTo(state._movement, state._delta);
1212
- this.computeValues(values);
1213
- this.compute(event);
1214
- this.emit();
1215
- }
1216
- scrollEnd() {
1217
- if (!this.state._active) return;
1218
- this.state._active = false;
1219
- this.compute();
1220
- this.emit();
1221
- }
1222
- bind(bindFunction) {
1223
- bindFunction("scroll", "", this.scroll.bind(this));
1224
- }
1225
- };
1226
- scrollConfigResolver = coordinatesConfigResolver;
1227
- WheelEngine = class extends CoordinatesEngine {
1228
- constructor(...args) {
1229
- super(...args);
1230
- _defineProperty(this, "ingKey", "wheeling");
1231
- }
1232
- wheel(event) {
1233
- if (!this.state._active) this.start(event);
1234
- this.wheelChange(event);
1235
- this.timeoutStore.add("wheelEnd", this.wheelEnd.bind(this));
1236
- }
1237
- wheelChange(event) {
1238
- const state = this.state;
1239
- state._delta = wheelValues(event);
1240
- V.addTo(state._movement, state._delta);
1241
- clampStateInternalMovementToBounds(state);
1242
- this.compute(event);
1243
- this.emit();
1244
- }
1245
- wheelEnd() {
1246
- if (!this.state._active) return;
1247
- this.state._active = false;
1248
- this.compute();
1249
- this.emit();
1250
- }
1251
- bind(bindFunction) {
1252
- bindFunction("wheel", "", this.wheel.bind(this));
1253
- }
1254
- };
1255
- wheelConfigResolver = coordinatesConfigResolver;
1256
- HoverEngine = class extends CoordinatesEngine {
1257
- constructor(...args) {
1258
- super(...args);
1259
- _defineProperty(this, "ingKey", "hovering");
1260
- }
1261
- enter(event) {
1262
- if (this.config.mouseOnly && event.pointerType !== "mouse") return;
1263
- this.start(event);
1264
- this.computeValues(pointerValues(event));
1265
- this.compute(event);
1266
- this.emit();
1267
- }
1268
- leave(event) {
1269
- if (this.config.mouseOnly && event.pointerType !== "mouse") return;
1270
- const state = this.state;
1271
- if (!state._active) return;
1272
- state._active = false;
1273
- const values = pointerValues(event);
1274
- state._movement = state._delta = V.sub(values, state._values);
1275
- this.computeValues(values);
1276
- this.compute(event);
1277
- state.delta = state.movement;
1278
- this.emit();
1279
- }
1280
- bind(bindFunction) {
1281
- bindFunction("pointer", "enter", this.enter.bind(this));
1282
- bindFunction("pointer", "leave", this.leave.bind(this));
1283
- }
1284
- };
1285
- hoverConfigResolver = _objectSpread2(_objectSpread2({}, coordinatesConfigResolver), {}, { mouseOnly: (value = true) => value });
1286
- EngineMap = /* @__PURE__ */ new Map();
1287
- ConfigResolverMap = /* @__PURE__ */ new Map();
1288
- dragAction = {
1289
- key: "drag",
1290
- engine: DragEngine,
1291
- resolver: dragConfigResolver
1292
- };
1293
- hoverAction = {
1294
- key: "hover",
1295
- engine: HoverEngine,
1296
- resolver: hoverConfigResolver
1297
- };
1298
- moveAction = {
1299
- key: "move",
1300
- engine: MoveEngine,
1301
- resolver: moveConfigResolver
1302
- };
1303
- pinchAction = {
1304
- key: "pinch",
1305
- engine: PinchEngine,
1306
- resolver: pinchConfigResolver
1307
- };
1308
- scrollAction = {
1309
- key: "scroll",
1310
- engine: ScrollEngine,
1311
- resolver: scrollConfigResolver
1312
- };
1313
- wheelAction = {
1314
- key: "wheel",
1315
- engine: WheelEngine,
1316
- resolver: wheelConfigResolver
1317
- };
1318
- }));
1319
-
1320
- //#endregion
1321
- //#region node_modules/@use-gesture/core/actions/dist/use-gesture-core-actions.esm.js
1322
- var use_gesture_core_actions_esm_exports = /* @__PURE__ */ __export({
1323
- ConfigResolverMap: () => ConfigResolverMap,
1324
- EngineMap: () => EngineMap,
1325
- dragAction: () => dragAction,
1326
- hoverAction: () => hoverAction,
1327
- moveAction: () => moveAction,
1328
- pinchAction: () => pinchAction,
1329
- registerAction: () => registerAction,
1330
- scrollAction: () => scrollAction,
1331
- wheelAction: () => wheelAction
1332
- });
1333
- var init_use_gesture_core_actions_esm = __esmMin((() => {
1334
- init_actions_fe213e88_esm();
1335
- }));
1336
-
1337
- //#endregion
1338
- //#region node_modules/@use-gesture/core/dist/use-gesture-core.esm.js
1339
- var use_gesture_core_esm_exports = /* @__PURE__ */ __export({
1340
- Controller: () => Controller,
1341
- parseMergedHandlers: () => parseMergedHandlers
1342
- });
1343
- function _objectWithoutPropertiesLoose(source, excluded) {
1344
- if (source == null) return {};
1345
- var target = {};
1346
- var sourceKeys = Object.keys(source);
1347
- var key, i;
1348
- for (i = 0; i < sourceKeys.length; i++) {
1349
- key = sourceKeys[i];
1350
- if (excluded.indexOf(key) >= 0) continue;
1351
- target[key] = source[key];
1352
- }
1353
- return target;
1354
- }
1355
- function _objectWithoutProperties(source, excluded) {
1356
- if (source == null) return {};
1357
- var target = _objectWithoutPropertiesLoose(source, excluded);
1358
- var key, i;
1359
- if (Object.getOwnPropertySymbols) {
1360
- var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
1361
- for (i = 0; i < sourceSymbolKeys.length; i++) {
1362
- key = sourceSymbolKeys[i];
1363
- if (excluded.indexOf(key) >= 0) continue;
1364
- if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
1365
- target[key] = source[key];
1366
- }
1367
- }
1368
- return target;
1369
- }
1370
- function resolveWith(config = {}, resolvers) {
1371
- const result = {};
1372
- for (const [key, resolver] of Object.entries(resolvers)) switch (typeof resolver) {
1373
- case "function":
1374
- if (process.env.NODE_ENV === "development") {
1375
- const r = resolver.call(result, config[key], key, config);
1376
- if (!Number.isNaN(r)) result[key] = r;
1377
- } else result[key] = resolver.call(result, config[key], key, config);
1378
- break;
1379
- case "object":
1380
- result[key] = resolveWith(config[key], resolver);
1381
- break;
1382
- case "boolean":
1383
- if (resolver) result[key] = config[key];
1384
- break;
1385
- }
1386
- return result;
1387
- }
1388
- function parse(newConfig, gestureKey, _config = {}) {
1389
- const _ref = newConfig, { target, eventOptions, window: window$1, enabled, transform } = _ref, rest = _objectWithoutProperties(_ref, _excluded);
1390
- _config.shared = resolveWith({
1391
- target,
1392
- eventOptions,
1393
- window: window$1,
1394
- enabled,
1395
- transform
1396
- }, sharedConfigResolver);
1397
- if (gestureKey) {
1398
- const resolver = ConfigResolverMap.get(gestureKey);
1399
- _config[gestureKey] = resolveWith(_objectSpread2({ shared: _config.shared }, rest), resolver);
1400
- } else for (const key in rest) {
1401
- const resolver = ConfigResolverMap.get(key);
1402
- if (resolver) _config[key] = resolveWith(_objectSpread2({ shared: _config.shared }, rest[key]), resolver);
1403
- else if (process.env.NODE_ENV === "development") {
1404
- if (![
1405
- "drag",
1406
- "pinch",
1407
- "scroll",
1408
- "wheel",
1409
- "move",
1410
- "hover"
1411
- ].includes(key)) {
1412
- if (key === "domTarget") throw Error(`[@use-gesture]: \`domTarget\` option has been renamed to \`target\`.`);
1413
- console.warn(`[@use-gesture]: Unknown config key \`${key}\` was used. Please read the documentation for further information.`);
1414
- }
1415
- }
1416
- }
1417
- return _config;
1418
- }
1419
- function setupGesture(ctrl, gestureKey) {
1420
- ctrl.gestures.add(gestureKey);
1421
- ctrl.gestureEventStores[gestureKey] = new EventStore(ctrl, gestureKey);
1422
- ctrl.gestureTimeoutStores[gestureKey] = new TimeoutStore();
1423
- }
1424
- function resolveGestures(ctrl, internalHandlers) {
1425
- if (internalHandlers.drag) setupGesture(ctrl, "drag");
1426
- if (internalHandlers.wheel) setupGesture(ctrl, "wheel");
1427
- if (internalHandlers.scroll) setupGesture(ctrl, "scroll");
1428
- if (internalHandlers.move) setupGesture(ctrl, "move");
1429
- if (internalHandlers.pinch) setupGesture(ctrl, "pinch");
1430
- if (internalHandlers.hover) setupGesture(ctrl, "hover");
1431
- }
1432
- function sortHandlers(_handlers) {
1433
- const native = {};
1434
- const handlers = {};
1435
- const actions = /* @__PURE__ */ new Set();
1436
- for (let key in _handlers) if (RE_NOT_NATIVE.test(key)) {
1437
- actions.add(RegExp.lastMatch);
1438
- handlers[key] = _handlers[key];
1439
- } else native[key] = _handlers[key];
1440
- return [
1441
- handlers,
1442
- native,
1443
- actions
1444
- ];
1445
- }
1446
- function registerGesture(actions, handlers, handlerKey, key, internalHandlers, config) {
1447
- if (!actions.has(handlerKey)) return;
1448
- if (!EngineMap.has(key)) {
1449
- if (process.env.NODE_ENV === "development") console.warn(`[@use-gesture]: You've created a custom handler that that uses the \`${key}\` gesture but isn't properly configured.\n\nPlease add \`${key}Action\` when creating your handler.`);
1450
- return;
1451
- }
1452
- const startKey = handlerKey + "Start";
1453
- const endKey = handlerKey + "End";
1454
- const fn = (state) => {
1455
- let memo = void 0;
1456
- if (state.first && startKey in handlers) handlers[startKey](state);
1457
- if (handlerKey in handlers) memo = handlers[handlerKey](state);
1458
- if (state.last && endKey in handlers) handlers[endKey](state);
1459
- return memo;
1460
- };
1461
- internalHandlers[key] = fn;
1462
- config[key] = config[key] || {};
1463
- }
1464
- function parseMergedHandlers(mergedHandlers, mergedConfig) {
1465
- const [handlers, nativeHandlers, actions] = sortHandlers(mergedHandlers);
1466
- const internalHandlers = {};
1467
- registerGesture(actions, handlers, "onDrag", "drag", internalHandlers, mergedConfig);
1468
- registerGesture(actions, handlers, "onWheel", "wheel", internalHandlers, mergedConfig);
1469
- registerGesture(actions, handlers, "onScroll", "scroll", internalHandlers, mergedConfig);
1470
- registerGesture(actions, handlers, "onPinch", "pinch", internalHandlers, mergedConfig);
1471
- registerGesture(actions, handlers, "onMove", "move", internalHandlers, mergedConfig);
1472
- registerGesture(actions, handlers, "onHover", "hover", internalHandlers, mergedConfig);
1473
- return {
1474
- handlers: internalHandlers,
1475
- config: mergedConfig,
1476
- nativeHandlers
1477
- };
1478
- }
1479
- var sharedConfigResolver, _excluded, EventStore, TimeoutStore, Controller, bindToProps, RE_NOT_NATIVE;
1480
- var init_use_gesture_core_esm = __esmMin((() => {
1481
- init_actions_fe213e88_esm();
1482
- sharedConfigResolver = {
1483
- target(value) {
1484
- if (value) return () => "current" in value ? value.current : value;
1485
- },
1486
- enabled(value = true) {
1487
- return value;
1488
- },
1489
- window(value = SUPPORT.isBrowser ? window : void 0) {
1490
- return value;
1491
- },
1492
- eventOptions({ passive = true, capture = false } = {}) {
1493
- return {
1494
- passive,
1495
- capture
1496
- };
1497
- },
1498
- transform(value) {
1499
- return value;
1500
- }
1501
- };
1502
- _excluded = [
1503
- "target",
1504
- "eventOptions",
1505
- "window",
1506
- "enabled",
1507
- "transform"
1508
- ];
1509
- EventStore = class {
1510
- constructor(ctrl, gestureKey) {
1511
- _defineProperty(this, "_listeners", /* @__PURE__ */ new Set());
1512
- this._ctrl = ctrl;
1513
- this._gestureKey = gestureKey;
1514
- }
1515
- add(element, device, action, handler, options) {
1516
- const listeners = this._listeners;
1517
- const type = toDomEventType(device, action);
1518
- const eventOptions = _objectSpread2(_objectSpread2({}, this._gestureKey ? this._ctrl.config[this._gestureKey].eventOptions : {}), options);
1519
- element.addEventListener(type, handler, eventOptions);
1520
- const remove = () => {
1521
- element.removeEventListener(type, handler, eventOptions);
1522
- listeners.delete(remove);
1523
- };
1524
- listeners.add(remove);
1525
- return remove;
1526
- }
1527
- clean() {
1528
- this._listeners.forEach((remove) => remove());
1529
- this._listeners.clear();
1530
- }
1531
- };
1532
- TimeoutStore = class {
1533
- constructor() {
1534
- _defineProperty(this, "_timeouts", /* @__PURE__ */ new Map());
1535
- }
1536
- add(key, callback, ms = 140, ...args) {
1537
- this.remove(key);
1538
- this._timeouts.set(key, window.setTimeout(callback, ms, ...args));
1539
- }
1540
- remove(key) {
1541
- const timeout = this._timeouts.get(key);
1542
- if (timeout) window.clearTimeout(timeout);
1543
- }
1544
- clean() {
1545
- this._timeouts.forEach((timeout) => void window.clearTimeout(timeout));
1546
- this._timeouts.clear();
1547
- }
1548
- };
1549
- Controller = class {
1550
- constructor(handlers) {
1551
- _defineProperty(this, "gestures", /* @__PURE__ */ new Set());
1552
- _defineProperty(this, "_targetEventStore", new EventStore(this));
1553
- _defineProperty(this, "gestureEventStores", {});
1554
- _defineProperty(this, "gestureTimeoutStores", {});
1555
- _defineProperty(this, "handlers", {});
1556
- _defineProperty(this, "config", {});
1557
- _defineProperty(this, "pointerIds", /* @__PURE__ */ new Set());
1558
- _defineProperty(this, "touchIds", /* @__PURE__ */ new Set());
1559
- _defineProperty(this, "state", { shared: {
1560
- shiftKey: false,
1561
- metaKey: false,
1562
- ctrlKey: false,
1563
- altKey: false
1564
- } });
1565
- resolveGestures(this, handlers);
1566
- }
1567
- setEventIds(event) {
1568
- if (isTouch(event)) {
1569
- this.touchIds = new Set(touchIds(event));
1570
- return this.touchIds;
1571
- } else if ("pointerId" in event) {
1572
- if (event.type === "pointerup" || event.type === "pointercancel") this.pointerIds.delete(event.pointerId);
1573
- else if (event.type === "pointerdown") this.pointerIds.add(event.pointerId);
1574
- return this.pointerIds;
1575
- }
1576
- }
1577
- applyHandlers(handlers, nativeHandlers) {
1578
- this.handlers = handlers;
1579
- this.nativeHandlers = nativeHandlers;
1580
- }
1581
- applyConfig(config, gestureKey) {
1582
- this.config = parse(config, gestureKey, this.config);
1583
- }
1584
- clean() {
1585
- this._targetEventStore.clean();
1586
- for (const key of this.gestures) {
1587
- this.gestureEventStores[key].clean();
1588
- this.gestureTimeoutStores[key].clean();
1589
- }
1590
- }
1591
- effect() {
1592
- if (this.config.shared.target) this.bind();
1593
- return () => this._targetEventStore.clean();
1594
- }
1595
- bind(...args) {
1596
- const sharedConfig = this.config.shared;
1597
- const props = {};
1598
- let target;
1599
- if (sharedConfig.target) {
1600
- target = sharedConfig.target();
1601
- if (!target) return;
1602
- }
1603
- if (sharedConfig.enabled) {
1604
- for (const gestureKey of this.gestures) {
1605
- const gestureConfig = this.config[gestureKey];
1606
- const bindFunction = bindToProps(props, gestureConfig.eventOptions, !!target);
1607
- if (gestureConfig.enabled) new (EngineMap.get(gestureKey))(this, args, gestureKey).bind(bindFunction);
1608
- }
1609
- const nativeBindFunction = bindToProps(props, sharedConfig.eventOptions, !!target);
1610
- for (const eventKey in this.nativeHandlers) nativeBindFunction(eventKey, "", (event) => this.nativeHandlers[eventKey](_objectSpread2(_objectSpread2({}, this.state.shared), {}, {
1611
- event,
1612
- args
1613
- })), void 0, true);
1614
- }
1615
- for (const handlerProp in props) props[handlerProp] = chain(...props[handlerProp]);
1616
- if (!target) return props;
1617
- for (const handlerProp in props) {
1618
- const { device, capture, passive } = parseProp(handlerProp);
1619
- this._targetEventStore.add(target, device, "", props[handlerProp], {
1620
- capture,
1621
- passive
1622
- });
1623
- }
1624
- }
1625
- };
1626
- bindToProps = (props, eventOptions, withPassiveOption) => (device, action, handler, options = {}, isNative = false) => {
1627
- var _options$capture, _options$passive;
1628
- const capture = (_options$capture = options.capture) !== null && _options$capture !== void 0 ? _options$capture : eventOptions.capture;
1629
- const passive = (_options$passive = options.passive) !== null && _options$passive !== void 0 ? _options$passive : eventOptions.passive;
1630
- let handlerProp = isNative ? device : toHandlerProp(device, action, capture);
1631
- if (withPassiveOption && passive) handlerProp += "Passive";
1632
- props[handlerProp] = props[handlerProp] || [];
1633
- props[handlerProp].push(handler);
1634
- };
1635
- RE_NOT_NATIVE = /^on(Drag|Wheel|Scroll|Move|Pinch|Hover)/;
1636
- }));
1637
-
1638
- //#endregion
1639
- //#region node_modules/@use-gesture/core/utils/dist/use-gesture-core-utils.esm.js
1640
- var use_gesture_core_utils_esm_exports = /* @__PURE__ */ __export({ rubberbandIfOutOfBounds: () => rubberbandIfOutOfBounds });
1641
- var init_use_gesture_core_utils_esm = __esmMin((() => {
1642
- init_maths_0ab39ae9_esm();
1643
- }));
1644
-
1645
- //#endregion
1646
- //#region node_modules/@use-gesture/core/types/dist/use-gesture-core-types.esm.js
1647
- var require_use_gesture_core_types_esm = /* @__PURE__ */ __commonJSMin((() => {}));
1648
-
1649
- //#endregion
1650
- export { use_gesture_core_esm_exports as a, init_use_gesture_core_esm as i, init_use_gesture_core_utils_esm as n, init_use_gesture_core_actions_esm as o, use_gesture_core_utils_esm_exports as r, use_gesture_core_actions_esm_exports as s, require_use_gesture_core_types_esm as t };