function h(){return d()||u()}function d(){return/iPhone|iPad|iPod/i.test(navigator.userAgent)||m()}function u(){return/Android/i.test(navigator.userAgent)}function m(){return navigator.userAgent.toLowerCase().indexOf("macintosh")!==-1&&!!navigator.maxTouchPoints&&navigator.maxTouchPoints>2}function v(e,t){let s=0;const n=i=>{const o=window.innerWidth;(!h()||s!==o)&&(e(i),s=o)};return window.addEventListener("resize",n,t),()=>{window.removeEventListener("resize",n)}}var f=class{constructor(){this.watcherConfigs=[]}add(e){Array.isArray(e.on)?e.on.forEach(s=>{const n=Object.assign({},e);n.on=s,this.addSingleEvent(n)}):this.addSingleEvent(e)}addSingleEvent(e){const t=s=>{e.runWhen?e.runWhen()&&e.callback(s):e.callback(s)};if(e.listener=t,e.on==="smartResize")e.remover=v(t,e.eventOptions||{});else if(e.on==="resize"&&e.element!==window){const s=new ResizeObserver(n=>{t(n)});s.observe(e.element),e.remover=()=>{s.unobserve(e.element)}}else if(e.on==="mutation"){const s=new MutationObserver(n=>{t(n)});s.observe(e.element,e.eventOptions),e.remover=()=>{s.disconnect()}}else e.element instanceof MediaQueryList?(e.element.addEventListener(e.on,t,e.eventOptions||{}),e.remover=()=>{e.element.removeEventListener(e.on,t,e.eventOptions||{})}):(e.element.addEventListener(e.on,t,e.eventOptions||{}),e.remover=()=>{e.element.removeEventListener(e.on,t,e.eventOptions||{})});this.watcherConfigs.push(e)}removeById(e){this.watcherConfigs=this.watcherConfigs.filter(t=>{if(t.id&&t.id===e){const s=t.remover;return s&&s(),!1}return t})}removeAll(){this.watcherConfigs.forEach(e=>{const t=e.remover;t&&t()}),this.watcherConfigs=[]}run(e){this.watcherConfigs.filter(s=>s.id&&s.id===e).forEach(s=>{s.callback()&&s.callback()})}dispose(){this.removeAll()}};const r={AUTOPLAY_ENABLED:"scrollable:autoplay-enabled",SCROLLABLE_START:"scrollable:start",SCROLLABLE_END:"scrollable:end",DOT_AUTOPLAY:"dot:autoplay"};class p extends HTMLElement{constructor(){super(...arguments),this.domWatcher=new f,this.disableScroll=!1,this.scrollProgress=0,this.scrollPage=0,this.activeIndexOverride=null,this.activeIndexTimeout=null,this.autoplaySpeed=0,this.autoplayTimeout=null,this.autoplayStarted=!1}connectedCallback(){if(this.content=this.getSlotElement("content"),this.prevButton=this.getSlotElement("prev"),this.nextButton=this.getSlotElement("next"),this.dots=this.getSlotElement("dots"),this.getAttribute("autoplay")&&!S()&&(this.autoplaySpeed=Number(this.getAttribute("autoplay")),this.classList.add(r.AUTOPLAY_ENABLED)),this.domWatcher.add({element:this.content,on:"scroll",callback:()=>this.onContentScroll()}),this.onContentScroll(),this.prevButton&&this.domWatcher.add({element:this.prevButton,on:"click",callback:()=>this.prev()}),this.nextButton&&this.domWatcher.add({element:this.nextButton,on:"click",callback:()=>this.next()}),this.domWatcher.add({element:this.content,on:"focusin",callback:t=>this.onFocusChange(t)}),this.domWatcher.add({element:window,on:"smartResize",callback:()=>this.onResize()}),this.setCSSVariables(),this.initDots(),this.syncControlEls(),this.autoplaySpeed>0){const t=new IntersectionObserver(s=>{this.autoplayStarted||s.forEach(n=>{n.isIntersecting&&(this.autoplayStarted=!0,this.syncControlEls(),t.disconnect())})});t.observe(this)}}initDots(){this.dots&&Array.from(this.dots.children).forEach((s,n)=>{const i=s.querySelector("button");i&&this.domWatcher.add({element:i,on:"click",callback:()=>{this.disableAutoplay();const o=this.content.children[n];this.scrollToTarget(o)}})})}getSlotElement(t){return this.querySelector(`[data-slot="${t}"]`)||null}setCSSVariables(){const t=this.content.scrollWidth/this.content.offsetWidth*100;this.setAttribute("data-scrollable",t>100?"true":"false")}onContentScroll(){const t=this.content.scrollLeft,s=this.content.scrollWidth-this.content.clientWidth;this.scrollProgress=t/s;const n=this.getLastVisibleChild(),i=n?.5*n.offsetWidth:10;this.classList.toggle(r.SCROLLABLE_START,t<=i),this.classList.toggle(r.SCROLLABLE_END,t>=s-i),this.syncControlEls()}getLastVisibleChild(){const t=this.content.children.length;for(let s=0;s{const o=n.querySelector("button");if(o){const l=i===t;o.setAttribute("aria-selected",String(l)),this.autoplayStarted&&this.autoplaySpeed>0&&l?(o.style.setProperty("--dot-autoplay-duration",`${this.autoplaySpeed}ms`),o.classList.add(r.DOT_AUTOPLAY),this.queueAutoplay()):(o.style.removeProperty("--dot-autoplay-duration"),o.classList.remove(r.DOT_AUTOPLAY))}})}disableAutoplay(){this.autoplayTimeout&&(window.clearTimeout(this.autoplayTimeout),this.autoplayTimeout=null),this.autoplaySpeed=0,this.classList.remove(r.AUTOPLAY_ENABLED)}queueAutoplay(){this.contentIsScrollable()&&(this.autoplayTimeout&&window.clearTimeout(this.autoplayTimeout),this.autoplayTimeout=window.setTimeout(()=>{this.next()},this.autoplaySpeed))}contentIsScrollable(){return this.content.scrollWidth-this.content.clientWidth>0}onResize(){this.setCSSVariables(),this.initDots()}onFocusChange(t){if(!this.contentIsScrollable())return;const n=t.target;if(!this.content.contains(n))return;let i=n;for(;i.parentElement!==this.content;)i=i.parentElement;this.scrollToTarget(i)}getActiveElement(){const t=Array.from(this.content.children);if(t.length===0)return null;if(b(this.content))return t[0];if(a(this.content))return t.at(-1);let s;const n=this.content.scrollLeft+.5*this.content.offsetWidth;for(const i of t){const o=i.offsetLeft,l=o+i.offsetWidth;if(o<=n-60&&l>=n+60){s=i;break}}return s}getActiveIndex(){if(this.activeIndexOverride!==null)return this.activeIndexOverride;const t=Array.from(this.content.children);if(t.length===0)return 0;const s=this.getActiveElement();return t.findIndex(n=>n===s)}setActiveIndexOverride(t){this.activeIndexOverride=t,this.activeIndexTimeout&&window.clearTimeout(this.activeIndexTimeout),this.activeIndexTimeout=window.setTimeout(()=>{this.activeIndexOverride=null,this.activeIndexTimeout=null},750)}prev(){if(this.content.children.length===0)return;const t=this.getActiveElement();if(t&&t.previousElementSibling)this.scrollToTarget(t.previousElementSibling);else{const s=this.content.children.length-1;this.scrollToTarget(this.content.children[s])}}next(){if(this.content.children.length===0)return;if(a(this.content)){this.scrollToTarget(this.content.children[0]);return}const t=this.getActiveElement();t&&t.nextElementSibling&&this.scrollToTarget(t.nextElementSibling)}scrollToTarget(t){const s=t.offsetLeft+.5*t.offsetWidth-.5*this.content.offsetWidth,n=navigator.userAgent,i=/Safari/.test(n)&&!/Chrome|Chromium/.test(n);"scrollBehavior"in document.documentElement.style&&!i?this.content.scroll({left:s,behavior:"smooth"}):this.content.scroll({left:s});const l=Array.from(this.content.children).findIndex(c=>c===t);l!==-1&&this.setActiveIndexOverride(l),this.syncControlEls()}}function b(e){return e.scrollLeft===0}function a(e){return e.scrollWidth-e.scrollLeft-24<=e.clientWidth}function S(){return window.matchMedia("(prefers-reduced-motion: reduce)").matches}customElements.get("photos-scrollable")||customElements.define("photos-scrollable",p);