teamsync-pdf-viewer 1.5.1 → 1.6.0

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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,18 @@
2
2
 
3
3
  All notable changes to `teamsync-pdf-viewer` are documented here.
4
4
 
5
+ ## [1.6.0] — 2026-09-06
6
+
7
+ ### Added
8
+ - **Whitespace-Tolerant Text Search**: Search queries now match across line breaks, multiple whitespace runs, tabs, NBSP (`\u00A0`), and other unicode whitespace variants seamlessly. Matches in normalized space while accurately reporting raw source coordinates and bounds.
9
+ - **Shared `pageText` Builder & Bounding Box Interpolator**: Unified raw text extraction and character coordinate mapping between PDF search and regex redactions via internal `buildPageText` and `boundsForRawRange` helpers.
10
+ - **Page-Scoped Search & Highlighting**:
11
+ - Added additive 5th parameter `pages?: number[]` to `searchPdfText(doc, query, redactions, onProgress, pages)`.
12
+ - Added `options.pages?: number[]` to `instance.searchText(query, options)`.
13
+ - Added `scope?: 'document' | 'page'` to `instance.highlightSnippet(query, options)` allowing strict page restriction when navigating to snippet citations.
14
+ - **Sidebar Highlighting Precision**: Result `matchLength` now reflects the exact consumed raw glyph span, ensuring sidebar bold highlights match rendered page text identically.
15
+ - **Stable Search Results Sorting**: Corrected search result sorting to maintain page index ascending order while preserving intra-page ascending match order.
16
+
5
17
  ## [1.5.1] — 2026-09-06
6
18
 
7
19
  ### Added
@@ -70,8 +70,14 @@ export declare class WebViewerInstance {
70
70
  setCurrentPage(pageNumber: number): void;
71
71
  /**
72
72
  * Search the document for text matches, returning snippets and page bounding boxes.
73
+ *
74
+ * @param query - Search term.
75
+ * @param options - Search options:
76
+ * - `pages`: Specific 1-based page numbers to search. Defaults to all pages.
73
77
  */
74
- searchText(query: string): Promise<SearchResult[]>;
78
+ searchText(query: string, options?: {
79
+ pages?: number[];
80
+ }): Promise<SearchResult[]>;
75
81
  /** Get the current list of transient highlights. */
76
82
  getTransientHighlights(): TransientHighlight[];
77
83
  /**
@@ -87,9 +93,21 @@ export declare class WebViewerInstance {
87
93
  /**
88
94
  * Search for a snippet or citation query, scroll to its page, and highlight it temporarily.
89
95
  * Returns the matched SearchResult or null if not found.
96
+ *
97
+ * @param query - The text snippet to locate and highlight.
98
+ * @param options - Navigation and display options:
99
+ * - `pageIndex`: Preferred page (1-based). When `scope: 'page'`, restricts search to this page.
100
+ * - `scope`: Search scope. `'document'` (default) searches all pages, keeping `pageIndex` as a preference.
101
+ * `'page'` restricts the search strictly to `pageIndex` (avoids full-document walk).
102
+ * If `scope: 'page'` is provided without `pageIndex`, it gracefully degrades to `'document'`.
103
+ * - `pulse`: Animate focus ring (default true).
104
+ * - `scrollTo`: Scroll page into view (default true).
105
+ * - `color`: Background highlight color.
106
+ * - `tooltip`: Tooltip text above the highlight (defaults to matched snippet).
90
107
  */
91
108
  highlightSnippet(query: string, options?: {
92
109
  pageIndex?: number;
110
+ scope?: 'document' | 'page';
93
111
  pulse?: boolean;
94
112
  scrollTo?: boolean;
95
113
  color?: string;
@@ -10,10 +10,10 @@ export interface SearchResult {
10
10
  bounds: SearchBounds[];
11
11
  }
12
12
  /**
13
- * Standalone asynchronous text search across all pages of a PDFDocumentProxy.
13
+ * Standalone asynchronous text search across all pages (or specified pages) of a PDFDocumentProxy.
14
14
  * Sanitizes redacted regions and returns matching snippets and bounding boxes.
15
15
  */
16
- export declare function searchPdfText(pdfDoc: pdfjsLib.PDFDocumentProxy, query: string, redactions?: Redaction[], onProgress?: (progress: number) => void): Promise<SearchResult[]>;
16
+ export declare function searchPdfText(pdfDoc: pdfjsLib.PDFDocumentProxy, query: string, redactions?: Redaction[], onProgress?: (progress: number) => void, pages?: number[]): Promise<SearchResult[]>;
17
17
  export declare function usePdfSearch(pdfDoc: pdfjsLib.PDFDocumentProxy | null, redactions?: Redaction[]): {
18
18
  search: (query: string) => Promise<void>;
19
19
  searchResults: SearchResult[];
@@ -0,0 +1,23 @@
1
+ import { SearchBounds } from '../core/types';
2
+ export interface PageText {
3
+ fullText: string;
4
+ itemIndices: number[];
5
+ charIndices: number[];
6
+ normText: string;
7
+ normToRaw: number[];
8
+ }
9
+ /**
10
+ * Collapses any consecutive whitespace runs to a single space and trims edges.
11
+ */
12
+ export declare function collapseWhitespace(s: string): string;
13
+ /**
14
+ * Builds raw page text with item/char index source-mapping, followed by a second pass
15
+ * creating normalized text (collapsing any maximal whitespace run to a single space)
16
+ * and a 1-to-1 index map back to raw string indices.
17
+ */
18
+ export declare function buildPageText(items: any[]): PageText;
19
+ /**
20
+ * Computes bounding boxes in PDF coordinate points for a matched range [rawStart, rawEndExcl) in fullText.
21
+ * Separator sentinels (-1) are skipped, and character positions are interpolated across each TextItem.
22
+ */
23
+ export declare function boundsForRawRange(items: any[], pageText: Pick<PageText, 'itemIndices' | 'charIndices'>, rawStart: number, rawEndExcl: number): SearchBounds[];