@qrcommunication/gigapdf-lib 0.52.5 → 0.54.0

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/CHANGELOG.md CHANGED
@@ -4,6 +4,35 @@ All notable changes to `@qrcommunication/gigapdf-lib` are documented here.
4
4
  The format follows [Keep a Changelog](https://keepachangelog.com/) and the
5
5
  project adheres to [Semantic Versioning](https://semver.org/).
6
6
 
7
+ ## [0.54.0] - 2026-06-20
8
+
9
+ ### Added
10
+
11
+ - **OCR front-end restoration (no API change — automatic in `ocr`).** Before recognition the
12
+ engine now (1) **auto-crops a photographed page** — detects the document's four corners on a
13
+ contrasting background and perspective-warps it head-on (8×8 DLT homography + bilinear warp,
14
+ pure `std`), and (2) **flattens uneven illumination** (flat-field divide by a local background:
15
+ shadows/glare → uniform page). Both are **gated to no-op on already-clean scans**, so they only
16
+ help phone photos / creased paper. Rescues real-world captures with zero caller changes.
17
+ - **Chinese OCR — new `cjk` script.** `loadBundledOcrModel("cjk")` / `ALL_OCR_SCRIPTS` now load
18
+ `ocr_cjk.gpocr` (data-driven **2401-class** charset, 32/64/128 backbone) — **CER 0.206 on CASIA
19
+ handwritten Chinese**, the first CJK model shipped.
20
+ - **Japanese & Korean scripts declared** (`"japanese"`, `"korean"` → `ocr_jpn.gpocr` /
21
+ `ocr_kor.gpocr`). Their charsets include kana+kanji / Hangul **plus full ASCII** (mixed
22
+ alphanumerics). Models train upstream and land in a follow-up release — `loadBundledOcrModel`
23
+ now **returns `false` for an absent blob instead of throwing**, so `ALL_OCR_SCRIPTS` stays safe.
24
+ - **Handwriting & degraded variants** bundled: `ocr_alpha_hw.gpocr` (real-cursive, **beats
25
+ Tesseract on IAM — CER 0.309 vs 0.353**) and `ocr_alpha_photo.gpocr` (degradation-augmented,
26
+ beats the plain HW model on degraded input). Host-load via `loadOcrModel`.
27
+
28
+ ### Changed
29
+
30
+ - **Non-Latin models rebuilt at the 32/64/128 backbone** — Devanagari, Bengali, Tamil and
31
+ Arabic validation CER roughly **halved** (deva 0.039, beng 0.042, taml 0.011, arabic 0.030);
32
+ the bundled `.gpocr` blobs are updated. Capacity, not data, was the bound.
33
+ - **Faster real-dataset training downloads** (dev tooling): `hw_datasets.py` fetches line images
34
+ **concurrently** (`GIGA_OCR_DL_WORKERS`), ~16× quicker — pairs with an HF Pro token.
35
+
7
36
  ## [0.52.5] - 2026-06-19
8
37
 
9
38
  ### Added
package/dist/index.cjs CHANGED
@@ -25,12 +25,7 @@ __export(index_exports, {
25
25
  GigaPdfEngine: () => GigaPdfEngine
26
26
  });
27
27
  module.exports = __toCommonJS(index_exports);
28
-
29
- // node_modules/.pnpm/tsup@8.5.1_postcss@8.5.15_typescript@6.0.3/node_modules/tsup/assets/cjs_shims.js
30
- var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.tagName.toUpperCase() === "SCRIPT" ? document.currentScript.src : new URL("main.js", document.baseURI).href;
31
- var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
32
-
33
- // src/index.ts
28
+ var import_node_fs = require("./node-fs.js");
34
29
  var enc = new TextEncoder();
35
30
  var dec = new TextDecoder();
36
31
  var OCR_MODEL_FILES = {
@@ -38,14 +33,20 @@ var OCR_MODEL_FILES = {
38
33
  arabic: "ocr_arabic.gpocr",
39
34
  devanagari: "ocr_deva.gpocr",
40
35
  bengali: "ocr_beng.gpocr",
41
- tamil: "ocr_taml.gpocr"
36
+ tamil: "ocr_taml.gpocr",
37
+ cjk: "ocr_cjk.gpocr",
38
+ japanese: "ocr_jpn.gpocr",
39
+ korean: "ocr_kor.gpocr"
42
40
  };
43
41
  var ALL_OCR_SCRIPTS = [
44
42
  "alpha",
45
43
  "arabic",
46
44
  "devanagari",
47
45
  "bengali",
48
- "tamil"
46
+ "tamil",
47
+ "cjk",
48
+ "japanese",
49
+ "korean"
49
50
  ];
50
51
  var GigaPdfEngine = class _GigaPdfEngine {
51
52
  constructor(ex) {
@@ -97,15 +98,7 @@ var GigaPdfEngine = class _GigaPdfEngine {
97
98
  * for the consuming route so the `.wasm` is copied into the standalone bundle.
98
99
  */
99
100
  static async loadDefault() {
100
- const nodeImport = (m) => import(
101
- /* webpackIgnore: true */
102
- /* @vite-ignore */
103
- m
104
- );
105
- const { readFile } = await nodeImport("node:fs/promises");
106
- const { fileURLToPath } = await nodeImport("node:url");
107
- const wasmPath = fileURLToPath(new URL("../gigapdf.wasm", importMetaUrl));
108
- return _GigaPdfEngine.load(await readFile(wasmPath));
101
+ return _GigaPdfEngine.load(await (0, import_node_fs.loadDefaultWasmBytes)());
109
102
  }
110
103
  // ── linear-memory ABI helpers (internal) ─────────────────────────────────
111
104
  u8() {
@@ -424,20 +417,17 @@ var GigaPdfEngine = class _GigaPdfEngine {
424
417
  * the engine via {@link loadOcrModel}. **Node hosts only** — it reads the blob
425
418
  * from disk the same way {@link loadDefault} resolves the wasm. Returns `true`
426
419
  * on success. Use this to recognize non-Latin scripts (Arabic, Devanagari,
427
- * Bengali, Tamil) or to upgrade Latin/Cyrillic/Greek to the CRNN (`alpha`).
420
+ * Bengali, Tamil, Chinese `cjk`, Japanese, Korean) or to upgrade
421
+ * Latin/Cyrillic/Greek to the CRNN (`alpha`). Returns `false` (rather than
422
+ * throwing) when the blob isn't bundled in this release — e.g. a script still
423
+ * training upstream — so loading a set stays resilient.
428
424
  */
429
425
  async loadBundledOcrModel(script) {
430
- const nodeImport = (m) => import(
431
- /* webpackIgnore: true */
432
- /* @vite-ignore */
433
- m
434
- );
435
- const { readFile } = await nodeImport("node:fs/promises");
436
- const { fileURLToPath } = await nodeImport("node:url");
437
- const path = fileURLToPath(
438
- new URL(`../models/${OCR_MODEL_FILES[script]}`, importMetaUrl)
439
- );
440
- return this.loadOcrModel(await readFile(path));
426
+ try {
427
+ return this.loadOcrModel(await (0, import_node_fs.readModelFile)(OCR_MODEL_FILES[script]));
428
+ } catch {
429
+ return false;
430
+ }
441
431
  }
442
432
  /**
443
433
  * Load several bundled OCR models (idempotent per call). Returns the scripts
@@ -460,25 +450,9 @@ var GigaPdfEngine = class _GigaPdfEngine {
460
450
  * any model added later — with no code change. Returns the number loaded.
461
451
  */
462
452
  async loadAllBundledOcrModels() {
463
- const nodeImport = (m) => import(
464
- /* webpackIgnore: true */
465
- /* @vite-ignore */
466
- m
467
- );
468
- const { readFile, readdir } = await nodeImport("node:fs/promises");
469
- const { fileURLToPath } = await nodeImport("node:url");
470
- let entries;
471
- try {
472
- entries = await readdir(fileURLToPath(new URL("../models/", importMetaUrl)));
473
- } catch {
474
- return 0;
475
- }
453
+ const models = await (0, import_node_fs.readModelsDir)();
476
454
  let count = 0;
477
- for (const name of entries) {
478
- if (!name.endsWith(".gpocr")) continue;
479
- const bytes = await readFile(
480
- fileURLToPath(new URL(`../models/${name}`, importMetaUrl))
481
- );
455
+ for (const { bytes } of models) {
482
456
  if (this.loadOcrModel(bytes)) count += 1;
483
457
  }
484
458
  return count;