@react-hook/resize-observer
Advanced tools
Comparing version 1.1.0 to 1.1.1
@@ -21,3 +21,3 @@ "use strict"; | ||
*/ | ||
const useResizeObserver = (target, callback) => { | ||
function useResizeObserver(target, callback) { | ||
const resizeObserver = getResizeObserver(); | ||
@@ -27,20 +27,11 @@ const storedCallback = (0, _latest.default)(callback); | ||
let didUnsubscribe = false; | ||
const callback = (entries, observer) => { | ||
const targetEl = target && 'current' in target ? target.current : target; | ||
if (!targetEl) return; | ||
resizeObserver.subscribe(targetEl, (entry, observer) => { | ||
if (didUnsubscribe) return; | ||
const targetEl = target && 'current' in target ? target.current : target; | ||
for (let i = 0; i < entries.length; i++) { | ||
const entry = entries[i]; | ||
if (entry.target === targetEl) { | ||
storedCallback.current(entry, observer); | ||
} | ||
} | ||
}; | ||
resizeObserver.subscribe(callback); | ||
storedCallback.current(entry, observer); | ||
}); | ||
return () => { | ||
didUnsubscribe = true; | ||
resizeObserver.unsubscribe(callback); | ||
resizeObserver.unsubscribe(targetEl); | ||
}; | ||
@@ -55,14 +46,24 @@ }, [target, resizeObserver, storedCallback]); | ||
return resizeObserver.observer; | ||
}; | ||
} | ||
const createResizeObserver = () => { | ||
const callbacks = new Set(); | ||
function createResizeObserver() { | ||
const callbacks = new Map(); | ||
return { | ||
observer: new _resizeObserverPolyfill.default((entries, observer) => { | ||
for (const callback of callbacks) callback(entries, observer); | ||
if (entries.length === 1) { | ||
var _callbacks$get; | ||
(_callbacks$get = callbacks.get(entries[0].target)) === null || _callbacks$get === void 0 ? void 0 : _callbacks$get(entries[0], observer); | ||
} else { | ||
for (let i = 0; i < entries.length; i++) { | ||
var _callbacks$get2; | ||
(_callbacks$get2 = callbacks.get(entries[i].target)) === null || _callbacks$get2 === void 0 ? void 0 : _callbacks$get2(entries[i], observer); | ||
} | ||
} | ||
}), | ||
subscribe: callback => callbacks.add(callback), | ||
unsubscribe: callback => callbacks.delete(callback) | ||
subscribe: (target, callback) => callbacks.set(target, callback), | ||
unsubscribe: target => callbacks.delete(target) | ||
}; | ||
}; | ||
} | ||
@@ -69,0 +70,0 @@ let _resizeObserver; |
@@ -12,3 +12,3 @@ import ResizeObserver from 'resize-observer-polyfill'; | ||
const useResizeObserver = (target, callback) => { | ||
function useResizeObserver(target, callback) { | ||
const resizeObserver = getResizeObserver(); | ||
@@ -18,20 +18,11 @@ const storedCallback = useLatest(callback); | ||
let didUnsubscribe = false; | ||
const callback = (entries, observer) => { | ||
const targetEl = target && 'current' in target ? target.current : target; | ||
if (!targetEl) return; | ||
resizeObserver.subscribe(targetEl, (entry, observer) => { | ||
if (didUnsubscribe) return; | ||
const targetEl = target && 'current' in target ? target.current : target; | ||
for (let i = 0; i < entries.length; i++) { | ||
const entry = entries[i]; | ||
if (entry.target === targetEl) { | ||
storedCallback.current(entry, observer); | ||
} | ||
} | ||
}; | ||
resizeObserver.subscribe(callback); | ||
storedCallback.current(entry, observer); | ||
}); | ||
return () => { | ||
didUnsubscribe = true; | ||
resizeObserver.unsubscribe(callback); | ||
resizeObserver.unsubscribe(targetEl); | ||
}; | ||
@@ -46,14 +37,24 @@ }, [target, resizeObserver, storedCallback]); | ||
return resizeObserver.observer; | ||
}; | ||
} | ||
const createResizeObserver = () => { | ||
const callbacks = new Set(); | ||
function createResizeObserver() { | ||
const callbacks = new Map(); | ||
return { | ||
observer: new ResizeObserver((entries, observer) => { | ||
for (const callback of callbacks) callback(entries, observer); | ||
if (entries.length === 1) { | ||
var _callbacks$get; | ||
(_callbacks$get = callbacks.get(entries[0].target)) === null || _callbacks$get === void 0 ? void 0 : _callbacks$get(entries[0], observer); | ||
} else { | ||
for (let i = 0; i < entries.length; i++) { | ||
var _callbacks$get2; | ||
(_callbacks$get2 = callbacks.get(entries[i].target)) === null || _callbacks$get2 === void 0 ? void 0 : _callbacks$get2(entries[i], observer); | ||
} | ||
} | ||
}), | ||
subscribe: callback => callbacks.add(callback), | ||
unsubscribe: callback => callbacks.delete(callback) | ||
subscribe: (target, callback) => callbacks.set(target, callback), | ||
unsubscribe: target => callbacks.delete(target) | ||
}; | ||
}; | ||
} | ||
@@ -60,0 +61,0 @@ let _resizeObserver; |
@@ -1,2 +0,2 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("react")):"function"==typeof define&&define.amd?define(["react"],e):(t=t||self).useResizeObserver=e(t.React)}(this,(function(t){"use strict";function e(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);e>n;n++)r[n]=t[n];return r}function n(t,e){var n=-1;return t.some((function(t,r){return t[0]===e?(n=r,1):0})),n}function r(){this.__entries__=[]}function i(){return this.__entries__.length}function o(t){var e=n(this.__entries__,t),r=this.__entries__[e];return r&&r[1]}function s(t,e){var r=n(this.__entries__,t);~r?this.__entries__[r][1]=e:this.__entries__.push([t,e])}function c(t){var e=this.__entries__,r=n(e,t);~r&&e.splice(r,1)}function u(t){return!!~n(this.__entries__,t)}function a(){this.__entries__.splice(0)}function f(t,e){void 0===e&&(e=null);for(var n=0,r=this.__entries__;n<r.length;n++){var i=r[n];t.call(e,i[1],i[0])}}function h(t){return setTimeout((function(){return t(Date.now())}),1e3/60)}function d(){this.connected_=0,this.mutationEventsAdded_=0,this.mutationsObserver_=null,this.observers_=[],this.onTransitionEnd_=this.onTransitionEnd_.bind(this),this.refresh=function(t){function e(){i&&(i=0,t()),o&&r()}function n(){N(e)}function r(){var t=Date.now();if(i){if(2>t-s)return;o=1}else i=1,o=0,setTimeout(n,20);s=t}var i=0,o=0,s=0;return r}(this.refresh.bind(this))}function v(t){~this.observers_.indexOf(t)||this.observers_.push(t),this.connected_||this.connect_()}function l(t){var e=this.observers_,n=e.indexOf(t);~n&&e.splice(n,1),!e.length&&this.connected_&&this.disconnect_()}function p(){this.updateObservers_()&&this.refresh()}function b(t){return t.gatherActive(),t.hasActive()}function _(t){return t.broadcastActive()}function y(){var t=this.observers_.filter(b);return t.forEach(_),t.length>0}function m(){V&&!this.connected_&&(document.addEventListener("transitionend",this.onTransitionEnd_),window.addEventListener("resize",this.refresh),$?(this.mutationsObserver_=new MutationObserver(this.refresh),this.mutationsObserver_.observe(document,{attributes:1,childList:1,characterData:1,subtree:1})):(document.addEventListener("DOMSubtreeModified",this.refresh),this.mutationEventsAdded_=1),this.connected_=1)}function g(){V&&this.connected_&&(document.removeEventListener("transitionend",this.onTransitionEnd_),window.removeEventListener("resize",this.refresh),this.mutationsObserver_&&this.mutationsObserver_.disconnect(),this.mutationEventsAdded_&&document.removeEventListener("DOMSubtreeModified",this.refresh),this.mutationsObserver_=null,this.mutationEventsAdded_=0,this.connected_=0)}function w(t){var e=t.propertyName,n=void 0===e?"":e;U.some((function(t){return!!~n.indexOf(t)}))&&this.refresh()}function E(){return this.instance_||(this.instance_=new d),this.instance_}function O(t){return parseFloat(t)||0}function A(t){for(var e=[],n=1;arguments.length>n;n++)e[n-1]=arguments[n];return e.reduce((function(e,n){return e+O(t["border-"+n+"-width"])}),0)}function M(t){return t instanceof Q(t).SVGGraphicsElement}function T(t){return t instanceof Q(t).SVGElement&&"function"==typeof t.getBBox}function x(t){return V?Y(t)?function(t){var e=t.getBBox();return R(0,0,e.width,e.height)}(t):function(t){var e=t.clientWidth,n=t.clientHeight;if(!e&&!n)return X;var r=Q(t).getComputedStyle(t),i=function(t){for(var e={},n=0,r=["top","right","bottom","left"];r.length>n;n++){var i=r[n],o=t["padding-"+i];e[i]=O(o)}return e}(r),o=i.left+i.right,s=i.top+i.bottom,c=O(r.width),u=O(r.height);if("border-box"===r.boxSizing&&(Math.round(c+o)!==e&&(c-=A(r,"left","right")+o),Math.round(u+s)!==n&&(u-=A(r,"top","bottom")+s)),!function(t){return t===Q(t).document.documentElement}(t)){var a=Math.round(c+o)-e,f=Math.round(u+s)-n;1!==Math.abs(a)&&(c-=a),1!==Math.abs(f)&&(u-=f)}return R(i.left,i.top,c,u)}(t):X}function R(t,e,n,r){return{x:t,y:e,width:n,height:r}}function S(t){this.broadcastWidth=0,this.broadcastHeight=0,this.contentRect_=R(0,0,0,0),this.target=t}function j(){var t=x(this.target);return this.contentRect_=t,t.width!==this.broadcastWidth||t.height!==this.broadcastHeight}function z(){var t=this.contentRect_;return this.broadcastWidth=t.width,this.broadcastHeight=t.height,t}function D(t,e){var n,r,i,o,s,c,u,a=(r=(n=e).x,i=n.y,o=n.width,s=n.height,c="undefined"!=typeof DOMRectReadOnly?DOMRectReadOnly:Object,u=Object.create(c.prototype),K(u,{x:r,y:i,width:o,height:s,top:i,right:r+o,bottom:s+i,left:r}),u);K(this,{target:t,contentRect:a})}function k(t,e,n){if(this.activeObservations_=[],this.observations_=new H,"function"!=typeof t)throw new TypeError("The callback provided as parameter 1 is not a function.");this.callback_=t,this.controller_=e,this.callbackCtx_=n}function L(t){if(!arguments.length)throw new TypeError("1 argument required, but only 0 present.");if("undefined"!=typeof Element&&Element instanceof Object){if(!(t instanceof Q(t).Element))throw new TypeError('parameter 1 is not of type "Element".');var e=this.observations_;e.has(t)||(e.set(t,new Z(t)),this.controller_.addObserver(this),this.controller_.refresh())}}function q(t){if(!arguments.length)throw new TypeError("1 argument required, but only 0 present.");if("undefined"!=typeof Element&&Element instanceof Object){if(!(t instanceof Q(t).Element))throw new TypeError('parameter 1 is not of type "Element".');var e=this.observations_;e.has(t)&&(e.delete(t),e.size||this.controller_.removeObserver(this))}}function W(){this.clearActive(),this.observations_.clear(),this.controller_.removeObserver(this)}function C(){var t=this;this.clearActive(),this.observations_.forEach((function(e){e.isActive()&&t.activeObservations_.push(e)}))}function G(t){return new tt(t.target,t.broadcastRect())}function I(){if(this.hasActive()){var t=this.callbackCtx_,e=this.activeObservations_.map(G);this.callback_.call(t,e,t),this.clearActive()}}function B(){this.activeObservations_.splice(0)}function F(){return this.activeObservations_.length>0}var H=function(){return"undefined"!=typeof Map?Map:(Object.defineProperty(r.prototype,"size",{get:i,enumerable:1,configurable:1}),r.prototype.get=o,r.prototype.set=s,r.prototype.delete=c,r.prototype.has=u,r.prototype.clear=a,r.prototype.forEach=f,r)}(),V="undefined"!=typeof window&&"undefined"!=typeof document&&window.document===document,P=function(){return"undefined"!=typeof global&&global.Math===Math?global:"undefined"!=typeof self&&self.Math===Math?self:"undefined"!=typeof window&&window.Math===Math?window:Function("return this")()}(),N=function(){return"function"==typeof requestAnimationFrame?requestAnimationFrame.bind(P):h}(),U=["top","right","bottom","left","width","height","size","weight"],$="undefined"!=typeof MutationObserver,J=function(){return d.prototype.addObserver=v,d.prototype.removeObserver=l,d.prototype.refresh=p,d.prototype.updateObservers_=y,d.prototype.connect_=m,d.prototype.disconnect_=g,d.prototype.onTransitionEnd_=w,d.getInstance=E,d.instance_=null,d}(),K=function(t,e){for(var n=0,r=Object.keys(e);n<r.length;n++){var i=r[n];Object.defineProperty(t,i,{value:e[i],enumerable:0,writable:0,configurable:1})}return t},Q=function(t){return t&&t.ownerDocument&&t.ownerDocument.defaultView||P},X=R(0,0,0,0),Y=function(){return"undefined"!=typeof SVGGraphicsElement?M:T}(),Z=function(){return S.prototype.isActive=j,S.prototype.broadcastRect=z,S}(),tt=function(){return D}(),et=function(){return k.prototype.observe=L,k.prototype.unobserve=q,k.prototype.disconnect=W,k.prototype.gatherActive=C,k.prototype.broadcastActive=I,k.prototype.clearActive=B,k.prototype.hasActive=F,k}(),nt="undefined"!=typeof WeakMap?new WeakMap:new H,rt=function(){return function t(e){if(!(this instanceof t))throw new TypeError("Cannot call a class as a function.");if(!arguments.length)throw new TypeError("1 argument required, but only 0 present.");var n=J.getInstance(),r=new et(e,n,this);nt.set(this,r)}}();["observe","unobserve","disconnect"].forEach((function(t){rt.prototype[t]=function(){var e;return(e=nt.get(this))[t].apply(e,arguments)}}));var it,ot=function(){return void 0!==P.ResizeObserver?P.ResizeObserver:rt}(),st=t["undefined"!=typeof document&&void 0!==document.createElement?"useLayoutEffect":"useEffect"],ct=function(){return it||(t=new Set,it={observer:new ot((function(n,r){for(var i,o=function(t,n){var r;if("undefined"==typeof Symbol||null==t[Symbol.iterator]){if(Array.isArray(t)||(r=function(t){if(t){if("string"==typeof t)return e(t,void 0);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?e(t,void 0):void 0}}(t))||n&&t&&"number"==typeof t.length){r&&(t=r);var i=0;return function(){return i<t.length?{done:0,value:t[i++]}:{done:1}}}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(r=t[Symbol.iterator]()).next.bind(r)}(t);!(i=o()).done;)(0,i.value)(n,r)})),subscribe:function(e){return t.add(e)},unsubscribe:function(e){return t.delete(e)}});var t};return function(e,n){var r,i,o=ct(),s=(r=n,(i=t.useRef(r)).current=r,i);return st((function(){var t=0,n=function(n,r){if(!t)for(var i=(e&&"current"in e?e.current:e),o=0;o<n.length;o++){var c=n[o];c.target===i&&s.current(c,r)}};return o.subscribe(n),function(){t=1,o.unsubscribe(n)}}),[e,o,s]),st((function(){var t=e&&"current"in e?e.current:e;if(t)return o.observer.observe(t),function(){return o.observer.unobserve(t)}}),[e,o.observer]),o.observer}})); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("react")):"function"==typeof define&&define.amd?define(["react"],e):(t=t||self).useResizeObserver=e(t.React)}(this,(function(t){"use strict";function e(t,e){var n=-1;return t.some((function(t,r){return t[0]===e?(n=r,1):0})),n}function n(){this.__entries__=[]}function r(){return this.__entries__.length}function i(t){var n=e(this.__entries__,t),r=this.__entries__[n];return r&&r[1]}function o(t,n){var r=e(this.__entries__,t);~r?this.__entries__[r][1]=n:this.__entries__.push([t,n])}function s(t){var n=this.__entries__,r=e(n,t);~r&&n.splice(r,1)}function c(t){return!!~e(this.__entries__,t)}function u(){this.__entries__.splice(0)}function a(t,e){void 0===e&&(e=null);for(var n=0,r=this.__entries__;n<r.length;n++){var i=r[n];t.call(e,i[1],i[0])}}function h(t){return setTimeout((function(){return t(Date.now())}),1e3/60)}function f(){this.connected_=0,this.mutationEventsAdded_=0,this.mutationsObserver_=null,this.observers_=[],this.onTransitionEnd_=this.onTransitionEnd_.bind(this),this.refresh=function(t){function e(){i&&(i=0,t()),o&&r()}function n(){P(e)}function r(){var t=Date.now();if(i){if(2>t-s)return;o=1}else i=1,o=0,setTimeout(n,20);s=t}var i=0,o=0,s=0;return r}(this.refresh.bind(this))}function d(t){~this.observers_.indexOf(t)||this.observers_.push(t),this.connected_||this.connect_()}function v(t){var e=this.observers_,n=e.indexOf(t);~n&&e.splice(n,1),!e.length&&this.connected_&&this.disconnect_()}function p(){this.updateObservers_()&&this.refresh()}function l(t){return t.gatherActive(),t.hasActive()}function b(t){return t.broadcastActive()}function _(){var t=this.observers_.filter(l);return t.forEach(b),t.length>0}function m(){V&&!this.connected_&&(document.addEventListener("transitionend",this.onTransitionEnd_),window.addEventListener("resize",this.refresh),J?(this.mutationsObserver_=new MutationObserver(this.refresh),this.mutationsObserver_.observe(document,{attributes:1,childList:1,characterData:1,subtree:1})):(document.addEventListener("DOMSubtreeModified",this.refresh),this.mutationEventsAdded_=1),this.connected_=1)}function y(){V&&this.connected_&&(document.removeEventListener("transitionend",this.onTransitionEnd_),window.removeEventListener("resize",this.refresh),this.mutationsObserver_&&this.mutationsObserver_.disconnect(),this.mutationEventsAdded_&&document.removeEventListener("DOMSubtreeModified",this.refresh),this.mutationsObserver_=null,this.mutationEventsAdded_=0,this.connected_=0)}function g(t){var e=t.propertyName,n=void 0===e?"":e;N.some((function(t){return!!~n.indexOf(t)}))&&this.refresh()}function w(){return this.instance_||(this.instance_=new f),this.instance_}function E(t){return parseFloat(t)||0}function O(t){for(var e=[],n=1;arguments.length>n;n++)e[n-1]=arguments[n];return e.reduce((function(e,n){return e+E(t["border-"+n+"-width"])}),0)}function M(t){return t instanceof U(t).SVGGraphicsElement}function A(t){return t instanceof U(t).SVGElement&&"function"==typeof t.getBBox}function R(t){return V?Y(t)?function(t){var e=t.getBBox();return T(0,0,e.width,e.height)}(t):function(t){var e=t.clientWidth,n=t.clientHeight;if(!e&&!n)return X;var r=U(t).getComputedStyle(t),i=function(t){for(var e={},n=0,r=["top","right","bottom","left"];r.length>n;n++){var i=r[n],o=t["padding-"+i];e[i]=E(o)}return e}(r),o=i.left+i.right,s=i.top+i.bottom,c=E(r.width),u=E(r.height);if("border-box"===r.boxSizing&&(Math.round(c+o)!==e&&(c-=O(r,"left","right")+o),Math.round(u+s)!==n&&(u-=O(r,"top","bottom")+s)),!function(t){return t===U(t).document.documentElement}(t)){var a=Math.round(c+o)-e,h=Math.round(u+s)-n;1!==Math.abs(a)&&(c-=a),1!==Math.abs(h)&&(u-=h)}return T(i.left,i.top,c,u)}(t):X}function T(t,e,n,r){return{x:t,y:e,width:n,height:r}}function x(t){this.broadcastWidth=0,this.broadcastHeight=0,this.contentRect_=T(0,0,0,0),this.target=t}function z(){var t=R(this.target);return this.contentRect_=t,t.width!==this.broadcastWidth||t.height!==this.broadcastHeight}function D(){var t=this.contentRect_;return this.broadcastWidth=t.width,this.broadcastHeight=t.height,t}function j(t,e){var n,r,i,o,s,c,u,a=(r=(n=e).x,i=n.y,o=n.width,s=n.height,c="undefined"!=typeof DOMRectReadOnly?DOMRectReadOnly:Object,u=Object.create(c.prototype),Q(u,{x:r,y:i,width:o,height:s,top:i,right:r+o,bottom:s+i,left:r}),u);Q(this,{target:t,contentRect:a})}function k(t,e,n){if(this.activeObservations_=[],this.observations_=new H,"function"!=typeof t)throw new TypeError("The callback provided as parameter 1 is not a function.");this.callback_=t,this.controller_=e,this.callbackCtx_=n}function L(t){if(!arguments.length)throw new TypeError("1 argument required, but only 0 present.");if("undefined"!=typeof Element&&Element instanceof Object){if(!(t instanceof U(t).Element))throw new TypeError('parameter 1 is not of type "Element".');var e=this.observations_;e.has(t)||(e.set(t,new Z(t)),this.controller_.addObserver(this),this.controller_.refresh())}}function S(t){if(!arguments.length)throw new TypeError("1 argument required, but only 0 present.");if("undefined"!=typeof Element&&Element instanceof Object){if(!(t instanceof U(t).Element))throw new TypeError('parameter 1 is not of type "Element".');var e=this.observations_;e.has(t)&&(e.delete(t),e.size||this.controller_.removeObserver(this))}}function q(){this.clearActive(),this.observations_.clear(),this.controller_.removeObserver(this)}function W(){var t=this;this.clearActive(),this.observations_.forEach((function(e){e.isActive()&&t.activeObservations_.push(e)}))}function G(t){return new $(t.target,t.broadcastRect())}function B(){if(this.hasActive()){var t=this.callbackCtx_,e=this.activeObservations_.map(G);this.callback_.call(t,e,t),this.clearActive()}}function C(){this.activeObservations_.splice(0)}function F(){return this.activeObservations_.length>0}var H=function(){return"undefined"!=typeof Map?Map:(Object.defineProperty(n.prototype,"size",{get:r,enumerable:1,configurable:1}),n.prototype.get=i,n.prototype.set=o,n.prototype.delete=s,n.prototype.has=c,n.prototype.clear=u,n.prototype.forEach=a,n)}(),V="undefined"!=typeof window&&"undefined"!=typeof document&&window.document===document,I=function(){return"undefined"!=typeof global&&global.Math===Math?global:"undefined"!=typeof self&&self.Math===Math?self:"undefined"!=typeof window&&window.Math===Math?window:Function("return this")()}(),P=function(){return"function"==typeof requestAnimationFrame?requestAnimationFrame.bind(I):h}(),N=["top","right","bottom","left","width","height","size","weight"],J="undefined"!=typeof MutationObserver,K=function(){return f.prototype.addObserver=d,f.prototype.removeObserver=v,f.prototype.refresh=p,f.prototype.updateObservers_=_,f.prototype.connect_=m,f.prototype.disconnect_=y,f.prototype.onTransitionEnd_=g,f.getInstance=w,f.instance_=null,f}(),Q=function(t,e){for(var n=0,r=Object.keys(e);n<r.length;n++){var i=r[n];Object.defineProperty(t,i,{value:e[i],enumerable:0,writable:0,configurable:1})}return t},U=function(t){return t&&t.ownerDocument&&t.ownerDocument.defaultView||I},X=T(0,0,0,0),Y=function(){return"undefined"!=typeof SVGGraphicsElement?M:A}(),Z=function(){return x.prototype.isActive=z,x.prototype.broadcastRect=D,x}(),$=function(){return j}(),tt=function(){return k.prototype.observe=L,k.prototype.unobserve=S,k.prototype.disconnect=q,k.prototype.gatherActive=W,k.prototype.broadcastActive=B,k.prototype.clearActive=C,k.prototype.hasActive=F,k}(),et="undefined"!=typeof WeakMap?new WeakMap:new H,nt=function(){return function t(e){if(!(this instanceof t))throw new TypeError("Cannot call a class as a function.");if(!arguments.length)throw new TypeError("1 argument required, but only 0 present.");var n=K.getInstance(),r=new tt(e,n,this);et.set(this,r)}}();["observe","unobserve","disconnect"].forEach((function(t){nt.prototype[t]=function(){var e;return(e=et.get(this))[t].apply(e,arguments)}}));var rt,it=function(){return void 0!==I.ResizeObserver?I.ResizeObserver:nt}(),ot=t["undefined"!=typeof document&&void 0!==document.createElement?"useLayoutEffect":"useEffect"];return function(e,n){var r,i,o,s=rt||(o=new Map,rt={observer:new it((function(t,e){var n;if(1===t.length)null===(n=o.get(t[0].target))||void 0===n||n(t[0],e);else for(var r=0;r<t.length;r++){var i;null===(i=o.get(t[r].target))||void 0===i||i(t[r],e)}})),subscribe:function(t,e){return o.set(t,e)},unsubscribe:function(t){return o.delete(t)}}),c=(r=n,(i=t.useRef(r)).current=r,i);return ot((function(){var t=0,n=e&&"current"in e?e.current:e;if(n)return s.subscribe(n,(function(e,n){t||c.current(e,n)})),function(){t=1,s.unsubscribe(n)}}),[e,s,c]),ot((function(){var t=e&&"current"in e?e.current:e;if(t)return s.observer.observe(t),function(){return s.observer.unobserve(t)}}),[e,s.observer]),s.observer}})); | ||
//# sourceMappingURL=use-resize-observer.js.map |
{ | ||
"name": "@react-hook/resize-observer", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"homepage": "https://github.com/jaredLunde/react-hook/tree/master/packages/resize-observer#readme", | ||
@@ -121,3 +121,3 @@ "repository": "github:jaredLunde/react-hook", | ||
"lint-staged": "latest", | ||
"lundle": "latest", | ||
"lundle": "^0.4.9", | ||
"prettier": "latest", | ||
@@ -124,0 +124,0 @@ "react": "latest", |
@@ -15,10 +15,5 @@ <hr> | ||
</a> | ||
<!-- | ||
<a aria-label="Code coverage report" href="https://codecov.io/gh/jaredLunde/react-hook"> | ||
<img alt="Code coverage" src="https://img.shields.io/codecov/c/gh/jaredLunde/react-hook?style=for-the-badge&labelColor=24292e"> | ||
</a> | ||
<a aria-label="Build status" href="https://travis-ci.com/jaredLunde/react-hook"> | ||
<img alt="Build status" src="https://img.shields.io/travis/com/jaredLunde/react-hook?style=for-the-badge&labelColor=24292e"> | ||
</a> | ||
--> | ||
<a aria-label="NPM version" href="https://www.npmjs.com/package/@react-hook/resize-observer"> | ||
@@ -25,0 +20,0 @@ <img alt="NPM Version" src="https://img.shields.io/npm/v/@react-hook/resize-observer?style=for-the-badge&labelColor=24292e"> |
@@ -10,6 +10,6 @@ import * as React from 'react' | ||
*/ | ||
declare const useResizeObserver: <T extends HTMLElement>( | ||
target: T | React.RefObject<T> | null, | ||
declare function useResizeObserver<T extends HTMLElement>( | ||
target: React.RefObject<T> | T | null, | ||
callback: UseResizeObserverCallback | ||
) => ResizeObserver | ||
): ResizeObserver | ||
export declare type UseResizeObserverCallback = ( | ||
@@ -16,0 +16,0 @@ entry: ResizeObserverEntry, |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
185526
16
1327
103
3