@exige/web-scanner-sdk 0.2.26 → 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 +3 -3
- package/dist/assets/document-worker.js +1 -1
- package/dist/assets/document-worker.js.map +1 -1
- package/dist/{finder-Dcg3mVJM.js → finder-BvBpdbHa.js} +488 -461
- package/dist/finder-BvBpdbHa.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/react/types.d.ts +14 -5
- package/dist/react.js +301 -275
- package/dist/react.js.map +1 -1
- package/dist/scanner-sdk.js +159 -159
- package/dist/scanner-sdk.js.map +1 -1
- package/dist/sdk/camera.d.ts +16 -6
- 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-Dcg3mVJM.js.map +0 -1
package/dist/scanner-sdk.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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
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;
|
|
@@ -7,7 +7,7 @@ function x(e, t, n) {
|
|
|
7
7
|
y: (e.y - l) / s
|
|
8
8
|
};
|
|
9
9
|
}
|
|
10
|
-
function
|
|
10
|
+
function we(e, t, n) {
|
|
11
11
|
return {
|
|
12
12
|
topLeft: x(e.topLeft, t, n),
|
|
13
13
|
topRight: x(e.topRight, t, n),
|
|
@@ -57,7 +57,7 @@ function C(e, t, n) {
|
|
|
57
57
|
y: n.centerY + e * i + t * r
|
|
58
58
|
};
|
|
59
59
|
}
|
|
60
|
-
function
|
|
60
|
+
function Te(e) {
|
|
61
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,
|
|
@@ -86,13 +86,13 @@ function Ce(e) {
|
|
|
86
86
|
}
|
|
87
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;
|
|
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
98
|
t && (n ||= a, w(e, S(a - n, e.width, e.height)), r = requestAnimationFrame(i));
|
|
@@ -111,7 +111,7 @@ function we(e) {
|
|
|
111
111
|
}
|
|
112
112
|
//#endregion
|
|
113
113
|
//#region src/sdk/ocr-runtime.ts
|
|
114
|
-
var
|
|
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
115
|
function T(e) {
|
|
116
116
|
try {
|
|
117
117
|
return typeof WebAssembly < "u" && WebAssembly.validate(e);
|
|
@@ -119,16 +119,16 @@ function T(e) {
|
|
|
119
119
|
return !1;
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
|
-
function
|
|
122
|
+
function Pe() {
|
|
123
123
|
return {
|
|
124
|
-
relaxedSimd: T(
|
|
125
|
-
simd: T(
|
|
124
|
+
relaxedSimd: T(Me),
|
|
125
|
+
simd: T(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 Pe(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
|
-
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
|
-
let a = !1,
|
|
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 y("worker", `OCR worker failed to start (${t}).`));
|
|
158
158
|
};
|
|
159
159
|
e(t, void 0, {
|
|
160
160
|
workerPath: n.workerPath,
|
|
@@ -162,14 +162,14 @@ async function Le(e, t, n) {
|
|
|
162
162
|
langPath: n.langPath,
|
|
163
163
|
gzip: !0,
|
|
164
164
|
logger: n.logger,
|
|
165
|
-
errorHandler:
|
|
165
|
+
errorHandler: o
|
|
166
166
|
}).then((e) => {
|
|
167
167
|
if (a) {
|
|
168
168
|
e.terminate?.();
|
|
169
169
|
return;
|
|
170
170
|
}
|
|
171
171
|
a = !0, r(e);
|
|
172
|
-
},
|
|
172
|
+
}, o);
|
|
173
173
|
});
|
|
174
174
|
}
|
|
175
175
|
//#endregion
|
|
@@ -190,13 +190,13 @@ 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 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
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) => Be(t, e) >= .65) || n.push(e);
|
|
200
200
|
return n;
|
|
201
201
|
}
|
|
202
202
|
function k(e, t, n, r, i) {
|
|
@@ -210,7 +210,7 @@ function k(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);
|
|
@@ -241,7 +241,7 @@ function A(e, t, n, r) {
|
|
|
241
241
|
}
|
|
242
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: 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 : []
|
|
@@ -249,7 +249,7 @@ function A(e, t, n, r) {
|
|
|
249
249
|
}
|
|
250
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 {
|
|
@@ -258,7 +258,7 @@ function j(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 });
|
|
@@ -270,26 +270,26 @@ function Be(e) {
|
|
|
270
270
|
};
|
|
271
271
|
n.drawImage(e, 0, 0, t.width, t.height);
|
|
272
272
|
let { luminance: r } = j(t);
|
|
273
|
-
return
|
|
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 We(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;
|
|
@@ -318,23 +318,23 @@ function Ke(e, t, n, r) {
|
|
|
318
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 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 M(
|
|
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
|
-
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 });
|
|
@@ -353,33 +353,33 @@ function Je(e) {
|
|
|
353
353
|
};
|
|
354
354
|
}
|
|
355
355
|
async function N(e, t = {}) {
|
|
356
|
-
await
|
|
357
|
-
let n =
|
|
356
|
+
await v("ocr");
|
|
357
|
+
let n = Ie(t.language, t.langPath), r = n.language;
|
|
358
358
|
D(t.minConfidence);
|
|
359
|
-
let i = await
|
|
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
|
-
} :
|
|
365
|
-
workerPath:
|
|
366
|
-
corePath:
|
|
367
|
-
langPath:
|
|
364
|
+
} : He(i), { createWorker: c, PSM: l } = await import("tesseract.js"), u = 0, d = s.strong ? 3 : 2, f = await ze(c, r, {
|
|
365
|
+
workerPath: De.href,
|
|
366
|
+
corePath: Fe(Pe()).href,
|
|
367
|
+
langPath: Re(n),
|
|
368
368
|
logger(e) {
|
|
369
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
|
-
u = 1, await
|
|
378
|
+
u = 1, await f.setParameters({
|
|
379
379
|
tessedit_pageseg_mode: l.SPARSE_TEXT,
|
|
380
380
|
preserve_interword_spaces: "1"
|
|
381
381
|
});
|
|
382
|
-
let n = await
|
|
382
|
+
let n = await f.recognize(a, {}, {
|
|
383
383
|
text: !0,
|
|
384
384
|
blocks: !0
|
|
385
385
|
}), c = [{ blocks: e.data.blocks }, {
|
|
@@ -389,21 +389,21 @@ async function N(e, t = {}) {
|
|
|
389
389
|
}], d = {
|
|
390
390
|
...t,
|
|
391
391
|
includeWords: !0
|
|
392
|
-
},
|
|
392
|
+
}, p = Xe(i), m = A(c, d, {
|
|
393
393
|
width: i.width,
|
|
394
394
|
height: i.height
|
|
395
|
-
},
|
|
395
|
+
}, p), h = t.shadowPass !== !1 && qe(s, m.words, {
|
|
396
396
|
width: i.width,
|
|
397
397
|
height: i.height
|
|
398
|
-
},
|
|
398
|
+
}, p);
|
|
399
399
|
if (h && s.region) {
|
|
400
400
|
u = 2;
|
|
401
|
-
let { tile: e, passMapping: t } =
|
|
402
|
-
await
|
|
401
|
+
let { tile: e, passMapping: t } = Je(o, s.region, i.width, i.height);
|
|
402
|
+
await f.setParameters({
|
|
403
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
|
});
|
|
@@ -415,7 +415,7 @@ async function N(e, t = {}) {
|
|
|
415
415
|
let g = c.length === 2 ? m : A(c, d, {
|
|
416
416
|
width: i.width,
|
|
417
417
|
height: i.height
|
|
418
|
-
},
|
|
418
|
+
}, p);
|
|
419
419
|
return t.onProgress?.(1, "recognizing text"), {
|
|
420
420
|
text: g.text,
|
|
421
421
|
confidence: g.confidence,
|
|
@@ -436,17 +436,17 @@ async function N(e, t = {}) {
|
|
|
436
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
444
|
async function P(e, t, n = {}) {
|
|
445
|
-
await
|
|
446
|
-
let r = await
|
|
447
|
-
if (!i) throw
|
|
445
|
+
await v("redaction");
|
|
446
|
+
let r = await b(e), i = r.getContext("2d");
|
|
447
|
+
if (!i) throw o();
|
|
448
448
|
for (let e of t) {
|
|
449
|
-
let t =
|
|
449
|
+
let t = Se(e, r.width, r.height);
|
|
450
450
|
if (t.width < 1 || t.height < 1) continue;
|
|
451
451
|
if ((e.mode ?? n.mode ?? "blackout") === "blackout") {
|
|
452
452
|
i.fillStyle = "#050706", i.fillRect(t.x, t.y, t.width, t.height);
|
|
@@ -462,17 +462,17 @@ async function P(e, t, n = {}) {
|
|
|
462
462
|
}
|
|
463
463
|
return {
|
|
464
464
|
canvas: r,
|
|
465
|
-
blob: await
|
|
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 F = /* @__PURE__ */ new Map(),
|
|
471
|
-
function
|
|
470
|
+
var F = /* @__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,39 +480,39 @@ function Ze(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 r = await
|
|
496
|
+
async function tt(e, t, n = .35) {
|
|
497
|
+
let r = await b(e, { cloneCanvas: !1 }), i = await import("onnxruntime-web"), a = document.createElement("canvas");
|
|
498
498
|
a.width = 640, a.height = 640;
|
|
499
|
-
let
|
|
500
|
-
if (!
|
|
501
|
-
|
|
502
|
-
let
|
|
503
|
-
for (let e = 0; e <
|
|
504
|
-
let
|
|
505
|
-
|
|
499
|
+
let s = a.getContext("2d", { willReadFrequently: !0 });
|
|
500
|
+
if (!s) throw o();
|
|
501
|
+
s.drawImage(r, 0, 0, 640, 640);
|
|
502
|
+
let c = s.getImageData(0, 0, 640, 640).data, l = 409600, u = new Float32Array(l * 3);
|
|
503
|
+
for (let e = 0; e < l; e += 1) u[e] = c[e * 4] / 255, u[l + e] = c[e * 4 + 1] / 255, u[l * 2 + e] = c[e * 4 + 2] / 255;
|
|
504
|
+
let d = F.get(t);
|
|
505
|
+
d || (d = i.InferenceSession.create(t, {
|
|
506
506
|
executionProviders: ["wasm"],
|
|
507
507
|
graphOptimizationLevel: "all"
|
|
508
|
-
}), F.set(t,
|
|
509
|
-
let
|
|
508
|
+
}), F.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
|
-
]) }))[
|
|
515
|
-
return
|
|
514
|
+
]) }))[f.outputNames[0]];
|
|
515
|
+
return et(p.data, p.dims.map(Number), {
|
|
516
516
|
confidence: n,
|
|
517
517
|
imageWidth: r.width,
|
|
518
518
|
imageHeight: r.height,
|
|
@@ -529,17 +529,17 @@ var I = /* @__PURE__ */ new Map(), L = [
|
|
|
529
529
|
"expiration_date",
|
|
530
530
|
"postal_code",
|
|
531
531
|
"state"
|
|
532
|
-
],
|
|
532
|
+
], nt = 8400;
|
|
533
533
|
function R(e) {
|
|
534
534
|
return 5 + e;
|
|
535
535
|
}
|
|
536
536
|
var z = 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 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 ||
|
|
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 V(e, t, n, r, i, a, o) {
|
|
545
545
|
return {
|
|
@@ -559,15 +559,15 @@ function H(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 = 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, ${
|
|
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 it(e, t, n, r, i, a, o) {
|
|
|
584
584
|
}
|
|
585
585
|
return B(l);
|
|
586
586
|
}
|
|
587
|
-
function
|
|
587
|
+
function st(e, t, n, r, i, a, o) {
|
|
588
588
|
let s = H(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,23 +603,23 @@ function at(e, t, n, r, i, a, o) {
|
|
|
603
603
|
}
|
|
604
604
|
return B(c);
|
|
605
605
|
}
|
|
606
|
-
function
|
|
606
|
+
function ct(e, t, n) {
|
|
607
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" ?
|
|
610
|
-
}
|
|
611
|
-
async function
|
|
612
|
-
let
|
|
613
|
-
|
|
614
|
-
let
|
|
615
|
-
if (!
|
|
616
|
-
|
|
617
|
-
let
|
|
618
|
-
for (let e = 0; e < p; e += 1) m[e] =
|
|
609
|
+
return (n.layout ?? (o ? "yolox" : "yolov8")) === "yolox" ? st(e, t, r, i, a, n.imageWidth, n.imageHeight) : ot(e, t, r, i, a, n.imageWidth, n.imageHeight);
|
|
610
|
+
}
|
|
611
|
+
async function lt(e, t, n = L, r = .35, i) {
|
|
612
|
+
let a = await b(e, { cloneCanvas: !1 }), s = import("onnxruntime-web"), c = z, u = document.createElement("canvas");
|
|
613
|
+
u.width = c, u.height = c;
|
|
614
|
+
let d = u.getContext("2d", { willReadFrequently: !0 });
|
|
615
|
+
if (!d) throw o();
|
|
616
|
+
d.drawImage(a, 0, 0, c, c);
|
|
617
|
+
let f = d.getImageData(0, 0, c, c).data, p = c * c, m = new Float32Array(p * 3);
|
|
618
|
+
for (let e = 0; e < p; e += 1) m[e] = f[e * 4] / 255, m[p + e] = f[e * 4 + 1] / 255, m[p * 2 + e] = f[e * 4 + 2] / 255;
|
|
619
619
|
let h = I.get(t);
|
|
620
620
|
h || (h = (async () => {
|
|
621
621
|
try {
|
|
622
|
-
let [e, n] = await Promise.all([s,
|
|
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"
|
|
@@ -628,18 +628,18 @@ async function st(e, t, n = L, r = .35, i) {
|
|
|
628
628
|
throw I.delete(t), e;
|
|
629
629
|
}
|
|
630
630
|
})(), I.set(t, h));
|
|
631
|
-
let [
|
|
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
634
|
c,
|
|
635
635
|
c
|
|
636
|
-
]) }))[
|
|
637
|
-
return
|
|
636
|
+
]) }))[_.outputNames[0]];
|
|
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:
|
|
641
|
+
imageWidth: a.width,
|
|
642
|
+
imageHeight: a.height,
|
|
643
643
|
inputSize: c
|
|
644
644
|
});
|
|
645
645
|
}
|
|
@@ -676,7 +676,7 @@ function G(e, t, n = !1) {
|
|
|
676
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 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 ct(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 = 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
720
|
if (i.every((e, t) => G(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 ut(e, t, n, r, i, a) {
|
|
|
728
728
|
});
|
|
729
729
|
}
|
|
730
730
|
function q(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 = U(o), c = new Set(o), l = t.filter((e) => !c.has(e)), u = e.direction === "any" ? [
|
|
734
734
|
"right",
|
|
@@ -737,7 +737,7 @@ function q(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 = W(
|
|
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);
|
|
@@ -795,7 +795,7 @@ var J = {
|
|
|
795
795
|
"POSTAL"
|
|
796
796
|
],
|
|
797
797
|
state: ["STATE", "DAJ"]
|
|
798
|
-
},
|
|
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
799
|
function Q(e, t) {
|
|
800
800
|
let n = t.trim();
|
|
801
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;
|
|
@@ -810,17 +810,17 @@ function $(e, t, n, r, i = 1) {
|
|
|
810
810
|
confidence: Math.max(0, Math.min(1, K(n) * i))
|
|
811
811
|
};
|
|
812
812
|
}
|
|
813
|
-
function
|
|
813
|
+
function mt(e, t, n) {
|
|
814
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) => !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
|
}
|
|
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 pt(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 mt(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) && X.test(e.text));
|
|
856
856
|
if (e < 0) return [];
|
|
@@ -870,7 +870,7 @@ function ht(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) => Y.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 ? [$(t, "layout", [a[0].word], void 0, .72)] : [];
|
|
876
876
|
}
|
|
@@ -888,29 +888,29 @@ function ht(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 (Q(e.field, i)) return $(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}`,
|
|
@@ -925,16 +925,16 @@ function bt(e, t, n, r) {
|
|
|
925
925
|
confidence: 1
|
|
926
926
|
};
|
|
927
927
|
}
|
|
928
|
-
function
|
|
928
|
+
function Ct(e, t) {
|
|
929
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" ? 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 ?? []) {
|
|
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 = q({
|
|
@@ -955,36 +955,36 @@ function xt(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 n = await
|
|
967
|
-
|
|
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
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 lt(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 = Ct(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 = Tt(c, t.requireAll), u = [], d = "not-requested", f;
|
|
984
984
|
if (t.models?.face) try {
|
|
985
|
-
u = await
|
|
985
|
+
u = await tt(n, t.models.face, t.models.faceConfidence), d = "loaded";
|
|
986
986
|
} catch (e) {
|
|
987
|
-
|
|
987
|
+
f = e instanceof Error ? e.message : "The face model could not load.", d = "failed";
|
|
988
988
|
}
|
|
989
989
|
if (l === "unmatched") return {
|
|
990
990
|
...c,
|
|
@@ -994,9 +994,9 @@ async function wt(e, t) {
|
|
|
994
994
|
modelError: s,
|
|
995
995
|
faces: u,
|
|
996
996
|
faceStatus: d,
|
|
997
|
-
faceError:
|
|
997
|
+
faceError: f
|
|
998
998
|
};
|
|
999
|
-
let
|
|
999
|
+
let p = await P(n, [...c.matches.map((e) => ({
|
|
1000
1000
|
...e.bbox,
|
|
1001
1001
|
mode: t.style?.mode
|
|
1002
1002
|
})), ...u.map((e) => ({
|
|
@@ -1007,16 +1007,16 @@ async function wt(e, t) {
|
|
|
1007
1007
|
...c,
|
|
1008
1008
|
status: l,
|
|
1009
1009
|
ocr: r,
|
|
1010
|
-
canvas:
|
|
1011
|
-
blob:
|
|
1010
|
+
canvas: p.canvas,
|
|
1011
|
+
blob: p.blob,
|
|
1012
1012
|
modelStatus: o,
|
|
1013
1013
|
modelError: s,
|
|
1014
1014
|
faces: u,
|
|
1015
1015
|
faceStatus: d,
|
|
1016
|
-
faceError:
|
|
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
|