pdf-oxide-fips 0.3.47

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 (127) hide show
  1. package/LICENSE-APACHE +176 -0
  2. package/LICENSE-MIT +25 -0
  3. package/README.md +218 -0
  4. package/lib/builders/annotation-builder.d.ts +198 -0
  5. package/lib/builders/annotation-builder.js +317 -0
  6. package/lib/builders/conversion-options-builder.d.ts +106 -0
  7. package/lib/builders/conversion-options-builder.js +214 -0
  8. package/lib/builders/document-builder.d.ts +381 -0
  9. package/lib/builders/document-builder.js +770 -0
  10. package/lib/builders/index.d.ts +13 -0
  11. package/lib/builders/index.js +13 -0
  12. package/lib/builders/metadata-builder.d.ts +201 -0
  13. package/lib/builders/metadata-builder.js +285 -0
  14. package/lib/builders/pdf-builder.d.ts +216 -0
  15. package/lib/builders/pdf-builder.js +350 -0
  16. package/lib/builders/search-options-builder.d.ts +73 -0
  17. package/lib/builders/search-options-builder.js +129 -0
  18. package/lib/builders/streaming-table.d.ts +64 -0
  19. package/lib/builders/streaming-table.js +140 -0
  20. package/lib/document-editor-manager.d.ts +139 -0
  21. package/lib/document-editor-manager.js +256 -0
  22. package/lib/document-editor.d.ts +124 -0
  23. package/lib/document-editor.js +318 -0
  24. package/lib/errors.d.ts +382 -0
  25. package/lib/errors.js +1115 -0
  26. package/lib/form-field-manager.d.ts +299 -0
  27. package/lib/form-field-manager.js +568 -0
  28. package/lib/hybrid-ml-manager.d.ts +142 -0
  29. package/lib/hybrid-ml-manager.js +208 -0
  30. package/lib/index.d.ts +205 -0
  31. package/lib/index.js +693 -0
  32. package/lib/managers/accessibility-manager.d.ts +148 -0
  33. package/lib/managers/accessibility-manager.js +234 -0
  34. package/lib/managers/annotation-manager.d.ts +219 -0
  35. package/lib/managers/annotation-manager.js +359 -0
  36. package/lib/managers/barcode-manager.d.ts +82 -0
  37. package/lib/managers/barcode-manager.js +263 -0
  38. package/lib/managers/batch-manager.d.ts +185 -0
  39. package/lib/managers/batch-manager.js +385 -0
  40. package/lib/managers/cache-manager.d.ts +181 -0
  41. package/lib/managers/cache-manager.js +384 -0
  42. package/lib/managers/compliance-manager.d.ts +103 -0
  43. package/lib/managers/compliance-manager.js +453 -0
  44. package/lib/managers/content-manager.d.ts +120 -0
  45. package/lib/managers/content-manager.js +294 -0
  46. package/lib/managers/document-utility-manager.d.ts +369 -0
  47. package/lib/managers/document-utility-manager.js +730 -0
  48. package/lib/managers/dom-pdf-creator.d.ts +104 -0
  49. package/lib/managers/dom-pdf-creator.js +299 -0
  50. package/lib/managers/editing-manager.d.ts +248 -0
  51. package/lib/managers/editing-manager.js +387 -0
  52. package/lib/managers/enterprise-manager.d.ts +192 -0
  53. package/lib/managers/enterprise-manager.js +307 -0
  54. package/lib/managers/extended-managers.d.ts +122 -0
  55. package/lib/managers/extended-managers.js +664 -0
  56. package/lib/managers/extraction-manager.d.ts +246 -0
  57. package/lib/managers/extraction-manager.js +482 -0
  58. package/lib/managers/final-utilities.d.ts +127 -0
  59. package/lib/managers/final-utilities.js +657 -0
  60. package/lib/managers/hybrid-ml-advanced.d.ts +136 -0
  61. package/lib/managers/hybrid-ml-advanced.js +722 -0
  62. package/lib/managers/index.d.ts +64 -0
  63. package/lib/managers/index.js +69 -0
  64. package/lib/managers/layer-manager.d.ts +203 -0
  65. package/lib/managers/layer-manager.js +401 -0
  66. package/lib/managers/metadata-manager.d.ts +148 -0
  67. package/lib/managers/metadata-manager.js +280 -0
  68. package/lib/managers/ocr-manager.d.ts +194 -0
  69. package/lib/managers/ocr-manager.js +582 -0
  70. package/lib/managers/optimization-manager.d.ts +102 -0
  71. package/lib/managers/optimization-manager.js +213 -0
  72. package/lib/managers/outline-manager.d.ts +101 -0
  73. package/lib/managers/outline-manager.js +169 -0
  74. package/lib/managers/page-manager.d.ts +142 -0
  75. package/lib/managers/page-manager.js +235 -0
  76. package/lib/managers/pattern-detection.d.ts +169 -0
  77. package/lib/managers/pattern-detection.js +322 -0
  78. package/lib/managers/rendering-manager.d.ts +353 -0
  79. package/lib/managers/rendering-manager.js +679 -0
  80. package/lib/managers/search-manager.d.ts +235 -0
  81. package/lib/managers/search-manager.js +329 -0
  82. package/lib/managers/security-manager.d.ts +161 -0
  83. package/lib/managers/security-manager.js +292 -0
  84. package/lib/managers/signature-manager.d.ts +738 -0
  85. package/lib/managers/signature-manager.js +1509 -0
  86. package/lib/managers/streams.d.ts +262 -0
  87. package/lib/managers/streams.js +477 -0
  88. package/lib/managers/xfa-manager.d.ts +227 -0
  89. package/lib/managers/xfa-manager.js +539 -0
  90. package/lib/native-loader.d.ts +7 -0
  91. package/lib/native-loader.js +62 -0
  92. package/lib/native.d.ts +16 -0
  93. package/lib/native.js +69 -0
  94. package/lib/pdf-creator-manager.d.ts +200 -0
  95. package/lib/pdf-creator-manager.js +381 -0
  96. package/lib/properties.d.ts +79 -0
  97. package/lib/properties.js +454 -0
  98. package/lib/result-accessors-manager.d.ts +346 -0
  99. package/lib/result-accessors-manager.js +706 -0
  100. package/lib/thumbnail-manager.d.ts +121 -0
  101. package/lib/thumbnail-manager.js +205 -0
  102. package/lib/timestamp.d.ts +54 -0
  103. package/lib/timestamp.js +115 -0
  104. package/lib/tsa-client.d.ts +44 -0
  105. package/lib/tsa-client.js +67 -0
  106. package/lib/types/common.d.ts +189 -0
  107. package/lib/types/common.js +17 -0
  108. package/lib/types/document-types.d.ts +352 -0
  109. package/lib/types/document-types.js +82 -0
  110. package/lib/types/index.d.ts +5 -0
  111. package/lib/types/index.js +5 -0
  112. package/lib/types/manager-types.d.ts +179 -0
  113. package/lib/types/manager-types.js +100 -0
  114. package/lib/types/native-bindings.d.ts +439 -0
  115. package/lib/types/native-bindings.js +7 -0
  116. package/lib/workers/index.d.ts +6 -0
  117. package/lib/workers/index.js +5 -0
  118. package/lib/workers/pool.d.ts +64 -0
  119. package/lib/workers/pool.js +192 -0
  120. package/lib/workers/worker.d.ts +5 -0
  121. package/lib/workers/worker.js +99 -0
  122. package/package.json +79 -0
  123. package/prebuilds/darwin-arm64/pdf_oxide.node +0 -0
  124. package/prebuilds/darwin-x64/pdf_oxide.node +0 -0
  125. package/prebuilds/linux-arm64/pdf_oxide.node +0 -0
  126. package/prebuilds/linux-x64/pdf_oxide.node +0 -0
  127. package/prebuilds/win32-x64/pdf_oxide.node +0 -0
