pdf-oxide 0.3.24 → 0.3.28

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 (271) hide show
  1. package/lib/builders/annotation-builder.d.ts +199 -0
  2. package/lib/builders/annotation-builder.d.ts.map +1 -0
  3. package/lib/builders/annotation-builder.js +318 -0
  4. package/lib/builders/annotation-builder.js.map +1 -0
  5. package/lib/builders/conversion-options-builder.d.ts +107 -0
  6. package/lib/builders/conversion-options-builder.d.ts.map +1 -0
  7. package/lib/builders/conversion-options-builder.js +215 -0
  8. package/lib/builders/conversion-options-builder.js.map +1 -0
  9. package/{src/builders/index.ts → lib/builders/index.d.ts} +1 -1
  10. package/lib/builders/index.d.ts.map +1 -0
  11. package/lib/builders/index.js +12 -0
  12. package/lib/builders/index.js.map +1 -0
  13. package/lib/builders/metadata-builder.d.ts +202 -0
  14. package/lib/builders/metadata-builder.d.ts.map +1 -0
  15. package/lib/builders/metadata-builder.js +286 -0
  16. package/lib/builders/metadata-builder.js.map +1 -0
  17. package/lib/builders/pdf-builder.d.ts +215 -0
  18. package/lib/builders/pdf-builder.d.ts.map +1 -0
  19. package/lib/builders/pdf-builder.js +339 -0
  20. package/lib/builders/pdf-builder.js.map +1 -0
  21. package/lib/builders/search-options-builder.d.ts +74 -0
  22. package/lib/builders/search-options-builder.d.ts.map +1 -0
  23. package/lib/builders/search-options-builder.js +130 -0
  24. package/lib/builders/search-options-builder.js.map +1 -0
  25. package/lib/document-editor-manager.d.ts +140 -0
  26. package/lib/document-editor-manager.d.ts.map +1 -0
  27. package/lib/document-editor-manager.js +257 -0
  28. package/lib/document-editor-manager.js.map +1 -0
  29. package/lib/errors.d.ts +383 -0
  30. package/lib/errors.d.ts.map +1 -0
  31. package/lib/errors.js +1117 -0
  32. package/lib/errors.js.map +1 -0
  33. package/lib/form-field-manager.d.ts +300 -0
  34. package/lib/form-field-manager.d.ts.map +1 -0
  35. package/lib/form-field-manager.js +567 -0
  36. package/lib/form-field-manager.js.map +1 -0
  37. package/lib/hybrid-ml-manager.d.ts +143 -0
  38. package/lib/hybrid-ml-manager.d.ts.map +1 -0
  39. package/lib/hybrid-ml-manager.js +209 -0
  40. package/lib/hybrid-ml-manager.js.map +1 -0
  41. package/lib/index.d.ts +23 -0
  42. package/lib/index.d.ts.map +1 -0
  43. package/lib/index.js +280 -0
  44. package/lib/index.js.map +1 -0
  45. package/lib/managers/accessibility-manager.d.ts +149 -0
  46. package/lib/managers/accessibility-manager.d.ts.map +1 -0
  47. package/lib/managers/accessibility-manager.js +224 -0
  48. package/lib/managers/accessibility-manager.js.map +1 -0
  49. package/lib/managers/annotation-manager.d.ts +220 -0
  50. package/lib/managers/annotation-manager.d.ts.map +1 -0
  51. package/lib/managers/annotation-manager.js +360 -0
  52. package/lib/managers/annotation-manager.js.map +1 -0
  53. package/lib/managers/barcode-manager.d.ts +80 -0
  54. package/lib/managers/barcode-manager.d.ts.map +1 -0
  55. package/lib/managers/barcode-manager.js +226 -0
  56. package/lib/managers/barcode-manager.js.map +1 -0
  57. package/lib/managers/batch-manager.d.ts +186 -0
  58. package/lib/managers/batch-manager.d.ts.map +1 -0
  59. package/lib/managers/batch-manager.js +389 -0
  60. package/lib/managers/batch-manager.js.map +1 -0
  61. package/lib/managers/cache-manager.d.ts +182 -0
  62. package/lib/managers/cache-manager.d.ts.map +1 -0
  63. package/lib/managers/cache-manager.js +387 -0
  64. package/lib/managers/cache-manager.js.map +1 -0
  65. package/lib/managers/compliance-manager.d.ts +104 -0
  66. package/lib/managers/compliance-manager.d.ts.map +1 -0
  67. package/lib/managers/compliance-manager.js +415 -0
  68. package/lib/managers/compliance-manager.js.map +1 -0
  69. package/lib/managers/content-manager.d.ts +121 -0
  70. package/lib/managers/content-manager.d.ts.map +1 -0
  71. package/lib/managers/content-manager.js +295 -0
  72. package/lib/managers/content-manager.js.map +1 -0
  73. package/lib/managers/document-utility-manager.d.ts +370 -0
  74. package/lib/managers/document-utility-manager.d.ts.map +1 -0
  75. package/lib/managers/document-utility-manager.js +731 -0
  76. package/lib/managers/document-utility-manager.js.map +1 -0
  77. package/lib/managers/dom-pdf-creator.d.ts +105 -0
  78. package/lib/managers/dom-pdf-creator.d.ts.map +1 -0
  79. package/lib/managers/dom-pdf-creator.js +300 -0
  80. package/lib/managers/dom-pdf-creator.js.map +1 -0
  81. package/lib/managers/editing-manager.d.ts +249 -0
  82. package/lib/managers/editing-manager.d.ts.map +1 -0
  83. package/lib/managers/editing-manager.js +388 -0
  84. package/lib/managers/editing-manager.js.map +1 -0
  85. package/lib/managers/enterprise-manager.d.ts +193 -0
  86. package/lib/managers/enterprise-manager.d.ts.map +1 -0
  87. package/lib/managers/enterprise-manager.js +305 -0
  88. package/lib/managers/enterprise-manager.js.map +1 -0
  89. package/lib/managers/extended-managers.d.ts +123 -0
  90. package/lib/managers/extended-managers.d.ts.map +1 -0
  91. package/lib/managers/extended-managers.js +658 -0
  92. package/lib/managers/extended-managers.js.map +1 -0
  93. package/lib/managers/extraction-manager.d.ts +247 -0
  94. package/lib/managers/extraction-manager.d.ts.map +1 -0
  95. package/lib/managers/extraction-manager.js +478 -0
  96. package/lib/managers/extraction-manager.js.map +1 -0
  97. package/lib/managers/final-utilities.d.ts +128 -0
  98. package/lib/managers/final-utilities.d.ts.map +1 -0
  99. package/lib/managers/final-utilities.js +653 -0
  100. package/lib/managers/final-utilities.js.map +1 -0
  101. package/lib/managers/hybrid-ml-advanced.d.ts +137 -0
  102. package/lib/managers/hybrid-ml-advanced.d.ts.map +1 -0
  103. package/lib/managers/hybrid-ml-advanced.js +707 -0
  104. package/lib/managers/hybrid-ml-advanced.js.map +1 -0
  105. package/lib/managers/index.d.ts +65 -0
  106. package/lib/managers/index.d.ts.map +1 -0
  107. package/lib/managers/index.js +70 -0
  108. package/lib/managers/index.js.map +1 -0
  109. package/lib/managers/layer-manager.d.ts +204 -0
  110. package/lib/managers/layer-manager.d.ts.map +1 -0
  111. package/lib/managers/layer-manager.js +403 -0
  112. package/lib/managers/layer-manager.js.map +1 -0
  113. package/lib/managers/metadata-manager.d.ts +149 -0
  114. package/lib/managers/metadata-manager.d.ts.map +1 -0
  115. package/lib/managers/metadata-manager.js +281 -0
  116. package/lib/managers/metadata-manager.js.map +1 -0
  117. package/lib/managers/ocr-manager.d.ts +195 -0
  118. package/lib/managers/ocr-manager.d.ts.map +1 -0
  119. package/lib/managers/ocr-manager.js +583 -0
  120. package/lib/managers/ocr-manager.js.map +1 -0
  121. package/lib/managers/optimization-manager.d.ts +103 -0
  122. package/lib/managers/optimization-manager.d.ts.map +1 -0
  123. package/lib/managers/optimization-manager.js +194 -0
  124. package/lib/managers/optimization-manager.js.map +1 -0
  125. package/lib/managers/outline-manager.d.ts +102 -0
  126. package/lib/managers/outline-manager.d.ts.map +1 -0
  127. package/lib/managers/outline-manager.js +170 -0
  128. package/lib/managers/outline-manager.js.map +1 -0
  129. package/lib/managers/page-manager.d.ts +143 -0
  130. package/lib/managers/page-manager.d.ts.map +1 -0
  131. package/lib/managers/page-manager.js +237 -0
  132. package/lib/managers/page-manager.js.map +1 -0
  133. package/lib/managers/pattern-detection.d.ts +170 -0
  134. package/lib/managers/pattern-detection.d.ts.map +1 -0
  135. package/lib/managers/pattern-detection.js +325 -0
  136. package/lib/managers/pattern-detection.js.map +1 -0
  137. package/lib/managers/rendering-manager.d.ts +354 -0
  138. package/lib/managers/rendering-manager.d.ts.map +1 -0
  139. package/lib/managers/rendering-manager.js +680 -0
  140. package/lib/managers/rendering-manager.js.map +1 -0
  141. package/lib/managers/search-manager.d.ts +236 -0
  142. package/lib/managers/search-manager.d.ts.map +1 -0
  143. package/lib/managers/search-manager.js +330 -0
  144. package/lib/managers/search-manager.js.map +1 -0
  145. package/lib/managers/security-manager.d.ts +162 -0
  146. package/lib/managers/security-manager.d.ts.map +1 -0
  147. package/lib/managers/security-manager.js +293 -0
  148. package/lib/managers/security-manager.js.map +1 -0
  149. package/lib/managers/signature-manager.d.ts +725 -0
  150. package/lib/managers/signature-manager.d.ts.map +1 -0
  151. package/lib/managers/signature-manager.js +1365 -0
  152. package/lib/managers/signature-manager.js.map +1 -0
  153. package/lib/managers/streams.d.ts +263 -0
  154. package/lib/managers/streams.d.ts.map +1 -0
  155. package/lib/managers/streams.js +472 -0
  156. package/lib/managers/streams.js.map +1 -0
  157. package/lib/managers/xfa-manager.d.ts +228 -0
  158. package/lib/managers/xfa-manager.d.ts.map +1 -0
  159. package/lib/managers/xfa-manager.js +490 -0
  160. package/lib/managers/xfa-manager.js.map +1 -0
  161. package/lib/pdf-creator-manager.d.ts +201 -0
  162. package/lib/pdf-creator-manager.d.ts.map +1 -0
  163. package/lib/pdf-creator-manager.js +379 -0
  164. package/lib/pdf-creator-manager.js.map +1 -0
  165. package/lib/properties.d.ts +80 -0
  166. package/lib/properties.d.ts.map +1 -0
  167. package/lib/properties.js +455 -0
  168. package/lib/properties.js.map +1 -0
  169. package/lib/result-accessors-manager.d.ts +347 -0
  170. package/lib/result-accessors-manager.d.ts.map +1 -0
  171. package/lib/result-accessors-manager.js +705 -0
  172. package/lib/result-accessors-manager.js.map +1 -0
  173. package/lib/thumbnail-manager.d.ts +122 -0
  174. package/lib/thumbnail-manager.d.ts.map +1 -0
  175. package/lib/thumbnail-manager.js +206 -0
  176. package/lib/thumbnail-manager.js.map +1 -0
  177. package/lib/types/common.d.ts +93 -0
  178. package/lib/types/common.d.ts.map +1 -0
  179. package/lib/types/common.js +5 -0
  180. package/lib/types/common.js.map +1 -0
  181. package/lib/types/document-types.d.ts +353 -0
  182. package/lib/types/document-types.d.ts.map +1 -0
  183. package/lib/types/document-types.js +83 -0
  184. package/lib/types/document-types.js.map +1 -0
  185. package/{src/types/index.ts → lib/types/index.d.ts} +1 -1
  186. package/lib/types/index.d.ts.map +1 -0
  187. package/lib/types/index.js +6 -0
  188. package/lib/types/index.js.map +1 -0
  189. package/lib/types/manager-types.d.ts +180 -0
  190. package/lib/types/manager-types.d.ts.map +1 -0
  191. package/lib/types/manager-types.js +99 -0
  192. package/lib/types/manager-types.js.map +1 -0
  193. package/lib/types/native-bindings.d.ts +440 -0
  194. package/lib/types/native-bindings.d.ts.map +1 -0
  195. package/lib/types/native-bindings.js +8 -0
  196. package/lib/types/native-bindings.js.map +1 -0
  197. package/{src/workers/index.ts → lib/workers/index.d.ts} +1 -1
  198. package/lib/workers/index.d.ts.map +1 -0
  199. package/lib/workers/index.js +6 -0
  200. package/lib/workers/index.js.map +1 -0
  201. package/lib/workers/pool.d.ts +65 -0
  202. package/lib/workers/pool.d.ts.map +1 -0
  203. package/lib/workers/pool.js +195 -0
  204. package/lib/workers/pool.js.map +1 -0
  205. package/lib/workers/worker.d.ts +6 -0
  206. package/lib/workers/worker.d.ts.map +1 -0
  207. package/lib/workers/worker.js +100 -0
  208. package/lib/workers/worker.js.map +1 -0
  209. package/package.json +12 -22
  210. package/prebuilds/darwin-arm64/pdf_oxide.node +0 -0
  211. package/prebuilds/darwin-x64/pdf_oxide.node +0 -0
  212. package/prebuilds/linux-arm64/pdf_oxide.node +0 -0
  213. package/prebuilds/linux-x64/pdf_oxide.node +0 -0
  214. package/prebuilds/win32-x64/pdf_oxide.node +0 -0
  215. package/binding.gyp +0 -35
  216. package/src/builders/annotation-builder.ts +0 -367
  217. package/src/builders/conversion-options-builder.ts +0 -257
  218. package/src/builders/metadata-builder.ts +0 -317
  219. package/src/builders/pdf-builder.ts +0 -386
  220. package/src/builders/search-options-builder.ts +0 -151
  221. package/src/document-editor-manager.ts +0 -318
  222. package/src/errors.ts +0 -1629
  223. package/src/form-field-manager.ts +0 -666
  224. package/src/hybrid-ml-manager.ts +0 -283
  225. package/src/index.ts +0 -453
  226. package/src/managers/accessibility-manager.ts +0 -338
  227. package/src/managers/annotation-manager.ts +0 -439
  228. package/src/managers/barcode-manager.ts +0 -235
  229. package/src/managers/batch-manager.ts +0 -533
  230. package/src/managers/cache-manager.ts +0 -486
  231. package/src/managers/compliance-manager.ts +0 -375
  232. package/src/managers/content-manager.ts +0 -339
  233. package/src/managers/document-utility-manager.ts +0 -922
  234. package/src/managers/dom-pdf-creator.ts +0 -365
  235. package/src/managers/editing-manager.ts +0 -514
  236. package/src/managers/enterprise-manager.ts +0 -478
  237. package/src/managers/extended-managers.ts +0 -437
  238. package/src/managers/extraction-manager.ts +0 -583
  239. package/src/managers/final-utilities.ts +0 -429
  240. package/src/managers/hybrid-ml-advanced.ts +0 -479
  241. package/src/managers/index.ts +0 -239
  242. package/src/managers/layer-manager.ts +0 -500
  243. package/src/managers/metadata-manager.ts +0 -303
  244. package/src/managers/ocr-manager.ts +0 -756
  245. package/src/managers/optimization-manager.ts +0 -262
  246. package/src/managers/outline-manager.ts +0 -196
  247. package/src/managers/page-manager.ts +0 -289
  248. package/src/managers/pattern-detection.ts +0 -440
  249. package/src/managers/rendering-manager.ts +0 -863
  250. package/src/managers/search-manager.ts +0 -385
  251. package/src/managers/security-manager.ts +0 -345
  252. package/src/managers/signature-manager.ts +0 -1664
  253. package/src/managers/streams.ts +0 -618
  254. package/src/managers/xfa-manager.ts +0 -500
  255. package/src/pdf-creator-manager.ts +0 -494
  256. package/src/properties.ts +0 -522
  257. package/src/result-accessors-manager.ts +0 -867
  258. package/src/tests/advanced-features.test.ts +0 -414
  259. package/src/tests/advanced.test.ts +0 -266
  260. package/src/tests/extended-managers.test.ts +0 -316
  261. package/src/tests/final-utilities.test.ts +0 -455
  262. package/src/tests/foundation.test.ts +0 -315
  263. package/src/tests/high-demand.test.ts +0 -257
  264. package/src/tests/specialized.test.ts +0 -97
  265. package/src/thumbnail-manager.ts +0 -272
  266. package/src/types/common.ts +0 -142
  267. package/src/types/document-types.ts +0 -457
  268. package/src/types/manager-types.ts +0 -284
  269. package/src/types/native-bindings.ts +0 -517
  270. package/src/workers/pool.ts +0 -274
  271. package/src/workers/worker.ts +0 -131
