1 |
- import{t as e,C as a,w as t,A as i,d as l,E as o,r as s,aA as n,ab as c,c as u,a9 as v,H as r,a6 as h,a7 as p,G as d,o as f,ac as g,ad as w,Z as m,_ as x,k as y,a as b,a4 as C,K as S,aB as z,ap as M,ay as T,x as k,an as E}from"./index-08a3bcfa.js";const[I,O]=e("swipe"),X={loop:a,width:t,height:t,vertical:Boolean,autoplay:i(0),duration:i(500),touchable:a,lazyRender:Boolean,initialSwipe:i(0),indicatorColor:String,showIndicators:a,stopPropagation:a},Y=Symbol(I),A=k(l({name:I,props:X,emits:["change","dragStart","dragEnd"],setup(e,{emit:a,slots:t}){const i=o(),l=o(),k=s({rect:null,width:0,height:0,offset:0,active:0,swiping:!1});let E=!1;const I=n(),{children:X,linkChildren:A}=c(Y),B=u((()=>X.length)),D=u((()=>k[e.vertical?"height":"width"])),P=u((()=>e.vertical?I.deltaY.value:I.deltaX.value)),H=u((()=>k.rect?(e.vertical?k.rect.height:k.rect.width)-D.value*B.value:0)),R=u((()=>D.value?Math.ceil(Math.abs(H.value)/D.value):B.value)),j=u((()=>B.value*D.value)),F=u((()=>(k.active+B.value)%B.value)),G=u((()=>{const a=e.vertical?"vertical":"horizontal";return I.direction.value===a})),K=u((()=>{const a={transitionDuration:"".concat(k.swiping?0:e.duration,"ms"),transform:"translate".concat(e.vertical?"Y":"X","(").concat(+k.offset.toFixed(2),"px)")};if(D.value){const t=e.vertical?"height":"width",i=e.vertical?"width":"height";a[t]="".concat(j.value,"px"),a[i]=e[i]?"".concat(e[i],"px"):""}return a})),W=(a,t=0)=>{let i=a*D.value;e.loop||(i=Math.min(i,-H.value));let l=t-i;return e.loop||(l=T(l,H.value,0)),l},Z=({pace:t=0,offset:i=0,emitChange:l})=>{if(B.value<=1)return;const{active:o}=k,s=(a=>{const{active:t}=k;return a?e.loop?T(t+a,-1,B.value):T(t+a,0,R.value):t})(t),n=W(s,i);if(e.loop){if(X[0]&&n!==H.value){const e=n<H.value;X[0].setOffset(e?j.value:0)}if(X[B.value-1]&&0!==n){const e=n>0;X[B.value-1].setOffset(e?-j.value:0)}}k.active=s,k.offset=n,l&&s!==o&&a("change",F.value)},_=()=>{k.swiping=!0,k.active<=-1?Z({pace:B.value}):k.active>=B.value&&Z({pace:-B.value})},q=()=>{_(),I.reset(),M((()=>{k.swiping=!1,Z({pace:1,emitChange:!0})}))};let J;const L=()=>clearTimeout(J),N=()=>{L(),+e.autoplay>0&&B.value>1&&(J=setTimeout((()=>{q(),N()}),+e.autoplay))},Q=(a=+e.initialSwipe)=>{if(!i.value)return;const t=()=>{var t,l;if(!C(i)){const a={width:i.value.offsetWidth,height:i.value.offsetHeight};k.rect=a,k.width=+(null!=(t=e.width)?t:a.width),k.height=+(null!=(l=e.height)?l:a.height)}B.value&&-1===(a=Math.min(B.value-1,a))&&(a=B.value-1),k.active=a,k.swiping=!0,k.offset=W(a),X.forEach((e=>{e.setOffset(0)})),N()};C(i)?S().then(t):t()},U=()=>Q(k.active);let V;const $=a=>{!e.touchable||a.touches.length>1||(I.start(a),E=!1,V=Date.now(),L(),_())},ee=()=>{if(!e.touchable||!k.swiping)return;const t=Date.now()-V,i=P.value/t;if((Math.abs(i)>.25||Math.abs(P.value)>D.value/2)&&G.value){const a=e.vertical?I.offsetY.value:I.offsetX.value;let t=0;t=e.loop?a>0?P.value>0?-1:1:0:-Math[P.value>0?"ceil":"floor"](P.value/D.value),Z({pace:t,emitChange:!0})}else P.value&&Z({pace:0});E=!1,k.swiping=!1,a("dragEnd",{index:F.value}),N()},ae=(a,t)=>{const i=t===F.value,l=i?{backgroundColor:e.indicatorColor}:void 0;return b("i",{style:l,"class":O("indicator",{active:i})},null)};return v({prev:()=>{_(),I.reset(),M((()=>{k.swiping=!1,Z({pace:-1,emitChange:!0})}))},next:q,state:k,resize:U,swipeTo:(a,t={})=>{_(),I.reset(),M((()=>{let i;i=e.loop&&a===B.value?0===k.active?0:a:a%B.value,t.immediate?M((()=>{k.swiping=!1})):k.swiping=!1,Z({pace:i-k.active,emitChange:!0})}))}}),A({size:D,props:e,count:B,activeIndicator:F}),r((()=>e.initialSwipe),(e=>Q(+e))),r(B,(()=>Q(k.active))),r((()=>e.autoplay),N),r([h,p,()=>e.width,()=>e.height],U),r(d(),(e=>{"visible"===e?N():L()})),f(Q),g((()=>Q(k.active))),w((()=>Q(k.active))),m(L),x(L),y("touchmove",(t=>{e.touchable&&k.swiping&&(I.move(t),G.value)&&(!e.loop&&(0===k.active&&P.value>0||k.active===B.value-1&&P.value<0)||(z(t,e.stopPropagation),Z({offset:P.value}),E||(a("dragStart",{index:F.value}),E=!0)))}),{target:l}),()=>{var a;return b("div",{ref:i,"class":O()},[b("div",{ref:l,style:K.value,"class":O("track",{vertical:e.vertical}),onTouchstartPassive:$,onTouchend:ee,onTouchcancel:ee},[null==(a=t["default"])?void 0:a.call(t)]),t.indicator?t.indicator({active:F.value,total:B.value}):e.showIndicators&&B.value>1?b("div",{"class":O("indicators",{vertical:e.vertical})},[Array(B.value).fill("").map(ae)]):void 0])}}})),[B,D]=e("swipe-item"),P=k(l({name:B,setup(e,{slots:a}){let t;const i=s({offset:0,inited:!1,mounted:!1}),{parent:l,index:o}=E(Y);if(!l)return;const n=u((()=>{const e={},{vertical:a}=l.props;return l.size.value&&(e[a?"height":"width"]="".concat(l.size.value,"px")),i.offset&&(e.transform="translate".concat(a?"Y":"X","(").concat(i.offset,"px)")),e})),c=u((()=>{const{loop:e,lazyRender:a}=l.props;if(!a||t)return!0;if(!i.mounted)return!1;const s=l.activeIndicator.value,n=l.count.value-1,c=0===s&&e?n:s-1,u=s===n&&e?0:s+1;return t=o.value===s||o.value===c||o.value===u,t}));return f((()=>{S((()=>{i.mounted=!0}))})),v({setOffset:e=>{i.offset=e}}),()=>{var e;return b("div",{"class":D(),style:n.value},[c.value?null==(e=a["default"])?void 0:e.call(a):null])}}}));export{A as S,P as a};
|