@exige/web-scanner-sdk 0.2.27 → 0.2.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/assets/document-worker.js +1 -1
- package/dist/assets/document-worker.js.map +1 -1
- package/dist/{finder-BlN89ZeT.js → finder-BvBpdbHa.js} +476 -453
- package/dist/finder-BvBpdbHa.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/react/types.d.ts +5 -0
- package/dist/react.js +48 -48
- package/dist/scanner-sdk.js +243 -243
- package/dist/scanner-sdk.js.map +1 -1
- package/dist/sdk/camera.d.ts +8 -1
- package/dist/sdk/finder.d.ts +21 -1
- package/dist/sdk/ort-runtime.d.ts +2 -1
- package/dist/sdk/scan.d.ts +5 -0
- package/package.json +1 -1
- package/dist/finder-BlN89ZeT.js.map +0 -1
package/dist/scanner-sdk.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { A as e, B as t, C as n, D as r, E as i, F as a,
|
|
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";
|
|
2
2
|
//#region src/sdk/frame-geometry.ts
|
|
3
|
-
function
|
|
3
|
+
function x(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,
|
|
@@ -9,15 +9,15 @@ function b(e, t, n) {
|
|
|
9
9
|
}
|
|
10
10
|
function we(e, t, n) {
|
|
11
11
|
return {
|
|
12
|
-
topLeft:
|
|
13
|
-
topRight:
|
|
14
|
-
bottomRight:
|
|
15
|
-
bottomLeft:
|
|
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)
|
|
16
16
|
};
|
|
17
17
|
}
|
|
18
18
|
//#endregion
|
|
19
19
|
//#region src/sdk/finder-simulator.ts
|
|
20
|
-
function
|
|
20
|
+
function S(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,7 +50,7 @@ function x(e, t = 960, n = 600) {
|
|
|
50
50
|
phase: "settled"
|
|
51
51
|
};
|
|
52
52
|
}
|
|
53
|
-
function
|
|
53
|
+
function C(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,
|
|
@@ -58,7 +58,7 @@ function S(e, t, n) {
|
|
|
58
58
|
};
|
|
59
59
|
}
|
|
60
60
|
function Te(e) {
|
|
61
|
-
let t =
|
|
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);
|
|
62
62
|
return {
|
|
63
63
|
topLeft: t,
|
|
64
64
|
topRight: n,
|
|
@@ -84,9 +84,9 @@ function Te(e) {
|
|
|
84
84
|
}
|
|
85
85
|
};
|
|
86
86
|
}
|
|
87
|
-
function
|
|
87
|
+
function w(e, t) {
|
|
88
88
|
let n = e.getContext("2d");
|
|
89
|
-
if (!n) throw
|
|
89
|
+
if (!n) throw o();
|
|
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;
|
|
@@ -95,9 +95,9 @@ function C(e, t) {
|
|
|
95
95
|
function Ee(e) {
|
|
96
96
|
e.width ||= 960, e.height ||= 600;
|
|
97
97
|
let t = !1, n = 0, r = 0, i = (a) => {
|
|
98
|
-
t && (n ||= a,
|
|
98
|
+
t && (n ||= a, w(e, S(a - n, e.width, e.height)), r = requestAnimationFrame(i));
|
|
99
99
|
}, a = () => {
|
|
100
|
-
n = 0,
|
|
100
|
+
n = 0, w(e, S(0, e.width, e.height));
|
|
101
101
|
};
|
|
102
102
|
return a(), {
|
|
103
103
|
start() {
|
|
@@ -112,7 +112,7 @@ function Ee(e) {
|
|
|
112
112
|
//#endregion
|
|
113
113
|
//#region src/sdk/ocr-runtime.ts
|
|
114
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
|
|
115
|
+
function T(e) {
|
|
116
116
|
try {
|
|
117
117
|
return typeof WebAssembly < "u" && WebAssembly.validate(e);
|
|
118
118
|
} catch {
|
|
@@ -121,8 +121,8 @@ function w(e) {
|
|
|
121
121
|
}
|
|
122
122
|
function Pe() {
|
|
123
123
|
return {
|
|
124
|
-
relaxedSimd:
|
|
125
|
-
simd:
|
|
124
|
+
relaxedSimd: T(Me),
|
|
125
|
+
simd: T(Ne)
|
|
126
126
|
};
|
|
127
127
|
}
|
|
128
128
|
function Fe(e) {
|
|
@@ -139,7 +139,7 @@ function Ie(e, t) {
|
|
|
139
139
|
kind: "bundled-eng",
|
|
140
140
|
language: "eng"
|
|
141
141
|
};
|
|
142
|
-
throw new
|
|
142
|
+
throw new y("language", `OCR language "${n}" is not packaged. Pass langPath, a directory URL that contains ${n}.traineddata.gz.`);
|
|
143
143
|
}
|
|
144
144
|
function Le(e = je) {
|
|
145
145
|
let t = e.href, n = t.lastIndexOf("/");
|
|
@@ -154,7 +154,7 @@ async function ze(e, t, n) {
|
|
|
154
154
|
if (a) return;
|
|
155
155
|
a = !0;
|
|
156
156
|
let t = e instanceof Error ? e.message : String(e);
|
|
157
|
-
i(new
|
|
157
|
+
i(new y("worker", `OCR worker failed to start (${t}).`));
|
|
158
158
|
};
|
|
159
159
|
e(t, void 0, {
|
|
160
160
|
workerPath: n.workerPath,
|
|
@@ -174,7 +174,7 @@ async function ze(e, t, n) {
|
|
|
174
174
|
}
|
|
175
175
|
//#endregion
|
|
176
176
|
//#region src/sdk/ocr.ts
|
|
177
|
-
function
|
|
177
|
+
function E(e, t = 1, n = 1, r = 0, i = 0) {
|
|
178
178
|
return {
|
|
179
179
|
text: e.text,
|
|
180
180
|
confidence: Math.max(0, Math.min(1, e.confidence / 100)),
|
|
@@ -186,7 +186,7 @@ function T(e, t = 1, n = 1, r = 0, i = 0) {
|
|
|
186
186
|
}
|
|
187
187
|
};
|
|
188
188
|
}
|
|
189
|
-
function
|
|
189
|
+
function D(e = .5) {
|
|
190
190
|
if (!Number.isFinite(e) || e < 0 || e > 1) throw RangeError("OCR minConfidence must be between 0 and 1.");
|
|
191
191
|
return e;
|
|
192
192
|
}
|
|
@@ -194,12 +194,12 @@ function Be(e, t) {
|
|
|
194
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
195
|
return s > 0 ? o / s : 0;
|
|
196
196
|
}
|
|
197
|
-
function
|
|
197
|
+
function O(e) {
|
|
198
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
199
|
for (let e of t) n.some((t) => Be(t, e) >= .65) || n.push(e);
|
|
200
200
|
return n;
|
|
201
201
|
}
|
|
202
|
-
function
|
|
202
|
+
function k(e, t, n, r, i) {
|
|
203
203
|
let a = e.text.trim();
|
|
204
204
|
if (!a || !/[\p{L}\p{N}]/u.test(a)) return !1;
|
|
205
205
|
let o = e.bbox.width * e.bbox.height / Math.max(1, n * r), s = e.bbox.width / Math.max(1, e.bbox.height);
|
|
@@ -226,20 +226,20 @@ function Ve(e) {
|
|
|
226
226
|
}
|
|
227
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
228
|
}
|
|
229
|
-
function
|
|
230
|
-
let i =
|
|
229
|
+
function A(e, t, n, r) {
|
|
230
|
+
let i = D(t.minConfidence), a = [], o = [], s = 1, c = 1;
|
|
231
231
|
for (let t of e) {
|
|
232
232
|
let e = t.scaleX ?? 1, n = t.scaleY ?? 1, r = t.offsetX ?? 0, l = t.offsetY ?? 0;
|
|
233
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 =
|
|
234
|
+
let u = E(t, e, n, r, l);
|
|
235
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
236
|
for (let a of t.symbols) {
|
|
237
|
-
let t =
|
|
237
|
+
let t = E(a, e, n, r, l);
|
|
238
238
|
t.confidence >= i && o.push(t);
|
|
239
239
|
}
|
|
240
240
|
}
|
|
241
241
|
}
|
|
242
|
-
let l = n?.width ?? s, u = n?.height ?? c, d =
|
|
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
243
|
return {
|
|
244
244
|
text: Ve(d),
|
|
245
245
|
confidence: d.length ? d.reduce((e, t) => e + t.confidence, 0) / d.length : 0,
|
|
@@ -247,9 +247,9 @@ function k(e, t, n, r) {
|
|
|
247
247
|
characters: t.includeCharacters ? f : []
|
|
248
248
|
};
|
|
249
249
|
}
|
|
250
|
-
function
|
|
250
|
+
function j(e) {
|
|
251
251
|
let t = e.getContext("2d", { willReadFrequently: !0 });
|
|
252
|
-
if (!t) throw
|
|
252
|
+
if (!t) throw o();
|
|
253
253
|
let n = t.getImageData(0, 0, e.width, e.height), r = new Uint8Array(e.width * e.height);
|
|
254
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
255
|
return {
|
|
@@ -269,7 +269,7 @@ function He(e) {
|
|
|
269
269
|
areaRatio: 0
|
|
270
270
|
};
|
|
271
271
|
n.drawImage(e, 0, 0, t.width, t.height);
|
|
272
|
-
let { luminance: r } =
|
|
272
|
+
let { luminance: r } = j(t);
|
|
273
273
|
return ue(r, t.width, t.height);
|
|
274
274
|
}
|
|
275
275
|
function Ue(e, t, n, r) {
|
|
@@ -315,23 +315,23 @@ function Je(e, t, n, r) {
|
|
|
315
315
|
}
|
|
316
316
|
};
|
|
317
317
|
}
|
|
318
|
-
function
|
|
318
|
+
function M(e, t) {
|
|
319
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
320
|
}
|
|
321
321
|
function Ye(e) {
|
|
322
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
323
|
i.width = Math.max(1, Math.round(e.width * r)), i.height = Math.max(1, Math.round(e.height * r));
|
|
324
324
|
let a = i.getContext("2d", { willReadFrequently: !0 });
|
|
325
|
-
if (!a) throw
|
|
325
|
+
if (!a) throw o();
|
|
326
326
|
a.drawImage(e, 0, 0, i.width, i.height);
|
|
327
|
-
let { image:
|
|
328
|
-
|
|
329
|
-
let
|
|
330
|
-
if (!
|
|
331
|
-
let
|
|
332
|
-
return
|
|
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
333
|
sparseCanvas: i,
|
|
334
|
-
flattenedCanvas:
|
|
334
|
+
flattenedCanvas: d
|
|
335
335
|
};
|
|
336
336
|
}
|
|
337
337
|
function Xe(e) {
|
|
@@ -352,122 +352,122 @@ function Xe(e) {
|
|
|
352
352
|
return l / s.length;
|
|
353
353
|
};
|
|
354
354
|
}
|
|
355
|
-
async function
|
|
356
|
-
await
|
|
357
|
-
let
|
|
358
|
-
|
|
359
|
-
let
|
|
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
360
|
strong: !1,
|
|
361
361
|
strength: 0,
|
|
362
362
|
darkness: 0,
|
|
363
363
|
areaRatio: 0
|
|
364
|
-
} : He(
|
|
364
|
+
} : He(i), { createWorker: c, PSM: l } = await import("tesseract.js"), u = 0, d = s.strong ? 3 : 2, f = await ze(c, r, {
|
|
365
365
|
workerPath: De.href,
|
|
366
366
|
corePath: Fe(Pe()).href,
|
|
367
|
-
langPath: Re(
|
|
367
|
+
langPath: Re(n),
|
|
368
368
|
logger(e) {
|
|
369
|
-
typeof e.progress == "number" &&
|
|
369
|
+
typeof e.progress == "number" && t.onProgress?.(Math.min(1, (u + e.progress) / d), e.status ?? "recognizing text");
|
|
370
370
|
}
|
|
371
371
|
});
|
|
372
372
|
try {
|
|
373
|
-
await
|
|
374
|
-
let e = await
|
|
373
|
+
await f.setParameters({ tessedit_pageseg_mode: l.AUTO });
|
|
374
|
+
let e = await f.recognize(i, {}, {
|
|
375
375
|
text: !0,
|
|
376
376
|
blocks: !0
|
|
377
377
|
});
|
|
378
|
-
|
|
379
|
-
tessedit_pageseg_mode:
|
|
378
|
+
u = 1, await f.setParameters({
|
|
379
|
+
tessedit_pageseg_mode: l.SPARSE_TEXT,
|
|
380
380
|
preserve_interword_spaces: "1"
|
|
381
381
|
});
|
|
382
|
-
let
|
|
382
|
+
let n = await f.recognize(a, {}, {
|
|
383
383
|
text: !0,
|
|
384
384
|
blocks: !0
|
|
385
|
-
}),
|
|
386
|
-
blocks:
|
|
387
|
-
scaleX:
|
|
388
|
-
scaleY:
|
|
389
|
-
}],
|
|
390
|
-
...
|
|
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
391
|
includeWords: !0
|
|
392
|
-
},
|
|
393
|
-
width:
|
|
394
|
-
height:
|
|
395
|
-
},
|
|
396
|
-
width:
|
|
397
|
-
height:
|
|
398
|
-
},
|
|
399
|
-
if (h &&
|
|
400
|
-
|
|
401
|
-
let { tile: e, passMapping: t } = Je(
|
|
402
|
-
await
|
|
403
|
-
tessedit_pageseg_mode:
|
|
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
404
|
preserve_interword_spaces: "1"
|
|
405
405
|
});
|
|
406
|
-
let n = await
|
|
406
|
+
let n = await f.recognize(e, {}, {
|
|
407
407
|
text: !0,
|
|
408
408
|
blocks: !0
|
|
409
409
|
});
|
|
410
|
-
|
|
410
|
+
c.push({
|
|
411
411
|
blocks: n.data.blocks,
|
|
412
412
|
...t
|
|
413
413
|
});
|
|
414
414
|
}
|
|
415
|
-
let g =
|
|
416
|
-
width:
|
|
417
|
-
height:
|
|
418
|
-
},
|
|
419
|
-
return
|
|
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
420
|
text: g.text,
|
|
421
421
|
confidence: g.confidence,
|
|
422
|
-
language:
|
|
423
|
-
imageWidth:
|
|
424
|
-
imageHeight:
|
|
422
|
+
language: r,
|
|
423
|
+
imageWidth: i.width,
|
|
424
|
+
imageHeight: i.height,
|
|
425
425
|
diagnostics: {
|
|
426
426
|
shadowPassUsed: h,
|
|
427
|
-
castShadowStrength:
|
|
428
|
-
shadowRegion:
|
|
429
|
-
x:
|
|
430
|
-
y:
|
|
431
|
-
width:
|
|
432
|
-
height:
|
|
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
433
|
} : void 0
|
|
434
434
|
},
|
|
435
|
-
...
|
|
436
|
-
...
|
|
435
|
+
...t.includeWords ? { words: g.words } : {},
|
|
436
|
+
...t.includeCharacters ? { characters: g.characters } : {}
|
|
437
437
|
};
|
|
438
438
|
} finally {
|
|
439
|
-
await
|
|
439
|
+
await f.terminate();
|
|
440
440
|
}
|
|
441
441
|
}
|
|
442
442
|
//#endregion
|
|
443
443
|
//#region src/sdk/redact.ts
|
|
444
|
-
async function
|
|
445
|
-
await
|
|
446
|
-
let
|
|
447
|
-
if (!
|
|
448
|
-
for (let e of
|
|
449
|
-
let t =
|
|
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
450
|
if (t.width < 1 || t.height < 1) continue;
|
|
451
|
-
if ((e.mode ??
|
|
452
|
-
|
|
451
|
+
if ((e.mode ?? n.mode ?? "blackout") === "blackout") {
|
|
452
|
+
i.fillStyle = "#050706", i.fillRect(t.x, t.y, t.width, t.height);
|
|
453
453
|
continue;
|
|
454
454
|
}
|
|
455
|
-
let
|
|
456
|
-
|
|
457
|
-
let
|
|
458
|
-
if (!
|
|
459
|
-
|
|
460
|
-
let s = Math.max(12,
|
|
461
|
-
|
|
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
462
|
}
|
|
463
463
|
return {
|
|
464
|
-
canvas:
|
|
465
|
-
blob: await
|
|
464
|
+
canvas: r,
|
|
465
|
+
blob: await ye(r, n.mimeType ?? "image/png", n.quality)
|
|
466
466
|
};
|
|
467
467
|
}
|
|
468
468
|
//#endregion
|
|
469
469
|
//#region src/sdk/face-model.ts
|
|
470
|
-
var
|
|
470
|
+
var F = /* @__PURE__ */ new Map(), Ze = 8400;
|
|
471
471
|
function Qe(e, t) {
|
|
472
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
473
|
return n / Math.max(1, e.width * e.height + t.width * t.height - n);
|
|
@@ -494,18 +494,18 @@ function et(e, t, n) {
|
|
|
494
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
495
|
}
|
|
496
496
|
async function tt(e, t, n = .35) {
|
|
497
|
-
let r = await
|
|
498
|
-
|
|
499
|
-
let s =
|
|
500
|
-
if (!s) throw
|
|
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
501
|
s.drawImage(r, 0, 0, 640, 640);
|
|
502
502
|
let c = s.getImageData(0, 0, 640, 640).data, l = 409600, u = new Float32Array(l * 3);
|
|
503
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 =
|
|
504
|
+
let d = F.get(t);
|
|
505
505
|
d || (d = i.InferenceSession.create(t, {
|
|
506
506
|
executionProviders: ["wasm"],
|
|
507
507
|
graphOptimizationLevel: "all"
|
|
508
|
-
}),
|
|
508
|
+
}), F.set(t, d));
|
|
509
509
|
let f = await d, p = (await f.run({ [f.inputNames[0]]: new i.Tensor("float32", u, [
|
|
510
510
|
1,
|
|
511
511
|
3,
|
|
@@ -521,7 +521,7 @@ async function tt(e, t, n = .35) {
|
|
|
521
521
|
}
|
|
522
522
|
//#endregion
|
|
523
523
|
//#region src/sdk/field-model.ts
|
|
524
|
-
var
|
|
524
|
+
var I = /* @__PURE__ */ new Map(), L = [
|
|
525
525
|
"person_name",
|
|
526
526
|
"date_of_birth",
|
|
527
527
|
"address",
|
|
@@ -530,18 +530,18 @@ var F = /* @__PURE__ */ new Map(), I = [
|
|
|
530
530
|
"postal_code",
|
|
531
531
|
"state"
|
|
532
532
|
], nt = 8400;
|
|
533
|
-
function
|
|
533
|
+
function R(e) {
|
|
534
534
|
return 5 + e;
|
|
535
535
|
}
|
|
536
|
-
var
|
|
536
|
+
var z = 640;
|
|
537
537
|
function rt(e, t) {
|
|
538
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
539
|
return n / Math.max(1, e.bbox.width * e.bbox.height + t.bbox.width * t.bbox.height - n);
|
|
540
540
|
}
|
|
541
|
-
function
|
|
541
|
+
function B(e) {
|
|
542
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
543
|
}
|
|
544
|
-
function
|
|
544
|
+
function V(e, t, n, r, i, a, o) {
|
|
545
545
|
return {
|
|
546
546
|
x: (e - n / 2) / i * a,
|
|
547
547
|
y: (t - r / 2) / i * o,
|
|
@@ -549,8 +549,8 @@ function B(e, t, n, r, i, a, o) {
|
|
|
549
549
|
height: r / i * o
|
|
550
550
|
};
|
|
551
551
|
}
|
|
552
|
-
function
|
|
553
|
-
let n =
|
|
552
|
+
function H(e, t) {
|
|
553
|
+
let n = R(t);
|
|
554
554
|
return e.length === 3 && e[0] === 1 && e[2] === n && e[1] > e[2] ? {
|
|
555
555
|
anchors: e[1],
|
|
556
556
|
features: n
|
|
@@ -563,7 +563,7 @@ function it(e) {
|
|
|
563
563
|
return e.length === 3 && e[1] >= 5 && e[2] >= 1;
|
|
564
564
|
}
|
|
565
565
|
function at(e) {
|
|
566
|
-
let t =
|
|
566
|
+
let t = R(e);
|
|
567
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
568
|
}
|
|
569
569
|
function ot(e, t, n, r, i, a, o) {
|
|
@@ -579,13 +579,13 @@ function ot(e, t, n, r, i, a, o) {
|
|
|
579
579
|
!f || u < r || l.push({
|
|
580
580
|
field: f,
|
|
581
581
|
confidence: u,
|
|
582
|
-
bbox:
|
|
582
|
+
bbox: V(e[t], e[c + t], e[c * 2 + t], e[c * 3 + t], i, a, o)
|
|
583
583
|
});
|
|
584
584
|
}
|
|
585
|
-
return
|
|
585
|
+
return B(l);
|
|
586
586
|
}
|
|
587
587
|
function st(e, t, n, r, i, a, o) {
|
|
588
|
-
let s =
|
|
588
|
+
let s = H(t, n.length);
|
|
589
589
|
if (!s) throw at(n.length);
|
|
590
590
|
let c = [];
|
|
591
591
|
for (let t = 0; t < s.anchors; t += 1) {
|
|
@@ -598,54 +598,54 @@ function st(e, t, n, r, i, a, o) {
|
|
|
598
598
|
!p || m < r || c.push({
|
|
599
599
|
field: p,
|
|
600
600
|
confidence: m,
|
|
601
|
-
bbox:
|
|
601
|
+
bbox: V(e[l], e[l + 1], e[l + 2], e[l + 3], i, a, o)
|
|
602
602
|
});
|
|
603
603
|
}
|
|
604
|
-
return
|
|
604
|
+
return B(c);
|
|
605
605
|
}
|
|
606
606
|
function ct(e, t, n) {
|
|
607
|
-
let r = n.classes ??
|
|
607
|
+
let r = n.classes ?? L, i = n.confidence ?? .35, a = n.inputSize ?? z, o = H(t, r.length);
|
|
608
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
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
610
|
}
|
|
611
|
-
async function lt(e, t, n =
|
|
612
|
-
let
|
|
613
|
-
u.width =
|
|
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
614
|
let d = u.getContext("2d", { willReadFrequently: !0 });
|
|
615
|
-
if (!d) throw
|
|
616
|
-
d.drawImage(
|
|
617
|
-
let f = d.getImageData(0, 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
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 =
|
|
619
|
+
let h = I.get(t);
|
|
620
620
|
h || (h = (async () => {
|
|
621
621
|
try {
|
|
622
|
-
let [e, n] = await Promise.all([
|
|
622
|
+
let [e, n] = await Promise.all([s, l(t)]);
|
|
623
623
|
return await e.InferenceSession.create(n, {
|
|
624
624
|
executionProviders: ["wasm"],
|
|
625
625
|
graphOptimizationLevel: "all"
|
|
626
626
|
});
|
|
627
627
|
} catch (e) {
|
|
628
|
-
throw
|
|
628
|
+
throw I.delete(t), e;
|
|
629
629
|
}
|
|
630
|
-
})(),
|
|
631
|
-
let [g, _] = await Promise.all([
|
|
630
|
+
})(), I.set(t, h));
|
|
631
|
+
let [g, _] = await Promise.all([s, h]), v = (await _.run({ [_.inputNames[0]]: new g.Tensor("float32", m, [
|
|
632
632
|
1,
|
|
633
633
|
3,
|
|
634
|
-
|
|
635
|
-
|
|
634
|
+
c,
|
|
635
|
+
c
|
|
636
636
|
]) }))[_.outputNames[0]];
|
|
637
|
-
return ct(
|
|
637
|
+
return ct(v.data, v.dims.map(Number), {
|
|
638
638
|
classes: n,
|
|
639
639
|
confidence: r,
|
|
640
640
|
layout: i,
|
|
641
|
-
imageWidth:
|
|
642
|
-
imageHeight:
|
|
643
|
-
inputSize:
|
|
641
|
+
imageWidth: a.width,
|
|
642
|
+
imageHeight: a.height,
|
|
643
|
+
inputSize: c
|
|
644
644
|
});
|
|
645
645
|
}
|
|
646
646
|
//#endregion
|
|
647
647
|
//#region src/sdk/programmatic-redaction.ts
|
|
648
|
-
function
|
|
648
|
+
function U(e) {
|
|
649
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
650
|
return {
|
|
651
651
|
x: t,
|
|
@@ -654,11 +654,11 @@ function H(e) {
|
|
|
654
654
|
height: i - n
|
|
655
655
|
};
|
|
656
656
|
}
|
|
657
|
-
function
|
|
657
|
+
function W(e) {
|
|
658
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
659
|
for (let e of n) {
|
|
660
660
|
let n = e.bbox.y + e.bbox.height / 2, r = t.find((t) => {
|
|
661
|
-
let r =
|
|
661
|
+
let r = U(t), i = r.y + r.height / 2;
|
|
662
662
|
return Math.abs(n - i) <= Math.max(e.bbox.height, r.height) * .65;
|
|
663
663
|
});
|
|
664
664
|
r ? r.push(e) : t.push([e]);
|
|
@@ -666,14 +666,14 @@ function U(e) {
|
|
|
666
666
|
return t.map((e) => (e.sort((e, t) => e.bbox.x - t.bbox.x), {
|
|
667
667
|
words: e,
|
|
668
668
|
text: e.map((e) => e.text).join(" "),
|
|
669
|
-
bbox:
|
|
669
|
+
bbox: U(e)
|
|
670
670
|
}));
|
|
671
671
|
}
|
|
672
|
-
function
|
|
672
|
+
function G(e, t, n = !1) {
|
|
673
673
|
let r = e.trim().replace(/\s+/g, " "), i = n ? r.replace(/[::]\s*$/, "") : r;
|
|
674
674
|
return t ? i.toLocaleLowerCase() : i;
|
|
675
675
|
}
|
|
676
|
-
function
|
|
676
|
+
function K(e) {
|
|
677
677
|
return e.reduce((e, t) => e + t.confidence, 0) / Math.max(1, e.length);
|
|
678
678
|
}
|
|
679
679
|
function ut(e, t) {
|
|
@@ -687,14 +687,14 @@ function ut(e, t) {
|
|
|
687
687
|
ruleId: e.id,
|
|
688
688
|
strategy: "string",
|
|
689
689
|
source: "string",
|
|
690
|
-
bbox:
|
|
690
|
+
bbox: U(t),
|
|
691
691
|
text: t.map((e) => e.text).join(" "),
|
|
692
|
-
confidence:
|
|
692
|
+
confidence: K(t)
|
|
693
693
|
});
|
|
694
694
|
if (i === "word") {
|
|
695
695
|
for (let e of t) for (let t of e.words) {
|
|
696
|
-
let e =
|
|
697
|
-
(a ? a.test(t.text) : o.some((t) => e ===
|
|
696
|
+
let e = G(t.text, r);
|
|
697
|
+
(a ? a.test(t.text) : o.some((t) => e === G(t, r))) && c([t]);
|
|
698
698
|
}
|
|
699
699
|
return s;
|
|
700
700
|
}
|
|
@@ -704,20 +704,20 @@ function ut(e, t) {
|
|
|
704
704
|
continue;
|
|
705
705
|
}
|
|
706
706
|
for (let t of o) {
|
|
707
|
-
let n =
|
|
707
|
+
let n = G(t, r).split(" ");
|
|
708
708
|
for (let t = 0; t <= e.words.length - n.length; t += 1) {
|
|
709
709
|
let i = e.words.slice(t, t + n.length);
|
|
710
|
-
i.every((e, t) =>
|
|
710
|
+
i.every((e, t) => G(e.text, r) === n[t]) && c(i);
|
|
711
711
|
}
|
|
712
712
|
}
|
|
713
713
|
}
|
|
714
714
|
return s;
|
|
715
715
|
}
|
|
716
716
|
function dt(e, t) {
|
|
717
|
-
let n = e.labelMode !== "exact", r =
|
|
717
|
+
let n = e.labelMode !== "exact", r = G(e.label, n, !0).split(" ");
|
|
718
718
|
for (let e of t) for (let t = 0; t <= e.words.length - r.length; t += 1) {
|
|
719
719
|
let i = e.words.slice(t, t + r.length);
|
|
720
|
-
if (i.every((e, t) =>
|
|
720
|
+
if (i.every((e, t) => G(e.text, n, !0) === r[t])) return i;
|
|
721
721
|
}
|
|
722
722
|
}
|
|
723
723
|
function ft(e, t, n, r, i, a) {
|
|
@@ -727,17 +727,17 @@ function ft(e, t, n, r, i, a) {
|
|
|
727
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
728
|
});
|
|
729
729
|
}
|
|
730
|
-
function
|
|
730
|
+
function q(e, t, n, r, i, a = "label") {
|
|
731
731
|
let o = dt(e, n);
|
|
732
732
|
if (!o) return [];
|
|
733
|
-
let s =
|
|
733
|
+
let s = U(o), c = new Set(o), l = t.filter((e) => !c.has(e)), u = e.direction === "any" ? [
|
|
734
734
|
"right",
|
|
735
735
|
"below",
|
|
736
736
|
"left",
|
|
737
737
|
"above"
|
|
738
738
|
] : [e.direction], d;
|
|
739
739
|
for (let t of u) {
|
|
740
|
-
let n =
|
|
740
|
+
let n = W(ft(l, s, t, r, i, e));
|
|
741
741
|
for (let t of n) {
|
|
742
742
|
if (e.valuePattern && !new RegExp(e.valuePattern, e.patternFlags).test(t.text)) continue;
|
|
743
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);
|
|
@@ -753,12 +753,12 @@ function K(e, t, n, r, i, a = "label") {
|
|
|
753
753
|
ruleId: e.id,
|
|
754
754
|
strategy: a,
|
|
755
755
|
source: a === "template-anchor" ? "template" : "label",
|
|
756
|
-
bbox:
|
|
756
|
+
bbox: U(f),
|
|
757
757
|
text: d.words.map((e) => e.text).join(" "),
|
|
758
|
-
confidence: Math.max(0,
|
|
758
|
+
confidence: Math.max(0, K(d.words) * (1 - Math.min(.5, d.distance)))
|
|
759
759
|
}];
|
|
760
760
|
}
|
|
761
|
-
var
|
|
761
|
+
var J = {
|
|
762
762
|
person_name: [
|
|
763
763
|
"LN",
|
|
764
764
|
"FN",
|
|
@@ -795,28 +795,28 @@ var q = {
|
|
|
795
795
|
"POSTAL"
|
|
796
796
|
],
|
|
797
797
|
state: ["STATE", "DAJ"]
|
|
798
|
-
}, pt = new Set(Object.values(
|
|
799
|
-
function
|
|
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
800
|
let n = t.trim();
|
|
801
|
-
return n ? e === "date_of_birth" || e === "expiration_date" ?
|
|
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
802
|
}
|
|
803
|
-
function
|
|
803
|
+
function $(e, t, n, r, i = 1) {
|
|
804
804
|
return {
|
|
805
805
|
ruleId: e,
|
|
806
806
|
strategy: "semantic",
|
|
807
807
|
source: t,
|
|
808
|
-
bbox:
|
|
808
|
+
bbox: U(n),
|
|
809
809
|
text: r ?? n.map((e) => e.text).join(" "),
|
|
810
|
-
confidence: Math.max(0, Math.min(1,
|
|
810
|
+
confidence: Math.max(0, Math.min(1, K(n) * i))
|
|
811
811
|
};
|
|
812
812
|
}
|
|
813
813
|
function mt(e, t, n) {
|
|
814
|
-
let r =
|
|
814
|
+
let r = J[e], i = [];
|
|
815
815
|
for (let a of n) for (let n = 0; n < a.words.length; n += 1) {
|
|
816
816
|
let o = a.words[n].text.toUpperCase().replace(/[^A-Z0-9]/g, ""), s = r.find((e) => o === e || o.startsWith(e));
|
|
817
817
|
if (!s) continue;
|
|
818
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 &&
|
|
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
820
|
}
|
|
821
821
|
return i;
|
|
822
822
|
}
|
|
@@ -830,15 +830,15 @@ function ht(e, t, n) {
|
|
|
830
830
|
let e = r.find((e) => e.text.includes("<<"));
|
|
831
831
|
if (!e) return [];
|
|
832
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 ? [
|
|
833
|
+
return a ? [$(t, "mrz", e.words, a, .96)] : [];
|
|
834
834
|
}
|
|
835
835
|
if (e === "date_of_birth") for (let e of r) {
|
|
836
836
|
let n = e.text.replace(/\s/g, ""), r = /^\d{6}/.exec(n)?.[0] ?? /^.{13}(\d{6})/.exec(n)?.[1];
|
|
837
|
-
if (r) return [
|
|
837
|
+
if (r) return [$(t, "mrz", e.words, r, .96)];
|
|
838
838
|
}
|
|
839
839
|
if (e === "document_number") {
|
|
840
840
|
let e = r[0];
|
|
841
|
-
return [
|
|
841
|
+
return [$(t, "mrz", e.words, e.text, .9)];
|
|
842
842
|
}
|
|
843
843
|
return [];
|
|
844
844
|
}
|
|
@@ -852,39 +852,39 @@ function gt(e) {
|
|
|
852
852
|
}
|
|
853
853
|
function _t(e, t, n, r, i) {
|
|
854
854
|
if (e === "address") {
|
|
855
|
-
let e = r.findIndex((e) => /\d/.test(e.text) &&
|
|
855
|
+
let e = r.findIndex((e) => /\d/.test(e.text) && X.test(e.text));
|
|
856
856
|
if (e < 0) return [];
|
|
857
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), [
|
|
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
859
|
}
|
|
860
860
|
if (e === "person_name") {
|
|
861
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 && !
|
|
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
863
|
return {
|
|
864
864
|
line: e,
|
|
865
|
-
score: r ? .45 +
|
|
865
|
+
score: r ? .45 + K(e.words) * .3 + a * .15 + (n < .65 ? .1 : 0) : 0
|
|
866
866
|
};
|
|
867
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 ? [] : [
|
|
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
869
|
}
|
|
870
870
|
if (e === "date_of_birth" || e === "expiration_date") {
|
|
871
|
-
let r = (/* @__PURE__ */ new Date()).getFullYear(), i = n.filter((e) =>
|
|
871
|
+
let r = (/* @__PURE__ */ new Date()).getFullYear(), i = n.filter((e) => Y.test(e.text.replace(/\s/g, ""))).map((e) => ({
|
|
872
872
|
word: e,
|
|
873
873
|
year: gt(e.text)
|
|
874
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 ? [
|
|
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
876
|
}
|
|
877
877
|
if (e === "postal_code") {
|
|
878
|
-
let r = n.find((t) =>
|
|
879
|
-
return r ? [
|
|
878
|
+
let r = n.find((t) => Q(e, t.text));
|
|
879
|
+
return r ? [$(t, "layout", [r], void 0, .78)] : [];
|
|
880
880
|
}
|
|
881
881
|
if (e === "state") {
|
|
882
|
-
let r = n.filter((t) =>
|
|
883
|
-
return r.length === 1 ? [
|
|
882
|
+
let r = n.filter((t) => Q(e, t.text));
|
|
883
|
+
return r.length === 1 ? [$(t, "layout", r, void 0, .7)] : [];
|
|
884
884
|
}
|
|
885
885
|
if (e === "document_number") {
|
|
886
|
-
let r = n.filter((t) =>
|
|
887
|
-
return r.sort((e, t) => t.text.length - e.text.length), r.length ? [
|
|
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
888
|
}
|
|
889
889
|
return [];
|
|
890
890
|
}
|
|
@@ -901,7 +901,7 @@ function bt(e, t, n) {
|
|
|
901
901
|
let r = t.filter((e) => vt(n.bbox, e.bbox) >= .3);
|
|
902
902
|
if (!r.length) continue;
|
|
903
903
|
let i = r.map((e) => e.text).join(" ");
|
|
904
|
-
if (
|
|
904
|
+
if (Q(e.field, i)) return $(e.id, "model", r, i, n.confidence);
|
|
905
905
|
}
|
|
906
906
|
}
|
|
907
907
|
function xt(e, t, n, r, i, a) {
|
|
@@ -925,10 +925,10 @@ function St(e, t, n, r) {
|
|
|
925
925
|
confidence: 1
|
|
926
926
|
};
|
|
927
927
|
}
|
|
928
|
-
function
|
|
929
|
-
let n = t.imageWidth ?? e?.imageWidth ?? 0, r = t.imageHeight ?? e?.imageHeight ?? 0, i = e?.words ?? [], a =
|
|
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
930
|
for (let e of t.rules) {
|
|
931
|
-
let c = e.strategy === "string" ? ut(e, a) : e.strategy === "label" ?
|
|
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
932
|
c.length ? o.push(...c) : s.push(e.id);
|
|
933
933
|
}
|
|
934
934
|
for (let e of t.template?.fields ?? []) {
|
|
@@ -937,7 +937,7 @@ function $(e, t) {
|
|
|
937
937
|
n && r ? o.push(St(e, t.template.id, n, r)) : s.push(c);
|
|
938
938
|
continue;
|
|
939
939
|
}
|
|
940
|
-
let l =
|
|
940
|
+
let l = q({
|
|
941
941
|
...e,
|
|
942
942
|
id: c,
|
|
943
943
|
strategy: "label"
|
|
@@ -955,68 +955,68 @@ function $(e, t) {
|
|
|
955
955
|
confidence: u
|
|
956
956
|
};
|
|
957
957
|
}
|
|
958
|
-
function
|
|
958
|
+
function wt(e) {
|
|
959
959
|
return e.rules.length > 0 || e.template?.fields.some((e) => e.strategy === "anchor") === !0;
|
|
960
960
|
}
|
|
961
|
-
function
|
|
961
|
+
function Tt(e, t = !1) {
|
|
962
962
|
return t && !e.complete ? "unmatched" : e.complete ? "success" : "partial";
|
|
963
963
|
}
|
|
964
|
-
async function
|
|
965
|
-
await
|
|
966
|
-
let
|
|
967
|
-
|
|
968
|
-
let
|
|
969
|
-
if (
|
|
970
|
-
|
|
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
971
|
} catch (e) {
|
|
972
|
-
|
|
973
|
-
let
|
|
974
|
-
|
|
975
|
-
}
|
|
976
|
-
let
|
|
977
|
-
rules:
|
|
978
|
-
template:
|
|
979
|
-
imageWidth:
|
|
980
|
-
imageHeight:
|
|
981
|
-
semanticDetections:
|
|
982
|
-
modelRequested:
|
|
983
|
-
}),
|
|
984
|
-
if (
|
|
985
|
-
|
|
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
986
|
} catch (e) {
|
|
987
|
-
|
|
988
|
-
}
|
|
989
|
-
if (
|
|
990
|
-
...
|
|
991
|
-
status:
|
|
992
|
-
ocr:
|
|
993
|
-
modelStatus:
|
|
994
|
-
modelError:
|
|
995
|
-
faces:
|
|
996
|
-
faceStatus:
|
|
997
|
-
faceError:
|
|
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
998
|
};
|
|
999
|
-
let
|
|
999
|
+
let p = await P(n, [...c.matches.map((e) => ({
|
|
1000
1000
|
...e.bbox,
|
|
1001
|
-
mode:
|
|
1002
|
-
})), ...
|
|
1001
|
+
mode: t.style?.mode
|
|
1002
|
+
})), ...u.map((e) => ({
|
|
1003
1003
|
...e.bbox,
|
|
1004
|
-
mode:
|
|
1005
|
-
}))],
|
|
1004
|
+
mode: t.style?.mode
|
|
1005
|
+
}))], t.style);
|
|
1006
1006
|
return {
|
|
1007
|
-
...
|
|
1008
|
-
status:
|
|
1009
|
-
ocr:
|
|
1010
|
-
canvas:
|
|
1011
|
-
blob:
|
|
1012
|
-
modelStatus:
|
|
1013
|
-
modelError:
|
|
1014
|
-
faces:
|
|
1015
|
-
faceStatus:
|
|
1016
|
-
faceError:
|
|
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
1017
|
};
|
|
1018
1018
|
}
|
|
1019
1019
|
//#endregion
|
|
1020
|
-
export {
|
|
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 };
|
|
1021
1021
|
|
|
1022
1022
|
//# sourceMappingURL=scanner-sdk.js.map
|