import{useRef as n,useCallback as t,useEffect as e,useMemo as r}from"react";function o(){return(o=Object.assign||function(n){for(var t=1;t<arguments.length;t++){var e=arguments[t];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r])}return n}).apply(this,arguments)}var u,c;function i(n){var t=n.nativeEvent;return window.TouchEvent?t instanceof TouchEvent:"touches"in t}function a(n){return n.nativeEvent instanceof MouseEvent}function v(n){return i(n)?{x:n.touches[0].pageX,y:n.touches[0].pageY}:a(n)?{x:n.pageX,y:n.pageY}:null}function f(f,l){var s=void 0===l?{}:l,E=s.threshold,M=void 0===E?400:E,h=s.captureEvent,T=void 0!==h&&h,d=s.detect,p=void 0===d?c.BOTH:d,O=s.cancelOnMovement,y=void 0!==O&&O,C=s.filterEvents,m=s.onStart,x=s.onMove,_=s.onFinish,b=s.onCancel,U=n(!1),g=n(!1),B=n(),N=n(f),Y=n(null),D=t(function(n){return function(t){if(!g.current&&(a(t)||i(t))&&(void 0===C||C(t))){Y.current=v(t),T&&t.persist();var e=void 0===n?{}:{context:n};null==m||m(t,e),g.current=!0,B.current=setTimeout(function(){N.current&&(N.current(t,e),U.current=!0)},M)}}},[T,C,m,M]),L=t(function(n,t){return function(e){if(a(e)||i(e)){Y.current=null,T&&e.persist();var r=void 0===n?{}:{context:n};U.current?null==_||_(e,r):g.current&&(null==b||b(e,o({},r,{reason:null!=t?t:u.CANCELED_BY_TIMEOUT}))),U.current=!1,g.current=!1,void 0!==B.current&&clearTimeout(B.current)}}},[T,_,b]),w=t(function(n){return function(t){if(null==x||x(t,{context:n}),y&&Y.current){var e=v(t);if(e){var r=!0===y?25:y,o={x:Math.abs(e.x-Y.current.x),y:Math.abs(e.y-Y.current.y)};(o.x>r||o.y>r)&&L(n,u.CANCELED_BY_MOVEMENT)(t)}}}},[L,y,x]);return e(function(){return function(){void 0!==B.current&&clearTimeout(B.current)}},[]),e(function(){N.current=f},[f]),r(function(){return function(n){var t={onMouseDown:D(n),onMouseMove:w(n),onMouseUp:L(n),onMouseLeave:L(n)},e={onTouchStart:D(n),onTouchMove:w(n),onTouchEnd:L(n)};return null===f?{}:p===c.MOUSE?t:p===c.TOUCH?e:o({},t,e)}},[f,L,p,w,D])}!function(n){n.CANCELED_BY_MOVEMENT="canceled-by-movement",n.CANCELED_BY_TIMEOUT="canceled-by-timeout"}(u||(u={})),function(n){n.BOTH="both",n.MOUSE="mouse",n.TOUCH="touch"}(c||(c={}));export{c as LongPressDetectEvents,u as LongPressEventReason,f as useLongPress};
//# sourceMappingURL=index.module.js.map
