build
Browse files- dist/main.bundle.js +63 -30
- dist/main.bundle.js.map +0 -0
dist/main.bundle.js
CHANGED
|
@@ -5547,73 +5547,106 @@ function _loadFragments() {
|
|
| 5547 |
;// ./src/syncHFSpacesURLHash.js
|
| 5548 |
var queryArg = "section";
|
| 5549 |
function syncHFSpacesURLHash() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5550 |
// Check for section parameter in URL
|
| 5551 |
var urlParams = new URLSearchParams(window.location.search);
|
| 5552 |
var sectionId = urlParams.get(queryArg);
|
|
|
|
|
|
|
| 5553 |
if (sectionId) {
|
| 5554 |
-
// Find the element with the specified ID
|
| 5555 |
var targetElement = document.getElementById(sectionId);
|
| 5556 |
-
|
| 5557 |
-
// scroll if the element exists
|
| 5558 |
if (targetElement) {
|
| 5559 |
-
|
| 5560 |
-
|
|
|
|
|
|
|
|
|
|
| 5561 |
}
|
|
|
|
| 5562 |
}
|
| 5563 |
-
updateHashBasedOnHashChange();
|
| 5564 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5565 |
// Variables to manage throttling
|
| 5566 |
var isScrolling = false;
|
| 5567 |
var lastKnownScrollPosition = 0;
|
|
|
|
| 5568 |
|
| 5569 |
-
// Add the scroll event listener
|
| 5570 |
window.addEventListener('scroll', function () {
|
| 5571 |
lastKnownScrollPosition = window.scrollY;
|
| 5572 |
if (!isScrolling) {
|
| 5573 |
window.requestAnimationFrame(function () {
|
| 5574 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5575 |
isScrolling = false;
|
| 5576 |
});
|
| 5577 |
}
|
| 5578 |
isScrolling = true;
|
| 5579 |
});
|
| 5580 |
-
|
| 5581 |
-
// Initial hash update on page load
|
| 5582 |
-
updateHashBasedOnScroll(window.scrollY);
|
| 5583 |
}
|
| 5584 |
|
| 5585 |
// Function to update the URL hash based on scroll position
|
| 5586 |
function updateHashBasedOnScroll(scrollPosition) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5587 |
// Get only heading elements with IDs that we want to track
|
| 5588 |
-
var
|
| 5589 |
|
| 5590 |
-
// Skip
|
| 5591 |
-
if (
|
| 5592 |
|
| 5593 |
-
// Find the element closest to the
|
| 5594 |
-
var
|
| 5595 |
var closestDistance = Infinity;
|
| 5596 |
var viewportMiddle = scrollPosition + window.innerHeight / 2;
|
| 5597 |
|
| 5598 |
-
// Iterate through all
|
| 5599 |
-
|
| 5600 |
-
var
|
| 5601 |
-
var distance = Math.abs(
|
| 5602 |
if (distance < closestDistance) {
|
| 5603 |
closestDistance = distance;
|
| 5604 |
-
|
| 5605 |
}
|
| 5606 |
});
|
|
|
|
|
|
|
| 5607 |
|
| 5608 |
-
|
| 5609 |
-
|
| 5610 |
-
|
| 5611 |
-
if (window.location.hash !== "#".concat(closestElement.id)) {
|
| 5612 |
-
// Update the URL without adding a new history entry
|
| 5613 |
-
history.replaceState(null, null, "#".concat(closestElement.id));
|
| 5614 |
-
postMessageToHFSpaces(closestElement.id);
|
| 5615 |
-
}
|
| 5616 |
-
}
|
| 5617 |
}
|
| 5618 |
function updateHashBasedOnHashChange() {
|
| 5619 |
window.addEventListener('hashchange', function () {
|
|
|
|
| 5547 |
;// ./src/syncHFSpacesURLHash.js
|
| 5548 |
var queryArg = "section";
|
| 5549 |
function syncHFSpacesURLHash() {
|
| 5550 |
+
// Handle explicit section requests (don't update hash automatically on load)
|
| 5551 |
+
var hasExplicitRequest = handleExplicitSectionRequest();
|
| 5552 |
+
|
| 5553 |
+
// Set up hash change monitoring
|
| 5554 |
+
updateHashBasedOnHashChange();
|
| 5555 |
+
|
| 5556 |
+
// Always set up scroll monitoring to update hash during scrolling
|
| 5557 |
+
setupScrollMonitoring();
|
| 5558 |
+
|
| 5559 |
+
// If no explicit request, we don't update the hash on initial load
|
| 5560 |
+
// The hash will only start updating when the user scrolls
|
| 5561 |
+
}
|
| 5562 |
+
function handleExplicitSectionRequest() {
|
| 5563 |
// Check for section parameter in URL
|
| 5564 |
var urlParams = new URLSearchParams(window.location.search);
|
| 5565 |
var sectionId = urlParams.get(queryArg);
|
| 5566 |
+
|
| 5567 |
+
// If we have an explicit section request
|
| 5568 |
if (sectionId) {
|
|
|
|
| 5569 |
var targetElement = document.getElementById(sectionId);
|
|
|
|
|
|
|
| 5570 |
if (targetElement) {
|
| 5571 |
+
// Slight delay to ensure the browser doesn't try to do its own scrolling first
|
| 5572 |
+
setTimeout(function () {
|
| 5573 |
+
targetElement.scrollIntoView();
|
| 5574 |
+
history.replaceState(null, null, "#".concat(sectionId));
|
| 5575 |
+
}, 100);
|
| 5576 |
}
|
| 5577 |
+
return true;
|
| 5578 |
}
|
|
|
|
| 5579 |
|
| 5580 |
+
// No explicit section parameter found
|
| 5581 |
+
return false;
|
| 5582 |
+
}
|
| 5583 |
+
function setupScrollMonitoring() {
|
| 5584 |
// Variables to manage throttling
|
| 5585 |
var isScrolling = false;
|
| 5586 |
var lastKnownScrollPosition = 0;
|
| 5587 |
+
var initialScroll = true;
|
| 5588 |
|
| 5589 |
+
// Add the scroll event listener
|
| 5590 |
window.addEventListener('scroll', function () {
|
| 5591 |
lastKnownScrollPosition = window.scrollY;
|
| 5592 |
if (!isScrolling) {
|
| 5593 |
window.requestAnimationFrame(function () {
|
| 5594 |
+
// Skip the first scroll event which might be browser's automatic scroll
|
| 5595 |
+
// to a hash on page load
|
| 5596 |
+
if (initialScroll) {
|
| 5597 |
+
initialScroll = false;
|
| 5598 |
+
} else {
|
| 5599 |
+
updateHashBasedOnScroll(lastKnownScrollPosition);
|
| 5600 |
+
}
|
| 5601 |
isScrolling = false;
|
| 5602 |
});
|
| 5603 |
}
|
| 5604 |
isScrolling = true;
|
| 5605 |
});
|
|
|
|
|
|
|
|
|
|
| 5606 |
}
|
| 5607 |
|
| 5608 |
// Function to update the URL hash based on scroll position
|
| 5609 |
function updateHashBasedOnScroll(scrollPosition) {
|
| 5610 |
+
var closestHeading = findClosestHeading(scrollPosition);
|
| 5611 |
+
|
| 5612 |
+
// Update the URL hash if we found a closest element
|
| 5613 |
+
if (closestHeading && closestHeading.id) {
|
| 5614 |
+
// Only update if the hash is different to avoid unnecessary operations
|
| 5615 |
+
if (window.location.hash !== "#".concat(closestHeading.id)) {
|
| 5616 |
+
silentlyUpdateHash(closestHeading.id);
|
| 5617 |
+
postMessageToHFSpaces(closestHeading.id);
|
| 5618 |
+
}
|
| 5619 |
+
}
|
| 5620 |
+
}
|
| 5621 |
+
|
| 5622 |
+
// Find the closest heading to the current scroll position
|
| 5623 |
+
function findClosestHeading(scrollPosition) {
|
| 5624 |
// Get only heading elements with IDs that we want to track
|
| 5625 |
+
var headingsWithIds = Array.from(document.querySelectorAll('h1[id], h2[id], h3[id], h4[id], h5[id], h6[id]'));
|
| 5626 |
|
| 5627 |
+
// Skip if there are no headings with IDs
|
| 5628 |
+
if (headingsWithIds.length === 0) return null;
|
| 5629 |
|
| 5630 |
+
// Find the element closest to the middle of the viewport
|
| 5631 |
+
var closestHeading = null;
|
| 5632 |
var closestDistance = Infinity;
|
| 5633 |
var viewportMiddle = scrollPosition + window.innerHeight / 2;
|
| 5634 |
|
| 5635 |
+
// Iterate through all headings to find the closest one
|
| 5636 |
+
headingsWithIds.forEach(function (heading) {
|
| 5637 |
+
var headingTop = heading.getBoundingClientRect().top + scrollPosition;
|
| 5638 |
+
var distance = Math.abs(headingTop - viewportMiddle);
|
| 5639 |
if (distance < closestDistance) {
|
| 5640 |
closestDistance = distance;
|
| 5641 |
+
closestHeading = heading;
|
| 5642 |
}
|
| 5643 |
});
|
| 5644 |
+
return closestHeading;
|
| 5645 |
+
}
|
| 5646 |
|
| 5647 |
+
// Update hash without triggering scroll or other side effects
|
| 5648 |
+
function silentlyUpdateHash(id) {
|
| 5649 |
+
history.replaceState(null, null, "#".concat(id));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5650 |
}
|
| 5651 |
function updateHashBasedOnHashChange() {
|
| 5652 |
window.addEventListener('hashchange', function () {
|
dist/main.bundle.js.map
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|