Comparing version 3.1.1 to 4.0.0
@@ -1,2 +0,2 @@ | ||
function t(t,e){var i=this;this.container=t,this.observers=[],this.lastX=0,this.lastY=0;var o=!1,n=function(){o||(o=!0,requestAnimationFrame(function(){for(var t=i.observers,e=i.getState(),n=t.length;n--;)t[n].check(e);i.lastX=e.positionX,i.lastY=e.positionY,o=!1}))},r=e.handleScrollResize,s=this.handler=r?r(n):n,h=function(){(i.mutationObserver=new MutationObserver(n)).observe(document,{attributes:!0,childList:!0,subtree:!0})};addEventListener("scroll",s,!0),addEventListener("resize",s,!0),"loading"!==document.readyState?h():addEventListener("DOMContentLoaded",h)}function e(t){return this.offset=~~t.offset||0,this.container=t.container||document.body,this.once=Boolean(t.once),this.observerCollection=t.observerCollection||o,this.activate()}function i(t){for(var e=arguments.length,o=Array(e);e--;)o[e]=arguments[e];if(void 0===t&&(t={}),!(this instanceof i))return new(Function.prototype.bind.apply(i,[null].concat(o)));this.viewports=new Map,this.handleScrollResize=t.handleScrollResize}t.prototype={getState:function(){var t,e,i,o,n=this.container,r=this.lastX,s=this.lastY;return n===document.body?(t=window.innerWidth,e=window.innerHeight,i=window.pageXOffset,o=window.pageYOffset):(t=n.offsetWidth,e=n.offsetHeight,i=n.scrollLeft,o=n.scrollTop),{width:t,height:e,positionX:i,positionY:o,directionX:r<i?"right":r>i?"left":"none",directionY:s<o?"down":s>o?"up":"none"}},destroy:function(){var t=this.handler,e=this.mutationObserver;removeEventListener("scroll",t),removeEventListener("resize",t),e&&e.disconnect()}},e.prototype={activate:function(){var e=this.container,i=this.observerCollection,o=i.viewports,n=o.get(e);n||(n=new t(e,i),o.set(e,n));var r=n.observers;return r.indexOf(this)<0&&r.push(this),n},destroy:function(){var t=this.container,e=this.observerCollection.viewports,i=e.get(t);if(i){var o=i.observers,n=o.indexOf(this);n>-1&&o.splice(n,1),o.length||(i.destroy(),e.delete(t))}}};var o=new i;function n(t){for(var i=arguments.length,o=Array(i);i--;)o[i]=arguments[i];if(void 0===t&&(t={}),!(this instanceof n))return new(Function.prototype.bind.apply(n,[null].concat(o)));this.onTop=t.onTop,this.onBottom=t.onBottom,this.onLeft=t.onLeft,this.onRight=t.onRight,this.onMaximized=t.onMaximized,this._wasTop=!0,this._wasBottom=!1,this._wasLeft=!0,this._wasRight=!1;var r=e.call(this,t);this.check(r.getState())}function r(t,i){for(var o=arguments.length,n=Array(o);o--;)n[o]=arguments[o];if(void 0===i&&(i={}),!(this instanceof r))return new(Function.prototype.bind.apply(r,[null].concat(n)));this.element=t,this.onEnter=i.onEnter,this.onExit=i.onExit,this._didEnter=!1;var h=e.call(this,i);s(t)&&this.check(h.getState())}function s(t){return t&&t.parentNode}n.prototype=Object.create(e.prototype),n.prototype.constructor=n,n.prototype.check=function(t){var e=this,i=e.onTop,o=e.onBottom,n=e.onLeft,r=e.onRight,s=e.onMaximized,h=e._wasTop,a=e._wasBottom,c=e._wasLeft,l=e._wasRight,d=e.container,f=e.offset,p=e.once,u=d.scrollHeight,v=d.scrollWidth,w=t.width,g=t.height,y=t.positionX,b=t.positionY,m=b-f<=0,_=u>g&&g+b+f>=u,E=y-f<=0,L=v>w&&w+y+f>=v,R=!1;o&&!a&&_?o.call(this,d,t):i&&!h&&m?i.call(this,d,t):r&&!l&&L?r.call(this,d,t):n&&!c&&E?n.call(this,d,t):s&&u===g?s.call(this,d,t):R=!0,p&&!R&&this.destroy(),this._wasTop=m,this._wasBottom=_,this._wasLeft=E,this._wasRight=L},r.prototype=Object.create(e.prototype),r.prototype.constructor=r,r.prototype.check=function(t){var e=this.container,i=this.onEnter,o=this.onExit,n=this.element,r=this.offset,h=this.once,a=this._didEnter;if(!s(n))return this.destroy();var c=function(t,e,i,o){var n,r,s,h,a=t.getBoundingClientRect();if(!a.width||!a.height)return!1;var c=window.innerWidth,l=window.innerHeight,d=c;if(o===document.body)n=l,r=0,s=d,h=0;else{var f=a.top<l&&a.bottom>0&&a.left<d&&a.right>0;if(!f)return!1;var p=o.getBoundingClientRect();n=p.bottom,r=p.top,s=p.right,h=p.left}return a.top<n+e&&a.bottom>r-e&&a.left<s+e&&a.right>h-e}(n,r,0,e);!a&&c?(this._didEnter=!0,i&&(i.call(this,n,t),h&&this.destroy())):a&&!c&&(this._didEnter=!1,o&&(o.call(this,n,t),h&&this.destroy()))};export{r as ElementObserver,i as ObserverCollection,n as PositionObserver}; | ||
function t(t,e){var i=this;this.container=t,this.observers=[],this.lastX=0,this.lastY=0;var o=!1,n=function(){o||(o=!0,requestAnimationFrame((function(){for(var t=i.observers,e=i.getState(),n=t.length;n--;)t[n].check(e);i.lastX=e.positionX,i.lastY=e.positionY,o=!1})))},s=e.handleScrollResize,r=this.handler=s?s(n):n,h=function(){(i.mutationObserver=new MutationObserver(n)).observe(document,{attributes:!0,childList:!0,subtree:!0})};addEventListener("scroll",r,!0),addEventListener("resize",r,!0),"loading"!==document.readyState?h():addEventListener("DOMContentLoaded",h)}function e(t){return this.offset=~~t.offset||0,this.container=t.container||document.body,this.once=Boolean(t.once),this.observerCollection=t.observerCollection||o,this.activate()}function i(t){if(void 0===t&&(t={}),!(this instanceof i))return new i(t);this.viewports=new Map,this.handleScrollResize=t.handleScrollResize}t.prototype={getState:function(){var t,e,i,o,n=this.container,s=this.lastX,r=this.lastY;return n===document.body?(t=window.innerWidth,e=window.innerHeight,i=window.pageXOffset,o=window.pageYOffset):(t=n.offsetWidth,e=n.offsetHeight,i=n.scrollLeft,o=n.scrollTop),{width:t,height:e,positionX:i,positionY:o,directionX:s<i?"right":s>i?"left":"none",directionY:r<o?"down":r>o?"up":"none"}},destroy:function(){var t=this.handler,e=this.mutationObserver;removeEventListener("scroll",t),removeEventListener("resize",t),e&&e.disconnect()}},e.prototype={activate:function(){var e=this.container,i=this.observerCollection,o=i.viewports,n=o.get(e);n||(n=new t(e,i),o.set(e,n));var s=n.observers;return s.indexOf(this)<0&&s.push(this),n},destroy:function(){var t=this.container,e=this.observerCollection.viewports,i=e.get(t);if(i){var o=i.observers,n=o.indexOf(this);n>-1&&o.splice(n,1),o.length||(i.destroy(),e.delete(t))}}};var o=new i;function n(t){if(void 0===t&&(t={}),!(this instanceof n))return new n(t);this.onTop=t.onTop,this.onBottom=t.onBottom,this.onLeft=t.onLeft,this.onRight=t.onRight,this.onFit=t.onFit,this._wasTop=!0,this._wasBottom=!1,this._wasLeft=!0,this._wasRight=!1,this._wasFit=!1;var i=e.call(this,t);this.check(i.getState())}function s(t,i){if(void 0===i&&(i={}),!(this instanceof s))return new s(t,i);this.element=t,this.onEnter=i.onEnter,this.onExit=i.onExit,this._didEnter=!1;var o=e.call(this,i);r(t)&&this.check(o.getState())}function r(t){return t&&t.parentNode}n.prototype=Object.create(e.prototype),n.prototype.constructor=n,n.prototype.check=function(t){var e=this,i=e.onTop,o=e.onBottom,n=e.onLeft,s=e.onRight,r=e.onFit,h=e._wasTop,a=e._wasBottom,c=e._wasLeft,l=e._wasRight,d=e._wasFit,f=e.container,p=e.offset,v=e.once,u=f.scrollHeight,w=f.scrollWidth,g=t.width,b=t.height,m=t.positionX,y=t.positionY,_=y-p<=0,E=u>b&&b+y+p>=u,L=m-p<=0,R=w>g&&g+m+p>=w,O=u<=b&&w<=g,B=!1;o&&!a&&E?o.call(this,f,t):i&&!h&&_?i.call(this,f,t):s&&!l&&R?s.call(this,f,t):n&&!c&&L?n.call(this,f,t):r&&!d&&O?r.call(this,f,t):B=!0,v&&!B&&this.destroy(),this._wasTop=_,this._wasBottom=E,this._wasLeft=L,this._wasRight=R,this._wasFit=O},s.prototype=Object.create(e.prototype),s.prototype.constructor=s,s.prototype.check=function(t){var e=this.container,i=this.onEnter,o=this.onExit,n=this.element,s=this.offset,h=this.once,a=this._didEnter;if(!r(n))return this.destroy();var c=function(t,e,i,o){var n,s,r,h,a=t.getBoundingClientRect();if(!a.width||!a.height)return!1;var c=window.innerWidth,l=window.innerHeight,d=c;if(o===document.body)n=l,s=0,r=d,h=0;else{if(!(a.top<l&&a.bottom>0&&a.left<d&&a.right>0))return!1;var f=o.getBoundingClientRect();n=f.bottom,s=f.top,r=f.right,h=f.left}return a.top<n+e&&a.bottom>s-e&&a.left<r+e&&a.right>h-e}(n,s,0,e);!a&&c?(this._didEnter=!0,i&&(i.call(this,n,t),h&&this.destroy())):a&&!c&&(this._didEnter=!1,o&&(o.call(this,n,t),h&&this.destroy()))};export{s as ElementObserver,i as ObserverCollection,n as PositionObserver}; | ||
//# sourceMappingURL=viewprt.esm.js.map |
@@ -1,2 +0,2 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t=t||self).viewprt={})}(this,function(t){"use strict";function e(t,e){var o=this;this.container=t,this.observers=[],this.lastX=0,this.lastY=0;var i=!1,n=function(){i||(i=!0,requestAnimationFrame(function(){for(var t=o.observers,e=o.getState(),n=t.length;n--;)t[n].check(e);o.lastX=e.positionX,o.lastY=e.positionY,i=!1}))},r=e.handleScrollResize,s=this.handler=r?r(n):n,h=function(){(o.mutationObserver=new MutationObserver(n)).observe(document,{attributes:!0,childList:!0,subtree:!0})};addEventListener("scroll",s,!0),addEventListener("resize",s,!0),"loading"!==document.readyState?h():addEventListener("DOMContentLoaded",h)}function o(t){return this.offset=~~t.offset||0,this.container=t.container||document.body,this.once=Boolean(t.once),this.observerCollection=t.observerCollection||n,this.activate()}function i(t){for(var e=arguments.length,o=Array(e);e--;)o[e]=arguments[e];if(void 0===t&&(t={}),!(this instanceof i))return new(Function.prototype.bind.apply(i,[null].concat(o)));this.viewports=new Map,this.handleScrollResize=t.handleScrollResize}e.prototype={getState:function(){var t,e,o,i,n=this.container,r=this.lastX,s=this.lastY;return n===document.body?(t=window.innerWidth,e=window.innerHeight,o=window.pageXOffset,i=window.pageYOffset):(t=n.offsetWidth,e=n.offsetHeight,o=n.scrollLeft,i=n.scrollTop),{width:t,height:e,positionX:o,positionY:i,directionX:r<o?"right":r>o?"left":"none",directionY:s<i?"down":s>i?"up":"none"}},destroy:function(){var t=this.handler,e=this.mutationObserver;removeEventListener("scroll",t),removeEventListener("resize",t),e&&e.disconnect()}},o.prototype={activate:function(){var t=this.container,o=this.observerCollection,i=o.viewports,n=i.get(t);n||(n=new e(t,o),i.set(t,n));var r=n.observers;return r.indexOf(this)<0&&r.push(this),n},destroy:function(){var t=this.container,e=this.observerCollection.viewports,o=e.get(t);if(o){var i=o.observers,n=i.indexOf(this);n>-1&&i.splice(n,1),i.length||(o.destroy(),e.delete(t))}}};var n=new i;function r(t){for(var e=arguments.length,i=Array(e);e--;)i[e]=arguments[e];if(void 0===t&&(t={}),!(this instanceof r))return new(Function.prototype.bind.apply(r,[null].concat(i)));this.onTop=t.onTop,this.onBottom=t.onBottom,this.onLeft=t.onLeft,this.onRight=t.onRight,this.onMaximized=t.onMaximized,this._wasTop=!0,this._wasBottom=!1,this._wasLeft=!0,this._wasRight=!1;var n=o.call(this,t);this.check(n.getState())}function s(t,e){for(var i=arguments.length,n=Array(i);i--;)n[i]=arguments[i];if(void 0===e&&(e={}),!(this instanceof s))return new(Function.prototype.bind.apply(s,[null].concat(n)));this.element=t,this.onEnter=e.onEnter,this.onExit=e.onExit,this._didEnter=!1;var r=o.call(this,e);h(t)&&this.check(r.getState())}function h(t){return t&&t.parentNode}r.prototype=Object.create(o.prototype),r.prototype.constructor=r,r.prototype.check=function(t){var e=this,o=e.onTop,i=e.onBottom,n=e.onLeft,r=e.onRight,s=e.onMaximized,h=e._wasTop,a=e._wasBottom,c=e._wasLeft,l=e._wasRight,d=e.container,f=e.offset,p=e.once,u=d.scrollHeight,v=d.scrollWidth,w=t.width,g=t.height,y=t.positionX,b=t.positionY,m=b-f<=0,_=u>g&&g+b+f>=u,E=y-f<=0,L=v>w&&w+y+f>=v,O=!1;i&&!a&&_?i.call(this,d,t):o&&!h&&m?o.call(this,d,t):r&&!l&&L?r.call(this,d,t):n&&!c&&E?n.call(this,d,t):s&&u===g?s.call(this,d,t):O=!0,p&&!O&&this.destroy(),this._wasTop=m,this._wasBottom=_,this._wasLeft=E,this._wasRight=L},s.prototype=Object.create(o.prototype),s.prototype.constructor=s,s.prototype.check=function(t){var e=this.container,o=this.onEnter,i=this.onExit,n=this.element,r=this.offset,s=this.once,a=this._didEnter;if(!h(n))return this.destroy();var c=function(t,e,o,i){var n,r,s,h,a=t.getBoundingClientRect();if(!a.width||!a.height)return!1;var c=window.innerWidth,l=window.innerHeight,d=c;if(i===document.body)n=l,r=0,s=d,h=0;else{var f=a.top<l&&a.bottom>0&&a.left<d&&a.right>0;if(!f)return!1;var p=i.getBoundingClientRect();n=p.bottom,r=p.top,s=p.right,h=p.left}return a.top<n+e&&a.bottom>r-e&&a.left<s+e&&a.right>h-e}(n,r,0,e);!a&&c?(this._didEnter=!0,o&&(o.call(this,n,t),s&&this.destroy())):a&&!c&&(this._didEnter=!1,i&&(i.call(this,n,t),s&&this.destroy()))},t.ElementObserver=s,t.ObserverCollection=i,t.PositionObserver=r,Object.defineProperty(t,"__esModule",{value:!0})}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t=t||self).viewprt={})}(this,(function(t){"use strict";function e(t,e){var i=this;this.container=t,this.observers=[],this.lastX=0,this.lastY=0;var o=!1,n=function(){o||(o=!0,requestAnimationFrame((function(){for(var t=i.observers,e=i.getState(),n=t.length;n--;)t[n].check(e);i.lastX=e.positionX,i.lastY=e.positionY,o=!1})))},s=e.handleScrollResize,r=this.handler=s?s(n):n,h=function(){(i.mutationObserver=new MutationObserver(n)).observe(document,{attributes:!0,childList:!0,subtree:!0})};addEventListener("scroll",r,!0),addEventListener("resize",r,!0),"loading"!==document.readyState?h():addEventListener("DOMContentLoaded",h)}function i(t){return this.offset=~~t.offset||0,this.container=t.container||document.body,this.once=Boolean(t.once),this.observerCollection=t.observerCollection||n,this.activate()}function o(t){if(void 0===t&&(t={}),!(this instanceof o))return new o(t);this.viewports=new Map,this.handleScrollResize=t.handleScrollResize}e.prototype={getState:function(){var t,e,i,o,n=this.container,s=this.lastX,r=this.lastY;return n===document.body?(t=window.innerWidth,e=window.innerHeight,i=window.pageXOffset,o=window.pageYOffset):(t=n.offsetWidth,e=n.offsetHeight,i=n.scrollLeft,o=n.scrollTop),{width:t,height:e,positionX:i,positionY:o,directionX:s<i?"right":s>i?"left":"none",directionY:r<o?"down":r>o?"up":"none"}},destroy:function(){var t=this.handler,e=this.mutationObserver;removeEventListener("scroll",t),removeEventListener("resize",t),e&&e.disconnect()}},i.prototype={activate:function(){var t=this.container,i=this.observerCollection,o=i.viewports,n=o.get(t);n||(n=new e(t,i),o.set(t,n));var s=n.observers;return s.indexOf(this)<0&&s.push(this),n},destroy:function(){var t=this.container,e=this.observerCollection.viewports,i=e.get(t);if(i){var o=i.observers,n=o.indexOf(this);n>-1&&o.splice(n,1),o.length||(i.destroy(),e.delete(t))}}};var n=new o;function s(t){if(void 0===t&&(t={}),!(this instanceof s))return new s(t);this.onTop=t.onTop,this.onBottom=t.onBottom,this.onLeft=t.onLeft,this.onRight=t.onRight,this.onFit=t.onFit,this._wasTop=!0,this._wasBottom=!1,this._wasLeft=!0,this._wasRight=!1,this._wasFit=!1;var e=i.call(this,t);this.check(e.getState())}function r(t,e){if(void 0===e&&(e={}),!(this instanceof r))return new r(t,e);this.element=t,this.onEnter=e.onEnter,this.onExit=e.onExit,this._didEnter=!1;var o=i.call(this,e);h(t)&&this.check(o.getState())}function h(t){return t&&t.parentNode}s.prototype=Object.create(i.prototype),s.prototype.constructor=s,s.prototype.check=function(t){var e=this,i=e.onTop,o=e.onBottom,n=e.onLeft,s=e.onRight,r=e.onFit,h=e._wasTop,a=e._wasBottom,c=e._wasLeft,l=e._wasRight,d=e._wasFit,f=e.container,p=e.offset,u=e.once,v=f.scrollHeight,w=f.scrollWidth,g=t.width,b=t.height,m=t.positionX,y=t.positionY,_=y-p<=0,E=v>b&&b+y+p>=v,L=m-p<=0,O=w>g&&g+m+p>=w,R=v<=b&&w<=g,B=!1;o&&!a&&E?o.call(this,f,t):i&&!h&&_?i.call(this,f,t):s&&!l&&O?s.call(this,f,t):n&&!c&&L?n.call(this,f,t):r&&!d&&R?r.call(this,f,t):B=!0,u&&!B&&this.destroy(),this._wasTop=_,this._wasBottom=E,this._wasLeft=L,this._wasRight=O,this._wasFit=R},r.prototype=Object.create(i.prototype),r.prototype.constructor=r,r.prototype.check=function(t){var e=this.container,i=this.onEnter,o=this.onExit,n=this.element,s=this.offset,r=this.once,a=this._didEnter;if(!h(n))return this.destroy();var c=function(t,e,i,o){var n,s,r,h,a=t.getBoundingClientRect();if(!a.width||!a.height)return!1;var c=window.innerWidth,l=window.innerHeight,d=c;if(o===document.body)n=l,s=0,r=d,h=0;else{if(!(a.top<l&&a.bottom>0&&a.left<d&&a.right>0))return!1;var f=o.getBoundingClientRect();n=f.bottom,s=f.top,r=f.right,h=f.left}return a.top<n+e&&a.bottom>s-e&&a.left<r+e&&a.right>h-e}(n,s,0,e);!a&&c?(this._didEnter=!0,i&&(i.call(this,n,t),r&&this.destroy())):a&&!c&&(this._didEnter=!1,o&&(o.call(this,n,t),r&&this.destroy()))},t.ElementObserver=r,t.ObserverCollection=o,t.PositionObserver=s,Object.defineProperty(t,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=viewprt.umd.js.map |
{ | ||
"name": "viewprt", | ||
"version": "3.1.1", | ||
"version": "4.0.0", | ||
"description": "A tiny, dependency-free, high performance viewport position & intersection observation tool", | ||
@@ -34,9 +34,9 @@ "author": "Garth Poitras <garth22@gmail.com>", | ||
"devDependencies": { | ||
"flt": "^0.15.0", | ||
"puppeteer": "^1.18.1", | ||
"rollup": "^1.17.0", | ||
"flt": "^0.17.0", | ||
"puppeteer": "^1.20.0", | ||
"rollup": "^1.21.2", | ||
"rollup-plugin-buble": "^0.19.8", | ||
"rollup-plugin-replace": "^2.2.0", | ||
"rollup-plugin-terser": "^5.1.1" | ||
"rollup-plugin-terser": "^5.1.2" | ||
} | ||
} |
@@ -40,3 +40,3 @@ # viewprt [](https://travis-ci.org/gpoitch/viewprt) | ||
onRight(container, viewport) {}, // callback when the viewport reaches the right | ||
onMaximized(container, viewport) {}, // callback when the viewport and container are the same size | ||
onFit(container, viewport) {}, // callback when the viewport contents fit within the container without having to scroll | ||
container: document.body, // the viewport element to observe the position of | ||
@@ -43,0 +43,0 @@ offset: 0, // offset from the edges of the viewport in pixels |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
42780
33