UNPKG

bootstrap-vue-next

Version:

BootstrapVueNext is an early and lovely component library for Vue 3 & Nuxt 3 based on Bootstrap 5 and Typescript.

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