| 1 |
- import{av as K,ai as we,aw as Te,G as V,d as W,H as B,I as D,X as C,j as h,N as U,ax as Ce,ay as Z,V as $,a4 as I,W as Se,a1 as ke,ac as O,a2 as xe,ad as Ie,ak as Be,U as Re,ae as _e,am as $e,Y as _,al as ae,ap as Ae,aq as Pe,ab as Ne,ag as ze,ah as Le,a3 as Q,az as Oe,aA as Ee,aB as p,a9 as De,aC as Ve,Z as ee,aD as We,aE as He,K as Me,L as Ze,J as Fe,au as Ke,aF as Ue,a7 as Xe,aG as Ye,P as le}from"./index.c8a33855.js";import{u as ie}from"./use-id.c5c54d4f.js";import{T as je}from"./use-tab-status.9eeb64d0.js";import{S as qe,a as Ge}from"./index.3dff5bed.js";import{u as Je}from"./use-refs.ef9788ce.js";import{S as Qe}from"./index.e91b3eaf.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&&K(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?K(o):f&&K(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,E]=V("tabs"),it={type:ke("line"),color:String,border:Boolean,sticky:Boolean,shrink:Boolean,active:O(0),duration:O(.3),animated:Boolean,ellipsis:D,swipeable:Boolean,scrollspy:Boolean,offsetTop:O(0),background:String,lazyRender:D,lineWidth:B,lineHeight:B,beforeChange:Function,swipeThreshold:O(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},Y=C(()=>{const t=c[s.currentIndex];if(t)return A(t,s.currentIndex)}),M=C(()=>_e(e.offsetTop)),j=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)-j.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>j.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:E("line"),style:s.lineStyle},null)},G=()=>{var t,n;const{type:r,border:b}=e;return h("div",{ref:w,class:[E("wrap"),{[Oe]:r==="line"&&b}]},[h("div",{ref:g,role:"tablist",class:E("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!==Y.value&&z(t)}),I(()=>c.length,()=>{s.inited&&(z(e.active),T(),_(()=>{P(!0)}))}),I(()=>s.currentIndex,()=>{P(),T(),v&&!e.scrollspy&&Ee(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:Y,scrollIntoView:P}),()=>{var t;return h("div",{ref:o,class:E([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,F]=V("tab"),st=Me({},Ze,{dot:Boolean,name:B,badge:B,title:String,disabled:Boolean,titleClass:Fe,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}=Ke(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(je,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:F("panel-wrapper",{inactive:!o.value}),tabindex:o.value?0:-1,"aria-hidden":!o.value,"aria-labelledby":w},{default:()=>{var k;return[h("div",{class:F("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:F("panel"),tabindex:c?0:-1,"aria-labelledby":w},[s]),[[Ye,c]])}}});const gt=le(ct),mt=le(ot);export{mt as T,gt as a};
|