@effortlessmotion/pdf-to-md 0.1.8 → 0.2.1

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 (108) hide show
  1. package/README.md +5 -5
  2. package/dist/cjs/analyze.d.cts +3 -1
  3. package/dist/cjs/analyze.d.ts +3 -1
  4. package/dist/cjs/analyze.js +38 -100
  5. package/dist/cjs/analyze.js.map +1 -1
  6. package/dist/cjs/audit.d.cts +6 -5
  7. package/dist/cjs/audit.d.ts +6 -5
  8. package/dist/cjs/audit.js +368 -60
  9. package/dist/cjs/audit.js.map +1 -1
  10. package/dist/cjs/cli/audit.js.map +1 -1
  11. package/dist/cjs/cli/extract.js +13 -48
  12. package/dist/cjs/cli/extract.js.map +1 -1
  13. package/dist/cjs/cli/index.js.map +1 -1
  14. package/dist/cjs/cli/render.js.map +1 -1
  15. package/dist/cjs/cli/types.js.map +1 -1
  16. package/dist/cjs/cli.js.map +1 -1
  17. package/dist/cjs/collect.js +91 -35
  18. package/dist/cjs/collect.js.map +1 -1
  19. package/dist/cjs/dict.js.map +1 -1
  20. package/dist/cjs/emit.js.map +1 -1
  21. package/dist/cjs/engines/tesseract.js.map +1 -1
  22. package/dist/cjs/errors.d.cts +2 -0
  23. package/dist/cjs/errors.d.ts +2 -0
  24. package/dist/cjs/errors.js.map +1 -1
  25. package/dist/cjs/extract.d.cts +20 -9
  26. package/dist/cjs/extract.d.ts +20 -9
  27. package/dist/cjs/extract.js +333 -106
  28. package/dist/cjs/extract.js.map +1 -1
  29. package/dist/cjs/geometry.js.map +1 -1
  30. package/dist/cjs/index.js.map +1 -1
  31. package/dist/cjs/lines.js +21 -10
  32. package/dist/cjs/lines.js.map +1 -1
  33. package/dist/cjs/markdown.js +140 -54
  34. package/dist/cjs/markdown.js.map +1 -1
  35. package/dist/cjs/page-marker.d.cts +1 -1
  36. package/dist/cjs/page-marker.d.ts +1 -1
  37. package/dist/cjs/page-marker.js +39 -8
  38. package/dist/cjs/page-marker.js.map +1 -1
  39. package/dist/cjs/pdf-open.js.map +1 -1
  40. package/dist/cjs/raster.js.map +1 -1
  41. package/dist/cjs/render-analysis.d.cts +4 -2
  42. package/dist/cjs/render-analysis.d.ts +4 -2
  43. package/dist/cjs/render-analysis.js +5 -3
  44. package/dist/cjs/render-analysis.js.map +1 -1
  45. package/dist/cjs/report.d.cts +2 -2
  46. package/dist/cjs/report.d.ts +2 -2
  47. package/dist/cjs/report.js +27 -8
  48. package/dist/cjs/report.js.map +1 -1
  49. package/dist/cjs/resolve.js.map +1 -1
  50. package/dist/cjs/text-analysis.d.cts +12 -0
  51. package/dist/cjs/text-analysis.d.ts +12 -0
  52. package/dist/cjs/text-analysis.js +175 -0
  53. package/dist/cjs/text-analysis.js.map +1 -0
  54. package/dist/cjs/types.d.cts +40 -3
  55. package/dist/cjs/types.d.ts +40 -3
  56. package/dist/cjs/types.js +2 -3
  57. package/dist/cjs/types.js.map +1 -1
  58. package/dist/cjs/validate.js.map +1 -1
  59. package/dist/esm/analyze.d.ts +3 -1
  60. package/dist/esm/analyze.js +18 -89
  61. package/dist/esm/analyze.js.map +1 -1
  62. package/dist/esm/audit.d.ts +6 -5
  63. package/dist/esm/audit.js +236 -29
  64. package/dist/esm/audit.js.map +1 -1
  65. package/dist/esm/cli/audit.js.map +1 -1
  66. package/dist/esm/cli/extract.js +10 -23
  67. package/dist/esm/cli/extract.js.map +1 -1
  68. package/dist/esm/cli/index.js.map +1 -1
  69. package/dist/esm/cli/render.js.map +1 -1
  70. package/dist/esm/cli/types.js.map +1 -1
  71. package/dist/esm/cli.js.map +1 -1
  72. package/dist/esm/collect.js +64 -15
  73. package/dist/esm/collect.js.map +1 -1
  74. package/dist/esm/dict.js.map +1 -1
  75. package/dist/esm/emit.js.map +1 -1
  76. package/dist/esm/engines/tesseract.js.map +1 -1
  77. package/dist/esm/errors.d.ts +2 -0
  78. package/dist/esm/errors.js.map +1 -1
  79. package/dist/esm/extract.d.ts +20 -9
  80. package/dist/esm/extract.js +167 -76
  81. package/dist/esm/extract.js.map +1 -1
  82. package/dist/esm/geometry.js.map +1 -1
  83. package/dist/esm/index.js.map +1 -1
  84. package/dist/esm/lines.js +14 -10
  85. package/dist/esm/lines.js.map +1 -1
  86. package/dist/esm/markdown.js +110 -27
  87. package/dist/esm/markdown.js.map +1 -1
  88. package/dist/esm/page-marker.d.ts +1 -1
  89. package/dist/esm/page-marker.js +15 -9
  90. package/dist/esm/page-marker.js.map +1 -1
  91. package/dist/esm/pdf-open.js.map +1 -1
  92. package/dist/esm/raster.js.map +1 -1
  93. package/dist/esm/render-analysis.d.ts +4 -2
  94. package/dist/esm/render-analysis.js +9 -5
  95. package/dist/esm/render-analysis.js.map +1 -1
  96. package/dist/esm/report.d.ts +2 -2
  97. package/dist/esm/report.js +12 -7
  98. package/dist/esm/report.js.map +1 -1
  99. package/dist/esm/resolve.js.map +1 -1
  100. package/dist/esm/text-analysis.d.ts +12 -0
  101. package/dist/esm/text-analysis.js +81 -0
  102. package/dist/esm/text-analysis.js.map +1 -0
  103. package/dist/esm/types.d.ts +40 -3
  104. package/dist/esm/types.js +4 -4
  105. package/dist/esm/types.js.map +1 -1
  106. package/dist/esm/validate.js.map +1 -1
  107. package/package.json +1 -1
  108. package/skills/pdf-to-md/SKILL.md +39 -66
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/formats/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,iBAAiB;AAEvB,2EAA2E;AAC3E,wFAAwF;AACxF,IAAMC,cAAc;AAEpB,kFAAkF;AAClF,wEAAwE;AACxE,IAAMC,oBAAoB;AAInB,IAAMR,2BAA2B;AAIjC,IAAMD,4BAA4B;AAQzC,4EAA4E;AAC5E,4JAA4J;AAC5J,SAASU,oBAAoBC,KAA4B;IACvD,IAAMC,SAAS,IAAIC;QACd,kCAAA,2BAAA;;QAAL,QAAK,YAAWF,0BAAX,SAAA,6BAAA,QAAA,yBAAA,iCAAkB;YAAlB,IAAMG,IAAN;gBAEWF;YADd,IAAIE,EAAEC,UAAU,KAAKC,WAAW;YAChC,IAAMC,SAAQL,cAAAA,OAAOM,GAAG,CAACJ,EAAEK,IAAI,eAAjBP,yBAAAA,cAAsB;gBAAEQ,UAAU;gBAAGC,KAAK;gBAAGC,UAAU,EAAE;YAAC;YACxEL,MAAMG,QAAQ;YACd,IAAIN,EAAEC,UAAU,GAAGd,0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DAAuD;QACvDyC,UAAU,AAACzB,CAAAA,GAAGb,KAAK,CAAC,oCAAoC,EAAE,AAAD,EAAGH,MAAM;QAClEU,QAAQ,AAACM,CAAAA,GAAGb,KAAK,CAAC,sBAAsB,EAAE,AAAD,EAAGH,MAAM;QAClDY,cAAcoB,aAAaW,MAAM,CAAC,SAACC,KAAKC;mBAAMD,MAAMC,EAAEjC,YAAY;WAAE;QACpEC,eAAemB,aAAaW,MAAM,CAAC,SAACC,KAAKC;mBAAMD,MAAMC,EAAEhC,aAAa;WAAE;QACtEC,cAAckB,aAAaW,MAAM,CAAC,SAACC,KAAKC;mBAAMD,MAAMC,EAAE/B,YAAY;WAAE;QACpEgC,oBAAoBd,aAAaW,MAAM,CAAC,SAACC,KAAKC;gBAAaA;mBAAPD,QAAOC,wBAAAA,EAAEC,kBAAkB,cAApBD,mCAAAA,wBAAwB;WAAI;QACvF9B,WAAWiB;IACb;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/open-source/formats/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 = 2;\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' | 'path' | '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, path: 'text' | 'ocr', hybridPages?: number[], pagePaths?: Map<number, 'text' | 'ocr'>): PageStatsRow[] {\n const rows: PageStatsRow[] = [];\n for (const { page, body } of splitByPageMarker(md)) {\n const row: PageStatsRow = { page, path: pagePaths?.get(page) ?? path, ...measurePage(body) };\n if (hybridPages && row.path === 'text') 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, 'text', 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 = [], pagePaths, hybridPages }: 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, 'ocr', hybridPages, pagePaths);\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 const mixed = pagePaths !== undefined && [...pagePaths.values()].some((path) => path === 'text');\n return {\n outputVersion: OUTPUT_VERSION,\n path: mixed ? 'mixed' : '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","path","hybridPages","pagePaths","rows","splitByPageMarker","row","largeImages","includes","numPages","statsMd","stats","bodyH","headingSizes","isPageMarkerLine","perPage","Math","round","perPageStats","outputVersion","pages","bodyFontHeight","charsPerPage","sparse","listItems","joinedPairs","callouts","closedHyphens","reduce","sum","r","lowConfidenceWords","fallback","countPageMarkers","lowConf","lowConfidenceSample","mixed","values","some","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,iBAAiB;AAEvB,2EAA2E;AAC3E,wFAAwF;AACxF,IAAMC,cAAc;AAEpB,kFAAkF;AAClF,wEAAwE;AACxE,IAAMC,oBAAoB;AAInB,IAAMR,2BAA2B;AAIjC,IAAMD,4BAA4B;AAQzC,4EAA4E;AAC5E,4JAA4J;AAC5J,SAASU,oBAAoBC,KAA4B;IACvD,IAAMC,SAAS,IAAIC;QACd,kCAAA,2BAAA;;QAAL,QAAK,YAAWF,0BAAX,SAAA,6BAAA,QAAA,yBAAA,iCAAkB;YAAlB,IAAMG,IAAN;gBAEWF;YADd,IAAIE,EAAEC,UAAU,KAAKC,WAAW;YAChC,IAAMC,SAAQL,cAAAA,OAAOM,GAAG,CAACJ,EAAEK,IAAI,eAAjBP,yBAAAA,cAAsB;gBAAEQ,UAAU;gBAAGC,KAAK;gBAAGC,UAAU,EAAE;YAAC;YACxEL,MAAMG,QAAQ;YACd,IAAIN,EAAEC,UAAU,GAAGd,0BAA0B;gBAC3CgB,MAAMI,GA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,aAAa,CAAC,CAACP;QACf3C,OAAOW,GAAGhB,MAAM;QAChBsC,cAAcP;QACdQ,QAAQR,UAAUtE;QAClB6C,UAAUJ,MAAMF,MAAM;QACtBO,cAAcL,MAAMM,MAAM,CAAC,SAACC;mBAAM,CAAC,cAAcV,IAAI,CAACU;WAAIT,MAAM;QAChEW,YAAY,AAACK,CAAAA,GAAGb,KAAK,CAAC,wBAAwB,EAAE,AAAD,EAAGH,MAAM;QACxD,yEAAyE;QACzE,uDAAuD;QACvD0C,UAAU,AAAC1B,CAAAA,GAAGb,KAAK,CAAC,oCAAoC,EAAE,AAAD,EAAGH,MAAM;QAClEU,QAAQ,AAACM,CAAAA,GAAGb,KAAK,CAAC,sBAAsB,EAAE,AAAD,EAAGH,MAAM;QAClDY,cAAcsB,aAAaU,MAAM,CAAC,SAACC,KAAKC;mBAAMD,MAAMC,EAAElC,YAAY;WAAE;QACpEC,eAAeqB,aAAaU,MAAM,CAAC,SAACC,KAAKC;mBAAMD,MAAMC,EAAEjC,aAAa;WAAE;QACtEC,cAAcoB,aAAaU,MAAM,CAAC,SAACC,KAAKC;mBAAMD,MAAMC,EAAEhC,YAAY;WAAE;QACpEiC,oBAAoBb,aAAaU,MAAM,CAAC,SAACC,KAAKC;gBAAaA;mBAAPD,QAAOC,wBAAAA,EAAEC,kBAAkB,cAApBD,mCAAAA,wBAAwB;WAAI;QACvF/B,WAAWmB;IACb;AACF"}
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/formats/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"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/open-source/formats/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,12 @@
1
+ import type { PageWord } from './geometry.js';
2
+ import type { Analysis, CollectResult } from './types.js';
3
+ export interface TextAnalysisResult {
4
+ analysis: Analysis;
5
+ markdown: string;
6
+ words: PageWord[];
7
+ }
8
+ export declare function selectCollectedPages(collected: CollectResult, pageNumbers: Set<number>): CollectResult;
9
+ /** Builds the text result once for Markdown, raw analysis, text callbacks,
10
+ * and reporting. The `pages` returned by buildMarkdown own the actual block
11
+ * construction, so this never reconstructs ownership from rendered text. */
12
+ export declare function buildTextAnalysis(collected: CollectResult, pageMarkers: boolean): TextAnalysisResult;
@@ -0,0 +1,12 @@
1
+ import type { PageWord } from './geometry.js';
2
+ import type { Analysis, CollectResult } from './types.js';
3
+ export interface TextAnalysisResult {
4
+ analysis: Analysis;
5
+ markdown: string;
6
+ words: PageWord[];
7
+ }
8
+ export declare function selectCollectedPages(collected: CollectResult, pageNumbers: Set<number>): CollectResult;
9
+ /** Builds the text result once for Markdown, raw analysis, text callbacks,
10
+ * and reporting. The `pages` returned by buildMarkdown own the actual block
11
+ * construction, so this never reconstructs ownership from rendered text. */
12
+ export declare function buildTextAnalysis(collected: CollectResult, pageMarkers: boolean): TextAnalysisResult;
@@ -0,0 +1,175 @@
1
+ // Shared text-layer analysis. It keeps PDF source runs separate from layout
2
+ // reconstruction, while Markdown blocks retain the source-run indexes that
3
+ // produced them.
4
+ "use strict";
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ function _export(target, all) {
9
+ for(var name in all)Object.defineProperty(target, name, {
10
+ enumerable: true,
11
+ get: Object.getOwnPropertyDescriptor(all, name).get
12
+ });
13
+ }
14
+ _export(exports, {
15
+ get buildTextAnalysis () {
16
+ return buildTextAnalysis;
17
+ },
18
+ get selectCollectedPages () {
19
+ return selectCollectedPages;
20
+ }
21
+ });
22
+ var _linests = require("./lines.js");
23
+ var _markdownts = require("./markdown.js");
24
+ var _reportts = require("./report.js");
25
+ function _define_property(obj, key, value) {
26
+ if (key in obj) {
27
+ Object.defineProperty(obj, key, {
28
+ value: value,
29
+ enumerable: true,
30
+ configurable: true,
31
+ writable: true
32
+ });
33
+ } else obj[key] = value;
34
+ return obj;
35
+ }
36
+ function _object_spread(target) {
37
+ for(var i = 1; i < arguments.length; i++){
38
+ var source = arguments[i] != null ? arguments[i] : {};
39
+ var ownKeys = Object.keys(source);
40
+ if (typeof Object.getOwnPropertySymbols === "function") {
41
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
42
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
43
+ }));
44
+ }
45
+ ownKeys.forEach(function(key) {
46
+ _define_property(target, key, source[key]);
47
+ });
48
+ }
49
+ return target;
50
+ }
51
+ function sourceWord(glyph, dims) {
52
+ return {
53
+ text: glyph.s,
54
+ box: {
55
+ x: dims.width > 0 ? glyph.bounds.x / dims.width : 0,
56
+ y: dims.height > 0 ? (dims.height - glyph.bounds.y - glyph.bounds.h) / dims.height : 0,
57
+ w: dims.width > 0 ? glyph.bounds.w / dims.width : 0,
58
+ h: dims.height > 0 ? glyph.bounds.h / dims.height : 0
59
+ }
60
+ };
61
+ }
62
+ function callbackWords(pages) {
63
+ return pages.flatMap(function(page) {
64
+ return page.words.map(function(word) {
65
+ return _object_spread({
66
+ page: page.page,
67
+ text: word.text
68
+ }, word.box);
69
+ });
70
+ });
71
+ }
72
+ function selectCollectedPages(collected, pageNumbers) {
73
+ var pages = collected.pages.filter(function(page) {
74
+ return pageNumbers.has(page.page);
75
+ });
76
+ var heightChars = new Map();
77
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
78
+ try {
79
+ for(var _iterator = pages[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
80
+ var page = _step.value;
81
+ var _heightChars_get;
82
+ var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
83
+ try {
84
+ for(var _iterator1 = page.glyphs[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
85
+ var glyph = _step1.value;
86
+ heightChars.set(glyph.h, ((_heightChars_get = heightChars.get(glyph.h)) !== null && _heightChars_get !== void 0 ? _heightChars_get : 0) + glyph.s.length);
87
+ }
88
+ } catch (err) {
89
+ _didIteratorError1 = true;
90
+ _iteratorError1 = err;
91
+ } finally{
92
+ try {
93
+ if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
94
+ _iterator1.return();
95
+ }
96
+ } finally{
97
+ if (_didIteratorError1) {
98
+ throw _iteratorError1;
99
+ }
100
+ }
101
+ }
102
+ }
103
+ } catch (err) {
104
+ _didIteratorError = true;
105
+ _iteratorError = err;
106
+ } finally{
107
+ try {
108
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
109
+ _iterator.return();
110
+ }
111
+ } finally{
112
+ if (_didIteratorError) {
113
+ throw _iteratorError;
114
+ }
115
+ }
116
+ }
117
+ return {
118
+ numPages: pages.length,
119
+ pages: pages,
120
+ heightChars: heightChars
121
+ };
122
+ }
123
+ function buildTextAnalysis(collected, pageMarkers) {
124
+ var pageLines = collected.pages.map(function(page) {
125
+ return {
126
+ page: page.page,
127
+ lines: (0, _linests.toLines)(page)
128
+ };
129
+ });
130
+ var rendered = (0, _markdownts.buildMarkdown)(pageLines, collected.heightChars, {
131
+ pageMarkers: pageMarkers
132
+ });
133
+ var statsMd = pageMarkers ? rendered.md : (0, _markdownts.buildMarkdown)(pageLines, collected.heightChars, {
134
+ pageMarkers: true
135
+ }).md;
136
+ var hybridPages = collected.pages.filter(function(page) {
137
+ return page.largeImage;
138
+ }).map(function(page) {
139
+ return page.page;
140
+ });
141
+ var report = (0, _reportts.buildReport)({
142
+ numPages: collected.numPages,
143
+ md: rendered.md,
144
+ statsMd: statsMd,
145
+ stats: rendered.stats,
146
+ bodyH: rendered.bodyH,
147
+ headingSizes: rendered.headingSizes,
148
+ hybridPages: hybridPages
149
+ });
150
+ var analysisPages = collected.pages.map(function(page) {
151
+ var _ref;
152
+ var _rendered_pages_find;
153
+ return {
154
+ page: page.page,
155
+ path: 'text',
156
+ words: page.glyphs.map(function(glyph) {
157
+ return sourceWord(glyph, page);
158
+ }),
159
+ blocks: (_ref = (_rendered_pages_find = rendered.pages.find(function(renderedPage) {
160
+ return renderedPage.page === page.page;
161
+ })) === null || _rendered_pages_find === void 0 ? void 0 : _rendered_pages_find.blocks) !== null && _ref !== void 0 ? _ref : []
162
+ };
163
+ });
164
+ var analysis = {
165
+ outputVersion: _reportts.OUTPUT_VERSION,
166
+ report: report,
167
+ pages: analysisPages
168
+ };
169
+ return {
170
+ analysis: analysis,
171
+ markdown: rendered.md,
172
+ words: callbackWords(analysisPages)
173
+ };
174
+ }
175
+ /* 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/Dev/open-source/formats/pdf-to-md/src/text-analysis.ts"],"sourcesContent":["// Shared text-layer analysis. It keeps PDF source runs separate from layout\n// reconstruction, while Markdown blocks retain the source-run indexes that\n// produced them.\nimport type { PageWord } from './geometry.ts';\nimport { toLines } from './lines.ts';\nimport { buildMarkdown } from './markdown.ts';\nimport { buildReport, OUTPUT_VERSION } from './report.ts';\nimport type { Analysis, AnalysisPage, AnalysisWord, CollectResult, Glyph, PageLines } from './types.ts';\n\nfunction sourceWord(glyph: Glyph, dims: { width: number; height: number }): AnalysisWord {\n return {\n text: glyph.s,\n box: {\n x: dims.width > 0 ? glyph.bounds.x / dims.width : 0,\n y: dims.height > 0 ? (dims.height - glyph.bounds.y - glyph.bounds.h) / dims.height : 0,\n w: dims.width > 0 ? glyph.bounds.w / dims.width : 0,\n h: dims.height > 0 ? glyph.bounds.h / dims.height : 0,\n },\n };\n}\n\nfunction callbackWords(pages: AnalysisPage[]): PageWord[] {\n return pages.flatMap((page) => page.words.map((word) => ({ page: page.page, text: word.text, ...word.box })));\n}\n\nexport interface TextAnalysisResult {\n analysis: Analysis;\n markdown: string;\n words: PageWord[];\n}\n\nexport function selectCollectedPages(collected: CollectResult, pageNumbers: Set<number>): CollectResult {\n const pages = collected.pages.filter((page) => pageNumbers.has(page.page));\n const heightChars = new Map<number, number>();\n for (const page of pages) {\n for (const glyph of page.glyphs) heightChars.set(glyph.h, (heightChars.get(glyph.h) ?? 0) + glyph.s.length);\n }\n return { numPages: pages.length, pages, heightChars };\n}\n\n/** Builds the text result once for Markdown, raw analysis, text callbacks,\n * and reporting. The `pages` returned by buildMarkdown own the actual block\n * construction, so this never reconstructs ownership from rendered text. */\nexport function buildTextAnalysis(collected: CollectResult, pageMarkers: boolean): TextAnalysisResult {\n const pageLines: PageLines[] = collected.pages.map((page) => ({ page: page.page, lines: toLines(page) }));\n const rendered = buildMarkdown(pageLines, collected.heightChars, { pageMarkers });\n const statsMd = pageMarkers ? rendered.md : buildMarkdown(pageLines, collected.heightChars, { pageMarkers: true }).md;\n const hybridPages = collected.pages.filter((page) => page.largeImage).map((page) => page.page);\n const report = buildReport({\n numPages: collected.numPages,\n md: rendered.md,\n statsMd,\n stats: rendered.stats,\n bodyH: rendered.bodyH,\n headingSizes: rendered.headingSizes,\n hybridPages,\n });\n const analysisPages: AnalysisPage[] = collected.pages.map((page) => ({\n page: page.page,\n path: 'text',\n words: page.glyphs.map((glyph) => sourceWord(glyph, page)),\n blocks: rendered.pages.find((renderedPage) => renderedPage.page === page.page)?.blocks ?? [],\n }));\n const analysis: Analysis = { outputVersion: OUTPUT_VERSION, report, pages: analysisPages };\n return { analysis, markdown: rendered.md, words: callbackWords(analysisPages) };\n}\n"],"names":["buildTextAnalysis","selectCollectedPages","sourceWord","glyph","dims","text","s","box","x","width","bounds","y","height","h","w","callbackWords","pages","flatMap","page","words","map","word","collected","pageNumbers","filter","has","heightChars","Map","glyphs","set","get","length","numPages","pageMarkers","pageLines","lines","toLines","rendered","buildMarkdown","statsMd","md","hybridPages","largeImage","report","buildReport","stats","bodyH","headingSizes","analysisPages","path","blocks","find","renderedPage","analysis","outputVersion","OUTPUT_VERSION","markdown"],"mappings":"AAAA,4EAA4E;AAC5E,2EAA2E;AAC3E,iBAAiB;;;;;;;;;;;;QAyCDA;eAAAA;;QAZAC;eAAAA;;;uBA3BQ;0BACM;wBACc;;;;;;;;;;;;;;;;;;;;;;;;;;;AAG5C,SAASC,WAAWC,KAAY,EAAEC,IAAuC;IACvE,OAAO;QACLC,MAAMF,MAAMG,CAAC;QACbC,KAAK;YACHC,GAAGJ,KAAKK,KAAK,GAAG,IAAIN,MAAMO,MAAM,CAACF,CAAC,GAAGJ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AE;QAC9F;;IACA,IAAMG,WAAqB;QAAEC,eAAeC,wBAAc;QAAEZ,QAAAA;QAAQ3B,OAAOgC;IAAc;IACzF,OAAO;QAAEK,UAAAA;QAAUG,UAAUnB,SAASG,EAAE;QAAErB,OAAOJ,cAAciC;IAAe;AAChF"}
@@ -1,9 +1,18 @@
1
+ /** Viewport-point AABB for a source text run's transformed advance by
2
+ * font-height box. This is a run box, not fabricated per-token geometry. */
3
+ export interface GlyphBounds {
4
+ x: number;
5
+ y: number;
6
+ w: number;
7
+ h: number;
8
+ }
1
9
  export interface Glyph {
2
10
  s: string;
3
11
  x: number;
4
12
  y: number;
5
13
  w: number;
6
14
  h: number;
15
+ bounds: GlyphBounds;
7
16
  }
