@exige/web-scanner-sdk 0.2.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 (37) hide show
  1. package/README.md +288 -0
  2. package/dist/assets/document-worker-QjcJjl9-.js +2 -0
  3. package/dist/assets/document-worker-QjcJjl9-.js.map +1 -0
  4. package/dist/assets/ort.min-CA5AZ7mL.js +2937 -0
  5. package/dist/assets/ort.min-CA5AZ7mL.js.map +1 -0
  6. package/dist/components/ScannerCameraOverlay.d.ts +36 -0
  7. package/dist/components/scanner-camera-overlay.css +2 -0
  8. package/dist/finder-Clo7f2gN.js +1447 -0
  9. package/dist/finder-Clo7f2gN.js.map +1 -0
  10. package/dist/index.d.ts +20 -0
  11. package/dist/live-overlay-geometry.d.ts +11 -0
  12. package/dist/react.d.ts +2 -0
  13. package/dist/react.js +448 -0
  14. package/dist/react.js.map +1 -0
  15. package/dist/scanner-sdk.js +921 -0
  16. package/dist/scanner-sdk.js.map +1 -0
  17. package/dist/sdk/camera.d.ts +142 -0
  18. package/dist/sdk/detect.d.ts +3 -0
  19. package/dist/sdk/display-quad.d.ts +23 -0
  20. package/dist/sdk/document-analysis.d.ts +14 -0
  21. package/dist/sdk/document-geometry.d.ts +21 -0
  22. package/dist/sdk/field-model.d.ts +4 -0
  23. package/dist/sdk/finder-simulator.d.ts +17 -0
  24. package/dist/sdk/finder.d.ts +166 -0
  25. package/dist/sdk/frame-geometry.d.ts +6 -0
  26. package/dist/sdk/image.d.ts +18 -0
  27. package/dist/sdk/license-codec.d.ts +2 -0
  28. package/dist/sdk/license-public-key.d.ts +9 -0
  29. package/dist/sdk/license-runtime.d.ts +2 -0
  30. package/dist/sdk/license.d.ts +76 -0
  31. package/dist/sdk/lighting.d.ts +22 -0
  32. package/dist/sdk/ocr.d.ts +75 -0
  33. package/dist/sdk/programmatic-redaction.d.ts +102 -0
  34. package/dist/sdk/redact.d.ts +12 -0
  35. package/dist/sdk/scan.d.ts +32 -0
  36. package/dist/sdk/types.d.ts +92 -0
  37. package/package.json +74 -0
