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