fumadocs-core 13.0.5 → 13.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/toc.js +12 -4
  2. package/package.json +1 -1
package/dist/toc.js CHANGED
@@ -29,17 +29,24 @@ function useAnchorObserver(watch) {
29
29
  (entries) => {
30
30
  setActiveAnchor((f) => {
31
31
  for (const entry of entries) {
32
- const aboveHalf = window.innerHeight / 2 > entry.boundingClientRect.y;
33
- const active = aboveHalf && entry.isIntersecting;
34
- if (active) {
32
+ if (entry.isIntersecting) {
35
33
  return entry.target.id;
36
34
  }
37
35
  }
38
36
  return f ?? watch[0];
39
37
  });
40
38
  },
41
- { rootMargin: `0% 0% -80% 0%` }
39
+ { rootMargin: `-60px 0% -70% 0%`, threshold: 1 }
42
40
  );
41
+ const scroll = () => {
42
+ const element = document.scrollingElement;
43
+ if (!element) return;
44
+ if (element.scrollTop >= // assume you have a 10px margin
45
+ element.scrollHeight - element.clientHeight - 10) {
46
+ setActiveAnchor(watch.at(-1));
47
+ }
48
+ };
49
+ window.addEventListener("scroll", scroll);
43
50
  for (const heading of watch) {
44
51
  const element = document.getElementById(heading);
45
52
  if (element !== null) {
@@ -47,6 +54,7 @@ function useAnchorObserver(watch) {
47
54
  }
48
55
  }
49
56
  return () => {
57
+ window.removeEventListener("scroll", scroll);
50
58
  observer.disconnect();
51
59
  };
52
60
  }, [watch]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fumadocs-core",
3
- "version": "13.0.5",
3
+ "version": "13.0.7",
4
4
  "description": "The library for building a documentation website in Next.js",
5
5
  "keywords": [
6
6
  "NextJs",