index-legacy-a0dec7b5.js 5.1 KB

1
  1. System.register(["./index-legacy-2e3f3675.js"],(function(e,t){"use strict";var a,i,l,o,n,u,r,v,s,c,h,p,d,f,g,w,m,b,y,x,S,C,z,M,$,T,I,k,E;return{setters:[e=>{a=e.c,i=e.t,l=e.n,o=e.b,n=e.d,u=e.r,r=e.x,v=e.u,s=e.ab,c=e.e,h=e.Z,p=e.w,d=e.bL,f=e.bM,g=e.aL,w=e.y,m=e.aU,b=e.bN,y=e.aV,x=e.aC,S=e._,C=e.a,z=e.bE,M=e.z,$=e.aP,T=e.p,I=e.a0,k=e.k,E=e.ae}],execute:function(){const[t,O]=a("swipe"),P={loop:i,width:l,height:l,vertical:Boolean,autoplay:o(0),duration:o(500),touchable:i,lazyRender:Boolean,initialSwipe:o(0),indicatorColor:String,showIndicators:i,stopPropagation:i},X=Symbol(t);var Y=n({name:t,props:P,emits:["change","dragStart","dragEnd"],setup(e,{emit:t,slots:a}){const i=u(),l=u(),o=r({rect:null,width:0,height:0,offset:0,active:0,swiping:!1});let n=!1;const k=v(),{children:E,linkChildren:P}=s(X),Y=c((()=>E.length)),D=c((()=>o[e.vertical?"height":"width"])),B=c((()=>e.vertical?k.deltaY.value:k.deltaX.value)),L=c((()=>o.rect?(e.vertical?o.rect.height:o.rect.width)-D.value*Y.value:0)),R=c((()=>D.value?Math.ceil(Math.abs(L.value)/D.value):Y.value)),V=c((()=>Y.value*D.value)),j=c((()=>(o.active+Y.value)%Y.value)),A=c((()=>{const t=e.vertical?"vertical":"horizontal";return k.direction.value===t})),H=c((()=>{const t={transitionDuration:`${o.swiping?0:e.duration}ms`,transform:`translate${e.vertical?"Y":"X"}(${o.offset}px)`};if(D.value){const a=e.vertical?"height":"width",i=e.vertical?"width":"height";t[a]=`${V.value}px`,t[i]=e[i]?`${e[i]}px`:""}return t})),N=(t,a=0)=>{let i=t*D.value;e.loop||(i=Math.min(i,-L.value));let l=a-i;return e.loop||(l=I(l,L.value,0)),l},U=({pace:a=0,offset:i=0,emitChange:l})=>{if(Y.value<=1)return;const{active:n}=o,u=(t=>{const{active:a}=o;return t?e.loop?I(a+t,-1,Y.value):I(a+t,0,R.value):a})(a),r=N(u,i);if(e.loop){if(E[0]&&r!==L.value){const e=r<L.value;E[0].setOffset(e?V.value:0)}if(E[Y.value-1]&&0!==r){const e=r>0;E[Y.value-1].setOffset(e?-V.value:0)}}o.active=u,o.offset=r,l&&u!==n&&t("change",j.value)},W=()=>{o.swiping=!0,o.active<=-1?U({pace:Y.value}):o.active>=Y.value&&U({pace:-Y.value})},Z=()=>{W(),k.reset(),$((()=>{o.swiping=!1,U({pace:1,emitChange:!0})}))};let _;const q=()=>clearTimeout(_),F=()=>{q(),+e.autoplay>0&&Y.value>1&&(_=setTimeout((()=>{Z(),F()}),+e.autoplay))},G=(t=+e.initialSwipe)=>{if(!i.value)return;const a=()=>{var a,l;if(!z(i)){const t={width:i.value.offsetWidth,height:i.value.offsetHeight};o.rect=t,o.width=+(null!=(a=e.width)?a:t.width),o.height=+(null!=(l=e.height)?l:t.height)}Y.value&&-1===(t=Math.min(Y.value-1,t))&&(t=Y.value-1),o.active=t,o.swiping=!0,o.offset=N(t),E.forEach((e=>{e.setOffset(0)})),F()};z(i)?M().then(a):a()},J=()=>G(o.active);let K;const Q=t=>{!e.touchable||t.touches.length>1||(k.start(t),n=!1,K=Date.now(),q(),W())},ee=()=>{if(!e.touchable||!o.swiping)return;const a=Date.now()-K,i=B.value/a;if((Math.abs(i)>.25||Math.abs(B.value)>D.value/2)&&A.value){const t=e.vertical?k.offsetY.value:k.offsetX.value;let a=0;a=e.loop?t>0?B.value>0?-1:1:0:-Math[B.value>0?"ceil":"floor"](B.value/D.value),U({pace:a,emitChange:!0})}else B.value&&U({pace:0});n=!1,o.swiping=!1,t("dragEnd",{index:j.value}),F()},te=(t,a)=>{const i=a===j.value,l=i?{backgroundColor:e.indicatorColor}:void 0;return C("i",{style:l,class:O("indicator",{active:i})},null)};return h({prev:()=>{W(),k.reset(),$((()=>{o.swiping=!1,U({pace:-1,emitChange:!0})}))},next:Z,state:o,resize:J,swipeTo:(t,a={})=>{W(),k.reset(),$((()=>{let i;i=e.loop&&t===Y.value?0===o.active?0:t:t%Y.value,a.immediate?$((()=>{o.swiping=!1})):o.swiping=!1,U({pace:i-o.active,emitChange:!0})}))}}),P({size:D,props:e,count:Y,activeIndicator:j}),p((()=>e.initialSwipe),(e=>G(+e))),p(Y,(()=>G(o.active))),p((()=>e.autoplay),F),p([d,f,()=>e.width,()=>e.height],J),p(g(),(e=>{"visible"===e?F():q()})),w(G),m((()=>G(o.active))),b((()=>G(o.active))),y(q),x(q),S("touchmove",(a=>{e.touchable&&o.swiping&&(k.move(a),A.value)&&(!e.loop&&(0===o.active&&B.value>0||o.active===Y.value-1&&B.value<0)||(T(a,e.stopPropagation),U({offset:B.value}),n||(t("dragStart",{index:j.value}),n=!0)))}),{target:l}),()=>{var t;return C("div",{ref:i,class:O()},[C("div",{ref:l,style:H.value,class:O("track",{vertical:e.vertical}),onTouchstartPassive:Q,onTouchend:ee,onTouchcancel:ee},[null==(t=a.default)?void 0:t.call(a)]),a.indicator?a.indicator({active:j.value,total:Y.value}):e.showIndicators&&Y.value>1?C("div",{class:O("indicators",{vertical:e.vertical})},[Array(Y.value).fill("").map(te)]):void 0])}}});e("S",k(Y));const[D,B]=a("swipe-item");var L=n({name:D,setup(e,{slots:t}){let a;const i=r({offset:0,inited:!1,mounted:!1}),{parent:l,index:o}=E(X);if(!l)return void console.error("[Vant] <SwipeItem> must be a child component of <Swipe>.");const n=c((()=>{const e={},{vertical:t}=l.props;return l.size.value&&(e[t?"height":"width"]=`${l.size.value}px`),i.offset&&(e.transform=`translate${t?"Y":"X"}(${i.offset}px)`),e})),u=c((()=>{const{loop:e,lazyRender:t}=l.props;if(!t||a)return!0;if(!i.mounted)return!1;const n=l.activeIndicator.value,u=l.count.value-1,r=0===n&&e?u:n-1,v=n===u&&e?0:n+1;return a=o.value===n||o.value===r||o.value===v,a}));return w((()=>{M((()=>{i.mounted=!0}))})),h({setOffset:e=>{i.offset=e}}),()=>{var e;return C("div",{class:B(),style:n.value},[u.value?null==(e=t.default)?void 0:e.call(t):null])}}});e("a",k(L))}}}));