import{c as F,t as A,n as W,b as O,v as le,f as G,e as ce,x as ue,o as re,i as V,y as ve,z as _,w as K}from"./index.555136dd.js";import{d as L,r as fe,k as U,E as de,p as d,w as S,M as he,D as j,G as me,y as ge,z as we,c as C,F as q,N as I,I as ye}from"./index.fdb8061e.js";const[J,M]=F("swipe"),pe={loop:A,width:W,height:W,vertical:Boolean,autoplay:O(0),duration:O(500),touchable:A,lazyRender:Boolean,initialSwipe:O(0),indicatorColor:String,showIndicators:A,stopPropagation:A},Q=Symbol(J);var be=L({name:J,props:pe,emits:["change"],setup(a,{emit:P,slots:h}){const u=fe(),e=U({rect:null,width:0,height:0,offset:0,active:0,swiping:!1}),l=le(),{children:m,linkChildren:k}=de(Q),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?_(s+t,-1,i.value):_(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=_(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),T=R(c,s);if(a.loop){if(m[0]&&T!==f.value){const D=T<f.value;m[0].setOffset(D?p.value:0)}if(m[i.value-1]&&T!==0){const D=T>0;m[i.value-1].setOffset(D?-p.value:0)}}e.active=c,e.offset=T,o&&c!==v&&P("change",w.value)},z=()=>{e.swiping=!0,e.active<=-1?g({pace:i.value}):e.active>=i.value&&g({pace:-i.value})},te=()=>{z(),l.reset(),I(()=>{e.swiping=!1,g({pace:-1,emitChange:!0})})},B=()=>{z(),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(!V(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()};V(u)?q().then(s):s()},N=()=>y(e.active);let X;const ae=t=>{!a.touchable||(l.start(t),X=Date.now(),b(),z())},ie=t=>{a.touchable&&e.swiping&&(l.move(t),E.value&&(ve(t,a.stopPropagation),g({offset:r.value})))},H=()=>{if(!a.touchable||!e.swiping)return;const t=Date.now()-X,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={})=>{z(),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 G({prev:te,next:B,state:e,resize:N,swipeTo:ne}),k({size:n,props:a,count:i,activeIndicator:w}),S(()=>a.initialSwipe,t=>y(+t)),S(i,()=>y(e.active)),S(()=>a.autoplay,x),S([ce,ue],N),S(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:H,onTouchcancel:H},[(t=h.default)==null?void 0:t.call(h)]),se()])}}});const $e=K(be),[xe,Te]=F("swipe-item");var Se=L({name:xe,setup(a,{slots:P}){let h;const u=U({offset:0,inited:!1,mounted:!1}),{parent:e,index:l}=ye(Q);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}),k=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})}),G({setOffset:i}),()=>{var n;return C("div",{class:Te(),style:m.value},[k.value?(n=P.default)==null?void 0:n.call(P):null])}}});const ze=K(Se);export{$e as S,ze as a};
