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