@effortlessmotion/pdf-to-md 0.1.8 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -5
- package/dist/cjs/analyze.d.cts +3 -1
- package/dist/cjs/analyze.d.ts +3 -1
- package/dist/cjs/analyze.js +38 -100
- package/dist/cjs/analyze.js.map +1 -1
- package/dist/cjs/audit.d.cts +6 -5
- package/dist/cjs/audit.d.ts +6 -5
- package/dist/cjs/audit.js +368 -60
- package/dist/cjs/audit.js.map +1 -1
- package/dist/cjs/cli/audit.js.map +1 -1
- package/dist/cjs/cli/extract.js +13 -48
- package/dist/cjs/cli/extract.js.map +1 -1
- package/dist/cjs/cli/index.js.map +1 -1
- package/dist/cjs/cli/render.js.map +1 -1
- package/dist/cjs/cli/types.js.map +1 -1
- package/dist/cjs/cli.js.map +1 -1
- package/dist/cjs/collect.js +91 -35
- package/dist/cjs/collect.js.map +1 -1
- package/dist/cjs/dict.js.map +1 -1
- package/dist/cjs/emit.js.map +1 -1
- package/dist/cjs/engines/tesseract.js.map +1 -1
- package/dist/cjs/errors.d.cts +2 -0
- package/dist/cjs/errors.d.ts +2 -0
- package/dist/cjs/errors.js.map +1 -1
- package/dist/cjs/extract.d.cts +20 -9
- package/dist/cjs/extract.d.ts +20 -9
- package/dist/cjs/extract.js +333 -106
- package/dist/cjs/extract.js.map +1 -1
- package/dist/cjs/geometry.js.map +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/lines.js +21 -10
- package/dist/cjs/lines.js.map +1 -1
- package/dist/cjs/markdown.js +140 -54
- package/dist/cjs/markdown.js.map +1 -1
- package/dist/cjs/page-marker.d.cts +1 -1
- package/dist/cjs/page-marker.d.ts +1 -1
- package/dist/cjs/page-marker.js +39 -8
- package/dist/cjs/page-marker.js.map +1 -1
- package/dist/cjs/pdf-open.js.map +1 -1
- package/dist/cjs/raster.js.map +1 -1
- package/dist/cjs/render-analysis.d.cts +4 -2
- package/dist/cjs/render-analysis.d.ts +4 -2
- package/dist/cjs/render-analysis.js +5 -3
- package/dist/cjs/render-analysis.js.map +1 -1
- package/dist/cjs/report.d.cts +2 -2
- package/dist/cjs/report.d.ts +2 -2
- package/dist/cjs/report.js +27 -8
- package/dist/cjs/report.js.map +1 -1
- package/dist/cjs/resolve.js.map +1 -1
- package/dist/cjs/text-analysis.d.cts +12 -0
- package/dist/cjs/text-analysis.d.ts +12 -0
- package/dist/cjs/text-analysis.js +175 -0
- package/dist/cjs/text-analysis.js.map +1 -0
- package/dist/cjs/types.d.cts +40 -3
- package/dist/cjs/types.d.ts +40 -3
- package/dist/cjs/types.js +2 -3
- package/dist/cjs/types.js.map +1 -1
- package/dist/cjs/validate.js.map +1 -1
- package/dist/esm/analyze.d.ts +3 -1
- package/dist/esm/analyze.js +18 -89
- package/dist/esm/analyze.js.map +1 -1
- package/dist/esm/audit.d.ts +6 -5
- package/dist/esm/audit.js +236 -29
- package/dist/esm/audit.js.map +1 -1
- package/dist/esm/cli/audit.js.map +1 -1
- package/dist/esm/cli/extract.js +10 -23
- package/dist/esm/cli/extract.js.map +1 -1
- package/dist/esm/cli/index.js.map +1 -1
- package/dist/esm/cli/render.js.map +1 -1
- package/dist/esm/cli/types.js.map +1 -1
- package/dist/esm/cli.js.map +1 -1
- package/dist/esm/collect.js +64 -15
- package/dist/esm/collect.js.map +1 -1
- package/dist/esm/dict.js.map +1 -1
- package/dist/esm/emit.js.map +1 -1
- package/dist/esm/engines/tesseract.js.map +1 -1
- package/dist/esm/errors.d.ts +2 -0
- package/dist/esm/errors.js.map +1 -1
- package/dist/esm/extract.d.ts +20 -9
- package/dist/esm/extract.js +167 -76
- package/dist/esm/extract.js.map +1 -1
- package/dist/esm/geometry.js.map +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lines.js +14 -10
- package/dist/esm/lines.js.map +1 -1
- package/dist/esm/markdown.js +110 -27
- package/dist/esm/markdown.js.map +1 -1
- package/dist/esm/page-marker.d.ts +1 -1
- package/dist/esm/page-marker.js +15 -9
- package/dist/esm/page-marker.js.map +1 -1
- package/dist/esm/pdf-open.js.map +1 -1
- package/dist/esm/raster.js.map +1 -1
- package/dist/esm/render-analysis.d.ts +4 -2
- package/dist/esm/render-analysis.js +9 -5
- package/dist/esm/render-analysis.js.map +1 -1
- package/dist/esm/report.d.ts +2 -2
- package/dist/esm/report.js +12 -7
- package/dist/esm/report.js.map +1 -1
- package/dist/esm/resolve.js.map +1 -1
- package/dist/esm/text-analysis.d.ts +12 -0
- package/dist/esm/text-analysis.js +81 -0
- package/dist/esm/text-analysis.js.map +1 -0
- package/dist/esm/types.d.ts +40 -3
- package/dist/esm/types.js +4 -4
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/validate.js.map +1 -1
- package/package.json +1 -1
- package/skills/pdf-to-md/SKILL.md +39 -66
package/dist/cjs/audit.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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":["auditWords","norm","s","normalize","replace","toLowerCase","counter","items","m","Map","item","set","get","wordsPath","mdPath","rec","parsed","skipped","wordsRaw","readFileSync","rawLines","split","length","pop","line","trim","startsWith","o","JSON","parse","t","text","arr","page","push","md","out","bodyByPage","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;;;;;+B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,EAAEE,OAAO,CAAC,OAAO,QAAQA,OAAO,CAAC,MAAM,QAAO;OAAIiD,IAAI,CAAC,OAAM;AAC/F"}
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/open-source/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. Matching consumes evidence so\n// a single output occurrence cannot satisfy repeated source occurrences.\n//\n// NOTE: no producer guarantees JSON key order in a --debug-words dump —\n// parse, never grep.\nimport { readFileSync } from 'node:fs';\nimport { PdfToMdError } from './errors.ts';\nimport { foldTypographic } from './lines.ts';\nimport { bodyByPage } from './page-marker.ts';\n\nconst WORD_RE = /[\\p{L}\\p{N}][\\p{L}\\p{N}\\p{M}]*/gu;\nconst HYPHEN_RE = /[\\p{Pd}\\u2212]\\s*$/u;\nconst LINE_HYPHEN_RE = /^[\\p{Pd}\\u2212][ \\t]*\\r?\\n[ \\t]*$/u;\nconst INLINE_HYPHEN_RE = /^[\\p{Pd}\\u2212][ \\t]*$/u;\n\ninterface Token {\n text: string;\n start: number;\n end: number;\n gapAfter: string;\n}\n\ninterface SourceRun {\n page: number;\n tokens: number[];\n terminalHyphen: boolean;\n hyphenOnly: boolean;\n leadingWhitespace: boolean;\n trailingWhitespace: boolean;\n box?: Box;\n}\n\ninterface PageEvidence {\n tokens: string[];\n sourcePairs: SourcePair[];\n}\n\ninterface SourcePair {\n first: number;\n second: number;\n explicitHyphen: boolean;\n}\n\ninterface Box {\n x: number;\n y: number;\n w: number;\n h: number;\n}\n\ninterface AuditRecord {\n page: number;\n text: string;\n x?: number;\n y?: number;\n w?: number;\n h?: number;\n}\n\nfunction tokens(text: string): Token[] {\n const folded = foldTypographic(text);\n WORD_RE.lastIndex = 0;\n const matches = [...folded.matchAll(WORD_RE)];\n return matches.map((match, index) => {\n const start = match.index as number;\n const end = start + match[0].length;\n const next = matches[index + 1];\n return {\n text: match[0].normalize('NFC').toLowerCase(),\n start,\n end,\n gapAfter: folded.slice(end, next?.index ?? folded.length),\n };\n });\n}\n\nfunction markdownText(md: string): string {\n return md\n .replace(/<!--[\\s\\S]*?-->/gu, ' ')\n .replace(/!\\[[^\\]]*\\]\\([^)]*\\)/gu, ' ')\n .replace(/!\\[[^\\]]*\\]\\[[^\\]]*\\]/gu, ' ')\n .replace(/<img\\b[^>]*>/giu, ' ')\n .replace(/<a\\b[^>]*>/giu, ' ')\n .replace(/<\\/a>/giu, ' ')\n .replace(/^\\s*\\[[^\\]]+\\]:[^\\n]*$/gmu, ' ')\n .replace(/^>\\s*\\[(?:review:[^\\]]*|floats)\\]\\s*/gmu, '')\n .replace(/\\[([^\\]]*)\\]\\([^)]*\\)/gu, '$1')\n .replace(/\\[([^\\]]*)\\]\\[[^\\]]*\\]/gu, '$1');\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; auditWords rejects\n * evidence with any such line */\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 nonzero 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 on its page. Invalid evidence or absent page provenance throws a\n * PdfToMdError with code `AUDIT_INPUT`.\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, PageEvidence>();\n let parsed = 0;\n let skipped = 0;\n const errors: string[] = [];\n const runsByPage = new Map<number, SourceRun[]>();\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 (const [lineIndex, rawLine] of rawLines.entries()) {\n const line = rawLine.trim();\n if (!line.startsWith('{')) {\n skipped++;\n errors.push(`line ${lineIndex + 1} is not valid JSON`);\n continue;\n }\n let o: unknown;\n try {\n o = JSON.parse(line);\n } catch {\n skipped++;\n errors.push(`line ${lineIndex + 1} is not valid JSON`);\n continue;\n }\n parsed++;\n if (!isAuditRecord(o)) {\n errors.push(`line ${lineIndex + 1} must contain a positive integer page and non-empty text`);\n continue;\n }\n let evidence = rec.get(o.page);\n if (!evidence) {\n evidence = { tokens: [], sourcePairs: [] };\n rec.set(o.page, evidence);\n }\n const runTokenDetails = tokens(o.text);\n const runTokens = runTokenDetails.map((token) => token.text);\n const start = evidence.tokens.length;\n evidence.tokens.push(...runTokens);\n for (let index = 0; index + 1 < runTokenDetails.length; index++) {\n if (INLINE_HYPHEN_RE.test(runTokenDetails[index].gapAfter)) {\n evidence.sourcePairs.push({ first: start + index, second: start + index + 1, explicitHyphen: true });\n }\n }\n const run = {\n page: o.page,\n tokens: runTokens.map((_, index) => start + index),\n terminalHyphen: HYPHEN_RE.test(o.text),\n hyphenOnly: /^[\\p{Pd}\\u2212]\\s*$/u.test(o.text),\n leadingWhitespace: /^\\s/u.test(o.text),\n trailingWhitespace: /\\s$/u.test(o.text),\n box: recordBox(o),\n };\n const pageRuns = runsByPage.get(o.page);\n if (pageRuns) pageRuns.push(run);\n else runsByPage.set(o.page, [run]);\n }\n\n if (parsed === 0) errors.push('word dump contains no JSON records');\n if (rec.size === 0) errors.push('word dump contains no valid records');\n if ([...rec.values()].every((evidence) => evidence.tokens.length === 0)) errors.push('word dump contains no lexical tokens');\n for (const [page, runs] of runsByPage) {\n for (let index = 0; index + 1 < runs.length; index++) {\n const current = runs[index];\n const next = runs[index + 1];\n if (current.tokens.length > 0 && current.terminalHyphen && next.tokens.length > 0) {\n const evidence = rec.get(page) as PageEvidence;\n evidence.sourcePairs.push({ first: current.tokens[current.tokens.length - 1], second: next.tokens[0], explicitHyphen: true });\n }\n if (current.tokens.length === 1 && next.tokens.length === 1 && !current.terminalHyphen && !next.hyphenOnly && !current.trailingWhitespace && !next.leadingWhitespace && touchingFragments(current.box, next.box)) {\n const evidence = rec.get(page) as PageEvidence;\n evidence.sourcePairs.push({ first: current.tokens[0], second: next.tokens[0], explicitHyphen: false });\n }\n if (current.tokens.length === 0 || !next.hyphenOnly || index + 2 >= runs.length) continue;\n const afterHyphen = runs[index + 2];\n if (afterHyphen.tokens.length === 0) continue;\n const evidence = rec.get(page) as PageEvidence;\n evidence.sourcePairs.push({ first: current.tokens[current.tokens.length - 1], second: afterHyphen.tokens[0], explicitHyphen: true });\n }\n }\n if (errors.length > 0) throw auditInputError(errors);\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 const absent = pages.filter((page) => !out.has(page));\n if (absent.length > 0) {\n const markers = absent.map((page) => `p${page}`).join(', ');\n throw auditInputError([`Markdown has no provenance marker for ${markers}; add \"### pN\" or \"<!-- pN -->\" for every dumped page`]);\n }\n\n for (const page of pages) {\n const evidence = rec.get(page) as PageEvidence;\n const output = tokens(markdownText(out.get(page) as string));\n const outputTokens = output.map((token) => token.text);\n const strictMissing = strictDeficits(evidence.tokens, outputTokens);\n strict += strictMissing;\n const missing = missingTokens(evidence, output);\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)?.tokens.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\nfunction isAuditRecord(value: unknown): value is AuditRecord {\n if (typeof value !== 'object' || value === null || Array.isArray(value)) return false;\n const record = value as Partial<AuditRecord>;\n if (!(typeof record.page === 'number' && Number.isSafeInteger(record.page) && record.page > 0 && typeof record.text === 'string' && record.text.trim().length > 0)) return false;\n const geometry = [record.x, record.y, record.w, record.h];\n return geometry.every((field) => field === undefined) || (geometry.every((field) => typeof field === 'number' && Number.isFinite(field)) && (record.w as number) >= 0 && (record.h as number) >= 0);\n}\n\nfunction recordBox(record: AuditRecord): Box | undefined {\n if (record.x === undefined || record.y === undefined || record.w === undefined || record.h === undefined) return undefined;\n return { x: record.x, y: record.y, w: record.w, h: record.h };\n}\n\nfunction touchingFragments(first: Box | undefined, second: Box | undefined): boolean {\n if (!first || !second) return false;\n const height = Math.max(first.h, second.h);\n if (height === 0) return false;\n const gap = second.x - (first.x + first.w);\n // Fragment repairs are restricted to nearly touching runs on one baseline.\n return Math.abs(first.y - second.y) <= height * 0.25 && Math.abs(gap) <= height * 0.15;\n}\n\nfunction auditInputError(errors: string[]): PdfToMdError {\n return new PdfToMdError('AUDIT_INPUT', `audit evidence is invalid: ${errors.join('; ')}`);\n}\n\nfunction strictDeficits(source: string[], output: string[]): number {\n let deficits = 0;\n const outputCounts = counter(output);\n for (const [token, count] of counter(source)) deficits += Math.max(0, count - (outputCounts.get(token) ?? 0));\n return deficits;\n}\n\nfunction missingTokens(evidence: PageEvidence, output: Token[]): string[] {\n const sourceAvailable = new Set(evidence.tokens.map((_, index) => index));\n const outputAvailable = new Set(output.map((_, index) => index));\n const linePairs = lineHyphenPairs(output);\n const inlinePairs = inlineHyphenPairs(output);\n\n // Reserve literal occurrences before attempting a repair. A repair may join\n // several source tokens into one output token, so doing it first can steal\n // an occurrence required by an unrelated literal source token.\n for (const sourceIndex of [...sourceAvailable]) {\n const direct = output.findIndex((token, index) => outputAvailable.has(index) && token.text === evidence.tokens[sourceIndex]);\n if (direct < 0) continue;\n sourceAvailable.delete(sourceIndex);\n outputAvailable.delete(direct);\n }\n\n for (const pair of evidence.sourcePairs) {\n if (!sourceAvailable.has(pair.first) || !sourceAvailable.has(pair.second)) continue;\n const joined = evidence.tokens[pair.first] + evidence.tokens[pair.second];\n if (pair.explicitHyphen) {\n const hyphenated =\n inlinePairs.find(([first, second]) => outputAvailable.has(first) && outputAvailable.has(second) && output[first].text + output[second].text === joined) ?? linePairs.find(([first, second]) => outputAvailable.has(first) && outputAvailable.has(second) && output[first].text + output[second].text === joined);\n if (hyphenated) {\n sourceAvailable.delete(pair.first);\n sourceAvailable.delete(pair.second);\n outputAvailable.delete(hyphenated[0]);\n outputAvailable.delete(hyphenated[1]);\n continue;\n }\n }\n const direct = output.findIndex((token, index) => outputAvailable.has(index) && token.text === joined);\n if (direct >= 0) {\n sourceAvailable.delete(pair.first);\n sourceAvailable.delete(pair.second);\n outputAvailable.delete(direct);\n }\n }\n\n for (const sourceIndex of [...sourceAvailable]) {\n const split = linePairs.find(([first, second]) => outputAvailable.has(first) && outputAvailable.has(second) && output[first].text + output[second].text === evidence.tokens[sourceIndex]);\n if (!split) continue;\n sourceAvailable.delete(sourceIndex);\n outputAvailable.delete(split[0]);\n outputAvailable.delete(split[1]);\n }\n\n return [...sourceAvailable].map((index) => evidence.tokens[index]);\n}\n\nfunction lineHyphenPairs(output: Token[]): [number, number][] {\n const pairs: [number, number][] = [];\n for (let index = 0; index + 1 < output.length; index++) {\n if (LINE_HYPHEN_RE.test(output[index].gapAfter)) pairs.push([index, index + 1]);\n }\n return pairs;\n}\n\nfunction inlineHyphenPairs(output: Token[]): [number, number][] {\n const pairs: [number, number][] = [];\n for (let index = 0; index + 1 < output.length; index++) {\n if (INLINE_HYPHEN_RE.test(output[index].gapAfter)) pairs.push([index, index + 1]);\n }\n return pairs;\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":["auditWords","WORD_RE","HYPHEN_RE","LINE_HYPHEN_RE","INLINE_HYPHEN_RE","tokens","text","folded","foldTypographic","lastIndex","matches","matchAll","map","match","index","start","end","length","next","normalize","toLowerCase","gapAfter","slice","markdownText","md","replace","counter","items","m","Map","item","set","get","wordsPath","mdPath","rec","parsed","skipped","errors","runsByPage","wordsRaw","readFileSync","rawLines","split","pop","lineIndex","rawLine","evidence","line","trim","startsWith","push","o","JSON","parse","isAuditRecord","page","sourcePairs","runTokenDetails","runTokens","token","test","first","second","explicitHyphen","run","_","terminalHyphen","hyphenOnly","leadingWhitespace","trailingWhitespace","box","recordBox","pageRuns","entries","size","values","every","runs","current","touchingFragments","afterHyphen","auditInputError","out","bodyByPage","lines","total","strict","perPage","pages","keys","sort","a","b","absent","filter","has","markers","join","output","outputTokens","strictMissing","strictDeficits","missing","missingTokens","pyRepr","words","reduce","sum","p","summaryLine","nonJsonSkipped","value","Array","isArray","record","Number","isSafeInteger","geometry","x","y","w","h","field","undefined","isFinite","height","Math","max","gap","abs","PdfToMdError","source","outputCounts","deficits","count","sourceAvailable","Set","outputAvailable","linePairs","lineHyphenPairs","inlinePairs","inlineHyphenPairs","sourceIndex","direct","findIndex","delete","pair","joined","hyphenated","find","pairs","s"],"mappings":"AAAA,2EAA2E;AAC3E,wEAAwE;AACxE,EAAE;AACF,qEAAqE;AACrE,6EAA6E;AAC7E,yEAAyE;AACzE,EAAE;AACF,wEAAwE;AACxE,qBAAqB;;;;;+BAgILA;;;eAAAA;;;sBA/Ha;wBACA;uBACG;4BACL;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE3B,IAAMC,UAAU;AAChB,IAAMC,YAAY;AAClB,IAAMC,iBAAiB;AACvB,IAAMC,mBAAmB;AA8CzB,SAASC,OAAOC,IAAY;IAC1B,IAAMC,SAASC,IAAAA,wBAAe,EAACF;IAC/BL,QAAQQ,SAAS,GAAG;IACpB,IAAMC,UAAW,qBAAGH,OAAOI,QAAQ,CAACV;IACpC,OAAOS,QAAQE,GAAG,CAAC,SAACC,OAAOC;;QACzB,IAAMC,QAAQF,MAAMC,KAAK;QACzB,IAAME,MAAMD,QAAQF,KAAK,CAAC,EAAE,CAACI,MAAM;QACnC,IAAMC,OAAOR,OAAO,CAACI,QAAQ,EAAE;QAC/B,OAAO;YACLR,MAAMO,KAAK,CAAC,EAAE,CAACM,SAAS,CAAC,OAAOC,WAAW;YAC3CL,OAAAA;YACAC,KAAAA;YACAK,UAAUd,OAAOe,KAAK,CAACN,aAAKE,iBAAAA,2BAAAA,KAAMJ,KAAK,uCAAIP,OAAOU,MAAM;QAC1D;IACF;AACF;AAEA,SAASM,aAAaC,EAAU;IAC9B,OAAOA,GACJC,OAAO,CAAC,mCAAqB,KAC7BA,OAAO,CAAC,2CAA0B,KAClCA,OAAO,CAAC,6CAA2B,KACnCA,OAAO,CAAC,gCAAmB,KAC3BA,OAAO,CAAC,8BAAiB,KACzBA,OAAO,CAAC,yBAAY,KACpBA,OAAO,CAAC,8CAA6B,KACr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AAE;QACjC;QANA,QAAK,aAAsB,qBAAG6F,qCAAzB,UAAA,8BAAA,SAAA,0BAAA;;QAAA;QAAA;;;iBAAA,8BAAA;gBAAA;;;gBAAA;sBAAA;;;;IAQL,OAAO,AAAC,qBAAGA,iBAAiB5H,GAAG,CAAC,SAACE;eAAUiC,SAAS1C,MAAM,CAACS,MAAM;;AACnE;AAEA,SAAS8H,gBAAgBzC,MAAe;IACtC,IAAMoD,QAA4B,EAAE;IACpC,IAAK,IAAIzI,QAAQ,GAAGA,QAAQ,IAAIqF,OAAOlF,MAAM,EAAEH,QAAS;QACtD,IAAIX,eAAe0D,IAAI,CAACsC,MAAM,CAACrF,MAAM,CAACO,QAAQ,GAAGkI,MAAMpG,IAAI,CAAC;YAACrC;YAAOA,QAAQ;SAAE;IAChF;IACA,OAAOyI;AACT;AAEA,SAAST,kBAAkB3C,MAAe;IACxC,IAAMoD,QAA4B,EAAE;IACpC,IAAK,IAAIzI,QAAQ,GAAGA,QAAQ,IAAIqF,OAAOlF,MAAM,EAAEH,QAAS;QACtD,IAAIV,iBAAiByD,IAAI,CAACsC,MAAM,CAACrF,MAAM,CAACO,QAAQ,GAAGkI,MAAMpG,IAAI,CAAC;YAACrC;YAAOA,QAAQ;SAAE;IAClF;IACA,OAAOyI;AACT;AAEA,0GAA0G;AAC1G,SAAS9C,OAAO9E,KAAe;IAC7B,OAAO,AAAC,IAAqF,OAAlFA,MAAMf,GAAG,CAAC,SAAC4I;eAAM,AAAC,IAAiD,OAA9CA,EAAE/H,OAAO,CAAC,OAAO,QAAQA,OAAO,CAAC,MAAM,QAAO;OAAIyE,IAAI,CAAC,OAAM;AAC/F"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/open-source/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 { auditWords } from '../audit.ts';\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 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 with the CLI's error code 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 = ctx.errorCode;\n};\n\nexport default audit;\n"],"names":["USAGE","audit","ctx","wordsPath","mdPath","result","line","rest","includes","console","log","usageError","auditWords","lines","missing","process","exitCode","errorCode"],"mappings":"AAAA,oEAAoE;AACpE,iJAAiJ;;;;;+BAsBjJ;;;eAAA;;;uBArB2B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAG3B,IAAMA,QAAQ;AAEd,IAAMC,QAAiB,eAAOC;;YAKAA,WAArBC,WAAWC,QAGZC,QACD,2BAAA,mBAAA,gBAAA,WAAA,OAAMC;;YARX,IAAIJ,IAAIK,IAAI,CAACC,QAAQ,CAAC,SAASN,IAAIK,IAAI,CAACC,QAAQ,CAAC,WAAW;gBAC1DC,QAAQC,GAAG,CAACV;gBACZ;;;YACF;YAC4BE,6BAAAA,IAAIK,IAAI,MAA7BJ,YAAqBD,cAAVE,SAAUF;YAC5B,IAAI,CAACC,aAAa,CAACC,QAAQF,IAAIS,UAAU,CAACX;YAEpCK,SAASO,IAAAA,mBAAU,EAACT,WAAWC;YAChC,kCAAA,2BAAA;;gBAAL,IAAK,YAAcC,OAAOQ,KAAK,uBAA1B,6BAAA,QAAA,yBAAA;oBAAMP,OAAN;oBAA4BG,QAAQC,GAAG,CAACJ;;;gBAAxC;gBAAA;;;yBAAA,6BAAA;wBAAA;;;wBAAA;8BAAA;;;;YAEL,2EAA2E;YAC3E,yJAAyJ;YACzJ,IAAID,OAAOS,OAAO,GAAG,GAAGC,QAAQC,QAAQ,GAAGd,IAAIe,SAAS;;;;;IAC1D;;IAEA,WAAehB"}
|
package/dist/cjs/cli/extract.js
CHANGED
|
@@ -290,7 +290,7 @@ var TUNING_FLAGS = [
|
|
|
290
290
|
];
|
|
291
291
|
var extract = function extract(ctx) {
|
|
292
292
|
return _async_to_generator(function() {
|
|
293
|
-
var parsed, values, positionals, _positionals, src, outArg, wordsPath, formatRaw, format, pages, m, first, last, tuning, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, spec, raw, value, ok, dpi, raw1, value1, source, defaultExt, dest, onWarning, showProgress, onProgress, debugWordsPath, onWords, common, ocrCommon, words, skipped, ref, content, report, markdown, ref1, ref2, analysis,
|
|
293
|
+
var parsed, values, positionals, _positionals, src, outArg, wordsPath, formatRaw, format, pages, m, first, last, tuning, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, spec, raw, value, ok, dpi, raw1, value1, source, defaultExt, dest, onWarning, showProgress, onProgress, debugWordsPath, onWords, common, ocrCommon, words, skipped, ref, content, report, markdown, ref1, ref2, analysis, _report_floats;
|
|
294
294
|
return _ts_generator(this, function(_state) {
|
|
295
295
|
switch(_state.label){
|
|
296
296
|
case 0:
|
|
@@ -461,7 +461,8 @@ var extract = function extract(ctx) {
|
|
|
461
461
|
} : undefined;
|
|
462
462
|
common = {
|
|
463
463
|
pages: pages,
|
|
464
|
-
onWarning: onWarning
|
|
464
|
+
onWarning: onWarning,
|
|
465
|
+
onWords: onWords
|
|
465
466
|
};
|
|
466
467
|
ocrCommon = _object_spread_props(_object_spread({}, common), {
|
|
467
468
|
tuning: tuning,
|
|
@@ -511,7 +512,7 @@ var extract = function extract(ctx) {
|
|
|
511
512
|
content = markdown;
|
|
512
513
|
return [
|
|
513
514
|
3,
|
|
514
|
-
|
|
515
|
+
10
|
|
515
516
|
];
|
|
516
517
|
case 5:
|
|
517
518
|
if (!(words !== undefined)) return [
|
|
@@ -529,62 +530,26 @@ var extract = function extract(ctx) {
|
|
|
529
530
|
case 6:
|
|
530
531
|
analysis = _state.sent();
|
|
531
532
|
return [
|
|
532
|
-
3,
|
|
533
|
-
13
|
|
534
|
-
];
|
|
535
|
-
case 7:
|
|
536
|
-
if (!values.ocr) return [
|
|
537
533
|
3,
|
|
538
534
|
9
|
|
539
535
|
];
|
|
536
|
+
case 7:
|
|
540
537
|
return [
|
|
541
538
|
4,
|
|
542
|
-
(0,
|
|
543
|
-
|
|
539
|
+
(0, _extractts.analyzePdfAuto)(src, _object_spread_props(_object_spread({}, ocrCommon), {
|
|
540
|
+
ocr: values.ocr,
|
|
541
|
+
noOcr: values['no-ocr'],
|
|
542
|
+
pageMarkers: values['page-markers']
|
|
544
543
|
}))
|
|
545
544
|
];
|
|
546
545
|
case 8:
|
|
547
|
-
analysis = _state.sent();
|
|
548
|
-
|
|
549
|
-
3,
|
|
550
|
-
13
|
|
551
|
-
];
|
|
546
|
+
analysis = _state.sent().analysis;
|
|
547
|
+
_state.label = 9;
|
|
552
548
|
case 9:
|
|
553
|
-
return [
|
|
554
|
-
4,
|
|
555
|
-
(0, _analyzets.analyze)(src, _object_spread_props(_object_spread({}, common), {
|
|
556
|
-
path: 'text',
|
|
557
|
-
pageMarkers: values['page-markers']
|
|
558
|
-
}))
|
|
559
|
-
];
|
|
560
|
-
case 10:
|
|
561
|
-
text = _state.sent();
|
|
562
|
-
if (!((0, _extractts.needsOcrFallback)(text.report.charsPerPage) && !values['no-ocr'])) return [
|
|
563
|
-
3,
|
|
564
|
-
12
|
|
565
|
-
];
|
|
566
|
-
onWarning((0, _extractts.ocrFallbackNotice)(text.report.charsPerPage));
|
|
567
|
-
return [
|
|
568
|
-
4,
|
|
569
|
-
(0, _analyzets.analyze)(src, _object_spread_props(_object_spread({}, ocrCommon), {
|
|
570
|
-
path: 'ocr',
|
|
571
|
-
fallback: true
|
|
572
|
-
}))
|
|
573
|
-
];
|
|
574
|
-
case 11:
|
|
575
|
-
analysis = _state.sent();
|
|
576
|
-
return [
|
|
577
|
-
3,
|
|
578
|
-
13
|
|
579
|
-
];
|
|
580
|
-
case 12:
|
|
581
|
-
analysis = text;
|
|
582
|
-
_state.label = 13;
|
|
583
|
-
case 13:
|
|
584
549
|
report = analysis.report;
|
|
585
550
|
content = format === 'raw' ? JSON.stringify(analysis, null, 1) : (0, _renderanalysists.toText)(analysis);
|
|
586
|
-
_state.label =
|
|
587
|
-
case
|
|
551
|
+
_state.label = 10;
|
|
552
|
+
case 10:
|
|
588
553
|
if (values.stdout) process.stdout.write(content);
|
|
589
554
|
else (0, _nodefs.writeFileSync)(dest, content);
|
|
590
555
|
// The library's Report stays clean of source/out; --json consumers keep
|
|
@@ -1 +1 @@
|
|
|
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 { analyze } from '../analyze.ts';\nimport type { OcrWordInput } from '../extract.ts';\nimport { extractOcr, needsOcrFallback, ocrFallbackNotice, pdfToMarkdown } from '../extract.ts';\nimport type { Tuning } from '../geometry.ts';\nimport { toText } from '../render-analysis.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 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 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":["USAGE","FORMATS","TUNING_FLAGS","name","key","allowZero","isInt","extract","ctx","parsed","values","positionals","src","outArg","wordsPath","formatRaw","format","pages","m","first","last","tuning","spec","raw","value","ok","dpi","source","defaultExt","dest","onWarning","showProgress","onProgress","debugWordsPath","onWords","common","ocrCommon","words","skipped","content","report","markdown","analysis","text","rest","includes","usageError","parseArgs","args","options","json","type","default","ocr","stdout","help","short","Object","fromEntries","map","f","allowPositionals","err","message","console","log","JSON","join","stringify","undefined","exec","Number","NaN","isFinite","Math","trunc","replace","error","process","stderr","isTTY","e","page","ms","trim","lines","w","entry","x","y","h","confidence","writeFileSync","length","parseWordLines","readFileSync","extractOcr","pdfToMarkdown","noOcr","pageMarkers","analyze","path","needsOcrFallback","charsPerPage","ocrFallbackNotice","fallback","toText","write","out","basename","padEnd","headings","junkHeadings","paragraphs","callouts","floats","danglingLong","bodyFontHeight","listItems","joinedPairs","sparse","split","line","push","parse"],"mappings":"AAAA,2EAA2E;AAC3E,qHAAqH;;;;;+BA0PrH;;;eAAA;;;sBAzP4C;+DAC3B;wBACS;yBACF;yBAEuD;gCAExD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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C,OAAN;YACH,IAAI,CAACA,KAAKtC,IAAI,IAAI;YAClB,IAAI;gBACF/C,MAAMsF,IAAI,CAACzD,KAAK0D,KAAK,CAACF;YACxB,EAAE,eAAM;gBACNpF;YACF;QACF;;QAPK;QAAA;;;iBAAA,6BAAA;gBAAA;;;gBAAA;sBAAA;;;;IAQL,OAAO;QAAED,OAAAA;QAAOC,SAAAA;IAAQ;AAC1B;IAEA,WAAe/B"}
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/open-source/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 { analyze } from '../analyze.ts';\nimport type { OcrWordInput } from '../extract.ts';\nimport { analyzePdfAuto, extractOcr, pdfToMarkdown } from '../extract.ts';\nimport type { Tuning } from '../geometry.ts';\nimport { toText } from '../render-analysis.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, onWords };\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 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 render the same routed Analysis as the Markdown API, so a\n // format switch cannot discard a sparse image page or change audit input.\n let analysis: Analysis;\n if (words !== undefined) {\n analysis = await analyze({ words }, { ...ocrCommon, path: 'ocr' });\n } else {\n analysis = (\n await analyzePdfAuto(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 ).analysis;\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":["USAGE","FORMATS","TUNING_FLAGS","name","key","allowZero","isInt","extract","ctx","parsed","values","positionals","src","outArg","wordsPath","formatRaw","format","pages","m","first","last","tuning","spec","raw","value","ok","dpi","source","defaultExt","dest","onWarning","showProgress","onProgress","debugWordsPath","onWords","common","ocrCommon","words","skipped","content","report","markdown","analysis","rest","includes","usageError","parseArgs","args","options","json","type","default","ocr","stdout","help","short","Object","fromEntries","map","f","allowPositionals","err","message","console","log","JSON","join","stringify","undefined","exec","Number","NaN","isFinite","Math","trunc","replace","error","process","stderr","isTTY","e","page","ms","trim","lines","w","entry","text","x","y","h","confidence","writeFileSync","length","parseWordLines","readFileSync","extractOcr","pdfToMarkdown","noOcr","pageMarkers","analyze","path","analyzePdfAuto","toText","write","out","basename","padEnd","headings","junkHeadings","paragraphs","callouts","floats","danglingLong","charsPerPage","bodyFontHeight","listItems","joinedPairs","sparse","split","line","push","parse"],"mappings":"AAAA,2EAA2E;AAC3E,qHAAqH;;;;;+BAyPrH;;;eAAA;;;sBAxP4C;+DAC3B;wBACS;yBACF;yBAEkC;gCAEnC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIvB,IAAMA,QACJ,iGACA,yEACA,8GACA,8FACA,oDACA,uGACA;AAEF,IAAMC,UAAU;IAAC;IAAM;IAAO;CAAM;AAGpC,mHAAmH;AACnH,IAAMC,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;QAAc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F;;AAEA,8EAA8E;AAC9E,wGAAwG;AACxG,SAASxB,eAAevE,GAAW;IACjC,IAAMc,QAAwB,EAAE;IAChC,IAAIC,UAAU;QACT,kCAAA,2BAAA;;QAAL,QAAK,YAAcf,IAAIgG,KAAK,CAAC,0BAAxB,SAAA,6BAAA,QAAA,yBAAA,iCAA+B;YAA/B,IAAMC,OAAN;YACH,IAAI,CAACA,KAAKrC,IAAI,IAAI;YAClB,IAAI;gBACF9C,MAAMoF,IAAI,CAACxD,KAAKyD,KAAK,CAACF;YACxB,EAAE,eAAM;gBACNlF;YACF;QACF;;QAPK;QAAA;;;iBAAA,6BAAA;gBAAA;;;gBAAA;sBAAA;;;;IAQL,OAAO;QAAED,OAAAA;QAAOC,SAAAA;IAAQ;AAC1B;IAEA,WAAe/B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/open-source/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":";;;;+BAIaA;;;eAAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAN,IAAMA,WAAgE;IAC3EC,SAAS,SAATA;eAAe;2DAAA,QAAO;;;IACtBC,QAAQ,SAARA;eAAc;2DAAA,QAAO;;;IACrBC,OAAO,SAAPA;eAAa;2DAAA,QAAO;;;AACtB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/open-source/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 { awaitPdfOpen, openPdfForRender } from '../pdf-open.ts';\nimport { renderLoadedPage } from '../raster.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 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":["USAGE","render","ctx","values","parsed","positionals","pdfPath","spec","m","firstPage","lastPage","dpi","outDir","stem","loadingTask","doc","n","png","outPath","parseArgs","args","rest","options","type","default","short","out","help","allowPositionals","err","usageError","message","console","log","exec","Number","undefined","parseFloat","process","cwd","mkdirSync","recursive","path","basename","extname","replaceAll","openPdfForRender","awaitPdfOpen","numPages","PdfToMdError","renderLoadedPage","join","writeFileSync","destroy"],"mappings":"AAAA,kEAAkE;AAClE,yIAAyI;;;;;+BAuEzI;;;eAAA;;;sBAtEyC;+DACxB;wBACS;wBACG;yBACkB;wBACd;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGjC,IAAMA,QAAQ;AAEd,IAAMC,SAAkB,gBAAOC;;YAoCdC,aAnCTC,QAgBED,QAAQE,aAOQA,cAAjBC,SAASC,MAGVC,GAEAC,WACAC,UAGAC,KAGAC,QAEAC,MAEAC,aAEEC,KAOGC,GACCC,KACFC;;;;oBAlDJd,SAAS,AAAC;wBACd,IAAI;4BACF,OAAOe,IAAAA,mBAAS,EAAC;gCACfC,MAAMlB,IAAImB,IAAI;gCACdC,SAAS;oCACPX,KAAK;wCAAEY,MAAM;wCAAUC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EAAC5B,QAAQ;wBAAE6B,WAAW;oBAAK;oBAC9B5B,OAAO6B,iBAAI,CAACC,QAAQ,CAACrC,SAASoC,iBAAI,CAACE,OAAO,CAACtC,UAAUuC,UAAU,CAAC,KAAK;oBAErE/B,cAAcgC,IAAAA,2BAAgB,EAACxC;;;;;;;;;oBAEvB;;wBAAMyC,IAAAA,uBAAY,EAACjC,aAAaR;;;oBAAtCS,MAAM;oBAEZ,wEAAwE;oBACxE,4DAA4D;oBAC5D,IAAIL,WAAWK,IAAIiC,QAAQ,EAAE;wBAC3B,MAAM,IAAIC,sBAAY,CAAC,cAAc,AAAC,cAA0BvC,OAAbD,WAAU,KAA2CM,OAAxCL,UAAS,iCAA4C,OAAbK,IAAIiC,QAAQ,EAAC;oBACvH;oBACShC,IAAIP;;;yBAAWO,CAAAA,KAAKN,QAAO;;;;oBAClB;;wBAAMwC,IAAAA,0BAAgB,EAACnC,KAAKC,GAAGL;;;oBAAvCM,MAAQ,cAARA;oBACFC,UAAUwB,iBAAI,CAACS,IAAI,CAACvC,QAAQ,AAAC,GAAWI,OAATH,MAAK,MAAM,OAAFG,GAAE;oBAChDoC,IAAAA,qBAAa,EAAClC,SAASD;oBACvBe,QAAQC,GAAG,CAACf;;;oBAJyBF;;;;;;;;;;;oBAOvC;;wBAAMF,YAAYuC,OAAO;;;oBAAzB;;;;;;;;;;IAEJ;;IAEA,WAAepD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/open-source/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 /** the CLI's fixed non-zero exit code, for result signals like audit loss */\n readonly errorCode: number;\n /** print the message and exit with the CLI's error code, on 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"}
|
package/dist/cjs/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/open-source/formats/pdf-to-md/src/cli.ts"],"sourcesContent":["// Parsing and dispatch only. Commands live in src/cli/, one file each,\n// lazy-loaded — nothing tree- or dependency-heavy may be imported at the top of this file (`render` must never load the OCR engine, `--version` must load almost nothing).\nimport { readFileSync } from 'node:fs';\nimport path from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport { COMMANDS } from './cli/index.ts';\nimport type { Ctx } from './cli/types.ts';\n\n// __dirname (CJS) or its ESM equivalent, then two fixed hops up to the\n// package root. NOT `import.meta.resolve('pdf-to-md/package.json')` — Node's self-reference lookup throws ERR_MODULE_NOT_FOUND from a file this deep; a location-relative path is stable across both build targets.\nconst __dirname = path.dirname(typeof __filename !== 'undefined' ? __filename : fileURLToPath(import.meta.url));\nconst ERROR_CODE = 19;\n\nfunction packageVersion(): string {\n try {\n const pkgPath = path.resolve(__dirname, '..', '..', 'package.json');\n const pkg = JSON.parse(readFileSync(pkgPath, 'utf8')) as { version?: string };\n return pkg.version ?? 'unknown';\n } catch {\n return 'unknown';\n }\n}\n\nfunction usage(name: string): string {\n return (\n `usage: ${name} <file.pdf> [out.md] [flags...] convert a PDF to markdown\\n` +\n ` ${name} extract <file.pdf> [out.md] [flags...] (same, explicit)\\n` +\n ` ${name} render <file.pdf> <page>[-<page>] [--dpi|-d N (default 288)] [--out|-o DIR (default .)]\\n` +\n ` ${name} audit <words.jsonl> <file.md> severity-1 word-loss check\\n` +\n ` ${name} --version | --help\\n` +\n '\\n' +\n 'extract flags:\\n' +\n ' --ocr force the OCR path (image-only/scanned pages)\\n' +\n ' --no-ocr never fall back to OCR; keep sparse text output\\n' +\n ' --pages N[-M] convert only these 1-based source pages\\n' +\n ' --stdout write markdown to stdout instead of a file\\n' +\n ' --json print the full QA report as JSON\\n' +\n ` --page-markers emit a \"### pN\" heading per page\\n` +\n ' --format md|txt|raw output format (default md; raw = Analysis JSON incl. the\\n' +\n ' report; txt = reading-order plain text)\\n' +\n ' --words-json=FILE OCR path from a recognized-word dump (offline replay)\\n' +\n ' --debug-words=FILE dump every recognized word as JSON lines to FILE\\n' +\n ' --dpi=N OCR render resolution (default 288; raise for tiny print or\\n' +\n ' chart/label pages, >~400 measured worse on ordinary prose)\\n' +\n '\\n' +\n `extract tuning (measured defaults; see README's tuning table):\\n` +\n ' --float-max-words=N --float-max-width=F --float-margin=F --para-gap=F\\n' +\n ' --heading-scale=F --col-max-width=F --col-split=F --line-y-tol=F\\n' +\n ' --line-height-ratio=F\\n' +\n '\\n' +\n 'examples:\\n' +\n ` ${name} book.pdf # text layer -> book.md (auto-OCR if scanned)\\n` +\n ` ${name} scan.pdf out.md --ocr --json # force OCR, print the QA report\\n` +\n ` ${name} book.pdf --pages 27-31 --stdout # re-extract a page range to stdout\\n` +\n ` ${name} render book.pdf 27 # render p27 to PNG for eyeballing (288 dpi)\\n` +\n ` ${name} audit words.jsonl book.md # check no recognized word was lost`\n );\n}\n\n// All failures exit ERROR_CODE: usage errors with the usage text, thrown errors with the message verbatim.\nexport default async function cli(argv: string[], name: string): Promise<void> {\n if (argv[0] === '--version' || argv[0] === '-v') {\n console.log(packageVersion());\n return;\n }\n if (argv.length === 0 || argv[0] === '--help' || argv[0] === '-h') {\n // No args is a usage ERROR (bare `pdf-to-md` can't do anything); asking\n // for --help is not.\n if (argv.length === 0) {\n console.error(usage(name));\n process.exit(ERROR_CODE);\n }\n console.log(`${name} v${packageVersion()}`);\n console.log('');\n console.log(usage(name));\n return;\n }\n\n const ctx: Ctx = {\n name,\n rest: argv.slice(1),\n usageError(message) {\n console.error(message);\n process.exit(ERROR_CODE);\n },\n errorCode: ERROR_CODE,\n };\n\n try {\n const load = COMMANDS[argv[0]];\n if (load) {\n await (await load()).default(ctx);\n } else {\n // Compat shim: `pdf-to-md file.pdf [...]` — any first word that isn't\n // a reserved command is extract's own first argument.\n ctx.rest = argv;\n await (await COMMANDS.extract()).default(ctx);\n }\n } catch (err) {\n console.error((err as Error).message);\n process.exit(ERROR_CODE);\n }\n}\n"],"names":["cli","__dirname","path","dirname","__filename","fileURLToPath","ERROR_CODE","packageVersion","pkg","pkgPath","resolve","JSON","parse","readFileSync","version","usage","name","argv","ctx","load","err","console","log","length","error","process","exit","rest","slice","usageError","message","errorCode","COMMANDS","default","extract"],"mappings":"AAAA,uEAAuE;AACvE,2KAA2K;;;;;+BA0D3K,2GAA2G;AAC3G;;;eAA8BA;;;sBA1DD;+DACZ;uBACa;uBACL;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGzB,uEAAuE;AACvE,oNAAoN;AACpN,IAAMC,YAAYC,iBAAI,CAACC,OAAO,CAAC,OAAOC,eAAe,cAAcA,aAAaC,IAAAA,sBAAa,EAAC;AAC9F,IAAMC,aAAa;AAEnB,SAASC;IACP,IAAI;YAGKC;QAFP,IAAMC,UAAUP,iBAAI,CAACQ,OAAO,CAACT,WAAW,MAAM,MAAM;QACpD,IAAMO,MAAMG,KAAKC,KAAK,CAACC,IAAAA,oBAAY,EAACJ,SAAS;QAC7C,QAAOD,eAAAA,IAAIM,OAAO,cAAXN,0BAAAA,eAAe;IACxB,EAAE,eAAM;QACN,OAAO;IACT;AACF;AAEA,SAASO,MAAMC,IAAY;IACzB,OACE,AAAC,UAAc,OAALA,MAAK,wEACf,AAAC,UAAc,OAALA,MAAK,gEACf,AAA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