@react-hook/mouse-position
Advanced tools
Comparing version
@@ -7,2 +7,4 @@ (function (global, factory) { | ||
var React__default = 'default' in React ? React['default'] : React; | ||
function _defineProperty(obj, key, value) { | ||
@@ -57,42 +59,42 @@ if (key in obj) { | ||
var usePassiveLayoutEffect = React[typeof document !== 'undefined' && document.createElement !== void 0 ? 'useLayoutEffect' : 'useEffect']; | ||
var usePassiveLayoutEffect = React__default[typeof document !== 'undefined' && document.createElement !== void 0 ? 'useLayoutEffect' : 'useEffect']; | ||
var useLatest = function useLatest(current) { | ||
var storedValue = React.useRef(current); | ||
storedValue.current = current; | ||
return storedValue; | ||
}; | ||
function useEvent(target, type, listener, cleanup) { | ||
if (cleanup === void 0) { | ||
cleanup = noop; | ||
} | ||
var storedListener = React.useRef(listener); | ||
var storedCleanup = React.useRef(cleanup); | ||
usePassiveLayoutEffect(function () { | ||
storedListener.current = listener; | ||
storedCleanup.current = cleanup; | ||
}); | ||
usePassiveLayoutEffect(function () { | ||
var targetEl = target && 'current' in target ? target.current : target; | ||
if (!targetEl) return; | ||
var didUnsubscribe = 0; | ||
var storedListener = useLatest(listener); | ||
var storedCleanup = useLatest(cleanup); | ||
function listener() { | ||
if (didUnsubscribe) return; | ||
function _listener() { | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
storedListener.current(this, args); | ||
} | ||
storedListener.current.apply(this, args); | ||
} | ||
usePassiveLayoutEffect(function () { | ||
var targetEl = target && 'current' in target ? target.current : target; | ||
if (!targetEl) return; | ||
var listener = _listener; | ||
targetEl.addEventListener(type, listener); | ||
var cleanup = storedCleanup.current; | ||
return function () { | ||
didUnsubscribe = 1; | ||
targetEl.removeEventListener(type, listener); | ||
cleanup(); | ||
cleanup && cleanup(); | ||
}; // eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [target, type]); | ||
} // eslint-disable-next-line @typescript-eslint/no-empty-function | ||
} | ||
var useLatest = function useLatest(current) { | ||
var storedValue = React.useRef(current); | ||
storedValue.current = current; | ||
return storedValue; | ||
}; | ||
function noop() {} | ||
var perf = typeof performance !== 'undefined' ? performance : Date; | ||
@@ -99,0 +101,0 @@ |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("react")):"function"==typeof define&&define.amd?define(["react"],t):(e=e||self).useMousePosition=t(e.React)}(this,(function(e){"use strict";function t(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:1,configurable:1,writable:1}):e[t]=n,e}function n(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var u=Object.getOwnPropertySymbols(e);t&&(u=u.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,u)}return n}function u(e){for(var u=1;arguments.length>u;u++){var o=null!=arguments[u]?arguments[u]:{};u%2?n(Object(o),1).forEach((function(n){t(e,n,o[n])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(o)):n(Object(o)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(o,t))}))}return e}function o(e,t,n,u){function o(){for(var e=arguments.length,t=new Array(e),n=0;e>n;n++)t[n]=arguments[n];c.current.apply(this,t)}void 0===u&&(u=r);var c=f(n),i=f(u);a((function(){var n=e&&"current"in e?e.current:e;if(n){var u=o;n.addEventListener(t,u);var r=i.current;return function(){n.removeEventListener(t,u),r()}}}),[e,t])}function r(){}function c(t,n,u){function o(){i.current=0,a()}void 0===n&&(n=30),void 0===u&&(u=0);var r=f(t),c=1e3/n,i=e.useRef(0),s=e.useRef(),a=function(){return s.current&&clearTimeout(s.current)},l=[n,u,r];return e.useEffect((function(){return o}),l),e.useCallback((function(){var e=arguments,t=v(),n=function(){i.current=t,a(),r.current.apply(null,e)},o=i.current;if(u&&0===o)return n();if(t-o>c){if(o>0)return n();i.current=t}a(),s.current=setTimeout((function(){n(),i.current=0}),c)}),l)}function i(e,t){if("undefined"==typeof window)return e;var n=t.event,o=t.element,r="touches"in n?n.touches[0]:n,c=r.clientX,i=r.clientY,s=r.screenX,a=r.screenY,f=r.pageX,l=void 0===f?0:f,v=r.pageY,p=void 0===v?0:v,d=o.getBoundingClientRect(),m=l-d.left-(window.pageXOffset||window.scrollX),h=p-d.top-(window.pageYOffset||window.scrollY);return"touches"in n&&(0>m||0>h||m>d.width||h>d.height)?u(u({},e),{},{context:u(u({},e.context),{},{hoverStatus:"leave",touchStatus:"end"})}):{context:u(u({},e.context),{},{hoverStatus:"enter"}),mouse:u(u({},e.mouse),{},{x:m,y:h,pageX:l,pageY:p,clientX:c,clientY:i,screenX:s,screenY:a,elementWidth:d.width,elementHeight:d.height,isOver:1,isTouch:"touches"in n})}}function s(e,t){var n=e.mouse,o=e.context,r=i;return"mousemove"===t.type?"end"===o.touchStatus?e:r(e,t):"touchmove"===t.type?r({context:u(u({},o),{},{touchStatus:"start"}),mouse:n},t):"touchdown"===t.type?r({context:u(u({},o),{},{touchStatus:"start"}),mouse:u(u({},n),{},{isDown:1})},t):"mousedown"===t.type?{context:o,mouse:u(u({},n),{},{isDown:1})}:"mouseup"===t.type?{context:o,mouse:u(u({},n),{},{isDown:0})}:"mouseleave"===t.type?{context:u(u({},o),{},{hoverStatus:"leave"}),mouse:u(u({},n),{},{isOver:0})}:"touchleave"===t.type?{context:u(u({},o),{},{hoverStatus:"leave",touchStatus:"end"}),mouse:u(u({},n),{},{isOver:0,isDown:0})}:"activeStatus"===t.type?{context:u(u({},o),{},{activeStatus:t.value}),mouse:n}:e}var a=e["undefined"!=typeof document&&void 0!==document.createElement?"useLayoutEffect":"useEffect"],f=function(t){var n=e.useRef(t);return n.current=t,n},l="undefined"!=typeof performance?performance:Date,v=function(){return l.now()},p={x:null,y:null,pageX:null,pageY:null,clientX:null,clientY:null,screenX:null,screenY:null,elementWidth:null,elementHeight:null,isOver:0,isDown:0,isTouch:0},d={hoverStatus:"idle",touchStatus:"idle",activeStatus:"inactive"};return function(t,n){function u(){return O({type:"activeStatus",value:"active"})}function r(){return O({type:"activeStatus",value:"inactive"})}void 0===n&&(n={});var i=n,a=i.fps,f=void 0===a?30:a,l=i.enterDelay,v=void 0===l?0:l,m=i.leaveDelay,h=void 0===m?0:m,y=e.useReducer(s,{mouse:p,context:d}),w=y[0],O=y[1],g=c((function(e){var n=t&&"current"in t?t.current:t;n&&O({type:"mousemove",event:e,element:n})}),f,1),S=c((function(e){var n=t&&"current"in t?t.current:t;n&&O({type:"touchmove",event:e,element:n})}),f,1),b=c((function(){return O({type:"mouseleave"})}),f,0),x=c((function(e){var n=t&&"current"in t?t.current:t;n&&O("touches"in e?{type:"touchdown",element:n,event:e}:{type:"mousedown",element:n,event:e})}),f,1),j=c((function(){return O({type:"mouseup"})}),f,0),D=c((function(){return O({type:"touchleave"})}),f,0);return o(t,"mouseenter",g),o(t,"mousemove",g),o(t,"mouseleave",b),o(t,"mousedown",x),o("undefined"!=typeof window?window:null,"mousedown",x),o("undefined"!=typeof window?window:null,"mouseup",j),o(t,"touchstart",x),o(t,"touchmove",S),o(t,"touchend",D),o(t,"touchcancel",D),e.useEffect((function(){if("enter"===w.context.hoverStatus){if(v){var e=setTimeout(u,v);return function(){return clearTimeout(e)}}O({type:"activeStatus",value:"active"})}else{if(h){var t=setTimeout(r,h);return function(){return clearTimeout(t)}}O({type:"activeStatus",value:"inactive"})}}),[w.context.hoverStatus,v,h]),"active"===w.context.activeStatus?w.mouse:p}})); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("react")):"function"==typeof define&&define.amd?define(["react"],t):(e=e||self).useMousePosition=t(e.React)}(this,(function(e){"use strict";function t(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:1,configurable:1,writable:1}):e[t]=n,e}function n(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var u=Object.getOwnPropertySymbols(e);t&&(u=u.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,u)}return n}function u(e){for(var u=1;arguments.length>u;u++){var o=null!=arguments[u]?arguments[u]:{};u%2?n(Object(o),1).forEach((function(n){t(e,n,o[n])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(o)):n(Object(o)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(o,t))}))}return e}function o(t,n,u,o){var r=e.useRef(u),c=e.useRef(o);s((function(){r.current=u,c.current=o})),s((function(){function e(){if(!o){for(var e=arguments.length,t=new Array(e),n=0;e>n;n++)t[n]=arguments[n];r.current(this,t)}}var u=t&&"current"in t?t.current:t;if(u){var o=0;u.addEventListener(n,e);var i=c.current;return function(){o=1,u.removeEventListener(n,e),i&&i()}}}),[t,n])}function r(t,n,u){function o(){a.current=0,v()}void 0===n&&(n=30),void 0===u&&(u=0);var r,c,i=(r=t,(c=e.useRef(r)).current=r,c),s=1e3/n,a=e.useRef(0),l=e.useRef(),v=function(){return l.current&&clearTimeout(l.current)},d=[n,u,i];return e.useEffect((function(){return o}),d),e.useCallback((function(){var e=arguments,t=f(),n=function(){a.current=t,v(),i.current.apply(null,e)},o=a.current;if(u&&0===o)return n();if(t-o>s){if(o>0)return n();a.current=t}v(),l.current=setTimeout((function(){n(),a.current=0}),s)}),d)}function c(e,t){if("undefined"==typeof window)return e;var n=t.event,o=t.element,r="touches"in n?n.touches[0]:n,c=r.clientX,i=r.clientY,s=r.screenX,a=r.screenY,f=r.pageX,l=void 0===f?0:f,v=r.pageY,d=void 0===v?0:v,p=o.getBoundingClientRect(),m=l-p.left-(window.pageXOffset||window.scrollX),h=d-p.top-(window.pageYOffset||window.scrollY);return"touches"in n&&(0>m||0>h||m>p.width||h>p.height)?u(u({},e),{},{context:u(u({},e.context),{},{hoverStatus:"leave",touchStatus:"end"})}):{context:u(u({},e.context),{},{hoverStatus:"enter"}),mouse:u(u({},e.mouse),{},{x:m,y:h,pageX:l,pageY:d,clientX:c,clientY:i,screenX:s,screenY:a,elementWidth:p.width,elementHeight:p.height,isOver:1,isTouch:"touches"in n})}}function i(e,t){var n=e.mouse,o=e.context,r=c;return"mousemove"===t.type?"end"===o.touchStatus?e:r(e,t):"touchmove"===t.type?r({context:u(u({},o),{},{touchStatus:"start"}),mouse:n},t):"touchdown"===t.type?r({context:u(u({},o),{},{touchStatus:"start"}),mouse:u(u({},n),{},{isDown:1})},t):"mousedown"===t.type?{context:o,mouse:u(u({},n),{},{isDown:1})}:"mouseup"===t.type?{context:o,mouse:u(u({},n),{},{isDown:0})}:"mouseleave"===t.type?{context:u(u({},o),{},{hoverStatus:"leave"}),mouse:u(u({},n),{},{isOver:0})}:"touchleave"===t.type?{context:u(u({},o),{},{hoverStatus:"leave",touchStatus:"end"}),mouse:u(u({},n),{},{isOver:0,isDown:0})}:"activeStatus"===t.type?{context:u(u({},o),{},{activeStatus:t.value}),mouse:n}:e}var s=("default"in e?e.default:e)["undefined"!=typeof document&&void 0!==document.createElement?"useLayoutEffect":"useEffect"],a="undefined"!=typeof performance?performance:Date,f=function(){return a.now()},l={x:null,y:null,pageX:null,pageY:null,clientX:null,clientY:null,screenX:null,screenY:null,elementWidth:null,elementHeight:null,isOver:0,isDown:0,isTouch:0},v={hoverStatus:"idle",touchStatus:"idle",activeStatus:"inactive"};return function(t,n){function u(){return O({type:"activeStatus",value:"active"})}function c(){return O({type:"activeStatus",value:"inactive"})}void 0===n&&(n={});var s=n,a=s.fps,f=void 0===a?30:a,d=s.enterDelay,p=void 0===d?0:d,m=s.leaveDelay,h=void 0===m?0:m,y=e.useReducer(i,{mouse:l,context:v}),w=y[0],O=y[1],g=r((function(e){var n=t&&"current"in t?t.current:t;n&&O({type:"mousemove",event:e,element:n})}),f,1),S=r((function(e){var n=t&&"current"in t?t.current:t;n&&O({type:"touchmove",event:e,element:n})}),f,1),b=r((function(){return O({type:"mouseleave"})}),f,0),x=r((function(e){var n=t&&"current"in t?t.current:t;n&&O("touches"in e?{type:"touchdown",element:n,event:e}:{type:"mousedown",element:n,event:e})}),f,1),j=r((function(){return O({type:"mouseup"})}),f,0),D=r((function(){return O({type:"touchleave"})}),f,0);return o(t,"mouseenter",g),o(t,"mousemove",g),o(t,"mouseleave",b),o(t,"mousedown",x),o("undefined"!=typeof window?window:null,"mousedown",x),o("undefined"!=typeof window?window:null,"mouseup",j),o(t,"touchstart",x),o(t,"touchmove",S),o(t,"touchend",D),o(t,"touchcancel",D),e.useEffect((function(){if("enter"===w.context.hoverStatus){if(p){var e=setTimeout(u,p);return function(){return clearTimeout(e)}}O({type:"activeStatus",value:"active"})}else{if(h){var t=setTimeout(c,h);return function(){return clearTimeout(t)}}O({type:"activeStatus",value:"inactive"})}}),[w.context.hoverStatus,p,h]),"active"===w.context.activeStatus?w.mouse:l}})); | ||
//# sourceMappingURL=use-mouse-position.js.map |
{ | ||
"name": "@react-hook/mouse-position", | ||
"version": "4.1.1", | ||
"version": "4.1.2", | ||
"homepage": "https://github.com/jaredLunde/react-hook/tree/master/packages/mouse-position#readme", | ||
@@ -132,3 +132,3 @@ "repository": "github:jaredLunde/react-hook", | ||
"dependencies": { | ||
"@react-hook/event": "^1.2.1", | ||
"@react-hook/event": "^1.2.5", | ||
"@react-hook/throttle": "^2.2.0" | ||
@@ -135,0 +135,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
135013
0.32%1535
0.2%Updated