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