@xberg-io/xberg-wasm 1.0.11 → 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
 
@@ -100,6 +111,7 @@ pnpm add @xberg-io/xberg-wasm
100
111
  ```
101
112
 
102
113
  ### System Requirements
114
+
103
115
  - Modern browser with WebAssembly support, or Deno 1.0+, or Cloudflare Workers
104
116
  - Optional: [Tesseract WASM](https://github.com/naptha/tesseract.js) for OCR functionality
105
117
 
@@ -109,11 +121,11 @@ pnpm add @xberg-io/xberg-wasm
109
121
 
110
122
  Extract text, metadata, and structure from any supported document format:
111
123
 
112
- ```ts
113
- import { ExtractInputKind, extract, initWasm } from "@xberg-io/xberg-wasm";
124
+ ```typescript title="Wasm"
125
+ import init, { WasmExtractInputKind, extract } from "@xberg-io/xberg-wasm";
114
126
 
115
127
  async function main() {
116
- await initWasm();
128
+ await init();
117
129
 
118
130
  const buffer = await fetch("document.pdf").then((r) => r.arrayBuffer());
119
131
  const bytes = new Uint8Array(buffer);
@@ -123,7 +135,7 @@ async function main() {
123
135
  bytes,
124
136
  mimeType: "application/pdf",
125
137
  filename: "document.pdf",
126
- });
138
+ }, undefined);
127
139
 
128
140
  console.log("Extracted content:");
129
141
  console.log(output.results[0].content);
@@ -142,22 +154,17 @@ Most use cases benefit from configuration to control extraction behavior:
142
154
 
143
155
  **With OCR (for scanned documents):**
144
156
 
145
- ```ts
146
- import { enableOcr, ExtractInputKind, extract, initWasm } from "@xberg-io/xberg-wasm";
157
+ ```typescript title="Wasm"
158
+ import init, { WasmExtractInputKind, extract } from "@xberg-io/xberg-wasm";
147
159
 
148
160
  async function extractWithOcr() {
149
- await initWasm();
150
-
151
- try {
152
- await enableOcr();
153
- console.log("OCR enabled successfully");
154
- } catch (error) {
155
- console.error("Failed to enable OCR:", error);
156
- return;
157
- }
161
+ await init();
158
162
 
159
- 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);
160
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.
161
168
  const output = await extract(
162
169
  {
163
170
  kind: "bytes",
@@ -167,7 +174,8 @@ async function extractWithOcr() {
167
174
  },
168
175
  {
169
176
  ocr: {
170
- backend: "tesseract-wasm",
177
+ enabled: true,
178
+ backend: "tesseract",
171
179
  language: ["eng"],
172
180
  },
173
181
  },
@@ -186,8 +194,8 @@ See [Configuration Guide](https://docs.xberg.io/guides/configuration/) for table
186
194
 
187
195
  #### Processing Multiple Files
188
196
 
189
- ```ts
190
- import { extractBatch, initWasm } from "@xberg-io/xberg-wasm";
197
+ ```typescript title="Wasm"
198
+ import init, { WasmExtractInput, extractBatch } from "@xberg-io/xberg-wasm";
191
199
 
192
200
  interface DocumentJob {
193
201
  name: string;
@@ -196,19 +204,15 @@ interface DocumentJob {
196
204
  }
197
205
 
198
206
  async function _processBatch(documents: DocumentJob[], concurrency: number = 3) {
199
- await initWasm();
207
+ await init();
200
208
 
201
209
  const results: Record<string, string> = {};
202
210
 
203
211
  for (let index = 0; index < documents.length; index += concurrency) {
204
212
  const batch = documents.slice(index, index + concurrency);
205
213
  const output = await extractBatch(
206
- batch.map((doc) => ({
207
- kind: "bytes",
208
- bytes: doc.bytes,
209
- mimeType: doc.mimeType,
210
- filename: doc.name,
211
- })),
214
+ batch.map((doc) => WasmExtractInput.fromBytes(doc.bytes, doc.mimeType, doc.name)),
215
+ undefined,
212
216
  );
213
217
 
214
218
  output.results.forEach((result, resultIndex) => {
@@ -223,24 +227,19 @@ async function _processBatch(documents: DocumentJob[], concurrency: number = 3)
223
227
 
224
228
  For non-blocking document processing:
225
229
 
226
- ```ts
227
- import { extract, getWasmCapabilities, initWasm } from "@xberg-io/xberg-wasm";
230
+ ```typescript title="Wasm"
231
+ import init, { extract } from "@xberg-io/xberg-wasm";
228
232
 
229
233
  async function extractDocuments(files: Uint8Array[], mimeTypes: string[]) {
230
- const caps = getWasmCapabilities();
231
- if (!caps.hasWasm) {
232
- throw new Error("WebAssembly not supported");
233
- }
234
-
235
- await initWasm();
234
+ await init();
236
235
 
237
236
  const results = await Promise.all(
238
- files.map((bytes, index) => extract({ kind: "bytes", bytes, mimeType: mimeTypes[index] })),
237
+ files.map((bytes, index) => extract({ kind: "bytes", bytes, mimeType: mimeTypes[index] }, undefined)),
239
238
  );
240
239
 
241
240
  return results.map((r) => ({
242
- content: r.content,
243
- pageCount: r.metadata?.pageCount,
241
+ content: r.results[0].content,
242
+ metadata: r.results[0].metadata,
244
243
  }));
245
244
  }
246
245
 
@@ -255,15 +254,15 @@ extractDocuments(fileBytes, mimes)
255
254
  ### Next Steps
256
255
 
257
256
  - **[Installation Guide](https://docs.xberg.io/getting-started/installation/)** - Platform-specific setup
258
- - **[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
259
258
  - **[Examples & Guides](https://docs.xberg.io/)** - Full code examples and usage guides
260
259
  - **[Configuration Guide](https://docs.xberg.io/guides/configuration/)** - Advanced configuration options
261
260
 
262
261
  ## Features
263
262
 
264
- ### Supported File Formats (101 formats · 115 file extensions)
263
+ ### Supported File Formats (107 formats · 141 file extensions · 56 MIME aliases)
265
264
 
266
- 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.
267
266
 
268
267
  #### Office Documents
269
268
 
@@ -271,10 +270,10 @@ extractDocuments(fileBytes, mimes)
271
270
  |----------|---------|--------------|
272
271
  | **Word Processing** | `.docx`, `.docm`, `.doc`, `.dotx`, `.dotm`, `.dot`, `.odt`, `.pages`, `.wpd`, `.wp`, `.wp5`, `.wp6` | Full text, tables, images, metadata, styles |
273
272
  | **Spreadsheets** | `.xlsx`, `.xlsm`, `.xlsb`, `.xls`, `.xla`, `.xlam`, `.xltm`, `.xltx`, `.xlt`, `.ods`, `.numbers` | Sheet data, formulas, cell metadata, charts |
274
- | **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 |
275
274
  | **PDF** | `.pdf` | Text, tables, images, metadata, OCR support |
276
275
  | **eBooks** | `.epub`, `.fb2` | Chapters, metadata, embedded resources |
277
- | **Database** | `.dbf` | Table data extraction, field type support |
276
+ | **Database** | `.dbf`, `.sqlite`, `.sqlite3`, `.db`, `.gpkg`, `.gpkx` | Bounded table extraction, schema metadata, GeoPackage detection |
278
277
  | **Hangul** | `.hwp`, `.hwpx` | Korean document format, text extraction |
279
278
 
280
279
  #### Images (OCR-Enabled)
@@ -282,16 +281,16 @@ extractDocuments(fileBytes, mimes)
282
281
  | Category | Formats | Features |
283
282
  |----------|---------|----------|
284
283
  | **Raster** | `.png`, `.jpg`, `.jpeg`, `.gif`, `.webp`, `.bmp`, `.tiff`, `.tif` | OCR, table detection, EXIF metadata, dimensions, color space |
285
- | **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 |
286
285
  | **Vector** | `.svg` | DOM parsing, embedded text, graphics metadata |
287
286
 
288
287
  #### Web & Data
289
288
 
290
289
  | Category | Formats | Features |
291
290
  |----------|---------|----------|
292
- | **Markup** | `.html`, `.htm`, `.xhtml`, `.xml`, `.svg` | DOM parsing, metadata (Open Graph, Twitter Card), link extraction |
293
- | **Structured Data** | `.json`, `.yaml`, `.yml`, `.toml`, `.csv`, `.tsv` | Schema detection, nested structures, validation |
294
- | **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 |
295
294
 
296
295
  #### Email & Archives
297
296
 
@@ -305,9 +304,9 @@ extractDocuments(fileBytes, mimes)
305
304
  | Category | Formats | Features |
306
305
  |----------|---------|----------|
307
306
  | **Citations** | `.bib`, `.ris`, `.nbib`, `.enw` | Structured parsing: RIS, PubMed/MEDLINE, EndNote XML, BibTeX/BibLaTeX, CSL JSON by MIME type |
308
- | **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 |
309
309
  | **Publishing** | `.fb2`, `.docbook`, `.dbk`, `.docbook4`, `.docbook5`, `.opml` | FictionBook, DocBook XML, OPML outlines |
310
- | **Documentation** | MIME-only POD, mdoc, troff | Technical documentation formats |
311
310
 
312
311
  #### Code Intelligence (371 Languages)
313
312
 
@@ -336,9 +335,8 @@ Powered by [tree-sitter-language-pack](https://github.com/xberg-io/tree-sitter-l
336
335
  - **Batch Processing** - Efficiently process multiple documents in parallel
337
336
  - **Memory Efficient** - Stream large files without loading entirely into memory
338
337
  - **Language Detection** - Detect and support multiple languages in documents
339
- - **Code Intelligence** - Extract structure, imports, exports, symbols, and docstrings from [371 programming languages](https://docs.tree-sitter-language-pack.xberg.io) via tree-sitter
340
338
  - **Configuration** - Fine-grained control over extraction behavior
341
- - **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
342
340
 
343
341
  ## OCR Support
344
342
 
@@ -346,24 +344,21 @@ Xberg supports multiple OCR backends for extracting text from scanned documents
346
344
 
347
345
  - **Tesseract-Wasm**
348
346
 
347
+ - **Sceptre (Opt-In Worker Api)**
348
+
349
349
  ### OCR Configuration Example
350
350
 
351
- ```ts
352
- import { enableOcr, ExtractInputKind, extract, initWasm } from "@xberg-io/xberg-wasm";
351
+ ```typescript title="Wasm"
352
+ import init, { WasmExtractInputKind, extract } from "@xberg-io/xberg-wasm";
353
353
 
354
354
  async function extractWithOcr() {
355
- await initWasm();
356
-
357
- try {
358
- await enableOcr();
359
- console.log("OCR enabled successfully");
360
- } catch (error) {
361
- console.error("Failed to enable OCR:", error);
362
- return;
363
- }
355
+ await init();
364
356
 
365
- 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);
366
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.
367
362
  const output = await extract(
368
363
  {
369
364
  kind: "bytes",
@@ -373,7 +368,8 @@ async function extractWithOcr() {
373
368
  },
374
369
  {
375
370
  ocr: {
376
- backend: "tesseract-wasm",
371
+ enabled: true,
372
+ backend: "tesseract",
377
373
  language: ["eng"],
378
374
  },
379
375
  },
@@ -390,24 +386,19 @@ extractWithOcr().catch(console.error);
390
386
 
391
387
  This binding provides full async/await support for non-blocking document processing:
392
388
 
393
- ```ts
394
- import { extract, getWasmCapabilities, initWasm } from "@xberg-io/xberg-wasm";
389
+ ```typescript title="Wasm"
390
+ import init, { extract } from "@xberg-io/xberg-wasm";
395
391
 
396
392
  async function extractDocuments(files: Uint8Array[], mimeTypes: string[]) {
397
- const caps = getWasmCapabilities();
398
- if (!caps.hasWasm) {
399
- throw new Error("WebAssembly not supported");
400
- }
401
-
402
- await initWasm();
393
+ await init();
403
394
 
404
395
  const results = await Promise.all(
405
- files.map((bytes, index) => extract({ kind: "bytes", bytes, mimeType: mimeTypes[index] })),
396
+ files.map((bytes, index) => extract({ kind: "bytes", bytes, mimeType: mimeTypes[index] }, undefined)),
406
397
  );
407
398
 
408
399
  return results.map((r) => ({
409
- content: r.content,
410
- pageCount: r.metadata?.pageCount,
400
+ content: r.results[0].content,
401
+ metadata: r.results[0].metadata,
411
402
  }));
412
403
  }
413
404
 
@@ -429,8 +420,8 @@ For detailed plugin documentation, visit [Plugin System Guide](https://docs.xber
429
420
 
430
421
  Process multiple documents efficiently:
431
422
 
432
- ```ts
433
- import { extractBatch, initWasm } from "@xberg-io/xberg-wasm";
423
+ ```typescript title="Wasm"
424
+ import init, { WasmExtractInput, extractBatch } from "@xberg-io/xberg-wasm";
434
425
 
435
426
  interface DocumentJob {
436
427
  name: string;
@@ -439,19 +430,15 @@ interface DocumentJob {
439
430
  }
440
431
 
441
432
  async function _processBatch(documents: DocumentJob[], concurrency: number = 3) {
442
- await initWasm();
433
+ await init();
443
434
 
444
435
  const results: Record<string, string> = {};
445
436
 
446
437
  for (let index = 0; index < documents.length; index += concurrency) {
447
438
  const batch = documents.slice(index, index + concurrency);
448
439
  const output = await extractBatch(
449
- batch.map((doc) => ({
450
- kind: "bytes",
451
- bytes: doc.bytes,
452
- mimeType: doc.mimeType,
453
- filename: doc.name,
454
- })),
440
+ batch.map((doc) => WasmExtractInput.fromBytes(doc.bytes, doc.mimeType, doc.name)),
441
+ undefined,
455
442
  );
456
443
 
457
444
  output.results.forEach((result, resultIndex) => {
@@ -471,15 +458,18 @@ For advanced configuration options including language detection, table extractio
471
458
  ## Documentation
472
459
 
473
460
  - **[Official Documentation](https://docs.xberg.io/)**
474
- - **[API Reference](https://docs.xberg.io/reference/api-python/)**
461
+ - **[API Reference](https://docs.xberg.io/reference/api-wasm/)**
475
462
  - **[Examples & Guides](https://docs.xberg.io/)**
476
463
 
477
464
  ## Contributing
478
465
 
479
466
  Contributions are welcome! See [Contributing Guide](https://github.com/xberg-io/xberg/blob/main/CONTRIBUTING.md).
480
467
 
481
- ## Part of Xberg.dev
468
+ ## Part of Xberg.io
482
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.
483
473
  - [crawlberg](https://github.com/xberg-io/crawlberg) — web crawling and scraping with HTML→Markdown and headless-Chrome fallback.
484
474
  - [html-to-markdown](https://github.com/xberg-io/html-to-markdown) — fast, lossless HTML→Markdown engine.
485
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.11",
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
  }