ll-package
Version:
2 lines (1 loc) • 5.2 kB
JavaScript
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const $=require("../../../@babel/runtime/helpers/esm/objectSpread2.js"),R=require("../../../@babel/runtime/helpers/esm/extends.js"),l=require("vue"),j=require("../../../scroll-into-view-if-needed/es/index.js"),A=require("../_util/classNames.js"),b=require("../vc-util/Dom/addEventListener.js"),H=require("../affix/index.js"),U=require("../_util/scrollTo.js"),W=require("../_util/getScroll.js"),G=require("../config-provider/hooks/useConfigInject.js"),J=require("./context.js"),K=require("./style/index.js"),Q=require("./AnchorLink.js"),X=require("../_util/vue-types/index.js"),L=require("../vc-util/devWarning.js"),Y=require("../_util/type.js");function Z(){return window}function O(r,f){if(!r.getClientRects().length)return 0;const u=r.getBoundingClientRect();return u.width||u.height?f===window?(f=r.ownerDocument.documentElement,u.top-f.clientTop):u.top-f.getBoundingClientRect().top:u.top}const I=/#([\S ]+)$/,M=()=>({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:Y.arrayType(),direction:X.default.oneOf(["vertical","horizontal"]).def("vertical"),onChange:Function,onClick:Function}),ee=l.defineComponent({compatConfig:{MODE:3},name:"AAnchor",inheritAttrs:!1,props:M(),setup(r,f){let{emit:u,attrs:_,slots:m,expose:z}=f;var k;const{prefixCls:x,getTargetContainer:T,direction:B}=G.default("anchor",r),p=l.computed(()=>{var e;return(e=r.direction)!==null&&e!==void 0?e:"vertical"});process.env.NODE_ENV!=="production"&&L.default(r.items&&typeof m.default!="function","Anchor","`Anchor children` is deprecated. Please use `items` instead."),process.env.NODE_ENV!=="production"&&L.default(!(p.value==="horizontal"&&(!((k=r.items)===null||k===void 0)&&k.some(e=>"children"in e))),"Anchor","`Anchor items#children` is not supported when `Anchor` direction is horizontal.");const h=l.ref(null),w=l.ref(),n=l.reactive({links:[],scrollContainer:null,scrollEvent:null,animating:!1}),C=l.ref(null),v=l.computed(()=>{const{getContainer:e}=r;return e||(T==null?void 0:T.value)||Z}),V=function(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:0,t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:5;const i=[],a=v.value();return n.links.forEach(o=>{const c=I.exec(o.toString());if(!c)return;const s=document.getElementById(c[1]);if(s){const d=O(s,a);d<e+t&&i.push({link:o,top:d})}}),i.length?i.reduce((c,s)=>s.top>c.top?s:c).link:""},S=e=>{const{getCurrentAnchor:t}=r;C.value!==e&&(C.value=typeof t=="function"?t(e):e,u("change",e))},E=e=>{const{offsetTop:t,targetOffset:i}=r;S(e);const a=I.exec(e);if(!a)return;const o=document.getElementById(a[1]);if(!o)return;const c=v.value(),s=W.default(c,!0),d=O(o,c);let g=s+d;g-=i!==void 0?i:t||0,n.animating=!0,U.default(g,{callback:()=>{n.animating=!1},getContainer:v.value})};z({scrollTo:E});const y=()=>{if(n.animating)return;const{offsetTop:e,bounds:t,targetOffset:i}=r,a=V(i!==void 0?i:e||0,t);S(a)},D=()=>{const e=w.value.querySelector(`.${x.value}-link-title-active`);if(e&&h.value){const t=p.value==="horizontal";h.value.style.top=t?"":`${e.offsetTop+e.clientHeight/2}px`,h.value.style.height=t?"":`${e.clientHeight}px`,h.value.style.left=t?`${e.offsetLeft}px`:"",h.value.style.width=t?`${e.clientWidth}px`:"",t&&j.default(e,{scrollMode:"if-needed",block:"nearest"})}};J.useProvideAnchor({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:E,handleClick:(e,t)=>{u("click",e,t)},direction:p}),l.onMounted(()=>{l.nextTick(()=>{const e=v.value();n.scrollContainer=e,n.scrollEvent=b.default(n.scrollContainer,"scroll",y),y()})}),l.onBeforeUnmount(()=>{n.scrollEvent&&n.scrollEvent.remove()}),l.onUpdated(()=>{if(n.scrollEvent){const e=v.value();n.scrollContainer!==e&&(n.scrollContainer=e,n.scrollEvent.remove(),n.scrollEvent=b.default(n.scrollContainer,"scroll",y),y())}D()});const q=e=>Array.isArray(e)?e.map(t=>{const{children:i,key:a,href:o,target:c,class:s,style:d,title:g}=t;return l.createVNode(Q.default,{key:a,href:o,target:c,class:s,style:d,title:g,customTitleProps:t},{default:()=>[p.value==="vertical"?q(i):null],customTitle:m.customTitle})}):null,[F,P]=K.default(x);return()=>{var e;const{offsetTop:t,affix:i,showInkInFixed:a}=r,o=x.value,c=A.default(`${o}-ink`,{[`${o}-ink-visible`]:C.value}),s=A.default(P.value,r.wrapperClass,`${o}-wrapper`,{[`${o}-wrapper-horizontal`]:p.value==="horizontal",[`${o}-rtl`]:B.value==="rtl"}),d=A.default(o,{[`${o}-fixed`]:!i&&!a}),g=R.default({maxHeight:t?`calc(100vh - ${t}px)`:"100vh"},r.wrapperStyle),N=l.createVNode("div",{class:s,style:g,ref:w},[l.createVNode("div",{class:d},[l.createVNode("span",{class:c,ref:h},null),Array.isArray(r.items)?q(r.items):(e=m.default)===null||e===void 0?void 0:e.call(m)])]);return F(i?l.createVNode(H.default,$.default($.default({},_),{},{offsetTop:t,target:v.value}),{default:()=>[N]}):N)}}});exports.anchorProps=M;exports.default=ee;
;