@effortlessmotion/pdf-to-md 0.1.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.
Files changed (189) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +157 -0
  3. package/bin/cli.js +9 -0
  4. package/dist/cjs/analyze.d.cts +35 -0
  5. package/dist/cjs/analyze.d.ts +35 -0
  6. package/dist/cjs/analyze.js +620 -0
  7. package/dist/cjs/analyze.js.map +1 -0
  8. package/dist/cjs/audit.d.cts +38 -0
  9. package/dist/cjs/audit.d.ts +38 -0
  10. package/dist/cjs/audit.js +252 -0
  11. package/dist/cjs/audit.js.map +1 -0
  12. package/dist/cjs/cli/audit.d.cts +3 -0
  13. package/dist/cjs/cli/audit.d.ts +3 -0
  14. package/dist/cjs/cli/audit.js +269 -0
  15. package/dist/cjs/cli/audit.js.map +1 -0
  16. package/dist/cjs/cli/extract.d.cts +3 -0
  17. package/dist/cjs/cli/extract.d.ts +3 -0
  18. package/dist/cjs/cli/extract.js +704 -0
  19. package/dist/cjs/cli/extract.js.map +1 -0
  20. package/dist/cjs/cli/index.d.cts +5 -0
  21. package/dist/cjs/cli/index.d.ts +5 -0
  22. package/dist/cjs/cli/index.js +58 -0
  23. package/dist/cjs/cli/index.js.map +1 -0
  24. package/dist/cjs/cli/render.d.cts +3 -0
  25. package/dist/cjs/cli/render.d.ts +3 -0
  26. package/dist/cjs/cli/render.js +361 -0
  27. package/dist/cjs/cli/render.js.map +1 -0
  28. package/dist/cjs/cli/types.d.cts +10 -0
  29. package/dist/cjs/cli/types.d.ts +10 -0
  30. package/dist/cjs/cli/types.js +7 -0
  31. package/dist/cjs/cli/types.js.map +1 -0
  32. package/dist/cjs/cli.d.cts +2 -0
  33. package/dist/cjs/cli.d.ts +2 -0
  34. package/dist/cjs/cli.js +345 -0
  35. package/dist/cjs/cli.js.map +1 -0
  36. package/dist/cjs/collect.d.cts +6 -0
  37. package/dist/cjs/collect.d.ts +6 -0
  38. package/dist/cjs/collect.js +370 -0
  39. package/dist/cjs/collect.js.map +1 -0
  40. package/dist/cjs/dict.d.cts +8 -0
  41. package/dist/cjs/dict.d.ts +8 -0
  42. package/dist/cjs/dict.js +55 -0
  43. package/dist/cjs/dict.js.map +1 -0
  44. package/dist/cjs/emit.d.cts +27 -0
  45. package/dist/cjs/emit.d.ts +27 -0
  46. package/dist/cjs/emit.js +187 -0
  47. package/dist/cjs/emit.js.map +1 -0
  48. package/dist/cjs/engines/tesseract.d.cts +30 -0
  49. package/dist/cjs/engines/tesseract.d.ts +30 -0
  50. package/dist/cjs/engines/tesseract.js +650 -0
  51. package/dist/cjs/engines/tesseract.js.map +1 -0
  52. package/dist/cjs/errors.d.cts +21 -0
  53. package/dist/cjs/errors.d.ts +21 -0
  54. package/dist/cjs/errors.js +124 -0
  55. package/dist/cjs/errors.js.map +1 -0
  56. package/dist/cjs/extract.d.cts +88 -0
  57. package/dist/cjs/extract.d.ts +88 -0
  58. package/dist/cjs/extract.js +436 -0
  59. package/dist/cjs/extract.js.map +1 -0
  60. package/dist/cjs/geometry.d.cts +63 -0
  61. package/dist/cjs/geometry.d.ts +63 -0
  62. package/dist/cjs/geometry.js +521 -0
  63. package/dist/cjs/geometry.js.map +1 -0
  64. package/dist/cjs/index.d.cts +15 -0
  65. package/dist/cjs/index.d.ts +15 -0
  66. package/dist/cjs/index.js +56 -0
  67. package/dist/cjs/index.js.map +1 -0
  68. package/dist/cjs/lines.d.cts +3 -0
  69. package/dist/cjs/lines.d.ts +3 -0
  70. package/dist/cjs/lines.js +181 -0
  71. package/dist/cjs/lines.js.map +1 -0
  72. package/dist/cjs/markdown.d.cts +2 -0
  73. package/dist/cjs/markdown.d.ts +2 -0
  74. package/dist/cjs/markdown.js +222 -0
  75. package/dist/cjs/markdown.js.map +1 -0
  76. package/dist/cjs/package.json +1 -0
  77. package/dist/cjs/page-marker.d.cts +16 -0
  78. package/dist/cjs/page-marker.d.ts +16 -0
  79. package/dist/cjs/page-marker.js +85 -0
  80. package/dist/cjs/page-marker.js.map +1 -0
  81. package/dist/cjs/pdf-open.d.cts +12 -0
  82. package/dist/cjs/pdf-open.d.ts +12 -0
  83. package/dist/cjs/pdf-open.js +257 -0
  84. package/dist/cjs/pdf-open.js.map +1 -0
  85. package/dist/cjs/raster.d.cts +26 -0
  86. package/dist/cjs/raster.d.ts +26 -0
  87. package/dist/cjs/raster.js +262 -0
  88. package/dist/cjs/raster.js.map +1 -0
  89. package/dist/cjs/render-analysis.d.cts +25 -0
  90. package/dist/cjs/render-analysis.d.ts +25 -0
  91. package/dist/cjs/render-analysis.js +319 -0
  92. package/dist/cjs/render-analysis.js.map +1 -0
  93. package/dist/cjs/report.d.cts +12 -0
  94. package/dist/cjs/report.d.ts +12 -0
  95. package/dist/cjs/report.js +392 -0
  96. package/dist/cjs/report.js.map +1 -0
  97. package/dist/cjs/resolve.d.cts +1 -0
  98. package/dist/cjs/resolve.d.ts +1 -0
  99. package/dist/cjs/resolve.js +18 -0
  100. package/dist/cjs/resolve.js.map +1 -0
  101. package/dist/cjs/types.d.cts +171 -0
  102. package/dist/cjs/types.d.ts +171 -0
  103. package/dist/cjs/types.js +9 -0
  104. package/dist/cjs/types.js.map +1 -0
  105. package/dist/cjs/validate.d.cts +14 -0
  106. package/dist/cjs/validate.d.ts +14 -0
  107. package/dist/cjs/validate.js +96 -0
  108. package/dist/cjs/validate.js.map +1 -0
  109. package/dist/esm/analyze.d.ts +35 -0
  110. package/dist/esm/analyze.js +270 -0
  111. package/dist/esm/analyze.js.map +1 -0
  112. package/dist/esm/audit.d.ts +38 -0
  113. package/dist/esm/audit.js +113 -0
  114. package/dist/esm/audit.js.map +1 -0
  115. package/dist/esm/cli/audit.d.ts +3 -0
  116. package/dist/esm/cli/audit.js +20 -0
  117. package/dist/esm/cli/audit.js.map +1 -0
  118. package/dist/esm/cli/extract.d.ts +3 -0
  119. package/dist/esm/cli/extract.js +313 -0
  120. package/dist/esm/cli/extract.js.map +1 -0
  121. package/dist/esm/cli/index.d.ts +5 -0
  122. package/dist/esm/cli/index.js +7 -0
  123. package/dist/esm/cli/index.js.map +1 -0
  124. package/dist/esm/cli/render.d.ts +3 -0
  125. package/dist/esm/cli/render.js +77 -0
  126. package/dist/esm/cli/render.js.map +1 -0
  127. package/dist/esm/cli/types.d.ts +10 -0
  128. package/dist/esm/cli/types.js +3 -0
  129. package/dist/esm/cli/types.js.map +1 -0
  130. package/dist/esm/cli.d.ts +2 -0
  131. package/dist/esm/cli.js +90 -0
  132. package/dist/esm/cli.js.map +1 -0
  133. package/dist/esm/collect.d.ts +6 -0
  134. package/dist/esm/collect.js +80 -0
  135. package/dist/esm/collect.js.map +1 -0
  136. package/dist/esm/dict.d.ts +8 -0
  137. package/dist/esm/dict.js +28 -0
  138. package/dist/esm/dict.js.map +1 -0
  139. package/dist/esm/emit.d.ts +27 -0
  140. package/dist/esm/emit.js +131 -0
  141. package/dist/esm/emit.js.map +1 -0
  142. package/dist/esm/engines/tesseract.d.ts +30 -0
  143. package/dist/esm/engines/tesseract.js +190 -0
  144. package/dist/esm/engines/tesseract.js.map +1 -0
  145. package/dist/esm/errors.d.ts +21 -0
  146. package/dist/esm/errors.js +9 -0
  147. package/dist/esm/errors.js.map +1 -0
  148. package/dist/esm/extract.d.ts +88 -0
  149. package/dist/esm/extract.js +147 -0
  150. package/dist/esm/extract.js.map +1 -0
  151. package/dist/esm/geometry.d.ts +63 -0
  152. package/dist/esm/geometry.js +279 -0
  153. package/dist/esm/geometry.js.map +1 -0
  154. package/dist/esm/index.d.ts +15 -0
  155. package/dist/esm/index.js +10 -0
  156. package/dist/esm/index.js.map +1 -0
  157. package/dist/esm/lines.d.ts +3 -0
  158. package/dist/esm/lines.js +67 -0
  159. package/dist/esm/lines.js.map +1 -0
  160. package/dist/esm/markdown.d.ts +2 -0
  161. package/dist/esm/markdown.js +153 -0
  162. package/dist/esm/markdown.js.map +1 -0
  163. package/dist/esm/package.json +1 -0
  164. package/dist/esm/page-marker.d.ts +16 -0
  165. package/dist/esm/page-marker.js +40 -0
  166. package/dist/esm/page-marker.js.map +1 -0
  167. package/dist/esm/pdf-open.d.ts +12 -0
  168. package/dist/esm/pdf-open.js +61 -0
  169. package/dist/esm/pdf-open.js.map +1 -0
  170. package/dist/esm/raster.d.ts +26 -0
  171. package/dist/esm/raster.js +60 -0
  172. package/dist/esm/raster.js.map +1 -0
  173. package/dist/esm/render-analysis.d.ts +25 -0
  174. package/dist/esm/render-analysis.js +115 -0
  175. package/dist/esm/render-analysis.js.map +1 -0
  176. package/dist/esm/report.d.ts +12 -0
  177. package/dist/esm/report.js +182 -0
  178. package/dist/esm/report.js.map +1 -0
  179. package/dist/esm/resolve.d.ts +1 -0
  180. package/dist/esm/resolve.js +7 -0
  181. package/dist/esm/resolve.js.map +1 -0
  182. package/dist/esm/types.d.ts +171 -0
  183. package/dist/esm/types.js +6 -0
  184. package/dist/esm/types.js.map +1 -0
  185. package/dist/esm/validate.d.ts +14 -0
  186. package/dist/esm/validate.js +56 -0
  187. package/dist/esm/validate.js.map +1 -0
  188. package/package.json +67 -0
  189. package/skills/pdf-to-md/SKILL.md +102 -0
