@exige/web-scanner-sdk 0.2.40 → 0.2.42
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/{driver-license-BV2-PjpZ.js → driver-license-D9y7PQn4.js} +504 -546
- package/dist/driver-license-D9y7PQn4.js.map +1 -0
- package/dist/react/parts.d.ts +1 -1
- package/dist/react/types.d.ts +4 -2
- package/dist/react.js +443 -454
- package/dist/react.js.map +1 -1
- package/dist/scanner-sdk.js +3 -3
- package/dist/sdk/driver-license.d.ts +2 -2
- package/dist/sdk/finder.d.ts +13 -6
- package/package.json +1 -1
- package/dist/driver-license-BV2-PjpZ.js.map +0 -1
|
@@ -207,13 +207,13 @@ function ie(e) {
|
|
|
207
207
|
T.delete(e);
|
|
208
208
|
};
|
|
209
209
|
}
|
|
210
|
-
function
|
|
210
|
+
function ae(e, t) {
|
|
211
211
|
t.done ? w.delete(e) : w.set(e, {
|
|
212
212
|
loaded: t.loaded,
|
|
213
213
|
total: t.total
|
|
214
214
|
}), re();
|
|
215
215
|
}
|
|
216
|
-
async function
|
|
216
|
+
async function oe(e, t) {
|
|
217
217
|
let n = te(e);
|
|
218
218
|
if (!e.body) {
|
|
219
219
|
let r = await e.arrayBuffer();
|
|
@@ -238,19 +238,19 @@ async function ae(e, t) {
|
|
|
238
238
|
total: n
|
|
239
239
|
}), o.buffer;
|
|
240
240
|
}
|
|
241
|
-
async function
|
|
241
|
+
async function se(t, n) {
|
|
242
242
|
let r = ee.get(t);
|
|
243
243
|
if (r) return r.slice(0);
|
|
244
244
|
let i = E.get(t);
|
|
245
245
|
if (i) return i.then((e) => e.slice(0));
|
|
246
246
|
let a = (async () => {
|
|
247
|
-
|
|
247
|
+
ae(t, {
|
|
248
248
|
loaded: 0,
|
|
249
249
|
total: null
|
|
250
250
|
});
|
|
251
251
|
let r = await fetch(t, { cache: n?.cache });
|
|
252
252
|
if (!r.ok) throw new e("model-http", `Model request failed with HTTP ${r.status}.`);
|
|
253
|
-
return
|
|
253
|
+
return oe(r, (e) => ae(t, e));
|
|
254
254
|
})();
|
|
255
255
|
E.set(t, a);
|
|
256
256
|
try {
|
|
@@ -262,7 +262,7 @@ async function oe(t, n) {
|
|
|
262
262
|
}
|
|
263
263
|
//#endregion
|
|
264
264
|
//#region src/sdk/camera.ts
|
|
265
|
-
function
|
|
265
|
+
function ce(e, t) {
|
|
266
266
|
let { engine: n } = t;
|
|
267
267
|
return [
|
|
268
268
|
`${e}:`,
|
|
@@ -277,9 +277,9 @@ function se(e, t) {
|
|
|
277
277
|
` torch: ${t.torch.mode} supported=${t.torch.supported} on=${t.torch.on}`
|
|
278
278
|
].join("\n");
|
|
279
279
|
}
|
|
280
|
-
function
|
|
280
|
+
function le(e) {
|
|
281
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(
|
|
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(ce("shutter", e.shutter)), e.live && t.push(ce("live", e.live)), e.finder) {
|
|
283
283
|
let n = e.finder;
|
|
284
284
|
t.push([
|
|
285
285
|
"finder:",
|
|
@@ -296,7 +296,7 @@ function ce(e) {
|
|
|
296
296
|
}
|
|
297
297
|
return `${t.join("\n")}\n`;
|
|
298
298
|
}
|
|
299
|
-
function
|
|
299
|
+
function D(e = typeof navigator > "u" ? "" : navigator.userAgent, t = typeof navigator > "u" ? 0 : navigator.maxTouchPoints) {
|
|
300
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
301
|
return {
|
|
302
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",
|
|
@@ -305,40 +305,40 @@ function O(e = typeof navigator > "u" ? "" : navigator.userAgent, t = typeof nav
|
|
|
305
305
|
userAgent: e
|
|
306
306
|
};
|
|
307
307
|
}
|
|
308
|
-
function
|
|
308
|
+
function ue(e) {
|
|
309
309
|
return /Android/i.test(e.userAgent) && !e.iosWebKit;
|
|
310
310
|
}
|
|
311
|
-
function
|
|
312
|
-
return e.engine === "webkit" && !
|
|
311
|
+
function de(e = D()) {
|
|
312
|
+
return e.engine === "webkit" && !ue(e);
|
|
313
313
|
}
|
|
314
|
-
function
|
|
315
|
-
return e === "system-camera" || e !== "live" &&
|
|
314
|
+
function fe(e = "auto", t = D()) {
|
|
315
|
+
return e === "system-camera" || e !== "live" && ue(t);
|
|
316
316
|
}
|
|
317
|
-
function
|
|
317
|
+
function pe(e, t) {
|
|
318
318
|
return t && !e.iosWebKit;
|
|
319
319
|
}
|
|
320
|
-
function
|
|
320
|
+
function me(e, t) {
|
|
321
321
|
if (!e || !Number.isFinite(e)) return;
|
|
322
322
|
let n = t?.max;
|
|
323
323
|
if (!n || !Number.isFinite(n)) return Math.round(e);
|
|
324
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
325
|
return Math.round(Math.min(n, Math.max(r, a)));
|
|
326
326
|
}
|
|
327
|
-
function
|
|
328
|
-
let t =
|
|
327
|
+
function he(e) {
|
|
328
|
+
let t = me(e?.imageWidth?.max ?? 0, e?.imageWidth), n = me(e?.imageHeight?.max ?? 0, e?.imageHeight);
|
|
329
329
|
if (t && n) return t >= n ? { imageWidth: t } : { imageHeight: n };
|
|
330
330
|
if (t) return { imageWidth: t };
|
|
331
331
|
if (n) return { imageHeight: n };
|
|
332
332
|
}
|
|
333
|
-
function
|
|
333
|
+
function ge(e, t) {
|
|
334
334
|
return !e.width || !e.height || !t.width || !t.height ? !1 : e.width * e.height > t.width * t.height * 1.15;
|
|
335
335
|
}
|
|
336
|
-
function
|
|
336
|
+
function _e(e, t) {
|
|
337
337
|
if (!e.width || !e.height || !t.width || !t.height) return !1;
|
|
338
338
|
let n = e.width / e.height / (t.width / t.height);
|
|
339
339
|
return n > .97 && n < 1.03;
|
|
340
340
|
}
|
|
341
|
-
var
|
|
341
|
+
var ve = 10, ye = class {
|
|
342
342
|
on = !1;
|
|
343
343
|
darkCount = 0;
|
|
344
344
|
brightCount = 0;
|
|
@@ -361,7 +361,7 @@ var _e = 10, ve = class {
|
|
|
361
361
|
return this.on;
|
|
362
362
|
}
|
|
363
363
|
};
|
|
364
|
-
function
|
|
364
|
+
function be(e, t) {
|
|
365
365
|
return t ? e === "alwaysOn" || e === "alwaysOff" ? {
|
|
366
366
|
mode: e,
|
|
367
367
|
supported: !0,
|
|
@@ -385,7 +385,7 @@ function ye(e, t) {
|
|
|
385
385
|
automatic: e === "auto"
|
|
386
386
|
};
|
|
387
387
|
}
|
|
388
|
-
function
|
|
388
|
+
function O(e) {
|
|
389
389
|
let t = Math.floor(e.length / 4);
|
|
390
390
|
if (!t) return 0;
|
|
391
391
|
let n = 0;
|
|
@@ -393,32 +393,32 @@ function be(e) {
|
|
|
393
393
|
return n / t;
|
|
394
394
|
}
|
|
395
395
|
function k(e) {
|
|
396
|
-
return !e.width || !e.height ||
|
|
396
|
+
return !e.width || !e.height || Se(e, e.width, e.height) <= 10;
|
|
397
397
|
}
|
|
398
398
|
function xe(e, t = 10) {
|
|
399
399
|
if (e.length < 4) return !0;
|
|
400
400
|
let n = Math.floor(e.length / 4), r = 0;
|
|
401
401
|
for (let i = 0; i < n * 4; i += 4) e[i] * .299 + e[i + 1] * .587 + e[i + 2] * .114 > t * 2 && (r += 1);
|
|
402
|
-
return
|
|
402
|
+
return O(e) <= t && r / n < .01;
|
|
403
403
|
}
|
|
404
|
-
function
|
|
404
|
+
function Se(e, t, n) {
|
|
405
405
|
if (!t || !n) return 0;
|
|
406
406
|
let r = document.createElement("canvas");
|
|
407
407
|
r.width = Math.min(32, t), r.height = Math.min(32, n);
|
|
408
408
|
let i = r.getContext("2d", { willReadFrequently: !0 });
|
|
409
|
-
return i ? (i.drawImage(e, 0, 0, r.width, r.height),
|
|
409
|
+
return i ? (i.drawImage(e, 0, 0, r.width, r.height), O(i.getImageData(0, 0, r.width, r.height).data)) : 0;
|
|
410
410
|
}
|
|
411
|
-
function
|
|
412
|
-
return
|
|
411
|
+
function Ce(e) {
|
|
412
|
+
return Se(e, e.width, e.height);
|
|
413
413
|
}
|
|
414
|
-
function
|
|
414
|
+
function we(e, t = 120) {
|
|
415
415
|
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 = () => {
|
|
416
416
|
a && (o = i ? e.requestVideoFrameCallback(f) : requestAnimationFrame(f));
|
|
417
417
|
};
|
|
418
418
|
function f() {
|
|
419
419
|
if (!a) return;
|
|
420
420
|
let { videoWidth: i, videoHeight: o } = e, f = performance.now();
|
|
421
|
-
r && i && o && f - s >= t && (s = f, l =
|
|
421
|
+
r && i && o && f - s >= t && (s = f, l = Se(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();
|
|
422
422
|
}
|
|
423
423
|
return d(), {
|
|
424
424
|
stop() {
|
|
@@ -430,34 +430,34 @@ function Ce(e, t = 120) {
|
|
|
430
430
|
getMirrorAgeMs: () => c ? performance.now() - c : Infinity
|
|
431
431
|
};
|
|
432
432
|
}
|
|
433
|
-
function
|
|
433
|
+
function Te(e) {
|
|
434
434
|
let t = document.createElement("canvas");
|
|
435
435
|
return t.width = e.width, t.height = e.height, t.getContext("2d")?.drawImage(e, 0, 0), t;
|
|
436
436
|
}
|
|
437
|
-
function
|
|
438
|
-
let r =
|
|
439
|
-
if (r.width === e.width && r.height === e.height) return
|
|
437
|
+
function Ee(e, n) {
|
|
438
|
+
let r = j(e.width, e.height, n);
|
|
439
|
+
if (r.width === e.width && r.height === e.height) return Te(e);
|
|
440
440
|
let i = document.createElement("canvas");
|
|
441
441
|
i.width = r.width, i.height = r.height;
|
|
442
442
|
let a = i.getContext("2d");
|
|
443
443
|
if (!a) throw t();
|
|
444
444
|
return a.imageSmoothingEnabled = !0, "imageSmoothingQuality" in a && (a.imageSmoothingQuality = "high"), a.drawImage(e, 0, 0, i.width, i.height), i;
|
|
445
445
|
}
|
|
446
|
-
function
|
|
446
|
+
function De(e, t, n) {
|
|
447
447
|
try {
|
|
448
|
-
let t =
|
|
448
|
+
let t = M(e, n);
|
|
449
449
|
if (!k(t)) return t;
|
|
450
450
|
} catch {}
|
|
451
451
|
let r = t.getFrame();
|
|
452
452
|
if (!r) throw Error("The camera is not ready to capture a frame.");
|
|
453
|
-
let i =
|
|
453
|
+
let i = Ee(r, n);
|
|
454
454
|
if (k(i)) throw Error("The camera preview produced no visible pixels.");
|
|
455
455
|
return i;
|
|
456
456
|
}
|
|
457
|
-
function
|
|
457
|
+
function Oe(e) {
|
|
458
458
|
return e.engine === "blink";
|
|
459
459
|
}
|
|
460
|
-
function
|
|
460
|
+
function A(e = {}, t = D()) {
|
|
461
461
|
let n = { ideal: e.idealWidth ?? 3840 }, r = { ideal: e.idealHeight ?? 2160 };
|
|
462
462
|
e.maxWidth && (n.max = e.maxWidth), e.maxHeight && (r.max = e.maxHeight);
|
|
463
463
|
let i = {
|
|
@@ -469,20 +469,20 @@ function j(e = {}, t = O()) {
|
|
|
469
469
|
max: e.maxFrameRate ?? 30
|
|
470
470
|
}
|
|
471
471
|
};
|
|
472
|
-
return
|
|
472
|
+
return Oe(t) && (i.resizeMode = { ideal: "none" }), {
|
|
473
473
|
audio: !1,
|
|
474
474
|
video: i
|
|
475
475
|
};
|
|
476
476
|
}
|
|
477
|
-
function
|
|
477
|
+
function j(e, t, n) {
|
|
478
478
|
let r = n ? Math.min(1, n / Math.max(e, t)) : 1;
|
|
479
479
|
return {
|
|
480
480
|
width: Math.max(1, Math.round(e * r)),
|
|
481
481
|
height: Math.max(1, Math.round(t * r))
|
|
482
482
|
};
|
|
483
483
|
}
|
|
484
|
-
var
|
|
485
|
-
function
|
|
484
|
+
var ke = 4096;
|
|
485
|
+
function Ae(e, t) {
|
|
486
486
|
let n = e.width, r = e.height, i = t?.width?.max, a = t?.height?.max;
|
|
487
487
|
if (!n || !r || !i || !a) return;
|
|
488
488
|
let o = Math.min(i / n, a / r);
|
|
@@ -491,13 +491,13 @@ function ke(e, t) {
|
|
|
491
491
|
height: { ideal: Math.round(r * o) }
|
|
492
492
|
};
|
|
493
493
|
}
|
|
494
|
-
async function
|
|
495
|
-
let t =
|
|
494
|
+
async function je(e) {
|
|
495
|
+
let t = Ae(e.getSettings(), typeof e.getCapabilities == "function" ? e.getCapabilities() : void 0);
|
|
496
496
|
if (t) try {
|
|
497
497
|
await e.applyConstraints(t);
|
|
498
498
|
} catch {}
|
|
499
499
|
}
|
|
500
|
-
async function
|
|
500
|
+
async function Me(e) {
|
|
501
501
|
try {
|
|
502
502
|
return await createImageBitmap(e, {
|
|
503
503
|
imageOrientation: "from-image",
|
|
@@ -507,7 +507,7 @@ async function je(e) {
|
|
|
507
507
|
return await createImageBitmap(e);
|
|
508
508
|
}
|
|
509
509
|
}
|
|
510
|
-
async function
|
|
510
|
+
async function Ne(e) {
|
|
511
511
|
try {
|
|
512
512
|
await e.applyConstraints({ advanced: [{ pointsOfInterest: [{
|
|
513
513
|
x: .5,
|
|
@@ -515,25 +515,25 @@ async function Me(e) {
|
|
|
515
515
|
}] }] }), await new Promise((e) => window.setTimeout(e, 180));
|
|
516
516
|
} catch {}
|
|
517
517
|
}
|
|
518
|
-
async function
|
|
519
|
-
let n = await
|
|
518
|
+
async function Pe(e) {
|
|
519
|
+
let n = await Me(e), r = j(n.width, n.height, ke), i = document.createElement("canvas");
|
|
520
520
|
i.width = r.width, i.height = r.height;
|
|
521
521
|
let a = i.getContext("2d");
|
|
522
522
|
if (!a) throw n.close?.(), t();
|
|
523
523
|
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;
|
|
524
524
|
}
|
|
525
|
-
async function
|
|
525
|
+
async function Fe(e) {
|
|
526
526
|
let t = globalThis.ImageCapture;
|
|
527
527
|
if (!t) return;
|
|
528
|
-
await
|
|
529
|
-
let n = new t(e), r = n.getPhotoCapabilities ? await n.getPhotoCapabilities() : void 0, i =
|
|
528
|
+
await Ne(e);
|
|
529
|
+
let n = new t(e), r = n.getPhotoCapabilities ? await n.getPhotoCapabilities() : void 0, i = he(r), a;
|
|
530
530
|
try {
|
|
531
531
|
a = await n.takePhoto(i);
|
|
532
532
|
} catch {
|
|
533
533
|
a = await n.takePhoto();
|
|
534
534
|
}
|
|
535
535
|
return {
|
|
536
|
-
frame: await
|
|
536
|
+
frame: await Pe(a),
|
|
537
537
|
requested: i,
|
|
538
538
|
photoMax: {
|
|
539
539
|
width: r?.imageWidth?.max,
|
|
@@ -541,42 +541,42 @@ async function Pe(e) {
|
|
|
541
541
|
}
|
|
542
542
|
};
|
|
543
543
|
}
|
|
544
|
-
function
|
|
544
|
+
function M(e, n) {
|
|
545
545
|
if (!e.videoWidth || !e.videoHeight) throw Error("The camera is not ready to capture a frame.");
|
|
546
|
-
let r =
|
|
546
|
+
let r = j(e.videoWidth, e.videoHeight, n), i = document.createElement("canvas");
|
|
547
547
|
i.width = r.width, i.height = r.height;
|
|
548
548
|
let a = i.getContext("2d");
|
|
549
549
|
if (!a) throw t();
|
|
550
550
|
return a.drawImage(e, 0, 0, i.width, i.height), i;
|
|
551
551
|
}
|
|
552
|
-
function
|
|
553
|
-
let t =
|
|
554
|
-
return e.idealWidth || e.idealHeight || e.maxWidth || e.maxHeight ? [
|
|
555
|
-
|
|
552
|
+
function Ie(e) {
|
|
553
|
+
let t = D();
|
|
554
|
+
return e.idealWidth || e.idealHeight || e.maxWidth || e.maxHeight ? [A(e, t)] : [
|
|
555
|
+
A({
|
|
556
556
|
...e,
|
|
557
557
|
idealWidth: 3840,
|
|
558
558
|
idealHeight: 2160
|
|
559
559
|
}, t),
|
|
560
|
-
|
|
560
|
+
A({
|
|
561
561
|
...e,
|
|
562
562
|
idealWidth: 2560,
|
|
563
563
|
idealHeight: 1440
|
|
564
564
|
}, t),
|
|
565
|
-
|
|
565
|
+
A({
|
|
566
566
|
...e,
|
|
567
567
|
idealWidth: 1920,
|
|
568
568
|
idealHeight: 1080
|
|
569
569
|
}, t)
|
|
570
570
|
];
|
|
571
571
|
}
|
|
572
|
-
async function
|
|
572
|
+
async function Le(t, n = {}) {
|
|
573
573
|
await x("scan");
|
|
574
574
|
let r = n.torch ?? "alwaysOff";
|
|
575
575
|
if (r !== "alwaysOff" && await x("torch"), !window.isSecureContext && location.hostname !== "localhost") throw new e("secure-context", "Camera access requires HTTPS.");
|
|
576
576
|
if (!navigator.mediaDevices?.getUserMedia) throw Error("Live camera access is unavailable. Use the native camera picker instead.");
|
|
577
577
|
t.muted = !0, t.autoplay = !0, t.playsInline = !0, t.setAttribute("playsinline", "");
|
|
578
578
|
let i, a;
|
|
579
|
-
for (let e of
|
|
579
|
+
for (let e of Ie(n)) try {
|
|
580
580
|
i = await navigator.mediaDevices.getUserMedia(e);
|
|
581
581
|
break;
|
|
582
582
|
} catch (e) {
|
|
@@ -589,8 +589,8 @@ async function Ie(t, n = {}) {
|
|
|
589
589
|
for (let e of i.getTracks()) e.stop();
|
|
590
590
|
throw Error("The camera did not provide a video track.");
|
|
591
591
|
}
|
|
592
|
-
await
|
|
593
|
-
let s =
|
|
592
|
+
await je(o);
|
|
593
|
+
let s = we(t), c = "ImageCapture" in globalThis, l = be(r, (typeof o.getCapabilities == "function" ? o.getCapabilities() : void 0)?.torch === !0), u = !1, d = async (e) => {
|
|
594
594
|
if (!l.supported || o.readyState !== "live") return !1;
|
|
595
595
|
try {
|
|
596
596
|
return await o.applyConstraints({ advanced: [{ torch: e }] }), l = {
|
|
@@ -608,7 +608,7 @@ async function Ie(t, n = {}) {
|
|
|
608
608
|
}
|
|
609
609
|
};
|
|
610
610
|
l.on && await d(!0);
|
|
611
|
-
let f = r === "auto" && l.supported ? new
|
|
611
|
+
let f = r === "auto" && l.supported ? new ye() : void 0, p = f ? window.setInterval(() => {
|
|
612
612
|
if (u || !l.supported) return;
|
|
613
613
|
let e = f.update(s.getLiveLuminance());
|
|
614
614
|
e !== void 0 && e !== l.on && (u = !0, d(e).finally(() => {
|
|
@@ -634,7 +634,7 @@ async function Ie(t, n = {}) {
|
|
|
634
634
|
torchSupported: l.supported,
|
|
635
635
|
torchOn: l.on,
|
|
636
636
|
torch: { ...l },
|
|
637
|
-
engine:
|
|
637
|
+
engine: D()
|
|
638
638
|
};
|
|
639
639
|
};
|
|
640
640
|
return {
|
|
@@ -648,20 +648,20 @@ async function Ie(t, n = {}) {
|
|
|
648
648
|
get torchOn() {
|
|
649
649
|
return l.on;
|
|
650
650
|
},
|
|
651
|
-
capture: (e) =>
|
|
651
|
+
capture: (e) => De(t, s, e),
|
|
652
652
|
async captureLiveFrame(e) {
|
|
653
653
|
let n = globalThis.ImageCapture;
|
|
654
654
|
if (n) try {
|
|
655
655
|
let t = await new n(o).grabFrame?.();
|
|
656
656
|
if (t) {
|
|
657
|
-
let n =
|
|
657
|
+
let n = j(t.width, t.height, e), r = document.createElement("canvas");
|
|
658
658
|
r.width = n.width, r.height = n.height;
|
|
659
659
|
let i = r.getContext("2d");
|
|
660
660
|
if (i && (i.imageSmoothingEnabled = !0, "imageSmoothingQuality" in i && (i.imageSmoothingQuality = "high"), i.drawImage(t, 0, 0, r.width, r.height)), t.close?.(), r.width && !k(r)) return r;
|
|
661
661
|
}
|
|
662
662
|
} catch {}
|
|
663
663
|
try {
|
|
664
|
-
return
|
|
664
|
+
return De(t, s, e);
|
|
665
665
|
} catch {
|
|
666
666
|
return;
|
|
667
667
|
}
|
|
@@ -669,13 +669,13 @@ async function Ie(t, n = {}) {
|
|
|
669
669
|
async capturePhoto() {
|
|
670
670
|
let e, n = 0;
|
|
671
671
|
try {
|
|
672
|
-
e =
|
|
672
|
+
e = M(t), n = Ce(e);
|
|
673
673
|
} catch {
|
|
674
674
|
e = void 0;
|
|
675
675
|
}
|
|
676
676
|
let r = s.getFrame(), i, a = !1, l = !1, u, d;
|
|
677
|
-
if (
|
|
678
|
-
let e = await
|
|
677
|
+
if (pe(D(), c)) try {
|
|
678
|
+
let e = await Fe(o);
|
|
679
679
|
i = e?.frame, u = e?.requested, d = e?.photoMax;
|
|
680
680
|
} catch {
|
|
681
681
|
a = !0, i = void 0;
|
|
@@ -683,14 +683,14 @@ async function Ie(t, n = {}) {
|
|
|
683
683
|
let f = {
|
|
684
684
|
width: t.videoWidth,
|
|
685
685
|
height: t.videoHeight
|
|
686
|
-
}, p = i ?
|
|
686
|
+
}, p = i ? Ce(i) : 0, h = !!(i && p > 10 && ge(i, f));
|
|
687
687
|
if (i && p > 10 && !h && (l = !0), h && i) return console.info("[exige-scanner] capture", {
|
|
688
688
|
method: "image-capture",
|
|
689
689
|
frame: `${i.width}×${i.height}`,
|
|
690
690
|
video: `${t.videoWidth}×${t.videoHeight}`,
|
|
691
691
|
photoMax: d ? `${d.width ?? "—"}×${d.height ?? "—"}` : void 0,
|
|
692
692
|
photoRequest: u,
|
|
693
|
-
aspectMatch:
|
|
693
|
+
aspectMatch: _e(i, f)
|
|
694
694
|
}), {
|
|
695
695
|
frame: i,
|
|
696
696
|
method: "image-capture",
|
|
@@ -698,7 +698,7 @@ async function Ie(t, n = {}) {
|
|
|
698
698
|
luminance: p,
|
|
699
699
|
diagnostics: m()
|
|
700
700
|
};
|
|
701
|
-
let g = e && n > 10 ? e : void 0, _ = g ?? (r ?
|
|
701
|
+
let g = e && n > 10 ? e : void 0, _ = g ?? (r ? Te(r) : void 0);
|
|
702
702
|
if (!_) throw Error("The camera preview produced no visible pixels. Keep the scanner on screen, wait for the preview, and retake.");
|
|
703
703
|
let v = l ? "image-capture-preview-size" : i ? "image-capture-empty" : a ? "image-capture-failed" : g ? void 0 : "video-frame-empty";
|
|
704
704
|
return console.info("[exige-scanner] capture", {
|
|
@@ -730,13 +730,13 @@ async function Ie(t, n = {}) {
|
|
|
730
730
|
}
|
|
731
731
|
};
|
|
732
732
|
}
|
|
733
|
-
function
|
|
733
|
+
function Re() {
|
|
734
734
|
let e = typeof navigator > "u" ? void 0 : navigator.userActivation;
|
|
735
735
|
return !e || e.isActive;
|
|
736
736
|
}
|
|
737
|
-
async function
|
|
737
|
+
async function ze() {
|
|
738
738
|
let e = document.createElement("input");
|
|
739
|
-
return e.type = "file", e.accept = "image/*", e.capture = "environment", e.setAttribute("capture", "environment"),
|
|
739
|
+
return e.type = "file", e.accept = "image/*", e.capture = "environment", e.setAttribute("capture", "environment"), Pe(await new Promise((t, n) => {
|
|
740
740
|
e.addEventListener("change", () => {
|
|
741
741
|
let r = e.files?.[0];
|
|
742
742
|
r ? t(r) : n(/* @__PURE__ */ Error("No photo was selected."));
|
|
@@ -747,20 +747,20 @@ async function Re() {
|
|
|
747
747
|
}
|
|
748
748
|
//#endregion
|
|
749
749
|
//#region src/sdk/ort-cdn.ts
|
|
750
|
-
var
|
|
751
|
-
`${
|
|
752
|
-
function
|
|
750
|
+
var Be = "1.30.0";
|
|
751
|
+
`${Be}`, `${Be}`;
|
|
752
|
+
function Ve(e) {
|
|
753
753
|
return !e.ok && e.status !== 206 ? !1 : !(e.headers.get("content-type") ?? "").toLowerCase().includes("text/html");
|
|
754
754
|
}
|
|
755
|
-
async function
|
|
755
|
+
async function He(e, t = fetch) {
|
|
756
756
|
if (!e) return !1;
|
|
757
757
|
try {
|
|
758
758
|
let n = await t(e, { method: "HEAD" });
|
|
759
|
-
if (
|
|
759
|
+
if (Ve(n)) return !0;
|
|
760
760
|
if (n.status === 404 || n.status === 410) return !1;
|
|
761
761
|
} catch {}
|
|
762
762
|
try {
|
|
763
|
-
return
|
|
763
|
+
return Ve(await t(e, {
|
|
764
764
|
method: "GET",
|
|
765
765
|
headers: { Range: "bytes=0-63" }
|
|
766
766
|
}));
|
|
@@ -770,29 +770,29 @@ async function Ve(e, t = fetch) {
|
|
|
770
770
|
}
|
|
771
771
|
//#endregion
|
|
772
772
|
//#region src/sdk/ort-runtime.ts
|
|
773
|
-
var
|
|
774
|
-
function
|
|
773
|
+
var Ue = new URL("./assets/ort-wasm-simd-threaded.jsep.wasm", import.meta.url), We = new URL("./assets/ort-wasm-simd-threaded.jsep.mjs", import.meta.url);
|
|
774
|
+
function Ge() {
|
|
775
775
|
return {
|
|
776
|
-
wasm:
|
|
777
|
-
mjs:
|
|
776
|
+
wasm: Ue.href,
|
|
777
|
+
mjs: We.href
|
|
778
778
|
};
|
|
779
779
|
}
|
|
780
|
-
function
|
|
781
|
-
return typeof e == "string" ? e.trim() ||
|
|
780
|
+
function Ke(e) {
|
|
781
|
+
return typeof e == "string" ? e.trim() || Ge() : e?.wasm.trim() && e.mjs.trim() ? {
|
|
782
782
|
wasm: e.wasm.trim(),
|
|
783
783
|
mjs: e.mjs.trim()
|
|
784
|
-
} :
|
|
784
|
+
} : Ge();
|
|
785
785
|
}
|
|
786
786
|
//#endregion
|
|
787
787
|
//#region src/sdk/image.ts
|
|
788
|
-
function
|
|
788
|
+
function qe(e, t, n) {
|
|
789
789
|
let r = n ? Math.min(1, n / Math.max(e, t)) : 1;
|
|
790
790
|
return {
|
|
791
791
|
width: Math.max(1, Math.round(e * r)),
|
|
792
792
|
height: Math.max(1, Math.round(t * r))
|
|
793
793
|
};
|
|
794
794
|
}
|
|
795
|
-
async function
|
|
795
|
+
async function Je(e) {
|
|
796
796
|
let t = URL.createObjectURL(e);
|
|
797
797
|
try {
|
|
798
798
|
let e = new Image();
|
|
@@ -801,26 +801,26 @@ async function qe(e) {
|
|
|
801
801
|
URL.revokeObjectURL(t);
|
|
802
802
|
}
|
|
803
803
|
}
|
|
804
|
-
async function
|
|
804
|
+
async function N(e, n = {}) {
|
|
805
805
|
if (e instanceof HTMLCanvasElement && n.cloneCanvas === !1 && !n.maxDimension) return e;
|
|
806
806
|
let r = document.createElement("canvas"), i = r.getContext("2d", { willReadFrequently: !0 });
|
|
807
807
|
if (!i) throw t();
|
|
808
808
|
if (e instanceof Blob) {
|
|
809
809
|
if ("createImageBitmap" in window) try {
|
|
810
|
-
let t = await createImageBitmap(e), a =
|
|
810
|
+
let t = await createImageBitmap(e), a = qe(t.width, t.height, n.maxDimension);
|
|
811
811
|
return r.width = a.width, r.height = a.height, i.drawImage(t, 0, 0, a.width, a.height), t.close(), r;
|
|
812
812
|
} catch {}
|
|
813
|
-
e = await
|
|
813
|
+
e = await Je(e);
|
|
814
814
|
}
|
|
815
815
|
let a = e instanceof HTMLImageElement ? e.naturalWidth : e.width, o = e instanceof HTMLImageElement ? e.naturalHeight : e.height;
|
|
816
816
|
if (!a || !o) throw Error("The image has no readable dimensions.");
|
|
817
|
-
let s =
|
|
817
|
+
let s = qe(a, o, n.maxDimension);
|
|
818
818
|
return r.width = s.width, r.height = s.height, i.drawImage(e, 0, 0, s.width, s.height), r;
|
|
819
819
|
}
|
|
820
|
-
function
|
|
820
|
+
function Ye(e, t = "image/png", n = .92) {
|
|
821
821
|
return new Promise((r, i) => e.toBlob((e) => e ? r(e) : i(/* @__PURE__ */ Error("Could not encode the image.")), t, n));
|
|
822
822
|
}
|
|
823
|
-
function
|
|
823
|
+
function Xe(e, t, n) {
|
|
824
824
|
let r = Math.max(0, Math.min(t, e.x)), i = Math.max(0, Math.min(n, e.y));
|
|
825
825
|
return {
|
|
826
826
|
x: r,
|
|
@@ -831,20 +831,20 @@ function Ye(e, t, n) {
|
|
|
831
831
|
}
|
|
832
832
|
//#endregion
|
|
833
833
|
//#region src/sdk/scan.ts
|
|
834
|
-
var
|
|
835
|
-
function
|
|
834
|
+
var Ze = "https://exige-scanner-sdk.vercel.app/models/docaligner-lcnet100-f4117b78.onnx", Qe = 1280;
|
|
835
|
+
function $e(e, t, n) {
|
|
836
836
|
if (n) return n;
|
|
837
|
-
let r = Math.max(e, t), i = r / Math.max(1, Math.min(e, t)), a =
|
|
838
|
-
return i >= 1.6 ? Math.min(r, Math.max(a,
|
|
837
|
+
let r = Math.max(e, t), i = r / Math.max(1, Math.min(e, t)), a = at() ? 560 : 900;
|
|
838
|
+
return i >= 1.6 ? Math.min(r, Math.max(a, Qe)) : a;
|
|
839
839
|
}
|
|
840
|
-
function
|
|
840
|
+
function et(e) {
|
|
841
841
|
return e?.trim() || "https://exige-scanner-sdk.vercel.app/models/docaligner-lcnet100-f4117b78.onnx";
|
|
842
842
|
}
|
|
843
|
-
var
|
|
844
|
-
function
|
|
843
|
+
var tt = 3, P, nt = 0, F = /* @__PURE__ */ new Map();
|
|
844
|
+
function I(e, t) {
|
|
845
845
|
return Math.hypot(e.x - t.x, e.y - t.y);
|
|
846
846
|
}
|
|
847
|
-
function
|
|
847
|
+
function rt(e) {
|
|
848
848
|
return {
|
|
849
849
|
...e,
|
|
850
850
|
edges: {
|
|
@@ -867,7 +867,7 @@ function nt(e) {
|
|
|
867
867
|
}
|
|
868
868
|
};
|
|
869
869
|
}
|
|
870
|
-
function
|
|
870
|
+
function it(e, t) {
|
|
871
871
|
let n = (e) => ({
|
|
872
872
|
x: e.x / t,
|
|
873
873
|
y: e.y / t
|
|
@@ -879,43 +879,43 @@ function rt(e, t) {
|
|
|
879
879
|
bottomLeft: n(e.bottomLeft)
|
|
880
880
|
};
|
|
881
881
|
}
|
|
882
|
-
function
|
|
882
|
+
function at() {
|
|
883
883
|
return typeof navigator > "u" ? !1 : navigator.maxTouchPoints > 0 || navigator.hardwareConcurrency <= 4 || typeof matchMedia == "function" && matchMedia("(pointer: coarse)").matches;
|
|
884
884
|
}
|
|
885
|
-
function
|
|
885
|
+
function ot(t, n, r, i) {
|
|
886
886
|
return new Promise((a, o) => {
|
|
887
|
-
|
|
887
|
+
P || (P = new Worker(new URL("./assets/document-worker.js", import.meta.url), { type: "module" }), P.onmessage = (t) => {
|
|
888
888
|
if (t.data.download?.url) {
|
|
889
|
-
|
|
889
|
+
ae(t.data.download.url, t.data.download);
|
|
890
890
|
return;
|
|
891
891
|
}
|
|
892
|
-
let n =
|
|
893
|
-
n && (
|
|
894
|
-
},
|
|
892
|
+
let n = F.get(t.data.id);
|
|
893
|
+
n && (F.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.")));
|
|
894
|
+
}, P.onerror = () => {
|
|
895
895
|
let t = new e("worker", "The document worker could not start.");
|
|
896
|
-
for (let e of
|
|
897
|
-
|
|
896
|
+
for (let e of F.values()) e.reject(t);
|
|
897
|
+
F.clear(), P?.terminate(), P = void 0;
|
|
898
898
|
});
|
|
899
|
-
let s = ++
|
|
900
|
-
|
|
899
|
+
let s = ++nt;
|
|
900
|
+
F.set(s, {
|
|
901
901
|
resolve: a,
|
|
902
902
|
reject: o
|
|
903
903
|
});
|
|
904
904
|
let c = t.slice().buffer;
|
|
905
|
-
|
|
905
|
+
P.postMessage({
|
|
906
906
|
id: s,
|
|
907
907
|
pixels: c,
|
|
908
908
|
width: n,
|
|
909
909
|
height: r,
|
|
910
|
-
modelUrl:
|
|
910
|
+
modelUrl: et(i.modelUrl),
|
|
911
911
|
heatmapThreshold: i.heatmapThreshold,
|
|
912
912
|
cacheModel: i.cacheModel,
|
|
913
|
-
ortWasmPaths:
|
|
914
|
-
preferWebGpu: i.preferWebGpu ??
|
|
913
|
+
ortWasmPaths: Ke(i.ortWasmPaths),
|
|
914
|
+
preferWebGpu: i.preferWebGpu ?? de()
|
|
915
915
|
}, [c]);
|
|
916
916
|
});
|
|
917
917
|
}
|
|
918
|
-
async function
|
|
918
|
+
async function st(n, r) {
|
|
919
919
|
let { width: i, height: a } = n, o = r.minDimension ?? 360;
|
|
920
920
|
if (Math.min(i, a) < o) return {
|
|
921
921
|
status: "low-quality",
|
|
@@ -924,7 +924,7 @@ async function ot(n, r) {
|
|
|
924
924
|
sourceWidth: i,
|
|
925
925
|
sourceHeight: a
|
|
926
926
|
};
|
|
927
|
-
let s =
|
|
927
|
+
let s = $e(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;
|
|
928
928
|
if (c === 1) {
|
|
929
929
|
let e = n.getContext("2d", { willReadFrequently: !0 });
|
|
930
930
|
if (!e) throw t();
|
|
@@ -938,7 +938,7 @@ async function ot(n, r) {
|
|
|
938
938
|
}
|
|
939
939
|
let f;
|
|
940
940
|
if (r.useWorker !== !1 && typeof Worker < "u") try {
|
|
941
|
-
f = await
|
|
941
|
+
f = await ot(d, l, u, r);
|
|
942
942
|
} catch (t) {
|
|
943
943
|
if (t instanceof e && (t.code === "worker" || t.code === "model-http")) throw t;
|
|
944
944
|
f = {
|
|
@@ -962,7 +962,7 @@ async function ot(n, r) {
|
|
|
962
962
|
modelNote: y,
|
|
963
963
|
inferenceMs: b
|
|
964
964
|
};
|
|
965
|
-
if (p <
|
|
965
|
+
if (p < tt) return {
|
|
966
966
|
status: "low-quality",
|
|
967
967
|
confidence: Math.min(.3, p / 18),
|
|
968
968
|
message: "The image is too soft or dark to resolve four document edges.",
|
|
@@ -978,7 +978,7 @@ async function ot(n, r) {
|
|
|
978
978
|
sourceHeight: a,
|
|
979
979
|
...x
|
|
980
980
|
};
|
|
981
|
-
let S =
|
|
981
|
+
let S = it(m.corners, c), C = rt(S), w = r.minConfidence ?? .58;
|
|
982
982
|
return m.confidence < w ? {
|
|
983
983
|
status: "low-confidence",
|
|
984
984
|
quad: C,
|
|
@@ -999,14 +999,14 @@ async function ot(n, r) {
|
|
|
999
999
|
...x
|
|
1000
1000
|
};
|
|
1001
1001
|
}
|
|
1002
|
-
function
|
|
1003
|
-
let n = Math.max(1, Math.round(Math.max(
|
|
1002
|
+
function ct(e, t) {
|
|
1003
|
+
let n = Math.max(1, Math.round(Math.max(I(e.topLeft, e.topRight), I(e.bottomLeft, e.bottomRight)))), r = Math.max(1, Math.round(Math.max(I(e.topLeft, e.bottomLeft), I(e.topRight, e.bottomRight)))), i = Math.min(1, t / Math.max(n, r));
|
|
1004
1004
|
return {
|
|
1005
1005
|
width: Math.max(1, Math.round(n * i)),
|
|
1006
1006
|
height: Math.max(1, Math.round(r * i))
|
|
1007
1007
|
};
|
|
1008
1008
|
}
|
|
1009
|
-
function
|
|
1009
|
+
function lt(e, t, n, r, i) {
|
|
1010
1010
|
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) => {
|
|
1011
1011
|
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;
|
|
1012
1012
|
return Math.round(n * (1 - f) + r * f);
|
|
@@ -1018,8 +1018,8 @@ function ct(e, t, n, r, i) {
|
|
|
1018
1018
|
255
|
|
1019
1019
|
];
|
|
1020
1020
|
}
|
|
1021
|
-
function
|
|
1022
|
-
let { width: i, height: a } =
|
|
1021
|
+
function ut(e, n, r) {
|
|
1022
|
+
let { width: i, height: a } = ct(n, r), o = e.getContext("2d", { willReadFrequently: !0 });
|
|
1023
1023
|
if (!o) throw t();
|
|
1024
1024
|
let s = o.getImageData(0, 0, e.width, e.height), c = document.createElement("canvas");
|
|
1025
1025
|
c.width = i, c.height = a;
|
|
@@ -1029,58 +1029,58 @@ function lt(e, n, r) {
|
|
|
1029
1029
|
for (let t = 0; t < a; t += 1) {
|
|
1030
1030
|
let n = t / Math.max(1, a - 1);
|
|
1031
1031
|
for (let r = 0; r < i; r += 1) {
|
|
1032
|
-
let a = r / Math.max(1, i - 1), o = S * a + C * n + 1, c = (w * a + T * n + d.x) / o, l = (ee * a + E * n + d.y) / o, [f, p, m, h] =
|
|
1032
|
+
let a = r / Math.max(1, i - 1), o = S * a + C * n + 1, c = (w * a + T * n + d.x) / o, l = (ee * a + E * n + d.y) / o, [f, p, m, h] = lt(s.data, e.width, e.height, c, l), g = (t * i + r) * 4;
|
|
1033
1033
|
u.data[g] = f, u.data[g + 1] = p, u.data[g + 2] = m, u.data[g + 3] = h;
|
|
1034
1034
|
}
|
|
1035
1035
|
}
|
|
1036
1036
|
return l.putImageData(u, 0, 0), c;
|
|
1037
1037
|
}
|
|
1038
|
-
async function
|
|
1039
|
-
return await x("scan"),
|
|
1038
|
+
async function dt(e, t = {}) {
|
|
1039
|
+
return await x("scan"), st(await N(e, { cloneCanvas: !1 }), t);
|
|
1040
1040
|
}
|
|
1041
|
-
async function
|
|
1041
|
+
async function ft(e, t, n = {}) {
|
|
1042
1042
|
await x("scan");
|
|
1043
|
-
let r = await
|
|
1043
|
+
let r = await N(e, { cloneCanvas: !1 }), i = n.maxOutputDimension ?? 4096;
|
|
1044
1044
|
return {
|
|
1045
1045
|
status: "success",
|
|
1046
1046
|
corners: t,
|
|
1047
|
-
quad:
|
|
1047
|
+
quad: rt(t),
|
|
1048
1048
|
confidence: 1,
|
|
1049
1049
|
message: "Captured with the document edges shown in the finder.",
|
|
1050
1050
|
sourceWidth: r.width,
|
|
1051
1051
|
sourceHeight: r.height,
|
|
1052
|
-
canvas:
|
|
1052
|
+
canvas: ut(r, t, i)
|
|
1053
1053
|
};
|
|
1054
1054
|
}
|
|
1055
|
-
async function
|
|
1055
|
+
async function L(e, t = {}) {
|
|
1056
1056
|
await x("scan");
|
|
1057
|
-
let n = await
|
|
1057
|
+
let n = await N(e, { cloneCanvas: !1 }), r = await st(n, t);
|
|
1058
1058
|
if (r.status !== "success" || !r.corners) return r;
|
|
1059
1059
|
let i = t.maxOutputDimension ?? 4096;
|
|
1060
1060
|
return {
|
|
1061
1061
|
...r,
|
|
1062
|
-
canvas:
|
|
1062
|
+
canvas: ut(n, r.corners, i),
|
|
1063
1063
|
message: "Four document edges detected and perspective-corrected."
|
|
1064
1064
|
};
|
|
1065
1065
|
}
|
|
1066
|
-
function
|
|
1066
|
+
function pt(e) {
|
|
1067
1067
|
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})` : ""}`;
|
|
1068
1068
|
}
|
|
1069
|
-
async function
|
|
1070
|
-
let n = await
|
|
1069
|
+
async function mt(e, t = {}) {
|
|
1070
|
+
let n = await L(e, t);
|
|
1071
1071
|
return n.status === "success" ? n : {
|
|
1072
1072
|
...n,
|
|
1073
|
-
message:
|
|
1073
|
+
message: pt(n)
|
|
1074
1074
|
};
|
|
1075
1075
|
}
|
|
1076
1076
|
//#endregion
|
|
1077
1077
|
//#region src/sdk/lighting.ts
|
|
1078
|
-
function
|
|
1078
|
+
function ht(e, t) {
|
|
1079
1079
|
if (!e.length) return 0;
|
|
1080
1080
|
let n = [...e].sort((e, t) => e - t);
|
|
1081
1081
|
return n[Math.min(n.length - 1, Math.floor(n.length * t))];
|
|
1082
1082
|
}
|
|
1083
|
-
function
|
|
1083
|
+
function gt(e, t, n, r = 12) {
|
|
1084
1084
|
if (!t || !n || e.length < t * n) return {
|
|
1085
1085
|
strong: !1,
|
|
1086
1086
|
strength: 0,
|
|
@@ -1103,7 +1103,7 @@ function ht(e, t, n, r = 12) {
|
|
|
1103
1103
|
});
|
|
1104
1104
|
}
|
|
1105
1105
|
}
|
|
1106
|
-
let s =
|
|
1106
|
+
let s = ht(o.map((e) => e.mean), .8), c = o.map((e) => s - e.mean >= 24 && e.mean >= 35), l = new Uint8Array(o.length), u = [];
|
|
1107
1107
|
for (let e = 0; e < o.length; e += 1) {
|
|
1108
1108
|
if (!c[e] || l[e]) continue;
|
|
1109
1109
|
let t = [], n = [e];
|
|
@@ -1151,11 +1151,11 @@ function ht(e, t, n, r = 12) {
|
|
|
1151
1151
|
}
|
|
1152
1152
|
return d;
|
|
1153
1153
|
}
|
|
1154
|
-
function
|
|
1154
|
+
function _t(e, t, n, r, i, a, o) {
|
|
1155
1155
|
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));
|
|
1156
1156
|
return (e[c * t + u] - e[s * t + u] - e[c * t + l] + e[s * t + l]) / d;
|
|
1157
1157
|
}
|
|
1158
|
-
function
|
|
1158
|
+
function vt(e, t, n) {
|
|
1159
1159
|
let r = t + 1, i = new Uint32Array((t + 1) * (n + 1));
|
|
1160
1160
|
for (let a = 1; a <= n; a += 1) {
|
|
1161
1161
|
let n = 0;
|
|
@@ -1166,23 +1166,23 @@ function _t(e, t, n) {
|
|
|
1166
1166
|
stride: r
|
|
1167
1167
|
};
|
|
1168
1168
|
}
|
|
1169
|
-
function
|
|
1170
|
-
let { integral: i, stride: a } =
|
|
1169
|
+
function yt(e, t, n, r = Math.max(12, Math.round(Math.max(t, n) / 32))) {
|
|
1170
|
+
let { integral: i, stride: a } = vt(e, t, n), o = new Uint8Array(e.length);
|
|
1171
1171
|
for (let s = 0; s < n; s += 1) for (let c = 0; c < t; c += 1) {
|
|
1172
|
-
let l =
|
|
1172
|
+
let l = _t(i, a, t, n, c, s, r);
|
|
1173
1173
|
o[s * t + c] = Math.max(0, Math.min(255, Math.round(e[s * t + c] * 235 / Math.max(24, l))));
|
|
1174
1174
|
}
|
|
1175
1175
|
return o;
|
|
1176
1176
|
}
|
|
1177
|
-
function
|
|
1178
|
-
let { integral: a, stride: o } =
|
|
1177
|
+
function bt(e, t, n, r = Math.max(8, Math.round(Math.max(t, n) / 64)), i = .12) {
|
|
1178
|
+
let { integral: a, stride: o } = vt(e, t, n), s = new Uint8Array(e.length), c = 1 - i;
|
|
1179
1179
|
for (let i = 0; i < n; i += 1) for (let l = 0; l < t; l += 1) {
|
|
1180
|
-
let u =
|
|
1180
|
+
let u = _t(a, o, t, n, l, i, r);
|
|
1181
1181
|
s[i * t + l] = e[i * t + l] < u * c ? 0 : 255;
|
|
1182
1182
|
}
|
|
1183
1183
|
return s;
|
|
1184
1184
|
}
|
|
1185
|
-
function
|
|
1185
|
+
function xt(e, t, n) {
|
|
1186
1186
|
let r = [
|
|
1187
1187
|
e.topLeft,
|
|
1188
1188
|
e.topRight,
|
|
@@ -1196,8 +1196,8 @@ function bt(e, t, n) {
|
|
|
1196
1196
|
height: s - a
|
|
1197
1197
|
};
|
|
1198
1198
|
}
|
|
1199
|
-
function
|
|
1200
|
-
let n =
|
|
1199
|
+
function St(e, t) {
|
|
1200
|
+
let n = xt(t, e.width, e.height);
|
|
1201
1201
|
if (n.width <= 0 || n.height <= 0) return {
|
|
1202
1202
|
strong: !1,
|
|
1203
1203
|
strength: 0,
|
|
@@ -1216,26 +1216,26 @@ function xt(e, t) {
|
|
|
1216
1216
|
i.drawImage(e, n.left, n.top, n.width, n.height, 0, 0, r.width, r.height);
|
|
1217
1217
|
let a = i.getImageData(0, 0, r.width, r.height).data, o = new Uint8Array(r.width * r.height);
|
|
1218
1218
|
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);
|
|
1219
|
-
return
|
|
1219
|
+
return gt(o, r.width, r.height);
|
|
1220
1220
|
}
|
|
1221
1221
|
//#endregion
|
|
1222
1222
|
//#region src/sdk/finder.ts
|
|
1223
|
-
function
|
|
1223
|
+
function Ct(e, t) {
|
|
1224
1224
|
return t.castShadow && (e.reason === "hold-still" || e.reason === "ready") ? t.hint ?? e.hint : e.hint;
|
|
1225
1225
|
}
|
|
1226
|
-
function
|
|
1226
|
+
function wt(e, t, n) {
|
|
1227
1227
|
if (n <= 0) return 0;
|
|
1228
1228
|
let r = n - (t - e);
|
|
1229
1229
|
return r <= 0 ? 0 : Math.max(1, Math.ceil(r / 1e3));
|
|
1230
1230
|
}
|
|
1231
|
-
function
|
|
1232
|
-
return
|
|
1231
|
+
function Tt(e) {
|
|
1232
|
+
return "Hold still";
|
|
1233
1233
|
}
|
|
1234
|
-
async function
|
|
1234
|
+
async function Et(e, t) {
|
|
1235
1235
|
let n = await e();
|
|
1236
1236
|
return t(), n;
|
|
1237
1237
|
}
|
|
1238
|
-
function
|
|
1238
|
+
function Dt(e) {
|
|
1239
1239
|
return e === "alwaysOn" || e === "only" ? {
|
|
1240
1240
|
visible: !1,
|
|
1241
1241
|
checked: !0,
|
|
@@ -1250,7 +1250,7 @@ function Et(e) {
|
|
|
1250
1250
|
mutable: !0
|
|
1251
1251
|
};
|
|
1252
1252
|
}
|
|
1253
|
-
function
|
|
1253
|
+
function R(e) {
|
|
1254
1254
|
return [
|
|
1255
1255
|
e.topLeft,
|
|
1256
1256
|
e.topRight,
|
|
@@ -1258,19 +1258,19 @@ function z(e) {
|
|
|
1258
1258
|
e.bottomLeft
|
|
1259
1259
|
];
|
|
1260
1260
|
}
|
|
1261
|
-
var
|
|
1262
|
-
function
|
|
1261
|
+
var Ot = 1e3, kt = 1600;
|
|
1262
|
+
function At(e = D()) {
|
|
1263
1263
|
return e.iosWebKit ? {
|
|
1264
1264
|
intervalMs: 70,
|
|
1265
1265
|
maxFrameDimension: 720,
|
|
1266
1266
|
maxAnalysisDimension: 720
|
|
1267
1267
|
} : {
|
|
1268
1268
|
intervalMs: 140,
|
|
1269
|
-
maxFrameDimension:
|
|
1269
|
+
maxFrameDimension: kt,
|
|
1270
1270
|
maxAnalysisDimension: 520
|
|
1271
1271
|
};
|
|
1272
1272
|
}
|
|
1273
|
-
function
|
|
1273
|
+
function jt(e, t) {
|
|
1274
1274
|
let n = e.status === "success" && e.modelStatus !== "failed", r = {
|
|
1275
1275
|
status: e.status,
|
|
1276
1276
|
confidence: Number(e.confidence.toFixed(3)),
|
|
@@ -1293,7 +1293,7 @@ function At(e, t) {
|
|
|
1293
1293
|
detail: r
|
|
1294
1294
|
};
|
|
1295
1295
|
}
|
|
1296
|
-
function
|
|
1296
|
+
function Mt(e) {
|
|
1297
1297
|
let t = 0;
|
|
1298
1298
|
for (let n = 0; n < e.length; n += 1) {
|
|
1299
1299
|
let r = e[n], i = e[(n + 1) % e.length];
|
|
@@ -1301,42 +1301,42 @@ function jt(e) {
|
|
|
1301
1301
|
}
|
|
1302
1302
|
return Math.abs(t) / 2;
|
|
1303
1303
|
}
|
|
1304
|
-
function
|
|
1304
|
+
function z(e, t) {
|
|
1305
1305
|
return Math.hypot(e.x - t.x, e.y - t.y);
|
|
1306
1306
|
}
|
|
1307
|
-
var
|
|
1307
|
+
var B = {
|
|
1308
1308
|
widthFill: 0,
|
|
1309
1309
|
heightFill: 0,
|
|
1310
1310
|
limitingFill: 0,
|
|
1311
1311
|
areaFill: 0,
|
|
1312
1312
|
aspectRatio: 1
|
|
1313
1313
|
};
|
|
1314
|
-
function
|
|
1315
|
-
let r =
|
|
1314
|
+
function Nt(e, t, n) {
|
|
1315
|
+
let r = R(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(z(c, l), z(d, u)), p = Math.max(z(c, d), z(l, u));
|
|
1316
1316
|
return {
|
|
1317
1317
|
widthFill: o,
|
|
1318
1318
|
heightFill: s,
|
|
1319
1319
|
limitingFill: Math.max(o, s),
|
|
1320
|
-
areaFill:
|
|
1320
|
+
areaFill: Mt(r) / Math.max(1, t * n),
|
|
1321
1321
|
aspectRatio: Math.max(f, p) / Math.max(1, Math.min(f, p))
|
|
1322
1322
|
};
|
|
1323
1323
|
}
|
|
1324
|
-
function
|
|
1324
|
+
function Pt(e, t, n, r = {}) {
|
|
1325
1325
|
let i = t ? r.exitFillRatio ?? .64 : r.minFillRatio ?? .72, a = r.highAspectRatio ?? 2.2;
|
|
1326
1326
|
if (e.aspectRatio < a) return i;
|
|
1327
1327
|
let o = t ? r.highAspectExitFillRatio : r.highAspectFillRatio;
|
|
1328
1328
|
return Math.min(o ?? i + .08, 1 - n * 2);
|
|
1329
1329
|
}
|
|
1330
|
-
function
|
|
1330
|
+
function Ft(e, t, n = {}) {
|
|
1331
1331
|
let r = n.confidenceThreshold ?? .72;
|
|
1332
1332
|
if (e.status !== "success" || !e.quad || e.confidence < r || !e.sourceWidth || !e.sourceHeight) return {
|
|
1333
1333
|
hint: "Place the document in the frame",
|
|
1334
1334
|
reason: "place-document",
|
|
1335
1335
|
fillRatio: 0,
|
|
1336
|
-
fill:
|
|
1336
|
+
fill: B,
|
|
1337
1337
|
readyForAutoCapture: !1
|
|
1338
1338
|
};
|
|
1339
|
-
let i =
|
|
1339
|
+
let i = R(e.quad), a = Nt(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;
|
|
1340
1340
|
if (i.some(({ x: t, y: n }) => t <= c || t >= e.sourceWidth - c || n <= l || n >= e.sourceHeight - l)) return {
|
|
1341
1341
|
hint: "Move farther away",
|
|
1342
1342
|
reason: "move-farther-away",
|
|
@@ -1344,14 +1344,14 @@ function Pt(e, t, n = {}) {
|
|
|
1344
1344
|
fill: a,
|
|
1345
1345
|
readyForAutoCapture: !1
|
|
1346
1346
|
};
|
|
1347
|
-
let [u, d, f, p] = i, m =
|
|
1347
|
+
let [u, d, f, p] = i, m = z(u, d), h = z(d, f), g = z(f, p), _ = z(p, u);
|
|
1348
1348
|
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) ? {
|
|
1349
1349
|
hint: "Hold the camera straight",
|
|
1350
1350
|
reason: "straighten-camera",
|
|
1351
1351
|
fillRatio: o,
|
|
1352
1352
|
fill: a,
|
|
1353
1353
|
readyForAutoCapture: !1
|
|
1354
|
-
} : o <
|
|
1354
|
+
} : o < Pt(a, t.previouslyReady === !0, s, n) ? {
|
|
1355
1355
|
hint: "Move closer",
|
|
1356
1356
|
reason: "move-closer",
|
|
1357
1357
|
fillRatio: o,
|
|
@@ -1365,7 +1365,7 @@ function Pt(e, t, n = {}) {
|
|
|
1365
1365
|
readyForAutoCapture: t.ready
|
|
1366
1366
|
};
|
|
1367
1367
|
}
|
|
1368
|
-
var
|
|
1368
|
+
var It = class {
|
|
1369
1369
|
previous;
|
|
1370
1370
|
count = 0;
|
|
1371
1371
|
ready = !1;
|
|
@@ -1382,8 +1382,8 @@ var Ft = class {
|
|
|
1382
1382
|
ready: !1,
|
|
1383
1383
|
movement: Infinity
|
|
1384
1384
|
};
|
|
1385
|
-
let t = Math.hypot(e.sourceWidth, e.sourceHeight), n = this.previous ? Math.max(...
|
|
1386
|
-
let r =
|
|
1385
|
+
let t = Math.hypot(e.sourceWidth, e.sourceHeight), n = this.previous ? Math.max(...R(e.quad).map((e, n) => {
|
|
1386
|
+
let r = R(this.previous)[n];
|
|
1387
1387
|
return Math.hypot(e.x - r.x, e.y - r.y) / Math.max(1, t);
|
|
1388
1388
|
})) : Infinity, r = this.options.exitCornerTolerance ?? Math.max(this.options.cornerTolerance, .036);
|
|
1389
1389
|
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, {
|
|
@@ -1393,14 +1393,14 @@ var Ft = class {
|
|
|
1393
1393
|
};
|
|
1394
1394
|
}
|
|
1395
1395
|
};
|
|
1396
|
-
function
|
|
1396
|
+
function Lt(e, n) {
|
|
1397
1397
|
let r = Math.min(1, n / Math.max(e.width, e.height)), i = document.createElement("canvas");
|
|
1398
1398
|
i.width = Math.max(1, Math.round(e.width * r)), i.height = Math.max(1, Math.round(e.height * r));
|
|
1399
1399
|
let a = i.getContext("2d");
|
|
1400
1400
|
if (!a) throw t();
|
|
1401
1401
|
return a.drawImage(e, 0, 0, i.width, i.height), i;
|
|
1402
1402
|
}
|
|
1403
|
-
function
|
|
1403
|
+
function Rt() {
|
|
1404
1404
|
let e = window.AudioContext ?? window.webkitAudioContext;
|
|
1405
1405
|
if (!e) return;
|
|
1406
1406
|
let t = new e(), n = Math.round(t.sampleRate * .09), r = t.createBuffer(1, n, t.sampleRate), i = r.getChannelData(0);
|
|
@@ -1411,29 +1411,29 @@ function Lt() {
|
|
|
1411
1411
|
let a = t.createBufferSource(), o = t.createBiquadFilter(), s = t.createGain();
|
|
1412
1412
|
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();
|
|
1413
1413
|
}
|
|
1414
|
-
async function
|
|
1414
|
+
async function zt(e) {
|
|
1415
1415
|
let t = document.createElement("video");
|
|
1416
1416
|
return t.muted = !0, t.autoplay = !0, t.playsInline = !0, t.srcObject = e, await t.play(), t;
|
|
1417
1417
|
}
|
|
1418
|
-
async function
|
|
1418
|
+
async function Bt(t) {
|
|
1419
1419
|
await x("scan");
|
|
1420
|
-
let n =
|
|
1420
|
+
let n = Dt(t.autoCapture), r = t.holdStillMs ?? 1e3, i = new It({
|
|
1421
1421
|
stableFrames: t.stableFrames ?? 4,
|
|
1422
1422
|
confidenceThreshold: t.confidenceThreshold ?? .72,
|
|
1423
1423
|
cornerTolerance: t.cornerTolerance ?? .024,
|
|
1424
1424
|
exitCornerTolerance: t.exitCornerTolerance ?? .036
|
|
1425
|
-
}), a =
|
|
1425
|
+
}), a = At(), o = t.maxFrameDimension ?? a.maxFrameDimension, s = t.intervalMs ?? a.intervalMs, c = {
|
|
1426
1426
|
minDimension: 220,
|
|
1427
1427
|
maxAnalysisDimension: a.maxAnalysisDimension,
|
|
1428
1428
|
...t.detection
|
|
1429
|
-
}, l = typeof MediaStream < "u" && t.source instanceof MediaStream ? await
|
|
1429
|
+
}, l = typeof MediaStream < "u" && t.source instanceof MediaStream ? await zt(t.source) : t.source, u = !0, d = !1, f = !1, p, m = 0, h, g = "", _ = 0, v = {
|
|
1430
1430
|
state: "detecting",
|
|
1431
1431
|
confidence: 0,
|
|
1432
1432
|
guidance: {
|
|
1433
1433
|
hint: "Place the document in the frame",
|
|
1434
1434
|
reason: "place-document",
|
|
1435
1435
|
fillRatio: 0,
|
|
1436
|
-
fill:
|
|
1436
|
+
fill: B,
|
|
1437
1437
|
readyForAutoCapture: !1
|
|
1438
1438
|
},
|
|
1439
1439
|
lighting: {
|
|
@@ -1443,10 +1443,10 @@ async function zt(t) {
|
|
|
1443
1443
|
stableFrames: 0,
|
|
1444
1444
|
requiredStableFrames: t.stableFrames ?? 4,
|
|
1445
1445
|
autoCapture: { ...n }
|
|
1446
|
-
}, y = () => l instanceof HTMLCanvasElement ?
|
|
1446
|
+
}, y = () => l instanceof HTMLCanvasElement ? Lt(l, o) : M(l, o), b = (e) => {
|
|
1447
1447
|
v = e, t.onStatus?.(e);
|
|
1448
1448
|
}, S = (e) => {
|
|
1449
|
-
let t =
|
|
1449
|
+
let t = jt(e, l instanceof HTMLVideoElement ? {
|
|
1450
1450
|
width: l.videoWidth,
|
|
1451
1451
|
height: l.videoHeight
|
|
1452
1452
|
} : {
|
|
@@ -1461,11 +1461,11 @@ async function zt(t) {
|
|
|
1461
1461
|
d = !0;
|
|
1462
1462
|
let n;
|
|
1463
1463
|
try {
|
|
1464
|
-
n = await
|
|
1464
|
+
n = await Et(t.captureFrame ?? y, () => {
|
|
1465
1465
|
b({
|
|
1466
1466
|
...v,
|
|
1467
1467
|
state: "captured"
|
|
1468
|
-
}), t.playShutterSound !== !1 &&
|
|
1468
|
+
}), t.playShutterSound !== !1 && Rt(), C();
|
|
1469
1469
|
});
|
|
1470
1470
|
} catch (e) {
|
|
1471
1471
|
throw d = !1, e instanceof Error ? e : /* @__PURE__ */ Error("The camera frame could not be captured.");
|
|
@@ -1479,9 +1479,9 @@ async function zt(t) {
|
|
|
1479
1479
|
}, T = async () => {
|
|
1480
1480
|
if (u && !d) {
|
|
1481
1481
|
try {
|
|
1482
|
-
let e = y(), a = await
|
|
1482
|
+
let e = y(), a = await dt(e, c);
|
|
1483
1483
|
h = a, S(a);
|
|
1484
|
-
let o = a.quad ?
|
|
1484
|
+
let o = a.quad ? St(e, a.quad) : {
|
|
1485
1485
|
strong: !1,
|
|
1486
1486
|
strength: 0
|
|
1487
1487
|
}, s = o.strong ? {
|
|
@@ -1491,7 +1491,7 @@ async function zt(t) {
|
|
|
1491
1491
|
} : {
|
|
1492
1492
|
castShadow: !1,
|
|
1493
1493
|
strength: o.strength
|
|
1494
|
-
}, l = i.update(a), u =
|
|
1494
|
+
}, l = i.update(a), u = Ft(a, {
|
|
1495
1495
|
...l,
|
|
1496
1496
|
previouslyReady: f
|
|
1497
1497
|
}, {
|
|
@@ -1499,11 +1499,11 @@ async function zt(t) {
|
|
|
1499
1499
|
...t.guidance
|
|
1500
1500
|
});
|
|
1501
1501
|
f = u.readyForAutoCapture;
|
|
1502
|
-
let d = performance.now();
|
|
1503
|
-
u.readyForAutoCapture && n.checked ? p ??= d : p = void 0;
|
|
1504
|
-
let
|
|
1502
|
+
let d = performance.now(), m = t.holdStillReady?.() ?? !0;
|
|
1503
|
+
u.readyForAutoCapture && n.checked && m ? p ??= d : p = void 0;
|
|
1504
|
+
let g = p === void 0 ? void 0 : wt(p, d, r), _ = a.status !== "success" || u.reason === "place-document" ? "seeking" : u.readyForAutoCapture ? "ready" : "unstable";
|
|
1505
1505
|
if (b({
|
|
1506
|
-
state:
|
|
1506
|
+
state: _,
|
|
1507
1507
|
confidence: a.confidence,
|
|
1508
1508
|
quad: a.quad,
|
|
1509
1509
|
guidance: u,
|
|
@@ -1511,7 +1511,7 @@ async function zt(t) {
|
|
|
1511
1511
|
stableFrames: l.stableFrames,
|
|
1512
1512
|
requiredStableFrames: v.requiredStableFrames,
|
|
1513
1513
|
autoCapture: { ...n },
|
|
1514
|
-
holdStillSeconds:
|
|
1514
|
+
holdStillSeconds: g && g > 0 ? g : void 0,
|
|
1515
1515
|
sourceWidth: a.sourceWidth,
|
|
1516
1516
|
sourceHeight: a.sourceHeight,
|
|
1517
1517
|
detector: a.detector,
|
|
@@ -1520,7 +1520,7 @@ async function zt(t) {
|
|
|
1520
1520
|
modelError: a.modelError,
|
|
1521
1521
|
modelNote: a.modelNote,
|
|
1522
1522
|
inferenceMs: a.inferenceMs
|
|
1523
|
-
}), u.readyForAutoCapture && n.checked &&
|
|
1523
|
+
}), u.readyForAutoCapture && n.checked && g === 0) try {
|
|
1524
1524
|
await w("auto");
|
|
1525
1525
|
return;
|
|
1526
1526
|
} catch (e) {
|
|
@@ -1547,7 +1547,7 @@ async function zt(t) {
|
|
|
1547
1547
|
hint: "Place the document in the frame",
|
|
1548
1548
|
reason: "place-document",
|
|
1549
1549
|
fillRatio: 0,
|
|
1550
|
-
fill:
|
|
1550
|
+
fill: B,
|
|
1551
1551
|
readyForAutoCapture: !1
|
|
1552
1552
|
},
|
|
1553
1553
|
lighting: {
|
|
@@ -1578,24 +1578,24 @@ async function zt(t) {
|
|
|
1578
1578
|
}
|
|
1579
1579
|
//#endregion
|
|
1580
1580
|
//#region src/sdk/ocr-runtime.ts
|
|
1581
|
-
var
|
|
1582
|
-
function
|
|
1581
|
+
var Vt = new URL("./assets/tesseract/worker.min.js", import.meta.url), Ht = new URL("./assets/tesseract/tesseract-core-lstm.wasm.js", import.meta.url), Ut = new URL("./assets/tesseract/tesseract-core-simd-lstm.wasm.js", import.meta.url), Wt = new URL("./assets/tesseract/tesseract-core-relaxedsimd-lstm.wasm.js", import.meta.url), Gt = new URL("./assets/tesseract/eng.traineddata.gz", import.meta.url), Kt = 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), qt = 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);
|
|
1582
|
+
function Jt(e) {
|
|
1583
1583
|
try {
|
|
1584
1584
|
return typeof WebAssembly < "u" && WebAssembly.validate(e);
|
|
1585
1585
|
} catch {
|
|
1586
1586
|
return !1;
|
|
1587
1587
|
}
|
|
1588
1588
|
}
|
|
1589
|
-
function
|
|
1589
|
+
function Yt() {
|
|
1590
1590
|
return {
|
|
1591
|
-
relaxedSimd:
|
|
1592
|
-
simd: qt
|
|
1591
|
+
relaxedSimd: Jt(Kt),
|
|
1592
|
+
simd: Jt(qt)
|
|
1593
1593
|
};
|
|
1594
1594
|
}
|
|
1595
|
-
function
|
|
1596
|
-
return e.relaxedSimd ?
|
|
1595
|
+
function Xt(e) {
|
|
1596
|
+
return e.relaxedSimd ? Wt : e.simd ? Ut : Ht;
|
|
1597
1597
|
}
|
|
1598
|
-
function
|
|
1598
|
+
function Zt(t, n) {
|
|
1599
1599
|
let r = t?.trim() || "eng", i = n?.trim() || "";
|
|
1600
1600
|
if (i) return {
|
|
1601
1601
|
kind: "lang-path",
|
|
@@ -1608,14 +1608,14 @@ function Xt(t, n) {
|
|
|
1608
1608
|
};
|
|
1609
1609
|
throw new e("language", `OCR language "${r}" is not packaged. Pass langPath, a directory URL that contains ${r}.traineddata.gz.`);
|
|
1610
1610
|
}
|
|
1611
|
-
function
|
|
1611
|
+
function Qt(e = Gt) {
|
|
1612
1612
|
let t = e.href, n = t.lastIndexOf("/");
|
|
1613
1613
|
return n === -1 ? t : t.slice(0, n);
|
|
1614
1614
|
}
|
|
1615
|
-
function
|
|
1616
|
-
return e.kind === "bundled-eng" ?
|
|
1615
|
+
function $t(e) {
|
|
1616
|
+
return e.kind === "bundled-eng" ? Qt() : e.langPath;
|
|
1617
1617
|
}
|
|
1618
|
-
async function
|
|
1618
|
+
async function en(t, n, r) {
|
|
1619
1619
|
return new Promise((i, a) => {
|
|
1620
1620
|
let o = !1, s = (t) => {
|
|
1621
1621
|
o || (o = !0, a(new e("worker", `OCR worker failed to start (${t instanceof Error ? t.message : String(t)}).`)));
|
|
@@ -1638,7 +1638,7 @@ async function $t(t, n, r) {
|
|
|
1638
1638
|
}
|
|
1639
1639
|
//#endregion
|
|
1640
1640
|
//#region src/sdk/ocr.ts
|
|
1641
|
-
function
|
|
1641
|
+
function tn(e, t = 1, n = 1, r = 0, i = 0) {
|
|
1642
1642
|
return {
|
|
1643
1643
|
text: e.text,
|
|
1644
1644
|
confidence: Math.max(0, Math.min(1, e.confidence / 100)),
|
|
@@ -1650,20 +1650,20 @@ function en(e, t = 1, n = 1, r = 0, i = 0) {
|
|
|
1650
1650
|
}
|
|
1651
1651
|
};
|
|
1652
1652
|
}
|
|
1653
|
-
function
|
|
1653
|
+
function nn(e = .5) {
|
|
1654
1654
|
if (!Number.isFinite(e) || e < 0 || e > 1) throw RangeError("OCR minConfidence must be between 0 and 1.");
|
|
1655
1655
|
return e;
|
|
1656
1656
|
}
|
|
1657
|
-
function
|
|
1657
|
+
function rn(e, t) {
|
|
1658
1658
|
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);
|
|
1659
1659
|
return s > 0 ? o / s : 0;
|
|
1660
1660
|
}
|
|
1661
|
-
function
|
|
1661
|
+
function an(e) {
|
|
1662
1662
|
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 = [];
|
|
1663
|
-
for (let e of t) n.some((t) =>
|
|
1663
|
+
for (let e of t) n.some((t) => rn(t, e) >= .65) || n.push(e);
|
|
1664
1664
|
return n;
|
|
1665
1665
|
}
|
|
1666
|
-
function
|
|
1666
|
+
function on(e, t, n, r, i) {
|
|
1667
1667
|
let a = e.text.trim();
|
|
1668
1668
|
if (!a || !/[\p{L}\p{N}]/u.test(a)) return !1;
|
|
1669
1669
|
let o = e.bbox.width * e.bbox.height / Math.max(1, n * r), s = e.bbox.width / Math.max(1, e.bbox.height);
|
|
@@ -1674,7 +1674,7 @@ function an(e, t, n, r, i) {
|
|
|
1674
1674
|
}
|
|
1675
1675
|
return !0;
|
|
1676
1676
|
}
|
|
1677
|
-
function
|
|
1677
|
+
function sn(e) {
|
|
1678
1678
|
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 = [];
|
|
1679
1679
|
for (let e of t) {
|
|
1680
1680
|
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);
|
|
@@ -1690,28 +1690,28 @@ function on(e) {
|
|
|
1690
1690
|
}
|
|
1691
1691
|
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");
|
|
1692
1692
|
}
|
|
1693
|
-
function
|
|
1694
|
-
let i =
|
|
1693
|
+
function cn(e, t, n, r) {
|
|
1694
|
+
let i = nn(t.minConfidence), a = [], o = [], s = 1, c = 1;
|
|
1695
1695
|
for (let t of e) {
|
|
1696
1696
|
let e = t.scaleX ?? 1, n = t.scaleY ?? 1, r = t.offsetX ?? 0, l = t.offsetY ?? 0;
|
|
1697
1697
|
for (let u of t.blocks ?? []) for (let t of u.paragraphs) for (let u of t.lines) for (let t of u.words) {
|
|
1698
|
-
let u =
|
|
1698
|
+
let u = tn(t, e, n, r, l);
|
|
1699
1699
|
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);
|
|
1700
1700
|
for (let a of t.symbols) {
|
|
1701
|
-
let t =
|
|
1701
|
+
let t = tn(a, e, n, r, l);
|
|
1702
1702
|
t.confidence >= i && o.push(t);
|
|
1703
1703
|
}
|
|
1704
1704
|
}
|
|
1705
1705
|
}
|
|
1706
|
-
let l = n?.width ?? s, u = n?.height ?? c, d =
|
|
1706
|
+
let l = n?.width ?? s, u = n?.height ?? c, d = an(a).filter((e) => on(e, "word", l, u, r)), f = an(o).filter((e) => on(e, "character", l, u, r));
|
|
1707
1707
|
return {
|
|
1708
|
-
text:
|
|
1708
|
+
text: sn(d),
|
|
1709
1709
|
confidence: d.length ? d.reduce((e, t) => e + t.confidence, 0) / d.length : 0,
|
|
1710
1710
|
words: t.includeWords ? d : [],
|
|
1711
1711
|
characters: t.includeCharacters ? f : []
|
|
1712
1712
|
};
|
|
1713
1713
|
}
|
|
1714
|
-
function
|
|
1714
|
+
function ln(e) {
|
|
1715
1715
|
let n = e.getContext("2d", { willReadFrequently: !0 });
|
|
1716
1716
|
if (!n) throw t();
|
|
1717
1717
|
let r = n.getImageData(0, 0, e.width, e.height), i = new Uint8Array(e.width * e.height);
|
|
@@ -1722,7 +1722,7 @@ function cn(e) {
|
|
|
1722
1722
|
luminance: i
|
|
1723
1723
|
};
|
|
1724
1724
|
}
|
|
1725
|
-
function
|
|
1725
|
+
function un(e) {
|
|
1726
1726
|
let t = document.createElement("canvas");
|
|
1727
1727
|
t.width = 72, t.height = 72;
|
|
1728
1728
|
let n = t.getContext("2d", { willReadFrequently: !0 });
|
|
@@ -1733,27 +1733,27 @@ function ln(e) {
|
|
|
1733
1733
|
areaRatio: 0
|
|
1734
1734
|
};
|
|
1735
1735
|
n.drawImage(e, 0, 0, t.width, t.height);
|
|
1736
|
-
let { luminance: r } =
|
|
1737
|
-
return
|
|
1736
|
+
let { luminance: r } = ln(t);
|
|
1737
|
+
return gt(r, t.width, t.height);
|
|
1738
1738
|
}
|
|
1739
|
-
function
|
|
1739
|
+
function dn(e, t, n, r) {
|
|
1740
1740
|
let i = (e.bbox.x + e.bbox.width / 2) / n, a = (e.bbox.y + e.bbox.height / 2) / r;
|
|
1741
1741
|
return i >= t.x && i <= t.x + t.width && a >= t.y && a <= t.y + t.height;
|
|
1742
1742
|
}
|
|
1743
|
-
var
|
|
1744
|
-
function
|
|
1743
|
+
var fn = .58;
|
|
1744
|
+
function pn(e) {
|
|
1745
1745
|
let t = e.trim();
|
|
1746
1746
|
if (!t || !/[\p{L}\p{N}]/u.test(t)) return 0;
|
|
1747
1747
|
if (/^\$?\d{1,5}([.,]\d{2})?$/.test(t)) return 1;
|
|
1748
1748
|
let n = t.replace(/[^\p{L}]/gu, "");
|
|
1749
1749
|
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;
|
|
1750
1750
|
}
|
|
1751
|
-
function
|
|
1751
|
+
function mn(e, t, n) {
|
|
1752
1752
|
let r = Math.max(0, Math.min(1, (1 - e.darkness / 80) * (1 - e.strength / 24)));
|
|
1753
1753
|
if (!t.length) return r * .35;
|
|
1754
1754
|
let i = 0;
|
|
1755
1755
|
for (let e of t) {
|
|
1756
|
-
let t =
|
|
1756
|
+
let t = pn(e.text);
|
|
1757
1757
|
if (n) {
|
|
1758
1758
|
let r = n(e.bbox);
|
|
1759
1759
|
(r < .04 || r > .62) && (t *= .4);
|
|
@@ -1762,10 +1762,10 @@ function pn(e, t, n) {
|
|
|
1762
1762
|
}
|
|
1763
1763
|
return r * .7 + i / t.length * .3;
|
|
1764
1764
|
}
|
|
1765
|
-
function mn(e, t, n, r) {
|
|
1766
|
-
return !e.strong || !e.region ? !1 : pn(e, t.filter((t) => un(t, e.region, n.width, n.height)), r) < dn;
|
|
1767
|
-
}
|
|
1768
1765
|
function hn(e, t, n, r) {
|
|
1766
|
+
return !e.strong || !e.region ? !1 : mn(e, t.filter((t) => dn(t, e.region, n.width, n.height)), r) < fn;
|
|
1767
|
+
}
|
|
1768
|
+
function gn(e, t, n, r) {
|
|
1769
1769
|
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");
|
|
1770
1770
|
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);
|
|
1771
1771
|
let l = n / e.width, u = r / e.height;
|
|
@@ -1779,26 +1779,26 @@ function hn(e, t, n, r) {
|
|
|
1779
1779
|
}
|
|
1780
1780
|
};
|
|
1781
1781
|
}
|
|
1782
|
-
function
|
|
1782
|
+
function _n(e, t) {
|
|
1783
1783
|
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;
|
|
1784
1784
|
}
|
|
1785
|
-
function
|
|
1785
|
+
function vn(e) {
|
|
1786
1786
|
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");
|
|
1787
1787
|
a.width = Math.max(1, Math.round(e.width * i)), a.height = Math.max(1, Math.round(e.height * i));
|
|
1788
1788
|
let o = a.getContext("2d", { willReadFrequently: !0 });
|
|
1789
1789
|
if (!o) throw t();
|
|
1790
1790
|
o.drawImage(e, 0, 0, a.width, a.height);
|
|
1791
|
-
let { image: s, luminance: c } =
|
|
1791
|
+
let { image: s, luminance: c } = ln(a), l = yt(c, a.width, a.height), u = bt(l, a.width, a.height), d = document.createElement("canvas");
|
|
1792
1792
|
d.width = a.width, d.height = a.height;
|
|
1793
1793
|
let f = d.getContext("2d", { willReadFrequently: !0 });
|
|
1794
1794
|
if (!f) throw t();
|
|
1795
1795
|
let p = f.createImageData(d.width, d.height);
|
|
1796
|
-
return
|
|
1796
|
+
return _n(p, l), f.putImageData(p, 0, 0), _n(s, u), o.putImageData(s, 0, 0), {
|
|
1797
1797
|
sparseCanvas: a,
|
|
1798
1798
|
flattenedCanvas: d
|
|
1799
1799
|
};
|
|
1800
1800
|
}
|
|
1801
|
-
function
|
|
1801
|
+
function yn(e) {
|
|
1802
1802
|
let t = document.createElement("canvas");
|
|
1803
1803
|
t.width = 24, t.height = 24;
|
|
1804
1804
|
let n = t.getContext("2d", { willReadFrequently: !0 });
|
|
@@ -1816,19 +1816,19 @@ function vn(e) {
|
|
|
1816
1816
|
return l / s.length;
|
|
1817
1817
|
};
|
|
1818
1818
|
}
|
|
1819
|
-
async function
|
|
1819
|
+
async function bn(e, t = {}) {
|
|
1820
1820
|
await x("ocr");
|
|
1821
|
-
let n =
|
|
1822
|
-
|
|
1823
|
-
let i = await
|
|
1821
|
+
let n = Zt(t.language, t.langPath), r = n.language;
|
|
1822
|
+
nn(t.minConfidence);
|
|
1823
|
+
let i = await N(e, { cloneCanvas: !1 }), { sparseCanvas: a, flattenedCanvas: o } = vn(i), s = t.shadowPass === !1 ? {
|
|
1824
1824
|
strong: !1,
|
|
1825
1825
|
strength: 0,
|
|
1826
1826
|
darkness: 0,
|
|
1827
1827
|
areaRatio: 0
|
|
1828
|
-
} :
|
|
1829
|
-
workerPath:
|
|
1830
|
-
corePath: Yt(
|
|
1831
|
-
langPath:
|
|
1828
|
+
} : un(i), { createWorker: c, PSM: l } = await import("tesseract.js"), u = 0, d = s.strong ? 3 : 2, f = await en(c, r, {
|
|
1829
|
+
workerPath: Vt.href,
|
|
1830
|
+
corePath: Xt(Yt()).href,
|
|
1831
|
+
langPath: $t(n),
|
|
1832
1832
|
logger(e) {
|
|
1833
1833
|
typeof e.progress == "number" && t.onProgress?.(Math.min(1, (u + e.progress) / d), e.status ?? "recognizing text");
|
|
1834
1834
|
}
|
|
@@ -1853,16 +1853,16 @@ async function H(e, t = {}) {
|
|
|
1853
1853
|
}], d = {
|
|
1854
1854
|
...t,
|
|
1855
1855
|
includeWords: !0
|
|
1856
|
-
}, p =
|
|
1856
|
+
}, p = yn(i), m = cn(c, d, {
|
|
1857
1857
|
width: i.width,
|
|
1858
1858
|
height: i.height
|
|
1859
|
-
}, p), h = t.shadowPass !== !1 &&
|
|
1859
|
+
}, p), h = t.shadowPass !== !1 && hn(s, m.words, {
|
|
1860
1860
|
width: i.width,
|
|
1861
1861
|
height: i.height
|
|
1862
1862
|
}, p);
|
|
1863
1863
|
if (h && s.region) {
|
|
1864
1864
|
u = 2;
|
|
1865
|
-
let { tile: e, passMapping: t } =
|
|
1865
|
+
let { tile: e, passMapping: t } = gn(o, s.region, i.width, i.height);
|
|
1866
1866
|
await f.setParameters({
|
|
1867
1867
|
tessedit_pageseg_mode: l.SPARSE_TEXT,
|
|
1868
1868
|
preserve_interword_spaces: "1"
|
|
@@ -1876,7 +1876,7 @@ async function H(e, t = {}) {
|
|
|
1876
1876
|
...t
|
|
1877
1877
|
});
|
|
1878
1878
|
}
|
|
1879
|
-
let g = c.length === 2 ? m :
|
|
1879
|
+
let g = c.length === 2 ? m : cn(c, d, {
|
|
1880
1880
|
width: i.width,
|
|
1881
1881
|
height: i.height
|
|
1882
1882
|
}, p);
|
|
@@ -1905,68 +1905,68 @@ async function H(e, t = {}) {
|
|
|
1905
1905
|
}
|
|
1906
1906
|
//#endregion
|
|
1907
1907
|
//#region src/sdk/zxing-runtime.ts
|
|
1908
|
-
var
|
|
1909
|
-
function
|
|
1908
|
+
var xn = new URL("./assets/zxing_reader.wasm", import.meta.url), Sn = "3.1.6", Cn = "zxing_reader.wasm", wn = `https://exige-scanner-sdk.vercel.app/zxing/${Sn}/`, Tn = `https://cdn.jsdelivr.net/npm/zxing-wasm@${Sn}/dist/reader/`;
|
|
1909
|
+
function En(e, t) {
|
|
1910
1910
|
return `${e.endsWith("/") ? e : `${e}/`}${t}`;
|
|
1911
1911
|
}
|
|
1912
|
-
function
|
|
1913
|
-
return
|
|
1912
|
+
function Dn(e = wn) {
|
|
1913
|
+
return En(e, Cn);
|
|
1914
1914
|
}
|
|
1915
|
-
function
|
|
1916
|
-
return
|
|
1915
|
+
function On() {
|
|
1916
|
+
return xn.href;
|
|
1917
1917
|
}
|
|
1918
|
-
var
|
|
1919
|
-
function
|
|
1918
|
+
var kn, An;
|
|
1919
|
+
function jn() {
|
|
1920
1920
|
return {
|
|
1921
|
-
binary:
|
|
1922
|
-
url:
|
|
1921
|
+
binary: kn,
|
|
1922
|
+
url: An
|
|
1923
1923
|
};
|
|
1924
1924
|
}
|
|
1925
|
-
async function
|
|
1926
|
-
let t =
|
|
1927
|
-
if (await
|
|
1928
|
-
let n =
|
|
1929
|
-
return await
|
|
1925
|
+
async function Mn(e = fetch) {
|
|
1926
|
+
let t = On();
|
|
1927
|
+
if (await He(t, e)) return t;
|
|
1928
|
+
let n = Dn(wn);
|
|
1929
|
+
return await He(n, e) ? n : Dn(Tn);
|
|
1930
1930
|
}
|
|
1931
|
-
async function
|
|
1932
|
-
let t =
|
|
1931
|
+
async function Nn(e = fetch) {
|
|
1932
|
+
let t = jn();
|
|
1933
1933
|
if (t.binary) return t.binary.slice(0);
|
|
1934
|
-
let n = await e(await
|
|
1934
|
+
let n = await e(await Mn(e));
|
|
1935
1935
|
if (!n.ok) throw Error(`Could not download zxing-wasm (${n.status}).`);
|
|
1936
1936
|
return await n.arrayBuffer();
|
|
1937
1937
|
}
|
|
1938
1938
|
//#endregion
|
|
1939
1939
|
//#region src/sdk/barcode.ts
|
|
1940
|
-
var
|
|
1940
|
+
var Pn = 1600, Fn = [
|
|
1941
1941
|
1600,
|
|
1942
1942
|
1280,
|
|
1943
1943
|
960,
|
|
1944
1944
|
720,
|
|
1945
1945
|
480
|
|
1946
|
-
],
|
|
1946
|
+
], In = [
|
|
1947
1947
|
[.2, .8],
|
|
1948
1948
|
[.32, .72],
|
|
1949
1949
|
[.4, .86]
|
|
1950
1950
|
];
|
|
1951
|
-
function
|
|
1951
|
+
function Ln(e, t) {
|
|
1952
1952
|
let n = Math.max(e, t);
|
|
1953
1953
|
if (!Number.isFinite(n) || n < 1) return [];
|
|
1954
|
-
let r = Math.min(n,
|
|
1955
|
-
for (let e of
|
|
1954
|
+
let r = Math.min(n, Pn), i = [r];
|
|
1955
|
+
for (let e of Fn) e <= r - 16 && i.push(e);
|
|
1956
1956
|
return i;
|
|
1957
1957
|
}
|
|
1958
|
-
var
|
|
1958
|
+
var V = class extends Error {
|
|
1959
1959
|
code = "zxing-wasm-load";
|
|
1960
1960
|
constructor(e) {
|
|
1961
1961
|
super("The barcode decoder failed to load."), this.name = "Pdf417DecoderError", e !== void 0 && (this.cause = e);
|
|
1962
1962
|
}
|
|
1963
1963
|
};
|
|
1964
|
-
function
|
|
1964
|
+
function Rn() {
|
|
1965
1965
|
let e = globalThis.BarcodeDetector;
|
|
1966
1966
|
return typeof e == "function" ? e : void 0;
|
|
1967
1967
|
}
|
|
1968
|
-
async function
|
|
1969
|
-
let e =
|
|
1968
|
+
async function zn() {
|
|
1969
|
+
let e = Rn();
|
|
1970
1970
|
if (!e?.getSupportedFormats) return !1;
|
|
1971
1971
|
try {
|
|
1972
1972
|
return (await e.getSupportedFormats()).some((e) => e.toLowerCase() === "pdf417");
|
|
@@ -1974,41 +1974,38 @@ async function Ln() {
|
|
|
1974
1974
|
return !1;
|
|
1975
1975
|
}
|
|
1976
1976
|
}
|
|
1977
|
-
function
|
|
1977
|
+
function Bn(e) {
|
|
1978
1978
|
try {
|
|
1979
1979
|
return e.getContext("2d", { willReadFrequently: !0 })?.getImageData(0, 0, e.width, e.height);
|
|
1980
1980
|
} catch {
|
|
1981
1981
|
return;
|
|
1982
1982
|
}
|
|
1983
1983
|
}
|
|
1984
|
-
async function
|
|
1984
|
+
async function Vn(e) {
|
|
1985
1985
|
let t = [];
|
|
1986
1986
|
if (e instanceof Blob && t.push(e), e instanceof HTMLCanvasElement) {
|
|
1987
|
-
let n =
|
|
1987
|
+
let n = Bn(e);
|
|
1988
1988
|
n && t.push(n);
|
|
1989
1989
|
try {
|
|
1990
|
-
t.push(await
|
|
1990
|
+
t.push(await Ye(e, "image/png"));
|
|
1991
1991
|
} catch {}
|
|
1992
1992
|
} else if (!(e instanceof Blob)) try {
|
|
1993
|
-
let n =
|
|
1993
|
+
let n = Bn(await N(e, { cloneCanvas: !1 }));
|
|
1994
1994
|
n && t.push(n);
|
|
1995
1995
|
} catch {}
|
|
1996
1996
|
return t;
|
|
1997
1997
|
}
|
|
1998
|
-
var
|
|
1999
|
-
async function
|
|
2000
|
-
return
|
|
2001
|
-
let [e, t] = await Promise.all([import("zxing-wasm/reader"),
|
|
1998
|
+
var H;
|
|
1999
|
+
async function Hn() {
|
|
2000
|
+
return H ||= (async () => {
|
|
2001
|
+
let [e, t] = await Promise.all([import("zxing-wasm/reader"), Nn()]);
|
|
2002
2002
|
return await e.prepareZXingModule({
|
|
2003
2003
|
overrides: { wasmBinary: t },
|
|
2004
2004
|
fireImmediately: !0
|
|
2005
2005
|
}), e;
|
|
2006
2006
|
})().catch((e) => {
|
|
2007
|
-
throw
|
|
2008
|
-
}),
|
|
2009
|
-
}
|
|
2010
|
-
async function Hn() {
|
|
2011
|
-
await Vn();
|
|
2007
|
+
throw H = void 0, e instanceof Error && e.message, console.error("[exige-scanner] zxing-wasm failed to load", e), new V(e);
|
|
2008
|
+
}), H;
|
|
2012
2009
|
}
|
|
2013
2010
|
function Un(e) {
|
|
2014
2011
|
let t = e.position;
|
|
@@ -2066,7 +2063,7 @@ function Wn(e) {
|
|
|
2066
2063
|
}
|
|
2067
2064
|
};
|
|
2068
2065
|
}
|
|
2069
|
-
function
|
|
2066
|
+
function U(e, t) {
|
|
2070
2067
|
let n = t.scale > 0 ? t.scale : 1;
|
|
2071
2068
|
return {
|
|
2072
2069
|
x: t.originX + e.x / n,
|
|
@@ -2075,15 +2072,15 @@ function W(e, t) {
|
|
|
2075
2072
|
}
|
|
2076
2073
|
function Gn(e, t) {
|
|
2077
2074
|
return {
|
|
2078
|
-
topLeft:
|
|
2079
|
-
topRight:
|
|
2080
|
-
bottomRight:
|
|
2081
|
-
bottomLeft:
|
|
2075
|
+
topLeft: U(e.topLeft, t),
|
|
2076
|
+
topRight: U(e.topRight, t),
|
|
2077
|
+
bottomRight: U(e.bottomRight, t),
|
|
2078
|
+
bottomLeft: U(e.bottomLeft, t)
|
|
2082
2079
|
};
|
|
2083
2080
|
}
|
|
2084
2081
|
async function Kn(e) {
|
|
2085
|
-
let { readBarcodes: t } = await
|
|
2086
|
-
for (let n of await
|
|
2082
|
+
let { readBarcodes: t } = await Hn();
|
|
2083
|
+
for (let n of await Vn(e)) {
|
|
2087
2084
|
let e = (await t(n, {
|
|
2088
2085
|
formats: ["PDF417"],
|
|
2089
2086
|
tryHarder: !0,
|
|
@@ -2114,7 +2111,7 @@ function Jn(e, t, n) {
|
|
|
2114
2111
|
let o = a.getContext("2d", { willReadFrequently: !0 }) ?? a.getContext("2d");
|
|
2115
2112
|
return o && o.drawImage(e, 0, r, e.width, i, 0, 0, e.width, i), a;
|
|
2116
2113
|
}
|
|
2117
|
-
function
|
|
2114
|
+
function W(e, t, n = 0, r = 0) {
|
|
2118
2115
|
let i = Math.max(e.width, e.height);
|
|
2119
2116
|
return i <= t ? {
|
|
2120
2117
|
canvas: e,
|
|
@@ -2128,28 +2125,28 @@ function Yn(e, t, n = 0, r = 0) {
|
|
|
2128
2125
|
scale: t / i
|
|
2129
2126
|
};
|
|
2130
2127
|
}
|
|
2131
|
-
function
|
|
2128
|
+
function Yn(e) {
|
|
2132
2129
|
let t = /* @__PURE__ */ new Set(), n = [], r = (e) => {
|
|
2133
2130
|
let r = `${e.canvas.width}x${e.canvas.height}@${e.originX},${e.originY},${e.scale}`;
|
|
2134
2131
|
t.has(r) || (t.add(r), n.push(e));
|
|
2135
2132
|
};
|
|
2136
|
-
if (e.height >= e.width * 1.15 && e.height >= 120) for (let [t, n] of
|
|
2133
|
+
if (e.height >= e.width * 1.15 && e.height >= 120) for (let [t, n] of In) {
|
|
2137
2134
|
let i = Math.max(0, Math.round(e.height * t)), a = Jn(e, t, n);
|
|
2138
|
-
r(
|
|
2139
|
-
let o =
|
|
2140
|
-
o && r(
|
|
2135
|
+
r(W(a, Pn, 0, i));
|
|
2136
|
+
let o = Ln(a.width, a.height).find((e) => e <= 960);
|
|
2137
|
+
o && r(W(a, o, 0, i));
|
|
2141
2138
|
}
|
|
2142
|
-
for (let t of
|
|
2139
|
+
for (let t of Ln(e.width, e.height)) r(W(e, t));
|
|
2143
2140
|
return n;
|
|
2144
2141
|
}
|
|
2145
|
-
async function
|
|
2142
|
+
async function Xn(e) {
|
|
2146
2143
|
let t;
|
|
2147
2144
|
try {
|
|
2148
|
-
t = await
|
|
2145
|
+
t = await N(e, { cloneCanvas: !1 });
|
|
2149
2146
|
} catch {
|
|
2150
2147
|
t = e instanceof HTMLCanvasElement ? e : document.createElement("canvas");
|
|
2151
2148
|
}
|
|
2152
|
-
let n = t.width && t.height ?
|
|
2149
|
+
let n = t.width && t.height ? Yn(t) : [];
|
|
2153
2150
|
for (let e of n) try {
|
|
2154
2151
|
let t = await Kn(e.canvas);
|
|
2155
2152
|
if (t?.text) {
|
|
@@ -2161,7 +2158,7 @@ async function Zn(e) {
|
|
|
2161
2158
|
};
|
|
2162
2159
|
}
|
|
2163
2160
|
} catch (e) {
|
|
2164
|
-
if (e instanceof
|
|
2161
|
+
if (e instanceof V) throw e;
|
|
2165
2162
|
}
|
|
2166
2163
|
if (e instanceof Blob) try {
|
|
2167
2164
|
let t = await Kn(e);
|
|
@@ -2171,15 +2168,15 @@ async function Zn(e) {
|
|
|
2171
2168
|
quad: t.position ? Wn(t.position) : void 0
|
|
2172
2169
|
} : void 0;
|
|
2173
2170
|
} catch (e) {
|
|
2174
|
-
if (e instanceof
|
|
2171
|
+
if (e instanceof V) throw e;
|
|
2175
2172
|
return;
|
|
2176
2173
|
}
|
|
2177
2174
|
}
|
|
2178
|
-
var G = 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(".")),
|
|
2175
|
+
var G = 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(".")), Zn = /* @__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("."), Qn = /* @__PURE__ */ new Set([
|
|
2179
2176
|
"expirationDate",
|
|
2180
2177
|
"dateOfBirth",
|
|
2181
2178
|
"issueDate"
|
|
2182
|
-
]),
|
|
2179
|
+
]), $n = {
|
|
2183
2180
|
DAJ: "issuerJurisdiction",
|
|
2184
2181
|
DBA: "expirationDate",
|
|
2185
2182
|
DAQ: "documentNumber",
|
|
@@ -2215,16 +2212,16 @@ function K(e, t, n) {
|
|
|
2215
2212
|
let r = Number(e), i = Number(t), a = Number(n);
|
|
2216
2213
|
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")}`;
|
|
2217
2214
|
}
|
|
2218
|
-
function
|
|
2215
|
+
function er(e, t) {
|
|
2219
2216
|
return t ? e >= 30 ? 1900 + e : 2e3 + e : e >= 50 ? 1900 + e : 2e3 + e;
|
|
2220
2217
|
}
|
|
2221
|
-
function
|
|
2218
|
+
function q(e, t = !1) {
|
|
2222
2219
|
let n = e.trim();
|
|
2223
2220
|
if (!n) return;
|
|
2224
2221
|
let r = /^(\d{1,2})[/-](\d{1,2})[/-](\d{2,4})$/.exec(n);
|
|
2225
2222
|
if (r) {
|
|
2226
2223
|
let e = r[1], n = r[2], i = r[3];
|
|
2227
|
-
return i.length === 2 && (i = String(
|
|
2224
|
+
return i.length === 2 && (i = String(er(Number(i), t))), K(i, e.padStart(2, "0"), n.padStart(2, "0"));
|
|
2228
2225
|
}
|
|
2229
2226
|
let i = /^(\d{4})-(\d{2})-(\d{2})$/.exec(n);
|
|
2230
2227
|
if (i) return K(i[1], i[2], i[3]);
|
|
@@ -2234,11 +2231,11 @@ function nr(e, t = !1) {
|
|
|
2234
2231
|
return e >= 1900 && e <= 2100 ? K(a.slice(0, 4), a.slice(4, 6), a.slice(6, 8)) : K(a.slice(4, 8), a.slice(0, 2), a.slice(2, 4));
|
|
2235
2232
|
}
|
|
2236
2233
|
if (a.length === 6) {
|
|
2237
|
-
let e =
|
|
2234
|
+
let e = er(Number(a.slice(4, 6)), t);
|
|
2238
2235
|
return K(String(e), a.slice(0, 2), a.slice(2, 4));
|
|
2239
2236
|
}
|
|
2240
2237
|
}
|
|
2241
|
-
function
|
|
2238
|
+
function tr(e) {
|
|
2242
2239
|
let t = e.trim();
|
|
2243
2240
|
if (!t || t === "@") return "";
|
|
2244
2241
|
if (/^(ANSI|AAMVA)\b/.test(t)) {
|
|
@@ -2247,10 +2244,10 @@ function rr(e) {
|
|
|
2247
2244
|
}
|
|
2248
2245
|
return t;
|
|
2249
2246
|
}
|
|
2250
|
-
function
|
|
2247
|
+
function nr(e) {
|
|
2251
2248
|
return (e.startsWith("DL") || e.startsWith("ID") || e.startsWith("ZV")) && e.length >= 5 && G.has(e.slice(2, 5)) ? e.slice(2) : e;
|
|
2252
2249
|
}
|
|
2253
|
-
function
|
|
2250
|
+
function rr(e, t) {
|
|
2254
2251
|
let n = 0;
|
|
2255
2252
|
for (; n < e.length;) {
|
|
2256
2253
|
let r = e.slice(n, n + 3);
|
|
@@ -2269,7 +2266,7 @@ function ar(e, t) {
|
|
|
2269
2266
|
(!(r in t) || a) && (t[r] = a), n = i, (e[n] === "\n" || e[n] === "\r" || e[n] === "") && (n += 1);
|
|
2270
2267
|
}
|
|
2271
2268
|
}
|
|
2272
|
-
function
|
|
2269
|
+
function ir(e) {
|
|
2273
2270
|
let t = /(?:ANSI|AAMVA)\s?(\d{6})(\d{2})(\d{2})(\d{2})/.exec(e);
|
|
2274
2271
|
if (t) return {
|
|
2275
2272
|
iin: t[1],
|
|
@@ -2277,22 +2274,22 @@ function or(e) {
|
|
|
2277
2274
|
jurisdictionVersion: t[3]
|
|
2278
2275
|
};
|
|
2279
2276
|
}
|
|
2280
|
-
function
|
|
2277
|
+
function ar(e) {
|
|
2281
2278
|
let t = e.replace(/\r\n/g, "\n").replace(/\r/g, "\n"), n = {}, r = t.split("\n").flatMap((e) => e.split(""));
|
|
2282
2279
|
if (r.some((e) => {
|
|
2283
|
-
let t =
|
|
2280
|
+
let t = nr(tr(e));
|
|
2284
2281
|
return G.has(t.slice(0, 3));
|
|
2285
2282
|
})) {
|
|
2286
2283
|
for (let e of r) {
|
|
2287
|
-
let t =
|
|
2288
|
-
t &&
|
|
2284
|
+
let t = nr(tr(e));
|
|
2285
|
+
t && rr(t, n);
|
|
2289
2286
|
}
|
|
2290
2287
|
return n;
|
|
2291
2288
|
}
|
|
2292
|
-
return
|
|
2289
|
+
return rr(t, n), n;
|
|
2293
2290
|
}
|
|
2294
|
-
function
|
|
2295
|
-
if (
|
|
2291
|
+
function or(e, t) {
|
|
2292
|
+
if (Qn.has(t)) return q(e, t === "dateOfBirth") ?? e.trim();
|
|
2296
2293
|
if (t === "issuerJurisdiction" || t === "country") return e.trim().toUpperCase();
|
|
2297
2294
|
if (t === "addressPostalCode") {
|
|
2298
2295
|
let t = e.trim();
|
|
@@ -2300,11 +2297,11 @@ function cr(e, t) {
|
|
|
2300
2297
|
}
|
|
2301
2298
|
return e.trim();
|
|
2302
2299
|
}
|
|
2303
|
-
function
|
|
2300
|
+
function sr(e) {
|
|
2304
2301
|
let t = {};
|
|
2305
2302
|
for (let [n, r] of Object.entries(e)) {
|
|
2306
|
-
let e =
|
|
2307
|
-
e && r.trim() && (t[e] || (t[e] =
|
|
2303
|
+
let e = $n[n];
|
|
2304
|
+
e && r.trim() && (t[e] || (t[e] = or(r, e)));
|
|
2308
2305
|
}
|
|
2309
2306
|
if (!t.firstName && e.DCT?.trim()) {
|
|
2310
2307
|
let n = e.DCT.trim().split(/\s+/);
|
|
@@ -2312,29 +2309,29 @@ function lr(e) {
|
|
|
2312
2309
|
}
|
|
2313
2310
|
return t;
|
|
2314
2311
|
}
|
|
2315
|
-
function
|
|
2316
|
-
let t =
|
|
2312
|
+
function cr(e) {
|
|
2313
|
+
let t = ar(e);
|
|
2317
2314
|
return {
|
|
2318
2315
|
rawElements: t,
|
|
2319
|
-
fields:
|
|
2320
|
-
header:
|
|
2316
|
+
fields: sr(t),
|
|
2317
|
+
header: ir(e)
|
|
2321
2318
|
};
|
|
2322
2319
|
}
|
|
2323
|
-
function
|
|
2320
|
+
function lr() {
|
|
2324
2321
|
return {};
|
|
2325
2322
|
}
|
|
2326
|
-
function
|
|
2327
|
-
for (let r of
|
|
2323
|
+
function ur(e, t, n) {
|
|
2324
|
+
for (let r of Zn) t[r] && (e[r] = n);
|
|
2328
2325
|
return e;
|
|
2329
2326
|
}
|
|
2330
2327
|
//#endregion
|
|
2331
2328
|
//#region src/sdk/face-model.ts
|
|
2332
|
-
var
|
|
2333
|
-
function
|
|
2329
|
+
var dr = /* @__PURE__ */ new Map(), fr = 8400;
|
|
2330
|
+
function pr(e, t) {
|
|
2334
2331
|
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));
|
|
2335
2332
|
return n / Math.max(1, e.width * e.height + t.width * t.height - n);
|
|
2336
2333
|
}
|
|
2337
|
-
function
|
|
2334
|
+
function mr(e, t, n, r, i, a, o) {
|
|
2338
2335
|
return {
|
|
2339
2336
|
x: (e - n / 2) / i * a,
|
|
2340
2337
|
y: (t - r / 2) / i * o,
|
|
@@ -2342,39 +2339,39 @@ function gr(e, t, n, r, i, a, o) {
|
|
|
2342
2339
|
height: r / i * o
|
|
2343
2340
|
};
|
|
2344
2341
|
}
|
|
2345
|
-
function
|
|
2342
|
+
function hr(e, t, n) {
|
|
2346
2343
|
let r = t.length === 3 ? t[1] : t[0], i = t.length === 3 ? t[2] : t[1];
|
|
2347
|
-
if (i !== 6 || r < 1) throw Error(`Face model expects [1, anchors, 6]. A 640 YOLOX-Nano face export is [1, ${
|
|
2344
|
+
if (i !== 6 || r < 1) throw Error(`Face model expects [1, anchors, 6]. A 640 YOLOX-Nano face export is [1, ${fr}, 6].`);
|
|
2348
2345
|
let a = n.confidence ?? .35, o = n.inputSize ?? 640, s = [];
|
|
2349
2346
|
for (let t = 0; t < r; t += 1) {
|
|
2350
2347
|
let r = t * i, c = e[r + 4] * e[r + 5];
|
|
2351
2348
|
c < a || s.push({
|
|
2352
2349
|
confidence: c,
|
|
2353
|
-
bbox:
|
|
2350
|
+
bbox: mr(e[r], e[r + 1], e[r + 2], e[r + 3], o, n.imageWidth, n.imageHeight)
|
|
2354
2351
|
});
|
|
2355
2352
|
}
|
|
2356
|
-
return s.sort((e, t) => t.confidence - e.confidence).filter((e, t, n) => n.slice(0, t).every((t) =>
|
|
2353
|
+
return s.sort((e, t) => t.confidence - e.confidence).filter((e, t, n) => n.slice(0, t).every((t) => pr(e.bbox, t.bbox) < .45)).slice(0, 8);
|
|
2357
2354
|
}
|
|
2358
|
-
async function
|
|
2359
|
-
let i = await
|
|
2355
|
+
async function gr(e, n, r = .35) {
|
|
2356
|
+
let i = await N(e, { cloneCanvas: !1 }), a = await import("onnxruntime-web"), o = document.createElement("canvas");
|
|
2360
2357
|
o.width = 640, o.height = 640;
|
|
2361
2358
|
let s = o.getContext("2d", { willReadFrequently: !0 });
|
|
2362
2359
|
if (!s) throw t();
|
|
2363
2360
|
s.drawImage(i, 0, 0, 640, 640);
|
|
2364
2361
|
let c = s.getImageData(0, 0, 640, 640).data, l = 409600, u = new Float32Array(l * 3);
|
|
2365
2362
|
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;
|
|
2366
|
-
let d =
|
|
2363
|
+
let d = dr.get(n);
|
|
2367
2364
|
d || (d = a.InferenceSession.create(n, {
|
|
2368
2365
|
executionProviders: ["wasm"],
|
|
2369
2366
|
graphOptimizationLevel: "all"
|
|
2370
|
-
}),
|
|
2367
|
+
}), dr.set(n, d));
|
|
2371
2368
|
let f = await d, p = (await f.run({ [f.inputNames[0]]: new a.Tensor("float32", u, [
|
|
2372
2369
|
1,
|
|
2373
2370
|
3,
|
|
2374
2371
|
640,
|
|
2375
2372
|
640
|
|
2376
2373
|
]) }))[f.outputNames[0]];
|
|
2377
|
-
return
|
|
2374
|
+
return hr(p.data, p.dims.map(Number), {
|
|
2378
2375
|
confidence: r,
|
|
2379
2376
|
imageWidth: i.width,
|
|
2380
2377
|
imageHeight: i.height,
|
|
@@ -2383,7 +2380,7 @@ async function vr(e, n, r = .35) {
|
|
|
2383
2380
|
}
|
|
2384
2381
|
//#endregion
|
|
2385
2382
|
//#region src/sdk/field-model.ts
|
|
2386
|
-
var
|
|
2383
|
+
var J = /* @__PURE__ */ new Map(), _r = [
|
|
2387
2384
|
"person_name",
|
|
2388
2385
|
"date_of_birth",
|
|
2389
2386
|
"address",
|
|
@@ -2391,19 +2388,19 @@ var yr = /* @__PURE__ */ new Map(), br = [
|
|
|
2391
2388
|
"expiration_date",
|
|
2392
2389
|
"postal_code",
|
|
2393
2390
|
"state"
|
|
2394
|
-
],
|
|
2395
|
-
function
|
|
2391
|
+
], vr = 8400;
|
|
2392
|
+
function yr(e) {
|
|
2396
2393
|
return 5 + e;
|
|
2397
2394
|
}
|
|
2398
|
-
var
|
|
2399
|
-
function
|
|
2395
|
+
var br = 640;
|
|
2396
|
+
function xr(e, t) {
|
|
2400
2397
|
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));
|
|
2401
2398
|
return n / Math.max(1, e.bbox.width * e.bbox.height + t.bbox.width * t.bbox.height - n);
|
|
2402
2399
|
}
|
|
2403
|
-
function
|
|
2404
|
-
return e.sort((e, t) => t.confidence - e.confidence).filter((e, t, n) => n.slice(0, t).every((t) => t.field !== e.field ||
|
|
2400
|
+
function Sr(e) {
|
|
2401
|
+
return e.sort((e, t) => t.confidence - e.confidence).filter((e, t, n) => n.slice(0, t).every((t) => t.field !== e.field || xr(e, t) < .45)).slice(0, 30);
|
|
2405
2402
|
}
|
|
2406
|
-
function
|
|
2403
|
+
function Cr(e, t, n, r, i, a, o) {
|
|
2407
2404
|
return {
|
|
2408
2405
|
x: (e - n / 2) / i * a,
|
|
2409
2406
|
y: (t - r / 2) / i * o,
|
|
@@ -2411,8 +2408,8 @@ function Er(e, t, n, r, i, a, o) {
|
|
|
2411
2408
|
height: r / i * o
|
|
2412
2409
|
};
|
|
2413
2410
|
}
|
|
2414
|
-
function
|
|
2415
|
-
let n =
|
|
2411
|
+
function wr(e, t) {
|
|
2412
|
+
let n = yr(t);
|
|
2416
2413
|
return e.length === 3 && e[0] === 1 && e[2] === n && e[1] > e[2] ? {
|
|
2417
2414
|
anchors: e[1],
|
|
2418
2415
|
features: n
|
|
@@ -2421,15 +2418,15 @@ function Dr(e, t) {
|
|
|
2421
2418
|
features: n
|
|
2422
2419
|
} : null;
|
|
2423
2420
|
}
|
|
2424
|
-
function
|
|
2421
|
+
function Tr(e) {
|
|
2425
2422
|
return e.length === 3 && e[1] >= 5 && e[2] >= 1;
|
|
2426
2423
|
}
|
|
2427
|
-
function
|
|
2428
|
-
let t =
|
|
2429
|
-
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, ${
|
|
2424
|
+
function Er(e) {
|
|
2425
|
+
let t = yr(e);
|
|
2426
|
+
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, ${vr}, ${t}].`);
|
|
2430
2427
|
}
|
|
2431
|
-
function
|
|
2432
|
-
if (!
|
|
2428
|
+
function Dr(e, t, n, r, i, a, o) {
|
|
2429
|
+
if (!Tr(t)) throw Error("Unsupported field-model YOLO output shape.");
|
|
2433
2430
|
let s = t[1], c = t[2], l = [];
|
|
2434
2431
|
for (let t = 0; t < c; t += 1) {
|
|
2435
2432
|
let u = 0, d = 0;
|
|
@@ -2441,14 +2438,14 @@ function Ar(e, t, n, r, i, a, o) {
|
|
|
2441
2438
|
!f || u < r || l.push({
|
|
2442
2439
|
field: f,
|
|
2443
2440
|
confidence: u,
|
|
2444
|
-
bbox:
|
|
2441
|
+
bbox: Cr(e[t], e[c + t], e[c * 2 + t], e[c * 3 + t], i, a, o)
|
|
2445
2442
|
});
|
|
2446
2443
|
}
|
|
2447
|
-
return
|
|
2444
|
+
return Sr(l);
|
|
2448
2445
|
}
|
|
2449
|
-
function
|
|
2450
|
-
let s =
|
|
2451
|
-
if (!s) throw
|
|
2446
|
+
function Or(e, t, n, r, i, a, o) {
|
|
2447
|
+
let s = wr(t, n.length);
|
|
2448
|
+
if (!s) throw Er(n.length);
|
|
2452
2449
|
let c = [];
|
|
2453
2450
|
for (let t = 0; t < s.anchors; t += 1) {
|
|
2454
2451
|
let l = t * s.features, u = e[l + 4], d = 0, f = 0;
|
|
@@ -2460,43 +2457,43 @@ function jr(e, t, n, r, i, a, o) {
|
|
|
2460
2457
|
!p || m < r || c.push({
|
|
2461
2458
|
field: p,
|
|
2462
2459
|
confidence: m,
|
|
2463
|
-
bbox:
|
|
2460
|
+
bbox: Cr(e[l], e[l + 1], e[l + 2], e[l + 3], i, a, o)
|
|
2464
2461
|
});
|
|
2465
2462
|
}
|
|
2466
|
-
return
|
|
2463
|
+
return Sr(c);
|
|
2467
2464
|
}
|
|
2468
|
-
function
|
|
2469
|
-
let r = n.classes ??
|
|
2465
|
+
function kr(e, t, n) {
|
|
2466
|
+
let r = n.classes ?? _r, i = n.confidence ?? .35, a = n.inputSize ?? br, o = wr(t, r.length);
|
|
2470
2467
|
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.");
|
|
2471
|
-
return (n.layout ?? (o ? "yolox" : "yolov8")) === "yolox" ?
|
|
2468
|
+
return (n.layout ?? (o ? "yolox" : "yolov8")) === "yolox" ? Or(e, t, r, i, a, n.imageWidth, n.imageHeight) : Dr(e, t, r, i, a, n.imageWidth, n.imageHeight);
|
|
2472
2469
|
}
|
|
2473
|
-
async function
|
|
2474
|
-
let o = await
|
|
2470
|
+
async function Ar(e, n, r = _r, i = .35, a) {
|
|
2471
|
+
let o = await N(e, { cloneCanvas: !1 }), s = import("onnxruntime-web"), c = br, l = document.createElement("canvas");
|
|
2475
2472
|
l.width = c, l.height = c;
|
|
2476
2473
|
let u = l.getContext("2d", { willReadFrequently: !0 });
|
|
2477
2474
|
if (!u) throw t();
|
|
2478
2475
|
u.drawImage(o, 0, 0, c, c);
|
|
2479
2476
|
let d = u.getImageData(0, 0, c, c).data, f = c * c, p = new Float32Array(f * 3);
|
|
2480
2477
|
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;
|
|
2481
|
-
let m =
|
|
2478
|
+
let m = J.get(n);
|
|
2482
2479
|
m || (m = (async () => {
|
|
2483
2480
|
try {
|
|
2484
|
-
let [e, t] = await Promise.all([s,
|
|
2481
|
+
let [e, t] = await Promise.all([s, se(n)]);
|
|
2485
2482
|
return await e.InferenceSession.create(t, {
|
|
2486
2483
|
executionProviders: ["wasm"],
|
|
2487
2484
|
graphOptimizationLevel: "all"
|
|
2488
2485
|
});
|
|
2489
2486
|
} catch (e) {
|
|
2490
|
-
throw
|
|
2487
|
+
throw J.delete(n), e;
|
|
2491
2488
|
}
|
|
2492
|
-
})(),
|
|
2489
|
+
})(), J.set(n, m));
|
|
2493
2490
|
let [h, g] = await Promise.all([s, m]), _ = (await g.run({ [g.inputNames[0]]: new h.Tensor("float32", p, [
|
|
2494
2491
|
1,
|
|
2495
2492
|
3,
|
|
2496
2493
|
c,
|
|
2497
2494
|
c
|
|
2498
2495
|
]) }))[g.outputNames[0]];
|
|
2499
|
-
return
|
|
2496
|
+
return kr(_.data, _.dims.map(Number), {
|
|
2500
2497
|
classes: r,
|
|
2501
2498
|
confidence: i,
|
|
2502
2499
|
layout: a,
|
|
@@ -2507,12 +2504,12 @@ async function Nr(e, n, r = br, i = .35, a) {
|
|
|
2507
2504
|
}
|
|
2508
2505
|
//#endregion
|
|
2509
2506
|
//#region src/sdk/redact.ts
|
|
2510
|
-
async function
|
|
2507
|
+
async function jr(e, n, r = {}) {
|
|
2511
2508
|
await x("redaction");
|
|
2512
|
-
let i = await
|
|
2509
|
+
let i = await N(e), a = i.getContext("2d");
|
|
2513
2510
|
if (!a) throw t();
|
|
2514
2511
|
for (let e of n) {
|
|
2515
|
-
let t =
|
|
2512
|
+
let t = Xe(e, i.width, i.height);
|
|
2516
2513
|
if (t.width < 1 || t.height < 1) continue;
|
|
2517
2514
|
if ((e.mode ?? r.mode ?? "blackout") === "blackout") {
|
|
2518
2515
|
a.fillStyle = "#050706", a.fillRect(t.x, t.y, t.width, t.height);
|
|
@@ -2528,12 +2525,12 @@ async function Pr(e, n, r = {}) {
|
|
|
2528
2525
|
}
|
|
2529
2526
|
return {
|
|
2530
2527
|
canvas: i,
|
|
2531
|
-
blob: await
|
|
2528
|
+
blob: await Ye(i, r.mimeType ?? "image/png", r.quality)
|
|
2532
2529
|
};
|
|
2533
2530
|
}
|
|
2534
2531
|
//#endregion
|
|
2535
2532
|
//#region src/sdk/programmatic-redaction.ts
|
|
2536
|
-
function
|
|
2533
|
+
function Y(e) {
|
|
2537
2534
|
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));
|
|
2538
2535
|
return {
|
|
2539
2536
|
x: t,
|
|
@@ -2542,11 +2539,11 @@ function q(e) {
|
|
|
2542
2539
|
height: i - n
|
|
2543
2540
|
};
|
|
2544
2541
|
}
|
|
2545
|
-
function
|
|
2542
|
+
function Mr(e) {
|
|
2546
2543
|
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);
|
|
2547
2544
|
for (let e of n) {
|
|
2548
2545
|
let n = e.bbox.y + e.bbox.height / 2, r = t.find((t) => {
|
|
2549
|
-
let r =
|
|
2546
|
+
let r = Y(t), i = r.y + r.height / 2;
|
|
2550
2547
|
return Math.abs(n - i) <= Math.max(e.bbox.height, r.height) * .65;
|
|
2551
2548
|
});
|
|
2552
2549
|
r ? r.push(e) : t.push([e]);
|
|
@@ -2554,17 +2551,17 @@ function Fr(e) {
|
|
|
2554
2551
|
return t.map((e) => (e.sort((e, t) => e.bbox.x - t.bbox.x), {
|
|
2555
2552
|
words: e,
|
|
2556
2553
|
text: e.map((e) => e.text).join(" "),
|
|
2557
|
-
bbox:
|
|
2554
|
+
bbox: Y(e)
|
|
2558
2555
|
}));
|
|
2559
2556
|
}
|
|
2560
|
-
function
|
|
2557
|
+
function X(e, t, n = !1) {
|
|
2561
2558
|
let r = e.trim().replace(/\s+/g, " "), i = n ? r.replace(/[::]\s*$/, "") : r;
|
|
2562
2559
|
return t ? i.toLocaleLowerCase() : i;
|
|
2563
2560
|
}
|
|
2564
|
-
function
|
|
2561
|
+
function Z(e) {
|
|
2565
2562
|
return e.reduce((e, t) => e + t.confidence, 0) / Math.max(1, e.length);
|
|
2566
2563
|
}
|
|
2567
|
-
function
|
|
2564
|
+
function Nr(e, t) {
|
|
2568
2565
|
let n = e.mode, r = n === "case-insensitive", i = e.scope ?? "line", a;
|
|
2569
2566
|
if (n === "regex") {
|
|
2570
2567
|
let t = e.pattern ?? e.values?.[0];
|
|
@@ -2575,14 +2572,14 @@ function Ir(e, t) {
|
|
|
2575
2572
|
ruleId: e.id,
|
|
2576
2573
|
strategy: "string",
|
|
2577
2574
|
source: "string",
|
|
2578
|
-
bbox:
|
|
2575
|
+
bbox: Y(t),
|
|
2579
2576
|
text: t.map((e) => e.text).join(" "),
|
|
2580
|
-
confidence:
|
|
2577
|
+
confidence: Z(t)
|
|
2581
2578
|
});
|
|
2582
2579
|
if (i === "word") {
|
|
2583
2580
|
for (let e of t) for (let t of e.words) {
|
|
2584
|
-
let e =
|
|
2585
|
-
(a ? a.test(t.text) : o.some((t) => e ===
|
|
2581
|
+
let e = X(t.text, r);
|
|
2582
|
+
(a ? a.test(t.text) : o.some((t) => e === X(t, r))) && c([t]);
|
|
2586
2583
|
}
|
|
2587
2584
|
return s;
|
|
2588
2585
|
}
|
|
@@ -2592,40 +2589,40 @@ function Ir(e, t) {
|
|
|
2592
2589
|
continue;
|
|
2593
2590
|
}
|
|
2594
2591
|
for (let t of o) {
|
|
2595
|
-
let n =
|
|
2592
|
+
let n = X(t, r).split(" ");
|
|
2596
2593
|
for (let t = 0; t <= e.words.length - n.length; t += 1) {
|
|
2597
2594
|
let i = e.words.slice(t, t + n.length);
|
|
2598
|
-
i.every((e, t) =>
|
|
2595
|
+
i.every((e, t) => X(e.text, r) === n[t]) && c(i);
|
|
2599
2596
|
}
|
|
2600
2597
|
}
|
|
2601
2598
|
}
|
|
2602
2599
|
return s;
|
|
2603
2600
|
}
|
|
2604
|
-
function
|
|
2605
|
-
let n = e.labelMode !== "exact", r =
|
|
2601
|
+
function Pr(e, t) {
|
|
2602
|
+
let n = e.labelMode !== "exact", r = X(e.label, n, !0).split(" ");
|
|
2606
2603
|
for (let e of t) for (let t = 0; t <= e.words.length - r.length; t += 1) {
|
|
2607
2604
|
let i = e.words.slice(t, t + r.length);
|
|
2608
|
-
if (i.every((e, t) =>
|
|
2605
|
+
if (i.every((e, t) => X(e.text, n, !0) === r[t])) return i;
|
|
2609
2606
|
}
|
|
2610
2607
|
}
|
|
2611
|
-
function
|
|
2608
|
+
function Fr(e, t, n, r, i, a) {
|
|
2612
2609
|
let o = a.window?.distance ?? .28, s = a.window?.crossAxis ?? .12, c = t.x + t.width / 2, l = t.y + t.height / 2;
|
|
2613
2610
|
return e.filter((e) => {
|
|
2614
2611
|
let a = e.bbox.x + e.bbox.width / 2, u = e.bbox.y + e.bbox.height / 2;
|
|
2615
2612
|
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;
|
|
2616
2613
|
});
|
|
2617
2614
|
}
|
|
2618
|
-
function
|
|
2619
|
-
let o =
|
|
2615
|
+
function Ir(e, t, n, r, i, a = "label") {
|
|
2616
|
+
let o = Pr(e, n);
|
|
2620
2617
|
if (!o) return [];
|
|
2621
|
-
let s =
|
|
2618
|
+
let s = Y(o), c = new Set(o), l = t.filter((e) => !c.has(e)), u = e.direction === "any" ? [
|
|
2622
2619
|
"right",
|
|
2623
2620
|
"below",
|
|
2624
2621
|
"left",
|
|
2625
2622
|
"above"
|
|
2626
2623
|
] : [e.direction], d;
|
|
2627
2624
|
for (let t of u) {
|
|
2628
|
-
let n = Fr(
|
|
2625
|
+
let n = Mr(Fr(l, s, t, r, i, e));
|
|
2629
2626
|
for (let t of n) {
|
|
2630
2627
|
if (e.valuePattern && !new RegExp(e.valuePattern, e.patternFlags).test(t.text)) continue;
|
|
2631
2628
|
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);
|
|
@@ -2641,12 +2638,12 @@ function zr(e, t, n, r, i, a = "label") {
|
|
|
2641
2638
|
ruleId: e.id,
|
|
2642
2639
|
strategy: a,
|
|
2643
2640
|
source: a === "template-anchor" ? "template" : "label",
|
|
2644
|
-
bbox:
|
|
2641
|
+
bbox: Y(f),
|
|
2645
2642
|
text: d.words.map((e) => e.text).join(" "),
|
|
2646
|
-
confidence: Math.max(0,
|
|
2643
|
+
confidence: Math.max(0, Z(d.words) * (1 - Math.min(.5, d.distance)))
|
|
2647
2644
|
}];
|
|
2648
2645
|
}
|
|
2649
|
-
var
|
|
2646
|
+
var Lr = {
|
|
2650
2647
|
person_name: [
|
|
2651
2648
|
"LN",
|
|
2652
2649
|
"FN",
|
|
@@ -2683,32 +2680,32 @@ var Br = {
|
|
|
2683
2680
|
"POSTAL"
|
|
2684
2681
|
],
|
|
2685
2682
|
state: ["STATE", "DAJ"]
|
|
2686
|
-
},
|
|
2687
|
-
function
|
|
2683
|
+
}, Rr = new Set(Object.values(Lr).flat()), zr = /^(?:\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, Vr = /\b(?:DRIVER|LICENSE|IDENTIFICATION|CARD|CLASS|SEX|EYES|HEIGHT|RESTRICTIONS)\b/i;
|
|
2684
|
+
function Q(e, t) {
|
|
2688
2685
|
let n = t.trim();
|
|
2689
|
-
return n ? e === "date_of_birth" || e === "expiration_date" ?
|
|
2686
|
+
return n ? e === "date_of_birth" || e === "expiration_date" ? zr.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) && !Vr.test(n) : /\d/.test(n) && /[A-Z]/i.test(n) : !1;
|
|
2690
2687
|
}
|
|
2691
|
-
function
|
|
2688
|
+
function $(e, t, n, r, i = 1) {
|
|
2692
2689
|
return {
|
|
2693
2690
|
ruleId: e,
|
|
2694
2691
|
strategy: "semantic",
|
|
2695
2692
|
source: t,
|
|
2696
|
-
bbox:
|
|
2693
|
+
bbox: Y(n),
|
|
2697
2694
|
text: r ?? n.map((e) => e.text).join(" "),
|
|
2698
|
-
confidence: Math.max(0, Math.min(1,
|
|
2695
|
+
confidence: Math.max(0, Math.min(1, Z(n) * i))
|
|
2699
2696
|
};
|
|
2700
2697
|
}
|
|
2701
|
-
function
|
|
2702
|
-
let r =
|
|
2698
|
+
function Hr(e, t, n) {
|
|
2699
|
+
let r = Lr[e], i = [];
|
|
2703
2700
|
for (let a of n) for (let n = 0; n < a.words.length; n += 1) {
|
|
2704
2701
|
let o = a.words[n].text.toUpperCase().replace(/[^A-Z0-9]/g, ""), s = r.find((e) => o === e || o.startsWith(e));
|
|
2705
2702
|
if (!s) continue;
|
|
2706
2703
|
let c, l;
|
|
2707
|
-
o === s ? (c = a.words.slice(n + 1).filter((e) => !
|
|
2704
|
+
o === s ? (c = a.words.slice(n + 1).filter((e) => !Rr.has(e.text.toUpperCase().replace(/[^A-Z0-9]/g, ""))), l = c.map((e) => e.text).join(" ")) : (c = [a.words[n]], l = a.words[n].text.replace(RegExp(`^${s}[:\\s-]*`, "i"), "")), c.length && Q(e, l) && i.push($(t, "alias", c, l, .98));
|
|
2708
2705
|
}
|
|
2709
2706
|
return i;
|
|
2710
2707
|
}
|
|
2711
|
-
function
|
|
2708
|
+
function Ur(e, t, n) {
|
|
2712
2709
|
let r = n.filter((e) => {
|
|
2713
2710
|
let t = e.text.replace(/\s/g, "");
|
|
2714
2711
|
return t.includes("<<") || /^[A-Z0-9<]{25,}$/.test(t);
|
|
@@ -2718,19 +2715,19 @@ function Kr(e, t, n) {
|
|
|
2718
2715
|
let e = r.find((e) => e.text.includes("<<"));
|
|
2719
2716
|
if (!e) return [];
|
|
2720
2717
|
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();
|
|
2721
|
-
return a ? [
|
|
2718
|
+
return a ? [$(t, "mrz", e.words, a, .96)] : [];
|
|
2722
2719
|
}
|
|
2723
2720
|
if (e === "date_of_birth") for (let e of r) {
|
|
2724
2721
|
let n = e.text.replace(/\s/g, ""), r = /^\d{6}/.exec(n)?.[0] ?? /^.{13}(\d{6})/.exec(n)?.[1];
|
|
2725
|
-
if (r) return [
|
|
2722
|
+
if (r) return [$(t, "mrz", e.words, r, .96)];
|
|
2726
2723
|
}
|
|
2727
2724
|
if (e === "document_number") {
|
|
2728
2725
|
let e = r[0];
|
|
2729
|
-
return [
|
|
2726
|
+
return [$(t, "mrz", e.words, e.text, .9)];
|
|
2730
2727
|
}
|
|
2731
2728
|
return [];
|
|
2732
2729
|
}
|
|
2733
|
-
function
|
|
2730
|
+
function Wr(e) {
|
|
2734
2731
|
let t = e.replace(/\s/g, ""), n = t.match(/\d{4}/)?.[0];
|
|
2735
2732
|
if (n) return Number(n);
|
|
2736
2733
|
let r = t.match(/^\d{2}/)?.[0];
|
|
@@ -2738,67 +2735,67 @@ function qr(e) {
|
|
|
2738
2735
|
let i = Number(r);
|
|
2739
2736
|
return i > (/* @__PURE__ */ new Date()).getFullYear() % 100 ? 1900 + i : 2e3 + i;
|
|
2740
2737
|
}
|
|
2741
|
-
function
|
|
2738
|
+
function Gr(e, t, n, r, i) {
|
|
2742
2739
|
if (e === "address") {
|
|
2743
|
-
let e = r.findIndex((e) => /\d/.test(e.text) &&
|
|
2740
|
+
let e = r.findIndex((e) => /\d/.test(e.text) && Br.test(e.text));
|
|
2744
2741
|
if (e < 0) return [];
|
|
2745
2742
|
let n = [...r[e].words], i = r[e + 1];
|
|
2746
|
-
return i && /(?:\b[A-Z]{2}\b.*\d{5}|\d{5})/i.test(i.text) && n.push(...i.words), [
|
|
2743
|
+
return i && /(?:\b[A-Z]{2}\b.*\d{5}|\d{5})/i.test(i.text) && n.push(...i.words), [$(t, "layout", n, void 0, .76)];
|
|
2747
2744
|
}
|
|
2748
2745
|
if (e === "person_name") {
|
|
2749
2746
|
let e = r.map((e) => {
|
|
2750
|
-
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 && !
|
|
2747
|
+
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 && !Vr.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);
|
|
2751
2748
|
return {
|
|
2752
2749
|
line: e,
|
|
2753
|
-
score: r ? .45 +
|
|
2750
|
+
score: r ? .45 + Z(e.words) * .3 + a * .15 + (n < .65 ? .1 : 0) : 0
|
|
2754
2751
|
};
|
|
2755
2752
|
}).filter((e) => e.score >= .68).sort((e, t) => t.score - e.score);
|
|
2756
|
-
return !e.length || e[1] && e[0].score - e[1].score < .04 ? [] : [
|
|
2753
|
+
return !e.length || e[1] && e[0].score - e[1].score < .04 ? [] : [$(t, "layout", e[0].line.words, void 0, e[0].score)];
|
|
2757
2754
|
}
|
|
2758
2755
|
if (e === "date_of_birth" || e === "expiration_date") {
|
|
2759
|
-
let r = (/* @__PURE__ */ new Date()).getFullYear(), i = n.filter((e) =>
|
|
2756
|
+
let r = (/* @__PURE__ */ new Date()).getFullYear(), i = n.filter((e) => zr.test(e.text.replace(/\s/g, ""))).map((e) => ({
|
|
2760
2757
|
word: e,
|
|
2761
|
-
year:
|
|
2758
|
+
year: Wr(e.text)
|
|
2762
2759
|
})).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);
|
|
2763
|
-
return a.sort((t, n) => e === "date_of_birth" ? t.year - n.year : n.year - t.year), a.length ? [
|
|
2760
|
+
return a.sort((t, n) => e === "date_of_birth" ? t.year - n.year : n.year - t.year), a.length ? [$(t, "layout", [a[0].word], void 0, .72)] : [];
|
|
2764
2761
|
}
|
|
2765
2762
|
if (e === "postal_code") {
|
|
2766
|
-
let r = n.find((t) =>
|
|
2767
|
-
return r ? [
|
|
2763
|
+
let r = n.find((t) => Q(e, t.text));
|
|
2764
|
+
return r ? [$(t, "layout", [r], void 0, .78)] : [];
|
|
2768
2765
|
}
|
|
2769
2766
|
if (e === "state") {
|
|
2770
|
-
let r = n.filter((t) =>
|
|
2771
|
-
return r.length === 1 ? [
|
|
2767
|
+
let r = n.filter((t) => Q(e, t.text));
|
|
2768
|
+
return r.length === 1 ? [$(t, "layout", r, void 0, .7)] : [];
|
|
2772
2769
|
}
|
|
2773
2770
|
if (e === "document_number") {
|
|
2774
|
-
let r = n.filter((t) =>
|
|
2775
|
-
return r.sort((e, t) => t.text.length - e.text.length), r.length ? [
|
|
2771
|
+
let r = n.filter((t) => Q(e, t.text));
|
|
2772
|
+
return r.sort((e, t) => t.text.length - e.text.length), r.length ? [$(t, "layout", [r[0]], void 0, .7)] : [];
|
|
2776
2773
|
}
|
|
2777
2774
|
return [];
|
|
2778
2775
|
}
|
|
2779
|
-
function
|
|
2776
|
+
function Kr(e, t) {
|
|
2780
2777
|
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);
|
|
2781
2778
|
}
|
|
2782
|
-
function
|
|
2783
|
-
let i =
|
|
2784
|
-
return i.length || a.length ? [...i, ...a] :
|
|
2779
|
+
function qr(e, t, n, r) {
|
|
2780
|
+
let i = Hr(e.field, e.id, n), a = Ur(e.field, e.id, n);
|
|
2781
|
+
return i.length || a.length ? [...i, ...a] : Gr(e.field, e.id, t, n, r);
|
|
2785
2782
|
}
|
|
2786
|
-
function
|
|
2783
|
+
function Jr(e, t, n) {
|
|
2787
2784
|
let r = (n ?? []).filter((t) => t.field === e.field).sort((e, t) => t.confidence - e.confidence);
|
|
2788
2785
|
for (let n of r) {
|
|
2789
|
-
let r = t.filter((e) =>
|
|
2786
|
+
let r = t.filter((e) => Kr(n.bbox, e.bbox) >= .3);
|
|
2790
2787
|
if (!r.length) continue;
|
|
2791
2788
|
let i = r.map((e) => e.text).join(" ");
|
|
2792
|
-
if (
|
|
2789
|
+
if (Q(e.field, i)) return $(e.id, "model", r, i, n.confidence);
|
|
2793
2790
|
}
|
|
2794
2791
|
}
|
|
2795
|
-
function
|
|
2796
|
-
let o =
|
|
2792
|
+
function Yr(e, t, n, r, i, a) {
|
|
2793
|
+
let o = qr(e, t, n, r);
|
|
2797
2794
|
if (e.detector !== "model" || !a) return o;
|
|
2798
|
-
let s =
|
|
2795
|
+
let s = Jr(e, t, i);
|
|
2799
2796
|
return s ? [s] : [];
|
|
2800
2797
|
}
|
|
2801
|
-
function
|
|
2798
|
+
function Xr(e, t, n, r) {
|
|
2802
2799
|
let i = (e) => Math.max(0, Math.min(1, e)), a = i(e.rect.x), o = i(e.rect.y);
|
|
2803
2800
|
return {
|
|
2804
2801
|
ruleId: `${t}.${e.id}`,
|
|
@@ -2813,19 +2810,19 @@ function $r(e, t, n, r) {
|
|
|
2813
2810
|
confidence: 1
|
|
2814
2811
|
};
|
|
2815
2812
|
}
|
|
2816
|
-
function
|
|
2817
|
-
let n = t.imageWidth ?? e?.imageWidth ?? 0, r = t.imageHeight ?? e?.imageHeight ?? 0, i = e?.words ?? [], a =
|
|
2813
|
+
function Zr(e, t) {
|
|
2814
|
+
let n = t.imageWidth ?? e?.imageWidth ?? 0, r = t.imageHeight ?? e?.imageHeight ?? 0, i = e?.words ?? [], a = Mr(i), o = [], s = [];
|
|
2818
2815
|
for (let e of t.rules) {
|
|
2819
|
-
let c = e.strategy === "string" ?
|
|
2816
|
+
let c = e.strategy === "string" ? Nr(e, a) : e.strategy === "label" ? Ir(e, i, a, n, r) : Yr(e, i, a, r, t.semanticDetections, t.modelRequested === !0);
|
|
2820
2817
|
c.length ? o.push(...c) : s.push(e.id);
|
|
2821
2818
|
}
|
|
2822
2819
|
for (let e of t.template?.fields ?? []) {
|
|
2823
2820
|
let c = `${t.template.id}.${e.id}`;
|
|
2824
2821
|
if (e.strategy === "rect") {
|
|
2825
|
-
n && r ? o.push(
|
|
2822
|
+
n && r ? o.push(Xr(e, t.template.id, n, r)) : s.push(c);
|
|
2826
2823
|
continue;
|
|
2827
2824
|
}
|
|
2828
|
-
let l =
|
|
2825
|
+
let l = Ir({
|
|
2829
2826
|
...e,
|
|
2830
2827
|
id: c,
|
|
2831
2828
|
strategy: "label"
|
|
@@ -2843,34 +2840,34 @@ function ei(e, t) {
|
|
|
2843
2840
|
confidence: u
|
|
2844
2841
|
};
|
|
2845
2842
|
}
|
|
2846
|
-
function
|
|
2843
|
+
function Qr(e) {
|
|
2847
2844
|
return e.rules.length > 0 || e.template?.fields.some((e) => e.strategy === "anchor") === !0;
|
|
2848
2845
|
}
|
|
2849
|
-
function
|
|
2846
|
+
function $r(e, t = !1) {
|
|
2850
2847
|
return t && !e.complete ? "unmatched" : e.complete ? "success" : "partial";
|
|
2851
2848
|
}
|
|
2852
|
-
async function
|
|
2849
|
+
async function ei(e, t) {
|
|
2853
2850
|
await x("redaction");
|
|
2854
|
-
let n = await
|
|
2855
|
-
|
|
2851
|
+
let n = await N(e, { cloneCanvas: !1 }), r = t.ocr;
|
|
2852
|
+
Qr(t) && !r && (r = await bn(n, { includeWords: !0 }));
|
|
2856
2853
|
let i = t.semanticDetections, a = t.modelRequested === !0, o = "not-requested", s;
|
|
2857
2854
|
if (t.models?.fields) try {
|
|
2858
|
-
i = await
|
|
2855
|
+
i = await Ar(n, t.models.fields, t.models.fieldClasses, t.models.confidence, t.models.fieldLayout), a = !0, o = "loaded";
|
|
2859
2856
|
} catch (e) {
|
|
2860
2857
|
s = e instanceof Error ? e.message : "The field model could not load.";
|
|
2861
2858
|
let n = t.models.allowHeuristicFallback !== !1;
|
|
2862
2859
|
a = !n, o = n ? "fallback" : "failed";
|
|
2863
2860
|
}
|
|
2864
|
-
let c =
|
|
2861
|
+
let c = Zr(r, {
|
|
2865
2862
|
rules: t.rules,
|
|
2866
2863
|
template: t.template,
|
|
2867
2864
|
imageWidth: n.width,
|
|
2868
2865
|
imageHeight: n.height,
|
|
2869
2866
|
semanticDetections: i,
|
|
2870
2867
|
modelRequested: a
|
|
2871
|
-
}), l =
|
|
2868
|
+
}), l = $r(c, t.requireAll), u = [], d = "not-requested", f;
|
|
2872
2869
|
if (t.models?.face) try {
|
|
2873
|
-
u = await
|
|
2870
|
+
u = await gr(n, t.models.face, t.models.faceConfidence), d = "loaded";
|
|
2874
2871
|
} catch (e) {
|
|
2875
2872
|
f = e instanceof Error ? e.message : "The face model could not load.", d = "failed";
|
|
2876
2873
|
}
|
|
@@ -2884,7 +2881,7 @@ async function ri(e, t) {
|
|
|
2884
2881
|
faceStatus: d,
|
|
2885
2882
|
faceError: f
|
|
2886
2883
|
};
|
|
2887
|
-
let p = await
|
|
2884
|
+
let p = await jr(n, [...c.matches.map((e) => ({
|
|
2888
2885
|
...e.bbox,
|
|
2889
2886
|
mode: t.style?.mode
|
|
2890
2887
|
})), ...u.map((e) => ({
|
|
@@ -2906,7 +2903,7 @@ async function ri(e, t) {
|
|
|
2906
2903
|
}
|
|
2907
2904
|
//#endregion
|
|
2908
2905
|
//#region src/sdk/driver-license.ts
|
|
2909
|
-
var
|
|
2906
|
+
var ti = [
|
|
2910
2907
|
{
|
|
2911
2908
|
id: "issuerJurisdiction",
|
|
2912
2909
|
strategy: "semantic",
|
|
@@ -2943,11 +2940,11 @@ var ii = [
|
|
|
2943
2940
|
field: "person_name"
|
|
2944
2941
|
}
|
|
2945
2942
|
];
|
|
2946
|
-
function
|
|
2943
|
+
function ni(e, t, n) {
|
|
2947
2944
|
let r = n.trim();
|
|
2948
2945
|
if (r) {
|
|
2949
2946
|
if (t === "expirationDate" || t === "dateOfBirth" || t === "issueDate") {
|
|
2950
|
-
e[t] =
|
|
2947
|
+
e[t] = q(r, t === "dateOfBirth") ?? r;
|
|
2951
2948
|
return;
|
|
2952
2949
|
}
|
|
2953
2950
|
if (t === "issuerJurisdiction") {
|
|
@@ -2957,8 +2954,8 @@ function ai(e, t, n) {
|
|
|
2957
2954
|
e[t] = r;
|
|
2958
2955
|
}
|
|
2959
2956
|
}
|
|
2960
|
-
function
|
|
2961
|
-
let t = {}, n =
|
|
2957
|
+
function ri(e) {
|
|
2958
|
+
let t = {}, n = Zr(e, { rules: ti });
|
|
2962
2959
|
for (let e of n.matches) {
|
|
2963
2960
|
let n = e.text?.trim();
|
|
2964
2961
|
if (n) {
|
|
@@ -2967,29 +2964,29 @@ function Q(e) {
|
|
|
2967
2964
|
!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(" "));
|
|
2968
2965
|
continue;
|
|
2969
2966
|
}
|
|
2970
|
-
|
|
2967
|
+
ni(t, e.ruleId, n);
|
|
2971
2968
|
}
|
|
2972
2969
|
}
|
|
2973
2970
|
return t;
|
|
2974
2971
|
}
|
|
2975
|
-
function
|
|
2976
|
-
let n = { ...e }, r =
|
|
2972
|
+
function ii(e, t) {
|
|
2973
|
+
let n = { ...e }, r = ur(lr(), e, "barcode");
|
|
2977
2974
|
for (let [e, i] of Object.entries(t)) i && (n[e] || (n[e] = i, r[e] = "ocr"));
|
|
2978
2975
|
return {
|
|
2979
2976
|
fields: n,
|
|
2980
2977
|
sources: r
|
|
2981
2978
|
};
|
|
2982
2979
|
}
|
|
2983
|
-
async function
|
|
2984
|
-
return t?.status === "success" && t.corners ?
|
|
2980
|
+
async function ai(e, t, n) {
|
|
2981
|
+
return t?.status === "success" && t.corners ? ft(e, t.corners, { maxOutputDimension: n?.maxOutputDimension }) : L(e, n);
|
|
2985
2982
|
}
|
|
2986
|
-
async function
|
|
2983
|
+
async function oi(e, t, n) {
|
|
2987
2984
|
if (!e.width || !e.height) return {
|
|
2988
2985
|
kind: "retry",
|
|
2989
2986
|
status: "frontFailed",
|
|
2990
2987
|
message: "The front photo was empty. Try again."
|
|
2991
2988
|
};
|
|
2992
|
-
let r = await
|
|
2989
|
+
let r = await ai(e, t, n);
|
|
2993
2990
|
if (r.status !== "success" || !r.canvas) return {
|
|
2994
2991
|
kind: "retry",
|
|
2995
2992
|
status: "frontFailed",
|
|
@@ -2997,7 +2994,7 @@ async function ci(e, t, n) {
|
|
|
2997
2994
|
};
|
|
2998
2995
|
let i;
|
|
2999
2996
|
try {
|
|
3000
|
-
i = await
|
|
2997
|
+
i = await bn(r.canvas, { includeWords: !0 });
|
|
3001
2998
|
} catch {
|
|
3002
2999
|
i = void 0;
|
|
3003
3000
|
}
|
|
@@ -3010,44 +3007,7 @@ async function ci(e, t, n) {
|
|
|
3010
3007
|
}
|
|
3011
3008
|
};
|
|
3012
3009
|
}
|
|
3013
|
-
function
|
|
3014
|
-
return new DOMException("The barcode scan was cancelled.", "AbortError");
|
|
3015
|
-
}
|
|
3016
|
-
function li(e, t) {
|
|
3017
|
-
return new Promise((n, r) => {
|
|
3018
|
-
if (t?.aborted) {
|
|
3019
|
-
r($());
|
|
3020
|
-
return;
|
|
3021
|
-
}
|
|
3022
|
-
let i = setTimeout(() => {
|
|
3023
|
-
t?.removeEventListener("abort", a), n();
|
|
3024
|
-
}, e), a = () => {
|
|
3025
|
-
clearTimeout(i), r($());
|
|
3026
|
-
};
|
|
3027
|
-
t?.addEventListener("abort", a, { once: !0 });
|
|
3028
|
-
});
|
|
3029
|
-
}
|
|
3030
|
-
async function ui(e, t = {}) {
|
|
3031
|
-
let n = t.intervalMs ?? 140;
|
|
3032
|
-
for (await Hn();;) {
|
|
3033
|
-
if (t.signal?.aborted) throw $();
|
|
3034
|
-
try {
|
|
3035
|
-
let t = await e();
|
|
3036
|
-
if (t?.width && t.height) {
|
|
3037
|
-
let e = await Zn(t);
|
|
3038
|
-
if (e?.text) return {
|
|
3039
|
-
frame: t,
|
|
3040
|
-
quad: e.quad
|
|
3041
|
-
};
|
|
3042
|
-
}
|
|
3043
|
-
} catch (e) {
|
|
3044
|
-
if (t.signal?.aborted) throw $();
|
|
3045
|
-
if (e instanceof DOMException && e.name === "AbortError" || e instanceof U) throw e;
|
|
3046
|
-
}
|
|
3047
|
-
await li(n, t.signal);
|
|
3048
|
-
}
|
|
3049
|
-
}
|
|
3050
|
-
async function di(e, t) {
|
|
3010
|
+
async function si(e, t) {
|
|
3051
3011
|
if (!e.width || !e.height) return {
|
|
3052
3012
|
status: "backFailed",
|
|
3053
3013
|
fields: {},
|
|
@@ -3057,23 +3017,23 @@ async function di(e, t) {
|
|
|
3057
3017
|
back: {},
|
|
3058
3018
|
message: "The back photo was empty. Try again."
|
|
3059
3019
|
};
|
|
3060
|
-
let n = (await
|
|
3020
|
+
let n = (await Xn(e))?.text, r = {
|
|
3061
3021
|
canvas: e,
|
|
3062
3022
|
barcodeText: n
|
|
3063
3023
|
};
|
|
3064
3024
|
if (!n) {
|
|
3065
|
-
let e = t.ocr ?
|
|
3025
|
+
let e = t.ocr ? ri(t.ocr) : {};
|
|
3066
3026
|
return {
|
|
3067
3027
|
status: "barcodeUnreadable",
|
|
3068
3028
|
fields: e,
|
|
3069
3029
|
rawElements: {},
|
|
3070
|
-
sources:
|
|
3030
|
+
sources: ur(lr(), e, "ocr"),
|
|
3071
3031
|
front: t,
|
|
3072
3032
|
back: r,
|
|
3073
3033
|
message: "The PDF417 barcode on the back could not be read. Try again."
|
|
3074
3034
|
};
|
|
3075
3035
|
}
|
|
3076
|
-
let i =
|
|
3036
|
+
let i = cr(n), a = t.ocr ? ri(t.ocr) : {}, o = ii(i.fields, a);
|
|
3077
3037
|
return {
|
|
3078
3038
|
status: "success",
|
|
3079
3039
|
fields: o.fields,
|
|
@@ -3083,10 +3043,8 @@ async function di(e, t) {
|
|
|
3083
3043
|
back: r
|
|
3084
3044
|
};
|
|
3085
3045
|
}
|
|
3086
|
-
function
|
|
3087
|
-
|
|
3088
|
-
}
|
|
3089
|
-
function pi(e, t) {
|
|
3046
|
+
function ci(e) {}
|
|
3047
|
+
function li(e, t) {
|
|
3090
3048
|
return e === "front" ? {
|
|
3091
3049
|
title: "Scan a driver’s license",
|
|
3092
3050
|
headline: "Show the front of the license.",
|
|
@@ -3098,10 +3056,10 @@ function pi(e, t) {
|
|
|
3098
3056
|
} : {
|
|
3099
3057
|
title: "Scan a driver’s license",
|
|
3100
3058
|
headline: "Hold the whole barcode in view",
|
|
3101
|
-
detail: t ? "Take a photo of the entire PDF417 barcode.
|
|
3059
|
+
detail: t ? "Take a photo of the entire PDF417 barcode. We outline the card and the barcode after the photo." : "Keep the entire PDF417 in the preview. Closer is fine if the whole code is visible."
|
|
3102
3060
|
};
|
|
3103
3061
|
}
|
|
3104
|
-
async function
|
|
3062
|
+
async function ui(e = {}) {
|
|
3105
3063
|
await x("scan"), await x("ocr");
|
|
3106
3064
|
let t = "front", n, r = !1;
|
|
3107
3065
|
return {
|
|
@@ -3115,10 +3073,10 @@ async function mi(e = {}) {
|
|
|
3115
3073
|
message: "This license scan was cancelled."
|
|
3116
3074
|
};
|
|
3117
3075
|
if (t === "front") {
|
|
3118
|
-
let r = await
|
|
3076
|
+
let r = await oi(i, a, e.scan);
|
|
3119
3077
|
return r.kind === "need-back" && (n = r.front, t = "back"), r;
|
|
3120
3078
|
}
|
|
3121
|
-
let o = await
|
|
3079
|
+
let o = await si(i, n ?? {});
|
|
3122
3080
|
return o.status === "backFailed" ? {
|
|
3123
3081
|
kind: "retry",
|
|
3124
3082
|
status: "backFailed",
|
|
@@ -3134,6 +3092,6 @@ async function mi(e = {}) {
|
|
|
3134
3092
|
};
|
|
3135
3093
|
}
|
|
3136
3094
|
//#endregion
|
|
3137
|
-
export {
|
|
3095
|
+
export { y as $, mt as A, xe as B, Ct as C, dt as D, ft as E, M as F, fe as G, A as H, D as I, ie as J, Le as K, le as L, ye as M, ve as N, et as O, ke as P, b as Q, Re as R, Ft as S, Ze as T, ze as U, O as V, de as W, o as X, a as Y, x as Z, Dt as _, ui as a, Pt as b, jr as c, Pn as d, e as et, Xn as f, It as g, Ot as h, ii as i, pt as j, L as k, q as l, bn as m, ci as n, Zr as o, zn as p, be as q, li as r, ei as s, ri as t, t as tt, cr as u, Tt as v, Bt as w, Nt as x, wt as y, ue as z };
|
|
3138
3096
|
|
|
3139
|
-
//# sourceMappingURL=driver-license-
|
|
3097
|
+
//# sourceMappingURL=driver-license-D9y7PQn4.js.map
|