react-use-gesture
Advanced tools
Comparing version 8.0.0-beta.1 to 8.0.0-beta.2
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("react"),n=(e=t)&&"object"==typeof e&&"default"in e?e.default:e;function r(e,t){return e.map((function(e,n){return e+t[n]}))}function i(e,t){return e.map((function(e,n){return e-t[n]}))}function o(e){return Math.hypot.apply(Math,e)}function a(e,t){void 0===t&&(t=e);var n=o(t),r=0===n?0:1/n,i=t.map((function(e){return r*e}));return{distance:o(e),direction:i}}function s(e,t,n){var r=o(t),i=0===r?0:1/r,a=0===n?0:1/n,s=a*r,u=t.map((function(e){return a*e})),c=t.map((function(e){return i*e}));return{velocities:u,velocity:s,distance:o(e),direction:c}}function u(e){return Math.sign?Math.sign(e):Number(e>0)-Number(e<0)||+e}function c(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 l(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?-c(t-e,n-t,r)+t:e>n?+c(e-n,n-t,r)+n:e}function d(){return(d=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 v(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 h(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function p(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function g(e,t){var n;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return p(e,void 0);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?p(e,void 0):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0;return function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(n=e[Symbol.iterator]()).next.bind(n)}function m(){}function y(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return 0===t.length?m:1===t.length?t[0]:function(){for(var e,n,r=g(t);!(n=r()).done;){var i=n.value;e=i.apply(this,arguments)||e}return e}}function w(e,t){if(void 0===e){if(void 0===t)throw new Error("Must define fallback value if undefined is expected");e=t}return Array.isArray(e)?e:[e,e]}function b(e,t){return Object.assign({},t,e||{})}function S(e){if("function"==typeof e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];return e.apply(void 0,n)}return e}function _(e,t){void 0===e&&(e={});for(var n={},r=0,i=Object.entries(t);r<i.length;r++){var o=i[r],a=o[0],s=o[1];switch(typeof s){case"function":n[a]=s.call(n,e[a],a,e);break;case"object":n[a]=_(e[a],s);break;case"boolean":s&&(n[a]=e[a])}}return n}var G={threshold:function(e){return void 0===e&&(e=0),w(e)},rubberband:function(e){switch(void 0===e&&(e=0),e){case!0:return w(.15);case!1:return w(0);default:return w(e)}},enabled:function(e){return void 0===e&&(e=!0),e},triggerAllEvents:function(e){return void 0===e&&(e=!1),e},initial:function(e){return void 0===e&&(e=0),"function"==typeof e?e:w(e)}},T=d({},G,{axis:!0,lockDirection:function(e){return void 0===e&&(e=!1),e},bounds:function(e){if(void 0===e&&(e={}),"function"==typeof e)return function(t){return T.bounds(e(t))};var t=e.left,n=e.right,r=e.top,i=e.bottom;return[[void 0===t?-Infinity:t,void 0===n?Infinity:n],[void 0===r?-Infinity:r,void 0===i?Infinity:i]]}}),M={enabled:function(e){return void 0===e&&(e=!0),e},domTarget:!0,window:function(e){function t(t){return e.apply(this,arguments)}return t.toString=function(){return e.toString()},t}((function(e){return void 0===e&&(e="undefined"!=typeof window?window:void 0),e})),eventOptions:function(e){var t=void 0===e?{}:e,n=t.passive,r=t.capture;return{passive:void 0===n||n,capture:void 0!==r&&r}}},O=d({},G,{bounds:function(e,t,n){var r=n.distanceBounds,i=void 0===r?{}:r,o=n.angleBounds,a=void 0===o?{}:o,s=function(e){var t=b(S(i,e),{min:-Infinity,max:Infinity});return[t.min,t.max]},u=function(e){var t=b(S(a,e),{min:-Infinity,max:Infinity});return[t.min,t.max]};return"function"!=typeof i&&"function"!=typeof a?[s(),u()]:function(e){return[s(e),u(e)]}}}),E=d({},T,{threshold:function(e,t,n){var r=n.filterTaps,i=void 0!==r&&r,o=n.lockDirection,a=n.axis,s=w(e,i?3:void 0!==o&&o||(void 0===a?void 0:a)?1:0);return this.filterTaps=i||s[0]+s[1]>0,s},swipeVelocity:function(e){return void 0===e&&(e=.5),w(e)},swipeDistance:function(e){return void 0===e&&(e=60),w(e)},delay:function(e){switch(void 0===e&&(e=0),e){case!0:return 180;case!1:return 0;default:return e}}});function x(e){return void 0===e&&(e={}),_(e,M)}function K(e){return void 0===e&&(e={}),_(e,T)}function I(e){return void 0===e&&(e={}),_(e,O)}function k(e){return void 0===e&&(e={}),_(e,E)}function j(e){var t=e.domTarget,n=e.eventOptions,r=e.window,i=e.enabled,o=f(e,["domTarget","eventOptions","window","enabled"]),a=x({domTarget:t,eventOptions:n,window:r,enabled:i});return a.move=K(o),a}function D(e){var t=e.domTarget,n=e.eventOptions,r=e.window,i=e.enabled,o=f(e,["domTarget","eventOptions","window","enabled"]),a=x({domTarget:t,eventOptions:n,window:r,enabled:i});return a.hover=d({enabled:!0},o),a}function H(e){var t=e.domTarget,n=e.eventOptions,r=e.window,i=e.enabled,o=f(e,["domTarget","eventOptions","window","enabled"]),a=x({domTarget:t,eventOptions:n,window:r,enabled:i});return a.drag=k(o),a}function P(e){var t=e.domTarget,n=e.eventOptions,r=e.window,i=e.enabled,o=f(e,["domTarget","eventOptions","window","enabled"]),a=x({domTarget:t,eventOptions:n,window:r,enabled:i});return a.pinch=I(o),a}function C(e){var t=e.domTarget,n=e.eventOptions,r=e.window,i=e.enabled,o=f(e,["domTarget","eventOptions","window","enabled"]),a=x({domTarget:t,eventOptions:n,window:r,enabled:i});return a.scroll=K(o),a}function A(e){var t=e.domTarget,n=e.eventOptions,r=e.window,i=e.enabled,o=f(e,["domTarget","eventOptions","window","enabled"]),a=x({domTarget:t,eventOptions:n,window:r,enabled:i});return a.wheel=K(o),a}function W(e){return d({_active:!1,_blocked:!1,_intentional:[!1,!1],_movement:[0,0],_initial:[0,0],_bounds:[[-Infinity,Infinity],[-Infinity,Infinity]],_lastEventType:void 0,event:void 0,intentional:!1,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:m,canceled:!1,memo:void 0,args:void 0},e)}function L(){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:W({axis:void 0,xy:[0,0],vxvy:[0,0],velocity:0,distance:0,_isTap:!0,_delayedEvent:!1,_pointerId:void 0,tap:!1,swipe:[0,0]}),pinch:W({da:[0,0],vdva:[0,0],origin:void 0,turns:0}),wheel:W({axis:void 0,xy:[0,0],vxvy:[0,0],velocity:0,distance:0}),move:W({axis:void 0,xy:[0,0],vxvy:[0,0],velocity:0,distance:0}),scroll:W({axis:void 0,xy:[0,0],vxvy:[0,0],velocity:0,distance:0})}}var R=new Map,V=function(){function e(e,t){var n=this;void 0===t&&(t=[]),this.controller=e,this.args=t,this.debounced=!0,this.setTimeout=function(e,t){var r;void 0===t&&(t=140),clearTimeout(n.controller.timeouts[n.stateKey]);for(var i=arguments.length,o=new Array(i>2?i-2:0),a=2;a<i;a++)o[a-2]=arguments[a];n.controller.timeouts[n.stateKey]=(r=window).setTimeout.apply(r,[e,t].concat(o))},this.clearTimeout=function(){clearTimeout(n.controller.timeouts[n.stateKey])},this.fireGestureHandler=function(e){if(void 0===e&&(e=!1),n.state._blocked)return n.debounced||(n.state._active=!1,n.clean()),null;if(!e&&!n.state.intentional&&!n.config.triggerAllEvents)return null;if(n.state.intentional){var t=n.state.active,r=n.state._active;n.state.active=r,n.state.first=r&&!t,n.state.last=t&&!r,n.controller.state.shared[n.ingKey]=r}var i=d({},n.controller.state.shared,n.state,n.mapStateValues(n.state)),o=n.handler(i);return n.state.memo=void 0!==o?o:n.state.memo,n.state._active||n.clean(),i}}var t,n=e.prototype;return n.updateSharedState=function(e){Object.assign(this.controller.state.shared,e)},n.updateGestureState=function(e){Object.assign(this.state,e)},n.checkIntentionality=function(e,t){return{_intentional:e,_blocked:!1}},n.getMovement=function(e){var t=this.config,n=t.initial,o=t.bounds,a=t.rubberband,s=t.threshold,u=this.state,c=u._bounds,l=u._initial,v=u._active,f=u._intentional,h=u.lastOffset,p=u.movement,g=this.getInternalMovement(e,this.state),m=!1===f[0]?B(g[0],s[0]):f[0],y=!1===f[1]?B(g[1],s[1]):f[1],w=this.checkIntentionality([m,y],g);if(w._blocked)return d({},w,{_movement:g,delta:[0,0]});var b,_,G,T,M=w._intentional,O=g;!1!==M[0]&&!1===f[0]&&(_=S(n,this.state),b=S(o,this.state),l[0]=_[0],c[0]=b[0]),!1!==M[1]&&!1===f[1]&&(_=null!=(G=_)?G:S(n,this.state),b=null!=(T=b)?T:S(o,this.state),l[1]=_[1],c[1]=b[1]);var E=[!1!==M[0]?g[0]-M[0]:l[0],!1!==M[1]?g[1]-M[1]:l[1]],x=r(E,h),K=v?a:[0,0];return E=X(c,r(E,l),K),d({},w,{intentional:!1!==M[0]||!1!==M[1],_initial:l,_movement:O,movement:E,values:e,offset:X(c,x,K),delta:i(E,p)})},n.clean=function(){this.clearTimeout()},(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}();function B(e,t){return Math.abs(e)>=t&&u(e)*t}function X(e,t,n){var r=t[1],i=n[1],o=e[0],a=e[1],s=a[0],u=a[1];return[l(t[0],o[0],o[1],n[0]),l(r,s,u,i)]}function Y(e,t,n){var r=e.state,i=t.timeStamp;return{_lastEventType:t.type,event:t,timeStamp:i,elapsedTime:n?0:i-r.startTime,args:e.args,previous:r.values}}function F(e,t,n){var r=e.state.offset,i=n.timeStamp;return d({},L()[e.stateKey],{_active:!0,values:t,initial:t,offset:r,lastOffset:r,startTime:i})}function z(e,t){return function(n){for(var r=arguments.length,i=new Array(r>1?r-1:0),o=1;o<r;o++)i[o-1]=arguments[o];return e.call.apply(e,[this,d({},t,{event:n})].concat(i))}}var q=function(e){var t=this;this.classes=e,this.bind=function(){for(var e={},n=arguments.length,r=new Array(n),i=0;i<n;i++)r[i]=arguments[i];for(var o,a=g(t.classes);!(o=a()).done;){var s=o.value;new s(t,r).addBindings(e)}for(var u=0,c=Object.entries(t.nativeRefs);u<c.length;u++){var l=c[u],v=l[0],f=l[1];ee(e,v,z(f,d({},t.state.shared,{args:r})))}return t.config.domTarget?U(t,e):J(t,e)},this.effect=function(){return t.config.domTarget&&t.bind(),t.clean},this.clean=function(){var e=Z(t.config),n=t.config.eventOptions;e&&ne(e,Q(t.domListeners),n),Object.values(t.timeouts).forEach(clearTimeout),function(e){var t=e.config,n=t.window,r=t.eventOptions,i=e.windowListeners;if(n){for(var o in i)ne(n,i[o],r);e.windowListeners={}}}(t)},this.state=L(),this.timeouts={},this.domListeners=[],this.windowListeners={}};function $(e,t){var n=e.config,r=e.windowListeners;n.window&&(ne(n.window,r[t],n.eventOptions),delete r[t])}function N(e,t,n){var r=e.config,i=e.windowListeners;void 0===n&&(n=[]),r.window&&(ne(r.window,i[t],r.eventOptions),te(r.window,i[t]=n,r.eventOptions))}function U(e,t){var n=e.config,r=e.domListeners,i=Z(n);if(!i)throw new Error("domTarget must be defined");var o=n.eventOptions;ne(i,Q(r),o);for(var a=0,s=Object.entries(t);a<s.length;a++){var u=s[a],c=u[1],l=u[0].slice(2).toLowerCase();r.push([l,y.apply(void 0,c)])}te(i,r,o)}function J(e,t){for(var n={},r=e.config.eventOptions.capture?"Capture":"",i=0,o=Object.entries(t);i<o.length;i++){var a=o[i],s=a[0],u=a[1],c=Array.isArray(u)?u:[u];n[s+r]=y.apply(void 0,c)}return n}function Q(e){return void 0===e&&(e=[]),e.splice(0,e.length)}function Z(e){var t=e.domTarget;return t&&"current"in t?t.current:t}function ee(e,t,n){e[t]||(e[t]=[]),e[t].push(n)}function te(e,t,n){void 0===t&&(t=[]),void 0===n&&(n={});for(var r,i=g(t);!(r=i()).done;){var o=r.value;e.addEventListener(o[0],o[1],n)}}function ne(e,t,n){void 0===t&&(t=[]),void 0===n&&(n={});for(var r,i=g(t);!(r=i()).done;){var o=r.value;e.removeEventListener(o[0],o[1],n)}}function re(e,t,r){void 0===r&&(r={});var i=function(e){var t=new Set;return e.drag&&t.add(R.get("drag")),e.wheel&&t.add(R.get("wheel")),e.scroll&&t.add(R.get("scroll")),e.move&&t.add(R.get("move")),e.pinch&&t.add(R.get("pinch")),e.hover&&t.add(R.get("hover")),t}(e),o=n.useMemo((function(){return new q(i)}),[]);return o.config=t,o.handlers=e,o.nativeRefs=r,n.useEffect(o.effect,[]),o.config.domTarget?ie:o.bind}function ie(){}var oe=function(e){function t(){return e.apply(this,arguments)||this}v(t,e);var n=t.prototype;return n.getInternalMovement=function(e,t){return i(e,t.initial)},n.checkIntentionality=function(e,t){if(!1===e[0]&&!1===e[1])return{_intentional:e,axis:this.state.axis};var n=t.map(Math.abs),r=n[0],i=n[1],o=this.state.axis||(r>i?"x":r<i?"y":void 0);return this.config.axis||this.config.lockDirection?o?this.config.axis&&o!==this.config.axis?{_intentional:e,_blocked:!0,axis:o}:(e["x"===o?1:0]=!1,{_intentional:e,_blocked:!1,axis:o}):{_intentional:[!1,!1],_blocked:!1,axis:o}:{_intentional:e,_blocked:!1,axis:o}},n.getKinematics=function(e,t){var n=this.getMovement(e);return n._blocked||Object.assign(n,s(n.movement,n.delta,t.timeStamp-this.state.timeStamp)),n},n.mapStateValues=function(e){return{xy:e.values,vxvy:e.velocities}},t}(V);function ae(e){if("touches"in e){var t=e.targetTouches;return t.length>0?t:e.changedTouches}return null}function se(e){var t="buttons"in e?e.buttons:0,n=ae(e),r=n&&n.length||0;return{touches:r,down:r>0||t>0,buttons:t,shiftKey:e.shiftKey,altKey:e.altKey,metaKey:e.metaKey,ctrlKey:e.ctrlKey}}function ue(e){var t=ae(e),n=t?t[0]:e;return[n.clientX,n.clientY]}function ce(e){var t=e.currentTarget;return[t.scrollX||t.scrollLeft||0,t.scrollY||t.scrollTop||0]}function le(e){return[e.deltaX,e.deltaY]}function de(e){return[260*e.scale,e.rotation]}function ve(e){var t,n=e.targetTouches,r=n[0],i=n[1],o=i.clientX-r.clientX,a=i.clientY-r.clientY,s=(i.clientX+r.clientX)/2,u=(i.clientY+r.clientY)/2,c="nativeEvent"in e?e.nativeEvent:e;return{values:[Math.hypot(o,a),null!=(t=c.rotation)?t:-180*Math.atan2(o,a)/Math.PI],origin:[s,u]}}var fe=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).ingKey="dragging",t.stateKey="drag",t.onDragStart=function(e){t.enabled&&!t.state._active&&(N(t.controller,t.stateKey,[["pointermove",t.onDragChange],["pointerup",t.onDragEnd],["pointercancel",t.onDragEnd]]),t.updateGestureState({_pointerId:e.pointerId}),t.config.delay>0?(t.state._delayedEvent=!0,"persist"in e&&"function"==typeof e.persist&&e.persist(),t.setTimeout(t.startDrag.bind(h(t)),t.config.delay,e)):t.startDrag(e))},t.onDragChange=function(e){if(!t.state.canceled&&e.pointerId===t.state._pointerId)if(t.state._active){var n=se(e);if(n.down){t.updateSharedState(n);var r=ue(e),i=t.getKinematics(r,e),a=Y(h(t),e),s=t.state._isTap,u=o(i._movement);s&&u>=3&&(s=!1),t.updateGestureState(d({},a,i,{_isTap:s})),t.fireGestureHandler()}else t.onDragEnd(e)}else t.state._delayedEvent&&(t.clearTimeout(),t.startDrag(e))},t.onDragEnd=function(e){if(e.pointerId===t.state._pointerId){t.state._active=!1,t.updateSharedState({down:!1,buttons:0,touches:0});var n=t.state._isTap,r=t.state.velocities,i=r[0],o=r[1],a=t.state.movement,s=a[0],c=a[1],l=t.state._intentional,v=l[0],f=l[1],p=t.config.swipeVelocity,g=p[0],m=p[1],y=t.config.swipeDistance,w=y[0],b=y[1],S=d({},Y(h(t),e),t.getMovement(t.state.values)),_=[0,0];S.elapsedTime<220&&(!1!==v&&Math.abs(i)>g&&Math.abs(s)>w&&(_[0]=u(i)),!1!==f&&Math.abs(o)>m&&Math.abs(c)>b&&(_[1]=u(o))),t.updateGestureState(d({},S,{tap:n,swipe:_})),t.fireGestureHandler(!0===n)}},t.clean=function(){e.prototype.clean.call(h(t)),t.state._delayedEvent=!1,$(t.controller,t.stateKey)},t.onCancel=function(){t.state.canceled||(t.updateGestureState({canceled:!0}),t.state._active=!1,t.updateSharedState({down:!1,buttons:0,touches:0}),requestAnimationFrame((function(){return t.fireGestureHandler()})))},t.onClick=function(e){t.state._isTap||e.stopPropagation()},t}v(t,e);var n=t.prototype;return n.startDrag=function(e){var t=ue(e);this.updateSharedState(se(e)),this.updateGestureState(d({},F(this,t,e),Y(this,e,!0),{_pointerId:e.pointerId,cancel:this.onCancel})),this.updateGestureState(this.getMovement(t)),this.fireGestureHandler()},n.addBindings=function(e){ee(e,"onPointerDown",this.onDragStart),this.config.filterTaps&&ee(e,this.controller.config.eventOptions.capture?"onClick":"onClickCapture",this.onClick)},t}(oe);function he(e,t){var n,r,i=[],o=!1;return function(){for(var a=arguments.length,s=new Array(a),u=0;u<a;u++)s[u]=arguments[u];return o&&n===this&&t(s,i)||(r=e.apply(this,s),o=!0,n=this,i=s),r}}function pe(e,t){try{return function e(t,n){if(t===n)return!0;if(t&&n&&"object"==typeof t&&"object"==typeof n){if(t.constructor!==n.constructor)return!1;var r,i,o,a;if(Array.isArray(t)){if((r=t.length)!==n.length)return!1;for(i=r;0!=i--;)if(!e(t[i],n[i]))return!1;return!0}if("function"==typeof Map&&t instanceof Map&&n instanceof Map){if(t.size!==n.size)return!1;for(a=t.entries();!(i=a.next()).done;)if(!n.has(i.value[0]))return!1;for(a=t.entries();!(i=a.next()).done;)if(!e(i.value[1],n.get(i.value[0])))return!1;return!0}if("function"==typeof Set&&t instanceof Set&&n instanceof Set){if(t.size!==n.size)return!1;for(a=t.entries();!(i=a.next()).done;)if(!n.has(i.value[0]))return!1;return!0}if(t.constructor===RegExp)return t.source===n.source&&t.flags===n.flags;if(t.valueOf!==Object.prototype.valueOf)return t.valueOf()===n.valueOf();if(t.toString!==Object.prototype.toString)return t.toString()===n.toString();if((r=(o=Object.keys(t)).length)!==Object.keys(n).length)return!1;for(i=r;0!=i--;)if(!Object.prototype.hasOwnProperty.call(n,o[i]))return!1;if("undefined"!=typeof Element&&t instanceof Element)return!1;for(i=r;0!=i--;)if(!("_owner"===o[i]&&t.$$typeof||e(t[o[i]],n[o[i]])))return!1;return!0}return t!=t&&n!=n}(e,t)}catch(e){if((e.message||"").match(/stack|recursion/i))return console.warn("react-fast-compare cannot handle circular refs"),!1;throw e}}var ge=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).ingKey="pinching",t.stateKey="pinch",t.pinchShouldStart=function(e){var n=se(e);return t.enabled&&2===n.touches},t.onPinchStart=function(e){if(t.pinchShouldStart(e)){var n=ve(e),r=n.values,i=n.origin;t.updateSharedState(se(e)),t.updateGestureState(d({},F(h(t),r,e),Y(h(t),e,!0),{cancel:t.onCancel,origin:i})),t.updateGestureState(t.getMovement(r)),t.fireGestureHandler()}},t.onPinchChange=function(e){var n=t.state;if(!n.canceled&&n._active){var r=se(e);t.updateSharedState(r);var i=ve(e),o=i.origin,a=t.getKinematics(i.values,e);t.updateGestureState(d({},Y(h(t),e),a,{origin:o})),t.fireGestureHandler()}},t.onPinchEnd=function(e){t.state.active&&(t.state._active=!1,t.updateSharedState({down:!1,touches:0}),t.updateGestureState(d({},Y(h(t),e),t.getMovement(t.state.values))),t.fireGestureHandler())},t.onCancel=function(){t.state.canceled||(t.state._active=!1,t.updateGestureState({canceled:!0}),t.updateSharedState({down:!1,touches:0}),requestAnimationFrame((function(){return t.fireGestureHandler()})))},t.onGestureStart=function(e){if(t.enabled){e.preventDefault();var n=de(e);t.updateSharedState(se(e)),t.updateGestureState(d({},F(h(t),n,e),Y(h(t),e,!0),{cancel:t.onCancel})),t.updateGestureState(t.getMovement(n)),t.fireGestureHandler()}},t.onGestureChange=function(e){var n=t.state;if(!n.canceled&&n._active){e.preventDefault();var r=se(e);t.updateSharedState(r);var i=de(e),o=t.getKinematics(i,e);t.updateGestureState(d({},Y(h(t),e),o)),t.fireGestureHandler()}},t.onGestureEnd=function(e){e.preventDefault(),t.state.active&&(t.state._active=!1,t.updateSharedState({down:!1,touches:0}),t.updateGestureState(d({},Y(h(t),e),t.getMovement(t.state.values))),t.fireGestureHandler())},t.wheelShouldRun=function(e){return t.enabled&&e.ctrlKey},t.getWheelValuesFromEvent=function(e){var n=le(e)[1],r=t.state.values,i=r[1];return{values:[r[0]-n,void 0!==i?i:0],origin:[e.clientX,e.clientY],delta:[0,n]}},t.onWheel=function(e){t.wheelShouldRun(e)&&(t.setTimeout(t.onWheelEnd),t.state._active?t.onWheelChange(e):t.onWheelStart(e))},t.onWheelStart=function(e){var n=t.getWheelValuesFromEvent(e),r=n.values,i=n.delta,o=n.origin;t.controller.config.eventOptions.passive||e.preventDefault(),t.updateSharedState(se(e)),t.updateGestureState(d({},F(h(t),r,e),Y(h(t),e,!0),{initial:t.state.values,offset:r,delta:i,origin:o})),t.updateGestureState(t.getMovement(r)),t.fireGestureHandler()},t.onWheelChange=function(e){t.updateSharedState(se(e));var n=t.getWheelValuesFromEvent(e),r=n.values,i=n.origin,o=n.delta;t.updateGestureState(d({},Y(h(t),e),t.getKinematics(r,e),{origin:i,delta:o})),t.fireGestureHandler()},t.onWheelEnd=function(){t.state._active=!1,t.updateGestureState(t.getMovement(t.state.values)),t.fireGestureHandler()},t}return v(t,e),t.prototype.addBindings=function(e){this.controller.config.domTarget&&("undefined"==typeof window||null!==window.ontouchstart)&&function(){try{return"constructor"in GestureEvent}catch(e){return!1}}()?(ee(e,"onGestureStart",this.onGestureStart),ee(e,"onGestureChange",this.onGestureChange),ee(e,"onGestureEnd",this.onGestureEnd)):(ee(e,"onTouchStart",this.onPinchStart),ee(e,"onTouchMove",this.onPinchChange),ee(e,"onTouchEnd",this.onPinchEnd),ee(e,"onTouchCancel",this.onPinchEnd),ee(e,"onWheel",this.onWheel))},t}(function(e){function t(){return e.apply(this,arguments)||this}v(t,e);var n=t.prototype;return n.getInternalMovement=function(e,t){var n=t.values[1],r=e[0],o=e[1],a=void 0===o?n:o,s=a-n,c=t.turns;return Math.abs(s)>270&&(c+=u(s)),i([r,a-360*c],t.initial)},n.getKinematics=function(e,t){var n=this.getMovement(e);return d({turns:(e[1]-n.movement[1]-this.state.initial[1])/360},n,s(n.movement,n.delta,t.timeStamp-this.state.timeStamp))},n.mapStateValues=function(e){return{da:e.values,vdva:e.velocities}},t}(V)),me=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).ingKey="wheeling",t.stateKey="wheel",t.debounced=!0,t.handleEvent=function(e){if((!e.ctrlKey||!("pinch"in t.controller.handlers))&&t.enabled){t.setTimeout(t.onEnd),t.updateSharedState(se(e));var n=r(le(e),t.state.values);if(t.state._active)t.updateGestureState(d({},Y(h(t),e),t.getKinematics(n,e)));else{t.updateGestureState(d({},F(h(t),n,e),Y(h(t),e,!0),{initial:t.state.values}));var i=t.getMovement(n),o=a(i.delta);t.updateGestureState(i),t.updateGestureState(o)}t.fireGestureHandler()}},t.onEnd=function(){var e=t.getMovement(t.state.values);t.updateGestureState(e),t.updateGestureState({_active:!1,velocities:[0,0],velocity:0}),t.fireGestureHandler()},t}return v(t,e),t.prototype.addBindings=function(e){ee(e,"onWheel",this.handleEvent)},t}(oe),ye=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).ingKey="moving",t.stateKey="move",t.debounced=!0,t.onMove=function(e){t.enabled&&(t.setTimeout(t.onMoveEnd),t.state._active?t.onMoveChange(e):t.onMoveStart(e))},t.onMoveStart=function(e){t.updateSharedState(se(e));var n=ue(e);t.updateGestureState(d({},F(h(t),n,e),Y(h(t),e,!0))),t.updateGestureState(t.getMovement(n)),t.fireGestureHandler()},t.onMoveChange=function(e){t.updateSharedState(se(e));var n=ue(e);t.updateGestureState(d({},Y(h(t),e),t.getKinematics(n,e))),t.fireGestureHandler()},t.onMoveEnd=function(){t.updateGestureState(t.getMovement(t.state.values)),t.updateGestureState({velocities:[0,0],velocity:0,_active:!1}),t.fireGestureHandler()},t.onPointerEnter=function(e){if(t.controller.state.shared.hovering=!0,t.controller.config.enabled){if(t.controller.config.hover.enabled){var n=ue(e),r=d({},t.controller.state.shared,t.state,Y(h(t),e,!0),{values:n,active:!0,hovering:!0});t.controller.handlers.hover(d({},r,t.mapStateValues(r)))}"move"in t.controller.handlers&&t.onMoveStart(e)}},t.onPointerLeave=function(e){if(t.controller.state.shared.hovering=!1,"move"in t.controller.handlers&&t.onMoveEnd(),t.controller.config.hover.enabled){var n=ue(e),r=d({},t.controller.state.shared,t.state,Y(h(t),e),{values:n,active:!1});t.controller.handlers.hover(d({},r,t.mapStateValues(r)))}},t}return v(t,e),t.prototype.addBindings=function(e){"move"in this.controller.handlers&&ee(e,"onPointerMove",this.onMove),"hover"in this.controller.handlers&&(ee(e,"onPointerEnter",this.onPointerEnter),ee(e,"onPointerLeave",this.onPointerLeave))},t}(oe),we=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).ingKey="scrolling",t.stateKey="scroll",t.debounced=!0,t.handleEvent=function(e){if(t.enabled){t.clearTimeout(),t.setTimeout(t.onEnd);var n=ce(e);if(t.updateSharedState(se(e)),t.state._active)t.updateGestureState(d({},Y(h(t),e),t.getKinematics(n,e)));else{t.updateGestureState(d({},F(h(t),n,e),Y(h(t),e,!0),{initial:t.state.values}));var r=t.getMovement(n),i=a(r.delta);t.updateGestureState(r),t.updateGestureState(i)}t.fireGestureHandler()}},t.onEnd=function(){t.state._active=!1,t.updateGestureState(d({},t.getMovement(t.state.values),{velocities:[0,0],velocity:0})),t.fireGestureHandler()},t}return v(t,e),t.prototype.addBindings=function(e){ee(e,"onScroll",this.handleEvent)},t}(oe),be=/^on(Drag|Wheel|Scroll|Move|Pinch|Hover)/;function Se(e,t){var n=t+"Start",r=t+"End";return function(i){var o=void 0;return i.first&&n in e&&e[n](i),t in e&&(o=e[t](i)),i.last&&r in e&&e[r](i),o}}exports.addV=r,exports.rubberbandIfOutOfBounds=l,exports.subV=i,exports.useDrag=function(e,n){void 0===n&&(n={}),R.set("drag",fe);var r=t.useRef();return r.current||(r.current=he(H,pe)),re({drag:e},r.current(n))},exports.useGesture=function(e,t){void 0===t&&(t={});var n=function(e){var t={},n={},r=new Set;for(var i in e)be.test(i)?(r.add(RegExp.lastMatch),n[i]=e[i]):t[i]=e[i];return[n,t,r]}(e),r=n[0],i=n[1],o=n[2];R.set("drag",fe),R.set("hover",ye),R.set("move",ye),R.set("pinch",ge),R.set("scroll",we),R.set("wheel",me);var a=function(e,t){void 0===e&&(e={}),void 0===t&&(t=new Set);var n=e.drag,r=e.wheel,i=e.move,o=e.scroll,a=e.pinch,s=e.hover,u=x({eventOptions:e.eventOptions,window:e.window,domTarget:e.domTarget,enabled:e.enabled});return t.has("onDrag")&&(u.drag=k(n)),t.has("onWheel")&&(u.wheel=K(r)),t.has("onScroll")&&(u.scroll=K(o)),t.has("onMove")&&(u.move=K(i)),t.has("onPinch")&&(u.pinch=I(a)),t.has("onHover")&&(u.hover=d({enabled:!0},s)),u}(t,o),s={};return o.has("onDrag")&&(s.drag=Se(r,"onDrag")),o.has("onWheel")&&(s.wheel=Se(r,"onWheel")),o.has("onScroll")&&(s.scroll=Se(r,"onScroll")),o.has("onMove")&&(s.move=Se(r,"onMove")),o.has("onPinch")&&(s.pinch=Se(r,"onPinch")),o.has("onHover")&&(s.hover=r.onHover),re(s,a,i)},exports.useHover=function(e,n){void 0===n&&(n={}),R.set("hover",ye);var r=t.useRef();return r.current||(r.current=he(D,pe)),re({hover:e},r.current(n))},exports.useMove=function(e,n){void 0===n&&(n={}),R.set("move",ye);var r=t.useRef();return r.current||(r.current=he(j,pe)),re({move:e},r.current(n))},exports.usePinch=function(e,n){void 0===n&&(n={}),R.set("pinch",ge);var r=t.useRef();return r.current||(r.current=he(P,pe)),re({pinch:e},r.current(n))},exports.useScroll=function(e,n){void 0===n&&(n={}),R.set("scroll",we);var r=t.useRef();return r.current||(r.current=he(C,pe)),re({scroll:e},r.current(n))},exports.useWheel=function(e,n){void 0===n&&(n={}),R.set("wheel",me);var r=t.useRef();return r.current||(r.current=he(A,pe)),re({wheel:e},r.current(n))}; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("react"),n=(e=t)&&"object"==typeof e&&"default"in e?e.default:e;function r(e,t){return e.map((function(e,n){return e+t[n]}))}function i(e,t){return e.map((function(e,n){return e-t[n]}))}function o(e){return Math.hypot.apply(Math,e)}function a(e,t){void 0===t&&(t=e);var n=o(t),r=0===n?0:1/n,i=t.map((function(e){return r*e}));return{distance:o(e),direction:i}}function s(e,t,n){var r=o(t),i=0===r?0:1/r,a=0===n?0:1/n,s=a*r,u=t.map((function(e){return a*e})),c=t.map((function(e){return i*e}));return{velocities:u,velocity:s,distance:o(e),direction:c}}function u(e){return Math.sign?Math.sign(e):Number(e>0)-Number(e<0)||+e}function c(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 l(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?-c(t-e,n-t,r)+t:e>n?+c(e-n,n-t,r)+n:e}function d(){return(d=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 v(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 h(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function p(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function g(e,t){var n;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return p(e,void 0);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?p(e,void 0):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0;return function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(n=e[Symbol.iterator]()).next.bind(n)}function m(){}function y(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return 0===t.length?m:1===t.length?t[0]:function(){for(var e,n,r=g(t);!(n=r()).done;){var i=n.value;e=i.apply(this,arguments)||e}return e}}function w(e,t){if(void 0===e){if(void 0===t)throw new Error("Must define fallback value if undefined is expected");e=t}return Array.isArray(e)?e:[e,e]}function b(e,t){return Object.assign({},t,e||{})}function S(e){if("function"==typeof e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];return e.apply(void 0,n)}return e}function _(e,t){void 0===e&&(e={});for(var n={},r=0,i=Object.entries(t);r<i.length;r++){var o=i[r],a=o[0],s=o[1];switch(typeof s){case"function":n[a]=s.call(n,e[a],a,e);break;case"object":n[a]=_(e[a],s);break;case"boolean":s&&(n[a]=e[a])}}return n}var G={threshold:function(e){return void 0===e&&(e=0),w(e)},rubberband:function(e){switch(void 0===e&&(e=0),e){case!0:return w(.15);case!1:return w(0);default:return w(e)}},enabled:function(e){return void 0===e&&(e=!0),e},triggerAllEvents:function(e){return void 0===e&&(e=!1),e},initial:function(e){return void 0===e&&(e=0),"function"==typeof e?e:w(e)}},T=d({},G,{axis:!0,lockDirection:function(e){return void 0===e&&(e=!1),e},bounds:function(e){if(void 0===e&&(e={}),"function"==typeof e)return function(t){return T.bounds(e(t))};var t=e.left,n=e.right,r=e.top,i=e.bottom;return[[void 0===t?-Infinity:t,void 0===n?Infinity:n],[void 0===r?-Infinity:r,void 0===i?Infinity:i]]}}),M="undefined"!=typeof window&&window.document&&window.document.createElement,O={enabled:function(e){return void 0===e&&(e=!0),e},domTarget:function(e){return M?e:void 0},window:function(e){function t(t){return e.apply(this,arguments)}return t.toString=function(){return e.toString()},t}((function(e){return void 0===e&&(e=M?window:void 0),e})),eventOptions:function(e){var t=void 0===e?{}:e,n=t.passive,r=t.capture;return{passive:void 0===n||n,capture:void 0!==r&&r}}},E=d({},G,{bounds:function(e,t,n){var r=n.distanceBounds,i=void 0===r?{}:r,o=n.angleBounds,a=void 0===o?{}:o,s=function(e){var t=b(S(i,e),{min:-Infinity,max:Infinity});return[t.min,t.max]},u=function(e){var t=b(S(a,e),{min:-Infinity,max:Infinity});return[t.min,t.max]};return"function"!=typeof i&&"function"!=typeof a?[s(),u()]:function(e){return[s(e),u(e)]}}}),x=d({},T,{threshold:function(e,t,n){var r=n.filterTaps,i=void 0!==r&&r,o=n.lockDirection,a=n.axis,s=w(e,i?3:void 0!==o&&o||(void 0===a?void 0:a)?1:0);return this.filterTaps=i||s[0]+s[1]>0,s},swipeVelocity:function(e){return void 0===e&&(e=.5),w(e)},swipeDistance:function(e){return void 0===e&&(e=60),w(e)},delay:function(e){switch(void 0===e&&(e=0),e){case!0:return 180;case!1:return 0;default:return e}}});function K(e){return void 0===e&&(e={}),_(e,O)}function I(e){return void 0===e&&(e={}),_(e,T)}function k(e){return void 0===e&&(e={}),_(e,E)}function j(e){return void 0===e&&(e={}),_(e,x)}function D(e){var t=e.domTarget,n=e.eventOptions,r=e.window,i=e.enabled,o=f(e,["domTarget","eventOptions","window","enabled"]),a=K({domTarget:t,eventOptions:n,window:r,enabled:i});return a.move=I(o),a}function H(e){var t=e.domTarget,n=e.eventOptions,r=e.window,i=e.enabled,o=f(e,["domTarget","eventOptions","window","enabled"]),a=K({domTarget:t,eventOptions:n,window:r,enabled:i});return a.hover=d({enabled:!0},o),a}function P(e){var t=e.domTarget,n=e.eventOptions,r=e.window,i=e.enabled,o=f(e,["domTarget","eventOptions","window","enabled"]),a=K({domTarget:t,eventOptions:n,window:r,enabled:i});return a.drag=j(o),a}function C(e){var t=e.domTarget,n=e.eventOptions,r=e.window,i=e.enabled,o=f(e,["domTarget","eventOptions","window","enabled"]),a=K({domTarget:t,eventOptions:n,window:r,enabled:i});return a.pinch=k(o),a}function A(e){var t=e.domTarget,n=e.eventOptions,r=e.window,i=e.enabled,o=f(e,["domTarget","eventOptions","window","enabled"]),a=K({domTarget:t,eventOptions:n,window:r,enabled:i});return a.scroll=I(o),a}function W(e){var t=e.domTarget,n=e.eventOptions,r=e.window,i=e.enabled,o=f(e,["domTarget","eventOptions","window","enabled"]),a=K({domTarget:t,eventOptions:n,window:r,enabled:i});return a.wheel=I(o),a}function L(e){return d({_active:!1,_blocked:!1,_intentional:[!1,!1],_movement:[0,0],_initial:[0,0],_bounds:[[-Infinity,Infinity],[-Infinity,Infinity]],_lastEventType:void 0,event:void 0,intentional:!1,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:m,canceled:!1,memo:void 0,args:void 0},e)}function R(){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:L({axis:void 0,xy:[0,0],vxvy:[0,0],velocity:0,distance:0,_isTap:!0,_delayedEvent:!1,_pointerId:void 0,tap:!1,swipe:[0,0]}),pinch:L({da:[0,0],vdva:[0,0],origin:void 0,turns:0}),wheel:L({axis:void 0,xy:[0,0],vxvy:[0,0],velocity:0,distance:0}),move:L({axis:void 0,xy:[0,0],vxvy:[0,0],velocity:0,distance:0}),scroll:L({axis:void 0,xy:[0,0],vxvy:[0,0],velocity:0,distance:0})}}var V=new Map,B=function(){function e(e,t){var n=this;void 0===t&&(t=[]),this.controller=e,this.args=t,this.debounced=!0,this.setTimeout=function(e,t){var r;void 0===t&&(t=140),clearTimeout(n.controller.timeouts[n.stateKey]);for(var i=arguments.length,o=new Array(i>2?i-2:0),a=2;a<i;a++)o[a-2]=arguments[a];n.controller.timeouts[n.stateKey]=(r=window).setTimeout.apply(r,[e,t].concat(o))},this.clearTimeout=function(){clearTimeout(n.controller.timeouts[n.stateKey])},this.fireGestureHandler=function(e){if(void 0===e&&(e=!1),n.state._blocked)return n.debounced||(n.state._active=!1,n.clean()),null;if(!e&&!n.state.intentional&&!n.config.triggerAllEvents)return null;if(n.state.intentional){var t=n.state.active,r=n.state._active;n.state.active=r,n.state.first=r&&!t,n.state.last=t&&!r,n.controller.state.shared[n.ingKey]=r}var i=d({},n.controller.state.shared,n.state,n.mapStateValues(n.state)),o=n.handler(i);return n.state.memo=void 0!==o?o:n.state.memo,n.state._active||n.clean(),i}}var t,n=e.prototype;return n.updateSharedState=function(e){Object.assign(this.controller.state.shared,e)},n.updateGestureState=function(e){Object.assign(this.state,e)},n.checkIntentionality=function(e,t){return{_intentional:e,_blocked:!1}},n.getMovement=function(e){var t=this.config,n=t.initial,o=t.bounds,a=t.rubberband,s=t.threshold,u=this.state,c=u._bounds,l=u._initial,v=u._active,f=u._intentional,h=u.lastOffset,p=u.movement,g=this.getInternalMovement(e,this.state),m=!1===f[0]?X(g[0],s[0]):f[0],y=!1===f[1]?X(g[1],s[1]):f[1],w=this.checkIntentionality([m,y],g);if(w._blocked)return d({},w,{_movement:g,delta:[0,0]});var b,_,G,T,M=w._intentional,O=g;!1!==M[0]&&!1===f[0]&&(_=S(n,this.state),b=S(o,this.state),l[0]=_[0],c[0]=b[0]),!1!==M[1]&&!1===f[1]&&(_=null!=(G=_)?G:S(n,this.state),b=null!=(T=b)?T:S(o,this.state),l[1]=_[1],c[1]=b[1]);var E=[!1!==M[0]?g[0]-M[0]:l[0],!1!==M[1]?g[1]-M[1]:l[1]],x=r(E,h),K=v?a:[0,0];return E=Y(c,r(E,l),K),d({},w,{intentional:!1!==M[0]||!1!==M[1],_initial:l,_movement:O,movement:E,values:e,offset:Y(c,x,K),delta:i(E,p)})},n.clean=function(){this.clearTimeout()},(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}();function X(e,t){return Math.abs(e)>=t&&u(e)*t}function Y(e,t,n){var r=t[1],i=n[1],o=e[0],a=e[1],s=a[0],u=a[1];return[l(t[0],o[0],o[1],n[0]),l(r,s,u,i)]}function F(e,t,n){var r=e.state,i=t.timeStamp;return{_lastEventType:t.type,event:t,timeStamp:i,elapsedTime:n?0:i-r.startTime,args:e.args,previous:r.values}}function z(e,t,n){var r=e.state.offset,i=n.timeStamp;return d({},R()[e.stateKey],{_active:!0,values:t,initial:t,offset:r,lastOffset:r,startTime:i})}function q(e,t){return function(n){for(var r=arguments.length,i=new Array(r>1?r-1:0),o=1;o<r;o++)i[o-1]=arguments[o];return e.call.apply(e,[this,d({},t,{event:n})].concat(i))}}var $=function(e){var t=this;this.classes=e,this.bind=function(){for(var e={},n=arguments.length,r=new Array(n),i=0;i<n;i++)r[i]=arguments[i];for(var o,a=g(t.classes);!(o=a()).done;){var s=o.value;new s(t,r).addBindings(e)}for(var u=0,c=Object.entries(t.nativeRefs);u<c.length;u++){var l=c[u],v=l[0],f=l[1];te(e,v,q(f,d({},t.state.shared,{args:r})))}return t.config.domTarget?J(t,e):Q(t,e)},this.effect=function(){return t.config.domTarget&&t.bind(),t.clean},this.clean=function(){var e=ee(t.config),n=t.config.eventOptions;e&&re(e,Z(t.domListeners),n),Object.values(t.timeouts).forEach(clearTimeout),function(e){var t=e.config,n=t.window,r=t.eventOptions,i=e.windowListeners;if(n){for(var o in i)re(n,i[o],r);e.windowListeners={}}}(t)},this.state=R(),this.timeouts={},this.domListeners=[],this.windowListeners={}};function N(e,t){var n=e.config,r=e.windowListeners;n.window&&(re(n.window,r[t],n.eventOptions),delete r[t])}function U(e,t,n){var r=e.config,i=e.windowListeners;void 0===n&&(n=[]),r.window&&(re(r.window,i[t],r.eventOptions),ne(r.window,i[t]=n,r.eventOptions))}function J(e,t){var n=e.config,r=e.domListeners,i=ee(n);if(!i)throw new Error("domTarget must be defined");var o=n.eventOptions;re(i,Z(r),o);for(var a=0,s=Object.entries(t);a<s.length;a++){var u=s[a],c=u[1],l=u[0].slice(2).toLowerCase();r.push([l,y.apply(void 0,c)])}ne(i,r,o)}function Q(e,t){for(var n={},r=e.config.eventOptions.capture?"Capture":"",i=0,o=Object.entries(t);i<o.length;i++){var a=o[i],s=a[0],u=a[1],c=Array.isArray(u)?u:[u];n[s+r]=y.apply(void 0,c)}return n}function Z(e){return void 0===e&&(e=[]),e.splice(0,e.length)}function ee(e){var t=e.domTarget;return t&&"current"in t?t.current:t}function te(e,t,n){e[t]||(e[t]=[]),e[t].push(n)}function ne(e,t,n){void 0===t&&(t=[]),void 0===n&&(n={});for(var r,i=g(t);!(r=i()).done;){var o=r.value;e.addEventListener(o[0],o[1],n)}}function re(e,t,n){void 0===t&&(t=[]),void 0===n&&(n={});for(var r,i=g(t);!(r=i()).done;){var o=r.value;e.removeEventListener(o[0],o[1],n)}}function ie(e,t,r){void 0===r&&(r={});var i=function(e){var t=new Set;return e.drag&&t.add(V.get("drag")),e.wheel&&t.add(V.get("wheel")),e.scroll&&t.add(V.get("scroll")),e.move&&t.add(V.get("move")),e.pinch&&t.add(V.get("pinch")),e.hover&&t.add(V.get("hover")),t}(e),o=n.useMemo((function(){return new $(i)}),[]);return o.config=t,o.handlers=e,o.nativeRefs=r,n.useEffect(o.effect,[]),o.config.domTarget?oe:o.bind}function oe(){}var ae=function(e){function t(){return e.apply(this,arguments)||this}v(t,e);var n=t.prototype;return n.getInternalMovement=function(e,t){return i(e,t.initial)},n.checkIntentionality=function(e,t){if(!1===e[0]&&!1===e[1])return{_intentional:e,axis:this.state.axis};var n=t.map(Math.abs),r=n[0],i=n[1],o=this.state.axis||(r>i?"x":r<i?"y":void 0);return this.config.axis||this.config.lockDirection?o?this.config.axis&&o!==this.config.axis?{_intentional:e,_blocked:!0,axis:o}:(e["x"===o?1:0]=!1,{_intentional:e,_blocked:!1,axis:o}):{_intentional:[!1,!1],_blocked:!1,axis:o}:{_intentional:e,_blocked:!1,axis:o}},n.getKinematics=function(e,t){var n=this.getMovement(e);return n._blocked||Object.assign(n,s(n.movement,n.delta,t.timeStamp-this.state.timeStamp)),n},n.mapStateValues=function(e){return{xy:e.values,vxvy:e.velocities}},t}(B);function se(e){if("touches"in e){var t=e.targetTouches;return t.length>0?t:e.changedTouches}return null}function ue(e){var t="buttons"in e?e.buttons:0,n=se(e),r=n&&n.length||0;return{touches:r,down:r>0||t>0,buttons:t,shiftKey:e.shiftKey,altKey:e.altKey,metaKey:e.metaKey,ctrlKey:e.ctrlKey}}function ce(e){var t=se(e),n=t?t[0]:e;return[n.clientX,n.clientY]}function le(e){var t=e.currentTarget;return[t.scrollX||t.scrollLeft||0,t.scrollY||t.scrollTop||0]}function de(e){return[e.deltaX,e.deltaY]}function ve(e){return[260*e.scale,e.rotation]}function fe(e){var t,n=e.targetTouches,r=n[0],i=n[1],o=i.clientX-r.clientX,a=i.clientY-r.clientY,s=(i.clientX+r.clientX)/2,u=(i.clientY+r.clientY)/2,c="nativeEvent"in e?e.nativeEvent:e;return{values:[Math.hypot(o,a),null!=(t=c.rotation)?t:-180*Math.atan2(o,a)/Math.PI],origin:[s,u]}}var he=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).ingKey="dragging",t.stateKey="drag",t.onDragStart=function(e){t.enabled&&!t.state._active&&(U(t.controller,t.stateKey,[["pointermove",t.onDragChange],["pointerup",t.onDragEnd],["pointercancel",t.onDragEnd]]),t.updateGestureState({_pointerId:e.pointerId}),t.config.delay>0?(t.state._delayedEvent=!0,"persist"in e&&"function"==typeof e.persist&&e.persist(),t.setTimeout(t.startDrag.bind(h(t)),t.config.delay,e)):t.startDrag(e))},t.onDragChange=function(e){if(!t.state.canceled&&e.pointerId===t.state._pointerId)if(t.state._active){var n=ue(e);if(n.down){t.updateSharedState(n);var r=ce(e),i=t.getKinematics(r,e),a=F(h(t),e),s=t.state._isTap,u=o(i._movement);s&&u>=3&&(s=!1),t.updateGestureState(d({},a,i,{_isTap:s})),t.fireGestureHandler()}else t.onDragEnd(e)}else t.state._delayedEvent&&(t.clearTimeout(),t.startDrag(e))},t.onDragEnd=function(e){if(e.pointerId===t.state._pointerId){t.state._active=!1,t.updateSharedState({down:!1,buttons:0,touches:0});var n=t.state._isTap,r=t.state.velocities,i=r[0],o=r[1],a=t.state.movement,s=a[0],c=a[1],l=t.state._intentional,v=l[0],f=l[1],p=t.config.swipeVelocity,g=p[0],m=p[1],y=t.config.swipeDistance,w=y[0],b=y[1],S=d({},F(h(t),e),t.getMovement(t.state.values)),_=[0,0];S.elapsedTime<220&&(!1!==v&&Math.abs(i)>g&&Math.abs(s)>w&&(_[0]=u(i)),!1!==f&&Math.abs(o)>m&&Math.abs(c)>b&&(_[1]=u(o))),t.updateGestureState(d({},S,{tap:n,swipe:_})),t.fireGestureHandler(!0===n)}},t.clean=function(){e.prototype.clean.call(h(t)),t.state._delayedEvent=!1,N(t.controller,t.stateKey)},t.onCancel=function(){t.state.canceled||(t.updateGestureState({canceled:!0}),t.state._active=!1,t.updateSharedState({down:!1,buttons:0,touches:0}),requestAnimationFrame((function(){return t.fireGestureHandler()})))},t.onClick=function(e){t.state._isTap||e.stopPropagation()},t}v(t,e);var n=t.prototype;return n.startDrag=function(e){var t=ce(e);this.updateSharedState(ue(e)),this.updateGestureState(d({},z(this,t,e),F(this,e,!0),{_pointerId:e.pointerId,cancel:this.onCancel})),this.updateGestureState(this.getMovement(t)),this.fireGestureHandler()},n.addBindings=function(e){te(e,"onPointerDown",this.onDragStart),this.config.filterTaps&&te(e,this.controller.config.eventOptions.capture?"onClick":"onClickCapture",this.onClick)},t}(ae);function pe(e,t){var n,r,i=[],o=!1;return function(){for(var a=arguments.length,s=new Array(a),u=0;u<a;u++)s[u]=arguments[u];return o&&n===this&&t(s,i)||(r=e.apply(this,s),o=!0,n=this,i=s),r}}function ge(e,t){try{return function e(t,n){if(t===n)return!0;if(t&&n&&"object"==typeof t&&"object"==typeof n){if(t.constructor!==n.constructor)return!1;var r,i,o,a;if(Array.isArray(t)){if((r=t.length)!==n.length)return!1;for(i=r;0!=i--;)if(!e(t[i],n[i]))return!1;return!0}if("function"==typeof Map&&t instanceof Map&&n instanceof Map){if(t.size!==n.size)return!1;for(a=t.entries();!(i=a.next()).done;)if(!n.has(i.value[0]))return!1;for(a=t.entries();!(i=a.next()).done;)if(!e(i.value[1],n.get(i.value[0])))return!1;return!0}if("function"==typeof Set&&t instanceof Set&&n instanceof Set){if(t.size!==n.size)return!1;for(a=t.entries();!(i=a.next()).done;)if(!n.has(i.value[0]))return!1;return!0}if(t.constructor===RegExp)return t.source===n.source&&t.flags===n.flags;if(t.valueOf!==Object.prototype.valueOf)return t.valueOf()===n.valueOf();if(t.toString!==Object.prototype.toString)return t.toString()===n.toString();if((r=(o=Object.keys(t)).length)!==Object.keys(n).length)return!1;for(i=r;0!=i--;)if(!Object.prototype.hasOwnProperty.call(n,o[i]))return!1;if("undefined"!=typeof Element&&t instanceof Element)return!1;for(i=r;0!=i--;)if(!("_owner"===o[i]&&t.$$typeof||e(t[o[i]],n[o[i]])))return!1;return!0}return t!=t&&n!=n}(e,t)}catch(e){if((e.message||"").match(/stack|recursion/i))return console.warn("react-fast-compare cannot handle circular refs"),!1;throw e}}var me=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).ingKey="pinching",t.stateKey="pinch",t.pinchShouldStart=function(e){var n=ue(e);return t.enabled&&2===n.touches},t.onPinchStart=function(e){if(t.pinchShouldStart(e)){var n=fe(e),r=n.values,i=n.origin;t.updateSharedState(ue(e)),t.updateGestureState(d({},z(h(t),r,e),F(h(t),e,!0),{cancel:t.onCancel,origin:i})),t.updateGestureState(t.getMovement(r)),t.fireGestureHandler()}},t.onPinchChange=function(e){var n=t.state;if(!n.canceled&&n._active){var r=ue(e);t.updateSharedState(r);var i=fe(e),o=i.origin,a=t.getKinematics(i.values,e);t.updateGestureState(d({},F(h(t),e),a,{origin:o})),t.fireGestureHandler()}},t.onPinchEnd=function(e){t.state.active&&(t.state._active=!1,t.updateSharedState({down:!1,touches:0}),t.updateGestureState(d({},F(h(t),e),t.getMovement(t.state.values))),t.fireGestureHandler())},t.onCancel=function(){t.state.canceled||(t.state._active=!1,t.updateGestureState({canceled:!0}),t.updateSharedState({down:!1,touches:0}),requestAnimationFrame((function(){return t.fireGestureHandler()})))},t.onGestureStart=function(e){if(t.enabled){e.preventDefault();var n=ve(e);t.updateSharedState(ue(e)),t.updateGestureState(d({},z(h(t),n,e),F(h(t),e,!0),{cancel:t.onCancel})),t.updateGestureState(t.getMovement(n)),t.fireGestureHandler()}},t.onGestureChange=function(e){var n=t.state;if(!n.canceled&&n._active){e.preventDefault();var r=ue(e);t.updateSharedState(r);var i=ve(e),o=t.getKinematics(i,e);t.updateGestureState(d({},F(h(t),e),o)),t.fireGestureHandler()}},t.onGestureEnd=function(e){e.preventDefault(),t.state.active&&(t.state._active=!1,t.updateSharedState({down:!1,touches:0}),t.updateGestureState(d({},F(h(t),e),t.getMovement(t.state.values))),t.fireGestureHandler())},t.wheelShouldRun=function(e){return t.enabled&&e.ctrlKey},t.getWheelValuesFromEvent=function(e){var n=de(e)[1],r=t.state.values,i=r[1];return{values:[r[0]-n,void 0!==i?i:0],origin:[e.clientX,e.clientY],delta:[0,n]}},t.onWheel=function(e){t.wheelShouldRun(e)&&(t.setTimeout(t.onWheelEnd),t.state._active?t.onWheelChange(e):t.onWheelStart(e))},t.onWheelStart=function(e){var n=t.getWheelValuesFromEvent(e),r=n.values,i=n.delta,o=n.origin;t.controller.config.eventOptions.passive||e.preventDefault(),t.updateSharedState(ue(e)),t.updateGestureState(d({},z(h(t),r,e),F(h(t),e,!0),{initial:t.state.values,offset:r,delta:i,origin:o})),t.updateGestureState(t.getMovement(r)),t.fireGestureHandler()},t.onWheelChange=function(e){t.updateSharedState(ue(e));var n=t.getWheelValuesFromEvent(e),r=n.values,i=n.origin,o=n.delta;t.updateGestureState(d({},F(h(t),e),t.getKinematics(r,e),{origin:i,delta:o})),t.fireGestureHandler()},t.onWheelEnd=function(){t.state._active=!1,t.updateGestureState(t.getMovement(t.state.values)),t.fireGestureHandler()},t}return v(t,e),t.prototype.addBindings=function(e){this.controller.config.domTarget&&("undefined"==typeof window||null!==window.ontouchstart)&&function(){try{return"constructor"in GestureEvent}catch(e){return!1}}()?(te(e,"onGestureStart",this.onGestureStart),te(e,"onGestureChange",this.onGestureChange),te(e,"onGestureEnd",this.onGestureEnd)):(te(e,"onTouchStart",this.onPinchStart),te(e,"onTouchMove",this.onPinchChange),te(e,"onTouchEnd",this.onPinchEnd),te(e,"onTouchCancel",this.onPinchEnd),te(e,"onWheel",this.onWheel))},t}(function(e){function t(){return e.apply(this,arguments)||this}v(t,e);var n=t.prototype;return n.getInternalMovement=function(e,t){var n=t.values[1],r=e[0],o=e[1],a=void 0===o?n:o,s=a-n,c=t.turns;return Math.abs(s)>270&&(c+=u(s)),i([r,a-360*c],t.initial)},n.getKinematics=function(e,t){var n=this.getMovement(e);return d({turns:(e[1]-n.movement[1]-this.state.initial[1])/360},n,s(n.movement,n.delta,t.timeStamp-this.state.timeStamp))},n.mapStateValues=function(e){return{da:e.values,vdva:e.velocities}},t}(B)),ye=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).ingKey="wheeling",t.stateKey="wheel",t.debounced=!0,t.handleEvent=function(e){if((!e.ctrlKey||!("pinch"in t.controller.handlers))&&t.enabled){t.setTimeout(t.onEnd),t.updateSharedState(ue(e));var n=r(de(e),t.state.values);if(t.state._active)t.updateGestureState(d({},F(h(t),e),t.getKinematics(n,e)));else{t.updateGestureState(d({},z(h(t),n,e),F(h(t),e,!0),{initial:t.state.values}));var i=t.getMovement(n),o=a(i.delta);t.updateGestureState(i),t.updateGestureState(o)}t.fireGestureHandler()}},t.onEnd=function(){var e=t.getMovement(t.state.values);t.updateGestureState(e),t.updateGestureState({_active:!1,velocities:[0,0],velocity:0}),t.fireGestureHandler()},t}return v(t,e),t.prototype.addBindings=function(e){te(e,"onWheel",this.handleEvent)},t}(ae),we=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).ingKey="moving",t.stateKey="move",t.debounced=!0,t.onMove=function(e){t.enabled&&(t.setTimeout(t.onMoveEnd),t.state._active?t.onMoveChange(e):t.onMoveStart(e))},t.onMoveStart=function(e){t.updateSharedState(ue(e));var n=ce(e);t.updateGestureState(d({},z(h(t),n,e),F(h(t),e,!0))),t.updateGestureState(t.getMovement(n)),t.fireGestureHandler()},t.onMoveChange=function(e){t.updateSharedState(ue(e));var n=ce(e);t.updateGestureState(d({},F(h(t),e),t.getKinematics(n,e))),t.fireGestureHandler()},t.onMoveEnd=function(){t.updateGestureState(t.getMovement(t.state.values)),t.updateGestureState({velocities:[0,0],velocity:0,_active:!1}),t.fireGestureHandler()},t.onPointerEnter=function(e){if(t.controller.state.shared.hovering=!0,t.controller.config.enabled){if(t.controller.config.hover.enabled){var n=ce(e),r=d({},t.controller.state.shared,t.state,F(h(t),e,!0),{values:n,active:!0,hovering:!0});t.controller.handlers.hover(d({},r,t.mapStateValues(r)))}"move"in t.controller.handlers&&t.onMoveStart(e)}},t.onPointerLeave=function(e){if(t.controller.state.shared.hovering=!1,"move"in t.controller.handlers&&t.onMoveEnd(),t.controller.config.hover.enabled){var n=ce(e),r=d({},t.controller.state.shared,t.state,F(h(t),e),{values:n,active:!1});t.controller.handlers.hover(d({},r,t.mapStateValues(r)))}},t}return v(t,e),t.prototype.addBindings=function(e){"move"in this.controller.handlers&&te(e,"onPointerMove",this.onMove),"hover"in this.controller.handlers&&(te(e,"onPointerEnter",this.onPointerEnter),te(e,"onPointerLeave",this.onPointerLeave))},t}(ae),be=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).ingKey="scrolling",t.stateKey="scroll",t.debounced=!0,t.handleEvent=function(e){if(t.enabled){t.clearTimeout(),t.setTimeout(t.onEnd);var n=le(e);if(t.updateSharedState(ue(e)),t.state._active)t.updateGestureState(d({},F(h(t),e),t.getKinematics(n,e)));else{t.updateGestureState(d({},z(h(t),n,e),F(h(t),e,!0),{initial:t.state.values}));var r=t.getMovement(n),i=a(r.delta);t.updateGestureState(r),t.updateGestureState(i)}t.fireGestureHandler()}},t.onEnd=function(){t.state._active=!1,t.updateGestureState(d({},t.getMovement(t.state.values),{velocities:[0,0],velocity:0})),t.fireGestureHandler()},t}return v(t,e),t.prototype.addBindings=function(e){te(e,"onScroll",this.handleEvent)},t}(ae),Se=/^on(Drag|Wheel|Scroll|Move|Pinch|Hover)/;function _e(e,t){var n=t+"Start",r=t+"End";return function(i){var o=void 0;return i.first&&n in e&&e[n](i),t in e&&(o=e[t](i)),i.last&&r in e&&e[r](i),o}}exports.addV=r,exports.rubberbandIfOutOfBounds=l,exports.subV=i,exports.useDrag=function(e,n){void 0===n&&(n={}),V.set("drag",he);var r=t.useRef();return r.current||(r.current=pe(P,ge)),ie({drag:e},r.current(n))},exports.useGesture=function(e,t){void 0===t&&(t={});var n=function(e){var t={},n={},r=new Set;for(var i in e)Se.test(i)?(r.add(RegExp.lastMatch),n[i]=e[i]):t[i]=e[i];return[n,t,r]}(e),r=n[0],i=n[1],o=n[2];V.set("drag",he),V.set("hover",we),V.set("move",we),V.set("pinch",me),V.set("scroll",be),V.set("wheel",ye);var a=function(e,t){void 0===e&&(e={}),void 0===t&&(t=new Set);var n=e.drag,r=e.wheel,i=e.move,o=e.scroll,a=e.pinch,s=e.hover,u=K({eventOptions:e.eventOptions,window:e.window,domTarget:e.domTarget,enabled:e.enabled});return t.has("onDrag")&&(u.drag=j(n)),t.has("onWheel")&&(u.wheel=I(r)),t.has("onScroll")&&(u.scroll=I(o)),t.has("onMove")&&(u.move=I(i)),t.has("onPinch")&&(u.pinch=k(a)),t.has("onHover")&&(u.hover=d({enabled:!0},s)),u}(t,o),s={};return o.has("onDrag")&&(s.drag=_e(r,"onDrag")),o.has("onWheel")&&(s.wheel=_e(r,"onWheel")),o.has("onScroll")&&(s.scroll=_e(r,"onScroll")),o.has("onMove")&&(s.move=_e(r,"onMove")),o.has("onPinch")&&(s.pinch=_e(r,"onPinch")),o.has("onHover")&&(s.hover=r.onHover),ie(s,a,i)},exports.useHover=function(e,n){void 0===n&&(n={}),V.set("hover",we);var r=t.useRef();return r.current||(r.current=pe(H,ge)),ie({hover:e},r.current(n))},exports.useMove=function(e,n){void 0===n&&(n={}),V.set("move",we);var r=t.useRef();return r.current||(r.current=pe(D,ge)),ie({move:e},r.current(n))},exports.usePinch=function(e,n){void 0===n&&(n={}),V.set("pinch",me);var r=t.useRef();return r.current||(r.current=pe(C,ge)),ie({pinch:e},r.current(n))},exports.useScroll=function(e,n){void 0===n&&(n={}),V.set("scroll",be);var r=t.useRef();return r.current||(r.current=pe(A,ge)),ie({scroll:e},r.current(n))},exports.useWheel=function(e,n){void 0===n&&(n={}),V.set("wheel",ye);var r=t.useRef();return r.current||(r.current=pe(W,ge)),ie({wheel:e},r.current(n))}; | ||
//# sourceMappingURL=react-use-gesture.cjs.production.min.js.map |
{ | ||
"name": "react-use-gesture", | ||
"version": "8.0.0-beta.1", | ||
"version": "8.0.0-beta.2", | ||
"description": "React hook for receiving gestures https://use-gesture.netlify.app", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -57,3 +57,3 @@ # React UseGesture | ||
// Bind it to a component | ||
return <animated.div {...bind()} style={{ x, y }} /> | ||
return <animated.div {...bind()} style={{ x, y, touchAction: 'none' }} /> | ||
``` | ||
@@ -63,2 +63,4 @@ | ||
**Make sure you always set [`touchAction`](https://developer.mozilla.org/en-US/docs/Web/CSS/touch-action) on a draggable element to prevent glitches with the browser native scrolling on touch devices**. | ||
### Available hooks | ||
@@ -65,0 +67,0 @@ |
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
604159
5185
79