@qrcommunication/gigapdf-lib 0.43.0 → 0.44.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 +23 -0
- package/dist/index.cjs +80 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +35 -1
- package/dist/index.d.ts +35 -1
- package/dist/index.js +79 -0
- package/dist/index.js.map +1 -1
- package/gigapdf.wasm +0 -0
- package/models/ocr_alpha.gpocr +0 -0
- package/models/ocr_alpha_print.gpocr +0 -0
- package/models/ocr_taml.gpocr +0 -0
- package/package.json +3 -1
package/dist/index.d.cts
CHANGED
|
@@ -18,6 +18,17 @@ type Exports = {
|
|
|
18
18
|
gp_free(ptr: number, len: number): void;
|
|
19
19
|
[k: string]: any;
|
|
20
20
|
};
|
|
21
|
+
/**
|
|
22
|
+
* A trained per-script OCR model bundled with the package. `alpha` covers
|
|
23
|
+
* Latin, Cyrillic and Greek; `arabic` is the **RTL group** (Arabic, Urdu,
|
|
24
|
+
* Hebrew); the rest are dedicated scripts. The matching `.gpocr` CRNN blob
|
|
25
|
+
* ships under `models/` and is host-loaded on demand. To recognize any shipped
|
|
26
|
+
* language at once (including models added later), prefer
|
|
27
|
+
* {@link GigaPdfEngine.loadAllBundledOcrModels}.
|
|
28
|
+
*/
|
|
29
|
+
type OcrScript = "alpha" | "arabic" | "devanagari" | "bengali" | "tamil";
|
|
30
|
+
/** Every trained script — load all for "recognize text in any language". */
|
|
31
|
+
declare const ALL_OCR_SCRIPTS: readonly OcrScript[];
|
|
21
32
|
/** Loaded engine module. Create documents with {@link open} / {@link openEncrypted}. */
|
|
22
33
|
declare class GigaPdfEngine {
|
|
23
34
|
private readonly ex;
|
|
@@ -169,6 +180,29 @@ declare class GigaPdfEngine {
|
|
|
169
180
|
loadOcrModel(model: Uint8Array): boolean;
|
|
170
181
|
/** Drop every runtime-loaded OCR model (reverts to the mono-glyph classifier). */
|
|
171
182
|
clearOcrModels(): void;
|
|
183
|
+
/**
|
|
184
|
+
* Resolve a bundled `.gpocr` model (shipped under `models/`) and load it into
|
|
185
|
+
* the engine via {@link loadOcrModel}. **Node hosts only** — it reads the blob
|
|
186
|
+
* from disk the same way {@link loadDefault} resolves the wasm. Returns `true`
|
|
187
|
+
* on success. Use this to recognize non-Latin scripts (Arabic, Devanagari,
|
|
188
|
+
* Bengali, Tamil) or to upgrade Latin/Cyrillic/Greek to the CRNN (`alpha`).
|
|
189
|
+
*/
|
|
190
|
+
loadBundledOcrModel(script: OcrScript): Promise<boolean>;
|
|
191
|
+
/**
|
|
192
|
+
* Load several bundled OCR models (idempotent per call). Returns the scripts
|
|
193
|
+
* that loaded successfully. Pass {@link ALL_OCR_SCRIPTS} to recognize text in
|
|
194
|
+
* any supported language; the engine's script detector routes each line to the
|
|
195
|
+
* right model.
|
|
196
|
+
*/
|
|
197
|
+
loadBundledOcrModels(scripts: readonly OcrScript[]): Promise<OcrScript[]>;
|
|
198
|
+
/**
|
|
199
|
+
* Discover and load EVERY bundled `.gpocr` model (Node hosts only). The
|
|
200
|
+
* engine's script detector then routes each recognized line to the matching
|
|
201
|
+
* model, so the OCR recognizes text in any shipped script — Latin, Cyrillic,
|
|
202
|
+
* Greek, Arabic, Urdu, Hebrew (the RTL group), Devanagari, Bengali, Tamil, and
|
|
203
|
+
* any model added later — with no code change. Returns the number loaded.
|
|
204
|
+
*/
|
|
205
|
+
loadAllBundledOcrModels(): Promise<number>;
|
|
172
206
|
fontCatalog(): FontInfo[];
|
|
173
207
|
/** Google Fonts CSS2 URL for a family/weight/italic (host fetches it). */
|
|
174
208
|
fontRequestUrl(family: string, weight?: number, italic?: boolean): string;
|
|
@@ -951,4 +985,4 @@ declare class GigaPdfDoc {
|
|
|
951
985
|
}): boolean;
|
|
952
986
|
}
|
|
953
987
|
|
|
954
|
-
export { type AnnotationInfo, type Attachment, type Box, type DecodedImage, type Element, type EmbeddedFont, type FieldInfo, type FieldKind, type FieldStyle, type FontInfo, GigaPdfDoc, GigaPdfEngine, type HtmlFont, type HtmlFontRequest, type HtmlMargins, type HtmlRenderOptions, type HtmlResource, type HtmlResourceNeed, type ImageElementInfo, type LayerInfo, type LinkInfo, type NamedDest, type OcrWord, type OutlineEntry, type PageInfo, type PathSegment, type RadioOption, type SearchHit, type SignP12Options, type TextElementInfo, type TextLine, type TextRunInfo, type VectorPathInfo, type XlsxSheet };
|
|
988
|
+
export { ALL_OCR_SCRIPTS, type AnnotationInfo, type Attachment, type Box, type DecodedImage, type Element, type EmbeddedFont, type FieldInfo, type FieldKind, type FieldStyle, type FontInfo, GigaPdfDoc, GigaPdfEngine, type HtmlFont, type HtmlFontRequest, type HtmlMargins, type HtmlRenderOptions, type HtmlResource, type HtmlResourceNeed, type ImageElementInfo, type LayerInfo, type LinkInfo, type NamedDest, type OcrScript, type OcrWord, type OutlineEntry, type PageInfo, type PathSegment, type RadioOption, type SearchHit, type SignP12Options, type TextElementInfo, type TextLine, type TextRunInfo, type VectorPathInfo, type XlsxSheet };
|
package/dist/index.d.ts
CHANGED
|
@@ -18,6 +18,17 @@ type Exports = {
|
|
|
18
18
|
gp_free(ptr: number, len: number): void;
|
|
19
19
|
[k: string]: any;
|
|
20
20
|
};
|
|
21
|
+
/**
|
|
22
|
+
* A trained per-script OCR model bundled with the package. `alpha` covers
|
|
23
|
+
* Latin, Cyrillic and Greek; `arabic` is the **RTL group** (Arabic, Urdu,
|
|
24
|
+
* Hebrew); the rest are dedicated scripts. The matching `.gpocr` CRNN blob
|
|
25
|
+
* ships under `models/` and is host-loaded on demand. To recognize any shipped
|
|
26
|
+
* language at once (including models added later), prefer
|
|
27
|
+
* {@link GigaPdfEngine.loadAllBundledOcrModels}.
|
|
28
|
+
*/
|
|
29
|
+
type OcrScript = "alpha" | "arabic" | "devanagari" | "bengali" | "tamil";
|
|
30
|
+
/** Every trained script — load all for "recognize text in any language". */
|
|
31
|
+
declare const ALL_OCR_SCRIPTS: readonly OcrScript[];
|
|
21
32
|
/** Loaded engine module. Create documents with {@link open} / {@link openEncrypted}. */
|
|
22
33
|
declare class GigaPdfEngine {
|
|
23
34
|
private readonly ex;
|
|
@@ -169,6 +180,29 @@ declare class GigaPdfEngine {
|
|
|
169
180
|
loadOcrModel(model: Uint8Array): boolean;
|
|
170
181
|
/** Drop every runtime-loaded OCR model (reverts to the mono-glyph classifier). */
|
|
171
182
|
clearOcrModels(): void;
|
|
183
|
+
/**
|
|
184
|
+
* Resolve a bundled `.gpocr` model (shipped under `models/`) and load it into
|
|
185
|
+
* the engine via {@link loadOcrModel}. **Node hosts only** — it reads the blob
|
|
186
|
+
* from disk the same way {@link loadDefault} resolves the wasm. Returns `true`
|
|
187
|
+
* on success. Use this to recognize non-Latin scripts (Arabic, Devanagari,
|
|
188
|
+
* Bengali, Tamil) or to upgrade Latin/Cyrillic/Greek to the CRNN (`alpha`).
|
|
189
|
+
*/
|
|
190
|
+
loadBundledOcrModel(script: OcrScript): Promise<boolean>;
|
|
191
|
+
/**
|
|
192
|
+
* Load several bundled OCR models (idempotent per call). Returns the scripts
|
|
193
|
+
* that loaded successfully. Pass {@link ALL_OCR_SCRIPTS} to recognize text in
|
|
194
|
+
* any supported language; the engine's script detector routes each line to the
|
|
195
|
+
* right model.
|
|
196
|
+
*/
|
|
197
|
+
loadBundledOcrModels(scripts: readonly OcrScript[]): Promise<OcrScript[]>;
|
|
198
|
+
/**
|
|
199
|
+
* Discover and load EVERY bundled `.gpocr` model (Node hosts only). The
|
|
200
|
+
* engine's script detector then routes each recognized line to the matching
|
|
201
|
+
* model, so the OCR recognizes text in any shipped script — Latin, Cyrillic,
|
|
202
|
+
* Greek, Arabic, Urdu, Hebrew (the RTL group), Devanagari, Bengali, Tamil, and
|
|
203
|
+
* any model added later — with no code change. Returns the number loaded.
|
|
204
|
+
*/
|
|
205
|
+
loadAllBundledOcrModels(): Promise<number>;
|
|
172
206
|
fontCatalog(): FontInfo[];
|
|
173
207
|
/** Google Fonts CSS2 URL for a family/weight/italic (host fetches it). */
|
|
174
208
|
fontRequestUrl(family: string, weight?: number, italic?: boolean): string;
|
|
@@ -951,4 +985,4 @@ declare class GigaPdfDoc {
|
|
|
951
985
|
}): boolean;
|
|
952
986
|
}
|
|
953
987
|
|
|
954
|
-
export { type AnnotationInfo, type Attachment, type Box, type DecodedImage, type Element, type EmbeddedFont, type FieldInfo, type FieldKind, type FieldStyle, type FontInfo, GigaPdfDoc, GigaPdfEngine, type HtmlFont, type HtmlFontRequest, type HtmlMargins, type HtmlRenderOptions, type HtmlResource, type HtmlResourceNeed, type ImageElementInfo, type LayerInfo, type LinkInfo, type NamedDest, type OcrWord, type OutlineEntry, type PageInfo, type PathSegment, type RadioOption, type SearchHit, type SignP12Options, type TextElementInfo, type TextLine, type TextRunInfo, type VectorPathInfo, type XlsxSheet };
|
|
988
|
+
export { ALL_OCR_SCRIPTS, type AnnotationInfo, type Attachment, type Box, type DecodedImage, type Element, type EmbeddedFont, type FieldInfo, type FieldKind, type FieldStyle, type FontInfo, GigaPdfDoc, GigaPdfEngine, type HtmlFont, type HtmlFontRequest, type HtmlMargins, type HtmlRenderOptions, type HtmlResource, type HtmlResourceNeed, type ImageElementInfo, type LayerInfo, type LinkInfo, type NamedDest, type OcrScript, type OcrWord, type OutlineEntry, type PageInfo, type PathSegment, type RadioOption, type SearchHit, type SignP12Options, type TextElementInfo, type TextLine, type TextRunInfo, type VectorPathInfo, type XlsxSheet };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
2
|
var enc = new TextEncoder();
|
|
3
3
|
var dec = new TextDecoder();
|
|
4
|
+
var OCR_MODEL_FILES = {
|
|
5
|
+
alpha: "ocr_alpha.gpocr",
|
|
6
|
+
arabic: "ocr_arabic.gpocr",
|
|
7
|
+
devanagari: "ocr_deva.gpocr",
|
|
8
|
+
bengali: "ocr_beng.gpocr",
|
|
9
|
+
tamil: "ocr_taml.gpocr"
|
|
10
|
+
};
|
|
11
|
+
var ALL_OCR_SCRIPTS = [
|
|
12
|
+
"alpha",
|
|
13
|
+
"arabic",
|
|
14
|
+
"devanagari",
|
|
15
|
+
"bengali",
|
|
16
|
+
"tamil"
|
|
17
|
+
];
|
|
4
18
|
var GigaPdfEngine = class _GigaPdfEngine {
|
|
5
19
|
constructor(ex) {
|
|
6
20
|
this.ex = ex;
|
|
@@ -373,6 +387,70 @@ var GigaPdfEngine = class _GigaPdfEngine {
|
|
|
373
387
|
clearOcrModels() {
|
|
374
388
|
this.ex.gp_ocr_clear_models();
|
|
375
389
|
}
|
|
390
|
+
/**
|
|
391
|
+
* Resolve a bundled `.gpocr` model (shipped under `models/`) and load it into
|
|
392
|
+
* the engine via {@link loadOcrModel}. **Node hosts only** — it reads the blob
|
|
393
|
+
* from disk the same way {@link loadDefault} resolves the wasm. Returns `true`
|
|
394
|
+
* on success. Use this to recognize non-Latin scripts (Arabic, Devanagari,
|
|
395
|
+
* Bengali, Tamil) or to upgrade Latin/Cyrillic/Greek to the CRNN (`alpha`).
|
|
396
|
+
*/
|
|
397
|
+
async loadBundledOcrModel(script) {
|
|
398
|
+
const nodeImport = (m) => import(
|
|
399
|
+
/* webpackIgnore: true */
|
|
400
|
+
/* @vite-ignore */
|
|
401
|
+
m
|
|
402
|
+
);
|
|
403
|
+
const { readFile } = await nodeImport("node:fs/promises");
|
|
404
|
+
const { fileURLToPath } = await nodeImport("node:url");
|
|
405
|
+
const path = fileURLToPath(
|
|
406
|
+
new URL(`../models/${OCR_MODEL_FILES[script]}`, import.meta.url)
|
|
407
|
+
);
|
|
408
|
+
return this.loadOcrModel(await readFile(path));
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* Load several bundled OCR models (idempotent per call). Returns the scripts
|
|
412
|
+
* that loaded successfully. Pass {@link ALL_OCR_SCRIPTS} to recognize text in
|
|
413
|
+
* any supported language; the engine's script detector routes each line to the
|
|
414
|
+
* right model.
|
|
415
|
+
*/
|
|
416
|
+
async loadBundledOcrModels(scripts) {
|
|
417
|
+
const loaded = [];
|
|
418
|
+
for (const script of scripts) {
|
|
419
|
+
if (await this.loadBundledOcrModel(script)) loaded.push(script);
|
|
420
|
+
}
|
|
421
|
+
return loaded;
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* Discover and load EVERY bundled `.gpocr` model (Node hosts only). The
|
|
425
|
+
* engine's script detector then routes each recognized line to the matching
|
|
426
|
+
* model, so the OCR recognizes text in any shipped script — Latin, Cyrillic,
|
|
427
|
+
* Greek, Arabic, Urdu, Hebrew (the RTL group), Devanagari, Bengali, Tamil, and
|
|
428
|
+
* any model added later — with no code change. Returns the number loaded.
|
|
429
|
+
*/
|
|
430
|
+
async loadAllBundledOcrModels() {
|
|
431
|
+
const nodeImport = (m) => import(
|
|
432
|
+
/* webpackIgnore: true */
|
|
433
|
+
/* @vite-ignore */
|
|
434
|
+
m
|
|
435
|
+
);
|
|
436
|
+
const { readFile, readdir } = await nodeImport("node:fs/promises");
|
|
437
|
+
const { fileURLToPath } = await nodeImport("node:url");
|
|
438
|
+
let entries;
|
|
439
|
+
try {
|
|
440
|
+
entries = await readdir(fileURLToPath(new URL("../models/", import.meta.url)));
|
|
441
|
+
} catch {
|
|
442
|
+
return 0;
|
|
443
|
+
}
|
|
444
|
+
let count = 0;
|
|
445
|
+
for (const name of entries) {
|
|
446
|
+
if (!name.endsWith(".gpocr")) continue;
|
|
447
|
+
const bytes = await readFile(
|
|
448
|
+
fileURLToPath(new URL(`../models/${name}`, import.meta.url))
|
|
449
|
+
);
|
|
450
|
+
if (this.loadOcrModel(bytes)) count += 1;
|
|
451
|
+
}
|
|
452
|
+
return count;
|
|
453
|
+
}
|
|
376
454
|
// ── fonts (catalog / Google Fonts URL — the host performs the fetch) ───────
|
|
377
455
|
fontCatalog() {
|
|
378
456
|
return this._json((o) => this.ex.gp_font_catalog_json(o));
|
|
@@ -1536,6 +1614,7 @@ var GigaPdfDoc = class {
|
|
|
1536
1614
|
}
|
|
1537
1615
|
};
|
|
1538
1616
|
export {
|
|
1617
|
+
ALL_OCR_SCRIPTS,
|
|
1539
1618
|
GigaPdfDoc,
|
|
1540
1619
|
GigaPdfEngine
|
|
1541
1620
|
};
|