@anaralabs/lector 3.5.11 → 3.5.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -97,7 +97,7 @@ declare interface AnnotationState {
97
97
  setAnnotations: (annotations: Annotation[]) => void;
98
98
  }
99
99
 
100
- export declare const AnnotationTooltip: ({ annotation, children, renderTooltipContent, hoverTooltipContent, onOpenChange, className, hoverClassName, isOpen: controlledIsOpen, hoverIsOpen: controlledHoverIsOpen, }: AnnotationTooltipProps) => JSX.Element;
100
+ export declare const AnnotationTooltip: ({ annotation, children, renderTooltipContent, hoverTooltipContent, onOpenChange, className, focusedOpenId, hoverClassName, isOpen: controlledIsOpen, hoverIsOpen: controlledHoverIsOpen, }: AnnotationTooltipProps) => JSX.Element;
101
101
 
102
102
  export declare type AnnotationTooltipContentProps = {
103
103
  annotation: Annotation;
@@ -112,6 +112,7 @@ declare interface AnnotationTooltipProps {
112
112
  hoverTooltipContent?: React.ReactNode;
113
113
  onOpenChange?: (open: boolean) => void;
114
114
  isOpen?: boolean;
115
+ focusedOpenId?: string;
115
116
  className?: string;
116
117
  hoverClassName?: string;
117
118
  hoverIsOpen?: boolean;
package/dist/index.js CHANGED
@@ -274,6 +274,7 @@ var AnnotationTooltip = ({
274
274
  hoverTooltipContent,
275
275
  onOpenChange,
276
276
  className,
277
+ focusedOpenId,
277
278
  hoverClassName,
278
279
  isOpen: controlledIsOpen,
279
280
  hoverIsOpen: controlledHoverIsOpen
@@ -315,6 +316,7 @@ var AnnotationTooltip = ({
315
316
  }
316
317
  }, [controlledIsOpen, isOpen, setIsOpen]);
317
318
  const handleMouseEnter = useCallback(() => {
319
+ if (focusedOpenId && focusedOpenId !== annotation.id) return;
318
320
  if (hoverTooltipContent) {
319
321
  if (closeTimeoutRef.current) {
320
322
  clearTimeout(closeTimeoutRef.current);
@@ -502,6 +504,7 @@ var AnnotationHighlightLayer = ({
502
504
  annotation,
503
505
  className: tooltipClassName,
504
506
  hoverClassName: hoverTooltipClassName,
507
+ focusedOpenId: focusedAnnotationId,
505
508
  isOpen: focusedAnnotationId === annotation.id,
506
509
  hoverIsOpen: focusedHoverAnnotationId === annotation.id,
507
510
  onOpenChange: (open) => {
@@ -1136,8 +1139,10 @@ var consolidateHighlightRects = (rects) => {
1136
1139
  return Math.abs(topDiff) < 2 ? a.left - b.left : topDiff;
1137
1140
  });
1138
1141
  let current = sorted[0];
1142
+ if (!current) return rects;
1139
1143
  for (let i = 1; i < sorted.length; i++) {
1140
1144
  const next = sorted[i];
1145
+ if (!next) continue;
1141
1146
  const samePageAndLine = current.pageNumber === next.pageNumber && Math.abs(current.top - next.top) < Math.max(current.height, next.height) * 0.5;
1142
1147
  const horizontallyConnected = samePageAndLine && // Adjacent (touching or very close)
1143
1148
  (Math.abs(current.left + current.width - next.left) <= MERGE_THRESHOLD || Math.abs(next.left + next.width - current.left) <= MERGE_THRESHOLD || // Overlapping
@@ -1160,7 +1165,9 @@ var consolidateHighlightRects = (rects) => {
1160
1165
  current = next;
1161
1166
  }
1162
1167
  }
1163
- consolidated.push(current);
1168
+ if (current) {
1169
+ consolidated.push(current);
1170
+ }
1164
1171
  return consolidated;
1165
1172
  };
1166
1173
  var consolidateRects = (rects) => {
@@ -1336,13 +1343,14 @@ var useSelectionDimensions = () => {
1336
1343
  });
1337
1344
  textLayerMapHighlight.forEach((rects) => {
1338
1345
  if (rects.length > 0) {
1339
- const consolidated = consolidateHighlightRects(rects);
1340
- highlightRects.push(...consolidated);
1346
+ if (rects.length === 1) {
1347
+ highlightRects.push(...rects);
1348
+ } else {
1349
+ const consolidated = consolidateHighlightRects(rects);
1350
+ highlightRects.push(...consolidated);
1351
+ }
1341
1352
  }
1342
1353
  });
1343
- const finalHighlights = consolidateHighlightRects(highlightRects);
1344
- highlightRects.length = 0;
1345
- highlightRects.push(...finalHighlights);
1346
1354
  textLayerMapUnderline.forEach((rects) => {
1347
1355
  if (rects.length > 0) {
1348
1356
  const lineGroups = groupRectsByLine(rects);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anaralabs/lector",
3
- "version": "3.5.11",
3
+ "version": "3.5.13",
4
4
  "description": "Headless PDF viewer for React",
5
5
  "author": "andrewdr (https://github.com/andrewdoro)",
6
6
  "license": "MIT",