@3sln/emon 0.3.0-preview.3 → 0.3.0-preview.5

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/emon.wasm CHANGED
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@3sln/emon",
3
- "version": "0.3.0-preview.3",
3
+ "version": "0.3.0-preview.5",
4
4
  "license": "MIT",
5
5
  "description": "emon's JavaScript SDK: PDFs and images to semantic HTML in the browser, over the WASM binding (DEVLOG P9.3). The library has no dependencies; the devDependencies are the browser test harness and the tesseract.js engine the OCR adapter drives.",
6
6
  "keywords": ["pdf", "html", "semantic-html", "ocr", "document-conversion", "scraping", "wasm", "webassembly", "tables"],
@@ -25,7 +25,7 @@
25
25
  "publishConfig": { "access": "public" },
26
26
  "engines": { "node": ">=22" },
27
27
  "peerDependencies": {
28
- "@3sln/pdfium-wasm": "^0.3.0-preview.3"
28
+ "@3sln/pdfium-wasm": "^0.3.0-preview.5"
29
29
  },
30
30
  "peerDependenciesMeta": {
31
31
  "@3sln/pdfium-wasm": { "optional": true }
package/src/tesseract.js CHANGED
@@ -80,13 +80,29 @@ export function tesseractAdapter({ createWorker, languages = ['eng'], oem = 1, w
80
80
  s = {
81
81
  busy: 0,
82
82
  promise: (async () => {
83
- const w = await createWorker(key, oem, workerOptions);
83
+ // tesseract.js reports language and model initialization failures through
84
+ // errorHandler even when its createWorker promise remains pending.
85
+ let fail;
86
+ const failed = new Promise((_, reject) => { fail = reject; });
87
+ const w = await Promise.race([createWorker(key, oem, {
88
+ ...workerOptions,
89
+ errorHandler(error) {
90
+ fail(error);
91
+ workerOptions.errorHandler?.(error);
92
+ },
93
+ }), failed]);
84
94
  // the final candidates of the beam search, not one per timestep: the native adapter's setting (D213)
85
- await w.setParameters({ lstm_choice_mode: '2' });
95
+ try {
96
+ await w.setParameters({ lstm_choice_mode: '2' });
97
+ } catch (e) {
98
+ await w.terminate();
99
+ throw e;
100
+ }
86
101
  return w;
87
102
  })(),
88
103
  };
89
104
  pool.push(s);
105
+ s.promise.catch(() => pool.splice(pool.indexOf(s), 1));
90
106
  }
91
107
  return s || pool.reduce((a, b) => (a.busy <= b.busy ? a : b));
92
108
  };