tapirscan 1.2.1 → 1.3.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.
Files changed (84) hide show
  1. package/LICENSE +220 -0
  2. package/README.md +384 -226
  3. package/dist/browser-worker.d.ts +33 -0
  4. package/dist/browser-worker.js +83 -0
  5. package/dist/browser.d.ts +44 -0
  6. package/dist/browser.js +211 -0
  7. package/dist/freeze.d.ts +6 -0
  8. package/dist/freeze.js +7 -0
  9. package/dist/index.d.ts +53 -46
  10. package/dist/index.js +168 -209
  11. package/dist/layout.d.ts +19 -0
  12. package/dist/layout.js +27 -0
  13. package/dist/multiformat/format-registry.d.ts +26 -0
  14. package/dist/multiformat/format-registry.js +63 -0
  15. package/dist/multiformat/formats.d.ts +4 -24
  16. package/dist/multiformat/formats.js +15 -46
  17. package/dist/rust-session.d.ts +19 -0
  18. package/dist/rust-session.js +102 -0
  19. package/examples/camera.html +28 -29
  20. package/examples/vite/README.md +31 -0
  21. package/examples/vite/index.html +14 -0
  22. package/examples/vite/main.js +33 -0
  23. package/examples/vite/package.json +16 -0
  24. package/examples/vite/vite.config.js +6 -0
  25. package/package.json +28 -11
  26. package/wasm/build.json +295 -0
  27. package/wasm/experimental-turbo16.wasm +0 -0
  28. package/wasm/experimental-turbo2.wasm +0 -0
  29. package/wasm/experimental-turbo4.wasm +0 -0
  30. package/wasm/experimental-turbo8.wasm +0 -0
  31. package/wasm/high.wasm +0 -0
  32. package/wasm/low.wasm +0 -0
  33. package/wasm/medium.wasm +0 -0
  34. package/wasm/very-high.wasm +0 -0
  35. package/dist/completion-host.d.mts +0 -40
  36. package/dist/completion-host.mjs +0 -188
  37. package/dist/detail-20260914/continuity.d.mts +0 -2
  38. package/dist/detail-20260914/continuity.mjs +0 -62
  39. package/dist/detail-20260914/detail-proposals-rich.d.mts +0 -13
  40. package/dist/detail-20260914/detail-proposals-rich.mjs +0 -53
  41. package/dist/detail-20260914/direct-recovery.d.mts +0 -28
  42. package/dist/detail-20260914/direct-recovery.mjs +0 -139
  43. package/dist/detail-20260914/host.d.mts +0 -40
  44. package/dist/detail-20260914/host.mjs +0 -280
  45. package/dist/detail-20260914/scanner.d.mts +0 -12
  46. package/dist/detail-20260914/scanner.mjs +0 -64
  47. package/dist/detail-20260914/source-evidence.d.mts +0 -10
  48. package/dist/detail-20260914/source-evidence.mjs +0 -94
  49. package/dist/detail-canvas.d.ts +0 -35
  50. package/dist/detail-canvas.js +0 -73
  51. package/dist/detail-runtime/direct-recovery.d.mts +0 -28
  52. package/dist/detail-runtime/direct-recovery.mjs +0 -142
  53. package/dist/detail-runtime/host.d.mts +0 -40
  54. package/dist/detail-runtime/host.mjs +0 -284
  55. package/dist/detail-runtime/scanner.d.mts +0 -12
  56. package/dist/detail-runtime/scanner.mjs +0 -70
  57. package/dist/detail.d.ts +0 -20
  58. package/dist/detail.js +0 -84
  59. package/dist/host.d.ts +0 -112
  60. package/dist/host.js +0 -184
  61. package/dist/host64.d.ts +0 -112
  62. package/dist/host64.js +0 -184
  63. package/dist/multiformat/coverage.d.ts +0 -7
  64. package/dist/multiformat/coverage.js +0 -26
  65. package/dist/multiformat/geometry.d.ts +0 -37
  66. package/dist/multiformat/geometry.js +0 -132
  67. package/dist/multiformat/linear-duplicates.d.ts +0 -16
  68. package/dist/multiformat/linear-duplicates.js +0 -163
  69. package/dist/multiformat/pixels.d.ts +0 -3
  70. package/dist/multiformat/pixels.js +0 -36
  71. package/dist/multiformat/scanner.d.ts +0 -60
  72. package/dist/multiformat/scanner.js +0 -382
  73. package/dist/multiformat-host.d.ts +0 -121
  74. package/dist/multiformat-host.js +0 -207
  75. package/dist/policy.d.ts +0 -12
  76. package/dist/policy.js +0 -12
  77. package/examples/scan-worker.mjs +0 -20
  78. package/examples/worker-client.mjs +0 -63
  79. package/wasm/high-shared-retail-portable-20260919.wasm +0 -0
  80. package/wasm/low-shared-retail-portable-20260919.wasm +0 -0
  81. package/wasm/medium-shared-retail-portable-20260919.wasm +0 -0
  82. package/wasm/multiformat.json +0 -7
  83. package/wasm/multiformat.wasm +0 -0
  84. package/wasm/very-high-shared-retail-portable-20260919.wasm +0 -0
