const l={STICKY_BEFORE:"sticky:before",STICKY_ACTIVE:"sticky:active",STICKY_AFTER:"sticky:after",OVERFLOWING:"overflowing",LINK_ACTIVE:"link:active"};class c extends HTMLElement{constructor(){super(...arguments),this.links=[],this.sections=[],this.isSmoothScrolling=!1,this.currentActiveLink=""}connectedCallback(){this.scroller=this.getSlotElement("scroller"),this.links=this.getSlotElements("link"),this.links.forEach(t=>{const e=t.getAttribute("href");if(e.startsWith("#")){const s=document.getElementById(e.slice(1));s&&this.sections.push(s),t.addEventListener("click",i=>this.onLinkClicked(i))}}),this.ctas=this.getSlotElement("ctas"),this.init()}init(){window.addEventListener("scroll",()=>this.onScroll(),{passive:!0}),window.addEventListener("resize",()=>this.onResize(),{passive:!0}),this.onScroll(),this.onResize(),this.scroller&&(this.scroller.addEventListener("scroll",()=>this.onScrollX(),{passive:!0}),this.onScrollX())}getActiveSection(){let t="";for(const e of this.sections)e.getBoundingClientRect().top<=window.innerHeight/2&&(t=e.id);return t?`#${t}`:""}onScroll(){if(this.isSmoothScrolling)return;const t=r(this);this.classList.toggle(l.STICKY_BEFORE,t>2),this.classList.toggle(l.STICKY_ACTIVE,t<2&&t>-2),this.classList.toggle(l.STICKY_AFTER,t<-2);const e=this.getActiveSection();let s;this.links.forEach(i=>{const n=i.getAttribute("href")===e;i.classList.toggle(l.LINK_ACTIVE,n),n&&(s=i)}),s&&this.currentActiveLink!==e&&this.scroller.scrollWidth>this.scroller.offsetWidth,this.currentActiveLink=e}onResize(){this.scroller&&this.classList.toggle(l.OVERFLOWING,this.scroller.scrollWidth>this.scroller.offsetWidth),this.ctas&&this.style.setProperty("--ctas-width",`${this.ctas.offsetWidth}px`),this.onScroll(),document.body.style.setProperty("--scroll-margin-top",`${this.offsetHeight+30}px`)}onScrollX(){}onLinkClicked(t){const s=t.target?.getAttribute("href");if(s&&s.startsWith("#")){const i=document.getElementById(s.slice(1));i&&(t.preventDefault(),this.isSmoothScrolling=!0,this.classList.add(l.STICKY_ACTIVE),i.scrollIntoView({block:"start",behavior:"smooth"}),setTimeout(()=>{if(this.isSmoothScrolling=!1,document.activeElement){const n=document.activeElement;n.blur&&n.blur()}this.onScroll()},750))}}getSlotElement(t){return this.querySelector(`[data-slot="${t}"]`)}getSlotElements(t){return Array.from(this.querySelectorAll(`[data-slot="${t}"]`))}}function r(o){const t=window.getComputedStyle(o),e=o.getBoundingClientRect(),s=h(t.top);return Math.floor(e.top-s)}function h(o){return parseInt(o.slice(0,o.length-2))}customElements.get("photos-jumplinks")||customElements.define("photos-jumplinks",c);