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