import{C as Q,c as N,g as vt,m as Ct,i as W,r as St,t as yt,k as $t,L as D,N as xt}from"./useTranslation-CksCcIr-.js";import{r as o}from"./jsx-runtime-CgWCn3gT.js";import{e as bt}from"./index-DKjRcP81.js";import{aF as wt,aG as Et,aH as Lt,aI as Bt}from"./legacy-shell-D4JdMu14.js";const U=o.createContext(void 0),Z=n=>{const{href:t,title:r,prefixCls:u,children:l,className:m,target:c,replace:f}=n,$=o.useContext(U),{registerLink:x,unregisterLink:b,scrollTo:p,onClick:y,activeLink:k,direction:T}=$||{};o.useEffect(()=>(x?.(t),()=>{b?.(t)}),[t]);const w=h=>{if(y?.(h,{title:r,href:t}),p?.(t),h.defaultPrevented)return;if(t.startsWith("http://")||t.startsWith("https://")){f&&(h.preventDefault(),window.location.replace(t));return}h.preventDefault();const L=f?"replaceState":"pushState";window.history[L](null,"",t)},{getPrefixCls:E}=o.useContext(Q),a=E("anchor",u),I=k===t,C=N(`${a}-link`,m,{[`${a}-link-active`]:I}),P=N(`${a}-link-title`,{[`${a}-link-title-active`]:I});return o.createElement("div",{className:C},o.createElement("a",{className:P,href:t,title:typeof r=="string"?r:"",target:c,onClick:w},r),T!=="horizontal"?l:null)},At=n=>{const{componentCls:t,holderOffsetBlock:r,motionDurationSlow:u,lineWidthBold:l,colorPrimary:m,lineType:c,colorSplit:f,calc:$}=n;return{[`${t}-wrapper`]:{marginBlockStart:$(r).mul(-1).equal(),paddingBlockStart:r,[t]:Object.assign(Object.assign({},St(n)),{position:"relative",paddingInlineStart:l,[`${t}-link`]:{paddingBlock:n.linkPaddingBlock,paddingInline:`${W(n.linkPaddingInlineStart)} 0`,"&-title":Object.assign(Object.assign({},yt),{position:"relative",display:"block",marginBlockEnd:n.anchorTitleBlock,color:n.colorText,transition:`all ${n.motionDurationSlow}`,"&:only-child":{marginBlockEnd:0}}),[`&-active > ${t}-link-title`]:{color:n.colorPrimary},[`${t}-link`]:{paddingBlock:n.anchorPaddingBlockSecondary}}}),[`&:not(${t}-wrapper-horizontal)`]:{[t]:{"&::before":{position:"absolute",insetInlineStart:0,top:0,height:"100%",borderInlineStart:`${W(l)} ${c} ${f}`,content:'" "'},[`${t}-ink`]:{position:"absolute",insetInlineStart:0,display:"none",transform:"translateY(-50%)",transition:`top ${u} ease-in-out`,width:l,backgroundColor:m,[`&${t}-ink-visible`]:{display:"inline-block"}}}},[`${t}-fixed ${t}-ink ${t}-ink`]:{display:"none"}}}},Nt=n=>{const{componentCls:t,motionDurationSlow:r,lineWidthBold:u,colorPrimary:l}=n;return{[`${t}-wrapper-horizontal`]:{position:"relative","&::before":{position:"absolute",left:{_skip_check_:!0,value:0},right:{_skip_check_:!0,value:0},bottom:0,borderBottom:`${W(n.lineWidth)} ${n.lineType} ${n.colorSplit}`,content:'" "'},[t]:{overflowX:"scroll",position:"relative",display:"flex",scrollbarWidth:"none","&::-webkit-scrollbar":{display:"none"},[`${t}-link:first-of-type`]:{paddingInline:0},[`${t}-ink`]:{position:"absolute",bottom:0,transition:`left ${r} ease-in-out, width ${r} ease-in-out`,height:u,backgroundColor:l}}}}},Tt=n=>({linkPaddingBlock:n.paddingXXS,linkPaddingInlineStart:n.padding}),It=vt("Anchor",n=>{const{fontSize:t,fontSizeLG:r,paddingXXS:u,calc:l}=n,m=Ct(n,{holderOffsetBlock:u,anchorPaddingBlockSecondary:l(u).div(2).equal(),anchorTitleBlock:l(t).div(14).mul(3).equal(),anchorBallSize:l(r).div(2).equal()});return[At(m),Nt(m)]},Tt);function Pt(){return window}function Y(n,t){if(!n.getClientRects().length)return 0;const r=n.getBoundingClientRect();return r.width||r.height?t===window?r.top-n.ownerDocument.documentElement.clientTop:r.top-t.getBoundingClientRect().top:r.top}const K=/#([\S ]+)$/,Ot=n=>{var t;const{rootClassName:r,prefixCls:u,className:l,style:m,offsetTop:c,affix:f=!0,showInkInFixed:$=!1,children:x,items:b,direction:p="vertical",bounds:y,targetOffset:k,onClick:T,onChange:w,getContainer:E,getCurrentAnchor:a,replace:I}=n,[C,P]=o.useState([]),[h,H]=o.useState(null),L=o.useRef(h),M=o.useRef(null),O=o.useRef(null),z=o.useRef(!1),{direction:tt,getPrefixCls:et,className:nt,style:ot}=$t("anchor"),{getTargetContainer:it}=o.useContext(Q),g=et("anchor",u),q=wt(g),[rt,lt,st]=It(g,q),B=(t=E??it)!==null&&t!==void 0?t:Pt,X=JSON.stringify(C),ct=D(e=>{C.includes(e)||P(i=>[].concat(xt(i),[e]))}),at=D(e=>{C.includes(e)&&P(i=>i.filter(d=>d!==e))}),dt=()=>{var e;const i=(e=M.current)===null||e===void 0?void 0:e.querySelector(`.${g}-link-title-active`);if(i&&O.current){const{style:d}=O.current,s=p==="horizontal";d.top=s?"":`${i.offsetTop+i.clientHeight/2}px`,d.height=s?"":`${i.clientHeight}px`,d.left=s?`${i.offsetLeft}px`:"",d.width=s?`${i.clientWidth}px`:"",s&&bt(i,{scrollMode:"if-needed",block:"nearest"})}},ut=(e,i=0,d=5)=>{const s=[],_=B();return e.forEach(S=>{const v=K.exec(S?.toString());if(!v)return;const A=document.getElementById(v[1]);if(A){const J=Y(A,_);J<=i+d&&s.push({link:S,top:J})}}),s.length?s.reduce((v,A)=>A.top>v.top?A:v).link:""},R=D(e=>{if(L.current===e)return;const i=typeof a=="function"?a(e):e;H(i),L.current=i,w?.(e)}),j=o.useCallback(()=>{if(z.current)return;const e=ut(C,k!==void 0?k:c||0,y);R(e)},[C,k,c,y]),V=o.useCallback(e=>{R(e);const i=K.exec(e);if(!i)return;const d=document.getElementById(i[1]);if(!d)return;const s=B(),_=Et(s),S=Y(d,s);let v=_+S;v-=k!==void 0?k:c||0,z.current=!0,Lt(v,{getContainer:B,callback(){z.current=!1}})},[k,c]),ft=N(lt,st,q,r,`${g}-wrapper`,{[`${g}-wrapper-horizontal`]:p==="horizontal",[`${g}-rtl`]:tt==="rtl"},l,nt),pt=N(g,{[`${g}-fixed`]:!f&&!$}),ht=N(`${g}-ink`,{[`${g}-ink-visible`]:h}),gt=Object.assign(Object.assign({maxHeight:c?`calc(100vh - ${c}px)`:"100vh"},ot),m),F=e=>Array.isArray(e)?e.map(i=>o.createElement(Z,Object.assign({replace:I},i,{key:i.key}),p==="vertical"&&F(i.children))):null,G=o.createElement("div",{ref:M,className:ft,style:gt},o.createElement("div",{className:pt},o.createElement("span",{className:ht,ref:O}),"items"in n?F(b):x));o.useEffect(()=>{const e=B();return j(),e?.addEventListener("scroll",j),()=>{e?.removeEventListener("scroll",j)}},[X]),o.useEffect(()=>{typeof a=="function"&&R(a(L.current||""))},[a]),o.useEffect(()=>{dt()},[p,a,X,h]);const mt=o.useMemo(()=>({registerLink:ct,unregisterLink:at,scrollTo:V,activeLink:h,onClick:T,direction:p}),[h,T,V,p]),kt=f&&typeof f=="object"?f:void 0;return rt(o.createElement(U.Provider,{value:mt},f?o.createElement(Bt,Object.assign({offsetTop:c,target:B},kt),G):G))},zt=Ot;zt.Link=Z;export{zt as A};
