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