@reactuses/core 1.0.4 → 1.0.6-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.cjs CHANGED
@@ -2326,6 +2326,42 @@ function useWindowsFocus() {
2326
2326
  return focused;
2327
2327
  }
2328
2328
 
2329
+ function useWindowSize() {
2330
+ const [windowSize, setWindowSize] = react.useState({
2331
+ width: 0,
2332
+ height: 0
2333
+ });
2334
+ const handleSize = () => {
2335
+ setWindowSize({
2336
+ width: window.innerWidth,
2337
+ height: window.innerHeight
2338
+ });
2339
+ };
2340
+ useEventListener("resize", handleSize);
2341
+ useIsomorphicLayoutEffect(() => {
2342
+ handleSize();
2343
+ }, []);
2344
+ return windowSize;
2345
+ }
2346
+
2347
+ function useWindowScroll() {
2348
+ const [state, setState] = useRafState(() => ({
2349
+ x: 0,
2350
+ y: 0
2351
+ }));
2352
+ const handleScroll = () => {
2353
+ setState({ x: window.scrollX, y: window.scrollY });
2354
+ };
2355
+ useEventListener("scroll", handleScroll, window, {
2356
+ capture: false,
2357
+ passive: true
2358
+ });
2359
+ useIsomorphicLayoutEffect(() => {
2360
+ handleScroll();
2361
+ }, []);
2362
+ return state;
2363
+ }
2364
+
2329
2365
  exports.useActiveElement = useActiveElement;
2330
2366
  exports.useCounter = useCounter;
2331
2367
  exports.useCustomCompareEffect = useCustomCompareEffect;
@@ -2394,4 +2430,6 @@ exports.useUpdate = useUpdate;
2394
2430
  exports.useUpdateEffect = useUpdateEffect;
2395
2431
  exports.useUpdateLayoutEffect = useUpdateLayoutEffect;
2396
2432
  exports.useVirtualList = useVirtualList;
2433
+ exports.useWindowScroll = useWindowScroll;
2434
+ exports.useWindowSize = useWindowSize;
2397
2435
  exports.useWindowsFocus = useWindowsFocus;
