Files
Lin Manhui 1fc8b98180 [Feat] PaddleOCR.js (#17861)
* chore: import paddleocr-js subproject skeleton

Made-with: Cursor

* refactor: rename internal paddleocr-js workspaces

Made-with: Cursor

* fix: remove stale paddleocr-js workspace lock entries

Made-with: Cursor

* docs: rewrite paddleocr-js subproject docs

Made-with: Cursor

* test: fix ocr shared lint regression

Made-with: Cursor

* chore: add low-coupling paddleocr-js host integration

Made-with: Cursor

* Update docs

* Add langchain-paddleocr to skip gpu condition

* Skip subprojects

* Update lock

* docs(paddleocr-js): add TypeScript migration design spec

Made-with: Cursor

* docs(paddleocr-js): add TypeScript migration implementation plan

Made-with: Cursor

* build(paddleocr-js): add TypeScript toolchain and build infrastructure

Set up the TypeScript migration foundation:
- Add TypeScript, vite-plugin-dts, and type definitions as devDependencies
- Create tsconfig.json files (core, test, root project references)
- Configure Vite library build with ES/CJS/UMD outputs and .d.ts generation
- Update package.json entry points from src/ to dist/ with proper exports map
- Replace plain JS ESLint config with typescript-eslint strict type-checked rules
- Update Vitest coverage to target .ts files
- Add typecheck script, engines, keywords across workspace packages

Made-with: Cursor

* fix(paddleocr-js): exclude config files from strict TS lint, reorder exports types-first

Made-with: Cursor

* refactor(paddleocr-js): add third-party type declarations for clipper-lib and opencv

Minimal .d.ts files covering only the APIs actually used by the project.

Made-with: Cursor

* refactor(paddleocr-js): convert Layer 0-1 modules to TypeScript

Converts utils/common, worker/protocol, pipelines/ocr/default-config,
pipelines/ocr/runtime-params, runtime/opencv, runtime/ort,
runtime/index, and models/common from .js to .ts with full type
annotations.

Made-with: Cursor

* refactor(paddleocr-js): convert Layer 2 modules to TypeScript

Converts models/det, models/rec, models/index, resources/tar,
resources/cache, resources/registry, resources/standard-model,
resources/index, platform/browser, and platform/worker from .js to .ts
with interfaces for all model configs, results, and platform types.

Made-with: Cursor

* refactor(paddleocr-js): convert Layer 3-4 modules to TypeScript

Converts worker/client, worker/entry, pipelines/ocr/config,
pipelines/ocr/shared, pipelines/ocr/core, pipelines/ocr/worker-backed,
and pipelines/ocr/worker-entry from .js to .ts with full type
annotations for pipeline options, results, and initialization state.

Made-with: Cursor

* refactor(paddleocr-js): convert Layer 5 modules to TypeScript and add types/index.ts

Converts pipelines/ocr/index, pipelines/index, and src/index from .js
to .ts. Creates src/types/index.ts re-exporting all public-facing types.
Fixes all TypeScript errors (strict mode + verbatimModuleSyntax clean).

Made-with: Cursor

* refactor(paddleocr-js): convert test files to TypeScript

- Renamed all 29 test files from .js to .ts
- Added type annotations to test helpers and mocks
- Fixed barrel import in core.ts to maintain mock interceptability
- Restored createWorker: null in resolveWorkerOptions for API contract
- Updated public-api test to import from source directly

All 154 tests pass.

Made-with: Cursor

* fix(paddleocr-js): fix Vite build worker format and demo alias

- Add worker.format: 'es' to core vite config (fixes UMD build conflict)
- Add resolve alias in demo vite config to resolve paddleocr-js to source

Made-with: Cursor

* fix(paddleocr-js): resolve all ESLint strict type-checked errors

- Remove unnecessary optional chains, type assertions, and type conversions
- Remove unused type imports
- Fix floating promises, non-Error throws, and catch variable types
- Widen SourceToMatFn to accept sync or async returns
- Update tests to match sync dispose() and sourcePayloadToMat()

96 lint errors -> 0. All 154 tests pass.

Made-with: Cursor

* Update docs

* Remove AI docs

* Update node version bound

* Polish typing

* Fix bugs

* Fix doc

* Rename paddleocr-js to @paddleocr/paddleocr-js

* FIx CI

* Fix CI bug

* Fix git workflow

* Add viz utility design spec for paddleocr-js

Design document for an optional visualization module exported via
@paddleocr/paddleocr-js/viz subpath. Renders side-by-side composite
images (source + detection boxes | white panel + recognized text) with
custom font support and Blob export for browser download.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* docs(viz): add implementation plan for viz utility

11-task TDD plan covering types, color generation, canvas factory,
font management, box drawing, text drawing, side-by-side assembly,
OcrVisualizer class, subpath entry, build config, and final check.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* feat(viz): add foundational types for viz utility

Define RgbColor, FontConfig, BoxStyleOptions, and OcrVisualizerOptions
interfaces that will be shared across all viz module files. Include
type-level test coverage.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* feat(viz): add deterministic color generation via LCG

Extract the Linear Congruential Generator color function from the demo
app into the core viz utility so all consumers produce visually
consistent box colors for the same detection index.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Add canvas factory abstraction for viz module

Provides createCanvas, getContext2D, and canvasToBlob that abstract
over OffscreenCanvas vs HTMLCanvasElement differences, enabling the
viz module to work in both main-thread and web worker contexts.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Add font management utilities for viz (Task 4)

Implement loadFontFace/removeFontFace wrappers around the browser
FontFace API, with full test coverage using jsdom mocks.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Add draw-boxes panel for viz module (Task 5)

Draws the left panel of the side-by-side OCR visualization: source image
overlaid with colored detection box polygons. Uses save/restore for clean
state management and supports custom color functions.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* feat(viz): add right-panel text drawing

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* feat(viz): add side-by-side composite assembly

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* feat(viz): add OcrVisualizer class and renderOcrToBlob

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* feat(viz): add subpath entry point and public exports

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* build(viz): add viz subpath entry to Vite build and package.json exports

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* chore(viz): fix lint and formatting

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* feat(viz): update demo app and docs for viz module

- Replace demo's local deterministicColor with viz module import
- Add "Download Result" button to demo using OcrVisualizer.toBlob()
- Document viz subpath in README.md and README_cn.md
- Add viz to Package Layout and API sections

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* refactor: improve viz module, core SDK internals, and test coverage

- Refine draw-boxes rendering and font loading in viz module
- Improve type exports and internal module organization across
  models, pipelines, resources, runtime, platform, and worker layers
- Update test suite for cache, models, pipeline, runtime, worker-backed,
  and worker-client modules

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* docs: fix documentation accuracy across 6 files and add changeset

- Move visualization section before API reference in SDK READMEs (EN/CN)
- Add deterministicColor usage description to viz docs
- Add src/viz, src/types, src/utils to package layout sections
- Fix ESLint rule level: test files use recommendedTypeChecked
- Remove non-existent index.umd.js; add viz.mjs/viz.cjs to build outputs
- Correct worker WASM inflation size from ~78 MB to ~50 MB
- Add changeset for 0.2.0 minor release

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* chore: release @paddleocr/paddleocr-js v0.2.0

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: add paths mapping to tsconfig.eslint.json and demo tsconfig

Add @paddleocr/paddleocr-js and @paddleocr/paddleocr-js/viz paths
to tsconfig.eslint.json so IDE ESLint can resolve SDK types without
depending on workspace symlinks. Also add the viz subpath mapping
to apps/demo/tsconfig.json.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: add viz subpath alias to demo Vite dev config

Vite resolve.alias needs an explicit entry for the viz subpath —
tsconfig paths only affect TypeScript, not Vite's module resolution.
The more specific path is listed first to avoid prefix matching.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* refactor(demo): replace canvas rendering with viz module side-by-side output

Use OcrVisualizer.toBlob() to render detection boxes and recognized text
as a composite image displayed via <img>, replacing the manual canvas
drawing and removing the Download Result button. Configure PingFang SC
font from CDN for proper CJK text rendering in visualizations.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Fix bugs

* Remove superpowers docs

* Fix bugs

* Fix bug

* Refactor

* Fix bugs

* refactor: move cropByPoly from models/det to pipelines/ocr/crop

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* refactor: unify DetModel interface to predict(cv, mats, overrides)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* refactor: unify RecModel interface to predict(cv, mats, overrides)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* refactor: restructure getOcrRuntimeParams return into { det, rec, pipeline }

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* refactor: simplify OcrPipelineRunner.predict to pure orchestration

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Refactor

* Fix code style

* Fix and update

* Fix and update

* Bump to 0.3.0

* Remove v6

* Bump to v0.3.1

* Fix default paramter

* variant -> preset

* Add to mkdocs

* Update docs and add license headers

* Remove unused

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-20 21:53:27 +08:00

69 lines
1.9 KiB
JSON

{
"name": "paddleocr-js-workspace",
"version": "0.1.0",
"private": true,
"type": "module",
"repository": {
"type": "git",
"url": "https://github.com/PaddlePaddle/PaddleOCR.git",
"directory": "paddleocr-js"
},
"homepage": "https://github.com/PaddlePaddle/PaddleOCR/tree/main/paddleocr-js",
"bugs": {
"url": "https://github.com/PaddlePaddle/PaddleOCR/issues"
},
"keywords": [
"paddleocr",
"ocr",
"monorepo",
"browser-ocr",
"typescript"
],
"engines": {
"node": ">=20.11"
},
"workspaces": [
"packages/*",
"apps/*"
],
"scripts": {
"dev:demo": "npm run dev --workspace apps/demo --",
"build": "npm run build:sdk && npm run build:demo",
"build:demo": "npm run build --workspace apps/demo",
"build:sdk": "npm run build --workspace packages/core",
"preview:demo": "npm run preview --workspace apps/demo --",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"typecheck": "npm run typecheck --workspaces --if-present",
"test": "vitest run",
"test:coverage": "vitest run --coverage",
"test:watch": "vitest",
"format": "prettier . --write",
"format:check": "prettier . --check",
"clean": "rm -rf packages/*/dist apps/*/dist",
"check": "npm run format:check && npm run lint && npm run build:sdk && npm run typecheck && npm run test && npm run build:demo",
"release": "npm run build:sdk && npm publish --workspace packages/core"
},
"devDependencies": {
"@eslint/js": "^10.0.1",
"@vitest/coverage-v8": "^3.2.4",
"eslint": "^10.0.2",
"globals": "^17.4.0",
"husky": "^9.1.7",
"jsdom": "^26.1.0",
"lint-staged": "^16.3.2",
"prettier": "^3.8.1",
"typescript-eslint": "^8.57.2",
"vitest": "^3.2.4"
},
"lint-staged": {
"*.{js,ts}": [
"eslint --fix",
"prettier --write"
],
"*.{json,md,html,css,yaml,yml}": [
"prettier --write"
]
}
}