@gueshbzh-perso/scanner 0.5.1 → 0.7.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/LICENSE +21 -0
- package/README.md +38 -14
- package/dist/camera.d.ts.map +1 -1
- package/dist/camera.js +5 -2
- package/dist/camera.js.map +1 -1
- package/dist/core.d.ts +28 -10
- package/dist/core.d.ts.map +1 -1
- package/dist/core.js +92 -42
- package/dist/core.js.map +1 -1
- package/dist/engine.d.ts +26 -3
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +159 -51
- package/dist/engine.js.map +1 -1
- package/dist/grabber.d.ts +28 -0
- package/dist/grabber.d.ts.map +1 -1
- package/dist/grabber.js +81 -3
- package/dist/grabber.js.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +12 -11
- package/dist/overlay.js.map +1 -1
- package/dist/protocol.d.ts +9 -13
- package/dist/protocol.d.ts.map +1 -1
- package/dist/reader.d.ts +33 -3
- package/dist/reader.d.ts.map +1 -1
- package/dist/reader.js +113 -25
- package/dist/reader.js.map +1 -1
- package/dist/types.d.ts +11 -5
- package/dist/types.d.ts.map +1 -1
- package/dist/wasm/THIRD_PARTY_LICENSES.md +3879 -0
- package/dist/wasm/scanner_wasm.d.ts +52 -0
- package/dist/wasm/scanner_wasm.js +87 -0
- package/dist/wasm/scanner_wasm_bg.wasm +0 -0
- package/dist/wasm/scanner_wasm_bg.wasm.d.ts +6 -0
- package/dist/worker.js +15 -17
- package/dist/worker.js.map +1 -1
- package/package.json +6 -3
- package/src/camera.ts +107 -0
- package/src/core.ts +189 -0
- package/src/engine.ts +348 -0
- package/src/feedback.ts +50 -0
- package/src/geometry.ts +55 -0
- package/src/grabber.ts +385 -0
- package/src/index.ts +20 -0
- package/src/overlay.ts +225 -0
- package/src/protocol.ts +38 -0
- package/src/reader.ts +474 -0
- package/src/scan-image.ts +88 -0
- package/src/types.ts +155 -0
- package/src/worker.ts +57 -0
- package/dist/wasm/scanner_wasm_simd_bg.wasm +0 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Rom
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# @gueshbzh-perso/scanner
|
|
2
2
|
|
|
3
3
|
Fast QR code & barcode scanning for the web. Rust/WebAssembly decoder, WebGL2
|
|
4
|
-
frame pipeline, decoding in
|
|
4
|
+
frame pipeline, parallel decoding in Web Workers, camera management and a ready-made
|
|
5
5
|
overlay. No license key, no network calls: everything runs on the device.
|
|
6
6
|
|
|
7
7
|
⚠️ Work in progress: the API may still change before 1.0.
|
|
@@ -52,7 +52,8 @@ await reader.destroy(); // removes the preview, frees the engine
|
|
|
52
52
|
| `overlay` | all on | `showRegion`, `showDetections`, `showTorchButton`, `showCameraSwitch`, `color`, or `false`. |
|
|
53
53
|
| `feedback` | beep + vibrate | `{ beep, vibrate }` or `false`. |
|
|
54
54
|
| `processing` | `{ maxDimension: 1024, backend: 'auto' }` | Decoder image size; `'webgl'`, `'canvas'` or `'auto'`. |
|
|
55
|
-
| `worker` | `true` | Decode in
|
|
55
|
+
| `worker` | `true` | Decode in Web Workers; falls back to the main thread if unavailable. |
|
|
56
|
+
| `workers` | cores − 1 (1–3) | Number of decoding workers: frames are decoded in parallel. |
|
|
56
57
|
| `wasmUrl`, `workerUrl` | auto | Override asset URLs (CDN, custom bundler setup). |
|
|
57
58
|
|
|
58
59
|
### Reader API
|
|
@@ -63,7 +64,7 @@ await reader.destroy(); // removes the preview, frees the engine
|
|
|
63
64
|
- `setRegionOfInterest(region)`
|
|
64
65
|
- `setTorch(on)`, `torchAvailable`, `setZoom(zoom)`, `switchCamera(deviceId?)`, `BarcodeReader.listCameras()`
|
|
65
66
|
- `clearCooldown(text)` — allow a code to be reported again immediately
|
|
66
|
-
- `stats` — `{ fps, decodeMs, grabMs, frameWidth, frameHeight, backend, worker,
|
|
67
|
+
- `stats` — `{ fps, decodeMs, grabMs, frameWidth, frameHeight, backend, worker, workers }`
|
|
67
68
|
- `video` — the underlying `<video>` element
|
|
68
69
|
|
|
69
70
|
Detection points are in video pixels (`video.videoWidth` space).
|
|
@@ -96,26 +97,48 @@ export default { optimizeDeps: { exclude: ['@gueshbzh-perso/scanner'] } };
|
|
|
96
97
|
If your setup cannot resolve the assets, copy `node_modules/@gueshbzh-perso/scanner/dist`
|
|
97
98
|
to your public folder and pass `workerUrl` / `wasmUrl` explicitly.
|
|
98
99
|
|
|
100
|
+
## Content Security Policy
|
|
101
|
+
|
|
102
|
+
With a CSP, allow WebAssembly compilation and the SDK's module workers
|
|
103
|
+
(served from your origin by your bundler):
|
|
104
|
+
|
|
105
|
+
```
|
|
106
|
+
script-src 'self' 'wasm-unsafe-eval';
|
|
107
|
+
worker-src 'self';
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
The camera needs `camera` allowed by `Permissions-Policy` (allowed by default
|
|
111
|
+
for the top-level page; add `allow="camera"` to an `<iframe>`).
|
|
112
|
+
|
|
113
|
+
## Low-level engine
|
|
114
|
+
|
|
115
|
+
`createEngine()` decodes frames you already have as pixels (custom pipelines,
|
|
116
|
+
`VideoFrame`s…), with the same worker pool as the reader. It is an advanced API:
|
|
117
|
+
the `Engine` interface may gain members in minor versions.
|
|
118
|
+
|
|
99
119
|
## How it works
|
|
100
120
|
|
|
101
121
|
```
|
|
102
122
|
camera ─▶ <video> ─▶ WebGL2: crop to ROI · RGB→luma · box-filter downscale · pack 4 px/texel
|
|
103
123
|
│ async readback (pixel-pack buffer + fence) — width×height bytes
|
|
104
124
|
▼
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
125
|
+
session (main thread) ─ plan ─▶ pool of Web Workers (parallel) ─▶ WASM memory ─▶ Rust decoder
|
|
126
|
+
strategy scheduling │ fast pass every frame
|
|
127
|
+
multi-frame confirmation │ + 1 fallback per frame (CPU-time share)
|
|
128
|
+
de-dup │ (try-harder, inverted, CLAHE, Sauvola, Linear)
|
|
129
|
+
◀────────── report (codes, timing) ───────┘ 1D quiet-zone check
|
|
130
|
+
new codes + live detections
|
|
111
131
|
overlay (ROI mask, highlights, torch / camera buttons) · beep · vibration
|
|
112
132
|
```
|
|
113
133
|
|
|
114
|
-
-
|
|
115
|
-
|
|
116
|
-
|
|
134
|
+
- The grab of the next frame overlaps the decoding of the previous ones, and
|
|
135
|
+
frames are decoded by several workers at once. When every worker is busy,
|
|
136
|
+
frames are skipped instead of queued, so latency never builds up.
|
|
137
|
+
- The scan state lives in one place (main thread), so multi-frame
|
|
138
|
+
confirmation and de-duplication work across workers.
|
|
117
139
|
- If WebGL2 is missing or the context is lost, the pipeline switches to Canvas 2D.
|
|
118
140
|
- If the engine crashes, the worker is restarted transparently.
|
|
141
|
+
- The engine is downloaded and compiled once, then shared by every worker.
|
|
119
142
|
|
|
120
143
|
## Browser support
|
|
121
144
|
|
|
@@ -129,7 +152,7 @@ This package is part of an npm workspace: run commands from the repository root
|
|
|
129
152
|
|
|
130
153
|
```bash
|
|
131
154
|
npm install # at the repository root
|
|
132
|
-
npm run build # Rust → WASM
|
|
155
|
+
npm run build # Rust → WASM, then TypeScript
|
|
133
156
|
npm run test:e2e # headless Chromium with a fake camera (needs ffmpeg + Playwright)
|
|
134
157
|
```
|
|
135
158
|
|
|
@@ -139,4 +162,5 @@ automatically on first run; `wasm-opt` comes from the `binaryen` devDependency.
|
|
|
139
162
|
|
|
140
163
|
## License
|
|
141
164
|
|
|
142
|
-
MIT
|
|
165
|
+
MIT. The WebAssembly engine is compiled from Rust crates under permissive
|
|
166
|
+
licenses: see `dist/wasm/THIRD_PARTY_LICENSES.md` in the package.
|
package/dist/camera.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"camera.d.ts","sourceRoot":"","sources":["../src/camera.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAoB,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"camera.d.ts","sourceRoot":"","sources":["../src/camera.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAoB,MAAM,YAAY,CAAC;AAalE,wBAAgB,gBAAgB,IAAI,MAAM,GAAG,SAAS,CAMrD;AAED,wBAAgB,cAAc,CAAC,EAAE,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAM3D;AAED,wBAAsB,UAAU,CAAC,OAAO,GAAE,aAAkB,GAAG,OAAO,CAAC,WAAW,CAAC,CA6BlF;AAED,yFAAyF;AACzF,wBAAsB,WAAW,IAAI,OAAO,CAAC,eAAe,EAAE,CAAC,CAI9D;AAED,UAAU,oBAAqB,SAAQ,sBAAsB;IAC3D,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,IAAI,CAAC,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACnD,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;CACtB;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,gBAAgB,GAAG,SAAS,GAAG,oBAAoB,CAMtF;AAED,wBAAsB,QAAQ,CAAC,KAAK,EAAE,gBAAgB,EAAE,EAAE,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAGlF;AAED,wBAAsB,OAAO,CAAC,KAAK,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAKlF"}
|
package/dist/camera.js
CHANGED
|
@@ -3,10 +3,13 @@ const RESOLUTIONS = {
|
|
|
3
3
|
hd: [1280, 720],
|
|
4
4
|
fhd: [1920, 1080],
|
|
5
5
|
};
|
|
6
|
-
|
|
6
|
+
// Namespaced: the host page shares localStorage with the SDK.
|
|
7
|
+
const STORAGE_KEY = '@gueshbzh-perso/scanner:cameraId';
|
|
8
|
+
/** Key used up to 0.6: still read, so the remembered camera survives the upgrade. */
|
|
9
|
+
const LEGACY_STORAGE_KEY = 'scanner.cameraId';
|
|
7
10
|
export function rememberedCamera() {
|
|
8
11
|
try {
|
|
9
|
-
return localStorage.getItem(STORAGE_KEY) ?? undefined;
|
|
12
|
+
return localStorage.getItem(STORAGE_KEY) ?? localStorage.getItem(LEGACY_STORAGE_KEY) ?? undefined;
|
|
10
13
|
}
|
|
11
14
|
catch {
|
|
12
15
|
return undefined;
|
package/dist/camera.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"camera.js","sourceRoot":"","sources":["../src/camera.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,GAA+C;IAC9D,EAAE,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC;IACd,EAAE,EAAE,CAAC,IAAI,EAAE,GAAG,CAAC;IACf,GAAG,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC;CAClB,CAAC;AAEF,MAAM,WAAW,GAAG,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"camera.js","sourceRoot":"","sources":["../src/camera.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,GAA+C;IAC9D,EAAE,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC;IACd,EAAE,EAAE,CAAC,IAAI,EAAE,GAAG,CAAC;IACf,GAAG,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC;CAClB,CAAC;AAEF,8DAA8D;AAC9D,MAAM,WAAW,GAAG,kCAAkC,CAAC;AACvD,qFAAqF;AACrF,MAAM,kBAAkB,GAAG,kBAAkB,CAAC;AAE9C,MAAM,UAAU,gBAAgB;IAC9B,IAAI,CAAC;QACH,OAAO,YAAY,CAAC,OAAO,CAAC,WAAW,CAAC,IAAI,YAAY,CAAC,OAAO,CAAC,kBAAkB,CAAC,IAAI,SAAS,CAAC;IACpG,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,EAAsB;IACnD,IAAI,CAAC;QACH,IAAI,EAAE;YAAE,YAAY,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;IAChD,CAAC;IAAC,MAAM,CAAC;QACP,iCAAiC;IACnC,CAAC;AACH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,UAAyB,EAAE;IAC1D,IAAI,CAAC,SAAS,CAAC,YAAY,EAAE,YAAY,EAAE,CAAC;QAC1C,MAAM,IAAI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AAI,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC;IAC7D,MAAM,KAAK,CAAC,gBAAgB,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,IAAI,EAAE,KAAK,EAA6B,CAAC,EAAE,CAAC,CAAC;AAC3F,CAAC;AAED,KAAK,UAAU,aAAa,CAAC,KAAuB,EAAE,GAA4B;IAChF,MAAM,IAAI,GAAG,YAAY,CAAC,KAAK,CAA4B,CAAC;IAC5D,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE;QAC9C,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,OAAO,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC;IACjE,CAAC,CAAC,CAAC;IACH,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO;IACnC,IAAI,CAAC;QACH,MAAM,KAAK,CAAC,gBAAgB,CAAC,EAAE,QAAQ,EAAE,CAAC,MAAM,CAAC,WAAW,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IACtG,CAAC;IAAC,MAAM,CAAC;QACP,iBAAiB;IACnB,CAAC;AACH,CAAC"}
|
package/dist/core.d.ts
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { FramePlan, FrameReport, PixelFormat, ScanResult, WasmScanConfig } from './wasm/scanner_wasm.js';
|
|
2
2
|
import type { Detection, EngineOptions } from './types.js';
|
|
3
|
-
|
|
4
|
-
export declare function simdSupported(): boolean;
|
|
3
|
+
export type { FramePlan, FrameReport };
|
|
5
4
|
/** Default location of the engine binary, next to this module. */
|
|
6
|
-
export declare function defaultWasmUrl(
|
|
5
|
+
export declare function defaultWasmUrl(): URL;
|
|
6
|
+
/**
|
|
7
|
+
* Compile the engine once. The compiled module can be posted to any number
|
|
8
|
+
* of workers, which then only instantiate it (no second download or compile).
|
|
9
|
+
*/
|
|
10
|
+
export declare function compileWasm(url: string | URL): Promise<WebAssembly.Module>;
|
|
11
|
+
/** Instantiate the engine in this realm (once). Returns the engine version. */
|
|
12
|
+
export declare function loadWasm(source: string | URL | WebAssembly.Module): Promise<string>;
|
|
7
13
|
/** Keep only the engine options (drops URLs and other non-cloneable values). */
|
|
8
14
|
export declare function pickEngineOptions(o: EngineOptions): EngineOptions;
|
|
9
15
|
export declare function toWasmConfig(o: EngineOptions, extra?: Partial<WasmScanConfig>): WasmScanConfig;
|
|
@@ -15,17 +21,29 @@ export interface FrameOutcome {
|
|
|
15
21
|
live: Detection[];
|
|
16
22
|
decodeMs: number;
|
|
17
23
|
}
|
|
18
|
-
|
|
19
|
-
|
|
24
|
+
/** The scan session of a camera stream (state only, cheap calls). */
|
|
25
|
+
export declare class SessionCore {
|
|
20
26
|
private session;
|
|
21
|
-
private scanners;
|
|
22
|
-
private constructor();
|
|
23
|
-
static create(wasmUrl?: string | URL): Promise<EngineCore>;
|
|
24
27
|
configure(options: EngineOptions): void;
|
|
28
|
+
/** Strategy plan of the next frame, for a `DecoderCore` configured the same way. */
|
|
29
|
+
plan(): FramePlan;
|
|
30
|
+
/** Record a decoded frame; returns the new codes and the live ones. */
|
|
31
|
+
commit(report: FrameReport): FrameOutcome;
|
|
32
|
+
/** Decode on this thread (inline engine): plan, decode and commit at once. */
|
|
25
33
|
process(pixels: Uint8Array, width: number, height: number, format: PixelFormat): FrameOutcome;
|
|
26
|
-
scan(pixels: Uint8Array, width: number, height: number, format: PixelFormat, options: EngineOptions): Detection[];
|
|
27
34
|
reset(): void;
|
|
28
35
|
clearCooldown(text: string): void;
|
|
29
36
|
destroy(): void;
|
|
37
|
+
private active;
|
|
38
|
+
}
|
|
39
|
+
/** Frame decoding (stateless) and still-image scanning: the expensive part. */
|
|
40
|
+
export declare class DecoderCore {
|
|
41
|
+
private decoder;
|
|
42
|
+
private scanners;
|
|
43
|
+
configure(options: EngineOptions): void;
|
|
44
|
+
decode(pixels: Uint8Array, width: number, height: number, format: PixelFormat, plan: FramePlan): FrameReport;
|
|
45
|
+
/** One-shot scan of a still image, running every strategy. */
|
|
46
|
+
scan(pixels: Uint8Array, width: number, height: number, format: PixelFormat, options: EngineOptions): Detection[];
|
|
47
|
+
destroy(): void;
|
|
30
48
|
}
|
|
31
49
|
//# sourceMappingURL=core.d.ts.map
|
package/dist/core.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,WAAW,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAC9G,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE3D,YAAY,EAAE,SAAS,EAAE,WAAW,EAAE,CAAC;AAEvC,kEAAkE;AAClE,wBAAgB,cAAc,IAAI,GAAG,CAEpC;AAED;;;GAGG;AACH,wBAAsB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,GAAG,OAAO,CAAC,WAAW,CAAC,MAAM,CAAC,CAQhF;AAID,+EAA+E;AAC/E,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,GAAG,GAAG,WAAW,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CA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AAM,EAAE,UAAU,EAClB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,WAAW,EACnB,OAAO,EAAE,aAAa,GACrB,SAAS,EAAE;IAiBd,OAAO,IAAI,IAAI;CAMhB"}
|
package/dist/core.js
CHANGED
|
@@ -1,23 +1,35 @@
|
|
|
1
|
-
// Engine core: owns the WebAssembly module and
|
|
2
|
-
//
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
// Engine core: owns the WebAssembly module and its objects.
|
|
2
|
+
//
|
|
3
|
+
// Two roles, so that frames can be decoded on several threads while a single
|
|
4
|
+
// session keeps the state (strategy scheduling, multi-frame confirmation,
|
|
5
|
+
// de-duplication):
|
|
6
|
+
// - `SessionCore`: the session. Cheap calls (`plan`, `commit`), main thread.
|
|
7
|
+
// - `DecoderCore`: the expensive decoding, one per Web Worker.
|
|
8
|
+
// The inline engine (no Worker support) uses both on the main thread.
|
|
9
|
+
import init, { WasmFrameDecoder, WasmScanner, WasmScanSession, version } from './wasm/scanner_wasm.js';
|
|
10
|
+
/** Default location of the engine binary, next to this module. */
|
|
11
|
+
export function defaultWasmUrl() {
|
|
12
|
+
return new URL('./wasm/scanner_wasm_bg.wasm', import.meta.url);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Compile the engine once. The compiled module can be posted to any number
|
|
16
|
+
* of workers, which then only instantiate it (no second download or compile).
|
|
17
|
+
*/
|
|
18
|
+
export async function compileWasm(url) {
|
|
19
|
+
const response = fetch(url);
|
|
6
20
|
try {
|
|
7
|
-
return WebAssembly.
|
|
8
|
-
0, 97, 115, 109, 1, 0, 0, 0, 1, 5, 1, 96, 0, 1, 123, 3, 2, 1, 0, 10, 10, 1, 8, 0, 65, 0, 253, 15, 253,
|
|
9
|
-
98, 11,
|
|
10
|
-
]));
|
|
21
|
+
return await WebAssembly.compileStreaming(response);
|
|
11
22
|
}
|
|
12
23
|
catch {
|
|
13
|
-
|
|
24
|
+
// Servers that do not send `application/wasm` reject streaming compilation.
|
|
25
|
+
return WebAssembly.compile(await (await response).arrayBuffer());
|
|
14
26
|
}
|
|
15
27
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
28
|
+
let initPromise = null;
|
|
29
|
+
/** Instantiate the engine in this realm (once). Returns the engine version. */
|
|
30
|
+
export function loadWasm(source) {
|
|
31
|
+
initPromise ?? (initPromise = init({ module_or_path: source }).then(() => version()));
|
|
32
|
+
return initPromise;
|
|
21
33
|
}
|
|
22
34
|
/** Keep only the engine options (drops URLs and other non-cloneable values). */
|
|
23
35
|
export function pickEngineOptions(o) {
|
|
@@ -39,42 +51,86 @@ export function toWasmConfig(o, extra = {}) {
|
|
|
39
51
|
cfg.linearConfirmations = o.linearConfirmations;
|
|
40
52
|
return cfg;
|
|
41
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* Configuration of camera sessions and their decoders: they must be equal,
|
|
56
|
+
* since a plan refers to the decoder's list of fallback strategies.
|
|
57
|
+
*/
|
|
58
|
+
function streamConfig(o) {
|
|
59
|
+
// Back-pressure is handled by the SDK (frames are skipped, never queued),
|
|
60
|
+
// so the engine's own frame-skipping throttle would only drop useful frames.
|
|
61
|
+
return toWasmConfig(o, { adaptiveThrottle: false });
|
|
62
|
+
}
|
|
42
63
|
export function toDetection(r) {
|
|
43
64
|
const d = { text: r.text, format: r.format, points: r.points, timestamp: r.timestampMs };
|
|
44
65
|
if (r.rawBytes)
|
|
45
66
|
d.rawBytes = r.rawBytes;
|
|
46
67
|
return d;
|
|
47
68
|
}
|
|
48
|
-
|
|
49
|
-
export class
|
|
50
|
-
constructor(
|
|
51
|
-
this.version = version;
|
|
69
|
+
/** The scan session of a camera stream (state only, cheap calls). */
|
|
70
|
+
export class SessionCore {
|
|
71
|
+
constructor() {
|
|
52
72
|
this.session = null;
|
|
53
|
-
this.scanners = new Map();
|
|
54
|
-
}
|
|
55
|
-
static async create(wasmUrl) {
|
|
56
|
-
initPromise ?? (initPromise = init({ module_or_path: wasmUrl ?? defaultWasmUrl() }));
|
|
57
|
-
await initPromise;
|
|
58
|
-
return new EngineCore(version());
|
|
59
73
|
}
|
|
60
74
|
configure(options) {
|
|
61
75
|
this.session?.free();
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
76
|
+
this.session = new WasmScanSession(streamConfig(options));
|
|
77
|
+
}
|
|
78
|
+
/** Strategy plan of the next frame, for a `DecoderCore` configured the same way. */
|
|
79
|
+
plan() {
|
|
80
|
+
return this.active().plan();
|
|
81
|
+
}
|
|
82
|
+
/** Record a decoded frame; returns the new codes and the live ones. */
|
|
83
|
+
commit(report) {
|
|
84
|
+
const session = this.active();
|
|
85
|
+
const fresh = session.commit(report);
|
|
86
|
+
const results = fresh ? fresh.map(toDetection) : null;
|
|
87
|
+
return { results, live: results ?? session.lastDetections.map(toDetection), decodeMs: report.elapsedMs };
|
|
65
88
|
}
|
|
89
|
+
/** Decode on this thread (inline engine): plan, decode and commit at once. */
|
|
66
90
|
process(pixels, width, height, format) {
|
|
67
|
-
const session = this.
|
|
68
|
-
if (!session)
|
|
69
|
-
throw new Error('Engine not configured');
|
|
91
|
+
const session = this.active();
|
|
70
92
|
// Write straight into WASM memory: avoids one more copy of the frame.
|
|
71
93
|
session.frameBuffer(pixels.length).set(pixels);
|
|
72
94
|
const t0 = performance.now();
|
|
73
|
-
const
|
|
95
|
+
const fresh = session.processFrameBuffer(width, height, format);
|
|
74
96
|
const decodeMs = performance.now() - t0;
|
|
75
|
-
const
|
|
76
|
-
return { results
|
|
97
|
+
const results = fresh ? fresh.map(toDetection) : null;
|
|
98
|
+
return { results, live: results ?? session.lastDetections.map(toDetection), decodeMs };
|
|
99
|
+
}
|
|
100
|
+
reset() {
|
|
101
|
+
this.session?.reset();
|
|
102
|
+
}
|
|
103
|
+
clearCooldown(text) {
|
|
104
|
+
this.session?.clearCooldown(text);
|
|
105
|
+
}
|
|
106
|
+
destroy() {
|
|
107
|
+
this.session?.free();
|
|
108
|
+
this.session = null;
|
|
109
|
+
}
|
|
110
|
+
active() {
|
|
111
|
+
if (!this.session)
|
|
112
|
+
throw new Error('Engine not configured');
|
|
113
|
+
return this.session;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
/** Frame decoding (stateless) and still-image scanning: the expensive part. */
|
|
117
|
+
export class DecoderCore {
|
|
118
|
+
constructor() {
|
|
119
|
+
this.decoder = null;
|
|
120
|
+
this.scanners = new Map();
|
|
77
121
|
}
|
|
122
|
+
configure(options) {
|
|
123
|
+
this.decoder?.free();
|
|
124
|
+
this.decoder = new WasmFrameDecoder(streamConfig(options));
|
|
125
|
+
}
|
|
126
|
+
decode(pixels, width, height, format, plan) {
|
|
127
|
+
const decoder = this.decoder;
|
|
128
|
+
if (!decoder)
|
|
129
|
+
throw new Error('Engine not configured');
|
|
130
|
+
decoder.frameBuffer(pixels.length).set(pixels);
|
|
131
|
+
return decoder.decodeFrameBuffer(width, height, format, plan);
|
|
132
|
+
}
|
|
133
|
+
/** One-shot scan of a still image, running every strategy. */
|
|
78
134
|
scan(pixels, width, height, format, options) {
|
|
79
135
|
const config = toWasmConfig(options);
|
|
80
136
|
const key = JSON.stringify(config);
|
|
@@ -91,15 +147,9 @@ export class EngineCore {
|
|
|
91
147
|
scanner.frameBuffer(pixels.length).set(pixels);
|
|
92
148
|
return scanner.scanFrameBuffer(width, height, format).map(toDetection);
|
|
93
149
|
}
|
|
94
|
-
reset() {
|
|
95
|
-
this.session?.reset();
|
|
96
|
-
}
|
|
97
|
-
clearCooldown(text) {
|
|
98
|
-
this.session?.clearCooldown(text);
|
|
99
|
-
}
|
|
100
150
|
destroy() {
|
|
101
|
-
this.
|
|
102
|
-
this.
|
|
151
|
+
this.decoder?.free();
|
|
152
|
+
this.decoder = null;
|
|
103
153
|
for (const s of this.scanners.values())
|
|
104
154
|
s.free();
|
|
105
155
|
this.scanners.clear();
|
package/dist/core.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.js","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"core.js","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,EAAE;AACF,6EAA6E;AAC7E,0EAA0E;AAC1E,mBAAmB;AACnB,6EAA6E;AAC7E,+DAA+D;AAC/D,sEAAsE;AACtE,OAAO,IAAI,EAAE,EAAE,gBAAgB,EAAE,WAAW,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAMvG,kEAAkE;AAClE,MAAM,UAAU,cAAc;IAC5B,OAAO,IAAI,GAAG,CAAC,6BAA6B,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACjE,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,GAAiB;IACjD,MAAM,QAAQ,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;IAC5B,IAAI,CAAC;QACH,OAAO,MAAM,WAAW,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC;IACtD,CAAC;IAAC,MAAM,CAAC;QACP,4EAA4E;QAC5E,OAAO,WAAW,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,QAAQ,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC;IACnE,CAAC;AACH,CAAC;AAED,IAAI,WAAW,GAA2B,IAAI,CAAC;AAE/C,+EAA+E;AAC/E,MAAM,UAAU,QAAQ,CAAC,MAAyC;IAChE,WAAW,KAAX,WAAW,GAAK,IAAI,CAAC,EAAE,cAAc,EAAE,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC,EAAC;IACvE,OAAO,WAAW,CAAC;AACrB,CAAC;AAED,gFAAgF;AAChF,MAAM,UAAU,iBAAiB,CAAC,CAAgB;IAChD,MAAM,EAAE,OAAO,EAAE,aAAa,EAAE,SAA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EAAE,MAAM,CAAC,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IACzE,CAAC;IAED,OAAO;QACL,IAAI,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;QACpB,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE;YAAE,CAAC,CAAC,IAAI,EAAE,CAAC;QACjD,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;IACxB,CAAC;CACF"}
|
package/dist/engine.d.ts
CHANGED
|
@@ -9,8 +9,9 @@ export interface FrameReply {
|
|
|
9
9
|
}
|
|
10
10
|
export interface Engine {
|
|
11
11
|
readonly inWorker: boolean;
|
|
12
|
-
readonly simd: boolean;
|
|
13
12
|
readonly version: string;
|
|
13
|
+
/** Frames that can be decoded at the same time (number of workers). */
|
|
14
|
+
readonly concurrency: number;
|
|
14
15
|
configure(options: EngineOptions): Promise<void>;
|
|
15
16
|
/** Decode a camera frame. `buffer` is transferred and returned in the reply. */
|
|
16
17
|
processFrame(buffer: ArrayBuffer, width: number, height: number, format: PixelFormat): Promise<FrameReply>;
|
|
@@ -20,8 +21,30 @@ export interface Engine {
|
|
|
20
21
|
clearCooldown(text: string): Promise<void>;
|
|
21
22
|
destroy(): void;
|
|
22
23
|
}
|
|
23
|
-
/**
|
|
24
|
+
/**
|
|
25
|
+
* Default pool size: one worker per core, minus one for the main thread
|
|
26
|
+
* (camera, GPU, UI), capped at 3. Beyond 3 the frame rate is limited by the
|
|
27
|
+
* frame grab (~55 ms on a Galaxy A14, so ~18 fps) and more workers only cost
|
|
28
|
+
* memory (one WebAssembly instance each).
|
|
29
|
+
*/
|
|
30
|
+
export declare function defaultWorkerCount(): number;
|
|
31
|
+
/**
|
|
32
|
+
* The live worker with the fewest requests in progress. Dead workers are
|
|
33
|
+
* skipped: they reject instantly, so they always look the least busy and
|
|
34
|
+
* would otherwise receive most frames.
|
|
35
|
+
*/
|
|
36
|
+
export declare function pickWorker<W extends {
|
|
37
|
+
alive: boolean;
|
|
38
|
+
busy: number;
|
|
39
|
+
}>(workers: readonly W[]): W | undefined;
|
|
40
|
+
/**
|
|
41
|
+
* Load the engine: a pool of Web Workers when possible, else the main thread.
|
|
42
|
+
*
|
|
43
|
+
* Low-level API, for custom pipelines (frames you already have as pixels).
|
|
44
|
+
* Most applications should use `BarcodeReader` or `scanImage`. The `Engine`
|
|
45
|
+
* interface may gain members in minor versions.
|
|
46
|
+
*/
|
|
24
47
|
export declare function createEngine(options?: AssetOptions): Promise<Engine>;
|
|
25
|
-
/** Engine shared by `scanImage` calls. */
|
|
48
|
+
/** Engine shared by `scanImage` calls (one worker is enough for still images). */
|
|
26
49
|
export declare function sharedEngine(options?: AssetOptions): Promise<Engine>;
|
|
27
50
|
//# sourceMappingURL=engine.d.ts.map
|
package/dist/engine.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEzE,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC;IAC5B,IAAI,EAAE,SAAS,EAAE,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,+CAA+C;IAC/C,MAAM,EAAE,WAAW,CAAC;CACrB;AAED,MAAM,WAAW,MAAM;IACrB,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,uEAAuE;IACvE,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC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