(()=>{return(e,t)=>{const s={horizontal:{name:"horizontal",getMoveTransform:(e,t)=>{return`translateX(${e}px)`},setOtherTransform:_.throttle((e,t,s,n)=>{if(!t.classList.contains(r.ReorderingClassName)){return}const a=e.find(e=>e.element===t);if(!a){return}const o=a.rect;const l=e.filter(e=>e.rect.left{return t.rect.left-e.rect.left});const c=e.filter(e=>e.rect.left>o.left).sort((e,t)=>{return e.rect.left-t.rect.left});if(s>=0){const[e]=c;l.forEach(e=>{e.element.style.transform="";e.element.classList.remove(r.ReorderIncreaseClassName)});c.forEach(t=>{if(o.left+s+o.width>=t.rect.left+t.rect.width/2){t.element.classList.add(r.ReorderDecreaseClassName);t.element.style.transform=`translateX(-${e.rect.left-o.left}px)`}else{t.element.classList.remove(r.ReorderDecreaseClassName);t.element.style.transform=""}})}else{const[e]=l;c.forEach(e=>{e.element.style.transform="";e.element.classList.remove(r.ReorderDecreaseClassName)});l.forEach(t=>{if(o.left+s<=t.rect.left+t.rect.width/2){t.element.classList.add(r.ReorderIncreaseClassName);t.element.style.transform=`translateX(${o.left+o.width-e.rect.left-e.rect.width}px)`}else{t.element.classList.remove(r.ReorderIncreaseClassName);t.element.style.transform=""}})}},50)},vertical:{name:"vertical",getMoveTransform:(e,t)=>{return`translateY(${t}px)`},setOtherTransform:_.throttle((e,t,s,n)=>{if(!t.classList.contains(r.ReorderingClassName)){return}const a=e.find(e=>e.element===t);if(!a){return}const o=a.rect;const l=e.filter(e=>e.rect.top{return t.rect.top-e.rect.top});const c=e.filter(e=>e.rect.top>o.top).sort((e,t)=>{return e.rect.top-t.rect.top});if(n>=0){const[e]=c;l.forEach(e=>{e.element.style.transform="";e.element.classList.remove(r.ReorderIncreaseClassName)});c.forEach(t=>{if(o.top+n+o.height>=t.rect.top+t.rect.height/2){t.element.classList.add(r.ReorderDecreaseClassName);t.element.style.transform=`translateY(-${e.rect.top-o.top}px)`}else{t.element.classList.remove(r.ReorderDecreaseClassName);t.element.style.transform=""}})}else{const[e]=l;c.forEach(e=>{e.element.style.transform="";e.element.classList.remove(r.ReorderDecreaseClassName)});l.forEach(t=>{if(o.top+n<=t.rect.top+t.rect.height/2){t.element.classList.add(r.ReorderIncreaseClassName);t.element.style.transform=`translateY(${o.top+o.height-e.rect.top-e.rect.height}px)`}else{t.element.classList.remove(r.ReorderIncreaseClassName);t.element.style.transform=""}})}},50)}};class r extends EventTarget{constructor(e){super();this.container=e;this.orientation=s.horizontal;this.enabled=false;this.snapshots=new Map;this.attachedEvents=[];this.children=[...this.container.children];if(this.children.every(e=>e.style.order==="")){this.children.forEach((e,t)=>{e.style.order=(t+1).toString()})}}addEventListener(e,t,s){super.addEventListener(e,t,s)}removeEventListener(e,t,s){super.addEventListener(e,t,s)}getOrderMap(){return new Map(this.children.map(e=>{return[e,parseInt(e.style.order)]}))}toggle(){if(this.enabled){this.disable()}else{this.enable()}}generateSnapshots(){this.children.forEach(e=>{this.snapshots.set(e,{element:e,rect:e.getBoundingClientRect()})})}enable(){this.children.forEach(e=>{let t=0;let s=0;let n=false;e.classList.add(r.ReorderEnabledClassName);const a=()=>{const a=(a,o)=>{e.classList.add(r.ReorderingClassName);e.style.transition="none";e.style.userSelect="none";this.generateSnapshots();this.children.filter(t=>t!==e).forEach(e=>e.style.transition="transform .2s ease-out");t=a;s=o;n=true};const o=e=>{a(e.screenX,e.screenY)};e.addEventListener("mousedown",o);this.attachedEvents.push(()=>e.removeEventListener("mousedown",o));const l=e=>{if(e.touches.length!==1){return}const[t]=e.touches;a(t.screenX,t.screenY)};e.addEventListener("touchstart",l);this.attachedEvents.push(()=>e.removeEventListener("touchstart",l))};const o=()=>{const r=(r,n)=>{const a=r-t;const o=n-s;e.style.transform=this.orientation.getMoveTransform(a,o);this.orientation.setOtherTransform([...this.snapshots.values()],e,a,o)};const a=e=>{if(!n){return}r(e.screenX,e.screenY);if(e.cancelable){e.preventDefault()}};document.addEventListener("mousemove",a);this.attachedEvents.push(()=>document.removeEventListener("mousemove",a));const o=e=>{if(!n){return}if(e.touches.length!==1){return}const[t]=e.touches;r(t.screenX,t.screenY);if(e.cancelable){e.preventDefault()}};e.addEventListener("touchmove",o,{passive:false});this.attachedEvents.push(()=>e.removeEventListener("touchmove",o))};const l=()=>{const t=()=>{if(!n){return}e.classList.remove(r.ReorderingClassName);n=false;let t=0;const s=this.children.filter(t=>t!==e);const a=[];s.forEach(e=>{e.style.transform="";e.style.transition="";if(e.classList.contains(r.ReorderIncreaseClassName)){t--;e.style.order=(parseInt(e.style.order)+1).toString();e.classList.remove(r.ReorderIncreaseClassName);a.push(this.snapshots.get(e))}else if(e.classList.contains(r.ReorderDecreaseClassName)){t++;e.style.order=(parseInt(e.style.order)-1).toString();e.classList.remove(r.ReorderDecreaseClassName);a.push(this.snapshots.get(e))}});e.style.userSelect="";e.style.order=(parseInt(e.style.order)+t).toString();e.style.transform="";e.style.transition="";this.dispatchEvent(new CustomEvent("reorder",{detail:this.children.map(e=>{return{element:e,order:parseInt(e.style.order)}})}))};document.addEventListener("mouseup",t);this.attachedEvents.push(()=>document.removeEventListener("mouseup",t));e.addEventListener("touchend",t);this.attachedEvents.push(()=>e.removeEventListener("touchend",t))};a();o();l()});this.enabled=true}disable(){this.attachedEvents.forEach(e=>e());this.children.forEach(e=>e.classList.remove(r.ReorderEnabledClassName));this.enabled=false}}r.ReorderDecreaseClassName="reorder-decrease";r.ReorderIncreaseClassName="reorder-increase";r.ReorderEnabledClassName="reorder-enabled";r.ReorderingClassName="reordering";return{export:{ReorderOrientations:s,Reorder:r}}}})();