index.6bbd7daa.js 8.4 KB

1
  1. import{aK as se,aI as j,ar as Ce,aF as Ie,R as C,aL as Re,t as F,d as X,aB as Y,Z as B,$ as ke,W as G,c as h,z,u as xe,w as V,v as U,Q as ce,ap as Be,x as _e,r as $e,y as x,aM as Ae,aN as Pe,_ as P,aO as ze,aP as Ne,aH as Le,a0 as Oe,aA as Ee,U as ne,a1 as q,G as We,I as He,aQ as ae,aR as Me,aS as De,an as le,aT as Ve,N as Ze,ae as Ue,O as Fe,C as Xe,aU as Ke,aV as Ye,X as Qe,ac as je,aW as qe,aX as Ge,aY as Je,E as pe,am as ie,ay as et,a9 as tt,D as de}from"./index.5f7ffb46.js";import{T as nt}from"./use-tab-status.69b57a37.js";import{S as at,a as lt}from"./index.99e0cf1f.js";import{u as it,S as ot}from"./index.61ab9823.js";function rt(e,l,i){let c,s=0;const n=e.scrollLeft,o=i===0?1:Math.round(i*1e3/16);function f(){se(c)}function d(){e.scrollLeft+=(l-n)/o,++s<o&&(c=j(d))}return d(),f}function st(e,l,i,c){let s,n=Ce(e);const o=n<l,f=i===0?1:Math.round(i*1e3/16),d=(l-n)/f;function m(){se(s)}function T(){n+=d,(o&&n>l||!o&&n<l)&&(n=l),Ie(e,n),o&&n<l||!o&&n>l?s=j(T):c&&(s=j(c))}return T(),m}function ct(){const e=C([]),l=[];return Re(()=>{e.value=[]}),[e,c=>(l[c]||(l[c]=s=>{e.value[c]=s}),l[c])]}const[dt,oe]=F("tabs");var ut=X({name:dt,props:{count:Y(Number),inited:Boolean,animated:Boolean,duration:Y(z),swipeable:Boolean,lazyRender:Boolean,currentIndex:Y(Number)},emits:["change"],setup(e,{emit:l,slots:i}){const c=C(),s=f=>l("change",f),n=()=>{var f;const d=(f=i.default)==null?void 0:f.call(i);return e.animated||e.swipeable?h(at,{ref:c,loop:!1,class:oe("track"),duration:+e.duration*1e3,touchable:e.swipeable,lazyRender:e.lazyRender,showIndicators:!1,onChange:s},{default:()=>[d]}):d},o=f=>{const d=c.value;d&&d.state.active!==f&&d.swipeTo(f,{immediate:!e.inited})};return B(()=>e.currentIndex,o),ke(()=>{o(e.currentIndex)}),G({swipeRef:c}),()=>h("div",{class:oe("content",{animated:e.animated||e.swipeable})},[n()])}});const[ue,Z]=F("tabs"),ft={type:xe("line"),color:String,border:Boolean,sticky:Boolean,shrink:Boolean,active:V(0),duration:V(.3),animated:Boolean,ellipsis:U,swipeable:Boolean,scrollspy:Boolean,offsetTop:V(0),background:String,lazyRender:U,lineWidth:z,lineHeight:z,beforeChange:Function,swipeThreshold:V(5),titleActiveColor:String,titleInactiveColor:String},fe=Symbol(ue);var vt=X({name:ue,props:ft,emits:["change","scroll","rendered","clickTab","update:active"],setup(e,{emit:l,slots:i}){let c,s,n,o,f;const d=C(),m=C(),T=C(),_=C(),$=ce(),I=Be(d),[b,S]=ct(),{children:v,linkChildren:K}=_e(fe),u=$e({inited:!1,position:"",lineStyle:{},currentIndex:-1}),N=x(()=>v.length>+e.swipeThreshold||!e.ellipsis||e.shrink),E=x(()=>({borderColor:e.color,background:e.background})),L=(t,a)=>{var r;return(r=t.name)!=null?r:a},W=x(()=>{const t=v[u.currentIndex];if(t)return L(t,u.currentIndex)}),A=x(()=>Ae(e.offsetTop)),J=x(()=>e.sticky?A.value+c:0),O=t=>{const a=m.value,r=b.value;if(!N.value||!a||!r||!r[u.currentIndex])return;const y=r[u.currentIndex].$el,g=y.offsetLeft-(a.offsetWidth-y.offsetWidth)/2;o&&o(),o=rt(a,g,t?0:+e.duration)},R=()=>{const t=u.inited;P(()=>{const a=b.value;if(!a||!a[u.currentIndex]||e.type!=="line"||Ee(d.value))return;const r=a[u.currentIndex].$el,{lineWidth:y,lineHeight:g}=e,w=r.offsetLeft+r.offsetWidth/2,k={width:ne(y),backgroundColor:e.color,transform:`translateX(${w}px) translateX(-50%)`};if(t&&(k.transitionDuration=`${e.duration}s`),q(g)){const D=ne(g);k.height=D,k.borderRadius=D}u.lineStyle=k})},ve=t=>{const a=t<u.currentIndex?-1:1;for(;t>=0&&t<v.length;){if(!v[t].disabled)return t;t+=a}},H=(t,a)=>{const r=ve(t);if(!q(r))return;const y=v[r],g=L(y,r),w=u.currentIndex!==null;u.currentIndex!==r&&(u.currentIndex=r,a||O(),R()),g!==e.active&&(l("update:active",g),w&&l("change",g,y.title)),n&&!e.scrollspy&&He(Math.ceil(ae(d.value)-A.value))},M=(t,a)=>{const r=v.find((g,w)=>L(g,w)===t),y=r?v.indexOf(r):0;H(y,a)},p=(t=!1)=>{if(e.scrollspy){const a=v[u.currentIndex].$el;if(a&&I.value){const r=ae(a,I.value)-J.value;s=!0,f&&f(),f=st(I.value,r,t?0:+e.duration,()=>{s=!1})}}},be=(t,a,r)=>{const{title:y,disabled:g}=v[a],w=L(v[a],a);g||(Me(e.beforeChange,{args:[w],done:()=>{H(a),p()}}),De(t)),l("clickTab",{name:w,title:y,event:r,disabled:g})},he=t=>{n=t.isFixed,l("scroll",t)},ge=t=>{P(()=>{M(t),p(!0)})},me=()=>{for(let t=0;t<v.length;t++){const{top:a}=le(v[t].$el);if(a>J.value)return t===0?0:t-1}return v.length-1},ye=()=>{if(e.scrollspy&&!s){const t=me();H(t)}},Te=()=>{if(e.type==="line"&&v.length)return h("div",{class:Z("line"),style:u.lineStyle},null)},ee=()=>{var t,a,r;const{type:y,border:g,sticky:w}=e,k=[h("div",{ref:w?void 0:T,class:[Z("wrap"),{[We]:y==="line"&&g}]},[h("div",{ref:m,role:"tablist",class:Z("nav",[y,{shrink:e.shrink,complete:N.value}]),style:E.value,"aria-orientation":"horizontal"},[(t=i["nav-left"])==null?void 0:t.call(i),v.map(D=>D.renderTitle(be)),Te(),(a=i["nav-right"])==null?void 0:a.call(i)])]),(r=i["nav-bottom"])==null?void 0:r.call(i)];return w?h("div",{ref:T},[k]):k},te=()=>{R(),P(()=>{var t,a;O(!0),(a=(t=_.value)==null?void 0:t.swipeRef.value)==null||a.resize()})};B(()=>[e.color,e.duration,e.lineWidth,e.lineHeight],R),B(Pe,te),B(()=>e.active,t=>{t!==W.value&&M(t)}),B(()=>v.length,()=>{u.inited&&(M(e.active),R(),P(()=>{O(!0)}))});const Se=()=>{M(e.active,!0),P(()=>{u.inited=!0,T.value&&(c=le(T.value).height),O(!0)})},we=(t,a)=>l("rendered",t,a);return G({resize:te,scrollTo:ge}),ze(R),Ne(R),Le(Se),it(d,R),Oe("scroll",ye,{target:I,passive:!0}),K({id:$,props:e,setLine:R,scrollable:N,onRendered:we,currentName:W,setTitleRefs:S,scrollIntoView:O}),()=>h("div",{ref:d,class:Z([e.type])},[e.sticky?h(ot,{container:d.value,offsetTop:A.value,onScroll:he},{default:()=>[ee()]}):ee(),h(ut,{ref:_,count:v.length,inited:u.inited,animated:e.animated,duration:e.duration,swipeable:e.swipeable,lazyRender:e.lazyRender,currentIndex:u.currentIndex,onChange:H},{default:()=>{var t;return[(t=i.default)==null?void 0:t.call(i)]}})])}});const[bt,re]=F("tab"),ht=X({name:bt,props:{id:String,dot:Boolean,type:String,color:String,title:String,badge:z,shrink:Boolean,isActive:Boolean,disabled:Boolean,controls:String,scrollable:Boolean,activeColor:String,inactiveColor:String,showZeroBadge:U},setup(e,{slots:l}){const i=x(()=>{const s={},{type:n,color:o,disabled:f,isActive:d,activeColor:m,inactiveColor:T}=e;o&&n==="card"&&(s.borderColor=o,f||(d?s.backgroundColor=o:s.color=o));const $=d?m:T;return $&&(s.color=$),s}),c=()=>{const s=h("span",{class:re("text",{ellipsis:!e.scrollable})},[l.title?l.title():e.title]);return e.dot||q(e.badge)&&e.badge!==""?h(Ve,{dot:e.dot,content:e.badge,showZero:e.showZeroBadge},{default:()=>[s]}):s};return()=>h("div",{id:e.id,role:"tab",class:[re([e.type,{grow:e.scrollable&&!e.shrink,shrink:e.shrink,active:e.isActive,disabled:e.disabled}])],style:i.value,tabindex:e.disabled?void 0:e.isActive?0:-1,"aria-selected":e.isActive,"aria-disabled":e.disabled||void 0,"aria-controls":e.controls},[c()])}}),[gt,Q]=F("tab"),mt=Ze({},Ue,{dot:Boolean,name:z,badge:z,title:String,disabled:Boolean,titleClass:Fe,titleStyle:[String,Object],showZeroBadge:U});var yt=X({name:gt,props:mt,setup(e,{slots:l}){const i=ce(),c=C(!1),s=tt(),{parent:n,index:o}=Xe(fe);if(!n){console.error("[Vant] <Tab> must be a child component of <Tabs>.");return}const f=()=>{var b;return(b=e.name)!=null?b:o.value},d=()=>{c.value=!0,n.props.lazyRender&&P(()=>{n.onRendered(f(),e.title)})},m=x(()=>{const b=f()===n.currentName.value;return b&&!c.value&&d(),b}),T=C(""),_=C("");Ke(()=>{const{titleClass:b,titleStyle:S}=e;T.value=b?qe(b):"",_.value=S&&typeof S!="string"?Ge(Je(S)):S});const $=b=>h(ht,pe({key:i,id:`${n.id}-${o.value}`,ref:n.setTitleRefs(o.value),style:_.value,class:T.value,isActive:m.value,controls:i,scrollable:n.scrollable.value,activeColor:n.props.titleActiveColor,inactiveColor:n.props.titleInactiveColor,onClick:S=>b(s.proxy,o.value,S)},ie(n.props,["type","color","shrink"]),ie(e,["dot","badge","title","disabled","showZeroBadge"])),{title:l.title}),I=C(!m.value);return B(m,b=>{b?I.value=!1:Ye(()=>{I.value=!0})}),B(()=>e.title,()=>{n.setLine(),n.scrollIntoView()}),Qe(nt,m),G({id:i,renderTitle:$}),()=>{var b;const S=`${n.id}-${o.value}`,{animated:v,swipeable:K,scrollspy:u,lazyRender:N}=n.props;if(!l.default&&!v)return;const E=u||m.value;if(v||K)return h(lt,{id:i,role:"tabpanel",class:Q("panel-wrapper",{inactive:I.value}),tabindex:m.value?0:-1,"aria-hidden":!m.value,"aria-labelledby":S},{default:()=>{var A;return[h("div",{class:Q("panel")},[(A=l.default)==null?void 0:A.call(l)])]}});const W=c.value||u||!N?(b=l.default)==null?void 0:b.call(l):null;return je(h("div",{id:i,role:"tabpanel",class:Q("panel"),tabindex:E?0:-1,"aria-labelledby":S},[W]),[[et,E]])}}});const It=de(yt),Rt=de(vt);export{Rt as T,It as a,ct as u};