Skip to content

Commit

Permalink
Simplified getAnnotationBounds
Browse files Browse the repository at this point in the history
  • Loading branch information
oleksandr-danylchenko committed Nov 21, 2024
1 parent 97ddea3 commit f8c2313
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions packages/text-annotator/src/state/TextAnnotatorState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,19 +114,9 @@ export const createTextAnnotatorState = <I extends TextAnnotation = TextAnnotati
return all ? filtered : filtered[0];
}

const getAnnotationBounds = (id: string, x?: number, y?: number, buffer = 5): DOMRect | undefined => {
const getAnnotationBounds = (id: string): DOMRect | undefined => {
const rects = tree.getAnnotationRects(id);
if (rects.length === 0) return;

if (x && y) {
const match = rects.find(({ top, right, bottom, left }) =>
x >= left - buffer && x <= right + buffer && y >= top - buffer && y <= bottom + buffer);

// Preferred bounds: the rectangle
if (match) return match;
}

return tree.getAnnotationBounds(id);
return rects.length > 0 ? tree.getAnnotationBounds(id) : undefined;
}

const getIntersecting = (
Expand Down

0 comments on commit f8c2313

Please sign in to comment.