8
17
  export interface CollectedPage {
9
18
  page: number;
@@ -11,6 +20,8 @@ export interface CollectedPage {
11
20
  width: number;
12
21
  height: number;
13
22
  textChars: number;
23
+ /** any painted image operator, independent of text-layer density */
24
+ hasImage: boolean;
14
25
  largeImage: boolean;
15
26
  }
16
27
  export interface CollectResult {
@@ -24,6 +35,9 @@ export interface Line {
24
35
  y: number;
25
36
  h: number;
26
37
  col: number;
38
+ /** indexes of the collected PDF text runs that produced this line, in
39
+ * display order. OCR has its own source-word linkage. */
40
+ wordIndexes: number[];
27
41
  }
28
42
  export interface PageLines {
29
43
  page: number;
@@ -46,11 +60,16 @@ export interface MarkdownResult {
46
60
  stats: MarkdownStats;
47
61
  bodyH: number;
48
62
  headingSizes: number[];
63
+ /** The structural blocks that produced `md`, grouped by source page.
64
+ * Markers are rendering provenance and are deliberately not blocks. */
65
+ pages: MarkdownPage[];
49
66
  }
50
67
  /** One row of the per-page QA breakdown ("### pN" blocks) — used to decide
51
68
  * which pages are worth rendering and re-checking (README's "Design contract"). */
52
69
  export interface PageStatsRow {
53
70
  page: number;
71
+ /** producer retained for this page, including in a mixed result */
72
+ path: 'text' | 'ocr';
54
73
  chars: number;
55
74
  headings: number;
56
75
  junkHeadings: number;
@@ -92,6 +111,10 @@ export interface WordConfidenceInput {
92
111
  export interface BuildOcrReportInput {
93
112
  md: string;
94
113
  fallback?: boolean;
114
+ /** Per-page producer map for a mixed result. Omit for OCR-only output. */
115
+ pagePaths?: Map<number, 'text' | 'ocr'>;
116
+ /** text pages retaining a large embedded image, for mixed per-page QA */
117
+ hybridPages?: number[];
95
118
  /** every recognized word, for `report.ts`'s low-confidence detector.
96
119
  * Defaults to [] (a pre-confidence --words-json replay), reporting the detector absent, never wrong. */
97
120
  words?: WordConfidenceInput[];
@@ -102,7 +125,7 @@ export interface Report {
102
125
  /** manually-bumped integer (not the npm package version) — see
103
126
  * `report.ts`'s OUTPUT_VERSION for the bump rule; present on every Report so a frozen baseline's staleness is self-announcing. */
104
127
  outputVersion: number;
105
- path: 'text' | 'ocr';
128
+ path: 'text' | 'ocr' | 'mixed';
106
129
  pages: number;
107
130
  chars: number;
108
131
  charsPerPage: number;
@@ -149,13 +172,20 @@ export interface AnalysisBlock {
149
172
  /** Heading level (integer 1-6); REQUIRED when `type` is `'heading'`,
150
173
  * FORBIDDEN otherwise — toMarkdown()/toText() validate this fail-fast (throws PdfToMdError/'ANALYSIS_INPUT'), never silently ignored. */
151
174
  level?: number;
175
+ /** adjacent Markdown line with no blank separator, used for list items */
176
+ tight?: boolean;
152
177
  wordIndexes: number[];
153
178
  }
154
179
  /** One page's flat words plus its structural blocks. */
155
180
  export interface AnalysisPage {
156
181
  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. */
182
+ /** producer retained for this page; `Analysis.report.path` is `'mixed'`
183
+ * when the document has more than one page producer. */
184
+ path: 'text' | 'ocr';
185
+ /** Flat, page-relative source items; `AnalysisBlock.wordIndexes` indexes
186
+ * into it. OCR boxes are normalized [0,1]. Text-run boxes are page
187
+ * fractions and may extend outside that range when the PDF run extends past
188
+ * the viewport. Both use a bottom-left origin with y up. */
159
189
  words: AnalysisWord[];
160
190
  blocks: AnalysisBlock[];
161
191
  }
@@ -169,3 +199,10 @@ export interface Analysis {
169
199
  report: Report;
170
200
  pages: AnalysisPage[];
171
201
  }
202
+ /** One page's blocks from the text Markdown builder. This is internal
203
+ * rendering evidence, but it is declared here because the shared text
204
+ * analysis consumes it without parsing Markdown back into structure. */
205
+ export interface MarkdownPage {
206
+ page: number;
207
+ blocks: AnalysisBlock[];
208
+ }
@@ -1,9 +1,18 @@
1
+ /** Viewport-point AABB for a source text run's transformed advance by
2
+ * font-height box. This is a run box, not fabricated per-token geometry. */
3
+ export interface GlyphBounds {
4
+ x: number;
5
+ y: number;
6
+ w: number;
7
+ h: number;
8
+ }
1
9
  export interface Glyph {
2
10
  s: string;
3
11
  x: number;
4
12
  y: number;
5
13
  w: number;
6
14
  h: number;
15
+ bounds: GlyphBounds;
7
16
  }
8
17
  export interface CollectedPage {
9
18
  page: number;
@@ -11,6 +20,8 @@ export interface CollectedPage {
11
20
  width: number;
12
21
  height: number;
13
22
  textChars: number;
23
+ /** any painted image operator, independent of text-layer density */
24
+ hasImage: boolean;
14
25
  largeImage: boolean;
15
26
  }
16
27
  export interface CollectResult {
@@ -24,6 +35,9 @@ export interface Line {
24
35
  y: number;
25
36
  h: number;
26
37
  col: number;
38
+ /** indexes of the collected PDF text runs that produced this line, in
39
+ * display order. OCR has its own source-word linkage. */
40
+ wordIndexes: number[];
27
41
  }
28
42
  export interface PageLines {
29
43
  page: number;
@@ -46,11 +60,16 @@ export interface MarkdownResult {
46
60
  stats: MarkdownStats;
47
61
  bodyH: number;
48
62
  headingSizes: number[];
63
+ /** The structural blocks that produced `md`, grouped by source page.
64
+ * Markers are rendering provenance and are deliberately not blocks. */
65
+ pages: MarkdownPage[];
49
66
  }
50
67
  /** One row of the per-page QA breakdown ("### pN" blocks) — used to decide
51
68
  * which pages are worth rendering and re-checking (README's "Design contract"). */
52
69
  export interface PageStatsRow {
53
70
  page: number;
71
+ /** producer retained for this page, including in a mixed result */
72
+ path: 'text' | 'ocr';
54
73
  chars: number;
55
74
  headings: number;
56
75
  junkHeadings: number;
@@ -92,6 +111,10 @@ export interface WordConfidenceInput {
92
111
  export interface BuildOcrReportInput {
93
112
  md: string;
94
113
  fallback?: boolean;
114
+ /** Per-page producer map for a mixed result. Omit for OCR-only output. */
115
+ pagePaths?: Map<number, 'text' | 'ocr'>;
116
+ /** text pages retaining a large embedded image, for mixed per-page QA */
117
+ hybridPages?: number[];
95
118
  /** every recognized word, for `report.ts`'s low-confidence detector.
96
119
  * Defaults to [] (a pre-confidence --words-json replay), reporting the detector absent, never wrong. */
97
120
  words?: WordConfidenceInput[];
@@ -102,7 +125,7 @@ export interface Report {
102
125
  /** manually-bumped integer (not the npm package version) — see
103
126
  * `report.ts`'s OUTPUT_VERSION for the bump rule; present on every Report so a frozen baseline's staleness is self-announcing. */
104
127
  outputVersion: number;
105
- path: 'text' | 'ocr';
128
+ path: 'text' | 'ocr' | 'mixed';
106
129
  pages: number;
107
130
  chars: number;
108
131
  charsPerPage: number;
@@ -149,13 +172,20 @@ export interface AnalysisBlock {
149
172
  /** Heading level (integer 1-6); REQUIRED when `type` is `'heading'`,
150
173
  * FORBIDDEN otherwise — toMarkdown()/toText() validate this fail-fast (throws PdfToMdError/'ANALYSIS_INPUT'), never silently ignored. */
151
174
  level?: number;
175
+ /** adjacent Markdown line with no blank separator, used for list items */
176
+ tight?: boolean;
152
177
  wordIndexes: number[];
153
178
  }
154
179
  /** One page's flat words plus its structural blocks. */
155
180
  export interface AnalysisPage {
156
181
  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. */
182
+ /** producer retained for this page; `Analysis.report.path` is `'mixed'`
183
+ * when the document has more than one page producer. */
184
+ path: 'text' | 'ocr';
185
+ /** Flat, page-relative source items; `AnalysisBlock.wordIndexes` indexes
186
+ * into it. OCR boxes are normalized [0,1]. Text-run boxes are page
187
+ * fractions and may extend outside that range when the PDF run extends past
188
+ * the viewport. Both use a bottom-left origin with y up. */
159
189
  words: AnalysisWord[];
160
190
  blocks: AnalysisBlock[];
161
191
  }
@@ -169,3 +199,10 @@ export interface Analysis {
169
199
  report: Report;
170
200
  pages: AnalysisPage[];
171
201
  }
202
+ /** One page's blocks from the text Markdown builder. This is internal
203
+ * rendering evidence, but it is declared here because the shared text
204
+ * analysis consumes it without parsing Markdown back into structure. */
205
+ export interface MarkdownPage {
206
+ page: number;
207
+ blocks: AnalysisBlock[];
208
+ }
package/dist/cjs/types.js CHANGED
@@ -1,8 +1,7 @@
1
1
  // Shared shapes threaded through the collect -> lines -> markdown -> report
2
2
  // pipeline; kept in one place since every downstream stage uses at least one.
3
- // A positioned glyph run from the PDF's text layer: `s` may be more than one
4
- // character; `y` is flipped so ascending sorts top-down; `h` is font height rounded to 0.1pt.
5
- "use strict";
3
+ /** Viewport-point AABB for a source text run's transformed advance by
4
+ * font-height box. This is a run box, not fabricated per-token geometry. */ "use strict";
6
5
  Object.defineProperty(exports, "__esModule", {
7
6
  value: true
8
7
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/formats/pdf-to-md/src/types.ts"],"sourcesContent":["// Shared shapes threaded through the collect -> lines -> markdown -> report\n// pipeline; kept in one place since every downstream stage uses at least one.\n\n// A positioned glyph run from the PDF's text layer: `s` may be more than one\n// character; `y` is flipped so ascending sorts top-down; `h` is font height rounded to 0.1pt.\nexport interface Glyph {\n s: string;\n x: number;\n y: number;\n w: number;\n h: number;\n}\n\n// One page's worth of collected glyphs plus the geometry collect.ts needs\n// downstream (lines.ts's two-column detection, report.ts's hybrid-page flag).\nexport interface CollectedPage {\n page: number;\n glyphs: Glyph[];\n width: number;\n height: number;\n textChars: number;\n largeImage: boolean;\n}\n\n// collect.ts's return value: selected pages plus the char-weighted\n// font-height histogram, built ONLY from those pages (matters for a `--pages` re-extraction — see collect.ts).\nexport interface CollectResult {\n numPages: number;\n pages: CollectedPage[];\n heightChars: Map<number, number>;\n}\n\n// A visual line assembled from glyphs (lines.ts's `toLines`): `h` is the\n// char-weighted dominant height (not max); `col` is 0 (left/only) or 1 (right, de-braided page).\nexport interface Line {\n text: string;\n x: number;\n y: number;\n h: number;\n col: number;\n}\n\n// One page's lines, as src/extract.ts assembles them for buildMarkdown.\nexport interface PageLines {\n page: number;\n lines: Line[];\n}\n\nexport interface BuildMarkdownOptions {\n pageMarkers?: boolean;\n}\n\n// Running counters src/markdown.ts accumulates while building the output,\n// surfaced in the QA report (src/report.ts's buildReport).\nexport interface MarkdownStats {\n headings: number;\n listItems: number;\n paragraphs: number;\n joinedPairs: number;\n reflowed: number;\n callouts: number;\n closedHyphens: number;\n}\n\nexport interface MarkdownResult {\n md: string;\n stats: MarkdownStats;\n bodyH: number;\n headingSizes: number[];\n}\n\n/** One row of the per-page QA breakdown (\"### pN\" blocks) — used to decide\n * which pages are worth rendering and re-checking (README's \"Design contract\"). */\nexport interface PageStatsRow {\n page: number;\n chars: number;\n headings: number;\n junkHeadings: number;\n floats: number;\n paragraphs: number;\n danglingLong: number;\n danglingShort: number;\n /** count of `> [review: ...]` lines — blocks the geometry could not order\n * and labeled instead of guessing (README's \"Design contract\"). */\n reviewBlocks: number;\n /** present only on the text path's rows; omitted (not `false`) on the OCR\n * path, which has no per-page hybrid-image signal. */\n largeImages?: boolean;\n /** count of words below `report.ts`'s LOW_CONFIDENCE_THRESHOLD; omitted (not\n * 0) when the page had no confidence data at all, so \"measured 0\" and \"nothing to measure\" stay distinct. */\n lowConfidenceWords?: number;\n /** the suspect tokens behind `lowConfidenceWords`, worst-confidence first\n * and capped (`report.ts`'s LOW_CONFIDENCE_SAMPLE_CAP) so a chart-heavy page can't bloat the JSON. */\n lowConfidenceSample?: string[];\n}\n\n// buildReport's params (src/report.ts) — everything the text (default) path\n// hands over after running collect -> lines -> markdown.\nexport interface BuildReportInput {\n numPages: number;\n md: string;\n /** identical to `md` but always carries \"### pN\" markers, so pageStats is\n * measured independent of the caller's `--page-markers` choice; same string as `md` when markers were requested. */\n statsMd: string;\n stats: MarkdownStats;\n bodyH: number;\n headingSizes: number[];\n hybridPages?: number[];\n}\n\n/** One recognized word's page/text/confidence — `report.ts`'s low-confidence\n * detector input; a structural subset of OcrWordInput kept here so `types.ts` doesn't import the library-layer module that depends on it. */\nexport interface WordConfidenceInput {\n page: number;\n text: string;\n confidence?: number;\n}\n\nexport interface BuildOcrReportInput {\n md: string;\n fallback?: boolean;\n /** every recognized word, for `report.ts`'s low-confidence detector.\n * Defaults to [] (a pre-confidence --words-json replay), reporting the detector absent, never wrong. */\n words?: WordConfidenceInput[];\n}\n\n/** Per-document and per-page QA metrics returned by every extraction entry\n * point, discriminated by `path`; OCR-only and text-only fields are grouped below. */\nexport interface Report {\n /** manually-bumped integer (not the npm package version) — see\n * `report.ts`'s OUTPUT_VERSION for the bump rule; present on every Report so a frozen baseline's staleness is self-announcing. */\n outputVersion: number;\n path: 'text' | 'ocr';\n pages: number;\n chars: number;\n charsPerPage: number;\n sparse: boolean;\n headings: number;\n junkHeadings: number;\n paragraphs: number;\n callouts: number;\n danglingLong: number;\n danglingShort: number;\n /** total `> [review: ...]` blocks across all pages (sum of pageStats'\n * reviewBlocks); always 0 on the text path — only the OCR path emits review markers. */\n reviewBlocks: number;\n /** document-level sum of pageStats' `lowConfidenceWords` — see that\n * field for why 0 can mean \"measured 0\" or \"nothing to measure\". */\n lowConfidenceWords: number;\n pageStats: PageStatsRow[];\n\n // --- OCR-only ---\n floats?: number;\n ocrFallback?: boolean;\n\n // --- text-only ---\n bodyFontHeight?: number;\n headingSizes?: number[];\n listItems?: number;\n joinedPairs?: number;\n closedHyphens?: number;\n hybridPages?: number[];\n}\n\n// --- Analysis: the raw-mode IR (analyze() produces it; toMarkdown()/toText()\n// in render-analysis.ts render it — see toMarkdown's doc comment for the fail-fast validation contract) ---\n\n/** One recognized/collected word, page-relative; `box` is always present.\n * See `AnalysisPage.words` for the coordinate contract and per-path granularity difference. */\nexport interface AnalysisWord {\n text: string;\n box: { x: number; y: number; w: number; h: number };\n confidence?: number;\n}\n\n/** One structural block; `wordIndexes` links it to its page's `words` list (blocks -> words only).\n * `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. */\nexport interface AnalysisBlock {\n type: 'heading' | 'paragraph' | 'float' | 'review';\n text: string;\n /** Heading level (integer 1-6); REQUIRED when `type` is `'heading'`,\n * FORBIDDEN otherwise — toMarkdown()/toText() validate this fail-fast (throws PdfToMdError/'ANALYSIS_INPUT'), never silently ignored. */\n level?: number;\n wordIndexes: number[];\n}\n\n/** One page's flat words plus its structural blocks. */\nexport interface AnalysisPage {\n page: number;\n /** Flat, page-relative word list; `AnalysisBlock.wordIndexes` indexes into it. `box` is always normalized [0,1], origin bottom-left, y up, regardless of path.\n * 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. */\n words: AnalysisWord[];\n blocks: AnalysisBlock[];\n}\n\n/** analyze()'s output: plain, JSON-serializable per-page words/blocks plus\n * the same QA `report` the other entry points return. */\nexport interface Analysis {\n /** manually-bumped integer — see `Report.outputVersion` / `report.ts`'s OUTPUT_VERSION. */\n outputVersion: number;\n /** the same QA report extractText/extractOcr/pdfToMarkdown return, always\n * 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. */\n report: Report;\n pages: AnalysisPage[];\n}\n"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,8EAA8E;AAE9E,6EAA6E;AAC7E,8FAA8F"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/open-source/formats/pdf-to-md/src/types.ts"],"sourcesContent":["// Shared shapes threaded through the collect -> lines -> markdown -> report\n// pipeline; kept in one place since every downstream stage uses at least one.\n\n/** Viewport-point AABB for a source text run's transformed advance by\n * font-height box. This is a run box, not fabricated per-token geometry. */\nexport interface GlyphBounds {\n x: number;\n y: number;\n w: number;\n h: number;\n}\n\n// A positioned glyph run from the PDF's text layer: `s` may be more than one\n// character. x/y are the transformed baseline origin in viewport points;\n// w/h are its advance and font height, and bounds is their viewport AABB.\nexport interface Glyph {\n s: string;\n x: number;\n y: number;\n w: number;\n h: number;\n bounds: GlyphBounds;\n}\n\n// One page's worth of collected glyphs plus the geometry collect.ts needs\n// downstream (lines.ts's two-column detection, report.ts's hybrid-page flag).\nexport interface CollectedPage {\n page: number;\n glyphs: Glyph[];\n width: number;\n height: number;\n textChars: number;\n /** any painted image operator, independent of text-layer density */\n hasImage: boolean;\n largeImage: boolean;\n}\n\n// collect.ts's return value: selected pages plus the char-weighted\n// font-height histogram, built ONLY from those pages (matters for a `--pages` re-extraction — see collect.ts).\nexport interface CollectResult {\n numPages: number;\n pages: CollectedPage[];\n heightChars: Map<number, number>;\n}\n\n// A visual line assembled from glyphs (lines.ts's `toLines`): `h` is the\n// char-weighted dominant height (not max); `col` is 0 (left/only) or 1 (right, de-braided page).\nexport interface Line {\n text: string;\n x: number;\n y: number;\n h: number;\n col: number;\n /** indexes of the collected PDF text runs that produced this line, in\n * display order. OCR has its own source-word linkage. */\n wordIndexes: number[];\n}\n\n// One page's lines, as src/extract.ts assembles them for buildMarkdown.\nexport interface PageLines {\n page: number;\n lines: Line[];\n}\n\nexport interface BuildMarkdownOptions {\n pageMarkers?: boolean;\n}\n\n// Running counters src/markdown.ts accumulates while building the output,\n// surfaced in the QA report (src/report.ts's buildReport).\nexport interface MarkdownStats {\n headings: number;\n listItems: number;\n paragraphs: number;\n joinedPairs: number;\n reflowed: number;\n callouts: number;\n closedHyphens: number;\n}\n\nexport interface MarkdownResult {\n md: string;\n stats: MarkdownStats;\n bodyH: number;\n headingSizes: number[];\n /** The structural blocks that produced `md`, grouped by source page.\n * Markers are rendering provenance and are deliberately not blocks. */\n pages: MarkdownPage[];\n}\n\n/** One row of the per-page QA breakdown (\"### pN\" blocks) — used to decide\n * which pages are worth rendering and re-checking (README's \"Design contract\"). */\nexport interface PageStatsRow {\n page: number;\n /** producer retained for this page, including in a mixed result */\n path: 'text' | 'ocr';\n chars: number;\n headings: number;\n junkHeadings: number;\n floats: number;\n paragraphs: number;\n danglingLong: number;\n danglingShort: number;\n /** count of `> [review: ...]` lines — blocks the geometry could not order\n * and labeled instead of guessing (README's \"Design contract\"). */\n reviewBlocks: number;\n /** present only on the text path's rows; omitted (not `false`) on the OCR\n * path, which has no per-page hybrid-image signal. */\n largeImages?: boolean;\n /** count of words below `report.ts`'s LOW_CONFIDENCE_THRESHOLD; omitted (not\n * 0) when the page had no confidence data at all, so \"measured 0\" and \"nothing to measure\" stay distinct. */\n lowConfidenceWords?: number;\n /** the suspect tokens behind `lowConfidenceWords`, worst-confidence first\n * and capped (`report.ts`'s LOW_CONFIDENCE_SAMPLE_CAP) so a chart-heavy page can't bloat the JSON. */\n lowConfidenceSample?: string[];\n}\n\n// buildReport's params (src/report.ts) — everything the text (default) path\n// hands over after running collect -> lines -> markdown.\nexport interface BuildReportInput {\n numPages: number;\n md: string;\n /** identical to `md` but always carries \"### pN\" markers, so pageStats is\n * measured independent of the caller's `--page-markers` choice; same string as `md` when markers were requested. */\n statsMd: string;\n stats: MarkdownStats;\n bodyH: number;\n headingSizes: number[];\n hybridPages?: number[];\n}\n\n/** One recognized word's page/text/confidence — `report.ts`'s low-confidence\n * detector input; a structural subset of OcrWordInput kept here so `types.ts` doesn't import the library-layer module that depends on it. */\nexport interface WordConfidenceInput {\n page: number;\n text: string;\n confidence?: number;\n}\n\nexport interface BuildOcrReportInput {\n md: string;\n fallback?: boolean;\n /** Per-page producer map for a mixed result. Omit for OCR-only output. */\n pagePaths?: Map<number, 'text' | 'ocr'>;\n /** text pages retaining a large embedded image, for mixed per-page QA */\n hybridPages?: number[];\n /** every recognized word, for `report.ts`'s low-confidence detector.\n * Defaults to [] (a pre-confidence --words-json replay), reporting the detector absent, never wrong. */\n words?: WordConfidenceInput[];\n}\n\n/** Per-document and per-page QA metrics returned by every extraction entry\n * point, discriminated by `path`; OCR-only and text-only fields are grouped below. */\nexport interface Report {\n /** manually-bumped integer (not the npm package version) — see\n * `report.ts`'s OUTPUT_VERSION for the bump rule; present on every Report so a frozen baseline's staleness is self-announcing. */\n outputVersion: number;\n path: 'text' | 'ocr' | 'mixed';\n pages: number;\n chars: number;\n charsPerPage: number;\n sparse: boolean;\n headings: number;\n junkHeadings: number;\n paragraphs: number;\n callouts: number;\n danglingLong: number;\n danglingShort: number;\n /** total `> [review: ...]` blocks across all pages (sum of pageStats'\n * reviewBlocks); always 0 on the text path — only the OCR path emits review markers. */\n reviewBlocks: number;\n /** document-level sum of pageStats' `lowConfidenceWords` — see that\n * field for why 0 can mean \"measured 0\" or \"nothing to measure\". */\n lowConfidenceWords: number;\n pageStats: PageStatsRow[];\n\n // --- OCR-only ---\n floats?: number;\n ocrFallback?: boolean;\n\n // --- text-only ---\n bodyFontHeight?: number;\n headingSizes?: number[];\n listItems?: number;\n joinedPairs?: number;\n closedHyphens?: number;\n hybridPages?: number[];\n}\n\n// --- Analysis: the raw-mode IR (analyze() produces it; toMarkdown()/toText()\n// in render-analysis.ts render it — see toMarkdown's doc comment for the fail-fast validation contract) ---\n\n/** One recognized/collected word, page-relative; `box` is always present.\n * See `AnalysisPage.words` for the coordinate contract and per-path granularity difference. */\nexport interface AnalysisWord {\n text: string;\n box: { x: number; y: number; w: number; h: number };\n confidence?: number;\n}\n\n/** One structural block; `wordIndexes` links it to its page's `words` list (blocks -> words only).\n * `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. */\nexport interface AnalysisBlock {\n type: 'heading' | 'paragraph' | 'float' | 'review';\n text: string;\n /** Heading level (integer 1-6); REQUIRED when `type` is `'heading'`,\n * FORBIDDEN otherwise — toMarkdown()/toText() validate this fail-fast (throws PdfToMdError/'ANALYSIS_INPUT'), never silently ignored. */\n level?: number;\n /** adjacent Markdown line with no blank separator, used for list items */\n tight?: boolean;\n wordIndexes: number[];\n}\n\n/** One page's flat words plus its structural blocks. */\nexport interface AnalysisPage {\n page: number;\n /** producer retained for this page; `Analysis.report.path` is `'mixed'`\n * when the document has more than one page producer. */\n path: 'text' | 'ocr';\n /** Flat, page-relative source items; `AnalysisBlock.wordIndexes` indexes\n * into it. OCR boxes are normalized [0,1]. Text-run boxes are page\n * fractions and may extend outside that range when the PDF run extends past\n * the viewport. Both use a bottom-left origin with y up. */\n words: AnalysisWord[];\n blocks: AnalysisBlock[];\n}\n\n/** analyze()'s output: plain, JSON-serializable per-page words/blocks plus\n * the same QA `report` the other entry points return. */\nexport interface Analysis {\n /** manually-bumped integer — see `Report.outputVersion` / `report.ts`'s OUTPUT_VERSION. */\n outputVersion: number;\n /** the same QA report extractText/extractOcr/pdfToMarkdown return, always\n * 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. */\n report: Report;\n pages: AnalysisPage[];\n}\n\n/** One page's blocks from the text Markdown builder. This is internal\n * rendering evidence, but it is declared here because the shared text\n * analysis consumes it without parsing Markdown back into structure. */\nexport interface MarkdownPage {\n page: number;\n blocks: AnalysisBlock[];\n}\n"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,8EAA8E;AAE9E;0EAC0E"}
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/formats/pdf-to-md/src/validate.ts"],"sourcesContent":["// validate.ts — input-shape validation shared by analyze.ts and extract.ts,\n// kept out of both to dodge their value-level import cycle (extract.ts imports analyze.ts's buildOcrAnalysisPages; both need this).\nimport { PdfToMdError } from './errors.ts';\nimport type { OcrWordInput } from './extract.ts';\n\n/** Validates the one option every entry point accepts before touching the\n * PDF. Type-only import from `extract.ts` keeps this cycle-free. */\nexport function validatePages(pages: unknown): void {\n if (pages === undefined) return;\n const isRecord = typeof pages === 'object' && pages !== null;\n const first = isRecord ? (pages as Record<string, unknown>).first : undefined;\n const last = isRecord ? (pages as Record<string, unknown>).last : undefined;\n const firstOk = typeof first === 'number' && Number.isFinite(first) && first >= 1;\n const lastOk = last === undefined || (typeof last === 'number' && Number.isFinite(last) && last >= (first as number));\n if (!isRecord || !firstOk || !lastOk) {\n throw new PdfToMdError('PAGE_RANGE', `pages option must be { first: number, last?: number } with first >= 1 and last >= first (got ${JSON.stringify(pages)})`);\n }\n}\n\n/** Validates analyze()'s non-string `input` branch (`{ words }`) before\n * `.words` is read, so a plain-JS mistake like `analyze(null)` throws PdfToMdError/WORDS_INPUT instead of a raw TypeError. */\nexport function validateWordsInput(input: unknown): OcrWordInput[] {\n const isRecord = typeof input === 'object' && input !== null;\n const words = isRecord ? (input as Record<string, unknown>).words : undefined;\n if (!Array.isArray(words)) {\n throw new PdfToMdError('WORDS_INPUT', `analyze() input must be a pdf path (string) or { words: OcrWordInput[] } (got ${isRecord ? JSON.stringify(input) : String(input)})`);\n }\n return words as OcrWordInput[];\n}\n\n/** Runtime shape guard for `buildOcrAnalysisPages`'s input: a plain-JS\n * caller bypasses the TS union, so this turns a raw TypeError into PdfToMdError before any property is read off it. */\nexport function validateOcrAnalysisInput(input: unknown): { pdfPath: string } | { words: OcrWordInput[] } {\n if (typeof input === 'string') {\n throw new PdfToMdError('PDF_OPEN', `extractOcr/analyze input must be { pdfPath: string } or { words: OcrWordInput[] }, not a bare path string (got ${JSON.stringify(input)}) — did you mean { pdfPath: ${JSON.stringify(input)} }?`);\n }\n const isRecord = typeof input === 'object' && input !== null;\n const rawPdfPath = isRecord ? (input as Record<string, unknown>).pdfPath : undefined;\n const rawWords = isRecord ? (input as Record<string, unknown>).words : undefined;\n if (!isRecord || (rawPdfPath === undefined && rawWords === undefined)) {\n throw new PdfToMdError('WORDS_INPUT', `extractOcr/analyze input must be { pdfPath: string } or { words: OcrWordInput[] } (got ${isRecord ? JSON.stringify(input) : String(input)})`);\n }\n if (rawWords !== undefined && !Array.isArray(rawWords)) {\n throw new PdfToMdError('WORDS_INPUT', `extractOcr/analyze { words } input must be an array (got ${JSON.stringify(rawWords)})`);\n }\n if (rawPdfPath !== undefined && typeof rawPdfPath !== 'string') {\n throw new PdfToMdError('PDF_OPEN', `extractOcr/analyze { pdfPath } input must be a string (got ${JSON.stringify(rawPdfPath)})`);\n }\n if (rawWords !== undefined) {\n for (const w of rawWords as unknown[]) {\n const rec = w as Record<string, unknown>;\n if (typeof rec.page !== 'number' || typeof rec.text !== 'string' || typeof rec.x !== 'number' || typeof rec.y !== 'number' || typeof rec.w !== 'number' || typeof rec.h !== 'number') {\n throw new PdfToMdError('WORDS_INPUT', `malformed word entry (need {page, text, x, y, w, h}): ${JSON.stringify(w)}`);\n }\n }\n return { words: rawWords as OcrWordInput[] };\n }\n return { pdfPath: rawPdfPath as string };\n}\n"],"names":["validateOcrAnalysisInput","validatePages","validateWordsInput","pages","undefined","isRecord","first","last","firstOk","Number","isFinite","lastOk","PdfToMdError","JSON","stringify","input","words","Array","isArray","String","rawPdfPath","pdfPath","rawWords","w","rec","page","text","x","y","h"],"mappings":"AAAA,4EAA4E;AAC5E,oIAAoI;;;;;;;;;;;;QA+BpHA;eAAAA;;QAzBAC;eAAAA;;QAcAC;eAAAA;;;wBAnBa;;;;;AAKtB,SAASD,cAAcE,KAAc;IAC1C,IAAIA,UAAUC,WAAW;IACzB,IAAMC,WAAW,CAAA,OAAOF,sCAAP,SAAOA,MAAI,MAAM,YAAYA,UAAU;IACxD,IAAMG,QAAQD,WAAW,AAACF,MAAkCG,KAAK,GAAGF;IACpE,IAAMG,OAAOF,WAAW,AAACF,MAAkCI,IAAI,GAAGH;IAClE,IAAMI,UAAU,OAAOF,UAAU,YAAYG,OAAOC,QAAQ,CAACJ,UAAUA,SAAS;IAChF,IAAMK,SAASJ,SAASH,aAAc,OAAOG,SAAS,YAAYE,OAA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,aAAa,OAAOgB,eAAe,UAAU;QAC9D,MAAM,IAAIR,sBAAY,CAAC,YAAY,AAAC,8DAAwF,OAA3BC,KAAKC,SAAS,CAACM,aAAY;IAC9H;IACA,IAAIE,aAAalB,WAAW;YACrB,kCAAA,2BAAA;;YAAL,QAAK,YAAWkB,6BAAX,SAAA,6BAAA,QAAA,yBAAA,iCAAkC;gBAAlC,IAAMC,IAAN;gBACH,IAAMC,MAAMD;gBACZ,IAAI,OAAOC,IAAIC,IAAI,KAAK,YAAY,OAAOD,IAAIE,IAAI,KAAK,YAAY,OAAOF,IAAIG,CAAC,KAAK,YAAY,OAAOH,IAAII,CAAC,KAAK,YAAY,OAAOJ,IAAID,CAAC,KAAK,YAAY,OAAOC,IAAIK,CAAC,KAAK,UAAU;oBACpL,MAAM,IAAIjB,sBAAY,CAAC,eAAe,AAAC,yDAA0E,OAAlBC,KAAKC,SAAS,CAACS;gBAChH;YACF;;YALK;YAAA;;;qBAAA,6BAAA;oBAAA;;;oBAAA;0BAAA;;;;QAML,OAAO;YAAEP,OAAOM;QAA2B;IAC7C;IACA,OAAO;QAAED,SAASD;IAAqB;AACzC"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/open-source/formats/pdf-to-md/src/validate.ts"],"sourcesContent":["// validate.ts — input-shape validation shared by analyze.ts and extract.ts,\n// kept out of both to dodge their value-level import cycle (extract.ts imports analyze.ts's buildOcrAnalysisPages; both need this).\nimport { PdfToMdError } from './errors.ts';\nimport type { OcrWordInput } from './extract.ts';\n\n/** Validates the one option every entry point accepts before touching the\n * PDF. Type-only import from `extract.ts` keeps this cycle-free. */\nexport function validatePages(pages: unknown): void {\n if (pages === undefined) return;\n const isRecord = typeof pages === 'object' && pages !== null;\n const first = isRecord ? (pages as Record<string, unknown>).first : undefined;\n const last = isRecord ? (pages as Record<string, unknown>).last : undefined;\n const firstOk = typeof first === 'number' && Number.isFinite(first) && first >= 1;\n const lastOk = last === undefined || (typeof last === 'number' && Number.isFinite(last) && last >= (first as number));\n if (!isRecord || !firstOk || !lastOk) {\n throw new PdfToMdError('PAGE_RANGE', `pages option must be { first: number, last?: number } with first >= 1 and last >= first (got ${JSON.stringify(pages)})`);\n }\n}\n\n/** Validates analyze()'s non-string `input` branch (`{ words }`) before\n * `.words` is read, so a plain-JS mistake like `analyze(null)` throws PdfToMdError/WORDS_INPUT instead of a raw TypeError. */\nexport function validateWordsInput(input: unknown): OcrWordInput[] {\n const isRecord = typeof input === 'object' && input !== null;\n const words = isRecord ? (input as Record<string, unknown>).words : undefined;\n if (!Array.isArray(words)) {\n throw new PdfToMdError('WORDS_INPUT', `analyze() input must be a pdf path (string) or { words: OcrWordInput[] } (got ${isRecord ? JSON.stringify(input) : String(input)})`);\n }\n return words as OcrWordInput[];\n}\n\n/** Runtime shape guard for `buildOcrAnalysisPages`'s input: a plain-JS\n * caller bypasses the TS union, so this turns a raw TypeError into PdfToMdError before any property is read off it. */\nexport function validateOcrAnalysisInput(input: unknown): { pdfPath: string } | { words: OcrWordInput[] } {\n if (typeof input === 'string') {\n throw new PdfToMdError('PDF_OPEN', `extractOcr/analyze input must be { pdfPath: string } or { words: OcrWordInput[] }, not a bare path string (got ${JSON.stringify(input)}) — did you mean { pdfPath: ${JSON.stringify(input)} }?`);\n }\n const isRecord = typeof input === 'object' && input !== null;\n const rawPdfPath = isRecord ? (input as Record<string, unknown>).pdfPath : undefined;\n const rawWords = isRecord ? (input as Record<string, unknown>).words : undefined;\n if (!isRecord || (rawPdfPath === undefined && rawWords === undefined)) {\n throw new PdfToMdError('WORDS_INPUT', `extractOcr/analyze input must be { pdfPath: string } or { words: OcrWordInput[] } (got ${isRecord ? JSON.stringify(input) : String(input)})`);\n }\n if (rawWords !== undefined && !Array.isArray(rawWords)) {\n throw new PdfToMdError('WORDS_INPUT', `extractOcr/analyze { words } input must be an array (got ${JSON.stringify(rawWords)})`);\n }\n if (rawPdfPath !== undefined && typeof rawPdfPath !== 'string') {\n throw new PdfToMdError('PDF_OPEN', `extractOcr/analyze { pdfPath } input must be a string (got ${JSON.stringify(rawPdfPath)})`);\n }\n if (rawWords !== undefined) {\n for (const w of rawWords as unknown[]) {\n const rec = w as Record<string, unknown>;\n if (typeof rec.page !== 'number' || typeof rec.text !== 'string' || typeof rec.x !== 'number' || typeof rec.y !== 'number' || typeof rec.w !== 'number' || typeof rec.h !== 'number') {\n throw new PdfToMdError('WORDS_INPUT', `malformed word entry (need {page, text, x, y, w, h}): ${JSON.stringify(w)}`);\n }\n }\n return { words: rawWords as OcrWordInput[] };\n }\n return { pdfPath: rawPdfPath as string };\n}\n"],"names":["validateOcrAnalysisInput","validatePages","validateWordsInput","pages","undefined","isRecord","first","last","firstOk","Number","isFinite","lastOk","PdfToMdError","JSON","stringify","input","words","Array","isArray","String","rawPdfPath","pdfPath","rawWords","w","rec","page","text","x","y","h"],"mappings":"AAAA,4EAA4E;AAC5E,oIAAoI;;;;;;;;;;;;QA+BpHA;eAAAA;;QAzBAC;eAAAA;;QAcAC;eAAAA;;;wBAnBa;;;;;AAKtB,SAASD,cAAcE,KAAc;IAC1C,IAAIA,UAAUC,WAAW;IACzB,IAAMC,WAAW,CAAA,OAAOF,sCAAP,SAAOA,MAAI,MAAM,YAAYA,UAAU;IACxD,IAAMG,QAAQD,WAAW,AAACF,MAAkCG,KAAK,GAAGF;IACpE,IAAMG,OAAOF,WAAW,AAACF,MAAkCI,IAAI,GAAGH;IAClE,IAAMI,UAAU,OAAOF,UAAU,YAAYG,OAAOC,QAAQ,CAACJ,UAAUA,SAAS;IAChF,IAAMK,SAASJ,SAASH,aAAc,OAAOG,SAAS,YAAYE,OAAOC,QAAQ,CAACH,SAASA,QAASD;IACpG,IAAI,CAACD,YAAY,CAACG,WAAW,CAACG,QAAQ;QACpC,MAAM,IAAIC,sBAAY,CAAC,cAAc,AAAC,gGAAqH,OAAtBC,KAAKC,SAAS,CAACX,QAAO;IAC7J;AACF;AAIO,SAASD,mBAAmBa,KAAc;IAC/C,IAAMV,WAAW,CAAA,OAAOU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lC,IAAMC,IAAN;gBACH,IAAMC,MAAMD;gBACZ,IAAI,OAAOC,IAAIC,IAAI,KAAK,YAAY,OAAOD,IAAIE,IAAI,KAAK,YAAY,OAAOF,IAAIG,CAAC,KAAK,YAAY,OAAOH,IAAII,CAAC,KAAK,YAAY,OAAOJ,IAAID,CAAC,KAAK,YAAY,OAAOC,IAAIK,CAAC,KAAK,UAAU;oBACpL,MAAM,IAAIjB,sBAAY,CAAC,eAAe,AAAC,yDAA0E,OAAlBC,KAAKC,SAAS,CAACS;gBAChH;YACF;;YALK;YAAA;;;qBAAA,6BAAA;oBAAA;;;oBAAA;0BAAA;;;;QAML,OAAO;YAAEP,OAAOM;QAA2B;IAC7C;IACA,OAAO;QAAED,SAASD;IAAqB;AACzC"}
@@ -28,7 +28,9 @@ export declare function buildOcrAnalysisPages(input: {
28
28
  * `Analysis`: plain, JSON-serializable per-page `words`/`blocks` plus the same QA `report` the other entry points return. Render with toMarkdown()/toText(), or hand-edit/splice it (no merge API — see toMarkdown's doc comment).
29
29
  *
30
30
  * @param input a bare pdf path, or `{ words }` to replay a dump (always analyzed as OCR) — unlike extractOcr, never `{ pdfPath }`
31
- * @param opts see {@link AnalyzeOptions}; for a pdf path, `opts.path` picks 'text' (default) or 'ocr' — analyze() makes no auto-fallback decision (that's pdfToMarkdown's job)
31
+ * @param opts see {@link AnalyzeOptions}; for a PDF path, `path` explicitly
32
+ * selects text (default) or OCR. Automatic per-page routing belongs to
33
+ * pdfToMarkdown and the CLI output formats.
32
34
  */
33
35
  export declare function analyze(input: string | {
34
36
  words: OcrWordInput[];