@react-hook/window-size
Advanced tools
Comparing version 3.1.0 to 3.1.1
"use strict"; | ||
exports.__esModule = true; | ||
exports.useWindowWidth = exports.useWindowHeight = exports.useWindowSize = void 0; | ||
exports.useWindowWidth = exports.useWindowSize = exports.useWindowHeight = void 0; | ||
@@ -14,2 +14,3 @@ var _debounce = /*#__PURE__*/require("@react-hook/debounce"); | ||
const win = typeof window === 'undefined' ? null : window; | ||
const wv = win && typeof win.visualViewport !== 'undefined' ? win.visualViewport : null; | ||
@@ -31,3 +32,5 @@ const getSize = () => [document.documentElement.clientWidth, document.documentElement.clientHeight]; | ||
(0, _event.default)(win, 'resize', setSize); | ||
(0, _event.default)(win, 'resize', setSize); // @ts-expect-error | ||
(0, _event.default)(wv, 'resize', setSize); | ||
(0, _event.default)(win, 'orientationchange', setSize); | ||
@@ -34,0 +37,0 @@ return size; |
@@ -5,6 +5,11 @@ import { useDebounce } from '@react-hook/debounce'; | ||
const win = typeof window === 'undefined' ? null : window; | ||
const wv = win && typeof win.visualViewport !== 'undefined' ? win.visualViewport : null; | ||
const getSize = () => [document.documentElement.clientWidth, document.documentElement.clientHeight]; | ||
export const useWindowSize = (options = emptyObj) => { | ||
export const useWindowSize = function (options) { | ||
if (options === void 0) { | ||
options = emptyObj; | ||
} | ||
const { | ||
@@ -22,3 +27,5 @@ wait, | ||
useEvent(win, 'resize', setSize); | ||
useEvent(win, 'resize', setSize); // @ts-expect-error | ||
useEvent(wv, 'resize', setSize); | ||
useEvent(win, 'orientationchange', setSize); | ||
@@ -25,0 +32,0 @@ return size; |
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'react'], factory) : | ||
(global = global || self, factory(global.UseWindowSize = {}, global.React)); | ||
}(this, (function (exports, React) { 'use strict'; | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.UseWindowSize = {}, global.React)); | ||
})(this, (function (exports, React) { 'use strict'; | ||
function _interopNamespace(e) { | ||
if (e && e.__esModule) return e; | ||
var n = Object.create(null); | ||
if (e) { | ||
Object.keys(e).forEach(function (k) { | ||
if (k !== 'default') { | ||
var d = Object.getOwnPropertyDescriptor(e, k); | ||
Object.defineProperty(n, k, d.get ? d : { | ||
enumerable: true, | ||
get: function () { return e[k]; } | ||
}); | ||
} | ||
}); | ||
} | ||
n["default"] = e; | ||
return Object.freeze(n); | ||
} | ||
var React__namespace = /*#__PURE__*/_interopNamespace(React); | ||
var useLatest = function useLatest(current) { | ||
var storedValue = React.useRef(current); | ||
storedValue.current = current; | ||
var storedValue = React__namespace.useRef(current); | ||
React__namespace.useEffect(function () { | ||
storedValue.current = current; | ||
}); | ||
return storedValue; | ||
@@ -23,3 +45,3 @@ }; | ||
var storedCallback = useLatest(callback); | ||
var timeout = React.useRef(); | ||
var timeout = React__namespace.useRef(); | ||
var deps = [wait, leading, storedCallback]; // Cleans up pending timeouts when the deps change | ||
@@ -32,3 +54,3 @@ | ||
React.useEffect(function () { | ||
React__namespace.useEffect(function () { | ||
return _ref; | ||
@@ -41,3 +63,3 @@ }, deps); | ||
return React.useCallback(function () { | ||
return React__namespace.useCallback(function () { | ||
// eslint-disable-next-line prefer-rest-params | ||
@@ -63,42 +85,41 @@ var args = arguments; | ||
var useDebounce = function useDebounce(initialState, wait, leading) { | ||
var state = React.useState(initialState); | ||
var state = React__namespace.useState(initialState); | ||
return [state[0], useDebounceCallback(state[1], wait, leading)]; | ||
}; | ||
var usePassiveLayoutEffect = React[typeof document !== 'undefined' && document.createElement !== void 0 ? 'useLayoutEffect' : 'useEffect']; | ||
function useEvent(target, type, listener, cleanup) { | ||
if (cleanup === void 0) { | ||
cleanup = noop; | ||
} | ||
var storedListener = React__namespace.useRef(listener); | ||
var storedCleanup = React__namespace.useRef(cleanup); | ||
React__namespace.useEffect(function () { | ||
storedListener.current = listener; | ||
storedCleanup.current = cleanup; | ||
}); | ||
React__namespace.useEffect(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.apply(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 | ||
} | ||
function noop() {} | ||
var emptyObj = {}; | ||
var win = typeof window === 'undefined' ? null : window; | ||
var wv = win && typeof win.visualViewport !== 'undefined' ? win.visualViewport : null; | ||
@@ -132,3 +153,5 @@ var getSize = function getSize() { | ||
useEvent(win, 'resize', setSize); | ||
useEvent(win, 'resize', setSize); // @ts-expect-error | ||
useEvent(wv, 'resize', setSize); | ||
useEvent(win, 'orientationchange', setSize); | ||
@@ -150,3 +173,3 @@ return size; | ||
}))); | ||
})); | ||
//# sourceMappingURL=use-window-size.dev.js.map |
@@ -1,2 +0,2 @@ | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],n):n((e=e||self).UseWindowSize={},e.React)}(this,(function(e,n){"use strict";function t(e,n,t,i){function c(){for(var e=arguments.length,n=new Array(e),t=0;e>t;t++)n[t]=arguments[t];f.current.apply(this,n)}void 0===i&&(i=r);var f=u(t),d=u(i);o((function(){var t=e&&"current"in e?e.current:e;if(t){var r=c;t.addEventListener(n,r);var u=d.current;return function(){t.removeEventListener(n,r),u()}}}),[e,n])}function r(){}var u=function(e){var t=n.useRef(e);return t.current=e,t},i=function(e,t,r){function i(){f.current&&clearTimeout(f.current),f.current=void 0}function o(){f.current=void 0}void 0===t&&(t=100),void 0===r&&(r=0);var c=u(e),f=n.useRef(),d=[t,r,c];return n.useEffect((function(){return i}),d),n.useCallback((function(){var e=arguments,n=f.current;if(void 0===n&&r)return f.current=setTimeout(o,t),c.current.apply(null,e);n&&clearTimeout(n),f.current=setTimeout((function(){f.current=void 0,c.current.apply(null,e)}),t)}),d)},o=n["undefined"!=typeof document&&void 0!==document.createElement?"useLayoutEffect":"useEffect"],c={},f="undefined"==typeof window?null:window,d=function(){return[document.documentElement.clientWidth,document.documentElement.clientHeight]},a=function(e){void 0===e&&(e=c);var r=e,u=r.wait,o=r.leading,a=r.initialWidth,l=void 0===a?0:a,v=r.initialHeight,s=function(e,t,r){var u=n.useState(e);return[u[0],i(u[1],t,r)]}("undefined"==typeof document?[l,void 0===v?0:v]:d,u,o),m=s[0],p=s[1],y=function(){return p(d)};return t(f,"resize",y),t(f,"orientationchange",y),m};e.useWindowHeight=function(e){return a(e)[1]},e.useWindowSize=a,e.useWindowWidth=function(e){return a(e)[0]},Object.defineProperty(e,"__esModule",{value:1})})); | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).UseWindowSize={},e.React)}(this,(function(e,n){"use strict";function t(e){if(e&&e.__esModule)return e;var n=Object.create(null);return e&&Object.keys(e).forEach((function(t){if("default"!==t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:1,get:function(){return e[t]}})}})),n.default=e,Object.freeze(n)}function r(e,n,t,r){var i=u.useRef(t),o=u.useRef(r);u.useEffect((function(){i.current=t,o.current=r})),u.useEffect((function(){function t(){if(!u){for(var e=arguments.length,n=new Array(e),t=0;e>t;t++)n[t]=arguments[t];i.current.apply(this,n)}}var r=e&&"current"in e?e.current:e;if(r){var u=0;r.addEventListener(n,t);var c=o.current;return function(){u=1,r.removeEventListener(n,t),c&&c()}}}),[e,n])}var u=t(n),i=function(e,n,t){function r(){d.current&&clearTimeout(d.current),d.current=void 0}function i(){d.current=void 0}void 0===n&&(n=100),void 0===t&&(t=0);var o,c,f=(o=e,c=u.useRef(o),u.useEffect((function(){c.current=o})),c),d=u.useRef(),a=[n,t,f];return u.useEffect((function(){return r}),a),u.useCallback((function(){var e=arguments,r=d.current;if(void 0===r&&t)return d.current=setTimeout(i,n),f.current.apply(null,e);r&&clearTimeout(r),d.current=setTimeout((function(){d.current=void 0,f.current.apply(null,e)}),n)}),a)},o={},c="undefined"==typeof window?null:window,f=c&&void 0!==c.visualViewport?c.visualViewport:null,d=function(){return[document.documentElement.clientWidth,document.documentElement.clientHeight]},a=function(e){void 0===e&&(e=o);var n=e,t=n.wait,a=n.leading,l=n.initialWidth,s=void 0===l?0:l,v=n.initialHeight,p=function(e,n,t){var r=u.useState(e);return[r[0],i(r[1],n,t)]}("undefined"==typeof document?[s,void 0===v?0:v]:d,t,a),m=p[0],y=p[1],h=function(){return y(d)};return r(c,"resize",h),r(f,"resize",h),r(c,"orientationchange",h),m};e.useWindowHeight=function(e){return a(e)[1]},e.useWindowSize=a,e.useWindowWidth=function(e){return a(e)[0]},Object.defineProperty(e,"__esModule",{value:1})})); | ||
//# sourceMappingURL=use-window-size.js.map |
{ | ||
"name": "@react-hook/window-size", | ||
"version": "3.1.0", | ||
"version": "3.1.1", | ||
"homepage": "https://github.com/jaredLunde/react-hook/tree/master/packages/window-size#readme", | ||
@@ -124,2 +124,3 @@ "repository": "github:jaredLunde/react-hook", | ||
"test", | ||
"*.d.ts", | ||
"*.config.js" | ||
@@ -159,16 +160,16 @@ ], | ||
"@types/jest": "latest", | ||
"@types/react": "latest", | ||
"@types/react-dom": "latest", | ||
"@types/react": "^18.0.18", | ||
"@types/react-dom": "^18.0.6", | ||
"babel-jest": "latest", | ||
"eslint": "latest", | ||
"eslint-config-lunde": "latest", | ||
"eslint": "^7.32.0", | ||
"eslint-config-lunde": "^0.7.1", | ||
"husky": "latest", | ||
"jest": "latest", | ||
"lint-staged": "latest", | ||
"lundle": "^0.4.9", | ||
"lundle": "^0.4.14", | ||
"prettier": "^2.7.1", | ||
"react": "latest", | ||
"react-dom": "latest", | ||
"react-test-renderer": "latest", | ||
"typescript": "^3.9.5" | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0", | ||
"react-test-renderer": "^18.2.0", | ||
"typescript": "^4.7.0" | ||
}, | ||
@@ -182,3 +183,7 @@ "dependencies": { | ||
"react": ">=16.8" | ||
}, | ||
"resolutions": { | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0" | ||
} | ||
} |
@@ -0,1 +1,2 @@ | ||
/* eslint-disable jest/valid-title */ | ||
import {renderHook, act} from '@testing-library/react-hooks' | ||
@@ -2,0 +3,0 @@ // @ts-ignore |
"use strict"; | ||
exports.__esModule = true; | ||
exports.useWindowWidth = exports.useWindowHeight = exports.useWindowSize = void 0; | ||
exports.useWindowWidth = exports.useWindowSize = exports.useWindowHeight = void 0; | ||
@@ -15,2 +15,3 @@ var _throttle = /*#__PURE__*/require("@react-hook/throttle"); | ||
const win = typeof window === 'undefined' ? null : window; | ||
const wv = win && typeof win.visualViewport !== 'undefined' ? win.visualViewport : null; | ||
@@ -32,3 +33,5 @@ const getSize = () => [document.documentElement.clientWidth, document.documentElement.clientHeight]; | ||
(0, _event.default)(win, 'resize', setSize); | ||
(0, _event.default)(win, 'resize', setSize); // @ts-expect-error | ||
(0, _event.default)(wv, 'resize', setSize); | ||
(0, _event.default)(win, 'orientationchange', setSize); | ||
@@ -35,0 +38,0 @@ return size; |
@@ -6,6 +6,11 @@ /* eslint-disable import/no-extraneous-dependencies */ | ||
const win = typeof window === 'undefined' ? null : window; | ||
const wv = win && typeof win.visualViewport !== 'undefined' ? win.visualViewport : null; | ||
const getSize = () => [document.documentElement.clientWidth, document.documentElement.clientHeight]; | ||
export const useWindowSize = (options = emptyObj) => { | ||
export const useWindowSize = function (options) { | ||
if (options === void 0) { | ||
options = emptyObj; | ||
} | ||
const { | ||
@@ -23,3 +28,5 @@ fps, | ||
useEvent(win, 'resize', setSize); | ||
useEvent(win, 'resize', setSize); // @ts-expect-error | ||
useEvent(wv, 'resize', setSize); | ||
useEvent(win, 'orientationchange', setSize); | ||
@@ -26,0 +33,0 @@ return size; |
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'react'], factory) : | ||
(global = global || self, factory(global.UseWindowSize = {}, global.React)); | ||
}(this, (function (exports, React) { 'use strict'; | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.UseWindowSize = {}, global.React)); | ||
})(this, (function (exports, React) { 'use strict'; | ||
function _interopNamespace(e) { | ||
if (e && e.__esModule) return e; | ||
var n = Object.create(null); | ||
if (e) { | ||
Object.keys(e).forEach(function (k) { | ||
if (k !== 'default') { | ||
var d = Object.getOwnPropertyDescriptor(e, k); | ||
Object.defineProperty(n, k, d.get ? d : { | ||
enumerable: true, | ||
get: function () { return e[k]; } | ||
}); | ||
} | ||
}); | ||
} | ||
n["default"] = e; | ||
return Object.freeze(n); | ||
} | ||
var React__namespace = /*#__PURE__*/_interopNamespace(React); | ||
var useLatest = function useLatest(current) { | ||
var storedValue = React.useRef(current); | ||
storedValue.current = current; | ||
var storedValue = React__namespace.useRef(current); | ||
React__namespace.useEffect(function () { | ||
storedValue.current = current; | ||
}); | ||
return storedValue; | ||
@@ -30,4 +52,4 @@ }; | ||
var ms = 1000 / fps; | ||
var prev = React.useRef(0); | ||
var trailingTimeout = React.useRef(); | ||
var prev = React__namespace.useRef(0); | ||
var trailingTimeout = React__namespace.useRef(); | ||
@@ -45,6 +67,6 @@ var clearTrailing = function clearTrailing() { | ||
React.useEffect(function () { | ||
React__namespace.useEffect(function () { | ||
return _ref; | ||
}, deps); | ||
return React.useCallback(function () { | ||
return React__namespace.useCallback(function () { | ||
// eslint-disable-next-line prefer-rest-params | ||
@@ -78,43 +100,42 @@ var args = arguments; | ||
function useThrottle(initialState, fps, leading) { | ||
var state = React.useState(initialState); | ||
var state = React__namespace.useState(initialState); | ||
return [state[0], useThrottleCallback(state[1], fps, leading)]; | ||
} | ||
var usePassiveLayoutEffect = React[typeof document !== 'undefined' && document.createElement !== void 0 ? 'useLayoutEffect' : 'useEffect']; | ||
function useEvent(target, type, listener, cleanup) { | ||
if (cleanup === void 0) { | ||
cleanup = noop; | ||
} | ||
var storedListener = React__namespace.useRef(listener); | ||
var storedCleanup = React__namespace.useRef(cleanup); | ||
React__namespace.useEffect(function () { | ||
storedListener.current = listener; | ||
storedCleanup.current = cleanup; | ||
}); | ||
React__namespace.useEffect(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.apply(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 | ||
} | ||
function noop() {} | ||
/* eslint-disable import/no-extraneous-dependencies */ | ||
var emptyObj = {}; | ||
var win = typeof window === 'undefined' ? null : window; | ||
var wv = win && typeof win.visualViewport !== 'undefined' ? win.visualViewport : null; | ||
@@ -148,3 +169,5 @@ var getSize = function getSize() { | ||
useEvent(win, 'resize', setSize); | ||
useEvent(win, 'resize', setSize); // @ts-expect-error | ||
useEvent(wv, 'resize', setSize); | ||
useEvent(win, 'orientationchange', setSize); | ||
@@ -166,3 +189,3 @@ return size; | ||
}))); | ||
})); | ||
//# sourceMappingURL=use-window-size.dev.js.map |
@@ -1,2 +0,2 @@ | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],n):n((e=e||self).UseWindowSize={},e.React)}(this,(function(e,n){"use strict";function t(e,t,r){function u(){d.current=0,s()}void 0===t&&(t=30),void 0===r&&(r=0);var o=i(e),f=1e3/t,d=n.useRef(0),a=n.useRef(),s=function(){return a.current&&clearTimeout(a.current)},l=[t,r,o];return n.useEffect((function(){return u}),l),n.useCallback((function(){var e=arguments,n=c(),t=function(){d.current=n,s(),o.current.apply(null,e)},u=d.current;if(r&&0===u)return t();if(n-u>f){if(u>0)return t();d.current=n}s(),a.current=setTimeout((function(){t(),d.current=0}),f)}),l)}function r(e,n,t,r){function o(){for(var e=arguments.length,n=new Array(e),t=0;e>t;t++)n[t]=arguments[t];c.current.apply(this,n)}void 0===r&&(r=u);var c=i(t),d=i(r);f((function(){var t=e&&"current"in e?e.current:e;if(t){var r=o;t.addEventListener(n,r);var u=d.current;return function(){t.removeEventListener(n,r),u()}}}),[e,n])}function u(){}var i=function(e){var t=n.useRef(e);return t.current=e,t},o="undefined"!=typeof performance?performance:Date,c=function(){return o.now()},f=n["undefined"!=typeof document&&void 0!==document.createElement?"useLayoutEffect":"useEffect"],d={},a="undefined"==typeof window?null:window,s=function(){return[document.documentElement.clientWidth,document.documentElement.clientHeight]},l=function(e){void 0===e&&(e=d);var u=e,i=u.fps,o=u.leading,c=u.initialWidth,f=void 0===c?0:c,l=u.initialHeight,v=function(e,r,u){var i=n.useState(e);return[i[0],t(i[1],r,u)]}("undefined"==typeof document?[f,void 0===l?0:l]:s,i,o),p=v[0],m=v[1],y=function(){return m(s)};return r(a,"resize",y),r(a,"orientationchange",y),p};e.useWindowHeight=function(e){return l(e)[1]},e.useWindowSize=l,e.useWindowWidth=function(e){return l(e)[0]},Object.defineProperty(e,"__esModule",{value:1})})); | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).UseWindowSize={},e.React)}(this,(function(e,n){"use strict";function t(e){if(e&&e.__esModule)return e;var n=Object.create(null);return e&&Object.keys(e).forEach((function(t){if("default"!==t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:1,get:function(){return e[t]}})}})),n.default=e,Object.freeze(n)}function r(e,n,t){function r(){a.current=0,l()}void 0===n&&(n=30),void 0===t&&(t=0);var u,o,f=(u=e,o=i.useRef(u),i.useEffect((function(){o.current=u})),o),d=1e3/n,a=i.useRef(0),s=i.useRef(),l=function(){return s.current&&clearTimeout(s.current)},v=[n,t,f];return i.useEffect((function(){return r}),v),i.useCallback((function(){var e=arguments,n=c(),r=function(){a.current=n,l(),f.current.apply(null,e)},u=a.current;if(t&&0===u)return r();if(n-u>d){if(u>0)return r();a.current=n}l(),s.current=setTimeout((function(){r(),a.current=0}),d)}),v)}function u(e,n,t,r){var u=i.useRef(t),o=i.useRef(r);i.useEffect((function(){u.current=t,o.current=r})),i.useEffect((function(){function t(){if(!i){for(var e=arguments.length,n=new Array(e),t=0;e>t;t++)n[t]=arguments[t];u.current.apply(this,n)}}var r=e&&"current"in e?e.current:e;if(r){var i=0;r.addEventListener(n,t);var c=o.current;return function(){i=1,r.removeEventListener(n,t),c&&c()}}}),[e,n])}var i=t(n),o="undefined"!=typeof performance?performance:Date,c=function(){return o.now()},f={},d="undefined"==typeof window?null:window,a=d&&void 0!==d.visualViewport?d.visualViewport:null,s=function(){return[document.documentElement.clientWidth,document.documentElement.clientHeight]},l=function(e){void 0===e&&(e=f);var n=e,t=n.fps,o=n.leading,c=n.initialWidth,l=void 0===c?0:c,v=n.initialHeight,p=function(e,n,t){var u=i.useState(e);return[u[0],r(u[1],n,t)]}("undefined"==typeof document?[l,void 0===v?0:v]:s,t,o),m=p[0],y=p[1],h=function(){return y(s)};return u(d,"resize",h),u(a,"resize",h),u(d,"orientationchange",h),m};e.useWindowHeight=function(e){return l(e)[1]},e.useWindowSize=l,e.useWindowWidth=function(e){return l(e)[0]},Object.defineProperty(e,"__esModule",{value:1})})); | ||
//# sourceMappingURL=use-window-size.js.map |
@@ -0,1 +1,2 @@ | ||
/* eslint-disable jest/valid-title */ | ||
import {renderHook, act} from '@testing-library/react-hooks' | ||
@@ -26,4 +27,4 @@ import {resetSize, resizeTo, changeOrientation} from 'test-utils' | ||
.mockImplementation(() => ts) | ||
// @ts-ignore | ||
global.performance = { | ||
//@ts-expect-error | ||
now: perfNowStub, | ||
@@ -116,3 +117,5 @@ } | ||
act(() => changeOrientation(1280, 720)) | ||
act(() => jest.advanceTimersByTime(1000 / 30)) | ||
act(() => { | ||
jest.advanceTimersByTime(1000 / 30) | ||
}) | ||
@@ -131,3 +134,5 @@ expect(result.current[0]).toBe(1280) | ||
act(() => resizeTo(1280, 720)) | ||
act(() => jest.advanceTimersByTime(1000 / 30)) | ||
act(() => { | ||
jest.advanceTimersByTime(1000 / 30) | ||
}) | ||
expect(result.current).toBe(1280) | ||
@@ -144,5 +149,7 @@ }) | ||
act(() => resizeTo(1280, 720)) | ||
act(() => jest.advanceTimersByTime(1000 / 30)) | ||
act(() => { | ||
jest.advanceTimersByTime(1000 / 30) | ||
}) | ||
expect(result.current).toBe(720) | ||
}) | ||
}) |
@@ -11,10 +11,6 @@ export interface ThrottledWindowSizeOptions { | ||
export declare const useWindowHeight: ( | ||
options?: | ||
| Pick<ThrottledWindowSizeOptions, 'initialHeight' | 'fps' | 'leading'> | ||
| undefined | ||
options?: Omit<ThrottledWindowSizeOptions, 'initialWidth'> | ||
) => number | ||
export declare const useWindowWidth: ( | ||
options?: | ||
| Pick<ThrottledWindowSizeOptions, 'initialWidth' | 'fps' | 'leading'> | ||
| undefined | ||
options?: Omit<ThrottledWindowSizeOptions, 'initialHeight'> | ||
) => number |
@@ -11,10 +11,6 @@ export interface DebouncedWindowSizeOptions { | ||
export declare const useWindowHeight: ( | ||
options?: | ||
| Pick<DebouncedWindowSizeOptions, 'wait' | 'initialHeight' | 'leading'> | ||
| undefined | ||
options?: Omit<DebouncedWindowSizeOptions, 'initialWidth'> | ||
) => number | ||
export declare const useWindowWidth: ( | ||
options?: | ||
| Pick<DebouncedWindowSizeOptions, 'wait' | 'initialWidth' | 'leading'> | ||
| undefined | ||
options?: Omit<DebouncedWindowSizeOptions, 'initialHeight'> | ||
) => number |
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 not supported yet
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 not supported yet
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 not supported yet
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 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
103650
823