1 |
- import{E as U,H as z,G as N,ab as _,d as j,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 ge,a5 as me,i as C,ag as V,X as L,aq as we,ar as I,as as D,O as F,at as pe}from"./index.6b776f4b.js";const[J,M]=U("swipe"),ye={loop:z,width:N,height:N,vertical:Boolean,autoplay:_(0),duration:_(500),touchable:z,lazyRender:Boolean,initialSwipe:_(0),indicatorColor:String,showIndicators:z,stopPropagation:z},Q=Symbol(J);var be=j({name:J,props:ye,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:g,linkChildren:O}=ue(Q),i=d(()=>g.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),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]=`${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},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},m=({pace:t=0,offset:l=0,emitChange:o})=>{if(i.value<=1)return;const{active:v}=e,c=ee(t),S=R(c,l);if(a.loop){if(g[0]&&S!==f.value){const k=S<f.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,o&&c!==v&&P("change",w.value)},A=()=>{e.swiping=!0,e.active<=-1?m({pace:i.value}):e.active>=i.value&&m({pace:-i.value})},te=()=>{A(),s.reset(),I(()=>{e.swiping=!1,m({pace:-1,emitChange:!0})})},B=()=>{A(),s.reset(),I(()=>{e.swiping=!1,m({pace:1,emitChange:!0})})};let X;const b=()=>clearTimeout(X),x=()=>{b(),a.autoplay>0&&i.value>1&&(X=setTimeout(()=>{B(),x()},+a.autoplay))},p=(t=+a.initialSwipe)=>{if(!u.value)return;const l=()=>{var o,v;if(!V(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),g.forEach(c=>{c.setOffset(0)}),x()};V(u)?L().then(l):l()},Y=()=>p(e.active);let H;const ae=t=>{!a.touchable||(s.start(t),H=Date.now(),b(),A())},ie=t=>{a.touchable&&e.swiping&&(s.move(t),E.value&&(we(t,a.stopPropagation),m({offset:r.value})))},W=()=>{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),m({pace:c,emitChange:!0})}else r.value&&m({pace:0});e.swiping=!1,x()},ne=(t,l={})=>{A(),s.reset(),I(()=>{let o;a.loop&&t===i.value?o=e.active===0?0:t:o=t%i.value,l.immediate?I(()=>{e.swiping=!1}):e.swiping=!1,m({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,x),T([re,ve],Y),T(fe(),t=>{t==="visible"?x():b()}),K(p),de(()=>p(e.active)),he(()=>p(e.active)),ge(b),me(b),()=>{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:W,onTouchcancel:W},[(t=h.default)==null?void 0:t.call(h)]),le()])}}});const Pe=F(be),[xe,Se]=U("swipe-item");var Te=j({name:xe,setup(a,{slots:P}){let h;const u=q({offset:0,inited:!1,mounted:!1}),{parent:e,index:s}=pe(Q);if(!e)return;const g=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,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 C("div",{class:Se(),style:g.value},[O.value?(n=P.default)==null?void 0:n.call(P):null])}}});const $e=F(Te);export{Pe as S,$e as a};
|