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