class Stacky{constructor(t="header"){this.headers=document.querySelectorAll(t),this.headerArray=[]}init(){let t=0,e=this.headers.length-1;this.headers.forEach((o=>{o.setAttribute("data-stacky-id",`${t}`),o.setAttribute("data-stacky-top",`${t}`),o.setAttribute("data-stacky-bottom",`${e}`),this.headerArray.push({el:o,id:t,orderTop:t,orderBottom:e,parent:o.parentElement,height:o.clientHeight,position:"",offsetTop:o.clientHeight*t,offsetBottom:o.clientHeight*e}),t++,e--})),window.addEventListener("scroll",(t=>{this.headerArray.forEach((t=>{this.updateStack(t)}))}))}updateStack(t){let e="";const o=document.querySelector(`[data-stacky-id="${t.id}"]`),i=o.parentElement.getBoundingClientRect().top;i-o.clientHeight*t.orderTop<=0?e="top":i+o.clientHeight*(t.orderBottom+1)>=document.documentElement.clientHeight&&(e="bottom"),e?"top"===e?(t.position="top",o.style.position="fixed",o.style.top=`${t.offsetTop}px`,o.style.bottom="",o.parentElement.style.paddingTop=`${t.height}px`):"bottom"===e&&(t.position="bottom",o.style.position="fixed",o.style.top="",o.style.bottom=`${t.offsetBottom}px`,o.parentElement.style.paddingTop=`${t.height}px`):(o.style.position="",o.style.top="",o.style.width="",o.parentElement.style.paddingTop="")}}"undefined"!=typeof window&&(window.Stacky=Stacky);