@effortlessmotion/pdf-to-md 0.1.0 → 0.1.2

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 (53) hide show
  1. package/dist/cjs/analyze.js.map +1 -1
  2. package/dist/cjs/audit.js.map +1 -1
  3. package/dist/cjs/cli/audit.js.map +1 -1
  4. package/dist/cjs/cli/extract.js.map +1 -1
  5. package/dist/cjs/cli/index.js.map +1 -1
  6. package/dist/cjs/cli/render.js.map +1 -1
  7. package/dist/cjs/cli/types.js.map +1 -1
  8. package/dist/cjs/cli.js.map +1 -1
  9. package/dist/cjs/collect.js.map +1 -1
  10. package/dist/cjs/dict.js.map +1 -1
  11. package/dist/cjs/emit.js.map +1 -1
  12. package/dist/cjs/engines/tesseract.js.map +1 -1
  13. package/dist/cjs/errors.js.map +1 -1
  14. package/dist/cjs/extract.js.map +1 -1
  15. package/dist/cjs/geometry.js.map +1 -1
  16. package/dist/cjs/index.js.map +1 -1
  17. package/dist/cjs/lines.js.map +1 -1
  18. package/dist/cjs/markdown.js.map +1 -1
  19. package/dist/cjs/page-marker.js.map +1 -1
  20. package/dist/cjs/pdf-open.js.map +1 -1
  21. package/dist/cjs/raster.js.map +1 -1
  22. package/dist/cjs/render-analysis.js.map +1 -1
  23. package/dist/cjs/report.js.map +1 -1
  24. package/dist/cjs/resolve.js.map +1 -1
  25. package/dist/cjs/types.js.map +1 -1
  26. package/dist/cjs/validate.js.map +1 -1
  27. package/dist/esm/analyze.js.map +1 -1
  28. package/dist/esm/audit.js.map +1 -1
  29. package/dist/esm/cli/audit.js.map +1 -1
  30. package/dist/esm/cli/extract.js.map +1 -1
  31. package/dist/esm/cli/index.js.map +1 -1
  32. package/dist/esm/cli/render.js.map +1 -1
  33. package/dist/esm/cli/types.js.map +1 -1
  34. package/dist/esm/cli.js.map +1 -1
  35. package/dist/esm/collect.js.map +1 -1
  36. package/dist/esm/dict.js.map +1 -1
  37. package/dist/esm/emit.js.map +1 -1
  38. package/dist/esm/engines/tesseract.js.map +1 -1
  39. package/dist/esm/errors.js.map +1 -1
  40. package/dist/esm/extract.js.map +1 -1
  41. package/dist/esm/geometry.js.map +1 -1
  42. package/dist/esm/index.js.map +1 -1
  43. package/dist/esm/lines.js.map +1 -1
  44. package/dist/esm/markdown.js.map +1 -1
  45. package/dist/esm/page-marker.js.map +1 -1
  46. package/dist/esm/pdf-open.js.map +1 -1
  47. package/dist/esm/raster.js.map +1 -1
  48. package/dist/esm/render-analysis.js.map +1 -1
  49. package/dist/esm/report.js.map +1 -1
  50. package/dist/esm/resolve.js.map +1 -1
  51. package/dist/esm/types.js.map +1 -1
  52. package/dist/esm/validate.js.map +1 -1
  53. package/package.json +10 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Projects/pdf-to-md/src/render-analysis.ts"],"sourcesContent":["// Pure renderers over the Analysis IR: toMarkdown()/toText() are the public,\n// validated entry points; renderPagesToMarkdown/renderPagesToText below are the unvalidated core, reused (unvalidated) by src/analyze.ts.\nimport { PdfToMdError } from './errors.ts';\nimport { pageMarkerLine } from './page-marker.ts';\nimport type { Analysis, AnalysisBlock, AnalysisPage } from './types.ts';\n\nconst BLOCK_TYPES = new Set(['heading', 'paragraph', 'float', 'review']);\n\n// Whole-object, fail-fast validation: every page/block/wordIndexes entry is\n// checked BEFORE toMarkdown/toText render a single character — a malformed Analysis must never produce partial output, only a clean throw.\nfunction validateAnalysis(analysis: unknown): asserts analysis is Analysis {\n const fail = (msg: string): never => {\n throw new PdfToMdError('ANALYSIS_INPUT', msg);\n };\n if (typeof analysis !== 'object' || analysis === null) fail('Analysis must be an object');\n const a = analysis as Record<string, unknown>;\n if (typeof a.report !== 'object' || a.report === null) fail('Analysis.report must be an object');\n const path = (a.report as Record<string, unknown>).path;\n if (path !== 'text' && path !== 'ocr') fail(`Analysis.report.path must be \"text\" or \"ocr\" (got ${JSON.stringify(path)})`);\n if (!Array.isArray(a.pages)) fail('Analysis.pages must be an array');\n\n for (const [pi, page] of (a.pages as unknown[]).entries()) {\n if (typeof page !== 'object' || page === null) fail(`Analysis.pages[${pi}] must be an object`);\n const p = page as Record<string, unknown>;\n if (typeof p.page !== 'number') fail(`Analysis.pages[${pi}].page must be a number`);\n if (!Array.isArray(p.words)) fail(`Analysis.pages[${pi}].words must be an array`);\n for (const [wi, w] of (p.words as unknown[]).entries()) {\n if (typeof w !== 'object' || w === null || typeof (w as Record<string, unknown>).text !== 'string') {\n fail(`Analysis.pages[${pi}].words[${wi}] must be an object with a string 'text'`);\n }\n }\n const wordCount = (p.words as unknown[]).length;\n\n if (!Array.isArray(p.blocks)) fail(`Analysis.pages[${pi}].blocks must be an array`);\n for (const [bi, b] of (p.blocks as unknown[]).entries()) {\n if (typeof b !== 'object' || b === null) fail(`Analysis.pages[${pi}].blocks[${bi}] must be an object`);\n const block = b as Record<string, unknown>;\n if (typeof block.type !== 'string' || !BLOCK_TYPES.has(block.type)) {\n fail(`Analysis.pages[${pi}].blocks[${bi}].type must be one of heading|paragraph|float|review (got ${JSON.stringify(block.type)})`);\n }\n if (typeof block.text !== 'string') fail(`Analysis.pages[${pi}].blocks[${bi}].text must be a string`);\n // `level` contract (see AnalysisBlock, src/types.ts): required 1-6 on a\n // heading, forbidden otherwise — rejected, not ignored, since it likely means `type` was mistyped.\n if (block.type === 'heading') {\n if (!Number.isInteger(block.level) || (block.level as number) < 1 || (block.level as number) > 6) {\n fail(`Analysis.pages[${pi}].blocks[${bi}].level must be an integer 1-6 on a heading block (got ${JSON.stringify(block.level)})`);\n }\n } else if (block.level !== undefined) {\n fail(`Analysis.pages[${pi}].blocks[${bi}].level is only allowed on heading blocks (got a ${JSON.stringify(block.type)} block with level ${JSON.stringify(block.level)})`);\n }\n if (!Array.isArray(block.wordIndexes)) fail(`Analysis.pages[${pi}].blocks[${bi}].wordIndexes must be an array`);\n for (const idx of block.wordIndexes as unknown[]) {\n if (typeof idx !== 'number' || !Number.isInteger(idx) || idx < 0 || idx >= wordCount) {\n fail(`Analysis.pages[${pi}].blocks[${bi}].wordIndexes has an out-of-range index (${JSON.stringify(idx)}; page ${pi} has ${wordCount} words)`);\n }\n }\n }\n }\n}\n\n// See AnalysisBlock's doc comment (src/types.ts) for the `text` contract this relies on.\nfunction renderBlockLiteral(block: AnalysisBlock): string {\n // A heading's `level` is guaranteed present (1-6): validateAnalysis\n // enforces it, and src/analyze.ts (the only unvalidated caller) always sets it.\n if (block.type === 'heading') return `${'#'.repeat(block.level as number)} ${block.text}`;\n return block.text;\n}\n\n/** Unvalidated core, reused by `src/analyze.ts`. `forcePageMarkers` is the\n * OCR path's always-on \"### pN\"; `pageMarkers` is the text path's opt-in flag, ignored when `forcePageMarkers` is set. */\nexport function renderPagesToMarkdown(pages: AnalysisPage[], opts: { forcePageMarkers: boolean; pageMarkers: boolean }): string {\n let md = '';\n for (const page of pages) {\n if (opts.forcePageMarkers) md += `\\n${pageMarkerLine(page.page)}\\n\\n`;\n else if (opts.pageMarkers) md += `${pageMarkerLine(page.page)}\\n\\n`;\n for (const block of page.blocks) md += `${renderBlockLiteral(block)}\\n\\n`;\n }\n return md;\n}\n\n// Strips a block's markdown decoration for plain-text rendering (the inverse\n// of AnalysisBlock's literal-text convention); headings need no stripping.\nfunction bareBlockText(block: AnalysisBlock): string {\n if (block.type === 'heading') return block.text;\n if (block.type === 'review') return block.text.replace(/^> \\[review: [^\\]]*\\] /, '');\n if (block.type === 'float') return block.text.replace(/^> \\[floats\\] /, '');\n return block.text.replace(/^> /, '');\n}\n\nexport function renderPagesToText(pages: AnalysisPage[]): string {\n const out: string[] = [];\n for (const page of pages) {\n for (const block of page.blocks) out.push(bareBlockText(block));\n }\n return out.length ? `${out.join('\\n\\n').trim()}\\n` : '';\n}\n\n/**\n * Render an Analysis to markdown. PURE and fail-fast over any well-formed Analysis (including hand-built/spliced ones) — throws `PdfToMdError`/`'ANALYSIS_INPUT'` before any output on a malformed one.\n * OCR-origin output is byte-identical to extractOcr's own markdown (shared core); text-origin is NOT byte-identical to extractText's (see `AnalysisPage.words`, `src/types.ts`).\n *\n * @param analysis the Analysis to render (from analyze(), or hand-built/spliced)\n * @param opts.pageMarkers text-origin only; an OCR-origin Analysis always carries markers\n */\nexport function toMarkdown(analysis: Analysis, opts: { pageMarkers?: boolean } = {}): string {\n validateAnalysis(analysis);\n const isOcr = analysis.report.path === 'ocr';\n const md = renderPagesToMarkdown(analysis.pages, { forcePageMarkers: isOcr, pageMarkers: !!opts.pageMarkers });\n return isOcr ? md : `${md.trim()}\\n`;\n}\n\n/**\n * Render an Analysis to reading-order plain text: headings drop their `#`;\n * float/review content is INCLUDED with only its markdown decoration stripped, so no content is lost silently. Same fail-fast validation as toMarkdown.\n *\n * @param analysis the Analysis to render (from analyze(), or hand-built/spliced)\n */\nexport function toText(analysis: Analysis): string {\n validateAnalysis(analysis);\n return renderPagesToText(analysis.pages);\n}\n"],"names":["renderPagesToMarkdown","renderPagesToText","toMarkdown","toText","BLOCK_TYPES","Set","validateAnalysis","analysis","fail","msg","PdfToMdError","a","report","path","JSON","stringify","Array","isArray","pages","entries","pi","page","p","words","wi","w","text","wordCount","length","blocks","bi","b","block","type","has","Number","isInteger","level","undefined","wordIndexes","idx","renderBlockLiteral","repeat","opts","md","forcePageMarkers","pageMarkerLine","pageMarkers","bareBlockText","replace","out","push","join","trim","isOcr"],"mappings":"AAAA,6EAA6E;AAC7E,0IAA0I;;;;;;;;;;;;QAqE1HA;eAAAA;;QAmBAC;eAAAA;;QAeAC;eAAAA;;QAaAC;eAAAA;;;wBAnHa;4BACE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAG/B,IAAMC,cAAc,IAAIC,IAAI;IAAC;IAAW;IAAa;IAAS;CAAS;AAEvE,4EAA4E;AAC5E,2IAA2I;AAC3I,SAASC,iBAAiBC,QAAiB;IACzC,IAAMC,OAAO,cAACC;QACZ,MAAM,IAAIC,sBAAY,CAAC,kBAAkBD;IAC3C;IACA,IAAI,CAA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K;QAAA;;;iBAAA,6BAAA;gBAAA;;;gBAAA;sBAAA;;;;IAGL,OAAOkB,IAAItB,MAAM,GAAG,AAAC,GAA0B,OAAxBsB,IAAIE,IAAI,CAAC,QAAQC,IAAI,IAAG,QAAM;AACvD;AASO,SAASnD,WAAWK,QAAkB;QAAEoC,OAAAA,iEAAkC,CAAC;IAChFrC,iBAAiBC;IACjB,IAAM+C,QAAQ/C,SAASK,MAAM,CAACC,IAAI,KAAK;IACvC,IAAM+B,KAAK5C,sBAAsBO,SAASW,KAAK,EAAE;QAAE2B,kBAAkBS;QAAOP,aAAa,CAAC,CAACJ,KAAKI,WAAW;IAAC;IAC5G,OAAOO,QAAQV,KAAK,AAAC,GAAY,OAAVA,GAAGS,IAAI,IAAG;AACnC;AAQO,SAASlD,OAAOI,QAAkB;IACvCD,iBAAiBC;IACjB,OAAON,kBAAkBM,SAASW,KAAK;AACzC"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/formats/pdf-to-md/src/render-analysis.ts"],"sourcesContent":["// Pure renderers over the Analysis IR: toMarkdown()/toText() are the public,\n// validated entry points; renderPagesToMarkdown/renderPagesToText below are the unvalidated core, reused (unvalidated) by src/analyze.ts.\nimport { PdfToMdError } from './errors.ts';\nimport { pageMarkerLine } from './page-marker.ts';\nimport type { Analysis, AnalysisBlock, AnalysisPage } from './types.ts';\n\nconst BLOCK_TYPES = new Set(['heading', 'paragraph', 'float', 'review']);\n\n// Whole-object, fail-fast validation: every page/block/wordIndexes entry is\n// checked BEFORE toMarkdown/toText render a single character — a malformed Analysis must never produce partial output, only a clean throw.\nfunction validateAnalysis(analysis: unknown): asserts analysis is Analysis {\n const fail = (msg: string): never => {\n throw new PdfToMdError('ANALYSIS_INPUT', msg);\n };\n if (typeof analysis !== 'object' || analysis === null) fail('Analysis must be an object');\n const a = analysis as Record<string, unknown>;\n if (typeof a.report !== 'object' || a.report === null) fail('Analysis.report must be an object');\n const path = (a.report as Record<string, unknown>).path;\n if (path !== 'text' && path !== 'ocr') fail(`Analysis.report.path must be \"text\" or \"ocr\" (got ${JSON.stringify(path)})`);\n if (!Array.isArray(a.pages)) fail('Analysis.pages must be an array');\n\n for (const [pi, page] of (a.pages as unknown[]).entries()) {\n if (typeof page !== 'object' || page === null) fail(`Analysis.pages[${pi}] must be an object`);\n const p = page as Record<string, unknown>;\n if (typeof p.page !== 'number') fail(`Analysis.pages[${pi}].page must be a number`);\n if (!Array.isArray(p.words)) fail(`Analysis.pages[${pi}].words must be an array`);\n for (const [wi, w] of (p.words as unknown[]).entries()) {\n if (typeof w !== 'object' || w === null || typeof (w as Record<string, unknown>).text !== 'string') {\n fail(`Analysis.pages[${pi}].words[${wi}] must be an object with a string 'text'`);\n }\n }\n const wordCount = (p.words as unknown[]).length;\n\n if (!Array.isArray(p.blocks)) fail(`Analysis.pages[${pi}].blocks must be an array`);\n for (const [bi, b] of (p.blocks as unknown[]).entries()) {\n if (typeof b !== 'object' || b === null) fail(`Analysis.pages[${pi}].blocks[${bi}] must be an object`);\n const block = b as Record<string, unknown>;\n if (typeof block.type !== 'string' || !BLOCK_TYPES.has(block.type)) {\n fail(`Analysis.pages[${pi}].blocks[${bi}].type must be one of heading|paragraph|float|review (got ${JSON.stringify(block.type)})`);\n }\n if (typeof block.text !== 'string') fail(`Analysis.pages[${pi}].blocks[${bi}].text must be a string`);\n // `level` contract (see AnalysisBlock, src/types.ts): required 1-6 on a\n // heading, forbidden otherwise — rejected, not ignored, since it likely means `type` was mistyped.\n if (block.type === 'heading') {\n if (!Number.isInteger(block.level) || (block.level as number) < 1 || (block.level as number) > 6) {\n fail(`Analysis.pages[${pi}].blocks[${bi}].level must be an integer 1-6 on a heading block (got ${JSON.stringify(block.level)})`);\n }\n } else if (block.level !== undefined) {\n fail(`Analysis.pages[${pi}].blocks[${bi}].level is only allowed on heading blocks (got a ${JSON.stringify(block.type)} block with level ${JSON.stringify(block.level)})`);\n }\n if (!Array.isArray(block.wordIndexes)) fail(`Analysis.pages[${pi}].blocks[${bi}].wordIndexes must be an array`);\n for (const idx of block.wordIndexes as unknown[]) {\n if (typeof idx !== 'number' || !Number.isInteger(idx) || idx < 0 || idx >= wordCount) {\n fail(`Analysis.pages[${pi}].blocks[${bi}].wordIndexes has an out-of-range index (${JSON.stringify(idx)}; page ${pi} has ${wordCount} words)`);\n }\n }\n }\n }\n}\n\n// See AnalysisBlock's doc comment (src/types.ts) for the `text` contract this relies on.\nfunction renderBlockLiteral(block: AnalysisBlock): string {\n // A heading's `level` is guaranteed present (1-6): validateAnalysis\n // enforces it, and src/analyze.ts (the only unvalidated caller) always sets it.\n if (block.type === 'heading') return `${'#'.repeat(block.level as number)} ${block.text}`;\n return block.text;\n}\n\n/** Unvalidated core, reused by `src/analyze.ts`. `forcePageMarkers` is the\n * OCR path's always-on \"### pN\"; `pageMarkers` is the text path's opt-in flag, ignored when `forcePageMarkers` is set. */\nexport function renderPagesToMarkdown(pages: AnalysisPage[], opts: { forcePageMarkers: boolean; pageMarkers: boolean }): string {\n let md = '';\n for (const page of pages) {\n if (opts.forcePageMarkers) md += `\\n${pageMarkerLine(page.page)}\\n\\n`;\n else if (opts.pageMarkers) md += `${pageMarkerLine(page.page)}\\n\\n`;\n for (const block of page.blocks) md += `${renderBlockLiteral(block)}\\n\\n`;\n }\n return md;\n}\n\n// Strips a block's markdown decoration for plain-text rendering (the inverse\n// of AnalysisBlock's literal-text convention); headings need no stripping.\nfunction bareBlockText(block: AnalysisBlock): string {\n if (block.type === 'heading') return block.text;\n if (block.type === 'review') return block.text.replace(/^> \\[review: [^\\]]*\\] /, '');\n if (block.type === 'float') return block.text.replace(/^> \\[floats\\] /, '');\n return block.text.replace(/^> /, '');\n}\n\nexport function renderPagesToText(pages: AnalysisPage[]): string {\n const out: string[] = [];\n for (const page of pages) {\n for (const block of page.blocks) out.push(bareBlockText(block));\n }\n return out.length ? `${out.join('\\n\\n').trim()}\\n` : '';\n}\n\n/**\n * Render an Analysis to markdown. PURE and fail-fast over any well-formed Analysis (including hand-built/spliced ones) — throws `PdfToMdError`/`'ANALYSIS_INPUT'` before any output on a malformed one.\n * OCR-origin output is byte-identical to extractOcr's own markdown (shared core); text-origin is NOT byte-identical to extractText's (see `AnalysisPage.words`, `src/types.ts`).\n *\n * @param analysis the Analysis to render (from analyze(), or hand-built/spliced)\n * @param opts.pageMarkers text-origin only; an OCR-origin Analysis always carries markers\n */\nexport function toMarkdown(analysis: Analysis, opts: { pageMarkers?: boolean } = {}): string {\n validateAnalysis(analysis);\n const isOcr = analysis.report.path === 'ocr';\n const md = renderPagesToMarkdown(analysis.pages, { forcePageMarkers: isOcr, pageMarkers: !!opts.pageMarkers });\n return isOcr ? md : `${md.trim()}\\n`;\n}\n\n/**\n * Render an Analysis to reading-order plain text: headings drop their `#`;\n * float/review content is INCLUDED with only its markdown decoration stripped, so no content is lost silently. Same fail-fast validation as toMarkdown.\n *\n * @param analysis the Analysis to render (from analyze(), or hand-built/spliced)\n */\nexport function toText(analysis: Analysis): string {\n validateAnalysis(analysis);\n return renderPagesToText(analysis.pages);\n}\n"],"names":["renderPagesToMarkdown","renderPagesToText","toMarkdown","toText","BLOCK_TYPES","Set","validateAnalysis","analysis","fail","msg","PdfToMdError","a","report","path","JSON","stringify","Array","isArray","pages","entries","pi","page","p","words","wi","w","text","wordCount","length","blocks","bi","b","block","type","has","Number","isInteger","level","undefined","wordIndexes","idx","renderBlockLiteral","repeat","opts","md","forcePageMarkers","pageMarkerLine","pageMarkers","bareBlockText","replace","out","push","join","trim","isOcr"],"mappings":"AAAA,6EAA6E;AAC7E,0IAA0I;;;;;;;;;;;;QAqE1HA;eAAAA;;QAmBAC;eAAAA;;QAeAC;eAAAA;;QAaAC;eAAAA;;;wBAnHa;4BACE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAG/B,IAAMC,cAAc,IAAIC,IAAI;IAAC;IAAW;IAAa;IAAS;CAAS;AAEvE,4EAA4E;AAC5E,2IAA2I;AAC3I,SAAS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BAA4BkB,IAAIC,IAAI,CAACH,cAAchB;;;gBAAnD;gBAAA;;;yBAAA,8BAAA;wBAAA;;;wBAAA;8BAAA;;;;QACP;;QAFK;QAAA;;;iBAAA,6BAAA;gBAAA;;;gBAAA;sBAAA;;;;IAGL,OAAOkB,IAAItB,MAAM,GAAG,AAAC,GAA0B,OAAxBsB,IAAIE,IAAI,CAAC,QAAQC,IAAI,IAAG,QAAM;AACvD;AASO,SAASnD,WAAWK,QAAkB;QAAEoC,OAAAA,iEAAkC,CAAC;IAChFrC,iBAAiBC;IACjB,IAAM+C,QAAQ/C,SAASK,MAAM,CAACC,IAAI,KAAK;IACvC,IAAM+B,KAAK5C,sBAAsBO,SAASW,KAAK,EAAE;QAAE2B,kBAAkBS;QAAOP,aAAa,CAAC,CAACJ,KAAKI,WAAW;IAAC;IAC5G,OAAOO,QAAQV,KAAK,AAAC,GAAY,OAAVA,GAAGS,IAAI,IAAG;AACnC;AAQO,SAASlD,OAAOI,QAAkB;IACvCD,iBAAiBC;IACjB,OAAON,kBAAkBM,SAASW,KAAK;AACzC"}
