A fast, helpful, and open-source document parser
add docs support
Logan Markewichad5991ba458c
diff --git a/.github/workflows/sync-docs.yml b/.github/workflows/sync-docs.ymlnew file mode 100644index 0000000..e69de29diff --git a/.gitignore b/.gitignoreindex ce9a0b0..ccfc9a3 100644--- a/.gitignore+++ b/.gitignore@@ -63,3 +63,8 @@ ltt/# OCR data files*.traineddata++# Docs+.docs-preview/+docs/src/content/docs/liteparse/api.md+docs/src/content/docs/liteparse/.api-tmp/diff --git a/README.md b/README.mdindex 410d006..0346e0b 100644--- a/README.md+++ b/README.md@@ -96,13 +96,13 @@ Screenshots are essential for LLM agents to extract visual information that textlit screenshot document.pdf -o ./screenshots# Screenshot specific pages-lit screenshot document.pdf --pages "1,3,5" -o ./screenshots+lit screenshot document.pdf --target-pages "1,3,5" -o ./screenshots# Custom DPIlit screenshot document.pdf --dpi 300 -o ./screenshots# Screenshot page range-lit screenshot document.pdf --pages "1-10" -o ./screenshots+lit screenshot document.pdf --target-pages "1-10" -o ./screenshots```### Library Usage@@ -144,7 +144,6 @@ Options:--target-pages <pages> Target pages (e.g., "1-5,10,15-20")--dpi <dpi> DPI for rendering (default: "150")--no-precise-bbox Disable precise bounding boxes- --skip-diagonal-text Skip diagonal text--preserve-small-text Preserve very small text--config <file> Config file (JSON)-q, --quiet Suppress progress output@@ -185,7 +184,7 @@ Generate screenshots of PDF pagesOptions:-o, --output-dir <dir> Output directory for screenshots (default: "./screenshots")- --pages <pages> Page numbers to screenshot (e.g., "1,3,5" or "1-5")+ --target-pages <pages> Page numbers to screenshot (e.g., "1,3,5" or "1-5")--dpi <dpi> DPI for rendering (default: "150")--format <format> Image format: png|jpg (default: "png")--config <file> Config file (JSON)@@ -283,10 +282,7 @@ Create a `liteparse.config.json` file:"maxPages": 1000,"dpi": 150,"outputFormat": "json",- "includeImages": true,- "includeCharts": true,"preciseBoundingBox": true,- "skipDiagonalText": false,"preserveVerySmallText": false}```diff --git a/cli/parse.ts b/cli/parse.tsindex ac54cd3..975f398 100644--- a/cli/parse.ts+++ b/cli/parse.ts@@ -25,7 +25,6 @@ interface ParseCommandOptions {targetPages?: string;dpi?: string;preciseBbox?: boolean;- skipDiagonalText?: boolean;preserveSmallText?: boolean;config?: string;quiet?: boolean;@@ -33,7 +32,7 @@ interface ParseCommandOptions {interface ScreenshotCommandOptions {outputDir?: string;- pages?: string;+ targetPages?: string;dpi?: string;format?: string;config?: string;@@ -78,7 +77,6 @@ program.option("--target-pages <pages>", 'Target pages (e.g., "1-5,10,15-20")').option("--dpi <dpi>", "DPI for rendering", DEFAULT_DPI.toString()).option("--no-precise-bbox", "Disable precise bounding boxes")- .option("--skip-diagonal-text", "Skip diagonal text").option("--preserve-small-text", "Preserve very small text").option("--config <file>", "Config file (JSON)").option("-q, --quiet", "Suppress progress output")@@ -121,7 +119,6 @@ programtargetPages: options.targetPages,dpi: parseInt(options.dpi || DEFAULT_DPI.toString()),preciseBoundingBox: options.preciseBbox !== false,- skipDiagonalText: options.skipDiagonalText || false,preserveVerySmallText: options.preserveSmallText || false,};@@ -168,7 +165,7 @@ program.command("screenshot <file>").description("Generate screenshots of PDF pages").option("-o, --output-dir <dir>", "Output directory for screenshots", DEFAULT_SCREENSHOT_DIR)- .option("--pages <pages>", 'Page numbers to screenshot (e.g., "1,3,5" or "1-5")')+ .option("--target-pages <pages>", 'Page numbers to screenshot (e.g., "1,3,5" or "1-5")').option("--dpi <dpi>", "DPI for rendering", DEFAULT_DPI.toString()).option("--format <format>", "Image format: png|jpg", DEFAULT_SCREENSHOT_FORMAT).option("--config <file>", "Config file (JSON)")@@ -203,8 +200,8 @@ program// Parse target pageslet pageNumbers: number[] | undefined;- if (options.pages) {- pageNumbers = parsePageNumbers(options.pages);+ if (options.targetPages) {+ pageNumbers = parsePageNumbers(options.targetPages);}const outputDir = options.outputDir || DEFAULT_SCREENSHOT_DIR;diff --git a/package-lock.json b/package-lock.jsonindex bc0a6fc..2857c9f 100644--- a/package-lock.json+++ b/package-lock.json@@ -32,6 +32,8 @@"eslint-config-prettier": "^10.1.8","eslint-plugin-prettier": "^5.5.5","prettier": "^3.8.1",+ "typedoc": "^0.28.17",+ "typedoc-plugin-markdown": "^4.10.0","typescript": "~5.9.2","typescript-eslint": "^8.56.0","vitest": "^4.0.18"@@ -927,6 +929,20 @@"node": "^20.19.0 || ^22.13.0 || >=24"}},+ "node_modules/@gerrit0/mini-shiki": {+ "version": "3.23.0",+ "resolved": "https://registry.npmjs.org/@gerrit0/mini-shiki/-/mini-shiki-3.23.0.tgz",+ "integrity": "sha512-bEMORlG0cqdjVyCEuU0cDQbORWX+kYCeo0kV1lbxF5bt4r7SID2l9bqsxJEM0zndaxpOUT7riCyIVEuqq/Ynxg==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "@shikijs/engine-oniguruma": "^3.23.0",+ "@shikijs/langs": "^3.23.0",+ "@shikijs/themes": "^3.23.0",+ "@shikijs/types": "^3.23.0",+ "@shikijs/vscode-textmate": "^10.0.2"+ }+ },"node_modules/@humanfs/core": {"version": "0.19.1","resolved": "https://registry.npmjs.org/@humanfs/core/-/core-0.19.1.tgz",@@ -2018,6 +2034,55 @@"win32"]},+ "node_modules/@shikijs/engine-oniguruma": {+ "version": "3.23.0",+ "resolved": "https://registry.npmjs.org/@shikijs/engine-oniguruma/-/engine-oniguruma-3.23.0.tgz",+ "integrity": "sha512-1nWINwKXxKKLqPibT5f4pAFLej9oZzQTsby8942OTlsJzOBZ0MWKiwzMsd+jhzu8YPCHAswGnnN1YtQfirL35g==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "@shikijs/types": "3.23.0",+ "@shikijs/vscode-textmate": "^10.0.2"+ }+ },+ "node_modules/@shikijs/langs": {+ "version": "3.23.0",+ "resolved": "https://registry.npmjs.org/@shikijs/langs/-/langs-3.23.0.tgz",+ "integrity": "sha512-2Ep4W3Re5aB1/62RSYQInK9mM3HsLeB91cHqznAJMuylqjzNVAVCMnNWRHFtcNHXsoNRayP9z1qj4Sq3nMqYXg==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "@shikijs/types": "3.23.0"+ }+ },+ "node_modules/@shikijs/themes": {+ "version": "3.23.0",+ "resolved": "https://registry.npmjs.org/@shikijs/themes/-/themes-3.23.0.tgz",+ "integrity": "sha512-5qySYa1ZgAT18HR/ypENL9cUSGOeI2x+4IvYJu4JgVJdizn6kG4ia5Q1jDEOi7gTbN4RbuYtmHh0W3eccOrjMA==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "@shikijs/types": "3.23.0"+ }+ },+ "node_modules/@shikijs/types": {+ "version": "3.23.0",+ "resolved": "https://registry.npmjs.org/@shikijs/types/-/types-3.23.0.tgz",+ "integrity": "sha512-3JZ5HXOZfYjsYSk0yPwBrkupyYSLpAE26Qc0HLghhZNGTZg/SKxXIIgoxOpmmeQP0RRSDJTk1/vPfw9tbw+jSQ==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "@shikijs/vscode-textmate": "^10.0.2",+ "@types/hast": "^3.0.4"+ }+ },+ "node_modules/@shikijs/vscode-textmate": {+ "version": "10.0.2",+ "resolved": "https://registry.npmjs.org/@shikijs/vscode-textmate/-/vscode-textmate-10.0.2.tgz",+ "integrity": "sha512-83yeghZ2xxin3Nj8z1NMd/NCuca+gsYXswywDy5bHvwlWL8tpTQmzGeUuHd9FC3E/SBEMvzJRwWEOz5gGes9Qg==",+ "dev": true,+ "license": "MIT"+ },"node_modules/@standard-schema/spec": {"version": "1.1.0","resolved": "https://registry.npmjs.org/@standard-schema/spec/-/spec-1.1.0.tgz",@@ -2057,6 +2122,16 @@"dev": true,"license": "MIT"},+ "node_modules/@types/hast": {+ "version": "3.0.4",+ "resolved": "https://registry.npmjs.org/@types/hast/-/hast-3.0.4.tgz",+ "integrity": "sha512-WPs+bbQw5aCj+x6laNGWLH3wviHtoCv/P3+otBhbOhJgG8qtpdAMlTCxLtsTWA7LH1Oh/bFCHsBn0TPS5m30EQ==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "@types/unist": "*"+ }+ },"node_modules/@types/json-schema": {"version": "7.0.15","resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.15.tgz",@@ -2825,6 +2900,19 @@"node": ">=8.6"}},+ "node_modules/entities": {+ "version": "4.5.0",+ "resolved": "https://registry.npmjs.org/entities/-/entities-4.5.0.tgz",+ "integrity": "sha512-V0hjH4dGPh9Ao5p0MoRY6BVqtwCjhz6vI5LT8AJ55H+4g9/4vbHx1I54fS0XuclLhDHArPQCiMjDxjaL8fPxhw==",+ "dev": true,+ "license": "BSD-2-Clause",+ "engines": {+ "node": ">=0.12"+ },+ "funding": {+ "url": "https://github.com/fb55/entities?sponsor=1"+ }+ },"node_modules/es-define-property": {"version": "1.0.1","resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz",@@ -3750,6 +3838,16 @@"node": ">= 0.8.0"}},+ "node_modules/linkify-it": {+ "version": "5.0.0",+ "resolved": "https://registry.npmjs.org/linkify-it/-/linkify-it-5.0.0.tgz",+ "integrity": "sha512-5aHCbzQRADcdP+ATqnDuhhJ/MRIqDkZX5pyjFHRRysS8vZ5AbqGEoFIb6pYHPZ+L/OC2Lc+xT8uHVVR5CAK/wQ==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "uc.micro": "^2.0.0"+ }+ },"node_modules/locate-path": {"version": "6.0.0","resolved": "https://registry.npmjs.org/locate-path/-/locate-path-6.0.0.tgz",@@ -3773,6 +3871,13 @@"dev": true,"license": "MIT"},+ "node_modules/lunr": {+ "version": "2.3.9",+ "resolved": "https://registry.npmjs.org/lunr/-/lunr-2.3.9.tgz",+ "integrity": "sha512-zTU3DaZaF3Rt9rhN3uBMGQD3dD2/vFQqnvZCDv4dl5iOzq2IZQqTxu90r4E5J+nP70J3ilqVCrbho2eWaeW8Ow==",+ "dev": true,+ "license": "MIT"+ },"node_modules/magic-string": {"version": "0.30.21","resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.21.tgz",@@ -3783,6 +3888,24 @@"@jridgewell/sourcemap-codec": "^1.5.5"}},+ "node_modules/markdown-it": {+ "version": "14.1.1",+ "resolved": "https://registry.npmjs.org/markdown-it/-/markdown-it-14.1.1.tgz",+ "integrity": "sha512-BuU2qnTti9YKgK5N+IeMubp14ZUKUUw7yeJbkjtosvHiP0AZ5c8IAgEMk79D0eC8F23r4Ac/q8cAIFdm2FtyoA==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "argparse": "^2.0.1",+ "entities": "^4.4.0",+ "linkify-it": "^5.0.0",+ "mdurl": "^2.0.0",+ "punycode.js": "^2.3.1",+ "uc.micro": "^2.1.0"+ },+ "bin": {+ "markdown-it": "bin/markdown-it.mjs"+ }+ },"node_modules/math-intrinsics": {"version": "1.1.0","resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz",@@ -3792,6 +3915,13 @@"node": ">= 0.4"}},+ "node_modules/mdurl": {+ "version": "2.0.0",+ "resolved": "https://registry.npmjs.org/mdurl/-/mdurl-2.0.0.tgz",+ "integrity": "sha512-Lf+9+2r+Tdp5wXDXC4PcIBjTDtq4UKjCPMQhKIuzpJNW0b96kVqSwW0bT7FhRSfmAiFYgP+SCRvdrDozfh0U5w==",+ "dev": true,+ "license": "MIT"+ },"node_modules/merge2": {"version": "1.4.1","resolved": "https://registry.npmjs.org/merge2/-/merge2-1.4.1.tgz",@@ -4225,6 +4355,16 @@"node": ">=6"}},+ "node_modules/punycode.js": {+ "version": "2.3.1",+ "resolved": "https://registry.npmjs.org/punycode.js/-/punycode.js-2.3.1.tgz",+ "integrity": "sha512-uxFIHU0YlHYhDQtV4R9J6a52SLx28BCjT+4ieh7IGbgwVJWO+km431c4yRlREUAsAmt/uMjQUyQHNEPf0M39CA==",+ "dev": true,+ "license": "MIT",+ "engines": {+ "node": ">=6"+ }+ },"node_modules/quansync": {"version": "0.2.11","resolved": "https://registry.npmjs.org/quansync/-/quansync-0.2.11.tgz",@@ -4739,6 +4879,76 @@"node": ">= 0.8.0"}},+ "node_modules/typedoc": {+ "version": "0.28.17",+ "resolved": "https://registry.npmjs.org/typedoc/-/typedoc-0.28.17.tgz",+ "integrity": "sha512-ZkJ2G7mZrbxrKxinTQMjFqsCoYY6a5Luwv2GKbTnBCEgV2ihYm5CflA9JnJAwH0pZWavqfYxmDkFHPt4yx2oDQ==",+ "dev": true,+ "license": "Apache-2.0",+ "dependencies": {+ "@gerrit0/mini-shiki": "^3.17.0",+ "lunr": "^2.3.9",+ "markdown-it": "^14.1.0",+ "minimatch": "^9.0.5",+ "yaml": "^2.8.1"+ },+ "bin": {+ "typedoc": "bin/typedoc"+ },+ "engines": {+ "node": ">= 18",+ "pnpm": ">= 10"+ },+ "peerDependencies": {+ "typescript": "5.0.x || 5.1.x || 5.2.x || 5.3.x || 5.4.x || 5.5.x || 5.6.x || 5.7.x || 5.8.x || 5.9.x"+ }+ },+ "node_modules/typedoc-plugin-markdown": {+ "version": "4.10.0",+ "resolved": "https://registry.npmjs.org/typedoc-plugin-markdown/-/typedoc-plugin-markdown-4.10.0.tgz",+ "integrity": "sha512-psrg8Rtnv4HPWCsoxId+MzEN8TVK5jeKCnTbnGAbTBqcDapR9hM41bJT/9eAyKn9C2MDG9Qjh3MkltAYuLDoXg==",+ "dev": true,+ "license": "MIT",+ "engines": {+ "node": ">= 18"+ },+ "peerDependencies": {+ "typedoc": "0.28.x"+ }+ },+ "node_modules/typedoc/node_modules/balanced-match": {+ "version": "1.0.2",+ "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz",+ "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==",+ "dev": true,+ "license": "MIT"+ },+ "node_modules/typedoc/node_modules/brace-expansion": {+ "version": "2.0.2",+ "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.2.tgz",+ "integrity": "sha512-Jt0vHyM+jmUBqojB7E1NIYadt0vI0Qxjxd2TErW94wDz+E2LAm5vKMXXwg6ZZBTHPuUlDgQHKXvjGBdfcF1ZDQ==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "balanced-match": "^1.0.0"+ }+ },+ "node_modules/typedoc/node_modules/minimatch": {+ "version": "9.0.9",+ "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.9.tgz",+ "integrity": "sha512-OBwBN9AL4dqmETlpS2zasx+vTeWclWzkblfZk7KTA5j3jeOONz/tRCnZomUyvNg83wL5Zv9Ss6HMJXAgL8R2Yg==",+ "dev": true,+ "license": "ISC",+ "dependencies": {+ "brace-expansion": "^2.0.2"+ },+ "engines": {+ "node": ">=16 || 14 >=14.17"+ },+ "funding": {+ "url": "https://github.com/sponsors/isaacs"+ }+ },"node_modules/typescript": {"version": "5.9.3","resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz",@@ -4777,6 +4987,13 @@"typescript": ">=4.8.4 <6.0.0"}},+ "node_modules/uc.micro": {+ "version": "2.1.0",+ "resolved": "https://registry.npmjs.org/uc.micro/-/uc.micro-2.1.0.tgz",+ "integrity": "sha512-ARDJmphmdvUk6Glw7y9DQ2bFkKBHwQHLi2lsaH6PPmz/Ka9sFOBsBluozhDltWmnv9u/cF6Rt87znRTPV+yp/A==",+ "dev": true,+ "license": "MIT"+ },"node_modules/undici-types": {"version": "6.21.0","resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.21.0.tgz",@@ -5082,6 +5299,22 @@"node": ">=0.10.0"}},+ "node_modules/yaml": {+ "version": "2.8.2",+ "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.8.2.tgz",+ "integrity": "sha512-mplynKqc1C2hTVYxd0PU2xQAc22TI1vShAYGksCCfxbn/dFwnHTNi1bvYsBTkhdUNtGIf5xNOg938rrSSYvS9A==",+ "dev": true,+ "license": "ISC",+ "bin": {+ "yaml": "bin.mjs"+ },+ "engines": {+ "node": ">= 14.6"+ },+ "funding": {+ "url": "https://github.com/sponsors/eemeli"+ }+ },"node_modules/yocto-queue": {"version": "1.2.2","resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-1.2.2.tgz",diff --git a/package.json b/package.jsonindex 0822398..20d8aff 100644--- a/package.json+++ b/package.json@@ -34,6 +34,7 @@"lint:fix": "eslint src cli --fix","format": "prettier --write \"src/**/*.ts\" \"cli/**/*.ts\"","format:check": "prettier --check \"src/**/*.ts\" \"cli/**/*.ts\"",+ "docs:api": "bash scripts/generate-api-docs.sh","changeset": "changeset","version": "changeset version","release": "npm run build && changeset publish"@@ -58,6 +59,8 @@"eslint-config-prettier": "^10.1.8","eslint-plugin-prettier": "^5.5.5","prettier": "^3.8.1",+ "typedoc": "^0.28.17",+ "typedoc-plugin-markdown": "^4.10.0","typescript": "~5.9.2","typescript-eslint": "^8.56.0","vitest": "^4.0.18"diff --git a/packages/python/liteparse/parser.py b/packages/python/liteparse/parser.pyindex ef95e35..61f6811 100644--- a/packages/python/liteparse/parser.py+++ b/packages/python/liteparse/parser.py@@ -389,7 +389,7 @@ class LiteParse:file_path: Union[str, Path],output_dir: Optional[Union[str, Path]] = None,*,- pages: Optional[str] = None,+ target_pages: Optional[str] = None,dpi: int = 150,image_format: Union[ImageFormat, str] = ImageFormat.PNG,load_bytes: bool = False,@@ -401,7 +401,7 @@ class LiteParse:Args:file_path: Path to the document fileoutput_dir: Directory to save screenshots (uses temp dir if not provided)- pages: Specific pages to screenshot (e.g., "1,3,5" or "1-5")+ target_pages: Specific pages to screenshot (e.g., "1,3,5" or "1-5")dpi: DPI for renderingimage_format: Image format ("png" or "jpg")load_bytes: If True, load image bytes into ScreenshotResult objects@@ -439,8 +439,8 @@ class LiteParse:"-q",]- if pages:- cmd.extend(["--pages", pages])+ if target_pages:+ cmd.extend(["--target-pages", target_pages])try:result = subprocess.run(diff --git a/scripts/generate-api-docs.sh b/scripts/generate-api-docs.shnew file mode 100755index 0000000..bfaa299--- /dev/null+++ b/scripts/generate-api-docs.sh@@ -0,0 +1,28 @@+#!/usr/bin/env bash+# Generates API reference docs from TypeDoc and outputs a single+# Starlight-compatible markdown file with frontmatter.+set -euo pipefail++DOCS_DIR="./docs/src/content/docs/liteparse"+TMP_DIR="${DOCS_DIR}/.api-tmp"+OUT_FILE="${DOCS_DIR}/api.md"++# Generate markdown with TypeDoc+npx typedoc++# Prepend Starlight frontmatter to the generated README+cat > "${OUT_FILE}" <<'FRONTMATTER'+---+title: API Reference+description: API reference for the @llamaindex/liteparse TypeScript library.+sidebar:+ order: 6+---+FRONTMATTER++cat "${TMP_DIR}/README.md" >> "${OUT_FILE}"++# Clean up temp directory+rm -rf "${TMP_DIR}"++echo "Generated ${OUT_FILE}"diff --git a/scripts/sync-docs-to-developer-hub.sh b/scripts/sync-docs-to-developer-hub.shnew file mode 100644index 0000000..e69de29diff --git a/src/core/README.md b/src/core/README.mdindex 271e253..6a69975 100644--- a/src/core/README.md+++ b/src/core/README.md@@ -81,10 +81,7 @@ The core module contains the main orchestrator class, configuration management,maxPages: 1000,dpi: 150,outputFormat: 'json',- includeImages: true,- includeCharts: true,preciseBoundingBox: true,- skipDiagonalText: false,preserveVerySmallText: false,preserveLayoutAlignmentAcrossPages: false,}diff --git a/src/core/config.ts b/src/core/config.tsindex f48b101..b6bd793 100644--- a/src/core/config.ts+++ b/src/core/config.ts@@ -15,12 +15,9 @@ export const DEFAULT_CONFIG: LiteParseConfig = {// OutputoutputFormat: "json",- includeImages: true,- includeCharts: true,// FeaturespreciseBoundingBox: true,- skipDiagonalText: false,preserveVerySmallText: false,preserveLayoutAlignmentAcrossPages: false,};diff --git a/src/core/parser.ts b/src/core/parser.tsindex a3c3f23..2db8cb4 100644--- a/src/core/parser.ts+++ b/src/core/parser.ts@@ -13,11 +13,47 @@ import { formatJSON } from "../output/json.js";import { convertToPdf, cleanupConversionFiles } from "../conversion/convertToPdf.js";import { cleanOcrTableArtifacts } from "../processing/textUtils.js";+/**+ * Main document parser class. Handles PDF parsing, OCR, format conversion,+ * and screenshot generation.+ *+ * @example Basic text extraction+ * ```typescript+ * import { LiteParse } from "@llamaindex/liteparse";+ *+ * const parser = new LiteParse();+ * const result = await parser.parse("document.pdf");+ * console.log(result.text);+ * ```+ *+ * @example JSON output with bounding boxes+ * ```typescript+ * const parser = new LiteParse({ outputFormat: "json", dpi: 300 });+ * const result = await parser.parse("document.pdf");+ * for (const page of result.json.pages) {+ * console.log(`Page ${page.page}: ${page.boundingBoxes.length} bounding boxes`);+ * }+ * ```+ *+ * @example Using an HTTP OCR server+ * ```typescript+ * const parser = new LiteParse({+ * ocrServerUrl: "http://localhost:8828/ocr",+ * ocrLanguage: "en",+ * });+ * const result = await parser.parse("scanned-document.pdf");+ * ```+ */export class LiteParse {private config: LiteParseConfig;private pdfEngine: PdfEngine;private ocrEngine?: OcrEngine;+ /**+ * Create a new LiteParse instance.+ *+ * @param userConfig - Partial configuration to override defaults. See {@link LiteParseConfig} for all options.+ */constructor(userConfig: Partial<LiteParseConfig> = {}) {// Merge user config with defaultsthis.config = mergeConfig(userConfig);@@ -37,7 +73,16 @@ export class LiteParse {}/**- * Parse a PDF file and return structured result+ * Parse a document and return the extracted text, page data, and optionally structured JSON.+ *+ * Supports PDFs natively. Non-PDF formats (DOCX, XLSX, images, etc.) are automatically+ * converted to PDF before parsing if the required system tools are installed.+ *+ * @param filePath - Path to the document file.+ * @param quiet - If `true`, suppresses progress logging to stderr.+ * @returns Parsed document data including text, per-page info, and optional JSON.+ *+ * @throws Error if the file cannot be found, converted, or parsed.*/async parse(filePath: string, quiet = false): Promise<ParseResult> {const log = (msg: string) => {@@ -130,7 +175,15 @@ export class LiteParse {}/**- * Generate screenshots of PDF pages+ * Generate screenshots of PDF pages as image buffers.+ *+ * Uses PDFium for high-quality rendering. Each page is returned as a+ * {@link ScreenshotResult} with the raw image buffer and dimensions.+ *+ * @param filePath - Path to the PDF file.+ * @param pageNumbers - 1-indexed page numbers to screenshot. If omitted, all pages are rendered.+ * @param quiet - If `true`, suppresses progress logging to stderr.+ * @returns Array of screenshot results, one per rendered page.*/async screenshot(filePath: string,@@ -340,7 +393,9 @@ export class LiteParse {}/**- * Get current configuration+ * Get a copy of the current configuration, including defaults merged with user overrides.+ *+ * @returns A shallow copy of the active {@link LiteParseConfig}.*/getConfig(): LiteParseConfig {return { ...this.config };diff --git a/src/core/types.ts b/src/core/types.tsindex 0ceaee6..0ba0aff 100644--- a/src/core/types.ts+++ b/src/core/types.ts@@ -1,55 +1,162 @@+/**+ * Supported output formats for parsed documents.+ *+ * - `"json"` — Structured JSON with per-page text items, bounding boxes, and metadata.+ * - `"text"` — Plain text with spatial layout preserved.+ */export type OutputFormat = "json" | "text";+/**+ * Configuration options for the {@link LiteParse} parser.+ *+ * All fields have sensible defaults. Pass a `Partial<LiteParseConfig>` to the+ * constructor to override only the options you need.+ *+ * @example+ * ```typescript+ * const parser = new LiteParse({+ * ocrEnabled: true,+ * ocrLanguage: "fra",+ * dpi: 300,+ * outputFormat: "json",+ * });+ * ```+ */export interface LiteParseConfig {- // OCR+ /**+ * OCR language code(s). Uses ISO 639-3 codes for Tesseract (e.g., `"eng"`, `"fra"`)+ * or ISO 639-1 for HTTP OCR servers (e.g., `"en"`, `"fr"`).+ *+ * @defaultValue `"en"`+ */ocrLanguage: string | string[];++ /**+ * Whether to run OCR on pages with little or no native text.+ * When enabled, LiteParse selectively OCRs only images and text-sparse regions.+ *+ * @defaultValue `true`+ */ocrEnabled: boolean;- // HTTP OCR Server (optional - if not provided, uses Tesseract)+ /**+ * URL of an HTTP OCR server implementing the LiteParse OCR API.+ * If not provided, the built-in Tesseract.js engine is used.+ *+ * @see {@link https://github.com/run-llama/liteparse/blob/main/OCR_API_SPEC.md | OCR API Specification}+ */ocrServerUrl?: string;- // page processing concurrency (number of pages to process in parallel per document)+ /**+ * Number of pages to OCR in parallel. Higher values use more memory but+ * process faster on multi-core machines.+ *+ * @defaultValue CPU cores - 1 (minimum 1)+ */numWorkers: number;- // Processing+ /**+ * Maximum number of pages to parse from the document.+ *+ * @defaultValue `1000`+ */maxPages: number;++ /**+ * Specific pages to parse, as a comma-separated string of page numbers and ranges.+ *+ * @example `"1-5,10,15-20"`+ */targetPages?: string;++ /**+ * DPI (dots per inch) for rendering pages to images. Higher values improve+ * OCR accuracy but increase processing time and memory usage.+ *+ * @defaultValue `150`+ */dpi: number;- // Output+ /**+ * Output format for parsed results.+ *+ * @defaultValue `"json"`+ */outputFormat: OutputFormat;- includeImages: boolean;- includeCharts: boolean;- // Features+ /**+ * Calculate precise bounding boxes for each text line. Disable for faster+ * parsing when bounding boxes aren't needed.+ *+ * @defaultValue `true`+ */preciseBoundingBox: boolean;- skipDiagonalText: boolean;++ /**+ * Preserve very small text that would normally be filtered out.+ *+ * @defaultValue `false`+ */preserveVerySmallText: boolean;++ /**+ * Maintain consistent text alignment across page boundaries.+ *+ * @defaultValue `false`+ */preserveLayoutAlignmentAcrossPages: boolean;}+/**+ * An individual text element extracted from a page, with position, size, and font metadata.+ *+ * Coordinates use the PDF coordinate system where the origin is at the top-left+ * of the page, x increases to the right, and y increases downward.+ */export interface TextItem {+ /** The text content of this item. */str: string;+ /** X coordinate of the top-left corner, in PDF points. */x: number;+ /** Y coordinate of the top-left corner, in PDF points. */y: number;+ /** Width of the text item in PDF points. */width: number;+ /** Height of the text item in PDF points. */height: number;- w: number; // Alias for width- h: number; // Alias for height+ /** Alias for {@link TextItem.width | width}. */+ w: number;+ /** Alias for {@link TextItem.height | height}. */+ h: number;+ /** Font name (e.g., `"Helvetica"`, `"Times-Roman"`, `"OCR"` for OCR-detected text). */fontName?: string;+ /** Font size in PDF points. */fontSize?: number;- r?: number; // Rotation angle in degrees (0, 90, 180, 270)- rx?: number; // Rotated x coordinate- ry?: number; // Rotated y coordinate+ /** Rotation angle in degrees. One of `0`, `90`, `180`, or `270`. */+ r?: number;+ /** X coordinate after rotation transformation. */+ rx?: number;+ /** Y coordinate after rotation transformation. */+ ry?: number;+ /** Markup annotations (highlights, underlines, etc.) applied to this text. */markup?: MarkupData;+ /** @internal Whether this item represents a vertical gap. */vgap?: boolean;+ /** @internal Whether this is a placeholder item used during layout. */isPlaceholder?: boolean;}+/**+ * Markup annotation data associated with a text item.+ */export interface MarkupData {+ /** Highlight color (e.g., `"yellow"`, `"#FFFF00"`), or `undefined` if not highlighted. */highlight?: string;+ /** Whether the text is underlined. */underline?: boolean;+ /** Whether the text has a squiggly underline. */squiggly?: boolean;+ /** Whether the text is struck out. */strikeout?: boolean;}@@ -83,6 +190,10 @@ export interface ProjectionTextBox {d?: number; // Delta for rotation handling}+/**+ * A rectangle defined by position and dimensions.+ * @internal+ */export interface Coordinates {x: number;y: number;@@ -90,37 +201,71 @@ export interface Coordinates {h: number;}+/**+ * Raw OCR detection result before conversion to {@link TextItem}.+ * @internal+ */export interface OcrData {x: number;y: number;w: number;h: number;+ /** Confidence score from 0.0 to 1.0. */confidence: number;+ /** Recognized text. */text: string;}+/**+ * An axis-aligned bounding box defined by its top-left and bottom-right corners.+ *+ * All coordinates are in PDF points.+ */export interface BoundingBox {+ /** X coordinate of the top-left corner. */x1: number;+ /** Y coordinate of the top-left corner. */y1: number;+ /** X coordinate of the bottom-right corner. */x2: number;+ /** Y coordinate of the bottom-right corner. */y2: number;}+/**+ * Parsed data for a single page of a document.+ */export interface ParsedPage {+ /** 1-indexed page number. */pageNum: number;+ /** Page width in PDF points. */width: number;+ /** Page height in PDF points. */height: number;+ /** Full text content of the page with spatial layout preserved. */text: string;+ /** Individual text elements extracted from the page. */textItems: TextItem[];+ /** Bounding boxes for text lines. Present when {@link LiteParseConfig.preciseBoundingBox} is enabled. */boundingBoxes?: BoundingBox[];}+/**+ * Structured JSON representation of parsed document data.+ * Returned when {@link LiteParseConfig.outputFormat} is `"json"`.+ */export interface ParseResultJson {+ /** Array of page data. */pages: Array<{+ /** 1-indexed page number. */page: number;+ /** Page width in PDF points. */width: number;+ /** Page height in PDF points. */height: number;+ /** Full text content of the page. */text: string;+ /** Individual text elements with position and font metadata. */textItems: Array<{text: string;x: number;@@ -130,20 +275,35 @@ export interface ParseResultJson {fontName?: string;fontSize?: number;}>;+ /** Bounding boxes for text lines. */boundingBoxes: BoundingBox[];}>;}+/**+ * The result of parsing a document with {@link LiteParse.parse}.+ */export interface ParseResult {+ /** Per-page parsed data. */pages: ParsedPage[];+ /** Full document text, concatenated from all pages. */text: string;+ /** Structured JSON data. Present when {@link LiteParseConfig.outputFormat} is `"json"`. */json?: ParseResultJson;}+/**+ * The result of generating a screenshot with {@link LiteParse.screenshot}.+ */export interface ScreenshotResult {+ /** 1-indexed page number. */pageNum: number;+ /** Image width in pixels. */width: number;+ /** Image height in pixels. */height: number;+ /** Raw image data as a Node.js Buffer (PNG or JPG). */imageBuffer: Buffer;+ /** File path if the screenshot was saved to disk. */imagePath?: string;}diff --git a/src/lib.ts b/src/lib.tsindex 1791d6e..2ea7879 100644--- a/src/lib.ts+++ b/src/lib.ts@@ -1,8 +1,26 @@+/**+ * @packageDocumentation+ *+ * LiteParse — open-source PDF parsing with spatial text extraction, OCR, and bounding boxes.+ *+ * @example+ * ```typescript+ * import { LiteParse } from "@llamaindex/liteparse";+ *+ * const parser = new LiteParse({ ocrEnabled: true });+ * const result = await parser.parse("document.pdf");+ * console.log(result.text);+ * ```+ */export { LiteParse } from "./core/parser.js";export type {LiteParseConfig,OutputFormat,ParseResult,+ ParseResultJson,+ ParsedPage,BoundingBox,TextItem,+ ScreenshotResult,+ MarkupData,} from "./core/types.js";diff --git a/test-config.json b/test-config.jsondeleted file mode 100644index a5b5529..0000000--- a/test-config.json+++ /dev/null@@ -1,6 +0,0 @@-{- "skipDiagonalText": true,- "ocrEnabled": false,- "outputFormat": "text",- "preserveLayoutAlignmentAcrossPages": false-}