| 1 |
- import{ay as de,az as q,bk as ue,bh as Ne,bs as Oe,aV as Ee,aE as Le,bj as fe,c as M,n as A,m as ve,b as O,d as W,r as k,bB as be,x as he,e as I,bE as me,ai as ge,i as He,w as $,a3 as ye,bD as G,z,a4 as E,bI as we,bJ as De,a as m,k as p,b8 as J,y as Me,a2 as ee,t as X,bn as xe,ag as We,aU as Ve,bK as Ze,o as ie,a1 as Q,aN as je,bm as Fe,bL as oe,a6 as Ue,bM as Ke,b5 as Xe,b2 as Je,ab as Ye,aj as qe,aX as Ge,bc as Qe,bN as pe,aJ as et,aP as tt,aD as nt,g as at,v as lt,h as it,ak as se,aS as ot}from"./index-1a6ecb3d.js";import{T as st}from"./use-tab-status-43751de8.js";import{S as rt,a as ct}from"./index-b131e6ae.js";import{u as dt}from"./use-refs-5ee62f63.js";function ut(e,l,i){let s,d=0;const t=e.scrollLeft,o=i===0?1:Math.round(i*1e3/16);function r(){de(s)}function v(){e.scrollLeft+=(l-t)/o,++d<o&&(s=q(v))}return v(),r}function ft(e,l,i,s){let d,t=ue(e);const o=t<l,r=i===0?1:Math.round(i*1e3/16),v=(l-t)/r;function g(){de(d)}function w(){t+=v,(o&&t>l||!o&&t<l)&&(t=l),Ne(e,t),o&&t<l||!o&&t>l?d=q(w):s&&(d=q(s))}return w(),g}function Te(e,l){if(!Oe||!window.IntersectionObserver)return;const i=new IntersectionObserver(t=>{l(t[0].intersectionRatio>0)},{root:document.body}),s=()=>{e.value&&i.observe(e.value)},d=()=>{e.value&&i.unobserve(e.value)};Ee(d),Le(d),fe(s)}const[vt,bt]=M("sticky"),ht={zIndex:A,position:ve("top"),container:Object,offsetTop:O(0),offsetBottom:O(0)};var mt=W({name:vt,props:ht,emits:["scroll","change"],setup(e,{emit:l,slots:i}){const s=k(),d=be(s),t=he({fixed:!1,width:0,height:0,transform:0}),o=k(!1),r=I(()=>me(e.position==="top"?e.offsetTop:e.offsetBottom)),v=I(()=>{if(o.value)return;const{fixed:f,height:S,width:u}=t;if(f)return{width:`${u}px`,height:`${S}px`}}),g=I(()=>{if(!t.fixed||o.value)return;const f=ge(He(e.zIndex),{width:`${t.width}px`,height:`${t.height}px`,[e.position]:`${r.value}px`});return t.transform&&(f.transform=`translate3d(0, ${t.transform}px, 0)`),f}),w=f=>l("scroll",{scrollTop:f,isFixed:t.fixed}),R=()=>{if(!s.value||G(s))return;const{container:f,position:S}=e,u=E(s),T=ue(window);if(t.width=u.width,t.height=u.height,S==="top")if(f){const c=E(f),B=c.bottom-r.value-t.height;t.fixed=r.value>u.top&&c.bottom>0,t.transform=B<0?B:0}else t.fixed=r.value>u.top;else{const{clientHeight:c}=document.documentElement;if(f){const B=E(f),h=c-B.top-r.value-t.height;t.fixed=c-r.value<u.bottom&&c>B.top,t.transform=h<0?-h:0}else t.fixed=c-r.value<u.bottom}w(T)};return $(()=>t.fixed,f=>l("change",f)),ye("scroll",R,{target:d,passive:!0}),Te(s,R),$([we,De],()=>{!s.value||G(s)||!t.fixed||(o.value=!0,z(()=>{const f=E(s);t.width=f.width,t.height=f.height,o.value=!1}))}),()=>{var f;return m("div",{ref:s,style:v.value},[m("div",{class:bt({fixed:t.fixed&&!o.value}),style:g.value},[(f=i.default)==null?void 0:f.call(i)])])}}});const gt=p(mt),[yt,re]=M("tabs");var wt=W({name:yt,props:{count:J(Number),inited:Boolean,animated:Boolean,duration:J(A),swipeable:Boolean,lazyRender:Boolean,currentIndex:J(Number)},emits:["change"],setup(e,{emit:l,slots:i}){const s=k(),d=r=>l("change",r),t=()=>{var r;const v=(r=i.default)==null?void 0:r.call(i);return e.animated||e.swipeable?m(rt,{ref:s,loop:!1,class:re("track"),duration:+e.duration*1e3,touchable:e.swipeable,lazyRender:e.lazyRender,showIndicators:!1,onChange:d},{default:()=>[v]}):v},o=r=>{const v=s.value;v&&v.state.active!==r&&v.swipeTo(r,{immediate:!e.inited})};return $(()=>e.currentIndex,o),Me(()=>{o(e.currentIndex)}),ee({swipeRef:s}),()=>m("div",{class:re("content",{animated:e.animated||e.swipeable})},[t()])}});const[Se,K]=M("tabs"),xt={type:ve("line"),color:String,border:Boolean,sticky:Boolean,shrink:Boolean,active:O(0),duration:O(.3),animated:Boolean,ellipsis:X,swipeable:Boolean,scrollspy:Boolean,offsetTop:O(0),background:String,lazyRender:X,lineWidth:A,lineHeight:A,beforeChange:Function,swipeThreshold:O(5),titleActiveColor:String,titleInactiveColor:String},Ce=Symbol(Se);var Tt=W({name:Se,props:xt,emits:["change","scroll","rendered","clickTab","update:active"],setup(e,{emit:l,slots:i}){let s,d,t,o,r;const v=k(),g=k(),w=k(),R=k(),f=xe(),S=be(v),[u,T]=dt(),{children:c,linkChildren:B}=We(Ce),h=he({inited:!1,position:"",lineStyle:{},currentIndex:-1}),L=I(()=>c.length>+e.swipeThreshold||!e.ellipsis||e.shrink),V=I(()=>({borderColor:e.color,background:e.background})),H=(n,a)=>{var b;return(b=n.name)!=null?b:a},Z=I(()=>{const n=c[h.currentIndex];if(n)return H(n,h.currentIndex)}),N=I(()=>me(e.offsetTop)),te=I(()=>e.sticky?N.value+s:0),D=n=>{const a=g.value,b=u.value;if(!L.value||!a||!b||!b[h.currentIndex])return;const x=b[h.currentIndex].$el,y=x.offsetLeft-(a.offsetWidth-x.offsetWidth)/2;o&&o(),o=ut(a,y,n?0:+e.duration)},_=()=>{const n=h.inited;z(()=>{const a=u.value;if(!a||!a[h.currentIndex]||e.type!=="line"||G(v.value))return;const b=a[h.currentIndex].$el,{lineWidth:x,lineHeight:y}=e,C=b.offsetLeft+b.offsetWidth/2,P={width:ie(x),backgroundColor:e.color,transform:`translateX(${C}px) translateX(-50%)`};if(n&&(P.transitionDuration=`${e.duration}s`),Q(y)){const U=ie(y);P.height=U,P.borderRadius=U}h.lineStyle=P})},ke=n=>{const a=n<h.currentIndex?-1:1;for(;n>=0&&n<c.length;){if(!c[n].disabled)return n;n+=a}},j=(n,a)=>{const b=ke(n);if(!Q(b))return;const x=c[b],y=H(x,b),C=h.currentIndex!==null;h.currentIndex!==b&&(h.currentIndex=b,a||D(),_()),y!==e.active&&(l("update:active",y),C&&l("change",y,x.title)),t&&!e.scrollspy&&Fe(Math.ceil(oe(v.value)-N.value))},F=(n,a)=>{const b=c.find((y,C)=>H(y,C)===n),x=b?c.indexOf(b):0;j(x,a)},ne=(n=!1)=>{if(e.scrollspy){const a=c[h.currentIndex].$el;if(a&&S.value){const b=oe(a,S.value)-te.value;d=!0,r&&r(),r=ft(S.value,b,n?0:+e.duration,()=>{d=!1})}}},Ie=(n,a,b)=>{const{title:x,disabled:y}=c[a],C=H(c[a],a);y||(Ue(e.beforeChange,{args:[C],done:()=>{j(a),ne()}}),Ke(n)),l("clickTab",{name:C,title:x,event:b,disabled:y})},Re=n=>{t=n.isFixed,l("scroll",n)},Be=n=>{z(()=>{F(n),ne(!0)})},$e=()=>{for(let n=0;n<c.length;n++){const{top:a}=E(c[n].$el);if(a>te.value)return n===0?0:n-1}return c.length-1},_e=()=>{if(e.scrollspy&&!d){const n=$e();j(n)}},Pe=()=>{if(e.type==="line"&&c.length)return m("div",{class:K("line"),style:h.lineStyle},null)},ae=()=>{var n,a,b;const{type:x,border:y,sticky:C}=e,P=[m("div",{ref:C?void 0:w,class:[K("wrap"),{[je]:x==="line"&&y}]},[m("div",{ref:g,role:"tablist",class:K("nav",[x,{shrink:e.shrink,complete:L.value}]),style:V.value,"aria-orientation":"horizontal"},[(n=i["nav-left"])==null?void 0:n.call(i),c.map(U=>U.renderTitle(Ie)),Pe(),(a=i["nav-right"])==null?void 0:a.call(i)])]),(b=i["nav-bottom"])==null?void 0:b.call(i)];return C?m("div",{ref:w},[P]):P},le=()=>{_(),z(()=>{var n,a;D(!0),(a=(n=R.value)==null?void 0:n.swipeRef.value)==null||a.resize()})};$(()=>[e.color,e.duration,e.lineWidth,e.lineHeight],_),$(we,le),$(()=>e.active,n=>{n!==Z.value&&F(n)}),$(()=>c.length,()=>{h.inited&&(F(e.active),_(),z(()=>{D(!0)}))});const ze=()=>{F(e.active,!0),z(()=>{h.inited=!0,w.value&&(s=E(w.value).height),D(!0)})},Ae=(n,a)=>l("rendered",n,a);return ee({resize:le,scrollTo:Be}),Ve(_),Ze(_),fe(ze),Te(v,_),ye("scroll",_e,{target:S,passive:!0}),B({id:f,props:e,setLine:_,scrollable:L,onRendered:Ae,currentName:Z,setTitleRefs:T,scrollIntoView:D}),()=>m("div",{ref:v,class:K([e.type])},[e.sticky?m(gt,{container:v.value,offsetTop:N.value,onScroll:Re},{default:()=>[ae()]}):ae(),m(wt,{ref:R,count:c.length,inited:h.inited,animated:e.animated,duration:e.duration,swipeable:e.swipeable,lazyRender:e.lazyRender,currentIndex:h.currentIndex,onChange:j},{default:()=>{var n;return[(n=i.default)==null?void 0:n.call(i)]}})])}});const[St,ce]=M("tab"),Ct=W({name:St,props:{id:String,dot:Boolean,type:String,color:String,title:String,badge:A,shrink:Boolean,isActive:Boolean,disabled:Boolean,controls:String,scrollable:Boolean,activeColor:String,inactiveColor:String,showZeroBadge:X},setup(e,{slots:l}){const i=I(()=>{const d={},{type:t,color:o,disabled:r,isActive:v,activeColor:g,inactiveColor:w}=e;o&&t==="card"&&(d.borderColor=o,r||(v?d.backgroundColor=o:d.color=o));const f=v?g:w;return f&&(d.color=f),d}),s=()=>{const d=m("span",{class:ce("text",{ellipsis:!e.scrollable})},[l.title?l.title():e.title]);return e.dot||Q(e.badge)&&e.badge!==""?m(Xe,{dot:e.dot,content:e.badge,showZero:e.showZeroBadge},{default:()=>[d]}):d};return()=>m("div",{id:e.id,role:"tab",class:[ce([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},[s()])}}),[kt,Y]=M("tab"),It=ge({},Je,{dot:Boolean,name:A,badge:A,title:String,disabled:Boolean,titleClass:Ye,titleStyle:[String,Object],showZeroBadge:X});var Rt=W({name:kt,props:It,setup(e,{slots:l}){const i=xe(),s=k(!1),d=ot(),{parent:t,index:o}=qe(Ce);if(!t){console.error("[Vant] <Tab> must be a child component of <Tabs>.");return}const r=()=>{var u;return(u=e.name)!=null?u:o.value},v=()=>{s.value=!0,t.props.lazyRender&&z(()=>{t.onRendered(r(),e.title)})},g=I(()=>{const u=r()===t.currentName.value;return u&&!s.value&&v(),u}),w=k(""),R=k("");Ge(()=>{const{titleClass:u,titleStyle:T}=e;w.value=u?Qe(u):"",R.value=T&&typeof T!="string"?pe(et(T)):T});const f=u=>m(Ct,it({key:i,id:`${t.id}-${o.value}`,ref:t.setTitleRefs(o.value),style:R.value,class:w.value,isActive:g.value,controls:i,scrollable:t.scrollable.value,activeColor:t.props.titleActiveColor,inactiveColor:t.props.titleInactiveColor,onClick:T=>u(d.proxy,o.value,T)},se(t.props,["type","color","shrink"]),se(e,["dot","badge","title","disabled","showZeroBadge"])),{title:l.title}),S=k(!g.value);return $(g,u=>{u?S.value=!1:tt(()=>{S.value=!0})}),$(()=>e.title,()=>{t.setLine(),t.scrollIntoView()}),nt(st,g),ee({id:i,renderTitle:f}),()=>{var u;const T=`${t.id}-${o.value}`,{animated:c,swipeable:B,scrollspy:h,lazyRender:L}=t.props;if(!l.default&&!c)return;const V=h||g.value;if(c||B)return m(ct,{id:i,role:"tabpanel",class:Y("panel-wrapper",{inactive:S.value}),tabindex:g.value?0:-1,"aria-hidden":!g.value,"aria-labelledby":T},{default:()=>{var N;return[m("div",{class:Y("panel")},[(N=l.default)==null?void 0:N.call(l)])]}});const Z=s.value||h||!L?(u=l.default)==null?void 0:u.call(l):null;return at(m("div",{id:i,role:"tabpanel",class:Y("panel"),tabindex:V?0:-1,"aria-labelledby":T},[Z]),[[lt,V]])}}});const zt=p(Rt),At=p(Tt);export{At as T,zt as a};
|