index.7c580591.js 8.0 KB

1
  1. import{aI as K,ar as ye,aF as we,R as C,aK as Te,t as H,d as M,z as $,v as E,y as B,c as b,a1 as X,aL as Se,aB as U,Z as _,$ as Ce,W as Q,u as ke,w as O,Q as le,ap as Ie,x as Re,r as Be,aM as xe,aN as _e,_ as x,aO as $e,aP as Ae,aH as Pe,a0 as Ne,aA as ze,U as p,G as Oe,I as Le,aQ as ee,an as te,E as Ee,am as He,aR as Me,aS as We,N as De,ae as Ze,O as Fe,C as Ue,aT as Ve,X as Ke,ac as Xe,ay as Qe,D as ie}from"./index.332c7f08.js";import{T as Ye}from"./use-tab-status.9d769af8.js";import{S as je,a as qe}from"./index.1e2dfe6e.js";import{S as Ge}from"./index.4aa8e076.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&&K(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?K(r):s&&K(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=M({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=B(()=>{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||X(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=M({name:at,props:{count:U(Number),inited:Boolean,animated:Boolean,duration:U($),swipeable:Boolean,lazyRender:Boolean,currentIndex:U(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(je,{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)}),Q({swipeRef:s}),()=>b("div",{class:ae("content",{animated:e.animated||e.swipeable})},[f()])}});const[oe,L]=H("tabs"),it={type:ke("line"),color:String,border:Boolean,sticky:Boolean,shrink:Boolean,active:O(0),duration:O(.3),animated:Boolean,ellipsis:E,swipeable:Boolean,scrollspy:Boolean,offsetTop:O(0),background:String,lazyRender:E,lineWidth:$,lineHeight:$,beforeChange:Function,swipeThreshold:O(5),titleActiveColor:String,titleInactiveColor:String},re=Symbol(oe);var ot=M({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:D}=Re(re),c=Be({inited:!1,position:"",lineStyle:{},currentIndex:-1}),A=B(()=>u.length>e.swipeThreshold||!e.ellipsis||e.shrink),Z=B(()=>({borderColor:e.color,background:e.background})),k=(t,n)=>{var i;return(i=t.name)!=null?i:n},Y=B(()=>{const t=u[c.currentIndex];if(t)return k(t,c.currentIndex)}),F=B(()=>xe(e.offsetTop)),j=B(()=>e.sticky?F.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;x(()=>{const n=S.value;if(!n||!n[c.currentIndex]||e.type!=="line"||ze(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`),X(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}},N=(t,n)=>{const i=se(t);if(!X(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&&Le(Math.ceil(ee(d.value)-F.value))},z=(t,n)=>{const i=u.find((g,y)=>k(g,y)===t),m=i?u.indexOf(i):0;N(m,n)},q=(t=!1)=>{if(e.scrollspy){const n=u[c.currentIndex].$el;if(n&&T.value){const i=ee(n,T.value)-j.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||(Me(e.beforeChange,{args:[y],done:()=>{N(n),q()}}),We(t)),l("clickTab",{name:y,title:m,event:i,disabled:g})},de=t=>{f=t.isFixed,l("scroll",t)},ue=t=>{x(()=>{z(t),q(!0)})},fe=()=>{for(let t=0;t<u.length;t++){const{top:n}=te(u[t].$el);if(n>j.value)return t===0?0:t-1}return u.length-1},ve=()=>{if(e.scrollspy&&!a){const t=fe();N(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:L("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:[L("wrap"),{[Oe]:m==="line"&&g}]},[b("div",{ref:v,role:"tablist",class:L("nav",[m,{shrink:e.shrink,complete:A.value}]),style:Z.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!==Y.value&&z(t)}),_(()=>u.length,()=>{c.inited&&(z(e.active),I(),x(()=>{P(!0)}))});const ge=()=>{z(e.active,!0),x(()=>{c.inited=!0,r.value&&(s=te(r.value).height),P(!0)})},me=(t,n)=>l("rendered",t,n);return Q({resize:()=>{I(),x(()=>{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),Ne("scroll",ve,{target:T,passive:!0}),D({id:h,props:e,setLine:I,onRendered:me,currentName:Y,scrollIntoView:P}),()=>b("div",{ref:d,class:L([e.type])},[e.sticky?b(Ge,{container:d.value,offsetTop:F.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:N},{default:()=>{var t;return[(t=o.default)==null?void 0:t.call(o)]}})])}});const[rt,V]=H("tab"),st=De({},Ze,{dot:Boolean,name:$,badge:$,title:String,disabled:Boolean,titleClass:Fe,titleStyle:[String,Object],showZeroBadge:E});var ct=M({name:rt,props:st,setup(e,{slots:l}){const o=le(),s=C(!1),{parent:a,index:f}=Ue(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&&x(()=>{a.onRendered(d(),e.title)})},r=B(()=>{const h=d()===a.currentName.value;return h&&!s.value&&v(),h}),w=C(!r.value);return _(r,h=>{h?w.value=!1:Ve(()=>{w.value=!0})}),_(()=>e.title,()=>{a.setLine(),a.scrollIntoView()}),Ke(Ye,r),()=>{var h;const T=`${a.id}-${f.value}`,{animated:S,swipeable:W,scrollspy:u,lazyRender:D}=a.props;if(!l.default&&!S)return;const c=u||r.value;if(S||W)return b(qe,{id:o,role:"tabpanel",class:V("panel-wrapper",{inactive:w.value}),tabindex:r.value?0:-1,"aria-hidden":!r.value,"aria-labelledby":T},{default:()=>{var k;return[b("div",{class:V("panel")},[(k=l.default)==null?void 0:k.call(l)])]}});const Z=s.value||u||!D?(h=l.default)==null?void 0:h.call(l):null;return Q({id:o}),Xe(b("div",{id:o,role:"tabpanel",class:V("panel"),tabindex:c?0:-1,"aria-labelledby":T},[Z]),[[Qe,c]])}}});const ht=ie(ct),gt=ie(ot);export{gt as T,ht as a,et as u};