package/index.d.ts CHANGED
@@ -690,4 +690,16 @@ declare function useElementVisibility(target: BasicTarget<HTMLElement | SVGEleme
690
690
 
691
691
  declare function useWindowsFocus(): boolean;
692
692
 
693
- export { useActiveElement, useCounter, useCustomCompareEffect, useDarkMode, useDebounce, useDebounceFn, useDeepCompareEffect, useDocumentVisibility, useDraggable, useDropZone, useElementBounding, useElementSize, useElementVisibility, useEvent, useEventEmitter, useEventListener, useFavicon, useFileDialog, useFirstMountState, _default as useFps, useFullscreen, useGeolocation, useIdle, useInfiniteScroll, useIntersectionObserver, useInterval, useIsomorphicLayoutEffect, useKeyModifier, useLatest, useLocalStorage, useLongPress, useMarkdown, _default$1 as useMediaDevices, useMediaQuery, useMount, useMountedState, useMouse, useMousePressed, useMutationObserver, useNetwork, useObjectUrl, useOnline, useOrientation, usePageLeave, usePermission, usePreferredColorScheme, usePreferredContrast, usePreferredDark, usePrevious, useRafFn, useRafState, useResizeObserver, useScriptTag, useScroll, useScrollLock, useSessionStorage, useTextDirection, useThrottle, useThrottleFn, useTimeout, useTimeoutFn, useTitle, useToggle, useUnmount, useUpdate, _default$3 as useUpdateEffect, _default$2 as useUpdateLayoutEffect, useVirtualList, useWindowsFocus };
693
+ interface WindowSize {
694
+ width: number;
695
+ height: number;
696
+ }
697
+ declare function useWindowSize(): WindowSize;
698
+
699
+ interface State {
700
+ x: number;
701
+ y: number;
702
+ }
703
+ declare function useWindowScroll(): State;
704
+
705
+ export { useActiveElement, useCounter, useCustomCompareEffect, useDarkMode, useDebounce, useDebounceFn, useDeepCompareEffect, useDocumentVisibility, useDraggable, useDropZone, useElementBounding, useElementSize, useElementVisibility, useEvent, useEventEmitter, useEventListener, useFavicon, useFileDialog, useFirstMountState, _default as useFps, useFullscreen, useGeolocation, useIdle, useInfiniteScroll, useIntersectionObserver, useInterval, useIsomorphicLayoutEffect, useKeyModifier, useLatest, useLocalStorage, useLongPress, useMarkdown, _default$1 as useMediaDevices, useMediaQuery, useMount, useMountedState, useMouse, useMousePressed, useMutationObserver, useNetwork, useObjectUrl, useOnline, useOrientation, usePageLeave, usePermission, usePreferredColorScheme, usePreferredContrast, usePreferredDark, usePrevious, useRafFn, useRafState, useResizeObserver, useScriptTag, useScroll, useScrollLock, useSessionStorage, useTextDirection, useThrottle, useThrottleFn, useTimeout, useTimeoutFn, useTitle, useToggle, useUnmount, useUpdate, _default$3 as useUpdateEffect, _default$2 as useUpdateLayoutEffect, useVirtualList, useWindowScroll, useWindowSize, useWindowsFocus };
package/index.mjs CHANGED
@@ -2322,4 +2322,40 @@ function useWindowsFocus() {
2322
2322
  return focused;
2323
2323
  }
2324
2324
 
2325
- export { useActiveElement, useCounter, useCustomCompareEffect, useDarkMode, useDebounce, useDebounceFn, useDeepCompareEffect, useDocumentVisibility, useDraggable, useDropZone, useElementBounding, useElementSize, useElementVisibility, useEvent, useEventEmitter, useEventListener, useFavicon, useFileDialog, useFirstMountState, useFps$1 as useFps, useFullscreen, useGeolocation, useIdle, useInfiniteScroll, useIntersectionObserver, useInterval, useIsomorphicLayoutEffect, useKeyModifier, useLatest, useLocalStorage, useLongPress, useMarkdown, useMediaDevices$1 as useMediaDevices, useMediaQuery, useMount, useMountedState, useMouse, useMousePressed, useMutationObserver, useNetwork, useObjectUrl, useOnline, useOrientation, usePageLeave, usePermission, usePreferredColorScheme, usePreferredContrast, usePreferredDark, usePrevious, useRafFn, useRafState, useResizeObserver, useScriptTag, useScroll, useScrollLock, useSessionStorage, useTextDirection, useThrottle, useThrottleFn, useTimeout, useTimeoutFn, useTitle, useToggle, useUnmount, useUpdate, useUpdateEffect, useUpdateLayoutEffect, useVirtualList, useWindowsFocus };
2325
+ function useWindowSize() {
2326
+ const [windowSize, setWindowSize] = useState({
2327
+ width: 0,
2328
+ height: 0
2329
+ });
2330
+ const handleSize = () => {
2331
+ setWindowSize({
2332
+ width: window.innerWidth,
2333
+ height: window.innerHeight
2334
+ });
2335
+ };
2336
+ useEventListener("resize", handleSize);
2337
+ useIsomorphicLayoutEffect(() => {
2338
+ handleSize();
2339
+ }, []);
2340
+ return windowSize;
2341
+ }
2342
+
2343
+ function useWindowScroll() {
2344
+ const [state, setState] = useRafState(() => ({
2345
+ x: 0,
2346
+ y: 0
2347
+ }));
2348
+ const handleScroll = () => {
2349
+ setState({ x: window.scrollX, y: window.scrollY });
2350
+ };
2351
+ useEventListener("scroll", handleScroll, window, {
2352
+ capture: false,
2353
+ passive: true
2354
+ });
2355
+ useIsomorphicLayoutEffect(() => {
2356
+ handleScroll();
2357
+ }, []);
2358
+ return state;
2359
+ }
2360
+
2361
+ export { useActiveElement, useCounter, useCustomCompareEffect, useDarkMode, useDebounce, useDebounceFn, useDeepCompareEffect, useDocumentVisibility, useDraggable, useDropZone, useElementBounding, useElementSize, useElementVisibility, useEvent, useEventEmitter, useEventListener, useFavicon, useFileDialog, useFirstMountState, useFps$1 as useFps, useFullscreen, useGeolocation, useIdle, useInfiniteScroll, useIntersectionObserver, useInterval, useIsomorphicLayoutEffect, useKeyModifier, useLatest, useLocalStorage, useLongPress, useMarkdown, useMediaDevices$1 as useMediaDevices, useMediaQuery, useMount, useMountedState, useMouse, useMousePressed, useMutationObserver, useNetwork, useObjectUrl, useOnline, useOrientation, usePageLeave, usePermission, usePreferredColorScheme, usePreferredContrast, usePreferredDark, usePrevious, useRafFn, useRafState, useResizeObserver, useScriptTag, useScroll, useScrollLock, useSessionStorage, useTextDirection, useThrottle, useThrottleFn, useTimeout, useTimeoutFn, useTitle, useToggle, useUnmount, useUpdate, useUpdateEffect, useUpdateLayoutEffect, useVirtualList, useWindowScroll, useWindowSize, useWindowsFocus };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reactuses/core",
3
- "version": "1.0.4",
3
+ "version": "1.0.6-beta.1",
4
4
  "main": "./index.cjs",
5
5
  "module": "./index.mjs",
6
6
  "types": "./index.d.ts",