@xberg-io/xberg-wasm 1.0.12 → 1.1.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/README.md CHANGED
@@ -1,8 +1,19 @@
1
+ <!-- This file is auto-generated by alef — DO NOT EDIT. -->
2
+ <!-- alef:hash:3ccb6772a03d9b6fcc002e6420f88eb8d105b0179169016db2e720b2f497b3f1 -->
3
+ <!-- To regenerate: alef readme -->
4
+ <!-- To verify freshness: alef verify -->
5
+
1
6
  # WebAssembly
2
7
 
3
8
  <div align="center" style="display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 20px 0;">
9
+ <a href="https://github.com/xberg-io/xberg/actions/workflows/ci-rust.yaml">
10
+ <img src="https://github.com/xberg-io/xberg/actions/workflows/ci-rust.yaml/badge.svg?branch=main" alt="Rust CI">
11
+ </a>
12
+ <a href="https://codecov.io/gh/xberg-io/xberg">
13
+ <img src="https://codecov.io/gh/xberg-io/xberg/branch/main/graph/badge.svg" alt="Coverage">
14
+ </a>
4
15
  <a href="https://github.com/xberg-io/alef">
5
- <img src="https://img.shields.io/badge/Bindings-alef%20%D7%90-007ec6" alt="Bindings">
16
+ <img src="https://img.shields.io/badge/built%20with-alef%20%D7%90-007ec6" alt="Built with alef">
6
17
  </a>
7
18
  <!-- Language Bindings -->
8
19
  <a href="https://crates.io/crates/xberg">
@@ -80,7 +91,7 @@
80
91
  </a>
81
92
  </div>
82
93
 
83
- Extract text, tables, images, metadata, and code intelligence from 101 file formats and 371 programming languages including PDF, Office documents, and images. WebAssembly bindings for browsers, Deno, and Cloudflare Workers with portable deployment and multi-threading support.
94
+ Extract text, tables, images, and metadata from 107 file formats including PDF, Office documents, and images. WebAssembly bindings for browsers, Deno, and Cloudflare Workers with a single-threaded synchronous core and an async JavaScript surface.
84
95
 
85
96
  ## What This Package Provides
86
97
 
@@ -110,11 +121,11 @@ pnpm add @xberg-io/xberg-wasm
110
121
 
111
122
  Extract text, metadata, and structure from any supported document format:
112
123
 
113
- ```ts
114
- import { ExtractInputKind, extract, initWasm } from "@xberg-io/xberg-wasm";
124
+ ```typescript title="Wasm"
125
+ import init, { WasmExtractInputKind, extract } from "@xberg-io/xberg-wasm";
115
126
 
116
127
  async function main() {
117
- await initWasm();
128
+ await init();
118
129
 
119
130
  const buffer = await fetch("document.pdf").then((r) => r.arrayBuffer());
120
131
  const bytes = new Uint8Array(buffer);
@@ -124,7 +135,7 @@ async function main() {
124
135
  bytes,
125
136
  mimeType: "application/pdf",
126
137
  filename: "document.pdf",
127
- });
138
+ }, undefined);
128
139
 
129
140
  console.log("Extracted content:");
130
141
  console.log(output.results[0].content);
@@ -143,22 +154,17 @@ Most use cases benefit from configuration to control extraction behavior:
143
154
 
144
155
  **With OCR (for scanned documents):**
145
156
 
146
- ```ts
147
- import { enableOcr, ExtractInputKind, extract, initWasm } from "@xberg-io/xberg-wasm";
157
+ ```typescript title="Wasm"
158
+ import init, { WasmExtractInputKind, extract } from "@xberg-io/xberg-wasm";
148
159
 
