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