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