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