"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const o=require("vue"),R=require("../node_modules/.pnpm/scroll-into-view-if-needed@3.1.0/node_modules/scroll-into-view-if-needed/dist/index.js"),y=require("../_util/classNames.js"),z=require("../_util/getScroll.js"),V=require("../_util/scrollTo.js"),D=require("../_util/type.js"),P=require("../_util/vue-types/index.js"),j=require("../affix/index.js"),H=require("../config-provider/hooks/useConfigInject.js"),$=require("../vc-util/Dom/addEventListener.js"),U=require("./AnchorLink.js"),_=require("./context.js"),W=require("./style/index.js");function G(){return window}function q(l,f){if(!l.getClientRects().length)return 0;const d=l.getBoundingClientRect();return d.width||d.height?f===window?(f=l.ownerDocument.documentElement,d.top-f.clientTop):d.top-f.getBoundingClientRect().top:d.top}const E=/#([\S ]+)$/,L=()=>({prefixCls:String,offsetTop:Number,bounds:Number,affix:{type:Boolean,default:!0},showInkInFixed:{type:Boolean,default:!1},getContainer:Function,wrapperClass:String,wrapperStyle:{type:Object,default:void 0},getCurrentAnchor:Function,targetOffset:Number,items:D.arrayType(),direction:P.default.oneOf(["vertical","horizontal"]).def("vertical"),onChange:Function,onClick:Function}),J=o.defineComponent({compatConfig:{MODE:3},name:"AAnchor",inheritAttrs:!1,props:L(),setup(l,{emit:f,attrs:d,slots:x,expose:N}){const{prefixCls:k,getTargetContainer:b,direction:O}=H.default("anchor",l),p=o.computed(()=>l.direction??"vertical"),g=o.ref(null),T=o.ref(),n=o.reactive({links:[],scrollContainer:null,scrollEvent:null,animating:!1}),C=o.ref(null),v=o.computed(()=>{const{getContainer:e}=l;return e||b?.value||G}),I=(e=0,t=5)=>{const c=[],r=v.value();return n.links.forEach(s=>{const i=E.exec(s.toString());if(!i)return;const a=document.getElementById(i[1]);if(a){const u=q(a,r);u<e+t&&c.push({link:s,top:u})}}),c.length?c.reduce((i,a)=>a.top>i.top?a:i).link:""},w=e=>{const{getCurrentAnchor:t}=l;C.value!==e&&(C.value=typeof t=="function"?t(e):e,f("change",e))},S=e=>{const{offsetTop:t,targetOffset:c}=l;w(e);const r=E.exec(e);if(!r)return;const s=document.getElementById(r[1]);if(!s)return;const i=v.value(),a=z.default(i),u=q(s,i);let h=a+u;h-=c!==void 0?c:t||0,n.animating=!0,V.default(h,{callback:()=>{n.animating=!1},getContainer:v.value})};N({scrollTo:S});const m=()=>{if(n.animating)return;const{offsetTop:e,bounds:t,targetOffset:c}=l,r=I(c!==void 0?c:e||0,t);w(r)},M=()=>{const e=T.value.querySelector(`.${k.value}-link-title-active`);if(e&&g.value){const t=p.value==="horizontal";g.value.style.top=t?"":`${e.offsetTop+e.clientHeight/2}px`,g.value.style.height=t?"":`${e.clientHeight}px`,g.value.style.left=t?`${e.offsetLeft}px`:"",g.value.style.width=t?`${e.clientWidth}px`:"",t&&R.default(e,{scrollMode:"if-needed",block:"nearest"})}};_.default({registerLink:e=>{n.links.includes(e)||n.links.push(e)},unregisterLink:e=>{const t=n.links.indexOf(e);t!==-1&&n.links.splice(t,1)},activeLink:C,scrollTo:S,handleClick:(e,t)=>{f("click",e,t)},direction:p}),o.onMounted(()=>{o.nextTick(()=>{const e=v.value();n.scrollContainer=e,n.scrollEvent=$.default(n.scrollContainer,"scroll",m),m()})}),o.onBeforeUnmount(()=>{n.scrollEvent&&n.scrollEvent.remove()}),o.onUpdated(()=>{if(n.scrollEvent){const e=v.value();n.scrollContainer!==e&&(n.scrollContainer=e,n.scrollEvent.remove(),n.scrollEvent=$.default(n.scrollContainer,"scroll",m),m())}M()});const A=e=>Array.isArray(e)?e.map(t=>{const{children:c,key:r,href:s,target:i,class:a,style:u,title:h}=t;return o.createVNode(U.default,{key:r,href:s,target:i,class:a,style:u,title:h,customTitleProps:t},{default:()=>[p.value==="vertical"?A(c):null],customTitle:x.customTitle})}):null,[B,F]=W.default(k);return()=>{const{offsetTop:e,affix:t,showInkInFixed:c}=l,r=k.value,s=y.default(`${r}-ink`,{[`${r}-ink-visible`]:C.value}),i=y.default(F.value,l.wrapperClass,`${r}-wrapper`,{[`${r}-wrapper-horizontal`]:p.value==="horizontal",[`${r}-rtl`]:O.value==="rtl"}),a=y.default(r,{[`${r}-fixed`]:!t&&!c}),u={maxHeight:e?`calc(100vh - ${e}px)`:"100vh",...l.wrapperStyle},h=o.createVNode("div",{class:i,style:u,ref:T},[o.createVNode("div",{class:a},[o.createVNode("span",{class:s,ref:g},null),Array.isArray(l.items)?A(l.items):x.default?.()])]);return B(t?o.createVNode(j.default,{...d,offsetTop:e,target:v.value},{default:()=>[h]}):h)}}});exports.anchorProps=L;exports.default=J;
