- Add DISCOVERY_LOG_LEVEL=debug - Add DISCOVERY_SHOW_PROGRESS=true - Temporary changes for debugging InitializerProcessor fixes on production
2 lines
2.5 KiB
JavaScript
2 lines
2.5 KiB
JavaScript
const e=new class{constructor(){this.triggers=new Set,this.viewportHeight=window.innerHeight,this._loop=this._loop.bind(this),window.addEventListener("resize",()=>{this.viewportHeight=window.innerHeight}),requestAnimationFrame(this._loop)}register(e){this.triggers.add(e)}unregister(e){this.triggers.delete(e)}clear(){this.triggers.clear()}_loop(){this.triggers.forEach(e=>{e.update(this.viewportHeight)}),requestAnimationFrame(this._loop)}};class t{constructor(e){if(this.element=this.resolveElement(e.element),this.target=e.target?this.element.querySelector(e.target):this.element,e.target&&!this.target)throw new Error(`Target selector '${e.target}' not found inside element '${e.element}'.`);this.start=e.start||"top 80%",this.end=e.end||"bottom 20%",this.scrub=e.scrub||!1,this.onEnter=e.onEnter||null,this.onLeave=e.onLeave||null,this.onUpdate=e.onUpdate||null,this._wasVisible=!1,this._progress=0}resolveElement(e){if("string"==typeof e){const t=document.querySelectorAll(e);if(1===t.length)return t[0];throw new Error(`Selector '${e}' matched ${t.length} elements, expected exactly 1.`)}return e}getScrollProgress(e){const t=this.element.getBoundingClientRect(),i=this.parsePosition(this.start,e),s=this.parsePosition(this.end,e)-i,r=t.top-i;return 1-Math.min(Math.max(r/s,0),1)}parsePosition(e,t){const[i,s]=e.split(" ");return("top"===i?0:t)-t*(parseFloat(s)/100)}update(e){const t=this.element.getBoundingClientRect(),i=t.bottom>0&&t.top<e;if(i&&!this._wasVisible&&(this._wasVisible=!0,this.onEnter&&this.onEnter(this.target)),!i&&this._wasVisible&&(this._wasVisible=!1,this.onLeave&&this.onLeave(this.target)),this.scrub&&i){const t=this.getScrollProgress(e);this.onUpdate&&this.onUpdate(this.target,t)}}}const i=Object.freeze(Object.defineProperty({__proto__:null,createTrigger:function(i){const s="string"==typeof i.element?document.querySelectorAll(i.element):[i.element],r=[];return s.forEach(s=>{const n=new t({...i,element:s});e.register(n),r.push(n)}),1===r.length?r[0]:r},init:function(e={}){const{selector:t=".fade-in-on-scroll, .zoom-in, .fade-out, .fade",offset:i=.85,baseDelay:s=.05,once:r=!0}=e,n=Array.from(document.querySelectorAll(t)).map(e=>({el:e,triggered:!1}));requestAnimationFrame(function e(){const t=window.innerHeight*i;n.forEach((e,i)=>{if(e.triggered&&r)return;e.el.getBoundingClientRect().top<t?(e.el.style.transitionDelay=i*s+"s",e.el.classList.add("visible","entered"),e.el.classList.remove("fade-out"),e.triggered=!0):r||(e.el.classList.remove("visible","entered"),e.triggered=!1)}),requestAnimationFrame(e)})}},Symbol.toStringTag,{value:"Module"}));export{i as _};
|