@anaralabs/lector 3.5.10 → 3.5.11

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.
Files changed (2) hide show
  1. package/dist/index.js +32 -28
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -548,9 +548,8 @@ var AnnotationHighlightLayer = ({
548
548
  top: rect.top,
549
549
  left: rect.left,
550
550
  width: rect.width,
551
- height: rect.height,
552
- backgroundColor: annotation.borderColor,
553
- borderBottom: "1.5px"
551
+ height: 1.1,
552
+ backgroundColor: annotation.borderColor
554
553
  },
555
554
  "data-comment-id": annotation.id
556
555
  },
@@ -1129,36 +1128,40 @@ var shouldMergeRects = (rect1, rect2) => {
1129
1128
  };
1130
1129
  var consolidateHighlightRects = (rects) => {
1131
1130
  if (rects.length <= 1) return rects;
1131
+ const consolidated = [];
1132
1132
  const sorted = [...rects].sort((a, b) => {
1133
+ const pageCompare = a.pageNumber - b.pageNumber;
1134
+ if (pageCompare !== 0) return pageCompare;
1133
1135
  const topDiff = a.top - b.top;
1134
1136
  return Math.abs(topDiff) < 2 ? a.left - b.left : topDiff;
1135
1137
  });
1136
- const result = [];
1137
- let currentGroup = [sorted[0]];
1138
+ let current = sorted[0];
1138
1139
  for (let i = 1; i < sorted.length; i++) {
1139
- const currentRect = sorted[i];
1140
- const lastInGroup = currentGroup[currentGroup.length - 1];
1141
- const sameLineThreshold = Math.max(lastInGroup.height, currentRect.height) * 0.5;
1142
- const onSameLine = Math.abs(lastInGroup.top - currentRect.top) < sameLineThreshold;
1143
- const adjacent = Math.abs(lastInGroup.left + lastInGroup.width - currentRect.left) <= MERGE_THRESHOLD;
1144
- const overlapping = lastInGroup.left < currentRect.left + currentRect.width && currentRect.left < lastInGroup.left + lastInGroup.width;
1145
- if (onSameLine && (adjacent || overlapping)) {
1146
- currentGroup.push(currentRect);
1140
+ const next = sorted[i];
1141
+ const samePageAndLine = current.pageNumber === next.pageNumber && Math.abs(current.top - next.top) < Math.max(current.height, next.height) * 0.5;
1142
+ const horizontallyConnected = samePageAndLine && // Adjacent (touching or very close)
1143
+ (Math.abs(current.left + current.width - next.left) <= MERGE_THRESHOLD || Math.abs(next.left + next.width - current.left) <= MERGE_THRESHOLD || // Overlapping
1144
+ current.left < next.left + next.width && next.left < current.left + current.width || // Very close (small gap)
1145
+ Math.abs(current.left + current.width - next.left) <= current.height * 0.2);
1146
+ if (horizontallyConnected) {
1147
+ const newLeft = Math.min(current.left, next.left);
1148
+ const newRight = Math.max(current.left + current.width, next.left + next.width);
1149
+ const newTop = Math.min(current.top, next.top);
1150
+ const newBottom = Math.max(current.top + current.height, next.top + next.height);
1151
+ current = {
1152
+ left: newLeft,
1153
+ top: newTop,
1154
+ width: newRight - newLeft,
1155
+ height: newBottom - newTop,
1156
+ pageNumber: current.pageNumber
1157
+ };
1147
1158
  } else {
1148
- if (currentGroup.length === 1) {
1149
- result.push(currentGroup[0]);
1150
- } else {
1151
- result.push(mergeRectGroup(currentGroup));
1152
- }
1153
- currentGroup = [currentRect];
1159
+ consolidated.push(current);
1160
+ current = next;
1154
1161
  }
1155
1162
  }
1156
- if (currentGroup.length === 1) {
1157
- result.push(currentGroup[0]);
1158
- } else {
1159
- result.push(mergeRectGroup(currentGroup));
1160
- }
1161
- return result;
1163
+ consolidated.push(current);
1164
+ return consolidated;
1162
1165
  };
1163
1166
  var consolidateRects = (rects) => {
1164
1167
  if (rects.length <= 1) return rects;
@@ -1337,6 +1340,9 @@ var useSelectionDimensions = () => {
1337
1340
  highlightRects.push(...consolidated);
1338
1341
  }
1339
1342
  });
1343
+ const finalHighlights = consolidateHighlightRects(highlightRects);
1344
+ highlightRects.length = 0;
1345
+ highlightRects.push(...finalHighlights);
1340
1346
  textLayerMapUnderline.forEach((rects) => {
1341
1347
  if (rects.length > 0) {
1342
1348
  const lineGroups = groupRectsByLine(rects);
@@ -1368,11 +1374,9 @@ var useSelectionDimensions = () => {
1368
1374
  i++;
1369
1375
  continue;
1370
1376
  }
1371
- const zoom = store.getState().zoom;
1372
1377
  const lineRect = {
1373
1378
  width: endRect.left + endRect.width - startRect.left,
1374
- height: 2 / zoom,
1375
- // Fixed 2px thickness
1379
+ height: 1.5,
1376
1380
  top: startRect.top,
1377
1381
  left: startRect.left,
1378
1382
  pageNumber: startRect.pageNumber
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anaralabs/lector",
3
- "version": "3.5.10",
3
+ "version": "3.5.11",
4
4
  "description": "Headless PDF viewer for React",
5
5
  "author": "andrewdr (https://github.com/andrewdoro)",
6
6
  "license": "MIT",