|
|
export function scrollToAnchor(doc: Document, anchor: string): void { |
|
|
if (doc) { |
|
|
const selectors = [ |
|
|
`a[name="${anchor}"]`, |
|
|
`a[id="${anchor}"]`, |
|
|
`[id="${anchor}"]`, |
|
|
]; |
|
|
|
|
|
let targetElement: HTMLElement | null = null; |
|
|
|
|
|
for (const selector of selectors) { |
|
|
targetElement = doc.querySelector(selector); |
|
|
if (targetElement) { |
|
|
targetElement.scrollIntoView({ |
|
|
behavior: 'smooth', |
|
|
block: 'center' |
|
|
}); |
|
|
break; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export function dimScreen(iframe: HTMLIFrameElement): void { |
|
|
const curtain = document.createElement("div"); |
|
|
Object.assign(curtain.style, { |
|
|
position: 'fixed', |
|
|
left: '0', |
|
|
top: '0', |
|
|
width: '100%', |
|
|
height: '100%', |
|
|
background: 'black', |
|
|
opacity: '0.2', |
|
|
zIndex: '999' |
|
|
}); |
|
|
curtain.id = "__mdx_overlay_id"; |
|
|
iframe.contentDocument?.body.appendChild(curtain); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function undimScreen(iframe: HTMLIFrameElement): void { |
|
|
const element = iframe.contentDocument?.getElementById("__mdx_overlay_id"); |
|
|
if (element && element.parentNode) |
|
|
element.parentNode.removeChild(element); |
|
|
} |