@embedpdf/plugin-selection 2.6.1 → 2.6.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.
@@ -17,6 +17,24 @@ export interface SelectionPluginConfig extends BasePluginConfig {
17
17
  * Configuration for marquee selection behavior.
18
18
  */
19
19
  marquee?: MarqueeSelectionConfig;
20
+ /**
21
+ * Tolerance factor for hit-testing glyphs. Multiplied by average glyph
22
+ * height to derive the tolerance radius. Set to 0 to require exact hits.
23
+ * @default 1.5
24
+ */
25
+ toleranceFactor?: number;
26
+ /**
27
+ * Minimum drag distance (in page-coordinate units) the pointer must move
28
+ * before a drag-selection starts. Prevents accidental selection on simple clicks.
29
+ * @default 3
30
+ */
31
+ minSelectionDragDistance?: number;
32
+ /**
33
+ * Maximum number of pages whose geometry data is kept in memory per document.
34
+ * Oldest unused pages are evicted when this limit is exceeded.
35
+ * @default 50
36
+ */
37
+ maxCachedGeometries?: number;
20
38
  }
21
39
  export interface SelectionMenuPlacement {
22
40
  pageIndex: number;
@@ -1,12 +1,21 @@
1
1
  import { PdfPageGeometry, Position, Rect } from '@embedpdf/models';
2
2
  import { SelectionRangeX } from './types';
3
3
  /**
4
- * Hit-test helper using runs
4
+ * Hit-test helper using runs, with tolerance-based fallback.
5
+ *
6
+ * Adapted from PDFium's FPDFText_GetCharIndexAtPos / CPDF_TextPage::GetIndexAtPos:
7
+ * 1. Exact match: return the glyph whose bounding box contains the point.
8
+ * 2. Tolerance expansion: expand each glyph box by tolerance/2 on every side,
9
+ * then pick the closest glyph by Manhattan distance.
10
+ *
5
11
  * @param geo - page geometry
6
- * @param pt - point
7
- * @returns glyph index
12
+ * @param pt - point in page coordinates
13
+ * @param toleranceFactor - multiplied by average glyph height to derive the
14
+ * tolerance radius. 0 disables the fallback.
15
+ * Default 1.5 (see Chromium's pdfium-page.cc kTolerance).
16
+ * @returns glyph index, or -1 if nothing was hit
8
17
  */
9
- export declare function glyphAt(geo: PdfPageGeometry, pt: Position): number;
18
+ export declare function glyphAt(geo: PdfPageGeometry, pt: Position, toleranceFactor?: number): number;
10
19
  /**
11
20
  * Helper: min/max glyph indices on `page` for current sel
12
21
  * @param sel - selection range
@@ -44,11 +53,12 @@ export declare function rectsWithinSlice(geo: PdfPageGeometry, from: number, to:
44
53
  * Adapted for TypeScript and this project's Rect/geometry types.
45
54
  */
46
55
  /**
47
- * Text run info for rect merging (similar to Chromium's ScreenRectTextRunInfo)
56
+ * Text run info for rect merging (similar to Chromium's PdfRectTextRunInfo)
48
57
  */
49
58
  export interface TextRunInfo {
50
59
  rect: Rect;
51
60
  charCount: number;
61
+ fontSize?: number;
52
62
  }
53
63
  /**
54
64
  * Helper functions for Rect operations
@@ -65,6 +75,34 @@ export declare function getVerticalOverlap(rect1: Rect, rect2: Rect): number;
65
75
  */
66
76
  export declare function shouldMergeHorizontalRects(textRun1: TextRunInfo, textRun2: TextRunInfo): boolean;
67
77
  /**
68
- * Merge adjacent rectangles based on proximity and overlap (similar to Chromium's algorithm)
78
+ * Merge adjacent rectangles based on proximity and overlap.
79
+ *
80
+ * Adapted from Chromium's MergeAdjacentRects (pdfium_range.cc):
81
+ * - The merge DECISION uses the loose `rect` (via shouldMergeHorizontalRects).
82
+ * - The OUTPUT rect always uses loose bounds.
69
83
  */
70
84
  export declare function mergeAdjacentRects(textRuns: TextRunInfo[]): Rect[];
85
+ /**
86
+ * Expand a character index to the word surrounding it.
87
+ *
88
+ * Walks backward and forward from `charIndex` within the page geometry
89
+ * until a word-boundary glyph (space or empty) is encountered.
90
+ *
91
+ * @returns `{ from, to }` inclusive indices, or null if charIndex is invalid.
92
+ */
93
+ export declare function expandToWordBoundary(geo: PdfPageGeometry, charIndex: number): {
94
+ from: number;
95
+ to: number;
96
+ } | null;
97
+ /**
98
+ * Expand a character index to the full visual line (row) it belongs to.
99
+ *
100
+ * Finds all runs whose vertical extent overlaps with the run containing `charIndex`,
101
+ * then returns the first-to-last character span across those runs.
102
+ *
103
+ * @returns `{ from, to }` inclusive indices, or null if charIndex is invalid.
104
+ */
105
+ export declare function expandToLineBoundary(geo: PdfPageGeometry, charIndex: number): {
106
+ from: number;
107
+ to: number;
108
+ } | null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@embedpdf/plugin-selection",
3
- "version": "2.6.1",
3
+ "version": "2.6.2",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "main": "./dist/index.cjs",
@@ -34,17 +34,17 @@
34
34
  }
35
35
  },
36
36
  "dependencies": {
37
- "@embedpdf/models": "2.6.1",
38
- "@embedpdf/utils": "2.6.1"
37
+ "@embedpdf/models": "2.6.2",
38
+ "@embedpdf/utils": "2.6.2"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@types/react": "^18.2.0",
42
42
  "typescript": "^5.0.0",
43
43
  "@embedpdf/build": "1.1.0",
44
- "@embedpdf/plugin-viewport": "2.6.1",
45
- "@embedpdf/core": "2.6.1",
46
- "@embedpdf/plugin-scroll": "2.6.1",
47
- "@embedpdf/plugin-interaction-manager": "2.6.1"
44
+ "@embedpdf/core": "2.6.2",
45
+ "@embedpdf/plugin-viewport": "2.6.2",
46
+ "@embedpdf/plugin-interaction-manager": "2.6.2",
47
+ "@embedpdf/plugin-scroll": "2.6.2"
48
48
  },
49
49
  "peerDependencies": {
50
50
  "react": ">=16.8.0",
@@ -52,8 +52,8 @@
52
52
  "preact": "^10.26.4",
53
53
  "vue": ">=3.2.0",
54
54
  "svelte": ">=5 <6",
55
- "@embedpdf/core": "2.6.1",
56
- "@embedpdf/plugin-interaction-manager": "2.6.1"
55
+ "@embedpdf/core": "2.6.2",
56
+ "@embedpdf/plugin-interaction-manager": "2.6.2"
57
57
  },
58
58
  "files": [
59
59
  "dist",