🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

react-use-rect

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-use-rect - npm Package Compare versions

Comparing version

to
0.1.0-alpha.5

2

dist/index.d.ts

@@ -15,2 +15,2 @@ export interface Rect {

}
export declare function useRect({ scroll, transitionEnd }: Options): [(targetElement: Element | null) => void, Rect];
export declare function useRect({ scroll, transitionEnd }?: Options): [(targetElement: Element | null) => void, Rect];

@@ -85,7 +85,9 @@ 'use strict';

function useRect(_ref) {
var _ref$scroll = _ref.scroll,
function useRect(_temp) {
var _ref = _temp === void 0 ? {} : _temp,
_ref$scroll = _ref.scroll,
scroll = _ref$scroll === void 0 ? true : _ref$scroll,
_ref$transitionEnd = _ref.transitionEnd,
transitionEnd = _ref$transitionEnd === void 0 ? true : _ref$transitionEnd;
var resizeObserverRef = react.useRef();

@@ -92,0 +94,0 @@ var targetElementRef = react.useRef();

@@ -1,2 +0,2 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@juggle/resize-observer"),t=require("react");function r(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}var n={bottom:0,height:0,left:0,right:0,top:0,width:0,x:0,y:0},o=["bottom","height","left","right","top","width","x","y"],i="undefined"==typeof window?t.useEffect:t.useLayoutEffect;exports.useRect=function(u){var c=u.scroll,a=void 0===c||c,s=u.transitionEnd,l=void 0===s||s,d=t.useRef(),f=t.useRef(),v=t.useRef(n),b=function(){var e=t.useState({})[1];return t.useCallback((function(){return e({})}),[])}(),h=t.useCallback((function(){if(f.current){var e=f.current.getBoundingClientRect(),t={bottom:e.bottom,height:e.height,left:e.left,right:e.right,top:e.top,width:e.width,x:e.x,y:e.y};(function(e,t){for(var n,i=function(e,t){var n;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return r(e,void 0);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?r(e,void 0):void 0}}(e))){n&&(e=n);var o=0;return function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(n=e[Symbol.iterator]()).next.bind(n)}(o);!(n=i()).done;){var u=n.value;if(e[u]!==t[u])return!0}return!1})(v.current,t)&&(v.current=t,b())}else v.current!==n&&(v.current=n,b())}),[b]),y=t.useCallback((function(t){f.current=null!=t?t:void 0,d.current&&(d.current.disconnect(),d.current=void 0),f.current&&(d.current=new e.ResizeObserver(h),d.current.observe(f.current))}),[h]);return i((function(){var e=function(){return h()},t={capture:!0,passive:!0};return a&&window.addEventListener("scroll",e,t),l&&window.addEventListener("transitionend",e,t),function(){a&&window.removeEventListener("scroll",e,t),l&&window.removeEventListener("transitionend",e,t)}}),[a,l,h]),i(h),[y,v.current]};
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@juggle/resize-observer"),t=require("react");function r(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}var n={bottom:0,height:0,left:0,right:0,top:0,width:0,x:0,y:0},o=["bottom","height","left","right","top","width","x","y"],i="undefined"==typeof window?t.useEffect:t.useLayoutEffect;exports.useRect=function(u){var c=void 0===u?{}:u,a=c.scroll,s=void 0===a||a,l=c.transitionEnd,d=void 0===l||l,f=t.useRef(),v=t.useRef(),b=t.useRef(n),h=function(){var e=t.useState({})[1];return t.useCallback((function(){return e({})}),[])}(),y=t.useCallback((function(){if(v.current){var e=v.current.getBoundingClientRect(),t={bottom:e.bottom,height:e.height,left:e.left,right:e.right,top:e.top,width:e.width,x:e.x,y:e.y};(function(e,t){for(var n,i=function(e,t){var n;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return r(e,void 0);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?r(e,void 0):void 0}}(e))){n&&(e=n);var o=0;return function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(n=e[Symbol.iterator]()).next.bind(n)}(o);!(n=i()).done;){var u=n.value;if(e[u]!==t[u])return!0}return!1})(b.current,t)&&(b.current=t,h())}else b.current!==n&&(b.current=n,h())}),[h]),g=t.useCallback((function(t){v.current=null!=t?t:void 0,f.current&&(f.current.disconnect(),f.current=void 0),v.current&&(f.current=new e.ResizeObserver(y),f.current.observe(v.current))}),[y]);return i((function(){var e=function(){return y()},t={capture:!0,passive:!0};return s&&window.addEventListener("scroll",e,t),d&&window.addEventListener("transitionend",e,t),function(){s&&window.removeEventListener("scroll",e,t),d&&window.removeEventListener("transitionend",e,t)}}),[s,d,y]),i(y),[g,b.current]};
//# sourceMappingURL=react-use-rect.cjs.production.min.js.map

@@ -81,7 +81,9 @@ import { ResizeObserver } from '@juggle/resize-observer';

function useRect(_ref) {
var _ref$scroll = _ref.scroll,
function useRect(_temp) {
var _ref = _temp === void 0 ? {} : _temp,
_ref$scroll = _ref.scroll,
scroll = _ref$scroll === void 0 ? true : _ref$scroll,
_ref$transitionEnd = _ref.transitionEnd,
transitionEnd = _ref$transitionEnd === void 0 ? true : _ref$transitionEnd;
var resizeObserverRef = useRef();

@@ -88,0 +90,0 @@ var targetElementRef = useRef();

{
"name": "react-use-rect",
"version": "0.1.0-alpha.4",
"version": "0.1.0-alpha.5",
"description": "React hook that measures target element boundaries",

@@ -5,0 +5,0 @@ "license": "MIT",

@@ -66,3 +66,3 @@ import { ResizeObserver } from '@juggle/resize-observer';

export function useRect({ scroll = true, transitionEnd = true }: Options) {
export function useRect({ scroll = true, transitionEnd = true }: Options = {}) {
const resizeObserverRef = useRef<ResizeObserver>();

@@ -69,0 +69,0 @@ const targetElementRef = useRef<Element>();

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