1 |
- import{at as F,ag as we,au as Te,A as V,d as W,E as B,G as D,V as C,j as h,L as U,av as Ce,aw as Z,S as _,a2 as I,U as Se,$ as ke,aa as E,a0 as xe,ab as Ie,ai as Be,Q as Re,ac as $e,ak as _e,W as $,aj as ae,an as Ae,ao as Pe,a9 as Ne,ae as ze,af as Le,a1 as Q,ax as Ee,ay as Oe,az as p,a7 as De,aA as Ve,X as ee,aB as We,aC as He,I as Me,J as Ze,H as je,as as Fe,aD as Ue,a5 as Xe,aE as Ke,N as le}from"./index.e6d6174e.js";import{u as ie}from"./use-id.f239f36f.js";import{T as Ye}from"./use-tab-status.e9ba8498.js";import{S as qe,a as Ge}from"./index.b4a53c6a.js";import{u as Je}from"./use-refs.eb803454.js";import{S as Qe}from"./index.9093bc60.js";function pe(e,l,i){let f=0;const a=e.scrollLeft,u=i===0?1:Math.round(i*1e3/16);function d(){e.scrollLeft+=(l-a)/u,++f<u&&F(d)}d()}function et(e,l,i,f){let a=we(e);const u=a<l,d=i===0?1:Math.round(i*1e3/16),v=(l-a)/d;function o(){a+=v,(u&&a>l||!u&&a<l)&&(a=l),Te(e,a),u&&a<l||!u&&a>l?F(o):f&&F(f)}o()}const[tt,te]=V("tab");var nt=W({name:tt,props:{id:String,dot:Boolean,type:String,color:String,title:String,badge:B,shrink:Boolean,isActive:Boolean,disabled:Boolean,controls:String,scrollable:Boolean,activeColor:String,inactiveColor:String,showZeroBadge:D},setup(e,{slots:l}){const i=C(()=>{const a={},{type:u,color:d,disabled:v,isActive:o,activeColor:g,inactiveColor:w}=e;d&&u==="card"&&(a.borderColor=d,v||(o?a.backgroundColor=d:a.color=d));const y=o?g:w;return y&&(a.color=y),a}),f=()=>{const a=h("span",{class:te("text",{ellipsis:!e.scrollable})},[l.title?l.title():e.title]);return e.dot||U(e.badge)&&e.badge!==""?h(Ce,{dot:e.dot,content:e.badge,showZero:e.showZeroBadge},{default:()=>[a]}):a};return()=>h("div",{id:e.id,role:"tab",class:[te([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},[f()])}});const[at,ne]=V("tabs");var lt=W({name:at,props:{count:Z(Number),inited:Boolean,animated:Boolean,duration:Z(B),swipeable:Boolean,lazyRender:Boolean,currentIndex:Z(Number)},emits:["change"],setup(e,{emit:l,slots:i}){const f=_(),a=v=>l("change",v),u=()=>{var v;const o=(v=i.default)==null?void 0:v.call(i);return e.animated||e.swipeable?h(qe,{ref:f,loop:!1,class:ne("track"),duration:+e.duration*1e3,touchable:e.swipeable,lazyRender:e.lazyRender,showIndicators:!1,onChange:a},{default:()=>[o]}):o},d=v=>{const o=f.value;o&&o.state.active!==v&&o.swipeTo(v,{immediate:!e.inited})};return I(()=>e.currentIndex,d),Se(()=>{d(e.currentIndex)}),()=>h("div",{class:ne("content",{animated:e.animated||e.swipeable})},[u()])}});const[oe,O]=V("tabs"),it={type:ke("line"),color:String,border:Boolean,sticky:Boolean,shrink:Boolean,active:E(0),duration:E(.3),animated:Boolean,ellipsis:D,swipeable:Boolean,scrollspy:Boolean,offsetTop:E(0),background:String,lazyRender:D,lineWidth:B,lineHeight:B,beforeChange:Function,swipeThreshold:E(5),titleActiveColor:String,titleInactiveColor:String},re=Symbol(oe);var ot=W({name:oe,props:it,emits:["click","change","scroll","disabled","rendered","click-tab","update:active"],setup(e,{emit:l,slots:i}){var f,a;{const t=(a=(f=xe())==null?void 0:f.vnode)==null?void 0:a.props;t&&"onClick"in t&&console.warn('[Vant] Tabs: "click" event is deprecated, using "click-tab" instead.'),t&&"onDisabled"in t&&console.warn('[Vant] Tabs: "disabled" event is deprecated, using "click-tab" instead.')}let u,d,v;const o=_(),g=_(),w=_(),S=ie(),y=Ie(o),[R,H]=Je(),{children:c,linkChildren:X}=Be(re),s=Re({inited:!1,position:"",lineStyle:{},currentIndex:-1}),k=C(()=>c.length>e.swipeThreshold||!e.ellipsis||e.shrink),se=C(()=>({borderColor:e.color,background:e.background})),A=(t,n)=>{var r;return(r=t.name)!=null?r:n},K=C(()=>{const t=c[s.currentIndex];if(t)return A(t,s.currentIndex)}),M=C(()=>$e(e.offsetTop)),Y=C(()=>e.sticky?M.value+u:0),P=t=>{const n=g.value,r=R.value;if(!k.value||!n||!r||!r[s.currentIndex])return;const b=r[s.currentIndex].$el,m=b.offsetLeft-(n.offsetWidth-b.offsetWidth)/2;pe(n,m,t?0:+e.duration)},T=()=>{const t=s.inited;$(()=>{const n=R.value;if(!n||!n[s.currentIndex]||e.type!=="line"||Le(o.value))return;const r=n[s.currentIndex].$el,{lineWidth:b,lineHeight:m}=e,x=r.offsetLeft+r.offsetWidth/2,L={width:Q(b),backgroundColor:e.color,transform:`translateX(${x}px) translateX(-50%)`};if(t&&(L.transitionDuration=`${e.duration}s`),U(m)){const J=Q(m);L.height=J,L.borderRadius=J}s.lineStyle=L})},ce=t=>{const n=t<s.currentIndex?-1:1;for(;t>=0&&t<c.length;){if(!c[t].disabled)return t;t+=n}},N=t=>{const n=ce(t);if(!U(n))return;const r=c[n],b=A(r,n),m=s.currentIndex!==null;s.currentIndex=n,b!==e.active&&(l("update:active",b),m&&l("change",b,r.title))},z=t=>{const n=c.find((b,m)=>A(b,m)===t),r=n?c.indexOf(n):0;N(r)},q=(t=!1)=>{if(e.scrollspy){const n=c[s.currentIndex].$el;if(n&&y.value){const r=p(n,y.value)-Y.value;d=!0,et(y.value,r,t?0:+e.duration,()=>{d=!1})}}},de=(t,n,r)=>{const{title:b,disabled:m}=c[n],x=A(c[n],n);m?l("disabled",x,b):(We(e.beforeChange,{args:[x],done:()=>{N(n),q()}}),l("click",x,b),He(t)),l("click-tab",{name:x,title:b,event:r,disabled:m})},ue=t=>{v=t.isFixed,l("scroll",t)},fe=t=>{$(()=>{z(t),q(!0)})},ve=()=>{for(let t=0;t<c.length;t++){const{top:n}=ee(c[t].$el);if(n>Y.value)return t===0?0:t-1}return c.length-1},be=()=>{if(e.scrollspy&&!d){const t=ve();N(t)}},he=()=>c.map((t,n)=>h(nt,De({id:`${S}-${n}`,ref:H(n),type:e.type,color:e.color,style:t.titleStyle,class:t.titleClass,shrink:e.shrink,isActive:n===s.currentIndex,controls:t.id,scrollable:k.value,activeColor:e.titleActiveColor,inactiveColor:e.titleInactiveColor,onClick:r=>de(t,n,r)},Ve(t,["dot","badge","title","disabled","showZeroBadge"])),{title:t.$slots.title})),ge=()=>{if(e.type==="line"&&c.length)return h("div",{class:O("line"),style:s.lineStyle},null)},G=()=>{var t,n;const{type:r,border:b}=e;return h("div",{ref:w,class:[O("wrap"),{[Ee]:r==="line"&&b}]},[h("div",{ref:g,role:"tablist",class:O("nav",[r,{shrink:e.shrink,complete:k.value}]),style:se.value,"aria-orientation":"horizontal"},[(t=i["nav-left"])==null?void 0:t.call(i),he(),ge(),(n=i["nav-right"])==null?void 0:n.call(i)])])};I([()=>e.color,_e],T),I(()=>e.active,t=>{t!==K.value&&z(t)}),I(()=>c.length,()=>{s.inited&&(z(e.active),T(),$(()=>{P(!0)}))}),I(()=>s.currentIndex,()=>{P(),T(),v&&!e.scrollspy&&Oe(Math.ceil(p(o.value)-M.value))});const me=()=>{z(e.active),$(()=>{s.inited=!0,w.value&&(u=ee(w.value).height),P(!0)})},ye=(t,n)=>l("rendered",t,n);return ae({resize:T,scrollTo:fe}),Ae(T),Pe(T),Ne(me),ze("scroll",be,{target:y}),X({id:S,props:e,setLine:T,onRendered:ye,currentName:K,scrollIntoView:P}),()=>{var t;return h("div",{ref:o,class:O([e.type])},[e.sticky?h(Qe,{container:o.value,offsetTop:M.value,onScroll:ue},{default:()=>{var n;return[G(),(n=i["nav-bottom"])==null?void 0:n.call(i)]}}):[G(),(t=i["nav-bottom"])==null?void 0:t.call(i)],h(lt,{count:c.length,inited:s.inited,animated:e.animated,duration:e.duration,swipeable:e.swipeable,lazyRender:e.lazyRender,currentIndex:s.currentIndex,onChange:N},{default:()=>{var n;return[(n=i.default)==null?void 0:n.call(i)]}})])}}});const[rt,j]=V("tab"),st=Me({},Ze,{dot:Boolean,name:B,badge:B,title:String,disabled:Boolean,titleClass:je,titleStyle:[String,Object],showZeroBadge:D});var ct=W({name:rt,props:st,setup(e,{slots:l}){const i=ie(),f=_(!1),{parent:a,index:u}=Fe(re);if(!a){console.error("[Vant] <Tab> must be a child component of <Tabs>.");return}const d=()=>{var g;return(g=e.name)!=null?g:u.value},v=()=>{f.value=!0,a.props.lazyRender&&$(()=>{a.onRendered(d(),e.title)})},o=C(()=>{const g=d()===a.currentName.value;return g&&!f.value&&v(),g});return I(()=>e.title,()=>{a.setLine(),a.scrollIntoView()}),Ue(Ye,o),()=>{var g;const w=`${a.id}-${u.value}`,{animated:S,swipeable:y,scrollspy:R,lazyRender:H}=a.props;if(!l.default&&!S)return;const c=R||o.value;if(S||y)return h(Ge,{id:i,role:"tabpanel",class:j("panel-wrapper",{inactive:!o.value}),tabindex:o.value?0:-1,"aria-hidden":!o.value,"aria-labelledby":w},{default:()=>{var k;return[h("div",{class:j("panel")},[(k=l.default)==null?void 0:k.call(l)])]}});const s=f.value||R||!H?(g=l.default)==null?void 0:g.call(l):null;return ae({id:i}),Xe(h("div",{id:i,role:"tabpanel",class:j("panel"),tabindex:c?0:-1,"aria-labelledby":w},[s]),[[Ke,c]])}}});const gt=le(ct),mt=le(ot);export{mt as T,gt as a};
|