@@ -0,0 +1,921 @@
1
+ import { A as e, B as t, C as n, D as r, E as i, F as a, H as o, I as s, L as c, M as l, N as u, O as d, P as f, R as p, S as m, T as h, U as g, V as _, W as v, _ as y, a as ee, b as te, c as ne, d as re, f as ie, g as ae, h as oe, i as se, j as ce, k as le, l as ue, m as de, n as fe, o as pe, p as b, r as x, s as S, t as me, u as he, v as ge, w as _e, x as ve, y as ye, z as C } from "./finder-Clo7f2gN.js";
2
+ //#region src/sdk/frame-geometry.ts
3
+ function w(e, t, n) {
4
+ let r = Math.max(1, t.width), i = Math.max(1, t.height), a = Math.max(1, n.width), o = Math.max(1, n.height), s = Math.max(r / a, i / o), c = (r - a * s) / 2, l = (i - o * s) / 2;
5
+ return {
6
+ x: (e.x - c) / s,
7
+ y: (e.y - l) / s
8
+ };
9
+ }
10
+ function be(e, t, n) {
11
+ return {
12
+ topLeft: w(e.topLeft, t, n),
13
+ topRight: w(e.topRight, t, n),
14
+ bottomRight: w(e.bottomRight, t, n),
15
+ bottomLeft: w(e.bottomLeft, t, n)
16
+ };
17
+ }
18
+ //#endregion
19
+ //#region src/sdk/finder-simulator.ts
20
+ function T(e, t = 960, n = 600) {
21
+ let r = t * .86, i = n * .86;
22
+ if (e < 1200) {
23
+ let a = e / 1200;
24
+ return {
25
+ centerX: -r / 2 + (t / 2 + r / 2) * (1 - (1 - a) ** 3),
26
+ centerY: n / 2,
27
+ rotation: -.14 + a * .08,
28
+ width: r,
29
+ height: i,
30
+ phase: "entering"
31
+ };
32
+ }
33
+ if (e < 3600) {
34
+ let a = (e - 1200) / 2400, o = (1 - a) * 18;
35
+ return {
36
+ centerX: t / 2 + Math.sin(e / 85) * o,
37
+ centerY: n / 2 + Math.cos(e / 110) * o * .55,
38
+ rotation: -.055 + Math.sin(e / 125) * (1 - a) * .045,
39
+ width: r,
40
+ height: i,
41
+ phase: "jittering"
42
+ };
43
+ }
44
+ return {
45
+ centerX: t / 2,
46
+ centerY: n / 2,
47
+ rotation: 0,
48
+ width: r,
49
+ height: i,
50
+ phase: "settled"
51
+ };
52
+ }
53
+ function E(e, t, n) {
54
+ let r = Math.cos(n.rotation), i = Math.sin(n.rotation);
55
+ return {
56
+ x: n.centerX + e * r - t * i,
57
+ y: n.centerY + e * i + t * r
58
+ };
59
+ }
60
+ function xe(e) {
61
+ let t = E(-e.width / 2, -e.height / 2, e), n = E(e.width / 2, -e.height / 2, e), r = E(e.width / 2, e.height / 2, e), i = E(-e.width / 2, e.height / 2, e);
62
+ return {
63
+ topLeft: t,
64
+ topRight: n,
65
+ bottomRight: r,
66
+ bottomLeft: i,
67
+ edges: {
68
+ top: {
69
+ start: t,
70
+ end: n
71
+ },
72
+ right: {
73
+ start: n,
74
+ end: r
75
+ },
76
+ bottom: {
77
+ start: r,
78
+ end: i
79
+ },
80
+ left: {
81
+ start: i,
82
+ end: t
83
+ }
84
+ }
85
+ };
86
+ }
87
+ function D(e, t) {
88
+ let n = e.getContext("2d");
89
+ if (!n) throw Error("Canvas 2D is unavailable in this browser.");
90
+ let r = n.createLinearGradient(0, 0, e.width, e.height);
91
+ r.addColorStop(0, "#16231c"), r.addColorStop(1, "#32443a"), n.fillStyle = r, n.fillRect(0, 0, e.width, e.height), n.save(), n.translate(t.centerX, t.centerY), n.rotate(t.rotation), n.shadowColor = "rgba(0,0,0,.45)", n.shadowBlur = 24, n.fillStyle = "#fffdf4", n.strokeStyle = "#111914", n.lineWidth = 7, n.fillRect(-t.width / 2, -t.height / 2, t.width, t.height), n.strokeRect(-t.width / 2, -t.height / 2, t.width, t.height), n.shadowColor = "transparent";
92
+ let i = -t.width / 2, a = -t.height / 2;
93
+ n.fillStyle = "#d7ded8", n.fillRect(i + 38, a + 84, 145, 190), n.fillStyle = "#617269", n.beginPath(), n.arc(i + 110, a + 140, 38, 0, Math.PI * 2), n.fill(), n.fillRect(i + 70, a + 185, 80, 65), n.fillStyle = "#17231c", n.font = "700 25px Arial", n.fillText("IDENTITY CARD", i + 38, a + 48), n.font = "700 31px Arial", n.fillText("TAYLOR MORGAN", i + 220, a + 118), n.font = "23px Arial", n.fillText("01/02/1990", i + 220, a + 166), n.fillText("A1234567", i + 220, a + 208), n.fillText("123 MAIN ST", i + 220, a + 270), n.fillText("AUSTIN TX 78701", i + 220, a + 307), n.restore();
94
+ }
95
+ function Se(e) {
96
+ e.width ||= 960, e.height ||= 600;
97
+ let t = !1, n = 0, r = 0, i = (a) => {
98
+ t && (n ||= a, D(e, T(a - n, e.width, e.height)), r = requestAnimationFrame(i));
99
+ }, a = () => {
100
+ n = 0, D(e, T(0, e.width, e.height));
101
+ };
102
+ return a(), {
103
+ start() {
104
+ t || (t = !0, r = requestAnimationFrame(i));
105
+ },
106
+ stop() {
107
+ t = !1, cancelAnimationFrame(r);
108
+ },
109
+ reset: a
110
+ };
111
+ }
112
+ //#endregion
113
+ //#region src/sdk/ocr.ts
114
+ function O(e, t = 1, n = 1, r = 0, i = 0) {
115
+ return {
116
+ text: e.text,
117
+ confidence: Math.max(0, Math.min(1, e.confidence / 100)),
118
+ bbox: {
119
+ x: e.bbox.x0 * t + r,
120
+ y: e.bbox.y0 * n + i,
121
+ width: Math.max(0, e.bbox.x1 - e.bbox.x0) * t,
122
+ height: Math.max(0, e.bbox.y1 - e.bbox.y0) * n
123
+ }
124
+ };
125
+ }
126
+ function k(e = .5) {
127
+ if (!Number.isFinite(e) || e < 0 || e > 1) throw RangeError("OCR minConfidence must be between 0 and 1.");
128
+ return e;
129
+ }
130
+ function A(e, t) {
131
+ let n = Math.max(e.bbox.x, t.bbox.x), r = Math.max(e.bbox.y, t.bbox.y), i = Math.min(e.bbox.x + e.bbox.width, t.bbox.x + t.bbox.width), a = Math.min(e.bbox.y + e.bbox.height, t.bbox.y + t.bbox.height), o = Math.max(0, i - n) * Math.max(0, a - r), s = Math.min(e.bbox.width * e.bbox.height, t.bbox.width * t.bbox.height);
132
+ return s > 0 ? o / s : 0;
133
+ }
134
+ function j(e) {
135
+ let t = [...e].sort((e, t) => t.confidence - e.confidence || e.bbox.y - t.bbox.y || e.bbox.x - t.bbox.x || e.text.localeCompare(t.text)), n = [];
136
+ for (let e of t) n.some((t) => A(t, e) >= .65) || n.push(e);
137
+ return n;
138
+ }
139
+ function M(e, t, n, r, i) {
140
+ let a = e.text.trim();
141
+ if (!a || !/[\p{L}\p{N}]/u.test(a)) return !1;
142
+ let o = e.bbox.width * e.bbox.height / Math.max(1, n * r), s = e.bbox.width / Math.max(1, e.bbox.height);
143
+ if (o < (t === "word" ? 15e-6 : 15e-7) || s < .05 || s > (t === "word" ? 50 : 8)) return !1;
144
+ if (i) {
145
+ let t = i(e.bbox);
146
+ if (t < .01 || t > .9) return !1;
147
+ }
148
+ return !0;
149
+ }
150
+ function Ce(e) {
151
+ let t = [...e].sort((e, t) => e.bbox.y + e.bbox.height / 2 - (t.bbox.y + t.bbox.height / 2) || e.bbox.x - t.bbox.x), n = [];
152
+ for (let e of t) {
153
+ let t = e.bbox.y + e.bbox.height / 2, r = n.find((n) => Math.abs(n.centerY - t) <= Math.max(n.height, e.bbox.height) * .6);
154
+ if (r) {
155
+ r.words.push(e);
156
+ let n = r.words.length;
157
+ r.centerY = (r.centerY * (n - 1) + t) / n, r.height = Math.max(r.height, e.bbox.height);
158
+ } else n.push({
159
+ centerY: t,
160
+ height: e.bbox.height,
161
+ words: [e]
162
+ });
163
+ }
164
+ return n.sort((e, t) => e.centerY - t.centerY).map((e) => e.words.sort((e, t) => e.bbox.x - t.bbox.x).map((e) => e.text.trim()).join(" ")).join("\n");
165
+ }
166
+ function N(e, t, n, r) {
167
+ let i = k(t.minConfidence), a = [], o = [], s = 1, c = 1;
168
+ for (let t of e) {
169
+ let e = t.scaleX ?? 1, n = t.scaleY ?? 1, r = t.offsetX ?? 0, l = t.offsetY ?? 0;
170
+ for (let u of t.blocks ?? []) for (let t of u.paragraphs) for (let u of t.lines) for (let t of u.words) {
171
+ let u = O(t, e, n, r, l);
172
+ s = Math.max(s, u.bbox.x + u.bbox.width), c = Math.max(c, u.bbox.y + u.bbox.height), u.confidence >= i && a.push(u);
173
+ for (let a of t.symbols) {
174
+ let t = O(a, e, n, r, l);
175
+ t.confidence >= i && o.push(t);
176
+ }
177
+ }
178
+ }
179
+ let l = n?.width ?? s, u = n?.height ?? c, d = j(a).filter((e) => M(e, "word", l, u, r)), f = j(o).filter((e) => M(e, "character", l, u, r));
180
+ return {
181
+ text: Ce(d),
182
+ confidence: d.length ? d.reduce((e, t) => e + t.confidence, 0) / d.length : 0,
183
+ words: t.includeWords ? d : [],
184
+ characters: t.includeCharacters ? f : []
185
+ };
186
+ }
187
+ function we(e) {
188
+ let t = /* @__PURE__ */ new Uint32Array(256);
189
+ for (let n of e) t[n] += 1;
190
+ let n = 0;
191
+ for (let e = 0; e < 256; e += 1) n += e * t[e];
192
+ let r = 0, i = 0, a = -1, o = 127;
193
+ for (let s = 0; s < 256; s += 1) {
194
+ if (r += t[s], !r) continue;
195
+ let c = e.length - r;
196
+ if (!c) break;
197
+ i += s * t[s];
198
+ let l = i / r, u = (n - i) / c, d = r * c * (l - u) ** 2;
199
+ d > a && (a = d, o = s);
200
+ }
201
+ return o;
202
+ }
203
+ function P(e) {
204
+ let t = e.getContext("2d", { willReadFrequently: !0 });
205
+ if (!t) throw Error("Canvas 2D is unavailable in this browser.");
206
+ let n = t.getImageData(0, 0, e.width, e.height), r = new Uint8Array(e.width * e.height);
207
+ for (let e = 0, t = 0; e < r.length; e += 1, t += 4) r[e] = Math.round(n.data[t] * .299 + n.data[t + 1] * .587 + n.data[t + 2] * .114);
208
+ return {
209
+ context: t,
210
+ image: n,
211
+ luminance: r
212
+ };
213
+ }
214
+ function Te(e) {
215
+ let t = 1800, n = Math.max(e.width, e.height), r = n > t ? t / n : Math.min(2, t / Math.max(1, n)), i = document.createElement("canvas");
216
+ i.width = Math.max(1, Math.round(e.width * r)), i.height = Math.max(1, Math.round(e.height * r));
217
+ let a = i.getContext("2d", { willReadFrequently: !0 });
218
+ if (!a) throw Error("Canvas 2D is unavailable in this browser.");
219
+ a.drawImage(e, 0, 0, i.width, i.height);
220
+ let { image: o, luminance: s } = P(i), c = ve(s, i.width, i.height);
221
+ for (let e = 0, t = 0; e < c.length; e += 1, t += 4) o.data[t] = c[e], o.data[t + 1] = c[e], o.data[t + 2] = c[e], o.data[t + 3] = 255;
222
+ return a.putImageData(o, 0, 0), i;
223
+ }
224
+ function Ee(e) {
225
+ let t = document.createElement("canvas");
226
+ t.width = 72, t.height = 72;
227
+ let n = t.getContext("2d", { willReadFrequently: !0 });
228
+ if (!n) return {
229
+ strong: !1,
230
+ strength: 0,
231
+ darkness: 0,
232
+ areaRatio: 0
233
+ };
234
+ n.drawImage(e, 0, 0, t.width, t.height);
235
+ let { luminance: r } = P(t);
236
+ return te(r, t.width, t.height);
237
+ }
238
+ function De(e, t, n, r) {
239
+ let i = (e.bbox.x + e.bbox.width / 2) / n, a = (e.bbox.y + e.bbox.height / 2) / r;
240
+ return i >= t.x && i <= t.x + t.width && a >= t.y && a <= t.y + t.height;
241
+ }
242
+ function Oe(e, t, n) {
243
+ if (!e.strong || !e.region) return !1;
244
+ let r = t.filter((t) => De(t, e.region, n.width, n.height)).length, i = t.length - r, a = e.region.width * e.region.height, o = i > 0 && a < .95 ? i / (1 - a) * a : 3;
245
+ return r < Math.max(3, o * .85);
246
+ }
247
+ function ke(e, t, n, r) {
248
+ let i = Math.max(0, Math.floor(t.x * e.width)), a = Math.max(0, Math.floor(t.y * e.height)), o = Math.min(e.width, Math.ceil((t.x + t.width) * e.width)), s = Math.min(e.height, Math.ceil((t.y + t.height) * e.height)), c = document.createElement("canvas");
249
+ c.width = Math.max(1, o - i), c.height = Math.max(1, s - a), c.getContext("2d")?.drawImage(e, i, a, c.width, c.height, 0, 0, c.width, c.height);
250
+ let l = n / e.width, u = r / e.height;
251
+ return {
252
+ tile: c,
253
+ passMapping: {
254
+ scaleX: l,
255
+ scaleY: u,
256
+ offsetX: i * l,
257
+ offsetY: a * u
258
+ }
259
+ };
260
+ }
261
+ function Ae(e) {
262
+ let t = 2200, n = Math.max(e.width, e.height), r = n > t ? t / n : Math.min(1.5, t / Math.max(1, n)), i = document.createElement("canvas");
263
+ i.width = Math.max(1, Math.round(e.width * r)), i.height = Math.max(1, Math.round(e.height * r));
264
+ let a = i.getContext("2d", { willReadFrequently: !0 });
265
+ if (!a) throw Error("Canvas 2D is unavailable in this browser.");
266
+ a.drawImage(e, 0, 0, i.width, i.height);
267
+ let o = a.getImageData(0, 0, i.width, i.height), s = new Uint8Array(i.width * i.height);
268
+ for (let e = 0, t = 0; e < s.length; e += 1, t += 4) s[e] = Math.round(o.data[t] * .299 + o.data[t + 1] * .587 + o.data[t + 2] * .114);
269
+ let c = we(s);
270
+ for (let e = 0, t = 0; e < s.length; e += 1, t += 4) {
271
+ let n = s[e] <= c ? 0 : 255;
272
+ o.data[t] = n, o.data[t + 1] = n, o.data[t + 2] = n, o.data[t + 3] = 255;
273
+ }
274
+ return a.putImageData(o, 0, 0), i;
275
+ }
276
+ function je(e) {
277
+ let t = document.createElement("canvas");
278
+ t.width = 24, t.height = 24;
279
+ let n = t.getContext("2d", { willReadFrequently: !0 });
280
+ return (r) => {
281
+ if (!n || r.width <= 0 || r.height <= 0) return 0;
282
+ n.clearRect(0, 0, t.width, t.height), n.drawImage(e, r.x, r.y, r.width, r.height, 0, 0, t.width, t.height);
283
+ let i = n.getImageData(0, 0, t.width, t.height).data, a = 255, o = 0, s = new Uint8Array(t.width * t.height);
284
+ for (let e = 0, t = 0; e < s.length; e += 1, t += 4) {
285
+ let n = Math.round(i[t] * .299 + i[t + 1] * .587 + i[t + 2] * .114);
286
+ s[e] = n, a = Math.min(a, n), o = Math.max(o, n);
287
+ }
288
+ if (o - a < 12) return 0;
289
+ let c = a + (o - a) * .55, l = 0;
290
+ for (let e of s) e < c && (l += 1);
291
+ return l / s.length;
292
+ };
293
+ }
294
+ async function F(e, t = {}) {
295
+ await o("ocr");
296
+ let n = t.language ?? "eng";
297
+ k(t.minConfidence);
298
+ let r = await C(e, { cloneCanvas: !1 }), i = Ae(r), a = t.shadowPass === !1 ? {
299
+ strong: !1,
300
+ strength: 0,
301
+ darkness: 0,
302
+ areaRatio: 0
303
+ } : Ee(r), { createWorker: s, PSM: c } = await import("tesseract.js"), l = 0, u = a.strong ? 3 : 2, d = await s(n, void 0, { logger(e) {
304
+ typeof e.progress == "number" && t.onProgress?.(Math.min(1, (l + e.progress) / u), e.status);
305
+ } });
306
+ try {
307
+ await d.setParameters({ tessedit_pageseg_mode: c.AUTO });
308
+ let e = await d.recognize(r, {}, {
309
+ text: !0,
310
+ blocks: !0
311
+ });
312
+ l = 1, await d.setParameters({
313
+ tessedit_pageseg_mode: c.SPARSE_TEXT,
314
+ preserve_interword_spaces: "1"
315
+ });
316
+ let o = await d.recognize(i, {}, {
317
+ text: !0,
318
+ blocks: !0
319
+ }), s = [{ blocks: e.data.blocks }, {
320
+ blocks: o.data.blocks,
321
+ scaleX: r.width / i.width,
322
+ scaleY: r.height / i.height
323
+ }], u = {
324
+ ...t,
325
+ includeWords: !0
326
+ }, f = je(r), p = N(s, u, {
327
+ width: r.width,
328
+ height: r.height
329
+ }, f), m = t.shadowPass !== !1 && Oe(a, p.words, {
330
+ width: r.width,
331
+ height: r.height
332
+ });
333
+ if (m && a.region) {
334
+ l = 2;
335
+ let { tile: e, passMapping: t } = ke(Te(r), a.region, r.width, r.height);
336
+ await d.setParameters({
337
+ tessedit_pageseg_mode: c.SPARSE_TEXT,
338
+ preserve_interword_spaces: "1"
339
+ });
340
+ let n = await d.recognize(e, {}, {
341
+ text: !0,
342
+ blocks: !0
343
+ });
344
+ s.push({
345
+ blocks: n.data.blocks,
346
+ ...t
347
+ });
348
+ }
349
+ let h = s.length === 2 ? p : N(s, u, {
350
+ width: r.width,
351
+ height: r.height
352
+ }, f);
353
+ return t.onProgress?.(1, "recognizing text"), {
354
+ text: h.text,
355
+ confidence: h.confidence,
356
+ language: n,
357
+ imageWidth: r.width,
358
+ imageHeight: r.height,
359
+ diagnostics: {
360
+ shadowPassUsed: m,
361
+ castShadowStrength: a.strength,
362
+ shadowRegion: a.region ? {
363
+ x: a.region.x * r.width,
364
+ y: a.region.y * r.height,
365
+ width: a.region.width * r.width,
366
+ height: a.region.height * r.height
367
+ } : void 0
368
+ },
369
+ ...t.includeWords ? { words: h.words } : {},
370
+ ...t.includeCharacters ? { characters: h.characters } : {}
371
+ };
372
+ } finally {
373
+ await d.terminate();
374
+ }
375
+ }
376
+ //#endregion
377
+ //#region src/sdk/detect.ts
378
+ var I = /* @__PURE__ */ new Map();
379
+ function Me(e, t) {
380
+ let n = Math.max(0, Math.min(e.x + e.width, t.x + t.width) - Math.max(e.x, t.x)) * Math.max(0, Math.min(e.y + e.height, t.y + t.height) - Math.max(e.y, t.y));
381
+ return n / (e.width * e.height + t.width * t.height - n);
382
+ }
383
+ function Ne(e) {
384
+ return e.sort((e, t) => t.confidence - e.confidence).filter((e, t, n) => n.slice(0, t).every((t) => Me(e, t) < .45)).slice(0, 20);
385
+ }
386
+ function L(e, t) {
387
+ let n = t === "plate";
388
+ if (e.width < 320 || e.height < 180) return [];
389
+ let r = e.width / e.height;
390
+ if (n && r < 1.15) return [];
391
+ let i = e.width * (n ? .24 : .58), a = e.height * (n ? .1 : .35);
392
+ return [{
393
+ id: `${t}-fallback-1`,
394
+ label: n ? "possible plate" : "possible vehicle",
395
+ confidence: n ? .42 : .48,
396
+ source: "heuristic",
397
+ x: (e.width - i) / 2,
398
+ y: e.height * (n ? .58 : .43),
399
+ width: i,
400
+ height: a
401
+ }];
402
+ }
403
+ async function Pe(e, t, n, r) {
404
+ let i = await import("onnxruntime-web"), a = document.createElement("canvas");
405
+ a.width = 640, a.height = 640;
406
+ let o = a.getContext("2d", { willReadFrequently: !0 });
407
+ if (!o) throw Error("Canvas 2D is unavailable in this browser.");
408
+ o.drawImage(e, 0, 0, 640, 640);
409
+ let s = o.getImageData(0, 0, 640, 640).data, c = 409600, l = new Float32Array(c * 3);
410
+ for (let e = 0; e < c; e += 1) l[e] = s[e * 4] / 255, l[c + e] = s[e * 4 + 1] / 255, l[c * 2 + e] = s[e * 4 + 2] / 255;
411
+ let u = I.get(n);
412
+ u || (u = i.InferenceSession.create(n, {
413
+ executionProviders: ["wasm"],
414
+ graphOptimizationLevel: "all"
415
+ }), I.set(n, u));
416
+ let d = await u, f = d.inputNames[0], p = (await d.run({ [f]: new i.Tensor("float32", l, [
417
+ 1,
418
+ 3,
419
+ 640,
420
+ 640
421
+ ]) }))[d.outputNames[0]], m = p.dims.map(Number), h = p.data, g = m.length === 3 ? m[1] : 0, _ = m.length === 3 ? m[2] : 0;
422
+ if (g < 5 || _ < 1) throw Error("Unsupported YOLO output shape.");
423
+ let v = /* @__PURE__ */ new Set([
424
+ 2,
425
+ 3,
426
+ 5,
427
+ 7
428
+ ]), y = [];
429
+ for (let n = 0; n < _; n += 1) {
430
+ let i = 0, a = 0;
431
+ for (let e = 4; e < g; e += 1) {
432
+ let t = h[e * _ + n];
433
+ t > i && (i = t, a = e - 4);
434
+ }
435
+ if (i < r || t === "vehicle" && !v.has(a)) continue;
436
+ let o = h[n], s = h[_ + n], c = h[_ * 2 + n], l = h[_ * 3 + n];
437
+ y.push({
438
+ id: `${t}-${n}`,
439
+ label: t === "plate" ? "license plate" : [
440
+ "car",
441
+ "motorcycle",
442
+ "bus",
443
+ "truck"
444
+ ][[
445
+ 2,
446
+ 3,
447
+ 5,
448
+ 7
449
+ ].indexOf(a)] ?? "vehicle",
450
+ confidence: i,
451
+ source: "model",
452
+ x: (o - c / 2) / 640 * e.width,
453
+ y: (s - l / 2) / 640 * e.height,
454
+ width: c / 640 * e.width,
455
+ height: l / 640 * e.height
456
+ });
457
+ }
458
+ return Ne(y);
459
+ }
460
+ async function R(e, t, n) {
461
+ let r = await C(e);
462
+ if (!n.modelUrl) return n.allowFallback === !1 ? [] : L(r, t);
463
+ try {
464
+ let e = await Pe(r, t, n.modelUrl, n.confidence ?? .35);
465
+ return e.length || n.allowFallback === !1 ? e : L(r, t);
466
+ } catch (e) {
467
+ if (n.allowFallback === !1) throw e;
468
+ return L(r, t);
469
+ }
470
+ }
471
+ async function z(e, t = {}) {
472
+ return await o("vehicles"), R(e, "vehicle", t);
473
+ }
474
+ async function Fe(e, t = {}) {
475
+ return await o("vehicles"), R(e, "plate", t);
476
+ }
477
+ //#endregion
478
+ //#region src/sdk/redact.ts
479
+ async function B(e, t, n = {}) {
480
+ await o("redaction");
481
+ let r = await C(e), i = r.getContext("2d");
482
+ if (!i) throw Error("Canvas 2D is unavailable in this browser.");
483
+ for (let e of t) {
484
+ let t = p(e, r.width, r.height);
485
+ if (t.width < 1 || t.height < 1) continue;
486
+ if ((e.mode ?? n.mode ?? "blackout") === "blackout") {
487
+ i.fillStyle = "#050706", i.fillRect(t.x, t.y, t.width, t.height);
488
+ continue;
489
+ }
490
+ let a = document.createElement("canvas");
491
+ a.width = Math.ceil(t.width), a.height = Math.ceil(t.height);
492
+ let o = a.getContext("2d");
493
+ if (!o) continue;
494
+ o.filter = `blur(${n.blurRadius ?? 18}px)`;
495
+ let s = Math.max(12, n.blurRadius ?? 18);
496
+ o.drawImage(r, t.x - s, t.y - s, t.width + s * 2, t.height + s * 2, -s, -s, t.width + s * 2, t.height + s * 2), i.drawImage(a, t.x, t.y, t.width, t.height);
497
+ }
498
+ return {
499
+ canvas: r,
500
+ blob: await c(r, n.mimeType ?? "image/png", n.quality)
501
+ };
502
+ }
503
+ //#endregion
504
+ //#region src/sdk/field-model.ts
505
+ var V = /* @__PURE__ */ new Map(), Ie = [
506
+ "person_name",
507
+ "date_of_birth",
508
+ "address",
509
+ "document_number",
510
+ "expiration_date",
511
+ "postal_code",
512
+ "state"
513
+ ];
514
+ function Le(e, t) {
515
+ let n = Math.max(0, Math.min(e.bbox.x + e.bbox.width, t.bbox.x + t.bbox.width) - Math.max(e.bbox.x, t.bbox.x)) * Math.max(0, Math.min(e.bbox.y + e.bbox.height, t.bbox.y + t.bbox.height) - Math.max(e.bbox.y, t.bbox.y));
516
+ return n / Math.max(1, e.bbox.width * e.bbox.height + t.bbox.width * t.bbox.height - n);
517
+ }
518
+ async function Re(e, t, n = Ie, r = .35) {
519
+ let i = await C(e, { cloneCanvas: !1 }), a = await import("onnxruntime-web"), o = document.createElement("canvas");
520
+ o.width = 640, o.height = 640;
521
+ let s = o.getContext("2d", { willReadFrequently: !0 });
522
+ if (!s) throw Error("Canvas 2D is unavailable in this browser.");
523
+ s.drawImage(i, 0, 0, 640, 640);
524
+ let c = s.getImageData(0, 0, 640, 640).data, l = 409600, u = new Float32Array(l * 3);
525
+ for (let e = 0; e < l; e += 1) u[e] = c[e * 4] / 255, u[l + e] = c[e * 4 + 1] / 255, u[l * 2 + e] = c[e * 4 + 2] / 255;
526
+ let d = V.get(t);
527
+ d || (d = a.InferenceSession.create(t, {
528
+ executionProviders: ["wasm"],
529
+ graphOptimizationLevel: "all"
530
+ }), V.set(t, d));
531
+ let f = await d, p = (await f.run({ [f.inputNames[0]]: new a.Tensor("float32", u, [
532
+ 1,
533
+ 3,
534
+ 640,
535
+ 640
536
+ ]) }))[f.outputNames[0]], m = p.dims.map(Number), h = p.data, g = m.length === 3 ? m[1] : 0, _ = m.length === 3 ? m[2] : 0;
537
+ if (g < 5 || _ < 1) throw Error("Unsupported field-model YOLO output shape.");
538
+ let v = [];
539
+ for (let e = 0; e < _; e += 1) {
540
+ let t = 0, a = 0;
541
+ for (let r = 4; r < Math.min(g, n.length + 4); r += 1) {
542
+ let n = h[r * _ + e];
543
+ n > t && (t = n, a = r - 4);
544
+ }
545
+ let o = n[a];
546
+ if (!o || t < r) continue;
547
+ let s = h[e], c = h[_ + e], l = h[_ * 2 + e], u = h[_ * 3 + e];
548
+ v.push({
549
+ field: o,
550
+ confidence: t,
551
+ bbox: {
552
+ x: (s - l / 2) / 640 * i.width,
553
+ y: (c - u / 2) / 640 * i.height,
554
+ width: l / 640 * i.width,
555
+ height: u / 640 * i.height
556
+ }
557
+ });
558
+ }
559
+ return v.sort((e, t) => t.confidence - e.confidence).filter((e, t, n) => n.slice(0, t).every((t) => t.field !== e.field || Le(e, t) < .45)).slice(0, 30);
560
+ }
561
+ //#endregion
562
+ //#region src/sdk/programmatic-redaction.ts
563
+ function H(e) {
564
+ let t = Math.min(...e.map((e) => e.bbox.x)), n = Math.min(...e.map((e) => e.bbox.y)), r = Math.max(...e.map((e) => e.bbox.x + e.bbox.width)), i = Math.max(...e.map((e) => e.bbox.y + e.bbox.height));
565
+ return {
566
+ x: t,
567
+ y: n,
568
+ width: r - t,
569
+ height: i - n
570
+ };
571
+ }
572
+ function U(e) {
573
+ let t = [], n = [...e].sort((e, t) => e.bbox.y + e.bbox.height / 2 - (t.bbox.y + t.bbox.height / 2) || e.bbox.x - t.bbox.x);
574
+ for (let e of n) {
575
+ let n = e.bbox.y + e.bbox.height / 2, r = t.find((t) => {
576
+ let r = H(t), i = r.y + r.height / 2;
577
+ return Math.abs(n - i) <= Math.max(e.bbox.height, r.height) * .65;
578
+ });
579
+ r ? r.push(e) : t.push([e]);
580
+ }
581
+ return t.map((e) => (e.sort((e, t) => e.bbox.x - t.bbox.x), {
582
+ words: e,
583
+ text: e.map((e) => e.text).join(" "),
584
+ bbox: H(e)
585
+ }));
586
+ }
587
+ function W(e, t, n = !1) {
588
+ let r = e.trim().replace(/\s+/g, " "), i = n ? r.replace(/[::]\s*$/, "") : r;
589
+ return t ? i.toLocaleLowerCase() : i;
590
+ }
591
+ function G(e) {
592
+ return e.reduce((e, t) => e + t.confidence, 0) / Math.max(1, e.length);
593
+ }
594
+ function ze(e, t) {
595
+ let n = e.mode, r = n === "case-insensitive", i = e.scope ?? "line", a;
596
+ if (n === "regex") {
597
+ let t = e.pattern ?? e.values?.[0];
598
+ if (!t) return [];
599
+ a = new RegExp(t, e.flags?.replace("g", "") ?? "");
600
+ }
601
+ let o = (e.values ?? []).filter(Boolean), s = [], c = (t) => s.push({
602
+ ruleId: e.id,
603
+ strategy: "string",
604
+ source: "string",
605
+ bbox: H(t),
606
+ text: t.map((e) => e.text).join(" "),
607
+ confidence: G(t)
608
+ });
609
+ if (i === "word") {
610
+ for (let e of t) for (let t of e.words) {
611
+ let e = W(t.text, r);
612
+ (a ? a.test(t.text) : o.some((t) => e === W(t, r))) && c([t]);
613
+ }
614
+ return s;
615
+ }
616
+ for (let e of t) {
617
+ if (a) {
618
+ a.test(e.text) && c(e.words);
619
+ continue;
620
+ }
621
+ for (let t of o) {
622
+ let n = W(t, r).split(" ");
623
+ for (let t = 0; t <= e.words.length - n.length; t += 1) {
624
+ let i = e.words.slice(t, t + n.length);
625
+ i.every((e, t) => W(e.text, r) === n[t]) && c(i);
626
+ }
627
+ }
628
+ }
629
+ return s;
630
+ }
631
+ function Be(e, t) {
632
+ let n = e.labelMode !== "exact", r = W(e.label, n, !0).split(" ");
633
+ for (let e of t) for (let t = 0; t <= e.words.length - r.length; t += 1) {
634
+ let i = e.words.slice(t, t + r.length);
635
+ if (i.every((e, t) => W(e.text, n, !0) === r[t])) return i;
636
+ }
637
+ }
638
+ function Ve(e, t, n, r, i, a) {
639
+ let o = a.window?.distance ?? .28, s = a.window?.crossAxis ?? .12, c = t.x + t.width / 2, l = t.y + t.height / 2;
640
+ return e.filter((e) => {
641
+ let a = e.bbox.x + e.bbox.width / 2, u = e.bbox.y + e.bbox.height / 2;
642
+ return n === "right" ? e.bbox.x >= t.x + t.width && e.bbox.x - t.x - t.width <= r * o && Math.abs(u - l) <= i * s : n === "left" ? e.bbox.x + e.bbox.width <= t.x && t.x - e.bbox.x - e.bbox.width <= r * o && Math.abs(u - l) <= i * s : n === "below" ? e.bbox.y >= t.y + t.height && e.bbox.y - t.y - t.height <= i * o && Math.abs(a - c) <= r * s : e.bbox.y + e.bbox.height <= t.y && t.y - e.bbox.y - e.bbox.height <= i * o && Math.abs(a - c) <= r * s;
643
+ });
644
+ }
645
+ function K(e, t, n, r, i, a = "label") {
646
+ let o = Be(e, n);
647
+ if (!o) return [];
648
+ let s = H(o), c = new Set(o), l = t.filter((e) => !c.has(e)), u = e.direction === "any" ? [
649
+ "right",
650
+ "below",
651
+ "left",
652
+ "above"
653
+ ] : [e.direction], d;
654
+ for (let t of u) {
655
+ let n = U(Ve(l, s, t, r, i, e));
656
+ for (let t of n) {
657
+ if (e.valuePattern && !new RegExp(e.valuePattern, e.patternFlags).test(t.text)) continue;
658
+ let n = t.bbox.x + t.bbox.width / 2, a = t.bbox.y + t.bbox.height / 2, o = s.x + s.width / 2, c = s.y + s.height / 2, l = Math.hypot((n - o) / r, (a - c) / i);
659
+ (!d || l < d.distance) && (d = {
660
+ words: t.words,
661
+ distance: l
662
+ });
663
+ }
664
+ }
665
+ if (!d) return [];
666
+ let f = e.redactLabel ? [...o, ...d.words] : d.words;
667
+ return [{
668
+ ruleId: e.id,
669
+ strategy: a,
670
+ source: a === "template-anchor" ? "template" : "label",
671
+ bbox: H(f),
672
+ text: d.words.map((e) => e.text).join(" "),
673
+ confidence: Math.max(0, G(d.words) * (1 - Math.min(.5, d.distance)))
674
+ }];
675
+ }
676
+ var q = {
677
+ person_name: [
678
+ "LN",
679
+ "FN",
680
+ "DCS",
681
+ "DAC",
682
+ "DAD",
683
+ "NAME"
684
+ ],
685
+ date_of_birth: [
686
+ "DOB",
687
+ "DBB",
688
+ "BIRTH"
689
+ ],
690
+ address: [
691
+ "ADDRESS",
692
+ "ADDR",
693
+ "DAG",
694
+ "DAI"
695
+ ],
696
+ document_number: [
697
+ "DLN",
698
+ "DAQ",
699
+ "IDNO",
700
+ "LICNO"
701
+ ],
702
+ expiration_date: [
703
+ "EXP",
704
+ "DBA",
705
+ "EXPIRES"
706
+ ],
707
+ postal_code: [
708
+ "ZIP",
709
+ "DAK",
710
+ "POSTAL"
711
+ ],
712
+ state: ["STATE", "DAJ"]
713
+ }, He = new Set(Object.values(q).flat()), J = /^(?:\d{2}[/-]\d{2}[/-]\d{2,4}|\d{4}[/-]\d{2}[/-]\d{2}|\d{6}|\d{8})$/, Y = /\b(?:ST|STREET|AVE|AVENUE|RD|ROAD|BLVD|BOULEVARD|LN|LANE|DR|DRIVE|WAY|CT|COURT)\b/i, X = /\b(?:DRIVER|LICENSE|IDENTIFICATION|CARD|CLASS|SEX|EYES|HEIGHT|RESTRICTIONS)\b/i;
714
+ function Z(e, t) {
715
+ let n = t.trim();
716
+ return n ? e === "date_of_birth" || e === "expiration_date" ? J.test(n.replace(/\s/g, "")) : e === "postal_code" ? /^(?:\d{5}(?:-\d{4})?|[A-Z]\d[A-Z]\s?\d[A-Z]\d)$/i.test(n) : e === "state" ? /^[A-Z]{2}$/i.test(n) : e === "document_number" ? /^(?=.*\d)[A-Z0-9-]{5,20}$/i.test(n) : e === "person_name" ? !/\d/.test(n) && /^[A-ZÀ-ÖØ-öø-ÿ' -]{3,}$/i.test(n) && !X.test(n) : /\d/.test(n) && /[A-Z]/i.test(n) : !1;
717
+ }
718
+ function Q(e, t, n, r, i = 1) {
719
+ return {
720
+ ruleId: e,
721
+ strategy: "semantic",
722
+ source: t,
723
+ bbox: H(n),
724
+ text: r ?? n.map((e) => e.text).join(" "),
725
+ confidence: Math.max(0, Math.min(1, G(n) * i))
726
+ };
727
+ }
728
+ function Ue(e, t, n) {
729
+ let r = q[e], i = [];
730
+ for (let a of n) for (let n = 0; n < a.words.length; n += 1) {
731
+ let o = a.words[n].text.toUpperCase().replace(/[^A-Z0-9]/g, ""), s = r.find((e) => o === e || o.startsWith(e));
732
+ if (!s) continue;
733
+ let c, l;
734
+ o === s ? (c = a.words.slice(n + 1).filter((e) => !He.has(e.text.toUpperCase().replace(/[^A-Z0-9]/g, ""))), l = c.map((e) => e.text).join(" ")) : (c = [a.words[n]], l = a.words[n].text.replace(RegExp(`^${s}[:\\s-]*`, "i"), "")), c.length && Z(e, l) && i.push(Q(t, "alias", c, l, .98));
735
+ }
736
+ return i;
737
+ }
738
+ function We(e, t, n) {
739
+ let r = n.filter((e) => {
740
+ let t = e.text.replace(/\s/g, "");
741
+ return t.includes("<<") || /^[A-Z0-9<]{25,}$/.test(t);
742
+ });
743
+ if (!r.length) return [];
744
+ if (e === "person_name") {
745
+ let e = r.find((e) => e.text.includes("<<"));
746
+ if (!e) return [];
747
+ let n = e.text.replace(/\s/g, ""), i = /^[PIV]<[A-Z]{3}/.test(n) ? 5 : n.indexOf("<") + 1, a = n.slice(i).replace(/<+/g, " ").trim();
748
+ return a ? [Q(t, "mrz", e.words, a, .96)] : [];
749
+ }
750
+ if (e === "date_of_birth") for (let e of r) {
751
+ let n = e.text.replace(/\s/g, ""), r = /^\d{6}/.exec(n)?.[0] ?? /^.{13}(\d{6})/.exec(n)?.[1];
752
+ if (r) return [Q(t, "mrz", e.words, r, .96)];
753
+ }
754
+ if (e === "document_number") {
755
+ let e = r[0];
756
+ return [Q(t, "mrz", e.words, e.text, .9)];
757
+ }
758
+ return [];
759
+ }
760
+ function Ge(e) {
761
+ let t = e.replace(/\s/g, ""), n = t.match(/\d{4}/)?.[0];
762
+ if (n) return Number(n);
763
+ let r = t.match(/^\d{2}/)?.[0];
764
+ if (!r) return;
765
+ let i = Number(r);
766
+ return i > (/* @__PURE__ */ new Date()).getFullYear() % 100 ? 1900 + i : 2e3 + i;
767
+ }
768
+ function Ke(e, t, n, r, i) {
769
+ if (e === "address") {
770
+ let e = r.findIndex((e) => /\d/.test(e.text) && Y.test(e.text));
771
+ if (e < 0) return [];
772
+ let n = [...r[e].words], i = r[e + 1];
773
+ return i && /(?:\b[A-Z]{2}\b.*\d{5}|\d{5})/i.test(i.text) && n.push(...i.words), [Q(t, "layout", n, void 0, .76)];
774
+ }
775
+ if (e === "person_name") {
776
+ let e = r.map((e) => {
777
+ let t = e.words.filter((e) => /^[A-ZÀ-ÖØ-öø-ÿ'-]+$/i.test(e.text)), n = e.bbox.y / Math.max(1, i), r = t.length >= 2 && t.length <= 5 && t.length === e.words.length && !X.test(e.text) && !Y.test(e.text) && !e.text.includes("<"), a = e.text.replace(/[^A-Z]/g, "").length / Math.max(1, e.text.replace(/[^A-Za-z]/g, "").length);
778
+ return {
779
+ line: e,
780
+ score: r ? .45 + G(e.words) * .3 + a * .15 + (n < .65 ? .1 : 0) : 0
781
+ };
782
+ }).filter((e) => e.score >= .68).sort((e, t) => t.score - e.score);
783
+ return !e.length || e[1] && e[0].score - e[1].score < .04 ? [] : [Q(t, "layout", e[0].line.words, void 0, e[0].score)];
784
+ }
785
+ if (e === "date_of_birth" || e === "expiration_date") {
786
+ let r = (/* @__PURE__ */ new Date()).getFullYear(), i = n.filter((e) => J.test(e.text.replace(/\s/g, ""))).map((e) => ({
787
+ word: e,
788
+ year: Ge(e.text)
789
+ })).filter((e) => e.year !== void 0), a = e === "date_of_birth" ? i.filter((e) => e.year <= r - 14 && e.year >= r - 120) : i.filter((e) => e.year >= r - 1);
790
+ return a.sort((t, n) => e === "date_of_birth" ? t.year - n.year : n.year - t.year), a.length ? [Q(t, "layout", [a[0].word], void 0, .72)] : [];
791
+ }
792
+ if (e === "postal_code") {
793
+ let r = n.find((t) => Z(e, t.text));
794
+ return r ? [Q(t, "layout", [r], void 0, .78)] : [];
795
+ }
796
+ if (e === "state") {
797
+ let r = n.filter((t) => Z(e, t.text));
798
+ return r.length === 1 ? [Q(t, "layout", r, void 0, .7)] : [];
799
+ }
800
+ if (e === "document_number") {
801
+ let r = n.filter((t) => Z(e, t.text));
802
+ return r.sort((e, t) => t.text.length - e.text.length), r.length ? [Q(t, "layout", [r[0]], void 0, .7)] : [];
803
+ }
804
+ return [];
805
+ }
806
+ function qe(e, t) {
807
+ return Math.max(0, Math.min(e.x + e.width, t.x + t.width) - Math.max(e.x, t.x)) * Math.max(0, Math.min(e.y + e.height, t.y + t.height) - Math.max(e.y, t.y)) / Math.max(1, t.width * t.height);
808
+ }
809
+ function Je(e, t) {
810
+ return Math.max(0, Math.min(e.x + e.width, t.x + t.width) - Math.max(e.x, t.x)) * Math.max(0, Math.min(e.y + e.height, t.y + t.height) - Math.max(e.y, t.y)) / Math.max(1, Math.min(e.width * e.height, t.width * t.height));
811
+ }
812
+ function Ye(e, t, n, r, i, a) {
813
+ let o = Ue(e.field, e.id, n), s = We(e.field, e.id, n), c = [...o, ...s], l = c.length ? c : Ke(e.field, e.id, t, n, r);
814
+ if (!a) return l;
815
+ let u = (i ?? []).filter((t) => t.field === e.field).sort((e, t) => t.confidence - e.confidence);
816
+ for (let n of u) {
817
+ let r = t.filter((e) => qe(n.bbox, e.bbox) >= .3);
818
+ if (!r.length) continue;
819
+ let i = r.map((e) => e.text).join(" ");
820
+ if (!Z(e.field, i)) continue;
821
+ let a = Q(e.id, "model", r, i, n.confidence);
822
+ if (!l.length || l.some((e) => Je(e.bbox, a.bbox) >= .25)) return [a];
823
+ }
824
+ return [];
825
+ }
826
+ function Xe(e, t, n, r) {
827
+ let i = (e) => Math.max(0, Math.min(1, e)), a = i(e.rect.x), o = i(e.rect.y);
828
+ return {
829
+ ruleId: `${t}.${e.id}`,
830
+ strategy: "template-rect",
831
+ source: "template",
832
+ bbox: {
833
+ x: a * n,
834
+ y: o * r,
835
+ width: Math.max(0, Math.min(1 - a, e.rect.width)) * n,
836
+ height: Math.max(0, Math.min(1 - o, e.rect.height)) * r
837
+ },
838
+ confidence: 1
839
+ };
840
+ }
841
+ function $(e, t) {
842
+ let n = t.imageWidth ?? e?.imageWidth ?? 0, r = t.imageHeight ?? e?.imageHeight ?? 0, i = e?.words ?? [], a = U(i), o = [], s = [];
843
+ for (let e of t.rules) {
844
+ let c = e.strategy === "string" ? ze(e, a) : e.strategy === "label" ? K(e, i, a, n, r) : Ye(e, i, a, r, t.semanticDetections, t.modelRequested === !0);
845
+ c.length ? o.push(...c) : s.push(e.id);
846
+ }
847
+ for (let e of t.template?.fields ?? []) {
848
+ let c = `${t.template.id}.${e.id}`;
849
+ if (e.strategy === "rect") {
850
+ n && r ? o.push(Xe(e, t.template.id, n, r)) : s.push(c);
851
+ continue;
852
+ }
853
+ let l = K({
854
+ ...e,
855
+ id: c,
856
+ strategy: "label"
857
+ }, i, a, n, r, "template-anchor");
858
+ l.length ? o.push(...l) : s.push(c);
859
+ }
860
+ let c = t.rules.length + (t.template?.fields.length ?? 0), l = new Set(o.map((e) => e.ruleId)), u = c ? [...l].reduce((e, t) => {
861
+ let n = o.filter((e) => e.ruleId === t);
862
+ return e + Math.max(...n.map((e) => e.confidence));
863
+ }, 0) / c : 1;
864
+ return {
865
+ matches: o,
866
+ unmatchedRuleIds: s,
867
+ complete: s.length === 0,
868
+ confidence: u
869
+ };
870
+ }
871
+ function Ze(e) {
872
+ return e.rules.length > 0 || e.template?.fields.some((e) => e.strategy === "anchor") === !0;
873
+ }
874
+ function Qe(e, t = !1) {
875
+ return t && !e.complete ? "unmatched" : e.complete ? "success" : "partial";
876
+ }
877
+ async function $e(e, t) {
878
+ await o("redaction");
879
+ let n = await C(e, { cloneCanvas: !1 }), r = t.ocr;
880
+ Ze(t) && !r?.words && (r = await F(n, { includeWords: !0 }));
881
+ let i = t.semanticDetections, a = t.modelRequested === !0, s = "not-requested", c;
882
+ if (t.models?.fields) try {
883
+ i = await Re(n, t.models.fields, t.models.fieldClasses, t.models.confidence), a = !0, s = "loaded";
884
+ } catch (e) {
885
+ c = e instanceof Error ? e.message : "The field model could not load.";
886
+ let n = t.models.allowHeuristicFallback !== !1;
887
+ a = !n, s = n ? "fallback" : "failed";
888
+ }
889
+ let l = $(r, {
890
+ rules: t.rules,
891
+ template: t.template,
892
+ imageWidth: n.width,
893
+ imageHeight: n.height,
894
+ semanticDetections: i,
895
+ modelRequested: a
896
+ }), u = Qe(l, t.requireAll);
897
+ if (u === "unmatched") return {
898
+ ...l,
899
+ status: u,
900
+ ocr: r,
901
+ modelStatus: s,
902
+ modelError: c
903
+ };
904
+ let d = await B(n, l.matches.map((e) => ({
905
+ ...e.bbox,
906
+ mode: t.style?.mode
907
+ })), t.style);
908
+ return {
909
+ ...l,
910
+ status: u,
911
+ ocr: r,
912
+ canvas: d.canvas,
913
+ blob: d.blob,
914
+ modelStatus: s,
915
+ modelError: c
916
+ };
917
+ }
918
+ //#endregion
919
+ export { m as AutoTorchController, l as DEFAULT_DOCUMENT_MODEL_URL, me as DEFAULT_FINDER_CONFIDENCE_THRESHOLD, fe as DEFAULT_FINDER_CORNER_TOLERANCE, x as DEFAULT_FINDER_EDGE_MARGIN_RATIO, se as DEFAULT_FINDER_EXIT_CORNER_TOLERANCE, ee as DEFAULT_FINDER_EXIT_EDGE_MARGIN_RATIO, pe as DEFAULT_FINDER_EXIT_FILL_RATIO, S as DEFAULT_FINDER_EXIT_MIN_PERSPECTIVE_RATIO, ne as DEFAULT_FINDER_HIGH_ASPECT_FILL_MARGIN, ue as DEFAULT_FINDER_HIGH_ASPECT_RATIO, he as DEFAULT_FINDER_MIN_FILL_RATIO, re as DEFAULT_FINDER_MIN_PERSPECTIVE_RATIO, ie as DEFAULT_FINDER_STABLE_FRAMES, t as DEV_LICENSE_HOSTS, _ as LicenseError, n as NEAR_BLACK_LUMINANCE, b as QuadStabilityTracker, B as applyRedactions, o as assertLicense, de as autoCaptureControl, _e as captureVideoFrame, Se as createFinderSimulator, u as cropDocument, h as detectBrowserEngine, f as detectDocument, Fe as detectPlates, z as detectVehicles, i as formatCaptureDiagnosticsReport, g as getLicense, r as isNearBlackFrame, oe as limitingFillTarget, be as mapDocumentCornersToFrame, $ as matchRedactionRules, d as meanFrameLuminance, ae as measureQuadFill, le as mobileCameraConstraints, F as recognizeText, $e as redactProgrammatically, a as resolveDocumentModelUrl, s as scanDocument, y as selectFinderGuidance, ge as selectFinderHint, v as setLicenseKey, T as simulatorPose, xe as simulatorQuad, e as startCamera, ye as startFinder, ce as torchControl };
920
+
921
+ //# sourceMappingURL=scanner-sdk.js.map