Merge branch 'dev' into v4

This commit is contained in:
neerajadhav 2025-07-08 18:22:52 +05:30
commit ca892e24d3
2 changed files with 34 additions and 62 deletions

View File

@ -130,7 +130,7 @@ async function mouseEnterHandler(
const targetID = `popover-internal-${el.id}` const targetID = `popover-internal-${el.id}`
el.id = targetID el.id = targetID
}) })
const elts = Array.from(html.getElementsByClassName("popover-hint")) const elts = [...html.getElementsByClassName("popover-hint")]
if (elts.length === 0) return if (elts.length === 0) return
elts.forEach((elt) => popoverInner.appendChild(elt)) elts.forEach((elt) => popoverInner.appendChild(elt))
@ -167,9 +167,8 @@ document.addEventListener("nav", () => {
for (const link of links) { for (const link of links) {
link.addEventListener("mouseenter", mouseEnterHandler) link.addEventListener("mouseenter", mouseEnterHandler)
link.addEventListener("mouseleave", clearActivePopoverAndHighlights) link.addEventListener("mouseleave", clearActivePopoverAndHighlights)
// Use type assertion to avoid TypeScript error when checking individual files if (typeof window.addCleanup === "function") {
if (typeof (window as any).addCleanup === "function") { window.addCleanup(() => {
;(window as any).addCleanup(() => {
link.removeEventListener("mouseenter", mouseEnterHandler) link.removeEventListener("mouseenter", mouseEnterHandler)
link.removeEventListener("mouseleave", clearActivePopoverAndHighlights) link.removeEventListener("mouseleave", clearActivePopoverAndHighlights)
}) })

View File

@ -14,13 +14,12 @@ export function registerEscapeHandler(outsideContainer: HTMLElement | null, cb:
} }
outsideContainer?.addEventListener("click", click) outsideContainer?.addEventListener("click", click)
// Use type assertion to avoid TypeScript error when checking individual files if (typeof window.addCleanup === "function") {
if (typeof (window as any).addCleanup === "function") { window.addCleanup(() => outsideContainer?.removeEventListener("click", click))
;(window as any).addCleanup(() => outsideContainer?.removeEventListener("click", click))
} }
document.addEventListener("keydown", esc) document.addEventListener("keydown", esc)
if (typeof (window as any).addCleanup === "function") { if (typeof window.addCleanup === "function") {
;(window as any).addCleanup(() => document.removeEventListener("keydown", esc)) window.addCleanup(() => document.removeEventListener("keydown", esc))
} }
} }
@ -69,20 +68,6 @@ export function clearAllHighlights() {
element.style.transition = originalTransition element.style.transition = originalTransition
}) })
activeHighlights.clear() activeHighlights.clear()
// Also clear any highlights that might not be tracked (backup cleanup)
// This catches highlights in popovers or other edge cases
const allHighlightedElements = document.querySelectorAll('[style*="background-color"]')
allHighlightedElements.forEach((el) => {
const element = el as HTMLElement
if (
element.style.backgroundColor.includes("var(--highlight") ||
element.style.backgroundColor.includes("#ffeb3b")
) {
element.style.backgroundColor = ""
element.style.transition = ""
}
})
} }
/** /**
@ -97,12 +82,11 @@ export function highlightElement(
color: string = "var(--highlight, #ffeb3b40)", color: string = "var(--highlight, #ffeb3b40)",
) { ) {
// Clear any existing highlight on this element // Clear any existing highlight on this element
activeHighlights.forEach((highlight) => { const existingHighlight = Array.from(activeHighlights).find(h => h.element === el)
if (highlight.element === el) { if (existingHighlight) {
clearTimeout(highlight.timeoutId) clearTimeout(existingHighlight.timeoutId)
activeHighlights.delete(highlight) activeHighlights.delete(existingHighlight)
} }
})
// Store original styles // Store original styles
const originalBackground = el.style.backgroundColor const originalBackground = el.style.backgroundColor
@ -113,27 +97,21 @@ export function highlightElement(
el.style.backgroundColor = color el.style.backgroundColor = color
// Set up cleanup // Set up cleanup
const timeoutId = window.setTimeout(() => { const highlight = {
el.style.backgroundColor = originalBackground
// Remove transition after background fades back
setTimeout(() => {
el.style.transition = originalTransition
// Remove from active highlights
activeHighlights.forEach((highlight) => {
if (highlight.element === el) {
activeHighlights.delete(highlight)
}
})
}, 300)
}, duration)
// Track this highlight
activeHighlights.add({
element: el, element: el,
originalBackground, originalBackground,
originalTransition, originalTransition,
timeoutId, timeoutId: 0,
}) }
highlight.timeoutId = window.setTimeout(() => {
el.style.backgroundColor = originalBackground
el.style.transition = originalTransition
activeHighlights.delete(highlight)
}, duration)
// Track this highlight
activeHighlights.add(highlight)
} }
/** /**
@ -183,8 +161,7 @@ export function scrollInContainerToElement(
highlight: boolean = true, highlight: boolean = true,
behavior: ScrollBehavior = "instant", behavior: ScrollBehavior = "instant",
) { ) {
// Use requestAnimationFrame to ensure content is rendered before scrolling // Scroll immediately, since content should already be rendered in a static site
requestAnimationFrame(() => {
const targetPosition = target.offsetTop - buffer const targetPosition = target.offsetTop - buffer
container.scroll({ container.scroll({
top: Math.max(0, targetPosition), top: Math.max(0, targetPosition),
@ -193,10 +170,6 @@ export function scrollInContainerToElement(
// Add highlight effect if requested // Add highlight effect if requested
if (highlight) { if (highlight) {
// Small delay to ensure scroll completes before highlighting
setTimeout(() => {
highlightElement(target) highlightElement(target)
}, 50)
} }
})
} }