UNPKG

7.28 kBJavaScriptView Raw
1System.register([],(function(){"use strict";return{execute:function(){(function(){if(typeof window!=="object"){return}if("IntersectionObserver"in window&&"IntersectionObserverEntry"in window&&"intersectionRatio"in window.IntersectionObserverEntry.prototype){if(!("isIntersecting"in window.IntersectionObserverEntry.prototype)){Object.defineProperty(window.IntersectionObserverEntry.prototype,"isIntersecting",{get:function(){return this.intersectionRatio>0}})}return}var t=window.document;function e(t){this.time=t.time;this.target=t.target;this.rootBounds=t.rootBounds;this.boundingClientRect=t.boundingClientRect;this.intersectionRect=t.intersectionRect||a();this.isIntersecting=!!t.intersectionRect;var e=this.boundingClientRect;var n=e.width*e.height;var r=this.intersectionRect;var i=r.width*r.height;if(n){this.intersectionRatio=Number((i/n).toFixed(4))}else{this.intersectionRatio=this.isIntersecting?1:0}}function n(t,e){var n=e||{};if(typeof t!="function"){throw new Error("callback must be a function")}if(n.root&&n.root.nodeType!=1){throw new Error("root must be an Element")}this._checkForIntersections=i(this._checkForIntersections.bind(this),this.THROTTLE_TIMEOUT);this._callback=t;this._observationTargets=[];this._queuedEntries=[];this._rootMarginValues=this._parseRootMargin(n.rootMargin);this.thresholds=this._initThresholds(n.threshold);this.root=n.root||null;this.rootMargin=this._rootMarginValues.map((function(t){return t.value+t.unit})).join(" ")}n.prototype.THROTTLE_TIMEOUT=100;n.prototype.POLL_INTERVAL=null;n.prototype.USE_MUTATION_OBSERVER=true;n.prototype.observe=function(t){var e=this._observationTargets.some((function(e){return e.element==t}));if(e){return}if(!(t&&t.nodeType==1)){throw new Error("target must be an Element")}this._registerInstance();this._observationTargets.push({element:t,entry:null});this._monitorIntersections();this._checkForIntersections()};n.prototype.unobserve=function(t){this._observationTargets=this._observationTargets.filter((function(e){return e.element!=t}));if(!this._observationTargets.length){this._unmonitorIntersections();this._unregisterInstance()}};n.prototype.disconnect=function(){this._observationTargets=[];this._unmonitorIntersections();this._unregisterInstance()};n.prototype.takeRecords=function(){var t=this._queuedEntries.slice();this._queuedEntries=[];return t};n.prototype._initThresholds=function(t){var e=t||[0];if(!Array.isArray(e))e=[e];return e.sort().filter((function(t,e,n){if(typeof t!="number"||isNaN(t)||t<0||t>1){throw new Error("threshold must be a number between 0 and 1 inclusively")}return t!==n[e-1]}))};n.prototype._parseRootMargin=function(t){var e=t||"0px";var n=e.split(/\s+/).map((function(t){var e=/^(-?\d*\.?\d+)(px|%)$/.exec(t);if(!e){throw new Error("rootMargin must be specified in pixels or percent")}return{value:parseFloat(e[1]),unit:e[2]}}));n[1]=n[1]||n[0];n[2]=n[2]||n[0];n[3]=n[3]||n[1];return n};n.prototype._monitorIntersections=function(){if(!this._monitoringIntersections){this._monitoringIntersections=true;if(this.POLL_INTERVAL){this._monitoringInterval=setInterval(this._checkForIntersections,this.POLL_INTERVAL)}else{o(window,"resize",this._checkForIntersections,true);o(t,"scroll",this._checkForIntersections,true);if(this.USE_MUTATION_OBSERVER&&"MutationObserver"in window){this._domObserver=new MutationObserver(this._checkForIntersections);this._domObserver.observe(t,{attributes:true,childList:true,characterData:true,subtree:true})}}}};n.prototype._unmonitorIntersections=function(){if(this._monitoringIntersections){this._monitoringIntersections=false;clearInterval(this._monitoringInterval);this._monitoringInterval=null;s(window,"resize",this._checkForIntersections,true);s(t,"scroll",this._checkForIntersections,true);if(this._domObserver){this._domObserver.disconnect();this._domObserver=null}}};n.prototype._checkForIntersections=function(){var t=this._rootIsInDom();var n=t?this._getRootRect():a();this._observationTargets.forEach((function(i){var o=i.element;var s=c(o);var h=this._rootContainsTarget(o);var a=i.entry;var u=t&&h&&this._computeTargetAndRootIntersection(o,n);var f=i.entry=new e({time:r(),target:o,boundingClientRect:s,rootBounds:n,intersectionRect:u});if(!a){this._queuedEntries.push(f)}else if(t&&h){if(this._hasCrossedThreshold(a,f)){this._queuedEntries.push(f)}}else{if(a&&a.isIntersecting){this._queuedEntries.push(f)}}}),this);if(this._queuedEntries.length){this._callback(this.takeRecords(),this)}};n.prototype._computeTargetAndRootIntersection=function(e,n){if(window.getComputedStyle(e).display=="none")return;var r=c(e);var i=r;var o=f(e);var s=false;while(!s){var a=null;var u=o.nodeType==1?window.getComputedStyle(o):{};if(u.display=="none")return;if(o==this.root||o==t){s=true;a=n}else{if(o!=t.body&&o!=t.documentElement&&u.overflow!="visible"){a=c(o)}}if(a){i=h(a,i);if(!i)break}o=f(o)}return i};n.prototype._getRootRect=function(){var e;if(this.root){e=c(this.root)}else{var n=t.documentElement;var r=t.body;e={top:0,left:0,right:n.clientWidth||r.clientWidth,width:n.clientWidth||r.clientWidth,bottom:n.clientHeight||r.clientHeight,height:n.clientHeight||r.clientHeight}}return this._expandRectByRootMargin(e)};n.prototype._expandRectByRootMargin=function(t){var e=this._rootMarginValues.map((function(e,n){return e.unit=="px"?e.value:e.value*(n%2?t.width:t.height)/100}));var n={top:t.top-e[0],right:t.right+e[1],bottom:t.bottom+e[2],left:t.left-e[3]};n.width=n.right-n.left;n.height=n.bottom-n.top;return n};n.prototype._hasCrossedThreshold=function(t,e){var n=t&&t.isIntersecting?t.intersectionRatio||0:-1;var r=e.isIntersecting?e.intersectionRatio||0:-1;if(n===r)return;for(var i=0;i<this.thresholds.length;i++){var o=this.thresholds[i];if(o==n||o==r||o<n!==o<r){return true}}};n.prototype._rootIsInDom=function(){return!this.root||u(t,this.root)};n.prototype._rootContainsTarget=function(e){return u(this.root||t,e)};n.prototype._registerInstance=function(){};n.prototype._unregisterInstance=function(){};function r(){return window.performance&&performance.now&&performance.now()}function i(t,e){var n=null;return function(){if(!n){n=setTimeout((function(){t();n=null}),e)}}}function o(t,e,n,r){if(typeof t.addEventListener=="function"){t.addEventListener(e,n,r||false)}else if(typeof t.attachEvent=="function"){t.attachEvent("on"+e,n)}}function s(t,e,n,r){if(typeof t.removeEventListener=="function"){t.removeEventListener(e,n,r||false)}else if(typeof t.detatchEvent=="function"){t.detatchEvent("on"+e,n)}}function h(t,e){var n=Math.max(t.top,e.top);var r=Math.min(t.bottom,e.bottom);var i=Math.max(t.left,e.left);var o=Math.min(t.right,e.right);var s=o-i;var h=r-n;return s>=0&&h>=0&&{top:n,bottom:r,left:i,right:o,width:s,height:h}}function c(t){var e;try{e=t.getBoundingClientRect()}catch(t){}if(!e)return a();if(!(e.width&&e.height)){e={top:e.top,right:e.right,bottom:e.bottom,left:e.left,width:e.right-e.left,height:e.bottom-e.top}}return e}function a(){return{top:0,bottom:0,left:0,right:0,width:0,height:0}}function u(t,e){var n=e;while(n){if(n==t)return true;n=f(n)}return false}function f(t){var e=t.parentNode;if(e&&e.nodeType==11&&e.host){return e.host}if(e&&e.assignedSlot){return e.assignedSlot.parentNode}return e}window.IntersectionObserver=n;window.IntersectionObserverEntry=e})()}}}));
\No newline at end of file