@@ -0,0 +1,392 @@
1
+ // report.ts — QA report over an extraction, machine-readable with --json.
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ function _export(target, all) {
7
+ for(var name in all)Object.defineProperty(target, name, {
8
+ enumerable: true,
9
+ get: Object.getOwnPropertyDescriptor(all, name).get
10
+ });
11
+ }
12
+ _export(exports, {
13
+ get AUTO_OCR_CHARS_PER_PAGE () {
14
+ return AUTO_OCR_CHARS_PER_PAGE;
15
+ },
16
+ get LOW_CONFIDENCE_SAMPLE_CAP () {
17
+ return LOW_CONFIDENCE_SAMPLE_CAP;
18
+ },
19
+ get LOW_CONFIDENCE_THRESHOLD () {
20
+ return LOW_CONFIDENCE_THRESHOLD;
21
+ },
22
+ get OUTPUT_VERSION () {
23
+ return OUTPUT_VERSION;
24
+ },
25
+ get SPARSE_CHARS_PER_PAGE () {
26
+ return SPARSE_CHARS_PER_PAGE;
27
+ },
28
+ get buildOcrReport () {
29
+ return buildOcrReport;
30
+ },
31
+ get buildReport () {
32
+ return buildReport;
33
+ }
34
+ });
35
+ var _pagemarkerts = require("./page-marker.js");
36
+ function _array_like_to_array(arr, len) {
37
+ if (len == null || len > arr.length) len = arr.length;
38
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
39
+ return arr2;
40
+ }
41
+ function _array_with_holes(arr) {
42
+ if (Array.isArray(arr)) return arr;
43
+ }
44
+ function _define_property(obj, key, value) {
45
+ if (key in obj) {
46
+ Object.defineProperty(obj, key, {
47
+ value: value,
48
+ enumerable: true,
49
+ configurable: true,
50
+ writable: true
51
+ });
52
+ } else obj[key] = value;
53
+ return obj;
54
+ }
55
+ function _iterable_to_array_limit(arr, i) {
56
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
57
+ if (_i == null) return;
58
+ var _arr = [];
59
+ var _n = true;
60
+ var _d = false;
61
+ var _s, _e;
62
+ try {
63
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
64
+ _arr.push(_s.value);
65
+ if (i && _arr.length === i) break;
66
+ }
67
+ } catch (err) {
68
+ _d = true;
69
+ _e = err;
70
+ } finally{
71
+ try {
72
+ if (!_n && _i["return"] != null) _i["return"]();
73
+ } finally{
74
+ if (_d) throw _e;
75
+ }
76
+ }
77
+ return _arr;
78
+ }
79
+ function _non_iterable_rest() {
80
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
81
+ }
82
+ function _object_spread(target) {
83
+ for(var i = 1; i < arguments.length; i++){
84
+ var source = arguments[i] != null ? arguments[i] : {};
85
+ var ownKeys = Object.keys(source);
86
+ if (typeof Object.getOwnPropertySymbols === "function") {
87
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
88
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
89
+ }));
90
+ }
91
+ ownKeys.forEach(function(key) {
92
+ _define_property(target, key, source[key]);
93
+ });
94
+ }
95
+ return target;
96
+ }
97
+ function _sliced_to_array(arr, i) {
98
+ return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
99
+ }
100
+ function _unsupported_iterable_to_array(o, minLen) {
101
+ if (!o) return;
102
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
103
+ var n = Object.prototype.toString.call(o).slice(8, -1);
104
+ if (n === "Object" && o.constructor) n = o.constructor.name;
105
+ if (n === "Map" || n === "Set") return Array.from(n);
106
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
107
+ }
108
+ var SPARSE_CHARS_PER_PAGE = 200;
109
+ var AUTO_OCR_CHARS_PER_PAGE = 20;
110
+ var OUTPUT_VERSION = 1;
111
+ // A body paragraph line may end in sentence/clause punctuation, a closing
112
+ // quote/bracket, an ellipsis, or a digit (chart/label lines like "1/3" legitimately end in a number).
113
+ var TERMINAL_PUNCT = /[.!?:;"”'’)\]…0-9]$/;
114
+ // Lines that are not body prose at all: headings (incl. "### pN" markers),
115
+ // floats/blockquotes, table rows, and list items — excluded before TERMINAL_PUNCT runs.
116
+ var NON_PROSE_LINE = /^[#>|*-]/;
117
+ // A `> [review: reason] text` line (src/emit.ts). Shared by pageStats (per
118
+ // page) and both top-level report builders (whole doc) so the counts can't drift apart.
119
+ var REVIEW_LINE = /^> \[review: /gm;
120
+ // Dangling lines split by length: long ones are the invisible column-break/splice
121
+ // signal; short ones are usually a missed heading or an unjoined label.
122
+ var DANGLING_LONG_MIN = 60;
123
+ var LOW_CONFIDENCE_THRESHOLD = 60;
124
+ var LOW_CONFIDENCE_SAMPLE_CAP = 12;
125
+ // Grouped from the flat recognized-word list (confidence is per-word, never
126
+ // merged into a line — see Word's comment). `measured` is tracked separately from `low` so a page with nothing to measure reports ABSENT, not a lying zero.
127
+ function lowConfidenceByPage(words) {
128
+ var byPage = new Map();
129
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
130
+ try {
131
+ for(var _iterator = words[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
132
+ var w = _step.value;
133
+ var _byPage_get;
134
+ if (w.confidence === undefined) continue;
135
+ var entry = (_byPage_get = byPage.get(w.page)) !== null && _byPage_get !== void 0 ? _byPage_get : {
136
+ measured: 0,
137
+ low: 0,
138
+ lowWords: []
139
+ };
140
+ entry.measured++;
141
+ if (w.confidence < LOW_CONFIDENCE_THRESHOLD) {
142
+ entry.low++;
143
+ entry.lowWords.push({
144
+ text: w.text,
145
+ confidence: w.confidence
146
+ });
147
+ }
148
+ byPage.set(w.page, entry);
149
+ }
150
+ } catch (err) {
151
+ _didIteratorError = true;
152
+ _iteratorError = err;
153
+ } finally{
154
+ try {
155
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
156
+ _iterator.return();
157
+ }
158
+ } finally{
159
+ if (_didIteratorError) {
160
+ throw _iteratorError;
161
+ }
162
+ }
163
+ }
164
+ var result = new Map();
165
+ var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
166
+ try {
167
+ for(var _iterator1 = byPage[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
168
+ var _step_value = _sliced_to_array(_step1.value, 2), page = _step_value[0], entry1 = _step_value[1];
169
+ // Sort ascending by confidence BEFORE capping, so the cap keeps the
170
+ // worst offenders regardless of appearance order.
171
+ var sample = entry1.lowWords.slice().sort(function(a, b) {
172
+ return a.confidence - b.confidence;
173
+ }).slice(0, LOW_CONFIDENCE_SAMPLE_CAP).map(function(w) {
174
+ return w.text;
175
+ });
176
+ result.set(page, {
177
+ measured: entry1.measured,
178
+ low: entry1.low,
179
+ sample: sample
180
+ });
181
+ }
182
+ } catch (err) {
183
+ _didIteratorError1 = true;
184
+ _iteratorError1 = err;
185
+ } finally{
186
+ try {
187
+ if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
188
+ _iterator1.return();
189
+ }
190
+ } finally{
191
+ if (_didIteratorError1) {
192
+ throw _iteratorError1;
193
+ }
194
+ }
195
+ }
196
+ return result;
197
+ }
198
+ // Counts of body paragraph LINES ending WITHOUT terminal punctuation, split
199
+ // by length: `long` is the invisible column-break/splice signal; `short` is usually a missed heading or unjoined label.
200
+ function danglingCounts(body) {
201
+ var long = 0;
202
+ var short = 0;
203
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
204
+ try {
205
+ for(var _iterator = body.split('\n')[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
206
+ var raw = _step.value;
207
+ var line = raw.trim();
208
+ if (!line || NON_PROSE_LINE.test(line)) continue;
209
+ if (TERMINAL_PUNCT.test(line)) continue;
210
+ if (line.length >= DANGLING_LONG_MIN) long++;
211
+ else short++;
212
+ }
213
+ } catch (err) {
214
+ _didIteratorError = true;
215
+ _iteratorError = err;
216
+ } finally{
217
+ try {
218
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
219
+ _iterator.return();
220
+ }
221
+ } finally{
222
+ if (_didIteratorError) {
223
+ throw _iteratorError;
224
+ }
225
+ }
226
+ }
227
+ return {
228
+ long: long,
229
+ short: short
230
+ };
231
+ }
232
+ // One page's own measured stats, derivable from its body text alone —
233
+ // shared by `pageStats` and any future caller that already has a page's body text in hand.
234
+ function measurePage(body) {
235
+ var heads = body.match(/^#{1,6}\s*(.+)$/gm) || [];
236
+ var dangling = danglingCounts(body);
237
+ return {
238
+ chars: body.length,
239
+ headings: heads.length,
240
+ junkHeadings: heads.filter(function(h) {
241
+ return !/[A-Za-z]{3}/.test(h);
242
+ }).length,
243
+ floats: (body.match(/^> \[floats\]/gm) || []).length,
244
+ paragraphs: (body.match(/^(?![#>-])\S.*$/gm) || []).length,
245
+ danglingLong: dangling.long,
246
+ danglingShort: dangling.short,
247
+ reviewBlocks: (body.match(REVIEW_LINE) || []).length
248
+ };
249
+ }
250
+ // Per-page QA rows, one per "### pN" block. The text path always passes
251
+ // markdown with markers forced on (`statsMd`) regardless of `--page-markers`, so pageStats is always populated.
252
+ //
253
+ // `hybridPages` (text path only) marks a row `largeImages: true` when that
254
+ // page used its text layer but also carries a large embedded image; omitted entirely on the OCR path, which has no equivalent signal.
255
+ function pageStats(md, hybridPages) {
256
+ var rows = [];
257
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
258
+ try {
259
+ for(var _iterator = (0, _pagemarkerts.splitByPageMarker)(md)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
260
+ var _step_value = _step.value, page = _step_value.page, body = _step_value.body;
261
+ var row = _object_spread({
262
+ page: page
263
+ }, measurePage(body));
264
+ if (hybridPages) row.largeImages = hybridPages.includes(page);
265
+ rows.push(row);
266
+ }
267
+ } catch (err) {
268
+ _didIteratorError = true;
269
+ _iteratorError = err;
270
+ } finally{
271
+ try {
272
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
273
+ _iterator.return();
274
+ }
275
+ } finally{
276
+ if (_didIteratorError) {
277
+ throw _iteratorError;
278
+ }
279
+ }
280
+ }
281
+ return rows;
282
+ }
283
+ function buildReport(param) {
284
+ var numPages = param.numPages, md = param.md, statsMd = param.statsMd, stats = param.stats, bodyH = param.bodyH, headingSizes = param.headingSizes, _param_hybridPages = param.hybridPages, hybridPages = _param_hybridPages === void 0 ? [] : _param_hybridPages;
285
+ var heads = (md.match(/^#{1,6}\s*(.+)$/gm) || []).filter(function(h) {
286
+ return !(0, _pagemarkerts.isPageMarkerLine)(h);
287
+ }); // page markers are provenance, not structure
288
+ var perPage = Math.round(md.length / numPages);
289
+ var perPageStats = pageStats(statsMd, hybridPages);
290
+ return {
291
+ outputVersion: OUTPUT_VERSION,
292
+ path: 'text',
293
+ pages: numPages,
294
+ bodyFontHeight: bodyH,
295
+ headingSizes: headingSizes.slice(0, 6),
296
+ chars: md.length,
297
+ charsPerPage: perPage,
298
+ sparse: perPage < SPARSE_CHARS_PER_PAGE,
299
+ headings: heads.length,
300
+ junkHeadings: heads.filter(function(h) {
301
+ return !/[A-Za-z]{3}/.test(h);
302
+ }).length,
303
+ listItems: stats.listItems,
304
+ paragraphs: stats.paragraphs,
305
+ joinedPairs: stats.joinedPairs,
306
+ callouts: stats.callouts,
307
+ closedHyphens: stats.closedHyphens,
308
+ danglingLong: perPageStats.reduce(function(sum, r) {
309
+ return sum + r.danglingLong;
310
+ }, 0),
311
+ danglingShort: perPageStats.reduce(function(sum, r) {
312
+ return sum + r.danglingShort;
313
+ }, 0),
314
+ reviewBlocks: perPageStats.reduce(function(sum, r) {
315
+ return sum + r.reviewBlocks;
316
+ }, 0),
317
+ // The text path never sees per-word confidence at all; 0 here means
318
+ // "nothing to measure" (see PageStatsRow's field doc), not "measured 0".
319
+ lowConfidenceWords: 0,
320
+ hybridPages: hybridPages,
321
+ pageStats: perPageStats
322
+ };
323
+ }
324
+ function buildOcrReport(param) {
325
+ var md = param.md, fallback = param.fallback, _param_words = param.words, words = _param_words === void 0 ? [] : _param_words;
326
+ var numPages = (0, _pagemarkerts.countPageMarkers)(md);
327
+ var heads = (md.match(/^#{1,6}\s*(.+)$/gm) || []).filter(function(h) {
328
+ return !(0, _pagemarkerts.isPageMarkerLine)(h);
329
+ });
330
+ var perPage = numPages ? Math.round(md.length / numPages) : 0;
331
+ var perPageStats = pageStats(md);
332
+ // Attach the low-confidence detector's per-page results after the fact:
333
+ // pageStats() has no confidence data (it reads markdown text only), so join it in here by page number.
334
+ var lowConf = lowConfidenceByPage(words);
335
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
336
+ try {
337
+ for(var _iterator = perPageStats[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
338
+ var row = _step.value;
339
+ var entry = lowConf.get(row.page);
340
+ if (entry && entry.measured > 0) {
341
+ row.lowConfidenceWords = entry.low;
342
+ if (entry.sample.length) row.lowConfidenceSample = entry.sample;
343
+ }
344
+ }
345
+ } catch (err) {
346
+ _didIteratorError = true;
347
+ _iteratorError = err;
348
+ } finally{
349
+ try {
350
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
351
+ _iterator.return();
352
+ }
353
+ } finally{
354
+ if (_didIteratorError) {
355
+ throw _iteratorError;
356
+ }
357
+ }
358
+ }
359
+ return {
360
+ outputVersion: OUTPUT_VERSION,
361
+ path: 'ocr',
362
+ pages: numPages,
363
+ ocrFallback: !!fallback,
364
+ chars: md.length,
365
+ charsPerPage: perPage,
366
+ sparse: perPage < SPARSE_CHARS_PER_PAGE,
367
+ headings: heads.length,
368
+ junkHeadings: heads.filter(function(h) {
369
+ return !/[A-Za-z]{3}/.test(h);
370
+ }).length,
371
+ paragraphs: (md.match(/^(?![#>-])\S.*$/gm) || []).length,
372
+ // Exclude BOTH "[floats]" and "[review: ...]" lines — a review marker is
373
+ // a labeled unstructured block, not a genuine callout.
374
+ callouts: (md.match(/^> (?!\[floats\]|\[review:)/gm) || []).length,
375
+ floats: (md.match(/^> \[floats\]/gm) || []).length,
376
+ danglingLong: perPageStats.reduce(function(sum, r) {
377
+ return sum + r.danglingLong;
378
+ }, 0),
379
+ danglingShort: perPageStats.reduce(function(sum, r) {
380
+ return sum + r.danglingShort;
381
+ }, 0),
382
+ reviewBlocks: perPageStats.reduce(function(sum, r) {
383
+ return sum + r.reviewBlocks;
384
+ }, 0),
385
+ lowConfidenceWords: perPageStats.reduce(function(sum, r) {
386
+ var _r_lowConfidenceWords;
387
+ return sum + ((_r_lowConfidenceWords = r.lowConfidenceWords) !== null && _r_lowConfidenceWords !== void 0 ? _r_lowConfidenceWords : 0);
388
+ }, 0),
389
+ pageStats: perPageStats
390
+ };
391
+ }
392
+ /* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/Users/kevin/Projects/pdf-to-md/src/report.ts"],"sourcesContent":["// report.ts — QA report over an extraction, machine-readable with --json.\nimport { countPageMarkers, isPageMarkerLine, splitByPageMarker } from './page-marker.ts';\nimport type { BuildOcrReportInput, BuildReportInput, PageStatsRow, Report, WordConfidenceInput } from './types.ts';\n\n// < SPARSE warns only; < AUTO_OCR means the pages are certainly images (measured:\n// an image-only 100-pager yields ~4 chars/page) and the auto-OCR fallback fires.\nexport const SPARSE_CHARS_PER_PAGE = 200;\nexport const AUTO_OCR_CHARS_PER_PAGE = 20;\n\n/** A manually-bumped integer, deliberately not the npm package version —\n * bump whenever a change can alter output for identical input. See `CHANGELOG.md` for history. */\nexport const OUTPUT_VERSION = 1;\n\n// A body paragraph line may end in sentence/clause punctuation, a closing\n// quote/bracket, an ellipsis, or a digit (chart/label lines like \"1/3\" legitimately end in a number).\nconst TERMINAL_PUNCT = /[.!?:;\"”'’)\\]…0-9]$/;\n\n// Lines that are not body prose at all: headings (incl. \"### pN\" markers),\n// floats/blockquotes, table rows, and list items — excluded before TERMINAL_PUNCT runs.\nconst NON_PROSE_LINE = /^[#>|*-]/;\n\n// A `> [review: reason] text` line (src/emit.ts). Shared by pageStats (per\n// page) and both top-level report builders (whole doc) so the counts can't drift apart.\nconst REVIEW_LINE = /^> \\[review: /gm;\n\n// Dangling lines split by length: long ones are the invisible column-break/splice\n// signal; short ones are usually a missed heading or an unjoined label.\nconst DANGLING_LONG_MIN = 60;\n\n/** Below this per-word confidence (0-100, tesseract.js's `confidence`), a\n * word counts as low-confidence. Measured: junk max 43 vs prose min 76, cut 60, 2026-08-17. */\nexport const LOW_CONFIDENCE_THRESHOLD = 60;\n\n// Cap on `lowConfidenceSample`'s length per page — a few representative\n// offenders, not the whole page re-emitted a second time.\nexport const LOW_CONFIDENCE_SAMPLE_CAP = 12;\n\ninterface LowConfidenceStats {\n measured: number; // words on this page that carried a confidence value at all\n low: number; // of those, how many scored below LOW_CONFIDENCE_THRESHOLD\n sample: string[]; // worst-confidence-first, capped list of the actual low-confidence tokens\n}\n\n// Grouped from the flat recognized-word list (confidence is per-word, never\n// merged into a line — see Word's comment). `measured` is tracked separately from `low` so a page with nothing to measure reports ABSENT, not a lying zero.\nfunction lowConfidenceByPage(words: WordConfidenceInput[]): Map<number, LowConfidenceStats> {\n const byPage = new Map<number, { measured: number; low: number; lowWords: { text: string; confidence: number }[] }>();\n for (const w of words) {\n if (w.confidence === undefined) continue;\n const entry = byPage.get(w.page) ?? { measured: 0, low: 0, lowWords: [] };\n entry.measured++;\n if (w.confidence < LOW_CONFIDENCE_THRESHOLD) {\n entry.low++;\n entry.lowWords.push({ text: w.text, confidence: w.confidence });\n }\n byPage.set(w.page, entry);\n }\n const result = new Map<number, LowConfidenceStats>();\n for (const [page, entry] of byPage) {\n // Sort ascending by confidence BEFORE capping, so the cap keeps the\n // worst offenders regardless of appearance order.\n const sample = entry.lowWords\n .slice()\n .sort((a, b) => a.confidence - b.confidence)\n .slice(0, LOW_CONFIDENCE_SAMPLE_CAP)\n .map((w) => w.text);\n result.set(page, { measured: entry.measured, low: entry.low, sample });\n }\n return result;\n}\n\ninterface DanglingCounts {\n long: number;\n short: number;\n}\n\n// Counts of body paragraph LINES ending WITHOUT terminal punctuation, split\n// by length: `long` is the invisible column-break/splice signal; `short` is usually a missed heading or unjoined label.\nfunction danglingCounts(body: string): DanglingCounts {\n let long = 0;\n let short = 0;\n for (const raw of body.split('\\n')) {\n const line = raw.trim();\n if (!line || NON_PROSE_LINE.test(line)) continue;\n if (TERMINAL_PUNCT.test(line)) continue;\n if (line.length >= DANGLING_LONG_MIN) long++;\n else short++;\n }\n return { long, short };\n}\n\n// One page's own measured stats, derivable from its body text alone —\n// shared by `pageStats` and any future caller that already has a page's body text in hand.\nfunction measurePage(body: string): Omit<PageStatsRow, 'page' | 'largeImages' | 'lowConfidenceWords' | 'lowConfidenceSample'> {\n const heads = body.match(/^#{1,6}\\s*(.+)$/gm) || [];\n const dangling = danglingCounts(body);\n return {\n chars: body.length,\n headings: heads.length,\n junkHeadings: heads.filter((h) => !/[A-Za-z]{3}/.test(h)).length,\n floats: (body.match(/^> \\[floats\\]/gm) || []).length,\n paragraphs: (body.match(/^(?![#>-])\\S.*$/gm) || []).length,\n danglingLong: dangling.long,\n danglingShort: dangling.short,\n reviewBlocks: (body.match(REVIEW_LINE) || []).length,\n };\n}\n\n// Per-page QA rows, one per \"### pN\" block. The text path always passes\n// markdown with markers forced on (`statsMd`) regardless of `--page-markers`, so pageStats is always populated.\n//\n// `hybridPages` (text path only) marks a row `largeImages: true` when that\n// page used its text layer but also carries a large embedded image; omitted entirely on the OCR path, which has no equivalent signal.\nfunction pageStats(md: string, hybridPages?: number[]): PageStatsRow[] {\n const rows: PageStatsRow[] = [];\n for (const { page, body } of splitByPageMarker(md)) {\n const row: PageStatsRow = { page, ...measurePage(body) };\n if (hybridPages) row.largeImages = hybridPages.includes(page);\n rows.push(row);\n }\n return rows;\n}\n\nexport function buildReport({ numPages, md, statsMd, stats, bodyH, headingSizes, hybridPages = [] }: BuildReportInput): Report {\n const heads = (md.match(/^#{1,6}\\s*(.+)$/gm) || []).filter((h) => !isPageMarkerLine(h)); // page markers are provenance, not structure\n const perPage = Math.round(md.length / numPages);\n const perPageStats = pageStats(statsMd, hybridPages);\n return {\n outputVersion: OUTPUT_VERSION,\n path: 'text',\n pages: numPages,\n bodyFontHeight: bodyH,\n headingSizes: headingSizes.slice(0, 6),\n chars: md.length,\n charsPerPage: perPage,\n sparse: perPage < SPARSE_CHARS_PER_PAGE,\n headings: heads.length,\n junkHeadings: heads.filter((h) => !/[A-Za-z]{3}/.test(h)).length,\n listItems: stats.listItems,\n paragraphs: stats.paragraphs,\n joinedPairs: stats.joinedPairs,\n callouts: stats.callouts,\n closedHyphens: stats.closedHyphens,\n danglingLong: perPageStats.reduce((sum, r) => sum + r.danglingLong, 0),\n danglingShort: perPageStats.reduce((sum, r) => sum + r.danglingShort, 0),\n reviewBlocks: perPageStats.reduce((sum, r) => sum + r.reviewBlocks, 0),\n // The text path never sees per-word confidence at all; 0 here means\n // \"nothing to measure\" (see PageStatsRow's field doc), not \"measured 0\".\n lowConfidenceWords: 0,\n hybridPages,\n pageStats: perPageStats,\n };\n}\n\n// QA report for the OCR path: measured from the emitted markdown text.\n// `fallback` records that the text layer was tried first and found empty.\nexport function buildOcrReport({ md, fallback, words = [] }: BuildOcrReportInput): Report {\n const numPages = countPageMarkers(md);\n const heads = (md.match(/^#{1,6}\\s*(.+)$/gm) || []).filter((h) => !isPageMarkerLine(h));\n const perPage = numPages ? Math.round(md.length / numPages) : 0;\n const perPageStats = pageStats(md);\n // Attach the low-confidence detector's per-page results after the fact:\n // pageStats() has no confidence data (it reads markdown text only), so join it in here by page number.\n const lowConf = lowConfidenceByPage(words);\n for (const row of perPageStats) {\n const entry = lowConf.get(row.page);\n if (entry && entry.measured > 0) {\n row.lowConfidenceWords = entry.low;\n if (entry.sample.length) row.lowConfidenceSample = entry.sample;\n }\n }\n return {\n outputVersion: OUTPUT_VERSION,\n path: 'ocr',\n pages: numPages,\n ocrFallback: !!fallback,\n chars: md.length,\n charsPerPage: perPage,\n sparse: perPage < SPARSE_CHARS_PER_PAGE,\n headings: heads.length,\n junkHeadings: heads.filter((h) => !/[A-Za-z]{3}/.test(h)).length,\n paragraphs: (md.match(/^(?![#>-])\\S.*$/gm) || []).length,\n // Exclude BOTH \"[floats]\" and \"[review: ...]\" lines — a review marker is\n // a labeled unstructured block, not a genuine callout.\n callouts: (md.match(/^> (?!\\[floats\\]|\\[review:)/gm) || []).length,\n floats: (md.match(/^> \\[floats\\]/gm) || []).length,\n danglingLong: perPageStats.reduce((sum, r) => sum + r.danglingLong, 0),\n danglingShort: perPageStats.reduce((sum, r) => sum + r.danglingShort, 0),\n reviewBlocks: perPageStats.reduce((sum, r) => sum + r.reviewBlocks, 0),\n lowConfidenceWords: perPageStats.reduce((sum, r) => sum + (r.lowConfidenceWords ?? 0), 0),\n pageStats: perPageStats,\n };\n}\n"],"names":["AUTO_OCR_CHARS_PER_PAGE","LOW_CONFIDENCE_SAMPLE_CAP","LOW_CONFIDENCE_THRESHOLD","OUTPUT_VERSION","SPARSE_CHARS_PER_PAGE","buildOcrReport","buildReport","TERMINAL_PUNCT","NON_PROSE_LINE","REVIEW_LINE","DANGLING_LONG_MIN","lowConfidenceByPage","words","byPage","Map","w","confidence","undefined","entry","get","page","measured","low","lowWords","push","text","set","result","sample","slice","sort","a","b","map","danglingCounts","body","long","short","split","raw","line","trim","test","length","measurePage","heads","match","dangling","chars","headings","junkHeadings","filter","h","floats","paragraphs","danglingLong","danglingShort","reviewBlocks","pageStats","md","hybridPages","rows","splitByPageMarker","row","largeImages","includes","numPages","statsMd","stats","bodyH","headingSizes","isPageMarkerLine","perPage","Math","round","perPageStats","outputVersion","path","pages","bodyFontHeight","charsPerPage","sparse","listItems","joinedPairs","callouts","closedHyphens","reduce","sum","r","lowConfidenceWords","fallback","countPageMarkers","lowConf","lowConfidenceSample","ocrFallback"],"mappings":"AAAA,0EAA0E;;;;;;;;;;;;QAO7DA;eAAAA;;QA4BAC;eAAAA;;QAJAC;eAAAA;;QApBAC;eAAAA;;QALAC;eAAAA;;QAsJGC;eAAAA;;QAjCAC;eAAAA;;;4BA1HsD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAK/D,IAAMF,wBAAwB;AAC9B,IAAMJ,0BAA0B;AAIhC,IAAMG,iBAAiB;AAE9B,0EAA0E;AAC1E,sGAAsG;AACtG,IAAMI,iBAAiB;AAEvB,2EAA2E;AAC3E,wFAAwF;AACxF,IAAMC,iB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+ export declare function resolvePackagePath(specifier: string): string;
@@ -0,0 +1,18 @@
1
+ // Resolves an installed package file's on-disk path for both build targets:
2
+ // ESM's import.meta.resolve returns a file:// URL, the CJS build's rewritten require.resolve a plain path — normalizes both to a plain path.
3
+ "use strict";
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ Object.defineProperty(exports, "resolvePackagePath", {
8
+ enumerable: true,
9
+ get: function() {
10
+ return resolvePackagePath;
11
+ }
12
+ });
13
+ var _nodeurl = require("node:url");
14
+ function resolvePackagePath(specifier) {
15
+ var resolved = require.resolve(specifier);
16
+ return resolved.startsWith('file://') ? (0, _nodeurl.fileURLToPath)(resolved) : resolved;
17
+ }
18
+ /* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/Users/kevin/Projects/pdf-to-md/src/resolve.ts"],"sourcesContent":["// Resolves an installed package file's on-disk path for both build targets:\n// ESM's import.meta.resolve returns a file:// URL, the CJS build's rewritten require.resolve a plain path — normalizes both to a plain path.\nimport { fileURLToPath } from 'node:url';\n\nexport function resolvePackagePath(specifier: string): string {\n const resolved = import.meta.resolve(specifier);\n return resolved.startsWith('file://') ? fileURLToPath(resolved) : resolved;\n}\n"],"names":["resolvePackagePath","specifier","resolved","resolve","startsWith","fileURLToPath"],"mappings":"AAAA,4EAA4E;AAC5E,6IAA6I;;;;;+BAG7HA;;;eAAAA;;;uBAFc;AAEvB,SAASA,mBAAmBC,SAAiB;IAClD,IAAMC,WAAW,QAAYC,OAAO,CAACF;IACrC,OAAOC,SAASE,UAAU,CAAC,aAAaC,IAAAA,sBAAa,EAACH,YAAYA;AACpE"}
@@ -0,0 +1,171 @@
1
+ export interface Glyph {
2
+ s: string;
3
+ x: number;
4
+ y: number;
5
+ w: number;
6
+ h: number;
7
+ }
8
+ export interface CollectedPage {
9
+ page: number;
10
+ glyphs: Glyph[];
11
+ width: number;
12
+ height: number;
13
+ textChars: number;
14
+ largeImage: boolean;
15
+ }
16
+ export interface CollectResult {
17
+ numPages: number;
18
+ pages: CollectedPage[];
19
+ heightChars: Map<number, number>;
20
+ }
21
+ export interface Line {
22
+ text: string;
23
+ x: number;
24
+ y: number;
25
+ h: number;
26
+ col: number;
27
+ }
28
+ export interface PageLines {
29
+ page: number;
30
+ lines: Line[];
31
+ }
32
+ export interface BuildMarkdownOptions {
33
+ pageMarkers?: boolean;
34
+ }
35
+ export interface MarkdownStats {
36
+ headings: number;
37
+ listItems: number;
38
+ paragraphs: number;
39
+ joinedPairs: number;
40
+ reflowed: number;
41
+ callouts: number;
42
+ closedHyphens: number;
43
+ }
44
+ export interface MarkdownResult {
45
+ md: string;
46
+ stats: MarkdownStats;
47
+ bodyH: number;
48
+ headingSizes: number[];
49
+ }
50
+ /** One row of the per-page QA breakdown ("### pN" blocks) — used to decide
51
+ * which pages are worth rendering and re-checking (README's "Design contract"). */
52
+ export interface PageStatsRow {
53
+ page: number;
54
+ chars: number;
55
+ headings: number;
56
+ junkHeadings: number;
57
+ floats: number;
58
+ paragraphs: number;
59
+ danglingLong: number;
60
+ danglingShort: number;
61
+ /** count of `> [review: ...]` lines — blocks the geometry could not order
62
+ * and labeled instead of guessing (README's "Design contract"). */
63
+ reviewBlocks: number;
64
+ /** present only on the text path's rows; omitted (not `false`) on the OCR
65
+ * path, which has no per-page hybrid-image signal. */
66
+ largeImages?: boolean;
67
+ /** count of words below `report.ts`'s LOW_CONFIDENCE_THRESHOLD; omitted (not
68
+ * 0) when the page had no confidence data at all, so "measured 0" and "nothing to measure" stay distinct. */
69
+ lowConfidenceWords?: number;
70
+ /** the suspect tokens behind `lowConfidenceWords`, worst-confidence first
71
+ * and capped (`report.ts`'s LOW_CONFIDENCE_SAMPLE_CAP) so a chart-heavy page can't bloat the JSON. */
72
+ lowConfidenceSample?: string[];
73
+ }
74
+ export interface BuildReportInput {
75
+ numPages: number;
76
+ md: string;
77
+ /** identical to `md` but always carries "### pN" markers, so pageStats is
78
+ * measured independent of the caller's `--page-markers` choice; same string as `md` when markers were requested. */
79
+ statsMd: string;
80
+ stats: MarkdownStats;
81
+ bodyH: number;
82
+ headingSizes: number[];
83
+ hybridPages?: number[];
84
+ }
85
+ /** One recognized word's page/text/confidence — `report.ts`'s low-confidence
86
+ * detector input; a structural subset of OcrWordInput kept here so `types.ts` doesn't import the library-layer module that depends on it. */
87
+ export interface WordConfidenceInput {
88
+ page: number;
89
+ text: string;
90
+ confidence?: number;
91
+ }
92
+ export interface BuildOcrReportInput {
93
+ md: string;
94
+ fallback?: boolean;
95
+ /** every recognized word, for `report.ts`'s low-confidence detector.
96
+ * Defaults to [] (a pre-confidence --words-json replay), reporting the detector absent, never wrong. */
97
+ words?: WordConfidenceInput[];
98
+ }
99
+ /** Per-document and per-page QA metrics returned by every extraction entry
100
+ * point, discriminated by `path`; OCR-only and text-only fields are grouped below. */
101
+ export interface Report {
102
+ /** manually-bumped integer (not the npm package version) — see
103
+ * `report.ts`'s OUTPUT_VERSION for the bump rule; present on every Report so a frozen baseline's staleness is self-announcing. */
104
+ outputVersion: number;
105
+ path: 'text' | 'ocr';
106
+ pages: number;
107
+ chars: number;
108
+ charsPerPage: number;
109
+ sparse: boolean;
110
+ headings: number;
111
+ junkHeadings: number;
112
+ paragraphs: number;
113
+ callouts: number;
114
+ danglingLong: number;
115
+ danglingShort: number;
116
+ /** total `> [review: ...]` blocks across all pages (sum of pageStats'
117
+ * reviewBlocks); always 0 on the text path — only the OCR path emits review markers. */
118
+ reviewBlocks: number;
119
+ /** document-level sum of pageStats' `lowConfidenceWords` — see that
120
+ * field for why 0 can mean "measured 0" or "nothing to measure". */
121
+ lowConfidenceWords: number;
122
+ pageStats: PageStatsRow[];
123
+ floats?: number;
124
+ ocrFallback?: boolean;
125
+ bodyFontHeight?: number;
126
+ headingSizes?: number[];
127
+ listItems?: number;
128
+ joinedPairs?: number;
129
+ closedHyphens?: number;
130
+ hybridPages?: number[];
131
+ }
132
+ /** One recognized/collected word, page-relative; `box` is always present.
133
+ * See `AnalysisPage.words` for the coordinate contract and per-path granularity difference. */
134
+ export interface AnalysisWord {
135
+ text: string;
136
+ box: {
137
+ x: number;
138
+ y: number;
139
+ w: number;
140
+ h: number;
141
+ };
142
+ confidence?: number;
143
+ }
144
+ /** One structural block; `wordIndexes` links it to its page's `words` list (blocks -> words only).
145
+ * `text` is bare content for `'heading'` (level separate), else the LITERAL markdown line (decoration included, round-trippable) — a pull-quote is `'paragraph'`, not a 5th type. */
146
+ export interface AnalysisBlock {
147
+ type: 'heading' | 'paragraph' | 'float' | 'review';
148
+ text: string;
149
+ /** Heading level (integer 1-6); REQUIRED when `type` is `'heading'`,
150
+ * FORBIDDEN otherwise — toMarkdown()/toText() validate this fail-fast (throws PdfToMdError/'ANALYSIS_INPUT'), never silently ignored. */
151
+ level?: number;
152
+ wordIndexes: number[];
153
+ }
154
+ /** One page's flat words plus its structural blocks. */
155
+ export interface AnalysisPage {
156
+ page: number;
157
+ /** Flat, page-relative word list; `AnalysisBlock.wordIndexes` indexes into it. `box` is always normalized [0,1], origin bottom-left, y up, regardless of path.
158
+ * OCR-path is genuinely per-word; TEXT-path is per visual LINE (`box.w` always 0, `box.y` the line's baseline) — coarser but honest, not faked. */
159
+ words: AnalysisWord[];
160
+ blocks: AnalysisBlock[];
161
+ }
162
+ /** analyze()'s output: plain, JSON-serializable per-page words/blocks plus
163
+ * the same QA `report` the other entry points return. */
164
+ export interface Analysis {
165
+ /** manually-bumped integer — see `Report.outputVersion` / `report.ts`'s OUTPUT_VERSION. */
166
+ outputVersion: number;
167
+ /** the same QA report extractText/extractOcr/pdfToMarkdown return, always
168
+ * measured off real markdown (OCR: the shared core's output; TEXT: buildMarkdown's reflowed output, not this coarser IR) — never stale relative to the IR. */
169
+ report: Report;
170
+ pages: AnalysisPage[];
171
+ }