UNPKG

fluid-dnd

Version:

An agnostic drag and drop library to sort all kind of lists. With current support for vue, react and svelte

2 lines (1 loc) 22.6 kB
"use strict";var $e=Object.defineProperty;var Ve=(t,e,n)=>e in t?$e(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var X=(t,e,n)=>Ve(t,typeof e!="symbol"?e+"":e,n);const Y="horizontal",q="vertical",W="draggable",Yt="droppable",wt="handler-class",Ft="dragging",Xt="dragging-handler-class",Wt="dropping",ae="grabbing",le="grab",Ye="disable-transition",U=(t,e)=>t.classList.contains(e),it=(t,e,n=!1)=>{t.classList.toggle(e,n)},st=(t,e)=>{t.classList.add(e)},_t=(t,e)=>{t.classList.remove(e)},Xe=(t,e)=>Et(e).every(n=>U(t,n)),lt=t=>`.${Et(t).join(".")}`,We=(t,e)=>{const n=Et(e);t.classList.add(...n)},Et=t=>((t==null?void 0:t.split(" "))??[]).filter(e=>e),_e=()=>{const{scrollX:t,scrollY:e}=window;return{scrollX:t,scrollY:e}},Zt=t=>!t||t.trim().length==0||t=="normal"?0:parseFloat(t),He=t=>t?parseInt(t):-1,qe=t=>{const e=getComputedStyle(t),n=new DOMMatrixReadOnly(e.transform);return{x:n.m41,y:n.m42}},ue=(t,e)=>t.x1>e.x1?ue(e,t):t.x2<e.x1?0:t.x2>=e.x2?t.x2-t.x1:t.x2-e.x1,vt=(t,e)=>!ze(t,e),ze=(t,e)=>{const{intersectionX:n,intersectionY:s,rect1:o,rect2:r}=ge(t,e);return s>=Math.min(o.height,r.height)/2&&n>=Math.min(o.width,r.width)/2},je=(t,e)=>!Ze(t,e),Ze=(t,e)=>{const{intersectionX:n,intersectionY:s}=ge(t,e);return s>=0&&n>=0},ge=(t,e)=>{const n=w(t),s=w(e),o=ee(n,s,q),r=ee(n,s,Y);return{rect1:n,rect2:s,intersectionX:r,intersectionY:o}},ee=(t,e,n)=>{const{before:s,distance:o}=I(n);return ue({x1:t[s],x2:t[s]+t[o]},{x1:e[s],x2:e[s]+e[o]})},Ct=(t,e)=>t?Zt(getComputedStyle(t)[e]):0,ne=t=>{const{scrollLeft:e,scrollTop:n}=t;return{scrollLeft:e,scrollTop:n}},w=t=>t.getBoundingClientRect(),z=(t,e)=>{const{distance:n}=I(t);return[e[n],n]},Nt=(t,e)=>{const{axis:n}=I(t);return e[n]},ut=(t,e)=>{const{borderBeforeWidth:n}=I(t);return Ct(e,n)},Lt=(t,e)=>{const{beforeMargin:n}=I(t);return Ct(e,n)},fe=(t,e)=>{const{beforeMargin:n}=I(t);return Ct(e,n)},Dt=(t,e)=>{const{afterMargin:n}=I(t);return Ct(e,n)},j=(t,e)=>{const{before:n}=I(t);return e[n]},Tt=(t,e)=>{const{scrollElement:n}=I(t);return[e[n],n]},at=(t,e)=>{const{scroll:n}=I(t);return e[n]},ke=(t,e)=>{const{inner:n}=I(t);return e[n]},kt=(t,e)=>{const{page:n}=I(t);return e[n]},pe=(t,e)=>{const{offset:n}=I(t);return e[n]},I=t=>{const e=t==Y;return{beforeMargin:e?"marginLeft":"marginTop",afterMargin:e?"marginRight":"marginBottom",borderBeforeWidth:e?"borderLeftWidth":"borderTopWidth",before:e?"left":"top",gap:e?"columnGap":"rowGap",distance:e?"width":"height",axis:e?"x":"y",offset:e?"offsetX":"offsetY",scroll:e?"scrollX":"scrollY",scrollElement:e?"scrollLeft":"scrollTop",page:e?"pageX":"pageY",inner:e?"innerWidth":"innerHeight",scrollDistance:e?"scrollWidth":"scrollHeight",clientDistance:e?"clientWidth":"clientHeight",paddingBefore:e?"paddingLeft":"paddingTop",getRect:w}},Ot=(t,e)=>Je(t,e),Ue=t=>[...t.children].filter(n=>U(n,W)),Je=(t,e)=>{const n=[...e.children].filter(o=>U(o,W)&&!o.isEqualNode(t)).toReversed(),s=[...e.children].findLastIndex(o=>o.isEqualNode(t));return[n,s,e]},Ke=t=>{let e=t.parentElement;for(;e;){const n=window.getComputedStyle(e);if(n.translate!=="none"||n.willChange==="transform")return e;e=e.parentElement}return null},he=(t,e)=>{const n=Ke(t);return n?j(e,w(n))+ut(e,n):0},P=(t,e)=>t==null?void 0:t.isSameNode(e),Qe=t=>t&&getComputedStyle(t).transform!=="none",de="startDrag",Pt="drag",me="startDrop",rt="temp-child",Ut="cubic-bezier(0.2, 0, 0, 1)",Rt={height:0,width:0},mt=t=>window.TouchEvent&&t instanceof TouchEvent,Q=t=>t instanceof HTMLElement,Se=t=>t instanceof MouseEvent,tn=["onmouseup","onmousedown","onmousemove"],en=(t,e)=>{t.style.height=`${e.height}px`,t.style.width=`${e.width}px`},ot=(t,e=Rt)=>{!t||!Q(t)||(e.width==0&&e.height==0?t.style.transform="":t.style.transform=`translate(${e.width}px,${e.height}px)`)},nn=(t,e,n,s)=>{t[e]=o=>{if(o.defaultPrevented)return;s&&s(o);const r=Ht(o);n(r)}},Vt=(t,e,n,s)=>{n&&(sn(e)?t[e]=n:nn(t,e,n,s))},sn=t=>tn.includes(t),on=t=>{const{target:e}=t;return{clientX:0,clientY:0,pageX:0,pageY:0,screenX:0,screenY:0,target:e,offsetX:0,offsetY:0}},rn=(t,e)=>{const n=(s,o)=>an(e,window,o,s);if(Se(t)){const{offsetX:s,offsetY:o}=t;return[s,o]}else{const s=t.target;return[n(s,Y),n(s,q)]}},Ht=t=>{const e=cn(t);if(!e)return on(t);const[n,s]=rn(t,e),{clientX:o,clientY:r,pageX:i,pageY:a,screenX:f,screenY:g,target:d}=e;return{clientX:o,clientY:r,pageX:i,pageY:a,screenX:f,screenY:g,target:d,offsetX:n,offsetY:s}},cn=t=>{if(mt(t))return t.touches[0]??t.changedTouches[0];if(Se(t))return t},an=(t,e,n,s)=>{const o=w(s);return kt(n,t)-at(n,e)-j(n,o)-ut(n,s)},yt=(t,e,n="ease-out",s="transform")=>{Q(t)&&(t.style.transitionDuration=`${e}ms`,t.style.transitionTimingFunction=`${n}`,t.style.transitionProperty=`${s}`)},ve=(t,e,n)=>{!t||!Q(t)||(t[e]=()=>{n()})},ln=t=>{var e=t.querySelector("style");if(!e){var n=document.createElement("style");return t.appendChild(n),n}return e},un=(t,e)=>{const n=/\.-?[_a-zA-Z0-9-*\s<>():]+/g,[s]=e.match(n)||[];for(const o of t.cssRules){const[r]=o.cssText.match(n)||[];if(s===r)return!0}return!1},gn=(t,e)=>{e.forEach(n=>{fn(t,n)})},fn=(t,e)=>{var s;var n=ln(t);n.sheet&&!un(n.sheet,e)&&((s=n.sheet)==null||s.insertRule(e,n.sheet.cssRules.length))},De=(t,e={})=>{for(const n of Object.keys(e)){const s=e[n];s!=null&&pn(t,`--${n}`,s)}},pn=(t,e,n)=>t&&t.style.setProperty(e,n),It=t=>{Q(t)&&(t.style.transition="",t.style.transform="")},hn=(t,e,n)=>{n!=0&&(e==="vertical"?t.scrollBy(0,n):t.scrollBy(n,0))},dn=t=>{let e=.5;const n=.03,s=(i,a,f,g)=>{const[d]=z(i,w(t)),h=w(a),x=j(i,f)-j(i,h)+Nt(i,g),[R]=z(i,h),b=R-d,C=x/b,D=d/b,A=.25,T=.2,M=.8;let F=0;const _=je(t,a);!_&&C<T&&C>-D?F=o(C<0?0:C,T):!_&&C>M&&C<1+D&&(F=r(C,M));const G=A*d*F;e=Math.sign(G)*Math.min(Math.abs(G),Math.abs(e)+n),hn(a,i,e)},o=(i,a)=>Math.pow(i/a,1/3)-1,r=(i,a)=>Math.pow(1/(1-a)*(i-a),3);return[s]},mn=(t,e)=>{let n={offsetX:0,offsetY:0},s={top:0,left:0},o={x:0,y:0};const[r]=dn(t),i=h=>{t.style.transform=`translate( ${h.x}px, ${h.y}px)`},a=h=>{t.style.top=`${h.top}px`,t.style.left=`${h.left}px`},f=(h,x,R,b)=>{const C=T=>{const M=kt(T,R),F=at(T,window),_=ke(T,window),[G]=z(T,w(h)),Z=ut(T,h),J=Lt(T,h),k=M-pe(T,n),tt=he(h,T);if(k>=F-G/2&&k<=F+_){const u=Te(T,x),p=k-j(T,s)-Z-J-F-tt-u;return D(T),p}return Nt(T,o)},D=T=>{h&&U(h,Ft)&&T===b&&r(b,x,s,o)},A=T=>{const{axis:M}=I(T);o[M]=C(T),i(g())};A(Y),A(q)},g=()=>{let h=o;for(const x of e)h=x(h,t);return h};return[f,(h,x)=>{const[R,b]=Tn(h,x,t);s=R,a(s),n=b}]},Mt=(t,e,n)=>j(t,w(e))-j(t,w(n))-ut(t,n),Sn=(t,e)=>{let{offsetX:n,offsetY:s,target:o}=t,r=vn(o,e);const i=o;return i&&r&&!P(i,r)&&(n+=Mt(Y,i,r),s+=Mt(q,i,r)),r&&e!=o&&(n+=Mt(Y,r,e),s+=Mt(q,r,e)),{offsetX:n,offsetY:s}},vn=(t,e)=>{const n=t==null?void 0:t.closest(`.${wt}`);return n&&P(e,n)?t:n},se=(t,e,n,s)=>{const o=he(n,t),r=n.parentElement,i=Te(t,r);return kt(t,e)-pe(t,s)-Lt(t,n)-ut(t,n)-at(t,window)-o-i},Te=(t,e)=>e&&Dn(e)?j(t,w(e)):0,Dn=t=>{let e=t;for(;e;){if(Qe(e))return!0;e=e.parentElement}return!1},Tn=(t,e,n)=>{const s=Sn(t,n);return[{top:se(q,t,e,s),left:se(Y,t,e,s)},s]},H=class H{static addConfig(e,n){const s=H.configs.filter(r=>!P(r.droppable,e)),o=ne(e);s.push({droppable:e,config:n,scroll:o}),H.configs=s}static updateScrolls(e,n){for(const s of H.configs){const{droppable:o}=s;(n&&Xe(o,n)||P(e,o))&&(s.scroll=ne(o))}}static getConfig(e){return H.configs.find(({droppable:s})=>P(e,s))}};X(H,"configs",[]),X(H,"removeObsoleteConfigs",()=>{const e=H.configs.filter(({droppable:n})=>document.contains(n));H.configs=e});let ct=H;const qt=t=>t.length==0?0:Zt(t.replace("px","")),En=(t,e)=>{const n=getComputedStyle(t)[e];if(n.match("%")){const o=Zt(n.replace("%","")),{width:r}=w(t);return r*(o/100)}return qt(n)},Cn=(t,e)=>{if(!(t instanceof Element))return[0,!1];const n=En(t,e),s=getComputedStyle(t).display,o=n>0||s==="flex";return[n,o]},yn=t=>{const{top:e,left:n}=getComputedStyle(t);return[qt(e),qt(n)]},Jt=(t,e)=>{const{gap:n}=I(e);return Cn(t,n)},bn=(t,e)=>{const[n,s]=Jt(t,e);return s?n:0},Kt=(t,e,n,s=()=>!0)=>{const o=new MutationObserver(r=>{if(r=r.filter(s),r.length>0){const i=r[0];t(o,i)}});return o.observe(e,n),o},zt=t=>Q(t)?t.classList.contains(rt):!1;function St(t,e,n,s,o=t.previousElementSibling,r=t.nextElementSibling){let{height:i,width:a}=An(n,t,o,r);return vt(t,s)&&e==Pt&&(i=0,a=0),{height:i,width:a}}const An=(t,e,n,s)=>{const o=Dt(t,e),r=Lt(t,e),i=Lt(t,s),[a,f]=Jt(e.parentElement,t),[g]=z(t,w(e));if(f)return oe(g,r,o,a,0,t);const[d,h,x]=xn(n,i,o,r,t);return oe(g,h,d,0,x,t)},xn=(t,e,n,s,o)=>{const r=Math.max(e,n);let i=s,a=e;if(t){const f=Dt(o,t);i=Math.max(f,s),a=Math.max(a,f)}return[r,i,a]},oe=(t,e,n,s,o,r)=>Mn(r,t+e+n+s-o),Mn=(t,e)=>t==Y?{width:e,height:0}:{width:0,height:e},On="startDrag",Ee="cubic-bezier(0.2, 0, 0, 1)",Ce=50,ye="width, min-width, height",Bn=(t,e,n)=>{let s=St(e,On,n,t);const o=bn(t,n),[,r]=z(n,s);s[r]-=o;const[i,a]=wn(n,e);return s[a]=i,s},wn=(t,e)=>{const n=t==Y?q:Y;return z(n,w(e))},gt=(t,e=Rt)=>{en(t,e),t.style.minWidth=`${e.width}px`},Ln=(t,e,n)=>s=>{e.contains(t)&&(gt(t,n),s.disconnect())},be=(t,e)=>{const{scrollDistance:n,clientDistance:s}=I(e);return t[n]-t[s]},Pn=(t,e,n)=>{const[s]=Tt(t,n);return s/be(e,t)},Rn=(t,e,n,s)=>{if(!s)return;const{direction:o}=e,r=Pn(o,t,n)>.99,[,i]=Tt(o,t);r&&(t[i]=be(t,o))},Ae=(t,e,n,s)=>{const{droppable:o,config:r,scroll:i}=n,{direction:a,animationDuration:f}=r;if(Rn(o,r,i,e),o.querySelector(`.${rt}`)||!t)return;var g=t.tagName=="LI"?"DIV":t.tagName,d=document.createElement(g);st(d,rt),gt(d);const h=Bn(o,t,a);return yt(d,f,Ee,ye),[d,h,o]},jt=(t,e,n,s,o)=>{const r=Ae(t,n,s);if(!r)return;const[i,a,f]=r;P(e,f)&&gt(i,a),Kt(Ln(i,f,a),f,{childList:!0,subtree:!0}),f.appendChild(i)},In=(t,e,n)=>{const s=Ae(t,e,n);if(!s)return;const[o,r,i]=s;i.appendChild(o),Fn(o,r)},Fn=(t,e)=>requestAnimationFrame(()=>{gt(t,e),requestAnimationFrame(()=>{yt(t,0,Ee,ye)})}),Nn=(t,e,n,s,o=!0)=>{if(n){var r=document.querySelectorAll(`${lt(n)} > .${rt}`);r.forEach(i=>{const a=i.parentElement;if(P(e,a)||!o&&P(t,a))return;gt(i),setTimeout(()=>{var g;(g=i.parentNode)==null||g.removeChild(i)},s+Ce)})}},Bt=(t,e,n=!1)=>{var s=t.querySelectorAll(`.${rt}`);s.forEach(o=>{const r=o;n?(gt(r),setTimeout(()=>{t.contains(r)&&t.removeChild(r)},e+Ce)):t.removeChild(o)})},Gn=(t,e)=>{const{config:n,droppable:s}=t,{onInsertEvent:o,onDragEnd:r}=n;return{...n,onDragEnd:f=>{const{index:g,value:d}=f;r({index:g,value:e(d,s)})},onInsertEvent:(f,g)=>o(f,e(g,s),!0)}};class $n{constructor(e,n,s,o,r,i){X(this,"initial");X(this,"current");X(this,"parent");X(this,"draggableElement");X(this,"groupClass");X(this,"dragEvent");X(this,"changeDroppable");X(this,"mapFrom");this.parent=s,this.draggableElement=e,this.groupClass=n,this.dragEvent=o,this.mapFrom=i,this.initial=ct.getConfig(s),this.changeDroppable=r}getDraggableAncestor(e,n,s){return document.elementsFromPoint(e,n).filter(o=>!P(s,o))}getElementBelow(e,n){return(o=>{const[r]=o.getDraggableAncestor(n.clientX,n.clientY,e);return r})(this)}getCurrent(e,n){const s=this.getElementBelow(e,n);return!this.groupClass||!s?void 0:s.closest(lt(this.groupClass))}isOutsideOfAllDroppables(e){return(this.groupClass?Array.from(document.querySelectorAll(lt(this.groupClass))):[this.parent]).every(s=>vt(e,s))}isNotInsideAnotherDroppable(e,n){return!vt(e,n)||this.isOutsideOfAllDroppables(e)}onScrollEvent(){this.dragEvent()}setOnScroll(e){ve(e,"onscroll",()=>{this.onScrollEvent()})}getConfigFrom(e){const n=ct.getConfig(e);if(n)return P(this.parent,e)?n:{...n,config:Gn(n,this.mapFrom)}}droppableIfInsideCurrent(e,n){return e&&!P(n,e)&&n.contains(e)}getCurrentConfig(e){var o,r;const n=this.draggableElement,s=this.getCurrent(n,e);return this.current&&this.isNotInsideAnotherDroppable(n,(o=this.current)==null?void 0:o.droppable)&&!this.droppableIfInsideCurrent(s,(r=this.current)==null?void 0:r.droppable)?this.current:s?(Q(s)&&!s.onscroll&&this.setOnScroll(s),this.getConfigFrom(s)):this.getConfigFrom(this.parent)}updateConfig(e){const n=this.current;this.current=this.getCurrentConfig(e),this.changeDroppable(this.current,n)}isOutside(e){const n=this.draggableElement;return!this.getCurrent(n,e)}}const re=(t,e)=>{const{paddingBefore:n}=I(t),s=ut(t,e),o=Ct(e,n),r=Nt(t,w(e));return s+o+r},Vn=(t,e)=>{const[n,s]=yn(e),o=re(q,t);return[re(Y,t)-s,o-n]};function Yn(t,e,n,s,o,r,i,a,f){let g=0,d=0;const h=!!(n<0&&f);if(n===s&&!h)return ce({height:g,width:d},t,o,i,h);const[x,R,b,C]=_n(e,n,s,f);if(h){const[p,m]=Vn(a,f);g+=m,d+=p}const[D,A]=Jt(a,t),[T,M,F]=qn(x,R==null?void 0:R.previousElementSibling,C,A,h,t),[_,G,Z]=Hn(b,D,A,t),J=Wn(G,_,Z,M,T,D),[k]=Tt(t,a),tt=h?k:Xn(a,r,t),u=(C?J-F:F-J)-tt;return t===q?g+=u:t===Y&&(d+=u),ce({height:g,width:d},t,o,i,h)}const Xn=(t,e,n)=>{const[s]=Tt(n,t),[o]=Tt(n,e);return s-o},Wn=(t,e,n,s,o,r)=>{const i=Math.max(e,o);return Math.max(n,s)+t+i+r},_n=(t,e,n,s)=>{const o=e<n,[r,i]=[e,n].toSorted((d,h)=>d-h),a=t[e]??s,f=t[n];let g=o?t.slice(r+1,i+1):t.slice(r,i);return r<0&&s&&(g=t.slice(r+1,i)),[a,f,g,o]},Hn=(t,e,n,s)=>{if(t.length==0)return[0,0,0];const o=Dt(s,t[0]);let r=0,i=-o;for(const[a,f]of t.entries()){const[g]=z(s,w(f)),d=fe(s,f);n&&(r+=d),n&&a>0?r+=e:r=Math.max(r,d),i+=r+g,r=Dt(s,f)}return[o,i,r]},ce=(t,e,n,s,o)=>{const r=at(e,window),i=at(e,n),a=o?0:i-2*r+at(e,s),[,f]=z(e,t);return t[f]+=a,t},qn=(t,e,n,s,o,r)=>{const i=n?t.previousElementSibling:e;return zn(i,t,s,o,r)},zn=(t,e,n,s,o)=>{if(n)return[0,0,0];const r=Dt(o,s?null:t),i=fe(o,e);let a=Math.max(r,i);return[r,i,a]},xe=(t,e,n)=>{const{handlerSelector:s,animationDuration:o}=t,r=g=>{n(),i(g,!1),It(g),g.style.top="",g.style.left="",De(g,{fixedHeight:"",fixedWidth:""})},i=(g,d)=>{it(g,Ft,d),a(d,g),e.toggleGrabClass(!d)},a=(g,d)=>{const h=d.querySelector(s);it(document.body,ae,g),it(h||d,Xt,g)};return[r,i,(g,d)=>{yt(g,o,Ut),ot(g,d)}]},jn=50;function Zn(t,e,n,s,o,r){let i=e;const{onRemoveAtEvent:a,animationDuration:f,draggingClass:g}=t,[d,h,x]=xe(t,o,r),R=(u,p,m,y)=>{const O=St(u,p,y.direction,m);C(u,p,O,m,y)},b=(u,p,m,y,O)=>{if(!m)return;const{droppable:E,scroll:L,config:B}=m,S=St(u,p,B.direction,E);T(u,p,S,y,E,L,B,O)},C=(u,p,m,y,O)=>{const[E]=Ot(u,y),L=vt(u,y),{direction:B,onDragOver:S}=O;S({element:u,index:e,targetIndex:i,value:t.onGetValue(e),droppable:y}),E.length==0&&A(m,1,B,E);for(const[$,N]of E.entries()){if(!U(N,W))continue;const K=D(B,u,N,m);if(!L&&K)m=K;else if(!L)continue;const ft=E.length-$;A(m,ft,B,E),p===de?ot(N,m):p===Pt&&x(N,m)}},D=(u,p,m,y)=>{const O=w(p),E=w(m),L=j(u,O),B=j(u,E),[S]=z(u,E),$=B+S/2,N=Nt(u,qe(m)),K=$-N;return L>K?Rt:y},A=(u,p,m,y)=>{const O=y.filter(L=>U(L,W)).length,[E]=z(m,u);E==0?i=Math.max(i,p):i=Math.min(i,p-1),i=Math.min(i,O)},T=(u,p,m,y,O,E,L,B)=>{const[S,$]=Ot(u,O),N=S.toReversed(),K=$===-1?N.length:$;N.splice(K,0,u);const[ft,bt,pt]=M(u,$,N,O);m=St(u,p,L.direction,n,ft,bt);const Gt=_e(),At=Yn(L.direction,N,$,pt,Gt,E,y,O,u);S.length==0&&F(void 0,m,u,At);for(const[$t,ht]of S.toReversed().entries()){let xt=m;pt-1>=$t&&(xt=Rt),p===me&&!U(ht,rt)&&F(ht,xt,u,At)}_(pt,u,L,O,B)},M=(u,p,m,y)=>{const E=vt(u,y)?p:i,L=()=>p<E?[E,E+1]:p>E?[E-1,E]:[E-1,E+1],[B,S]=L(),$=m[B]??null,N=m[S]??null;return[$,N,E]},F=(u,p,m,y)=>{ot(u,p),ot(m,y)},_=(u,p,m,y,O)=>{const{onInsertEvent:E,onDragEnd:L}=m;st(p,Wt),J(p,n,y,()=>{if(_t(p,Wt),O!=null){const B=a(O,!0);B!=null&&E(u,B,!0),Z(p,()=>{B!=null&&L({value:B,index:u})}),G()}})},G=()=>{if(s){var u=document.querySelectorAll(`${lt(s)} > .${W}`);for(const p of u)It(p)}},Z=(u,p)=>{setTimeout(()=>{_t(u,g),p&&p()},jn)},J=(u,p,m,y)=>{setTimeout(()=>{y&&y(),k(p,m),tt(m),d(u),et(u,p),et(u,m)},f)},k=(u,p)=>{P(u,p)?Bt(u,f):(Bt(u,f,!0),Bt(p,f))},tt=u=>{if(!P(n,u)){var[p]=n.querySelectorAll(`.${rt}`);p&&Q(p)&&(p.style.height="0px",p.style.width="0px")}},et=(u,p)=>{const[m]=Ot(u,p);for(const y of[...m,u])It(y)};return[R,b,h]}const ie="onmousedown";function kn(t,e,n,s,o){const{handlerSelector:r,isDraggable:i,droppableGroup:a,animationDuration:f,draggingClass:g,droppableClass:d,onDragStart:h,delayBeforeTouchMoveEvent:x,coordinateTransform:R}=n,b=Et(a).map(c=>`droppable-group-${c}`).join(" ");let C=0,D={scrollX:0,scrollY:0},A={pageX:0,pageY:0},T,M;const[F,_]=mn(t,R),G=()=>{C=0},[Z,J,k]=Zn(n,e,s,b,o,G),tt=()=>{st(t,W)},et=c=>{st(c,wt),o.addSubscriber(c)},u=()=>{if(i(t)){const c=t.querySelector(r);et(c||t)}},p=()=>{u(),tt()},m=c=>{const l=c==null?void 0:c.querySelector(`.${wt}`),v=l==null?void 0:l.parentElement;return l&&v&&U(v,Yt)&&!P(s,v)?null:l},y=c=>{const l=m(c)??c;l&&i(c)&&(Vt(l,ie,ht("mousemove","mouseup")),Vt(l,"ontouchstart",ht("touchmove","touchend"),v=>{const V=v.touches[0];M={x:V.clientX,y:V.clientY}}),O(l)),P(c,l)||Vt(c,ie,xt),st(s,Yt)},O=c=>{const l=c.querySelectorAll("img");Array.from(l).forEach(v=>{v.onmousedown=()=>!1})},E=()=>{if(A.pageX==0&&A.pageY==0||!S.current)return;const{droppable:c,config:l}=S.current;F(t,c,A,l.direction),Z(t,Pt,c,l)},L=c=>{const l=c.querySelectorAll(`.${W}`);for(const v of l)ot(v)},B=(c,l)=>{l&&C==2&&!P(c==null?void 0:c.droppable,l.droppable)&&(Z(t,Pt,l.droppable,l.config),L(l.droppable))},S=new $n(t,b,s,E,B,n.mapFrom),$=c=>{if(!S.current)return;const l=b?Array.from(document.querySelectorAll(lt(b))):[s];for(const v of l)v.classList.toggle(d,!c&&P(v,S.current.droppable))},N=(c,l=!1)=>{S.updateConfig(c);const v=S.isOutside(c);$(v),C===1&&!l?te(c):C===2&&(K(v),we(c))},K=(c=!0)=>{if(!S.current)return;const{droppable:l}=S.current;Nn(l,s,b,f,c),!c&&jt(t,s,C==1,S.current)},ft=c=>{if(mt(c)&&M&&C==1){const l=c.touches[0],v=Math.abs(l.clientX-M.x),V=Math.abs(l.clientY-M.y);if(Math.abs(v)>5&&Math.abs(V)>5)return clearTimeout(T),!1}return!0},bt=c=>{clearTimeout(T);const l=Ht(c);if(mt(c)&&c.cancelable&&C==2&&c.preventDefault(),mt(c)&&!c.cancelable||!ft(c)){Qt("touchmove",c);return}N(l,mt(c))},pt=(c,l)=>{c=="touchmove"?T=setTimeout(()=>{l()},x):l()},Gt=(c,l)=>{const{clientX:v,clientY:V}=c,nt=document.elementFromPoint(v,V),dt=nt==null?void 0:nt.closest(`.${W}`);return dt&&P(l,dt)},At=c=>{const l=n.onGetValue(e);return{index:e,element:c,value:l}},$t=c=>{S.updateConfig(c),$(S.isOutside(c)),te(c)},ht=(c,l)=>v=>{if(!Gt(v,t))return;ct.updateScrolls(s,b);const{scrollX:V,scrollY:nt}=window;if(D={scrollX:V,scrollY:nt},C===0){C=1;const dt=At(t);dt&&h(dt),pt(c,()=>{c=="touchmove"&&$t(v)}),document.addEventListener(c,bt,{passive:!1}),Le(s),document.addEventListener(l,Me(c),{once:!0})}},xt=c=>S.updateConfig(c),Me=c=>l=>{Qt(c,l)},Qt=(c,l)=>{$(!0);const v=Ht(l);Re(S.isOutside(v)),clearTimeout(T),document.removeEventListener(c,bt),S.updateConfig(v);const V=S.getCurrentConfig(v);if(V){const{droppable:nt}=V;Oe(nt)}s.onscroll=null,G()},Oe=c=>{if(c.onscroll=null,!b)return;const l=Array.from(document.querySelectorAll(lt(b)));for(const v of l)Q(v)&&(v.onscroll=null)},te=c=>{S.current&&jt(t,s,C==1,S.current),Be(),S.current&&Z(t,de,S.current.droppable,S.current.config),Fe(t),_(c,t)},Be=()=>{C=2},we=c=>{const{pageX:l,pageY:v}=c;A={pageX:l,pageY:v},E()},Le=c=>ve(c,"onscroll",Pe),Pe=()=>E(),Re=c=>{if(C!==2&&C!==1){G();return}C=3,Ie(t),t.classList.contains(Ft)&&J(t,me,c?S.initial:S.current,D,e)},Ie=c=>{yt(c,f,Ut),ot(c)},Fe=c=>{const{height:l,width:v}=w(c);De(c,{fixedHeight:`${l}px`,fixedWidth:`${v}px`}),k(c,!0),it(c,g,!0),c.style.transition=""},Ne=c=>{Promise.resolve().then(()=>require("./remove--3FbKNTA.cjs")).then(l=>{const[v]=l.default(n,s,o,G);S.initial&&v(e,c,t,S.initial)})},Ge=(c,l)=>{(c===e||c===n.onGetLegth()&&e===c-1)&&Promise.resolve().then(()=>require("./insert-DHSt0mSS.cjs")).then(v=>{const[V]=v.default(n,s,o,G);S.initial&&V(c,t,s,l,S.initial)})};return p(),y(t),[Ne,Ge]}const Un=(t,e)=>{t&&We(e,t)},Jn=()=>{gn(document.body,[`.${W}{touch-action:manipulation;user-select:none;box-sizing:border-box!important;-webkit-user-select:none;}`,`.${wt}{pointer-events:auto!important;}`,`.${le}{cursor:grab;}`,".temp-child{touch-action:none;pointer-events:none;box-sizing:border-box!important;}",".droppable{box-sizing:border-box!important;}",`.${Ft}{position:fixed;z-index:5000;width:var(--fixedWidth)!important;height:var(--fixedHeight)!important;}`,`.${Xt}{pointer-events:none!important;}`,`.${Wt}{pointer-events:none!important;}`,`.${ae}{cursor:grabbing;}`,".disable-transition{transition:none!important;}"])};function Kn(t,e,n,s="index"){const o=s;let r=[],i=[];const{droppableGroup:a}=t;if(!n)return[r,i];const f=Et(a).map(g=>`droppable-group-${g}`).join(" ");Jn(),Un(f,n);for(const g of n.children){const d=g.getAttribute(o),h=He(d),x=g;if(x&&h>=0){const[R,b]=kn(x,h,t,n,e);r.push(R),i.push(b)}}return[r,i]}const Qn=(t,e)=>{const n=(a,f)=>t.removeAtEvent(a,f),s=(a,f,g)=>t.insertEvent(a,f,g),o=()=>t.getLength(),r=a=>t.getValue(a),i=a=>a;return{direction:(e==null?void 0:e.direction)??q,handlerSelector:(e==null?void 0:e.handlerSelector)??W,draggingClass:(e==null?void 0:e.draggingClass)??"dragging",droppableClass:(e==null?void 0:e.droppableClass)??"droppable-hover",isDraggable:(e==null?void 0:e.isDraggable)??(()=>!0),onDragStart:(e==null?void 0:e.onDragStart)??(()=>{}),onDragEnd:(e==null?void 0:e.onDragEnd)??(()=>{}),onDragOver:(e==null?void 0:e.onDragOver)??(()=>{}),droppableGroup:e==null?void 0:e.droppableGroup,onRemoveAtEvent:n,onInsertEvent:s,onGetLegth:o,onGetValue:r,animationDuration:(e==null?void 0:e.animationDuration)??200,removingClass:(e==null?void 0:e.removingClass)??"removing",insertingFromClass:(e==null?void 0:e.insertingFromClass)??"from-inserting",delayBeforeRemove:(e==null?void 0:e.delayBeforeRemove)??200,delayBeforeInsert:(e==null?void 0:e.delayBeforeInsert)??200,mapFrom:(e==null?void 0:e.mapFrom)??i,delayBeforeTouchMoveEvent:(e==null?void 0:e.delayBeforeTouchMoveEvent)??150,coordinateTransform:(e==null?void 0:e.coordinateTransform)??[a=>a]}};function ts(t,e,n,s="index"){let o=[],r=[],i;const a=Qn(t,n),f=D=>{for(const A of o)A(D)},g=(D,A)=>{if(a.onGetLegth()===0)t.insertToListEmpty(a,D,A);else for(const M of r)M(D,A)},d=D=>{const[A,T]=Kn(a,e,D,s);o=A,r=T},h=D=>{const A=Array.from(D.addedNodes??[]).values().filter(M=>!zt(M)).toArray(),T=Array.from(D.removedNodes??[]).values().filter(M=>!zt(M)).toArray();return A.length>0||T.length>0},x=D=>{i=Kt(()=>{d(D)},D,{childList:!0},h)},R=D=>{st(D,Yt)},b=D=>{ct.addConfig(D,a)};return[f,g,D=>{if(D)return R(D),b(D),x(D),d(D),ct.removeObsoleteConfigs(),i}]}exports.DISABLE_TRANSITION=Ye;exports.DRAGGABLE_CLASS=W;exports.GRAB_CLASS=le;exports.addClass=st;exports.addTempChild=jt;exports.addTempChildOnInsert=In;exports.containClass=U;exports.dragAndDrop=ts;exports.draggableTargetTimingFunction=Ut;exports.getParentDraggableChildren=Ue;exports.getSiblings=Ot;exports.getTranslationByDraggingAndEvent=St;exports.isTempElement=zt;exports.moveTranslate=ot;exports.observeMutation=Kt;exports.removeClass=_t;exports.removeTempChild=Bt;exports.removeTranslateWhitoutTransition=It;exports.setTranistion=yt;exports.toggleClass=it;exports.useChangeDraggableStyles=xe;