@hortonstudio/main 1.7.16 → 1.8.1
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.
- package/autoInit/accessibility.js +42 -3
- package/index.js +3 -0
- package/package.json +1 -1
|
@@ -593,10 +593,18 @@ export function init() {
|
|
|
593
593
|
}
|
|
594
594
|
|
|
595
595
|
|
|
596
|
-
const template = tocList.children[0];
|
|
596
|
+
const template = tocList.children[0].cloneNode(true);
|
|
597
|
+
// Remove is-active class from template if it exists
|
|
598
|
+
const templateLink = template.querySelector("a");
|
|
599
|
+
if (templateLink) {
|
|
600
|
+
templateLink.classList.remove('is-active');
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
// Clear all original TOC items
|
|
597
604
|
tocList.innerHTML = "";
|
|
605
|
+
|
|
598
606
|
const h2Headings = contentArea.querySelectorAll("h2");
|
|
599
|
-
|
|
607
|
+
|
|
600
608
|
|
|
601
609
|
// Create sections and wrap content
|
|
602
610
|
h2Headings.forEach((heading) => {
|
|
@@ -604,7 +612,7 @@ export function init() {
|
|
|
604
612
|
.toLowerCase()
|
|
605
613
|
.replace(/[^a-z0-9]+/g, "-")
|
|
606
614
|
.replace(/(^-|-$)/g, "");
|
|
607
|
-
|
|
615
|
+
|
|
608
616
|
const section = document.createElement("div");
|
|
609
617
|
section.id = sectionId;
|
|
610
618
|
heading.parentNode.insertBefore(section, heading);
|
|
@@ -661,6 +669,37 @@ export function init() {
|
|
|
661
669
|
tocList.appendChild(tocItem);
|
|
662
670
|
});
|
|
663
671
|
|
|
672
|
+
// Set up IntersectionObserver for active state (Webflow-style)
|
|
673
|
+
const sections = Array.from(h2Headings).map(heading => heading.parentElement);
|
|
674
|
+
const tocLinks = tocList.querySelectorAll('a');
|
|
675
|
+
|
|
676
|
+
const observerOptions = {
|
|
677
|
+
rootMargin: '0px 0px -75% 0px', // Trigger when section is 25% from bottom
|
|
678
|
+
threshold: 0
|
|
679
|
+
};
|
|
680
|
+
|
|
681
|
+
const observer = new IntersectionObserver((entries) => {
|
|
682
|
+
entries.forEach(entry => {
|
|
683
|
+
if (entry.isIntersecting) {
|
|
684
|
+
const sectionId = entry.target.id;
|
|
685
|
+
|
|
686
|
+
// Remove is-active from all links
|
|
687
|
+
tocLinks.forEach(link => link.classList.remove('is-active'));
|
|
688
|
+
|
|
689
|
+
// Add is-active to the corresponding link
|
|
690
|
+
const activeLink = Array.from(tocLinks).find(link =>
|
|
691
|
+
link.getAttribute('href') === `#${sectionId}`
|
|
692
|
+
);
|
|
693
|
+
if (activeLink) {
|
|
694
|
+
activeLink.classList.add('is-active');
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
});
|
|
698
|
+
}, observerOptions);
|
|
699
|
+
|
|
700
|
+
// Observe all sections
|
|
701
|
+
sections.forEach(section => observer.observe(section));
|
|
702
|
+
|
|
664
703
|
});
|
|
665
704
|
}
|
|
666
705
|
|
package/index.js
CHANGED
|
@@ -9,6 +9,9 @@ const initializeHsMain = async () => {
|
|
|
9
9
|
return;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
+
// Add hs-main class to HTML element immediately
|
|
13
|
+
document.documentElement.classList.add('hs-main');
|
|
14
|
+
|
|
12
15
|
const queuedModules = Array.isArray(window[API_NAME]) ? window[API_NAME] : [];
|
|
13
16
|
|
|
14
17
|
const animationModules = {};
|