index-d3d6ebd4.js 9.6 KB

1
  1. import{aL as X,bD as ie,bE as $e,r as I,aT as _e,aM as Pe,az as Ae,av as ze,aJ as le,c as E,n as A,m as se,b as N,d as L,by as re,x as ce,e as k,bB as de,ab as ue,i as Ne,w as P,Y as fe,a as m,bA as ve,Z as O,k as j,t as Z,W as Y,as as Oe,b4 as U,y as Ee,X as q,bp as be,a9 as Le,b6 as De,z,ay as He,aI as Me,o as te,a_ as We,bl as Ze,bF as ne,h as Fe,ad as Ve,$ as Ue,bG as Ke,ap as Xe,a3 as Ye,ac as je,aK as qe,aE as Ge,g as Je,v as Qe}from"./index-4498bb4b.js";import{T as pe}from"./use-tab-status-aa90eee5.js";import{S as et,a as tt}from"./index-1a1d3a14.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&&X(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?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 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]=E("sticky"),st={zIndex:A,position:se("top"),container:Object,offsetTop:N(0),offsetBottom:N(0)};var rt=L({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(Ne(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=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-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=O(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=j(rt),[dt,ae]=E("tab");var ut=L({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:Z},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||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: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]=E("tabs");var vt=L({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),Ee(()=>{r(e.currentIndex)}),q({swipeRef:l}),()=>m("div",{class:oe("content",{animated:e.animated||e.swipeable})},[a()])}});const[me,W]=E("tabs"),bt={type:se("line"),color:String,border:Boolean,sticky:Boolean,shrink:Boolean,active:N(0),duration:N(.3),animated:Boolean,ellipsis:Z,swipeable:Boolean,scrollspy:Boolean,offsetTop:N(0),background:String,lazyRender:Z,lineWidth:A,lineHeight:A,beforeChange:Function,swipeThreshold:N(5),titleActiveColor:String,titleInactiveColor:String},ge=Symbol(me);var ht=L({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}=Le(ge),c=ce({inited:!1,position:"",lineStyle:{},currentIndex:-1}),B=k(()=>v.length>+e.swipeThreshold||!e.ellipsis||e.shrink),F=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)}),V=k(()=>de(e.offsetTop)),J=k(()=>e.sticky?V.value+l:0),D=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`),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}},H=(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||D(),R()),g!==e.active&&(i("update:active",g),S&&i("change",g,y.title)),a&&!e.scrollspy&&Ze(Math.ceil(ne(r.value)-V.value))},M=(t,o)=>{const d=v.find((g,S)=>$(g,S)===t),y=d?v.indexOf(d):0;H(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:()=>{H(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(()=>{M(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();H(t)}},ke=()=>v.map((t,o)=>m(ut,Fe({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)},Ve(t,["dot","badge","title","disabled","showZeroBadge"])),{title:t.$slots.title})),Ie=()=>{if(e.type==="line"&&v.length)return m("div",{class:W("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:[W("wrap"),{[We]:y==="line"&&g}]},[m("div",{ref:b,role:"tablist",class:W("nav",[y,{shrink:e.shrink,complete:B.value}]),style:F.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,De],R),P(()=>e.active,t=>{t!==G.value&&M(t)}),P(()=>v.length,()=>{c.inited&&(M(e.active),R(),z(()=>{D(!0)}))});const Re=()=>{M(e.active,!0),z(()=>{c.inited=!0,u.value&&(l=O(u.value).height),D(!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}),He(R),Me(R),le(Re),he(r,R),fe("scroll",Ce,{target:f,passive:!0}),T({id:h,props:e,setLine:R,onRendered:Be,currentName:G,scrollIntoView:D}),()=>m("div",{ref:r,class:W([e.type])},[e.sticky?m(ct,{container:r.value,offsetTop:V.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:H},{default:()=>{var t;return[(t=s.default)==null?void 0:t.call(s)]}})])}});const[mt,K]=E("tab"),gt=ue({},Xe,{dot:Boolean,name:A,badge:A,title:String,disabled:Boolean,titleClass:Ye,titleStyle:[String,Object],showZeroBadge:Z});var yt=L({name:mt,props:gt,setup(e,{slots:i}){const s=be(),l=I(!1),{parent:n,index:a}=je(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:qe(()=>{C.value=!0})}),P(()=>e.title,()=>{n.setLine(),n.scrollIntoView()}),Ge(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: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 F=l.value||v||!T?(h=i.default)==null?void 0:h.call(i):null;return q({id:s}),Je(m("div",{id:s,role:"tabpanel",class:K("panel"),tabindex:c?0:-1,"aria-labelledby":f},[F]),[[Qe,c]])}}});const Ct=j(yt),kt=j(ht);export{kt as T,Ct as a};