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