@exige/web-scanner-sdk 0.2.24 → 0.2.26
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-B3kHQ2Jh.js → finder-Dcg3mVJM.js} +268 -198
- package/dist/finder-Dcg3mVJM.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 +13 -1
- package/dist/react.d.ts +1 -1
- package/dist/react.js +381 -274
- package/dist/react.js.map +1 -1
- package/dist/scanner-sdk.js +239 -239
- package/dist/scanner-sdk.js.map +1 -1
- package/dist/sdk/camera.d.ts +44 -2
- package/dist/sdk/ocr.d.ts +1 -1
- package/dist/sdk/scan.d.ts +12 -0
- package/package.json +1 -1
- package/dist/finder-B3kHQ2Jh.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 _, _ as v, a as y, b as ee, c as te, d as ne, f as re, g as ie, h as ae, i as oe, j as se, k as ce, l as le, m as ue, n as de, o as fe, p as pe, r as me, s as he, t as ge, u as _e, v as ve, w as ye, x as be, y as xe, z as b } from "./finder-Dcg3mVJM.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,
|
|
7
7
|
y: (e.y - l) / s
|
|
8
8
|
};
|
|
9
9
|
}
|
|
10
|
-
function
|
|
10
|
+
function Se(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,15 +50,15 @@ 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,
|
|
57
57
|
y: n.centerY + e * i + t * r
|
|
58
58
|
};
|
|
59
59
|
}
|
|
60
|
-
function
|
|
61
|
-
let t =
|
|
60
|
+
function Ce(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);
|
|
62
62
|
return {
|
|
63
63
|
topLeft: t,
|
|
64
64
|
topRight: n,
|
|
@@ -84,20 +84,20 @@ function ye(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 g();
|
|
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
|
|
95
|
+
function we(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() {
|
|
@@ -111,24 +111,24 @@ function be(e) {
|
|
|
111
111
|
}
|
|
112
112
|
//#endregion
|
|
113
113
|
//#region src/sdk/ocr-runtime.ts
|
|
114
|
-
var
|
|
115
|
-
function
|
|
114
|
+
var Te = new URL("./assets/tesseract/worker.min.js", import.meta.url), Ee = new URL("./assets/tesseract/tesseract-core-lstm.wasm.js", import.meta.url), De = new URL("./assets/tesseract/tesseract-core-simd-lstm.wasm.js", import.meta.url), Oe = new URL("./assets/tesseract/tesseract-core-relaxedsimd-lstm.wasm.js", import.meta.url), ke = new URL("./assets/tesseract/eng.traineddata.gz", import.meta.url), Ae = 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), je = 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
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 Me() {
|
|
123
123
|
return {
|
|
124
|
-
relaxedSimd:
|
|
125
|
-
simd:
|
|
124
|
+
relaxedSimd: T(Ae),
|
|
125
|
+
simd: T(je)
|
|
126
126
|
};
|
|
127
127
|
}
|
|
128
|
-
function
|
|
129
|
-
return e.relaxedSimd ?
|
|
128
|
+
function Ne(e) {
|
|
129
|
+
return e.relaxedSimd ? Oe : e.simd ? De : Ee;
|
|
130
130
|
}
|
|
131
|
-
function
|
|
131
|
+
function Pe(e, t) {
|
|
132
132
|
let n = e?.trim() || "eng", r = t?.trim() || "";
|
|
133
133
|
if (r) return {
|
|
134
134
|
kind: "lang-path",
|
|
@@ -141,14 +141,14 @@ function Ae(e, t) {
|
|
|
141
141
|
};
|
|
142
142
|
throw new o("language", `OCR language "${n}" is not packaged. Pass langPath, a directory URL that contains ${n}.traineddata.gz.`);
|
|
143
143
|
}
|
|
144
|
-
function
|
|
144
|
+
function Fe(e = ke) {
|
|
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 Ie(e) {
|
|
149
|
+
return e.kind === "bundled-eng" ? Fe() : e.langPath;
|
|
150
150
|
}
|
|
151
|
-
async function
|
|
151
|
+
async function Le(e, t, n) {
|
|
152
152
|
return new Promise((r, i) => {
|
|
153
153
|
let a = !1, s = (e) => {
|
|
154
154
|
if (a) return;
|
|
@@ -174,7 +174,7 @@ async function Ne(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,20 +186,20 @@ 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
|
}
|
|
193
|
-
function
|
|
193
|
+
function Re(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
|
-
for (let e of t) n.some((t) =>
|
|
199
|
+
for (let e of t) n.some((t) => Re(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);
|
|
@@ -210,7 +210,7 @@ function O(e, t, n, r, i) {
|
|
|
210
210
|
}
|
|
211
211
|
return !0;
|
|
212
212
|
}
|
|
213
|
-
function
|
|
213
|
+
function ze(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,30 +226,30 @@ function Fe(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
|
-
text:
|
|
244
|
+
text: ze(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 j(e) {
|
|
251
251
|
let t = e.getContext("2d", { willReadFrequently: !0 });
|
|
252
|
-
if (!t) throw
|
|
252
|
+
if (!t) throw g();
|
|
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 {
|
|
@@ -258,7 +258,7 @@ function A(e) {
|
|
|
258
258
|
luminance: r
|
|
259
259
|
};
|
|
260
260
|
}
|
|
261
|
-
function
|
|
261
|
+
function Be(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 Ie(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 } = j(t);
|
|
273
|
+
return le(r, t.width, t.height);
|
|
274
274
|
}
|
|
275
|
-
function
|
|
275
|
+
function Ve(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 He = .58;
|
|
280
|
+
function Ue(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 We(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 = Ue(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 Be(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 Ge(e, t, n, r) {
|
|
302
|
+
return !e.strong || !e.region ? !1 : We(e, t.filter((t) => Ve(t, e.region, n.width, n.height)), r) < He;
|
|
303
303
|
}
|
|
304
|
-
function
|
|
304
|
+
function Ke(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 He(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
|
-
function
|
|
321
|
+
function qe(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 g();
|
|
326
326
|
a.drawImage(e, 0, 0, i.width, i.height);
|
|
327
|
-
let { image: o, luminance: s } =
|
|
327
|
+
let { image: o, luminance: s } = j(i), c = _e(s, i.width, i.height), l = te(c, i.width, i.height), u = document.createElement("canvas");
|
|
328
328
|
u.width = i.width, u.height = i.height;
|
|
329
|
-
let
|
|
330
|
-
if (!
|
|
331
|
-
let
|
|
332
|
-
return
|
|
329
|
+
let d = u.getContext("2d", { willReadFrequently: !0 });
|
|
330
|
+
if (!d) throw g();
|
|
331
|
+
let f = d.createImageData(u.width, u.height);
|
|
332
|
+
return M(f, c), d.putImageData(f, 0, 0), M(o, l), a.putImageData(o, 0, 0), {
|
|
333
333
|
sparseCanvas: i,
|
|
334
334
|
flattenedCanvas: u
|
|
335
335
|
};
|
|
336
336
|
}
|
|
337
|
-
function
|
|
337
|
+
function Je(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,21 +352,21 @@ function We(e) {
|
|
|
352
352
|
return l / s.length;
|
|
353
353
|
};
|
|
354
354
|
}
|
|
355
|
-
async function
|
|
356
|
-
await
|
|
357
|
-
let n =
|
|
358
|
-
|
|
359
|
-
let i = await
|
|
355
|
+
async function N(e, t = {}) {
|
|
356
|
+
await b("ocr");
|
|
357
|
+
let n = Pe(t.language, t.langPath), r = n.language;
|
|
358
|
+
D(t.minConfidence);
|
|
359
|
+
let i = await f(e, { cloneCanvas: !1 }), { sparseCanvas: a, flattenedCanvas: o } = qe(i), s = t.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
|
+
} : Be(i), { createWorker: c, PSM: l } = await import("tesseract.js"), u = 0, d = s.strong ? 3 : 2, p = await Le(c, r, {
|
|
365
|
+
workerPath: Te.href,
|
|
366
|
+
corePath: Ne(Me()).href,
|
|
367
|
+
langPath: Ie(n),
|
|
368
368
|
logger(e) {
|
|
369
|
-
typeof e.progress == "number" && t.onProgress?.(Math.min(1, (
|
|
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 {
|
|
@@ -375,7 +375,7 @@ async function M(e, t = {}) {
|
|
|
375
375
|
text: !0,
|
|
376
376
|
blocks: !0
|
|
377
377
|
});
|
|
378
|
-
|
|
378
|
+
u = 1, await p.setParameters({
|
|
379
379
|
tessedit_pageseg_mode: l.SPARSE_TEXT,
|
|
380
380
|
preserve_interword_spaces: "1"
|
|
381
381
|
});
|
|
@@ -386,19 +386,19 @@ async function M(e, t = {}) {
|
|
|
386
386
|
blocks: n.data.blocks,
|
|
387
387
|
scaleX: i.width / a.width,
|
|
388
388
|
scaleY: i.height / a.height
|
|
389
|
-
}],
|
|
389
|
+
}], d = {
|
|
390
390
|
...t,
|
|
391
391
|
includeWords: !0
|
|
392
|
-
}, f =
|
|
392
|
+
}, f = Je(i), m = A(c, d, {
|
|
393
393
|
width: i.width,
|
|
394
394
|
height: i.height
|
|
395
|
-
}, f), h = t.shadowPass !== !1 &&
|
|
395
|
+
}, f), h = t.shadowPass !== !1 && Ge(s, m.words, {
|
|
396
396
|
width: i.width,
|
|
397
397
|
height: i.height
|
|
398
398
|
}, f);
|
|
399
399
|
if (h && s.region) {
|
|
400
|
-
|
|
401
|
-
let { tile: e, passMapping: t } =
|
|
400
|
+
u = 2;
|
|
401
|
+
let { tile: e, passMapping: t } = Ke(o, s.region, i.width, i.height);
|
|
402
402
|
await p.setParameters({
|
|
403
403
|
tessedit_pageseg_mode: l.SPARSE_TEXT,
|
|
404
404
|
preserve_interword_spaces: "1"
|
|
@@ -412,7 +412,7 @@ async function M(e, t = {}) {
|
|
|
412
412
|
...t
|
|
413
413
|
});
|
|
414
414
|
}
|
|
415
|
-
let g = c.length === 2 ? m :
|
|
415
|
+
let g = c.length === 2 ? m : A(c, d, {
|
|
416
416
|
width: i.width,
|
|
417
417
|
height: i.height
|
|
418
418
|
}, f);
|
|
@@ -441,38 +441,38 @@ async function M(e, t = {}) {
|
|
|
441
441
|
}
|
|
442
442
|
//#endregion
|
|
443
443
|
//#region src/sdk/redact.ts
|
|
444
|
-
async function
|
|
445
|
-
await
|
|
446
|
-
let
|
|
447
|
-
if (!
|
|
444
|
+
async function P(e, t, n = {}) {
|
|
445
|
+
await b("redaction");
|
|
446
|
+
let r = await f(e), i = r.getContext("2d");
|
|
447
|
+
if (!i) throw g();
|
|
448
448
|
for (let e of t) {
|
|
449
|
-
let t =
|
|
449
|
+
let t = u(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 o =
|
|
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
458
|
if (!o) continue;
|
|
459
|
-
o.filter = `blur(${
|
|
460
|
-
let s = Math.max(12,
|
|
461
|
-
o.drawImage(
|
|
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 l(r, n.mimeType ?? "image/png", n.quality)
|
|
466
466
|
};
|
|
467
467
|
}
|
|
468
468
|
//#endregion
|
|
469
469
|
//#region src/sdk/face-model.ts
|
|
470
|
-
var
|
|
471
|
-
function
|
|
470
|
+
var F = /* @__PURE__ */ new Map(), Ye = 8400;
|
|
471
|
+
function Xe(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 Ze(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,39 +480,39 @@ function qe(e, t, n, r, i, a, o) {
|
|
|
480
480
|
height: r / i * o
|
|
481
481
|
};
|
|
482
482
|
}
|
|
483
|
-
function
|
|
483
|
+
function Qe(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, ${Ye}, 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: Ze(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) => Xe(e.bbox, t.bbox) < .45)).slice(0, 8);
|
|
495
495
|
}
|
|
496
|
-
async function
|
|
497
|
-
let r = await
|
|
496
|
+
async function $e(e, t, n = .35) {
|
|
497
|
+
let r = await f(e, { cloneCanvas: !1 }), i = await import("onnxruntime-web"), a = document.createElement("canvas");
|
|
498
498
|
a.width = 640, a.height = 640;
|
|
499
499
|
let o = a.getContext("2d", { willReadFrequently: !0 });
|
|
500
|
-
if (!o) throw
|
|
500
|
+
if (!o) throw g();
|
|
501
501
|
o.drawImage(r, 0, 0, 640, 640);
|
|
502
502
|
let s = o.getImageData(0, 0, 640, 640).data, c = 409600, l = new Float32Array(c * 3);
|
|
503
503
|
for (let e = 0; e < c; e += 1) l[e] = s[e * 4] / 255, l[c + e] = s[e * 4 + 1] / 255, l[c * 2 + e] = s[e * 4 + 2] / 255;
|
|
504
|
-
let u =
|
|
504
|
+
let u = F.get(t);
|
|
505
505
|
u || (u = i.InferenceSession.create(t, {
|
|
506
506
|
executionProviders: ["wasm"],
|
|
507
507
|
graphOptimizationLevel: "all"
|
|
508
|
-
}),
|
|
509
|
-
let
|
|
508
|
+
}), F.set(t, u));
|
|
509
|
+
let d = await u, p = (await d.run({ [d.inputNames[0]]: new i.Tensor("float32", l, [
|
|
510
510
|
1,
|
|
511
511
|
3,
|
|
512
512
|
640,
|
|
513
513
|
640
|
|
514
|
-
]) }))[
|
|
515
|
-
return
|
|
514
|
+
]) }))[d.outputNames[0]];
|
|
515
|
+
return Qe(p.data, p.dims.map(Number), {
|
|
516
516
|
confidence: n,
|
|
517
517
|
imageWidth: r.width,
|
|
518
518
|
imageHeight: r.height,
|
|
@@ -521,7 +521,7 @@ async function Ye(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",
|
|
@@ -529,19 +529,19 @@ var F = /* @__PURE__ */ new Map(), I = [
|
|
|
529
529
|
"expiration_date",
|
|
530
530
|
"postal_code",
|
|
531
531
|
"state"
|
|
532
|
-
],
|
|
533
|
-
function
|
|
532
|
+
], et = 8400;
|
|
533
|
+
function R(e) {
|
|
534
534
|
return 5 + e;
|
|
535
535
|
}
|
|
536
|
-
var
|
|
537
|
-
function
|
|
536
|
+
var z = 640;
|
|
537
|
+
function tt(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
|
|
542
|
-
return e.sort((e, t) => t.confidence - e.confidence).filter((e, t, n) => n.slice(0, t).every((t) => t.field !== e.field ||
|
|
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 || tt(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
|
|
@@ -559,15 +559,15 @@ function V(e, t) {
|
|
|
559
559
|
features: n
|
|
560
560
|
} : null;
|
|
561
561
|
}
|
|
562
|
-
function
|
|
562
|
+
function nt(e) {
|
|
563
563
|
return e.length === 3 && e[1] >= 5 && e[2] >= 1;
|
|
564
564
|
}
|
|
565
|
-
function
|
|
566
|
-
let t =
|
|
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, ${
|
|
565
|
+
function rt(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, ${et}, ${t}].`);
|
|
568
568
|
}
|
|
569
|
-
function
|
|
570
|
-
if (!
|
|
569
|
+
function it(e, t, n, r, i, a, o) {
|
|
570
|
+
if (!nt(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;
|
|
@@ -579,14 +579,14 @@ function et(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
|
-
function
|
|
588
|
-
let s =
|
|
589
|
-
if (!s) throw
|
|
587
|
+
function at(e, t, n, r, i, a, o) {
|
|
588
|
+
let s = H(t, n.length);
|
|
589
|
+
if (!s) throw rt(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;
|
|
@@ -598,46 +598,46 @@ function tt(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
|
-
function
|
|
607
|
-
let r = n.classes ??
|
|
606
|
+
function ot(e, t, n) {
|
|
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
|
-
return (n.layout ?? (o ? "yolox" : "yolov8")) === "yolox" ?
|
|
609
|
+
return (n.layout ?? (o ? "yolox" : "yolov8")) === "yolox" ? at(e, t, r, i, a, n.imageWidth, n.imageHeight) : it(e, t, r, i, a, n.imageWidth, n.imageHeight);
|
|
610
610
|
}
|
|
611
|
-
async function
|
|
612
|
-
let o = await
|
|
611
|
+
async function st(e, t, n = L, r = .35, i) {
|
|
612
|
+
let o = await f(e, { cloneCanvas: !1 }), s = import("onnxruntime-web"), c = z, l = document.createElement("canvas");
|
|
613
613
|
l.width = c, l.height = c;
|
|
614
614
|
let u = l.getContext("2d", { willReadFrequently: !0 });
|
|
615
|
-
if (!u) throw
|
|
615
|
+
if (!u) throw g();
|
|
616
616
|
u.drawImage(o, 0, 0, c, c);
|
|
617
|
-
let
|
|
618
|
-
for (let e = 0; e < p; e += 1) m[e] =
|
|
619
|
-
let h =
|
|
617
|
+
let d = u.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] = d[e * 4] / 255, m[p + e] = d[e * 4 + 1] / 255, m[p * 2 + e] = d[e * 4 + 2] / 255;
|
|
619
|
+
let h = I.get(t);
|
|
620
620
|
h || (h = (async () => {
|
|
621
621
|
try {
|
|
622
|
-
let [
|
|
623
|
-
return await
|
|
622
|
+
let [e, n] = await Promise.all([s, a(t)]);
|
|
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 [
|
|
630
|
+
})(), I.set(t, h));
|
|
631
|
+
let [_, v] = await Promise.all([s, h]), y = (await v.run({ [v.inputNames[0]]: new _.Tensor("float32", m, [
|
|
632
632
|
1,
|
|
633
633
|
3,
|
|
634
634
|
c,
|
|
635
635
|
c
|
|
636
|
-
]) }))[
|
|
637
|
-
return
|
|
638
|
-
classes:
|
|
639
|
-
confidence:
|
|
640
|
-
layout:
|
|
636
|
+
]) }))[v.outputNames[0]];
|
|
637
|
+
return ot(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
643
|
inputSize: c
|
|
@@ -645,7 +645,7 @@ async function rt(t, n, r = I, i = .35, a) {
|
|
|
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,17 +666,17 @@ 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
|
-
function
|
|
679
|
+
function ct(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];
|
|
@@ -687,14 +687,14 @@ function it(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,40 +704,40 @@ function it(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
|
-
function
|
|
717
|
-
let n = e.labelMode !== "exact", r =
|
|
716
|
+
function lt(e, t) {
|
|
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
|
-
function
|
|
723
|
+
function ut(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;
|
|
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
|
|
731
|
-
let o =
|
|
730
|
+
function q(e, t, n, r, i, a = "label") {
|
|
731
|
+
let o = lt(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(ut(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,32 +795,32 @@ var q = {
|
|
|
795
795
|
"POSTAL"
|
|
796
796
|
],
|
|
797
797
|
state: ["STATE", "DAJ"]
|
|
798
|
-
},
|
|
799
|
-
function
|
|
798
|
+
}, dt = 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
|
-
function
|
|
814
|
-
let r =
|
|
813
|
+
function ft(e, t, n) {
|
|
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) => !
|
|
819
|
+
o === s ? (c = a.words.slice(n + 1).filter((e) => !dt.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
|
}
|
|
823
|
-
function
|
|
823
|
+
function pt(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);
|
|
@@ -830,19 +830,19 @@ function lt(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
|
}
|
|
845
|
-
function
|
|
845
|
+
function mt(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,67 +850,67 @@ function ut(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 ht(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
|
-
year:
|
|
873
|
+
year: mt(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
|
}
|
|
891
|
-
function
|
|
891
|
+
function gt(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 _t(e, t, n, r) {
|
|
895
|
+
let i = ft(e.field, e.id, n), a = pt(e.field, e.id, n);
|
|
896
|
+
return i.length || a.length ? [...i, ...a] : ht(e.field, e.id, t, n, r);
|
|
897
897
|
}
|
|
898
|
-
function
|
|
898
|
+
function vt(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) => gt(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
|
-
function
|
|
908
|
-
let o =
|
|
907
|
+
function yt(e, t, n, r, i, a) {
|
|
908
|
+
let o = _t(e, t, n, r);
|
|
909
909
|
if (e.detector !== "model" || !a) return o;
|
|
910
|
-
let s =
|
|
910
|
+
let s = vt(e, t, i);
|
|
911
911
|
return s ? [s] : [];
|
|
912
912
|
}
|
|
913
|
-
function
|
|
913
|
+
function bt(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}`,
|
|
@@ -925,19 +925,19 @@ function gt(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 xt(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" ?
|
|
931
|
+
let c = e.strategy === "string" ? ct(e, a) : e.strategy === "label" ? q(e, i, a, n, r) : yt(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(bt(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,36 +955,36 @@ function $(e, t) {
|
|
|
955
955
|
confidence: u
|
|
956
956
|
};
|
|
957
957
|
}
|
|
958
|
-
function
|
|
958
|
+
function St(e) {
|
|
959
959
|
return e.rules.length > 0 || e.template?.fields.some((e) => e.strategy === "anchor") === !0;
|
|
960
960
|
}
|
|
961
|
-
function
|
|
961
|
+
function Ct(e, t = !1) {
|
|
962
962
|
return t && !e.complete ? "unmatched" : e.complete ? "success" : "partial";
|
|
963
963
|
}
|
|
964
|
-
async function
|
|
965
|
-
await
|
|
966
|
-
let n = await
|
|
967
|
-
|
|
964
|
+
async function wt(e, t) {
|
|
965
|
+
await b("redaction");
|
|
966
|
+
let n = await f(e, { cloneCanvas: !1 }), r = t.ocr;
|
|
967
|
+
St(t) && !r && (r = await N(n, { includeWords: !0 }));
|
|
968
968
|
let i = t.semanticDetections, a = t.modelRequested === !0, o = "not-requested", s;
|
|
969
969
|
if (t.models?.fields) try {
|
|
970
|
-
i = await
|
|
970
|
+
i = await st(n, t.models.fields, t.models.fieldClasses, t.models.confidence, t.models.fieldLayout), a = !0, o = "loaded";
|
|
971
971
|
} catch (e) {
|
|
972
972
|
s = e instanceof Error ? e.message : "The field model could not load.";
|
|
973
973
|
let n = t.models.allowHeuristicFallback !== !1;
|
|
974
974
|
a = !n, o = n ? "fallback" : "failed";
|
|
975
975
|
}
|
|
976
|
-
let c =
|
|
976
|
+
let c = xt(r, {
|
|
977
977
|
rules: t.rules,
|
|
978
978
|
template: t.template,
|
|
979
979
|
imageWidth: n.width,
|
|
980
980
|
imageHeight: n.height,
|
|
981
981
|
semanticDetections: i,
|
|
982
982
|
modelRequested: a
|
|
983
|
-
}), l =
|
|
983
|
+
}), l = Ct(c, t.requireAll), u = [], d = "not-requested", p;
|
|
984
984
|
if (t.models?.face) try {
|
|
985
|
-
|
|
985
|
+
u = await $e(n, t.models.face, t.models.faceConfidence), d = "loaded";
|
|
986
986
|
} catch (e) {
|
|
987
|
-
p = e instanceof Error ? e.message : "The face model could not load.",
|
|
987
|
+
p = e instanceof Error ? e.message : "The face model could not load.", d = "failed";
|
|
988
988
|
}
|
|
989
989
|
if (l === "unmatched") return {
|
|
990
990
|
...c,
|
|
@@ -992,14 +992,14 @@ async function yt(e, t) {
|
|
|
992
992
|
ocr: r,
|
|
993
993
|
modelStatus: o,
|
|
994
994
|
modelError: s,
|
|
995
|
-
faces:
|
|
996
|
-
faceStatus:
|
|
995
|
+
faces: u,
|
|
996
|
+
faceStatus: d,
|
|
997
997
|
faceError: p
|
|
998
998
|
};
|
|
999
|
-
let m = await
|
|
999
|
+
let m = await P(n, [...c.matches.map((e) => ({
|
|
1000
1000
|
...e.bbox,
|
|
1001
1001
|
mode: t.style?.mode
|
|
1002
|
-
})), ...
|
|
1002
|
+
})), ...u.map((e) => ({
|
|
1003
1003
|
...e.bbox,
|
|
1004
1004
|
mode: t.style?.mode
|
|
1005
1005
|
}))], t.style);
|
|
@@ -1011,12 +1011,12 @@ async function yt(e, t) {
|
|
|
1011
1011
|
blob: m.blob,
|
|
1012
1012
|
modelStatus: o,
|
|
1013
1013
|
modelError: s,
|
|
1014
|
-
faces:
|
|
1015
|
-
faceStatus:
|
|
1014
|
+
faces: u,
|
|
1015
|
+
faceStatus: d,
|
|
1016
1016
|
faceError: p
|
|
1017
1017
|
};
|
|
1018
1018
|
}
|
|
1019
1019
|
//#endregion
|
|
1020
|
-
export {
|
|
1020
|
+
export { ne as AutoTorchController, h as DEFAULT_DOCUMENT_MODEL_URL, c as DEV_LICENSE_HOSTS, p as LicenseError, re as NEAR_BLACK_LUMINANCE, ge as QuadStabilityTracker, pe as STILL_MAX_EDGE, o as ScannerError, P as applyRedactions, b as assertLicense, de as autoCaptureControl, ue as captureVideoFrame, we as createFinderSimulator, i as cropDocument, ae as detectBrowserEngine, r as detectDocument, ie as formatCaptureDiagnosticsReport, t as getLicense, v as isAndroidBrowser, ve as isNearBlackFrame, me as limitingFillTarget, Se as mapDocumentCornersToFrame, xt as matchRedactionRules, xe as meanFrameLuminance, oe as measureQuadFill, ee as mobileCameraConstraints, be as pickNativeCameraStill, N as recognizeText, wt as redactProgrammatically, d as resolveDocumentModelUrl, ce as scanDocument, e as scanSystemCameraStill, y as selectFinderGuidance, fe as selectFinderHint, _ as setLicenseKey, m as shouldUseSystemCameraCapture, Ce as simulatorQuad, n as startCamera, he as startFinder, s as subscribeModelDownloads, se as systemCameraFindMessage, ye as torchControl };
|
|
1021
1021
|
|
|
1022
1022
|
//# sourceMappingURL=scanner-sdk.js.map
|