tapirscan 1.2.0 → 1.2.2

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 (62) hide show
  1. package/README.md +9 -10
  2. package/dist/index.d.ts +24 -29
  3. package/dist/index.js +64 -154
  4. package/dist/multiformat/format-registry.d.ts +26 -0
  5. package/dist/multiformat/format-registry.js +62 -0
  6. package/dist/multiformat/formats.d.ts +2 -24
  7. package/dist/multiformat/formats.js +3 -41
  8. package/dist/rust-session.d.ts +19 -0
  9. package/dist/rust-session.js +92 -0
  10. package/package.json +7 -9
  11. package/wasm/high-release-1.2.2-public-low-r2.wasm +0 -0
  12. package/wasm/low-release-1.2.2-public-low-r2.wasm +0 -0
  13. package/wasm/medium-release-1.2.2-public-low-r2.wasm +0 -0
  14. package/wasm/very-high-release-1.2.2-public-low-r2.wasm +0 -0
  15. package/dist/completion-host.d.mts +0 -40
  16. package/dist/completion-host.mjs +0 -188
  17. package/dist/detail-20260914/continuity.d.mts +0 -2
  18. package/dist/detail-20260914/continuity.mjs +0 -62
  19. package/dist/detail-20260914/detail-proposals-rich.d.mts +0 -13
  20. package/dist/detail-20260914/detail-proposals-rich.mjs +0 -53
  21. package/dist/detail-20260914/direct-recovery.d.mts +0 -28
  22. package/dist/detail-20260914/direct-recovery.mjs +0 -139
  23. package/dist/detail-20260914/host.d.mts +0 -40
  24. package/dist/detail-20260914/host.mjs +0 -280
  25. package/dist/detail-20260914/scanner.d.mts +0 -12
  26. package/dist/detail-20260914/scanner.mjs +0 -64
  27. package/dist/detail-20260914/source-evidence.d.mts +0 -10
  28. package/dist/detail-20260914/source-evidence.mjs +0 -94
  29. package/dist/detail-canvas.d.ts +0 -35
  30. package/dist/detail-canvas.js +0 -73
  31. package/dist/detail-runtime/direct-recovery.d.mts +0 -28
  32. package/dist/detail-runtime/direct-recovery.mjs +0 -142
  33. package/dist/detail-runtime/host.d.mts +0 -40
  34. package/dist/detail-runtime/host.mjs +0 -282
  35. package/dist/detail-runtime/scanner.d.mts +0 -12
  36. package/dist/detail-runtime/scanner.mjs +0 -70
  37. package/dist/detail.d.ts +0 -18
  38. package/dist/detail.js +0 -84
  39. package/dist/host.d.ts +0 -112
  40. package/dist/host.js +0 -184
  41. package/dist/host64.d.ts +0 -112
  42. package/dist/host64.js +0 -184
  43. package/dist/multiformat/coverage.d.ts +0 -7
  44. package/dist/multiformat/coverage.js +0 -26
  45. package/dist/multiformat/geometry.d.ts +0 -37
  46. package/dist/multiformat/geometry.js +0 -132
  47. package/dist/multiformat/linear-duplicates.d.ts +0 -16
  48. package/dist/multiformat/linear-duplicates.js +0 -163
  49. package/dist/multiformat/pixels.d.ts +0 -3
  50. package/dist/multiformat/pixels.js +0 -36
  51. package/dist/multiformat/scanner.d.ts +0 -60
  52. package/dist/multiformat/scanner.js +0 -361
  53. package/dist/multiformat-host.d.ts +0 -121
  54. package/dist/multiformat-host.js +0 -207
  55. package/dist/policy.d.ts +0 -12
  56. package/dist/policy.js +0 -12
  57. package/wasm/high-complete-release-20260916.wasm +0 -0
  58. package/wasm/low-complete-release-20260916.wasm +0 -0
  59. package/wasm/medium-complete-release-20260916.wasm +0 -0
  60. package/wasm/multiformat.json +0 -7
  61. package/wasm/multiformat.wasm +0 -0
  62. package/wasm/very-high-complete-release-20260916.wasm +0 -0
