index.7077e759.js 4.7 KB

1
  1. import{c as L,t as z,n as N,b as _,x as le,f as U,e as ce,y as ue,o as re,i as V,z as ve,A as k,w as J}from"./index.2b675c4f.js";import{d as K,r as fe,n as j,R as de,y as d,w as S,V as he,o as q,L as me,D as ge,E as we,c as C,J as F,W as I,U as ye}from"./index.3718c0a8.js";const[G,M]=L("swipe"),pe={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(G);var be=K({name:G,props:pe,emits:["change"],setup(a,{emit:P,slots:h}){const u=fe(),e=j({rect:null,width:0,height:0,offset:0,active:0,swiping:!1}),l=le(),{children:m,linkChildren:D}=de(Q),i=d(()=>m.length),n=d(()=>e[a.vertical?"height":"width"]),r=d(()=>a.vertical?l.deltaY.value:l.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)),p=d(()=>i.value*n.value),w=d(()=>(e.active+i.value)%i.value),R=d(()=>{const t=a.vertical?"vertical":"horizontal";return l.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 s=a.vertical?"height":"width",o=a.vertical?"width":"height";t[s]=`${p.value}px`,t[o]=a[o]?`${a[o]}px`:""}return t}),ee=t=>{const{active:s}=e;return t?a.loop?k(s+t,-1,i.value):k(s+t,0,$.value):s},E=(t,s=0)=>{let o=t*n.value;a.loop||(o=Math.min(o,-f.value));let v=s-o;return a.loop||(v=k(v,f.value,0)),v},g=({pace:t=0,offset:s=0,emitChange:o})=>{if(i.value<=1)return;const{active:v}=e,c=ee(t),T=E(c,s);if(a.loop){if(m[0]&&T!==f.value){const O=T<f.value;m[0].setOffset(O?p.value:0)}if(m[i.value-1]&&T!==0){const O=T>0;m[i.value-1].setOffset(O?-p.value:0)}}e.active=c,e.offset=T,o&&c!==v&&P("change",w.value)},A=()=>{e.swiping=!0,e.active<=-1?g({pace:i.value}):e.active>=i.value&&g({pace:-i.value})},te=()=>{A(),l.reset(),I(()=>{e.swiping=!1,g({pace:-1,emitChange:!0})})},B=()=>{A(),l.reset(),I(()=>{e.swiping=!1,g({pace:1,emitChange:!0})})};let Y;const b=()=>clearTimeout(Y),x=()=>{b(),a.autoplay>0&&i.value>1&&(Y=setTimeout(()=>{B(),x()},+a.autoplay))},y=(t=+a.initialSwipe)=>{if(!u.value)return;const s=()=>{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=E(t),m.forEach(c=>{c.setOffset(0)}),x()};V(u)?F().then(s):s()},W=()=>y(e.active);let X;const ae=t=>{!a.touchable||(l.start(t),X=Date.now(),b(),A())},ie=t=>{a.touchable&&e.swiping&&(l.move(t),R.value&&(ve(t,a.stopPropagation),g({offset:r.value})))},H=()=>{if(!a.touchable||!e.swiping)return;const t=Date.now()-X,s=r.value/t;if((Math.abs(s)>.25||Math.abs(r.value)>n.value/2)&&R.value){const v=a.vertical?l.offsetY.value:l.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),g({pace:c,emitChange:!0})}else r.value&&g({pace:0});e.swiping=!1,x()},ne=(t,s={})=>{A(),l.reset(),I(()=>{let o;a.loop&&t===i.value?o=e.active===0?0:t:o=t%i.value,s.immediate?I(()=>{e.swiping=!1}):e.swiping=!1,g({pace:o-e.active,emitChange:!0})})},oe=(t,s)=>{const o=s===w.value,v=o?{backgroundColor:a.indicatorColor}:void 0;return C("i",{style:v,class:M("indicator",{active:o})},null)},se=()=>{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 U({prev:te,next:B,state:e,resize:W,swipeTo:ne}),D({size:n,props:a,count:i,activeIndicator:w}),S(()=>a.initialSwipe,t=>y(+t)),S(i,()=>y(e.active)),S(()=>a.autoplay,x),S([ce,ue],W),S(he(),t=>{t==="visible"?x():b()}),q(y),me(()=>y(e.active)),re(()=>y(e.active)),ge(b),we(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:H,onTouchcancel:H},[(t=h.default)==null?void 0:t.call(h)]),se()])}}});const $e=J(be),[xe,Te]=L("swipe-item");var Se=K({name:xe,setup(a,{slots:P}){let h;const u=j({offset:0,inited:!1,mounted:!1}),{parent:e,index:l}=ye(Q);if(!e)return;const m=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}),D=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,p=f===0&&n?$:f-1,w=f===$&&n?0:f+1;return h=l.value===f||l.value===p||l.value===w,h}),i=n=>{u.offset=n};return q(()=>{F(()=>{u.mounted=!0})}),U({setOffset:i}),()=>{var n;return C("div",{class:Te(),style:m.value},[D.value?(n=P.default)==null?void 0:n.call(P):null])}}});const Ae=J(Se);export{$e as S,Ae as a};