index.cf00521e.js 4.8 KB

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