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