react-use-gesture
Advanced tools
Comparing version 7.0.5 to 7.0.6
# Changelog | ||
## 7.0.6 Release | ||
**Summary:** fixes `onGestureEnd` logic. | ||
### Fixed | ||
1. Prevents `onPinchEnd` from firing when releasing the pointer without actually triggering pinch in the first place. Fixes [#148](https://github.com/react-spring/react-use-gesture/issues/148). | ||
2. Fixes `onGestureEnd` logic for other gestures. | ||
## 7.0.5 Release | ||
@@ -4,0 +13,0 @@ |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=(e=require("react"))&&"object"==typeof e&&"default"in e?e.default:e;function n(e,t){return e.map((function(e,n){return e+t[n]}))}function r(e,t){return e.map((function(e,n){return e-t[n]}))}function i(e,t,n){return n=n||Math.hypot.apply(Math,e),t?n/t:0}function o(e,t){return t?e.map((function(e){return e/t})):Array(e.length).fill(0)}function a(e){return Math.hypot.apply(Math,e)}function s(e,t){return t=t||Math.hypot.apply(Math,e)||1,e.map((function(e){return e/t}))}function u(e,t,n){var r=Math.hypot.apply(Math,t);return{velocities:o(t,n),velocity:i(t,n,r),distance:a(e),direction:s(t,r)}}function c(e,t){return Math.abs(e)>=t&&Math.sign(e)*t}function l(e,t,n){return 0===t||Infinity===Math.abs(t)?function(e,t){return Math.pow(e,5*t)}(e,n):e*t*n/(t+n*e)}function d(e,t,n,r){return void 0===r&&(r=.15),0===r?function(e,t,n){return Math.max(t,Math.min(e,n))}(e,t,n):e<t?-l(t-e,n-t,r)+t:e>n?l(e-n,n-t,r)+n:e}function v(){return(v=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}function h(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}function f(e,t){if(null==e)return{};var n,r,i={},o=Object.keys(e);for(r=0;r<o.length;r++)t.indexOf(n=o[r])>=0||(i[n]=e[n]);return i}function g(){}var p=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return function(){for(var e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];return t.forEach((function(e){return e.apply(void 0,n)}))}},m={array:function(e){return Array.isArray(e)?e:[e,e]},withDefault:function(e,t){return void 0!==e?e:t}};function S(e,t){var n={};return Object.entries(e).forEach((function(e){var r=e[0],i=e[1];return(void 0!==i||r in t)&&(n[r]=i)})),n}function y(e){return"function"==typeof e?e():e}function w(){var e={_active:!1,_blocked:!1,_intentional:[!1,!1],_movement:[0,0],_initial:[0,0],event:void 0,values:[0,0],velocities:[0,0],delta:[0,0],movement:[0,0],offset:[0,0],lastOffset:[0,0],direction:[0,0],initial:[0,0],previous:[0,0],first:!1,last:!1,active:!1,timeStamp:0,startTime:0,elapsedTime:0,cancel:g,canceled:!1,memo:void 0,args:void 0},t={axis:void 0,xy:[0,0],vxvy:[0,0],velocity:0,distance:0};return{shared:{hovering:!1,scrolling:!1,wheeling:!1,dragging:!1,moving:!1,pinching:!1,touches:0,buttons:0,down:!1,shiftKey:!1,altKey:!1,metaKey:!1,ctrlKey:!1},drag:v({},e,{},t,{_isTap:!0,_delayedEvent:!1,tap:!1,swipe:[0,0]}),pinch:v({},e,{},{da:[0,0],vdva:[0,0],origin:void 0,turns:0}),wheel:v({},e,{},t),move:v({},e,{},t),scroll:v({},e,{},t)}}var b=function(e){return function(t,n,r){var i=e?"addEventListener":"removeEventListener";n.forEach((function(e){return t[i](e[0],e[1],r)}))}},G=b(!0),T=b(!1);function M(e){if("touches"in e){var t=e.touches;return t.length>0?t:e.changedTouches}return null}function _(e){var t="buttons"in e?e.buttons:0,n=M(e),r=n&&n.length||0;return v({touches:r,down:r>0||t>0,buttons:t},function(e){return{shiftKey:e.shiftKey,altKey:e.altKey,metaKey:e.metaKey,ctrlKey:e.ctrlKey}}(e))}function D(e){var t=e.currentTarget;return{values:[t.scrollX||t.scrollLeft||0,t.scrollY||t.scrollTop||0]}}function E(e){return{values:[e.deltaX,e.deltaY]}}function P(e){var t=M(e),n=t?t[0]:e;return{values:[n.clientX,n.clientY]}}var O=260;function B(e){return{values:[e.scale*O,e.rotation]}}function K(e){var t=e.touches,n=t[1].clientX-t[0].clientX,r=t[1].clientY-t[0].clientY;return{values:[Math.hypot(n,r),-180*Math.atan2(n,r)/Math.PI],origin:[(t[1].clientX+t[0].clientX)/2,(t[1].clientY+t[0].clientY)/2]}}var W=function(){var e=this;this.state=w(),this.timeouts={},this.domListeners=[],this.windowListeners={},this.bindings={},this.clean=function(){e.resetBindings(),Object.values(e.timeouts).forEach(clearTimeout),Object.keys(e.windowListeners).forEach((function(t){return e.removeWindowListeners(t)}))},this.resetBindings=function(){e.bindings={};var t=e.getDomTarget();t&&(T(t,e.domListeners,e.config.eventOptions),e.domListeners=[])},this.getDomTarget=function(){var t=e.config.domTarget;return t&&"current"in t?t.current:t},this.addWindowListeners=function(t,n){e.config.window&&(e.windowListeners[t]=n,G(e.config.window,n,e.config.eventOptions))},this.removeWindowListeners=function(t){if(e.config.window){var n=e.windowListeners[t];n&&(T(e.config.window,n,e.config.eventOptions),delete e.windowListeners[t])}},this.addDomTargetListeners=function(t){Object.entries(e.bindings).forEach((function(t){var n=t[1];e.domListeners.push([t[0].substr(2).toLowerCase(),p.apply(void 0,n)])})),G(t,e.domListeners,e.config.eventOptions)},this.addBindings=function(t,n){(Array.isArray(t)?t:[t]).forEach((function(t){e.bindings[t]?e.bindings[t].push(n):e.bindings[t]=[n]}))},this.getBindings=function(){var t={},n=e.config.captureString;return Object.entries(e.bindings).forEach((function(e){var r=e[0],i=e[1],o=Array.isArray(i)?i:[i];t[r+n]=p.apply(void 0,o)})),t},this.getBind=function(){if(e.config.domTarget){var t=e.getDomTarget();return t&&e.addDomTargetListeners(t),e.clean}return e.getBindings()}};function L(e,n,r,i){var o=t.useRef(),a=t.useRef();return o.current||(o.current=new W),o.current.config=r,o.current.handlers=e,a.current=i,t.useEffect((function(){return o.current.clean}),[]),t.useState((function(){return function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];return o.current.resetBindings(),n.forEach((function(e){new e(o.current,t).addBindings()})),a.current&&Object.entries(a.current).forEach((function(e){o.current.addBindings(e[0],e[1])})),o.current.getBind()}}))[0]}var x=function(){function e(e,t,n){var r=this;void 0===n&&(n=[]),this.stateKey=e,this.controller=t,this.args=n,this.debounced=!0,this.setTimeout=function(e,t){var n;void 0===t&&(t=140);for(var i=arguments.length,o=new Array(i>2?i-2:0),a=2;a<i;a++)o[a-2]=arguments[a];r.controller.timeouts[r.stateKey]=(n=window).setTimeout.apply(n,[e,t].concat(o))},this.clearTimeout=function(){clearTimeout(r.controller.timeouts[r.stateKey])},this.addWindowListeners=function(e){r.controller.addWindowListeners(r.stateKey,e)},this.removeWindowListeners=function(){r.controller.removeWindowListeners(r.stateKey)},this.getStartGestureState=function(e,t){return v({},w()[r.stateKey],{_active:!0,values:e,initial:e,offset:r.state.offset,lastOffset:r.state.offset,startTime:t.timeStamp})},this.rubberband=function(e,t){var n=r.config.bounds;return e.map((function(e,r){return d(e,n[r][0],n[r][1],t[r])}))},this.fireGestureHandler=function(e){if(r.state._blocked)return r.debounced||(r.state._active=!1,r.clean()),null;var t=r.state._intentional;if(!e&&!1===t[0]&&!1===t[1])return null;var n=r.state,i=n._active,o=n.active;r.state.active=i,r.state.first=i&&!o,r.state.last=!i,r.controller.state.shared[r.ingKey]=i;var a=v({},r.controller.state.shared,{},r.state,{},r.mapStateValues(r.state)),s=r.handler(a);return r.state.memo=void 0!==s?s:r.state.memo,i||r.clean(),a}}var t,i=e.prototype;return i.updateSharedState=function(e){Object.assign(this.controller.state.shared,e)},i.updateGestureState=function(e){Object.assign(this.state,e)},i.getGenericPayload=function(e,t){var n=e.timeStamp,r=this.state;return{event:e,timeStamp:n,elapsedTime:t?0:n-r.startTime,args:this.args,previous:r.values}},i.checkIntentionality=function(e,t,n){return{_intentional:e,_blocked:!1}},i.getMovement=function(e,t){void 0===t&&(t=this.state);var i=this.config,o=i.initial,a=i.threshold,s=i.rubberband,u=a[0],l=a[1],d=t._initial,h=t._active,f=t._intentional,g=t.lastOffset,p=t.movement,m=f[0],S=f[1],w=this.getInternalMovement(e,t),b=w[0],G=w[1];!1===m&&(m=c(b,u)),!1===S&&(S=c(G,l));var T=this.checkIntentionality([m,S],[b,G],t),M=T._intentional,_=T._blocked,D=M[0],E=M[1],P=[b,G];if(!1!==D&&!1===f[0]&&(d[0]=y(o)[0]),!1!==E&&!1===f[1]&&(d[1]=y(o)[1]),_)return v({},T,{_movement:P,delta:[0,0]});var O=[!1!==D?b-D:y(o)[0],!1!==E?G-E:y(o)[1]],B=n(O,g),K=h?s:[0,0];return v({},T,{_initial:d,_movement:P,movement:O=this.rubberband(n(O,d),K),offset:this.rubberband(B,K),delta:r(O,p)})},i.clean=function(){this.clearTimeout(),this.removeWindowListeners()},(t=[{key:"config",get:function(){return this.controller.config[this.stateKey]}},{key:"enabled",get:function(){return this.controller.config.enabled&&this.config.enabled}},{key:"state",get:function(){return this.controller.state[this.stateKey]}},{key:"handler",get:function(){return this.controller.handlers[this.stateKey]}}])&&function(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}(e.prototype,t),e}(),C=function(e){function t(){return e.apply(this,arguments)||this}h(t,e);var n=t.prototype;return n.getInternalMovement=function(e,t){return r(e,t.initial)},n.checkIntentionality=function(e,t,n){var r=n.axis,i=!1;if(!1!==e[0]||!1!==e[1]){var o=t.map(Math.abs),a=o[0],s=o[1],u=this.config,c=u.axis;r=r||(a>s?"x":a<s?"y":void 0),(c||u.lockDirection)&&(r?c&&r!==c?i=!0:e["x"===r?1:0]=!1:e=[!1,!1])}return{_intentional:e,_blocked:i,axis:r}},n.getKinematics=function(e,t){var n=this.state.timeStamp,r=this.getMovement(e,this.state),i=r.delta;return r._blocked?r:v({values:e,delta:i},r,{},u(r.movement,i,t.timeStamp-n))},n.mapStateValues=function(e){return{xy:e.values,vxvy:e.velocities}},t}(x),H=3,k=220,I=function(e){function t(t,n){var r;return(r=e.call(this,"drag",t,n)||this).ingKey="dragging",r.dragShouldStart=function(e){var t=_(e);return r.enabled&&t.touches<2},r.setPointers=function(e){var t=e.currentTarget,n=e.pointerId;t&&t.setPointerCapture(n),r.updateGestureState({currentTarget:t,pointerId:n})},r.removePointers=function(){var e=r.state,t=e.currentTarget;t&&t.releasePointerCapture(e.pointerId)},r.setListeners=function(){r.removeWindowListeners(),r.addWindowListeners([["touchmove",r.onDragChange],["touchend",r.onDragEnd],["touchcancel",r.onDragEnd],["mousemove",r.onDragChange],["mouseup",r.onDragEnd]])},r.onDragStart=function(e){r.dragShouldStart(e)&&(r.controller.config.pointer?r.setPointers(e):r.setListeners(),r.config.delay>0?(r.state._delayedEvent=!0,"function"==typeof e.persist&&e.persist(),r.setTimeout((function(){return r.startDrag(e)}),r.config.delay)):r.startDrag(e))},r.onDragChange=function(e){if(!r.state.canceled)if(r.state._active){var t=_(e);if(t.down){r.updateSharedState(t);var n=P(e),i=r.getKinematics(n.values,e),o=r.state._isTap;o&&a(i._movement)>=H&&(o=!1),r.updateGestureState(v({},r.getGenericPayload(e),{},i,{_isTap:o,cancel:function(){return r.onCancel()}})),r.fireGestureHandler()}else r.onDragEnd(e)}else r.state._delayedEvent&&(r.clearTimeout(),r.startDrag(e))},r.onDragEnd=function(e){r.state._active=!1,r.updateSharedState({down:!1,buttons:0,touches:0});var t=r.state,n=t._isTap,i=t.values,o=t.velocities,a=o[0],s=o[1],u=t.movement,c=u[0],l=u[1],d=t._intentional,h=d[0],f=d[1],g=v({},r.getGenericPayload(e),{},r.getMovement(i)),p=r.config,m=p.swipeVelocity,S=m[0],y=m[1],w=p.swipeDistance,b=w[0],G=w[1],T=[0,0];g.elapsedTime<k&&(!1!==h&&Math.abs(a)>S&&Math.abs(c)>b&&(T[0]=Math.sign(a)),!1!==f&&Math.abs(s)>y&&Math.abs(l)>G&&(T[1]=Math.sign(s))),r.updateGestureState(v({event:e},g,{tap:n,swipe:T})),r.fireGestureHandler(r.config.filterTaps&&r.state._isTap)},r.clean=function(){e.prototype.clean.call(function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(r)),r.state._delayedEvent=!1,r.controller.config.pointer&&r.removePointers()},r.onCancel=function(){r.updateGestureState({canceled:!0,cancel:g}),r.state._active=!1,r.updateSharedState({down:!1,buttons:0,touches:0}),requestAnimationFrame((function(){return r.fireGestureHandler()}))},r}h(t,e);var n=t.prototype;return n.startDrag=function(e){var t=this,n=P(e).values;this.updateSharedState(_(e));var r=v({},this.getStartGestureState(n,e),{},this.getGenericPayload(e,!0));this.updateGestureState(v({},r,{},this.getMovement(n,r),{cancel:function(){return t.onCancel()}})),this.fireGestureHandler()},n.addBindings=function(){this.controller.config.pointer?(this.controller.addBindings("onPointerDown",this.onDragStart),this.controller.addBindings("onPointerMove",this.onDragChange),this.controller.addBindings(["onPointerUp","onPointerCancel"],this.onDragEnd)):this.controller.addBindings(["onTouchStart","onMouseDown"],this.onDragStart)},t}(C),V=180,j=.15;function A(){return"undefined"!=typeof window?window:void 0}function R(e){void 0===e&&(e={});var t={domTarget:void 0,eventOptions:{passive:!0,capture:!1,pointer:!1},window:A(),enabled:!0},n=t.eventOptions,r=t.window,i=f(t,["eventOptions","window"]),o=e.eventOptions,a=e.window,s=f(e,["eventOptions","window"]),u=v({},n,{},o),c=u.capture;return v({},i,{},s,{window:a||r,eventOptions:{passive:!e.domTarget||!!u.passive,capture:!!c},captureString:c?"Capture":"",pointer:!!u.pointer})}function F(e){var t=v({},{enabled:!0,initial:[0,0],threshold:void 0,rubberband:0},{},e),n=t.threshold,r=t.rubberband;return"boolean"==typeof r&&(r=r?j:0),void 0===n&&(n=0),{enabled:t.enabled,initial:t.initial,threshold:m.array(n),rubberband:m.array(r)}}function X(e){void 0===e&&(e={});var t=e.axis,n=e.lockDirection,r=e.bounds,i=void 0===r?{}:r,o=f(e,["axis","lockDirection","bounds"]),a=[[m.withDefault(i.left,-Infinity),m.withDefault(i.right,Infinity)],[m.withDefault(i.top,-Infinity),m.withDefault(i.bottom,Infinity)]];return v({},F(o),{},{lockDirection:!1,axis:void 0,bounds:void 0},{},S({axis:t,lockDirection:n},e),{bounds:a})}function Y(e){void 0===e&&(e={});var t=e.distanceBounds,n=void 0===t?{}:t,r=e.angleBounds,i=void 0===r?{}:r,o=f(e,["distanceBounds","angleBounds"]),a=[[m.withDefault(n.min,-Infinity),m.withDefault(n.max,Infinity)],[m.withDefault(i.min,-Infinity),m.withDefault(i.max,Infinity)]];return v({},F(o),{bounds:a})}function q(e){void 0===e&&(e={});var t=e.enabled,n=e.threshold,r=e.bounds,i=e.rubberband,o=e.initial,a=v({},{filterTaps:!1,swipeVelocity:.5,swipeDistance:60,delay:!1},{},f(e,["enabled","threshold","bounds","rubberband","initial"])),s=a.swipeVelocity,u=a.swipeDistance,c=a.delay,l=a.filterTaps,d=a.axis,h=a.lockDirection;void 0===n?n=Math.max(0,l?3:0,h||d?1:0):l=!0;var g=X(S({enabled:t,threshold:n,bounds:r,rubberband:i,axis:d,lockDirection:h,initial:o},e));return v({},g,{filterTaps:l||g.threshold[0]+g.threshold[1]>0,swipeVelocity:m.array(s),swipeDistance:m.array(u),delay:"number"==typeof c?c:c?V:0})}var U=function(e){function t(t,n){var r;return(r=e.call(this,"pinch",t,n)||this).ingKey="pinching",r.pinchShouldStart=function(e){var t=_(e);return r.enabled&&2===t.touches},r.onPinchStart=function(e){if(r.pinchShouldStart(e)){var t=K(e),n=t.values,i=t.origin;r.updateSharedState(_(e));var o=v({},r.getStartGestureState(n,e),{},r.getGenericPayload(e,!0));r.updateGestureState(v({},o,{},r.getMovement(n,o),{origin:i,cancel:function(){return r.onCancel()}})),r.fireGestureHandler()}},r.onPinchChange=function(e){var t=r.state,n=t.timeStamp;if(!t.canceled&&t._active){var i=_(e);if(2===i.touches&&e.timeStamp!==n){r.updateSharedState(i);var o=K(e),a=o.origin,s=r.getKinematics(o.values,e);r.updateGestureState(v({},r.getGenericPayload(e),{},s,{origin:a,cancel:function(){return r.onCancel()}})),r.fireGestureHandler()}}},r.onPinchEnd=function(e){r.state._active=!1,r.updateSharedState({down:!1,touches:0}),r.updateGestureState(v({event:e},r.getGenericPayload(e),{},r.getMovement(r.state.values))),r.fireGestureHandler()},r.onCancel=function(){r.state._active=!1,r.updateGestureState({canceled:!0,cancel:g}),r.updateSharedState({down:!1,touches:0}),requestAnimationFrame((function(){return r.fireGestureHandler()}))},r.onGestureStart=function(e){if(r.enabled){e.preventDefault();var t=B(e).values;r.updateSharedState(_(e));var n=v({},r.getStartGestureState(t,e),{},r.getGenericPayload(e,!0));r.updateGestureState(v({},n,{},r.getMovement(t,n),{cancel:function(){return r.onCancel()}})),r.fireGestureHandler()}},r.onGestureChange=function(e){var t=r.state;if(!t.canceled&&t._active){e.preventDefault();var n=_(e);r.updateSharedState(n);var i=B(e),o=r.getKinematics(i.values,e);r.updateGestureState(v({},r.getGenericPayload(e),{},o,{cancel:function(){return r.onCancel()}})),r.fireGestureHandler()}},r.onGestureEnd=function(e){e.preventDefault(),r.state._active=!1,r.updateSharedState({down:!1,touches:0}),r.updateGestureState(v({event:e},r.getGenericPayload(e),{},r.getMovement(r.state.values))),r.fireGestureHandler()},r.updateTouchData=function(e){if(r.enabled&&2===e.touches.length){var t=K(e);r.state.origin=t.origin}},r.wheelShouldRun=function(e){return r.enabled&&e.ctrlKey},r.getWheelValuesFromEvent=function(e){var t=E(e).values[1],n=r.state.values,i=n[1];return{values:[n[0]-t,void 0!==i?i:0],origin:[e.clientX,e.clientY],delta:[0,t]}},r.onWheel=function(e){r.wheelShouldRun(e)&&(r.clearTimeout(),r.setTimeout(r.onWheelEnd),r.state._active?r.onWheelChange(e):r.onWheelStart(e))},r.onWheelStart=function(e){var t=r.getWheelValuesFromEvent(e),n=t.values,i=t.delta,o=t.origin;r.controller.config.eventOptions.passive||e.preventDefault(),r.updateSharedState(_(e));var a=v({},r.getStartGestureState(n,e),{},r.getGenericPayload(e,!0),{initial:r.state.values});r.updateGestureState(v({},a,{},r.getMovement(n,a),{offset:n,delta:i,origin:o})),r.fireGestureHandler()},r.onWheelChange=function(e){var t=_(e);r.updateSharedState(t);var n=r.getWheelValuesFromEvent(e),i=n.origin,o=n.delta,a=r.getKinematics(n.values,e);r.updateGestureState(v({},r.getGenericPayload(e),{},a,{origin:i,delta:o})),r.fireGestureHandler()},r.onWheelEnd=function(){r.state._active=!1,r.updateGestureState(r.getMovement(r.state.values)),r.fireGestureHandler()},r}return h(t,e),t.prototype.addBindings=function(){!function(){try{return"constructor"in GestureEvent}catch(e){return!1}}()?(this.controller.addBindings("onTouchStart",this.onPinchStart),this.controller.addBindings("onTouchMove",this.onPinchChange),this.controller.addBindings(["onTouchEnd","onTouchCancel"],this.onPinchEnd),this.controller.addBindings("onWheel",this.onWheel)):(this.controller.addBindings("onGestureStart",this.onGestureStart),this.controller.addBindings("onGestureChange",this.onGestureChange),this.controller.addBindings(["onGestureEnd","onTouchCancel"],this.onGestureEnd),this.controller.addBindings(["onTouchStart","onTouchMove"],this.updateTouchData))},t}(function(e){function t(){return e.apply(this,arguments)||this}h(t,e);var n=t.prototype;return n.getInternalMovement=function(e,t){var n=e[0],r=e[1],i=t.values,o=t.turns,a=t.initial,s=(r=void 0!==r?r:i[1])-i[1],u=Math.abs(s)>270?o+Math.sign(s):o;return[n-a[0],r-360*u-a[1]]},n.getKinematics=function(e,t){var n=this.state,r=n.timeStamp,i=n.initial,o=this.getMovement(e,this.state),a=o.delta,s=o.movement;return v({values:e,delta:a,turns:(e[1]-s[1]-i[1])/360},o,{},u(s,a,t.timeStamp-r))},n.mapStateValues=function(e){return{da:e.values,vdva:e.velocities}},t}(x)),z=function(e){function t(t,r){var i;return(i=e.call(this,"wheel",t,r)||this).ingKey="wheeling",i.debounced=!0,i.wheelShouldRun=function(e){return!(e.ctrlKey&&"pinch"in i.controller.handlers)&&i.enabled},i.getValuesFromEvent=function(e){var t=i.state.values;return{values:n(E(e).values,t)}},i.onWheel=function(e){i.wheelShouldRun(e)&&(i.clearTimeout(),i.setTimeout(i.onWheelEnd),i.state._active?i.onWheelChange(e):i.onWheelStart(e))},i.onWheelStart=function(e){var t=i.getValuesFromEvent(e).values;i.updateSharedState(_(e));var n=v({},i.getStartGestureState(t,e),{},i.getGenericPayload(e,!0),{initial:i.state.values}),r=i.getMovement(t,n),o=r.delta;i.updateGestureState(v({},n,{},r,{distance:a(o),direction:s(o)})),i.fireGestureHandler()},i.onWheelChange=function(e){var t=_(e);i.updateSharedState(t);var n=i.getValuesFromEvent(e),r=i.getKinematics(n.values,e);i.updateGestureState(v({},i.getGenericPayload(e),{},r)),i.fireGestureHandler()},i.onWheelEnd=function(){i.state._active=!1,i.updateGestureState(v({},i.getMovement(i.state.values),{velocities:[0,0],velocity:0})),i.fireGestureHandler()},i}return h(t,e),t.prototype.addBindings=function(){this.controller.addBindings("onWheel",this.onWheel)},t}(C),J=function(e){function t(t,n){var r;return(r=e.call(this,"move",t,n)||this).ingKey="moving",r.debounced=!0,r.moveShouldRun=function(){return r.enabled},r.onMove=function(e){r.moveShouldRun()&&(r.clearTimeout(),r.setTimeout(r.onMoveEnd),r.state._active?r.onMoveChange(e):r.onMoveStart(e))},r.onMoveStart=function(e){var t=P(e).values;r.updateSharedState(_(e));var n=v({},r.getStartGestureState(t,e),{},r.getGenericPayload(e,!0));r.updateGestureState(v({},n,{},r.getMovement(t,n))),r.fireGestureHandler()},r.onMoveChange=function(e){var t=_(e);r.updateSharedState(t);var n=P(e),i=r.getKinematics(n.values,e);r.updateGestureState(v({},r.getGenericPayload(e),{},i)),r.fireGestureHandler()},r.onMoveEnd=function(){r.state._active=!1,r.updateGestureState(v({},r.getMovement(r.state.values),{velocities:[0,0],velocity:0})),r.fireGestureHandler()},r.onPointerEnter=function(e){if(r.controller.state.shared.hovering=!0,r.controller.config.enabled){if(r.controller.config.hover.enabled){var t=P(e).values,n=v({},r.controller.state.shared,{},r.state,{},r.getGenericPayload(e,!0),{values:t,active:!0,hovering:!0});r.controller.handlers.hover(v({},n,{},r.mapStateValues(n)))}"move"in r.controller.handlers&&r.onMoveStart(e)}},r.onPointerLeave=function(e){if(r.controller.state.shared.hovering=!1,r.controller.config.hover.enabled){var t=P(e).values,n=v({},r.controller.state.shared,{},r.state,{},r.getGenericPayload(e),{values:t,active:!1});r.controller.handlers.hover(v({},n,{},r.mapStateValues(n)))}"move"in r.controller.handlers&&r.onMoveEnd()},r}return h(t,e),t.prototype.addBindings=function(){this.controller.config.pointer?("move"in this.controller.handlers&&this.controller.addBindings("onPointerMove",this.onMove),"hover"in this.controller.handlers&&(this.controller.addBindings("onPointerEnter",this.onPointerEnter),this.controller.addBindings("onPointerLeave",this.onPointerLeave))):("move"in this.controller.handlers&&this.controller.addBindings("onMouseMove",this.onMove),"hover"in this.controller.handlers&&(this.controller.addBindings("onMouseEnter",this.onPointerEnter),this.controller.addBindings("onMouseLeave",this.onPointerLeave)))},t}(C),N=function(e){function t(t,n){var r;return(r=e.call(this,"scroll",t,n)||this).ingKey="scrolling",r.debounced=!0,r.scrollShouldRun=function(){return r.enabled},r.onScroll=function(e){r.scrollShouldRun()&&(r.clearTimeout(),r.setTimeout(r.onScrollEnd),r.state._active?r.onScrollChange(e):r.onScrollStart(e))},r.onScrollStart=function(e){var t=D(e).values;r.updateSharedState(_(e));var n=v({},r.getStartGestureState(t,e),{},r.getGenericPayload(e,!0),{initial:r.state.values}),i=r.getMovement(t,n),o=i.delta;r.updateGestureState(v({},n,{},i,{distance:a(o),direction:s(o)})),r.fireGestureHandler()},r.onScrollChange=function(e){var t=_(e);r.updateSharedState(t);var n=D(e),i=r.getKinematics(n.values,e);r.updateGestureState(v({},r.getGenericPayload(e),{},i)),r.fireGestureHandler()},r.onScrollEnd=function(){r.state._active=!1,r.updateGestureState(v({},r.getMovement(r.state.values),{velocities:[0,0],velocity:0})),r.fireGestureHandler()},r}return h(t,e),t.prototype.addBindings=function(){this.controller.addBindings("onScroll",this.onScroll)},t}(C);function Q(e,t,n){var r=t+"Start",i=t+"End";return delete n[t],delete n[r],delete n[i],function(n){var o=void 0;return n.first&&r in e&&e[r](n),t in e&&(o=e[t](n)),n.last&&i in e&&e[i](n),o}}exports.addV=n,exports.rubberbandIfOutOfBounds=d,exports.subV=r,exports.useDrag=function(e,t){void 0===t&&(t={});var n=t.domTarget,r=t.eventOptions,i=t.window,o=f(t,["domTarget","eventOptions","window"]),a=v({},R({domTarget:n,eventOptions:r,window:i}),{drag:q(o)});return L({drag:e},[I],a)},exports.useGesture=function(e,n){void 0===n&&(n={});var r=t.useState((function(){return new Set(Object.keys(e).map((function(e){return e.replace(/End|Start/,"")})))}))[0],i=n.drag,o=n.wheel,a=n.move,s=n.scroll,u=n.pinch,c=n.hover,l=R(f(n,["drag","wheel","move","scroll","pinch","hover"])),d=[],h={},g=v({},e);return r.has("onDrag")&&(d.push(I),h.drag=Q(e,"onDrag",g),l.drag=q(i)),r.has("onWheel")&&(d.push(z),h.wheel=Q(e,"onWheel",g),l.wheel=X(o)),r.has("onScroll")&&(d.push(N),h.scroll=Q(e,"onScroll",g),l.scroll=X(s)),r.has("onMove")&&(d.push(J),h.move=Q(e,"onMove",g),l.move=X(a)),r.has("onPinch")&&(d.push(U),h.pinch=Q(e,"onPinch",g),l.pinch=Y(u)),r.has("onHover")&&(r.has("onMove")||d.push(J),h.hover=e.onHover,l.hover=v({enabled:!0},c),delete g.onHover),L(h,d,l,g)},exports.useHover=function(e,t){void 0===t&&(t={});var n=t.domTarget,r=t.eventOptions,i=t.window,o=f(t,["domTarget","eventOptions","window"]),a=v({},R({domTarget:n,eventOptions:r,window:i}),{hover:v({enabled:!0},o)});return L({hover:e},[J],a)},exports.useMove=function(e,t){void 0===t&&(t={});var n=t.domTarget,r=t.eventOptions,i=t.window,o=f(t,["domTarget","eventOptions","window"]),a=v({},R({domTarget:n,eventOptions:r,window:i}),{move:X(o)});return L({move:e},[J],a)},exports.usePinch=function(e,t){void 0===t&&(t={});var n=t.domTarget,r=t.eventOptions,i=t.window,o=f(t,["domTarget","eventOptions","window"]),a=v({},R({domTarget:n,eventOptions:r,window:i}),{pinch:Y(o)});return L({pinch:e},[U],a)},exports.useScroll=function(e,t){void 0===t&&(t={});var n=t.domTarget,r=t.eventOptions,i=t.window,o=f(t,["domTarget","eventOptions","window"]),a=v({},R({domTarget:n,eventOptions:r,window:i}),{scroll:X(o)});return L({scroll:e},[N],a)},exports.useWheel=function(e,t){void 0===t&&(t={});var n=t.domTarget,r=t.eventOptions,i=t.window,o=f(t,["domTarget","eventOptions","window"]),a=v({},R({domTarget:n,eventOptions:r,window:i}),{wheel:X(o)});return L({wheel:e},[z],a)}; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=(e=require("react"))&&"object"==typeof e&&"default"in e?e.default:e;function n(e,t){return e.map((function(e,n){return e+t[n]}))}function r(e,t){return e.map((function(e,n){return e-t[n]}))}function i(e,t,n){return n=n||Math.hypot.apply(Math,e),t?n/t:0}function o(e,t){return t?e.map((function(e){return e/t})):Array(e.length).fill(0)}function a(e){return Math.hypot.apply(Math,e)}function s(e,t){return t=t||Math.hypot.apply(Math,e)||1,e.map((function(e){return e/t}))}function u(e,t,n){var r=Math.hypot.apply(Math,t);return{velocities:o(t,n),velocity:i(t,n,r),distance:a(e),direction:s(t,r)}}function c(e,t){return Math.abs(e)>=t&&Math.sign(e)*t}function l(e,t,n){return 0===t||Infinity===Math.abs(t)?function(e,t){return Math.pow(e,5*t)}(e,n):e*t*n/(t+n*e)}function d(e,t,n,r){return void 0===r&&(r=.15),0===r?function(e,t,n){return Math.max(t,Math.min(e,n))}(e,t,n):e<t?-l(t-e,n-t,r)+t:e>n?l(e-n,n-t,r)+n:e}function v(){return(v=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}function h(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}function f(e,t){if(null==e)return{};var n,r,i={},o=Object.keys(e);for(r=0;r<o.length;r++)t.indexOf(n=o[r])>=0||(i[n]=e[n]);return i}function g(){}var p=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return function(){for(var e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];return t.forEach((function(e){return e.apply(void 0,n)}))}},m=function(e){return Array.isArray(e)?e:[e,e]},S=function(e,t){return void 0!==e?e:t};function y(e,t){var n={};return Object.entries(e).forEach((function(e){var r=e[0],i=e[1];return(void 0!==i||r in t)&&(n[r]=i)})),n}function w(e){return"function"==typeof e?e():e}function b(){var e={_active:!1,_blocked:!1,_intentional:[!1,!1],_movement:[0,0],_initial:[0,0],event:void 0,values:[0,0],velocities:[0,0],delta:[0,0],movement:[0,0],offset:[0,0],lastOffset:[0,0],direction:[0,0],initial:[0,0],previous:[0,0],first:!1,last:!1,active:!1,timeStamp:0,startTime:0,elapsedTime:0,cancel:g,canceled:!1,memo:void 0,args:void 0},t={axis:void 0,xy:[0,0],vxvy:[0,0],velocity:0,distance:0};return{shared:{hovering:!1,scrolling:!1,wheeling:!1,dragging:!1,moving:!1,pinching:!1,touches:0,buttons:0,down:!1,shiftKey:!1,altKey:!1,metaKey:!1,ctrlKey:!1},drag:v({},e,{},t,{_isTap:!0,_delayedEvent:!1,tap:!1,swipe:[0,0]}),pinch:v({},e,{},{da:[0,0],vdva:[0,0],origin:void 0,turns:0}),wheel:v({},e,{},t),move:v({},e,{},t),scroll:v({},e,{},t)}}var G=function(e){return function(t,n,r){var i=e?"addEventListener":"removeEventListener";n.forEach((function(e){return t[i](e[0],e[1],r)}))}},T=G(!0),M=G(!1);function _(e){if("touches"in e){var t=e.touches;return t.length>0?t:e.changedTouches}return null}function E(e){var t="buttons"in e?e.buttons:0,n=_(e),r=n&&n.length||0;return v({touches:r,down:r>0||t>0,buttons:t},function(e){return{shiftKey:e.shiftKey,altKey:e.altKey,metaKey:e.metaKey,ctrlKey:e.ctrlKey}}(e))}function P(e){var t=e.currentTarget;return{values:[t.scrollX||t.scrollLeft||0,t.scrollY||t.scrollTop||0]}}function O(e){return{values:[e.deltaX,e.deltaY]}}function D(e){var t=_(e),n=t?t[0]:e;return{values:[n.clientX,n.clientY]}}function B(e){return{values:[260*e.scale,e.rotation]}}function K(e){var t=e.touches,n=t[1].clientX-t[0].clientX,r=t[1].clientY-t[0].clientY;return{values:[Math.hypot(n,r),-180*Math.atan2(n,r)/Math.PI],origin:[(t[1].clientX+t[0].clientX)/2,(t[1].clientY+t[0].clientY)/2]}}var W=function(){var e=this;this.state=b(),this.timeouts={},this.domListeners=[],this.windowListeners={},this.bindings={},this.clean=function(){e.resetBindings(),Object.values(e.timeouts).forEach(clearTimeout),Object.keys(e.windowListeners).forEach((function(t){return e.removeWindowListeners(t)}))},this.resetBindings=function(){e.bindings={};var t=e.getDomTarget();t&&(M(t,e.domListeners,e.config.eventOptions),e.domListeners=[])},this.getDomTarget=function(){var t=e.config.domTarget;return t&&"current"in t?t.current:t},this.addWindowListeners=function(t,n){e.config.window&&(e.windowListeners[t]=n,T(e.config.window,n,e.config.eventOptions))},this.removeWindowListeners=function(t){if(e.config.window){var n=e.windowListeners[t];n&&(M(e.config.window,n,e.config.eventOptions),delete e.windowListeners[t])}},this.addDomTargetListeners=function(t){Object.entries(e.bindings).forEach((function(t){var n=t[1];e.domListeners.push([t[0].substr(2).toLowerCase(),p.apply(void 0,n)])})),T(t,e.domListeners,e.config.eventOptions)},this.addBindings=function(t,n){(Array.isArray(t)?t:[t]).forEach((function(t){e.bindings[t]?e.bindings[t].push(n):e.bindings[t]=[n]}))},this.getBindings=function(){var t={},n=e.config.captureString;return Object.entries(e.bindings).forEach((function(e){var r=e[0],i=e[1],o=Array.isArray(i)?i:[i];t[r+n]=p.apply(void 0,o)})),t},this.getBind=function(){if(e.config.domTarget){var t=e.getDomTarget();return t&&e.addDomTargetListeners(t),e.clean}return e.getBindings()}};function L(e,n,r,i){var o=t.useRef(),a=t.useRef();return o.current||(o.current=new W),o.current.config=r,o.current.handlers=e,a.current=i,t.useEffect((function(){return o.current.clean}),[]),t.useState((function(){return function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];return o.current.resetBindings(),n.forEach((function(e){new e(o.current,t).addBindings()})),a.current&&Object.entries(a.current).forEach((function(e){o.current.addBindings(e[0],e[1])})),o.current.getBind()}}))[0]}var x=function(){function e(e,t,n){var r=this;void 0===n&&(n=[]),this.stateKey=e,this.controller=t,this.args=n,this.debounced=!0,this.setTimeout=function(e,t){var n;void 0===t&&(t=140);for(var i=arguments.length,o=new Array(i>2?i-2:0),a=2;a<i;a++)o[a-2]=arguments[a];r.controller.timeouts[r.stateKey]=(n=window).setTimeout.apply(n,[e,t].concat(o))},this.clearTimeout=function(){clearTimeout(r.controller.timeouts[r.stateKey])},this.addWindowListeners=function(e){r.controller.addWindowListeners(r.stateKey,e)},this.removeWindowListeners=function(){r.controller.removeWindowListeners(r.stateKey)},this.getStartGestureState=function(e,t){return v({},b()[r.stateKey],{_active:!0,values:e,initial:e,offset:r.state.offset,lastOffset:r.state.offset,startTime:t.timeStamp})},this.rubberband=function(e,t){var n=r.config.bounds;return e.map((function(e,r){return d(e,n[r][0],n[r][1],t[r])}))},this.fireGestureHandler=function(e){if(r.state._blocked)return r.debounced||(r.state._active=!1,r.clean()),null;var t=r.state._intentional;if(!e&&!1===t[0]&&!1===t[1])return null;var n=r.state,i=n._active,o=n.active;r.state.active=i,r.state.first=i&&!o,r.state.last=o&&!i,r.controller.state.shared[r.ingKey]=i;var a=v({},r.controller.state.shared,{},r.state,{},r.mapStateValues(r.state)),s=r.handler(a);return r.state.memo=void 0!==s?s:r.state.memo,i||r.clean(),a}}var t,i=e.prototype;return i.updateSharedState=function(e){Object.assign(this.controller.state.shared,e)},i.updateGestureState=function(e){Object.assign(this.state,e)},i.getGenericPayload=function(e,t){var n=e.timeStamp,r=this.state;return{event:e,timeStamp:n,elapsedTime:t?0:n-r.startTime,args:this.args,previous:r.values}},i.checkIntentionality=function(e,t,n){return{_intentional:e,_blocked:!1}},i.getMovement=function(e,t){void 0===t&&(t=this.state);var i=this.config,o=i.initial,a=i.threshold,s=i.rubberband,u=a[0],l=a[1],d=t._initial,h=t._active,f=t._intentional,g=t.lastOffset,p=t.movement,m=f[0],S=f[1],y=this.getInternalMovement(e,t),b=y[0],G=y[1];!1===m&&(m=c(b,u)),!1===S&&(S=c(G,l));var T=this.checkIntentionality([m,S],[b,G],t),M=T._intentional,_=T._blocked,E=M[0],P=M[1],O=[b,G];if(!1!==E&&!1===f[0]&&(d[0]=w(o)[0]),!1!==P&&!1===f[1]&&(d[1]=w(o)[1]),_)return v({},T,{_movement:O,delta:[0,0]});var D=[!1!==E?b-E:w(o)[0],!1!==P?G-P:w(o)[1]],B=n(D,g),K=h?s:[0,0];return v({},T,{_initial:d,_movement:O,movement:D=this.rubberband(n(D,d),K),offset:this.rubberband(B,K),delta:r(D,p)})},i.clean=function(){this.clearTimeout(),this.removeWindowListeners()},(t=[{key:"config",get:function(){return this.controller.config[this.stateKey]}},{key:"enabled",get:function(){return this.controller.config.enabled&&this.config.enabled}},{key:"state",get:function(){return this.controller.state[this.stateKey]}},{key:"handler",get:function(){return this.controller.handlers[this.stateKey]}}])&&function(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}(e.prototype,t),e}(),C=function(e){function t(){return e.apply(this,arguments)||this}h(t,e);var n=t.prototype;return n.getInternalMovement=function(e,t){return r(e,t.initial)},n.checkIntentionality=function(e,t,n){var r=n.axis,i=!1;if(!1!==e[0]||!1!==e[1]){var o=t.map(Math.abs),a=o[0],s=o[1],u=this.config,c=u.axis;r=r||(a>s?"x":a<s?"y":void 0),(c||u.lockDirection)&&(r?c&&r!==c?i=!0:e["x"===r?1:0]=!1:e=[!1,!1])}return{_intentional:e,_blocked:i,axis:r}},n.getKinematics=function(e,t){var n=this.state.timeStamp,r=this.getMovement(e,this.state),i=r.delta;return r._blocked?r:v({values:e,delta:i},r,{},u(r.movement,i,t.timeStamp-n))},n.mapStateValues=function(e){return{xy:e.values,vxvy:e.velocities}},t}(x),H=function(e){function t(t,n){var r;return(r=e.call(this,"drag",t,n)||this).ingKey="dragging",r.dragShouldStart=function(e){var t=E(e);return r.enabled&&t.touches<2},r.setPointers=function(e){var t=e.currentTarget,n=e.pointerId;t&&t.setPointerCapture(n),r.updateGestureState({currentTarget:t,pointerId:n})},r.removePointers=function(){var e=r.state,t=e.currentTarget;t&&t.releasePointerCapture(e.pointerId)},r.setListeners=function(){r.removeWindowListeners(),r.addWindowListeners([["touchmove",r.onDragChange],["touchend",r.onDragEnd],["touchcancel",r.onDragEnd],["mousemove",r.onDragChange],["mouseup",r.onDragEnd]])},r.onDragStart=function(e){r.dragShouldStart(e)&&(r.controller.config.pointer?r.setPointers(e):r.setListeners(),r.config.delay>0?(r.state._delayedEvent=!0,"function"==typeof e.persist&&e.persist(),r.setTimeout((function(){return r.startDrag(e)}),r.config.delay)):r.startDrag(e))},r.onDragChange=function(e){if(!r.state.canceled)if(r.state._active){var t=E(e);if(t.down){r.updateSharedState(t);var n=D(e),i=r.getKinematics(n.values,e),o=r.state._isTap;o&&a(i._movement)>=3&&(o=!1),r.updateGestureState(v({},r.getGenericPayload(e),{},i,{_isTap:o,cancel:function(){return r.onCancel()}})),r.fireGestureHandler()}else r.onDragEnd(e)}else r.state._delayedEvent&&(r.clearTimeout(),r.startDrag(e))},r.onDragEnd=function(e){r.state._active=!1,r.updateSharedState({down:!1,buttons:0,touches:0});var t=r.state,n=t._isTap,i=t.values,o=t.velocities,a=o[0],s=o[1],u=t.movement,c=u[0],l=u[1],d=t._intentional,h=d[0],f=d[1],g=v({},r.getGenericPayload(e),{},r.getMovement(i)),p=r.config,m=p.swipeVelocity,S=m[0],y=m[1],w=p.swipeDistance,b=w[0],G=w[1],T=[0,0];g.elapsedTime<220&&(!1!==h&&Math.abs(a)>S&&Math.abs(c)>b&&(T[0]=Math.sign(a)),!1!==f&&Math.abs(s)>y&&Math.abs(l)>G&&(T[1]=Math.sign(s))),r.updateGestureState(v({event:e},g,{tap:n,swipe:T})),r.fireGestureHandler(r.config.filterTaps&&r.state._isTap)},r.clean=function(){e.prototype.clean.call(function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(r)),r.state._delayedEvent=!1,r.controller.config.pointer&&r.removePointers()},r.onCancel=function(){r.updateGestureState({canceled:!0,cancel:g}),r.state._active=!1,r.updateSharedState({down:!1,buttons:0,touches:0}),requestAnimationFrame((function(){return r.fireGestureHandler()}))},r}h(t,e);var n=t.prototype;return n.startDrag=function(e){var t=this,n=D(e).values;this.updateSharedState(E(e));var r=v({},this.getStartGestureState(n,e),{},this.getGenericPayload(e,!0));this.updateGestureState(v({},r,{},this.getMovement(n,r),{cancel:function(){return t.onCancel()}})),this.fireGestureHandler()},n.addBindings=function(){this.controller.config.pointer?(this.controller.addBindings("onPointerDown",this.onDragStart),this.controller.addBindings("onPointerMove",this.onDragChange),this.controller.addBindings(["onPointerUp","onPointerCancel"],this.onDragEnd)):this.controller.addBindings(["onTouchStart","onMouseDown"],this.onDragStart)},t}(C);function k(){return"undefined"!=typeof window?window:void 0}function I(e){void 0===e&&(e={});var t={domTarget:void 0,eventOptions:{passive:!0,capture:!1,pointer:!1},window:k(),enabled:!0},n=t.eventOptions,r=t.window,i=f(t,["eventOptions","window"]),o=e.eventOptions,a=e.window,s=f(e,["eventOptions","window"]),u=v({},n,{},o),c=u.capture;return v({},i,{},s,{window:a||r,eventOptions:{passive:!e.domTarget||!!u.passive,capture:!!c},captureString:c?"Capture":"",pointer:!!u.pointer})}function V(e){var t=v({},{enabled:!0,initial:[0,0],threshold:void 0,rubberband:0},{},e),n=t.threshold,r=t.rubberband;return"boolean"==typeof r&&(r=r?.15:0),void 0===n&&(n=0),{enabled:t.enabled,initial:t.initial,threshold:m(n),rubberband:m(r)}}function j(e){void 0===e&&(e={});var t=e.axis,n=e.lockDirection,r=e.bounds,i=void 0===r?{}:r,o=f(e,["axis","lockDirection","bounds"]),a=[[S(i.left,-Infinity),S(i.right,Infinity)],[S(i.top,-Infinity),S(i.bottom,Infinity)]];return v({},V(o),{},{lockDirection:!1,axis:void 0,bounds:void 0},{},y({axis:t,lockDirection:n},e),{bounds:a})}function A(e){void 0===e&&(e={});var t=e.distanceBounds,n=void 0===t?{}:t,r=e.angleBounds,i=void 0===r?{}:r,o=f(e,["distanceBounds","angleBounds"]),a=[[S(n.min,-Infinity),S(n.max,Infinity)],[S(i.min,-Infinity),S(i.max,Infinity)]];return v({},V(o),{bounds:a})}function R(e){void 0===e&&(e={});var t=e.enabled,n=e.threshold,r=e.bounds,i=e.rubberband,o=e.initial,a=v({},{filterTaps:!1,swipeVelocity:.5,swipeDistance:60,delay:!1},{},f(e,["enabled","threshold","bounds","rubberband","initial"])),s=a.swipeVelocity,u=a.swipeDistance,c=a.delay,l=a.filterTaps,d=a.axis,h=a.lockDirection;void 0===n?n=Math.max(0,l?3:0,h||d?1:0):l=!0;var g=j(y({enabled:t,threshold:n,bounds:r,rubberband:i,axis:d,lockDirection:h,initial:o},e));return v({},g,{filterTaps:l||g.threshold[0]+g.threshold[1]>0,swipeVelocity:m(s),swipeDistance:m(u),delay:"number"==typeof c?c:c?180:0})}var F=function(e){function t(t,n){var r;return(r=e.call(this,"pinch",t,n)||this).ingKey="pinching",r.pinchShouldStart=function(e){var t=E(e);return r.enabled&&2===t.touches},r.onPinchStart=function(e){if(r.pinchShouldStart(e)){var t=K(e),n=t.values,i=t.origin;r.updateSharedState(E(e));var o=v({},r.getStartGestureState(n,e),{},r.getGenericPayload(e,!0));r.updateGestureState(v({},o,{},r.getMovement(n,o),{origin:i,cancel:function(){return r.onCancel()}})),r.fireGestureHandler()}},r.onPinchChange=function(e){var t=r.state,n=t.timeStamp;if(!t.canceled&&t._active){var i=E(e);if(2===i.touches&&e.timeStamp!==n){r.updateSharedState(i);var o=K(e),a=o.origin,s=r.getKinematics(o.values,e);r.updateGestureState(v({},r.getGenericPayload(e),{},s,{origin:a,cancel:function(){return r.onCancel()}})),r.fireGestureHandler()}}},r.onPinchEnd=function(e){r.state.active&&(r.state._active=!1,r.updateSharedState({down:!1,touches:0}),r.updateGestureState(v({event:e},r.getGenericPayload(e),{},r.getMovement(r.state.values))),r.fireGestureHandler())},r.onCancel=function(){r.state._active=!1,r.updateGestureState({canceled:!0,cancel:g}),r.updateSharedState({down:!1,touches:0}),requestAnimationFrame((function(){return r.fireGestureHandler()}))},r.onGestureStart=function(e){if(r.enabled){e.preventDefault();var t=B(e).values;r.updateSharedState(E(e));var n=v({},r.getStartGestureState(t,e),{},r.getGenericPayload(e,!0));r.updateGestureState(v({},n,{},r.getMovement(t,n),{cancel:function(){return r.onCancel()}})),r.fireGestureHandler()}},r.onGestureChange=function(e){var t=r.state;if(!t.canceled&&t._active){e.preventDefault();var n=E(e);r.updateSharedState(n);var i=B(e),o=r.getKinematics(i.values,e);r.updateGestureState(v({},r.getGenericPayload(e),{},o,{cancel:function(){return r.onCancel()}})),r.fireGestureHandler()}},r.onGestureEnd=function(e){e.preventDefault(),r.state.active&&(r.state._active=!1,r.updateSharedState({down:!1,touches:0}),r.updateGestureState(v({event:e},r.getGenericPayload(e),{},r.getMovement(r.state.values))),r.fireGestureHandler())},r.updateTouchData=function(e){if(r.enabled&&2===e.touches.length){var t=K(e);r.state.origin=t.origin}},r.wheelShouldRun=function(e){return r.enabled&&e.ctrlKey},r.getWheelValuesFromEvent=function(e){var t=O(e).values[1],n=r.state.values,i=n[1];return{values:[n[0]-t,void 0!==i?i:0],origin:[e.clientX,e.clientY],delta:[0,t]}},r.onWheel=function(e){r.wheelShouldRun(e)&&(r.clearTimeout(),r.setTimeout(r.onWheelEnd),r.state._active?r.onWheelChange(e):r.onWheelStart(e))},r.onWheelStart=function(e){var t=r.getWheelValuesFromEvent(e),n=t.values,i=t.delta,o=t.origin;r.controller.config.eventOptions.passive||e.preventDefault(),r.updateSharedState(E(e));var a=v({},r.getStartGestureState(n,e),{},r.getGenericPayload(e,!0),{initial:r.state.values});r.updateGestureState(v({},a,{},r.getMovement(n,a),{offset:n,delta:i,origin:o})),r.fireGestureHandler()},r.onWheelChange=function(e){var t=E(e);r.updateSharedState(t);var n=r.getWheelValuesFromEvent(e),i=n.origin,o=n.delta,a=r.getKinematics(n.values,e);r.updateGestureState(v({},r.getGenericPayload(e),{},a,{origin:i,delta:o})),r.fireGestureHandler()},r.onWheelEnd=function(){r.state._active=!1,r.updateGestureState(r.getMovement(r.state.values)),r.fireGestureHandler()},r}return h(t,e),t.prototype.addBindings=function(){!function(){try{return"constructor"in GestureEvent}catch(e){return!1}}()?(this.controller.addBindings("onTouchStart",this.onPinchStart),this.controller.addBindings("onTouchMove",this.onPinchChange),this.controller.addBindings(["onTouchEnd","onTouchCancel"],this.onPinchEnd),this.controller.addBindings("onWheel",this.onWheel)):(this.controller.addBindings("onGestureStart",this.onGestureStart),this.controller.addBindings("onGestureChange",this.onGestureChange),this.controller.addBindings(["onGestureEnd","onTouchCancel"],this.onGestureEnd),this.controller.addBindings(["onTouchStart","onTouchMove"],this.updateTouchData))},t}(function(e){function t(){return e.apply(this,arguments)||this}h(t,e);var n=t.prototype;return n.getInternalMovement=function(e,t){var n=e[0],r=e[1],i=t.values,o=t.turns,a=t.initial,s=(r=void 0!==r?r:i[1])-i[1],u=Math.abs(s)>270?o+Math.sign(s):o;return[n-a[0],r-360*u-a[1]]},n.getKinematics=function(e,t){var n=this.state,r=n.timeStamp,i=n.initial,o=this.getMovement(e,this.state),a=o.delta,s=o.movement;return v({values:e,delta:a,turns:(e[1]-s[1]-i[1])/360},o,{},u(s,a,t.timeStamp-r))},n.mapStateValues=function(e){return{da:e.values,vdva:e.velocities}},t}(x)),X=function(e){function t(t,r){var i;return(i=e.call(this,"wheel",t,r)||this).ingKey="wheeling",i.debounced=!0,i.wheelShouldRun=function(e){return(!e.ctrlKey||!("pinch"in i.controller.handlers))&&i.enabled},i.getValuesFromEvent=function(e){var t=i.state.values;return{values:n(O(e).values,t)}},i.onWheel=function(e){i.wheelShouldRun(e)&&(i.clearTimeout(),i.setTimeout(i.onWheelEnd),i.state._active?i.onWheelChange(e):i.onWheelStart(e))},i.onWheelStart=function(e){var t=i.getValuesFromEvent(e).values;i.updateSharedState(E(e));var n=v({},i.getStartGestureState(t,e),{},i.getGenericPayload(e,!0),{initial:i.state.values}),r=i.getMovement(t,n),o=r.delta;i.updateGestureState(v({},n,{},r,{distance:a(o),direction:s(o)})),i.fireGestureHandler()},i.onWheelChange=function(e){var t=E(e);i.updateSharedState(t);var n=i.getValuesFromEvent(e),r=i.getKinematics(n.values,e);i.updateGestureState(v({},i.getGenericPayload(e),{},r)),i.fireGestureHandler()},i.onWheelEnd=function(){i.state._active=!1,i.updateGestureState(v({},i.getMovement(i.state.values),{velocities:[0,0],velocity:0})),i.fireGestureHandler()},i}return h(t,e),t.prototype.addBindings=function(){this.controller.addBindings("onWheel",this.onWheel)},t}(C),Y=function(e){function t(t,n){var r;return(r=e.call(this,"move",t,n)||this).ingKey="moving",r.debounced=!0,r.moveShouldRun=function(){return r.enabled},r.onMove=function(e){r.moveShouldRun()&&(r.clearTimeout(),r.setTimeout(r.onMoveEnd),r.state._active?r.onMoveChange(e):r.onMoveStart(e))},r.onMoveStart=function(e){var t=D(e).values;r.updateSharedState(E(e));var n=v({},r.getStartGestureState(t,e),{},r.getGenericPayload(e,!0));r.updateGestureState(v({},n,{},r.getMovement(t,n))),r.fireGestureHandler()},r.onMoveChange=function(e){var t=E(e);r.updateSharedState(t);var n=D(e),i=r.getKinematics(n.values,e);r.updateGestureState(v({},r.getGenericPayload(e),{},i)),r.fireGestureHandler()},r.onMoveEnd=function(){r.state._active=!1,r.updateGestureState(v({},r.getMovement(r.state.values),{velocities:[0,0],velocity:0})),r.fireGestureHandler()},r.onPointerEnter=function(e){if(r.controller.state.shared.hovering=!0,r.controller.config.enabled){if(r.controller.config.hover.enabled){var t=D(e).values,n=v({},r.controller.state.shared,{},r.state,{},r.getGenericPayload(e,!0),{values:t,active:!0,hovering:!0});r.controller.handlers.hover(v({},n,{},r.mapStateValues(n)))}"move"in r.controller.handlers&&r.onMoveStart(e)}},r.onPointerLeave=function(e){if(r.controller.state.shared.hovering=!1,r.controller.config.hover.enabled){var t=D(e).values,n=v({},r.controller.state.shared,{},r.state,{},r.getGenericPayload(e),{values:t,active:!1});r.controller.handlers.hover(v({},n,{},r.mapStateValues(n)))}"move"in r.controller.handlers&&r.onMoveEnd()},r}return h(t,e),t.prototype.addBindings=function(){this.controller.config.pointer?("move"in this.controller.handlers&&this.controller.addBindings("onPointerMove",this.onMove),"hover"in this.controller.handlers&&(this.controller.addBindings("onPointerEnter",this.onPointerEnter),this.controller.addBindings("onPointerLeave",this.onPointerLeave))):("move"in this.controller.handlers&&this.controller.addBindings("onMouseMove",this.onMove),"hover"in this.controller.handlers&&(this.controller.addBindings("onMouseEnter",this.onPointerEnter),this.controller.addBindings("onMouseLeave",this.onPointerLeave)))},t}(C),q=function(e){function t(t,n){var r;return(r=e.call(this,"scroll",t,n)||this).ingKey="scrolling",r.debounced=!0,r.scrollShouldRun=function(){return r.enabled},r.onScroll=function(e){r.scrollShouldRun()&&(r.clearTimeout(),r.setTimeout(r.onScrollEnd),r.state._active?r.onScrollChange(e):r.onScrollStart(e))},r.onScrollStart=function(e){var t=P(e).values;r.updateSharedState(E(e));var n=v({},r.getStartGestureState(t,e),{},r.getGenericPayload(e,!0),{initial:r.state.values}),i=r.getMovement(t,n),o=i.delta;r.updateGestureState(v({},n,{},i,{distance:a(o),direction:s(o)})),r.fireGestureHandler()},r.onScrollChange=function(e){var t=E(e);r.updateSharedState(t);var n=P(e),i=r.getKinematics(n.values,e);r.updateGestureState(v({},r.getGenericPayload(e),{},i)),r.fireGestureHandler()},r.onScrollEnd=function(){r.state._active=!1,r.updateGestureState(v({},r.getMovement(r.state.values),{velocities:[0,0],velocity:0})),r.fireGestureHandler()},r}return h(t,e),t.prototype.addBindings=function(){this.controller.addBindings("onScroll",this.onScroll)},t}(C);function U(e,t,n){var r=t+"Start",i=t+"End";return delete n[t],delete n[r],delete n[i],function(n){var o=void 0;return n.first&&r in e&&e[r](n),t in e&&(o=e[t](n)),n.last&&i in e&&e[i](n),o}}exports.addV=n,exports.rubberbandIfOutOfBounds=d,exports.subV=r,exports.useDrag=function(e,t){void 0===t&&(t={});var n=t.domTarget,r=t.eventOptions,i=t.window,o=f(t,["domTarget","eventOptions","window"]),a=v({},I({domTarget:n,eventOptions:r,window:i}),{drag:R(o)});return L({drag:e},[H],a)},exports.useGesture=function(e,n){void 0===n&&(n={});var r=t.useState((function(){return new Set(Object.keys(e).map((function(e){return e.replace(/End|Start/,"")})))}))[0],i=n.drag,o=n.wheel,a=n.move,s=n.scroll,u=n.pinch,c=n.hover,l=I(f(n,["drag","wheel","move","scroll","pinch","hover"])),d=[],h={},g=v({},e);return r.has("onDrag")&&(d.push(H),h.drag=U(e,"onDrag",g),l.drag=R(i)),r.has("onWheel")&&(d.push(X),h.wheel=U(e,"onWheel",g),l.wheel=j(o)),r.has("onScroll")&&(d.push(q),h.scroll=U(e,"onScroll",g),l.scroll=j(s)),r.has("onMove")&&(d.push(Y),h.move=U(e,"onMove",g),l.move=j(a)),r.has("onPinch")&&(d.push(F),h.pinch=U(e,"onPinch",g),l.pinch=A(u)),r.has("onHover")&&(r.has("onMove")||d.push(Y),h.hover=e.onHover,l.hover=v({enabled:!0},c),delete g.onHover),L(h,d,l,g)},exports.useHover=function(e,t){void 0===t&&(t={});var n=t.domTarget,r=t.eventOptions,i=t.window,o=f(t,["domTarget","eventOptions","window"]),a=v({},I({domTarget:n,eventOptions:r,window:i}),{hover:v({enabled:!0},o)});return L({hover:e},[Y],a)},exports.useMove=function(e,t){void 0===t&&(t={});var n=t.domTarget,r=t.eventOptions,i=t.window,o=f(t,["domTarget","eventOptions","window"]),a=v({},I({domTarget:n,eventOptions:r,window:i}),{move:j(o)});return L({move:e},[Y],a)},exports.usePinch=function(e,t){void 0===t&&(t={});var n=t.domTarget,r=t.eventOptions,i=t.window,o=f(t,["domTarget","eventOptions","window"]),a=v({},I({domTarget:n,eventOptions:r,window:i}),{pinch:A(o)});return L({pinch:e},[F],a)},exports.useScroll=function(e,t){void 0===t&&(t={});var n=t.domTarget,r=t.eventOptions,i=t.window,o=f(t,["domTarget","eventOptions","window"]),a=v({},I({domTarget:n,eventOptions:r,window:i}),{scroll:j(o)});return L({scroll:e},[q],a)},exports.useWheel=function(e,t){void 0===t&&(t={});var n=t.domTarget,r=t.eventOptions,i=t.window,o=f(t,["domTarget","eventOptions","window"]),a=v({},I({domTarget:n,eventOptions:r,window:i}),{wheel:j(o)});return L({wheel:e},[X],a)}; | ||
//# sourceMappingURL=react-use-gesture.cjs.production.min.js.map |
{ | ||
"name": "react-use-gesture", | ||
"version": "7.0.5", | ||
"version": "7.0.6", | ||
"description": "React hook for receiving gestures https://use-gesture.netlify.com", | ||
@@ -18,6 +18,7 @@ "main": "dist/index.js", | ||
"build-docs": "cd ./docusaurus && yarn build", | ||
"test": "tsdx test --env=jsdom", | ||
"test:watch": "tsdx test --env=jsdom --watchAll" | ||
"test": "tsdx test", | ||
"test:watch": "tsdx test --watchAll" | ||
}, | ||
"jest": { | ||
"testEnvironment": "jsdom", | ||
"setupFiles": [ | ||
@@ -72,7 +73,7 @@ "@testing-library/react/dont-cleanup-after-each" | ||
"husky": "^4.2.3", | ||
"prettier": "^1.19.1", | ||
"prettier": "^2.0.2", | ||
"pretty-quick": "^2.0.1", | ||
"react": "^16.13.0", | ||
"react-dom": "^16.13.0", | ||
"tsdx": "^0.12.3", | ||
"tsdx": "^0.13.1", | ||
"tslib": "^1.11.1", | ||
@@ -79,0 +80,0 @@ "typescript": "^3.8.3" |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
593788
35
4951