mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
2 lines
8.6 KiB
JavaScript
2 lines
8.6 KiB
JavaScript
import{K,L as Te,I as we,c as V,i as q,M as Ce,b as ke,G as Ie,N as xe,o as Be,n as Re,O as $e,h as ee,p as Ae,z as Pe,P as te,r as ne,e as Oe,u as Ne,Q as ze}from"./use-translate.d2900b8c.js";import{n as A,t as M,d as Z,m as je,c as E,u as Le,w as oe}from"./with-install.19a35764.js";import{z as D,D as x,e as m,Q,C as B,u as $,N as _e,H as Ee,q as R,L as He,A as Me,E as Ve,I as De,j as We,v as Ze}from"./vue-libs.b44bc779.js";import{u as le}from"./use-id.46df47b7.js";import{u as U}from"./use-expose.c942d5f8.js";import{a as Fe,r as Ke}from"./use-route.82f2be69.js";import{S as qe,a as Qe}from"./index.1461a543.js";import{b as Ue}from"./constant.80c6de18.js";import{c as Xe}from"./interceptor.f0c85874.js";import{u as Ye}from"./use-refs.b3168e03.js";import{o as Ge}from"./on-popup-reopen.138c77eb.js";import{S as Je}from"./index.99afab90.js";import{B as pe}from"./index.b70c9b40.js";function et(e,i,o){let f=0;const a=e.scrollLeft,b=o===0?1:Math.round(o*1e3/16);function c(){e.scrollLeft+=(i-a)/b,++f<b&&K(c)}c()}function tt(e,i,o,f){let a=Te(e);const b=a<i,c=o===0?1:Math.round(o*1e3/16),u=(i-a)/c;function r(){a+=u,(b&&a>i||!b&&a<i)&&(a=i),we(e,a),b&&a<i||!b&&a>i?K(r):f&&K(f)}r()}function nt(e){return typeof e=="function"||Object.prototype.toString.call(e)==="[object Object]"&&!Q(e)}const[at,ae]=V("tab"),it=D({name:at,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 o=x(()=>{const a={},{type:b,color:c,disabled:u,isActive:r,activeColor:S,inactiveColor:g}=e;c&&b==="card"&&(a.borderColor=c,u||(r?a.backgroundColor=c:a.color=c));const w=r?S:g;return w&&(a.color=w),a}),f=()=>{const a=m("span",{class:ae("text",{ellipsis:!e.scrollable})},[i.title?i.title():e.title]);return e.dot||q(e.badge)&&e.badge!==""?m(pe,{dot:e.dot,content:e.badge,showZero:e.showZeroBadge},nt(a)?a:{default:()=>[a]}):a};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:o.value,tabindex:e.disabled?void 0:e.isActive?0:-1,"aria-selected":e.isActive,"aria-disabled":e.disabled||void 0,"aria-controls":e.controls},[f()])}});function ot(e){return typeof e=="function"||Object.prototype.toString.call(e)==="[object Object]"&&!Q(e)}const[lt,ie]=V("tabs"),rt=D({name:lt,props:{count:Z(Number),inited:Boolean,animated:Boolean,duration:Z(A),swipeable:Boolean,lazyRender:Boolean,currentIndex:Z(Number)},emits:["change"],setup(e,{emit:i,slots:o}){const f=B(),a=u=>i("change",u),b=()=>{var r;const u=(r=o.default)==null?void 0:r.call(o);return e.animated||e.swipeable?m(qe,{ref:f,loop:!1,class:ie("track"),duration:+e.duration*1e3,touchable:e.swipeable,lazyRender:e.lazyRender,showIndicators:!1,onChange:a},ot(u)?u:{default:()=>[u]}):u},c=u=>{const r=f.value;r&&r.state.active!==u&&r.swipeTo(u,{immediate:!e.inited})};return $(()=>e.currentIndex,c),_e(()=>{c(e.currentIndex)}),U({swipeRef:f}),()=>m("div",{class:ie("content",{animated:e.animated||e.swipeable})},[b()])}});function ct(e){return typeof e=="function"||Object.prototype.toString.call(e)==="[object Object]"&&!Q(e)}const[re,H]=V("tabs"),st={type:je("line"),color:String,border:Boolean,sticky:Boolean,shrink:Boolean,active:E(0),duration:E(.3),animated:Boolean,ellipsis:M,swipeable:Boolean,scrollspy:Boolean,offsetTop:E(0),background:String,lazyRender:M,lineWidth:A,lineHeight:A,beforeChange:Function,swipeThreshold:E(5),titleActiveColor:String,titleInactiveColor:String},ce=Symbol(re),dt=D({name:re,props:st,emits:["click","change","scroll","disabled","rendered","click-tab","update:active"],setup(e,{emit:i,slots:o}){let f,a,b;const c=B(),u=B(),r=B(),S=B(),g=le(),T=Ce(c),[w,O]=Ye(),{children:d,linkChildren:N}=ke(ce),s=Ee({inited:!1,position:"",lineStyle:{},currentIndex:-1}),P=x(()=>d.length>e.swipeThreshold||!e.ellipsis||e.shrink),z=x(()=>({borderColor:e.color,background:e.background})),C=(t,n)=>{var l;return(l=t.name)!=null?l:n},X=x(()=>{const t=d[s.currentIndex];if(t)return C(t,s.currentIndex)}),W=x(()=>Ie(e.offsetTop)),Y=x(()=>e.sticky?W.value+f:0),j=t=>{const n=u.value,l=w.value;if(!P.value||!n||!l||!l[s.currentIndex])return;const v=l[s.currentIndex].$el,h=v.offsetLeft-(n.offsetWidth-v.offsetWidth)/2;et(n,h,t?0:+e.duration)},k=()=>{const t=s.inited;R(()=>{const n=w.value;if(!n||!n[s.currentIndex]||e.type!=="line"||$e(c.value))return;const l=n[s.currentIndex].$el,{lineWidth:v,lineHeight:h}=e,y=l.offsetLeft+l.offsetWidth/2,I={width:ee(v),backgroundColor:e.color,transform:`translateX(${y}px) translateX(-50%)`};if(t&&(I.transitionDuration=`${e.duration}s`),q(h)){const p=ee(h);I.height=p,I.borderRadius=p}s.lineStyle=I})},de=t=>{const n=t<s.currentIndex?-1:1;for(;t>=0&&t<d.length;){if(!d[t].disabled)return t;t+=n}},L=(t,n)=>{const l=de(t);if(!q(l))return;const v=d[l],h=C(v,l),y=s.currentIndex!==null;s.currentIndex!==l&&(s.currentIndex=l,n||j(),k()),h!==e.active&&(i("update:active",h),y&&i("change",h,v.title)),b&&!e.scrollspy&&Pe(Math.ceil(te(c.value)-W.value))},_=(t,n)=>{const l=d.find((h,y)=>C(h,y)===t),v=l?d.indexOf(l):0;L(v,n)},G=(t=!1)=>{if(e.scrollspy){const n=d[s.currentIndex].$el;if(n&&T.value){const l=te(n,T.value)-Y.value;a=!0,tt(T.value,l,t?0:+e.duration,()=>{a=!1})}}},ue=(t,n,l)=>{const{title:v,disabled:h}=d[n],y=C(d[n],n);h?i("disabled",y,v):(Xe(e.beforeChange,{args:[y],done:()=>{L(n),G()}}),i("click",y,v),Fe(t)),i("click-tab",{name:y,title:v,event:l,disabled:h})},fe=t=>{b=t.isFixed,i("scroll",t)},be=t=>{R(()=>{_(t),G(!0)})},ve=()=>{for(let t=0;t<d.length;t++){const{top:n}=ne(d[t].$el);if(n>Y.value)return t===0?0:t-1}return d.length-1},he=()=>{if(e.scrollspy&&!a){const t=ve();L(t)}},me=()=>d.map((t,n)=>m(it,Me({key:t.id,id:`${g}-${n}`,ref:O(n),type:e.type,color:e.color,style:t.titleStyle,class:t.titleClass,shrink:e.shrink,isActive:n===s.currentIndex,controls:t.id,scrollable:P.value,activeColor:e.titleActiveColor,inactiveColor:e.titleInactiveColor,onClick:l=>ue(t,n,l)},Ae(t,["dot","badge","title","disabled","showZeroBadge"])),{title:t.$slots.title})),ge=()=>{if(e.type==="line"&&d.length)return m("div",{class:H("line"),style:s.lineStyle},null)},J=()=>{var h,y,I;const{type:t,border:n,sticky:l}=e,v=[m("div",{ref:l?void 0:r,class:[H("wrap"),{[Ue]:t==="line"&&n}]},[m("div",{ref:u,role:"tablist",class:H("nav",[t,{shrink:e.shrink,complete:P.value}]),style:z.value,"aria-orientation":"horizontal"},[(h=o["nav-left"])==null?void 0:h.call(o),me(),ge(),(y=o["nav-right"])==null?void 0:y.call(o)])]),(I=o["nav-bottom"])==null?void 0:I.call(o)];return l?m("div",{ref:r},[v]):v};$([()=>e.color,xe],k),$(()=>e.active,t=>{t!==X.value&&_(t)}),$(()=>d.length,()=>{s.inited&&(_(e.active),k(),R(()=>{j(!0)}))});const ye=()=>{_(e.active,!0),R(()=>{s.inited=!0,r.value&&(f=ne(r.value).height),j(!0)})},Se=(t,n)=>i("rendered",t,n);return U({resize:()=>{k(),R(()=>{var t,n;return(n=(t=S.value)==null?void 0:t.swipeRef.value)==null?void 0:n.resize()})},scrollTo:be}),He(k),Ge(k),Be(ye),Re("scroll",he,{target:T,passive:!0}),N({id:g,props:e,setLine:k,onRendered:Se,currentName:X,scrollIntoView:j}),()=>{let t;return m("div",{ref:c,class:H([e.type])},[e.sticky?m(Je,{container:c.value,offsetTop:W.value,onScroll:fe},ct(t=J())?t:{default:()=>[t]}):J(),m(rt,{ref:S,count:d.length,inited:s.inited,animated:e.animated,duration:e.duration,swipeable:e.swipeable,lazyRender:e.lazyRender,currentIndex:s.currentIndex,onChange:L},{default:()=>{var n;return[(n=o.default)==null?void 0:n.call(o)]}})])}}}),se=Symbol(),Pt=()=>Ve(se,null),[ut,F]=V("tab"),ft=Oe({},Ke,{dot:Boolean,name:A,badge:A,title:String,disabled:Boolean,titleClass:Le,titleStyle:[String,Object],showZeroBadge:M}),bt=D({name:ut,props:ft,setup(e,{slots:i}){const o=le(),f=B(!1),{parent:a,index:b}=Ne(ce);if(!a)return;const c=()=>{var g;return(g=e.name)!=null?g:b.value},u=()=>{f.value=!0,a.props.lazyRender&&R(()=>{a.onRendered(c(),e.title)})},r=x(()=>{const g=c()===a.currentName.value;return g&&!f.value&&u(),g}),S=B(!r.value);return $(r,g=>{g?S.value=!1:ze(()=>{S.value=!0})}),$(()=>e.title,()=>{a.setLine(),a.scrollIntoView()}),De(se,r),()=>{var z;const g=`${a.id}-${b.value}`,{animated:T,swipeable:w,scrollspy:O,lazyRender:d}=a.props;if(!i.default&&!T)return;const N=O||r.value;if(T||w)return m(Qe,{id:o,role:"tabpanel",class:F("panel-wrapper",{inactive:S.value}),tabindex:r.value?0:-1,"aria-hidden":!r.value,"aria-labelledby":g},{default:()=>{var C;return[m("div",{class:F("panel")},[(C=i.default)==null?void 0:C.call(i)])]}});const P=f.value||O||!d?(z=i.default)==null?void 0:z.call(i):null;return U({id:o}),We(m("div",{id:o,role:"tabpanel",class:F("panel"),tabindex:N?0:-1,"aria-labelledby":g},[P]),[[Ze,N]])}}}),vt=oe(bt),Ot=vt,ht=oe(dt),Nt=ht;export{ht as T,Nt as V,vt as a,Ot as b,Pt as u};
|