@@ -1 +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","joinedP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E,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/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;;;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,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 +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"}
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 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Projects/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/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 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Projects/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,I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AA,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/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,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,sCAAP,SAAOA,MAAI,MAAM,YAAYA,UAAU;IACxD,IAAMC,QAAQX,WAAW,AAACU,MAAkCC,KAAK,GAAGZ;IACpE,IAAI,CAACa,MAAMC,OAAO,CAACF,QAAQ;QACzB,MAAM,IAAIJ,sBAAY,CAAC,eAAe,AAAC,iFAAiI,OAAjDP,WAAWQ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,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 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Projects/pdf-to-md/src/analyze.ts"],"sourcesContent":["// analyze() plus the OCR-path core (buildOcrAnalysisPages) that extractOcr\n// shares with it — same buildPageOCR -> emitPage -> renderPagesToMarkdown pipeline, so OCR-path markdown is byte-identical by construction, not two implementations kept in sync by hand. The TEXT path is NOT shared this way (see analyzeText).\nimport { collect, pageCount } from './collect.ts';\nimport { dictAvailable, dictUnavailableWarning } from './dict.ts';\nimport type { EmitBlock } from './emit.ts';\nimport { emitPage, renderEmitBlock } from './emit.ts';\n// Type-only: erased at compile time, so this does NOT create a runtime\n// circular dependency even though src/extract.ts imports (value-level) from this module.\nimport type { ExtractOcrOptions, ExtractTextOptions, OcrWordInput } from './extract.ts';\nimport type { PageOCR, Tuning, Word } from './geometry.ts';\nimport { buildPageOCR, DEFAULT_TUNING, headingLevels } from './geometry.ts';\nimport { toLines } from './lines.ts';\nimport { buildMarkdown } from './markdown.ts';\nimport { renderPagesToMarkdown } from './render-analysis.ts';\nimport { buildOcrReport, buildReport, OUTPUT_VERSION } from './report.ts';\nimport type { Analysis, AnalysisBlock, AnalysisPage, AnalysisWord, Line, PageLines } from './types.ts';\nimport { validateOcrAnalysisInput, validatePages, validateWordsInput } from './validate.ts';\n\n/** analyze(pdf) with the default/'text' path — OCR-only fields don't exist\n * on this branch, so passing e.g. `tuning` without `path: 'ocr'` is a compile error. */\nexport type AnalyzeTextOptions = ExtractTextOptions & { path?: 'text' };\n\n/** analyze(pdf, {path:'ocr'}) — same fields as {@link ExtractOcrOptions},\n * unlocked only once `path: 'ocr'` is set. */\nexport type AnalyzeOcrOptions = ExtractOcrOptions & { path: 'ocr' };\n\n/** Options for {@link analyze}: which fields type-check depends on `path`\n * (ignored, forced 'ocr', when `input` is a `{ words }` replay). */\nexport type AnalyzeOptions = AnalyzeTextOptions | AnalyzeOcrOptions;\n\nfunction toAnalysisWord(w: OcrWordInput): AnalysisWord {\n const box = { x: w.x, y: w.y, w: w.w, h: w.h };\n return w.confidence === undefined ? { text: w.text, box } : { text: w.text, box, confidence: w.confidence };\n}\n\n// EmitBlock -> AnalysisBlock: collapses emit.ts's 'quote' kind (a pull-quote)\n// into Analysis's 'paragraph' type, `text` keeping its literal '> ' prefix — see AnalysisBlock's doc comment (src/types.ts) for why.\nfunction toAnalysisBlock(b: EmitBlock, wordIndex: Map<Word, number>): AnalysisBlock {\n const wordIndexes = b.words.map((w) => wordIndex.get(w) as number);\n if (b.kind === 'heading') return { type: 'heading', text: b.text, level: b.level, wordIndexes };\n if (b.kind === 'review') return { type: 'review', text: renderEmitBlock(b), wordIndexes };\n return { type: 'paragraph', text: renderEmitBlock(b), wordIndexes };\n}\n\n/** The OCR-path core shared by extractOcr and analyze(..., {path:'ocr'}):\n * recognizes (or replays) words and runs the unchanged buildPageOCR/emitPage pipeline. Word IDENTITY (object reference), not value, carries indices through into the emitted blocks — see `geometry.ts`'s OcrLine.words. */\nexport async function buildOcrAnalysisPages(input: { pdfPath: string } | { words: OcrWordInput[] }, opts: ExtractOcrOptions, warn: (m: string) => void): Promise<{ pages: AnalysisPage[]; words: OcrWordInput[] }> {\n const tuning: Tuning = { ...DEFAULT_TUNING, ...opts.tuning };\n const validated = validateOcrAnalysisInput(input);\n\n let words: OcrWordInput[];\n let first: number;\n let last: number;\n if ('words' in validated) {\n // Replay: page range from --pages if given, else every page up to the highest one the dump mentions.\n words = validated.words;\n first = opts.pages?.first ?? 1;\n last = opts.pages?.last ?? opts.pages?.first ?? Math.max(1, ...words.map((w) => w.page));\n } else {\n const { recognizePdf } = await import('./engines/tesseract.ts');\n const totalPages = await pageCount(validated.pdfPath);\n const rawFirst = opts.pages?.first ?? 1;\n const rawLast = opts.pages?.last ?? (opts.pages ? rawFirst : totalPages);\n first = Math.min(Math.max(1, rawFirst), Math.max(1, totalPages));\n last = Math.min(Math.max(first, rawLast), totalPages);\n const result = await recognizePdf(validated.pdfPath, first, last, {\n dpi: opts.dpi,\n onProgress: opts.onProgress,\n onWarning: warn,\n });\n words = result.words;\n }\n\n opts.onWords?.(words);\n\n // Stable per-page index, assigned in recognition/replay order — this IS\n // the page's flat `words` list order; `wordIndex` recovers it later since geometry.ts never clones a Word (object identity survives row-building).\n const byPage = new Map<number, OcrWordInput[]>();\n const wordIndex = new Map<Word, number>();\n for (const w of words) {\n const list = byPage.get(w.page);\n if (list) {\n wordIndex.set(w, list.length);\n list.push(w);\n } else {\n wordIndex.set(w, 0);\n byPage.set(w.page, [w]);\n }\n }\n\n const pageOcrs = new Map<number, PageOCR>();\n for (let pn = first; pn <= last; pn++) pageOcrs.set(pn, buildPageOCR(byPage.get(pn) ?? [], tuning));\n const { levelOf } = headingLevels([...pageOcrs.values()], tuning);\n\n const pages: AnalysisPage[] = [];\n for (let pn = first; pn <= last; pn++) {\n const p = pageOcrs.get(pn) as PageOCR;\n // An in-range page with no recognized words stays visible (marker +\n // warning), never silently absent — same rule as extractOcr.\n if (!byPage.has(pn)) warn(`p${pn}: no recognized words, page emitted with no OCR text`);\n\n const blocks: AnalysisBlock[] = emitPage(p, levelOf, tuning).map((b) => toAnalysisBlock(b, wordIndex));\n // Decorative fragments always render as one visible \"> [floats]\" aside\n // per page (matching the one printed line) — see geometry.ts's PageOCR.floats.\n if (p.floats.length) {\n blocks.push({\n type: 'float',\n text: `> [floats] ${p.floats.map((f) => f.text).join(' · ')}`,\n wordIndexes: p.floats.flatMap((f) => f.words).map((w) => wordIndex.get(w) as number),\n });\n }\n\n pages.push({\n page: pn,\n words: (byPage.get(pn) ?? []).map(toAnalysisWord),\n blocks,\n });\n }\n\n return { pages, words };\n}\n\nasync function analyzeOcr(input: { pdfPath: string } | { words: OcrWordInput[] }, opts: ExtractOcrOptions): Promise<Analysis> {\n const warn = (m: string) => opts.onWarning?.(m);\n if (!dictAvailable()) warn(dictUnavailableWarning());\n const { pages, words } = await buildOcrAnalysisPages(input, opts, warn);\n const md = renderPagesToMarkdown(pages, { forcePageMarkers: true, pageMarkers: true });\n const report = buildOcrReport({ md, fallback: opts.fallback, words });\n return { outputVersion: OUTPUT_VERSION, report, pages };\n}\n\n// TEXT path: deliberately NOT routed through the OCR shared-core pattern —\n// buildMarkdown's reflow/hyphen-rejoin/list rules don't fit the 4-type Analysis block union, so this is an independent, intentionally coarser reconstruction (one word/block per visual LINE) — honest, not byte-identical to extractText (see AnalysisPage, src/types.ts).\n\n// Converts a text-path Line's page-point geometry (src/lines.ts) into the\n// same normalized box contract the OCR path uses (see AnalysisPage.words) — only the coordinate SYSTEM changes; `box.y` anchors on the line's baseline, `box.w` stays 0.\nfunction textLineBox(l: Line, dims: { width: number; height: number }): AnalysisWord['box'] {\n const { width, height } = dims;\n return {\n x: width > 0 ? l.x / width : 0,\n y: height > 0 ? (height - l.y) / height : 0,\n w: 0,\n h: height > 0 ? l.h / height : 0,\n };\n}\n\nasync function analyzeText(pdfPath: string, opts: ExtractTextOptions): Promise<Analysis> {\n const warn = (m: string) => opts.onWarning?.(m);\n if (!dictAvailable()) warn(dictUnavailableWarning());\n const range = opts.pages ? { first: opts.pages.first, last: opts.pages.last ?? opts.pages.first } : {};\n const { numPages, pages, heightChars } = await collect(pdfPath, range);\n const pageDims = new Map(pages.map((p) => [p.page, { width: p.width, height: p.height }]));\n const pageLines: PageLines[] = pages.map((p) => ({ page: p.page, lines: toLines(p) }));\n const pageMarkers = opts.pageMarkers ?? false;\n const { md, stats, bodyH, headingSizes } = buildMarkdown(pageLines, heightChars, { pageMarkers });\n const statsMd = pageMarkers ? md : buildMarkdown(pageLines, heightChars, { pageMarkers: true }).md;\n\n const hybridPages = pages.filter((p) => p.largeImage).map((p) => p.page);\n for (const n of hybridPages) {\n warn(`p${n}: text layer used but page carries large image(s); if it has baked-in text this output won't have it — compare (don't blindly replace) against --pages ${n} --ocr, which can itself introduce errors`);\n }\n\n // Report is measured from the REAL markdown above — accurate regardless of\n // the coarser block/word reconstruction below.\n const report = buildReport({ numPages, md, statsMd, stats, bodyH, headingSizes, hybridPages });\n\n // headingSizes is offset-independent — reused directly, then re-leveled\n // here with offset 0 regardless of `opts.pageMarkers` (see AnalysisPage).\n const levelOf = new Map(headingSizes.slice(0, 6).map((h, i) => [h, Math.min(6, i + 1)]));\n const analysisPages: AnalysisPage[] = pageLines.map(({ page, lines }) => {\n const dims = pageDims.get(page) as { width: number; height: number };\n const words: AnalysisWord[] = lines.map((l) => ({ text: l.text, box: textLineBox(l, dims) }));\n const blocks: AnalysisBlock[] = lines.map((l, i) => {\n const level = levelOf.get(l.h);\n return level !== undefined ? { type: 'heading' as const, text: l.text, level, wordIndexes: [i] } : { type: 'paragraph' as const, text: l.text, wordIndexes: [i] };\n });\n return { page, words, blocks };\n });\n\n return { outputVersion: OUTPUT_VERSION, report, pages: analysisPages };\n}\n\n/**\n * Analyze a PDF (or replay an already-recognized OCR word dump) into\n * `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).\n *\n * @param input a bare pdf path, or `{ words }` to replay a dump (always analyzed as OCR) — unlike extractOcr, never `{ pdfPath }`\n * @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)\n */\nexport async function analyze(input: string | { words: OcrWordInput[] }, opts: AnalyzeOptions = {}): Promise<Analysis> {\n validatePages(opts.pages);\n if (typeof input !== 'string') return analyzeOcr({ words: validateWordsInput(input) }, opts);\n if (opts.path === 'ocr') return analyzeOcr({ pdfPath: input }, opts);\n return analyzeText(input, opts);\n}\n"],"names":["collect","pageCount","dictAvailable","dictUnavailableWarning","emitPage","renderEmitBlock","buildPageOCR","DEFAULT_TUNING","headingLevels","toLines","buildMarkdown","renderPagesToMarkdown","buildOcrReport","buildReport","OUTPUT_VERSION","validateOcrAnalysisInput","validatePages","validateWordsInput","toAnalysisWord","w","box","x","y","h","confidence","undefined","text","toAnalysisBlock","b","wordIndex","wordIndexes","words","map","get","kind","type","level","buildOcrAnalysisPages","input","opts","warn","byPage","tuning","validated","first","last","pages","Math","max","page","recognizePdf","totalPages","pdfPath","rawFirst","rawLast","min","result","dpi","onProgress","onWarning","onWords","Map","list","set","length","push","pageOcrs","pn","levelOf","values","p","has","blocks","floats","f","join","flatMap","analyzeOcr","m","md","forcePageMarkers","pageMarkers","report","fallback","outputVersion","textLineBox","l","dims","width","height","analyzeText","range","numPages","heightChars","pageDims","pageLines","lines","stats","bodyH","headingSizes","statsMd","hybridPages","filter","largeImage","n","slice","i","analysisPages","analyze","path"],"mappings":"AAAA,2EAA2E;AAC3E,kPAAkP;AAClP,SAASA,OAAO,EAAEC,SAAS,QAAQ,eAAe;AAClD,SAASC,aAAa,EAAEC,sBAAsB,QAAQ,YAAY;AAElE,SAASC,QAAQ,EAAEC,eAAe,QAAQ,YAAY;AAKtD,SAASC,YAAY,EAAEC,cAAc,EAAEC,aAAa,QAAQ,gBAAgB;AAC5E,SAASC,OAAO,QAAQ,aAAa;AACrC,SAASC,aAAa,QAAQ,gBAAgB;AAC9C,SAASC,qBAAqB,QAAQ,uBAAuB;AAC7D,SAASC,cAAc,EAAEC,WAAW,EAAEC,cAAc,QAAQ,cAAc;AAE1E,SAASC,wBAAwB,EAAEC,aAAa,EAAEC,kBAAkB,QAAQ,gBAAgB;AAc5F,SAASC,eAAeC,CAAe;IACrC,MAAMC,MAAM;QAAEC,GAAGF,EAAEE,CAAC;QAAEC,GAAGH,EAAEG,CAAC;QAAEH,GAAGA,EAAEA,CAAC;QAAEI,GAAGJ,EAAEI,C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BAAgCZ,UAAU/D,GAAG,CAAC,CAAC,EAAEiB,IAAI,EAAE+C,KAAK,EAAE;QAClE,MAAMT,OAAOO,SAAS7D,GAAG,CAACgB;QAC1B,MAAMlB,QAAwBiE,MAAMhE,GAAG,CAAC,CAACsD,IAAO,CAAA;gBAAE5D,MAAM4D,EAAE5D,IAAI;gBAAEN,KAAKiE,YAAYC,GAAGC;YAAM,CAAA;QAC1F,MAAMf,SAA0BwB,MAAMhE,GAAG,CAAC,CAACsD,GAAGoB;YAC5C,MAAMtE,QAAQgC,QAAQnC,GAAG,CAACqD,EAAE/D,CAAC;YAC7B,OAAOa,UAAUX,YAAY;gBAAEU,MAAM;gBAAoBT,MAAM4D,EAAE5D,IAAI;gBAAEU;gBAAON,aAAa;oBAAC4E;iBAAE;YAAC,IAAI;gBAAEvE,MAAM;gBAAsBT,MAAM4D,EAAE5D,IAAI;gBAAEI,aAAa;oBAAC4E;iBAAE;YAAC;QAClK;QACA,OAAO;YAAEzD;YAAMlB;YAAOyC;QAAO;IAC/B;IAEA,OAAO;QAAEY,eAAetE;QAAgBoE;QAAQpC,OAAO6D;IAAc;AACvE;AAEA;;;;;;CAMC,GACD,OAAO,eAAeC,QAAQtE,KAAyC,EAAEC,OAAuB,CAAC,CAAC;IAChGvB,cAAcuB,KAAKO,KAAK;IACxB,IAAI,OAAOR,UAAU,UAAU,OAAOuC,WAAW;QAAE9C,OAAOd,mBAAmBqB;IAAO,GAAGC;IACvF,IAAIA,KAAKsE,IAAI,KAAK,OAAO,OAAOhC,WAAW;QAAEzB,SAASd;IAAM,GAAGC;IAC/D,OAAOmD,YAAYpD,OAAOC;AAC5B"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/formats/pdf-to-md/src/analyze.ts"],"sourcesContent":["// analyze() plus the OCR-path core (buildOcrAnalysisPages) that extractOcr\n// shares with it — same buildPageOCR -> emitPage -> renderPagesToMarkdown pipeline, so OCR-path markdown is byte-identical by construction, not two implementations kept in sync by hand. The TEXT path is NOT shared this way (see analyzeText).\nimport { collect, pageCount } from './collect.ts';\nimport { dictAvailable, dictUnavailableWarning } from './dict.ts';\nimport type { EmitBlock } from './emit.ts';\nimport { emitPage, renderEmitBlock } from './emit.ts';\n// Type-only: erased at compile time, so this does NOT create a runtime\n// circular dependency even though src/extract.ts imports (value-level) from this module.\nimport type { ExtractOcrOptions, ExtractTextOptions, OcrWordInput } from './extract.ts';\nimport type { PageOCR, Tuning, Word } from './geometry.ts';\nimport { buildPageOCR, DEFAULT_TUNING, headingLevels } from './geometry.ts';\nimport { toLines } from './lines.ts';\nimport { buildMarkdown } from './markdown.ts';\nimport { renderPagesToMarkdown } from './render-analysis.ts';\nimport { buildOcrReport, buildReport, OUTPUT_VERSION } from './report.ts';\nimport type { Analysis, AnalysisBlock, AnalysisPage, AnalysisWord, Line, PageLines } from './types.ts';\nimport { validateOcrAnalysisInput, validatePages, validateWordsInput } from './validate.ts';\n\n/** analyze(pdf) with the default/'text' path — OCR-only fields don't exist\n * on this branch, so passing e.g. `tuning` without `path: 'ocr'` is a compile error. */\nexport type AnalyzeTextOptions = ExtractTextOptions & { path?: 'text' };\n\n/** analyze(pdf, {path:'ocr'}) — same fields as {@link ExtractOcrOptions},\n * unlocked only once `path: 'ocr'` is set. */\nexport type AnalyzeOcrOptions = ExtractOcrOptions & { path: 'ocr' };\n\n/** Options for {@link analyze}: which fields type-check depends on `path`\n * (ignored, forced 'ocr', when `input` is a `{ words }` replay). */\nexport type AnalyzeOptions = AnalyzeTextOptions | AnalyzeOcrOptions;\n\nfunction toAnalysisWord(w: OcrWordInput): AnalysisWord {\n const box = { x: w.x, y: w.y, w: w.w, h: w.h };\n return w.confidence === undefined ? { text: w.text, box } : { text: w.text, box, confidence: w.confidence };\n}\n\n// EmitBlock -> AnalysisBlock: collapses emit.ts's 'quote' kind (a pull-quote)\n// into Analysis's 'paragraph' type, `text` keeping its literal '> ' prefix — see AnalysisBlock's doc comment (src/types.ts) for why.\nfunction toAnalysisBlock(b: EmitBlock, wordIndex: Map<Word, number>): AnalysisBlock {\n const wordIndexes = b.words.map((w) => wordIndex.get(w) as number);\n if (b.kind === 'heading') return { type: 'heading', text: b.text, level: b.level, wordIndexes };\n if (b.kind === 'review') return { type: 'review', text: renderEmitBlock(b), wordIndexes };\n return { type: 'paragraph', text: renderEmitBlock(b), wordIndexes };\n}\n\n/** The OCR-path core shared by extractOcr and analyze(..., {path:'ocr'}):\n * recognizes (or replays) words and runs the unchanged buildPageOCR/emitPage pipeline. Word IDENTITY (object reference), not value, carries indices through into the emitted blocks — see `geometry.ts`'s OcrLine.words. */\nexport async function buildOcrAnalysisPages(input: { pdfPath: string } | { words: OcrWordInput[] }, opts: ExtractOcrOptions, warn: (m: string) => void): Promise<{ pages: AnalysisPage[]; words: OcrWordInput[] }> {\n const tuning: Tuning = { ...DEFAULT_TUNING, ...opts.tuning };\n const validated = validateOcrAnalysisInput(input);\n\n let words: OcrWordInput[];\n let first: number;\n let last: number;\n if ('words' in validated) {\n // Replay: page range from --pages if given, else every page up to the highest one the dump mentions.\n words = validated.words;\n first = opts.pages?.first ?? 1;\n last = opts.pages?.last ?? opts.pages?.first ?? Math.max(1, ...words.map((w) => w.page));\n } else {\n const { recognizePdf } = await import('./engines/tesseract.ts');\n const totalPages = await pageCount(validated.pdfPath);\n const rawFirst = opts.pages?.first ?? 1;\n const rawLast = opts.pages?.last ?? (opts.pages ? rawFirst : totalPages);\n first = Math.min(Math.max(1, rawFirst), Math.max(1, totalPages));\n last = Math.min(Math.max(first, rawLast), totalPages);\n const result = await recognizePdf(validated.pdfPath, first, last, {\n dpi: opts.dpi,\n onProgress: opts.onProgress,\n onWarning: warn,\n });\n words = result.words;\n }\n\n opts.onWords?.(words);\n\n // Stable per-page index, assigned in recognition/replay order — this IS\n // the page's flat `words` list order; `wordIndex` recovers it later since geometry.ts never clones a Word (object identity survives row-building).\n const byPage = new Map<number, OcrWordInput[]>();\n const wordIndex = new Map<Word, number>();\n for (const w of words) {\n const list = byPage.get(w.page);\n if (list) {\n wordIndex.set(w, list.length);\n list.push(w);\n } else {\n wordIndex.set(w, 0);\n byPage.set(w.page, [w]);\n }\n }\n\n const pageOcrs = new Map<number, PageOCR>();\n for (let pn = first; pn <= last; pn++) pageOcrs.set(pn, buildPageOCR(byPage.get(pn) ?? [], tuning));\n const { levelOf } = headingLevels([...pageOcrs.values()], tuning);\n\n const pages: AnalysisPage[] = [];\n for (let pn = first; pn <= last; pn++) {\n const p = pageOcrs.get(pn) as PageOCR;\n // An in-range page with no recognized words stays visible (marker +\n // warning), never silently absent — same rule as extractOcr.\n if (!byPage.has(pn)) warn(`p${pn}: no recognized words, page emitted with no OCR text`);\n\n const blocks: AnalysisBlock[] = emitPage(p, levelOf, tuning).map((b) => toAnalysisBlock(b, wordIndex));\n // Decorative fragments always render as one visible \"> [floats]\" aside\n // per page (matching the one printed line) — see geometry.ts's PageOCR.floats.\n if (p.floats.length) {\n blocks.push({\n type: 'float',\n text: `> [floats] ${p.floats.map((f) => f.text).join(' · ')}`,\n wordIndexes: p.floats.flatMap((f) => f.words).map((w) => wordIndex.get(w) as number),\n });\n }\n\n pages.push({\n page: pn,\n words: (byPage.get(pn) ?? []).map(toAnalysisWord),\n blocks,\n });\n }\n\n return { pages, words };\n}\n\nasync function analyzeOcr(input: { pdfPath: string } | { words: OcrWordInput[] }, opts: ExtractOcrOptions): Promise<Analysis> {\n const warn = (m: string) => opts.onWarning?.(m);\n if (!dictAvailable()) warn(dictUnavailableWarning());\n const { pages, words } = await buildOcrAnalysisPages(input, opts, warn);\n const md = renderPagesToMarkdown(pages, { forcePageMarkers: true, pageMarkers: true });\n const report = buildOcrReport({ md, fallback: opts.fallback, words });\n return { outputVersion: OUTPUT_VERSION, report, pages };\n}\n\n// TEXT path: deliberately NOT routed through the OCR shared-core pattern —\n// buildMarkdown's reflow/hyphen-rejoin/list rules don't fit the 4-type Analysis block union, so this is an independent, intentionally coarser reconstruction (one word/block per visual LINE) — honest, not byte-identical to extractText (see AnalysisPage, src/types.ts).\n\n// Converts a text-path Line's page-point geometry (src/lines.ts) into the\n// same normalized box contract the OCR path uses (see AnalysisPage.words) — only the coordinate SYSTEM changes; `box.y` anchors on the line's baseline, `box.w` stays 0.\nfunction textLineBox(l: Line, dims: { width: number; height: number }): AnalysisWord['box'] {\n const { width, height } = dims;\n return {\n x: width > 0 ? l.x / width : 0,\n y: height > 0 ? (height - l.y) / height : 0,\n w: 0,\n h: height > 0 ? l.h / height : 0,\n };\n}\n\nasync function analyzeText(pdfPath: string, opts: ExtractTextOptions): Promise<Analysis> {\n const warn = (m: string) => opts.onWarning?.(m);\n if (!dictAvailable()) warn(dictUnavailableWarning());\n const range = opts.pages ? { first: opts.pages.first, last: opts.pages.last ?? opts.pages.first } : {};\n const { numPages, pages, heightChars } = await collect(pdfPath, range);\n const pageDims = new Map(pages.map((p) => [p.page, { width: p.width, height: p.height }]));\n const pageLines: PageLines[] = pages.map((p) => ({ page: p.page, lines: toLines(p) }));\n const pageMarkers = opts.pageMarkers ?? false;\n const { md, stats, bodyH, headingSizes } = buildMarkdown(pageLines, heightChars, { pageMarkers });\n const statsMd = pageMarkers ? md : buildMarkdown(pageLines, heightChars, { pageMarkers: true }).md;\n\n const hybridPages = pages.filter((p) => p.largeImage).map((p) => p.page);\n for (const n of hybridPages) {\n warn(`p${n}: text layer used but page carries large image(s); if it has baked-in text this output won't have it — compare (don't blindly replace) against --pages ${n} --ocr, which can itself introduce errors`);\n }\n\n // Report is measured from the REAL markdown above — accurate regardless of\n // the coarser block/word reconstruction below.\n const report = buildReport({ numPages, md, statsMd, stats, bodyH, headingSizes, hybridPages });\n\n // headingSizes is offset-independent — reused directly, then re-leveled\n // here with offset 0 regardless of `opts.pageMarkers` (see AnalysisPage).\n const levelOf = new Map(headingSizes.slice(0, 6).map((h, i) => [h, Math.min(6, i + 1)]));\n const analysisPages: AnalysisPage[] = pageLines.map(({ page, lines }) => {\n const dims = pageDims.get(page) as { width: number; height: number };\n const words: AnalysisWord[] = lines.map((l) => ({ text: l.text, box: textLineBox(l, dims) }));\n const blocks: AnalysisBlock[] = lines.map((l, i) => {\n const level = levelOf.get(l.h);\n return level !== undefined ? { type: 'heading' as const, text: l.text, level, wordIndexes: [i] } : { type: 'paragraph' as const, text: l.text, wordIndexes: [i] };\n });\n return { page, words, blocks };\n });\n\n return { outputVersion: OUTPUT_VERSION, report, pages: analysisPages };\n}\n\n/**\n * Analyze a PDF (or replay an already-recognized OCR word dump) into\n * `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).\n *\n * @param input a bare pdf path, or `{ words }` to replay a dump (always analyzed as OCR) — unlike extractOcr, never `{ pdfPath }`\n * @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)\n */\nexport async function analyze(input: string | { words: OcrWordInput[] }, opts: AnalyzeOptions = {}): Promise<Analysis> {\n validatePages(opts.pages);\n if (typeof input !== 'string') return analyzeOcr({ words: validateWordsInput(input) }, opts);\n if (opts.path === 'ocr') return analyzeOcr({ pdfPath: input }, opts);\n return analyzeText(input, opts);\n}\n"],"names":["collect","pageCount","dictAvailable","dictUnavailableWarning","emitPage","renderEmitBlock","buildPageOCR","DEFAULT_TUNING","headingLevels","toLines","buildMarkdown","renderPagesToMarkdown","buildOcrReport","buildReport","OUTPUT_VERSION","validateOcrAnalysisInput","validatePages","validateWordsInput","toAnalysisWord","w","box","x","y","h","confidence","undefined","text","toAnalysisBlock","b","wordIndex","wordIndexes","words","map","get","kind","type","level","buildOcrAnalysisPages","input","opts","warn","byPage","tuning","validated","first","last","pages","Math","max","page","recognizePdf","totalPages","pdfPath","rawFirst","rawLast","min","result","dpi","onProgress","onWarning","onWords","Map","list","set","length","push","pageOcrs","pn","levelOf","values","p","has","blocks","floats","f","join","flatMap","analyzeOcr","m","md","forcePageMarkers","pageMarkers","report","fallback","outputVersion","textLineBox","l","dims","width","height","analyzeText","range","numPages","heightChars","pageDims","pageLines","lines","stats","bodyH","headingSizes","statsMd","hybridPages","filter","largeImage","n","slice","i","analysisPages","analyze","path"],"mappings":"AAAA,2EAA2E;AAC3E,kPAAkP;AAClP,SAASA,OAAO,EAAEC,SAAS,QAAQ,eAAe;AAClD,SAASC,aAAa,EAAEC,sBAAsB,QAAQ,YAAY;AAElE,SAASC,QAAQ,EAAEC,eAAe,QAAQ,YAAY;AAKtD,SAASC,YAAY,EAAEC,cAAc,EAAEC,aAAa,QAAQ,gBAAgB;AAC5E,SAASC,OAAO,QAAQ,aAAa;AACrC,SAASC,aAAa,QAAQ,gBAAgB;AAC9C,SAASC,qBAAqB,QAAQ,uBAAuB;AAC7D,SAASC,cAAc,EAAEC,WAAW,EAAEC,cAAc,QAAQ,cAAc;AAE1E,SAASC,wBAAwB,EAAEC,aAAa,EAAEC,kBAAkB,QAAQ,gBAAgB;AAc5F,SAASC,eAAeC,CAAe;IACrC,MAAMC,MAAM;QAAEC,GAAGF,EAAEE,CAAC;QAAEC,GAAGH,EAAEG,CAAC;QAAEH,GAAGA,EAAEA,CAAC;QAAEI,GAAGJ,EAAEI,CAAC;IAAC;IAC7C,OAAOJ,EAAEK,UAAU,KAAKC,YAAY;QAAEC,MAAMP,EAAEO,IAAI;QAAEN;IAAI,IAAI;QAAEM,MAAMP,EAAEO,IAAI;QAAEN;QAAKI,YAAYL,EAAEK,UAAU;IAAC;AAC5G;AAEA,8EAA8E;AAC9E,qIAAqI;AACrI,SAASG,gBAAgBC,CAAY,EAAEC,SAA4B;IACjE,MAAMC,cAAcF,EAAEG,KAAK,CAACC,GAAG,CAAC,CAACb,IAAMU,UAAUI,GAAG,CAACd;IACrD,IAAIS,EAAEM,IAAI,KAAK,WAAW,OAAO;QAAEC,MAAM;QAAWT,MAAME,EAAEF,IAAI;QAAEU,OAAOR,EAAEQ,KAAK;QAAEN;IAAY;IAC9F,IAAIF,EAA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4E;iBAAE;YAAC,IAAI;gBAAEvE,MAAM;gBAAsBT,MAAM4D,EAAE5D,IAAI;gBAAEI,aAAa;oBAAC4E;iBAAE;YAAC;QAClK;QACA,OAAO;YAAEzD;YAAMlB;YAAOyC;QAAO;IAC/B;IAEA,OAAO;QAAEY,eAAetE;QAAgBoE;QAAQpC,OAAO6D;IAAc;AACvE;AAEA;;;;;;CAMC,GACD,OAAO,eAAeC,QAAQtE,KAAyC,EAAEC,OAAuB,CAAC,CAAC;IAChGvB,cAAcuB,KAAKO,KAAK;IACxB,IAAI,OAAOR,UAAU,UAAU,OAAOuC,WAAW;QAAE9C,OAAOd,mBAAmBqB;IAAO,GAAGC;IACvF,IAAIA,KAAKsE,IAAI,KAAK,OAAO,OAAOhC,WAAW;QAAEzB,SAASd;IAAM,GAAGC;IAC/D,OAAOmD,YAAYpD,OAAOC;AAC5B"}
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Projects/pdf-to-md/src/audit.ts"],"sourcesContent":["// audit.ts — the severity-1 audit instrument (README's \"Design contract\"),\n// shipped as part of the product, not just a path into the source tree.\n//\n// Every recognized word (a --debug-words dump, or an Analysis page's\n// `words`) must appear in its page's markdown — normalized, compared as a per-page multiset, with substring repair for hyphen joins.\n//\n// NOTE: no producer guarantees JSON key order in a --debug-words dump —\n// parse, never grep.\nimport { readFileSync } from 'node:fs';\nimport { bodyByPage } from './page-marker.ts';\n\nfunction norm(s: string): string {\n return s\n .normalize('NFKD')\n .replace(/\\p{M}/gu, '')\n .toLowerCase()\n .replace(/[^a-z0-9]/g, '');\n}\n\nfunction counter(items: Iterable<string>): Map<string, number> {\n const m = new Map<string, number>();\n for (const item of items) m.set(item, (m.get(item) ?? 0) + 1);\n return m;\n}\n\n/** auditWords()'s result — the severity-1 no-silent-loss check. */\nexport interface AuditResult {\n /** JSON lines successfully parsed from the word dump */\n parsed: number;\n /** lines in the dump that were not parseable JSON, skipped rather than\n * failing the whole audit (same policy `--words-json` itself uses) */\n nonJsonSkipped: number;\n /** distinct page numbers present in the dump */\n pages: number;\n /** total recognized words across all pages in the dump */\n words: number;\n /** words present in the dump but not found verbatim on their page, BEFORE\n * hyphen-join/split repair is applied; always `>= missing` */\n strictDeficits: number;\n /** words genuinely absent from the markdown after repair-checking; `0` is\n * the only passing value (`pdf-to-md audit` exits 1 otherwise) */\n missing: number;\n /** per-page detail for every page with at least one missing word (capped\n * sample of the missing tokens per page) */\n perPage: { page: number; missing: string[] }[];\n /** the one-line `parsed=… pages=… words=… strict_deficits=… MISSING=…`\n * summary, also the last entry of `lines` */\n summaryLine: string;\n /** every line `pdf-to-md audit` prints, in order: one per page with\n * missing words, then `summaryLine` */\n lines: string[];\n}\n\n/**\n * Audit a --debug-words dump against a markdown file: every recognized word\n * must land somewhere in its page's markdown. `result.missing === 0` is the pass/fail signal.\n *\n * @param wordsPath path to a --debug-words JSON-lines dump (`{page, text, ...}` per line)\n * @param mdPath path to the markdown file to check the dump against\n */\nexport function auditWords(wordsPath: string, mdPath: string): AuditResult {\n const rec = new Map<number, string[]>();\n let parsed = 0;\n let skipped = 0;\n\n const wordsRaw = readFileSync(wordsPath, 'utf8');\n // A trailing \"\\n\" at EOF must not yield a spurious final empty line; a\n // genuine blank line mid-file does count, as skipped.\n const rawLines = wordsRaw.split('\\n');\n if (rawLines.length > 0 && rawLines[rawLines.length - 1] === '') rawLines.pop();\n for (let line of rawLines) {\n line = line.trim();\n if (!line.startsWith('{')) {\n skipped++;\n continue;\n }\n let o: { page: number; text: string };\n try {\n o = JSON.parse(line);\n } catch {\n skipped++;\n continue;\n }\n parsed++;\n const t = norm(o.text);\n if (t) {\n const arr = rec.get(o.page);\n if (arr) arr.push(t);\n else rec.set(o.page, [t]);\n }\n }\n\n const md = readFileSync(mdPath, 'utf8');\n const out = bodyByPage(md);\n\n const lines: string[] = [];\n let total = 0;\n let strict = 0;\n const perPage: { page: number; missing: string[] }[] = [];\n const pages = [...rec.keys()].sort((a, b) => a - b);\n\n for (const page of pages) {\n const toks = (out.get(page)?.match(/\\S+/g) ?? []).map(norm).filter((t) => t.length > 0);\n const ms = counter(toks);\n const joined = toks.join('');\n const missing: string[] = [];\n for (const [tok, n] of counter(rec.get(page) ?? [])) {\n const d = n - (ms.get(tok) ?? 0);\n if (d <= 0) continue;\n strict += d;\n if (joined.includes(tok)) continue; // hyphen-join / split repair\n for (let i = 0; i < d; i++) missing.push(tok);\n }\n if (missing.length > 0) {\n total += missing.length;\n perPage.push({ page, missing });\n lines.push(`p${page}: MISSING ${missing.length}: ${pyRepr(missing.slice(0, 12))}`);\n }\n }\n\n const words = pages.reduce((sum, p) => sum + (rec.get(p)?.length ?? 0), 0);\n const summaryLine = `parsed=${parsed} non-json-skipped=${skipped} pages=${rec.size} words=${words} strict_deficits=${strict} MISSING=${total}`;\n lines.push(summaryLine);\n\n return {\n parsed,\n nonJsonSkipped: skipped,\n pages: rec.size,\n words,\n strictDeficits: strict,\n missing: total,\n perPage,\n summaryLine,\n lines,\n };\n}\n\n// Renders a string list as ['a', 'b'] (single-quoted) to match frozen baseline comparisons byte-for-byte.\nfunction pyRepr(items: string[]): string {\n return `[${items.map((s) => `'${s.replace(/\\\\/g, '\\\\\\\\').replace(/'/g, \"\\\\'\")}'`).join(', ')}]`;\n}\n"],"names":["readFileSync","bodyByPage","norm","s","normalize","replace","toLowerCase","counter","items","m","Map","item","set","get","auditWords","wordsPath","mdPath","rec","parsed","skipped","wordsRaw","rawLines","split","length","pop","line","trim","startsWith","o","JSON","parse","t","text","arr","page","push","md","out","lines","total","strict","perPage","pages","keys","sort","a","b","toks","match","map","filter","ms","joined","join","missing","tok","n","d","includes","i","pyRepr","slice","words","reduce","sum","p","summaryLine","size","nonJsonSkipped","strictDeficits"],"mappings":"AAAA,2EAA2E;AAC3E,wEAAwE;AACxE,EAAE;AACF,qEAAqE;AACrE,qIAAqI;AACrI,EAAE;AACF,wEAAwE;AACxE,qBAAqB;AACrB,SAASA,YAAY,QAAQ,UAAU;AACvC,SAASC,UAA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ACoD,gBAARhD,+BAAAA,SAAYM,MAAM,uCAAI;OAAI;IACxE,MAAM2C,cAAc,CAAC,OAAO,EAAEhD,OAAO,kBAAkB,EAAEC,QAAQ,OAAO,EAAEF,IAAIkD,IAAI,CAAC,OAAO,EAAEL,MAAM,iBAAiB,EAAEtB,OAAO,SAAS,EAAED,OAAO;IAC9ID,MAAMH,IAAI,CAAC+B;IAEX,OAAO;QACLhD;QACAkD,gBAAgBjD;QAChBuB,OAAOzB,IAAIkD,IAAI;QACfL;QACAO,gBAAgB7B;QAChBc,SAASf;QACTE;QACAyB;QACA5B;IACF;AACF;AAEA,0GAA0G;AAC1G,SAASsB,OAAOpD,KAAe;IAC7B,OAAO,CAAC,CAAC,EAAEA,MAAMyC,GAAG,CAAC,CAAC9C,IAAM,CAAC,CAAC,EAAEA,EAAEE,OAAO,CAAC,OAAO,QAAQA,OAAO,CAAC,MAAM,OAAO,CAAC,CAAC,EAAEgD,IAAI,CAAC,MAAM,CAAC,CAAC;AACjG"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/formats/pdf-to-md/src/audit.ts"],"sourcesContent":["// audit.ts — the severity-1 audit instrument (README's \"Design contract\"),\n// shipped as part of the product, not just a path into the source tree.\n//\n// Every recognized word (a --debug-words dump, or an Analysis page's\n// `words`) must appear in its page's markdown — normalized, compared as a per-page multiset, with substring repair for hyphen joins.\n//\n// NOTE: no producer guarantees JSON key order in a --debug-words dump —\n// parse, never grep.\nimport { readFileSync } from 'node:fs';\nimport { bodyByPage } from './page-marker.ts';\n\nfunction norm(s: string): string {\n return s\n .normalize('NFKD')\n .replace(/\\p{M}/gu, '')\n .toLowerCase()\n .replace(/[^a-z0-9]/g, '');\n}\n\nfunction counter(items: Iterable<string>): Map<string, number> {\n const m = new Map<string, number>();\n for (const item of items) m.set(item, (m.get(item) ?? 0) + 1);\n return m;\n}\n\n/** auditWords()'s result — the severity-1 no-silent-loss check. */\nexport interface AuditResult {\n /** JSON lines successfully parsed from the word dump */\n parsed: number;\n /** lines in the dump that were not parseable JSON, skipped rather than\n * failing the whole audit (same policy `--words-json` itself uses) */\n nonJsonSkipped: number;\n /** distinct page numbers present in the dump */\n pages: number;\n /** total recognized words across all pages in the dump */\n words: number;\n /** words present in the dump but not found verbatim on their page, BEFORE\n * hyphen-join/split repair is applied; always `>= missing` */\n strictDeficits: number;\n /** words genuinely absent from the markdown after repair-checking; `0` is\n * the only passing value (`pdf-to-md audit` exits 1 otherwise) */\n missing: number;\n /** per-page detail for every page with at least one missing word (capped\n * sample of the missing tokens per page) */\n perPage: { page: number; missing: string[] }[];\n /** the one-line `parsed=… pages=… words=… strict_deficits=… MISSING=…`\n * summary, also the last entry of `lines` */\n summaryLine: string;\n /** every line `pdf-to-md audit` prints, in order: one per page with\n * missing words, then `summaryLine` */\n lines: string[];\n}\n\n/**\n * Audit a --debug-words dump against a markdown file: every recognized word\n * must land somewhere in its page's markdown. `result.missing === 0` is the pass/fail signal.\n *\n * @param wordsPath path to a --debug-words JSON-lines dump (`{page, text, ...}` per line)\n * @param mdPath path to the markdown file to check the dump against\n */\nexport function auditWords(wordsPath: string, mdPath: string): AuditResult {\n const rec = new Map<number, string[]>();\n let parsed = 0;\n let skipped = 0;\n\n const wordsRaw = readFileSync(wordsPath, 'utf8');\n // A trailing \"\\n\" at EOF must not yield a spurious final empty line; a\n // genuine blank line mid-file does count, as skipped.\n const rawLines = wordsRaw.split('\\n');\n if (rawLines.length > 0 && rawLines[rawLines.length - 1] === '') rawLines.pop();\n for (let line of rawLines) {\n line = line.trim();\n if (!line.startsWith('{')) {\n skipped++;\n continue;\n }\n let o: { page: number; text: string };\n try {\n o = JSON.parse(line);\n } catch {\n skipped++;\n continue;\n }\n parsed++;\n const t = norm(o.text);\n if (t) {\n const arr = rec.get(o.page);\n if (arr) arr.push(t);\n else rec.set(o.page, [t]);\n }\n }\n\n const md = readFileSync(mdPath, 'utf8');\n const out = bodyByPage(md);\n\n const lines: string[] = [];\n let total = 0;\n let strict = 0;\n const perPage: { page: number; missing: string[] }[] = [];\n const pages = [...rec.keys()].sort((a, b) => a - b);\n\n for (const page of pages) {\n const toks = (out.get(page)?.match(/\\S+/g) ?? []).map(norm).filter((t) => t.length > 0);\n const ms = counter(toks);\n const joined = toks.join('');\n const missing: string[] = [];\n for (const [tok, n] of counter(rec.get(page) ?? [])) {\n const d = n - (ms.get(tok) ?? 0);\n if (d <= 0) continue;\n strict += d;\n if (joined.includes(tok)) continue; // hyphen-join / split repair\n for (let i = 0; i < d; i++) missing.push(tok);\n }\n if (missing.length > 0) {\n total += missing.length;\n perPage.push({ page, missing });\n lines.push(`p${page}: MISSING ${missing.length}: ${pyRepr(missing.slice(0, 12))}`);\n }\n }\n\n const words = pages.reduce((sum, p) => sum + (rec.get(p)?.length ?? 0), 0);\n const summaryLine = `parsed=${parsed} non-json-skipped=${skipped} pages=${rec.size} words=${words} strict_deficits=${strict} MISSING=${total}`;\n lines.push(summaryLine);\n\n return {\n parsed,\n nonJsonSkipped: skipped,\n pages: rec.size,\n words,\n strictDeficits: strict,\n missing: total,\n perPage,\n summaryLine,\n lines,\n };\n}\n\n// Renders a string list as ['a', 'b'] (single-quoted) to match frozen baseline comparisons byte-for-byte.\nfunction pyRepr(items: string[]): string {\n return `[${items.map((s) => `'${s.replace(/\\\\/g, '\\\\\\\\').replace(/'/g, \"\\\\'\")}'`).join(', ')}]`;\n}\n"],"names":["readFileSync","bodyByPage","norm","s","normalize","replace","toLowerCase","counter","items","m","Map","item","set","get","auditWords","wordsPath","mdPath","rec","parsed","skipped","wordsRaw","rawLines","split","length","pop","line","trim","startsWith","o","JSON","parse","t","text","arr","page","push","md","out","lines","total","strict","perPage","pages","keys","sort","a","b","toks","match","map","filter","ms","joined","join","missing","tok","n","d","includes","i","pyRepr","slice","words","reduce","sum","p","summaryLine","size","nonJsonSkipped","strictDeficits"],"mappings":"AAAA,2EAA2E;AAC3E,wEAAwE;AACxE,EAAE;AACF,qEAAqE;AACrE,qIAAqI;AACrI,EAAE;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AAM,CAAC,CAACC,KAAKC;;YAAahD;eAAP+C,gBAAO/C,WAAAA,IAAIJ,GAAG,CAACoD,gBAARhD,+BAAAA,SAAYM,MAAM,uCAAI;OAAI;IACxE,MAAM2C,cAAc,CAAC,OAAO,EAAEhD,OAAO,kBAAkB,EAAEC,QAAQ,OAAO,EAAEF,IAAIkD,IAAI,CAAC,OAAO,EAAEL,MAAM,iBAAiB,EAAEtB,OAAO,SAAS,EAAED,OAAO;IAC9ID,MAAMH,IAAI,CAAC+B;IAEX,OAAO;QACLhD;QACAkD,gBAAgBjD;QAChBuB,OAAOzB,IAAIkD,IAAI;QACfL;QACAO,gBAAgB7B;QAChBc,SAASf;QACTE;QACAyB;QACA5B;IACF;AACF;AAEA,0GAA0G;AAC1G,SAASsB,OAAOpD,KAAe;IAC7B,OAAO,CAAC,CAAC,EAAEA,MAAMyC,GAAG,CAAC,CAAC9C,IAAM,CAAC,CAAC,EAAEA,EAAEE,OAAO,CAAC,OAAO,QAAQA,OAAO,CAAC,MAAM,OAAO,CAAC,CAAC,EAAEgD,IAAI,CAAC,MAAM,CAAC,CAAC;AACjG"}
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Projects/pdf-to-md/src/cli/audit.ts"],"sourcesContent":["// audit command — the severity-1 audit instrument (README's \"Design\n// contract\") as a first-class subcommand. Thin wrapper over src/audit.ts's auditWords (the library returns data, only the CLI prints and exits).\nimport type { Command } from './types.ts';\n\nconst USAGE = 'usage: pdf-to-md audit <words.jsonl> <file.md>';\n\nconst audit: Command = async (ctx) => {\n if (ctx.rest.includes('-h') || ctx.rest.includes('--help')) {\n console.log(USAGE);\n return;\n }\n const [wordsPath, mdPath] = ctx.rest;\n if (!wordsPath || !mdPath) ctx.usageError(USAGE);\n\n // Imported here, not at module top, same lazy-load rule as every other\n // command — `pdf-to-md audit` should never pay for what the other commands need.\n const { auditWords } = await import('../audit.ts');\n const result = auditWords(wordsPath, mdPath);\n for (const line of result.lines) console.log(line);\n\n // MISSING>0 is the severity-1 fail signal: a recognized word this markdown\n // lost. Exit 1 so the subcommand is usable as a CI gate; strict_deficits from hyphen-join repairs are reported but not failures.\n if (result.missing > 0) process.exitCode = 1;\n};\n\nexport default audit;\n"],"names":["USAGE","audit","ctx","rest","includes","console","log","wordsPath","mdPath","usageError","auditWords","result","line","lines","missing","process","exitCode"],"mappings":"AAAA,oEAAoE;AACpE,iJAAiJ;AAGjJ,MAAMA,QAAQ;AAEd,MAAMC,QAAiB,OAAOC;IAC5B,IAAIA,IAAIC,IAAI,CAACC,QAAQ,CAAC,SAASF,IAAIC,IAAI,CAACC,QAAQ,CAAC,WAAW;QAC1DC,QAAQC,GAAG,CAACN;QACZ;IACF;IACA,MAAM,CAACO,WAAWC,OAAO,GAAGN,IAAIC,IAAI;IACpC,IAAI,CAACI,aAAa,CAACC,QAAQN,IAAIO,UAAU,CAACT;IAE1C,uEAAuE;IACvE,iFAAiF;IACjF,MAAM,EAAEU,UAAU,EAAE,GAAG,MAAM,MAAM,CAAC;IACpC,MAAMC,SAASD,WAAWH,WAAWC;IACrC,KAAK,MAAMI,QAAQD,OAAOE,KAAK,CAAER,QAAQC,GAAG,CAACM;IAE7C,2EAA2E;IAC3E,iIAAiI;IACjI,IAAID,OAAOG,OAAO,GAAG,GAAGC,QAAQC,QAAQ,GAAG;AAC7C;AAEA,eAAef,MAAM"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/formats/pdf-to-md/src/cli/audit.ts"],"sourcesContent":["// audit command — the severity-1 audit instrument (README's \"Design\n// contract\") as a first-class subcommand. Thin wrapper over src/audit.ts's auditWords (the library returns data, only the CLI prints and exits).\nimport type { Command } from './types.ts';\n\nconst USAGE = 'usage: pdf-to-md audit <words.jsonl> <file.md>';\n\nconst audit: Command = async (ctx) => {\n if (ctx.rest.includes('-h') || ctx.rest.includes('--help')) {\n console.log(USAGE);\n return;\n }\n const [wordsPath, mdPath] = ctx.rest;\n if (!wordsPath || !mdPath) ctx.usageError(USAGE);\n\n // Imported here, not at module top, same lazy-load rule as every other\n // command — `pdf-to-md audit` should never pay for what the other commands need.\n const { auditWords } = await import('../audit.ts');\n const result = auditWords(wordsPath, mdPath);\n for (const line of result.lines) console.log(line);\n\n // MISSING>0 is the severity-1 fail signal: a recognized word this markdown\n // lost. Exit 1 so the subcommand is usable as a CI gate; strict_deficits from hyphen-join repairs are reported but not failures.\n if (result.missing > 0) process.exitCode = 1;\n};\n\nexport default audit;\n"],"names":["USAGE","audit","ctx","rest","includes","console","log","wordsPath","mdPath","usageError","auditWords","result","line","lines","missing","process","exitCode"],"mappings":"AAAA,oEAAoE;AACpE,iJAAiJ;AAGjJ,MAAMA,QAAQ;AAEd,MAAMC,QAAiB,OAAOC;IAC5B,IAAIA,IAAIC,IAAI,CAACC,QAAQ,CAAC,SAASF,IAAIC,IAAI,CAACC,QAAQ,CAAC,WAAW;QAC1DC,QAAQC,GAAG,CAACN;QACZ;IACF;IACA,MAAM,CAACO,WAAWC,OAAO,GAAGN,IAAIC,IAAI;IACpC,IAAI,CAACI,aAAa,CAACC,QAAQN,IAAIO,UAAU,CAACT;IAE1C,uEAAuE;IACvE,iFAAiF;IACjF,MAAM,EAAEU,UAAU,EAAE,GAAG,MAAM,MAAM,CAAC;IACpC,MAAMC,SAASD,WAAWH,WAAWC;IACrC,KAAK,MAAMI,QAAQD,OAAOE,KAAK,CAAER,QAAQC,GAAG,CAACM;IAE7C,2EAA2E;IAC3E,iIAAiI;IACjI,IAAID,OAAOG,OAAO,GAAG,GAAGC,QAAQC,QAAQ,GAAG;AAC7C;AAEA,eAAef,MAAM"}
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Projects/pdf-to-md/src/cli/extract.ts"],"sourcesContent":["// extract command — parse this command's flags, call src/extract.ts, print\n// and write the result. No business logic here — the library returns data and throws; only the CLI prints and exits.\nimport { readFileSync, writeFileSync } from 'node:fs';\nimport path from 'node:path';\nimport { parseArgs } from 'node:util';\nimport type { OcrWordInput } from '../extract.ts';\nimport type { Tuning } from '../geometry.ts';\nimport type { Analysis, Report } from '../types.ts';\nimport type { Command } from './types.ts';\n\nconst USAGE =\n 'usage: pdf-to-md [extract] <file.pdf> [out.md] [--json] [--page-markers] [--ocr] [--no-ocr] ' +\n '[--pages N[-M]] [--stdout] [--words-json=FILE] [--debug-words=FILE] ' +\n '[--format md|txt|raw (default md; raw = Analysis JSON incl. the report; txt = reading-order plain text)] ' +\n '[--dpi=N (OCR render resolution, default 288; raise for tiny print or chart/label pages, ' +\n '>~400 measured worse on ordinary prose pages)] ' +\n '[--float-max-words=N] [--float-max-width=F] [--float-margin=F] [--para-gap=F] [--heading-scale=F] ' +\n '[--col-max-width=F] [--col-split=F] [--line-y-tol=F] [--line-height-ratio=F]';\n\nconst FORMATS = ['md', 'txt', 'raw'] as const;\ntype Format = (typeof FORMATS)[number];\n\n// A bad tuning-flag value (non-numeric, or <= 0 unless the flag allows zero) is a usage error, not a silent no-op.\nconst TUNING_FLAGS: {\n name: string;\n key: keyof Tuning;\n allowZero?: boolean;\n isInt?: boolean;\n}[] = [\n {\n name: 'float-max-words',\n key: 'floatMaxWords',\n allowZero: true,\n isInt: true,\n },\n { name: 'float-max-width', key: 'floatMaxWidth' },\n { name: 'float-margin', key: 'floatMargin' },\n { name: 'para-gap', key: 'paraGap' },\n { name: 'heading-scale', key: 'headingScale' },\n { name: 'col-max-width', key: 'colMaxWidth' },\n { name: 'col-split', key: 'colSplit' },\n { name: 'line-y-tol', key: 'lineYTol' },\n { name: 'line-height-ratio', key: 'lineHeightRatio' },\n];\n\nconst extract: Command = async (ctx) => {\n // --debug-words takes a required FILE value; a bare --debug-words is a\n // usage error, checked before parseArgs so it can't silently swallow the next token as its value.\n if (ctx.rest.includes('--debug-words')) {\n ctx.usageError(`${USAGE}\\n--debug-words requires a value: --debug-words=FILE`);\n }\n\n const parsed = (() => {\n try {\n return parseArgs({\n args: ctx.rest,\n options: {\n json: { type: 'boolean', default: false },\n 'page-markers': { type: 'boolean', default: false },\n ocr: { type: 'boolean', default: false },\n 'no-ocr': { type: 'boolean', default: false },\n stdout: { type: 'boolean', default: false },\n 'debug-words': { type: 'string' },\n help: { type: 'boolean', default: false, short: 'h' },\n pages: { type: 'string' },\n dpi: { type: 'string' },\n format: { type: 'string', default: 'md' },\n 'words-json': { type: 'string' },\n ...Object.fromEntries(TUNING_FLAGS.map((f) => [f.name, { type: 'string' as const }])),\n },\n allowPositionals: true,\n });\n } catch (err) {\n // usageError exits; the throw is dead code that tells the compiler so.\n throw ctx.usageError(`${(err as Error).message}\\n${USAGE}`);\n }\n })();\n const values = parsed.values as Record<string, string | boolean | undefined>;\n const positionals = parsed.positionals;\n\n if (values.help) {\n console.log(USAGE);\n return;\n }\n\n const [src, outArg] = positionals;\n const wordsPath = values['words-json'] as string | undefined;\n if (!src && !wordsPath) ctx.usageError(USAGE);\n\n const formatRaw = values.format as string;\n if (!(FORMATS as readonly string[]).includes(formatRaw)) {\n ctx.usageError(`${USAGE}\\n--format must be one of ${FORMATS.join('|')} (got ${JSON.stringify(formatRaw)})`);\n }\n const format = formatRaw as Format;\n\n // --pages: a malformed spec is a usage error; out-of-range page NUMBERS\n // clamp instead (collect.ts / the engine apply the same clamping policy).\n let pages: { first: number; last: number } | undefined;\n if (values.pages !== undefined) {\n const m = /^(\\d+)(?:-(\\d+))?$/.exec(values.pages as string);\n const first = m ? Number(m[1]) : Number.NaN;\n const last = m ? (m[2] !== undefined ? Number(m[2]) : first) : Number.NaN;\n if (!m || first < 1 || last < first) {\n ctx.usageError(`${USAGE}\\n--pages requires N or N-M, N >= 1, M >= N (got ${JSON.stringify(values.pages)})`);\n }\n pages = { first, last };\n }\n\n const tuning: Partial<Tuning> = {};\n for (const spec of TUNING_FLAGS) {\n const raw = values[spec.name] as string | undefined;\n if (raw === undefined) continue;\n const value = Number(raw);\n const ok = raw !== '' && Number.isFinite(value) && (spec.allowZero ? value >= 0 : value > 0);\n if (!ok) {\n ctx.usageError(`${USAGE}\\n--${spec.name} requires a ${spec.allowZero ? 'non-negative' : 'positive'} number (got ${JSON.stringify(raw)})`);\n }\n (tuning[spec.key] as number) = spec.isInt ? Math.trunc(value) : value;\n }\n\n // --dpi: page-render resolution, validated like the tuning flags. Default\n // 288 is the measured operating point; >~400 measured WORSE on ordinary pages — not a \"bigger is safer\" knob.\n let dpi: number | undefined;\n if (values.dpi !== undefined) {\n const raw = values.dpi as string;\n const value = Number(raw);\n if (raw === '' || !Number.isFinite(value) || value <= 0) {\n ctx.usageError(`${USAGE}\\n--dpi requires a positive number (got ${JSON.stringify(raw)})`);\n }\n dpi = value;\n }\n\n // In --words-json mode there may be no PDF positional; the words file\n // stands in for naming, extension stripped so the default dest can never overwrite the input. Default extension follows --format.\n const source = src ?? (wordsPath as string);\n const defaultExt = format === 'raw' ? 'json' : format === 'txt' ? 'txt' : 'md';\n const dest = outArg || `${source.replace(/\\.(pdf|jsonl)$/i, '')}.${defaultExt}`;\n\n const onWarning = (m: string) => console.error(m);\n const showProgress = process.stderr.isTTY;\n // onProgress carries per-page timing/count only; human-readable\n // diagnostics (e.g. the sparse-retry notice) arrive via onWarning instead, so they print regardless of TTY-ness.\n const onProgress = (e: { type: 'page'; page: number; words: number; ms: number }) => {\n if (showProgress) console.error(`p${e.page}: ${e.words} words, ${e.ms}ms`);\n };\n const debugWordsPath = values['debug-words'] as string | undefined;\n if (debugWordsPath !== undefined && debugWordsPath.trim() === '') {\n ctx.usageError(`${USAGE}\\n--debug-words requires a value: --debug-words=FILE`);\n }\n // The severity-1 audit instrument: every recognized word as clean JSON\n // lines to its own file. stderr stays a human channel (mixed prose), never a dump target — this file is guaranteed byte-for-byte parseable.\n const onWords = debugWordsPath\n ? (words: OcrWordInput[]) => {\n const lines = words.map((w) => {\n const entry: OcrWordInput = { page: w.page, text: w.text, x: w.x, y: w.y, w: w.w, h: w.h };\n if (w.confidence !== undefined) entry.confidence = w.confidence;\n return JSON.stringify(entry);\n });\n writeFileSync(debugWordsPath, lines.length ? `${lines.join('\\n')}\\n` : '');\n }\n : undefined;\n\n const common = { pages, onWarning };\n const ocrCommon = {\n ...common,\n tuning,\n dpi,\n onProgress,\n onWords,\n };\n\n let words: OcrWordInput[] | undefined;\n let skipped = 0;\n if (wordsPath !== undefined) {\n ({ words, skipped } = parseWordLines(readFileSync(wordsPath, 'utf8')));\n if (skipped > 0) console.error(`--words-json: skipped ${skipped} non-JSON line(s)`);\n }\n\n let content: string;\n let report: Report;\n if (format === 'md') {\n // Unchanged path: extractOcr/pdfToMarkdown directly, exactly as before\n // --format existed.\n const { extractOcr, pdfToMarkdown } = await import('../extract.ts');\n let markdown: string;\n if (words !== undefined) {\n ({ markdown, report } = await extractOcr({ words }, ocrCommon));\n } else {\n ({ markdown, report } = await pdfToMarkdown(src, {\n ...ocrCommon,\n ocr: values.ocr as boolean,\n noOcr: values['no-ocr'] as boolean,\n pageMarkers: values['page-markers'] as boolean,\n }));\n }\n content = markdown;\n } else {\n // raw/txt: both render from an Analysis — raw IS the Analysis as JSON;\n // txt is toText(analysis). Mirrors pdfToMarkdown's own auto-OCR fallback decision so a different --format doesn't silently pick a different path.\n const { analyze } = await import('../analyze.ts');\n const { toText } = await import('../render-analysis.ts');\n const { needsOcrFallback, ocrFallbackNotice } = await import('../extract.ts');\n let analysis: Analysis;\n if (words !== undefined) {\n analysis = await analyze({ words }, { ...ocrCommon, path: 'ocr' });\n } else if (values.ocr) {\n analysis = await analyze(src, { ...ocrCommon, path: 'ocr' });\n } else {\n const text = await analyze(src, { ...common, path: 'text', pageMarkers: values['page-markers'] as boolean });\n if (needsOcrFallback(text.report.charsPerPage) && !values['no-ocr']) {\n onWarning(ocrFallbackNotice(text.report.charsPerPage));\n analysis = await analyze(src, { ...ocrCommon, path: 'ocr', fallback: true });\n } else {\n analysis = text;\n }\n }\n report = analysis.report;\n content = format === 'raw' ? JSON.stringify(analysis, null, 1) : toText(analysis);\n }\n\n if (values.stdout) process.stdout.write(content);\n else writeFileSync(dest, content);\n\n // The library's Report stays clean of source/out; --json consumers keep\n // report.json files around and need to know which input produced each one, so the CLI (only) decorates the printed JSON with source/out here.\n if (values.json) console.log(JSON.stringify({ source, out: dest, ...report }, null, 1));\n else if (report.path === 'ocr') {\n console.error(`${path.basename(dest).padEnd(32)} OCR path heads=${report.headings}(junk ${report.junkHeadings}) ` + `paras=${report.paragraphs} callouts=${report.callouts} floats=${report.floats ?? 0} dangling=${report.danglingLong} (long) ` + `~${report.charsPerPage} chars/page`);\n } else {\n console.error(\n `${path.basename(dest).padEnd(32)} body=${report.bodyFontHeight}pt heads=${report.headings}(junk ${report.junkHeadings}) ` +\n `lists=${report.listItems} paras=${report.paragraphs} callouts=${report.callouts} pairs=${report.joinedPairs} ` +\n `~${report.charsPerPage} chars/page` +\n (report.sparse ? ' ⚠️ implausibly sparse — pages are likely images; re-run with --ocr' : '')\n );\n }\n};\n\n// Parse one word-dump JSON line per word — key order is not guaranteed, parse\n// never grep. Non-JSON lines are skipped with a count, not fatal (the auditor applies the same policy).\nfunction parseWordLines(raw: string): { words: OcrWordInput[]; skipped: number } {\n const words: OcrWordInput[] = [];\n let skipped = 0;\n for (const line of raw.split('\\n')) {\n if (!line.trim()) continue;\n try {\n words.push(JSON.parse(line));\n } catch {\n skipped++;\n }\n }\n return { words, skipped };\n}\n\nexport default extract;\n"],"names":["readFileSync","writeFileSync","path","parseArgs","USAGE","FORMATS","TUNING_FLAGS","name","key","allowZero","isInt","extract","ctx","rest","includes","usageError","parsed","args","options","json","type","default","ocr","stdout","help","short","pages","dpi","format","Object","fromEntries","map","f","allowPositionals","err","message","values","positionals","console","log","src","outArg","wordsPath","formatRaw","join","JSON","stringify","undefined","m","exec","first","Number","NaN","last","tuning","spec","raw","value","ok","isFinite","Math","trunc","source","defaultExt","dest","replace","onWarning","error","showProgress","process","stderr","isTTY","onProgress","e","page","words","ms","debugWordsPath","trim","onWords","lines","w","entry","text","x","y","h","confidence","length","common","ocrCommon","skipped","parseWordLines","content","report","extractOcr","pdfToMarkdown","markdown","noOcr","pageMarkers","analyze","toText","needsOcrFallback","ocrFallbackNotice","analysis","charsPerPage","fallback","write","out","basename","padEnd","headings","junkHeadings","paragraphs","callouts","floats","danglingLong","bodyFontHeight","listItems","joinedPairs","sparse","line","split","push","parse"],"mappings":"AAAA,2EAA2E;AAC3E,qHAAqH;AACrH,SAASA,YAAY,EAAEC,aAAa,QAAQ,UAAU;AACtD,OAAOC,UAAU,YAAY;AAC7B,SAASC,SAAS,QAAQ,YAAY;AAMtC,MAAMC,QACJ,iGACA,yEACA,8GACA,8FACA,oDACA,uGACA;AAEF,MAAMC,UAAU;IAAC;IAAM;IAAO;CAAM;AAGpC,mHAAmH;AACnH,MAAMC,eAKA;IACJ;QACEC,MAAM;QACNC,KAAK;QACLC,WAAW;QACXC,OAAO;IACT;IACA;QAAEH,MAAM;QAAmBC,KAAK;IAAgB;IAChD;QAAED,MAAM;QAAgBC,KAAK;IAAc;IAC3C;QAAED,MAAM;QAAYC,KAAK;IAAU;IACnC;QAAED,MAAM;QAAiBC,KAAK;IAAe;IAC7C;QAAED,MAAM;QAAiBC,KAAK;IAAc;IAC5C;QAAED,MAAM;QAAaC,KAAK;IAAW;IACrC;QAAED,MAAM;QAAcC,KAAK;IAAW;IACtC;QAAED,MAAM;QAAqBC,KAAK;IAAkB;CACrD;AAED,MAAMG,UAAmB,OAAOC;IAC9B,uEAAuE;IACvE,kGAAkG;IAClG,IAAIA,IAAIC,IAAI,CAACC,QAAQ,CAAC,kBAAkB;QACtCF,IAAIG,UAAU,CAAC,GAAGX,MAAM,oDAAoD,CAAC;IAC/E;IAEA,MAAMY,SAAS,AAAC,CAAA;QACd,IAAI;YACF,OAAOb,UAAU;gBACfc,MAAML,IAAIC,IAAI;gBACdK,SAAS;oBACPC,MAAM;wBAAEC,MAAM;wBAAWC,SAAS;oBAAM;oBACxC,gBAAgB;wBAAED,MAAM;wBAAWC,SAAS;oBAAM;oBAClDC,KAAK;wBAAEF,MAAM;wBAAWC,SAAS;oBAAM;oBACvC,UAAU;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;IAAQ;AAC1B;AAEA,eAAehF,QAAQ"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/formats/pdf-to-md/src/cli/extract.ts"],"sourcesContent":["// extract command — parse this command's flags, call src/extract.ts, print\n// and write the result. No business logic here — the library returns data and throws; only the CLI prints and exits.\nimport { readFileSync, writeFileSync } from 'node:fs';\nimport path from 'node:path';\nimport { parseArgs } from 'node:util';\nimport type { OcrWordInput } from '../extract.ts';\nimport type { Tuning } from '../geometry.ts';\nimport type { Analysis, Report } from '../types.ts';\nimport type { Command } from './types.ts';\n\nconst USAGE =\n 'usage: pdf-to-md [extract] <file.pdf> [out.md] [--json] [--page-markers] [--ocr] [--no-ocr] ' +\n '[--pages N[-M]] [--stdout] [--words-json=FILE] [--debug-words=FILE] ' +\n '[--format md|txt|raw (default md; raw = Analysis JSON incl. the report; txt = reading-order plain text)] ' +\n '[--dpi=N (OCR render resolution, default 288; raise for tiny print or chart/label pages, ' +\n '>~400 measured worse on ordinary prose pages)] ' +\n '[--float-max-words=N] [--float-max-width=F] [--float-margin=F] [--para-gap=F] [--heading-scale=F] ' +\n '[--col-max-width=F] [--col-split=F] [--line-y-tol=F] [--line-height-ratio=F]';\n\nconst FORMATS = ['md', 'txt', 'raw'] as const;\ntype Format = (typeof FORMATS)[number];\n\n// A bad tuning-flag value (non-numeric, or <= 0 unless the flag allows zero) is a usage error, not a silent no-op.\nconst TUNING_FLAGS: {\n name: string;\n key: keyof Tuning;\n allowZero?: boolean;\n isInt?: boolean;\n}[] = [\n {\n name: 'float-max-words',\n key: 'floatMaxWords',\n allowZero: true,\n isInt: true,\n },\n { name: 'float-max-width', key: 'floatMaxWidth' },\n { name: 'float-margin', key: 'floatMargin' },\n { name: 'para-gap', key: 'paraGap' },\n { name: 'heading-scale', key: 'headingScale' },\n { name: 'col-max-width', key: 'colMaxWidth' },\n { name: 'col-split', key: 'colSplit' },\n { name: 'line-y-tol', key: 'lineYTol' },\n { name: 'line-height-ratio', key: 'lineHeightRatio' },\n];\n\nconst extract: Command = async (ctx) => {\n // --debug-words takes a required FILE value; a bare --debug-words is a\n // usage error, checked before parseArgs so it can't silently swallow the next token as its value.\n if (ctx.rest.includes('--debug-words')) {\n ctx.usageError(`${USAGE}\\n--debug-words requires a value: --debug-words=FILE`);\n }\n\n const parsed = (() => {\n try {\n return parseArgs({\n args: ctx.rest,\n options: {\n json: { type: 'boolean', default: false },\n 'page-markers': { type: 'boolean', default: false },\n ocr: { type: 'boolean', default: false },\n 'no-ocr': { type: 'boolean', default: false },\n stdout: { type: 'boolean', default: false },\n 'debug-words': { type: 'string' },\n help: { type: 'boolean', default: false, short: 'h' },\n pages: { type: 'string' },\n dpi: { type: 'string' },\n format: { type: 'string', default: 'md' },\n 'words-json': { type: 'string' },\n ...Object.fromEntries(TUNING_FLAGS.map((f) => [f.name, { type: 'string' as const }])),\n },\n allowPositionals: true,\n });\n } catch (err) {\n // usageError exits; the throw is dead code that tells the compiler so.\n throw ctx.usageError(`${(err as Error).message}\\n${USAGE}`);\n }\n })();\n const values = parsed.values as Record<string, string | boolean | undefined>;\n const positionals = parsed.positionals;\n\n if (values.help) {\n console.log(USAGE);\n return;\n }\n\n const [src, outArg] = positionals;\n const wordsPath = values['words-json'] as string | undefined;\n if (!src && !wordsPath) ctx.usageError(USAGE);\n\n const formatRaw = values.format as string;\n if (!(FORMATS as readonly string[]).includes(formatRaw)) {\n ctx.usageError(`${USAGE}\\n--format must be one of ${FORMATS.join('|')} (got ${JSON.stringify(formatRaw)})`);\n }\n const format = formatRaw as Format;\n\n // --pages: a malformed spec is a usage error; out-of-range page NUMBERS\n // clamp instead (collect.ts / the engine apply the same clamping policy).\n let pages: { first: number; last: number } | undefined;\n if (values.pages !== undefined) {\n const m = /^(\\d+)(?:-(\\d+))?$/.exec(values.pages as string);\n const first = m ? Number(m[1]) : Number.NaN;\n const last = m ? (m[2] !== undefined ? Number(m[2]) : first) : Number.NaN;\n if (!m || first < 1 || last < first) {\n ctx.usageError(`${USAGE}\\n--pages requires N or N-M, N >= 1, M >= N (got ${JSON.stringify(values.pages)})`);\n }\n pages = { first, last };\n }\n\n const tuning: Partial<Tuning> = {};\n for (const spec of TUNING_FLAGS) {\n const raw = values[spec.name] as string | undefined;\n if (raw === undefined) continue;\n const value = Number(raw);\n const ok = raw !== '' && Number.isFinite(value) && (spec.allowZero ? value >= 0 : value > 0);\n if (!ok) {\n ctx.usageError(`${USAGE}\\n--${spec.name} requires a ${spec.allowZero ? 'non-negative' : 'positive'} number (got ${JSON.stringify(raw)})`);\n }\n (tuning[spec.key] as number) = spec.isInt ? Math.trunc(value) : value;\n }\n\n // --dpi: page-render resolution, validated like the tuning flags. Default\n // 288 is the measured operating point; >~400 measured WORSE on ordinary pages — not a \"bigger is safer\" knob.\n let dpi: number | undefined;\n if (values.dpi !== undefined) {\n const raw = values.dpi as string;\n const value = Number(raw);\n if (raw === '' || !Number.isFinite(value) || value <= 0) {\n ctx.usageError(`${USAGE}\\n--dpi requires a positive number (got ${JSON.stringify(raw)})`);\n }\n dpi = value;\n }\n\n // In --words-json mode there may be no PDF positional; the words file\n // stands in for naming, extension stripped so the default dest can never overwrite the input. Default extension follows --format.\n const source = src ?? (wordsPath as string);\n const defaultExt = format === 'raw' ? 'json' : format === 'txt' ? 'txt' : 'md';\n const dest = outArg || `${source.replace(/\\.(pdf|jsonl)$/i, '')}.${defaultExt}`;\n\n const onWarning = (m: string) => console.error(m);\n const showProgress = process.stderr.isTTY;\n // onProgress carries per-page timing/count only; human-readable\n // diagnostics (e.g. the sparse-retry notice) arrive via onWarning instead, so they print regardless of TTY-ness.\n const onProgress = (e: { type: 'page'; page: number; words: number; ms: number }) => {\n if (showProgress) console.error(`p${e.page}: ${e.words} words, ${e.ms}ms`);\n };\n const debugWordsPath = values['debug-words'] as string | undefined;\n if (debugWordsPath !== undefined && debugWordsPath.trim() === '') {\n ctx.usageError(`${USAGE}\\n--debug-words requires a value: --debug-words=FILE`);\n }\n // The severity-1 audit instrument: every recognized word as clean JSON\n // lines to its own file. stderr stays a human channel (mixed prose), never a dump target — this file is guaranteed byte-for-byte parseable.\n const onWords = debugWordsPath\n ? (words: OcrWordInput[]) => {\n const lines = words.map((w) => {\n const entry: OcrWordInput = { page: w.page, text: w.text, x: w.x, y: w.y, w: w.w, h: w.h };\n if (w.confidence !== undefined) entry.confidence = w.confidence;\n return JSON.stringify(entry);\n });\n writeFileSync(debugWordsPath, lines.length ? `${lines.join('\\n')}\\n` : '');\n }\n : undefined;\n\n const common = { pages, onWarning };\n const ocrCommon = {\n ...common,\n tuning,\n dpi,\n onProgress,\n onWords,\n };\n\n let words: OcrWordInput[] | undefined;\n let skipped = 0;\n if (wordsPath !== undefined) {\n ({ words, skipped } = parseWordLines(readFileSync(wordsPath, 'utf8')));\n if (skipped > 0) console.error(`--words-json: skipped ${skipped} non-JSON line(s)`);\n }\n\n let content: string;\n let report: Report;\n if (format === 'md') {\n // Unchanged path: extractOcr/pdfToMarkdown directly, exactly as before\n // --format existed.\n const { extractOcr, pdfToMarkdown } = await import('../extract.ts');\n let markdown: string;\n if (words !== undefined) {\n ({ markdown, report } = await extractOcr({ words }, ocrCommon));\n } else {\n ({ markdown, report } = await pdfToMarkdown(src, {\n ...ocrCommon,\n ocr: values.ocr as boolean,\n noOcr: values['no-ocr'] as boolean,\n pageMarkers: values['page-markers'] as boolean,\n }));\n }\n content = markdown;\n } else {\n // raw/txt: both render from an Analysis — raw IS the Analysis as JSON;\n // txt is toText(analysis). Mirrors pdfToMarkdown's own auto-OCR fallback decision so a different --format doesn't silently pick a different path.\n const { analyze } = await import('../analyze.ts');\n const { toText } = await import('../render-analysis.ts');\n const { needsOcrFallback, ocrFallbackNotice } = await import('../extract.ts');\n let analysis: Analysis;\n if (words !== undefined) {\n analysis = await analyze({ words }, { ...ocrCommon, path: 'ocr' });\n } else if (values.ocr) {\n analysis = await analyze(src, { ...ocrCommon, path: 'ocr' });\n } else {\n const text = await analyze(src, { ...common, path: 'text', pageMarkers: values['page-markers'] as boolean });\n if (needsOcrFallback(text.report.charsPerPage) && !values['no-ocr']) {\n onWarning(ocrFallbackNotice(text.report.charsPerPage));\n analysis = await analyze(src, { ...ocrCommon, path: 'ocr', fallback: true });\n } else {\n analysis = text;\n }\n }\n report = analysis.report;\n content = format === 'raw' ? JSON.stringify(analysis, null, 1) : toText(analysis);\n }\n\n if (values.stdout) process.stdout.write(content);\n else writeFileSync(dest, content);\n\n // The library's Report stays clean of source/out; --json consumers keep\n // report.json files around and need to know which input produced each one, so the CLI (only) decorates the printed JSON with source/out here.\n if (values.json) console.log(JSON.stringify({ source, out: dest, ...report }, null, 1));\n else if (report.path === 'ocr') {\n console.error(`${path.basename(dest).padEnd(32)} OCR path heads=${report.headings}(junk ${report.junkHeadings}) ` + `paras=${report.paragraphs} callouts=${report.callouts} floats=${report.floats ?? 0} dangling=${report.danglingLong} (long) ` + `~${report.charsPerPage} chars/page`);\n } else {\n console.error(\n `${path.basename(dest).padEnd(32)} body=${report.bodyFontHeight}pt heads=${report.headings}(junk ${report.junkHeadings}) ` +\n `lists=${report.listItems} paras=${report.paragraphs} callouts=${report.callouts} pairs=${report.joinedPairs} ` +\n `~${report.charsPerPage} chars/page` +\n (report.sparse ? ' ⚠️ implausibly sparse — pages are likely images; re-run with --ocr' : '')\n );\n }\n};\n\n// Parse one word-dump JSON line per word — key order is not guaranteed, parse\n// never grep. Non-JSON lines are skipped with a count, not fatal (the auditor applies the same policy).\nfunction parseWordLines(raw: string): { words: OcrWordInput[]; skipped: number } {\n const words: OcrWordInput[] = [];\n let skipped = 0;\n for (const line of raw.split('\\n')) {\n if (!line.trim()) continue;\n try {\n words.push(JSON.parse(line));\n } catch {\n skipped++;\n }\n }\n return { words, skipped };\n}\n\nexport default extract;\n"],"names":["readFileSync","writeFileSync","path","parseArgs","USAGE","FORMATS","TUNING_FLAGS","name","key","allowZero","isInt","extract","ctx","rest","includes","usageError","parsed","args","options","json","type","default","ocr","stdout","help","short","pages","dpi","format","Object","fromEntries","map","f","allowPositionals","err","message","values","positionals","console","log","src","outArg","wordsPath","formatRaw","join","JSON","stringify","undefined","m","exec","first","Number","NaN","last","tuning","spec","raw","value","ok","isFinite","Math","trunc","source","defaultExt","dest","replace","onWarning","error","showProgress","process","stderr","isTTY","onProgress","e","page","words","ms","debugWordsPath","trim","onWords","lines","w","entry","text","x","y","h","confidence","length","common","ocrCommon","skipped","parseWordLines","content","report","extractOcr","pdfToMarkdown","markdown","noOcr","pageMarkers","analyze","toText","needsOcrFallback","ocrFallbackNotice","analysis","charsPerPage","fallback","write","out","basename","padEnd","headings","junkHeadings","paragraphs","callouts","floats","danglingLong","bodyFontHeight","listItems","joinedPairs","sparse","line","split","push","parse"],"mappings":"AAAA,2EAA2E;AAC3E,qHAAqH;AACrH,SAASA,YAAY,EAAEC,aAAa,QAAQ,UAAU;AACtD,OAAOC,UAAU,YAAY;AAC7B,SAASC,SAAS,QAAQ,YAAY;AAMtC,MAAMC,QACJ,iGACA,yEACA,8GACA,8FACA,oDACA,uGACA;AAEF,MAAMC,UAAU;IAAC;IAAM;IAAO;CAAM;AAGpC,mHAAmH;AACnH,MAAMC,eAKA;IACJ;QACEC,MAAM;QACNC,KAAK;QACLC,WAAW;QACXC,OAAO;IACT;IACA;QAAEH,MAAM;QAAmBC,KAAK;IAAgB;IAChD;QAAED,MAAM;QAAgBC,KAAK;IAAc;IAC3C;QAAED,MAAM;QAAYC,KAAK;IAAU;IACnC;QAAED,MAAM;QAAiBC,KAAK;IAAe;IAC7C;QAAED,MAAM;QAAiBC,KAAK;IAAc;IAC5C;QAAED,MAAM;QAAaC,KAAK;IAAW;IACrC;QAAED,MAAM;QAAcC,KAAK;IAAW;IACtC;QAAED,MAAM;QAAqBC,KAAK;IAAkB;CACrD;AAED,MAAMG,UAAmB,OAAOC;IAC9B,uEAAuE;IACvE,kGAAkG;IAClG,IAAIA,IAAIC,IAAI,CAACC,QAAQ,CAAC,kBAAkB;QACtCF,IAAIG,UAAU,CAAC,GAAGX,MAAM,oDAA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5B,eAAepC,GAAW;IACjC,MAAMmB,QAAwB,EAAE;IAChC,IAAIgB,UAAU;IACd,KAAK,MAAM8B,QAAQjE,IAAIkE,KAAK,CAAC,MAAO;QAClC,IAAI,CAACD,KAAK3C,IAAI,IAAI;QAClB,IAAI;YACFH,MAAMgD,IAAI,CAAC9E,KAAK+E,KAAK,CAACH;QACxB,EAAE,OAAM;YACN9B;QACF;IACF;IACA,OAAO;QAAEhB;QAAOgB;IAAQ;AAC1B;AAEA,eAAehF,QAAQ"}
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Projects/pdf-to-md/src/cli/index.ts"],"sourcesContent":["import type { Command } from './types.ts';\n\n// Lazy registry: a command's imports load only when it runs. These names are\n// reserved — a PDF literally named `extract`/`render` (no extension) needs a ./ prefix.\nexport const COMMANDS: Record<string, () => Promise<{ default: Command }>> = {\n extract: () => import('./extract.ts'),\n render: () => import('./render.ts'),\n audit: () => import('./audit.ts'),\n};\n\nexport type { Command, Ctx } from './types.ts';\n"],"names":["COMMANDS","extract","render","audit"],"mappings":"AAEA,6EAA6E;AAC7E,wFAAwF;AACxF,OAAO,MAAMA,WAAgE;IAC3EC,SAAS,IAAM,MAAM,CAAC;IACtBC,QAAQ,IAAM,MAAM,CAAC;IACrBC,OAAO,IAAM,MAAM,CAAC;AACtB,EAAE"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/formats/pdf-to-md/src/cli/index.ts"],"sourcesContent":["import type { Command } from './types.ts';\n\n// Lazy registry: a command's imports load only when it runs. These names are\n// reserved — a PDF literally named `extract`/`render` (no extension) needs a ./ prefix.\nexport const COMMANDS: Record<string, () => Promise<{ default: Command }>> = {\n extract: () => import('./extract.ts'),\n render: () => import('./render.ts'),\n audit: () => import('./audit.ts'),\n};\n\nexport type { Command, Ctx } from './types.ts';\n"],"names":["COMMANDS","extract","render","audit"],"mappings":"AAEA,6EAA6E;AAC7E,wFAAwF;AACxF,OAAO,MAAMA,WAAgE;IAC3EC,SAAS,IAAM,MAAM,CAAC;IACtBC,QAAQ,IAAM,MAAM,CAAC;IACrBC,OAAO,IAAM,MAAM,CAAC;AACtB,EAAE"}
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Projects/pdf-to-md/src/cli/render.ts"],"sourcesContent":["// render command — render PDF pages to PNG for human/vision-model\n// verification (extraction output is a claim; the page itself is the truth). Thin wrapper: parse flags, call src/raster.ts, write files.\nimport { mkdirSync, writeFileSync } from 'node:fs';\nimport path from 'node:path';\nimport { parseArgs } from 'node:util';\nimport { PdfToMdError } from '../errors.ts';\nimport type { Command } from './types.ts';\n\nconst USAGE = 'usage: pdf-to-md render <file.pdf> <page>[-<page>] [--dpi|-d N (default 288)] [--out|-o DIR (default .)]';\n\nconst render: Command = async (ctx) => {\n const parsed = (() => {\n try {\n return parseArgs({\n args: ctx.rest,\n options: {\n dpi: { type: 'string', default: '288', short: 'd' },\n out: { type: 'string', short: 'o' },\n help: { type: 'boolean', default: false, short: 'h' },\n },\n allowPositionals: true,\n });\n } catch (err) {\n // usageError exits; the throw is dead code that tells the compiler so.\n throw ctx.usageError(`${(err as Error).message}\\n${USAGE}`);\n }\n })();\n const { values, positionals } = parsed;\n\n if (values.help) {\n console.log(USAGE);\n return;\n }\n\n const [pdfPath, spec] = positionals;\n if (!pdfPath || !spec) ctx.usageError(USAGE);\n\n const m = /^(\\d+)(?:-(\\d+))?$/.exec(spec);\n if (m === null) throw ctx.usageError(`${USAGE}\\ncould not parse page spec: ${spec}`);\n const firstPage = Number(m[1]);\n const lastPage = m[2] !== undefined ? Number(m[2]) : firstPage;\n if (!(firstPage >= 1) || !(lastPage >= firstPage)) throw ctx.usageError(`${USAGE}\\ninvalid page spec: ${spec}`);\n\n const dpi = Number.parseFloat(values.dpi as string);\n if (!(dpi > 0)) ctx.usageError(`${USAGE}\\n--dpi must be positive`);\n\n const outDir = values.out ?? process.cwd();\n mkdirSync(outDir, { recursive: true });\n const stem = path.basename(pdfPath, path.extname(pdfPath)).replaceAll(' ', '-');\n\n // Imported here, not at module top: keeps pdfjs/canvas out of every other command's startup.\n const { awaitPdfOpen, openPdfForRender } = await import('../pdf-open.ts');\n const { renderLoadedPage } = await import('../raster.ts');\n const loadingTask = openPdfForRender(pdfPath);\n try {\n const doc = await awaitPdfOpen(loadingTask, pdfPath);\n\n // Whole-range check before any file is written, so a partly-valid range\n // fails atomically; renderLoadedPage re-validates per page.\n if (lastPage > doc.numPages) {\n throw new PdfToMdError('PAGE_RANGE', `page range ${firstPage}-${lastPage} is outside this document (1-${doc.numPages})`);\n }\n for (let n = firstPage; n <= lastPage; n++) {\n const { png } = await renderLoadedPage(doc, n, dpi);\n const outPath = path.join(outDir, `${stem}-p${n}.png`);\n writeFileSync(outPath, png);\n console.log(outPath);\n }\n } finally {\n await loadingTask.destroy();\n }\n};\n\nexport default render;\n"],"names":["mkdirSync","writeFileSync","path","parseArgs","PdfToMdError","USAGE","render","ctx","values","parsed","args","rest","options","dpi","type","default","short","out","help","allowPositionals","err","usageError","message","positionals","console","log","pdfPath","spec","m","exec","firstPage","Number","lastPage","undefined","parseFloat","outDir","process","cwd","recursive","stem","basename","extname","replaceAll","awaitPdfOpen","openPdfForRender","renderLoadedPage","loadingTask","doc","numPages","n","png","outPath","join","destroy"],"mappings":"AAAA,kEAAkE;AAClE,yIAAyI;AACzI,SAASA,SAAS,EAAEC,aAAa,QAAQ,UAAU;AACnD,OAAOC,UAAU,YAAY;AAC7B,SAASC,SAAS,QAAQ,YAAY;AACtC,SAASC,YAAY,QAAQ,eAAe;AAG5C,MAAMC,QAAQ;AAEd,MAAMC,SAAkB,OAAOC;QAoCdC;IAnCf,MAAMC,SAAS,AAAC,CAAA;QACd,IAAI;YACF,OAAON,UAAU;gBACfO,MAAMH,IAAII,IAAI;gBACdC,SAAS;oBACPC,KAAK;wBAAEC,MAAM;wBAAUC,SAAS;wBAAOC,OAAO;oBAAI;oBAClDC,KAAK;wBAAEH,MAAM;wBAAUE,OAAO;oBAAI;oBAClCE,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IAE3E,6FAA6F;IAC7F,MAAM,EAAEC,YAAY,EAAEC,gBAAgB,EAAE,GAAG,MAAM,MAAM,CAAC;IACxD,MAAM,EAAEC,gBAAgB,EAAE,GAAG,MAAM,MAAM,CAAC;IAC1C,MAAMC,cAAcF,iBAAiBlB;IACrC,IAAI;QACF,MAAMqB,MAAM,MAAMJ,aAAaG,aAAapB;QAE5C,wEAAwE;QACxE,4DAA4D;QAC5D,IAAIM,WAAWe,IAAIC,QAAQ,EAAE;YAC3B,MAAM,IAAI5C,aAAa,cAAc,CAAC,WAAW,EAAE0B,UAAU,CAAC,EAAEE,SAAS,6BAA6B,EAAEe,IAAIC,QAAQ,CAAC,CAAC,CAAC;QACzH;QACA,IAAK,IAAIC,IAAInB,WAAWmB,KAAKjB,UAAUiB,IAAK;YAC1C,MAAM,EAAEC,GAAG,EAAE,GAAG,MAAML,iBAAiBE,KAAKE,GAAGpC;YAC/C,MAAMsC,UAAUjD,KAAKkD,IAAI,CAACjB,QAAQ,GAAGI,KAAK,EAAE,EAAEU,EAAE,IAAI,CAAC;YACrDhD,cAAckD,SAASD;YACvB1B,QAAQC,GAAG,CAAC0B;QACd;IACF,SAAU;QACR,MAAML,YAAYO,OAAO;IAC3B;AACF;AAEA,eAAe/C,OAAO"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/formats/pdf-to-md/src/cli/render.ts"],"sourcesContent":["// render command — render PDF pages to PNG for human/vision-model\n// verification (extraction output is a claim; the page itself is the truth). Thin wrapper: parse flags, call src/raster.ts, write files.\nimport { mkdirSync, writeFileSync } from 'node:fs';\nimport path from 'node:path';\nimport { parseArgs } from 'node:util';\nimport { PdfToMdError } from '../errors.ts';\nimport type { Command } from './types.ts';\n\nconst USAGE = 'usage: pdf-to-md render <file.pdf> <page>[-<page>] [--dpi|-d N (default 288)] [--out|-o DIR (default .)]';\n\nconst render: Command = async (ctx) => {\n const parsed = (() => {\n try {\n return parseArgs({\n args: ctx.rest,\n options: {\n dpi: { type: 'string', default: '288', short: 'd' },\n out: { type: 'string', short: 'o' },\n help: { type: 'boolean', default: false, short: 'h' },\n },\n allowPositionals: true,\n });\n } catch (err) {\n // usageError exits; the throw is dead code that tells the compiler so.\n throw ctx.usageError(`${(err as Error).message}\\n${USAGE}`);\n }\n })();\n const { values, positionals } = parsed;\n\n if (values.help) {\n console.log(USAGE);\n return;\n }\n\n const [pdfPath, spec] = positionals;\n if (!pdfPath || !spec) ctx.usageError(USAGE);\n\n const m = /^(\\d+)(?:-(\\d+))?$/.exec(spec);\n if (m === null) throw ctx.usageError(`${USAGE}\\ncould not parse page spec: ${spec}`);\n const firstPage = Number(m[1]);\n const lastPage = m[2] !== undefined ? Number(m[2]) : firstPage;\n if (!(firstPage >= 1) || !(lastPage >= firstPage)) throw ctx.usageError(`${USAGE}\\ninvalid page spec: ${spec}`);\n\n const dpi = Number.parseFloat(values.dpi as string);\n if (!(dpi > 0)) ctx.usageError(`${USAGE}\\n--dpi must be positive`);\n\n const outDir = values.out ?? process.cwd();\n mkdirSync(outDir, { recursive: true });\n const stem = path.basename(pdfPath, path.extname(pdfPath)).replaceAll(' ', '-');\n\n // Imported here, not at module top: keeps pdfjs/canvas out of every other command's startup.\n const { awaitPdfOpen, openPdfForRender } = await import('../pdf-open.ts');\n const { renderLoadedPage } = await import('../raster.ts');\n const loadingTask = openPdfForRender(pdfPath);\n try {\n const doc = await awaitPdfOpen(loadingTask, pdfPath);\n\n // Whole-range check before any file is written, so a partly-valid range\n // fails atomically; renderLoadedPage re-validates per page.\n if (lastPage > doc.numPages) {\n throw new PdfToMdError('PAGE_RANGE', `page range ${firstPage}-${lastPage} is outside this document (1-${doc.numPages})`);\n }\n for (let n = firstPage; n <= lastPage; n++) {\n const { png } = await renderLoadedPage(doc, n, dpi);\n const outPath = path.join(outDir, `${stem}-p${n}.png`);\n writeFileSync(outPath, png);\n console.log(outPath);\n }\n } finally {\n await loadingTask.destroy();\n }\n};\n\nexport default render;\n"],"names":["mkdirSync","writeFileSync","path","parseArgs","PdfToMdError","USAGE","render","ctx","values","parsed","args","rest","options","dpi","type","default","short","out","help","allowPositionals","err","usageError","message","positionals","console","log","pdfPath","spec","m","exec","firstPage","Number","lastPage","undefined","parseFloat","outDir","process","cwd","recursive","stem","basename","extname","replaceAll","awaitPdfOpen","openPdfForRender","renderLoadedPage","loadingTask","doc","numPages","n","png","outPath","join","destroy"],"mappings":"AAAA,kEAAkE;AAClE,yIAAyI;AACzI,SAASA,SAAS,EAAEC,aAAa,QAAQ,UAAU;AACnD,OAAOC,UAAU,YAAY;AAC7B,SAASC,SAAS,QAAQ,YAAY;AACtC,SAASC,YAAY,QAAQ,eAAe;AAG5C,MAAMC,QAAQ;AAEd,MAAMC,SAAkB,OAAOC;QAoCdC;IAnCf,MAAMC,SAAS,AAAC,CAAA;QACd,IAAI;YACF,OAAON,UAAU;gBACfO,MAAMH,IAAII,IAAI;gBACdC,SAAS;oBACPC,KAAK;wBAAEC,MAAM;wBAAUC,SAAS;wBAAOC,OAAO;oBAAI;oBAClDC,KAAK;wBAAEH,MAAM;wBAAUE,OAAO;oBAAI;oBAClCE,MAAM;wBAAEJ,MAAM;wBAAWC,SAAS;wBAAOC,OAAO;oBAAI;gBACtD;gBACAG,kBAAkB;YACpB;QACF,EAAE,OAAOC,KAAK;YACZ,uEAAuE;YACvE,MAAMb,IAAIc,UAAU,CAAC,GAAG,AAACD,IAAcE,OAAO,CAAC,EAAE,EAAEjB,OAAO;QAC5D;IACF,CAAA;IACA,MAAM,EAAEG,MAAM,EAAEe,WAAW,EAAE,GAAGd;IAEhC,IAAID,OAAOU,IAAI,EAAE;QACfM,QAAQC,GAAG,CAACpB;QACZ;IACF;IAEA,MAAM,CAACqB,SAASC,KAAK,GAAGJ;IACxB,IAAI,CAACG,WAAW,CAACC,MAAMpB,IAAIc,UAAU,CAAChB;IAEtC,MAAMuB,IAAI,qBAAqBC,IAAI,CAACF;IACpC,IAAIC,MAAM,MAAM,MAAMrB,IAAIc,UAAU,CAAC,G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iBE,KAAKE,GAAGpC;YAC/C,MAAMsC,UAAUjD,KAAKkD,IAAI,CAACjB,QAAQ,GAAGI,KAAK,EAAE,EAAEU,EAAE,IAAI,CAAC;YACrDhD,cAAckD,SAASD;YACvB1B,QAAQC,GAAG,CAAC0B;QACd;IACF,SAAU;QACR,MAAML,YAAYO,OAAO;IAC3B;AACF;AAEA,eAAe/C,OAAO"}
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Projects/pdf-to-md/src/cli/types.ts"],"sourcesContent":["// Handed to every command; the command word is peeled off in src/cli.ts and\n// each command owns its own parseArgs table over `rest` (our commands' flags are disjoint, so a shared table would let `render --para-gap=2` parse silently as a no-op).\nexport interface Ctx {\n /** binary name, for usage strings */\n name: string;\n /** argv after the command word */\n rest: string[];\n /** print the message and exit 2 — every malformed-invocation path.\n * Readonly property (not method) syntax: TS only applies never-return control-flow analysis to readonly property-typed function members. */\n readonly usageError: (message: string) => never;\n}\n\nexport type Command = (ctx: Ctx) => Promise<void> | void;\n"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,yKAAyK;AAWzK,WAAyD"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/formats/pdf-to-md/src/cli/types.ts"],"sourcesContent":["// Handed to every command; the command word is peeled off in src/cli.ts and\n// each command owns its own parseArgs table over `rest` (our commands' flags are disjoint, so a shared table would let `render --para-gap=2` parse silently as a no-op).\nexport interface Ctx {\n /** binary name, for usage strings */\n name: string;\n /** argv after the command word */\n rest: string[];\n /** print the message and exit 2 — every malformed-invocation path.\n * Readonly property (not method) syntax: TS only applies never-return control-flow analysis to readonly property-typed function members. */\n readonly usageError: (message: string) => never;\n}\n\nexport type Command = (ctx: Ctx) => Promise<void> | void;\n"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,yKAAyK;AAWzK,WAAyD"}