1 |
- import{aC as se,aD as Y,bH as Ce,bI as ke,r as C,aJ as Ie,c as F,d as K,bb as J,w as B,y as Re,a3 as G,a as h,n as z,m as xe,b as Z,t as U,bn as ce,bB as Be,ah as _e,x as $e,e as x,bE as Pe,bJ as Ae,z as A,aW as ze,bK as Ne,bL as Le,a4 as Oe,bD as Ee,o as ne,a2 as q,aP as He,a5 as ae,bm as We,bM as le,a7 as De,bN as Me,b8 as Ze,aj as Ve,b5 as Ue,ac as Fe,ak as Ke,aZ as je,bh as Je,bO as Xe,b0 as Ye,aR as qe,aH as Ge,g as Qe,v as pe,h as et,al as ie,aU as tt,k as de}from"./index-b80927fb.js";import{T as nt}from"./index-9f76e8fc.js";import{S as at,a as lt}from"./index-5e2dbcc6.js";import{u as it,S as ot}from"./index-6aeb1a0b.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=Y(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),ke(e,n),o&&n<l||!o&&n>l?s=Y(T):c&&(s=Y(c))}return T(),m}function ct(){const e=C([]),l=[];return Ie(()=>{e.value=[]}),[e,c=>(l[c]||(l[c]=s=>{e.value[c]=s}),l[c])]}const[dt,oe]=F("tabs");var ut=K({name:dt,props:{count:J(Number),inited:Boolean,animated:Boolean,duration:J(z),swipeable:Boolean,lazyRender:Boolean,currentIndex:J(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),Re(()=>{o(e.currentIndex)}),G({swipeRef:c}),()=>h("div",{class:oe("content",{animated:e.animated||e.swipeable})},[n()])}});const[ue,V]=F("tabs"),ft={type:xe("line"),color:String,border:Boolean,sticky:Boolean,shrink:Boolean,active:Z(0),duration:Z(.3),animated:Boolean,ellipsis:U,swipeable:Boolean,scrollspy:Boolean,offsetTop:Z(0),background:String,lazyRender:U,lineWidth:z,lineHeight:z,beforeChange:Function,swipeThreshold:Z(5),titleActiveColor:String,titleInactiveColor:String},fe=Symbol(ue);var vt=K({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(),k=Be(d),[b,S]=ct(),{children:v,linkChildren:j}=_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},H=x(()=>{const t=v[u.currentIndex];if(t)return L(t,u.currentIndex)}),P=x(()=>Pe(e.offsetTop)),Q=x(()=>e.sticky?P.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)},I=()=>{const t=u.inited;A(()=>{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,R={width:ne(y),backgroundColor:e.color,transform:`translateX(${w}px) translateX(-50%)`};if(t&&(R.transitionDuration=`${e.duration}s`),q(g)){const M=ne(g);R.height=M,R.borderRadius=M}u.lineStyle=R})},ve=t=>{const a=t<u.currentIndex?-1:1;for(;t>=0&&t<v.length;){if(!v[t].disabled)return t;t+=a}},W=(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(),I()),g!==e.active&&(l("update:active",g),w&&l("change",g,y.title)),n&&!e.scrollspy&&We(Math.ceil(le(d.value)-P.value))},D=(t,a)=>{const r=v.find((g,w)=>L(g,w)===t),y=r?v.indexOf(r):0;W(y,a)},p=(t=!1)=>{if(e.scrollspy){const a=v[u.currentIndex].$el;if(a&&k.value){const r=le(a,k.value)-Q.value;s=!0,f&&f(),f=st(k.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||(De(e.beforeChange,{args:[w],done:()=>{W(a),p()}}),Me(t)),l("clickTab",{name:w,title:y,event:r,disabled:g})},he=t=>{n=t.isFixed,l("scroll",t)},ge=t=>{A(()=>{D(t),p(!0)})},me=()=>{for(let t=0;t<v.length;t++){const{top:a}=ae(v[t].$el);if(a>Q.value)return t===0?0:t-1}return v.length-1},ye=()=>{if(e.scrollspy&&!s){const t=me();W(t)}},Te=()=>{if(e.type==="line"&&v.length)return h("div",{class:V("line"),style:u.lineStyle},null)},ee=()=>{var t,a,r;const{type:y,border:g,sticky:w}=e,R=[h("div",{ref:w?void 0:T,class:[V("wrap"),{[He]:y==="line"&&g}]},[h("div",{ref:m,role:"tablist",class:V("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(M=>M.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},[R]):R},te=()=>{I(),A(()=>{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],I),B(Ae,te),B(()=>e.active,t=>{t!==H.value&&D(t)}),B(()=>v.length,()=>{u.inited&&(D(e.active),I(),A(()=>{O(!0)}))});const Se=()=>{D(e.active,!0),A(()=>{u.inited=!0,T.value&&(c=ae(T.value).height),O(!0)})},we=(t,a)=>l("rendered",t,a);return G({resize:te,scrollTo:ge}),ze(I),Ne(I),Le(Se),it(d,I),Oe("scroll",ye,{target:k,passive:!0}),j({id:$,props:e,setLine:I,scrollable:N,onRendered:we,currentName:H,setTitleRefs:S,scrollIntoView:O}),()=>h("div",{ref:d,class:V([e.type])},[e.sticky?h(ot,{container:d.value,offsetTop:P.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:W},{default:()=>{var t;return[(t=i.default)==null?void 0:t.call(i)]}})])}});const[bt,re]=F("tab"),ht=K({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(Ze,{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,X]=F("tab"),mt=Ve({},Ue,{dot:Boolean,name:z,badge:z,title:String,disabled:Boolean,titleClass:Fe,titleStyle:[String,Object],showZeroBadge:U});var yt=K({name:gt,props:mt,setup(e,{slots:l}){const i=ce(),c=C(!1),s=tt(),{parent:n,index:o}=Ke(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&&A(()=>{n.onRendered(f(),e.title)})},m=x(()=>{const b=f()===n.currentName.value;return b&&!c.value&&d(),b}),T=C(""),_=C("");je(()=>{const{titleClass:b,titleStyle:S}=e;T.value=b?Je(b):"",_.value=S&&typeof S!="string"?Xe(Ye(S)):S});const $=b=>h(ht,et({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}),k=C(!m.value);return B(m,b=>{b?k.value=!1:qe(()=>{k.value=!0})}),B(()=>e.title,()=>{n.setLine(),n.scrollIntoView()}),Ge(nt,m),G({id:i,renderTitle:$}),()=>{var b;const S=`${n.id}-${o.value}`,{animated:v,swipeable:j,scrollspy:u,lazyRender:N}=n.props;if(!l.default&&!v)return;const E=u||m.value;if(v||j)return h(lt,{id:i,role:"tabpanel",class:X("panel-wrapper",{inactive:k.value}),tabindex:m.value?0:-1,"aria-hidden":!m.value,"aria-labelledby":S},{default:()=>{var P;return[h("div",{class:X("panel")},[(P=l.default)==null?void 0:P.call(l)])]}});const H=c.value||u||!N?(b=l.default)==null?void 0:b.call(l):null;return Qe(h("div",{id:i,role:"tabpanel",class:X("panel"),tabindex:E?0:-1,"aria-labelledby":S},[H]),[[pe,E]])}}});const kt=de(yt),It=de(vt);export{It as T,kt as a};
|