@reactuses/core 1.0.2 → 1.0.3

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.mjs CHANGED
@@ -2219,4 +2219,79 @@ function useDraggable(target, options = {}) {
2219
2219
  return [position.x, position.y, !!pressedDelta];
2220
2220
  }
2221
2221
 
2222
- export { useActiveElement, useCounter, useCustomCompareEffect, useDarkMode, useDebounce, useDebounceFn, useDeepCompareEffect, useDocumentVisibility, useDraggable, useDropZone, useElementSize, 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 };
2222
+ function useElementBounding(target, options = {}) {
2223
+ const {
2224
+ reset = true,
2225
+ windowResize = true,
2226
+ windowScroll = true,
2227
+ immediate = true
2228
+ } = options;
2229
+ const [height, setHeight] = useState(0);
2230
+ const [bottom, setBottom] = useState(0);
2231
+ const [left, setLeft] = useState(0);
2232
+ const [right, setRight] = useState(0);
2233
+ const [top, setTop] = useState(0);
2234
+ const [width, setWidth] = useState(0);
2235
+ const [x, setX] = useState(0);
2236
+ const [y, setY] = useState(0);
2237
+ const update = useEvent(() => {
2238
+ const element = getTargetElement(target);
2239
+ if (!element) {
2240
+ if (reset) {
2241
+ setHeight(0);
2242
+ setBottom(0);
2243
+ setLeft(0);
2244
+ setRight(0);
2245
+ setTop(0);
2246
+ setWidth(0);
2247
+ setX(0);
2248
+ setY(0);
2249
+ }
2250
+ return;
2251
+ }
2252
+ const rect = element.getBoundingClientRect();
2253
+ setHeight(rect.height);
2254
+ setBottom(rect.bottom);
2255
+ setLeft(rect.left);
2256
+ setRight(rect.right);
2257
+ setTop(rect.top);
2258
+ setWidth(rect.width);
2259
+ setX(rect.x);
2260
+ setY(rect.y);
2261
+ });
2262
+ useResizeObserver(target, update);
2263
+ useEffect(() => {
2264
+ if (immediate) {
2265
+ update();
2266
+ }
2267
+ }, [immediate, update]);
2268
+ useEffect(() => {
2269
+ if (windowScroll) {
2270
+ window.addEventListener("scroll", update, { passive: true });
2271
+ }
2272
+ if (windowResize) {
2273
+ window.addEventListener("resize", update, { passive: true });
2274
+ }
2275
+ return () => {
2276
+ if (windowScroll) {
2277
+ window.removeEventListener("scroll", update);
2278
+ }
2279
+ if (windowResize) {
2280
+ window.removeEventListener("resize", update);
2281
+ }
2282
+ };
2283
+ }, [update, windowResize, windowScroll]);
2284
+ return {
2285
+ height,
2286
+ bottom,
2287
+ left,
2288
+ right,
2289
+ top,
2290
+ width,
2291
+ x,
2292
+ y,
2293
+ update
2294
+ };
2295
+ }
2296
+
2297
+ export { useActiveElement, useCounter, useCustomCompareEffect, useDarkMode, useDebounce, useDebounceFn, useDeepCompareEffect, useDocumentVisibility, useDraggable, useDropZone, useElementBounding, useElementSize, 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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reactuses/core",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "main": "./index.cjs",
5
5
  "module": "./index.mjs",
6
6
  "types": "./index.d.ts",