@exige/web-scanner-sdk 0.2.28 → 0.2.30

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.
@@ -1,23 +1,23 @@
1
- import { A as e, B as t, C as n, D as r, E as i, F as a, G as o, H as s, I as c, L as l, M as u, N as d, O as f, P as p, R as m, S as h, T as g, U as _, V as v, W as y, _ as ee, a as te, b, 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 me, r as he, s as ge, t as _e, u as ve, v as ye, w as be, x as xe, y as Se, z as Ce } from "./finder-BvBpdbHa.js";
1
+ import { A as e, B as t, C as n, D as r, E as i, F as a, G as o, H as s, I as c, J as l, K as u, L as d, M as f, N as p, O as ee, P as m, R as h, S as g, T as _, U as v, V as y, W as b, X as x, Y as S, _ as C, a as w, b as T, c as E, d as D, f as O, g as k, h as A, i as j, j as M, k as N, l as te, m as P, n as F, o as I, p as L, q as R, r as z, s as B, t as V, u as H, v as U, w as W, x as G, y as K, z as q } from "./driver-license-DpjQqOKx.js";
2
2
  //#region src/sdk/frame-geometry.ts
3
- function x(e, t, n) {
3
+ function J(e, t, n) {
4
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
5
  return {
6
6
  x: (e.x - c) / s,
7
7
  y: (e.y - l) / s
8
8
  };
9
9
  }
10
- function we(e, t, n) {
10
+ function Y(e, t, n) {
11
11
  return {
12
- topLeft: x(e.topLeft, t, n),
13
- topRight: x(e.topRight, t, n),
14
- bottomRight: x(e.bottomRight, t, n),
15
- bottomLeft: x(e.bottomLeft, t, n)
12
+ topLeft: J(e.topLeft, t, n),
13
+ topRight: J(e.topRight, t, n),
14
+ bottomRight: J(e.bottomRight, t, n),
15
+ bottomLeft: J(e.bottomLeft, t, n)
16
16
  };
17
17
  }
18
18
  //#endregion
19
19
  //#region src/sdk/finder-simulator.ts
20
- function S(e, t = 960, n = 600) {
20
+ function X(e, t = 960, n = 600) {
21
21
  let r = t * .86, i = n * .86;
22
22
  if (e < 1200) {
23
23
  let a = e / 1200;
@@ -50,15 +50,15 @@ function S(e, t = 960, n = 600) {
50
50
  phase: "settled"
51
51
  };
52
52
  }
53
- function C(e, t, n) {
53
+ function Z(e, t, n) {
54
54
  let r = Math.cos(n.rotation), i = Math.sin(n.rotation);
55
55
  return {
56
56
  x: n.centerX + e * r - t * i,
57
57
  y: n.centerY + e * i + t * r
58
58
  };
59
59
  }
60
- function Te(e) {
61
- let t = C(-e.width / 2, -e.height / 2, e), n = C(e.width / 2, -e.height / 2, e), r = C(e.width / 2, e.height / 2, e), i = C(-e.width / 2, e.height / 2, e);
60
+ function Q(e) {
61
+ let t = Z(-e.width / 2, -e.height / 2, e), n = Z(e.width / 2, -e.height / 2, e), r = Z(e.width / 2, e.height / 2, e), i = Z(-e.width / 2, e.height / 2, e);
62
62
  return {
63
63
  topLeft: t,
64
64
  topRight: n,
@@ -84,20 +84,20 @@ function Te(e) {
84
84
  }
85
85
  };
86
86
  }
87
- function w(e, t) {
87
+ function $(e, t) {
88
88
  let n = e.getContext("2d");
89
- if (!n) throw o();
89
+ if (!n) throw x();
90
90
  let r = n.createLinearGradient(0, 0, e.width, e.height);
91
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
92
  let i = -t.width / 2, a = -t.height / 2;
93
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
94
  }
95
- function Ee(e) {
95
+ function ne(e) {
96
96
  e.width ||= 960, e.height ||= 600;
97
97
  let t = !1, n = 0, r = 0, i = (a) => {
98
- t && (n ||= a, w(e, S(a - n, e.width, e.height)), r = requestAnimationFrame(i));
98
+ t && (n ||= a, $(e, X(a - n, e.width, e.height)), r = requestAnimationFrame(i));
99
99
  }, a = () => {
100
- n = 0, w(e, S(0, e.width, e.height));
100
+ n = 0, $(e, X(0, e.width, e.height));
101
101
  };
102
102
  return a(), {
103
103
  start() {
@@ -110,913 +110,6 @@ function Ee(e) {
110
110
  };
111
111
  }
112
112
  //#endregion
113
- //#region src/sdk/ocr-runtime.ts
114
- var De = new URL("./assets/tesseract/worker.min.js", import.meta.url), Oe = new URL("./assets/tesseract/tesseract-core-lstm.wasm.js", import.meta.url), ke = new URL("./assets/tesseract/tesseract-core-simd-lstm.wasm.js", import.meta.url), Ae = new URL("./assets/tesseract/tesseract-core-relaxedsimd-lstm.wasm.js", import.meta.url), je = new URL("./assets/tesseract/eng.traineddata.gz", import.meta.url), Me = Uint8Array.of(0, 97, 115, 109, 1, 0, 0, 0, 1, 5, 1, 96, 0, 1, 123, 3, 2, 1, 0, 10, 15, 1, 13, 0, 65, 1, 253, 15, 65, 2, 253, 15, 253, 128, 2, 11), Ne = Uint8Array.of(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, 98, 11);
115
- function T(e) {
116
- try {
117
- return typeof WebAssembly < "u" && WebAssembly.validate(e);
118
- } catch {
119
- return !1;
120
- }
121
- }
122
- function Pe() {
123
- return {
124
- relaxedSimd: T(Me),
125
- simd: T(Ne)
126
- };
127
- }
128
- function Fe(e) {
129
- return e.relaxedSimd ? Ae : e.simd ? ke : Oe;
130
- }
131
- function Ie(e, t) {
132
- let n = e?.trim() || "eng", r = t?.trim() || "";
133
- if (r) return {
134
- kind: "lang-path",
135
- language: n,
136
- langPath: r
137
- };
138
- if (n === "eng") return {
139
- kind: "bundled-eng",
140
- language: "eng"
141
- };
142
- throw new y("language", `OCR language "${n}" is not packaged. Pass langPath, a directory URL that contains ${n}.traineddata.gz.`);
143
- }
144
- function Le(e = je) {
145
- let t = e.href, n = t.lastIndexOf("/");
146
- return n === -1 ? t : t.slice(0, n);
147
- }
148
- function Re(e) {
149
- return e.kind === "bundled-eng" ? Le() : e.langPath;
150
- }
151
- async function ze(e, t, n) {
152
- return new Promise((r, i) => {
153
- let a = !1, o = (e) => {
154
- if (a) return;
155
- a = !0;
156
- let t = e instanceof Error ? e.message : String(e);
157
- i(new y("worker", `OCR worker failed to start (${t}).`));
158
- };
159
- e(t, void 0, {
160
- workerPath: n.workerPath,
161
- corePath: n.corePath,
162
- langPath: n.langPath,
163
- gzip: !0,
164
- logger: n.logger,
165
- errorHandler: o
166
- }).then((e) => {
167
- if (a) {
168
- e.terminate?.();
169
- return;
170
- }
171
- a = !0, r(e);
172
- }, o);
173
- });
174
- }
175
- //#endregion
176
- //#region src/sdk/ocr.ts
177
- function E(e, t = 1, n = 1, r = 0, i = 0) {
178
- return {
179
- text: e.text,
180
- confidence: Math.max(0, Math.min(1, e.confidence / 100)),
181
- bbox: {
182
- x: e.bbox.x0 * t + r,
183
- y: e.bbox.y0 * n + i,
184
- width: Math.max(0, e.bbox.x1 - e.bbox.x0) * t,
185
- height: Math.max(0, e.bbox.y1 - e.bbox.y0) * n
186
- }
187
- };
188
- }
189
- function D(e = .5) {
190
- if (!Number.isFinite(e) || e < 0 || e > 1) throw RangeError("OCR minConfidence must be between 0 and 1.");
191
- return e;
192
- }
193
- function Be(e, t) {
194
- 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);
195
- return s > 0 ? o / s : 0;
196
- }
197
- function O(e) {
198
- 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 = [];
199
- for (let e of t) n.some((t) => Be(t, e) >= .65) || n.push(e);
200
- return n;
201
- }
202
- function k(e, t, n, r, i) {
203
- let a = e.text.trim();
204
- if (!a || !/[\p{L}\p{N}]/u.test(a)) return !1;
205
- let o = e.bbox.width * e.bbox.height / Math.max(1, n * r), s = e.bbox.width / Math.max(1, e.bbox.height);
206
- if (o < (t === "word" ? 15e-6 : 15e-7) || s < .05 || s > (t === "word" ? 50 : 8)) return !1;
207
- if (i) {
208
- let t = i(e.bbox);
209
- if (t < .01 || t > .9) return !1;
210
- }
211
- return !0;
212
- }
213
- function Ve(e) {
214
- 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 = [];
215
- for (let e of t) {
216
- 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);
217
- if (r) {
218
- r.words.push(e);
219
- let n = r.words.length;
220
- r.centerY = (r.centerY * (n - 1) + t) / n, r.height = Math.max(r.height, e.bbox.height);
221
- } else n.push({
222
- centerY: t,
223
- height: e.bbox.height,
224
- words: [e]
225
- });
226
- }
227
- 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");
228
- }
229
- function A(e, t, n, r) {
230
- let i = D(t.minConfidence), a = [], o = [], s = 1, c = 1;
231
- for (let t of e) {
232
- let e = t.scaleX ?? 1, n = t.scaleY ?? 1, r = t.offsetX ?? 0, l = t.offsetY ?? 0;
233
- for (let u of t.blocks ?? []) for (let t of u.paragraphs) for (let u of t.lines) for (let t of u.words) {
234
- let u = E(t, e, n, r, l);
235
- 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);
236
- for (let a of t.symbols) {
237
- let t = E(a, e, n, r, l);
238
- t.confidence >= i && o.push(t);
239
- }
240
- }
241
- }
242
- let l = n?.width ?? s, u = n?.height ?? c, d = O(a).filter((e) => k(e, "word", l, u, r)), f = O(o).filter((e) => k(e, "character", l, u, r));
243
- return {
244
- text: Ve(d),
245
- confidence: d.length ? d.reduce((e, t) => e + t.confidence, 0) / d.length : 0,
246
- words: t.includeWords ? d : [],
247
- characters: t.includeCharacters ? f : []
248
- };
249
- }
250
- function j(e) {
251
- let t = e.getContext("2d", { willReadFrequently: !0 });
252
- if (!t) throw o();
253
- let n = t.getImageData(0, 0, e.width, e.height), r = new Uint8Array(e.width * e.height);
254
- 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);
255
- return {
256
- context: t,
257
- image: n,
258
- luminance: r
259
- };
260
- }
261
- function He(e) {
262
- let t = document.createElement("canvas");
263
- t.width = 72, t.height = 72;
264
- let n = t.getContext("2d", { willReadFrequently: !0 });
265
- if (!n) return {
266
- strong: !1,
267
- strength: 0,
268
- darkness: 0,
269
- areaRatio: 0
270
- };
271
- n.drawImage(e, 0, 0, t.width, t.height);
272
- let { luminance: r } = j(t);
273
- return ue(r, t.width, t.height);
274
- }
275
- function Ue(e, t, n, r) {
276
- let i = (e.bbox.x + e.bbox.width / 2) / n, a = (e.bbox.y + e.bbox.height / 2) / r;
277
- return i >= t.x && i <= t.x + t.width && a >= t.y && a <= t.y + t.height;
278
- }
279
- var We = .58;
280
- function Ge(e) {
281
- let t = e.trim();
282
- if (!t || !/[\p{L}\p{N}]/u.test(t)) return 0;
283
- if (/^\$?\d{1,5}([.,]\d{2})?$/.test(t)) return 1;
284
- let n = t.replace(/[^\p{L}]/gu, "");
285
- return n.length >= 3 && /[aeiouy]/i.test(n) ? .9 : n.length >= 4 ? .7 : t.length <= 2 ? .35 : /[^\p{L}\p{N}.,'’$/-]/u.test(t) ? .25 : .5;
286
- }
287
- function Ke(e, t, n) {
288
- let r = Math.max(0, Math.min(1, (1 - e.darkness / 80) * (1 - e.strength / 24)));
289
- if (!t.length) return r * .35;
290
- let i = 0;
291
- for (let e of t) {
292
- let t = Ge(e.text);
293
- if (n) {
294
- let r = n(e.bbox);
295
- (r < .04 || r > .62) && (t *= .4);
296
- }
297
- i += t;
298
- }
299
- return r * .7 + i / t.length * .3;
300
- }
301
- function qe(e, t, n, r) {
302
- return !e.strong || !e.region ? !1 : Ke(e, t.filter((t) => Ue(t, e.region, n.width, n.height)), r) < We;
303
- }
304
- function Je(e, t, n, r) {
305
- 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");
306
- 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);
307
- let l = n / e.width, u = r / e.height;
308
- return {
309
- tile: c,
310
- passMapping: {
311
- scaleX: l,
312
- scaleY: u,
313
- offsetX: i * l,
314
- offsetY: a * u
315
- }
316
- };
317
- }
318
- function M(e, t) {
319
- for (let n = 0, r = 0; n < t.length; n += 1, r += 4) e.data[r] = t[n], e.data[r + 1] = t[n], e.data[r + 2] = t[n], e.data[r + 3] = 255;
320
- }
321
- function Ye(e) {
322
- 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");
323
- i.width = Math.max(1, Math.round(e.width * r)), i.height = Math.max(1, Math.round(e.height * r));
324
- let a = i.getContext("2d", { willReadFrequently: !0 });
325
- if (!a) throw o();
326
- a.drawImage(e, 0, 0, i.width, i.height);
327
- let { image: s, luminance: c } = j(i), l = ve(c, i.width, i.height), u = ne(l, i.width, i.height), d = document.createElement("canvas");
328
- d.width = i.width, d.height = i.height;
329
- let f = d.getContext("2d", { willReadFrequently: !0 });
330
- if (!f) throw o();
331
- let p = f.createImageData(d.width, d.height);
332
- return M(p, l), f.putImageData(p, 0, 0), M(s, u), a.putImageData(s, 0, 0), {
333
- sparseCanvas: i,
334
- flattenedCanvas: d
335
- };
336
- }
337
- function Xe(e) {
338
- let t = document.createElement("canvas");
339
- t.width = 24, t.height = 24;
340
- let n = t.getContext("2d", { willReadFrequently: !0 });
341
- return (r) => {
342
- if (!n || r.width <= 0 || r.height <= 0) return 0;
343
- 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);
344
- let i = n.getImageData(0, 0, t.width, t.height).data, a = 255, o = 0, s = new Uint8Array(t.width * t.height);
345
- for (let e = 0, t = 0; e < s.length; e += 1, t += 4) {
346
- let n = Math.round(i[t] * .299 + i[t + 1] * .587 + i[t + 2] * .114);
347
- s[e] = n, a = Math.min(a, n), o = Math.max(o, n);
348
- }
349
- if (o - a < 12) return 0;
350
- let c = a + (o - a) * .55, l = 0;
351
- for (let e of s) e < c && (l += 1);
352
- return l / s.length;
353
- };
354
- }
355
- async function N(e, t = {}) {
356
- await v("ocr");
357
- let n = Ie(t.language, t.langPath), r = n.language;
358
- D(t.minConfidence);
359
- let i = await b(e, { cloneCanvas: !1 }), { sparseCanvas: a, flattenedCanvas: o } = Ye(i), s = t.shadowPass === !1 ? {
360
- strong: !1,
361
- strength: 0,
362
- darkness: 0,
363
- areaRatio: 0
364
- } : He(i), { createWorker: c, PSM: l } = await import("tesseract.js"), u = 0, d = s.strong ? 3 : 2, f = await ze(c, r, {
365
- workerPath: De.href,
366
- corePath: Fe(Pe()).href,
367
- langPath: Re(n),
368
- logger(e) {
369
- typeof e.progress == "number" && t.onProgress?.(Math.min(1, (u + e.progress) / d), e.status ?? "recognizing text");
370
- }
371
- });
372
- try {
373
- await f.setParameters({ tessedit_pageseg_mode: l.AUTO });
374
- let e = await f.recognize(i, {}, {
375
- text: !0,
376
- blocks: !0
377
- });
378
- u = 1, await f.setParameters({
379
- tessedit_pageseg_mode: l.SPARSE_TEXT,
380
- preserve_interword_spaces: "1"
381
- });
382
- let n = await f.recognize(a, {}, {
383
- text: !0,
384
- blocks: !0
385
- }), c = [{ blocks: e.data.blocks }, {
386
- blocks: n.data.blocks,
387
- scaleX: i.width / a.width,
388
- scaleY: i.height / a.height
389
- }], d = {
390
- ...t,
391
- includeWords: !0
392
- }, p = Xe(i), m = A(c, d, {
393
- width: i.width,
394
- height: i.height
395
- }, p), h = t.shadowPass !== !1 && qe(s, m.words, {
396
- width: i.width,
397
- height: i.height
398
- }, p);
399
- if (h && s.region) {
400
- u = 2;
401
- let { tile: e, passMapping: t } = Je(o, s.region, i.width, i.height);
402
- await f.setParameters({
403
- tessedit_pageseg_mode: l.SPARSE_TEXT,
404
- preserve_interword_spaces: "1"
405
- });
406
- let n = await f.recognize(e, {}, {
407
- text: !0,
408
- blocks: !0
409
- });
410
- c.push({
411
- blocks: n.data.blocks,
412
- ...t
413
- });
414
- }
415
- let g = c.length === 2 ? m : A(c, d, {
416
- width: i.width,
417
- height: i.height
418
- }, p);
419
- return t.onProgress?.(1, "recognizing text"), {
420
- text: g.text,
421
- confidence: g.confidence,
422
- language: r,
423
- imageWidth: i.width,
424
- imageHeight: i.height,
425
- diagnostics: {
426
- shadowPassUsed: h,
427
- castShadowStrength: s.strength,
428
- shadowRegion: s.region ? {
429
- x: s.region.x * i.width,
430
- y: s.region.y * i.height,
431
- width: s.region.width * i.width,
432
- height: s.region.height * i.height
433
- } : void 0
434
- },
435
- ...t.includeWords ? { words: g.words } : {},
436
- ...t.includeCharacters ? { characters: g.characters } : {}
437
- };
438
- } finally {
439
- await f.terminate();
440
- }
441
- }
442
- //#endregion
443
- //#region src/sdk/redact.ts
444
- async function P(e, t, n = {}) {
445
- await v("redaction");
446
- let r = await b(e), i = r.getContext("2d");
447
- if (!i) throw o();
448
- for (let e of t) {
449
- let t = Se(e, r.width, r.height);
450
- if (t.width < 1 || t.height < 1) continue;
451
- if ((e.mode ?? n.mode ?? "blackout") === "blackout") {
452
- i.fillStyle = "#050706", i.fillRect(t.x, t.y, t.width, t.height);
453
- continue;
454
- }
455
- let a = document.createElement("canvas");
456
- a.width = Math.ceil(t.width), a.height = Math.ceil(t.height);
457
- let o = a.getContext("2d");
458
- if (!o) continue;
459
- o.filter = `blur(${n.blurRadius ?? 18}px)`;
460
- let s = Math.max(12, n.blurRadius ?? 18);
461
- 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);
462
- }
463
- return {
464
- canvas: r,
465
- blob: await ye(r, n.mimeType ?? "image/png", n.quality)
466
- };
467
- }
468
- //#endregion
469
- //#region src/sdk/face-model.ts
470
- var F = /* @__PURE__ */ new Map(), Ze = 8400;
471
- function Qe(e, t) {
472
- 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));
473
- return n / Math.max(1, e.width * e.height + t.width * t.height - n);
474
- }
475
- function $e(e, t, n, r, i, a, o) {
476
- return {
477
- x: (e - n / 2) / i * a,
478
- y: (t - r / 2) / i * o,
479
- width: n / i * a,
480
- height: r / i * o
481
- };
482
- }
483
- function et(e, t, n) {
484
- let r = t.length === 3 ? t[1] : t[0], i = t.length === 3 ? t[2] : t[1];
485
- if (i !== 6 || r < 1) throw Error(`Face model expects [1, anchors, 6]. A 640 YOLOX-Nano face export is [1, ${Ze}, 6].`);
486
- let a = n.confidence ?? .35, o = n.inputSize ?? 640, s = [];
487
- for (let t = 0; t < r; t += 1) {
488
- let r = t * i, c = e[r + 4] * e[r + 5];
489
- c < a || s.push({
490
- confidence: c,
491
- bbox: $e(e[r], e[r + 1], e[r + 2], e[r + 3], o, n.imageWidth, n.imageHeight)
492
- });
493
- }
494
- return s.sort((e, t) => t.confidence - e.confidence).filter((e, t, n) => n.slice(0, t).every((t) => Qe(e.bbox, t.bbox) < .45)).slice(0, 8);
495
- }
496
- async function tt(e, t, n = .35) {
497
- let r = await b(e, { cloneCanvas: !1 }), i = await import("onnxruntime-web"), a = document.createElement("canvas");
498
- a.width = 640, a.height = 640;
499
- let s = a.getContext("2d", { willReadFrequently: !0 });
500
- if (!s) throw o();
501
- s.drawImage(r, 0, 0, 640, 640);
502
- let c = s.getImageData(0, 0, 640, 640).data, l = 409600, u = new Float32Array(l * 3);
503
- 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;
504
- let d = F.get(t);
505
- d || (d = i.InferenceSession.create(t, {
506
- executionProviders: ["wasm"],
507
- graphOptimizationLevel: "all"
508
- }), F.set(t, d));
509
- let f = await d, p = (await f.run({ [f.inputNames[0]]: new i.Tensor("float32", u, [
510
- 1,
511
- 3,
512
- 640,
513
- 640
514
- ]) }))[f.outputNames[0]];
515
- return et(p.data, p.dims.map(Number), {
516
- confidence: n,
517
- imageWidth: r.width,
518
- imageHeight: r.height,
519
- inputSize: 640
520
- });
521
- }
522
- //#endregion
523
- //#region src/sdk/field-model.ts
524
- var I = /* @__PURE__ */ new Map(), L = [
525
- "person_name",
526
- "date_of_birth",
527
- "address",
528
- "document_number",
529
- "expiration_date",
530
- "postal_code",
531
- "state"
532
- ], nt = 8400;
533
- function R(e) {
534
- return 5 + e;
535
- }
536
- var z = 640;
537
- function rt(e, t) {
538
- 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));
539
- return n / Math.max(1, e.bbox.width * e.bbox.height + t.bbox.width * t.bbox.height - n);
540
- }
541
- function B(e) {
542
- return e.sort((e, t) => t.confidence - e.confidence).filter((e, t, n) => n.slice(0, t).every((t) => t.field !== e.field || rt(e, t) < .45)).slice(0, 30);
543
- }
544
- function V(e, t, n, r, i, a, o) {
545
- return {
546
- x: (e - n / 2) / i * a,
547
- y: (t - r / 2) / i * o,
548
- width: n / i * a,
549
- height: r / i * o
550
- };
551
- }
552
- function H(e, t) {
553
- let n = R(t);
554
- return e.length === 3 && e[0] === 1 && e[2] === n && e[1] > e[2] ? {
555
- anchors: e[1],
556
- features: n
557
- } : e.length === 2 && e[1] === n && e[0] > e[1] ? {
558
- anchors: e[0],
559
- features: n
560
- } : null;
561
- }
562
- function it(e) {
563
- return e.length === 3 && e[1] >= 5 && e[2] >= 1;
564
- }
565
- function at(e) {
566
- let t = R(e);
567
- return /* @__PURE__ */ Error(`YOLOX field layout expects [1, anchors, ${t}] (cx, cy, w, h, objectness, ${e} class scores). A 640 YOLOX-Nano export with decode baked in is [1, ${nt}, ${t}].`);
568
- }
569
- function ot(e, t, n, r, i, a, o) {
570
- if (!it(t)) throw Error("Unsupported field-model YOLO output shape.");
571
- let s = t[1], c = t[2], l = [];
572
- for (let t = 0; t < c; t += 1) {
573
- let u = 0, d = 0;
574
- for (let r = 4; r < Math.min(s, n.length + 4); r += 1) {
575
- let n = e[r * c + t];
576
- n > u && (u = n, d = r - 4);
577
- }
578
- let f = n[d];
579
- !f || u < r || l.push({
580
- field: f,
581
- confidence: u,
582
- bbox: V(e[t], e[c + t], e[c * 2 + t], e[c * 3 + t], i, a, o)
583
- });
584
- }
585
- return B(l);
586
- }
587
- function st(e, t, n, r, i, a, o) {
588
- let s = H(t, n.length);
589
- if (!s) throw at(n.length);
590
- let c = [];
591
- for (let t = 0; t < s.anchors; t += 1) {
592
- let l = t * s.features, u = e[l + 4], d = 0, f = 0;
593
- for (let t = 0; t < n.length; t += 1) {
594
- let n = e[l + 5 + t];
595
- n > d && (d = n, f = t);
596
- }
597
- let p = n[f], m = u * d;
598
- !p || m < r || c.push({
599
- field: p,
600
- confidence: m,
601
- bbox: V(e[l], e[l + 1], e[l + 2], e[l + 3], i, a, o)
602
- });
603
- }
604
- return B(c);
605
- }
606
- function ct(e, t, n) {
607
- let r = n.classes ?? L, i = n.confidence ?? .35, a = n.inputSize ?? z, o = H(t, r.length);
608
- if (n.layout === "yolov8" && o) throw Error("This tensor is YOLOX [1, anchors, 5+classes]. Pass fieldLayout: 'yolox', or omit fieldLayout to detect it from the shape.");
609
- return (n.layout ?? (o ? "yolox" : "yolov8")) === "yolox" ? st(e, t, r, i, a, n.imageWidth, n.imageHeight) : ot(e, t, r, i, a, n.imageWidth, n.imageHeight);
610
- }
611
- async function lt(e, t, n = L, r = .35, i) {
612
- let a = await b(e, { cloneCanvas: !1 }), s = import("onnxruntime-web"), c = z, u = document.createElement("canvas");
613
- u.width = c, u.height = c;
614
- let d = u.getContext("2d", { willReadFrequently: !0 });
615
- if (!d) throw o();
616
- d.drawImage(a, 0, 0, c, c);
617
- let f = d.getImageData(0, 0, c, c).data, p = c * c, m = new Float32Array(p * 3);
618
- for (let e = 0; e < p; e += 1) m[e] = f[e * 4] / 255, m[p + e] = f[e * 4 + 1] / 255, m[p * 2 + e] = f[e * 4 + 2] / 255;
619
- let h = I.get(t);
620
- h || (h = (async () => {
621
- try {
622
- let [e, n] = await Promise.all([s, l(t)]);
623
- return await e.InferenceSession.create(n, {
624
- executionProviders: ["wasm"],
625
- graphOptimizationLevel: "all"
626
- });
627
- } catch (e) {
628
- throw I.delete(t), e;
629
- }
630
- })(), I.set(t, h));
631
- let [g, _] = await Promise.all([s, h]), v = (await _.run({ [_.inputNames[0]]: new g.Tensor("float32", m, [
632
- 1,
633
- 3,
634
- c,
635
- c
636
- ]) }))[_.outputNames[0]];
637
- return ct(v.data, v.dims.map(Number), {
638
- classes: n,
639
- confidence: r,
640
- layout: i,
641
- imageWidth: a.width,
642
- imageHeight: a.height,
643
- inputSize: c
644
- });
645
- }
646
- //#endregion
647
- //#region src/sdk/programmatic-redaction.ts
648
- function U(e) {
649
- 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));
650
- return {
651
- x: t,
652
- y: n,
653
- width: r - t,
654
- height: i - n
655
- };
656
- }
657
- function W(e) {
658
- 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);
659
- for (let e of n) {
660
- let n = e.bbox.y + e.bbox.height / 2, r = t.find((t) => {
661
- let r = U(t), i = r.y + r.height / 2;
662
- return Math.abs(n - i) <= Math.max(e.bbox.height, r.height) * .65;
663
- });
664
- r ? r.push(e) : t.push([e]);
665
- }
666
- return t.map((e) => (e.sort((e, t) => e.bbox.x - t.bbox.x), {
667
- words: e,
668
- text: e.map((e) => e.text).join(" "),
669
- bbox: U(e)
670
- }));
671
- }
672
- function G(e, t, n = !1) {
673
- let r = e.trim().replace(/\s+/g, " "), i = n ? r.replace(/[::]\s*$/, "") : r;
674
- return t ? i.toLocaleLowerCase() : i;
675
- }
676
- function K(e) {
677
- return e.reduce((e, t) => e + t.confidence, 0) / Math.max(1, e.length);
678
- }
679
- function ut(e, t) {
680
- let n = e.mode, r = n === "case-insensitive", i = e.scope ?? "line", a;
681
- if (n === "regex") {
682
- let t = e.pattern ?? e.values?.[0];
683
- if (!t) return [];
684
- a = new RegExp(t, e.flags?.replace("g", "") ?? "");
685
- }
686
- let o = (e.values ?? []).filter(Boolean), s = [], c = (t) => s.push({
687
- ruleId: e.id,
688
- strategy: "string",
689
- source: "string",
690
- bbox: U(t),
691
- text: t.map((e) => e.text).join(" "),
692
- confidence: K(t)
693
- });
694
- if (i === "word") {
695
- for (let e of t) for (let t of e.words) {
696
- let e = G(t.text, r);
697
- (a ? a.test(t.text) : o.some((t) => e === G(t, r))) && c([t]);
698
- }
699
- return s;
700
- }
701
- for (let e of t) {
702
- if (a) {
703
- a.test(e.text) && c(e.words);
704
- continue;
705
- }
706
- for (let t of o) {
707
- let n = G(t, r).split(" ");
708
- for (let t = 0; t <= e.words.length - n.length; t += 1) {
709
- let i = e.words.slice(t, t + n.length);
710
- i.every((e, t) => G(e.text, r) === n[t]) && c(i);
711
- }
712
- }
713
- }
714
- return s;
715
- }
716
- function dt(e, t) {
717
- let n = e.labelMode !== "exact", r = G(e.label, n, !0).split(" ");
718
- for (let e of t) for (let t = 0; t <= e.words.length - r.length; t += 1) {
719
- let i = e.words.slice(t, t + r.length);
720
- if (i.every((e, t) => G(e.text, n, !0) === r[t])) return i;
721
- }
722
- }
723
- function ft(e, t, n, r, i, a) {
724
- let o = a.window?.distance ?? .28, s = a.window?.crossAxis ?? .12, c = t.x + t.width / 2, l = t.y + t.height / 2;
725
- return e.filter((e) => {
726
- let a = e.bbox.x + e.bbox.width / 2, u = e.bbox.y + e.bbox.height / 2;
727
- 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;
728
- });
729
- }
730
- function q(e, t, n, r, i, a = "label") {
731
- let o = dt(e, n);
732
- if (!o) return [];
733
- let s = U(o), c = new Set(o), l = t.filter((e) => !c.has(e)), u = e.direction === "any" ? [
734
- "right",
735
- "below",
736
- "left",
737
- "above"
738
- ] : [e.direction], d;
739
- for (let t of u) {
740
- let n = W(ft(l, s, t, r, i, e));
741
- for (let t of n) {
742
- if (e.valuePattern && !new RegExp(e.valuePattern, e.patternFlags).test(t.text)) continue;
743
- 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);
744
- (!d || l < d.distance) && (d = {
745
- words: t.words,
746
- distance: l
747
- });
748
- }
749
- }
750
- if (!d) return [];
751
- let f = e.redactLabel ? [...o, ...d.words] : d.words;
752
- return [{
753
- ruleId: e.id,
754
- strategy: a,
755
- source: a === "template-anchor" ? "template" : "label",
756
- bbox: U(f),
757
- text: d.words.map((e) => e.text).join(" "),
758
- confidence: Math.max(0, K(d.words) * (1 - Math.min(.5, d.distance)))
759
- }];
760
- }
761
- var J = {
762
- person_name: [
763
- "LN",
764
- "FN",
765
- "DCS",
766
- "DAC",
767
- "DAD",
768
- "NAME"
769
- ],
770
- date_of_birth: [
771
- "DOB",
772
- "DBB",
773
- "BIRTH"
774
- ],
775
- address: [
776
- "ADDRESS",
777
- "ADDR",
778
- "DAG",
779
- "DAI"
780
- ],
781
- document_number: [
782
- "DLN",
783
- "DAQ",
784
- "IDNO",
785
- "LICNO"
786
- ],
787
- expiration_date: [
788
- "EXP",
789
- "DBA",
790
- "EXPIRES"
791
- ],
792
- postal_code: [
793
- "ZIP",
794
- "DAK",
795
- "POSTAL"
796
- ],
797
- state: ["STATE", "DAJ"]
798
- }, pt = new Set(Object.values(J).flat()), Y = /^(?:\d{2}[/-]\d{2}[/-]\d{2,4}|\d{4}[/-]\d{2}[/-]\d{2}|\d{6}|\d{8})$/, X = /\b(?:ST|STREET|AVE|AVENUE|RD|ROAD|BLVD|BOULEVARD|LN|LANE|DR|DRIVE|WAY|CT|COURT)\b/i, Z = /\b(?:DRIVER|LICENSE|IDENTIFICATION|CARD|CLASS|SEX|EYES|HEIGHT|RESTRICTIONS)\b/i;
799
- function Q(e, t) {
800
- let n = t.trim();
801
- return n ? e === "date_of_birth" || e === "expiration_date" ? Y.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) && !Z.test(n) : /\d/.test(n) && /[A-Z]/i.test(n) : !1;
802
- }
803
- function $(e, t, n, r, i = 1) {
804
- return {
805
- ruleId: e,
806
- strategy: "semantic",
807
- source: t,
808
- bbox: U(n),
809
- text: r ?? n.map((e) => e.text).join(" "),
810
- confidence: Math.max(0, Math.min(1, K(n) * i))
811
- };
812
- }
813
- function mt(e, t, n) {
814
- let r = J[e], i = [];
815
- for (let a of n) for (let n = 0; n < a.words.length; n += 1) {
816
- let o = a.words[n].text.toUpperCase().replace(/[^A-Z0-9]/g, ""), s = r.find((e) => o === e || o.startsWith(e));
817
- if (!s) continue;
818
- let c, l;
819
- o === s ? (c = a.words.slice(n + 1).filter((e) => !pt.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 && Q(e, l) && i.push($(t, "alias", c, l, .98));
820
- }
821
- return i;
822
- }
823
- function ht(e, t, n) {
824
- let r = n.filter((e) => {
825
- let t = e.text.replace(/\s/g, "");
826
- return t.includes("<<") || /^[A-Z0-9<]{25,}$/.test(t);
827
- });
828
- if (!r.length) return [];
829
- if (e === "person_name") {
830
- let e = r.find((e) => e.text.includes("<<"));
831
- if (!e) return [];
832
- 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();
833
- return a ? [$(t, "mrz", e.words, a, .96)] : [];
834
- }
835
- if (e === "date_of_birth") for (let e of r) {
836
- let n = e.text.replace(/\s/g, ""), r = /^\d{6}/.exec(n)?.[0] ?? /^.{13}(\d{6})/.exec(n)?.[1];
837
- if (r) return [$(t, "mrz", e.words, r, .96)];
838
- }
839
- if (e === "document_number") {
840
- let e = r[0];
841
- return [$(t, "mrz", e.words, e.text, .9)];
842
- }
843
- return [];
844
- }
845
- function gt(e) {
846
- let t = e.replace(/\s/g, ""), n = t.match(/\d{4}/)?.[0];
847
- if (n) return Number(n);
848
- let r = t.match(/^\d{2}/)?.[0];
849
- if (!r) return;
850
- let i = Number(r);
851
- return i > (/* @__PURE__ */ new Date()).getFullYear() % 100 ? 1900 + i : 2e3 + i;
852
- }
853
- function _t(e, t, n, r, i) {
854
- if (e === "address") {
855
- let e = r.findIndex((e) => /\d/.test(e.text) && X.test(e.text));
856
- if (e < 0) return [];
857
- let n = [...r[e].words], i = r[e + 1];
858
- return i && /(?:\b[A-Z]{2}\b.*\d{5}|\d{5})/i.test(i.text) && n.push(...i.words), [$(t, "layout", n, void 0, .76)];
859
- }
860
- if (e === "person_name") {
861
- let e = r.map((e) => {
862
- 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 && !Z.test(e.text) && !X.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);
863
- return {
864
- line: e,
865
- score: r ? .45 + K(e.words) * .3 + a * .15 + (n < .65 ? .1 : 0) : 0
866
- };
867
- }).filter((e) => e.score >= .68).sort((e, t) => t.score - e.score);
868
- return !e.length || e[1] && e[0].score - e[1].score < .04 ? [] : [$(t, "layout", e[0].line.words, void 0, e[0].score)];
869
- }
870
- if (e === "date_of_birth" || e === "expiration_date") {
871
- let r = (/* @__PURE__ */ new Date()).getFullYear(), i = n.filter((e) => Y.test(e.text.replace(/\s/g, ""))).map((e) => ({
872
- word: e,
873
- year: gt(e.text)
874
- })).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);
875
- return a.sort((t, n) => e === "date_of_birth" ? t.year - n.year : n.year - t.year), a.length ? [$(t, "layout", [a[0].word], void 0, .72)] : [];
876
- }
877
- if (e === "postal_code") {
878
- let r = n.find((t) => Q(e, t.text));
879
- return r ? [$(t, "layout", [r], void 0, .78)] : [];
880
- }
881
- if (e === "state") {
882
- let r = n.filter((t) => Q(e, t.text));
883
- return r.length === 1 ? [$(t, "layout", r, void 0, .7)] : [];
884
- }
885
- if (e === "document_number") {
886
- let r = n.filter((t) => Q(e, t.text));
887
- return r.sort((e, t) => t.text.length - e.text.length), r.length ? [$(t, "layout", [r[0]], void 0, .7)] : [];
888
- }
889
- return [];
890
- }
891
- function vt(e, t) {
892
- 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);
893
- }
894
- function yt(e, t, n, r) {
895
- let i = mt(e.field, e.id, n), a = ht(e.field, e.id, n);
896
- return i.length || a.length ? [...i, ...a] : _t(e.field, e.id, t, n, r);
897
- }
898
- function bt(e, t, n) {
899
- let r = (n ?? []).filter((t) => t.field === e.field).sort((e, t) => t.confidence - e.confidence);
900
- for (let n of r) {
901
- let r = t.filter((e) => vt(n.bbox, e.bbox) >= .3);
902
- if (!r.length) continue;
903
- let i = r.map((e) => e.text).join(" ");
904
- if (Q(e.field, i)) return $(e.id, "model", r, i, n.confidence);
905
- }
906
- }
907
- function xt(e, t, n, r, i, a) {
908
- let o = yt(e, t, n, r);
909
- if (e.detector !== "model" || !a) return o;
910
- let s = bt(e, t, i);
911
- return s ? [s] : [];
912
- }
913
- function St(e, t, n, r) {
914
- let i = (e) => Math.max(0, Math.min(1, e)), a = i(e.rect.x), o = i(e.rect.y);
915
- return {
916
- ruleId: `${t}.${e.id}`,
917
- strategy: "template-rect",
918
- source: "template",
919
- bbox: {
920
- x: a * n,
921
- y: o * r,
922
- width: Math.max(0, Math.min(1 - a, e.rect.width)) * n,
923
- height: Math.max(0, Math.min(1 - o, e.rect.height)) * r
924
- },
925
- confidence: 1
926
- };
927
- }
928
- function Ct(e, t) {
929
- let n = t.imageWidth ?? e?.imageWidth ?? 0, r = t.imageHeight ?? e?.imageHeight ?? 0, i = e?.words ?? [], a = W(i), o = [], s = [];
930
- for (let e of t.rules) {
931
- let c = e.strategy === "string" ? ut(e, a) : e.strategy === "label" ? q(e, i, a, n, r) : xt(e, i, a, r, t.semanticDetections, t.modelRequested === !0);
932
- c.length ? o.push(...c) : s.push(e.id);
933
- }
934
- for (let e of t.template?.fields ?? []) {
935
- let c = `${t.template.id}.${e.id}`;
936
- if (e.strategy === "rect") {
937
- n && r ? o.push(St(e, t.template.id, n, r)) : s.push(c);
938
- continue;
939
- }
940
- let l = q({
941
- ...e,
942
- id: c,
943
- strategy: "label"
944
- }, i, a, n, r, "template-anchor");
945
- l.length ? o.push(...l) : s.push(c);
946
- }
947
- let c = t.rules.length + (t.template?.fields.length ?? 0), l = new Set(o.map((e) => e.ruleId)), u = c ? [...l].reduce((e, t) => {
948
- let n = o.filter((e) => e.ruleId === t);
949
- return e + Math.max(...n.map((e) => e.confidence));
950
- }, 0) / c : 1;
951
- return {
952
- matches: o,
953
- unmatchedRuleIds: s,
954
- complete: s.length === 0,
955
- confidence: u
956
- };
957
- }
958
- function wt(e) {
959
- return e.rules.length > 0 || e.template?.fields.some((e) => e.strategy === "anchor") === !0;
960
- }
961
- function Tt(e, t = !1) {
962
- return t && !e.complete ? "unmatched" : e.complete ? "success" : "partial";
963
- }
964
- async function Et(e, t) {
965
- await v("redaction");
966
- let n = await b(e, { cloneCanvas: !1 }), r = t.ocr;
967
- wt(t) && !r && (r = await N(n, { includeWords: !0 }));
968
- let i = t.semanticDetections, a = t.modelRequested === !0, o = "not-requested", s;
969
- if (t.models?.fields) try {
970
- i = await lt(n, t.models.fields, t.models.fieldClasses, t.models.confidence, t.models.fieldLayout), a = !0, o = "loaded";
971
- } catch (e) {
972
- s = e instanceof Error ? e.message : "The field model could not load.";
973
- let n = t.models.allowHeuristicFallback !== !1;
974
- a = !n, o = n ? "fallback" : "failed";
975
- }
976
- let c = Ct(r, {
977
- rules: t.rules,
978
- template: t.template,
979
- imageWidth: n.width,
980
- imageHeight: n.height,
981
- semanticDetections: i,
982
- modelRequested: a
983
- }), l = Tt(c, t.requireAll), u = [], d = "not-requested", f;
984
- if (t.models?.face) try {
985
- u = await tt(n, t.models.face, t.models.faceConfidence), d = "loaded";
986
- } catch (e) {
987
- f = e instanceof Error ? e.message : "The face model could not load.", d = "failed";
988
- }
989
- if (l === "unmatched") return {
990
- ...c,
991
- status: l,
992
- ocr: r,
993
- modelStatus: o,
994
- modelError: s,
995
- faces: u,
996
- faceStatus: d,
997
- faceError: f
998
- };
999
- let p = await P(n, [...c.matches.map((e) => ({
1000
- ...e.bbox,
1001
- mode: t.style?.mode
1002
- })), ...u.map((e) => ({
1003
- ...e.bbox,
1004
- mode: t.style?.mode
1005
- }))], t.style);
1006
- return {
1007
- ...c,
1008
- status: l,
1009
- ocr: r,
1010
- canvas: p.canvas,
1011
- blob: p.blob,
1012
- modelStatus: o,
1013
- modelError: s,
1014
- faces: u,
1015
- faceStatus: d,
1016
- faceError: f
1017
- };
1018
- }
1019
- //#endregion
1020
- export { xe as AutoTorchController, re as DEFAULT_DOCUMENT_MODEL_URL, Ce as DEV_LICENSE_HOSTS, t as LicenseError, h as NEAR_BLACK_LUMINANCE, _e as QuadStabilityTracker, n as STILL_MAX_EDGE, y as ScannerError, P as applyRedactions, v as assertLicense, fe as autoCaptureControl, be as captureVideoFrame, Ee as createFinderSimulator, ie as cropDocument, g as detectBrowserEngine, me as detectDocument, i as formatCaptureDiagnosticsReport, s as getLicense, r as hasTransientUserActivation, f as isAndroidBrowser, le as isNearBlackFrame, he as limitingFillTarget, we as mapDocumentCornersToFrame, Ct as matchRedactionRules, e as meanFrameLuminance, se as measureQuadFill, ce as mobileCameraConstraints, u as pickNativeCameraStill, N as recognizeText, Et as redactProgrammatically, de as resolveDocumentModelUrl, oe as scanDocument, ae as scanSystemCameraStill, te as selectFinderGuidance, pe as selectFinderHint, _ as setLicenseKey, d as shouldPreferWebGpuForDocumentModel, p as shouldUseSystemCameraCapture, Te as simulatorQuad, a as startCamera, ge as startFinder, m as subscribeModelDownloads, ee as systemCameraFindMessage, c as torchControl };
113
+ export { r as AutoTorchController, T as DEFAULT_DOCUMENT_MODEL_URL, b as DEV_LICENSE_HOSTS, o as LicenseError, ee as NEAR_BLACK_LUMINANCE, L as QuadStabilityTracker, N as STILL_MAX_EDGE, S as ScannerError, B as applyRedactions, u as assertLicense, P as autoCaptureControl, e as captureVideoFrame, ne as createFinderSimulator, G as cropDocument, H as decodePdf417, M as detectBrowserEngine, g as detectDocument, V as driverLicenseFieldsFromOcr, F as driverLicensePrompt, f as formatCaptureDiagnosticsReport, R as getLicense, p as hasTransientUserActivation, m as isAndroidBrowser, a as isNearBlackFrame, A as limitingFillTarget, Y as mapDocumentCornersToFrame, w as matchRedactionRules, c as meanFrameLuminance, k as measureQuadFill, z as mergeDriverLicenseFields, d as mobileCameraConstraints, E as parseAamvaDate, te as parseAamvaPayload, D as pdf417BarcodeDetectorSupported, h as pickNativeCameraStill, O as recognizeText, I as redactProgrammatically, n as resolveDocumentModelUrl, W as scanDocument, _ as scanSystemCameraStill, C as selectFinderGuidance, U as selectFinderHint, l as setLicenseKey, q as shouldPreferWebGpuForDocumentModel, t as shouldUseSystemCameraCapture, Q as simulatorQuad, y as startCamera, j as startDriverLicenseSession, K as startFinder, v as subscribeModelDownloads, i as systemCameraFindMessage, s as torchControl };
1021
114
 
1022
115
  //# sourceMappingURL=scanner-sdk.js.map