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