bootstrap-vue-next
Version:
Seamless integration of Vue 3, Bootstrap 5, and TypeScript for modern, type-safe UI development
3 lines (2 loc) • 2.78 kB
JavaScript
;Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../../../index-C8tYBJvG.js"),t=require("vue"),l=require("../../../getElement-BIaUkSEc.js"),r=require("../../../index-CbGpN2AJ.js");exports.useScrollspy=(o,s,n={})=>{const i=t.toRef(o),a=t.toRef(s),u=t.ref(l.getElement(i.value)),c=t.ref(l.getElement(a.value));t.watch([i,a],()=>{q()});const{contentQuery:v=":scope > [id]",targetQuery:d="[href]",manual:f=!1,root:g,rootMargin:m="0px 0px -25%",threshold:p=[.1,.5,1],watchChanges:h=!0}=n,y=t.ref(null),b=t.ref([]),S=t.ref([]);t.getCurrentInstance()?t.onMounted(()=>{r.syncRef(i,u,{transform:{ltr:e=>l.getElement(e)},direction:"ltr",immediate:!0}),r.syncRef(a,c,{transform:{ltr:e=>l.getElement(e)},direction:"ltr",immediate:!0}),q()}):t.nextTick(()=>{q()});const q=()=>{S.value=u.value?Array.from(u.value.querySelectorAll(v)):[],b.value=S.value.map(e=>({id:e.id,el:e,visible:!1,text:e.textContent}))};let E=!0,L=0;const x=t.computed(()=>u.value&&"visible"===getComputedStyle(u.value).overflowY?null:u.value),w=e.useIntersectionObserver(S,e=>{const t=(x.value||document?.documentElement)?.scrollTop;E=t>L,L=t,e.forEach(e=>{e.isIntersecting?b.value.forEach(t=>{t.el===e.target&&(t.visible=!0)}):b.value.forEach(t=>{t.el===e.target&&(t.visible=!1)})});let l=null;l=E?[...b.value].reverse().find(e=>e.visible)?.id||null:b.value.find(e=>e.visible)?.id||null,null!==l&&(y.value=l),y.value||(y.value=b.value[0]?.id||null)},{root:g?l.getElement(g):x,rootMargin:m,threshold:p});t.watch(y,e=>{if(f)return;const t=c.value?.querySelectorAll(d);if(void 0===t)return;let l=!1,r=null;t.forEach(t=>{const o=t.closest(".dropdown");if(t.getAttribute("href")?.includes(`#${e}`)){r=t,t.classList.add("active"),o&&(o?.querySelector(".dropdown-toggle")?.classList.add("active"),l=!0);let e=t.closest(".nav")?.previousSibling;for(;e?.classList?.contains("nav-item");)l=!0,e.querySelector(".nav-link")?.classList.add("active"),e=e.closest(".nav")?.previousSibling}else if(t.classList.remove("active"),o&&!l&&o?.querySelector(".dropdown-toggle")?.classList.remove("active"),!l){let e=t.closest(".nav")?.previousSibling;for(;e?.classList?.contains("nav-item");)l=!0,e.querySelector(".nav-link")!==r&&e.querySelector(".nav-link")?.classList.remove("active"),e=e.closest(".nav")?.previousSibling}})});const T=h?e.useMutationObserver(u,()=>{q()},{childList:!0}):{stop:()=>{}};return{current:t.readonly(y),list:b,content:u,target:c,scrollIntoView:(e,t=!1)=>{e.preventDefault();const l=e.target?.getAttribute?.("href"),r=l?document?.querySelector(l):null;r&&u.value&&(u.value.scrollTo?u.value.scrollTo({top:r.offsetTop,behavior:t?"smooth":"auto"}):u.value.scrollTop=r.offsetTop)},updateList:q,cleanup:()=>{w.stop(),T.stop()}}};
//# sourceMappingURL=index.umd.js.map