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