hd-intersection-observer
Version:
An abstract layer that would make using intersection observer easier
3 lines (2 loc) • 1.64 kB
JavaScript
;Object.defineProperty(exports,"__esModule",{value:!0});var e=new Map,t=new WeakMap,r=0,n=void 0;function o(e){return Object.keys(e).sort().filter((function(t){return void 0!==e[t]})).map((function(n){return n+"_"+("root"===n?(o=e.root)?(t.has(o)||t.set(o,(r+=1).toString()),t.get(o)):"0":e[n]);var o})).toString()}exports.default=function(t,r,i,s){void 0===i&&(i={rootMargin:"0px",threshold:.5}),void 0===s&&(s=n);var c=Array.isArray(t)?t:[t];if(void 0===window.IntersectionObserver&&void 0!==s)return c.forEach((function(e){var t=e.getBoundingClientRect();r(s,{isIntersecting:s,target:e,intersectionRatio:"number"==typeof i.threshold?i.threshold:0,time:0,boundingClientRect:t,intersectionRect:t,rootBounds:t})})),function(){};var a=function(t){var r=o(t),n=e.get(r);if(!n){var i,s=new Map,c=new IntersectionObserver((function(e){e.forEach((function(r){var n,o=r.isIntersecting&&i.some((function(e){return r.intersectionRatio>=e}));t.trackVisibility&&void 0===r.isVisible&&(r.isVisible=o),null==(n=s.get(r.target))||n.forEach((function(t){t(o,r,e)}))}))}),t);i=c.thresholds||(Array.isArray(t.threshold)?t.threshold:[t.threshold||0]),e.set(r,n={id:r,observer:c,elements:s})}return n}(i),u=a.id,d=a.observer,f=a.elements;return c.forEach((function(e){var t=f.get(e)||[];f.has(e)||f.set(e,t),t.push(r),d.observe(e)})),function(){c.forEach((function(t){var n=f.get(t)||[];n.splice(n.indexOf(r),1),0===n.length&&(f.delete(t),d.unobserve(t)),0===f.size&&(d.disconnect(),e.delete(u))}))}},exports.defaultFallbackInView=function(e){n=e},exports.optionsToId=o;
//# sourceMappingURL=hd-intersection-observer.cjs.production.min.js.map