@huridocs/react-text-selection-handler
Version:
React pdf handler allows to render a PDF and handle text selection and highlights.
7 lines (6 loc) • 368 B
text/typescript
export const elementContainsDomRect = (rect: DOMRect) => (region: Element) => {
const regionRect = region.getBoundingClientRect();
const horizontalMatch = regionRect.x <= rect.x && rect.x <= regionRect.x + regionRect.width;
const verticalMatch = regionRect.y <= rect.y && rect.y <= regionRect.y + regionRect.height;
return horizontalMatch && verticalMatch;
};