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