@anaralabs/lector 3.12.0 → 3.12.2

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 +8 -5
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1623,6 +1623,7 @@ CanvasLayer.displayName = "CanvasLayer";
1623
1623
 
1624
1624
  // src/hooks/useSelectionDimensions.tsx
1625
1625
  var MERGE_THRESHOLD = 2;
1626
+ var LAYER_ATTRIBUTION_TOLERANCE_PX = 4;
1626
1627
  var getTextNodeClientRects = (range) => {
1627
1628
  const root = range.commonAncestorContainer;
1628
1629
  const ownerDoc = root.ownerDocument ?? document;
@@ -1684,8 +1685,9 @@ var mapSelectionRectsToLayers = (range) => {
1684
1685
  const layerForRect = (rect) => {
1685
1686
  const cx = rect.left + rect.width / 2;
1686
1687
  const cy = rect.top + rect.height / 2;
1688
+ const T = LAYER_ATTRIBUTION_TOLERANCE_PX;
1687
1689
  const geomMatch = textLayerEntries.find(
1688
- ({ rect: lr }) => cx >= lr.left - 1 && cx <= lr.right + 1 && cy >= lr.top - 1 && cy <= lr.bottom + 1
1690
+ ({ rect: lr }) => cx >= lr.left - T && cx <= lr.right + T && cy >= lr.top - T && cy <= lr.bottom + T
1689
1691
  );
1690
1692
  if (geomMatch) return geomMatch.el;
1691
1693
  const points = [
@@ -1707,8 +1709,6 @@ var mapSelectionRectsToLayers = (range) => {
1707
1709
  const layer = layerForRect(clientRect);
1708
1710
  if (!layer) continue;
1709
1711
  const layerRect = layer.getBoundingClientRect();
1710
- const fitsInLayer = clientRect.top >= layerRect.top - 1 && clientRect.bottom <= layerRect.bottom + 1 && clientRect.left >= layerRect.left - 1 && clientRect.right <= layerRect.right + 1;
1711
- if (!fitsInLayer) continue;
1712
1712
  const pageNumber = parseInt(
1713
1713
  layer.getAttribute("data-page-number") || "1",
1714
1714
  10
@@ -5099,13 +5099,16 @@ var useViewportContainer = ({
5099
5099
  const elementRect = currentElement.getBoundingClientRect();
5100
5100
  const containerRect = currentContainer.getBoundingClientRect();
5101
5101
  const currentZoom = transformations.current.zoom;
5102
+ const containerStyle = getComputedStyle(currentContainer);
5103
+ const paddingTop = parseFloat(containerStyle.paddingTop) || 0;
5104
+ const paddingLeft = parseFloat(containerStyle.paddingLeft) || 0;
5102
5105
  const contentPosition = [
5103
5106
  origin[0] - elementRect.left,
5104
5107
  origin[1] - elementRect.top
5105
5108
  ];
5106
5109
  const containerPosition = [
5107
- origin[0] - containerRect.left,
5108
- origin[1] - containerRect.top
5110
+ origin[0] - containerRect.left - paddingLeft,
5111
+ origin[1] - containerRect.top - paddingTop
5109
5112
  ];
5110
5113
  originRef.current = [
5111
5114
  contentPosition[0] / currentZoom,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anaralabs/lector",
3
- "version": "3.12.0",
3
+ "version": "3.12.2",
4
4
  "description": "A headless PDF viewer for React",
5
5
  "author": "andrewdr (https://github.com/andrewdoro)",
6
6
  "license": "MIT",