@arcships/light-ocr 0.5.5 → 0.5.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +279 -11
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -1,31 +1,299 @@
1
1
  # @arcships/light-ocr
2
2
 
3
- The stable PP-OCRv6 Small entry for local image and PDF OCR on Node.js 22 and 24.
3
+ [![npm version](https://img.shields.io/npm/v/%40arcships%2Flight-ocr?color=CB3837)](https://www.npmjs.com/package/@arcships/light-ocr)
4
+ [![Node.js 22 and 24](https://img.shields.io/badge/Node.js-22%20%7C%2024-339933)](https://nodejs.org/)
5
+ [![Apache-2.0](https://img.shields.io/npm/l/%40arcships%2Flight-ocr)](https://github.com/arcships/light-ocr/blob/main/LICENSE)
6
+
7
+ ![light-ocr](https://raw.githubusercontent.com/arcships/light-ocr/main/docs/assets/light-ocr-banner.png)
8
+
9
+ **Offline image and PDF OCR for Node.js — prebuilt, typed, and
10
+ self-contained.**
11
+
12
+ `@arcships/light-ocr` is the stable PP-OCRv6 Small package. It recognizes
13
+ JPEG, PNG, PDF, decoded pixels, and multi-page image jobs without Python,
14
+ cloud APIs, postinstall downloads, or local native compilation.
15
+
16
+ | | |
17
+ | --- | --- |
18
+ | **Input** | JPEG, PNG, PDF, `Uint8Array`, or decoded pixel buffers |
19
+ | **Output** | text lines in reading order, confidence, quadrilateral boxes, and timing |
20
+ | **Runtime** | CommonJS + ESM + bundled TypeScript declarations |
21
+ | **Platforms** | macOS, Linux glibc, and Windows on x64 and ARM64 |
22
+ | **Node.js** | 22 and 24 |
23
+
24
+ ## Install
4
25
 
5
26
  ```bash
6
27
  npm install @arcships/light-ocr
28
+ ```
29
+
30
+ That single command installs the Small model, shared JavaScript runtime, and
31
+ the native OCR/PDF package matching the current platform. The package has no
32
+ install script and remains installable with scripts disabled.
33
+
34
+ ## Quick start
35
+
36
+ ### Recognize an image
37
+
38
+ ```js
39
+ import { createEngine } from "@arcships/light-ocr";
40
+ import { readFile } from "node:fs/promises";
41
+
42
+ const engine = await createEngine();
43
+
44
+ try {
45
+ const result = await engine.recognizeEncoded(
46
+ await readFile("receipt.png"),
47
+ );
48
+
49
+ for (const line of result.lines) {
50
+ console.log(line.text, line.confidence, line.box);
51
+ }
52
+ } finally {
53
+ await engine.close();
54
+ }
55
+ ```
56
+
57
+ CommonJS uses the same API:
58
+
59
+ ```js
60
+ const { createEngine } = require("@arcships/light-ocr");
61
+ ```
62
+
63
+ ### Stream pages from a PDF
64
+
65
+ ```js
66
+ import { recognizeDocument } from "@arcships/light-ocr";
67
+
68
+ for await (const page of recognizeDocument("report.pdf", {
69
+ dpi: 200,
70
+ pageRange: { start: 1, end: 10 },
71
+ })) {
72
+ console.log(`page ${page.index + 1}`);
73
+ for (const line of page.lines) console.log(line.text);
74
+ }
75
+ ```
76
+
77
+ `recognizeDocument()` accepts a file path, PDF/image bytes, or an array of
78
+ image paths and byte buffers. Pages are yielded as they finish, so callers do
79
+ not need to retain the complete document result.
80
+
81
+ ### Use the CLI
82
+
83
+ The `light-ocr` command is included:
84
+
85
+ ```bash
86
+ # Image OCR
7
87
  light-ocr image.png --format text
88
+
89
+ # PDF OCR; PDFium and the fallback font are already installed
8
90
  light-ocr report.pdf --pages 1-10 --format jsonl
91
+
92
+ # Multiple images as one document
93
+ light-ocr document scan-1.png scan-2.png scan-3.png --format text
94
+
95
+ # Detection only
96
+ light-ocr detect screenshot.png
97
+
98
+ # Voluntary hardware/provider diagnostics
9
99
  light-ocr doctor --json
10
100
  ```
11
101
 
12
- The package exact-pins one model-free runtime, the Small model, and the native
13
- component and PDFium renderer for the current platform. It has no install
14
- script and its complete release closure is tested with npm offline and scripts
15
- disabled.
102
+ ## Everything needed for PDF OCR is included
103
+
104
+ The package does not defer essential files to an installer or first-run
105
+ download:
106
+
107
+ | Component | Distribution |
108
+ | --- | --- |
109
+ | PP-OCRv6 Small model | exact-pinned required npm dependency |
110
+ | JavaScript runtime and types | exact-pinned required npm dependency |
111
+ | Native OCR addon and runtime libraries | matching platform npm dependency |
112
+ | PDFium addon and shared library | inside the matching platform package |
113
+ | Noto Sans SC fallback font and OFL license | inside the matching platform package |
114
+
115
+ The bundled, checksum-pinned fallback font is used when a PDF references a
116
+ common Chinese font without embedding its glyphs. PDFium therefore renders the
117
+ page correctly before OCR instead of handing missing-glyph boxes to the model.
118
+
119
+ There is no postinstall fetch, runtime font/model/PDFium download, GitHub
120
+ access, compiler requirement, or system Chinese-font requirement on customer
121
+ machines.
122
+
123
+ ## Node.js API
124
+
125
+ ### Main exports
126
+
127
+ | Export | Purpose |
128
+ | --- | --- |
129
+ | `createEngine(options?)` | Create a reusable image OCR engine |
130
+ | `recognizeDocument(source, options?)` | Stream PDF or image pages with automatic cleanup |
131
+ | `createDocumentEngine(options?)` | Reuse one engine across multiple document jobs |
132
+ | `hasPdfSupport()` | Check that the bundled PDF renderer can be loaded |
133
+ | `modelProfile` | Inspect the selected model tier and language metadata |
134
+ | `OcrError` | Stable typed error with a machine-readable `code` |
135
+
136
+ ### Recognize decoded pixels
137
+
138
+ Applications that already decode images can avoid re-encoding:
139
+
140
+ ```js
141
+ const result = await engine.recognize({
142
+ data: rgbaBytes,
143
+ width,
144
+ height,
145
+ stride: width * 4,
146
+ pixelFormat: "rgba8",
147
+ });
148
+ ```
149
+
150
+ Supported pixel formats are `gray8`, `rgb8`, `bgr8`, and `rgba8`.
151
+
152
+ ### Region, cancellation, and execution provider
16
153
 
17
154
  ```js
18
- const { createEngine } = require('@arcships/light-ocr');
155
+ const controller = new AbortController();
156
+
157
+ const engine = await createEngine({
158
+ execution: { provider: "auto" },
159
+ queueCapacity: 4,
160
+ });
19
161
 
20
- const engine = await createEngine();
21
162
  try {
22
- const result = await engine.recognizeEncoded(imageBytes);
163
+ const result = await engine.recognizeEncoded(imageBytes, {
164
+ region: { x: 100, y: 80, width: 640, height: 320 },
165
+ applyExif: true,
166
+ signal: controller.signal,
167
+ });
168
+
23
169
  console.log(result.lines);
170
+ console.log(engine.info.execution.selectionTrace);
24
171
  } finally {
25
172
  await engine.close();
26
173
  }
27
174
  ```
28
175
 
29
- The main package exports `recognizeDocument()` and `createDocumentEngine()`.
30
- PDFium's native files are inside the platform npm package, so neither install
31
- nor runtime performs a secondary download.
176
+ Recognition runs on a dedicated worker instead of blocking the JavaScript main
177
+ thread. Queues are bounded, `AbortSignal` is supported, and engines must be
178
+ closed explicitly when the application is finished with them.
179
+
180
+ ### Document resource limits
181
+
182
+ PDF and multi-page calls apply conservative defaults before or during
183
+ rendering:
184
+
185
+ | Option | Default |
186
+ | --- | ---: |
187
+ | `dpi` | 150 |
188
+ | `maxFileBytes` | 100 MiB per input |
189
+ | `maxPages` | 100 |
190
+ | `maxPagePixels` | 4096 × 4096 |
191
+ | `maxTotalPixels` | 100 Mi pixels |
192
+
193
+ Limits are configurable per call. Violations reject with
194
+ `OcrError.code === "resource_limit_exceeded"`.
195
+
196
+ ### Result shape
197
+
198
+ Image OCR returns one line entry per recognized line:
199
+
200
+ ```json
201
+ {
202
+ "text": "TOTAL 42.00",
203
+ "confidence": 0.98,
204
+ "box": [
205
+ { "x": 24, "y": 80 },
206
+ { "x": 190, "y": 80 },
207
+ { "x": 190, "y": 108 },
208
+ { "x": 24, "y": 108 }
209
+ ]
210
+ }
211
+ ```
212
+
213
+ Coordinates use `pageSpace`: top-left origin, positive x to the right, and
214
+ positive y downward after EXIF correction. Document pages add a stable page
215
+ index, source metadata, dimensions, applied PDF transforms, and timing.
216
+
217
+ ## CLI reference
218
+
219
+ | Command | Purpose |
220
+ | --- | --- |
221
+ | `light-ocr [recognize] <image>` | Full image OCR; `recognize` is optional |
222
+ | `light-ocr <document.pdf>` | Stream a PDF through document OCR |
223
+ | `light-ocr document <source...>` | Process a PDF or multiple page images |
224
+ | `light-ocr detect <image>` | Return text-region boxes without recognition |
225
+ | `light-ocr info --version` | Print package/Core version information |
226
+ | `light-ocr info --model-info` | Print model and execution information |
227
+ | `light-ocr doctor --json` | Print voluntary system/provider diagnostics |
228
+
229
+ Image OCR supports `--format json|jsonl|text`, `--region x,y,w,h`,
230
+ `--provider auto|cpu|apple|webgpu`, `--stdin`, and automatic EXIF correction.
231
+ Document OCR adds `--pages N-M`, `--dpi`, and the page/file/pixel limit flags.
232
+
233
+ `detect` always emits structured JSON and does not accept `--format`.
234
+ Diagnostics do not include the hostname or a stable device identifier.
235
+
236
+ ## Platform acceleration
237
+
238
+ The default `provider: "auto"` chooses a qualified accelerator when available
239
+ and ends with CPU as the stable fallback:
240
+
241
+ | Platform | Auto path |
242
+ | --- | --- |
243
+ | macOS 15+ on Apple Silicon | Core ML, then CPU |
244
+ | macOS on Intel | CPU |
245
+ | Linux x64 with glibc | WebGPU through Vulkan, then CPU |
246
+ | Linux arm64 with glibc | CPU |
247
+ | Windows x64 | WebGPU through D3D12, then CPU |
248
+ | Windows arm64 | CPU |
249
+
250
+ Explicit `cpu`, `apple`, and `webgpu` requests fail closed when the requested
251
+ provider is unavailable; they do not silently switch providers.
252
+
253
+ ## Model tiers
254
+
255
+ This package is the stable Small tier. Tiny and Medium are opt-in previews with
256
+ the same API, types, result schema, and error model:
257
+
258
+ | Tier | Install | Model payload | Status |
259
+ | --- | --- | ---: | --- |
260
+ | Small | `npm install @arcships/light-ocr` | about 30 MB | stable default |
261
+ | Tiny | `npm install @arcships/light-ocr-tiny@next` | about 6.3 MB | preview; 49 languages, no Japanese |
262
+ | Medium | `npm install @arcships/light-ocr-medium@next` | about 139 MB | preview; quality-first |
263
+
264
+ Each facade installs only its selected model.
265
+
266
+ ## Errors and diagnostics
267
+
268
+ Expected failures reject with `OcrError` and a stable `code`, including
269
+ `invalid_argument`, `invalid_image`, `resource_limit_exceeded`,
270
+ `package_load_failed`, and `inference_failed`.
271
+
272
+ For environment reports:
273
+
274
+ ```bash
275
+ light-ocr doctor --json
276
+ ```
277
+
278
+ For package/PDF capability checks:
279
+
280
+ ```js
281
+ import { hasPdfSupport, modelProfile } from "@arcships/light-ocr";
282
+
283
+ console.log(hasPdfSupport());
284
+ console.log(modelProfile);
285
+ ```
286
+
287
+ ## Documentation
288
+
289
+ - [Project overview](https://github.com/arcships/light-ocr)
290
+ - [Node.js and CLI reference](https://github.com/arcships/light-ocr/blob/main/bindings/node/README.md)
291
+ - [PDF 0.5.6 release notes](https://github.com/arcships/light-ocr/blob/main/docs/releases/npm-0.5.6.en.md)
292
+ - [Agent Skill](https://github.com/arcships/light-ocr/blob/main/.agents/skills/local-ocr/SKILL.md)
293
+ - [Changelog](https://github.com/arcships/light-ocr/blob/main/CHANGELOG.md)
294
+ - [Issues](https://github.com/arcships/light-ocr/issues)
295
+
296
+ ## License
297
+
298
+ Apache-2.0. The package also carries the applicable licenses and notices for
299
+ the bundled PP-OCRv6 model, native runtimes, PDFium, and Noto Sans SC font.
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  },
8
8
  "dependencies": {
9
9
  "@arcships/light-ocr-model-ppocrv6-small": "0.3.4",
10
- "@arcships/light-ocr-runtime": "0.1.5"
10
+ "@arcships/light-ocr-runtime": "0.1.6"
11
11
  },
12
12
  "description": "Offline image and PDF OCR for Node.js — the stable PP-OCRv6 Small tier",
13
13
  "engines": {
@@ -42,5 +42,5 @@
42
42
  },
43
43
  "type": "commonjs",
44
44
  "types": "./src/index.d.ts",
45
- "version": "0.5.5"
45
+ "version": "0.5.6"
46
46
  }