Repository: mdbootstrap/TW-Elements (language: javascript)

Issue:
Scrollspy items not activated correctly when page loads with scroll position not at the top of the page
When a page with scrollspy is loaded with the scroll position somewhere in the middle of the spied element (e.g. when the url has an anchor), the last nav link is always the one that's activated, and the scrollspy doesn't activate the corresponding links as you scroll up and down the page.
However, when the page is loaded with the scroll position at the top of the page, the scrollspy functions properly.

Scrollspy initialization JS:
```
import { ScrollSpy, Collapse, Modal, initTE } from "tw-elements";

initTE({ ScrollSpy, Collapse, Modal });

const profileScrollSpy = new ScrollSpy(document.body, {
        target: "#profile-nav",
        offset: 200,
    });
```

I am using NPM with Vite.

Error occurs on Chrome and Firefox (only browsers I've tested with so far)



Discussion / hints:

Fix patch:
diff --git a/src/js/dom/manipulator.js b/src/js/dom/manipulator.js
index a851397e1..cd1d7d2e6 100644
--- a/src/js/dom/manipulator.js
+++ b/src/js/dom/manipulator.js
@@ -151,6 +151,27 @@ const Manipulator = {
   hasClass(element, className) {
     return element.classList.contains(className);
   },
+
+  maxOffset(element) {
+    const rect = element.getBoundingClientRect();
+
+    return {
+      top:
+        rect.top +
+        Math.max(
+          document.body.scrollTop,
+          document.documentElement.scrollTop,
+          window.scrollY
+        ),
+      left:
+        rect.left +
+        Math.max(
+          document.body.scrollLeft,
+          document.documentElement.scrollLeft,
+          window.scrollX
+        ),
+    };
+  },
 };
 
 function _classNameOrListToArray(classNameOrList) {
diff --git a/src/js/navigation/scrollspy.js b/src/js/navigation/scrollspy.js
index 8b8d40dbb..d68667472 100644
--- a/src/js/navigation/scrollspy.js
+++ b/src/js/navigation/scrollspy.js
@@ -67,7 +67,7 @@ const SELECTOR_LINK_ITEMS = `${SELECTOR_NAV_LINKS}, ${SELECTOR_LIST_ITEMS}, ${SE
 const SELECTOR_DROPDOWN = "[data-te-dropdown-ref]";
 const SELECTOR_DROPDOWN_TOGGLE = "[data-te-dropdown-toggle-ref]";
 
-const METHOD_OFFSET = "offset";
+const METHOD_OFFSET = "maxOffset";
 const METHOD_POSITION = "position";
 
 /*


Test patch: