index-be2ca64a.js 8.4 KB

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