import{w as e,x as a,y as t,z as i,d as l,S as o,r as s,aG as n,A as c,c as u,aj as v,V as r,ag as h,ah as p,U as d,o as f,al as g,am as w,a8 as m,a9 as x,k as y,a as b,ae as C,X as S,aH as z,av as M,aE as T,E,I}from"./index-13c35f79.js";const[X,k]=e("swipe"),O={loop:a,width:t,height:t,vertical:Boolean,autoplay:i(0),duration:i(500),touchable:a,lazyRender:Boolean,initialSwipe:i(0),indicatorColor:String,showIndicators:a,stopPropagation:a},Y=Symbol(X),D=E(l({name:X,props:O,emits:["change","dragStart","dragEnd"],setup(e,{emit:a,slots:t}){const i=o(),l=o(),E=s({rect:null,width:0,height:0,offset:0,active:0,swiping:!1});let I=!1;const X=n(),{children:O,linkChildren:D}=c(Y),P=u((()=>O.length)),j=u((()=>E[e.vertical?"height":"width"])),A=u((()=>e.vertical?X.deltaY.value:X.deltaX.value)),B=u((()=>E.rect?(e.vertical?E.rect.height:E.rect.width)-j.value*P.value:0)),H=u((()=>j.value?Math.ceil(Math.abs(B.value)/j.value):P.value)),R=u((()=>P.value*j.value)),F=u((()=>(E.active+P.value)%P.value)),G=u((()=>{const a=e.vertical?"vertical":"horizontal";return X.direction.value===a})),U=u((()=>{const a={transitionDuration:"".concat(E.swiping?0:e.duration,"ms"),transform:"translate".concat(e.vertical?"Y":"X","(").concat(+E.offset.toFixed(2),"px)")};if(j.value){const t=e.vertical?"height":"width",i=e.vertical?"width":"height";a[t]="".concat(R.value,"px"),a[i]=e[i]?"".concat(e[i],"px"):""}return a})),V=(a,t=0)=>{let i=a*j.value;e.loop||(i=Math.min(i,-B.value));let l=t-i;return e.loop||(l=T(l,B.value,0)),l},W=({pace:t=0,offset:i=0,emitChange:l})=>{if(P.value<=1)return;const{active:o}=E,s=(a=>{const{active:t}=E;return a?e.loop?T(t+a,-1,P.value):T(t+a,0,H.value):t})(t),n=V(s,i);if(e.loop){if(O[0]&&n!==B.value){const e=n0;O[P.value-1].setOffset(e?-R.value:0)}}E.active=s,E.offset=n,l&&s!==o&&a("change",F.value)},q=()=>{E.swiping=!0,E.active<=-1?W({pace:P.value}):E.active>=P.value&&W({pace:-P.value})},J=()=>{q(),X.reset(),M((()=>{E.swiping=!1,W({pace:1,emitChange:!0})}))};let K;const L=()=>clearTimeout(K),N=()=>{L(),+e.autoplay>0&&P.value>1&&(K=setTimeout((()=>{J(),N()}),+e.autoplay))},Q=(a=+e.initialSwipe)=>{if(!i.value)return;const t=()=>{var t,l;if(!C(i)){const a={width:i.value.offsetWidth,height:i.value.offsetHeight};E.rect=a,E.width=+(null!=(t=e.width)?t:a.width),E.height=+(null!=(l=e.height)?l:a.height)}P.value&&-1===(a=Math.min(P.value-1,a))&&(a=P.value-1),E.active=a,E.swiping=!0,E.offset=V(a),O.forEach((e=>{e.setOffset(0)})),N()};C(i)?S().then(t):t()},Z=()=>Q(E.active);let $;const _=a=>{!e.touchable||a.touches.length>1||(X.start(a),I=!1,$=Date.now(),L(),q())},ee=()=>{if(!e.touchable||!E.swiping)return;const t=Date.now()-$,i=A.value/t;if((Math.abs(i)>.25||Math.abs(A.value)>j.value/2)&&G.value){const a=e.vertical?X.offsetY.value:X.offsetX.value;let t=0;t=e.loop?a>0?A.value>0?-1:1:0:-Math[A.value>0?"ceil":"floor"](A.value/j.value),W({pace:t,emitChange:!0})}else A.value&&W({pace:0});I=!1,E.swiping=!1,a("dragEnd",{index:F.value}),N()},ae=(a,t)=>{const i=t===F.value,l=i?{backgroundColor:e.indicatorColor}:void 0;return b("i",{style:l,"class":k("indicator",{active:i})},null)};return v({prev:()=>{q(),X.reset(),M((()=>{E.swiping=!1,W({pace:-1,emitChange:!0})}))},next:J,state:E,resize:Z,swipeTo:(a,t={})=>{q(),X.reset(),M((()=>{let i;i=e.loop&&a===P.value?0===E.active?0:a:a%P.value,t.immediate?M((()=>{E.swiping=!1})):E.swiping=!1,W({pace:i-E.active,emitChange:!0})}))}}),D({size:j,props:e,count:P,activeIndicator:F}),r((()=>e.initialSwipe),(e=>Q(+e))),r(P,(()=>Q(E.active))),r((()=>e.autoplay),N),r([h,p,()=>e.width,()=>e.height],Z),r(d(),(e=>{"visible"===e?N():L()})),f(Q),g((()=>Q(E.active))),w((()=>Q(E.active))),m(L),x(L),y("touchmove",(t=>{e.touchable&&E.swiping&&(X.move(t),G.value)&&(!e.loop&&(0===E.active&&A.value>0||E.active===P.value-1&&A.value<0)||(z(t,e.stopPropagation),W({offset:A.value}),I||(a("dragStart",{index:F.value}),I=!0)))}),{target:l}),()=>{var a;return b("div",{ref:i,"class":k()},[b("div",{ref:l,style:U.value,"class":k("track",{vertical:e.vertical}),onTouchstartPassive:_,onTouchend:ee,onTouchcancel:ee},[null==(a=t["default"])?void 0:a.call(t)]),t.indicator?t.indicator({active:F.value,total:P.value}):e.showIndicators&&P.value>1?b("div",{"class":k("indicators",{vertical:e.vertical})},[Array(P.value).fill("").map(ae)]):void 0])}}})),[P,j]=e("swipe-item"),A=E(l({name:P,setup(e,{slots:a}){let t;const i=s({offset:0,inited:!1,mounted:!1}),{parent:l,index:o}=I(Y);if(!l)return;const n=u((()=>{const e={},{vertical:a}=l.props;return l.size.value&&(e[a?"height":"width"]="".concat(l.size.value,"px")),i.offset&&(e.transform="translate".concat(a?"Y":"X","(").concat(i.offset,"px)")),e})),c=u((()=>{const{loop:e,lazyRender:a}=l.props;if(!a||t)return!0;if(!i.mounted)return!1;const s=l.activeIndicator.value,n=l.count.value-1,c=0===s&&e?n:s-1,u=s===n&&e?0:s+1;return t=o.value===s||o.value===c||o.value===u,t}));return f((()=>{S((()=>{i.mounted=!0}))})),v({setOffset:e=>{i.offset=e}}),()=>{var e;return b("div",{"class":j(),style:n.value},[c.value?null==(e=a["default"])?void 0:e.call(a):null])}}}));export{D as S,A as a};