@exige/web-scanner-sdk 0.2.27 → 0.2.29
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 +4 -4
- package/dist/assets/document-worker.js +1 -1
- package/dist/assets/document-worker.js.map +1 -1
- package/dist/assets/zxing-wasm.LICENSE +21 -0
- package/dist/assets/zxing-wasm.NOTICE +4 -0
- package/dist/assets/zxing_reader.wasm +0 -0
- package/dist/assets-manifest.json +2 -1
- package/dist/driver-license-CKMrW8dP.js +2876 -0
- package/dist/driver-license-CKMrW8dP.js.map +1 -0
- package/dist/index.d.ts +7 -1
- package/dist/react/context.d.ts +1 -1
- package/dist/react/types.d.ts +28 -2
- package/dist/react.d.ts +1 -1
- package/dist/react.js +435 -342
- package/dist/react.js.map +1 -1
- package/dist/scanner-sdk.js +17 -924
- package/dist/scanner-sdk.js.map +1 -1
- package/dist/sdk/aamva.d.ts +58 -0
- package/dist/sdk/barcode.d.ts +12 -0
- package/dist/sdk/camera.d.ts +8 -1
- package/dist/sdk/driver-license.d.ts +63 -0
- 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/dist/sdk/zxing-runtime.d.ts +22 -0
- package/package.json +4 -2
- package/dist/finder-BlN89ZeT.js +0 -1484
- package/dist/finder-BlN89ZeT.js.map +0 -1
|
@@ -0,0 +1,2876 @@
|
|
|
1
|
+
//#region src/sdk/errors.ts
|
|
2
|
+
var e = class extends Error {
|
|
3
|
+
code;
|
|
4
|
+
constructor(e, t) {
|
|
5
|
+
super(t), this.name = "ScannerError", this.code = e;
|
|
6
|
+
}
|
|
7
|
+
};
|
|
8
|
+
function t() {
|
|
9
|
+
return new e("canvas", "Canvas 2D is unavailable in this browser.");
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region src/sdk/license-codec.ts
|
|
13
|
+
function n(e) {
|
|
14
|
+
let t = e.replaceAll("-", "+").replaceAll("_", "/"), n = t + "=".repeat((4 - t.length % 4) % 4), r = atob(n), i = new Uint8Array(r.length);
|
|
15
|
+
for (let e = 0; e < r.length; e += 1) i[e] = r.charCodeAt(e);
|
|
16
|
+
return i;
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region src/sdk/license-public-key.ts
|
|
20
|
+
var r = "uFpA_UXGk-1AjjG31cFP6cqXOQX0w2TnuR7Bl-msZ6I";
|
|
21
|
+
//#endregion
|
|
22
|
+
//#region src/sdk/license-runtime.ts
|
|
23
|
+
function i() {
|
|
24
|
+
return n(r);
|
|
25
|
+
}
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region src/sdk/license.ts
|
|
28
|
+
var a = [
|
|
29
|
+
"localhost",
|
|
30
|
+
"127.0.0.1",
|
|
31
|
+
"exige-scanner-sdk.vercel.app",
|
|
32
|
+
"*.localhost",
|
|
33
|
+
"*.exige.io",
|
|
34
|
+
"*.ngrok.io",
|
|
35
|
+
"*.ngrok.app",
|
|
36
|
+
"*.ngrok.dev",
|
|
37
|
+
"*.ngrok-free.app",
|
|
38
|
+
"*.ngrok-free.dev"
|
|
39
|
+
], o = class extends Error {
|
|
40
|
+
code;
|
|
41
|
+
constructor(e, t) {
|
|
42
|
+
super(t), this.name = "LicenseError", this.code = e;
|
|
43
|
+
}
|
|
44
|
+
}, s, c;
|
|
45
|
+
function l(e) {
|
|
46
|
+
return e.trim().toLowerCase().replace(/\.$/u, "");
|
|
47
|
+
}
|
|
48
|
+
function u() {
|
|
49
|
+
let e = globalThis.location?.hostname;
|
|
50
|
+
if (typeof e == "string") return l(e) || void 0;
|
|
51
|
+
}
|
|
52
|
+
function d() {
|
|
53
|
+
return Math.floor(Date.now() / 1e3);
|
|
54
|
+
}
|
|
55
|
+
function f(e, t) {
|
|
56
|
+
let n = l(t);
|
|
57
|
+
if (n.startsWith("*.")) {
|
|
58
|
+
let t = n.slice(2), r = t === "localhost";
|
|
59
|
+
return !t.includes(".") && !r || t.startsWith(".") || t.includes("*") ? !1 : e === t || e.endsWith(`.${t}`);
|
|
60
|
+
}
|
|
61
|
+
return e === n;
|
|
62
|
+
}
|
|
63
|
+
function p(e) {
|
|
64
|
+
let t = l(e);
|
|
65
|
+
return !t || t.includes("*") ? !1 : a.some((e) => f(t, e));
|
|
66
|
+
}
|
|
67
|
+
function m(e) {
|
|
68
|
+
return {
|
|
69
|
+
customerId: "dev",
|
|
70
|
+
domains: [e],
|
|
71
|
+
exp: 4102444800,
|
|
72
|
+
features: {
|
|
73
|
+
scan: !0,
|
|
74
|
+
ocr: !0,
|
|
75
|
+
redaction: !0,
|
|
76
|
+
vehicles: !0,
|
|
77
|
+
torch: !0
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function h(e) {
|
|
82
|
+
return {
|
|
83
|
+
customerId: e.customerId,
|
|
84
|
+
domains: [...e.domains],
|
|
85
|
+
exp: e.exp,
|
|
86
|
+
features: { ...e.features }
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
function g(e = "This license key is not a signed payload.") {
|
|
90
|
+
return new o("malformed", e);
|
|
91
|
+
}
|
|
92
|
+
function _(e) {
|
|
93
|
+
if (!e || typeof e != "object" || Array.isArray(e)) throw g();
|
|
94
|
+
let t = e;
|
|
95
|
+
if (typeof t.customerId != "string" || t.customerId.trim() === "" || t.customerId.length > 200) throw g("This license key is missing a customer id.");
|
|
96
|
+
if (!Array.isArray(t.domains) || t.domains.some((e) => typeof e != "string")) throw g("This license key is missing a domain list.");
|
|
97
|
+
if (typeof t.exp != "number" || !Number.isSafeInteger(t.exp) || t.exp <= 0) throw g("This license key is missing a Unix expiry.");
|
|
98
|
+
if (!t.features || typeof t.features != "object" || Array.isArray(t.features)) throw g("This license key is missing feature flags.");
|
|
99
|
+
let n = t.features, r = [...new Set(t.domains.map((e) => l(e)).filter(Boolean))].sort();
|
|
100
|
+
return {
|
|
101
|
+
customerId: t.customerId.trim(),
|
|
102
|
+
domains: r,
|
|
103
|
+
exp: t.exp,
|
|
104
|
+
features: {
|
|
105
|
+
scan: n.scan === !0,
|
|
106
|
+
ocr: n.ocr === !0,
|
|
107
|
+
redaction: n.redaction === !0,
|
|
108
|
+
vehicles: n.vehicles === !0,
|
|
109
|
+
torch: n.torch === !0
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
async function v(e, t) {
|
|
114
|
+
let r = e.trim().split(".");
|
|
115
|
+
if (r.length !== 2 || !r[0] || !r[1]) throw g();
|
|
116
|
+
let i, a;
|
|
117
|
+
try {
|
|
118
|
+
i = n(r[0]), a = n(r[1]);
|
|
119
|
+
} catch {
|
|
120
|
+
throw g();
|
|
121
|
+
}
|
|
122
|
+
let s, c = !1;
|
|
123
|
+
try {
|
|
124
|
+
s = await crypto.subtle.importKey("raw", t.publicKey, { name: "Ed25519" }, !1, ["verify"]), c = await crypto.subtle.verify("Ed25519", s, a, i);
|
|
125
|
+
} catch {
|
|
126
|
+
c = !1;
|
|
127
|
+
}
|
|
128
|
+
if (!c) throw new o("invalid-signature", "This license key signature does not match the SDK public key.");
|
|
129
|
+
let u;
|
|
130
|
+
try {
|
|
131
|
+
u = JSON.parse(new TextDecoder().decode(i));
|
|
132
|
+
} catch {
|
|
133
|
+
throw g();
|
|
134
|
+
}
|
|
135
|
+
let d = _(u);
|
|
136
|
+
if (d.exp <= t.now) throw new o("expired", "This license key has expired.");
|
|
137
|
+
let f = l(t.hostname);
|
|
138
|
+
if (!f || !d.domains.includes(f)) throw new o("domain", `This license key is not valid for ${f || "this host"}.`);
|
|
139
|
+
return d;
|
|
140
|
+
}
|
|
141
|
+
async function y(e) {
|
|
142
|
+
let t = u();
|
|
143
|
+
if (!t) throw new o("domain", "The license check requires a browser hostname.");
|
|
144
|
+
let n = await v(e, {
|
|
145
|
+
publicKey: i(),
|
|
146
|
+
hostname: t,
|
|
147
|
+
now: d()
|
|
148
|
+
});
|
|
149
|
+
return s = e.trim(), c = n, h(n);
|
|
150
|
+
}
|
|
151
|
+
function b() {
|
|
152
|
+
let e = u();
|
|
153
|
+
return c && e && c.domains.includes(e) && c.exp > d() ? h(c) : !s && e && p(e) ? h(m(e)) : null;
|
|
154
|
+
}
|
|
155
|
+
async function x(e) {
|
|
156
|
+
let t = u();
|
|
157
|
+
if (!t) throw new o("domain", "The license check requires a browser hostname.");
|
|
158
|
+
if (!s) {
|
|
159
|
+
if (p(t)) return h(m(t));
|
|
160
|
+
throw new o("missing", "A license key is required. Call setLicenseKey() before using the scanner SDK.");
|
|
161
|
+
}
|
|
162
|
+
let n = await v(s, {
|
|
163
|
+
publicKey: i(),
|
|
164
|
+
hostname: t,
|
|
165
|
+
now: d()
|
|
166
|
+
});
|
|
167
|
+
if (c = n, !n.features[e]) throw new o("feature", `This license key does not include the ${e} feature.`);
|
|
168
|
+
return h(n);
|
|
169
|
+
}
|
|
170
|
+
//#endregion
|
|
171
|
+
//#region src/sdk/model-download.ts
|
|
172
|
+
var S = Symbol.for("exige.web-scanner-sdk.model-downloads");
|
|
173
|
+
function C() {
|
|
174
|
+
let e = globalThis;
|
|
175
|
+
return e[S] || (e[S] = {
|
|
176
|
+
active: /* @__PURE__ */ new Map(),
|
|
177
|
+
listeners: /* @__PURE__ */ new Set(),
|
|
178
|
+
cache: /* @__PURE__ */ new Map(),
|
|
179
|
+
inflight: /* @__PURE__ */ new Map()
|
|
180
|
+
}), e[S];
|
|
181
|
+
}
|
|
182
|
+
var w = C().active, T = C().listeners, E = C().cache, D = C().inflight;
|
|
183
|
+
function ee(e) {
|
|
184
|
+
let t = Number(e.headers.get("content-length"));
|
|
185
|
+
return Number.isFinite(t) && t > 0 ? t : null;
|
|
186
|
+
}
|
|
187
|
+
function te() {
|
|
188
|
+
if (w.size === 0) return {
|
|
189
|
+
downloading: !1,
|
|
190
|
+
loaded: 0,
|
|
191
|
+
total: null
|
|
192
|
+
};
|
|
193
|
+
let e = 0, t = 0, n = !0;
|
|
194
|
+
for (let r of w.values()) e += r.loaded, r.total == null ? n = !1 : t += r.total;
|
|
195
|
+
return {
|
|
196
|
+
downloading: !0,
|
|
197
|
+
loaded: e,
|
|
198
|
+
total: n ? t : null
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
function ne() {
|
|
202
|
+
let e = te();
|
|
203
|
+
for (let t of T) t(e);
|
|
204
|
+
}
|
|
205
|
+
function re(e) {
|
|
206
|
+
return e(te()), T.add(e), () => {
|
|
207
|
+
T.delete(e);
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
function O(e, t) {
|
|
211
|
+
t.done ? w.delete(e) : w.set(e, {
|
|
212
|
+
loaded: t.loaded,
|
|
213
|
+
total: t.total
|
|
214
|
+
}), ne();
|
|
215
|
+
}
|
|
216
|
+
async function ie(e, t) {
|
|
217
|
+
let n = ee(e);
|
|
218
|
+
if (!e.body) {
|
|
219
|
+
let r = await e.arrayBuffer();
|
|
220
|
+
return t?.({
|
|
221
|
+
loaded: r.byteLength,
|
|
222
|
+
total: n ?? r.byteLength
|
|
223
|
+
}), r;
|
|
224
|
+
}
|
|
225
|
+
let r = e.body.getReader(), i = [], a = 0;
|
|
226
|
+
for (;;) {
|
|
227
|
+
let { done: e, value: o } = await r.read();
|
|
228
|
+
if (e) break;
|
|
229
|
+
o?.byteLength && (i.push(o), a += o.byteLength, t?.({
|
|
230
|
+
loaded: a,
|
|
231
|
+
total: n
|
|
232
|
+
}));
|
|
233
|
+
}
|
|
234
|
+
let o = new Uint8Array(a), s = 0;
|
|
235
|
+
for (let e of i) o.set(e, s), s += e.byteLength;
|
|
236
|
+
return a === 0 && t?.({
|
|
237
|
+
loaded: 0,
|
|
238
|
+
total: n
|
|
239
|
+
}), o.buffer;
|
|
240
|
+
}
|
|
241
|
+
async function ae(t, n) {
|
|
242
|
+
let r = E.get(t);
|
|
243
|
+
if (r) return r.slice(0);
|
|
244
|
+
let i = D.get(t);
|
|
245
|
+
if (i) return i.then((e) => e.slice(0));
|
|
246
|
+
let a = (async () => {
|
|
247
|
+
O(t, {
|
|
248
|
+
loaded: 0,
|
|
249
|
+
total: null
|
|
250
|
+
});
|
|
251
|
+
let r = await fetch(t, { cache: n?.cache });
|
|
252
|
+
if (!r.ok) throw new e("model-http", `Model request failed with HTTP ${r.status}.`);
|
|
253
|
+
return ie(r, (e) => O(t, e));
|
|
254
|
+
})();
|
|
255
|
+
D.set(t, a);
|
|
256
|
+
try {
|
|
257
|
+
let e = await a;
|
|
258
|
+
return E.set(t, e), e.slice(0);
|
|
259
|
+
} finally {
|
|
260
|
+
D.delete(t), w.has(t) && (w.delete(t), ne());
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
//#endregion
|
|
264
|
+
//#region src/sdk/camera.ts
|
|
265
|
+
function oe(e, t) {
|
|
266
|
+
let { engine: n } = t;
|
|
267
|
+
return [
|
|
268
|
+
`${e}:`,
|
|
269
|
+
` engine: ${n.engine}/${n.browser}${n.iosWebKit ? " ios-webkit" : ""}`,
|
|
270
|
+
` ua: ${n.userAgent}`,
|
|
271
|
+
` video: ${t.videoWidth}x${t.videoHeight} readyState=${t.readyState}${t.paused ? " paused" : ""}${t.rendered ? "" : " hidden"}${t.connected ? "" : " disconnected"}`,
|
|
272
|
+
` track: ${t.trackReadyState}${t.trackEnabled ? "" : " disabled"}${t.trackMuted ? " muted" : ""}`,
|
|
273
|
+
` liveLuma: ${t.liveLuminance.toFixed(1)}`,
|
|
274
|
+
` mirrorLuma: ${t.mirrorLuminance.toFixed(1)}`,
|
|
275
|
+
` mirrorAgeMs: ${Number.isFinite(t.mirrorAgeMs) ? Math.round(t.mirrorAgeMs) : "none"}`,
|
|
276
|
+
` hasImageCapture: ${t.hasImageCapture}${t.engine.iosWebKit ? " (skipped on webkit)" : " (still capture)"}`,
|
|
277
|
+
` torch: ${t.torch.mode} supported=${t.torch.supported} on=${t.torch.on}`
|
|
278
|
+
].join("\n");
|
|
279
|
+
}
|
|
280
|
+
function se(e) {
|
|
281
|
+
let t = ["Exige scanner capture report", `time: ${e.capturedAt ?? (/* @__PURE__ */ new Date()).toISOString()}`];
|
|
282
|
+
if (e.error && t.push(`error: ${e.error}`), e.captureMethod && t.push(`method: ${e.captureMethod}`), e.luminance !== void 0 && t.push(`luminance: ${e.luminance.toFixed(1)}`), e.fallbackReason && t.push(`fallback: ${e.fallbackReason}`), e.shutter && t.push(oe("shutter", e.shutter)), e.live && t.push(oe("live", e.live)), e.finder) {
|
|
283
|
+
let n = e.finder;
|
|
284
|
+
t.push([
|
|
285
|
+
"finder:",
|
|
286
|
+
` state: ${n.state ?? "unknown"}`,
|
|
287
|
+
` confidence: ${n.confidence === void 0 ? "—" : n.confidence.toFixed(3)}`,
|
|
288
|
+
` stable: ${n.stableFrames ?? "—"}/${n.requiredStableFrames ?? "—"}`,
|
|
289
|
+
` detector: ${n.detector ?? "—"} ${n.modelStatus ?? ""}`.trim(),
|
|
290
|
+
` modelError: ${n.modelError ?? "—"}`,
|
|
291
|
+
` provider: ${n.modelProvider ?? "—"}`,
|
|
292
|
+
` note: ${n.modelNote ?? "—"}`,
|
|
293
|
+
` inferenceMs: ${n.inferenceMs === void 0 ? "—" : Math.round(n.inferenceMs)}`,
|
|
294
|
+
` source: ${n.sourceWidth ?? "—"}x${n.sourceHeight ?? "—"}`
|
|
295
|
+
].join("\n"));
|
|
296
|
+
}
|
|
297
|
+
return `${t.join("\n")}\n`;
|
|
298
|
+
}
|
|
299
|
+
function k(e = typeof navigator > "u" ? "" : navigator.userAgent, t = typeof navigator > "u" ? 0 : navigator.maxTouchPoints) {
|
|
300
|
+
let n = /CriOS|Chrome/i.test(e) ? "chrome" : /EdgiOS|Edg/i.test(e) ? "edge" : /FxiOS|Firefox/i.test(e) ? "firefox" : /Safari/i.test(e) ? "safari" : "unknown", r = /iPhone|iPad|iPod/i.test(e) || /Macintosh/i.test(e) && t > 1, i = /CriOS|EdgiOS|FxiOS|OPiOS|Mercury/i.test(e), a = r || i;
|
|
301
|
+
return {
|
|
302
|
+
engine: a || /AppleWebKit/i.test(e) && !/Chrome|Chromium|Edg/i.test(e) ? "webkit" : /Chrome|Chromium|Edg/i.test(e) ? "blink" : /Gecko\//i.test(e) ? "gecko" : "unknown",
|
|
303
|
+
browser: n,
|
|
304
|
+
iosWebKit: a,
|
|
305
|
+
userAgent: e
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
function A(e) {
|
|
309
|
+
return /Android/i.test(e.userAgent) && !e.iosWebKit;
|
|
310
|
+
}
|
|
311
|
+
function ce(e = k()) {
|
|
312
|
+
return e.engine === "webkit" && !A(e);
|
|
313
|
+
}
|
|
314
|
+
function le(e = "auto", t = k()) {
|
|
315
|
+
return e === "system-camera" || e !== "live" && A(t);
|
|
316
|
+
}
|
|
317
|
+
function ue(e, t) {
|
|
318
|
+
return t && !e.iosWebKit;
|
|
319
|
+
}
|
|
320
|
+
function de(e, t) {
|
|
321
|
+
if (!e || !Number.isFinite(e)) return;
|
|
322
|
+
let n = t?.max;
|
|
323
|
+
if (!n || !Number.isFinite(n)) return Math.round(e);
|
|
324
|
+
let r = t?.min && Number.isFinite(t.min) ? t.min : 1, i = t?.step && t.step > 0 ? t.step : 1, a = r + Math.round((Math.min(n, Math.max(r, e)) - r) / i) * i;
|
|
325
|
+
return Math.round(Math.min(n, Math.max(r, a)));
|
|
326
|
+
}
|
|
327
|
+
function fe(e) {
|
|
328
|
+
let t = de(e?.imageWidth?.max ?? 0, e?.imageWidth), n = de(e?.imageHeight?.max ?? 0, e?.imageHeight);
|
|
329
|
+
if (t && n) return t >= n ? { imageWidth: t } : { imageHeight: n };
|
|
330
|
+
if (t) return { imageWidth: t };
|
|
331
|
+
if (n) return { imageHeight: n };
|
|
332
|
+
}
|
|
333
|
+
function pe(e, t) {
|
|
334
|
+
return !e.width || !e.height || !t.width || !t.height ? !1 : e.width * e.height > t.width * t.height * 1.15;
|
|
335
|
+
}
|
|
336
|
+
function me(e, t) {
|
|
337
|
+
if (!e.width || !e.height || !t.width || !t.height) return !1;
|
|
338
|
+
let n = e.width / e.height / (t.width / t.height);
|
|
339
|
+
return n > .97 && n < 1.03;
|
|
340
|
+
}
|
|
341
|
+
var he = 10, ge = class {
|
|
342
|
+
on = !1;
|
|
343
|
+
darkCount = 0;
|
|
344
|
+
brightCount = 0;
|
|
345
|
+
turnOnLuminance;
|
|
346
|
+
turnOffLuminance;
|
|
347
|
+
darkSamples;
|
|
348
|
+
brightSamples;
|
|
349
|
+
constructor(e = {}) {
|
|
350
|
+
this.turnOnLuminance = e.turnOnLuminance ?? 62, this.turnOffLuminance = e.turnOffLuminance ?? 155, this.darkSamples = e.darkSamples ?? 3, this.brightSamples = e.brightSamples ?? 8;
|
|
351
|
+
}
|
|
352
|
+
update(e) {
|
|
353
|
+
if (!Number.isFinite(e) || e <= 10) {
|
|
354
|
+
this.darkCount = 0, this.brightCount = 0;
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
357
|
+
if (!this.on) return this.brightCount = 0, this.darkCount = e <= this.turnOnLuminance ? this.darkCount + 1 : 0, this.darkCount < this.darkSamples ? void 0 : (this.darkCount = 0, this.on = !0, !0);
|
|
358
|
+
if (this.darkCount = 0, this.brightCount = e >= this.turnOffLuminance ? this.brightCount + 1 : 0, !(this.brightCount < this.brightSamples)) return this.brightCount = 0, this.on = !1, !1;
|
|
359
|
+
}
|
|
360
|
+
getState() {
|
|
361
|
+
return this.on;
|
|
362
|
+
}
|
|
363
|
+
};
|
|
364
|
+
function _e(e, t) {
|
|
365
|
+
return t ? e === "alwaysOn" || e === "alwaysOff" ? {
|
|
366
|
+
mode: e,
|
|
367
|
+
supported: !0,
|
|
368
|
+
on: e === "alwaysOn",
|
|
369
|
+
visible: !1,
|
|
370
|
+
mutable: !1,
|
|
371
|
+
automatic: !1
|
|
372
|
+
} : {
|
|
373
|
+
mode: e,
|
|
374
|
+
supported: !0,
|
|
375
|
+
on: e === "defaultOn",
|
|
376
|
+
visible: !0,
|
|
377
|
+
mutable: e !== "auto",
|
|
378
|
+
automatic: e === "auto"
|
|
379
|
+
} : {
|
|
380
|
+
mode: e,
|
|
381
|
+
supported: !1,
|
|
382
|
+
on: !1,
|
|
383
|
+
visible: !1,
|
|
384
|
+
mutable: !1,
|
|
385
|
+
automatic: e === "auto"
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
function j(e) {
|
|
389
|
+
let t = Math.floor(e.length / 4);
|
|
390
|
+
if (!t) return 0;
|
|
391
|
+
let n = 0;
|
|
392
|
+
for (let r = 0; r < t * 4; r += 4) n += e[r] * .299 + e[r + 1] * .587 + e[r + 2] * .114;
|
|
393
|
+
return n / t;
|
|
394
|
+
}
|
|
395
|
+
function ve(e, t = 10) {
|
|
396
|
+
if (e.length < 4) return !0;
|
|
397
|
+
let n = Math.floor(e.length / 4), r = 0;
|
|
398
|
+
for (let i = 0; i < n * 4; i += 4) e[i] * .299 + e[i + 1] * .587 + e[i + 2] * .114 > t * 2 && (r += 1);
|
|
399
|
+
return j(e) <= t && r / n < .01;
|
|
400
|
+
}
|
|
401
|
+
function ye(e, t, n) {
|
|
402
|
+
if (!t || !n) return 0;
|
|
403
|
+
let r = document.createElement("canvas");
|
|
404
|
+
r.width = Math.min(32, t), r.height = Math.min(32, n);
|
|
405
|
+
let i = r.getContext("2d", { willReadFrequently: !0 });
|
|
406
|
+
return i ? (i.drawImage(e, 0, 0, r.width, r.height), j(i.getImageData(0, 0, r.width, r.height).data)) : 0;
|
|
407
|
+
}
|
|
408
|
+
function be(e) {
|
|
409
|
+
return ye(e, e.width, e.height);
|
|
410
|
+
}
|
|
411
|
+
function xe(e, t = 120) {
|
|
412
|
+
let n = document.createElement("canvas"), r = n.getContext("2d"), i = typeof e.requestVideoFrameCallback == "function", a = !0, o = 0, s = 0, c = 0, l = 0, u = 0, d = () => {
|
|
413
|
+
a && (o = i ? e.requestVideoFrameCallback(f) : requestAnimationFrame(f));
|
|
414
|
+
};
|
|
415
|
+
function f() {
|
|
416
|
+
if (!a) return;
|
|
417
|
+
let { videoWidth: i, videoHeight: o } = e, f = performance.now();
|
|
418
|
+
r && i && o && f - s >= t && (s = f, l = ye(e, i, o), l > 10 && ((n.width !== i || n.height !== o) && (n.width = i, n.height = o), r.drawImage(e, 0, 0, i, o), u = l, c = f)), d();
|
|
419
|
+
}
|
|
420
|
+
return d(), {
|
|
421
|
+
stop() {
|
|
422
|
+
a = !1, i ? e.cancelVideoFrameCallback?.(o) : cancelAnimationFrame(o);
|
|
423
|
+
},
|
|
424
|
+
getFrame: () => c ? n : void 0,
|
|
425
|
+
getLiveLuminance: () => l,
|
|
426
|
+
getMirrorLuminance: () => u,
|
|
427
|
+
getMirrorAgeMs: () => c ? performance.now() - c : Infinity
|
|
428
|
+
};
|
|
429
|
+
}
|
|
430
|
+
function Se(e) {
|
|
431
|
+
let t = document.createElement("canvas");
|
|
432
|
+
return t.width = e.width, t.height = e.height, t.getContext("2d")?.drawImage(e, 0, 0), t;
|
|
433
|
+
}
|
|
434
|
+
function Ce(e) {
|
|
435
|
+
return e.engine === "blink";
|
|
436
|
+
}
|
|
437
|
+
function M(e = {}, t = k()) {
|
|
438
|
+
let n = { ideal: e.idealWidth ?? 3840 }, r = { ideal: e.idealHeight ?? 2160 };
|
|
439
|
+
e.maxWidth && (n.max = e.maxWidth), e.maxHeight && (r.max = e.maxHeight);
|
|
440
|
+
let i = {
|
|
441
|
+
facingMode: { ideal: e.facingMode ?? "environment" },
|
|
442
|
+
width: n,
|
|
443
|
+
height: r,
|
|
444
|
+
frameRate: {
|
|
445
|
+
ideal: e.maxFrameRate ?? 30,
|
|
446
|
+
max: e.maxFrameRate ?? 30
|
|
447
|
+
}
|
|
448
|
+
};
|
|
449
|
+
return Ce(t) && (i.resizeMode = { ideal: "none" }), {
|
|
450
|
+
audio: !1,
|
|
451
|
+
video: i
|
|
452
|
+
};
|
|
453
|
+
}
|
|
454
|
+
function we(e, t, n) {
|
|
455
|
+
let r = n ? Math.min(1, n / Math.max(e, t)) : 1;
|
|
456
|
+
return {
|
|
457
|
+
width: Math.max(1, Math.round(e * r)),
|
|
458
|
+
height: Math.max(1, Math.round(t * r))
|
|
459
|
+
};
|
|
460
|
+
}
|
|
461
|
+
var Te = 4096;
|
|
462
|
+
function Ee(e, t) {
|
|
463
|
+
let n = e.width, r = e.height, i = t?.width?.max, a = t?.height?.max;
|
|
464
|
+
if (!n || !r || !i || !a) return;
|
|
465
|
+
let o = Math.min(i / n, a / r);
|
|
466
|
+
if (!(o <= 1.05)) return {
|
|
467
|
+
width: { ideal: Math.round(n * o) },
|
|
468
|
+
height: { ideal: Math.round(r * o) }
|
|
469
|
+
};
|
|
470
|
+
}
|
|
471
|
+
async function De(e) {
|
|
472
|
+
let t = Ee(e.getSettings(), typeof e.getCapabilities == "function" ? e.getCapabilities() : void 0);
|
|
473
|
+
if (t) try {
|
|
474
|
+
await e.applyConstraints(t);
|
|
475
|
+
} catch {}
|
|
476
|
+
}
|
|
477
|
+
async function Oe(e) {
|
|
478
|
+
try {
|
|
479
|
+
return await createImageBitmap(e, {
|
|
480
|
+
imageOrientation: "from-image",
|
|
481
|
+
colorSpaceConversion: "none"
|
|
482
|
+
});
|
|
483
|
+
} catch {
|
|
484
|
+
return await createImageBitmap(e);
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
async function ke(e) {
|
|
488
|
+
try {
|
|
489
|
+
await e.applyConstraints({ advanced: [{ pointsOfInterest: [{
|
|
490
|
+
x: .5,
|
|
491
|
+
y: .5
|
|
492
|
+
}] }] }), await new Promise((e) => window.setTimeout(e, 180));
|
|
493
|
+
} catch {}
|
|
494
|
+
}
|
|
495
|
+
async function Ae(e) {
|
|
496
|
+
let n = await Oe(e), r = we(n.width, n.height, Te), i = document.createElement("canvas");
|
|
497
|
+
i.width = r.width, i.height = r.height;
|
|
498
|
+
let a = i.getContext("2d");
|
|
499
|
+
if (!a) throw n.close?.(), t();
|
|
500
|
+
return a.imageSmoothingEnabled = r.width !== n.width || r.height !== n.height, a.imageSmoothingQuality = "high", a.drawImage(n, 0, 0, i.width, i.height), n.close?.(), i;
|
|
501
|
+
}
|
|
502
|
+
async function je(e) {
|
|
503
|
+
let t = globalThis.ImageCapture;
|
|
504
|
+
if (!t) return;
|
|
505
|
+
await ke(e);
|
|
506
|
+
let n = new t(e), r = n.getPhotoCapabilities ? await n.getPhotoCapabilities() : void 0, i = fe(r), a;
|
|
507
|
+
try {
|
|
508
|
+
a = await n.takePhoto(i);
|
|
509
|
+
} catch {
|
|
510
|
+
a = await n.takePhoto();
|
|
511
|
+
}
|
|
512
|
+
return {
|
|
513
|
+
frame: await Ae(a),
|
|
514
|
+
requested: i,
|
|
515
|
+
photoMax: {
|
|
516
|
+
width: r?.imageWidth?.max,
|
|
517
|
+
height: r?.imageHeight?.max
|
|
518
|
+
}
|
|
519
|
+
};
|
|
520
|
+
}
|
|
521
|
+
function N(e, n) {
|
|
522
|
+
if (!e.videoWidth || !e.videoHeight) throw Error("The camera is not ready to capture a frame.");
|
|
523
|
+
let r = we(e.videoWidth, e.videoHeight, n), i = document.createElement("canvas");
|
|
524
|
+
i.width = r.width, i.height = r.height;
|
|
525
|
+
let a = i.getContext("2d");
|
|
526
|
+
if (!a) throw t();
|
|
527
|
+
return a.drawImage(e, 0, 0, i.width, i.height), i;
|
|
528
|
+
}
|
|
529
|
+
function Me(e) {
|
|
530
|
+
let t = k();
|
|
531
|
+
return e.idealWidth || e.idealHeight || e.maxWidth || e.maxHeight ? [M(e, t)] : [
|
|
532
|
+
M({
|
|
533
|
+
...e,
|
|
534
|
+
idealWidth: 3840,
|
|
535
|
+
idealHeight: 2160
|
|
536
|
+
}, t),
|
|
537
|
+
M({
|
|
538
|
+
...e,
|
|
539
|
+
idealWidth: 2560,
|
|
540
|
+
idealHeight: 1440
|
|
541
|
+
}, t),
|
|
542
|
+
M({
|
|
543
|
+
...e,
|
|
544
|
+
idealWidth: 1920,
|
|
545
|
+
idealHeight: 1080
|
|
546
|
+
}, t)
|
|
547
|
+
];
|
|
548
|
+
}
|
|
549
|
+
async function Ne(t, n = {}) {
|
|
550
|
+
await x("scan");
|
|
551
|
+
let r = n.torch ?? "alwaysOff";
|
|
552
|
+
if (r !== "alwaysOff" && await x("torch"), !window.isSecureContext && location.hostname !== "localhost") throw new e("secure-context", "Camera access requires HTTPS.");
|
|
553
|
+
if (!navigator.mediaDevices?.getUserMedia) throw Error("Live camera access is unavailable. Use the native camera picker instead.");
|
|
554
|
+
t.muted = !0, t.autoplay = !0, t.playsInline = !0, t.setAttribute("playsinline", "");
|
|
555
|
+
let i, a;
|
|
556
|
+
for (let e of Me(n)) try {
|
|
557
|
+
i = await navigator.mediaDevices.getUserMedia(e);
|
|
558
|
+
break;
|
|
559
|
+
} catch (e) {
|
|
560
|
+
if (a = e, !(e instanceof DOMException) || e.name !== "OverconstrainedError") throw e;
|
|
561
|
+
}
|
|
562
|
+
if (!i) throw a ?? /* @__PURE__ */ Error("No rear camera resolution is available.");
|
|
563
|
+
t.srcObject = i, await t.play();
|
|
564
|
+
let o = i.getVideoTracks()[0];
|
|
565
|
+
if (!o) {
|
|
566
|
+
for (let e of i.getTracks()) e.stop();
|
|
567
|
+
throw Error("The camera did not provide a video track.");
|
|
568
|
+
}
|
|
569
|
+
await De(o);
|
|
570
|
+
let s = xe(t), c = "ImageCapture" in globalThis, l = _e(r, (typeof o.getCapabilities == "function" ? o.getCapabilities() : void 0)?.torch === !0), u = !1, d = async (e) => {
|
|
571
|
+
if (!l.supported || o.readyState !== "live") return !1;
|
|
572
|
+
try {
|
|
573
|
+
return await o.applyConstraints({ advanced: [{ torch: e }] }), l = {
|
|
574
|
+
...l,
|
|
575
|
+
on: e
|
|
576
|
+
}, !0;
|
|
577
|
+
} catch {
|
|
578
|
+
return l = {
|
|
579
|
+
...l,
|
|
580
|
+
supported: !1,
|
|
581
|
+
on: !1,
|
|
582
|
+
visible: !1,
|
|
583
|
+
mutable: !1
|
|
584
|
+
}, !1;
|
|
585
|
+
}
|
|
586
|
+
};
|
|
587
|
+
l.on && await d(!0);
|
|
588
|
+
let f = r === "auto" && l.supported ? new ge() : void 0, p = f ? window.setInterval(() => {
|
|
589
|
+
if (u || !l.supported) return;
|
|
590
|
+
let e = f.update(s.getLiveLuminance());
|
|
591
|
+
e !== void 0 && e !== l.on && (u = !0, d(e).finally(() => {
|
|
592
|
+
u = !1;
|
|
593
|
+
}));
|
|
594
|
+
}, 350) : 0, m = () => {
|
|
595
|
+
let e = t.getBoundingClientRect();
|
|
596
|
+
return {
|
|
597
|
+
videoWidth: t.videoWidth,
|
|
598
|
+
videoHeight: t.videoHeight,
|
|
599
|
+
readyState: t.readyState,
|
|
600
|
+
paused: t.paused,
|
|
601
|
+
connected: t.isConnected,
|
|
602
|
+
rendered: e.width > 0 && e.height > 0,
|
|
603
|
+
trackReadyState: o.readyState ?? "missing",
|
|
604
|
+
trackEnabled: o.enabled,
|
|
605
|
+
trackMuted: o.muted,
|
|
606
|
+
liveLuminance: s.getLiveLuminance(),
|
|
607
|
+
mirrorLuminance: s.getMirrorLuminance(),
|
|
608
|
+
mirrorAgeMs: s.getMirrorAgeMs(),
|
|
609
|
+
hasImageCapture: c,
|
|
610
|
+
torchMode: l.mode,
|
|
611
|
+
torchSupported: l.supported,
|
|
612
|
+
torchOn: l.on,
|
|
613
|
+
torch: { ...l },
|
|
614
|
+
engine: k()
|
|
615
|
+
};
|
|
616
|
+
};
|
|
617
|
+
return {
|
|
618
|
+
stream: i,
|
|
619
|
+
get torchMode() {
|
|
620
|
+
return l.mode;
|
|
621
|
+
},
|
|
622
|
+
get torchSupported() {
|
|
623
|
+
return l.supported;
|
|
624
|
+
},
|
|
625
|
+
get torchOn() {
|
|
626
|
+
return l.on;
|
|
627
|
+
},
|
|
628
|
+
capture: (e) => N(t, e),
|
|
629
|
+
async capturePhoto() {
|
|
630
|
+
let e, n = 0;
|
|
631
|
+
try {
|
|
632
|
+
e = N(t), n = be(e);
|
|
633
|
+
} catch {
|
|
634
|
+
e = void 0;
|
|
635
|
+
}
|
|
636
|
+
let r = s.getFrame(), i, a = !1, l = !1, u, d;
|
|
637
|
+
if (ue(k(), c)) try {
|
|
638
|
+
let e = await je(o);
|
|
639
|
+
i = e?.frame, u = e?.requested, d = e?.photoMax;
|
|
640
|
+
} catch {
|
|
641
|
+
a = !0, i = void 0;
|
|
642
|
+
}
|
|
643
|
+
let f = {
|
|
644
|
+
width: t.videoWidth,
|
|
645
|
+
height: t.videoHeight
|
|
646
|
+
}, p = i ? be(i) : 0, h = !!(i && p > 10 && pe(i, f));
|
|
647
|
+
if (i && p > 10 && !h && (l = !0), h && i) return console.info("[exige-scanner] capture", {
|
|
648
|
+
method: "image-capture",
|
|
649
|
+
frame: `${i.width}×${i.height}`,
|
|
650
|
+
video: `${t.videoWidth}×${t.videoHeight}`,
|
|
651
|
+
photoMax: d ? `${d.width ?? "—"}×${d.height ?? "—"}` : void 0,
|
|
652
|
+
photoRequest: u,
|
|
653
|
+
aspectMatch: me(i, f)
|
|
654
|
+
}), {
|
|
655
|
+
frame: i,
|
|
656
|
+
method: "image-capture",
|
|
657
|
+
settings: o.getSettings(),
|
|
658
|
+
luminance: p,
|
|
659
|
+
diagnostics: m()
|
|
660
|
+
};
|
|
661
|
+
let g = e && n > 10 ? e : void 0, _ = g ?? (r ? Se(r) : void 0);
|
|
662
|
+
if (!_) throw Error("The camera preview produced no visible pixels. Keep the scanner on screen, wait for the preview, and retake.");
|
|
663
|
+
let v = l ? "image-capture-preview-size" : i ? "image-capture-empty" : a ? "image-capture-failed" : g ? void 0 : "video-frame-empty";
|
|
664
|
+
return console.info("[exige-scanner] capture", {
|
|
665
|
+
method: g ? "video-frame" : "live-mirror",
|
|
666
|
+
frame: `${_.width}×${_.height}`,
|
|
667
|
+
video: `${t.videoWidth}×${t.videoHeight}`,
|
|
668
|
+
photoMax: d ? `${d.width ?? "—"}×${d.height ?? "—"}` : void 0,
|
|
669
|
+
photoRequest: u,
|
|
670
|
+
fallbackReason: v
|
|
671
|
+
}), {
|
|
672
|
+
frame: _,
|
|
673
|
+
method: g ? "video-frame" : "live-mirror",
|
|
674
|
+
settings: o.getSettings(),
|
|
675
|
+
fallbackReason: v,
|
|
676
|
+
luminance: g ? n : s.getMirrorLuminance(),
|
|
677
|
+
diagnostics: m()
|
|
678
|
+
};
|
|
679
|
+
},
|
|
680
|
+
getSettings: () => o.getSettings(),
|
|
681
|
+
getDiagnostics: m,
|
|
682
|
+
getTorchStatus: () => ({ ...l }),
|
|
683
|
+
async setTorch(e) {
|
|
684
|
+
return l.mutable ? d(e) : !1;
|
|
685
|
+
},
|
|
686
|
+
stop() {
|
|
687
|
+
p && window.clearInterval(p), s.stop();
|
|
688
|
+
for (let e of i.getTracks()) e.stop();
|
|
689
|
+
t.srcObject === i && (t.srcObject = null);
|
|
690
|
+
}
|
|
691
|
+
};
|
|
692
|
+
}
|
|
693
|
+
function Pe() {
|
|
694
|
+
let e = typeof navigator > "u" ? void 0 : navigator.userActivation;
|
|
695
|
+
return !e || e.isActive;
|
|
696
|
+
}
|
|
697
|
+
async function Fe() {
|
|
698
|
+
let e = document.createElement("input");
|
|
699
|
+
return e.type = "file", e.accept = "image/*", e.capture = "environment", e.setAttribute("capture", "environment"), Ae(await new Promise((t, n) => {
|
|
700
|
+
e.addEventListener("change", () => {
|
|
701
|
+
let r = e.files?.[0];
|
|
702
|
+
r ? t(r) : n(/* @__PURE__ */ Error("No photo was selected."));
|
|
703
|
+
}, { once: !0 }), e.addEventListener("cancel", () => {
|
|
704
|
+
n(/* @__PURE__ */ Error("No photo was selected."));
|
|
705
|
+
}, { once: !0 }), e.click();
|
|
706
|
+
}));
|
|
707
|
+
}
|
|
708
|
+
//#endregion
|
|
709
|
+
//#region src/sdk/ort-cdn.ts
|
|
710
|
+
var Ie = "1.30.0";
|
|
711
|
+
`${Ie}`, `${Ie}`;
|
|
712
|
+
function Le(e) {
|
|
713
|
+
return !e.ok && e.status !== 206 ? !1 : !(e.headers.get("content-type") ?? "").toLowerCase().includes("text/html");
|
|
714
|
+
}
|
|
715
|
+
async function Re(e, t = fetch) {
|
|
716
|
+
if (!e) return !1;
|
|
717
|
+
try {
|
|
718
|
+
let n = await t(e, { method: "HEAD" });
|
|
719
|
+
if (Le(n)) return !0;
|
|
720
|
+
if (n.status === 404 || n.status === 410) return !1;
|
|
721
|
+
} catch {}
|
|
722
|
+
try {
|
|
723
|
+
return Le(await t(e, {
|
|
724
|
+
method: "GET",
|
|
725
|
+
headers: { Range: "bytes=0-63" }
|
|
726
|
+
}));
|
|
727
|
+
} catch {
|
|
728
|
+
return !1;
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
//#endregion
|
|
732
|
+
//#region src/sdk/ort-runtime.ts
|
|
733
|
+
var ze = new URL("./assets/ort-wasm-simd-threaded.jsep.wasm", import.meta.url), Be = new URL("./assets/ort-wasm-simd-threaded.jsep.mjs", import.meta.url);
|
|
734
|
+
function Ve() {
|
|
735
|
+
return {
|
|
736
|
+
wasm: ze.href,
|
|
737
|
+
mjs: Be.href
|
|
738
|
+
};
|
|
739
|
+
}
|
|
740
|
+
function He(e) {
|
|
741
|
+
return typeof e == "string" ? e.trim() || Ve() : e?.wasm.trim() && e.mjs.trim() ? {
|
|
742
|
+
wasm: e.wasm.trim(),
|
|
743
|
+
mjs: e.mjs.trim()
|
|
744
|
+
} : Ve();
|
|
745
|
+
}
|
|
746
|
+
//#endregion
|
|
747
|
+
//#region src/sdk/image.ts
|
|
748
|
+
function Ue(e, t, n) {
|
|
749
|
+
let r = n ? Math.min(1, n / Math.max(e, t)) : 1;
|
|
750
|
+
return {
|
|
751
|
+
width: Math.max(1, Math.round(e * r)),
|
|
752
|
+
height: Math.max(1, Math.round(t * r))
|
|
753
|
+
};
|
|
754
|
+
}
|
|
755
|
+
async function We(e) {
|
|
756
|
+
let t = URL.createObjectURL(e);
|
|
757
|
+
try {
|
|
758
|
+
let e = new Image();
|
|
759
|
+
return e.src = t, await e.decode(), e;
|
|
760
|
+
} finally {
|
|
761
|
+
URL.revokeObjectURL(t);
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
async function P(e, n = {}) {
|
|
765
|
+
if (e instanceof HTMLCanvasElement && n.cloneCanvas === !1 && !n.maxDimension) return e;
|
|
766
|
+
let r = document.createElement("canvas"), i = r.getContext("2d", { willReadFrequently: !0 });
|
|
767
|
+
if (!i) throw t();
|
|
768
|
+
if (e instanceof Blob) {
|
|
769
|
+
if ("createImageBitmap" in window) try {
|
|
770
|
+
let t = await createImageBitmap(e), a = Ue(t.width, t.height, n.maxDimension);
|
|
771
|
+
return r.width = a.width, r.height = a.height, i.drawImage(t, 0, 0, a.width, a.height), t.close(), r;
|
|
772
|
+
} catch {}
|
|
773
|
+
e = await We(e);
|
|
774
|
+
}
|
|
775
|
+
let a = e instanceof HTMLImageElement ? e.naturalWidth : e.width, o = e instanceof HTMLImageElement ? e.naturalHeight : e.height;
|
|
776
|
+
if (!a || !o) throw Error("The image has no readable dimensions.");
|
|
777
|
+
let s = Ue(a, o, n.maxDimension);
|
|
778
|
+
return r.width = s.width, r.height = s.height, i.drawImage(e, 0, 0, s.width, s.height), r;
|
|
779
|
+
}
|
|
780
|
+
function Ge(e, t = "image/png", n = .92) {
|
|
781
|
+
return new Promise((r, i) => e.toBlob((e) => e ? r(e) : i(/* @__PURE__ */ Error("Could not encode the image.")), t, n));
|
|
782
|
+
}
|
|
783
|
+
function Ke(e, t, n) {
|
|
784
|
+
let r = Math.max(0, Math.min(t, e.x)), i = Math.max(0, Math.min(n, e.y));
|
|
785
|
+
return {
|
|
786
|
+
x: r,
|
|
787
|
+
y: i,
|
|
788
|
+
width: Math.max(0, Math.min(t - r, e.width)),
|
|
789
|
+
height: Math.max(0, Math.min(n - i, e.height))
|
|
790
|
+
};
|
|
791
|
+
}
|
|
792
|
+
//#endregion
|
|
793
|
+
//#region src/sdk/scan.ts
|
|
794
|
+
var qe = "https://exige-scanner-sdk.vercel.app/models/docaligner-lcnet100-f4117b78.onnx", Je = 1280;
|
|
795
|
+
function Ye(e, t, n) {
|
|
796
|
+
if (n) return n;
|
|
797
|
+
let r = Math.max(e, t), i = r / Math.max(1, Math.min(e, t)), a = tt() ? 560 : 900;
|
|
798
|
+
return i >= 1.6 ? Math.min(r, Math.max(a, Je)) : a;
|
|
799
|
+
}
|
|
800
|
+
function Xe(e) {
|
|
801
|
+
return e?.trim() || "https://exige-scanner-sdk.vercel.app/models/docaligner-lcnet100-f4117b78.onnx";
|
|
802
|
+
}
|
|
803
|
+
var Ze = 3, F, Qe = 0, I = /* @__PURE__ */ new Map();
|
|
804
|
+
function L(e, t) {
|
|
805
|
+
return Math.hypot(e.x - t.x, e.y - t.y);
|
|
806
|
+
}
|
|
807
|
+
function $e(e) {
|
|
808
|
+
return {
|
|
809
|
+
...e,
|
|
810
|
+
edges: {
|
|
811
|
+
top: {
|
|
812
|
+
start: e.topLeft,
|
|
813
|
+
end: e.topRight
|
|
814
|
+
},
|
|
815
|
+
right: {
|
|
816
|
+
start: e.topRight,
|
|
817
|
+
end: e.bottomRight
|
|
818
|
+
},
|
|
819
|
+
bottom: {
|
|
820
|
+
start: e.bottomRight,
|
|
821
|
+
end: e.bottomLeft
|
|
822
|
+
},
|
|
823
|
+
left: {
|
|
824
|
+
start: e.bottomLeft,
|
|
825
|
+
end: e.topLeft
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
};
|
|
829
|
+
}
|
|
830
|
+
function et(e, t) {
|
|
831
|
+
let n = (e) => ({
|
|
832
|
+
x: e.x / t,
|
|
833
|
+
y: e.y / t
|
|
834
|
+
});
|
|
835
|
+
return {
|
|
836
|
+
topLeft: n(e.topLeft),
|
|
837
|
+
topRight: n(e.topRight),
|
|
838
|
+
bottomRight: n(e.bottomRight),
|
|
839
|
+
bottomLeft: n(e.bottomLeft)
|
|
840
|
+
};
|
|
841
|
+
}
|
|
842
|
+
function tt() {
|
|
843
|
+
return typeof navigator > "u" ? !1 : navigator.maxTouchPoints > 0 || navigator.hardwareConcurrency <= 4 || typeof matchMedia == "function" && matchMedia("(pointer: coarse)").matches;
|
|
844
|
+
}
|
|
845
|
+
function nt(t, n, r, i) {
|
|
846
|
+
return new Promise((a, o) => {
|
|
847
|
+
F || (F = new Worker(new URL("./assets/document-worker.js", import.meta.url), { type: "module" }), F.onmessage = (t) => {
|
|
848
|
+
if (t.data.download?.url) {
|
|
849
|
+
O(t.data.download.url, t.data.download);
|
|
850
|
+
return;
|
|
851
|
+
}
|
|
852
|
+
let n = I.get(t.data.id);
|
|
853
|
+
n && (I.delete(t.data.id), t.data.error ? n.reject(t.data.errorCode ? new e(t.data.errorCode, t.data.error) : Error(t.data.error)) : t.data.result ? n.resolve(t.data.result) : n.reject(/* @__PURE__ */ Error("The document worker returned no result.")));
|
|
854
|
+
}, F.onerror = () => {
|
|
855
|
+
let t = new e("worker", "The document worker could not start.");
|
|
856
|
+
for (let e of I.values()) e.reject(t);
|
|
857
|
+
I.clear(), F?.terminate(), F = void 0;
|
|
858
|
+
});
|
|
859
|
+
let s = ++Qe;
|
|
860
|
+
I.set(s, {
|
|
861
|
+
resolve: a,
|
|
862
|
+
reject: o
|
|
863
|
+
});
|
|
864
|
+
let c = t.slice().buffer;
|
|
865
|
+
F.postMessage({
|
|
866
|
+
id: s,
|
|
867
|
+
pixels: c,
|
|
868
|
+
width: n,
|
|
869
|
+
height: r,
|
|
870
|
+
modelUrl: Xe(i.modelUrl),
|
|
871
|
+
heatmapThreshold: i.heatmapThreshold,
|
|
872
|
+
cacheModel: i.cacheModel,
|
|
873
|
+
ortWasmPaths: He(i.ortWasmPaths),
|
|
874
|
+
preferWebGpu: i.preferWebGpu ?? ce()
|
|
875
|
+
}, [c]);
|
|
876
|
+
});
|
|
877
|
+
}
|
|
878
|
+
async function rt(n, r) {
|
|
879
|
+
let { width: i, height: a } = n, o = r.minDimension ?? 360;
|
|
880
|
+
if (Math.min(i, a) < o) return {
|
|
881
|
+
status: "low-quality",
|
|
882
|
+
confidence: 0,
|
|
883
|
+
message: `Use an image at least ${o}px on its shortest side.`,
|
|
884
|
+
sourceWidth: i,
|
|
885
|
+
sourceHeight: a
|
|
886
|
+
};
|
|
887
|
+
let s = Ye(i, a, r.maxAnalysisDimension), c = Math.min(1, s / Math.max(i, a)), l = Math.max(1, Math.round(i * c)), u = Math.max(1, Math.round(a * c)), d;
|
|
888
|
+
if (c === 1) {
|
|
889
|
+
let e = n.getContext("2d", { willReadFrequently: !0 });
|
|
890
|
+
if (!e) throw t();
|
|
891
|
+
d = e.getImageData(0, 0, l, u).data;
|
|
892
|
+
} else {
|
|
893
|
+
let e = document.createElement("canvas");
|
|
894
|
+
e.width = l, e.height = u;
|
|
895
|
+
let r = e.getContext("2d", { willReadFrequently: !0 });
|
|
896
|
+
if (!r) throw t();
|
|
897
|
+
r.drawImage(n, 0, 0, e.width, e.height), d = r.getImageData(0, 0, e.width, e.height).data;
|
|
898
|
+
}
|
|
899
|
+
let f;
|
|
900
|
+
if (r.useWorker !== !1 && typeof Worker < "u") try {
|
|
901
|
+
f = await nt(d, l, u, r);
|
|
902
|
+
} catch (t) {
|
|
903
|
+
if (t instanceof e && (t.code === "worker" || t.code === "model-http")) throw t;
|
|
904
|
+
f = {
|
|
905
|
+
sharpness: 20,
|
|
906
|
+
detector: "ml",
|
|
907
|
+
modelStatus: "failed",
|
|
908
|
+
modelError: t instanceof Error ? t.message : "Document worker failed."
|
|
909
|
+
};
|
|
910
|
+
}
|
|
911
|
+
else f = {
|
|
912
|
+
sharpness: 20,
|
|
913
|
+
detector: "ml",
|
|
914
|
+
modelStatus: "failed",
|
|
915
|
+
modelError: "ML detection requires a Web Worker."
|
|
916
|
+
};
|
|
917
|
+
let { sharpness: p, candidate: m, detector: h, modelStatus: g, modelProvider: _, modelError: v, modelNote: y, inferenceMs: b } = f, x = {
|
|
918
|
+
detector: h,
|
|
919
|
+
modelStatus: g,
|
|
920
|
+
modelProvider: _,
|
|
921
|
+
modelError: v,
|
|
922
|
+
modelNote: y,
|
|
923
|
+
inferenceMs: b
|
|
924
|
+
};
|
|
925
|
+
if (p < Ze) return {
|
|
926
|
+
status: "low-quality",
|
|
927
|
+
confidence: Math.min(.3, p / 18),
|
|
928
|
+
message: "The image is too soft or dark to resolve four document edges.",
|
|
929
|
+
sourceWidth: i,
|
|
930
|
+
sourceHeight: a,
|
|
931
|
+
...x
|
|
932
|
+
};
|
|
933
|
+
if (!m) return {
|
|
934
|
+
status: "no-document",
|
|
935
|
+
confidence: 0,
|
|
936
|
+
message: "No document corners found. Place all four edges on a contrasting surface.",
|
|
937
|
+
sourceWidth: i,
|
|
938
|
+
sourceHeight: a,
|
|
939
|
+
...x
|
|
940
|
+
};
|
|
941
|
+
let S = et(m.corners, c), C = $e(S), w = r.minConfidence ?? .58;
|
|
942
|
+
return m.confidence < w ? {
|
|
943
|
+
status: "low-confidence",
|
|
944
|
+
quad: C,
|
|
945
|
+
corners: S,
|
|
946
|
+
confidence: m.confidence,
|
|
947
|
+
message: "Four possible corners were found, but the geometry is not reliable enough to crop.",
|
|
948
|
+
sourceWidth: i,
|
|
949
|
+
sourceHeight: a,
|
|
950
|
+
...x
|
|
951
|
+
} : {
|
|
952
|
+
status: "success",
|
|
953
|
+
quad: C,
|
|
954
|
+
corners: S,
|
|
955
|
+
confidence: m.confidence,
|
|
956
|
+
message: "Four document edges detected.",
|
|
957
|
+
sourceWidth: i,
|
|
958
|
+
sourceHeight: a,
|
|
959
|
+
...x
|
|
960
|
+
};
|
|
961
|
+
}
|
|
962
|
+
function it(e, t) {
|
|
963
|
+
let n = Math.max(1, Math.round(Math.max(L(e.topLeft, e.topRight), L(e.bottomLeft, e.bottomRight)))), r = Math.max(1, Math.round(Math.max(L(e.topLeft, e.bottomLeft), L(e.topRight, e.bottomRight)))), i = Math.min(1, t / Math.max(n, r));
|
|
964
|
+
return {
|
|
965
|
+
width: Math.max(1, Math.round(n * i)),
|
|
966
|
+
height: Math.max(1, Math.round(r * i))
|
|
967
|
+
};
|
|
968
|
+
}
|
|
969
|
+
function at(e, t, n, r, i) {
|
|
970
|
+
let a = Math.max(0, Math.min(t - 1, r)), o = Math.max(0, Math.min(n - 1, i)), s = Math.floor(a), c = Math.floor(o), l = Math.min(t - 1, s + 1), u = Math.min(n - 1, c + 1), d = a - s, f = o - c, p = c * t, m = u * t, h = (t) => {
|
|
971
|
+
let n = e[(p + s) * 4 + t] * (1 - d) + e[(p + l) * 4 + t] * d, r = e[(m + s) * 4 + t] * (1 - d) + e[(m + l) * 4 + t] * d;
|
|
972
|
+
return Math.round(n * (1 - f) + r * f);
|
|
973
|
+
};
|
|
974
|
+
return [
|
|
975
|
+
h(0),
|
|
976
|
+
h(1),
|
|
977
|
+
h(2),
|
|
978
|
+
255
|
|
979
|
+
];
|
|
980
|
+
}
|
|
981
|
+
function ot(e, n, r) {
|
|
982
|
+
let { width: i, height: a } = it(n, r), o = e.getContext("2d", { willReadFrequently: !0 });
|
|
983
|
+
if (!o) throw t();
|
|
984
|
+
let s = o.getImageData(0, 0, e.width, e.height), c = document.createElement("canvas");
|
|
985
|
+
c.width = i, c.height = a;
|
|
986
|
+
let l = c.getContext("2d");
|
|
987
|
+
if (!l) throw t();
|
|
988
|
+
let u = l.createImageData(i, a), { topLeft: d, topRight: f, bottomRight: p, bottomLeft: m } = n, h = f.x - p.x, g = m.x - p.x, _ = f.y - p.y, v = m.y - p.y, y = d.x - f.x + p.x - m.x, b = d.y - f.y + p.y - m.y, x = h * v - g * _, S = Math.abs(x) < 1e-4 ? 0 : (y * v - g * b) / x, C = Math.abs(x) < 1e-4 ? 0 : (h * b - y * _) / x, w = f.x - d.x + S * f.x, T = m.x - d.x + C * m.x, E = f.y - d.y + S * f.y, D = m.y - d.y + C * m.y;
|
|
989
|
+
for (let t = 0; t < a; t += 1) {
|
|
990
|
+
let n = t / Math.max(1, a - 1);
|
|
991
|
+
for (let r = 0; r < i; r += 1) {
|
|
992
|
+
let a = r / Math.max(1, i - 1), o = S * a + C * n + 1, c = (w * a + T * n + d.x) / o, l = (E * a + D * n + d.y) / o, [f, p, m, h] = at(s.data, e.width, e.height, c, l), g = (t * i + r) * 4;
|
|
993
|
+
u.data[g] = f, u.data[g + 1] = p, u.data[g + 2] = m, u.data[g + 3] = h;
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
return l.putImageData(u, 0, 0), c;
|
|
997
|
+
}
|
|
998
|
+
async function st(e, t = {}) {
|
|
999
|
+
return await x("scan"), rt(await P(e, { cloneCanvas: !1 }), t);
|
|
1000
|
+
}
|
|
1001
|
+
async function ct(e, t, n = {}) {
|
|
1002
|
+
await x("scan");
|
|
1003
|
+
let r = await P(e, { cloneCanvas: !1 }), i = n.maxOutputDimension ?? 4096;
|
|
1004
|
+
return {
|
|
1005
|
+
status: "success",
|
|
1006
|
+
corners: t,
|
|
1007
|
+
quad: $e(t),
|
|
1008
|
+
confidence: 1,
|
|
1009
|
+
message: "Captured with the document edges shown in the finder.",
|
|
1010
|
+
sourceWidth: r.width,
|
|
1011
|
+
sourceHeight: r.height,
|
|
1012
|
+
canvas: ot(r, t, i)
|
|
1013
|
+
};
|
|
1014
|
+
}
|
|
1015
|
+
async function R(e, t = {}) {
|
|
1016
|
+
await x("scan");
|
|
1017
|
+
let n = await P(e, { cloneCanvas: !1 }), r = await rt(n, t);
|
|
1018
|
+
if (r.status !== "success" || !r.corners) return r;
|
|
1019
|
+
let i = t.maxOutputDimension ?? 4096;
|
|
1020
|
+
return {
|
|
1021
|
+
...r,
|
|
1022
|
+
canvas: ot(n, r.corners, i),
|
|
1023
|
+
message: "Four document edges detected and perspective-corrected."
|
|
1024
|
+
};
|
|
1025
|
+
}
|
|
1026
|
+
function lt(e) {
|
|
1027
|
+
return e.status === "success" ? e.message : e.status === "low-quality" ? e.message.includes("shortest side") ? `${e.message} Take another photo.` : "That photo is too soft or dark to find a document. Take another photo in better light." : e.status === "low-confidence" ? "The page edges were not clear enough to crop. Take another photo with the whole page in frame." : `No document was found in that photo. Take another photo with the whole page in frame.${e.modelStatus === "failed" && e.modelError ? ` (${e.modelError})` : ""}`;
|
|
1028
|
+
}
|
|
1029
|
+
async function ut(e, t = {}) {
|
|
1030
|
+
let n = await R(e, t);
|
|
1031
|
+
return n.status === "success" ? n : {
|
|
1032
|
+
...n,
|
|
1033
|
+
message: lt(n)
|
|
1034
|
+
};
|
|
1035
|
+
}
|
|
1036
|
+
//#endregion
|
|
1037
|
+
//#region src/sdk/lighting.ts
|
|
1038
|
+
function dt(e, t) {
|
|
1039
|
+
if (!e.length) return 0;
|
|
1040
|
+
let n = [...e].sort((e, t) => e - t);
|
|
1041
|
+
return n[Math.min(n.length - 1, Math.floor(n.length * t))];
|
|
1042
|
+
}
|
|
1043
|
+
function ft(e, t, n, r = 12) {
|
|
1044
|
+
if (!t || !n || e.length < t * n) return {
|
|
1045
|
+
strong: !1,
|
|
1046
|
+
strength: 0,
|
|
1047
|
+
darkness: 0,
|
|
1048
|
+
areaRatio: 0
|
|
1049
|
+
};
|
|
1050
|
+
let i = Math.min(r, t), a = Math.min(r, n), o = [];
|
|
1051
|
+
for (let r = 0; r < a; r += 1) {
|
|
1052
|
+
let s = Math.floor(r * n / a), c = Math.max(s + 1, Math.floor((r + 1) * n / a));
|
|
1053
|
+
for (let n = 0; n < i; n += 1) {
|
|
1054
|
+
let r = Math.floor(n * t / i), a = Math.max(r + 1, Math.floor((n + 1) * t / i)), l = 0, u = 0, d = 0;
|
|
1055
|
+
for (let n = s; n < c; n += 1) for (let i = r; i < a; i += 1) {
|
|
1056
|
+
let r = e[n * t + i];
|
|
1057
|
+
l += r, u += r * r, d += 1;
|
|
1058
|
+
}
|
|
1059
|
+
let f = l / d;
|
|
1060
|
+
o.push({
|
|
1061
|
+
mean: f,
|
|
1062
|
+
deviation: Math.sqrt(Math.max(0, u / d - f * f))
|
|
1063
|
+
});
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
let s = dt(o.map((e) => e.mean), .8), c = o.map((e) => s - e.mean >= 24 && e.mean >= 35), l = new Uint8Array(o.length), u = [];
|
|
1067
|
+
for (let e = 0; e < o.length; e += 1) {
|
|
1068
|
+
if (!c[e] || l[e]) continue;
|
|
1069
|
+
let t = [], n = [e];
|
|
1070
|
+
for (l[e] = 1; n.length;) {
|
|
1071
|
+
let e = n.shift();
|
|
1072
|
+
t.push(e);
|
|
1073
|
+
let r = Math.floor(e / i), o = e % i;
|
|
1074
|
+
for (let [e, t] of [
|
|
1075
|
+
[o - 1, r],
|
|
1076
|
+
[o + 1, r],
|
|
1077
|
+
[o, r - 1],
|
|
1078
|
+
[o, r + 1]
|
|
1079
|
+
]) {
|
|
1080
|
+
if (e < 0 || e >= i || t < 0 || t >= a) continue;
|
|
1081
|
+
let r = t * i + e;
|
|
1082
|
+
c[r] && !l[r] && (l[r] = 1, n.push(r));
|
|
1083
|
+
}
|
|
1084
|
+
}
|
|
1085
|
+
u.push(t);
|
|
1086
|
+
}
|
|
1087
|
+
let d = {
|
|
1088
|
+
strong: !1,
|
|
1089
|
+
strength: 0,
|
|
1090
|
+
darkness: 0,
|
|
1091
|
+
areaRatio: 0
|
|
1092
|
+
};
|
|
1093
|
+
for (let e of u) {
|
|
1094
|
+
let t = e.length / o.length;
|
|
1095
|
+
if (t < .06 || t > .75) continue;
|
|
1096
|
+
let n = e.reduce((e, t) => e + s - o[t].mean, 0) / e.length, r = e.filter((e) => o[e].deviation >= 9).length / e.length;
|
|
1097
|
+
if (r < .08 && n < 42) continue;
|
|
1098
|
+
let c = e.map((e) => e % i), l = e.map((e) => Math.floor(e / i)), u = Math.min(...c), f = Math.max(...c), p = Math.min(...l), m = Math.max(...l), h = Math.max(0, u - 1) / i, g = Math.max(0, p - 1) / a, _ = Math.min(i, f + 1 + 1) / i, v = Math.min(a, m + 1 + 1) / a, y = n * Math.sqrt(t) * (.75 + Math.min(.25, r));
|
|
1099
|
+
y > d.strength && (d = {
|
|
1100
|
+
strong: y >= 10,
|
|
1101
|
+
strength: y,
|
|
1102
|
+
darkness: n,
|
|
1103
|
+
areaRatio: t,
|
|
1104
|
+
region: {
|
|
1105
|
+
x: h,
|
|
1106
|
+
y: g,
|
|
1107
|
+
width: _ - h,
|
|
1108
|
+
height: v - g
|
|
1109
|
+
}
|
|
1110
|
+
});
|
|
1111
|
+
}
|
|
1112
|
+
return d;
|
|
1113
|
+
}
|
|
1114
|
+
function pt(e, t, n, r, i, a, o) {
|
|
1115
|
+
let s = Math.max(0, a - o), c = Math.min(r, a + o + 1), l = Math.max(0, i - o), u = Math.min(n, i + o + 1), d = Math.max(1, (u - l) * (c - s));
|
|
1116
|
+
return (e[c * t + u] - e[s * t + u] - e[c * t + l] + e[s * t + l]) / d;
|
|
1117
|
+
}
|
|
1118
|
+
function mt(e, t, n) {
|
|
1119
|
+
let r = t + 1, i = new Uint32Array((t + 1) * (n + 1));
|
|
1120
|
+
for (let a = 1; a <= n; a += 1) {
|
|
1121
|
+
let n = 0;
|
|
1122
|
+
for (let o = 1; o <= t; o += 1) n += e[(a - 1) * t + o - 1], i[a * r + o] = i[(a - 1) * r + o] + n;
|
|
1123
|
+
}
|
|
1124
|
+
return {
|
|
1125
|
+
integral: i,
|
|
1126
|
+
stride: r
|
|
1127
|
+
};
|
|
1128
|
+
}
|
|
1129
|
+
function ht(e, t, n, r = Math.max(12, Math.round(Math.max(t, n) / 32))) {
|
|
1130
|
+
let { integral: i, stride: a } = mt(e, t, n), o = new Uint8Array(e.length);
|
|
1131
|
+
for (let s = 0; s < n; s += 1) for (let c = 0; c < t; c += 1) {
|
|
1132
|
+
let l = pt(i, a, t, n, c, s, r);
|
|
1133
|
+
o[s * t + c] = Math.max(0, Math.min(255, Math.round(e[s * t + c] * 235 / Math.max(24, l))));
|
|
1134
|
+
}
|
|
1135
|
+
return o;
|
|
1136
|
+
}
|
|
1137
|
+
function gt(e, t, n, r = Math.max(8, Math.round(Math.max(t, n) / 64)), i = .12) {
|
|
1138
|
+
let { integral: a, stride: o } = mt(e, t, n), s = new Uint8Array(e.length), c = 1 - i;
|
|
1139
|
+
for (let i = 0; i < n; i += 1) for (let l = 0; l < t; l += 1) {
|
|
1140
|
+
let u = pt(a, o, t, n, l, i, r);
|
|
1141
|
+
s[i * t + l] = e[i * t + l] < u * c ? 0 : 255;
|
|
1142
|
+
}
|
|
1143
|
+
return s;
|
|
1144
|
+
}
|
|
1145
|
+
function _t(e, t, n) {
|
|
1146
|
+
let r = [
|
|
1147
|
+
e.topLeft,
|
|
1148
|
+
e.topRight,
|
|
1149
|
+
e.bottomRight,
|
|
1150
|
+
e.bottomLeft
|
|
1151
|
+
], i = Math.max(0, Math.min(...r.map((e) => e.x))), a = Math.max(0, Math.min(...r.map((e) => e.y))), o = Math.min(t, Math.max(...r.map((e) => e.x))), s = Math.min(n, Math.max(...r.map((e) => e.y)));
|
|
1152
|
+
return {
|
|
1153
|
+
left: i,
|
|
1154
|
+
top: a,
|
|
1155
|
+
width: o - i,
|
|
1156
|
+
height: s - a
|
|
1157
|
+
};
|
|
1158
|
+
}
|
|
1159
|
+
function vt(e, t) {
|
|
1160
|
+
let n = _t(t, e.width, e.height);
|
|
1161
|
+
if (n.width <= 0 || n.height <= 0) return {
|
|
1162
|
+
strong: !1,
|
|
1163
|
+
strength: 0,
|
|
1164
|
+
darkness: 0,
|
|
1165
|
+
areaRatio: 0
|
|
1166
|
+
};
|
|
1167
|
+
let r = document.createElement("canvas");
|
|
1168
|
+
r.width = 60, r.height = 60;
|
|
1169
|
+
let i = r.getContext("2d", { willReadFrequently: !0 });
|
|
1170
|
+
if (!i) return {
|
|
1171
|
+
strong: !1,
|
|
1172
|
+
strength: 0,
|
|
1173
|
+
darkness: 0,
|
|
1174
|
+
areaRatio: 0
|
|
1175
|
+
};
|
|
1176
|
+
i.drawImage(e, n.left, n.top, n.width, n.height, 0, 0, r.width, r.height);
|
|
1177
|
+
let a = i.getImageData(0, 0, r.width, r.height).data, o = new Uint8Array(r.width * r.height);
|
|
1178
|
+
for (let e = 0, t = 0; e < o.length; e += 1, t += 4) o[e] = Math.round(a[t] * .299 + a[t + 1] * .587 + a[t + 2] * .114);
|
|
1179
|
+
return ft(o, r.width, r.height);
|
|
1180
|
+
}
|
|
1181
|
+
//#endregion
|
|
1182
|
+
//#region src/sdk/finder.ts
|
|
1183
|
+
function yt(e, t) {
|
|
1184
|
+
return t.castShadow && (e.reason === "hold-still" || e.reason === "ready") ? t.hint ?? e.hint : e.hint;
|
|
1185
|
+
}
|
|
1186
|
+
async function bt(e, t) {
|
|
1187
|
+
let n = await e();
|
|
1188
|
+
return t(), n;
|
|
1189
|
+
}
|
|
1190
|
+
function xt(e) {
|
|
1191
|
+
return e === "alwaysOn" || e === "only" ? {
|
|
1192
|
+
visible: !1,
|
|
1193
|
+
checked: !0,
|
|
1194
|
+
mutable: !1
|
|
1195
|
+
} : e === "alwaysOff" ? {
|
|
1196
|
+
visible: !1,
|
|
1197
|
+
checked: !1,
|
|
1198
|
+
mutable: !1
|
|
1199
|
+
} : {
|
|
1200
|
+
visible: !0,
|
|
1201
|
+
checked: e === "defaultOn",
|
|
1202
|
+
mutable: !0
|
|
1203
|
+
};
|
|
1204
|
+
}
|
|
1205
|
+
function z(e) {
|
|
1206
|
+
return [
|
|
1207
|
+
e.topLeft,
|
|
1208
|
+
e.topRight,
|
|
1209
|
+
e.bottomRight,
|
|
1210
|
+
e.bottomLeft
|
|
1211
|
+
];
|
|
1212
|
+
}
|
|
1213
|
+
var St = 1600;
|
|
1214
|
+
function Ct(e = k()) {
|
|
1215
|
+
return e.iosWebKit ? {
|
|
1216
|
+
intervalMs: 70,
|
|
1217
|
+
maxFrameDimension: 720,
|
|
1218
|
+
maxAnalysisDimension: 720
|
|
1219
|
+
} : {
|
|
1220
|
+
intervalMs: 140,
|
|
1221
|
+
maxFrameDimension: St,
|
|
1222
|
+
maxAnalysisDimension: 520
|
|
1223
|
+
};
|
|
1224
|
+
}
|
|
1225
|
+
function wt(e, t) {
|
|
1226
|
+
let n = e.status === "success" && e.modelStatus !== "failed", r = {
|
|
1227
|
+
status: e.status,
|
|
1228
|
+
confidence: Number(e.confidence.toFixed(3)),
|
|
1229
|
+
source: `${e.sourceWidth}×${e.sourceHeight}`
|
|
1230
|
+
};
|
|
1231
|
+
t?.width && t?.height && (r.video = `${t.width}×${t.height}`), e.modelStatus && (r.modelStatus = e.modelStatus), e.modelProvider && (r.provider = e.modelProvider), e.modelError && (r.modelError = e.modelError), e.modelNote && (r.modelNote = e.modelNote), e.inferenceMs !== void 0 && (r.inferenceMs = Math.round(e.inferenceMs)), !n && e.message && (r.message = e.message);
|
|
1232
|
+
let i = n ? "document found" : e.modelStatus === "failed" ? "document not found (ML failed)" : `document not found (${e.status})`;
|
|
1233
|
+
return {
|
|
1234
|
+
level: n ? "info" : "warn",
|
|
1235
|
+
key: [
|
|
1236
|
+
i,
|
|
1237
|
+
r.modelStatus ?? "",
|
|
1238
|
+
r.modelError ?? "",
|
|
1239
|
+
r.provider ?? "",
|
|
1240
|
+
r.modelNote ?? "",
|
|
1241
|
+
r.source,
|
|
1242
|
+
r.video ?? ""
|
|
1243
|
+
].join("|"),
|
|
1244
|
+
summary: i,
|
|
1245
|
+
detail: r
|
|
1246
|
+
};
|
|
1247
|
+
}
|
|
1248
|
+
function Tt(e) {
|
|
1249
|
+
let t = 0;
|
|
1250
|
+
for (let n = 0; n < e.length; n += 1) {
|
|
1251
|
+
let r = e[n], i = e[(n + 1) % e.length];
|
|
1252
|
+
t += r.x * i.y - i.x * r.y;
|
|
1253
|
+
}
|
|
1254
|
+
return Math.abs(t) / 2;
|
|
1255
|
+
}
|
|
1256
|
+
function B(e, t) {
|
|
1257
|
+
return Math.hypot(e.x - t.x, e.y - t.y);
|
|
1258
|
+
}
|
|
1259
|
+
var V = {
|
|
1260
|
+
widthFill: 0,
|
|
1261
|
+
heightFill: 0,
|
|
1262
|
+
limitingFill: 0,
|
|
1263
|
+
areaFill: 0,
|
|
1264
|
+
aspectRatio: 1
|
|
1265
|
+
};
|
|
1266
|
+
function Et(e, t, n) {
|
|
1267
|
+
let r = z(e), i = r.map(({ x: e }) => e), a = r.map(({ y: e }) => e), o = (Math.max(...i) - Math.min(...i)) / Math.max(1, t), s = (Math.max(...a) - Math.min(...a)) / Math.max(1, n), [c, l, u, d] = r, f = Math.max(B(c, l), B(d, u)), p = Math.max(B(c, d), B(l, u));
|
|
1268
|
+
return {
|
|
1269
|
+
widthFill: o,
|
|
1270
|
+
heightFill: s,
|
|
1271
|
+
limitingFill: Math.max(o, s),
|
|
1272
|
+
areaFill: Tt(r) / Math.max(1, t * n),
|
|
1273
|
+
aspectRatio: Math.max(f, p) / Math.max(1, Math.min(f, p))
|
|
1274
|
+
};
|
|
1275
|
+
}
|
|
1276
|
+
function Dt(e, t, n, r = {}) {
|
|
1277
|
+
let i = t ? r.exitFillRatio ?? .64 : r.minFillRatio ?? .72, a = r.highAspectRatio ?? 2.2;
|
|
1278
|
+
if (e.aspectRatio < a) return i;
|
|
1279
|
+
let o = t ? r.highAspectExitFillRatio : r.highAspectFillRatio;
|
|
1280
|
+
return Math.min(o ?? i + .08, 1 - n * 2);
|
|
1281
|
+
}
|
|
1282
|
+
function Ot(e, t, n = {}) {
|
|
1283
|
+
let r = n.confidenceThreshold ?? .72;
|
|
1284
|
+
if (e.status !== "success" || !e.quad || e.confidence < r || !e.sourceWidth || !e.sourceHeight) return {
|
|
1285
|
+
hint: "Place the document in the frame",
|
|
1286
|
+
reason: "place-document",
|
|
1287
|
+
fillRatio: 0,
|
|
1288
|
+
fill: V,
|
|
1289
|
+
readyForAutoCapture: !1
|
|
1290
|
+
};
|
|
1291
|
+
let i = z(e.quad), a = Et(e.quad, e.sourceWidth, e.sourceHeight), o = a.limitingFill, s = t.previouslyReady ? n.exitEdgeMarginRatio ?? .005 : n.edgeMarginRatio ?? .015, c = e.sourceWidth * s, l = e.sourceHeight * s;
|
|
1292
|
+
if (i.some(({ x: t, y: n }) => t <= c || t >= e.sourceWidth - c || n <= l || n >= e.sourceHeight - l)) return {
|
|
1293
|
+
hint: "Move farther away",
|
|
1294
|
+
reason: "move-farther-away",
|
|
1295
|
+
fillRatio: o,
|
|
1296
|
+
fill: a,
|
|
1297
|
+
readyForAutoCapture: !1
|
|
1298
|
+
};
|
|
1299
|
+
let [u, d, f, p] = i, m = B(u, d), h = B(d, f), g = B(f, p), _ = B(p, u);
|
|
1300
|
+
return Math.min(Math.min(m, g) / Math.max(1, Math.max(m, g)), Math.min(_, h) / Math.max(1, Math.max(_, h))) < (t.previouslyReady ? n.exitMinPerspectiveRatio ?? .4 : n.minPerspectiveRatio ?? .48) ? {
|
|
1301
|
+
hint: "Hold the camera straight",
|
|
1302
|
+
reason: "straighten-camera",
|
|
1303
|
+
fillRatio: o,
|
|
1304
|
+
fill: a,
|
|
1305
|
+
readyForAutoCapture: !1
|
|
1306
|
+
} : o < Dt(a, t.previouslyReady === !0, s, n) ? {
|
|
1307
|
+
hint: "Move closer",
|
|
1308
|
+
reason: "move-closer",
|
|
1309
|
+
fillRatio: o,
|
|
1310
|
+
fill: a,
|
|
1311
|
+
readyForAutoCapture: !1
|
|
1312
|
+
} : {
|
|
1313
|
+
hint: "Hold still",
|
|
1314
|
+
reason: t.ready ? "ready" : "hold-still",
|
|
1315
|
+
fillRatio: o,
|
|
1316
|
+
fill: a,
|
|
1317
|
+
readyForAutoCapture: t.ready
|
|
1318
|
+
};
|
|
1319
|
+
}
|
|
1320
|
+
var kt = class {
|
|
1321
|
+
previous;
|
|
1322
|
+
count = 0;
|
|
1323
|
+
ready = !1;
|
|
1324
|
+
options;
|
|
1325
|
+
constructor(e) {
|
|
1326
|
+
this.options = e;
|
|
1327
|
+
}
|
|
1328
|
+
reset() {
|
|
1329
|
+
this.previous = void 0, this.count = 0, this.ready = !1;
|
|
1330
|
+
}
|
|
1331
|
+
update(e) {
|
|
1332
|
+
if (e.status !== "success" || !e.quad || e.confidence < this.options.confidenceThreshold) return this.reset(), {
|
|
1333
|
+
stableFrames: 0,
|
|
1334
|
+
ready: !1,
|
|
1335
|
+
movement: Infinity
|
|
1336
|
+
};
|
|
1337
|
+
let t = Math.hypot(e.sourceWidth, e.sourceHeight), n = this.previous ? Math.max(...z(e.quad).map((e, n) => {
|
|
1338
|
+
let r = z(this.previous)[n];
|
|
1339
|
+
return Math.hypot(e.x - r.x, e.y - r.y) / Math.max(1, t);
|
|
1340
|
+
})) : Infinity, r = this.options.exitCornerTolerance ?? Math.max(this.options.cornerTolerance, .036);
|
|
1341
|
+
return this.ready && this.previous && n <= r ? this.count = Math.max(this.options.stableFrames, this.count + 1) : (this.ready = !1, this.count = this.previous && n <= this.options.cornerTolerance ? this.count + 1 : 1, this.count >= this.options.stableFrames && (this.ready = !0)), this.previous = e.quad, {
|
|
1342
|
+
stableFrames: this.count,
|
|
1343
|
+
ready: this.ready,
|
|
1344
|
+
movement: n
|
|
1345
|
+
};
|
|
1346
|
+
}
|
|
1347
|
+
};
|
|
1348
|
+
function At(e, n) {
|
|
1349
|
+
let r = Math.min(1, n / Math.max(e.width, e.height)), i = document.createElement("canvas");
|
|
1350
|
+
i.width = Math.max(1, Math.round(e.width * r)), i.height = Math.max(1, Math.round(e.height * r));
|
|
1351
|
+
let a = i.getContext("2d");
|
|
1352
|
+
if (!a) throw t();
|
|
1353
|
+
return a.drawImage(e, 0, 0, i.width, i.height), i;
|
|
1354
|
+
}
|
|
1355
|
+
function jt() {
|
|
1356
|
+
let e = window.AudioContext ?? window.webkitAudioContext;
|
|
1357
|
+
if (!e) return;
|
|
1358
|
+
let t = new e(), n = Math.round(t.sampleRate * .09), r = t.createBuffer(1, n, t.sampleRate), i = r.getChannelData(0);
|
|
1359
|
+
for (let e = 0; e < n; e += 1) {
|
|
1360
|
+
let n = Math.exp(-e / (t.sampleRate * .018));
|
|
1361
|
+
i[e] = (Math.random() * 2 - 1) * n;
|
|
1362
|
+
}
|
|
1363
|
+
let a = t.createBufferSource(), o = t.createBiquadFilter(), s = t.createGain();
|
|
1364
|
+
o.type = "bandpass", o.frequency.value = 1400, s.gain.value = .42, a.buffer = r, a.connect(o).connect(s).connect(t.destination), a.start(), a.onended = () => void t.close();
|
|
1365
|
+
}
|
|
1366
|
+
async function Mt(e) {
|
|
1367
|
+
let t = document.createElement("video");
|
|
1368
|
+
return t.muted = !0, t.autoplay = !0, t.playsInline = !0, t.srcObject = e, await t.play(), t;
|
|
1369
|
+
}
|
|
1370
|
+
async function Nt(t) {
|
|
1371
|
+
await x("scan");
|
|
1372
|
+
let n = xt(t.autoCapture), r = new kt({
|
|
1373
|
+
stableFrames: t.stableFrames ?? 4,
|
|
1374
|
+
confidenceThreshold: t.confidenceThreshold ?? .72,
|
|
1375
|
+
cornerTolerance: t.cornerTolerance ?? .024,
|
|
1376
|
+
exitCornerTolerance: t.exitCornerTolerance ?? .036
|
|
1377
|
+
}), i = Ct(), a = t.maxFrameDimension ?? i.maxFrameDimension, o = t.intervalMs ?? i.intervalMs, s = {
|
|
1378
|
+
minDimension: 220,
|
|
1379
|
+
maxAnalysisDimension: i.maxAnalysisDimension,
|
|
1380
|
+
...t.detection
|
|
1381
|
+
}, c = typeof MediaStream < "u" && t.source instanceof MediaStream ? await Mt(t.source) : t.source, l = !0, u = !1, d = !1, f = 0, p, m = "", h = 0, g = {
|
|
1382
|
+
state: "detecting",
|
|
1383
|
+
confidence: 0,
|
|
1384
|
+
guidance: {
|
|
1385
|
+
hint: "Place the document in the frame",
|
|
1386
|
+
reason: "place-document",
|
|
1387
|
+
fillRatio: 0,
|
|
1388
|
+
fill: V,
|
|
1389
|
+
readyForAutoCapture: !1
|
|
1390
|
+
},
|
|
1391
|
+
lighting: {
|
|
1392
|
+
castShadow: !1,
|
|
1393
|
+
strength: 0
|
|
1394
|
+
},
|
|
1395
|
+
stableFrames: 0,
|
|
1396
|
+
requiredStableFrames: t.stableFrames ?? 4,
|
|
1397
|
+
autoCapture: { ...n }
|
|
1398
|
+
}, _ = () => c instanceof HTMLCanvasElement ? At(c, a) : N(c, a), v = (e) => {
|
|
1399
|
+
g = e, t.onStatus?.(e);
|
|
1400
|
+
}, y = (e) => {
|
|
1401
|
+
let t = wt(e, c instanceof HTMLVideoElement ? {
|
|
1402
|
+
width: c.videoWidth,
|
|
1403
|
+
height: c.videoHeight
|
|
1404
|
+
} : {
|
|
1405
|
+
width: c.width,
|
|
1406
|
+
height: c.height
|
|
1407
|
+
}), n = performance.now();
|
|
1408
|
+
t.key === m && n - h < 2e3 || (m = t.key, h = n, console[t.level](`[exige-scanner] ${t.summary}`, t.detail));
|
|
1409
|
+
}, b = () => {
|
|
1410
|
+
l = !1, window.clearTimeout(f), c instanceof HTMLVideoElement && c !== t.source && (c.srcObject = null);
|
|
1411
|
+
}, S = async (e = "manual") => {
|
|
1412
|
+
if (u) throw Error("A finder capture is already in progress.");
|
|
1413
|
+
u = !0;
|
|
1414
|
+
let n;
|
|
1415
|
+
try {
|
|
1416
|
+
n = await bt(t.captureFrame ?? _, () => {
|
|
1417
|
+
v({
|
|
1418
|
+
...g,
|
|
1419
|
+
state: "captured"
|
|
1420
|
+
}), t.playShutterSound !== !1 && jt(), b();
|
|
1421
|
+
});
|
|
1422
|
+
} catch (e) {
|
|
1423
|
+
throw u = !1, e instanceof Error ? e : /* @__PURE__ */ Error("The camera frame could not be captured.");
|
|
1424
|
+
}
|
|
1425
|
+
let r = {
|
|
1426
|
+
frame: n,
|
|
1427
|
+
detection: p,
|
|
1428
|
+
reason: e
|
|
1429
|
+
};
|
|
1430
|
+
return await t.onCapture?.(r), r;
|
|
1431
|
+
}, C = async () => {
|
|
1432
|
+
if (l && !u) {
|
|
1433
|
+
try {
|
|
1434
|
+
let e = _(), i = await st(e, s);
|
|
1435
|
+
p = i, y(i);
|
|
1436
|
+
let a = i.quad ? vt(e, i.quad) : {
|
|
1437
|
+
strong: !1,
|
|
1438
|
+
strength: 0
|
|
1439
|
+
}, o = a.strong ? {
|
|
1440
|
+
castShadow: !0,
|
|
1441
|
+
strength: a.strength,
|
|
1442
|
+
hint: "Tilt to move the shadow off the page"
|
|
1443
|
+
} : {
|
|
1444
|
+
castShadow: !1,
|
|
1445
|
+
strength: a.strength
|
|
1446
|
+
}, c = r.update(i), l = Ot(i, {
|
|
1447
|
+
...c,
|
|
1448
|
+
previouslyReady: d
|
|
1449
|
+
}, {
|
|
1450
|
+
confidenceThreshold: t.confidenceThreshold ?? .72,
|
|
1451
|
+
...t.guidance
|
|
1452
|
+
});
|
|
1453
|
+
d = l.readyForAutoCapture;
|
|
1454
|
+
let u = i.status !== "success" || l.reason === "place-document" ? "seeking" : l.readyForAutoCapture ? "ready" : "unstable";
|
|
1455
|
+
if (v({
|
|
1456
|
+
state: u,
|
|
1457
|
+
confidence: i.confidence,
|
|
1458
|
+
quad: i.quad,
|
|
1459
|
+
guidance: l,
|
|
1460
|
+
lighting: o,
|
|
1461
|
+
stableFrames: c.stableFrames,
|
|
1462
|
+
requiredStableFrames: g.requiredStableFrames,
|
|
1463
|
+
autoCapture: { ...n },
|
|
1464
|
+
sourceWidth: i.sourceWidth,
|
|
1465
|
+
sourceHeight: i.sourceHeight,
|
|
1466
|
+
detector: i.detector,
|
|
1467
|
+
modelStatus: i.modelStatus,
|
|
1468
|
+
modelProvider: i.modelProvider,
|
|
1469
|
+
modelError: i.modelError,
|
|
1470
|
+
modelNote: i.modelNote,
|
|
1471
|
+
inferenceMs: i.inferenceMs
|
|
1472
|
+
}), l.readyForAutoCapture && n.checked) try {
|
|
1473
|
+
await S("auto");
|
|
1474
|
+
return;
|
|
1475
|
+
} catch (e) {
|
|
1476
|
+
r.reset(), d = !1, t.onCaptureError?.(e instanceof Error ? e : /* @__PURE__ */ Error("Automatic capture failed."));
|
|
1477
|
+
}
|
|
1478
|
+
} catch (t) {
|
|
1479
|
+
r.reset(), d = !1;
|
|
1480
|
+
let i = t instanceof e ? {
|
|
1481
|
+
detector: "ml",
|
|
1482
|
+
modelStatus: "failed",
|
|
1483
|
+
modelError: t.message
|
|
1484
|
+
} : { modelError: t instanceof Error ? t.message : "Finder tick failed." };
|
|
1485
|
+
y({
|
|
1486
|
+
status: "no-document",
|
|
1487
|
+
confidence: 0,
|
|
1488
|
+
message: i.modelError ?? "Finder tick failed.",
|
|
1489
|
+
sourceWidth: 0,
|
|
1490
|
+
sourceHeight: 0,
|
|
1491
|
+
...i
|
|
1492
|
+
}), v({
|
|
1493
|
+
state: "seeking",
|
|
1494
|
+
confidence: 0,
|
|
1495
|
+
guidance: {
|
|
1496
|
+
hint: "Place the document in the frame",
|
|
1497
|
+
reason: "place-document",
|
|
1498
|
+
fillRatio: 0,
|
|
1499
|
+
fill: V,
|
|
1500
|
+
readyForAutoCapture: !1
|
|
1501
|
+
},
|
|
1502
|
+
lighting: {
|
|
1503
|
+
castShadow: !1,
|
|
1504
|
+
strength: 0
|
|
1505
|
+
},
|
|
1506
|
+
stableFrames: 0,
|
|
1507
|
+
requiredStableFrames: g.requiredStableFrames,
|
|
1508
|
+
autoCapture: { ...n },
|
|
1509
|
+
...i
|
|
1510
|
+
});
|
|
1511
|
+
}
|
|
1512
|
+
l && (f = window.setTimeout(() => void C(), o));
|
|
1513
|
+
}
|
|
1514
|
+
};
|
|
1515
|
+
return t.onStatus?.(g), C(), {
|
|
1516
|
+
stop: b,
|
|
1517
|
+
capture: () => S("manual"),
|
|
1518
|
+
setAutoCapture(e) {
|
|
1519
|
+
return !n.mutable || u ? !1 : (n.checked = e, v({
|
|
1520
|
+
...g,
|
|
1521
|
+
autoCapture: { ...n }
|
|
1522
|
+
}), !0);
|
|
1523
|
+
},
|
|
1524
|
+
getStatus: () => g
|
|
1525
|
+
};
|
|
1526
|
+
}
|
|
1527
|
+
//#endregion
|
|
1528
|
+
//#region src/sdk/ocr-runtime.ts
|
|
1529
|
+
var Pt = new URL("./assets/tesseract/worker.min.js", import.meta.url), Ft = new URL("./assets/tesseract/tesseract-core-lstm.wasm.js", import.meta.url), It = new URL("./assets/tesseract/tesseract-core-simd-lstm.wasm.js", import.meta.url), Lt = new URL("./assets/tesseract/tesseract-core-relaxedsimd-lstm.wasm.js", import.meta.url), Rt = new URL("./assets/tesseract/eng.traineddata.gz", import.meta.url), zt = 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), Bt = 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);
|
|
1530
|
+
function Vt(e) {
|
|
1531
|
+
try {
|
|
1532
|
+
return typeof WebAssembly < "u" && WebAssembly.validate(e);
|
|
1533
|
+
} catch {
|
|
1534
|
+
return !1;
|
|
1535
|
+
}
|
|
1536
|
+
}
|
|
1537
|
+
function Ht() {
|
|
1538
|
+
return {
|
|
1539
|
+
relaxedSimd: Vt(zt),
|
|
1540
|
+
simd: Vt(Bt)
|
|
1541
|
+
};
|
|
1542
|
+
}
|
|
1543
|
+
function Ut(e) {
|
|
1544
|
+
return e.relaxedSimd ? Lt : e.simd ? It : Ft;
|
|
1545
|
+
}
|
|
1546
|
+
function Wt(t, n) {
|
|
1547
|
+
let r = t?.trim() || "eng", i = n?.trim() || "";
|
|
1548
|
+
if (i) return {
|
|
1549
|
+
kind: "lang-path",
|
|
1550
|
+
language: r,
|
|
1551
|
+
langPath: i
|
|
1552
|
+
};
|
|
1553
|
+
if (r === "eng") return {
|
|
1554
|
+
kind: "bundled-eng",
|
|
1555
|
+
language: "eng"
|
|
1556
|
+
};
|
|
1557
|
+
throw new e("language", `OCR language "${r}" is not packaged. Pass langPath, a directory URL that contains ${r}.traineddata.gz.`);
|
|
1558
|
+
}
|
|
1559
|
+
function Gt(e = Rt) {
|
|
1560
|
+
let t = e.href, n = t.lastIndexOf("/");
|
|
1561
|
+
return n === -1 ? t : t.slice(0, n);
|
|
1562
|
+
}
|
|
1563
|
+
function Kt(e) {
|
|
1564
|
+
return e.kind === "bundled-eng" ? Gt() : e.langPath;
|
|
1565
|
+
}
|
|
1566
|
+
async function qt(t, n, r) {
|
|
1567
|
+
return new Promise((i, a) => {
|
|
1568
|
+
let o = !1, s = (t) => {
|
|
1569
|
+
o || (o = !0, a(new e("worker", `OCR worker failed to start (${t instanceof Error ? t.message : String(t)}).`)));
|
|
1570
|
+
};
|
|
1571
|
+
t(n, void 0, {
|
|
1572
|
+
workerPath: r.workerPath,
|
|
1573
|
+
corePath: r.corePath,
|
|
1574
|
+
langPath: r.langPath,
|
|
1575
|
+
gzip: !0,
|
|
1576
|
+
logger: r.logger,
|
|
1577
|
+
errorHandler: s
|
|
1578
|
+
}).then((e) => {
|
|
1579
|
+
if (o) {
|
|
1580
|
+
e.terminate?.();
|
|
1581
|
+
return;
|
|
1582
|
+
}
|
|
1583
|
+
o = !0, i(e);
|
|
1584
|
+
}, s);
|
|
1585
|
+
});
|
|
1586
|
+
}
|
|
1587
|
+
//#endregion
|
|
1588
|
+
//#region src/sdk/ocr.ts
|
|
1589
|
+
function Jt(e, t = 1, n = 1, r = 0, i = 0) {
|
|
1590
|
+
return {
|
|
1591
|
+
text: e.text,
|
|
1592
|
+
confidence: Math.max(0, Math.min(1, e.confidence / 100)),
|
|
1593
|
+
bbox: {
|
|
1594
|
+
x: e.bbox.x0 * t + r,
|
|
1595
|
+
y: e.bbox.y0 * n + i,
|
|
1596
|
+
width: Math.max(0, e.bbox.x1 - e.bbox.x0) * t,
|
|
1597
|
+
height: Math.max(0, e.bbox.y1 - e.bbox.y0) * n
|
|
1598
|
+
}
|
|
1599
|
+
};
|
|
1600
|
+
}
|
|
1601
|
+
function Yt(e = .5) {
|
|
1602
|
+
if (!Number.isFinite(e) || e < 0 || e > 1) throw RangeError("OCR minConfidence must be between 0 and 1.");
|
|
1603
|
+
return e;
|
|
1604
|
+
}
|
|
1605
|
+
function Xt(e, t) {
|
|
1606
|
+
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);
|
|
1607
|
+
return s > 0 ? o / s : 0;
|
|
1608
|
+
}
|
|
1609
|
+
function Zt(e) {
|
|
1610
|
+
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 = [];
|
|
1611
|
+
for (let e of t) n.some((t) => Xt(t, e) >= .65) || n.push(e);
|
|
1612
|
+
return n;
|
|
1613
|
+
}
|
|
1614
|
+
function Qt(e, t, n, r, i) {
|
|
1615
|
+
let a = e.text.trim();
|
|
1616
|
+
if (!a || !/[\p{L}\p{N}]/u.test(a)) return !1;
|
|
1617
|
+
let o = e.bbox.width * e.bbox.height / Math.max(1, n * r), s = e.bbox.width / Math.max(1, e.bbox.height);
|
|
1618
|
+
if (o < (t === "word" ? 15e-6 : 15e-7) || s < .05 || s > (t === "word" ? 50 : 8)) return !1;
|
|
1619
|
+
if (i) {
|
|
1620
|
+
let t = i(e.bbox);
|
|
1621
|
+
if (t < .01 || t > .9) return !1;
|
|
1622
|
+
}
|
|
1623
|
+
return !0;
|
|
1624
|
+
}
|
|
1625
|
+
function $t(e) {
|
|
1626
|
+
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 = [];
|
|
1627
|
+
for (let e of t) {
|
|
1628
|
+
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);
|
|
1629
|
+
if (r) {
|
|
1630
|
+
r.words.push(e);
|
|
1631
|
+
let n = r.words.length;
|
|
1632
|
+
r.centerY = (r.centerY * (n - 1) + t) / n, r.height = Math.max(r.height, e.bbox.height);
|
|
1633
|
+
} else n.push({
|
|
1634
|
+
centerY: t,
|
|
1635
|
+
height: e.bbox.height,
|
|
1636
|
+
words: [e]
|
|
1637
|
+
});
|
|
1638
|
+
}
|
|
1639
|
+
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");
|
|
1640
|
+
}
|
|
1641
|
+
function en(e, t, n, r) {
|
|
1642
|
+
let i = Yt(t.minConfidence), a = [], o = [], s = 1, c = 1;
|
|
1643
|
+
for (let t of e) {
|
|
1644
|
+
let e = t.scaleX ?? 1, n = t.scaleY ?? 1, r = t.offsetX ?? 0, l = t.offsetY ?? 0;
|
|
1645
|
+
for (let u of t.blocks ?? []) for (let t of u.paragraphs) for (let u of t.lines) for (let t of u.words) {
|
|
1646
|
+
let u = Jt(t, e, n, r, l);
|
|
1647
|
+
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);
|
|
1648
|
+
for (let a of t.symbols) {
|
|
1649
|
+
let t = Jt(a, e, n, r, l);
|
|
1650
|
+
t.confidence >= i && o.push(t);
|
|
1651
|
+
}
|
|
1652
|
+
}
|
|
1653
|
+
}
|
|
1654
|
+
let l = n?.width ?? s, u = n?.height ?? c, d = Zt(a).filter((e) => Qt(e, "word", l, u, r)), f = Zt(o).filter((e) => Qt(e, "character", l, u, r));
|
|
1655
|
+
return {
|
|
1656
|
+
text: $t(d),
|
|
1657
|
+
confidence: d.length ? d.reduce((e, t) => e + t.confidence, 0) / d.length : 0,
|
|
1658
|
+
words: t.includeWords ? d : [],
|
|
1659
|
+
characters: t.includeCharacters ? f : []
|
|
1660
|
+
};
|
|
1661
|
+
}
|
|
1662
|
+
function tn(e) {
|
|
1663
|
+
let n = e.getContext("2d", { willReadFrequently: !0 });
|
|
1664
|
+
if (!n) throw t();
|
|
1665
|
+
let r = n.getImageData(0, 0, e.width, e.height), i = new Uint8Array(e.width * e.height);
|
|
1666
|
+
for (let e = 0, t = 0; e < i.length; e += 1, t += 4) i[e] = Math.round(r.data[t] * .299 + r.data[t + 1] * .587 + r.data[t + 2] * .114);
|
|
1667
|
+
return {
|
|
1668
|
+
context: n,
|
|
1669
|
+
image: r,
|
|
1670
|
+
luminance: i
|
|
1671
|
+
};
|
|
1672
|
+
}
|
|
1673
|
+
function nn(e) {
|
|
1674
|
+
let t = document.createElement("canvas");
|
|
1675
|
+
t.width = 72, t.height = 72;
|
|
1676
|
+
let n = t.getContext("2d", { willReadFrequently: !0 });
|
|
1677
|
+
if (!n) return {
|
|
1678
|
+
strong: !1,
|
|
1679
|
+
strength: 0,
|
|
1680
|
+
darkness: 0,
|
|
1681
|
+
areaRatio: 0
|
|
1682
|
+
};
|
|
1683
|
+
n.drawImage(e, 0, 0, t.width, t.height);
|
|
1684
|
+
let { luminance: r } = tn(t);
|
|
1685
|
+
return ft(r, t.width, t.height);
|
|
1686
|
+
}
|
|
1687
|
+
function rn(e, t, n, r) {
|
|
1688
|
+
let i = (e.bbox.x + e.bbox.width / 2) / n, a = (e.bbox.y + e.bbox.height / 2) / r;
|
|
1689
|
+
return i >= t.x && i <= t.x + t.width && a >= t.y && a <= t.y + t.height;
|
|
1690
|
+
}
|
|
1691
|
+
var an = .58;
|
|
1692
|
+
function on(e) {
|
|
1693
|
+
let t = e.trim();
|
|
1694
|
+
if (!t || !/[\p{L}\p{N}]/u.test(t)) return 0;
|
|
1695
|
+
if (/^\$?\d{1,5}([.,]\d{2})?$/.test(t)) return 1;
|
|
1696
|
+
let n = t.replace(/[^\p{L}]/gu, "");
|
|
1697
|
+
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;
|
|
1698
|
+
}
|
|
1699
|
+
function sn(e, t, n) {
|
|
1700
|
+
let r = Math.max(0, Math.min(1, (1 - e.darkness / 80) * (1 - e.strength / 24)));
|
|
1701
|
+
if (!t.length) return r * .35;
|
|
1702
|
+
let i = 0;
|
|
1703
|
+
for (let e of t) {
|
|
1704
|
+
let t = on(e.text);
|
|
1705
|
+
if (n) {
|
|
1706
|
+
let r = n(e.bbox);
|
|
1707
|
+
(r < .04 || r > .62) && (t *= .4);
|
|
1708
|
+
}
|
|
1709
|
+
i += t;
|
|
1710
|
+
}
|
|
1711
|
+
return r * .7 + i / t.length * .3;
|
|
1712
|
+
}
|
|
1713
|
+
function cn(e, t, n, r) {
|
|
1714
|
+
return !e.strong || !e.region ? !1 : sn(e, t.filter((t) => rn(t, e.region, n.width, n.height)), r) < an;
|
|
1715
|
+
}
|
|
1716
|
+
function ln(e, t, n, r) {
|
|
1717
|
+
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");
|
|
1718
|
+
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);
|
|
1719
|
+
let l = n / e.width, u = r / e.height;
|
|
1720
|
+
return {
|
|
1721
|
+
tile: c,
|
|
1722
|
+
passMapping: {
|
|
1723
|
+
scaleX: l,
|
|
1724
|
+
scaleY: u,
|
|
1725
|
+
offsetX: i * l,
|
|
1726
|
+
offsetY: a * u
|
|
1727
|
+
}
|
|
1728
|
+
};
|
|
1729
|
+
}
|
|
1730
|
+
function un(e, t) {
|
|
1731
|
+
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;
|
|
1732
|
+
}
|
|
1733
|
+
function dn(e) {
|
|
1734
|
+
let n = 2200, r = Math.max(e.width, e.height), i = r > n ? n / r : Math.min(1.5, n / Math.max(1, r)), a = document.createElement("canvas");
|
|
1735
|
+
a.width = Math.max(1, Math.round(e.width * i)), a.height = Math.max(1, Math.round(e.height * i));
|
|
1736
|
+
let o = a.getContext("2d", { willReadFrequently: !0 });
|
|
1737
|
+
if (!o) throw t();
|
|
1738
|
+
o.drawImage(e, 0, 0, a.width, a.height);
|
|
1739
|
+
let { image: s, luminance: c } = tn(a), l = ht(c, a.width, a.height), u = gt(l, a.width, a.height), d = document.createElement("canvas");
|
|
1740
|
+
d.width = a.width, d.height = a.height;
|
|
1741
|
+
let f = d.getContext("2d", { willReadFrequently: !0 });
|
|
1742
|
+
if (!f) throw t();
|
|
1743
|
+
let p = f.createImageData(d.width, d.height);
|
|
1744
|
+
return un(p, l), f.putImageData(p, 0, 0), un(s, u), o.putImageData(s, 0, 0), {
|
|
1745
|
+
sparseCanvas: a,
|
|
1746
|
+
flattenedCanvas: d
|
|
1747
|
+
};
|
|
1748
|
+
}
|
|
1749
|
+
function fn(e) {
|
|
1750
|
+
let t = document.createElement("canvas");
|
|
1751
|
+
t.width = 24, t.height = 24;
|
|
1752
|
+
let n = t.getContext("2d", { willReadFrequently: !0 });
|
|
1753
|
+
return (r) => {
|
|
1754
|
+
if (!n || r.width <= 0 || r.height <= 0) return 0;
|
|
1755
|
+
n.clearRect(0, 0, t.width, t.height), n.drawImage(e, r.x, r.y, r.width, r.height, 0, 0, t.width, t.height);
|
|
1756
|
+
let i = n.getImageData(0, 0, t.width, t.height).data, a = 255, o = 0, s = new Uint8Array(t.width * t.height);
|
|
1757
|
+
for (let e = 0, t = 0; e < s.length; e += 1, t += 4) {
|
|
1758
|
+
let n = Math.round(i[t] * .299 + i[t + 1] * .587 + i[t + 2] * .114);
|
|
1759
|
+
s[e] = n, a = Math.min(a, n), o = Math.max(o, n);
|
|
1760
|
+
}
|
|
1761
|
+
if (o - a < 12) return 0;
|
|
1762
|
+
let c = a + (o - a) * .55, l = 0;
|
|
1763
|
+
for (let e of s) e < c && (l += 1);
|
|
1764
|
+
return l / s.length;
|
|
1765
|
+
};
|
|
1766
|
+
}
|
|
1767
|
+
async function H(e, t = {}) {
|
|
1768
|
+
await x("ocr");
|
|
1769
|
+
let n = Wt(t.language, t.langPath), r = n.language;
|
|
1770
|
+
Yt(t.minConfidence);
|
|
1771
|
+
let i = await P(e, { cloneCanvas: !1 }), { sparseCanvas: a, flattenedCanvas: o } = dn(i), s = t.shadowPass === !1 ? {
|
|
1772
|
+
strong: !1,
|
|
1773
|
+
strength: 0,
|
|
1774
|
+
darkness: 0,
|
|
1775
|
+
areaRatio: 0
|
|
1776
|
+
} : nn(i), { createWorker: c, PSM: l } = await import("tesseract.js"), u = 0, d = s.strong ? 3 : 2, f = await qt(c, r, {
|
|
1777
|
+
workerPath: Pt.href,
|
|
1778
|
+
corePath: Ut(Ht()).href,
|
|
1779
|
+
langPath: Kt(n),
|
|
1780
|
+
logger(e) {
|
|
1781
|
+
typeof e.progress == "number" && t.onProgress?.(Math.min(1, (u + e.progress) / d), e.status ?? "recognizing text");
|
|
1782
|
+
}
|
|
1783
|
+
});
|
|
1784
|
+
try {
|
|
1785
|
+
await f.setParameters({ tessedit_pageseg_mode: l.AUTO });
|
|
1786
|
+
let e = await f.recognize(i, {}, {
|
|
1787
|
+
text: !0,
|
|
1788
|
+
blocks: !0
|
|
1789
|
+
});
|
|
1790
|
+
u = 1, await f.setParameters({
|
|
1791
|
+
tessedit_pageseg_mode: l.SPARSE_TEXT,
|
|
1792
|
+
preserve_interword_spaces: "1"
|
|
1793
|
+
});
|
|
1794
|
+
let n = await f.recognize(a, {}, {
|
|
1795
|
+
text: !0,
|
|
1796
|
+
blocks: !0
|
|
1797
|
+
}), c = [{ blocks: e.data.blocks }, {
|
|
1798
|
+
blocks: n.data.blocks,
|
|
1799
|
+
scaleX: i.width / a.width,
|
|
1800
|
+
scaleY: i.height / a.height
|
|
1801
|
+
}], d = {
|
|
1802
|
+
...t,
|
|
1803
|
+
includeWords: !0
|
|
1804
|
+
}, p = fn(i), m = en(c, d, {
|
|
1805
|
+
width: i.width,
|
|
1806
|
+
height: i.height
|
|
1807
|
+
}, p), h = t.shadowPass !== !1 && cn(s, m.words, {
|
|
1808
|
+
width: i.width,
|
|
1809
|
+
height: i.height
|
|
1810
|
+
}, p);
|
|
1811
|
+
if (h && s.region) {
|
|
1812
|
+
u = 2;
|
|
1813
|
+
let { tile: e, passMapping: t } = ln(o, s.region, i.width, i.height);
|
|
1814
|
+
await f.setParameters({
|
|
1815
|
+
tessedit_pageseg_mode: l.SPARSE_TEXT,
|
|
1816
|
+
preserve_interword_spaces: "1"
|
|
1817
|
+
});
|
|
1818
|
+
let n = await f.recognize(e, {}, {
|
|
1819
|
+
text: !0,
|
|
1820
|
+
blocks: !0
|
|
1821
|
+
});
|
|
1822
|
+
c.push({
|
|
1823
|
+
blocks: n.data.blocks,
|
|
1824
|
+
...t
|
|
1825
|
+
});
|
|
1826
|
+
}
|
|
1827
|
+
let g = c.length === 2 ? m : en(c, d, {
|
|
1828
|
+
width: i.width,
|
|
1829
|
+
height: i.height
|
|
1830
|
+
}, p);
|
|
1831
|
+
return t.onProgress?.(1, "recognizing text"), {
|
|
1832
|
+
text: g.text,
|
|
1833
|
+
confidence: g.confidence,
|
|
1834
|
+
language: r,
|
|
1835
|
+
imageWidth: i.width,
|
|
1836
|
+
imageHeight: i.height,
|
|
1837
|
+
diagnostics: {
|
|
1838
|
+
shadowPassUsed: h,
|
|
1839
|
+
castShadowStrength: s.strength,
|
|
1840
|
+
shadowRegion: s.region ? {
|
|
1841
|
+
x: s.region.x * i.width,
|
|
1842
|
+
y: s.region.y * i.height,
|
|
1843
|
+
width: s.region.width * i.width,
|
|
1844
|
+
height: s.region.height * i.height
|
|
1845
|
+
} : void 0
|
|
1846
|
+
},
|
|
1847
|
+
...t.includeWords ? { words: g.words } : {},
|
|
1848
|
+
...t.includeCharacters ? { characters: g.characters } : {}
|
|
1849
|
+
};
|
|
1850
|
+
} finally {
|
|
1851
|
+
await f.terminate();
|
|
1852
|
+
}
|
|
1853
|
+
}
|
|
1854
|
+
//#endregion
|
|
1855
|
+
//#region src/sdk/zxing-runtime.ts
|
|
1856
|
+
var pn = new URL("./assets/zxing_reader.wasm", import.meta.url), mn = "3.1.6", hn = "zxing_reader.wasm", gn = `https://exige-scanner-sdk.vercel.app/zxing/${mn}/`, _n = `https://cdn.jsdelivr.net/npm/zxing-wasm@${mn}/dist/reader/`;
|
|
1857
|
+
function vn(e, t) {
|
|
1858
|
+
return `${e.endsWith("/") ? e : `${e}/`}${t}`;
|
|
1859
|
+
}
|
|
1860
|
+
function yn(e = gn) {
|
|
1861
|
+
return vn(e, hn);
|
|
1862
|
+
}
|
|
1863
|
+
function bn() {
|
|
1864
|
+
return pn.href;
|
|
1865
|
+
}
|
|
1866
|
+
var xn, Sn;
|
|
1867
|
+
function Cn() {
|
|
1868
|
+
return {
|
|
1869
|
+
binary: xn,
|
|
1870
|
+
url: Sn
|
|
1871
|
+
};
|
|
1872
|
+
}
|
|
1873
|
+
async function wn(e = fetch) {
|
|
1874
|
+
let t = bn();
|
|
1875
|
+
if (await Re(t, e)) return t;
|
|
1876
|
+
let n = yn(gn);
|
|
1877
|
+
return await Re(n, e) ? n : yn(_n);
|
|
1878
|
+
}
|
|
1879
|
+
//#endregion
|
|
1880
|
+
//#region src/sdk/barcode.ts
|
|
1881
|
+
function Tn() {
|
|
1882
|
+
let e = globalThis.BarcodeDetector;
|
|
1883
|
+
return typeof e == "function" ? e : void 0;
|
|
1884
|
+
}
|
|
1885
|
+
async function En() {
|
|
1886
|
+
let e = Tn();
|
|
1887
|
+
if (!e?.getSupportedFormats) return !1;
|
|
1888
|
+
try {
|
|
1889
|
+
return (await e.getSupportedFormats()).some((e) => e.toLowerCase() === "pdf417");
|
|
1890
|
+
} catch {
|
|
1891
|
+
return !1;
|
|
1892
|
+
}
|
|
1893
|
+
}
|
|
1894
|
+
async function Dn(e) {
|
|
1895
|
+
let t = Tn();
|
|
1896
|
+
if (!t) return;
|
|
1897
|
+
let n = await new t({ formats: ["pdf417"] }).detect(e);
|
|
1898
|
+
return n.find((e) => {
|
|
1899
|
+
let t = e.format?.toLowerCase() ?? "";
|
|
1900
|
+
return (!t || t === "pdf417") && !!e.rawValue?.trim();
|
|
1901
|
+
})?.rawValue?.trim() || n.find((e) => e.rawValue?.trim())?.rawValue?.trim();
|
|
1902
|
+
}
|
|
1903
|
+
function On(e) {
|
|
1904
|
+
try {
|
|
1905
|
+
return e.getContext("2d", { willReadFrequently: !0 })?.getImageData(0, 0, e.width, e.height);
|
|
1906
|
+
} catch {
|
|
1907
|
+
return;
|
|
1908
|
+
}
|
|
1909
|
+
}
|
|
1910
|
+
async function kn(e) {
|
|
1911
|
+
let t = [];
|
|
1912
|
+
if (e instanceof Blob && t.push(e), e instanceof HTMLCanvasElement) {
|
|
1913
|
+
let n = On(e);
|
|
1914
|
+
n && t.push(n);
|
|
1915
|
+
try {
|
|
1916
|
+
t.push(await Ge(e, "image/png"));
|
|
1917
|
+
} catch {}
|
|
1918
|
+
} else if (!(e instanceof Blob)) try {
|
|
1919
|
+
let n = On(await P(e, { cloneCanvas: !1 }));
|
|
1920
|
+
n && t.push(n);
|
|
1921
|
+
} catch {}
|
|
1922
|
+
return t;
|
|
1923
|
+
}
|
|
1924
|
+
async function An(e) {
|
|
1925
|
+
let { prepareZXingModule: t, readBarcodes: n } = await import("zxing-wasm/reader"), r = Cn(), i = r.binary ? void 0 : await wn();
|
|
1926
|
+
await t({
|
|
1927
|
+
overrides: r.binary ? { wasmBinary: r.binary } : { locateFile: (e, t) => e.endsWith(".wasm") ? i ?? t + e : t + e },
|
|
1928
|
+
fireImmediately: !0
|
|
1929
|
+
});
|
|
1930
|
+
for (let t of await kn(e)) {
|
|
1931
|
+
let e = (await n(t, {
|
|
1932
|
+
formats: ["PDF417"],
|
|
1933
|
+
tryHarder: !0,
|
|
1934
|
+
maxNumberOfSymbols: 1
|
|
1935
|
+
})).find((e) => e.text?.trim())?.text?.trim();
|
|
1936
|
+
if (e) return e;
|
|
1937
|
+
}
|
|
1938
|
+
}
|
|
1939
|
+
async function U(e) {
|
|
1940
|
+
if (await En()) try {
|
|
1941
|
+
let t = await Dn(e instanceof HTMLCanvasElement || e instanceof Blob ? e : await P(e, { cloneCanvas: !1 }));
|
|
1942
|
+
if (t) return {
|
|
1943
|
+
text: t,
|
|
1944
|
+
source: "barcode-detector"
|
|
1945
|
+
};
|
|
1946
|
+
} catch {}
|
|
1947
|
+
try {
|
|
1948
|
+
let t = await An(e);
|
|
1949
|
+
return t ? {
|
|
1950
|
+
text: t,
|
|
1951
|
+
source: "zxing-wasm"
|
|
1952
|
+
} : void 0;
|
|
1953
|
+
} catch {
|
|
1954
|
+
return;
|
|
1955
|
+
}
|
|
1956
|
+
}
|
|
1957
|
+
var W = new Set(/* @__PURE__ */ "DCA.DCB.DCD.DBA.DCS.DAC.DAD.DBD.DBB.DBC.DAY.DAU.DAG.DAI.DAJ.DAK.DAQ.DCF.DCG.DDE.DDF.DDG.DAH.DAZ.DCI.DCJ.DCK.DBN.DBG.DBS.DCU.DCE.DCL.DCM.DCN.DCO.DCP.DCQ.DCR.DDA.DDB.DDC.DDD.DAW.DAX.DDH.DDI.DDJ.DDK.DDL.DCT.DAL.DAM.DAN.DAO.DAR.DAS.DAT.DAV.DBH.DBI.DBJ.DBK.DBL.DBM.DCH".split(".")), jn = /* @__PURE__ */ "issuerJurisdiction.expirationDate.documentNumber.firstName.middleName.lastName.dateOfBirth.sex.eyeColor.height.addressStreet.addressCity.addressPostalCode.issueDate.country.addressStreet2.hairColor.nameSuffix.vehicleClass.restrictionCodes.endorsementCodes.documentDiscriminator.inventoryControlNumber.raceEthnicity.organDonor.veteran.weight".split("."), Mn = /* @__PURE__ */ new Set([
|
|
1958
|
+
"expirationDate",
|
|
1959
|
+
"dateOfBirth",
|
|
1960
|
+
"issueDate"
|
|
1961
|
+
]), Nn = {
|
|
1962
|
+
DAJ: "issuerJurisdiction",
|
|
1963
|
+
DBA: "expirationDate",
|
|
1964
|
+
DAQ: "documentNumber",
|
|
1965
|
+
DAC: "firstName",
|
|
1966
|
+
DAD: "middleName",
|
|
1967
|
+
DCS: "lastName",
|
|
1968
|
+
DBB: "dateOfBirth",
|
|
1969
|
+
DBC: "sex",
|
|
1970
|
+
DAY: "eyeColor",
|
|
1971
|
+
DAU: "height",
|
|
1972
|
+
DAG: "addressStreet",
|
|
1973
|
+
DAI: "addressCity",
|
|
1974
|
+
DAK: "addressPostalCode",
|
|
1975
|
+
DBD: "issueDate",
|
|
1976
|
+
DCG: "country",
|
|
1977
|
+
DAH: "addressStreet2",
|
|
1978
|
+
DAZ: "hairColor",
|
|
1979
|
+
DCU: "nameSuffix",
|
|
1980
|
+
DCA: "vehicleClass",
|
|
1981
|
+
DCB: "restrictionCodes",
|
|
1982
|
+
DCD: "endorsementCodes",
|
|
1983
|
+
DCF: "documentDiscriminator",
|
|
1984
|
+
DCK: "inventoryControlNumber",
|
|
1985
|
+
DCL: "raceEthnicity",
|
|
1986
|
+
DDK: "organDonor",
|
|
1987
|
+
DDH: "organDonor",
|
|
1988
|
+
DDL: "veteran",
|
|
1989
|
+
DDI: "veteran",
|
|
1990
|
+
DAW: "weight",
|
|
1991
|
+
DAX: "weight"
|
|
1992
|
+
};
|
|
1993
|
+
function G(e, t, n) {
|
|
1994
|
+
let r = Number(e), i = Number(t), a = Number(n);
|
|
1995
|
+
if (Number.isInteger(r) && Number.isInteger(i) && Number.isInteger(a) && !(r < 1900 || r > 2100 || i < 1 || i > 12 || a < 1 || a > 31)) return `${String(r).padStart(4, "0")}-${String(i).padStart(2, "0")}-${String(a).padStart(2, "0")}`;
|
|
1996
|
+
}
|
|
1997
|
+
function Pn(e, t) {
|
|
1998
|
+
return t ? e >= 30 ? 1900 + e : 2e3 + e : e >= 50 ? 1900 + e : 2e3 + e;
|
|
1999
|
+
}
|
|
2000
|
+
function K(e, t = !1) {
|
|
2001
|
+
let n = e.trim();
|
|
2002
|
+
if (!n) return;
|
|
2003
|
+
let r = /^(\d{1,2})[/-](\d{1,2})[/-](\d{2,4})$/.exec(n);
|
|
2004
|
+
if (r) {
|
|
2005
|
+
let e = r[1], n = r[2], i = r[3];
|
|
2006
|
+
return i.length === 2 && (i = String(Pn(Number(i), t))), G(i, e.padStart(2, "0"), n.padStart(2, "0"));
|
|
2007
|
+
}
|
|
2008
|
+
let i = /^(\d{4})-(\d{2})-(\d{2})$/.exec(n);
|
|
2009
|
+
if (i) return G(i[1], i[2], i[3]);
|
|
2010
|
+
let a = n.replace(/[^\d]/g, "");
|
|
2011
|
+
if (a.length === 8) {
|
|
2012
|
+
let e = Number(a.slice(0, 4));
|
|
2013
|
+
return e >= 1900 && e <= 2100 ? G(a.slice(0, 4), a.slice(4, 6), a.slice(6, 8)) : G(a.slice(4, 8), a.slice(0, 2), a.slice(2, 4));
|
|
2014
|
+
}
|
|
2015
|
+
if (a.length === 6) {
|
|
2016
|
+
let e = Pn(Number(a.slice(4, 6)), t);
|
|
2017
|
+
return G(String(e), a.slice(0, 2), a.slice(2, 4));
|
|
2018
|
+
}
|
|
2019
|
+
}
|
|
2020
|
+
function Fn(e) {
|
|
2021
|
+
let t = e.trim();
|
|
2022
|
+
if (!t || t === "@") return "";
|
|
2023
|
+
if (/^(ANSI|AAMVA)\b/.test(t)) {
|
|
2024
|
+
let e = t.search(/(?:DL|ID)[A-Z]{3}/);
|
|
2025
|
+
return e >= 0 ? t.slice(e) : "";
|
|
2026
|
+
}
|
|
2027
|
+
return t;
|
|
2028
|
+
}
|
|
2029
|
+
function In(e) {
|
|
2030
|
+
return (e.startsWith("DL") || e.startsWith("ID") || e.startsWith("ZV")) && e.length >= 5 && W.has(e.slice(2, 5)) ? e.slice(2) : e;
|
|
2031
|
+
}
|
|
2032
|
+
function Ln(e, t) {
|
|
2033
|
+
let n = 0;
|
|
2034
|
+
for (; n < e.length;) {
|
|
2035
|
+
let r = e.slice(n, n + 3);
|
|
2036
|
+
if (!W.has(r)) {
|
|
2037
|
+
n += 1;
|
|
2038
|
+
continue;
|
|
2039
|
+
}
|
|
2040
|
+
n += 3;
|
|
2041
|
+
let i = n;
|
|
2042
|
+
for (; i < e.length;) {
|
|
2043
|
+
let t = e.slice(i, i + 3);
|
|
2044
|
+
if (W.has(t) || e[i] === "\n" || e[i] === "\r" || e[i] === "") break;
|
|
2045
|
+
i += 1;
|
|
2046
|
+
}
|
|
2047
|
+
let a = e.slice(n, i).trim();
|
|
2048
|
+
(!(r in t) || a) && (t[r] = a), n = i, (e[n] === "\n" || e[n] === "\r" || e[n] === "") && (n += 1);
|
|
2049
|
+
}
|
|
2050
|
+
}
|
|
2051
|
+
function Rn(e) {
|
|
2052
|
+
let t = /(?:ANSI|AAMVA)\s?(\d{6})(\d{2})(\d{2})(\d{2})/.exec(e);
|
|
2053
|
+
if (t) return {
|
|
2054
|
+
iin: t[1],
|
|
2055
|
+
aamvaVersion: t[2],
|
|
2056
|
+
jurisdictionVersion: t[3]
|
|
2057
|
+
};
|
|
2058
|
+
}
|
|
2059
|
+
function zn(e) {
|
|
2060
|
+
let t = e.replace(/\r\n/g, "\n").replace(/\r/g, "\n"), n = {}, r = t.split("\n").flatMap((e) => e.split(""));
|
|
2061
|
+
if (r.some((e) => {
|
|
2062
|
+
let t = In(Fn(e));
|
|
2063
|
+
return W.has(t.slice(0, 3));
|
|
2064
|
+
})) {
|
|
2065
|
+
for (let e of r) {
|
|
2066
|
+
let t = In(Fn(e));
|
|
2067
|
+
t && Ln(t, n);
|
|
2068
|
+
}
|
|
2069
|
+
return n;
|
|
2070
|
+
}
|
|
2071
|
+
return Ln(t, n), n;
|
|
2072
|
+
}
|
|
2073
|
+
function Bn(e, t) {
|
|
2074
|
+
if (Mn.has(t)) return K(e, t === "dateOfBirth") ?? e.trim();
|
|
2075
|
+
if (t === "issuerJurisdiction" || t === "country") return e.trim().toUpperCase();
|
|
2076
|
+
if (t === "addressPostalCode") {
|
|
2077
|
+
let t = e.trim();
|
|
2078
|
+
return /^\d{9}$/.test(t) && t.endsWith("0000") ? t.slice(0, 5) : t;
|
|
2079
|
+
}
|
|
2080
|
+
return e.trim();
|
|
2081
|
+
}
|
|
2082
|
+
function Vn(e) {
|
|
2083
|
+
let t = {};
|
|
2084
|
+
for (let [n, r] of Object.entries(e)) {
|
|
2085
|
+
let e = Nn[n];
|
|
2086
|
+
e && r.trim() && (t[e] || (t[e] = Bn(r, e)));
|
|
2087
|
+
}
|
|
2088
|
+
if (!t.firstName && e.DCT?.trim()) {
|
|
2089
|
+
let n = e.DCT.trim().split(/\s+/);
|
|
2090
|
+
t.firstName = n[0], !t.middleName && n.length > 1 && (t.middleName = n.slice(1).join(" "));
|
|
2091
|
+
}
|
|
2092
|
+
return t;
|
|
2093
|
+
}
|
|
2094
|
+
function Hn(e) {
|
|
2095
|
+
let t = zn(e);
|
|
2096
|
+
return {
|
|
2097
|
+
rawElements: t,
|
|
2098
|
+
fields: Vn(t),
|
|
2099
|
+
header: Rn(e)
|
|
2100
|
+
};
|
|
2101
|
+
}
|
|
2102
|
+
function Un() {
|
|
2103
|
+
return {};
|
|
2104
|
+
}
|
|
2105
|
+
function Wn(e, t, n) {
|
|
2106
|
+
for (let r of jn) t[r] && (e[r] = n);
|
|
2107
|
+
return e;
|
|
2108
|
+
}
|
|
2109
|
+
//#endregion
|
|
2110
|
+
//#region src/sdk/face-model.ts
|
|
2111
|
+
var Gn = /* @__PURE__ */ new Map(), Kn = 8400;
|
|
2112
|
+
function qn(e, t) {
|
|
2113
|
+
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));
|
|
2114
|
+
return n / Math.max(1, e.width * e.height + t.width * t.height - n);
|
|
2115
|
+
}
|
|
2116
|
+
function Jn(e, t, n, r, i, a, o) {
|
|
2117
|
+
return {
|
|
2118
|
+
x: (e - n / 2) / i * a,
|
|
2119
|
+
y: (t - r / 2) / i * o,
|
|
2120
|
+
width: n / i * a,
|
|
2121
|
+
height: r / i * o
|
|
2122
|
+
};
|
|
2123
|
+
}
|
|
2124
|
+
function Yn(e, t, n) {
|
|
2125
|
+
let r = t.length === 3 ? t[1] : t[0], i = t.length === 3 ? t[2] : t[1];
|
|
2126
|
+
if (i !== 6 || r < 1) throw Error(`Face model expects [1, anchors, 6]. A 640 YOLOX-Nano face export is [1, ${Kn}, 6].`);
|
|
2127
|
+
let a = n.confidence ?? .35, o = n.inputSize ?? 640, s = [];
|
|
2128
|
+
for (let t = 0; t < r; t += 1) {
|
|
2129
|
+
let r = t * i, c = e[r + 4] * e[r + 5];
|
|
2130
|
+
c < a || s.push({
|
|
2131
|
+
confidence: c,
|
|
2132
|
+
bbox: Jn(e[r], e[r + 1], e[r + 2], e[r + 3], o, n.imageWidth, n.imageHeight)
|
|
2133
|
+
});
|
|
2134
|
+
}
|
|
2135
|
+
return s.sort((e, t) => t.confidence - e.confidence).filter((e, t, n) => n.slice(0, t).every((t) => qn(e.bbox, t.bbox) < .45)).slice(0, 8);
|
|
2136
|
+
}
|
|
2137
|
+
async function Xn(e, n, r = .35) {
|
|
2138
|
+
let i = await P(e, { cloneCanvas: !1 }), a = await import("onnxruntime-web"), o = document.createElement("canvas");
|
|
2139
|
+
o.width = 640, o.height = 640;
|
|
2140
|
+
let s = o.getContext("2d", { willReadFrequently: !0 });
|
|
2141
|
+
if (!s) throw t();
|
|
2142
|
+
s.drawImage(i, 0, 0, 640, 640);
|
|
2143
|
+
let c = s.getImageData(0, 0, 640, 640).data, l = 409600, u = new Float32Array(l * 3);
|
|
2144
|
+
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;
|
|
2145
|
+
let d = Gn.get(n);
|
|
2146
|
+
d || (d = a.InferenceSession.create(n, {
|
|
2147
|
+
executionProviders: ["wasm"],
|
|
2148
|
+
graphOptimizationLevel: "all"
|
|
2149
|
+
}), Gn.set(n, d));
|
|
2150
|
+
let f = await d, p = (await f.run({ [f.inputNames[0]]: new a.Tensor("float32", u, [
|
|
2151
|
+
1,
|
|
2152
|
+
3,
|
|
2153
|
+
640,
|
|
2154
|
+
640
|
|
2155
|
+
]) }))[f.outputNames[0]];
|
|
2156
|
+
return Yn(p.data, p.dims.map(Number), {
|
|
2157
|
+
confidence: r,
|
|
2158
|
+
imageWidth: i.width,
|
|
2159
|
+
imageHeight: i.height,
|
|
2160
|
+
inputSize: 640
|
|
2161
|
+
});
|
|
2162
|
+
}
|
|
2163
|
+
//#endregion
|
|
2164
|
+
//#region src/sdk/field-model.ts
|
|
2165
|
+
var q = /* @__PURE__ */ new Map(), Zn = [
|
|
2166
|
+
"person_name",
|
|
2167
|
+
"date_of_birth",
|
|
2168
|
+
"address",
|
|
2169
|
+
"document_number",
|
|
2170
|
+
"expiration_date",
|
|
2171
|
+
"postal_code",
|
|
2172
|
+
"state"
|
|
2173
|
+
], Qn = 8400;
|
|
2174
|
+
function $n(e) {
|
|
2175
|
+
return 5 + e;
|
|
2176
|
+
}
|
|
2177
|
+
var er = 640;
|
|
2178
|
+
function tr(e, t) {
|
|
2179
|
+
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));
|
|
2180
|
+
return n / Math.max(1, e.bbox.width * e.bbox.height + t.bbox.width * t.bbox.height - n);
|
|
2181
|
+
}
|
|
2182
|
+
function nr(e) {
|
|
2183
|
+
return e.sort((e, t) => t.confidence - e.confidence).filter((e, t, n) => n.slice(0, t).every((t) => t.field !== e.field || tr(e, t) < .45)).slice(0, 30);
|
|
2184
|
+
}
|
|
2185
|
+
function rr(e, t, n, r, i, a, o) {
|
|
2186
|
+
return {
|
|
2187
|
+
x: (e - n / 2) / i * a,
|
|
2188
|
+
y: (t - r / 2) / i * o,
|
|
2189
|
+
width: n / i * a,
|
|
2190
|
+
height: r / i * o
|
|
2191
|
+
};
|
|
2192
|
+
}
|
|
2193
|
+
function ir(e, t) {
|
|
2194
|
+
let n = $n(t);
|
|
2195
|
+
return e.length === 3 && e[0] === 1 && e[2] === n && e[1] > e[2] ? {
|
|
2196
|
+
anchors: e[1],
|
|
2197
|
+
features: n
|
|
2198
|
+
} : e.length === 2 && e[1] === n && e[0] > e[1] ? {
|
|
2199
|
+
anchors: e[0],
|
|
2200
|
+
features: n
|
|
2201
|
+
} : null;
|
|
2202
|
+
}
|
|
2203
|
+
function ar(e) {
|
|
2204
|
+
return e.length === 3 && e[1] >= 5 && e[2] >= 1;
|
|
2205
|
+
}
|
|
2206
|
+
function or(e) {
|
|
2207
|
+
let t = $n(e);
|
|
2208
|
+
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, ${Qn}, ${t}].`);
|
|
2209
|
+
}
|
|
2210
|
+
function sr(e, t, n, r, i, a, o) {
|
|
2211
|
+
if (!ar(t)) throw Error("Unsupported field-model YOLO output shape.");
|
|
2212
|
+
let s = t[1], c = t[2], l = [];
|
|
2213
|
+
for (let t = 0; t < c; t += 1) {
|
|
2214
|
+
let u = 0, d = 0;
|
|
2215
|
+
for (let r = 4; r < Math.min(s, n.length + 4); r += 1) {
|
|
2216
|
+
let n = e[r * c + t];
|
|
2217
|
+
n > u && (u = n, d = r - 4);
|
|
2218
|
+
}
|
|
2219
|
+
let f = n[d];
|
|
2220
|
+
!f || u < r || l.push({
|
|
2221
|
+
field: f,
|
|
2222
|
+
confidence: u,
|
|
2223
|
+
bbox: rr(e[t], e[c + t], e[c * 2 + t], e[c * 3 + t], i, a, o)
|
|
2224
|
+
});
|
|
2225
|
+
}
|
|
2226
|
+
return nr(l);
|
|
2227
|
+
}
|
|
2228
|
+
function cr(e, t, n, r, i, a, o) {
|
|
2229
|
+
let s = ir(t, n.length);
|
|
2230
|
+
if (!s) throw or(n.length);
|
|
2231
|
+
let c = [];
|
|
2232
|
+
for (let t = 0; t < s.anchors; t += 1) {
|
|
2233
|
+
let l = t * s.features, u = e[l + 4], d = 0, f = 0;
|
|
2234
|
+
for (let t = 0; t < n.length; t += 1) {
|
|
2235
|
+
let n = e[l + 5 + t];
|
|
2236
|
+
n > d && (d = n, f = t);
|
|
2237
|
+
}
|
|
2238
|
+
let p = n[f], m = u * d;
|
|
2239
|
+
!p || m < r || c.push({
|
|
2240
|
+
field: p,
|
|
2241
|
+
confidence: m,
|
|
2242
|
+
bbox: rr(e[l], e[l + 1], e[l + 2], e[l + 3], i, a, o)
|
|
2243
|
+
});
|
|
2244
|
+
}
|
|
2245
|
+
return nr(c);
|
|
2246
|
+
}
|
|
2247
|
+
function lr(e, t, n) {
|
|
2248
|
+
let r = n.classes ?? Zn, i = n.confidence ?? .35, a = n.inputSize ?? er, o = ir(t, r.length);
|
|
2249
|
+
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.");
|
|
2250
|
+
return (n.layout ?? (o ? "yolox" : "yolov8")) === "yolox" ? cr(e, t, r, i, a, n.imageWidth, n.imageHeight) : sr(e, t, r, i, a, n.imageWidth, n.imageHeight);
|
|
2251
|
+
}
|
|
2252
|
+
async function ur(e, n, r = Zn, i = .35, a) {
|
|
2253
|
+
let o = await P(e, { cloneCanvas: !1 }), s = import("onnxruntime-web"), c = er, l = document.createElement("canvas");
|
|
2254
|
+
l.width = c, l.height = c;
|
|
2255
|
+
let u = l.getContext("2d", { willReadFrequently: !0 });
|
|
2256
|
+
if (!u) throw t();
|
|
2257
|
+
u.drawImage(o, 0, 0, c, c);
|
|
2258
|
+
let d = u.getImageData(0, 0, c, c).data, f = c * c, p = new Float32Array(f * 3);
|
|
2259
|
+
for (let e = 0; e < f; e += 1) p[e] = d[e * 4] / 255, p[f + e] = d[e * 4 + 1] / 255, p[f * 2 + e] = d[e * 4 + 2] / 255;
|
|
2260
|
+
let m = q.get(n);
|
|
2261
|
+
m || (m = (async () => {
|
|
2262
|
+
try {
|
|
2263
|
+
let [e, t] = await Promise.all([s, ae(n)]);
|
|
2264
|
+
return await e.InferenceSession.create(t, {
|
|
2265
|
+
executionProviders: ["wasm"],
|
|
2266
|
+
graphOptimizationLevel: "all"
|
|
2267
|
+
});
|
|
2268
|
+
} catch (e) {
|
|
2269
|
+
throw q.delete(n), e;
|
|
2270
|
+
}
|
|
2271
|
+
})(), q.set(n, m));
|
|
2272
|
+
let [h, g] = await Promise.all([s, m]), _ = (await g.run({ [g.inputNames[0]]: new h.Tensor("float32", p, [
|
|
2273
|
+
1,
|
|
2274
|
+
3,
|
|
2275
|
+
c,
|
|
2276
|
+
c
|
|
2277
|
+
]) }))[g.outputNames[0]];
|
|
2278
|
+
return lr(_.data, _.dims.map(Number), {
|
|
2279
|
+
classes: r,
|
|
2280
|
+
confidence: i,
|
|
2281
|
+
layout: a,
|
|
2282
|
+
imageWidth: o.width,
|
|
2283
|
+
imageHeight: o.height,
|
|
2284
|
+
inputSize: c
|
|
2285
|
+
});
|
|
2286
|
+
}
|
|
2287
|
+
//#endregion
|
|
2288
|
+
//#region src/sdk/redact.ts
|
|
2289
|
+
async function dr(e, n, r = {}) {
|
|
2290
|
+
await x("redaction");
|
|
2291
|
+
let i = await P(e), a = i.getContext("2d");
|
|
2292
|
+
if (!a) throw t();
|
|
2293
|
+
for (let e of n) {
|
|
2294
|
+
let t = Ke(e, i.width, i.height);
|
|
2295
|
+
if (t.width < 1 || t.height < 1) continue;
|
|
2296
|
+
if ((e.mode ?? r.mode ?? "blackout") === "blackout") {
|
|
2297
|
+
a.fillStyle = "#050706", a.fillRect(t.x, t.y, t.width, t.height);
|
|
2298
|
+
continue;
|
|
2299
|
+
}
|
|
2300
|
+
let n = document.createElement("canvas");
|
|
2301
|
+
n.width = Math.ceil(t.width), n.height = Math.ceil(t.height);
|
|
2302
|
+
let o = n.getContext("2d");
|
|
2303
|
+
if (!o) continue;
|
|
2304
|
+
o.filter = `blur(${r.blurRadius ?? 18}px)`;
|
|
2305
|
+
let s = Math.max(12, r.blurRadius ?? 18);
|
|
2306
|
+
o.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), a.drawImage(n, t.x, t.y, t.width, t.height);
|
|
2307
|
+
}
|
|
2308
|
+
return {
|
|
2309
|
+
canvas: i,
|
|
2310
|
+
blob: await Ge(i, r.mimeType ?? "image/png", r.quality)
|
|
2311
|
+
};
|
|
2312
|
+
}
|
|
2313
|
+
//#endregion
|
|
2314
|
+
//#region src/sdk/programmatic-redaction.ts
|
|
2315
|
+
function J(e) {
|
|
2316
|
+
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));
|
|
2317
|
+
return {
|
|
2318
|
+
x: t,
|
|
2319
|
+
y: n,
|
|
2320
|
+
width: r - t,
|
|
2321
|
+
height: i - n
|
|
2322
|
+
};
|
|
2323
|
+
}
|
|
2324
|
+
function fr(e) {
|
|
2325
|
+
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);
|
|
2326
|
+
for (let e of n) {
|
|
2327
|
+
let n = e.bbox.y + e.bbox.height / 2, r = t.find((t) => {
|
|
2328
|
+
let r = J(t), i = r.y + r.height / 2;
|
|
2329
|
+
return Math.abs(n - i) <= Math.max(e.bbox.height, r.height) * .65;
|
|
2330
|
+
});
|
|
2331
|
+
r ? r.push(e) : t.push([e]);
|
|
2332
|
+
}
|
|
2333
|
+
return t.map((e) => (e.sort((e, t) => e.bbox.x - t.bbox.x), {
|
|
2334
|
+
words: e,
|
|
2335
|
+
text: e.map((e) => e.text).join(" "),
|
|
2336
|
+
bbox: J(e)
|
|
2337
|
+
}));
|
|
2338
|
+
}
|
|
2339
|
+
function Y(e, t, n = !1) {
|
|
2340
|
+
let r = e.trim().replace(/\s+/g, " "), i = n ? r.replace(/[::]\s*$/, "") : r;
|
|
2341
|
+
return t ? i.toLocaleLowerCase() : i;
|
|
2342
|
+
}
|
|
2343
|
+
function X(e) {
|
|
2344
|
+
return e.reduce((e, t) => e + t.confidence, 0) / Math.max(1, e.length);
|
|
2345
|
+
}
|
|
2346
|
+
function pr(e, t) {
|
|
2347
|
+
let n = e.mode, r = n === "case-insensitive", i = e.scope ?? "line", a;
|
|
2348
|
+
if (n === "regex") {
|
|
2349
|
+
let t = e.pattern ?? e.values?.[0];
|
|
2350
|
+
if (!t) return [];
|
|
2351
|
+
a = new RegExp(t, e.flags?.replace("g", "") ?? "");
|
|
2352
|
+
}
|
|
2353
|
+
let o = (e.values ?? []).filter(Boolean), s = [], c = (t) => s.push({
|
|
2354
|
+
ruleId: e.id,
|
|
2355
|
+
strategy: "string",
|
|
2356
|
+
source: "string",
|
|
2357
|
+
bbox: J(t),
|
|
2358
|
+
text: t.map((e) => e.text).join(" "),
|
|
2359
|
+
confidence: X(t)
|
|
2360
|
+
});
|
|
2361
|
+
if (i === "word") {
|
|
2362
|
+
for (let e of t) for (let t of e.words) {
|
|
2363
|
+
let e = Y(t.text, r);
|
|
2364
|
+
(a ? a.test(t.text) : o.some((t) => e === Y(t, r))) && c([t]);
|
|
2365
|
+
}
|
|
2366
|
+
return s;
|
|
2367
|
+
}
|
|
2368
|
+
for (let e of t) {
|
|
2369
|
+
if (a) {
|
|
2370
|
+
a.test(e.text) && c(e.words);
|
|
2371
|
+
continue;
|
|
2372
|
+
}
|
|
2373
|
+
for (let t of o) {
|
|
2374
|
+
let n = Y(t, r).split(" ");
|
|
2375
|
+
for (let t = 0; t <= e.words.length - n.length; t += 1) {
|
|
2376
|
+
let i = e.words.slice(t, t + n.length);
|
|
2377
|
+
i.every((e, t) => Y(e.text, r) === n[t]) && c(i);
|
|
2378
|
+
}
|
|
2379
|
+
}
|
|
2380
|
+
}
|
|
2381
|
+
return s;
|
|
2382
|
+
}
|
|
2383
|
+
function mr(e, t) {
|
|
2384
|
+
let n = e.labelMode !== "exact", r = Y(e.label, n, !0).split(" ");
|
|
2385
|
+
for (let e of t) for (let t = 0; t <= e.words.length - r.length; t += 1) {
|
|
2386
|
+
let i = e.words.slice(t, t + r.length);
|
|
2387
|
+
if (i.every((e, t) => Y(e.text, n, !0) === r[t])) return i;
|
|
2388
|
+
}
|
|
2389
|
+
}
|
|
2390
|
+
function hr(e, t, n, r, i, a) {
|
|
2391
|
+
let o = a.window?.distance ?? .28, s = a.window?.crossAxis ?? .12, c = t.x + t.width / 2, l = t.y + t.height / 2;
|
|
2392
|
+
return e.filter((e) => {
|
|
2393
|
+
let a = e.bbox.x + e.bbox.width / 2, u = e.bbox.y + e.bbox.height / 2;
|
|
2394
|
+
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;
|
|
2395
|
+
});
|
|
2396
|
+
}
|
|
2397
|
+
function gr(e, t, n, r, i, a = "label") {
|
|
2398
|
+
let o = mr(e, n);
|
|
2399
|
+
if (!o) return [];
|
|
2400
|
+
let s = J(o), c = new Set(o), l = t.filter((e) => !c.has(e)), u = e.direction === "any" ? [
|
|
2401
|
+
"right",
|
|
2402
|
+
"below",
|
|
2403
|
+
"left",
|
|
2404
|
+
"above"
|
|
2405
|
+
] : [e.direction], d;
|
|
2406
|
+
for (let t of u) {
|
|
2407
|
+
let n = fr(hr(l, s, t, r, i, e));
|
|
2408
|
+
for (let t of n) {
|
|
2409
|
+
if (e.valuePattern && !new RegExp(e.valuePattern, e.patternFlags).test(t.text)) continue;
|
|
2410
|
+
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);
|
|
2411
|
+
(!d || l < d.distance) && (d = {
|
|
2412
|
+
words: t.words,
|
|
2413
|
+
distance: l
|
|
2414
|
+
});
|
|
2415
|
+
}
|
|
2416
|
+
}
|
|
2417
|
+
if (!d) return [];
|
|
2418
|
+
let f = e.redactLabel ? [...o, ...d.words] : d.words;
|
|
2419
|
+
return [{
|
|
2420
|
+
ruleId: e.id,
|
|
2421
|
+
strategy: a,
|
|
2422
|
+
source: a === "template-anchor" ? "template" : "label",
|
|
2423
|
+
bbox: J(f),
|
|
2424
|
+
text: d.words.map((e) => e.text).join(" "),
|
|
2425
|
+
confidence: Math.max(0, X(d.words) * (1 - Math.min(.5, d.distance)))
|
|
2426
|
+
}];
|
|
2427
|
+
}
|
|
2428
|
+
var _r = {
|
|
2429
|
+
person_name: [
|
|
2430
|
+
"LN",
|
|
2431
|
+
"FN",
|
|
2432
|
+
"DCS",
|
|
2433
|
+
"DAC",
|
|
2434
|
+
"DAD",
|
|
2435
|
+
"NAME"
|
|
2436
|
+
],
|
|
2437
|
+
date_of_birth: [
|
|
2438
|
+
"DOB",
|
|
2439
|
+
"DBB",
|
|
2440
|
+
"BIRTH"
|
|
2441
|
+
],
|
|
2442
|
+
address: [
|
|
2443
|
+
"ADDRESS",
|
|
2444
|
+
"ADDR",
|
|
2445
|
+
"DAG",
|
|
2446
|
+
"DAI"
|
|
2447
|
+
],
|
|
2448
|
+
document_number: [
|
|
2449
|
+
"DLN",
|
|
2450
|
+
"DAQ",
|
|
2451
|
+
"IDNO",
|
|
2452
|
+
"LICNO"
|
|
2453
|
+
],
|
|
2454
|
+
expiration_date: [
|
|
2455
|
+
"EXP",
|
|
2456
|
+
"DBA",
|
|
2457
|
+
"EXPIRES"
|
|
2458
|
+
],
|
|
2459
|
+
postal_code: [
|
|
2460
|
+
"ZIP",
|
|
2461
|
+
"DAK",
|
|
2462
|
+
"POSTAL"
|
|
2463
|
+
],
|
|
2464
|
+
state: ["STATE", "DAJ"]
|
|
2465
|
+
}, vr = new Set(Object.values(_r).flat()), yr = /^(?:\d{2}[/-]\d{2}[/-]\d{2,4}|\d{4}[/-]\d{2}[/-]\d{2}|\d{6}|\d{8})$/, br = /\b(?:ST|STREET|AVE|AVENUE|RD|ROAD|BLVD|BOULEVARD|LN|LANE|DR|DRIVE|WAY|CT|COURT)\b/i, xr = /\b(?:DRIVER|LICENSE|IDENTIFICATION|CARD|CLASS|SEX|EYES|HEIGHT|RESTRICTIONS)\b/i;
|
|
2466
|
+
function Z(e, t) {
|
|
2467
|
+
let n = t.trim();
|
|
2468
|
+
return n ? e === "date_of_birth" || e === "expiration_date" ? yr.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) && !xr.test(n) : /\d/.test(n) && /[A-Z]/i.test(n) : !1;
|
|
2469
|
+
}
|
|
2470
|
+
function Q(e, t, n, r, i = 1) {
|
|
2471
|
+
return {
|
|
2472
|
+
ruleId: e,
|
|
2473
|
+
strategy: "semantic",
|
|
2474
|
+
source: t,
|
|
2475
|
+
bbox: J(n),
|
|
2476
|
+
text: r ?? n.map((e) => e.text).join(" "),
|
|
2477
|
+
confidence: Math.max(0, Math.min(1, X(n) * i))
|
|
2478
|
+
};
|
|
2479
|
+
}
|
|
2480
|
+
function Sr(e, t, n) {
|
|
2481
|
+
let r = _r[e], i = [];
|
|
2482
|
+
for (let a of n) for (let n = 0; n < a.words.length; n += 1) {
|
|
2483
|
+
let o = a.words[n].text.toUpperCase().replace(/[^A-Z0-9]/g, ""), s = r.find((e) => o === e || o.startsWith(e));
|
|
2484
|
+
if (!s) continue;
|
|
2485
|
+
let c, l;
|
|
2486
|
+
o === s ? (c = a.words.slice(n + 1).filter((e) => !vr.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));
|
|
2487
|
+
}
|
|
2488
|
+
return i;
|
|
2489
|
+
}
|
|
2490
|
+
function Cr(e, t, n) {
|
|
2491
|
+
let r = n.filter((e) => {
|
|
2492
|
+
let t = e.text.replace(/\s/g, "");
|
|
2493
|
+
return t.includes("<<") || /^[A-Z0-9<]{25,}$/.test(t);
|
|
2494
|
+
});
|
|
2495
|
+
if (!r.length) return [];
|
|
2496
|
+
if (e === "person_name") {
|
|
2497
|
+
let e = r.find((e) => e.text.includes("<<"));
|
|
2498
|
+
if (!e) return [];
|
|
2499
|
+
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();
|
|
2500
|
+
return a ? [Q(t, "mrz", e.words, a, .96)] : [];
|
|
2501
|
+
}
|
|
2502
|
+
if (e === "date_of_birth") for (let e of r) {
|
|
2503
|
+
let n = e.text.replace(/\s/g, ""), r = /^\d{6}/.exec(n)?.[0] ?? /^.{13}(\d{6})/.exec(n)?.[1];
|
|
2504
|
+
if (r) return [Q(t, "mrz", e.words, r, .96)];
|
|
2505
|
+
}
|
|
2506
|
+
if (e === "document_number") {
|
|
2507
|
+
let e = r[0];
|
|
2508
|
+
return [Q(t, "mrz", e.words, e.text, .9)];
|
|
2509
|
+
}
|
|
2510
|
+
return [];
|
|
2511
|
+
}
|
|
2512
|
+
function wr(e) {
|
|
2513
|
+
let t = e.replace(/\s/g, ""), n = t.match(/\d{4}/)?.[0];
|
|
2514
|
+
if (n) return Number(n);
|
|
2515
|
+
let r = t.match(/^\d{2}/)?.[0];
|
|
2516
|
+
if (!r) return;
|
|
2517
|
+
let i = Number(r);
|
|
2518
|
+
return i > (/* @__PURE__ */ new Date()).getFullYear() % 100 ? 1900 + i : 2e3 + i;
|
|
2519
|
+
}
|
|
2520
|
+
function Tr(e, t, n, r, i) {
|
|
2521
|
+
if (e === "address") {
|
|
2522
|
+
let e = r.findIndex((e) => /\d/.test(e.text) && br.test(e.text));
|
|
2523
|
+
if (e < 0) return [];
|
|
2524
|
+
let n = [...r[e].words], i = r[e + 1];
|
|
2525
|
+
return i && /(?:\b[A-Z]{2}\b.*\d{5}|\d{5})/i.test(i.text) && n.push(...i.words), [Q(t, "layout", n, void 0, .76)];
|
|
2526
|
+
}
|
|
2527
|
+
if (e === "person_name") {
|
|
2528
|
+
let e = r.map((e) => {
|
|
2529
|
+
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 && !xr.test(e.text) && !br.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);
|
|
2530
|
+
return {
|
|
2531
|
+
line: e,
|
|
2532
|
+
score: r ? .45 + X(e.words) * .3 + a * .15 + (n < .65 ? .1 : 0) : 0
|
|
2533
|
+
};
|
|
2534
|
+
}).filter((e) => e.score >= .68).sort((e, t) => t.score - e.score);
|
|
2535
|
+
return !e.length || e[1] && e[0].score - e[1].score < .04 ? [] : [Q(t, "layout", e[0].line.words, void 0, e[0].score)];
|
|
2536
|
+
}
|
|
2537
|
+
if (e === "date_of_birth" || e === "expiration_date") {
|
|
2538
|
+
let r = (/* @__PURE__ */ new Date()).getFullYear(), i = n.filter((e) => yr.test(e.text.replace(/\s/g, ""))).map((e) => ({
|
|
2539
|
+
word: e,
|
|
2540
|
+
year: wr(e.text)
|
|
2541
|
+
})).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);
|
|
2542
|
+
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)] : [];
|
|
2543
|
+
}
|
|
2544
|
+
if (e === "postal_code") {
|
|
2545
|
+
let r = n.find((t) => Z(e, t.text));
|
|
2546
|
+
return r ? [Q(t, "layout", [r], void 0, .78)] : [];
|
|
2547
|
+
}
|
|
2548
|
+
if (e === "state") {
|
|
2549
|
+
let r = n.filter((t) => Z(e, t.text));
|
|
2550
|
+
return r.length === 1 ? [Q(t, "layout", r, void 0, .7)] : [];
|
|
2551
|
+
}
|
|
2552
|
+
if (e === "document_number") {
|
|
2553
|
+
let r = n.filter((t) => Z(e, t.text));
|
|
2554
|
+
return r.sort((e, t) => t.text.length - e.text.length), r.length ? [Q(t, "layout", [r[0]], void 0, .7)] : [];
|
|
2555
|
+
}
|
|
2556
|
+
return [];
|
|
2557
|
+
}
|
|
2558
|
+
function Er(e, t) {
|
|
2559
|
+
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);
|
|
2560
|
+
}
|
|
2561
|
+
function Dr(e, t, n, r) {
|
|
2562
|
+
let i = Sr(e.field, e.id, n), a = Cr(e.field, e.id, n);
|
|
2563
|
+
return i.length || a.length ? [...i, ...a] : Tr(e.field, e.id, t, n, r);
|
|
2564
|
+
}
|
|
2565
|
+
function Or(e, t, n) {
|
|
2566
|
+
let r = (n ?? []).filter((t) => t.field === e.field).sort((e, t) => t.confidence - e.confidence);
|
|
2567
|
+
for (let n of r) {
|
|
2568
|
+
let r = t.filter((e) => Er(n.bbox, e.bbox) >= .3);
|
|
2569
|
+
if (!r.length) continue;
|
|
2570
|
+
let i = r.map((e) => e.text).join(" ");
|
|
2571
|
+
if (Z(e.field, i)) return Q(e.id, "model", r, i, n.confidence);
|
|
2572
|
+
}
|
|
2573
|
+
}
|
|
2574
|
+
function kr(e, t, n, r, i, a) {
|
|
2575
|
+
let o = Dr(e, t, n, r);
|
|
2576
|
+
if (e.detector !== "model" || !a) return o;
|
|
2577
|
+
let s = Or(e, t, i);
|
|
2578
|
+
return s ? [s] : [];
|
|
2579
|
+
}
|
|
2580
|
+
function Ar(e, t, n, r) {
|
|
2581
|
+
let i = (e) => Math.max(0, Math.min(1, e)), a = i(e.rect.x), o = i(e.rect.y);
|
|
2582
|
+
return {
|
|
2583
|
+
ruleId: `${t}.${e.id}`,
|
|
2584
|
+
strategy: "template-rect",
|
|
2585
|
+
source: "template",
|
|
2586
|
+
bbox: {
|
|
2587
|
+
x: a * n,
|
|
2588
|
+
y: o * r,
|
|
2589
|
+
width: Math.max(0, Math.min(1 - a, e.rect.width)) * n,
|
|
2590
|
+
height: Math.max(0, Math.min(1 - o, e.rect.height)) * r
|
|
2591
|
+
},
|
|
2592
|
+
confidence: 1
|
|
2593
|
+
};
|
|
2594
|
+
}
|
|
2595
|
+
function $(e, t) {
|
|
2596
|
+
let n = t.imageWidth ?? e?.imageWidth ?? 0, r = t.imageHeight ?? e?.imageHeight ?? 0, i = e?.words ?? [], a = fr(i), o = [], s = [];
|
|
2597
|
+
for (let e of t.rules) {
|
|
2598
|
+
let c = e.strategy === "string" ? pr(e, a) : e.strategy === "label" ? gr(e, i, a, n, r) : kr(e, i, a, r, t.semanticDetections, t.modelRequested === !0);
|
|
2599
|
+
c.length ? o.push(...c) : s.push(e.id);
|
|
2600
|
+
}
|
|
2601
|
+
for (let e of t.template?.fields ?? []) {
|
|
2602
|
+
let c = `${t.template.id}.${e.id}`;
|
|
2603
|
+
if (e.strategy === "rect") {
|
|
2604
|
+
n && r ? o.push(Ar(e, t.template.id, n, r)) : s.push(c);
|
|
2605
|
+
continue;
|
|
2606
|
+
}
|
|
2607
|
+
let l = gr({
|
|
2608
|
+
...e,
|
|
2609
|
+
id: c,
|
|
2610
|
+
strategy: "label"
|
|
2611
|
+
}, i, a, n, r, "template-anchor");
|
|
2612
|
+
l.length ? o.push(...l) : s.push(c);
|
|
2613
|
+
}
|
|
2614
|
+
let c = t.rules.length + (t.template?.fields.length ?? 0), l = new Set(o.map((e) => e.ruleId)), u = c ? [...l].reduce((e, t) => {
|
|
2615
|
+
let n = o.filter((e) => e.ruleId === t);
|
|
2616
|
+
return e + Math.max(...n.map((e) => e.confidence));
|
|
2617
|
+
}, 0) / c : 1;
|
|
2618
|
+
return {
|
|
2619
|
+
matches: o,
|
|
2620
|
+
unmatchedRuleIds: s,
|
|
2621
|
+
complete: s.length === 0,
|
|
2622
|
+
confidence: u
|
|
2623
|
+
};
|
|
2624
|
+
}
|
|
2625
|
+
function jr(e) {
|
|
2626
|
+
return e.rules.length > 0 || e.template?.fields.some((e) => e.strategy === "anchor") === !0;
|
|
2627
|
+
}
|
|
2628
|
+
function Mr(e, t = !1) {
|
|
2629
|
+
return t && !e.complete ? "unmatched" : e.complete ? "success" : "partial";
|
|
2630
|
+
}
|
|
2631
|
+
async function Nr(e, t) {
|
|
2632
|
+
await x("redaction");
|
|
2633
|
+
let n = await P(e, { cloneCanvas: !1 }), r = t.ocr;
|
|
2634
|
+
jr(t) && !r && (r = await H(n, { includeWords: !0 }));
|
|
2635
|
+
let i = t.semanticDetections, a = t.modelRequested === !0, o = "not-requested", s;
|
|
2636
|
+
if (t.models?.fields) try {
|
|
2637
|
+
i = await ur(n, t.models.fields, t.models.fieldClasses, t.models.confidence, t.models.fieldLayout), a = !0, o = "loaded";
|
|
2638
|
+
} catch (e) {
|
|
2639
|
+
s = e instanceof Error ? e.message : "The field model could not load.";
|
|
2640
|
+
let n = t.models.allowHeuristicFallback !== !1;
|
|
2641
|
+
a = !n, o = n ? "fallback" : "failed";
|
|
2642
|
+
}
|
|
2643
|
+
let c = $(r, {
|
|
2644
|
+
rules: t.rules,
|
|
2645
|
+
template: t.template,
|
|
2646
|
+
imageWidth: n.width,
|
|
2647
|
+
imageHeight: n.height,
|
|
2648
|
+
semanticDetections: i,
|
|
2649
|
+
modelRequested: a
|
|
2650
|
+
}), l = Mr(c, t.requireAll), u = [], d = "not-requested", f;
|
|
2651
|
+
if (t.models?.face) try {
|
|
2652
|
+
u = await Xn(n, t.models.face, t.models.faceConfidence), d = "loaded";
|
|
2653
|
+
} catch (e) {
|
|
2654
|
+
f = e instanceof Error ? e.message : "The face model could not load.", d = "failed";
|
|
2655
|
+
}
|
|
2656
|
+
if (l === "unmatched") return {
|
|
2657
|
+
...c,
|
|
2658
|
+
status: l,
|
|
2659
|
+
ocr: r,
|
|
2660
|
+
modelStatus: o,
|
|
2661
|
+
modelError: s,
|
|
2662
|
+
faces: u,
|
|
2663
|
+
faceStatus: d,
|
|
2664
|
+
faceError: f
|
|
2665
|
+
};
|
|
2666
|
+
let p = await dr(n, [...c.matches.map((e) => ({
|
|
2667
|
+
...e.bbox,
|
|
2668
|
+
mode: t.style?.mode
|
|
2669
|
+
})), ...u.map((e) => ({
|
|
2670
|
+
...e.bbox,
|
|
2671
|
+
mode: t.style?.mode
|
|
2672
|
+
}))], t.style);
|
|
2673
|
+
return {
|
|
2674
|
+
...c,
|
|
2675
|
+
status: l,
|
|
2676
|
+
ocr: r,
|
|
2677
|
+
canvas: p.canvas,
|
|
2678
|
+
blob: p.blob,
|
|
2679
|
+
modelStatus: o,
|
|
2680
|
+
modelError: s,
|
|
2681
|
+
faces: u,
|
|
2682
|
+
faceStatus: d,
|
|
2683
|
+
faceError: f
|
|
2684
|
+
};
|
|
2685
|
+
}
|
|
2686
|
+
//#endregion
|
|
2687
|
+
//#region src/sdk/driver-license.ts
|
|
2688
|
+
var Pr = [
|
|
2689
|
+
{
|
|
2690
|
+
id: "issuerJurisdiction",
|
|
2691
|
+
strategy: "semantic",
|
|
2692
|
+
field: "state"
|
|
2693
|
+
},
|
|
2694
|
+
{
|
|
2695
|
+
id: "expirationDate",
|
|
2696
|
+
strategy: "semantic",
|
|
2697
|
+
field: "expiration_date"
|
|
2698
|
+
},
|
|
2699
|
+
{
|
|
2700
|
+
id: "documentNumber",
|
|
2701
|
+
strategy: "semantic",
|
|
2702
|
+
field: "document_number"
|
|
2703
|
+
},
|
|
2704
|
+
{
|
|
2705
|
+
id: "dateOfBirth",
|
|
2706
|
+
strategy: "semantic",
|
|
2707
|
+
field: "date_of_birth"
|
|
2708
|
+
},
|
|
2709
|
+
{
|
|
2710
|
+
id: "addressStreet",
|
|
2711
|
+
strategy: "semantic",
|
|
2712
|
+
field: "address"
|
|
2713
|
+
},
|
|
2714
|
+
{
|
|
2715
|
+
id: "addressPostalCode",
|
|
2716
|
+
strategy: "semantic",
|
|
2717
|
+
field: "postal_code"
|
|
2718
|
+
},
|
|
2719
|
+
{
|
|
2720
|
+
id: "personName",
|
|
2721
|
+
strategy: "semantic",
|
|
2722
|
+
field: "person_name"
|
|
2723
|
+
}
|
|
2724
|
+
];
|
|
2725
|
+
function Fr(e, t, n) {
|
|
2726
|
+
let r = n.trim();
|
|
2727
|
+
if (r) {
|
|
2728
|
+
if (t === "expirationDate" || t === "dateOfBirth" || t === "issueDate") {
|
|
2729
|
+
e[t] = K(r, t === "dateOfBirth") ?? r;
|
|
2730
|
+
return;
|
|
2731
|
+
}
|
|
2732
|
+
if (t === "issuerJurisdiction") {
|
|
2733
|
+
e[t] = r.toUpperCase();
|
|
2734
|
+
return;
|
|
2735
|
+
}
|
|
2736
|
+
e[t] = r;
|
|
2737
|
+
}
|
|
2738
|
+
}
|
|
2739
|
+
function Ir(e) {
|
|
2740
|
+
let t = {}, n = $(e, { rules: Pr });
|
|
2741
|
+
for (let e of n.matches) {
|
|
2742
|
+
let n = e.text?.trim();
|
|
2743
|
+
if (n) {
|
|
2744
|
+
if (e.ruleId === "personName") {
|
|
2745
|
+
let e = n.split(/\s+/).filter(Boolean);
|
|
2746
|
+
!t.firstName && e[0] && (t.firstName = e[0]), !t.lastName && e.length > 1 && (t.lastName = e[e.length - 1]), !t.middleName && e.length > 2 && (t.middleName = e.slice(1, -1).join(" "));
|
|
2747
|
+
continue;
|
|
2748
|
+
}
|
|
2749
|
+
Fr(t, e.ruleId, n);
|
|
2750
|
+
}
|
|
2751
|
+
}
|
|
2752
|
+
return t;
|
|
2753
|
+
}
|
|
2754
|
+
function Lr(e, t) {
|
|
2755
|
+
let n = { ...e }, r = Wn(Un(), e, "barcode");
|
|
2756
|
+
for (let [e, i] of Object.entries(t)) i && (n[e] || (n[e] = i, r[e] = "ocr"));
|
|
2757
|
+
return {
|
|
2758
|
+
fields: n,
|
|
2759
|
+
sources: r
|
|
2760
|
+
};
|
|
2761
|
+
}
|
|
2762
|
+
async function Rr(e, t, n) {
|
|
2763
|
+
return t?.status === "success" && t.corners ? ct(e, t.corners, { maxOutputDimension: n?.maxOutputDimension }) : R(e, n);
|
|
2764
|
+
}
|
|
2765
|
+
async function zr(e, t, n) {
|
|
2766
|
+
if (!e.width || !e.height) return {
|
|
2767
|
+
kind: "retry",
|
|
2768
|
+
status: "frontFailed",
|
|
2769
|
+
message: "The front photo was empty. Try again."
|
|
2770
|
+
};
|
|
2771
|
+
let r = await Rr(e, t, n);
|
|
2772
|
+
if (r.status !== "success" || !r.canvas) return {
|
|
2773
|
+
kind: "retry",
|
|
2774
|
+
status: "frontFailed",
|
|
2775
|
+
message: r.message || "The front of the license was not found. Try again."
|
|
2776
|
+
};
|
|
2777
|
+
let i;
|
|
2778
|
+
try {
|
|
2779
|
+
i = await H(r.canvas, { includeWords: !0 });
|
|
2780
|
+
} catch {
|
|
2781
|
+
i = void 0;
|
|
2782
|
+
}
|
|
2783
|
+
return {
|
|
2784
|
+
kind: "need-back",
|
|
2785
|
+
front: {
|
|
2786
|
+
canvas: r.canvas,
|
|
2787
|
+
ocr: i,
|
|
2788
|
+
quad: r.quad
|
|
2789
|
+
}
|
|
2790
|
+
};
|
|
2791
|
+
}
|
|
2792
|
+
async function Br(e, t, n) {
|
|
2793
|
+
if (!e.width || !e.height) return {
|
|
2794
|
+
status: "backFailed",
|
|
2795
|
+
fields: {},
|
|
2796
|
+
rawElements: {},
|
|
2797
|
+
sources: {},
|
|
2798
|
+
front: t,
|
|
2799
|
+
back: {},
|
|
2800
|
+
message: "The back photo was empty. Try again."
|
|
2801
|
+
};
|
|
2802
|
+
let r = await Rr(e, void 0, n), i = r.status === "success" ? r.canvas : void 0, a;
|
|
2803
|
+
i && (a = (await U(i))?.text), a ||= (await U(e))?.text;
|
|
2804
|
+
let o = {
|
|
2805
|
+
canvas: i ?? e,
|
|
2806
|
+
barcodeText: a
|
|
2807
|
+
};
|
|
2808
|
+
if (!a) {
|
|
2809
|
+
let e = t.ocr ? Ir(t.ocr) : {};
|
|
2810
|
+
return {
|
|
2811
|
+
status: "barcodeUnreadable",
|
|
2812
|
+
fields: e,
|
|
2813
|
+
rawElements: {},
|
|
2814
|
+
sources: Wn(Un(), e, "ocr"),
|
|
2815
|
+
front: t,
|
|
2816
|
+
back: o,
|
|
2817
|
+
message: "The PDF417 barcode on the back could not be read. Try again."
|
|
2818
|
+
};
|
|
2819
|
+
}
|
|
2820
|
+
let s = Hn(a), c = t.ocr ? Ir(t.ocr) : {}, l = Lr(s.fields, c);
|
|
2821
|
+
return {
|
|
2822
|
+
status: "success",
|
|
2823
|
+
fields: l.fields,
|
|
2824
|
+
rawElements: s.rawElements,
|
|
2825
|
+
sources: l.sources,
|
|
2826
|
+
front: t,
|
|
2827
|
+
back: o
|
|
2828
|
+
};
|
|
2829
|
+
}
|
|
2830
|
+
function Vr(e, t) {
|
|
2831
|
+
return e === "front" ? {
|
|
2832
|
+
title: "Scan a driver’s license",
|
|
2833
|
+
headline: "Show the front of the license.",
|
|
2834
|
+
detail: t ? "Take a photo of the front. There is no live document guide." : "Place the front of the license in the frame."
|
|
2835
|
+
} : {
|
|
2836
|
+
title: "Scan a driver’s license",
|
|
2837
|
+
headline: "Flip the card. Show the back of the license.",
|
|
2838
|
+
detail: t ? "Take a photo of the back so the PDF417 barcode is in frame." : "Place the back of the license in the frame so the barcode is visible."
|
|
2839
|
+
};
|
|
2840
|
+
}
|
|
2841
|
+
async function Hr(e = {}) {
|
|
2842
|
+
await x("scan"), await x("ocr");
|
|
2843
|
+
let t = "front", n, r = !1;
|
|
2844
|
+
return {
|
|
2845
|
+
get side() {
|
|
2846
|
+
return t;
|
|
2847
|
+
},
|
|
2848
|
+
async submitStill(i, a) {
|
|
2849
|
+
if (r) return {
|
|
2850
|
+
kind: "retry",
|
|
2851
|
+
status: t === "back" ? "backFailed" : "frontFailed",
|
|
2852
|
+
message: "This license scan was cancelled."
|
|
2853
|
+
};
|
|
2854
|
+
if (t === "front") {
|
|
2855
|
+
let r = await zr(i, a, e.scan);
|
|
2856
|
+
return r.kind === "need-back" && (n = r.front, t = "back"), r;
|
|
2857
|
+
}
|
|
2858
|
+
let o = await Br(i, n ?? {}, e.scan);
|
|
2859
|
+
return o.status === "backFailed" ? {
|
|
2860
|
+
kind: "retry",
|
|
2861
|
+
status: "backFailed",
|
|
2862
|
+
message: o.message ?? "The back of the license could not be captured. Try again."
|
|
2863
|
+
} : (r = !0, await e.onDriverLicense?.(o), {
|
|
2864
|
+
kind: "complete",
|
|
2865
|
+
result: o
|
|
2866
|
+
});
|
|
2867
|
+
},
|
|
2868
|
+
cancel() {
|
|
2869
|
+
r = !0, e.onCancel?.();
|
|
2870
|
+
}
|
|
2871
|
+
};
|
|
2872
|
+
}
|
|
2873
|
+
//#endregion
|
|
2874
|
+
export { N as A, le as B, Xe as C, ge as D, lt as E, ve as F, o as G, _e as H, j as I, y as J, x as K, M as L, se as M, Pe as N, he as O, A as P, Fe as R, st as S, ut as T, re as U, Ne as V, a as W, t as X, e as Y, Ot as _, $ as a, qe as b, K as c, En as d, H as f, Et as g, Dt as h, Hr as i, k as j, Te as k, Hn as l, xt as m, Vr as n, Nr as o, kt as p, b as q, Lr as r, dr as s, Ir as t, U as u, yt as v, R as w, ct as x, Nt as y, ce as z };
|
|
2875
|
+
|
|
2876
|
+
//# sourceMappingURL=driver-license-CKMrW8dP.js.map
|