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 8ad4fae
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 13 deletions.
2 changes: 1 addition & 1 deletion packages/text-annotator/src/state/TextAnnotationStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export interface TextAnnotationStore<T extends TextAnnotation = TextAnnotation>

getAnnotationRects(id: string): DOMRect[];

getAnnotationBounds(id: string, hintX?: number, hintY?: number, buffer?: number): DOMRect | undefined;
getAnnotationBounds(id: string): DOMRect | undefined;

getAnnotationRects(id: string): DOMRect[];

Expand Down
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 8ad4fae

Please sign in to comment.