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