149
160
  async function extractWithOcr() {
150
- await initWasm();
151
-
152
- try {
153
- await enableOcr();
154
- console.log("OCR enabled successfully");
155
- } catch (error) {
156
- console.error("Failed to enable OCR:", error);
157
- return;
158
- }
161
+ await init();
159
162
 
160
- const bytes = new Uint8Array(await fetch("scanned-page.png").then((r) => r.arrayBuffer()));
163
+ const buffer = await fetch("scanned-page.png").then((response) => response.arrayBuffer());
164
+ const bytes = new Uint8Array(buffer);
161
165
 
166
+ // OCR is turned on per extraction through the `ocr` config block. There is no
167
+ // separate global "enable OCR" call — the backend is selected by name here.
162
168
  const output = await extract(
163
169
  {
164
170
  kind: "bytes",
@@ -168,7 +174,8 @@ async function extractWithOcr() {
168
174
  },
169
175
  {
170
176
  ocr: {
171
- backend: "tesseract-wasm",
177
+ enabled: true,
178
+ backend: "tesseract",
172
179
  language: ["eng"],
173
180
  },
174
181
  },
@@ -187,8 +194,8 @@ See [Configuration Guide](https://docs.xberg.io/guides/configuration/) for table
187
194
 
188
195
  #### Processing Multiple Files
189
196
 
190
- ```ts
191
- import { extractBatch, initWasm } from "@xberg-io/xberg-wasm";
197
+ ```typescript title="Wasm"
198
+ import init, { WasmExtractInput, extractBatch } from "@xberg-io/xberg-wasm";
192
199
 
193
200
  interface DocumentJob {
194
201
  name: string;
@@ -197,19 +204,15 @@ interface DocumentJob {
197
204
  }
198
205
 
199
206
  async function _processBatch(documents: DocumentJob[], concurrency: number = 3) {
200
- await initWasm();
207
+ await init();
201
208
 
202
209
  const results: Record<string, string> = {};
203
210
 
204
211
  for (let index = 0; index < documents.length; index += concurrency) {
205
212
  const batch = documents.slice(index, index + concurrency);
206
213
  const output = await extractBatch(
207
- batch.map((doc) => ({
208
- kind: "bytes",
209
- bytes: doc.bytes,
210
- mimeType: doc.mimeType,
211
- filename: doc.name,
212
- })),
214
+ batch.map((doc) => WasmExtractInput.fromBytes(doc.bytes, doc.mimeType, doc.name)),
215
+ undefined,
213
216
  );
214
217
 
215
218
  output.results.forEach((result, resultIndex) => {
@@ -224,24 +227,19 @@ async function _processBatch(documents: DocumentJob[], concurrency: number = 3)
224
227
 
225
228
  For non-blocking document processing:
226
229
 
227
- ```ts
228
- import { extract, getWasmCapabilities, initWasm } from "@xberg-io/xberg-wasm";
230
+ ```typescript title="Wasm"
231
+ import init, { extract } from "@xberg-io/xberg-wasm";
229
232
 
230
233
  async function extractDocuments(files: Uint8Array[], mimeTypes: string[]) {
231
- const caps = getWasmCapabilities();
232
- if (!caps.hasWasm) {
233
- throw new Error("WebAssembly not supported");
234
- }
235
-
236
- await initWasm();
234
+ await init();
237
235
 
238
236
  const results = await Promise.all(
239
- files.map((bytes, index) => extract({ kind: "bytes", bytes, mimeType: mimeTypes[index] })),
237
+ files.map((bytes, index) => extract({ kind: "bytes", bytes, mimeType: mimeTypes[index] }, undefined)),
240
238
  );
241
239
 
242
240
  return results.map((r) => ({
243
- content: r.content,
244
- pageCount: r.metadata?.pageCount,
241
+ content: r.results[0].content,
242
+ metadata: r.results[0].metadata,
245
243
  }));
246
244
  }
247
245
 
@@ -256,15 +254,15 @@ extractDocuments(fileBytes, mimes)
256
254
  ### Next Steps
257
255
 
258
256
  - **[Installation Guide](https://docs.xberg.io/getting-started/installation/)** - Platform-specific setup
259
- - **[API Documentation](https://docs.xberg.io/reference/api-python/)** - Complete API reference
257
+ - **[API Documentation](https://docs.xberg.io/reference/api-wasm/)** - Complete API reference
260
258
  - **[Examples & Guides](https://docs.xberg.io/)** - Full code examples and usage guides
261
259
  - **[Configuration Guide](https://docs.xberg.io/guides/configuration/)** - Advanced configuration options
262
260
 
263
261
  ## Features
264
262
 
265
- ### Supported File Formats (101 formats · 115 file extensions)
263
+ ### Supported File Formats (107 formats · 141 file extensions · 56 MIME aliases)
266
264
 
267
- 101 formats across 115 file extensions in 8 major categories with intelligent format detection and comprehensive metadata extraction.
265
+ 107 formats across 140 unique file extensions, with 56 compatibility MIME aliases, intelligent format detection, and comprehensive metadata extraction.
268
266
 
269
267
  #### Office Documents
270
268
 
@@ -272,10 +270,10 @@ extractDocuments(fileBytes, mimes)
272
270
  |----------|---------|--------------|
273
271
  | **Word Processing** | `.docx`, `.docm`, `.doc`, `.dotx`, `.dotm`, `.dot`, `.odt`, `.pages`, `.wpd`, `.wp`, `.wp5`, `.wp6` | Full text, tables, images, metadata, styles |
274
272
  | **Spreadsheets** | `.xlsx`, `.xlsm`, `.xlsb`, `.xls`, `.xla`, `.xlam`, `.xltm`, `.xltx`, `.xlt`, `.ods`, `.numbers` | Sheet data, formulas, cell metadata, charts |
275
- | **Presentations** | `.pptx`, `.pptm`, `.ppt`, `.ppsx`, `.potx`, `.potm`, `.pot`, `.odp`, `.key` | Slides, speaker notes, images, metadata |
273
+ | **Presentations** | `.pptx`, `.pptm`, `.ppt`, `.pps`, `.ppsx`, `.potx`, `.potm`, `.pot`, `.odp`, `.key` | Slides, speaker notes, images, metadata |
276
274
  | **PDF** | `.pdf` | Text, tables, images, metadata, OCR support |
277
275
  | **eBooks** | `.epub`, `.fb2` | Chapters, metadata, embedded resources |
278
- | **Database** | `.dbf` | Table data extraction, field type support |
276
+ | **Database** | `.dbf`, `.sqlite`, `.sqlite3`, `.db`, `.gpkg`, `.gpkx` | Bounded table extraction, schema metadata, GeoPackage detection |
279
277
  | **Hangul** | `.hwp`, `.hwpx` | Korean document format, text extraction |
280
278
 
281
279
  #### Images (OCR-Enabled)
@@ -283,16 +281,16 @@ extractDocuments(fileBytes, mimes)
283
281
  | Category | Formats | Features |
284
282
  |----------|---------|----------|
285
283
  | **Raster** | `.png`, `.jpg`, `.jpeg`, `.gif`, `.webp`, `.bmp`, `.tiff`, `.tif` | OCR, table detection, EXIF metadata, dimensions, color space |
286
- | **Advanced** | `.jp2`, `.jpx`, `.jpm`, `.mj2`, `.jbig2`, `.jb2`, `.pnm`, `.pbm`, `.pgm`, `.ppm` | OCR via hayro-jpeg2000 (pure Rust decoder), JBIG2 support, table detection, format-specific metadata |
284
+ | **Advanced** | `.jp2`, `.jpg2`, `.j2c`, `.j2k`, `.jpc`, `.jbig2`, `.jb2`, `.pnm`, `.pbm`, `.pgm`, `.ppm` | OCR via hayro-jpeg2000 (pure Rust decoder), JBIG2 support, table detection, format-specific metadata |
287
285
  | **Vector** | `.svg` | DOM parsing, embedded text, graphics metadata |
288
286
 
289
287
  #### Web & Data
290
288
 
291
289
  | Category | Formats | Features |
292
290
  |----------|---------|----------|
293
- | **Markup** | `.html`, `.htm`, `.xhtml`, `.xml`, `.svg` | DOM parsing, metadata (Open Graph, Twitter Card), link extraction |
294
- | **Structured Data** | `.json`, `.yaml`, `.yml`, `.toml`, `.csv`, `.tsv` | Schema detection, nested structures, validation |
295
- | **Text & Markdown** | `.txt`, `.md`, `.markdown`, `.djot`, `.mdx`, `.rst`, `.org`, `.rtf` | CommonMark, GFM, Djot, MDX, reStructuredText, Org Mode |
291
+ | **Markup** | `.html`, `.htm`, `.xhtml`, `.xht`, `.xml`, `.kml`, `.svg` | DOM parsing, metadata (Open Graph, Twitter Card), link extraction |
292
+ | **Structured Data** | `.json`, `.geojson`, `.jsonl`, `.ndjson`, `.yaml`, `.yml`, `.toml`, `.csv`, `.tsv` | Schema detection, nested structures, validation |
293
+ | **Text & Markdown** | `.txt`, `.adoc`, `.asciidoc`, `.vtt`, `.md`, `.markdown`, `.commonmark`, `.qmd`, `.rmd`, `.djot`, `.dj`, `.mdx`, `.doctags`, `.rst`, `.org`, `.rtf` | AsciiDoc, CommonMark, MyST Markdown, Quarto, R Markdown, Djot, MDX, DocTags, reStructuredText, Org Mode |
296
294
 
297
295
  #### Email & Archives
298
296
 
@@ -306,9 +304,9 @@ extractDocuments(fileBytes, mimes)
306
304
  | Category | Formats | Features |
307
305
  |----------|---------|----------|
308
306
  | **Citations** | `.bib`, `.ris`, `.nbib`, `.enw` | Structured parsing: RIS, PubMed/MEDLINE, EndNote XML, BibTeX/BibLaTeX, CSL JSON by MIME type |
309
- | **Scientific** | `.tex`, `.latex`, `.typ`, `.typst`, `.jats`, `.ipynb` | LaTeX, Typst, Jupyter notebooks, PubMed JATS |
307
+ | **Scientific** | `.tex`, `.latex`, `.typ`, `.typst`, `.jats`, `.nxml` | LaTeX, Typst, PubMed JATS |
308
+ | **Text notebooks** | `.ipynb`, `.md`, `.py`, `.R`, `.jl` | Jupyter, MyST-NB, Jupytext percent/light, saved outputs, cell visibility tags |
310
309
  | **Publishing** | `.fb2`, `.docbook`, `.dbk`, `.docbook4`, `.docbook5`, `.opml` | FictionBook, DocBook XML, OPML outlines |
311
- | **Documentation** | MIME-only POD, mdoc, troff | Technical documentation formats |
312
310
 
313
311
  #### Code Intelligence (371 Languages)
314
312
 
@@ -337,9 +335,8 @@ Powered by [tree-sitter-language-pack](https://github.com/xberg-io/tree-sitter-l
337
335
  - **Batch Processing** - Efficiently process multiple documents in parallel
338
336
  - **Memory Efficient** - Stream large files without loading entirely into memory
339
337
  - **Language Detection** - Detect and support multiple languages in documents
340
- - **Code Intelligence** - Extract structure, imports, exports, symbols, and docstrings from [371 programming languages](https://docs.tree-sitter-language-pack.xberg.io) via tree-sitter
341
338
  - **Configuration** - Fine-grained control over extraction behavior
342
- - **Six Output Formats** - Plain text, Markdown, Djot, HTML, JSON tree structure, or Structured JSON with OCR metadata
339
+ - **Six Output Formats** - Plain text, Markdown, Djot, HTML, JSON tree structure, or Docling DocTags
343
340
 
344
341
  ## OCR Support
345
342
 
@@ -347,24 +344,21 @@ Xberg supports multiple OCR backends for extracting text from scanned documents
347
344
 
348
345
  - **Tesseract-Wasm**
349
346
 
347
+ - **Sceptre (Opt-In Worker Api)**
348
+
350
349
  ### OCR Configuration Example
351
350
 
352
- ```ts
353
- import { enableOcr, ExtractInputKind, extract, initWasm } from "@xberg-io/xberg-wasm";
351
+ ```typescript title="Wasm"
352
+ import init, { WasmExtractInputKind, extract } from "@xberg-io/xberg-wasm";
354
353
 
355
354
  async function extractWithOcr() {
356
- await initWasm();
357
-
358
- try {
359
- await enableOcr();
360
- console.log("OCR enabled successfully");
361
- } catch (error) {
362
- console.error("Failed to enable OCR:", error);
363
- return;
364
- }
355
+ await init();
365
356
 
366
- const bytes = new Uint8Array(await fetch("scanned-page.png").then((r) => r.arrayBuffer()));
357
+ const buffer = await fetch("scanned-page.png").then((response) => response.arrayBuffer());
358
+ const bytes = new Uint8Array(buffer);
367
359
 
360
+ // OCR is turned on per extraction through the `ocr` config block. There is no
361
+ // separate global "enable OCR" call — the backend is selected by name here.
368
362
  const output = await extract(
369
363
  {
370
364
  kind: "bytes",
@@ -374,7 +368,8 @@ async function extractWithOcr() {
374
368
  },
375
369
  {
376
370
  ocr: {
377
- backend: "tesseract-wasm",
371
+ enabled: true,
372
+ backend: "tesseract",
378
373
  language: ["eng"],
379
374
  },
380
375
  },
@@ -391,24 +386,19 @@ extractWithOcr().catch(console.error);
391
386
 
392
387
  This binding provides full async/await support for non-blocking document processing:
393
388
 
394
- ```ts
395
- import { extract, getWasmCapabilities, initWasm } from "@xberg-io/xberg-wasm";
389
+ ```typescript title="Wasm"
390
+ import init, { extract } from "@xberg-io/xberg-wasm";
396
391
 
397
392
  async function extractDocuments(files: Uint8Array[], mimeTypes: string[]) {
398
- const caps = getWasmCapabilities();
399
- if (!caps.hasWasm) {
400
- throw new Error("WebAssembly not supported");
401
- }
402
-
403
- await initWasm();
393
+ await init();
404
394
 
405
395
  const results = await Promise.all(
406
- files.map((bytes, index) => extract({ kind: "bytes", bytes, mimeType: mimeTypes[index] })),
396
+ files.map((bytes, index) => extract({ kind: "bytes", bytes, mimeType: mimeTypes[index] }, undefined)),
407
397
  );
408
398
 
409
399
  return results.map((r) => ({
410
- content: r.content,
411
- pageCount: r.metadata?.pageCount,
400
+ content: r.results[0].content,
401
+ metadata: r.results[0].metadata,
412
402
  }));
413
403
  }
414
404
 
@@ -430,8 +420,8 @@ For detailed plugin documentation, visit [Plugin System Guide](https://docs.xber
430
420
 
431
421
  Process multiple documents efficiently:
432
422
 
433
- ```ts
434
- import { extractBatch, initWasm } from "@xberg-io/xberg-wasm";
423
+ ```typescript title="Wasm"
424
+ import init, { WasmExtractInput, extractBatch } from "@xberg-io/xberg-wasm";
435
425
 
436
426
  interface DocumentJob {
437
427
  name: string;
@@ -440,19 +430,15 @@ interface DocumentJob {
440
430
  }
441
431
 
442
432
  async function _processBatch(documents: DocumentJob[], concurrency: number = 3) {
443
- await initWasm();
433
+ await init();
444
434
 
445
435
  const results: Record<string, string> = {};
446
436
 
447
437
  for (let index = 0; index < documents.length; index += concurrency) {
448
438
  const batch = documents.slice(index, index + concurrency);
449
439
  const output = await extractBatch(
450
- batch.map((doc) => ({
451
- kind: "bytes",
452
- bytes: doc.bytes,
453
- mimeType: doc.mimeType,
454
- filename: doc.name,
455
- })),
440
+ batch.map((doc) => WasmExtractInput.fromBytes(doc.bytes, doc.mimeType, doc.name)),
441
+ undefined,
456
442
  );
457
443
 
458
444
  output.results.forEach((result, resultIndex) => {
@@ -472,15 +458,18 @@ For advanced configuration options including language detection, table extractio
472
458
  ## Documentation
473
459
 
474
460
  - **[Official Documentation](https://docs.xberg.io/)**
475
- - **[API Reference](https://docs.xberg.io/reference/api-python/)**
461
+ - **[API Reference](https://docs.xberg.io/reference/api-wasm/)**
476
462
  - **[Examples & Guides](https://docs.xberg.io/)**
477
463
 
478
464
  ## Contributing
479
465
 
480
466
  Contributions are welcome! See [Contributing Guide](https://github.com/xberg-io/xberg/blob/main/CONTRIBUTING.md).
481
467
 
482
- ## Part of Xberg.dev
468
+ ## Part of Xberg.io
483
469
 
470
+ - [Xberg](https://github.com/xberg-io/xberg) — the open-source content-intelligence engine: text, tables, and metadata from 107 formats (141 file extensions), with OCR, transcription, and code intelligence. MIT.
471
+ - [Xberg Pro](https://xberg.io) — a complete self-hosted content-intelligence backend in a single container. Commercial.
472
+ - [Xberg Enterprise](https://xberg.io) — the distributed, governed content-intelligence platform, scaled on Kubernetes with team governance and support. Commercial.
484
473
  - [crawlberg](https://github.com/xberg-io/crawlberg) — web crawling and scraping with HTML→Markdown and headless-Chrome fallback.
485
474
  - [html-to-markdown](https://github.com/xberg-io/html-to-markdown) — fast, lossless HTML→Markdown engine.
486
475
  - [liter-llm](https://github.com/xberg-io/liter-llm) — universal LLM API client with native bindings for 14 languages and 165 providers.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xberg-io/xberg-wasm",
3
- "version": "1.0.12",
3
+ "version": "1.1.0",
4
4
  "private": false,
5
5
  "description": "High-performance document intelligence library",
6
6
  "license": "MIT",
@@ -13,13 +13,19 @@
13
13
  "access": "public"
14
14
  },
15
15
  "type": "module",
16
- "files": [
17
- "pkg/web",
18
- "README.md"
19
- ],
16
+ "files": ["pkg/web", "README.md"],
20
17
  "main": "pkg/web/xberg_wasm.js",
21
18
  "module": "pkg/web/xberg_wasm.js",
22
19
  "types": "pkg/web/xberg_wasm.d.ts",
20
+ "exports": {
21
+ ".": {
22
+ "types": "./pkg/web/xberg_wasm.d.ts",
23
+ "browser": "./pkg/web/xberg_wasm.js",
24
+ "import": "./pkg/web/xberg_wasm.js",
25
+ "require": "./pkg/web/xberg_wasm.js",
26
+ "default": "./pkg/web/xberg_wasm.js"
27
+ }
28
+ },
23
29
  "engines": {
24
30
  "node": ">= 22"
25
31
  },
@@ -32,5 +38,9 @@
32
38
  "test:watch": "vitest watch",
33
39
  "test:coverage": "vitest run --coverage",
34
40
  "clean": "rm -rf pkg dist"
41
+ },
42
+ "devDependencies": {
43
+ "vitest": "^4.1.11",
44
+ "@vitest/coverage-v8": "^4.1.11"
35
45
  }
36
46
  }