{
const target = (e.target as HTMLElement).closest("[data-highlight-id]");
if (target instanceof HTMLElement && target.dataset.highlightId) {
onHighlightClicked?.(target.dataset.highlightId);
}
}}
dangerouslySetInnerHTML={{ __html: renderedHtml }}
/>
);
}
export async function resolveHtmlSelectors(
selectors: readonly Selector[],
representation: DocumentRepresentation,
): Promise
{
return resolveSelectors(selectors, representation);
}
export async function scrollToHtmlTarget(
root: HTMLElement,
target: ResolvedAnchorTarget,
representation: DocumentRepresentation,
): Promise {
const span = target.textPosition;
if (!span || !representation.canonicalText) return;
const quote = representation.canonicalText.slice(span.start, span.end);
const walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT);
let node: Node | null;
while ((node = walker.nextNode())) {
const text = node.textContent ?? "";
const idx = text.indexOf(quote);
if (idx === -1) continue;
const range = document.createRange();
range.setStart(node, idx);
range.setEnd(node, idx + quote.length);
const rect = range.getBoundingClientRect();
if (rect.height > 0) {
range.startContainer.parentElement?.scrollIntoView({ block: "center", behavior: "smooth" });
return;
}
}
}
export async function renderHtmlHighlight(
target: ResolvedAnchorTarget,
opts?: HighlightRenderOptions,
): Promise {
void target;
void opts;
// Highlights are rendered inline during `HtmlViewerAdapter` render via stored annotations.
}