define(["exports","../browser.js","../dom.js","../visibleinviewport.js"],function(_exports,_browser,_dom,_visibleinviewport){var thresholdX,thresholdY;Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,_browser=babelHelpers.interopRequireDefault(_browser),_dom=babelHelpers.interopRequireDefault(_dom),_visibleinviewport=babelHelpers.interopRequireDefault(_visibleinviewport);window.requestIdleCallback;function resetThresholds(){thresholdX=.3*screen.availWidth,thresholdY=.3*screen.availHeight}function resetThresholdsOnTimer(){setTimeout(resetThresholds,500)}_browser.default.iOS?(_dom.default.addEventListener(window,"orientationchange",resetThresholdsOnTimer,{passive:!0}),_dom.default.addEventListener(window,"resize",resetThresholdsOnTimer,{passive:!0})):(_dom.default.addEventListener(window,"orientationchange",resetThresholds,{passive:!0}),_dom.default.addEventListener(window,"resize",resetThresholds,{passive:!0})),resetThresholds();var wheelEvent=document.implementation.hasFeature("Event.wheel","3.0")?"wheel":"mousewheel";var enableTimeoutHack=_browser.default.edge||_browser.default.safari;function unveilElementsInternal(instance,callback){var unveiledElements=[],cancellationTokens=[],loadedCount=0;function unveilInternal(tokenIndex){for(var elem,anyFound=!1,out=!1,elements=instance.elements,i=0,length=elements.length;i<length;i++){if(cancellationTokens[tokenIndex])return;unveiledElements[i]||(elem=elements[i],!out&&function(elem){return(0,_visibleinviewport.default)(elem,!0,thresholdX,thresholdY)}(elem)?(anyFound=!0,unveiledElements[i]=!0,callback(elem),loadedCount++):anyFound&&(out=!0))}loadedCount>=elements.length&&(_dom.default.removeEventListener(document,"focus",unveil,{capture:!0,passive:!0}),_dom.default.removeEventListener(document,"scroll",unveil,{capture:!0,passive:!0}),_dom.default.removeEventListener(document,wheelEvent,unveil,{capture:!0,passive:!0}),_dom.default.removeEventListener(window,"resize",unveil,{capture:!0,passive:!0}))}function unveil(){!function(tokens){for(var i=0,length=tokens.length;i<length;i++)tokens[i]=!0}(cancellationTokens);var index=cancellationTokens.length;cancellationTokens.length++,setTimeout(function(){unveilInternal(index)},1)}_dom.default.addEventListener(document,"focus",unveil,{capture:!0,passive:!0}),_dom.default.addEventListener(document,"scroll",unveil,{capture:!0,passive:!0}),_dom.default.addEventListener(document,wheelEvent,unveil,{capture:!0,passive:!0}),_dom.default.addEventListener(window,"resize",unveil,{capture:!0,passive:!0}),unveil(),enableTimeoutHack&&setTimeout(unveil,100)}function LazyLoader(options){this.options=options}LazyLoader.prototype.createObserver=function(){unveilElementsInternal(this,this.options.callback),this.observer=1},LazyLoader.prototype.addElements=function(elements){this.elements=this.elements||[];for(var i=0,length=elements.length;i<length;i++)this.elements.push(elements[i]);this.observer||this.createObserver()},LazyLoader.prototype.destroyObserver=function(elements){},LazyLoader.prototype.destroy=function(elements){this.destroyObserver(),this.options=null},LazyLoader.lazyChildren=function(elem,callback){!function(elements,callback){elements.length&&new LazyLoader({callback:callback}).addElements(elements)}(elem.getElementsByClassName("lazy"),callback)},_exports.default=LazyLoader});