@@ -1,207 +0,0 @@
1
- /** Explicit indices reject sparse arrays; nonfinite numeric geometry reaches Rust. */
2
- export function isQuadShape(value) {
3
- if (!Array.isArray(value) || value.length !== 4)
4
- return false;
5
- for (let i = 0; i < 4; i++) {
6
- if (!Object.hasOwn(value, i))
7
- return false;
8
- const point = value[i];
9
- if (!Array.isArray(point) || point.length !== 2)
10
- return false;
11
- for (let j = 0; j < 2; j++)
12
- if (!Object.hasOwn(point, j) || typeof point[j] !== 'number')
13
- return false;
14
- }
15
- return true;
16
- }
17
- export class ScannerError extends Error {
18
- code;
19
- constructor(code, message) { super(message); this.name = 'ScannerError'; this.code = code; }
20
- }
21
- function integer(value, min, max, name) {
22
- if (!Number.isSafeInteger(value) || value < min || value > max)
23
- throw new ScannerError('invalid_input', `Invalid ${name}`);
24
- return value;
25
- }
26
- function status(code) {
27
- if (code !== 0)
28
- throw new ScannerError(`core_${code}`, `Independent scanner rejected operation (${code})`);
29
- }
30
- function parseFrame(text, count) {
31
- const v = JSON.parse(text);
32
- if (!v || typeof v !== 'object')
33
- throw new ScannerError('invalid_output', 'Expected frame object');
34
- const f = v;
35
- if (!Array.isArray(f.candidates) || f.candidates.length !== count || !Array.isArray(f.barcodes) || typeof f.unfinished !== 'boolean' || !f.reconciliation)
36
- throw new ScannerError('invalid_output', 'Invalid frame shape');
37
- for (let i = 0; i < f.candidates.length; i++) {
38
- const c = f.candidates[i];
39
- if (c.candidate_index !== i || !Array.isArray(c.coverage) || c.coverage.length !== 4 || !Array.isArray(c.observations) || !Array.isArray(c.detections) || typeof c.error !== 'boolean')
40
- throw new ScannerError('invalid_output', 'Invalid candidate shape');
41
- }
42
- for (const b of f.barcodes)
43
- if (!/^\d{13}$/.test(b.text) || !Array.isArray(b.polygon) || b.polygon.length !== 4 || !Array.isArray(b.candidate_indices) || b.candidate_indices.some(i => !Number.isInteger(i) || i < 0 || i >= count))
44
- throw new ScannerError('invalid_output', 'Invalid barcode shape');
45
- return f;
46
- }
47
- /** Validate before asynchronous work; returned bytes are owned by the caller. */
48
- export function snapshotImage(image) {
49
- if (!image || typeof image !== 'object')
50
- throw new ScannerError('invalid_input', 'Invalid image');
51
- const width = integer(image.width, 1, 0xffffffff, 'width'), height = integer(image.height, 1, 0xffffffff, 'height');
52
- if (![1, 3, 4].includes(image.channels) || !(image.data instanceof Uint8Array))
53
- throw new ScannerError('invalid_input', 'Invalid image buffer/channels');
54
- const stride = integer(image.stride, width * image.channels, 0xffffffff, 'stride');
55
- const required = integer((height - 1) * stride + width * image.channels, 1, 128 * 1024 * 1024, 'image length');
56
- if (image.data.byteLength < required)
57
- throw new ScannerError('invalid_input', 'Image buffer is too short');
58
- return { data: new Uint8Array(image.data.subarray(0, required)), width, height, channels: image.channels, stride };
59
- }
60
- export function snapshotPolicy(policy) {
61
- if (!policy || typeof policy !== 'object')
62
- throw new ScannerError('invalid_input', 'Invalid policy');
63
- const copy = { ...policy };
64
- for (const key of ['transitionCleanup', 'sourceIdentity', 'interiorNormalization', 'guardBias', 'allowSingleRow'])
65
- if (copy[key] !== undefined && typeof copy[key] !== 'boolean')
66
- throw new ScannerError('invalid_input', `Invalid ${key}`);
67
- integer(copy.maxRetryPathsPerCandidate ?? 512, 0, 4096, 'candidate budget');
68
- integer(copy.maxRetryPathsPerFrame ?? 8192, 0, 65536, 'frame budget');
69
- integer(copy.maxAssociationChecks ?? 200000, 0, 2000000, 'comparison budget');
70
- integer(copy.maxAssociationPixels ?? 2000000, 0, 16000000, 'pixel budget');
71
- integer(copy.maxResults ?? 1024, 1, 4096, 'result budget');
72
- return copy;
73
- }
74
- /** Uncalibrated support ordering; ties preserve spatial output order. */
75
- export function rankBarcodes(barcodes) {
76
- return [...barcodes].sort((a, b) => b.support - a.support);
77
- }
78
- export class IndependentScanner {
79
- #exports;
80
- #handle;
81
- constructor(exports) {
82
- this.#exports = exports;
83
- if (exports.regions_version() !== 1)
84
- throw new ScannerError('abi_version', 'Unsupported scanner ABI');
85
- this.#handle = exports.regions_new();
86
- if (!this.#handle)
87
- throw new ScannerError('capacity', 'Scanner handle capacity exhausted');
88
- }
89
- static async create(bytes) {
90
- const module = await WebAssembly.compile(bytes);
91
- const instance = await WebAssembly.instantiate(module, {});
92
- const exports = instance.exports;
93
- for (const name of ['regions_localize', 'regions_version', 'regions_new', 'regions_destroy', 'regions_prepare', 'regions_input_ptr', 'regions_input_len', 'regions_quads_ptr', 'regions_output_ptr', 'regions_output_len', 'regions_scan']) {
94
- if (typeof instance.exports[name] !== 'function')
95
- throw new ScannerError('abi_shape', `Missing ${name}`);
96
- }
97
- if (!(exports.memory instanceof WebAssembly.Memory))
98
- throw new ScannerError('abi_shape', 'Missing memory');
99
- return new IndependentScanner(exports);
100
- }
101
- /** Localization-only entry point for opt-in independent linear decoders. */
102
- localizeOnly(image, fitLimit = 8) {
103
- if (!this.#handle)
104
- throw new ScannerError('disposed', 'Scanner is disposed');
105
- const width = integer(image.width, 3, 0xffffffff, 'width'), height = integer(image.height, 3, 0xffffffff, 'height');
106
- if (![1, 3, 4].includes(image.channels) || !(image.data instanceof Uint8Array))
107
- throw new ScannerError('invalid_input', 'Invalid image buffer/channels');
108
- const stride = integer(image.stride, width * image.channels, 0xffffffff, 'stride');
109
- const required = integer((height - 1) * stride + width * image.channels, 1, 128 * 1024 * 1024, 'image length');
110
- if (image.data.byteLength < required)
111
- throw new ScannerError('invalid_input', 'Image buffer is too short');
112
- integer(fitLimit, 0, 8, 'shear limit');
113
- const e = this.#exports, id = this.#handle;
114
- status(e.regions_prepare(id, width, height, image.channels, stride));
115
- if (e.regions_input_len(id) !== required)
116
- throw new ScannerError('abi_shape', 'Input allocation mismatch');
117
- new Uint8Array(e.memory.buffer, e.regions_input_ptr(id), required).set(image.data.subarray(0, required));
118
- status(e.regions_localize(id, fitLimit));
119
- const localization = JSON.parse(new TextDecoder().decode(new Uint8Array(e.memory.buffer, e.regions_output_ptr(id), e.regions_output_len(id))));
120
- if (!Array.isArray(localization.proposals) || localization.proposals.length > 32 || localization.proposals.some(p => !isQuadShape(p.polygon)))
121
- throw new ScannerError('abi_shape', 'Invalid localization');
122
- return localization;
123
- }
124
- /** All supplied regions receive the cheap pass; successful reads do not end scanning. */
125
- scan(image, quads, policy = {}) {
126
- return this.#scan(image, quads, policy, false);
127
- }
128
- /** Synchronous transaction: upload once, localize, decode the same owned pixels. */
129
- scanLocalized(image, policy = {}, fitLimit = 8, fullFrame = false) {
130
- const start = performance.now();
131
- if (!this.#handle)
132
- throw new ScannerError('disposed', 'Scanner is disposed');
133
- if (!image || typeof image !== 'object')
134
- throw new ScannerError('invalid_input', 'Invalid image');
135
- const width = integer(image.width, 3, 0xffffffff, 'width'), height = integer(image.height, 3, 0xffffffff, 'height');
136
- if (![1, 3, 4].includes(image.channels) || !(image.data instanceof Uint8Array))
137
- throw new ScannerError('invalid_input', 'Invalid image buffer/channels');
138
- const stride = integer(image.stride, width * image.channels, 0xffffffff, 'stride');
139
- const required = integer((height - 1) * stride + width * image.channels, 1, 128 * 1024 * 1024, 'image length');
140
- if (image.data.byteLength < required)
141
- throw new ScannerError('invalid_input', 'Image buffer is too short');
142
- integer(fitLimit, 0, 8, 'shear limit');
143
- const e = this.#exports, id = this.#handle;
144
- status(e.regions_prepare(id, width, height, image.channels, stride));
145
- if (e.regions_input_len(id) !== required)
146
- throw new ScannerError('abi_shape', 'Input allocation mismatch');
147
- new Uint8Array(e.memory.buffer, e.regions_input_ptr(id), required).set(image.data.subarray(0, required));
148
- status(e.regions_localize(id, fitLimit));
149
- const localization = JSON.parse(new TextDecoder().decode(new Uint8Array(e.memory.buffer, e.regions_output_ptr(id), e.regions_output_len(id))));
150
- if (!Array.isArray(localization.proposals) || localization.proposals.length > 32 || localization.proposals.some((p) => !isQuadShape(p.polygon)))
151
- throw new ScannerError('abi_shape', 'Invalid localization');
152
- const searchWindows = fullFrame ? [{ kind: 'full_frame_search', polygon: [[0, 0], [width - 1, 0], [width - 1, height - 1], [0, height - 1]], candidateIndex: localization.proposals.length }] : [];
153
- const localizationMs = performance.now() - start, decodeStart = performance.now();
154
- const scan = this.#scan(image, [...localization.proposals.map((p) => p.polygon), ...searchWindows.map(p => p.polygon)], policy, true);
155
- return { localization, searchWindows, scan, localizationMs, decodingMs: performance.now() - decodeStart, scanMs: performance.now() - start };
156
- }
157
- #scan(image, quads, policy, prepared) {
158
- const start = performance.now();
159
- if (!this.#handle)
160
- throw new ScannerError('disposed', 'Scanner is disposed');
161
- if (!image || typeof image !== 'object' || !Array.isArray(quads) || !policy || typeof policy !== 'object')
162
- throw new ScannerError('invalid_input', 'Invalid scan arguments');
163
- for (const key of ['transitionCleanup', 'sourceIdentity', 'interiorNormalization', 'guardBias', 'allowSingleRow'])
164
- if (policy[key] !== undefined && typeof policy[key] !== 'boolean')
165
- throw new ScannerError('invalid_input', `Invalid ${key}`);
166
- const e = this.#exports, id = this.#handle;
167
- const width = integer(image.width, 1, 0xffffffff, 'width'), height = integer(image.height, 1, 0xffffffff, 'height');
168
- if (![1, 3, 4].includes(image.channels) || !(image.data instanceof Uint8Array))
169
- throw new ScannerError('invalid_input', 'Invalid image buffer/channels');
170
- const stride = integer(image.stride, width * image.channels, 0xffffffff, 'stride');
171
- const required = integer((height - 1) * stride + width * image.channels, 1, 128 * 1024 * 1024, 'image length');
172
- if (image.data.byteLength < required)
173
- throw new ScannerError('invalid_input', 'Image buffer is too short');
174
- integer(quads.length, 0, 64, 'candidate count');
175
- for (const q of quads)
176
- if (!isQuadShape(q))
177
- throw new ScannerError('invalid_input', 'Invalid quad shape');
178
- const perCandidate = integer(policy.maxRetryPathsPerCandidate ?? 512, 0, 4096, 'candidate budget');
179
- const perFrame = integer(policy.maxRetryPathsPerFrame ?? 8192, 0, 65536, 'frame budget');
180
- const checks = integer(policy.maxAssociationChecks ?? 200000, 0, 2000000, 'comparison budget');
181
- const pixels = integer(policy.maxAssociationPixels ?? 2000000, 0, 16000000, 'pixel budget');
182
- const results = integer(policy.maxResults ?? 1024, 1, 4096, 'result budget');
183
- const flags = (policy.transitionCleanup ? 1 : 0) | (policy.sourceIdentity ? 2 : 0) | (policy.interiorNormalization ? 4 : 0) | (policy.guardBias ? 8 : 0) | (policy.allowSingleRow ? 16 : 0);
184
- if (!prepared) {
185
- status(e.regions_prepare(id, width, height, image.channels, stride));
186
- if (e.regions_input_len(id) !== required)
187
- throw new ScannerError('abi_shape', 'Input allocation mismatch');
188
- new Uint8Array(e.memory.buffer, e.regions_input_ptr(id), required).set(image.data.subarray(0, required));
189
- }
190
- const coordinates = new Float64Array(e.memory.buffer, e.regions_quads_ptr(id), 512);
191
- quads.forEach((q, i) => q.forEach((p, j) => { coordinates[i * 8 + j * 2] = p[0]; coordinates[i * 8 + j * 2 + 1] = p[1]; }));
192
- status(e.regions_scan(id, quads.length, flags, perCandidate, perFrame, checks, pixels, results));
193
- // Scan can grow memory. Never reuse the earlier input/coordinate views.
194
- const output = new Uint8Array(e.memory.buffer, e.regions_output_ptr(id), e.regions_output_len(id)).slice();
195
- const frame = parseFrame(new TextDecoder().decode(output), quads.length);
196
- return { ...frame, candidateTimingsAvailable: false, elapsedMs: performance.now() - start };
197
- }
198
- /** Separate convenience; it never changes find-all work or suppresses frame evidence. */
199
- best(result) {
200
- return rankBarcodes(result.barcodes)[0];
201
- }
202
- dispose() { if (this.#handle) {
203
- const id = this.#handle;
204
- this.#handle = 0;
205
- status(this.#exports.regions_destroy(id));
206
- } }
207
- }
package/dist/policy.d.ts DELETED
@@ -1,12 +0,0 @@
1
- export declare const policy: Readonly<{
2
- transitionCleanup: true;
3
- sourceIdentity: true;
4
- interiorNormalization: true;
5
- guardBias: true;
6
- allowSingleRow: false;
7
- maxRetryPathsPerCandidate: 512;
8
- maxRetryPathsPerFrame: 8192;
9
- maxAssociationChecks: 200000;
10
- maxAssociationPixels: 2000000;
11
- maxResults: 1024;
12
- }>;
package/dist/policy.js DELETED
@@ -1,12 +0,0 @@
1
- export const policy = Object.freeze({
2
- transitionCleanup: true,
3
- sourceIdentity: true,
4
- interiorNormalization: true,
5
- guardBias: true,
6
- allowSingleRow: false,
7
- maxRetryPathsPerCandidate: 512,
8
- maxRetryPathsPerFrame: 8192,
9
- maxAssociationChecks: 200000,
10
- maxAssociationPixels: 2000000,
11
- maxResults: 1024,
12
- });
@@ -1,7 +0,0 @@
1
- {
2
- "sha256": "06598e5fc13957c21e2c206de51990decb415d4e7037e8a42160d6108008df55",
3
- "sourceManifest": "provenance/import.json",
4
- "sourceDigest": "bfbc48d3bba63fbbe16c8396d3cf4b5278095f2affd0bc4f15d380e1414a8111",
5
- "rustToolchain": "1.91.1",
6
- "rustflags": "-C target-feature=+simd128 --remap-path-prefix=/home/runner/.rustup/toolchains/1.91.1-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library=/rustc/ed61e7d7e242494fb7057f2657300d9e77bb4fcb/library"
7
- }
Binary file