import{waitForEvent as t}from"./chunk.B4BZKR24.js";import{prefersReducedMotion as e}from"./chunk.W5IOVX7A.js";import{__decorateClass as n}from"./chunk.6M63UXML.js";var o,s=Symbol(),r=class{constructor(t){this.pointers=new Set,this.dragging=!1,this.scrolling=!1,this.mouseDragging=!1,this.handleScroll=()=>{this.scrolling||(this.scrolling=!0,this.host.requestUpdate()),this.handleScrollEnd()},this.handlePointerDown=t=>{if("touch"===t.pointerType)return;this.pointers.add(t.pointerId);this.mouseDragging&&!this.dragging&&0===t.button&&(t.preventDefault(),this.host.scrollContainer.addEventListener("pointermove",this.handlePointerMove))},this.handlePointerMove=t=>{const e=this.host.scrollContainer,n=!!t.movementX||!!t.movementY;!this.dragging&&n?(e.setPointerCapture(t.pointerId),this.handleDragStart()):e.hasPointerCapture(t.pointerId)&&this.handleDrag(t)},this.handlePointerUp=t=>{this.pointers.delete(t.pointerId),this.host.scrollContainer.releasePointerCapture(t.pointerId),0===this.pointers.size&&this.handleDragEnd()},this.handleTouchEnd=t=>{for(const e of t.changedTouches)this.pointers.delete(e.identifier)},this.handleTouchStart=t=>{for(const e of t.touches)this.pointers.add(e.identifier)},this.host=t,t.addController(this)}async hostConnected(){const t=this.host;await t.updateComplete;const e=t.scrollContainer;e.addEventListener("scroll",this.handleScroll,{passive:!0}),e.addEventListener("pointerdown",this.handlePointerDown),e.addEventListener("pointerup",this.handlePointerUp),e.addEventListener("pointercancel",this.handlePointerUp),e.addEventListener("touchstart",this.handleTouchStart,{passive:!0}),e.addEventListener("touchend",this.handleTouchEnd)}hostDisconnected(){const t=this.host.scrollContainer;t.removeEventListener("scroll",this.handleScroll),t.removeEventListener("pointerdown",this.handlePointerDown),t.removeEventListener("pointerup",this.handlePointerUp),t.removeEventListener("pointercancel",this.handlePointerUp),t.removeEventListener("touchstart",this.handleTouchStart),t.removeEventListener("touchend",this.handleTouchEnd)}handleScrollEnd(){this.pointers.size?this.handleScrollEnd():(this.scrolling=!1,this.host.scrollContainer.dispatchEvent(new CustomEvent("scrollend",{bubbles:!1,cancelable:!1})),this.host.requestUpdate())}handleDragStart(){const t=this.host;this.dragging=!0,t.scrollContainer.style.setProperty("scroll-snap-type","unset"),t.requestUpdate()}handleDrag(t){this.host.scrollContainer.scrollBy({left:-t.movementX,top:-t.movementY})}async handleDragEnd(){const n=this.host,o=n.scrollContainer;o.removeEventListener("pointermove",this.handlePointerMove),this.dragging=!1;const s=o.scrollLeft,r=o.scrollTop;o.style.removeProperty("scroll-snap-type");const i=o.scrollLeft,l=o.scrollTop;o.style.setProperty("scroll-snap-type","unset"),o.scrollTo({left:s,top:r,behavior:"auto"}),o.scrollTo({left:i,top:l,behavior:e()?"auto":"smooth"}),this.scrolling&&await t(o,"scrollend"),o.style.removeProperty("scroll-snap-type"),n.requestUpdate()}};n([(o=100,(t,e,n)=>{const r=n.value;n.value=function(...t){clearTimeout(this[s]),this[s]=window.setTimeout((()=>{r.apply(this,t)}),o)}})],r.prototype,"handleScrollEnd",1);export{r as ScrollController};