import{c as U,t as M,n as V,b as D,d as j,r as q,q as F,u as re,a4 as ve,e as d,X as G,w as E,aL as fe,aS as de,b2 as he,x as J,al as ge,aM as me,am as we,ad as ye,Y as be,a as $,aE as K,y as Q,a9 as k,p as pe,_ as R,k as Z,a7 as xe}from"./index-7f5059d9.js";const[ee,z]=U("swipe"),Se={loop:M,width:V,height:V,vertical:Boolean,autoplay:D(0),duration:D(500),touchable:M,lazyRender:Boolean,initialSwipe:D(0),indicatorColor:String,showIndicators:M,stopPropagation:M},te=Symbol(ee);var Te=j({name:ee,props:Se,emits:["change","dragStart","dragEnd"],setup(a,{emit:b,slots:g}){const u=q(),h=q(),t=F({rect:null,width:0,height:0,offset:0,active:0,swiping:!1});let p=!1;const r=re(),{children:m,linkChildren:o}=ve(te),i=d(()=>m.length),s=d(()=>t[a.vertical?"height":"width"]),v=d(()=>a.vertical?r.deltaY.value:r.deltaX.value),y=d(()=>t.rect?(a.vertical?t.rect.height:t.rect.width)-s.value*i.value:0),I=d(()=>s.value?Math.ceil(Math.abs(y.value)/s.value):i.value),_=d(()=>i.value*s.value),x=d(()=>(t.active+i.value)%i.value),Y=d(()=>{const e=a.vertical?"vertical":"horizontal";return r.direction.value===e}),ae=d(()=>{const e={transitionDuration:`${t.swiping?0:a.duration}ms`,transform:`translate${a.vertical?"Y":"X"}(${t.offset}px)`};if(s.value){const l=a.vertical?"height":"width",n=a.vertical?"width":"height";e[l]=`${_.value}px`,e[n]=a[n]?`${a[n]}px`:""}return e}),ie=e=>{const{active:l}=t;return e?a.loop?R(l+e,-1,i.value):R(l+e,0,I.value):l},B=(e,l=0)=>{let n=e*s.value;a.loop||(n=Math.min(n,-y.value));let f=l-n;return a.loop||(f=R(f,y.value,0)),f},w=({pace:e=0,offset:l=0,emitChange:n})=>{if(i.value<=1)return;const{active:f}=t,c=ie(e),C=B(c,l);if(a.loop){if(m[0]&&C!==y.value){const O=C0;m[i.value-1].setOffset(O?-_.value:0)}}t.active=c,t.offset=C,n&&c!==f&&b("change",x.value)},A=()=>{t.swiping=!0,t.active<=-1?w({pace:i.value}):t.active>=i.value&&w({pace:-i.value})},ne=()=>{A(),r.reset(),k(()=>{t.swiping=!1,w({pace:-1,emitChange:!0})})},X=()=>{A(),r.reset(),k(()=>{t.swiping=!1,w({pace:1,emitChange:!0})})};let H;const T=()=>clearTimeout(H),P=()=>{T(),+a.autoplay>0&&i.value>1&&(H=setTimeout(()=>{X(),P()},+a.autoplay))},S=(e=+a.initialSwipe)=>{if(!u.value)return;const l=()=>{var n,f;if(!K(u)){const c={width:u.value.offsetWidth,height:u.value.offsetHeight};t.rect=c,t.width=+((n=a.width)!=null?n:c.width),t.height=+((f=a.height)!=null?f:c.height)}i.value&&(e=Math.min(i.value-1,e),e===-1&&(e=i.value-1)),t.active=e,t.swiping=!0,t.offset=B(e),m.forEach(c=>{c.setOffset(0)}),P()};K(u)?Q().then(l):l()},L=()=>S(t.active);let N;const le=e=>{!a.touchable||e.touches.length>1||(r.start(e),p=!1,N=Date.now(),T(),A())},se=e=>{a.touchable&&t.swiping&&(r.move(e),Y.value&&(!a.loop&&(t.active===0&&v.value>0||t.active===i.value-1&&v.value<0)||(pe(e,a.stopPropagation),w({offset:v.value}),p||(b("dragStart",{index:x.value}),p=!0))))},W=()=>{if(!a.touchable||!t.swiping)return;const e=Date.now()-N,l=v.value/e;if((Math.abs(l)>.25||Math.abs(v.value)>s.value/2)&&Y.value){const f=a.vertical?r.offsetY.value:r.offsetX.value;let c=0;a.loop?c=f>0?v.value>0?-1:1:0:c=-Math[v.value>0?"ceil":"floor"](v.value/s.value),w({pace:c,emitChange:!0})}else v.value&&w({pace:0});p=!1,t.swiping=!1,b("dragEnd",{index:x.value}),P()},oe=(e,l={})=>{A(),r.reset(),k(()=>{let n;a.loop&&e===i.value?n=t.active===0?0:e:n=e%i.value,l.immediate?k(()=>{t.swiping=!1}):t.swiping=!1,w({pace:n-t.active,emitChange:!0})})},ce=(e,l)=>{const n=l===x.value,f=n?{backgroundColor:a.indicatorColor}:void 0;return $("i",{style:f,class:z("indicator",{active:n})},null)},ue=()=>{if(g.indicator)return g.indicator({active:x.value,total:i.value});if(a.showIndicators&&i.value>1)return $("div",{class:z("indicators",{vertical:a.vertical})},[Array(i.value).fill("").map(ce)])};return G({prev:ne,next:X,state:t,resize:L,swipeTo:oe}),o({size:s,props:a,count:i,activeIndicator:x}),E(()=>a.initialSwipe,e=>S(+e)),E(i,()=>S(t.active)),E(()=>a.autoplay,P),E([fe,de],L),E(he(),e=>{e==="visible"?P():T()}),J(S),ge(()=>S(t.active)),me(()=>S(t.active)),we(T),ye(T),be("touchmove",se,{target:h}),()=>{var e;return $("div",{ref:u,class:z()},[$("div",{ref:h,style:ae.value,class:z("track",{vertical:a.vertical}),onTouchstartPassive:le,onTouchend:W,onTouchcancel:W},[(e=g.default)==null?void 0:e.call(g)]),ue()])}}});const Ae=Z(Te),[Pe,Ce]=U("swipe-item");var Ee=j({name:Pe,setup(a,{slots:b}){let g;const u=F({offset:0,inited:!1,mounted:!1}),{parent:h,index:t}=xe(te);if(!h)return;const p=d(()=>{const o={},{vertical:i}=h.props;return h.size.value&&(o[i?"height":"width"]=`${h.size.value}px`),u.offset&&(o.transform=`translate${i?"Y":"X"}(${u.offset}px)`),o}),r=d(()=>{const{loop:o,lazyRender:i}=h.props;if(!i||g)return!0;if(!u.mounted)return!1;const s=h.activeIndicator.value,v=h.count.value-1,y=s===0&&o?v:s-1,I=s===v&&o?0:s+1;return g=t.value===s||t.value===y||t.value===I,g}),m=o=>{u.offset=o};return J(()=>{Q(()=>{u.mounted=!0})}),G({setOffset:m}),()=>{var o;return $("div",{class:Ce(),style:p.value},[r.value?(o=b.default)==null?void 0:o.call(b):null])}}});const Me=Z(Ee);export{Ae as S,Me as a};