@exige/web-scanner-sdk 0.2.25 → 0.2.27
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 +2 -2
- package/dist/{finder-B3t_3g6Z.js → finder-BlN89ZeT.js} +121 -101
- package/dist/finder-BlN89ZeT.js.map +1 -0
- package/dist/index.d.ts +3 -3
- package/dist/react/context.d.ts +1 -1
- package/dist/react/types.d.ts +17 -1
- package/dist/react.d.ts +1 -1
- package/dist/react.js +400 -267
- package/dist/react.js.map +1 -1
- package/dist/scanner-sdk.js +176 -176
- package/dist/scanner-sdk.js.map +1 -1
- package/dist/sdk/camera.d.ts +24 -4
- package/dist/sdk/scan.d.ts +10 -0
- package/package.json +1 -1
- package/dist/finder-B3t_3g6Z.js.map +0 -1
package/dist/scanner-sdk.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import { A as e,
|
|
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 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-BlN89ZeT.js";
|
|
2
2
|
//#region src/sdk/frame-geometry.ts
|
|
3
|
-
function
|
|
3
|
+
function b(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
|
|
10
|
+
function we(e, t, n) {
|
|
11
11
|
return {
|
|
12
|
-
topLeft:
|
|
13
|
-
topRight:
|
|
14
|
-
bottomRight:
|
|
15
|
-
bottomLeft:
|
|
12
|
+
topLeft: b(e.topLeft, t, n),
|
|
13
|
+
topRight: b(e.topRight, t, n),
|
|
14
|
+
bottomRight: b(e.bottomRight, t, n),
|
|
15
|
+
bottomLeft: b(e.bottomLeft, t, n)
|
|
16
16
|
};
|
|
17
17
|
}
|
|
18
18
|
//#endregion
|
|
19
19
|
//#region src/sdk/finder-simulator.ts
|
|
20
|
-
function
|
|
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 b(e, t = 960, n = 600) {
|
|
|
50
50
|
phase: "settled"
|
|
51
51
|
};
|
|
52
52
|
}
|
|
53
|
-
function
|
|
53
|
+
function S(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
|
|
61
|
-
let t =
|
|
60
|
+
function Te(e) {
|
|
61
|
+
let t = S(-e.width / 2, -e.height / 2, e), n = S(e.width / 2, -e.height / 2, e), r = S(e.width / 2, e.height / 2, e), i = S(-e.width / 2, e.height / 2, e);
|
|
62
62
|
return {
|
|
63
63
|
topLeft: t,
|
|
64
64
|
topRight: n,
|
|
@@ -84,7 +84,7 @@ function xe(e) {
|
|
|
84
84
|
}
|
|
85
85
|
};
|
|
86
86
|
}
|
|
87
|
-
function
|
|
87
|
+
function C(e, t) {
|
|
88
88
|
let n = e.getContext("2d");
|
|
89
89
|
if (!n) throw v();
|
|
90
90
|
let r = n.createLinearGradient(0, 0, e.width, e.height);
|
|
@@ -92,12 +92,12 @@ function S(e, t) {
|
|
|
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
|
|
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, C(e, x(a - n, e.width, e.height)), r = requestAnimationFrame(i));
|
|
99
99
|
}, a = () => {
|
|
100
|
-
n = 0,
|
|
100
|
+
n = 0, C(e, x(0, e.width, e.height));
|
|
101
101
|
};
|
|
102
102
|
return a(), {
|
|
103
103
|
start() {
|
|
@@ -111,24 +111,24 @@ function Se(e) {
|
|
|
111
111
|
}
|
|
112
112
|
//#endregion
|
|
113
113
|
//#region src/sdk/ocr-runtime.ts
|
|
114
|
-
var
|
|
115
|
-
function
|
|
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 w(e) {
|
|
116
116
|
try {
|
|
117
117
|
return typeof WebAssembly < "u" && WebAssembly.validate(e);
|
|
118
118
|
} catch {
|
|
119
119
|
return !1;
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
|
-
function
|
|
122
|
+
function Pe() {
|
|
123
123
|
return {
|
|
124
|
-
relaxedSimd:
|
|
125
|
-
simd:
|
|
124
|
+
relaxedSimd: w(Me),
|
|
125
|
+
simd: w(Ne)
|
|
126
126
|
};
|
|
127
127
|
}
|
|
128
|
-
function
|
|
129
|
-
return e.relaxedSimd ?
|
|
128
|
+
function Fe(e) {
|
|
129
|
+
return e.relaxedSimd ? Ae : e.simd ? ke : Oe;
|
|
130
130
|
}
|
|
131
|
-
function
|
|
131
|
+
function Ie(e, t) {
|
|
132
132
|
let n = e?.trim() || "eng", r = t?.trim() || "";
|
|
133
133
|
if (r) return {
|
|
134
134
|
kind: "lang-path",
|
|
@@ -139,22 +139,22 @@ function Me(e, t) {
|
|
|
139
139
|
kind: "bundled-eng",
|
|
140
140
|
language: "eng"
|
|
141
141
|
};
|
|
142
|
-
throw new
|
|
142
|
+
throw new g("language", `OCR language "${n}" is not packaged. Pass langPath, a directory URL that contains ${n}.traineddata.gz.`);
|
|
143
143
|
}
|
|
144
|
-
function
|
|
144
|
+
function Le(e = je) {
|
|
145
145
|
let t = e.href, n = t.lastIndexOf("/");
|
|
146
146
|
return n === -1 ? t : t.slice(0, n);
|
|
147
147
|
}
|
|
148
|
-
function
|
|
149
|
-
return e.kind === "bundled-eng" ?
|
|
148
|
+
function Re(e) {
|
|
149
|
+
return e.kind === "bundled-eng" ? Le() : e.langPath;
|
|
150
150
|
}
|
|
151
|
-
async function
|
|
151
|
+
async function ze(e, t, n) {
|
|
152
152
|
return new Promise((r, i) => {
|
|
153
153
|
let a = !1, o = (e) => {
|
|
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 g("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 Fe(e, t, n) {
|
|
|
174
174
|
}
|
|
175
175
|
//#endregion
|
|
176
176
|
//#region src/sdk/ocr.ts
|
|
177
|
-
function
|
|
177
|
+
function T(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,20 +186,20 @@ function w(e, t = 1, n = 1, r = 0, i = 0) {
|
|
|
186
186
|
}
|
|
187
187
|
};
|
|
188
188
|
}
|
|
189
|
-
function
|
|
189
|
+
function E(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
|
}
|
|
193
|
-
function
|
|
193
|
+
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 D(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
|
-
for (let e of t) n.some((t) =>
|
|
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 O(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);
|
|
@@ -210,7 +210,7 @@ function D(e, t, n, r, i) {
|
|
|
210
210
|
}
|
|
211
211
|
return !0;
|
|
212
212
|
}
|
|
213
|
-
function
|
|
213
|
+
function Ve(e) {
|
|
214
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
215
|
for (let e of t) {
|
|
216
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);
|
|
@@ -226,28 +226,28 @@ function Le(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 k(e, t, n, r) {
|
|
230
|
+
let i = E(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 = T(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 = T(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 = D(a).filter((e) => O(e, "word", l, u, r)), f = D(o).filter((e) => O(e, "character", l, u, r));
|
|
243
243
|
return {
|
|
244
|
-
text:
|
|
244
|
+
text: Ve(d),
|
|
245
245
|
confidence: d.length ? d.reduce((e, t) => e + t.confidence, 0) / d.length : 0,
|
|
246
246
|
words: t.includeWords ? d : [],
|
|
247
247
|
characters: t.includeCharacters ? f : []
|
|
248
248
|
};
|
|
249
249
|
}
|
|
250
|
-
function
|
|
250
|
+
function A(e) {
|
|
251
251
|
let t = e.getContext("2d", { willReadFrequently: !0 });
|
|
252
252
|
if (!t) throw v();
|
|
253
253
|
let n = t.getImageData(0, 0, e.width, e.height), r = new Uint8Array(e.width * e.height);
|
|
@@ -258,7 +258,7 @@ function k(e) {
|
|
|
258
258
|
luminance: r
|
|
259
259
|
};
|
|
260
260
|
}
|
|
261
|
-
function
|
|
261
|
+
function He(e) {
|
|
262
262
|
let t = document.createElement("canvas");
|
|
263
263
|
t.width = 72, t.height = 72;
|
|
264
264
|
let n = t.getContext("2d", { willReadFrequently: !0 });
|
|
@@ -269,27 +269,27 @@ function Re(e) {
|
|
|
269
269
|
areaRatio: 0
|
|
270
270
|
};
|
|
271
271
|
n.drawImage(e, 0, 0, t.width, t.height);
|
|
272
|
-
let { luminance: r } =
|
|
273
|
-
return
|
|
272
|
+
let { luminance: r } = A(t);
|
|
273
|
+
return ue(r, t.width, t.height);
|
|
274
274
|
}
|
|
275
|
-
function
|
|
275
|
+
function Ue(e, t, n, r) {
|
|
276
276
|
let i = (e.bbox.x + e.bbox.width / 2) / n, a = (e.bbox.y + e.bbox.height / 2) / r;
|
|
277
277
|
return i >= t.x && i <= t.x + t.width && a >= t.y && a <= t.y + t.height;
|
|
278
278
|
}
|
|
279
|
-
var
|
|
280
|
-
function
|
|
279
|
+
var We = .58;
|
|
280
|
+
function Ge(e) {
|
|
281
281
|
let t = e.trim();
|
|
282
282
|
if (!t || !/[\p{L}\p{N}]/u.test(t)) return 0;
|
|
283
283
|
if (/^\$?\d{1,5}([.,]\d{2})?$/.test(t)) return 1;
|
|
284
284
|
let n = t.replace(/[^\p{L}]/gu, "");
|
|
285
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
286
|
}
|
|
287
|
-
function
|
|
287
|
+
function Ke(e, t, n) {
|
|
288
288
|
let r = Math.max(0, Math.min(1, (1 - e.darkness / 80) * (1 - e.strength / 24)));
|
|
289
289
|
if (!t.length) return r * .35;
|
|
290
290
|
let i = 0;
|
|
291
291
|
for (let e of t) {
|
|
292
|
-
let t =
|
|
292
|
+
let t = Ge(e.text);
|
|
293
293
|
if (n) {
|
|
294
294
|
let r = n(e.bbox);
|
|
295
295
|
(r < .04 || r > .62) && (t *= .4);
|
|
@@ -298,10 +298,10 @@ function He(e, t, n) {
|
|
|
298
298
|
}
|
|
299
299
|
return r * .7 + i / t.length * .3;
|
|
300
300
|
}
|
|
301
|
-
function
|
|
302
|
-
return !e.strong || !e.region ? !1 :
|
|
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
303
|
}
|
|
304
|
-
function
|
|
304
|
+
function Je(e, t, n, r) {
|
|
305
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
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
307
|
let l = n / e.width, u = r / e.height;
|
|
@@ -315,26 +315,26 @@ function We(e, t, n, r) {
|
|
|
315
315
|
}
|
|
316
316
|
};
|
|
317
317
|
}
|
|
318
|
-
function
|
|
318
|
+
function j(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
|
-
function
|
|
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
325
|
if (!a) throw v();
|
|
326
326
|
a.drawImage(e, 0, 0, i.width, i.height);
|
|
327
|
-
let { image: o, luminance: s } =
|
|
327
|
+
let { image: o, luminance: s } = A(i), c = ve(s, i.width, i.height), l = ne(c, i.width, i.height), u = document.createElement("canvas");
|
|
328
328
|
u.width = i.width, u.height = i.height;
|
|
329
329
|
let d = u.getContext("2d", { willReadFrequently: !0 });
|
|
330
330
|
if (!d) throw v();
|
|
331
331
|
let f = d.createImageData(u.width, u.height);
|
|
332
|
-
return
|
|
332
|
+
return j(f, c), d.putImageData(f, 0, 0), j(o, l), a.putImageData(o, 0, 0), {
|
|
333
333
|
sparseCanvas: i,
|
|
334
334
|
flattenedCanvas: u
|
|
335
335
|
};
|
|
336
336
|
}
|
|
337
|
-
function
|
|
337
|
+
function Xe(e) {
|
|
338
338
|
let t = document.createElement("canvas");
|
|
339
339
|
t.width = 24, t.height = 24;
|
|
340
340
|
let n = t.getContext("2d", { willReadFrequently: !0 });
|
|
@@ -352,19 +352,19 @@ function Ke(e) {
|
|
|
352
352
|
return l / s.length;
|
|
353
353
|
};
|
|
354
354
|
}
|
|
355
|
-
async function
|
|
356
|
-
await
|
|
357
|
-
let r =
|
|
358
|
-
|
|
359
|
-
let o = await e
|
|
355
|
+
async function M(e, n = {}) {
|
|
356
|
+
await t("ocr");
|
|
357
|
+
let r = Ie(n.language, n.langPath), i = r.language;
|
|
358
|
+
E(n.minConfidence);
|
|
359
|
+
let o = await a(e, { cloneCanvas: !1 }), { sparseCanvas: s, flattenedCanvas: c } = Ye(o), l = n.shadowPass === !1 ? {
|
|
360
360
|
strong: !1,
|
|
361
361
|
strength: 0,
|
|
362
362
|
darkness: 0,
|
|
363
363
|
areaRatio: 0
|
|
364
|
-
} :
|
|
365
|
-
workerPath:
|
|
366
|
-
corePath:
|
|
367
|
-
langPath:
|
|
364
|
+
} : He(o), { createWorker: u, PSM: d } = await import("tesseract.js"), f = 0, p = l.strong ? 3 : 2, m = await ze(u, i, {
|
|
365
|
+
workerPath: De.href,
|
|
366
|
+
corePath: Fe(Pe()).href,
|
|
367
|
+
langPath: Re(r),
|
|
368
368
|
logger(e) {
|
|
369
369
|
typeof e.progress == "number" && n.onProgress?.(Math.min(1, (f + e.progress) / p), e.status ?? "recognizing text");
|
|
370
370
|
}
|
|
@@ -386,19 +386,19 @@ async function j(t, n = {}) {
|
|
|
386
386
|
blocks: t.data.blocks,
|
|
387
387
|
scaleX: o.width / s.width,
|
|
388
388
|
scaleY: o.height / s.height
|
|
389
|
-
}],
|
|
389
|
+
}], a = {
|
|
390
390
|
...n,
|
|
391
391
|
includeWords: !0
|
|
392
|
-
}, u =
|
|
392
|
+
}, u = Xe(o), p = k(r, a, {
|
|
393
393
|
width: o.width,
|
|
394
394
|
height: o.height
|
|
395
|
-
}, u), h = n.shadowPass !== !1 &&
|
|
395
|
+
}, u), h = n.shadowPass !== !1 && qe(l, p.words, {
|
|
396
396
|
width: o.width,
|
|
397
397
|
height: o.height
|
|
398
398
|
}, u);
|
|
399
399
|
if (h && l.region) {
|
|
400
400
|
f = 2;
|
|
401
|
-
let { tile: e, passMapping: t } =
|
|
401
|
+
let { tile: e, passMapping: t } = Je(c, l.region, o.width, o.height);
|
|
402
402
|
await m.setParameters({
|
|
403
403
|
tessedit_pageseg_mode: d.SPARSE_TEXT,
|
|
404
404
|
preserve_interword_spaces: "1"
|
|
@@ -412,14 +412,14 @@ async function j(t, n = {}) {
|
|
|
412
412
|
...t
|
|
413
413
|
});
|
|
414
414
|
}
|
|
415
|
-
let g = r.length === 2 ? p :
|
|
415
|
+
let g = r.length === 2 ? p : k(r, a, {
|
|
416
416
|
width: o.width,
|
|
417
417
|
height: o.height
|
|
418
418
|
}, u);
|
|
419
419
|
return n.onProgress?.(1, "recognizing text"), {
|
|
420
420
|
text: g.text,
|
|
421
421
|
confidence: g.confidence,
|
|
422
|
-
language:
|
|
422
|
+
language: i,
|
|
423
423
|
imageWidth: o.width,
|
|
424
424
|
imageHeight: o.height,
|
|
425
425
|
diagnostics: {
|
|
@@ -441,12 +441,12 @@ async function j(t, n = {}) {
|
|
|
441
441
|
}
|
|
442
442
|
//#endregion
|
|
443
443
|
//#region src/sdk/redact.ts
|
|
444
|
-
async function
|
|
445
|
-
await
|
|
446
|
-
let
|
|
444
|
+
async function N(e, n, r = {}) {
|
|
445
|
+
await t("redaction");
|
|
446
|
+
let i = await a(e), o = i.getContext("2d");
|
|
447
447
|
if (!o) throw v();
|
|
448
448
|
for (let e of n) {
|
|
449
|
-
let t =
|
|
449
|
+
let t = f(e, i.width, i.height);
|
|
450
450
|
if (t.width < 1 || t.height < 1) continue;
|
|
451
451
|
if ((e.mode ?? r.mode ?? "blackout") === "blackout") {
|
|
452
452
|
o.fillStyle = "#050706", o.fillRect(t.x, t.y, t.width, t.height);
|
|
@@ -454,25 +454,25 @@ async function M(t, n, r = {}) {
|
|
|
454
454
|
}
|
|
455
455
|
let n = document.createElement("canvas");
|
|
456
456
|
n.width = Math.ceil(t.width), n.height = Math.ceil(t.height);
|
|
457
|
-
let
|
|
458
|
-
if (!
|
|
459
|
-
|
|
457
|
+
let a = n.getContext("2d");
|
|
458
|
+
if (!a) continue;
|
|
459
|
+
a.filter = `blur(${r.blurRadius ?? 18}px)`;
|
|
460
460
|
let s = Math.max(12, r.blurRadius ?? 18);
|
|
461
|
-
|
|
461
|
+
a.drawImage(i, t.x - s, t.y - s, t.width + s * 2, t.height + s * 2, -s, -s, t.width + s * 2, t.height + s * 2), o.drawImage(n, t.x, t.y, t.width, t.height);
|
|
462
462
|
}
|
|
463
463
|
return {
|
|
464
|
-
canvas:
|
|
465
|
-
blob: await
|
|
464
|
+
canvas: i,
|
|
465
|
+
blob: await u(i, r.mimeType ?? "image/png", r.quality)
|
|
466
466
|
};
|
|
467
467
|
}
|
|
468
468
|
//#endregion
|
|
469
469
|
//#region src/sdk/face-model.ts
|
|
470
|
-
var
|
|
471
|
-
function
|
|
470
|
+
var P = /* @__PURE__ */ new Map(), Ze = 8400;
|
|
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);
|
|
474
474
|
}
|
|
475
|
-
function
|
|
475
|
+
function $e(e, t, n, r, i, a, o) {
|
|
476
476
|
return {
|
|
477
477
|
x: (e - n / 2) / i * a,
|
|
478
478
|
y: (t - r / 2) / i * o,
|
|
@@ -480,42 +480,42 @@ function P(e, t, n, r, i, a, o) {
|
|
|
480
480
|
height: r / i * o
|
|
481
481
|
};
|
|
482
482
|
}
|
|
483
|
-
function
|
|
483
|
+
function et(e, t, n) {
|
|
484
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, ${
|
|
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
486
|
let a = n.confidence ?? .35, o = n.inputSize ?? 640, s = [];
|
|
487
487
|
for (let t = 0; t < r; t += 1) {
|
|
488
488
|
let r = t * i, c = e[r + 4] * e[r + 5];
|
|
489
489
|
c < a || s.push({
|
|
490
490
|
confidence: c,
|
|
491
|
-
bbox:
|
|
491
|
+
bbox: $e(e[r], e[r + 1], e[r + 2], e[r + 3], o, n.imageWidth, n.imageHeight)
|
|
492
492
|
});
|
|
493
493
|
}
|
|
494
|
-
return s.sort((e, t) => t.confidence - e.confidence).filter((e, t, n) => n.slice(0, t).every((t) =>
|
|
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
|
-
async function
|
|
497
|
-
let
|
|
496
|
+
async function tt(e, t, n = .35) {
|
|
497
|
+
let r = await a(e, { cloneCanvas: !1 }), i = await import("onnxruntime-web"), o = document.createElement("canvas");
|
|
498
498
|
o.width = 640, o.height = 640;
|
|
499
499
|
let s = o.getContext("2d", { willReadFrequently: !0 });
|
|
500
500
|
if (!s) throw v();
|
|
501
|
-
s.drawImage(
|
|
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 =
|
|
505
|
-
d || (d =
|
|
504
|
+
let d = P.get(t);
|
|
505
|
+
d || (d = i.InferenceSession.create(t, {
|
|
506
506
|
executionProviders: ["wasm"],
|
|
507
507
|
graphOptimizationLevel: "all"
|
|
508
|
-
}),
|
|
509
|
-
let f = await d, p = (await f.run({ [f.inputNames[0]]: new
|
|
508
|
+
}), P.set(t, d));
|
|
509
|
+
let f = await d, p = (await f.run({ [f.inputNames[0]]: new i.Tensor("float32", u, [
|
|
510
510
|
1,
|
|
511
511
|
3,
|
|
512
512
|
640,
|
|
513
513
|
640
|
|
514
514
|
]) }))[f.outputNames[0]];
|
|
515
|
-
return
|
|
516
|
-
confidence:
|
|
517
|
-
imageWidth:
|
|
518
|
-
imageHeight:
|
|
515
|
+
return et(p.data, p.dims.map(Number), {
|
|
516
|
+
confidence: n,
|
|
517
|
+
imageWidth: r.width,
|
|
518
|
+
imageHeight: r.height,
|
|
519
519
|
inputSize: 640
|
|
520
520
|
});
|
|
521
521
|
}
|
|
@@ -529,17 +529,17 @@ var F = /* @__PURE__ */ new Map(), I = [
|
|
|
529
529
|
"expiration_date",
|
|
530
530
|
"postal_code",
|
|
531
531
|
"state"
|
|
532
|
-
],
|
|
532
|
+
], nt = 8400;
|
|
533
533
|
function L(e) {
|
|
534
534
|
return 5 + e;
|
|
535
535
|
}
|
|
536
536
|
var R = 640;
|
|
537
|
-
function
|
|
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
541
|
function z(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 ||
|
|
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
544
|
function B(e, t, n, r, i, a, o) {
|
|
545
545
|
return {
|
|
@@ -559,15 +559,15 @@ function V(e, t) {
|
|
|
559
559
|
features: n
|
|
560
560
|
} : null;
|
|
561
561
|
}
|
|
562
|
-
function
|
|
562
|
+
function it(e) {
|
|
563
563
|
return e.length === 3 && e[1] >= 5 && e[2] >= 1;
|
|
564
564
|
}
|
|
565
|
-
function
|
|
565
|
+
function at(e) {
|
|
566
566
|
let t = L(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, ${
|
|
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
|
-
function
|
|
570
|
-
if (
|
|
569
|
+
function ot(e, t, n, r, i, a, o) {
|
|
570
|
+
if (!it(t)) throw Error("Unsupported field-model YOLO output shape.");
|
|
571
571
|
let s = t[1], c = t[2], l = [];
|
|
572
572
|
for (let t = 0; t < c; t += 1) {
|
|
573
573
|
let u = 0, d = 0;
|
|
@@ -584,9 +584,9 @@ function tt(e, t, n, r, i, a, o) {
|
|
|
584
584
|
}
|
|
585
585
|
return z(l);
|
|
586
586
|
}
|
|
587
|
-
function
|
|
587
|
+
function st(e, t, n, r, i, a, o) {
|
|
588
588
|
let s = V(t, n.length);
|
|
589
|
-
if (!s) throw
|
|
589
|
+
if (!s) throw at(n.length);
|
|
590
590
|
let c = [];
|
|
591
591
|
for (let t = 0; t < s.anchors; t += 1) {
|
|
592
592
|
let l = t * s.features, u = e[l + 4], d = 0, f = 0;
|
|
@@ -603,44 +603,44 @@ function nt(e, t, n, r, i, a, o) {
|
|
|
603
603
|
}
|
|
604
604
|
return z(c);
|
|
605
605
|
}
|
|
606
|
-
function
|
|
606
|
+
function ct(e, t, n) {
|
|
607
607
|
let r = n.classes ?? I, i = n.confidence ?? .35, a = n.inputSize ?? R, o = V(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
|
-
return (n.layout ?? (o ? "yolox" : "yolov8")) === "yolox" ?
|
|
610
|
-
}
|
|
611
|
-
async function
|
|
612
|
-
let o = await e
|
|
613
|
-
|
|
614
|
-
let
|
|
615
|
-
if (!
|
|
616
|
-
|
|
617
|
-
let
|
|
618
|
-
for (let e = 0; e <
|
|
619
|
-
let
|
|
620
|
-
|
|
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 = I, r = .35, i) {
|
|
612
|
+
let o = await a(e, { cloneCanvas: !1 }), c = import("onnxruntime-web"), l = R, u = document.createElement("canvas");
|
|
613
|
+
u.width = l, u.height = l;
|
|
614
|
+
let d = u.getContext("2d", { willReadFrequently: !0 });
|
|
615
|
+
if (!d) throw v();
|
|
616
|
+
d.drawImage(o, 0, 0, l, l);
|
|
617
|
+
let f = d.getImageData(0, 0, l, l).data, p = l * l, 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 = F.get(t);
|
|
620
|
+
h || (h = (async () => {
|
|
621
621
|
try {
|
|
622
|
-
let [e,
|
|
623
|
-
return await e.InferenceSession.create(
|
|
622
|
+
let [e, n] = await Promise.all([c, s(t)]);
|
|
623
|
+
return await e.InferenceSession.create(n, {
|
|
624
624
|
executionProviders: ["wasm"],
|
|
625
625
|
graphOptimizationLevel: "all"
|
|
626
626
|
});
|
|
627
627
|
} catch (e) {
|
|
628
|
-
throw F.delete(
|
|
628
|
+
throw F.delete(t), e;
|
|
629
629
|
}
|
|
630
|
-
})(), F.set(
|
|
631
|
-
let [
|
|
630
|
+
})(), F.set(t, h));
|
|
631
|
+
let [g, _] = await Promise.all([c, h]), y = (await _.run({ [_.inputNames[0]]: new g.Tensor("float32", m, [
|
|
632
632
|
1,
|
|
633
633
|
3,
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
]) }))[
|
|
637
|
-
return
|
|
638
|
-
classes:
|
|
639
|
-
confidence:
|
|
640
|
-
layout:
|
|
634
|
+
l,
|
|
635
|
+
l
|
|
636
|
+
]) }))[_.outputNames[0]];
|
|
637
|
+
return ct(y.data, y.dims.map(Number), {
|
|
638
|
+
classes: n,
|
|
639
|
+
confidence: r,
|
|
640
|
+
layout: i,
|
|
641
641
|
imageWidth: o.width,
|
|
642
642
|
imageHeight: o.height,
|
|
643
|
-
inputSize:
|
|
643
|
+
inputSize: l
|
|
644
644
|
});
|
|
645
645
|
}
|
|
646
646
|
//#endregion
|
|
@@ -676,7 +676,7 @@ function W(e, t, n = !1) {
|
|
|
676
676
|
function G(e) {
|
|
677
677
|
return e.reduce((e, t) => e + t.confidence, 0) / Math.max(1, e.length);
|
|
678
678
|
}
|
|
679
|
-
function
|
|
679
|
+
function ut(e, t) {
|
|
680
680
|
let n = e.mode, r = n === "case-insensitive", i = e.scope ?? "line", a;
|
|
681
681
|
if (n === "regex") {
|
|
682
682
|
let t = e.pattern ?? e.values?.[0];
|
|
@@ -713,14 +713,14 @@ function at(e, t) {
|
|
|
713
713
|
}
|
|
714
714
|
return s;
|
|
715
715
|
}
|
|
716
|
-
function
|
|
716
|
+
function dt(e, t) {
|
|
717
717
|
let n = e.labelMode !== "exact", r = W(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
720
|
if (i.every((e, t) => W(e.text, n, !0) === r[t])) return i;
|
|
721
721
|
}
|
|
722
722
|
}
|
|
723
|
-
function
|
|
723
|
+
function ft(e, t, n, r, i, a) {
|
|
724
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
725
|
return e.filter((e) => {
|
|
726
726
|
let a = e.bbox.x + e.bbox.width / 2, u = e.bbox.y + e.bbox.height / 2;
|
|
@@ -728,7 +728,7 @@ function st(e, t, n, r, i, a) {
|
|
|
728
728
|
});
|
|
729
729
|
}
|
|
730
730
|
function K(e, t, n, r, i, a = "label") {
|
|
731
|
-
let o =
|
|
731
|
+
let o = dt(e, n);
|
|
732
732
|
if (!o) return [];
|
|
733
733
|
let s = H(o), c = new Set(o), l = t.filter((e) => !c.has(e)), u = e.direction === "any" ? [
|
|
734
734
|
"right",
|
|
@@ -737,7 +737,7 @@ function K(e, t, n, r, i, a = "label") {
|
|
|
737
737
|
"above"
|
|
738
738
|
] : [e.direction], d;
|
|
739
739
|
for (let t of u) {
|
|
740
|
-
let n = U(
|
|
740
|
+
let n = U(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);
|
|
@@ -795,7 +795,7 @@ var q = {
|
|
|
795
795
|
"POSTAL"
|
|
796
796
|
],
|
|
797
797
|
state: ["STATE", "DAJ"]
|
|
798
|
-
},
|
|
798
|
+
}, pt = 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;
|
|
799
799
|
function Z(e, t) {
|
|
800
800
|
let n = t.trim();
|
|
801
801
|
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;
|
|
@@ -810,17 +810,17 @@ function Q(e, t, n, r, i = 1) {
|
|
|
810
810
|
confidence: Math.max(0, Math.min(1, G(n) * i))
|
|
811
811
|
};
|
|
812
812
|
}
|
|
813
|
-
function
|
|
813
|
+
function mt(e, t, n) {
|
|
814
814
|
let r = q[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) => !
|
|
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 && Z(e, l) && i.push(Q(t, "alias", c, l, .98));
|
|
820
820
|
}
|
|
821
821
|
return i;
|
|
822
822
|
}
|
|
823
|
-
function
|
|
823
|
+
function ht(e, t, n) {
|
|
824
824
|
let r = n.filter((e) => {
|
|
825
825
|
let t = e.text.replace(/\s/g, "");
|
|
826
826
|
return t.includes("<<") || /^[A-Z0-9<]{25,}$/.test(t);
|
|
@@ -842,7 +842,7 @@ function ut(e, t, n) {
|
|
|
842
842
|
}
|
|
843
843
|
return [];
|
|
844
844
|
}
|
|
845
|
-
function
|
|
845
|
+
function gt(e) {
|
|
846
846
|
let t = e.replace(/\s/g, ""), n = t.match(/\d{4}/)?.[0];
|
|
847
847
|
if (n) return Number(n);
|
|
848
848
|
let r = t.match(/^\d{2}/)?.[0];
|
|
@@ -850,7 +850,7 @@ function dt(e) {
|
|
|
850
850
|
let i = Number(r);
|
|
851
851
|
return i > (/* @__PURE__ */ new Date()).getFullYear() % 100 ? 1900 + i : 2e3 + i;
|
|
852
852
|
}
|
|
853
|
-
function
|
|
853
|
+
function _t(e, t, n, r, i) {
|
|
854
854
|
if (e === "address") {
|
|
855
855
|
let e = r.findIndex((e) => /\d/.test(e.text) && Y.test(e.text));
|
|
856
856
|
if (e < 0) return [];
|
|
@@ -870,7 +870,7 @@ function ft(e, t, n, r, i) {
|
|
|
870
870
|
if (e === "date_of_birth" || e === "expiration_date") {
|
|
871
871
|
let r = (/* @__PURE__ */ new Date()).getFullYear(), i = n.filter((e) => J.test(e.text.replace(/\s/g, ""))).map((e) => ({
|
|
872
872
|
word: e,
|
|
873
|
-
year:
|
|
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
875
|
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)] : [];
|
|
876
876
|
}
|
|
@@ -888,29 +888,29 @@ function ft(e, t, n, r, i) {
|
|
|
888
888
|
}
|
|
889
889
|
return [];
|
|
890
890
|
}
|
|
891
|
-
function
|
|
891
|
+
function vt(e, t) {
|
|
892
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
893
|
}
|
|
894
|
-
function
|
|
895
|
-
let i =
|
|
896
|
-
return i.length || a.length ? [...i, ...a] :
|
|
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
897
|
}
|
|
898
|
-
function
|
|
898
|
+
function bt(e, t, n) {
|
|
899
899
|
let r = (n ?? []).filter((t) => t.field === e.field).sort((e, t) => t.confidence - e.confidence);
|
|
900
900
|
for (let n of r) {
|
|
901
|
-
let r = t.filter((e) =>
|
|
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
904
|
if (Z(e.field, i)) return Q(e.id, "model", r, i, n.confidence);
|
|
905
905
|
}
|
|
906
906
|
}
|
|
907
|
-
function
|
|
908
|
-
let o =
|
|
907
|
+
function xt(e, t, n, r, i, a) {
|
|
908
|
+
let o = yt(e, t, n, r);
|
|
909
909
|
if (e.detector !== "model" || !a) return o;
|
|
910
|
-
let s =
|
|
910
|
+
let s = bt(e, t, i);
|
|
911
911
|
return s ? [s] : [];
|
|
912
912
|
}
|
|
913
|
-
function
|
|
913
|
+
function St(e, t, n, r) {
|
|
914
914
|
let i = (e) => Math.max(0, Math.min(1, e)), a = i(e.rect.x), o = i(e.rect.y);
|
|
915
915
|
return {
|
|
916
916
|
ruleId: `${t}.${e.id}`,
|
|
@@ -928,13 +928,13 @@ function _t(e, t, n, r) {
|
|
|
928
928
|
function $(e, t) {
|
|
929
929
|
let n = t.imageWidth ?? e?.imageWidth ?? 0, r = t.imageHeight ?? e?.imageHeight ?? 0, i = e?.words ?? [], a = U(i), o = [], s = [];
|
|
930
930
|
for (let e of t.rules) {
|
|
931
|
-
let c = e.strategy === "string" ?
|
|
931
|
+
let c = e.strategy === "string" ? ut(e, a) : e.strategy === "label" ? K(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 ?? []) {
|
|
935
935
|
let c = `${t.template.id}.${e.id}`;
|
|
936
936
|
if (e.strategy === "rect") {
|
|
937
|
-
n && r ? o.push(
|
|
937
|
+
n && r ? o.push(St(e, t.template.id, n, r)) : s.push(c);
|
|
938
938
|
continue;
|
|
939
939
|
}
|
|
940
940
|
let l = K({
|
|
@@ -955,48 +955,48 @@ function $(e, t) {
|
|
|
955
955
|
confidence: u
|
|
956
956
|
};
|
|
957
957
|
}
|
|
958
|
-
function
|
|
958
|
+
function Ct(e) {
|
|
959
959
|
return e.rules.length > 0 || e.template?.fields.some((e) => e.strategy === "anchor") === !0;
|
|
960
960
|
}
|
|
961
|
-
function
|
|
961
|
+
function wt(e, t = !1) {
|
|
962
962
|
return t && !e.complete ? "unmatched" : e.complete ? "success" : "partial";
|
|
963
963
|
}
|
|
964
|
-
async function
|
|
965
|
-
await
|
|
966
|
-
let r = await e
|
|
967
|
-
|
|
964
|
+
async function Tt(e, n) {
|
|
965
|
+
await t("redaction");
|
|
966
|
+
let r = await a(e, { cloneCanvas: !1 }), i = n.ocr;
|
|
967
|
+
Ct(n) && !i && (i = await M(r, { includeWords: !0 }));
|
|
968
968
|
let o = n.semanticDetections, s = n.modelRequested === !0, c = "not-requested", l;
|
|
969
969
|
if (n.models?.fields) try {
|
|
970
|
-
o = await
|
|
970
|
+
o = await lt(r, n.models.fields, n.models.fieldClasses, n.models.confidence, n.models.fieldLayout), s = !0, c = "loaded";
|
|
971
971
|
} catch (e) {
|
|
972
972
|
l = e instanceof Error ? e.message : "The field model could not load.";
|
|
973
973
|
let t = n.models.allowHeuristicFallback !== !1;
|
|
974
974
|
s = !t, c = t ? "fallback" : "failed";
|
|
975
975
|
}
|
|
976
|
-
let u = $(
|
|
976
|
+
let u = $(i, {
|
|
977
977
|
rules: n.rules,
|
|
978
978
|
template: n.template,
|
|
979
979
|
imageWidth: r.width,
|
|
980
980
|
imageHeight: r.height,
|
|
981
981
|
semanticDetections: o,
|
|
982
982
|
modelRequested: s
|
|
983
|
-
}), d =
|
|
983
|
+
}), d = wt(u, n.requireAll), f = [], p = "not-requested", m;
|
|
984
984
|
if (n.models?.face) try {
|
|
985
|
-
f = await
|
|
985
|
+
f = await tt(r, n.models.face, n.models.faceConfidence), p = "loaded";
|
|
986
986
|
} catch (e) {
|
|
987
987
|
m = e instanceof Error ? e.message : "The face model could not load.", p = "failed";
|
|
988
988
|
}
|
|
989
989
|
if (d === "unmatched") return {
|
|
990
990
|
...u,
|
|
991
991
|
status: d,
|
|
992
|
-
ocr:
|
|
992
|
+
ocr: i,
|
|
993
993
|
modelStatus: c,
|
|
994
994
|
modelError: l,
|
|
995
995
|
faces: f,
|
|
996
996
|
faceStatus: p,
|
|
997
997
|
faceError: m
|
|
998
998
|
};
|
|
999
|
-
let h = await
|
|
999
|
+
let h = await N(r, [...u.matches.map((e) => ({
|
|
1000
1000
|
...e.bbox,
|
|
1001
1001
|
mode: n.style?.mode
|
|
1002
1002
|
})), ...f.map((e) => ({
|
|
@@ -1006,7 +1006,7 @@ async function bt(t, n) {
|
|
|
1006
1006
|
return {
|
|
1007
1007
|
...u,
|
|
1008
1008
|
status: d,
|
|
1009
|
-
ocr:
|
|
1009
|
+
ocr: i,
|
|
1010
1010
|
canvas: h.canvas,
|
|
1011
1011
|
blob: h.blob,
|
|
1012
1012
|
modelStatus: c,
|
|
@@ -1017,6 +1017,6 @@ async function bt(t, n) {
|
|
|
1017
1017
|
};
|
|
1018
1018
|
}
|
|
1019
1019
|
//#endregion
|
|
1020
|
-
export {
|
|
1020
|
+
export { re as AutoTorchController, i as DEFAULT_DOCUMENT_MODEL_URL, p as DEV_LICENSE_HOSTS, Ce as LicenseError, ie as NEAR_BLACK_LUMINANCE, _e as QuadStabilityTracker, me as STILL_MAX_EDGE, g as ScannerError, N as applyRedactions, t as assertLicense, fe as autoCaptureControl, de as captureVideoFrame, Ee as createFinderSimulator, r as cropDocument, oe as detectBrowserEngine, d as detectDocument, ae as formatCaptureDiagnosticsReport, _ as getLicense, y as hasTransientUserActivation, ye as isAndroidBrowser, Se as isNearBlackFrame, he as limitingFillTarget, we as mapDocumentCornersToFrame, $ as matchRedactionRules, te as meanFrameLuminance, se as measureQuadFill, xe as mobileCameraConstraints, m as pickNativeCameraStill, M as recognizeText, Tt as redactProgrammatically, le as resolveDocumentModelUrl, e as scanDocument, ce as scanSystemCameraStill, ee as selectFinderGuidance, pe as selectFinderHint, o as setLicenseKey, n as shouldUseSystemCameraCapture, Te as simulatorQuad, be as startCamera, ge as startFinder, c as subscribeModelDownloads, l as systemCameraFindMessage, h as torchControl };
|
|
1021
1021
|
|
|
1022
1022
|
//# sourceMappingURL=scanner-sdk.js.map
|