@@ -0,0 +1,705 @@
1
+ /**
2
+ * ResultAccessorsManager for extracting extended properties from PDF operations
3
+ *
4
+ * Provides detailed metadata from search results, fonts, images, and annotations.
5
+ * Enables advanced features like context extraction, font metrics analysis, and annotation tracking.
6
+ * API is consistent with Python, Java, C#, Go, and Swift implementations.
7
+ */
8
+ import { EventEmitter } from 'events';
9
+ /**
10
+ * Result Accessors Manager for extracting extended properties
11
+ *
12
+ * Provides methods to:
13
+ * - Extract context from search results
14
+ * - Get detailed font metrics
15
+ * - Inspect image metadata and ICC profiles
16
+ * - Track annotation relationships and metadata
17
+ * - Filter and analyze results by properties
18
+ *
19
+ * Matches: Python ResultAccessorsManager, Java ResultAccessorsManager, etc.
20
+ */
21
+ export class ResultAccessorsManager extends EventEmitter {
22
+ constructor(document) {
23
+ super();
24
+ this.resultCache = new Map();
25
+ this.maxCacheSize = 100;
26
+ this.document = document;
27
+ try {
28
+ this.native = require('../index.node');
29
+ }
30
+ catch {
31
+ // Fall back to framework defaults if native module not available
32
+ this.native = null;
33
+ }
34
+ }
35
+ setCached(key, value) {
36
+ if (this.resultCache.size >= this.maxCacheSize) {
37
+ // Remove oldest entry
38
+ const firstKey = this.resultCache.keys().next().value;
39
+ if (firstKey)
40
+ this.resultCache.delete(firstKey);
41
+ }
42
+ this.resultCache.set(key, value);
43
+ }
44
+ // ========== Search Result Accessors (10 functions) ==========
45
+ /**
46
+ * Gets context text around a search result
47
+ * Includes words before and after the match
48
+ * @param results Search results handle
49
+ * @param index Index of the result
50
+ * @param contextWidth Number of characters for context
51
+ * @returns Context text with highlighted match
52
+ */
53
+ async getSearchResultContext(results, index, contextWidth = 50) {
54
+ const cacheKey = `search:context:${index}:${contextWidth}`;
55
+ if (this.resultCache.has(cacheKey)) {
56
+ return this.resultCache.get(cacheKey);
57
+ }
58
+ const context = this.native?.search_result_context?.(index, contextWidth) ?? '';
59
+ this.setCached(cacheKey, context);
60
+ this.emit('searchContextExtracted', index);
61
+ return context;
62
+ }
63
+ /**
64
+ * Gets the line number of a search result
65
+ * @param results Search results handle
66
+ * @param index Index of the result
67
+ * @returns Line number (0-based)
68
+ */
69
+ async getSearchResultLineNumber(results, index) {
70
+ const cacheKey = `search:linenum:${index}`;
71
+ if (this.resultCache.has(cacheKey)) {
72
+ return this.resultCache.get(cacheKey);
73
+ }
74
+ const lineNumber = this.native?.search_result_line_number?.(index) ?? 0;
75
+ this.setCached(cacheKey, lineNumber);
76
+ return lineNumber;
77
+ }
78
+ /**
79
+ * Gets the paragraph number of a search result
80
+ * @param results Search results handle
81
+ * @param index Index of the result
82
+ * @returns Paragraph number (0-based)
83
+ */
84
+ async getSearchResultParagraphNumber(results, index) {
85
+ const cacheKey = `search:paragraphnum:${index}`;
86
+ if (this.resultCache.has(cacheKey)) {
87
+ return this.resultCache.get(cacheKey);
88
+ }
89
+ const paragraphNumber = this.native?.search_result_paragraph_number?.(index) ?? 0;
90
+ this.setCached(cacheKey, paragraphNumber);
91
+ return paragraphNumber;
92
+ }
93
+ /**
94
+ * Gets the confidence score of a search result
95
+ * Useful for OCR results where confidence varies
96
+ * @param results Search results handle
97
+ * @param index Index of the result
98
+ * @returns Confidence score (0.0 to 1.0)
99
+ */
100
+ async getSearchResultConfidence(results, index) {
101
+ const cacheKey = `search:confidence:${index}`;
102
+ if (this.resultCache.has(cacheKey)) {
103
+ return this.resultCache.get(cacheKey);
104
+ }
105
+ const confidence = this.native?.search_result_confidence?.(index) ?? 1.0;
106
+ this.setCached(cacheKey, confidence);
107
+ return confidence;
108
+ }
109
+ /**
110
+ * Checks if a search result is highlighted in the document
111
+ * @param results Search results handle
112
+ * @param index Index of the result
113
+ * @returns True if the result is highlighted
114
+ */
115
+ async isSearchResultHighlighted(results, index) {
116
+ const cacheKey = `search:highlighted:${index}`;
117
+ if (this.resultCache.has(cacheKey)) {
118
+ return this.resultCache.get(cacheKey);
119
+ }
120
+ const highlighted = this.native?.search_result_is_highlighted?.(index) ?? false;
121
+ this.setCached(cacheKey, highlighted);
122
+ return highlighted;
123
+ }
124
+ /**
125
+ * Gets font information for a search result
126
+ * Returns JSON with font name, size, family, etc.
127
+ * @param results Search results handle
128
+ * @param index Index of the result
129
+ * @returns Font info as JSON string
130
+ */
131
+ async getSearchResultFontInfo(results, index) {
132
+ const cacheKey = `search:fontinfo:${index}`;
133
+ if (this.resultCache.has(cacheKey)) {
134
+ return this.resultCache.get(cacheKey);
135
+ }
136
+ const fontInfo = this.native?.search_result_font_info?.(index) ?? '{}';
137
+ this.setCached(cacheKey, fontInfo);
138
+ return fontInfo;
139
+ }
140
+ /**
141
+ * Gets RGB color of a search result
142
+ * @param results Search results handle
143
+ * @param index Index of the result
144
+ * @returns Color as [R, G, B] array (0-255)
145
+ */
146
+ async getSearchResultColor(results, index) {
147
+ const cacheKey = `search:color:${index}`;
148
+ if (this.resultCache.has(cacheKey)) {
149
+ return this.resultCache.get(cacheKey);
150
+ }
151
+ let color = [0, 0, 0];
152
+ if (this.native?.search_result_color) {
153
+ try {
154
+ const colorJson = this.native.search_result_color(index);
155
+ const parsed = JSON.parse(colorJson);
156
+ color = [parsed.r ?? 0, parsed.g ?? 0, parsed.b ?? 0];
157
+ }
158
+ catch {
159
+ color = [0, 0, 0];
160
+ }
161
+ }
162
+ this.setCached(cacheKey, color);
163
+ return color;
164
+ }
165
+ /**
166
+ * Gets the rotation angle of a search result
167
+ * @param results Search results handle
168
+ * @param index Index of the result
169
+ * @returns Rotation in degrees (0, 90, 180, 270)
170
+ */
171
+ async getSearchResultRotation(results, index) {
172
+ const cacheKey = `search:rotation:${index}`;
173
+ if (this.resultCache.has(cacheKey)) {
174
+ return this.resultCache.get(cacheKey);
175
+ }
176
+ const rotation = this.native?.search_result_rotation?.(index) ?? 0;
177
+ this.setCached(cacheKey, rotation);
178
+ return rotation;
179
+ }
180
+ /**
181
+ * Gets the object ID of a search result
182
+ * @param results Search results handle
183
+ * @param index Index of the result
184
+ * @returns PDF object ID
185
+ */
186
+ async getSearchResultObjectId(results, index) {
187
+ const cacheKey = `search:objectid:${index}`;
188
+ if (this.resultCache.has(cacheKey)) {
189
+ return this.resultCache.get(cacheKey);
190
+ }
191
+ const objectId = this.native?.search_result_object_id?.(index) ?? 0;
192
+ this.setCached(cacheKey, objectId);
193
+ return objectId;
194
+ }
195
+ /**
196
+ * Gets the stream index of a search result
197
+ * @param results Search results handle
198
+ * @param index Index of the result
199
+ * @returns Stream index in the content
200
+ */
201
+ async getSearchResultStreamIndex(results, index) {
202
+ const cacheKey = `search:streamindex:${index}`;
203
+ if (this.resultCache.has(cacheKey)) {
204
+ return this.resultCache.get(cacheKey);
205
+ }
206
+ const streamIndex = this.native?.search_result_stream_index?.(index) ?? 0;
207
+ this.setCached(cacheKey, streamIndex);
208
+ return streamIndex;
209
+ }
210
+ /**
211
+ * Gets all properties of a search result at once
212
+ * More efficient than individual property calls
213
+ * @param results Search results handle
214
+ * @param index Index of the result
215
+ * @returns Object with all properties
216
+ */
217
+ async getSearchResultAllProperties(results, index) {
218
+ const cacheKey = `search:all:${index}`;
219
+ if (this.resultCache.has(cacheKey)) {
220
+ return this.resultCache.get(cacheKey);
221
+ }
222
+ // Aggregate all properties by calling individual native functions
223
+ const context = this.native?.search_result_context?.(index, 50) ?? '';
224
+ const lineNumber = this.native?.search_result_line_number?.(index) ?? 0;
225
+ const paragraphNumber = this.native?.search_result_paragraph_number?.(index) ?? 0;
226
+ const confidence = this.native?.search_result_confidence?.(index) ?? 1.0;
227
+ const isHighlighted = this.native?.search_result_is_highlighted?.(index) ?? false;
228
+ const fontInfo = this.native?.search_result_font_info?.(index) ?? '{}';
229
+ let color = [0, 0, 0];
230
+ if (this.native?.search_result_color) {
231
+ try {
232
+ const colorJson = this.native.search_result_color(index);
233
+ const parsed = JSON.parse(colorJson);
234
+ color = [parsed.r ?? 0, parsed.g ?? 0, parsed.b ?? 0];
235
+ }
236
+ catch {
237
+ color = [0, 0, 0];
238
+ }
239
+ }
240
+ const rotation = this.native?.search_result_rotation?.(index) ?? 0;
241
+ const objectId = this.native?.search_result_object_id?.(index) ?? 0;
242
+ const streamIndex = this.native?.search_result_stream_index?.(index) ?? 0;
243
+ const props = {
244
+ context,
245
+ lineNumber,
246
+ paragraphNumber,
247
+ confidence,
248
+ isHighlighted,
249
+ fontInfo,
250
+ color,
251
+ rotation,
252
+ objectId,
253
+ streamIndex,
254
+ };
255
+ this.setCached(cacheKey, props);
256
+ this.emit('searchPropertiesExtracted', index);
257
+ return props;
258
+ }
259
+ // ========== Font Accessors (8 functions) ==========
260
+ /**
261
+ * Gets the base font name
262
+ * @param fonts Font handle
263
+ * @param index Index of the font
264
+ * @returns Font name (e.g., "Helvetica", "Arial")
265
+ */
266
+ async getFontBaseFontName(fonts, index) {
267
+ const cacheKey = `font:basename:${index}`;
268
+ if (this.resultCache.has(cacheKey)) {
269
+ return this.resultCache.get(cacheKey);
270
+ }
271
+ const name = this.native?.font_get_base_font_name?.(index) ?? '';
272
+ this.setCached(cacheKey, name);
273
+ return name;
274
+ }
275
+ /**
276
+ * Gets the font descriptor JSON
277
+ * Contains details about font metrics and characteristics
278
+ * @param fonts Font handle
279
+ * @param index Index of the font
280
+ * @returns Font descriptor as JSON string
281
+ */
282
+ async getFontDescriptor(fonts, index) {
283
+ const cacheKey = `font:descriptor:${index}`;
284
+ if (this.resultCache.has(cacheKey)) {
285
+ return this.resultCache.get(cacheKey);
286
+ }
287
+ const descriptor = this.native?.font_get_descriptor?.(index) ?? '{}';
288
+ this.setCached(cacheKey, descriptor);
289
+ return descriptor;
290
+ }
291
+ /**
292
+ * Gets the descendant font name (for composite fonts)
293
+ * @param fonts Font handle
294
+ * @param index Index of the font
295
+ * @returns Descendant font name or empty string
296
+ */
297
+ async getFontDescendantFont(fonts, index) {
298
+ const cacheKey = `font:descendant:${index}`;
299
+ if (this.resultCache.has(cacheKey)) {
300
+ return this.resultCache.get(cacheKey);
301
+ }
302
+ const descendant = this.native?.font_get_descendant_font?.(index) ?? '';
303
+ this.setCached(cacheKey, descendant);
304
+ return descendant;
305
+ }
306
+ /**
307
+ * Gets the ToUnicode CMap for character to Unicode mapping
308
+ * @param fonts Font handle
309
+ * @param index Index of the font
310
+ * @returns ToUnicode CMap as string
311
+ */
312
+ async getFontToUnicodeCmap(fonts, index) {
313
+ const cacheKey = `font:tounicode:${index}`;
314
+ if (this.resultCache.has(cacheKey)) {
315
+ return this.resultCache.get(cacheKey);
316
+ }
317
+ const cmap = this.native?.font_get_to_unicode_cmap?.(index) ?? '';
318
+ this.setCached(cacheKey, cmap);
319
+ return cmap;
320
+ }
321
+ /**
322
+ * Checks if font is vertical (top-to-bottom layout)
323
+ * @param fonts Font handle
324
+ * @param index Index of the font
325
+ * @returns True if font is vertical
326
+ */
327
+ async isFontVertical(fonts, index) {
328
+ const cacheKey = `font:isvertical:${index}`;
329
+ if (this.resultCache.has(cacheKey)) {
330
+ return this.resultCache.get(cacheKey);
331
+ }
332
+ const vertical = this.native?.font_is_vertical?.(index) ?? false;
333
+ this.setCached(cacheKey, vertical);
334
+ return vertical;
335
+ }
336
+ /**
337
+ * Gets character widths for the font
338
+ * @param fonts Font handle
339
+ * @param index Index of the font
340
+ * @returns Array of character widths
341
+ */
342
+ async getFontWidths(fonts, index) {
343
+ const cacheKey = `font:widths:${index}`;
344
+ if (this.resultCache.has(cacheKey)) {
345
+ return this.resultCache.get(cacheKey);
346
+ }
347
+ const widths = this.native?.font_get_widths?.(index) ?? new Float32Array();
348
+ this.setCached(cacheKey, widths);
349
+ return widths;
350
+ }
351
+ /**
352
+ * Gets the ascender metric (height above baseline)
353
+ * @param fonts Font handle
354
+ * @param index Index of the font
355
+ * @returns Ascender value in font units
356
+ */
357
+ async getFontAscender(fonts, index) {
358
+ const cacheKey = `font:ascender:${index}`;
359
+ if (this.resultCache.has(cacheKey)) {
360
+ return this.resultCache.get(cacheKey);
361
+ }
362
+ const ascender = this.native?.font_get_ascender?.(index) ?? 0;
363
+ this.setCached(cacheKey, ascender);
364
+ return ascender;
365
+ }
366
+ /**
367
+ * Gets the descender metric (depth below baseline)
368
+ * @param fonts Font handle
369
+ * @param index Index of the font
370
+ * @returns Descender value in font units (usually negative)
371
+ */
372
+ async getFontDescender(fonts, index) {
373
+ const cacheKey = `font:descender:${index}`;
374
+ if (this.resultCache.has(cacheKey)) {
375
+ return this.resultCache.get(cacheKey);
376
+ }
377
+ const descender = this.native?.font_get_descender?.(index) ?? 0;
378
+ this.setCached(cacheKey, descender);
379
+ return descender;
380
+ }
381
+ /**
382
+ * Gets all font properties at once
383
+ * More efficient than individual property calls
384
+ * @param fonts Font handle
385
+ * @param index Index of the font
386
+ * @returns Object with all font properties
387
+ */
388
+ async getFontAllProperties(fonts, index) {
389
+ const cacheKey = `font:all:${index}`;
390
+ if (this.resultCache.has(cacheKey)) {
391
+ return this.resultCache.get(cacheKey);
392
+ }
393
+ // Aggregate all font properties by calling individual native functions
394
+ const baseFontName = this.native?.font_get_base_font_name?.(index) ?? '';
395
+ const descriptor = this.native?.font_get_descriptor?.(index) ?? '{}';
396
+ const descendantFont = this.native?.font_get_descendant_font?.(index) ?? '';
397
+ const toUnicodeCmap = this.native?.font_get_to_unicode_cmap?.(index) ?? '';
398
+ const isVertical = this.native?.font_is_vertical?.(index) ?? false;
399
+ const widths = this.native?.font_get_widths?.(index) ?? new Float32Array();
400
+ const ascender = this.native?.font_get_ascender?.(index) ?? 0;
401
+ const descender = this.native?.font_get_descender?.(index) ?? 0;
402
+ const props = {
403
+ baseFontName,
404
+ descriptor,
405
+ descendantFont,
406
+ toUnicodeCmap,
407
+ isVertical,
408
+ widths,
409
+ ascender,
410
+ descender,
411
+ };
412
+ this.setCached(cacheKey, props);
413
+ this.emit('fontPropertiesExtracted', index);
414
+ return props;
415
+ }
416
+ // ========== Image Accessors (5 functions) ==========
417
+ /**
418
+ * Checks if image has an alpha channel
419
+ * @param images Image handle
420
+ * @param index Index of the image
421
+ * @returns True if alpha channel is present
422
+ */
423
+ async hasImageAlphaChannel(images, index) {
424
+ const cacheKey = `image:hasalpha:${index}`;
425
+ if (this.resultCache.has(cacheKey)) {
426
+ return this.resultCache.get(cacheKey);
427
+ }
428
+ const hasAlpha = this.native?.image_has_alpha_channel?.(index) ?? false;
429
+ this.setCached(cacheKey, hasAlpha);
430
+ return hasAlpha;
431
+ }
432
+ /**
433
+ * Gets the ICC color profile
434
+ * @param images Image handle
435
+ * @param index Index of the image
436
+ * @returns ICC profile as binary data
437
+ */
438
+ async getImageIccProfile(images, index) {
439
+ const cacheKey = `image:iccprofile:${index}`;
440
+ if (this.resultCache.has(cacheKey)) {
441
+ return this.resultCache.get(cacheKey);
442
+ }
443
+ const profile = this.native?.image_get_icc_profile?.(index) ?? new Uint8Array();
444
+ this.setCached(cacheKey, profile);
445
+ return profile;
446
+ }
447
+ /**
448
+ * Gets the filter chain applied to the image
449
+ * (e.g., ["FlateDecode", "DCTDecode"])
450
+ * @param images Image handle
451
+ * @param index Index of the image
452
+ * @returns Filter chain as JSON string
453
+ */
454
+ async getImageFilterChain(images, index) {
455
+ const cacheKey = `image:filterchain:${index}`;
456
+ if (this.resultCache.has(cacheKey)) {
457
+ return this.resultCache.get(cacheKey);
458
+ }
459
+ const filterChain = this.native?.image_get_filter_chain?.(index) ?? '[]';
460
+ this.setCached(cacheKey, filterChain);
461
+ return filterChain;
462
+ }
463
+ /**
464
+ * Gets the decoded image data
465
+ * @param images Image handle
466
+ * @param index Index of the image
467
+ * @returns Decoded image data as binary
468
+ */
469
+ async getImageDecodedData(images, index) {
470
+ const cacheKey = `image:decoded:${index}`;
471
+ if (this.resultCache.has(cacheKey)) {
472
+ return this.resultCache.get(cacheKey);
473
+ }
474
+ const data = this.native?.image_get_decoded_data?.(index) ?? new Uint8Array();
475
+ this.setCached(cacheKey, data);
476
+ return data;
477
+ }
478
+ /**
479
+ * Gets the image width in pixels
480
+ * @param images Image handle
481
+ * @param index Index of the image
482
+ * @returns Width in pixels
483
+ */
484
+ async getImageWidth(images, index) {
485
+ const cacheKey = `image:width:${index}`;
486
+ if (this.resultCache.has(cacheKey)) {
487
+ return this.resultCache.get(cacheKey);
488
+ }
489
+ const width = this.native?.image_get_width?.(index) ?? 0;
490
+ this.setCached(cacheKey, width);
491
+ return width;
492
+ }
493
+ /**
494
+ * Gets the image height in pixels
495
+ * @param images Image handle
496
+ * @param index Index of the image
497
+ * @returns Height in pixels
498
+ */
499
+ async getImageHeight(images, index) {
500
+ const cacheKey = `image:height:${index}`;
501
+ if (this.resultCache.has(cacheKey)) {
502
+ return this.resultCache.get(cacheKey);
503
+ }
504
+ const height = this.native?.image_get_height?.(index) ?? 0;
505
+ this.setCached(cacheKey, height);
506
+ return height;
507
+ }
508
+ /**
509
+ * Gets the color space of the image
510
+ * @param images Image handle
511
+ * @param index Index of the image
512
+ * @returns Color space name (e.g., "RGB", "CMYK", "Gray")
513
+ */
514
+ async getImageColorSpace(images, index) {
515
+ const cacheKey = `image:colorspace:${index}`;
516
+ if (this.resultCache.has(cacheKey)) {
517
+ return this.resultCache.get(cacheKey);
518
+ }
519
+ const colorSpace = this.native?.image_get_color_space?.(index) ?? 'RGB';
520
+ this.setCached(cacheKey, colorSpace);
521
+ return colorSpace;
522
+ }
523
+ /**
524
+ * Gets all image properties at once
525
+ * More efficient than individual property calls
526
+ * @param images Image handle
527
+ * @param index Index of the image
528
+ * @returns Object with all image properties
529
+ */
530
+ async getImageAllProperties(images, index) {
531
+ const cacheKey = `image:all:${index}`;
532
+ if (this.resultCache.has(cacheKey)) {
533
+ return this.resultCache.get(cacheKey);
534
+ }
535
+ // Aggregate all image properties by calling individual native functions
536
+ const hasAlphaChannel = this.native?.image_has_alpha_channel?.(index) ?? false;
537
+ const iccProfile = this.native?.image_get_icc_profile?.(index) ?? new Uint8Array();
538
+ const filterChain = this.native?.image_get_filter_chain?.(index) ?? '[]';
539
+ const decodedData = this.native?.image_get_decoded_data?.(index) ?? new Uint8Array();
540
+ const width = this.native?.image_get_width?.(index) ?? 0;
541
+ const height = this.native?.image_get_height?.(index) ?? 0;
542
+ const colorSpace = this.native?.image_get_color_space?.(index) ?? 'RGB';
543
+ const props = {
544
+ hasAlphaChannel,
545
+ iccProfile,
546
+ filterChain,
547
+ decodedData,
548
+ width,
549
+ height,
550
+ colorSpace,
551
+ };
552
+ this.setCached(cacheKey, props);
553
+ this.emit('imagePropertiesExtracted', index);
554
+ return props;
555
+ }
556
+ // ========== Annotation Accessors (6 functions) ==========
557
+ /**
558
+ * Gets the modified date of an annotation
559
+ * @param annotations Annotation handle
560
+ * @param index Index of the annotation
561
+ * @returns Timestamp in milliseconds
562
+ */
563
+ async getAnnotationModifiedDate(annotations, index) {
564
+ const cacheKey = `annotation:modifieddate:${index}`;
565
+ if (this.resultCache.has(cacheKey)) {
566
+ return this.resultCache.get(cacheKey);
567
+ }
568
+ const timestamp = this.native?.annotation_get_modified_date?.(index) ?? 0;
569
+ this.setCached(cacheKey, timestamp);
570
+ return timestamp;
571
+ }
572
+ /**
573
+ * Gets the subject/title of an annotation
574
+ * @param annotations Annotation handle
575
+ * @param index Index of the annotation
576
+ * @returns Subject text
577
+ */
578
+ async getAnnotationSubject(annotations, index) {
579
+ const cacheKey = `annotation:subject:${index}`;
580
+ if (this.resultCache.has(cacheKey)) {
581
+ return this.resultCache.get(cacheKey);
582
+ }
583
+ const subject = this.native?.annotation_get_subject?.(index) ?? '';
584
+ this.setCached(cacheKey, subject);
585
+ return subject;
586
+ }
587
+ /**
588
+ * Gets the index of the annotation this is replying to
589
+ * @param annotations Annotation handle
590
+ * @param index Index of the annotation
591
+ * @returns Index of parent annotation, or -1 if not a reply
592
+ */
593
+ async getAnnotationReplyToIndex(annotations, index) {
594
+ const cacheKey = `annotation:replyto:${index}`;
595
+ if (this.resultCache.has(cacheKey)) {
596
+ return this.resultCache.get(cacheKey);
597
+ }
598
+ const replyToIndex = this.native?.annotation_get_reply_to?.(index) ?? -1;
599
+ this.setCached(cacheKey, replyToIndex);
600
+ return replyToIndex;
601
+ }
602
+ /**
603
+ * Gets the page number where annotation appears
604
+ * @param annotations Annotation handle
605
+ * @param index Index of the annotation
606
+ * @returns Page number (0-based)
607
+ */
608
+ async getAnnotationPageNumber(annotations, index) {
609
+ const cacheKey = `annotation:pagenum:${index}`;
610
+ if (this.resultCache.has(cacheKey)) {
611
+ return this.resultCache.get(cacheKey);
612
+ }
613
+ const pageNumber = this.native?.annotation_get_page_number?.(index) ?? 0;
614
+ this.setCached(cacheKey, pageNumber);
615
+ return pageNumber;
616
+ }
617
+ /**
618
+ * Gets the icon name for the annotation
619
+ * (e.g., "Comment", "Note", "Help")
620
+ * @param annotations Annotation handle
621
+ * @param index Index of the annotation
622
+ * @returns Icon name
623
+ */
624
+ async getAnnotationIconName(annotations, index) {
625
+ const cacheKey = `annotation:icon:${index}`;
626
+ if (this.resultCache.has(cacheKey)) {
627
+ return this.resultCache.get(cacheKey);
628
+ }
629
+ const icon = this.native?.annotation_get_icon_name?.(index) ?? '';
630
+ this.setCached(cacheKey, icon);
631
+ return icon;
632
+ }
633
+ /**
634
+ * Gets the author/creator of the annotation
635
+ * @param annotations Annotation handle
636
+ * @param index Index of the annotation
637
+ * @returns Author name
638
+ */
639
+ async getAnnotationAuthor(annotations, index) {
640
+ const cacheKey = `annotation:author:${index}`;
641
+ if (this.resultCache.has(cacheKey)) {
642
+ return this.resultCache.get(cacheKey);
643
+ }
644
+ const author = this.native?.annotation_get_author?.(index) ?? '';
645
+ this.setCached(cacheKey, author);
646
+ return author;
647
+ }
648
+ /**
649
+ * Gets all annotation properties at once
650
+ * More efficient than individual property calls
651
+ * @param annotations Annotation handle
652
+ * @param index Index of the annotation
653
+ * @returns Object with all annotation properties
654
+ */
655
+ async getAnnotationAllProperties(annotations, index) {
656
+ const cacheKey = `annotation:all:${index}`;
657
+ if (this.resultCache.has(cacheKey)) {
658
+ return this.resultCache.get(cacheKey);
659
+ }
660
+ // Aggregate all annotation properties by calling individual native functions
661
+ const modifiedDate = this.native?.annotation_get_modified_date?.(index) ?? 0;
662
+ const subject = this.native?.annotation_get_subject?.(index) ?? '';
663
+ const replyToIndex = this.native?.annotation_get_reply_to?.(index) ?? -1;
664
+ const pageNumber = this.native?.annotation_get_page_number?.(index) ?? 0;
665
+ const iconName = this.native?.annotation_get_icon_name?.(index) ?? '';
666
+ const author = this.native?.annotation_get_author?.(index) ?? '';
667
+ const props = {
668
+ modifiedDate,
669
+ subject,
670
+ replyToIndex,
671
+ pageNumber,
672
+ iconName,
673
+ author,
674
+ };
675
+ this.setCached(cacheKey, props);
676
+ this.emit('annotationPropertiesExtracted', index);
677
+ return props;
678
+ }
679
+ // ========== Cache Management ==========
680
+ /**
681
+ * Clears the result cache
682
+ */
683
+ clearCache() {
684
+ this.resultCache.clear();
685
+ this.emit('cacheCleared');
686
+ }
687
+ /**
688
+ * Gets cache statistics
689
+ * @returns Object with cache information
690
+ */
691
+ getCacheStats() {
692
+ return {
693
+ cacheSize: this.resultCache.size,
694
+ maxCacheSize: this.maxCacheSize,
695
+ entries: Array.from(this.resultCache.keys()),
696
+ };
697
+ }
698
+ clearCachePattern(pattern) {
699
+ const regex = new RegExp(pattern);
700
+ const keysToDelete = Array.from(this.resultCache.keys()).filter((key) => regex.test(key));
701
+ keysToDelete.forEach((key) => this.resultCache.delete(key));
702
+ }
703
+ }
704
+ export default ResultAccessorsManager;
705
+ //# sourceMappingURL=result-accessors-manager.js.map