react-within-viewport
Advanced tools
Comparing version 1.2.2 to 1.2.3
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("react")):"function"==typeof define&&define.amd?define(["react"],e):"object"==typeof exports?exports.WithinViewport=e(require("react")):t.WithinViewport=e(t.react)}(this,function(t){return function(t){function e(i){if(n[i])return n[i].exports;var o=n[i]={exports:{},id:i,loaded:!1};return t[i].call(o.exports,o,o.exports,e),o.loaded=!0,o.exports}var n={};return e.m=t,e.c=n,e.p="",e(0)}([function(t,e,n){"use strict";function i(t){return t&&t.__esModule?t:{"default":t}}Object.defineProperty(e,"__esModule",{value:!0});var o=n(1),r=i(o);e.default=r.default},function(t,e,n){"use strict";function i(t){return t&&t.__esModule?t:{"default":t}}function o(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function r(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function u(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}function a(){}Object.defineProperty(e,"__esModule",{value:!0});var f=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(t[i]=n[i])}return t},c=function(){function t(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}return function(e,n,i){return n&&t(e.prototype,n),i&&t(e,i),e}}(),l=n(7),d=i(l),s=n(6),p=i(s),v=n(5),w=i(v),h=n(3),g=i(h),y=function(){var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];return t&&t.getBoundingClientRect?t.getBoundingClientRect().height:t?t.clientHeight:null},m=function(){var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];return t&&t.getBoundingClientRect?t.getBoundingClientRect().width:t?t.clientWidth:null},b=function(){var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];return t&&t.getBoundingClientRect?t.getBoundingClientRect().top:t?t.clientTop:null},O=function(){var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];return t&&t.getBoundingClientRect?t.getBoundingClientRect().left:t?t.clientLeft:null},j=function(){var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],e=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];return t||e?t.innerHeight||e.clientHeight:null},_=function(){var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],e=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];return t||e?t.innerWidth||e.clientWidth:null},V=function(t){var e=t.inViewport;return{inViewport:e}},T={width:"100%",height:"100%",padding:0,border:0},x=function(){var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],e=t.transform,n=void 0===e?V:e,i=t.containerStyle,s=void 0===i?T:i,v=t.getHeight,h=void 0===v?y:v,x=t.getWidth,R=void 0===x?m:x,W=t.getTop,L=void 0===W?b:W,C=t.getLeft,E=void 0===C?O:C,H=t.getViewportHeight,M=void 0===H?j:H,S=t.getViewportWidth,U=void 0===S?_:S,k=t.defaultAnswer,z=void 0===k?!0:k,B=t.wait,P=void 0===B?200:B,q=t.onViewportEnter,A=void 0===q?a:q,F=t.onViewportLeave,N=void 0===F?a:F;return function(t){var e,i;return i=e=function(e){function i(){var t,e,n,u;o(this,i);for(var a=arguments.length,c=Array(a),l=0;a>l;l++)c[l]=arguments[l];return e=n=r(this,(t=Object.getPrototypeOf(i)).call.apply(t,[this].concat(c))),n.state={containerWidth:null,containerHeight:null,containerTopOffset:null,containerLeftOffset:null,windowWidth:null,windowHeight:null,ready:!1},n.updateResize=function(){if(n.mounted){var t=function(){var t=n.refs.withinViewportContainer,e={containerWidth:R(t),containerHeight:h(t),windowWidth:U(window,document),windowHeight:M(window,document)};n.setState(f({},e,{ready:n.isReady(f({},n.state,e))}))};"undefined"!=typeof window&&null!==window&&window.requestAnimationFrame?window.requestAnimationFrame(function(){return t()}):t()}},n.updateScroll=function(){if(n.mounted){var t=function(){var t=n.refs.withinViewportContainer,e={containerTopOffset:L(t),containerLeftOffset:E(t)};n.setState(f({},e,{ready:n.isReady(f({},n.state,e))}))};"undefined"!=typeof window&&null!==window&&window.requestAnimationFrame?window.requestAnimationFrame(function(){return t()}):t()}},n.isReady=function(){var t=arguments.length<=0||void 0===arguments[0]?n.state:arguments[0];return null!==t.containerWidth&&null!==t.containerHeight&&null!==t.containerTopOffset&&null!==t.containerLeftOffset&&null!==t.windowHeight&&null!==t.windowWidth},n.inViewport=function(){var t=arguments.length<=0||void 0===arguments[0]?n.state:arguments[0];return t.ready?(t.containerTopOffset<0&&t.containerHeight+t.containerTopOffset>0||t.containerTopOffset>=0&&t.containerTopOffset<t.windowHeight)&&(t.containerLeftOffset<0&&t.containerWidth+t.containerLeftOffset>0||t.containerLeftOffset>=0&&t.containerLeftOffset<t.windowWidth):z},u=e,r(n,u)}return u(i,e),c(i,[{key:"componentDidMount",value:function(){"undefined"!=typeof window&&null!==window&&window.addEventListener&&(this.mounted=!0,this.debouncedUpdateResize=(0,g.default)(this.updateResize,P),this.debouncedUpdateScroll=(0,g.default)(this.updateScroll,P),window.addEventListener("resize",this.debouncedUpdateResize,{passive:!0}),window.addEventListener("scroll",this.debouncedUpdateScroll,{passive:!0}),this.updateResize(),this.updateScroll())}},{key:"componentDidUpdate",value:function(t,e){var n=this.inViewport(e),i=this.inViewport(this.state);null===e.ready&&i===!1&&N(),null===e.ready&&i===!0&&A(),n===!0&&i===!1&&N(),n===!1&&i===!0&&A()}},{key:"componentWillUnmount",value:function(){"undefined"!=typeof window&&null!==window&&window.removeEventListener&&(this.mounted=!1,window.removeEventListener("resize",this.debouncedUpdateResize),window.removeEventListener("scroll",this.debouncedUpdateScroll))}},{key:"shouldComponentUpdate",value:function(t,e){return!(0,w.default)(this.props,t)||!(0,w.default)(n(f({inViewport:this.inViewport(this.state)},this.state)),n(f({inViewport:this.inViewport(e)},e)))}},{key:"render",value:function(){return d.default.createElement("div",{ref:"withinViewportContainer",style:s},d.default.createElement(t,f({},n(f({inViewport:this.inViewport()},this.state)),this.props)))}}]),i}(l.Component),e.displayName=(0,p.default)(t,"withinViewport"),i}};e.default=x},function(t,e){"use strict";function n(t,e){return t===e?0!==t||1/t===1/e:t!==t&&e!==e}function i(t,e){if(n(t,e))return!0;if("object"!=typeof t||null===t||"object"!=typeof e||null===e)return!1;var i=Object.keys(t),r=Object.keys(e);if(i.length!==r.length)return!1;for(var u=0;u<i.length;u++)if(!o.call(e,i[u])||!n(t[i[u]],e[i[u]]))return!1;return!0}var o=Object.prototype.hasOwnProperty;t.exports=i},function(t,e){function n(t,e,n){function i(e){var n=w,i=h;return w=h=void 0,V=e,y=t.apply(i,n)}function r(t){return V=t,m=setTimeout(l,e),T?i(t):y}function u(t){var n=t-_,i=t-V,o=e-n;return x?O(o,g-i):o}function c(t){var n=t-_,i=t-V;return!_||n>=e||0>n||x&&i>=g}function l(){var t=j();return c(t)?d(t):void(m=setTimeout(l,u(t)))}function d(t){return clearTimeout(m),m=void 0,R&&w?i(t):(w=h=void 0,y)}function s(){void 0!==m&&clearTimeout(m),_=V=0,w=h=m=void 0}function p(){return void 0===m?y:d(j())}function v(){var t=j(),n=c(t);if(w=arguments,h=this,_=t,n){if(void 0===m)return r(_);if(x)return clearTimeout(m),m=setTimeout(l,e),i(_)}return void 0===m&&(m=setTimeout(l,e)),y}var w,h,g,y,m,_=0,V=0,T=!1,x=!1,R=!0;if("function"!=typeof t)throw new TypeError(f);return e=a(e)||0,o(n)&&(T=!!n.leading,x="maxWait"in n,g=x?b(a(n.maxWait)||0,e):g,R="trailing"in n?!!n.trailing:R),v.cancel=s,v.flush=p,v}function i(t){var e=o(t)?m.call(t):"";return e==l||e==d}function o(t){var e=typeof t;return!!t&&("object"==e||"function"==e)}function r(t){return!!t&&"object"==typeof t}function u(t){return"symbol"==typeof t||r(t)&&m.call(t)==s}function a(t){if("number"==typeof t)return t;if(u(t))return c;if(o(t)){var e=i(t.valueOf)?t.valueOf():t;t=o(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=t.replace(p,"");var n=w.test(t);return n||h.test(t)?g(t.slice(2),n?2:8):v.test(t)?c:+t}var f="Expected a function",c=NaN,l="[object Function]",d="[object GeneratorFunction]",s="[object Symbol]",p=/^\s+|\s+$/g,v=/^[-+]0x[0-9a-f]+$/i,w=/^0b[01]+$/i,h=/^0o[0-7]+$/i,g=parseInt,y=Object.prototype,m=y.toString,b=Math.max,O=Math.min,j=Date.now;t.exports=n},function(t,e){"use strict";e.__esModule=!0;var n=function(t){if("string"==typeof t)return t;if(t)return t.displayName||t.name||"Component"};e.default=n},function(t,e,n){"use strict";function i(t){return t&&t.__esModule?t:{"default":t}}e.__esModule=!0;var o=n(2),r=i(o);e.default=r.default},function(t,e,n){"use strict";function i(t){return t&&t.__esModule?t:{"default":t}}e.__esModule=!0;var o=n(4),r=i(o),u=function(t,e){return e+"("+(0,r.default)(t)+")"};e.default=u},function(e,n){e.exports=t}])}); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react")):"function"==typeof define&&define.amd?define(["react"],t):"object"==typeof exports?exports.WithinViewport=t(require("react")):e.WithinViewport=t(e.react)}(this,function(e){return function(e){function t(i){if(n[i])return n[i].exports;var o=n[i]={exports:{},id:i,loaded:!1};return e[i].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var n={};return t.m=e,t.c=n,t.p="",t(0)}([function(e,t,n){"use strict";function i(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(t,"__esModule",{value:!0});var o=n(1),r=i(o);t.default=r.default},function(e,t,n){"use strict";function i(e){return e&&e.__esModule?e:{"default":e}}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function r(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function u(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function a(){}Object.defineProperty(t,"__esModule",{value:!0});var f=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(e[i]=n[i])}return e},c=function(){function e(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,n,i){return n&&e(t.prototype,n),i&&e(t,i),t}}(),l=n(7),d=i(l),s=n(6),p=i(s),v=n(5),w=i(v),h=n(3),g=i(h),y=function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];return e&&e.getBoundingClientRect?e.getBoundingClientRect().height:e?e.clientHeight:null},m=function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];return e&&e.getBoundingClientRect?e.getBoundingClientRect().width:e?e.clientWidth:null},b=function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];return e&&e.getBoundingClientRect?e.getBoundingClientRect().top:e?e.clientTop:null},O=function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];return e&&e.getBoundingClientRect?e.getBoundingClientRect().left:e?e.clientLeft:null},j=function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],t=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];return e||t?e.innerHeight||t.clientHeight:null},_=function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],t=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];return e||t?e.innerWidth||t.clientWidth:null},V=function(e){var t=e.inViewport;return{inViewport:t}},T={width:"100%",height:"100%",padding:0,border:0},x=function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],t=e.transform,n=void 0===t?V:t,i=e.containerStyle,s=void 0===i?T:i,v=e.getHeight,h=void 0===v?y:v,x=e.getWidth,R=void 0===x?m:x,W=e.getTop,L=void 0===W?b:W,C=e.getLeft,E=void 0===C?O:C,H=e.getViewportHeight,M=void 0===H?j:H,S=e.getViewportWidth,U=void 0===S?_:S,k=e.defaultAnswer,z=void 0===k?!0:k,B=e.wait,P=void 0===B?200:B,q=e.onViewportEnter,A=void 0===q?a:q,F=e.onViewportLeave,N=void 0===F?a:F;return function(e){var t,i;return i=t=function(t){function i(){var e,t,n,u;o(this,i);for(var a=arguments.length,c=Array(a),l=0;a>l;l++)c[l]=arguments[l];return t=n=r(this,(e=Object.getPrototypeOf(i)).call.apply(e,[this].concat(c))),n.state={containerWidth:null,containerHeight:null,containerTopOffset:null,containerLeftOffset:null,windowWidth:null,windowHeight:null,ready:!1},n.updateResize=function(){if(n.mounted){var e=function(){var e=n.refs.withinViewportContainer,t={containerWidth:R(e),containerHeight:h(e),windowWidth:U(window,document),windowHeight:M(window,document)};n.setState(f({},t,{ready:n.isReady(f({},n.state,t))}))};"undefined"!=typeof window&&null!==window&&window.requestAnimationFrame?window.requestAnimationFrame(function(){return e()}):e()}},n.updateScroll=function(){if(n.mounted){var e=function(){var e=n.refs.withinViewportContainer,t={containerTopOffset:L(e),containerLeftOffset:E(e)};n.setState(f({},t,{ready:n.isReady(f({},n.state,t))}))};"undefined"!=typeof window&&null!==window&&window.requestAnimationFrame?window.requestAnimationFrame(function(){return e()}):e()}},n.isReady=function(){var e=arguments.length<=0||void 0===arguments[0]?n.state:arguments[0];return null!==e.containerWidth&&null!==e.containerHeight&&null!==e.containerTopOffset&&null!==e.containerLeftOffset&&null!==e.windowHeight&&null!==e.windowWidth},n.inViewport=function(){var e=arguments.length<=0||void 0===arguments[0]?n.state:arguments[0];return e.ready?(e.containerTopOffset<0&&e.containerHeight+e.containerTopOffset>0||e.containerTopOffset>=0&&e.containerTopOffset<e.windowHeight)&&(e.containerLeftOffset<0&&e.containerWidth+e.containerLeftOffset>0||e.containerLeftOffset>=0&&e.containerLeftOffset<e.windowWidth):z},u=t,r(n,u)}return u(i,t),c(i,[{key:"componentDidMount",value:function(){"undefined"!=typeof window&&null!==window&&window.addEventListener&&(this.mounted=!0,this.debouncedUpdateResize=(0,g.default)(this.updateResize,P),this.debouncedUpdateScroll=(0,g.default)(this.updateScroll,P),window.addEventListener("resize",this.debouncedUpdateResize,{passive:!0}),window.addEventListener("scroll",this.debouncedUpdateScroll,{passive:!0}),this.updateResize(),this.updateScroll())}},{key:"componentDidUpdate",value:function(e,t){var n=this.inViewport(t),i=this.inViewport(this.state);null===t.ready&&i===!1&&N(),null===t.ready&&i===!0&&A(),n===!0&&i===!1&&N(),n===!1&&i===!0&&A()}},{key:"componentWillUnmount",value:function(){"undefined"!=typeof window&&null!==window&&window.removeEventListener&&(this.mounted=!1,window.removeEventListener("resize",this.debouncedUpdateResize,{passive:!0}),window.removeEventListener("scroll",this.debouncedUpdateScroll,{passive:!0}))}},{key:"shouldComponentUpdate",value:function(e,t){return!(0,w.default)(this.props,e)||!(0,w.default)(n(f({inViewport:this.inViewport(this.state)},this.state)),n(f({inViewport:this.inViewport(t)},t)))}},{key:"render",value:function(){return d.default.createElement("div",{ref:"withinViewportContainer",style:s},d.default.createElement(e,f({},n(f({inViewport:this.inViewport()},this.state)),this.props)))}}]),i}(l.Component),t.displayName=(0,p.default)(e,"withinViewport"),i}};t.default=x},function(e,t){"use strict";function n(e,t){return e===t?0!==e||1/e===1/t:e!==e&&t!==t}function i(e,t){if(n(e,t))return!0;if("object"!=typeof e||null===e||"object"!=typeof t||null===t)return!1;var i=Object.keys(e),r=Object.keys(t);if(i.length!==r.length)return!1;for(var u=0;u<i.length;u++)if(!o.call(t,i[u])||!n(e[i[u]],t[i[u]]))return!1;return!0}var o=Object.prototype.hasOwnProperty;e.exports=i},function(e,t){function n(e,t,n){function i(t){var n=w,i=h;return w=h=void 0,V=t,y=e.apply(i,n)}function r(e){return V=e,m=setTimeout(l,t),T?i(e):y}function u(e){var n=e-_,i=e-V,o=t-n;return x?O(o,g-i):o}function c(e){var n=e-_,i=e-V;return!_||n>=t||0>n||x&&i>=g}function l(){var e=j();return c(e)?d(e):void(m=setTimeout(l,u(e)))}function d(e){return clearTimeout(m),m=void 0,R&&w?i(e):(w=h=void 0,y)}function s(){void 0!==m&&clearTimeout(m),_=V=0,w=h=m=void 0}function p(){return void 0===m?y:d(j())}function v(){var e=j(),n=c(e);if(w=arguments,h=this,_=e,n){if(void 0===m)return r(_);if(x)return clearTimeout(m),m=setTimeout(l,t),i(_)}return void 0===m&&(m=setTimeout(l,t)),y}var w,h,g,y,m,_=0,V=0,T=!1,x=!1,R=!0;if("function"!=typeof e)throw new TypeError(f);return t=a(t)||0,o(n)&&(T=!!n.leading,x="maxWait"in n,g=x?b(a(n.maxWait)||0,t):g,R="trailing"in n?!!n.trailing:R),v.cancel=s,v.flush=p,v}function i(e){var t=o(e)?m.call(e):"";return t==l||t==d}function o(e){var t=typeof e;return!!e&&("object"==t||"function"==t)}function r(e){return!!e&&"object"==typeof e}function u(e){return"symbol"==typeof e||r(e)&&m.call(e)==s}function a(e){if("number"==typeof e)return e;if(u(e))return c;if(o(e)){var t=i(e.valueOf)?e.valueOf():e;e=o(t)?t+"":t}if("string"!=typeof e)return 0===e?e:+e;e=e.replace(p,"");var n=w.test(e);return n||h.test(e)?g(e.slice(2),n?2:8):v.test(e)?c:+e}var f="Expected a function",c=NaN,l="[object Function]",d="[object GeneratorFunction]",s="[object Symbol]",p=/^\s+|\s+$/g,v=/^[-+]0x[0-9a-f]+$/i,w=/^0b[01]+$/i,h=/^0o[0-7]+$/i,g=parseInt,y=Object.prototype,m=y.toString,b=Math.max,O=Math.min,j=Date.now;e.exports=n},function(e,t){"use strict";t.__esModule=!0;var n=function(e){if("string"==typeof e)return e;if(e)return e.displayName||e.name||"Component"};t.default=n},function(e,t,n){"use strict";function i(e){return e&&e.__esModule?e:{"default":e}}t.__esModule=!0;var o=n(2),r=i(o);t.default=r.default},function(e,t,n){"use strict";function i(e){return e&&e.__esModule?e:{"default":e}}t.__esModule=!0;var o=n(4),r=i(o),u=function(e,t){return t+"("+(0,r.default)(e)+")"};t.default=u},function(t,n){t.exports=e}])}); |
@@ -268,4 +268,4 @@ 'use strict'; | ||
this.mounted = false; | ||
window.removeEventListener('resize', this.debouncedUpdateResize); | ||
window.removeEventListener('scroll', this.debouncedUpdateScroll); | ||
window.removeEventListener('resize', this.debouncedUpdateResize, { passive: true }); | ||
window.removeEventListener('scroll', this.debouncedUpdateScroll, { passive: true }); | ||
} | ||
@@ -272,0 +272,0 @@ } |
{ | ||
"name": "react-within-viewport", | ||
"version": "1.2.2", | ||
"version": "1.2.3", | ||
"description": "Debounced React high order component to flag when it's container is inside the viewport.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -122,4 +122,4 @@ import React, { Component } from 'react' | ||
this.mounted = false | ||
window.removeEventListener('resize', this.debouncedUpdateResize) | ||
window.removeEventListener('scroll', this.debouncedUpdateScroll) | ||
window.removeEventListener('resize', this.debouncedUpdateResize, { passive: true }) | ||
window.removeEventListener('scroll', this.debouncedUpdateScroll, { passive: true }) | ||
} | ||
@@ -126,0 +126,0 @@ } |
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
39095