@@ -0,0 +1,235 @@
1
+ /**
2
+ * Manager for text search operations in PDF documents
3
+ *
4
+ * Caching is handled automatically at the Rust FFI layer, eliminating
5
+ * the need for duplicate cache implementations in the binding.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * import { SearchManager, SearchOptionsBuilder } from 'pdf_oxide';
10
+ *
11
+ * const doc = PdfDocument.open('document.pdf');
12
+ * const searchManager = new SearchManager(doc);
13
+ *
14
+ * // Simple search
15
+ * const results = searchManager.search('keyword');
16
+ *
17
+ * // Search with options
18
+ * const options = SearchOptionsBuilder.strict().build();
19
+ * const results = searchManager.search('keyword', options);
20
+ *
21
+ * // Count occurrences
22
+ * const count = searchManager.countOccurrences('keyword');
23
+ * ```
24
+ */
25
+ export interface SearchResult {
26
+ text?: string;
27
+ pageIndex?: number;
28
+ position?: number;
29
+ boundingBox?: Record<string, number>;
30
+ [key: string]: any;
31
+ }
32
+ export interface SearchStatistics {
33
+ searchText: string;
34
+ totalOccurrences: number;
35
+ pagesContaining: number;
36
+ firstMatchPage: number;
37
+ lastMatchPage: number;
38
+ pages: number[];
39
+ occurrencesPerPage: Array<{
40
+ pageIndex: number;
41
+ pageNumber: number;
42
+ count: number;
43
+ }>;
44
+ }
45
+ export interface SearchCapabilities {
46
+ caseSensitiveSearch: boolean;
47
+ wholeWordSearch: boolean;
48
+ regexSearch: boolean;
49
+ annotationSearch: boolean;
50
+ maxResults: number;
51
+ isSearchable: boolean;
52
+ }
53
+ export declare class SearchManager {
54
+ private _document;
55
+ /**
56
+ * Creates a new SearchManager for the given document
57
+ * @param document - The PDF document
58
+ * @throws Error if document is null or undefined
59
+ */
60
+ constructor(document: any);
61
+ /**
62
+ * Searches for text in a specific page.
63
+ * Results are automatically cached at the FFI layer.
64
+ * @param searchText - Text to search for
65
+ * @param pageIndex - Zero-based page index
66
+ * @param options - Search options (caseSensitive, wholeWords, useRegex, etc.)
67
+ * @returns Array of search results
68
+ * @throws Error if parameters are invalid
69
+ *
70
+ * @example
71
+ * ```typescript
72
+ * const results = manager.search('error', 0);
73
+ * results.forEach(result => {
74
+ * console.log(`Found at position ${result.position}`);
75
+ * });
76
+ * ```
77
+ */
78
+ search(searchText: string, pageIndex: number, options?: Record<string, any>): SearchResult[];
79
+ /**
80
+ * Searches for text across all pages
81
+ * @param searchText - Text to search for
82
+ * @param options - Search options
83
+ * @returns Array of search results with page information
84
+ *
85
+ * @example
86
+ * ```typescript
87
+ * const results = manager.searchAll('important');
88
+ * console.log(`Found ${results.length} occurrences`);
89
+ * ```
90
+ */
91
+ searchAll(searchText: string, options?: Record<string, any>): SearchResult[];
92
+ /**
93
+ * Counts occurrences of text in a page
94
+ * @param searchText - Text to search for
95
+ * @param pageIndex - Zero-based page index
96
+ * @param options - Search options
97
+ * @returns Number of occurrences found
98
+ *
99
+ * @example
100
+ * ```typescript
101
+ * const count = manager.countOccurrences('the', 0);
102
+ * console.log(`"the" appears ${count} times on page 1`);
103
+ * ```
104
+ */
105
+ countOccurrences(searchText: string, pageIndex: number, options?: Record<string, any>): number;
106
+ /**
107
+ * Counts occurrences of text across all pages
108
+ * @param searchText - Text to search for
109
+ * @param options - Search options
110
+ * @returns Total occurrences
111
+ *
112
+ * @example
113
+ * ```typescript
114
+ * const totalCount = manager.countAllOccurrences('the');
115
+ * console.log(`"the" appears ${totalCount} times in document`);
116
+ * ```
117
+ */
118
+ countAllOccurrences(searchText: string, options?: Record<string, any>): number;
119
+ /**
120
+ * Checks if text exists in a page
121
+ * @param searchText - Text to search for
122
+ * @param pageIndex - Zero-based page index
123
+ * @param options - Search options
124
+ * @returns True if text found
125
+ *
126
+ * @example
127
+ * ```typescript
128
+ * if (manager.contains('error', 0)) {
129
+ * console.log('Page contains "error"');
130
+ * }
131
+ * ```
132
+ */
133
+ contains(searchText: string, pageIndex: number, options?: Record<string, any>): boolean;
134
+ /**
135
+ * Checks if text exists anywhere in document
136
+ * @param searchText - Text to search for
137
+ * @param options - Search options
138
+ * @returns True if text found anywhere
139
+ *
140
+ * @example
141
+ * ```typescript
142
+ * if (manager.containsAnywhere('copyright')) {
143
+ * console.log('Document contains copyright notice');
144
+ * }
145
+ * ```
146
+ */
147
+ containsAnywhere(searchText: string, options?: Record<string, any>): boolean;
148
+ /**
149
+ * Gets pages containing the search text
150
+ * @param searchText - Text to search for
151
+ * @param options - Search options
152
+ * @returns Array of page indices (zero-based) containing the text
153
+ *
154
+ * @example
155
+ * ```typescript
156
+ * const pages = manager.getPagesContaining('error');
157
+ * console.log(`"error" found on pages: ${pages.map(p => p + 1).join(', ')}`);
158
+ * ```
159
+ */
160
+ getPagesContaining(searchText: string, options?: Record<string, any>): number[];
161
+ /**
162
+ * Gets statistics for search results
163
+ * @param searchText - Text to search for
164
+ * @param options - Search options
165
+ * @returns Search statistics
166
+ *
167
+ * @example
168
+ * ```typescript
169
+ * const stats = manager.getSearchStatistics('error');
170
+ * console.log(`Found ${stats.totalOccurrences} occurrences`);
171
+ * console.log(`On ${stats.pagesContaining} pages`);
172
+ * console.log(`First match on page ${stats.firstMatchPage + 1}`);
173
+ * ```
174
+ */
175
+ getSearchStatistics(searchText: string, options?: Record<string, any>): SearchStatistics;
176
+ /**
177
+ * Searches with a regular expression
178
+ * @param pattern - Regular expression pattern
179
+ * @param options - Search options (will set useRegex: true)
180
+ * @returns Array of search results
181
+ *
182
+ * @example
183
+ * ```typescript
184
+ * const results = manager.searchRegex(/error\d+/i);
185
+ * // Finds "error1", "ERROR2", "Error3", etc.
186
+ * ```
187
+ */
188
+ searchRegex(pattern: RegExp | string, options?: Record<string, any>): SearchResult[];
189
+ /**
190
+ * Finds first occurrence of text
191
+ * @param searchText - Text to search for
192
+ * @param options - Search options
193
+ * @returns First search result or null if not found
194
+ *
195
+ * @example
196
+ * ```typescript
197
+ * const first = manager.findFirst('chapter');
198
+ * if (first) {
199
+ * console.log(`First "chapter" found on page ${first.pageNumber}`);
200
+ * }
201
+ * ```
202
+ */
203
+ findFirst(searchText: string, options?: Record<string, any>): SearchResult | null;
204
+ /**
205
+ * Finds last occurrence of text
206
+ * @param searchText - Text to search for
207
+ * @param options - Search options
208
+ * @returns Last search result or null if not found
209
+ */
210
+ findLast(searchText: string, options?: Record<string, any>): SearchResult | null;
211
+ /**
212
+ * Replaces text occurrences with highlighted versions (view only)
213
+ * Gets all occurrences for highlighting without modification
214
+ * @param searchText - Text to find
215
+ * @param options - Search options
216
+ * @returns Results formatted for highlighting
217
+ *
218
+ * @example
219
+ * ```typescript
220
+ * const highlights = manager.highlightMatches('important');
221
+ * // Use results for UI highlighting
222
+ * ```
223
+ */
224
+ highlightMatches(searchText: string, options?: Record<string, any>): SearchResult[];
225
+ /**
226
+ * Checks if document is searchable
227
+ * @returns True if document supports text search
228
+ */
229
+ isSearchable(): boolean;
230
+ /**
231
+ * Gets search capabilities summary
232
+ * @returns Search capabilities information
233
+ */
234
+ getCapabilities(): SearchCapabilities;
235
+ }
@@ -0,0 +1,329 @@
1
+ /**
2
+ * Manager for text search operations in PDF documents
3
+ *
4
+ * Caching is handled automatically at the Rust FFI layer, eliminating
5
+ * the need for duplicate cache implementations in the binding.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * import { SearchManager, SearchOptionsBuilder } from 'pdf_oxide';
10
+ *
11
+ * const doc = PdfDocument.open('document.pdf');
12
+ * const searchManager = new SearchManager(doc);
13
+ *
14
+ * // Simple search
15
+ * const results = searchManager.search('keyword');
16
+ *
17
+ * // Search with options
18
+ * const options = SearchOptionsBuilder.strict().build();
19
+ * const results = searchManager.search('keyword', options);
20
+ *
21
+ * // Count occurrences
22
+ * const count = searchManager.countOccurrences('keyword');
23
+ * ```
24
+ */
25
+ export class SearchManager {
26
+ /**
27
+ * Creates a new SearchManager for the given document
28
+ * @param document - The PDF document
29
+ * @throws Error if document is null or undefined
30
+ */
31
+ constructor(document) {
32
+ if (!document) {
33
+ throw new Error('Document is required');
34
+ }
35
+ this._document = document;
36
+ }
37
+ /**
38
+ * Searches for text in a specific page.
39
+ * Results are automatically cached at the FFI layer.
40
+ * @param searchText - Text to search for
41
+ * @param pageIndex - Zero-based page index
42
+ * @param options - Search options (caseSensitive, wholeWords, useRegex, etc.)
43
+ * @returns Array of search results
44
+ * @throws Error if parameters are invalid
45
+ *
46
+ * @example
47
+ * ```typescript
48
+ * const results = manager.search('error', 0);
49
+ * results.forEach(result => {
50
+ * console.log(`Found at position ${result.position}`);
51
+ * });
52
+ * ```
53
+ */
54
+ search(searchText, pageIndex, options) {
55
+ if (!searchText || typeof searchText !== 'string') {
56
+ throw new Error('Search text must be a non-empty string');
57
+ }
58
+ if (typeof pageIndex !== 'number' || pageIndex < 0) {
59
+ throw new Error('Page index must be a non-negative number');
60
+ }
61
+ if (pageIndex >= this._document.pageCount) {
62
+ throw new Error(`Page index ${pageIndex} out of range`);
63
+ }
64
+ try {
65
+ return this._document.search(searchText, pageIndex, options) || [];
66
+ }
67
+ catch (error) {
68
+ throw new Error(`Search failed: ${error.message}`);
69
+ }
70
+ }
71
+ /**
72
+ * Searches for text across all pages
73
+ * @param searchText - Text to search for
74
+ * @param options - Search options
75
+ * @returns Array of search results with page information
76
+ *
77
+ * @example
78
+ * ```typescript
79
+ * const results = manager.searchAll('important');
80
+ * console.log(`Found ${results.length} occurrences`);
81
+ * ```
82
+ */
83
+ searchAll(searchText, options) {
84
+ if (!searchText || typeof searchText !== 'string') {
85
+ throw new Error('Search text must be a non-empty string');
86
+ }
87
+ const allResults = [];
88
+ try {
89
+ for (let i = 0; i < this._document.pageCount; i++) {
90
+ const results = this.search(searchText, i, options);
91
+ results.forEach((result) => {
92
+ result.pageIndex = i;
93
+ result.pageNumber = i + 1;
94
+ });
95
+ allResults.push(...results);
96
+ }
97
+ return allResults;
98
+ }
99
+ catch (error) {
100
+ throw new Error(`Search all failed: ${error.message}`);
101
+ }
102
+ }
103
+ /**
104
+ * Counts occurrences of text in a page
105
+ * @param searchText - Text to search for
106
+ * @param pageIndex - Zero-based page index
107
+ * @param options - Search options
108
+ * @returns Number of occurrences found
109
+ *
110
+ * @example
111
+ * ```typescript
112
+ * const count = manager.countOccurrences('the', 0);
113
+ * console.log(`"the" appears ${count} times on page 1`);
114
+ * ```
115
+ */
116
+ countOccurrences(searchText, pageIndex, options) {
117
+ const results = this.search(searchText, pageIndex, options);
118
+ return results.length;
119
+ }
120
+ /**
121
+ * Counts occurrences of text across all pages
122
+ * @param searchText - Text to search for
123
+ * @param options - Search options
124
+ * @returns Total occurrences
125
+ *
126
+ * @example
127
+ * ```typescript
128
+ * const totalCount = manager.countAllOccurrences('the');
129
+ * console.log(`"the" appears ${totalCount} times in document`);
130
+ * ```
131
+ */
132
+ countAllOccurrences(searchText, options) {
133
+ const results = this.searchAll(searchText, options);
134
+ return results.length;
135
+ }
136
+ /**
137
+ * Checks if text exists in a page
138
+ * @param searchText - Text to search for
139
+ * @param pageIndex - Zero-based page index
140
+ * @param options - Search options
141
+ * @returns True if text found
142
+ *
143
+ * @example
144
+ * ```typescript
145
+ * if (manager.contains('error', 0)) {
146
+ * console.log('Page contains "error"');
147
+ * }
148
+ * ```
149
+ */
150
+ contains(searchText, pageIndex, options) {
151
+ const results = this.search(searchText, pageIndex, options);
152
+ return results.length > 0;
153
+ }
154
+ /**
155
+ * Checks if text exists anywhere in document
156
+ * @param searchText - Text to search for
157
+ * @param options - Search options
158
+ * @returns True if text found anywhere
159
+ *
160
+ * @example
161
+ * ```typescript
162
+ * if (manager.containsAnywhere('copyright')) {
163
+ * console.log('Document contains copyright notice');
164
+ * }
165
+ * ```
166
+ */
167
+ containsAnywhere(searchText, options) {
168
+ const results = this.searchAll(searchText, options);
169
+ return results.length > 0;
170
+ }
171
+ /**
172
+ * Gets pages containing the search text
173
+ * @param searchText - Text to search for
174
+ * @param options - Search options
175
+ * @returns Array of page indices (zero-based) containing the text
176
+ *
177
+ * @example
178
+ * ```typescript
179
+ * const pages = manager.getPagesContaining('error');
180
+ * console.log(`"error" found on pages: ${pages.map(p => p + 1).join(', ')}`);
181
+ * ```
182
+ */
183
+ getPagesContaining(searchText, options) {
184
+ const results = this.searchAll(searchText, options);
185
+ const pageSet = new Set(results.map((r) => r.pageIndex || 0));
186
+ return Array.from(pageSet).sort((a, b) => a - b);
187
+ }
188
+ /**
189
+ * Gets statistics for search results
190
+ * @param searchText - Text to search for
191
+ * @param options - Search options
192
+ * @returns Search statistics
193
+ *
194
+ * @example
195
+ * ```typescript
196
+ * const stats = manager.getSearchStatistics('error');
197
+ * console.log(`Found ${stats.totalOccurrences} occurrences`);
198
+ * console.log(`On ${stats.pagesContaining} pages`);
199
+ * console.log(`First match on page ${stats.firstMatchPage + 1}`);
200
+ * ```
201
+ */
202
+ getSearchStatistics(searchText, options) {
203
+ const results = this.searchAll(searchText, options);
204
+ // Extract unique pages and calculate per-page counts in single pass
205
+ const pageMap = new Map();
206
+ for (const result of results) {
207
+ const pageIdx = result.pageIndex || 0;
208
+ if (!pageMap.has(pageIdx)) {
209
+ pageMap.set(pageIdx, 0);
210
+ }
211
+ pageMap.set(pageIdx, (pageMap.get(pageIdx) || 0) + 1);
212
+ }
213
+ const pages = Array.from(pageMap.keys()).sort((a, b) => a - b);
214
+ return {
215
+ searchText,
216
+ totalOccurrences: results.length,
217
+ pagesContaining: pages.length,
218
+ firstMatchPage: pages.length > 0 ? pages[0] : -1,
219
+ lastMatchPage: pages.length > 0 ? pages[pages.length - 1] : -1,
220
+ pages,
221
+ occurrencesPerPage: pages.map((p) => ({
222
+ pageIndex: p,
223
+ pageNumber: p + 1,
224
+ count: pageMap.get(p) || 0,
225
+ })),
226
+ };
227
+ }
228
+ /**
229
+ * Searches with a regular expression
230
+ * @param pattern - Regular expression pattern
231
+ * @param options - Search options (will set useRegex: true)
232
+ * @returns Array of search results
233
+ *
234
+ * @example
235
+ * ```typescript
236
+ * const results = manager.searchRegex(/error\d+/i);
237
+ * // Finds "error1", "ERROR2", "Error3", etc.
238
+ * ```
239
+ */
240
+ searchRegex(pattern, options = {}) {
241
+ const regexStr = pattern instanceof RegExp ? pattern.source : pattern;
242
+ if (!regexStr || typeof regexStr !== 'string') {
243
+ throw new Error('Pattern must be a valid regular expression');
244
+ }
245
+ // Merge options and ensure useRegex is true
246
+ const searchOptions = {
247
+ ...options,
248
+ useRegex: true,
249
+ };
250
+ try {
251
+ return this.searchAll(regexStr, searchOptions);
252
+ }
253
+ catch (error) {
254
+ throw new Error(`Regex search failed: ${error.message}`);
255
+ }
256
+ }
257
+ /**
258
+ * Finds first occurrence of text
259
+ * @param searchText - Text to search for
260
+ * @param options - Search options
261
+ * @returns First search result or null if not found
262
+ *
263
+ * @example
264
+ * ```typescript
265
+ * const first = manager.findFirst('chapter');
266
+ * if (first) {
267
+ * console.log(`First "chapter" found on page ${first.pageNumber}`);
268
+ * }
269
+ * ```
270
+ */
271
+ findFirst(searchText, options) {
272
+ const results = this.searchAll(searchText, options);
273
+ return results.length > 0 ? results[0] : null;
274
+ }
275
+ /**
276
+ * Finds last occurrence of text
277
+ * @param searchText - Text to search for
278
+ * @param options - Search options
279
+ * @returns Last search result or null if not found
280
+ */
281
+ findLast(searchText, options) {
282
+ const results = this.searchAll(searchText, options);
283
+ return results.length > 0 ? results[results.length - 1] : null;
284
+ }
285
+ /**
286
+ * Replaces text occurrences with highlighted versions (view only)
287
+ * Gets all occurrences for highlighting without modification
288
+ * @param searchText - Text to find
289
+ * @param options - Search options
290
+ * @returns Results formatted for highlighting
291
+ *
292
+ * @example
293
+ * ```typescript
294
+ * const highlights = manager.highlightMatches('important');
295
+ * // Use results for UI highlighting
296
+ * ```
297
+ */
298
+ highlightMatches(searchText, options) {
299
+ return this.searchAll(searchText, options);
300
+ }
301
+ /**
302
+ * Checks if document is searchable
303
+ * @returns True if document supports text search
304
+ */
305
+ isSearchable() {
306
+ try {
307
+ // Try searching for common text to verify searchability
308
+ this.searchAll('test');
309
+ return true;
310
+ }
311
+ catch (error) {
312
+ return false;
313
+ }
314
+ }
315
+ /**
316
+ * Gets search capabilities summary
317
+ * @returns Search capabilities information
318
+ */
319
+ getCapabilities() {
320
+ return {
321
+ caseSensitiveSearch: true,
322
+ wholeWordSearch: true,
323
+ regexSearch: true,
324
+ annotationSearch: true,
325
+ maxResults: 1000,
326
+ isSearchable: this.isSearchable(),
327
+ };
328
+ }
329
+ }