@@ -1,382 +0,0 @@
1
- import { mergeLinearDuplicates } from "./linear-duplicates.js";
2
- import { ReleaseDetailScanner, fitLimits } from "../detail.js";
3
- import { IndependentScanner } from "../completion-host.mjs";
4
- import { policy } from "../policy.js";
5
- import { rectify, rectificationPlan, project, distinctReads, polygonOverlap } from "./geometry.js";
6
- import { toGray } from "./pixels.js";
7
- import { maskFor, resolveFormats, linearFormats as supportedLinearFormats, } from "./formats.js";
8
- function scanGray(image) {
9
- return image.channels === 1 && image.stride === image.width
10
- ? image.data.subarray(0, image.width * image.height)
11
- : toGray(image);
12
- }
13
- /** Shared retail evidence over primary profiles, plus independent additional readers. */
14
- export class MediumMultiformatScanner {
15
- medium;
16
- mode = "medium";
17
- extra;
18
- handle = 0;
19
- rgba = false;
20
- crop = false;
21
- effort = 1;
22
- qrEffort = 1;
23
- disposed = false;
24
- constructor() { }
25
- static async create(mediumBytes, extraBytes, mode = "medium", recoveryBytes) {
26
- const scanner = new MediumMultiformatScanner();
27
- try {
28
- scanner.mode = mode;
29
- scanner.effort = { low: 0, medium: 1, high: 2, "very-high": 2 }[mode];
30
- scanner.qrEffort = { low: 0, medium: 1, high: 2, "very-high": 3 }[mode];
31
- if (mediumBytes)
32
- scanner.medium =
33
- mode !== "low" && recoveryBytes
34
- ? await ReleaseDetailScanner.create(mediumBytes, recoveryBytes, mode)
35
- : await IndependentScanner.create(mediumBytes);
36
- if (extraBytes) {
37
- const instance = await WebAssembly.instantiate(extraBytes, {});
38
- const e = instance.instance.exports;
39
- for (const name of [
40
- "multi_new",
41
- "multi_free",
42
- "multi_prepare",
43
- "multi_input",
44
- "multi_scan",
45
- "multi_output",
46
- "multi_output_len",
47
- ]) {
48
- if (typeof e[name] !== "function")
49
- throw Error(`Invalid multiformat WASM export: ${name}`);
50
- }
51
- if (!(e.memory instanceof WebAssembly.Memory))
52
- throw Error("Invalid multiformat WASM memory.");
53
- scanner.rgba =
54
- typeof e.multi_capabilities === "function" &&
55
- (e.multi_capabilities() & 4) !== 0 &&
56
- [e.multi_prepare_rgba, e.multi_input_rgba, e.multi_scan_rgba].every((f) => typeof f === "function");
57
- scanner.crop =
58
- typeof e.multi_capabilities === "function" &&
59
- (e.multi_capabilities() & 16) !== 0 &&
60
- [e.multi_capture_source, e.multi_crop_transform, e.multi_crop].every((f) => typeof f === "function");
61
- scanner.extra = e;
62
- scanner.handle = e.multi_new();
63
- if (!scanner.handle)
64
- throw Error("Could not create additional reader session.");
65
- }
66
- return scanner;
67
- }
68
- catch (error) {
69
- scanner.dispose();
70
- throw error;
71
- }
72
- }
73
- scan(image, inputFormats, options = {}) {
74
- if (this.disposed)
75
- throw Error("Scanner is disposed.");
76
- const medium = this.medium;
77
- const scanPolicy = { ...policy, finishCandidates: options.finishCandidates ?? false };
78
- const formats = resolveFormats(inputFormats);
79
- const eanAddOnSymbol = options.eanAddOnSymbol ?? "Ignore";
80
- if (!["Ignore", "Read", "Require"].includes(eanAddOnSymbol))
81
- throw Error("Unknown EAN add-on policy.");
82
- const requestedStrategy = options.linearStrategy ?? "scanlines";
83
- if (!["scanlines", "medium-localized"].includes(requestedStrategy))
84
- throw Error("Unknown linear strategy.");
85
- // Supplements extend beyond the frozen Medium crop, so they require the
86
- // full-frame supplemental pass. Default EAN13 remains untouched.
87
- const linearStrategy = eanAddOnSymbol === "Ignore" ? requestedStrategy : "scanlines";
88
- const localized = linearStrategy === "medium-localized" &&
89
- formats.some((f) => f !== "EAN13" && f !== "UPCA" && supportedLinearFormats.includes(f));
90
- let proposals = [];
91
- const start = performance.now();
92
- const { width, height, channels, stride, data } = image;
93
- if (!Number.isSafeInteger(width) ||
94
- !Number.isSafeInteger(height) ||
95
- width < 3 ||
96
- height < 3 ||
97
- width * height > 32 * 1024 * 1024 ||
98
- ![1, 3, 4].includes(channels) ||
99
- !Number.isSafeInteger(stride) ||
100
- stride < width * channels ||
101
- !(data instanceof Uint8Array) ||
102
- data.length < (height - 1) * stride + width * channels)
103
- throw Error("Invalid image dimensions or buffer.");
104
- const barcodes = [], regions = [];
105
- let primary;
106
- let unfinished = false, mediumMs = 0, additionalMs = 0, preparationMs = 0, localizationMs = 0;
107
- const sharedRetail = this.mode === "medium" &&
108
- eanAddOnSymbol === "Ignore" &&
109
- formats.some((f) => f === "EAN8" || f === "UPCE");
110
- const retailPolicy = { ...scanPolicy, ...(sharedRetail ? { retailMask: 15 } : {}) };
111
- const extraFormats = formats.filter((f) => (!sharedRetail || (f !== "EAN8" && f !== "UPCE")) &&
112
- (eanAddOnSymbol !== "Ignore" || (f !== "EAN13" && f !== "UPCA")));
113
- const conservative = medium instanceof ReleaseDetailScanner &&
114
- !localized &&
115
- eanAddOnSymbol === "Ignore" &&
116
- formats.some((f) => f === "EAN13" || f === "UPCA") &&
117
- extraFormats.some((f) => supportedLinearFormats.includes(f));
118
- let preparedGray;
119
- let preLinear;
120
- const coverage = [];
121
- if (conservative) {
122
- const prepareStart = performance.now();
123
- preparedGray = scanGray(image);
124
- preparationMs += performance.now() - prepareStart;
125
- const extraStart = performance.now();
126
- preLinear = this.scanExtra(preparedGray, width, height, extraFormats.filter((f) => supportedLinearFormats.includes(f)), this.effort, eanAddOnSymbol);
127
- additionalMs += performance.now() - extraStart;
128
- for (const read of preLinear.barcodes) {
129
- const error = read.error ?? Infinity;
130
- const checked = ["EAN8", "UPCE", "Code128"].includes(read.format) && read.support >= 3 && error <= 0.08;
131
- const unchecked = ["Code39", "ITF"].includes(read.format) &&
132
- read.support >= 8 &&
133
- error <= 0.035 &&
134
- read.text.length >= 8;
135
- if (checked || unchecked)
136
- coverage.push(read.polygon);
137
- }
138
- }
139
- if (sharedRetail || formats.includes("EAN13") || formats.includes("UPCA")) {
140
- if (!medium)
141
- throw Error("EAN13 engine has not been initialized.");
142
- const begin = performance.now();
143
- const found = medium instanceof ReleaseDetailScanner
144
- ? medium.scanLocalized(image, retailPolicy, fitLimits[this.mode], true, coverage)
145
- : medium.scanLocalized(image, scanPolicy, fitLimits[this.mode], true);
146
- primary = found;
147
- const localization = found.localization;
148
- proposals = localization.proposals;
149
- localizationMs = found.localizationMs;
150
- for (const b of found.scan.barcodes) {
151
- if (formats.includes("UPCA") && b.text.startsWith("0"))
152
- barcodes.push({
153
- format: "UPCA",
154
- text: b.text.slice(1),
155
- polygon: b.polygon,
156
- support: b.support,
157
- });
158
- else if (formats.includes("EAN13"))
159
- barcodes.push({ format: "EAN13", text: b.text, polygon: b.polygon, support: b.support });
160
- }
161
- if (sharedRetail) {
162
- const evidence = found;
163
- const shared = [...(evidence.scan.retail?.barcodes ?? [])];
164
- unfinished ||= evidence.scan.retail?.unfinished ?? false;
165
- for (const attempt of evidence.recovery?.attempts ?? []) {
166
- unfinished ||= attempt.frame.retail?.unfinished ?? false;
167
- for (const b of attempt.frame.retail?.barcodes ?? []) {
168
- const polygon = b.polygon.map(([x, y]) => [
169
- attempt.x + x / attempt.factor,
170
- attempt.y + y / attempt.factor,
171
- ]);
172
- shared.push({ ...b, polygon });
173
- }
174
- }
175
- barcodes.push(...shared.filter((b) => formats.includes(b.format)));
176
- }
177
- const decoded = new Set(found.scan.barcodes.flatMap((b) => b.candidate_indices));
178
- localization.proposals.forEach((p, i) => {
179
- if (!decoded.has(i))
180
- regions.push({ format: "Unknown", text: "", polygon: p.polygon, support: 0 });
181
- });
182
- if ("recovery" in found) {
183
- const recovery = found.recovery;
184
- for (const attempt of recovery.attempts) {
185
- const accepted = new Set(attempt.reads.flatMap((b) => b.candidate_indices));
186
- attempt.proposals.forEach((p, i) => {
187
- if (!accepted.has(i))
188
- regions.push({ format: "Unknown", text: "", polygon: p.polygon, support: 0 });
189
- });
190
- }
191
- }
192
- unfinished ||=
193
- found.scan.unfinished ||
194
- Boolean(localization.workLimited) ||
195
- (localization.omitted ?? 0) > 0;
196
- mediumMs = performance.now() - begin;
197
- }
198
- if (!sharedRetail && localized && !formats.includes("EAN13") && !formats.includes("UPCA")) {
199
- if (!medium)
200
- throw Error("EAN13 localization engine has not been initialized.");
201
- const begin = performance.now();
202
- const found = medium.scanLocalized(image, scanPolicy, fitLimits[this.mode], true)
203
- .localization;
204
- proposals = found.proposals;
205
- unfinished ||= Boolean(found.workLimited) || (found.omitted ?? 0) > 0;
206
- localizationMs = performance.now() - begin;
207
- }
208
- // UPC-A has the same optical structure as zero-prefixed EAN13, so the
209
- // frozen Medium reader handles it without a second optical search.
210
- if (extraFormats.length) {
211
- if (!this.extra || !this.handle)
212
- throw Error("Additional readers have not been loaded.");
213
- const begin = performance.now();
214
- const rgba = this.rgba &&
215
- !localized &&
216
- formats.length === 1 &&
217
- formats[0] === "QRCode" &&
218
- channels === 4 &&
219
- stride === width * 4;
220
- const gray = preparedGray ?? (rgba ? data.subarray(0, width * height * 4) : scanGray(image));
221
- preparationMs += performance.now() - begin;
222
- const matrixFormats = extraFormats.filter((f) => !supportedLinearFormats.includes(f));
223
- const linearFormats = extraFormats.filter((f) => supportedLinearFormats.includes(f));
224
- const run = (pixels, w, h, enabled, effort) => {
225
- const start = performance.now();
226
- const result = this.scanExtra(pixels, w, h, enabled, effort, eanAddOnSymbol, rgba);
227
- additionalMs += performance.now() - start;
228
- unfinished ||= result.unfinished;
229
- return result;
230
- };
231
- if (!localized || !proposals.length) {
232
- for (const [enabled, effort] of [
233
- [linearFormats, this.effort],
234
- [matrixFormats, matrixFormats.includes("QRCode") ? this.qrEffort : 1],
235
- ]) {
236
- if (!enabled.length)
237
- continue;
238
- const result = enabled === linearFormats && preLinear
239
- ? preLinear
240
- : run(gray, width, height, enabled, effort);
241
- unfinished ||= result.unfinished;
242
- barcodes.push(...result.barcodes);
243
- regions.push(...(result.regions ?? []));
244
- }
245
- }
246
- else {
247
- if (matrixFormats.length) {
248
- const result = run(gray, width, height, matrixFormats, matrixFormats.includes("QRCode") ? this.qrEffort : 1);
249
- barcodes.push(...result.barcodes);
250
- regions.push(...(result.regions ?? []));
251
- }
252
- if (this.crop) {
253
- this.extra.multi_prepare(this.handle, width, height);
254
- new Uint8Array(this.extra.memory.buffer, this.extra.multi_input(this.handle), width * height).set(gray);
255
- if (this.extra.multi_capture_source(this.handle) !== 0)
256
- throw Error("Could not retain source image.");
257
- }
258
- for (const proposal of proposals) {
259
- const start = performance.now();
260
- let crop;
261
- let pixels;
262
- try {
263
- if (this.crop) {
264
- crop = rectificationPlan(proposal.polygon);
265
- new Float64Array(this.extra.memory.buffer, this.extra.multi_crop_transform(this.handle), 8).set(crop.transform);
266
- if (this.extra.multi_crop(this.handle, crop.width, crop.height) !== 0)
267
- throw Error("Could not sample barcode crop.");
268
- }
269
- else {
270
- const sampled = rectify(gray, width, height, proposal.polygon);
271
- crop = sampled;
272
- pixels = sampled.data;
273
- }
274
- }
275
- catch {
276
- unfinished = true;
277
- regions.push({ format: "Unknown", text: "", polygon: proposal.polygon, support: 0 });
278
- continue;
279
- }
280
- preparationMs += performance.now() - start;
281
- const decodeStart = performance.now();
282
- const result = pixels
283
- ? run(pixels, crop.width, crop.height, linearFormats, 0)
284
- : this.scanPrepared(linearFormats, 0, eanAddOnSymbol);
285
- if (!pixels) {
286
- additionalMs += performance.now() - decodeStart;
287
- unfinished ||= result.unfinished;
288
- }
289
- const reads = result.barcodes;
290
- if (!reads.length)
291
- regions.push({ format: "Unknown", text: "", polygon: proposal.polygon, support: 0 });
292
- for (const read of [...reads, ...(result.regions ?? [])]) {
293
- const p = read.polygon;
294
- const mapped = (p) => project(crop.transform, p[0], p[1]);
295
- read.polygon = [mapped(p[0]), mapped(p[1]), mapped(p[2]), mapped(p[3])];
296
- if (read.text)
297
- barcodes.push(read);
298
- else
299
- regions.push(read);
300
- }
301
- }
302
- }
303
- }
304
- if (extraFormats.length) {
305
- for (const read of barcodes.filter((b) => b.eanAddOn)) {
306
- for (const base of barcodes) {
307
- if (base.format === read.format &&
308
- base.text === read.text &&
309
- !base.eanAddOn &&
310
- polygonOverlap(base.polygon, read.polygon).smaller >= 0.65)
311
- base.eanAddOn = read.eanAddOn;
312
- }
313
- }
314
- if (eanAddOnSymbol === "Require") {
315
- for (let i = barcodes.length - 1; i >= 0; i--) {
316
- const b = barcodes[i];
317
- if (["EAN13", "UPCA", "EAN8", "UPCE"].includes(b.format) && !b.eanAddOn) {
318
- regions.push({ ...b, text: "" });
319
- barcodes.splice(i, 1);
320
- }
321
- }
322
- }
323
- const distinct = distinctReads(barcodes);
324
- barcodes.splice(0, barcodes.length, ...distinct);
325
- const remaining = regions.filter((region) => !barcodes.some((b) => polygonOverlap(region.polygon, b.polygon).a >= 0.65));
326
- regions.splice(0, regions.length, ...distinctReads(remaining));
327
- }
328
- const mergedLinear = mergeLinearDuplicates(barcodes, image);
329
- barcodes.splice(0, barcodes.length, ...mergedLinear);
330
- barcodes.sort((a, b) => b.support - a.support);
331
- barcodes.forEach((b, i) => {
332
- b.rank = i + 1;
333
- });
334
- return {
335
- primary,
336
- barcodes,
337
- eanAddOnSymbol,
338
- regions: [...barcodes, ...regions],
339
- formats,
340
- unfinished,
341
- scanMs: performance.now() - start,
342
- mediumMs,
343
- additionalMs,
344
- preparationMs,
345
- localizationMs,
346
- linearStrategy,
347
- };
348
- }
349
- scanExtra(gray, width, height, formats, effort, eanAddOnSymbol, rgba = false) {
350
- const e = this.extra;
351
- if (!e || !this.handle)
352
- throw Error("Additional readers have not been loaded.");
353
- if ((rgba ? e.multi_prepare_rgba : e.multi_prepare)(this.handle, width, height) !== 0)
354
- throw Error("Additional reader rejected image size.");
355
- new Uint8Array(e.memory.buffer, (rgba ? e.multi_input_rgba : e.multi_input)(this.handle), width * height * (rgba ? 4 : 1)).set(gray);
356
- return this.scanPrepared(formats, effort, eanAddOnSymbol, rgba);
357
- }
358
- scanPrepared(formats, effort, eanAddOnSymbol, rgba = false) {
359
- const e = this.extra;
360
- if (!e || !this.handle)
361
- throw Error("Additional readers have not been loaded.");
362
- const mask = maskFor(formats) |
363
- (eanAddOnSymbol === "Read" ? 32768 : eanAddOnSymbol === "Require" ? 65536 : 0);
364
- if ((rgba ? e.multi_scan_rgba : e.multi_scan)(this.handle, mask, effort) !== 0)
365
- throw Error("Additional scanner failed.");
366
- const bytes = new Uint8Array(e.memory.buffer, e.multi_output(this.handle), e.multi_output_len(this.handle));
367
- const found = JSON.parse(new TextDecoder().decode(bytes));
368
- for (const b of [...found.barcodes, ...(found.regions ?? [])])
369
- if (!formats.includes(b.format))
370
- throw Error("Scanner returned a disabled format.");
371
- return found;
372
- }
373
- dispose() {
374
- if (this.disposed)
375
- return;
376
- this.medium?.dispose();
377
- if (this.handle)
378
- this.extra?.multi_free(this.handle);
379
- this.handle = 0;
380
- this.disposed = true;
381
- }
382
- }
@@ -1,121 +0,0 @@
1
- /** Independent EAN-13 supplied-region scanner. Experimental; no localizer or
2
- * reference decoder is imported. All result confidence remains uncalibrated. */
3
- export type Point = readonly [number, number];
4
- export type Quad = readonly [Point, Point, Point, Point];
5
- export interface Image {
6
- data: Uint8Array;
7
- width: number;
8
- height: number;
9
- channels: 1 | 3 | 4;
10
- stride: number;
11
- }
12
- export interface Policy {
13
- transitionCleanup?: boolean;
14
- sourceIdentity?: boolean;
15
- interiorNormalization?: boolean;
16
- guardBias?: boolean;
17
- /** Experimental: accept one full-quiet scanline; increases false-read risk. Default false. */
18
- allowSingleRow?: boolean;
19
- maxRetryPathsPerCandidate?: number;
20
- maxRetryPathsPerFrame?: number;
21
- maxAssociationChecks?: number;
22
- maxAssociationPixels?: number;
23
- maxResults?: number;
24
- }
25
- export interface Detection {
26
- text: string;
27
- polygon: Quad;
28
- support: number;
29
- axis: number;
30
- }
31
- export interface Barcode extends Detection {
32
- candidate_indices: number[];
33
- }
34
- export interface Observation {
35
- text: string;
36
- axis: number;
37
- fraction: number;
38
- left: number;
39
- right: number;
40
- cost: number;
41
- gap: number;
42
- }
43
- export interface Candidate {
44
- candidate_index: number;
45
- coverage: readonly (readonly [number | null, number | null])[];
46
- error: boolean;
47
- error_detail: 'invalid_geometry' | 'sampling_error' | null;
48
- unfinished: boolean;
49
- ms: number;
50
- work: Record<string, number>;
51
- detections: Detection[];
52
- observations: Observation[];
53
- }
54
- export interface ScanFrame {
55
- unfinished: boolean;
56
- candidates: Candidate[];
57
- barcodes: Barcode[];
58
- reconciliation: {
59
- comparisons: number;
60
- merged: number;
61
- ambiguous: number;
62
- conflicting: number;
63
- pending_observations: number;
64
- truncated: boolean;
65
- source_pairs: number;
66
- source_matches: number;
67
- source_pixels: number;
68
- source_capped: number;
69
- pending_coverage_checks: number;
70
- pending_quarantined: number;
71
- };
72
- }
73
- export interface ScanResult extends ScanFrame {
74
- /** This WASM build has no internal clock. Candidate ms values are unavailable zeros. */
75
- candidateTimingsAvailable: false;
76
- /** Actual host wall time, including validation, preparation/copies, decode and JSON parsing. */
77
- elapsedMs: number;
78
- }
79
- /** Explicit indices reject sparse arrays; nonfinite numeric geometry reaches Rust. */
80
- export declare function isQuadShape(value: unknown): value is Quad;
81
- export declare class ScannerError extends Error {
82
- readonly code: string;
83
- constructor(code: string, message: string);
84
- }
85
- /** Validate before asynchronous work; returned bytes are owned by the caller. */
86
- export declare function snapshotImage(image: Image): Image;
87
- export declare function snapshotPolicy(policy: Policy): Policy;
88
- /** Uncalibrated support ordering; ties preserve spatial output order. */
89
- export declare function rankBarcodes(barcodes: readonly Barcode[]): Barcode[];
90
- export declare class IndependentScanner {
91
- #private;
92
- private constructor();
93
- static create(bytes: BufferSource): Promise<IndependentScanner>;
94
- /** Localization-only entry point for opt-in independent linear decoders. */
95
- localizeOnly(image: Image, fitLimit?: number): {
96
- proposals: {
97
- polygon: Quad;
98
- score?: number;
99
- }[];
100
- workLimited?: boolean;
101
- omitted?: number;
102
- };
103
- /** All supplied regions receive the cheap pass; successful reads do not end scanning. */
104
- scan(image: Image, quads: readonly Quad[], policy?: Policy): ScanResult;
105
- /** Synchronous transaction: upload once, localize, decode the same owned pixels. */
106
- scanLocalized(image: Image, policy?: Policy, fitLimit?: number, fullFrame?: boolean): {
107
- localization: any;
108
- searchWindows: {
109
- kind: string;
110
- polygon: number[][];
111
- candidateIndex: any;
112
- }[];
113
- scan: ScanResult;
114
- localizationMs: number;
115
- decodingMs: number;
116
- scanMs: number;
117
- };
118
- /** Separate convenience; it never changes find-all work or suppresses frame evidence. */
119
- best(result: ScanFrame): Barcode | undefined;
120
- dispose(): void;
121
- }