diff --git a/.gitignore b/.gitignore index dcac261..b2b378e 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,7 @@ pnpm-debug.log* package-lock.json bun.lockb yarn.lock + +# ide +.idea +*.iml diff --git a/src/components/widget/TOC.astro b/src/components/widget/TOC.astro index 608de57..6cb2fab 100644 --- a/src/components/widget/TOC.astro +++ b/src/components/widget/TOC.astro @@ -55,7 +55,7 @@ const maxLevel = siteConfig.toc.depth; }]}>{removeTailingHash(heading.text)} )} -
} @@ -97,7 +97,7 @@ class TableOfContents extends HTMLElement { toggleActiveHeading = () => { let i = this.active.length - 1; - let min = this.active.length - 1, max = 0; + let min = this.active.length - 1, max = -1; while (i >= 0 && !this.active[i]) { this.tocEntries[i].classList.remove(this.visibleClass); i--; @@ -112,11 +112,15 @@ class TableOfContents extends HTMLElement { this.tocEntries[i].classList.remove(this.visibleClass); i--; } - let parentOffset = this.tocEl?.getBoundingClientRect().top || 0; - let scrollOffset = this.tocEl?.scrollTop || 0; - let top = this.tocEntries[min].getBoundingClientRect().top - parentOffset + scrollOffset; - let bottom = this.tocEntries[max].getBoundingClientRect().bottom - parentOffset + scrollOffset; - this.activeIndicator?.setAttribute("style", `top: ${top}px; height: ${bottom - top}px`); + if (min > max) { + this.activeIndicator?.setAttribute("style", `opacity: 0`); + } else { + let parentOffset = this.tocEl?.getBoundingClientRect().top || 0; + let scrollOffset = this.tocEl?.scrollTop || 0; + let top = this.tocEntries[min].getBoundingClientRect().top - parentOffset + scrollOffset; + let bottom = this.tocEntries[max].getBoundingClientRect().bottom - parentOffset + scrollOffset; + this.activeIndicator?.setAttribute("style", `top: ${top}px; height: ${bottom - top}px`); + } }; scrollToActiveHeading = () => {