@exige/web-scanner-sdk 0.2.33 → 0.2.36
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/dist/{driver-license-DBrWpI9w.js → driver-license-CBDCGp14.js} +510 -445
- package/dist/driver-license-CBDCGp14.js.map +1 -0
- package/dist/react.js +319 -317
- package/dist/react.js.map +1 -1
- package/dist/scanner-sdk.js +3 -3
- package/dist/sdk/barcode.d.ts +25 -2
- package/dist/sdk/zxing-runtime.d.ts +2 -2
- package/package.json +1 -1
- package/dist/driver-license-DBrWpI9w.js.map +0 -1
|
@@ -305,40 +305,40 @@ function k(e = typeof navigator > "u" ? "" : navigator.userAgent, t = typeof nav
|
|
|
305
305
|
userAgent: e
|
|
306
306
|
};
|
|
307
307
|
}
|
|
308
|
-
function
|
|
308
|
+
function ce(e) {
|
|
309
309
|
return /Android/i.test(e.userAgent) && !e.iosWebKit;
|
|
310
310
|
}
|
|
311
|
-
function
|
|
312
|
-
return e.engine === "webkit" && !
|
|
311
|
+
function le(e = k()) {
|
|
312
|
+
return e.engine === "webkit" && !ce(e);
|
|
313
313
|
}
|
|
314
|
-
function
|
|
315
|
-
return e === "system-camera" || e !== "live" &&
|
|
314
|
+
function ue(e = "auto", t = k()) {
|
|
315
|
+
return e === "system-camera" || e !== "live" && ce(t);
|
|
316
316
|
}
|
|
317
|
-
function
|
|
317
|
+
function de(e, t) {
|
|
318
318
|
return t && !e.iosWebKit;
|
|
319
319
|
}
|
|
320
|
-
function
|
|
320
|
+
function fe(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 pe(e) {
|
|
328
|
+
let t = fe(e?.imageWidth?.max ?? 0, e?.imageWidth), n = fe(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 me(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 he(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 ge = 10, _e = class {
|
|
342
342
|
on = !1;
|
|
343
343
|
darkCount = 0;
|
|
344
344
|
brightCount = 0;
|
|
@@ -361,7 +361,7 @@ var he = 10, ge = class {
|
|
|
361
361
|
return this.on;
|
|
362
362
|
}
|
|
363
363
|
};
|
|
364
|
-
function
|
|
364
|
+
function ve(e, t) {
|
|
365
365
|
return t ? e === "alwaysOn" || e === "alwaysOff" ? {
|
|
366
366
|
mode: e,
|
|
367
367
|
supported: !0,
|
|
@@ -385,37 +385,37 @@ function _e(e, t) {
|
|
|
385
385
|
automatic: e === "auto"
|
|
386
386
|
};
|
|
387
387
|
}
|
|
388
|
-
function
|
|
388
|
+
function ye(e) {
|
|
389
389
|
let t = Math.floor(e.length / 4);
|
|
390
390
|
if (!t) return 0;
|
|
391
391
|
let n = 0;
|
|
392
392
|
for (let r = 0; r < t * 4; r += 4) n += e[r] * .299 + e[r + 1] * .587 + e[r + 2] * .114;
|
|
393
393
|
return n / t;
|
|
394
394
|
}
|
|
395
|
-
function
|
|
395
|
+
function be(e, t = 10) {
|
|
396
396
|
if (e.length < 4) return !0;
|
|
397
397
|
let n = Math.floor(e.length / 4), r = 0;
|
|
398
398
|
for (let i = 0; i < n * 4; i += 4) e[i] * .299 + e[i + 1] * .587 + e[i + 2] * .114 > t * 2 && (r += 1);
|
|
399
|
-
return
|
|
399
|
+
return ye(e) <= t && r / n < .01;
|
|
400
400
|
}
|
|
401
|
-
function
|
|
401
|
+
function xe(e, t, n) {
|
|
402
402
|
if (!t || !n) return 0;
|
|
403
403
|
let r = document.createElement("canvas");
|
|
404
404
|
r.width = Math.min(32, t), r.height = Math.min(32, n);
|
|
405
405
|
let i = r.getContext("2d", { willReadFrequently: !0 });
|
|
406
|
-
return i ? (i.drawImage(e, 0, 0, r.width, r.height),
|
|
406
|
+
return i ? (i.drawImage(e, 0, 0, r.width, r.height), ye(i.getImageData(0, 0, r.width, r.height).data)) : 0;
|
|
407
407
|
}
|
|
408
|
-
function
|
|
409
|
-
return
|
|
408
|
+
function Se(e) {
|
|
409
|
+
return xe(e, e.width, e.height);
|
|
410
410
|
}
|
|
411
|
-
function
|
|
411
|
+
function Ce(e, t = 120) {
|
|
412
412
|
let n = document.createElement("canvas"), r = n.getContext("2d"), i = typeof e.requestVideoFrameCallback == "function", a = !0, o = 0, s = 0, c = 0, l = 0, u = 0, d = () => {
|
|
413
413
|
a && (o = i ? e.requestVideoFrameCallback(f) : requestAnimationFrame(f));
|
|
414
414
|
};
|
|
415
415
|
function f() {
|
|
416
416
|
if (!a) return;
|
|
417
417
|
let { videoWidth: i, videoHeight: o } = e, f = performance.now();
|
|
418
|
-
r && i && o && f - s >= t && (s = f, l =
|
|
418
|
+
r && i && o && f - s >= t && (s = f, l = xe(e, i, o), l > 10 && ((n.width !== i || n.height !== o) && (n.width = i, n.height = o), r.drawImage(e, 0, 0, i, o), u = l, c = f)), d();
|
|
419
419
|
}
|
|
420
420
|
return d(), {
|
|
421
421
|
stop() {
|
|
@@ -427,14 +427,14 @@ function xe(e, t = 120) {
|
|
|
427
427
|
getMirrorAgeMs: () => c ? performance.now() - c : Infinity
|
|
428
428
|
};
|
|
429
429
|
}
|
|
430
|
-
function
|
|
430
|
+
function we(e) {
|
|
431
431
|
let t = document.createElement("canvas");
|
|
432
432
|
return t.width = e.width, t.height = e.height, t.getContext("2d")?.drawImage(e, 0, 0), t;
|
|
433
433
|
}
|
|
434
|
-
function
|
|
434
|
+
function Te(e) {
|
|
435
435
|
return e.engine === "blink";
|
|
436
436
|
}
|
|
437
|
-
function
|
|
437
|
+
function A(e = {}, t = k()) {
|
|
438
438
|
let n = { ideal: e.idealWidth ?? 3840 }, r = { ideal: e.idealHeight ?? 2160 };
|
|
439
439
|
e.maxWidth && (n.max = e.maxWidth), e.maxHeight && (r.max = e.maxHeight);
|
|
440
440
|
let i = {
|
|
@@ -446,20 +446,20 @@ function M(e = {}, t = k()) {
|
|
|
446
446
|
max: e.maxFrameRate ?? 30
|
|
447
447
|
}
|
|
448
448
|
};
|
|
449
|
-
return
|
|
449
|
+
return Te(t) && (i.resizeMode = { ideal: "none" }), {
|
|
450
450
|
audio: !1,
|
|
451
451
|
video: i
|
|
452
452
|
};
|
|
453
453
|
}
|
|
454
|
-
function
|
|
454
|
+
function Ee(e, t, n) {
|
|
455
455
|
let r = n ? Math.min(1, n / Math.max(e, t)) : 1;
|
|
456
456
|
return {
|
|
457
457
|
width: Math.max(1, Math.round(e * r)),
|
|
458
458
|
height: Math.max(1, Math.round(t * r))
|
|
459
459
|
};
|
|
460
460
|
}
|
|
461
|
-
var
|
|
462
|
-
function
|
|
461
|
+
var De = 4096;
|
|
462
|
+
function Oe(e, t) {
|
|
463
463
|
let n = e.width, r = e.height, i = t?.width?.max, a = t?.height?.max;
|
|
464
464
|
if (!n || !r || !i || !a) return;
|
|
465
465
|
let o = Math.min(i / n, a / r);
|
|
@@ -468,13 +468,13 @@ function Ee(e, t) {
|
|
|
468
468
|
height: { ideal: Math.round(r * o) }
|
|
469
469
|
};
|
|
470
470
|
}
|
|
471
|
-
async function
|
|
472
|
-
let t =
|
|
471
|
+
async function ke(e) {
|
|
472
|
+
let t = Oe(e.getSettings(), typeof e.getCapabilities == "function" ? e.getCapabilities() : void 0);
|
|
473
473
|
if (t) try {
|
|
474
474
|
await e.applyConstraints(t);
|
|
475
475
|
} catch {}
|
|
476
476
|
}
|
|
477
|
-
async function
|
|
477
|
+
async function Ae(e) {
|
|
478
478
|
try {
|
|
479
479
|
return await createImageBitmap(e, {
|
|
480
480
|
imageOrientation: "from-image",
|
|
@@ -484,7 +484,7 @@ async function Oe(e) {
|
|
|
484
484
|
return await createImageBitmap(e);
|
|
485
485
|
}
|
|
486
486
|
}
|
|
487
|
-
async function
|
|
487
|
+
async function je(e) {
|
|
488
488
|
try {
|
|
489
489
|
await e.applyConstraints({ advanced: [{ pointsOfInterest: [{
|
|
490
490
|
x: .5,
|
|
@@ -492,25 +492,25 @@ async function ke(e) {
|
|
|
492
492
|
}] }] }), await new Promise((e) => window.setTimeout(e, 180));
|
|
493
493
|
} catch {}
|
|
494
494
|
}
|
|
495
|
-
async function
|
|
496
|
-
let n = await
|
|
495
|
+
async function Me(e) {
|
|
496
|
+
let n = await Ae(e), r = Ee(n.width, n.height, De), i = document.createElement("canvas");
|
|
497
497
|
i.width = r.width, i.height = r.height;
|
|
498
498
|
let a = i.getContext("2d");
|
|
499
499
|
if (!a) throw n.close?.(), t();
|
|
500
500
|
return a.imageSmoothingEnabled = r.width !== n.width || r.height !== n.height, a.imageSmoothingQuality = "high", a.drawImage(n, 0, 0, i.width, i.height), n.close?.(), i;
|
|
501
501
|
}
|
|
502
|
-
async function
|
|
502
|
+
async function Ne(e) {
|
|
503
503
|
let t = globalThis.ImageCapture;
|
|
504
504
|
if (!t) return;
|
|
505
|
-
await
|
|
506
|
-
let n = new t(e), r = n.getPhotoCapabilities ? await n.getPhotoCapabilities() : void 0, i =
|
|
505
|
+
await je(e);
|
|
506
|
+
let n = new t(e), r = n.getPhotoCapabilities ? await n.getPhotoCapabilities() : void 0, i = pe(r), a;
|
|
507
507
|
try {
|
|
508
508
|
a = await n.takePhoto(i);
|
|
509
509
|
} catch {
|
|
510
510
|
a = await n.takePhoto();
|
|
511
511
|
}
|
|
512
512
|
return {
|
|
513
|
-
frame: await
|
|
513
|
+
frame: await Me(a),
|
|
514
514
|
requested: i,
|
|
515
515
|
photoMax: {
|
|
516
516
|
width: r?.imageWidth?.max,
|
|
@@ -518,42 +518,42 @@ async function je(e) {
|
|
|
518
518
|
}
|
|
519
519
|
};
|
|
520
520
|
}
|
|
521
|
-
function
|
|
521
|
+
function j(e, n) {
|
|
522
522
|
if (!e.videoWidth || !e.videoHeight) throw Error("The camera is not ready to capture a frame.");
|
|
523
|
-
let r =
|
|
523
|
+
let r = Ee(e.videoWidth, e.videoHeight, n), i = document.createElement("canvas");
|
|
524
524
|
i.width = r.width, i.height = r.height;
|
|
525
525
|
let a = i.getContext("2d");
|
|
526
526
|
if (!a) throw t();
|
|
527
527
|
return a.drawImage(e, 0, 0, i.width, i.height), i;
|
|
528
528
|
}
|
|
529
|
-
function
|
|
529
|
+
function Pe(e) {
|
|
530
530
|
let t = k();
|
|
531
|
-
return e.idealWidth || e.idealHeight || e.maxWidth || e.maxHeight ? [
|
|
532
|
-
|
|
531
|
+
return e.idealWidth || e.idealHeight || e.maxWidth || e.maxHeight ? [A(e, t)] : [
|
|
532
|
+
A({
|
|
533
533
|
...e,
|
|
534
534
|
idealWidth: 3840,
|
|
535
535
|
idealHeight: 2160
|
|
536
536
|
}, t),
|
|
537
|
-
|
|
537
|
+
A({
|
|
538
538
|
...e,
|
|
539
539
|
idealWidth: 2560,
|
|
540
540
|
idealHeight: 1440
|
|
541
541
|
}, t),
|
|
542
|
-
|
|
542
|
+
A({
|
|
543
543
|
...e,
|
|
544
544
|
idealWidth: 1920,
|
|
545
545
|
idealHeight: 1080
|
|
546
546
|
}, t)
|
|
547
547
|
];
|
|
548
548
|
}
|
|
549
|
-
async function
|
|
549
|
+
async function Fe(t, n = {}) {
|
|
550
550
|
await x("scan");
|
|
551
551
|
let r = n.torch ?? "alwaysOff";
|
|
552
552
|
if (r !== "alwaysOff" && await x("torch"), !window.isSecureContext && location.hostname !== "localhost") throw new e("secure-context", "Camera access requires HTTPS.");
|
|
553
553
|
if (!navigator.mediaDevices?.getUserMedia) throw Error("Live camera access is unavailable. Use the native camera picker instead.");
|
|
554
554
|
t.muted = !0, t.autoplay = !0, t.playsInline = !0, t.setAttribute("playsinline", "");
|
|
555
555
|
let i, a;
|
|
556
|
-
for (let e of
|
|
556
|
+
for (let e of Pe(n)) try {
|
|
557
557
|
i = await navigator.mediaDevices.getUserMedia(e);
|
|
558
558
|
break;
|
|
559
559
|
} catch (e) {
|
|
@@ -566,8 +566,8 @@ async function Ne(t, n = {}) {
|
|
|
566
566
|
for (let e of i.getTracks()) e.stop();
|
|
567
567
|
throw Error("The camera did not provide a video track.");
|
|
568
568
|
}
|
|
569
|
-
await
|
|
570
|
-
let s =
|
|
569
|
+
await ke(o);
|
|
570
|
+
let s = Ce(t), c = "ImageCapture" in globalThis, l = ve(r, (typeof o.getCapabilities == "function" ? o.getCapabilities() : void 0)?.torch === !0), u = !1, d = async (e) => {
|
|
571
571
|
if (!l.supported || o.readyState !== "live") return !1;
|
|
572
572
|
try {
|
|
573
573
|
return await o.applyConstraints({ advanced: [{ torch: e }] }), l = {
|
|
@@ -585,7 +585,7 @@ async function Ne(t, n = {}) {
|
|
|
585
585
|
}
|
|
586
586
|
};
|
|
587
587
|
l.on && await d(!0);
|
|
588
|
-
let f = r === "auto" && l.supported ? new
|
|
588
|
+
let f = r === "auto" && l.supported ? new _e() : void 0, p = f ? window.setInterval(() => {
|
|
589
589
|
if (u || !l.supported) return;
|
|
590
590
|
let e = f.update(s.getLiveLuminance());
|
|
591
591
|
e !== void 0 && e !== l.on && (u = !0, d(e).finally(() => {
|
|
@@ -625,17 +625,17 @@ async function Ne(t, n = {}) {
|
|
|
625
625
|
get torchOn() {
|
|
626
626
|
return l.on;
|
|
627
627
|
},
|
|
628
|
-
capture: (e) =>
|
|
628
|
+
capture: (e) => j(t, e),
|
|
629
629
|
async capturePhoto() {
|
|
630
630
|
let e, n = 0;
|
|
631
631
|
try {
|
|
632
|
-
e =
|
|
632
|
+
e = j(t), n = Se(e);
|
|
633
633
|
} catch {
|
|
634
634
|
e = void 0;
|
|
635
635
|
}
|
|
636
636
|
let r = s.getFrame(), i, a = !1, l = !1, u, d;
|
|
637
|
-
if (
|
|
638
|
-
let e = await
|
|
637
|
+
if (de(k(), c)) try {
|
|
638
|
+
let e = await Ne(o);
|
|
639
639
|
i = e?.frame, u = e?.requested, d = e?.photoMax;
|
|
640
640
|
} catch {
|
|
641
641
|
a = !0, i = void 0;
|
|
@@ -643,14 +643,14 @@ async function Ne(t, n = {}) {
|
|
|
643
643
|
let f = {
|
|
644
644
|
width: t.videoWidth,
|
|
645
645
|
height: t.videoHeight
|
|
646
|
-
}, p = i ?
|
|
646
|
+
}, p = i ? Se(i) : 0, h = !!(i && p > 10 && me(i, f));
|
|
647
647
|
if (i && p > 10 && !h && (l = !0), h && i) return console.info("[exige-scanner] capture", {
|
|
648
648
|
method: "image-capture",
|
|
649
649
|
frame: `${i.width}×${i.height}`,
|
|
650
650
|
video: `${t.videoWidth}×${t.videoHeight}`,
|
|
651
651
|
photoMax: d ? `${d.width ?? "—"}×${d.height ?? "—"}` : void 0,
|
|
652
652
|
photoRequest: u,
|
|
653
|
-
aspectMatch:
|
|
653
|
+
aspectMatch: he(i, f)
|
|
654
654
|
}), {
|
|
655
655
|
frame: i,
|
|
656
656
|
method: "image-capture",
|
|
@@ -658,7 +658,7 @@ async function Ne(t, n = {}) {
|
|
|
658
658
|
luminance: p,
|
|
659
659
|
diagnostics: m()
|
|
660
660
|
};
|
|
661
|
-
let g = e && n > 10 ? e : void 0, _ = g ?? (r ?
|
|
661
|
+
let g = e && n > 10 ? e : void 0, _ = g ?? (r ? we(r) : void 0);
|
|
662
662
|
if (!_) throw Error("The camera preview produced no visible pixels. Keep the scanner on screen, wait for the preview, and retake.");
|
|
663
663
|
let v = l ? "image-capture-preview-size" : i ? "image-capture-empty" : a ? "image-capture-failed" : g ? void 0 : "video-frame-empty";
|
|
664
664
|
return console.info("[exige-scanner] capture", {
|
|
@@ -690,13 +690,13 @@ async function Ne(t, n = {}) {
|
|
|
690
690
|
}
|
|
691
691
|
};
|
|
692
692
|
}
|
|
693
|
-
function
|
|
693
|
+
function Ie() {
|
|
694
694
|
let e = typeof navigator > "u" ? void 0 : navigator.userActivation;
|
|
695
695
|
return !e || e.isActive;
|
|
696
696
|
}
|
|
697
|
-
async function
|
|
697
|
+
async function Le() {
|
|
698
698
|
let e = document.createElement("input");
|
|
699
|
-
return e.type = "file", e.accept = "image/*", e.capture = "environment", e.setAttribute("capture", "environment"),
|
|
699
|
+
return e.type = "file", e.accept = "image/*", e.capture = "environment", e.setAttribute("capture", "environment"), Me(await new Promise((t, n) => {
|
|
700
700
|
e.addEventListener("change", () => {
|
|
701
701
|
let r = e.files?.[0];
|
|
702
702
|
r ? t(r) : n(/* @__PURE__ */ Error("No photo was selected."));
|
|
@@ -707,20 +707,20 @@ async function Fe() {
|
|
|
707
707
|
}
|
|
708
708
|
//#endregion
|
|
709
709
|
//#region src/sdk/ort-cdn.ts
|
|
710
|
-
var
|
|
711
|
-
`${
|
|
712
|
-
function
|
|
710
|
+
var Re = "1.30.0";
|
|
711
|
+
`${Re}`, `${Re}`;
|
|
712
|
+
function ze(e) {
|
|
713
713
|
return !e.ok && e.status !== 206 ? !1 : !(e.headers.get("content-type") ?? "").toLowerCase().includes("text/html");
|
|
714
714
|
}
|
|
715
|
-
async function
|
|
715
|
+
async function Be(e, t = fetch) {
|
|
716
716
|
if (!e) return !1;
|
|
717
717
|
try {
|
|
718
718
|
let n = await t(e, { method: "HEAD" });
|
|
719
|
-
if (
|
|
719
|
+
if (ze(n)) return !0;
|
|
720
720
|
if (n.status === 404 || n.status === 410) return !1;
|
|
721
721
|
} catch {}
|
|
722
722
|
try {
|
|
723
|
-
return
|
|
723
|
+
return ze(await t(e, {
|
|
724
724
|
method: "GET",
|
|
725
725
|
headers: { Range: "bytes=0-63" }
|
|
726
726
|
}));
|
|
@@ -730,29 +730,29 @@ async function Re(e, t = fetch) {
|
|
|
730
730
|
}
|
|
731
731
|
//#endregion
|
|
732
732
|
//#region src/sdk/ort-runtime.ts
|
|
733
|
-
var
|
|
734
|
-
function
|
|
733
|
+
var Ve = new URL("./assets/ort-wasm-simd-threaded.jsep.wasm", import.meta.url), He = new URL("./assets/ort-wasm-simd-threaded.jsep.mjs", import.meta.url);
|
|
734
|
+
function Ue() {
|
|
735
735
|
return {
|
|
736
|
-
wasm:
|
|
737
|
-
mjs:
|
|
736
|
+
wasm: Ve.href,
|
|
737
|
+
mjs: He.href
|
|
738
738
|
};
|
|
739
739
|
}
|
|
740
|
-
function
|
|
741
|
-
return typeof e == "string" ? e.trim() ||
|
|
740
|
+
function We(e) {
|
|
741
|
+
return typeof e == "string" ? e.trim() || Ue() : e?.wasm.trim() && e.mjs.trim() ? {
|
|
742
742
|
wasm: e.wasm.trim(),
|
|
743
743
|
mjs: e.mjs.trim()
|
|
744
|
-
} :
|
|
744
|
+
} : Ue();
|
|
745
745
|
}
|
|
746
746
|
//#endregion
|
|
747
747
|
//#region src/sdk/image.ts
|
|
748
|
-
function
|
|
748
|
+
function Ge(e, t, n) {
|
|
749
749
|
let r = n ? Math.min(1, n / Math.max(e, t)) : 1;
|
|
750
750
|
return {
|
|
751
751
|
width: Math.max(1, Math.round(e * r)),
|
|
752
752
|
height: Math.max(1, Math.round(t * r))
|
|
753
753
|
};
|
|
754
754
|
}
|
|
755
|
-
async function
|
|
755
|
+
async function Ke(e) {
|
|
756
756
|
let t = URL.createObjectURL(e);
|
|
757
757
|
try {
|
|
758
758
|
let e = new Image();
|
|
@@ -761,26 +761,26 @@ async function We(e) {
|
|
|
761
761
|
URL.revokeObjectURL(t);
|
|
762
762
|
}
|
|
763
763
|
}
|
|
764
|
-
async function
|
|
764
|
+
async function M(e, n = {}) {
|
|
765
765
|
if (e instanceof HTMLCanvasElement && n.cloneCanvas === !1 && !n.maxDimension) return e;
|
|
766
766
|
let r = document.createElement("canvas"), i = r.getContext("2d", { willReadFrequently: !0 });
|
|
767
767
|
if (!i) throw t();
|
|
768
768
|
if (e instanceof Blob) {
|
|
769
769
|
if ("createImageBitmap" in window) try {
|
|
770
|
-
let t = await createImageBitmap(e), a =
|
|
770
|
+
let t = await createImageBitmap(e), a = Ge(t.width, t.height, n.maxDimension);
|
|
771
771
|
return r.width = a.width, r.height = a.height, i.drawImage(t, 0, 0, a.width, a.height), t.close(), r;
|
|
772
772
|
} catch {}
|
|
773
|
-
e = await
|
|
773
|
+
e = await Ke(e);
|
|
774
774
|
}
|
|
775
775
|
let a = e instanceof HTMLImageElement ? e.naturalWidth : e.width, o = e instanceof HTMLImageElement ? e.naturalHeight : e.height;
|
|
776
776
|
if (!a || !o) throw Error("The image has no readable dimensions.");
|
|
777
|
-
let s =
|
|
777
|
+
let s = Ge(a, o, n.maxDimension);
|
|
778
778
|
return r.width = s.width, r.height = s.height, i.drawImage(e, 0, 0, s.width, s.height), r;
|
|
779
779
|
}
|
|
780
|
-
function
|
|
780
|
+
function qe(e, t = "image/png", n = .92) {
|
|
781
781
|
return new Promise((r, i) => e.toBlob((e) => e ? r(e) : i(/* @__PURE__ */ Error("Could not encode the image.")), t, n));
|
|
782
782
|
}
|
|
783
|
-
function
|
|
783
|
+
function Je(e, t, n) {
|
|
784
784
|
let r = Math.max(0, Math.min(t, e.x)), i = Math.max(0, Math.min(n, e.y));
|
|
785
785
|
return {
|
|
786
786
|
x: r,
|
|
@@ -791,20 +791,20 @@ function Ke(e, t, n) {
|
|
|
791
791
|
}
|
|
792
792
|
//#endregion
|
|
793
793
|
//#region src/sdk/scan.ts
|
|
794
|
-
var
|
|
795
|
-
function
|
|
794
|
+
var Ye = "https://exige-scanner-sdk.vercel.app/models/docaligner-lcnet100-f4117b78.onnx", Xe = 1280;
|
|
795
|
+
function Ze(e, t, n) {
|
|
796
796
|
if (n) return n;
|
|
797
|
-
let r = Math.max(e, t), i = r / Math.max(1, Math.min(e, t)), a =
|
|
798
|
-
return i >= 1.6 ? Math.min(r, Math.max(a,
|
|
797
|
+
let r = Math.max(e, t), i = r / Math.max(1, Math.min(e, t)), a = rt() ? 560 : 900;
|
|
798
|
+
return i >= 1.6 ? Math.min(r, Math.max(a, Xe)) : a;
|
|
799
799
|
}
|
|
800
|
-
function
|
|
800
|
+
function Qe(e) {
|
|
801
801
|
return e?.trim() || "https://exige-scanner-sdk.vercel.app/models/docaligner-lcnet100-f4117b78.onnx";
|
|
802
802
|
}
|
|
803
|
-
var
|
|
804
|
-
function
|
|
803
|
+
var $e = 3, N, et = 0, P = /* @__PURE__ */ new Map();
|
|
804
|
+
function F(e, t) {
|
|
805
805
|
return Math.hypot(e.x - t.x, e.y - t.y);
|
|
806
806
|
}
|
|
807
|
-
function
|
|
807
|
+
function tt(e) {
|
|
808
808
|
return {
|
|
809
809
|
...e,
|
|
810
810
|
edges: {
|
|
@@ -827,7 +827,7 @@ function $e(e) {
|
|
|
827
827
|
}
|
|
828
828
|
};
|
|
829
829
|
}
|
|
830
|
-
function
|
|
830
|
+
function nt(e, t) {
|
|
831
831
|
let n = (e) => ({
|
|
832
832
|
x: e.x / t,
|
|
833
833
|
y: e.y / t
|
|
@@ -839,43 +839,43 @@ function et(e, t) {
|
|
|
839
839
|
bottomLeft: n(e.bottomLeft)
|
|
840
840
|
};
|
|
841
841
|
}
|
|
842
|
-
function
|
|
842
|
+
function rt() {
|
|
843
843
|
return typeof navigator > "u" ? !1 : navigator.maxTouchPoints > 0 || navigator.hardwareConcurrency <= 4 || typeof matchMedia == "function" && matchMedia("(pointer: coarse)").matches;
|
|
844
844
|
}
|
|
845
|
-
function
|
|
845
|
+
function it(t, n, r, i) {
|
|
846
846
|
return new Promise((a, o) => {
|
|
847
|
-
|
|
847
|
+
N || (N = new Worker(new URL("./assets/document-worker.js", import.meta.url), { type: "module" }), N.onmessage = (t) => {
|
|
848
848
|
if (t.data.download?.url) {
|
|
849
849
|
O(t.data.download.url, t.data.download);
|
|
850
850
|
return;
|
|
851
851
|
}
|
|
852
|
-
let n =
|
|
853
|
-
n && (
|
|
854
|
-
},
|
|
852
|
+
let n = P.get(t.data.id);
|
|
853
|
+
n && (P.delete(t.data.id), t.data.error ? n.reject(t.data.errorCode ? new e(t.data.errorCode, t.data.error) : Error(t.data.error)) : t.data.result ? n.resolve(t.data.result) : n.reject(/* @__PURE__ */ Error("The document worker returned no result.")));
|
|
854
|
+
}, N.onerror = () => {
|
|
855
855
|
let t = new e("worker", "The document worker could not start.");
|
|
856
|
-
for (let e of
|
|
857
|
-
|
|
856
|
+
for (let e of P.values()) e.reject(t);
|
|
857
|
+
P.clear(), N?.terminate(), N = void 0;
|
|
858
858
|
});
|
|
859
|
-
let s = ++
|
|
860
|
-
|
|
859
|
+
let s = ++et;
|
|
860
|
+
P.set(s, {
|
|
861
861
|
resolve: a,
|
|
862
862
|
reject: o
|
|
863
863
|
});
|
|
864
864
|
let c = t.slice().buffer;
|
|
865
|
-
|
|
865
|
+
N.postMessage({
|
|
866
866
|
id: s,
|
|
867
867
|
pixels: c,
|
|
868
868
|
width: n,
|
|
869
869
|
height: r,
|
|
870
|
-
modelUrl:
|
|
870
|
+
modelUrl: Qe(i.modelUrl),
|
|
871
871
|
heatmapThreshold: i.heatmapThreshold,
|
|
872
872
|
cacheModel: i.cacheModel,
|
|
873
|
-
ortWasmPaths:
|
|
874
|
-
preferWebGpu: i.preferWebGpu ??
|
|
873
|
+
ortWasmPaths: We(i.ortWasmPaths),
|
|
874
|
+
preferWebGpu: i.preferWebGpu ?? le()
|
|
875
875
|
}, [c]);
|
|
876
876
|
});
|
|
877
877
|
}
|
|
878
|
-
async function
|
|
878
|
+
async function at(n, r) {
|
|
879
879
|
let { width: i, height: a } = n, o = r.minDimension ?? 360;
|
|
880
880
|
if (Math.min(i, a) < o) return {
|
|
881
881
|
status: "low-quality",
|
|
@@ -884,7 +884,7 @@ async function rt(n, r) {
|
|
|
884
884
|
sourceWidth: i,
|
|
885
885
|
sourceHeight: a
|
|
886
886
|
};
|
|
887
|
-
let s =
|
|
887
|
+
let s = Ze(i, a, r.maxAnalysisDimension), c = Math.min(1, s / Math.max(i, a)), l = Math.max(1, Math.round(i * c)), u = Math.max(1, Math.round(a * c)), d;
|
|
888
888
|
if (c === 1) {
|
|
889
889
|
let e = n.getContext("2d", { willReadFrequently: !0 });
|
|
890
890
|
if (!e) throw t();
|
|
@@ -898,7 +898,7 @@ async function rt(n, r) {
|
|
|
898
898
|
}
|
|
899
899
|
let f;
|
|
900
900
|
if (r.useWorker !== !1 && typeof Worker < "u") try {
|
|
901
|
-
f = await
|
|
901
|
+
f = await it(d, l, u, r);
|
|
902
902
|
} catch (t) {
|
|
903
903
|
if (t instanceof e && (t.code === "worker" || t.code === "model-http")) throw t;
|
|
904
904
|
f = {
|
|
@@ -922,7 +922,7 @@ async function rt(n, r) {
|
|
|
922
922
|
modelNote: y,
|
|
923
923
|
inferenceMs: b
|
|
924
924
|
};
|
|
925
|
-
if (p <
|
|
925
|
+
if (p < $e) return {
|
|
926
926
|
status: "low-quality",
|
|
927
927
|
confidence: Math.min(.3, p / 18),
|
|
928
928
|
message: "The image is too soft or dark to resolve four document edges.",
|
|
@@ -938,7 +938,7 @@ async function rt(n, r) {
|
|
|
938
938
|
sourceHeight: a,
|
|
939
939
|
...x
|
|
940
940
|
};
|
|
941
|
-
let S =
|
|
941
|
+
let S = nt(m.corners, c), C = tt(S), w = r.minConfidence ?? .58;
|
|
942
942
|
return m.confidence < w ? {
|
|
943
943
|
status: "low-confidence",
|
|
944
944
|
quad: C,
|
|
@@ -959,14 +959,14 @@ async function rt(n, r) {
|
|
|
959
959
|
...x
|
|
960
960
|
};
|
|
961
961
|
}
|
|
962
|
-
function
|
|
963
|
-
let n = Math.max(1, Math.round(Math.max(
|
|
962
|
+
function ot(e, t) {
|
|
963
|
+
let n = Math.max(1, Math.round(Math.max(F(e.topLeft, e.topRight), F(e.bottomLeft, e.bottomRight)))), r = Math.max(1, Math.round(Math.max(F(e.topLeft, e.bottomLeft), F(e.topRight, e.bottomRight)))), i = Math.min(1, t / Math.max(n, r));
|
|
964
964
|
return {
|
|
965
965
|
width: Math.max(1, Math.round(n * i)),
|
|
966
966
|
height: Math.max(1, Math.round(r * i))
|
|
967
967
|
};
|
|
968
968
|
}
|
|
969
|
-
function
|
|
969
|
+
function st(e, t, n, r, i) {
|
|
970
970
|
let a = Math.max(0, Math.min(t - 1, r)), o = Math.max(0, Math.min(n - 1, i)), s = Math.floor(a), c = Math.floor(o), l = Math.min(t - 1, s + 1), u = Math.min(n - 1, c + 1), d = a - s, f = o - c, p = c * t, m = u * t, h = (t) => {
|
|
971
971
|
let n = e[(p + s) * 4 + t] * (1 - d) + e[(p + l) * 4 + t] * d, r = e[(m + s) * 4 + t] * (1 - d) + e[(m + l) * 4 + t] * d;
|
|
972
972
|
return Math.round(n * (1 - f) + r * f);
|
|
@@ -978,8 +978,8 @@ function at(e, t, n, r, i) {
|
|
|
978
978
|
255
|
|
979
979
|
];
|
|
980
980
|
}
|
|
981
|
-
function
|
|
982
|
-
let { width: i, height: a } =
|
|
981
|
+
function ct(e, n, r) {
|
|
982
|
+
let { width: i, height: a } = ot(n, r), o = e.getContext("2d", { willReadFrequently: !0 });
|
|
983
983
|
if (!o) throw t();
|
|
984
984
|
let s = o.getImageData(0, 0, e.width, e.height), c = document.createElement("canvas");
|
|
985
985
|
c.width = i, c.height = a;
|
|
@@ -989,58 +989,58 @@ function ot(e, n, r) {
|
|
|
989
989
|
for (let t = 0; t < a; t += 1) {
|
|
990
990
|
let n = t / Math.max(1, a - 1);
|
|
991
991
|
for (let r = 0; r < i; r += 1) {
|
|
992
|
-
let a = r / Math.max(1, i - 1), o = S * a + C * n + 1, c = (w * a + T * n + d.x) / o, l = (E * a + D * n + d.y) / o, [f, p, m, h] =
|
|
992
|
+
let a = r / Math.max(1, i - 1), o = S * a + C * n + 1, c = (w * a + T * n + d.x) / o, l = (E * a + D * n + d.y) / o, [f, p, m, h] = st(s.data, e.width, e.height, c, l), g = (t * i + r) * 4;
|
|
993
993
|
u.data[g] = f, u.data[g + 1] = p, u.data[g + 2] = m, u.data[g + 3] = h;
|
|
994
994
|
}
|
|
995
995
|
}
|
|
996
996
|
return l.putImageData(u, 0, 0), c;
|
|
997
997
|
}
|
|
998
|
-
async function
|
|
999
|
-
return await x("scan"),
|
|
998
|
+
async function lt(e, t = {}) {
|
|
999
|
+
return await x("scan"), at(await M(e, { cloneCanvas: !1 }), t);
|
|
1000
1000
|
}
|
|
1001
|
-
async function
|
|
1001
|
+
async function ut(e, t, n = {}) {
|
|
1002
1002
|
await x("scan");
|
|
1003
|
-
let r = await
|
|
1003
|
+
let r = await M(e, { cloneCanvas: !1 }), i = n.maxOutputDimension ?? 4096;
|
|
1004
1004
|
return {
|
|
1005
1005
|
status: "success",
|
|
1006
1006
|
corners: t,
|
|
1007
|
-
quad:
|
|
1007
|
+
quad: tt(t),
|
|
1008
1008
|
confidence: 1,
|
|
1009
1009
|
message: "Captured with the document edges shown in the finder.",
|
|
1010
1010
|
sourceWidth: r.width,
|
|
1011
1011
|
sourceHeight: r.height,
|
|
1012
|
-
canvas:
|
|
1012
|
+
canvas: ct(r, t, i)
|
|
1013
1013
|
};
|
|
1014
1014
|
}
|
|
1015
|
-
async function
|
|
1015
|
+
async function I(e, t = {}) {
|
|
1016
1016
|
await x("scan");
|
|
1017
|
-
let n = await
|
|
1017
|
+
let n = await M(e, { cloneCanvas: !1 }), r = await at(n, t);
|
|
1018
1018
|
if (r.status !== "success" || !r.corners) return r;
|
|
1019
1019
|
let i = t.maxOutputDimension ?? 4096;
|
|
1020
1020
|
return {
|
|
1021
1021
|
...r,
|
|
1022
|
-
canvas:
|
|
1022
|
+
canvas: ct(n, r.corners, i),
|
|
1023
1023
|
message: "Four document edges detected and perspective-corrected."
|
|
1024
1024
|
};
|
|
1025
1025
|
}
|
|
1026
|
-
function
|
|
1026
|
+
function dt(e) {
|
|
1027
1027
|
return e.status === "success" ? e.message : e.status === "low-quality" ? e.message.includes("shortest side") ? `${e.message} Take another photo.` : "That photo is too soft or dark to find a document. Take another photo in better light." : e.status === "low-confidence" ? "The page edges were not clear enough to crop. Take another photo with the whole page in frame." : `No document was found in that photo. Take another photo with the whole page in frame.${e.modelStatus === "failed" && e.modelError ? ` (${e.modelError})` : ""}`;
|
|
1028
1028
|
}
|
|
1029
|
-
async function
|
|
1030
|
-
let n = await
|
|
1029
|
+
async function ft(e, t = {}) {
|
|
1030
|
+
let n = await I(e, t);
|
|
1031
1031
|
return n.status === "success" ? n : {
|
|
1032
1032
|
...n,
|
|
1033
|
-
message:
|
|
1033
|
+
message: dt(n)
|
|
1034
1034
|
};
|
|
1035
1035
|
}
|
|
1036
1036
|
//#endregion
|
|
1037
1037
|
//#region src/sdk/lighting.ts
|
|
1038
|
-
function
|
|
1038
|
+
function pt(e, t) {
|
|
1039
1039
|
if (!e.length) return 0;
|
|
1040
1040
|
let n = [...e].sort((e, t) => e - t);
|
|
1041
1041
|
return n[Math.min(n.length - 1, Math.floor(n.length * t))];
|
|
1042
1042
|
}
|
|
1043
|
-
function
|
|
1043
|
+
function mt(e, t, n, r = 12) {
|
|
1044
1044
|
if (!t || !n || e.length < t * n) return {
|
|
1045
1045
|
strong: !1,
|
|
1046
1046
|
strength: 0,
|
|
@@ -1063,7 +1063,7 @@ function ft(e, t, n, r = 12) {
|
|
|
1063
1063
|
});
|
|
1064
1064
|
}
|
|
1065
1065
|
}
|
|
1066
|
-
let s =
|
|
1066
|
+
let s = pt(o.map((e) => e.mean), .8), c = o.map((e) => s - e.mean >= 24 && e.mean >= 35), l = new Uint8Array(o.length), u = [];
|
|
1067
1067
|
for (let e = 0; e < o.length; e += 1) {
|
|
1068
1068
|
if (!c[e] || l[e]) continue;
|
|
1069
1069
|
let t = [], n = [e];
|
|
@@ -1111,11 +1111,11 @@ function ft(e, t, n, r = 12) {
|
|
|
1111
1111
|
}
|
|
1112
1112
|
return d;
|
|
1113
1113
|
}
|
|
1114
|
-
function
|
|
1114
|
+
function ht(e, t, n, r, i, a, o) {
|
|
1115
1115
|
let s = Math.max(0, a - o), c = Math.min(r, a + o + 1), l = Math.max(0, i - o), u = Math.min(n, i + o + 1), d = Math.max(1, (u - l) * (c - s));
|
|
1116
1116
|
return (e[c * t + u] - e[s * t + u] - e[c * t + l] + e[s * t + l]) / d;
|
|
1117
1117
|
}
|
|
1118
|
-
function
|
|
1118
|
+
function gt(e, t, n) {
|
|
1119
1119
|
let r = t + 1, i = new Uint32Array((t + 1) * (n + 1));
|
|
1120
1120
|
for (let a = 1; a <= n; a += 1) {
|
|
1121
1121
|
let n = 0;
|
|
@@ -1126,23 +1126,23 @@ function mt(e, t, n) {
|
|
|
1126
1126
|
stride: r
|
|
1127
1127
|
};
|
|
1128
1128
|
}
|
|
1129
|
-
function
|
|
1130
|
-
let { integral: i, stride: a } =
|
|
1129
|
+
function _t(e, t, n, r = Math.max(12, Math.round(Math.max(t, n) / 32))) {
|
|
1130
|
+
let { integral: i, stride: a } = gt(e, t, n), o = new Uint8Array(e.length);
|
|
1131
1131
|
for (let s = 0; s < n; s += 1) for (let c = 0; c < t; c += 1) {
|
|
1132
|
-
let l =
|
|
1132
|
+
let l = ht(i, a, t, n, c, s, r);
|
|
1133
1133
|
o[s * t + c] = Math.max(0, Math.min(255, Math.round(e[s * t + c] * 235 / Math.max(24, l))));
|
|
1134
1134
|
}
|
|
1135
1135
|
return o;
|
|
1136
1136
|
}
|
|
1137
|
-
function
|
|
1138
|
-
let { integral: a, stride: o } =
|
|
1137
|
+
function vt(e, t, n, r = Math.max(8, Math.round(Math.max(t, n) / 64)), i = .12) {
|
|
1138
|
+
let { integral: a, stride: o } = gt(e, t, n), s = new Uint8Array(e.length), c = 1 - i;
|
|
1139
1139
|
for (let i = 0; i < n; i += 1) for (let l = 0; l < t; l += 1) {
|
|
1140
|
-
let u =
|
|
1140
|
+
let u = ht(a, o, t, n, l, i, r);
|
|
1141
1141
|
s[i * t + l] = e[i * t + l] < u * c ? 0 : 255;
|
|
1142
1142
|
}
|
|
1143
1143
|
return s;
|
|
1144
1144
|
}
|
|
1145
|
-
function
|
|
1145
|
+
function yt(e, t, n) {
|
|
1146
1146
|
let r = [
|
|
1147
1147
|
e.topLeft,
|
|
1148
1148
|
e.topRight,
|
|
@@ -1156,8 +1156,8 @@ function _t(e, t, n) {
|
|
|
1156
1156
|
height: s - a
|
|
1157
1157
|
};
|
|
1158
1158
|
}
|
|
1159
|
-
function
|
|
1160
|
-
let n =
|
|
1159
|
+
function bt(e, t) {
|
|
1160
|
+
let n = yt(t, e.width, e.height);
|
|
1161
1161
|
if (n.width <= 0 || n.height <= 0) return {
|
|
1162
1162
|
strong: !1,
|
|
1163
1163
|
strength: 0,
|
|
@@ -1176,26 +1176,26 @@ function vt(e, t) {
|
|
|
1176
1176
|
i.drawImage(e, n.left, n.top, n.width, n.height, 0, 0, r.width, r.height);
|
|
1177
1177
|
let a = i.getImageData(0, 0, r.width, r.height).data, o = new Uint8Array(r.width * r.height);
|
|
1178
1178
|
for (let e = 0, t = 0; e < o.length; e += 1, t += 4) o[e] = Math.round(a[t] * .299 + a[t + 1] * .587 + a[t + 2] * .114);
|
|
1179
|
-
return
|
|
1179
|
+
return mt(o, r.width, r.height);
|
|
1180
1180
|
}
|
|
1181
1181
|
//#endregion
|
|
1182
1182
|
//#region src/sdk/finder.ts
|
|
1183
|
-
function
|
|
1183
|
+
function xt(e, t) {
|
|
1184
1184
|
return t.castShadow && (e.reason === "hold-still" || e.reason === "ready") ? t.hint ?? e.hint : e.hint;
|
|
1185
1185
|
}
|
|
1186
|
-
function
|
|
1186
|
+
function St(e, t, n) {
|
|
1187
1187
|
if (n <= 0) return 0;
|
|
1188
1188
|
let r = n - (t - e);
|
|
1189
1189
|
return r <= 0 ? 0 : Math.max(1, Math.ceil(r / 1e3));
|
|
1190
1190
|
}
|
|
1191
|
-
function
|
|
1191
|
+
function Ct(e) {
|
|
1192
1192
|
return `Hold still for ${e}…`;
|
|
1193
1193
|
}
|
|
1194
|
-
async function
|
|
1194
|
+
async function wt(e, t) {
|
|
1195
1195
|
let n = await e();
|
|
1196
1196
|
return t(), n;
|
|
1197
1197
|
}
|
|
1198
|
-
function
|
|
1198
|
+
function Tt(e) {
|
|
1199
1199
|
return e === "alwaysOn" || e === "only" ? {
|
|
1200
1200
|
visible: !1,
|
|
1201
1201
|
checked: !0,
|
|
@@ -1210,7 +1210,7 @@ function Ct(e) {
|
|
|
1210
1210
|
mutable: !0
|
|
1211
1211
|
};
|
|
1212
1212
|
}
|
|
1213
|
-
function
|
|
1213
|
+
function L(e) {
|
|
1214
1214
|
return [
|
|
1215
1215
|
e.topLeft,
|
|
1216
1216
|
e.topRight,
|
|
@@ -1218,19 +1218,19 @@ function z(e) {
|
|
|
1218
1218
|
e.bottomLeft
|
|
1219
1219
|
];
|
|
1220
1220
|
}
|
|
1221
|
-
var
|
|
1222
|
-
function
|
|
1221
|
+
var Et = 3e3, Dt = 1600;
|
|
1222
|
+
function Ot(e = k()) {
|
|
1223
1223
|
return e.iosWebKit ? {
|
|
1224
1224
|
intervalMs: 70,
|
|
1225
1225
|
maxFrameDimension: 720,
|
|
1226
1226
|
maxAnalysisDimension: 720
|
|
1227
1227
|
} : {
|
|
1228
1228
|
intervalMs: 140,
|
|
1229
|
-
maxFrameDimension:
|
|
1229
|
+
maxFrameDimension: Dt,
|
|
1230
1230
|
maxAnalysisDimension: 520
|
|
1231
1231
|
};
|
|
1232
1232
|
}
|
|
1233
|
-
function
|
|
1233
|
+
function kt(e, t) {
|
|
1234
1234
|
let n = e.status === "success" && e.modelStatus !== "failed", r = {
|
|
1235
1235
|
status: e.status,
|
|
1236
1236
|
confidence: Number(e.confidence.toFixed(3)),
|
|
@@ -1253,7 +1253,7 @@ function Dt(e, t) {
|
|
|
1253
1253
|
detail: r
|
|
1254
1254
|
};
|
|
1255
1255
|
}
|
|
1256
|
-
function
|
|
1256
|
+
function At(e) {
|
|
1257
1257
|
let t = 0;
|
|
1258
1258
|
for (let n = 0; n < e.length; n += 1) {
|
|
1259
1259
|
let r = e[n], i = e[(n + 1) % e.length];
|
|
@@ -1261,42 +1261,42 @@ function Ot(e) {
|
|
|
1261
1261
|
}
|
|
1262
1262
|
return Math.abs(t) / 2;
|
|
1263
1263
|
}
|
|
1264
|
-
function
|
|
1264
|
+
function R(e, t) {
|
|
1265
1265
|
return Math.hypot(e.x - t.x, e.y - t.y);
|
|
1266
1266
|
}
|
|
1267
|
-
var
|
|
1267
|
+
var z = {
|
|
1268
1268
|
widthFill: 0,
|
|
1269
1269
|
heightFill: 0,
|
|
1270
1270
|
limitingFill: 0,
|
|
1271
1271
|
areaFill: 0,
|
|
1272
1272
|
aspectRatio: 1
|
|
1273
1273
|
};
|
|
1274
|
-
function
|
|
1275
|
-
let r =
|
|
1274
|
+
function jt(e, t, n) {
|
|
1275
|
+
let r = L(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(R(c, l), R(d, u)), p = Math.max(R(c, d), R(l, u));
|
|
1276
1276
|
return {
|
|
1277
1277
|
widthFill: o,
|
|
1278
1278
|
heightFill: s,
|
|
1279
1279
|
limitingFill: Math.max(o, s),
|
|
1280
|
-
areaFill:
|
|
1280
|
+
areaFill: At(r) / Math.max(1, t * n),
|
|
1281
1281
|
aspectRatio: Math.max(f, p) / Math.max(1, Math.min(f, p))
|
|
1282
1282
|
};
|
|
1283
1283
|
}
|
|
1284
|
-
function
|
|
1284
|
+
function Mt(e, t, n, r = {}) {
|
|
1285
1285
|
let i = t ? r.exitFillRatio ?? .64 : r.minFillRatio ?? .72, a = r.highAspectRatio ?? 2.2;
|
|
1286
1286
|
if (e.aspectRatio < a) return i;
|
|
1287
1287
|
let o = t ? r.highAspectExitFillRatio : r.highAspectFillRatio;
|
|
1288
1288
|
return Math.min(o ?? i + .08, 1 - n * 2);
|
|
1289
1289
|
}
|
|
1290
|
-
function
|
|
1290
|
+
function Nt(e, t, n = {}) {
|
|
1291
1291
|
let r = n.confidenceThreshold ?? .72;
|
|
1292
1292
|
if (e.status !== "success" || !e.quad || e.confidence < r || !e.sourceWidth || !e.sourceHeight) return {
|
|
1293
1293
|
hint: "Place the document in the frame",
|
|
1294
1294
|
reason: "place-document",
|
|
1295
1295
|
fillRatio: 0,
|
|
1296
|
-
fill:
|
|
1296
|
+
fill: z,
|
|
1297
1297
|
readyForAutoCapture: !1
|
|
1298
1298
|
};
|
|
1299
|
-
let i =
|
|
1299
|
+
let i = L(e.quad), a = jt(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;
|
|
1300
1300
|
if (i.some(({ x: t, y: n }) => t <= c || t >= e.sourceWidth - c || n <= l || n >= e.sourceHeight - l)) return {
|
|
1301
1301
|
hint: "Move farther away",
|
|
1302
1302
|
reason: "move-farther-away",
|
|
@@ -1304,14 +1304,14 @@ function jt(e, t, n = {}) {
|
|
|
1304
1304
|
fill: a,
|
|
1305
1305
|
readyForAutoCapture: !1
|
|
1306
1306
|
};
|
|
1307
|
-
let [u, d, f, p] = i, m =
|
|
1307
|
+
let [u, d, f, p] = i, m = R(u, d), h = R(d, f), g = R(f, p), _ = R(p, u);
|
|
1308
1308
|
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) ? {
|
|
1309
1309
|
hint: "Hold the camera straight",
|
|
1310
1310
|
reason: "straighten-camera",
|
|
1311
1311
|
fillRatio: o,
|
|
1312
1312
|
fill: a,
|
|
1313
1313
|
readyForAutoCapture: !1
|
|
1314
|
-
} : o <
|
|
1314
|
+
} : o < Mt(a, t.previouslyReady === !0, s, n) ? {
|
|
1315
1315
|
hint: "Move closer",
|
|
1316
1316
|
reason: "move-closer",
|
|
1317
1317
|
fillRatio: o,
|
|
@@ -1325,7 +1325,7 @@ function jt(e, t, n = {}) {
|
|
|
1325
1325
|
readyForAutoCapture: t.ready
|
|
1326
1326
|
};
|
|
1327
1327
|
}
|
|
1328
|
-
var
|
|
1328
|
+
var Pt = class {
|
|
1329
1329
|
previous;
|
|
1330
1330
|
count = 0;
|
|
1331
1331
|
ready = !1;
|
|
@@ -1342,8 +1342,8 @@ var Mt = class {
|
|
|
1342
1342
|
ready: !1,
|
|
1343
1343
|
movement: Infinity
|
|
1344
1344
|
};
|
|
1345
|
-
let t = Math.hypot(e.sourceWidth, e.sourceHeight), n = this.previous ? Math.max(...
|
|
1346
|
-
let r =
|
|
1345
|
+
let t = Math.hypot(e.sourceWidth, e.sourceHeight), n = this.previous ? Math.max(...L(e.quad).map((e, n) => {
|
|
1346
|
+
let r = L(this.previous)[n];
|
|
1347
1347
|
return Math.hypot(e.x - r.x, e.y - r.y) / Math.max(1, t);
|
|
1348
1348
|
})) : Infinity, r = this.options.exitCornerTolerance ?? Math.max(this.options.cornerTolerance, .036);
|
|
1349
1349
|
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, {
|
|
@@ -1353,14 +1353,14 @@ var Mt = class {
|
|
|
1353
1353
|
};
|
|
1354
1354
|
}
|
|
1355
1355
|
};
|
|
1356
|
-
function
|
|
1356
|
+
function Ft(e, n) {
|
|
1357
1357
|
let r = Math.min(1, n / Math.max(e.width, e.height)), i = document.createElement("canvas");
|
|
1358
1358
|
i.width = Math.max(1, Math.round(e.width * r)), i.height = Math.max(1, Math.round(e.height * r));
|
|
1359
1359
|
let a = i.getContext("2d");
|
|
1360
1360
|
if (!a) throw t();
|
|
1361
1361
|
return a.drawImage(e, 0, 0, i.width, i.height), i;
|
|
1362
1362
|
}
|
|
1363
|
-
function
|
|
1363
|
+
function It() {
|
|
1364
1364
|
let e = window.AudioContext ?? window.webkitAudioContext;
|
|
1365
1365
|
if (!e) return;
|
|
1366
1366
|
let t = new e(), n = Math.round(t.sampleRate * .09), r = t.createBuffer(1, n, t.sampleRate), i = r.getChannelData(0);
|
|
@@ -1371,29 +1371,29 @@ function Pt() {
|
|
|
1371
1371
|
let a = t.createBufferSource(), o = t.createBiquadFilter(), s = t.createGain();
|
|
1372
1372
|
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();
|
|
1373
1373
|
}
|
|
1374
|
-
async function
|
|
1374
|
+
async function Lt(e) {
|
|
1375
1375
|
let t = document.createElement("video");
|
|
1376
1376
|
return t.muted = !0, t.autoplay = !0, t.playsInline = !0, t.srcObject = e, await t.play(), t;
|
|
1377
1377
|
}
|
|
1378
|
-
async function
|
|
1378
|
+
async function Rt(t) {
|
|
1379
1379
|
await x("scan");
|
|
1380
|
-
let n =
|
|
1380
|
+
let n = Tt(t.autoCapture), r = t.holdStillMs ?? 3e3, i = new Pt({
|
|
1381
1381
|
stableFrames: t.stableFrames ?? 4,
|
|
1382
1382
|
confidenceThreshold: t.confidenceThreshold ?? .72,
|
|
1383
1383
|
cornerTolerance: t.cornerTolerance ?? .024,
|
|
1384
1384
|
exitCornerTolerance: t.exitCornerTolerance ?? .036
|
|
1385
|
-
}), a =
|
|
1385
|
+
}), a = Ot(), o = t.maxFrameDimension ?? a.maxFrameDimension, s = t.intervalMs ?? a.intervalMs, c = {
|
|
1386
1386
|
minDimension: 220,
|
|
1387
1387
|
maxAnalysisDimension: a.maxAnalysisDimension,
|
|
1388
1388
|
...t.detection
|
|
1389
|
-
}, l = typeof MediaStream < "u" && t.source instanceof MediaStream ? await
|
|
1389
|
+
}, l = typeof MediaStream < "u" && t.source instanceof MediaStream ? await Lt(t.source) : t.source, u = !0, d = !1, f = !1, p, m = 0, h, g = "", _ = 0, v = {
|
|
1390
1390
|
state: "detecting",
|
|
1391
1391
|
confidence: 0,
|
|
1392
1392
|
guidance: {
|
|
1393
1393
|
hint: "Place the document in the frame",
|
|
1394
1394
|
reason: "place-document",
|
|
1395
1395
|
fillRatio: 0,
|
|
1396
|
-
fill:
|
|
1396
|
+
fill: z,
|
|
1397
1397
|
readyForAutoCapture: !1
|
|
1398
1398
|
},
|
|
1399
1399
|
lighting: {
|
|
@@ -1403,10 +1403,10 @@ async function It(t) {
|
|
|
1403
1403
|
stableFrames: 0,
|
|
1404
1404
|
requiredStableFrames: t.stableFrames ?? 4,
|
|
1405
1405
|
autoCapture: { ...n }
|
|
1406
|
-
}, y = () => l instanceof HTMLCanvasElement ?
|
|
1406
|
+
}, y = () => l instanceof HTMLCanvasElement ? Ft(l, o) : j(l, o), b = (e) => {
|
|
1407
1407
|
v = e, t.onStatus?.(e);
|
|
1408
1408
|
}, S = (e) => {
|
|
1409
|
-
let t =
|
|
1409
|
+
let t = kt(e, l instanceof HTMLVideoElement ? {
|
|
1410
1410
|
width: l.videoWidth,
|
|
1411
1411
|
height: l.videoHeight
|
|
1412
1412
|
} : {
|
|
@@ -1421,11 +1421,11 @@ async function It(t) {
|
|
|
1421
1421
|
d = !0;
|
|
1422
1422
|
let n;
|
|
1423
1423
|
try {
|
|
1424
|
-
n = await
|
|
1424
|
+
n = await wt(t.captureFrame ?? y, () => {
|
|
1425
1425
|
b({
|
|
1426
1426
|
...v,
|
|
1427
1427
|
state: "captured"
|
|
1428
|
-
}), t.playShutterSound !== !1 &&
|
|
1428
|
+
}), t.playShutterSound !== !1 && It(), C();
|
|
1429
1429
|
});
|
|
1430
1430
|
} catch (e) {
|
|
1431
1431
|
throw d = !1, e instanceof Error ? e : /* @__PURE__ */ Error("The camera frame could not be captured.");
|
|
@@ -1439,9 +1439,9 @@ async function It(t) {
|
|
|
1439
1439
|
}, T = async () => {
|
|
1440
1440
|
if (u && !d) {
|
|
1441
1441
|
try {
|
|
1442
|
-
let e = y(), a = await
|
|
1442
|
+
let e = y(), a = await lt(e, c);
|
|
1443
1443
|
h = a, S(a);
|
|
1444
|
-
let o = a.quad ?
|
|
1444
|
+
let o = a.quad ? bt(e, a.quad) : {
|
|
1445
1445
|
strong: !1,
|
|
1446
1446
|
strength: 0
|
|
1447
1447
|
}, s = o.strong ? {
|
|
@@ -1451,7 +1451,7 @@ async function It(t) {
|
|
|
1451
1451
|
} : {
|
|
1452
1452
|
castShadow: !1,
|
|
1453
1453
|
strength: o.strength
|
|
1454
|
-
}, l = i.update(a), u =
|
|
1454
|
+
}, l = i.update(a), u = Nt(a, {
|
|
1455
1455
|
...l,
|
|
1456
1456
|
previouslyReady: f
|
|
1457
1457
|
}, {
|
|
@@ -1461,7 +1461,7 @@ async function It(t) {
|
|
|
1461
1461
|
f = u.readyForAutoCapture;
|
|
1462
1462
|
let d = performance.now();
|
|
1463
1463
|
u.readyForAutoCapture && n.checked ? p ??= d : p = void 0;
|
|
1464
|
-
let m = p === void 0 ? void 0 :
|
|
1464
|
+
let m = p === void 0 ? void 0 : St(p, d, r), g = a.status !== "success" || u.reason === "place-document" ? "seeking" : u.readyForAutoCapture ? "ready" : "unstable";
|
|
1465
1465
|
if (b({
|
|
1466
1466
|
state: g,
|
|
1467
1467
|
confidence: a.confidence,
|
|
@@ -1507,7 +1507,7 @@ async function It(t) {
|
|
|
1507
1507
|
hint: "Place the document in the frame",
|
|
1508
1508
|
reason: "place-document",
|
|
1509
1509
|
fillRatio: 0,
|
|
1510
|
-
fill:
|
|
1510
|
+
fill: z,
|
|
1511
1511
|
readyForAutoCapture: !1
|
|
1512
1512
|
},
|
|
1513
1513
|
lighting: {
|
|
@@ -1538,24 +1538,24 @@ async function It(t) {
|
|
|
1538
1538
|
}
|
|
1539
1539
|
//#endregion
|
|
1540
1540
|
//#region src/sdk/ocr-runtime.ts
|
|
1541
|
-
var
|
|
1542
|
-
function
|
|
1541
|
+
var zt = new URL("./assets/tesseract/worker.min.js", import.meta.url), Bt = new URL("./assets/tesseract/tesseract-core-lstm.wasm.js", import.meta.url), Vt = new URL("./assets/tesseract/tesseract-core-simd-lstm.wasm.js", import.meta.url), Ht = new URL("./assets/tesseract/tesseract-core-relaxedsimd-lstm.wasm.js", import.meta.url), Ut = new URL("./assets/tesseract/eng.traineddata.gz", import.meta.url), Wt = 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), Gt = 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);
|
|
1542
|
+
function Kt(e) {
|
|
1543
1543
|
try {
|
|
1544
1544
|
return typeof WebAssembly < "u" && WebAssembly.validate(e);
|
|
1545
1545
|
} catch {
|
|
1546
1546
|
return !1;
|
|
1547
1547
|
}
|
|
1548
1548
|
}
|
|
1549
|
-
function
|
|
1549
|
+
function qt() {
|
|
1550
1550
|
return {
|
|
1551
|
-
relaxedSimd: Wt
|
|
1552
|
-
simd:
|
|
1551
|
+
relaxedSimd: Kt(Wt),
|
|
1552
|
+
simd: Kt(Gt)
|
|
1553
1553
|
};
|
|
1554
1554
|
}
|
|
1555
|
-
function
|
|
1556
|
-
return e.relaxedSimd ?
|
|
1555
|
+
function Jt(e) {
|
|
1556
|
+
return e.relaxedSimd ? Ht : e.simd ? Vt : Bt;
|
|
1557
1557
|
}
|
|
1558
|
-
function
|
|
1558
|
+
function Yt(t, n) {
|
|
1559
1559
|
let r = t?.trim() || "eng", i = n?.trim() || "";
|
|
1560
1560
|
if (i) return {
|
|
1561
1561
|
kind: "lang-path",
|
|
@@ -1568,14 +1568,14 @@ function qt(t, n) {
|
|
|
1568
1568
|
};
|
|
1569
1569
|
throw new e("language", `OCR language "${r}" is not packaged. Pass langPath, a directory URL that contains ${r}.traineddata.gz.`);
|
|
1570
1570
|
}
|
|
1571
|
-
function
|
|
1571
|
+
function Xt(e = Ut) {
|
|
1572
1572
|
let t = e.href, n = t.lastIndexOf("/");
|
|
1573
1573
|
return n === -1 ? t : t.slice(0, n);
|
|
1574
1574
|
}
|
|
1575
|
-
function
|
|
1576
|
-
return e.kind === "bundled-eng" ?
|
|
1575
|
+
function Zt(e) {
|
|
1576
|
+
return e.kind === "bundled-eng" ? Xt() : e.langPath;
|
|
1577
1577
|
}
|
|
1578
|
-
async function
|
|
1578
|
+
async function Qt(t, n, r) {
|
|
1579
1579
|
return new Promise((i, a) => {
|
|
1580
1580
|
let o = !1, s = (t) => {
|
|
1581
1581
|
o || (o = !0, a(new e("worker", `OCR worker failed to start (${t instanceof Error ? t.message : String(t)}).`)));
|
|
@@ -1598,7 +1598,7 @@ async function Xt(t, n, r) {
|
|
|
1598
1598
|
}
|
|
1599
1599
|
//#endregion
|
|
1600
1600
|
//#region src/sdk/ocr.ts
|
|
1601
|
-
function
|
|
1601
|
+
function $t(e, t = 1, n = 1, r = 0, i = 0) {
|
|
1602
1602
|
return {
|
|
1603
1603
|
text: e.text,
|
|
1604
1604
|
confidence: Math.max(0, Math.min(1, e.confidence / 100)),
|
|
@@ -1610,20 +1610,20 @@ function Zt(e, t = 1, n = 1, r = 0, i = 0) {
|
|
|
1610
1610
|
}
|
|
1611
1611
|
};
|
|
1612
1612
|
}
|
|
1613
|
-
function
|
|
1613
|
+
function en(e = .5) {
|
|
1614
1614
|
if (!Number.isFinite(e) || e < 0 || e > 1) throw RangeError("OCR minConfidence must be between 0 and 1.");
|
|
1615
1615
|
return e;
|
|
1616
1616
|
}
|
|
1617
|
-
function
|
|
1617
|
+
function tn(e, t) {
|
|
1618
1618
|
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);
|
|
1619
1619
|
return s > 0 ? o / s : 0;
|
|
1620
1620
|
}
|
|
1621
|
-
function
|
|
1621
|
+
function nn(e) {
|
|
1622
1622
|
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 = [];
|
|
1623
|
-
for (let e of t) n.some((t) =>
|
|
1623
|
+
for (let e of t) n.some((t) => tn(t, e) >= .65) || n.push(e);
|
|
1624
1624
|
return n;
|
|
1625
1625
|
}
|
|
1626
|
-
function
|
|
1626
|
+
function rn(e, t, n, r, i) {
|
|
1627
1627
|
let a = e.text.trim();
|
|
1628
1628
|
if (!a || !/[\p{L}\p{N}]/u.test(a)) return !1;
|
|
1629
1629
|
let o = e.bbox.width * e.bbox.height / Math.max(1, n * r), s = e.bbox.width / Math.max(1, e.bbox.height);
|
|
@@ -1634,7 +1634,7 @@ function tn(e, t, n, r, i) {
|
|
|
1634
1634
|
}
|
|
1635
1635
|
return !0;
|
|
1636
1636
|
}
|
|
1637
|
-
function
|
|
1637
|
+
function an(e) {
|
|
1638
1638
|
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 = [];
|
|
1639
1639
|
for (let e of t) {
|
|
1640
1640
|
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);
|
|
@@ -1650,28 +1650,28 @@ function nn(e) {
|
|
|
1650
1650
|
}
|
|
1651
1651
|
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");
|
|
1652
1652
|
}
|
|
1653
|
-
function
|
|
1654
|
-
let i =
|
|
1653
|
+
function on(e, t, n, r) {
|
|
1654
|
+
let i = en(t.minConfidence), a = [], o = [], s = 1, c = 1;
|
|
1655
1655
|
for (let t of e) {
|
|
1656
1656
|
let e = t.scaleX ?? 1, n = t.scaleY ?? 1, r = t.offsetX ?? 0, l = t.offsetY ?? 0;
|
|
1657
1657
|
for (let u of t.blocks ?? []) for (let t of u.paragraphs) for (let u of t.lines) for (let t of u.words) {
|
|
1658
|
-
let u =
|
|
1658
|
+
let u = $t(t, e, n, r, l);
|
|
1659
1659
|
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);
|
|
1660
1660
|
for (let a of t.symbols) {
|
|
1661
|
-
let t =
|
|
1661
|
+
let t = $t(a, e, n, r, l);
|
|
1662
1662
|
t.confidence >= i && o.push(t);
|
|
1663
1663
|
}
|
|
1664
1664
|
}
|
|
1665
1665
|
}
|
|
1666
|
-
let l = n?.width ?? s, u = n?.height ?? c, d =
|
|
1666
|
+
let l = n?.width ?? s, u = n?.height ?? c, d = nn(a).filter((e) => rn(e, "word", l, u, r)), f = nn(o).filter((e) => rn(e, "character", l, u, r));
|
|
1667
1667
|
return {
|
|
1668
|
-
text:
|
|
1668
|
+
text: an(d),
|
|
1669
1669
|
confidence: d.length ? d.reduce((e, t) => e + t.confidence, 0) / d.length : 0,
|
|
1670
1670
|
words: t.includeWords ? d : [],
|
|
1671
1671
|
characters: t.includeCharacters ? f : []
|
|
1672
1672
|
};
|
|
1673
1673
|
}
|
|
1674
|
-
function
|
|
1674
|
+
function sn(e) {
|
|
1675
1675
|
let n = e.getContext("2d", { willReadFrequently: !0 });
|
|
1676
1676
|
if (!n) throw t();
|
|
1677
1677
|
let r = n.getImageData(0, 0, e.width, e.height), i = new Uint8Array(e.width * e.height);
|
|
@@ -1682,7 +1682,7 @@ function an(e) {
|
|
|
1682
1682
|
luminance: i
|
|
1683
1683
|
};
|
|
1684
1684
|
}
|
|
1685
|
-
function
|
|
1685
|
+
function cn(e) {
|
|
1686
1686
|
let t = document.createElement("canvas");
|
|
1687
1687
|
t.width = 72, t.height = 72;
|
|
1688
1688
|
let n = t.getContext("2d", { willReadFrequently: !0 });
|
|
@@ -1693,27 +1693,27 @@ function on(e) {
|
|
|
1693
1693
|
areaRatio: 0
|
|
1694
1694
|
};
|
|
1695
1695
|
n.drawImage(e, 0, 0, t.width, t.height);
|
|
1696
|
-
let { luminance: r } =
|
|
1697
|
-
return
|
|
1696
|
+
let { luminance: r } = sn(t);
|
|
1697
|
+
return mt(r, t.width, t.height);
|
|
1698
1698
|
}
|
|
1699
|
-
function
|
|
1699
|
+
function ln(e, t, n, r) {
|
|
1700
1700
|
let i = (e.bbox.x + e.bbox.width / 2) / n, a = (e.bbox.y + e.bbox.height / 2) / r;
|
|
1701
1701
|
return i >= t.x && i <= t.x + t.width && a >= t.y && a <= t.y + t.height;
|
|
1702
1702
|
}
|
|
1703
|
-
var
|
|
1704
|
-
function
|
|
1703
|
+
var un = .58;
|
|
1704
|
+
function dn(e) {
|
|
1705
1705
|
let t = e.trim();
|
|
1706
1706
|
if (!t || !/[\p{L}\p{N}]/u.test(t)) return 0;
|
|
1707
1707
|
if (/^\$?\d{1,5}([.,]\d{2})?$/.test(t)) return 1;
|
|
1708
1708
|
let n = t.replace(/[^\p{L}]/gu, "");
|
|
1709
1709
|
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;
|
|
1710
1710
|
}
|
|
1711
|
-
function
|
|
1711
|
+
function fn(e, t, n) {
|
|
1712
1712
|
let r = Math.max(0, Math.min(1, (1 - e.darkness / 80) * (1 - e.strength / 24)));
|
|
1713
1713
|
if (!t.length) return r * .35;
|
|
1714
1714
|
let i = 0;
|
|
1715
1715
|
for (let e of t) {
|
|
1716
|
-
let t =
|
|
1716
|
+
let t = dn(e.text);
|
|
1717
1717
|
if (n) {
|
|
1718
1718
|
let r = n(e.bbox);
|
|
1719
1719
|
(r < .04 || r > .62) && (t *= .4);
|
|
@@ -1722,10 +1722,10 @@ function un(e, t, n) {
|
|
|
1722
1722
|
}
|
|
1723
1723
|
return r * .7 + i / t.length * .3;
|
|
1724
1724
|
}
|
|
1725
|
-
function
|
|
1726
|
-
return !e.strong || !e.region ? !1 :
|
|
1725
|
+
function pn(e, t, n, r) {
|
|
1726
|
+
return !e.strong || !e.region ? !1 : fn(e, t.filter((t) => ln(t, e.region, n.width, n.height)), r) < un;
|
|
1727
1727
|
}
|
|
1728
|
-
function
|
|
1728
|
+
function mn(e, t, n, r) {
|
|
1729
1729
|
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");
|
|
1730
1730
|
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);
|
|
1731
1731
|
let l = n / e.width, u = r / e.height;
|
|
@@ -1739,26 +1739,26 @@ function fn(e, t, n, r) {
|
|
|
1739
1739
|
}
|
|
1740
1740
|
};
|
|
1741
1741
|
}
|
|
1742
|
-
function
|
|
1742
|
+
function hn(e, t) {
|
|
1743
1743
|
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;
|
|
1744
1744
|
}
|
|
1745
|
-
function
|
|
1745
|
+
function gn(e) {
|
|
1746
1746
|
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");
|
|
1747
1747
|
a.width = Math.max(1, Math.round(e.width * i)), a.height = Math.max(1, Math.round(e.height * i));
|
|
1748
1748
|
let o = a.getContext("2d", { willReadFrequently: !0 });
|
|
1749
1749
|
if (!o) throw t();
|
|
1750
1750
|
o.drawImage(e, 0, 0, a.width, a.height);
|
|
1751
|
-
let { image: s, luminance: c } =
|
|
1751
|
+
let { image: s, luminance: c } = sn(a), l = _t(c, a.width, a.height), u = vt(l, a.width, a.height), d = document.createElement("canvas");
|
|
1752
1752
|
d.width = a.width, d.height = a.height;
|
|
1753
1753
|
let f = d.getContext("2d", { willReadFrequently: !0 });
|
|
1754
1754
|
if (!f) throw t();
|
|
1755
1755
|
let p = f.createImageData(d.width, d.height);
|
|
1756
|
-
return
|
|
1756
|
+
return hn(p, l), f.putImageData(p, 0, 0), hn(s, u), o.putImageData(s, 0, 0), {
|
|
1757
1757
|
sparseCanvas: a,
|
|
1758
1758
|
flattenedCanvas: d
|
|
1759
1759
|
};
|
|
1760
1760
|
}
|
|
1761
|
-
function
|
|
1761
|
+
function _n(e) {
|
|
1762
1762
|
let t = document.createElement("canvas");
|
|
1763
1763
|
t.width = 24, t.height = 24;
|
|
1764
1764
|
let n = t.getContext("2d", { willReadFrequently: !0 });
|
|
@@ -1776,19 +1776,19 @@ function hn(e) {
|
|
|
1776
1776
|
return l / s.length;
|
|
1777
1777
|
};
|
|
1778
1778
|
}
|
|
1779
|
-
async function
|
|
1779
|
+
async function B(e, t = {}) {
|
|
1780
1780
|
await x("ocr");
|
|
1781
|
-
let n =
|
|
1782
|
-
|
|
1783
|
-
let i = await
|
|
1781
|
+
let n = Yt(t.language, t.langPath), r = n.language;
|
|
1782
|
+
en(t.minConfidence);
|
|
1783
|
+
let i = await M(e, { cloneCanvas: !1 }), { sparseCanvas: a, flattenedCanvas: o } = gn(i), s = t.shadowPass === !1 ? {
|
|
1784
1784
|
strong: !1,
|
|
1785
1785
|
strength: 0,
|
|
1786
1786
|
darkness: 0,
|
|
1787
1787
|
areaRatio: 0
|
|
1788
|
-
} :
|
|
1789
|
-
workerPath:
|
|
1790
|
-
corePath:
|
|
1791
|
-
langPath:
|
|
1788
|
+
} : cn(i), { createWorker: c, PSM: l } = await import("tesseract.js"), u = 0, d = s.strong ? 3 : 2, f = await Qt(c, r, {
|
|
1789
|
+
workerPath: zt.href,
|
|
1790
|
+
corePath: Jt(qt()).href,
|
|
1791
|
+
langPath: Zt(n),
|
|
1792
1792
|
logger(e) {
|
|
1793
1793
|
typeof e.progress == "number" && t.onProgress?.(Math.min(1, (u + e.progress) / d), e.status ?? "recognizing text");
|
|
1794
1794
|
}
|
|
@@ -1813,16 +1813,16 @@ async function H(e, t = {}) {
|
|
|
1813
1813
|
}], d = {
|
|
1814
1814
|
...t,
|
|
1815
1815
|
includeWords: !0
|
|
1816
|
-
}, p =
|
|
1816
|
+
}, p = _n(i), m = on(c, d, {
|
|
1817
1817
|
width: i.width,
|
|
1818
1818
|
height: i.height
|
|
1819
|
-
}, p), h = t.shadowPass !== !1 &&
|
|
1819
|
+
}, p), h = t.shadowPass !== !1 && pn(s, m.words, {
|
|
1820
1820
|
width: i.width,
|
|
1821
1821
|
height: i.height
|
|
1822
1822
|
}, p);
|
|
1823
1823
|
if (h && s.region) {
|
|
1824
1824
|
u = 2;
|
|
1825
|
-
let { tile: e, passMapping: t } =
|
|
1825
|
+
let { tile: e, passMapping: t } = mn(o, s.region, i.width, i.height);
|
|
1826
1826
|
await f.setParameters({
|
|
1827
1827
|
tessedit_pageseg_mode: l.SPARSE_TEXT,
|
|
1828
1828
|
preserve_interword_spaces: "1"
|
|
@@ -1836,7 +1836,7 @@ async function H(e, t = {}) {
|
|
|
1836
1836
|
...t
|
|
1837
1837
|
});
|
|
1838
1838
|
}
|
|
1839
|
-
let g = c.length === 2 ? m :
|
|
1839
|
+
let g = c.length === 2 ? m : on(c, d, {
|
|
1840
1840
|
width: i.width,
|
|
1841
1841
|
height: i.height
|
|
1842
1842
|
}, p);
|
|
@@ -1865,37 +1865,55 @@ async function H(e, t = {}) {
|
|
|
1865
1865
|
}
|
|
1866
1866
|
//#endregion
|
|
1867
1867
|
//#region src/sdk/zxing-runtime.ts
|
|
1868
|
-
var
|
|
1869
|
-
function
|
|
1868
|
+
var vn = new URL("./assets/zxing_reader.wasm", import.meta.url), yn = "3.1.6", bn = "zxing_reader.wasm", xn = `https://exige-scanner-sdk.vercel.app/zxing/${yn}/`, Sn = `https://cdn.jsdelivr.net/npm/zxing-wasm@${yn}/dist/reader/`;
|
|
1869
|
+
function Cn(e, t) {
|
|
1870
1870
|
return `${e.endsWith("/") ? e : `${e}/`}${t}`;
|
|
1871
1871
|
}
|
|
1872
|
-
function
|
|
1873
|
-
return
|
|
1872
|
+
function wn(e = xn) {
|
|
1873
|
+
return Cn(e, bn);
|
|
1874
1874
|
}
|
|
1875
|
-
function
|
|
1876
|
-
return
|
|
1875
|
+
function Tn() {
|
|
1876
|
+
return vn.href;
|
|
1877
1877
|
}
|
|
1878
|
-
var
|
|
1879
|
-
function
|
|
1878
|
+
var En, Dn;
|
|
1879
|
+
function On() {
|
|
1880
1880
|
return {
|
|
1881
|
-
binary:
|
|
1882
|
-
url:
|
|
1881
|
+
binary: En,
|
|
1882
|
+
url: Dn
|
|
1883
1883
|
};
|
|
1884
1884
|
}
|
|
1885
|
-
async function
|
|
1886
|
-
let t =
|
|
1887
|
-
if (await
|
|
1888
|
-
let n =
|
|
1889
|
-
return await
|
|
1885
|
+
async function kn(e = fetch) {
|
|
1886
|
+
let t = Tn();
|
|
1887
|
+
if (await Be(t, e)) return t;
|
|
1888
|
+
let n = wn(xn);
|
|
1889
|
+
return await Be(n, e) ? n : wn(Sn);
|
|
1890
1890
|
}
|
|
1891
1891
|
//#endregion
|
|
1892
1892
|
//#region src/sdk/barcode.ts
|
|
1893
|
-
|
|
1893
|
+
var V = 1600, An = [
|
|
1894
|
+
1600,
|
|
1895
|
+
1280,
|
|
1896
|
+
960,
|
|
1897
|
+
720,
|
|
1898
|
+
480
|
|
1899
|
+
], jn = [
|
|
1900
|
+
[.2, .8],
|
|
1901
|
+
[.32, .72],
|
|
1902
|
+
[.4, .86]
|
|
1903
|
+
];
|
|
1904
|
+
function Mn(e, t) {
|
|
1905
|
+
let n = Math.max(e, t);
|
|
1906
|
+
if (!Number.isFinite(n) || n < 1) return [];
|
|
1907
|
+
let r = Math.min(n, V), i = [r];
|
|
1908
|
+
for (let e of An) e <= r - 16 && i.push(e);
|
|
1909
|
+
return i;
|
|
1910
|
+
}
|
|
1911
|
+
function Nn() {
|
|
1894
1912
|
let e = globalThis.BarcodeDetector;
|
|
1895
1913
|
return typeof e == "function" ? e : void 0;
|
|
1896
1914
|
}
|
|
1897
|
-
async function
|
|
1898
|
-
let e =
|
|
1915
|
+
async function Pn() {
|
|
1916
|
+
let e = Nn();
|
|
1899
1917
|
if (!e?.getSupportedFormats) return !1;
|
|
1900
1918
|
try {
|
|
1901
1919
|
return (await e.getSupportedFormats()).some((e) => e.toLowerCase() === "pdf417");
|
|
@@ -1903,61 +1921,108 @@ async function kn() {
|
|
|
1903
1921
|
return !1;
|
|
1904
1922
|
}
|
|
1905
1923
|
}
|
|
1906
|
-
|
|
1907
|
-
let t = On();
|
|
1908
|
-
if (!t) return;
|
|
1909
|
-
let n = await new t({ formats: ["pdf417"] }).detect(e);
|
|
1910
|
-
return n.find((e) => {
|
|
1911
|
-
let t = e.format?.toLowerCase() ?? "";
|
|
1912
|
-
return (!t || t === "pdf417") && !!e.rawValue?.trim();
|
|
1913
|
-
})?.rawValue?.trim() || n.find((e) => e.rawValue?.trim())?.rawValue?.trim();
|
|
1914
|
-
}
|
|
1915
|
-
function jn(e) {
|
|
1924
|
+
function Fn(e) {
|
|
1916
1925
|
try {
|
|
1917
1926
|
return e.getContext("2d", { willReadFrequently: !0 })?.getImageData(0, 0, e.width, e.height);
|
|
1918
1927
|
} catch {
|
|
1919
1928
|
return;
|
|
1920
1929
|
}
|
|
1921
1930
|
}
|
|
1922
|
-
async function
|
|
1931
|
+
async function In(e) {
|
|
1923
1932
|
let t = [];
|
|
1924
1933
|
if (e instanceof Blob && t.push(e), e instanceof HTMLCanvasElement) {
|
|
1925
|
-
let n =
|
|
1934
|
+
let n = Fn(e);
|
|
1926
1935
|
n && t.push(n);
|
|
1927
1936
|
try {
|
|
1928
|
-
t.push(await
|
|
1937
|
+
t.push(await qe(e, "image/png"));
|
|
1929
1938
|
} catch {}
|
|
1930
1939
|
} else if (!(e instanceof Blob)) try {
|
|
1931
|
-
let n =
|
|
1940
|
+
let n = Fn(await M(e, { cloneCanvas: !1 }));
|
|
1932
1941
|
n && t.push(n);
|
|
1933
1942
|
} catch {}
|
|
1934
1943
|
return t;
|
|
1935
1944
|
}
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1945
|
+
var H;
|
|
1946
|
+
async function Ln() {
|
|
1947
|
+
return H ||= (async () => {
|
|
1948
|
+
let e = await import("zxing-wasm/reader"), t = On(), n = t.binary ? void 0 : await kn();
|
|
1949
|
+
return await e.prepareZXingModule({
|
|
1950
|
+
overrides: t.binary ? { wasmBinary: t.binary } : { locateFile: (e, t) => e.endsWith(".wasm") ? n ?? t + e : t + e },
|
|
1951
|
+
fireImmediately: !0
|
|
1952
|
+
}), e;
|
|
1953
|
+
})().catch((e) => {
|
|
1954
|
+
throw H = void 0, console.error("[exige-scanner] zxing-wasm failed to load", e), e;
|
|
1955
|
+
}), H;
|
|
1956
|
+
}
|
|
1957
|
+
async function Rn(e) {
|
|
1958
|
+
let { readBarcodes: t } = await Ln();
|
|
1959
|
+
for (let n of await In(e)) {
|
|
1960
|
+
let e = (await t(n, {
|
|
1944
1961
|
formats: ["PDF417"],
|
|
1945
1962
|
tryHarder: !0,
|
|
1963
|
+
tryRotate: !0,
|
|
1964
|
+
tryInvert: !0,
|
|
1965
|
+
tryDownscale: !0,
|
|
1966
|
+
downscaleFactor: 2,
|
|
1967
|
+
downscaleThreshold: 300,
|
|
1946
1968
|
maxNumberOfSymbols: 1
|
|
1947
1969
|
})).find((e) => e.text?.trim())?.text?.trim();
|
|
1948
1970
|
if (e) return e;
|
|
1949
1971
|
}
|
|
1950
1972
|
}
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1973
|
+
function U(e, t) {
|
|
1974
|
+
let n = Math.max(e.width, e.height);
|
|
1975
|
+
if (n <= t) return e;
|
|
1976
|
+
let r = t / n, i = document.createElement("canvas");
|
|
1977
|
+
i.width = Math.max(1, Math.round(e.width * r)), i.height = Math.max(1, Math.round(e.height * r));
|
|
1978
|
+
let a = i.getContext("2d", { willReadFrequently: !0 }) ?? i.getContext("2d");
|
|
1979
|
+
return a && (a.imageSmoothingEnabled = !0, "imageSmoothingQuality" in a && (a.imageSmoothingQuality = "high"), a.drawImage(e, 0, 0, i.width, i.height)), i;
|
|
1980
|
+
}
|
|
1981
|
+
function zn(e, t, n) {
|
|
1982
|
+
let r = Math.max(0, Math.round(e.height * t)), i = Math.max(1, Math.round(e.height * n) - r), a = document.createElement("canvas");
|
|
1983
|
+
a.width = e.width, a.height = i;
|
|
1984
|
+
let o = a.getContext("2d", { willReadFrequently: !0 }) ?? a.getContext("2d");
|
|
1985
|
+
return o && o.drawImage(e, 0, r, e.width, i, 0, 0, e.width, i), a;
|
|
1986
|
+
}
|
|
1987
|
+
function Bn(e) {
|
|
1988
|
+
return Mn(e.width, e.height).map((t) => U(e, t));
|
|
1989
|
+
}
|
|
1990
|
+
function Vn(e) {
|
|
1991
|
+
if (e.height < e.width * 1.15 || e.height < 120) return [];
|
|
1992
|
+
let t = [];
|
|
1993
|
+
for (let [n, r] of jn) {
|
|
1994
|
+
let i = zn(e, n, r);
|
|
1995
|
+
t.push(U(i, V));
|
|
1996
|
+
let a = Mn(i.width, i.height).find((e) => e <= 960);
|
|
1997
|
+
a && t.push(U(i, a));
|
|
1998
|
+
}
|
|
1999
|
+
return t;
|
|
2000
|
+
}
|
|
2001
|
+
function Hn(e) {
|
|
2002
|
+
let t = /* @__PURE__ */ new Set(), n = [];
|
|
2003
|
+
for (let r of [...Vn(e), ...Bn(e)]) {
|
|
2004
|
+
let e = `${r.width}x${r.height}`;
|
|
2005
|
+
t.has(e) || (t.add(e), n.push(r));
|
|
2006
|
+
}
|
|
2007
|
+
return n;
|
|
2008
|
+
}
|
|
2009
|
+
async function W(e) {
|
|
2010
|
+
let t;
|
|
2011
|
+
try {
|
|
2012
|
+
t = await M(e, { cloneCanvas: !1 });
|
|
2013
|
+
} catch {
|
|
2014
|
+
t = e instanceof HTMLCanvasElement ? e : document.createElement("canvas");
|
|
2015
|
+
}
|
|
2016
|
+
let n = t.width && t.height ? Hn(t) : [];
|
|
2017
|
+
for (let e of n) try {
|
|
2018
|
+
let t = await Rn(e);
|
|
1954
2019
|
if (t) return {
|
|
1955
2020
|
text: t,
|
|
1956
|
-
source: "
|
|
2021
|
+
source: "zxing-wasm"
|
|
1957
2022
|
};
|
|
1958
2023
|
} catch {}
|
|
1959
|
-
try {
|
|
1960
|
-
let t = await
|
|
2024
|
+
if (e instanceof Blob) try {
|
|
2025
|
+
let t = await Rn(e);
|
|
1961
2026
|
return t ? {
|
|
1962
2027
|
text: t,
|
|
1963
2028
|
source: "zxing-wasm"
|
|
@@ -1966,11 +2031,11 @@ async function U(e) {
|
|
|
1966
2031
|
return;
|
|
1967
2032
|
}
|
|
1968
2033
|
}
|
|
1969
|
-
var
|
|
2034
|
+
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(".")), Un = /* @__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("."), Wn = /* @__PURE__ */ new Set([
|
|
1970
2035
|
"expirationDate",
|
|
1971
2036
|
"dateOfBirth",
|
|
1972
2037
|
"issueDate"
|
|
1973
|
-
]),
|
|
2038
|
+
]), Gn = {
|
|
1974
2039
|
DAJ: "issuerJurisdiction",
|
|
1975
2040
|
DBA: "expirationDate",
|
|
1976
2041
|
DAQ: "documentNumber",
|
|
@@ -2002,34 +2067,34 @@ var W = new Set(/* @__PURE__ */ "DCA.DCB.DCD.DBA.DCS.DAC.DAD.DBD.DBB.DBC.DAY.DAU
|
|
|
2002
2067
|
DAW: "weight",
|
|
2003
2068
|
DAX: "weight"
|
|
2004
2069
|
};
|
|
2005
|
-
function
|
|
2070
|
+
function K(e, t, n) {
|
|
2006
2071
|
let r = Number(e), i = Number(t), a = Number(n);
|
|
2007
2072
|
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")}`;
|
|
2008
2073
|
}
|
|
2009
|
-
function
|
|
2074
|
+
function Kn(e, t) {
|
|
2010
2075
|
return t ? e >= 30 ? 1900 + e : 2e3 + e : e >= 50 ? 1900 + e : 2e3 + e;
|
|
2011
2076
|
}
|
|
2012
|
-
function
|
|
2077
|
+
function q(e, t = !1) {
|
|
2013
2078
|
let n = e.trim();
|
|
2014
2079
|
if (!n) return;
|
|
2015
2080
|
let r = /^(\d{1,2})[/-](\d{1,2})[/-](\d{2,4})$/.exec(n);
|
|
2016
2081
|
if (r) {
|
|
2017
2082
|
let e = r[1], n = r[2], i = r[3];
|
|
2018
|
-
return i.length === 2 && (i = String(
|
|
2083
|
+
return i.length === 2 && (i = String(Kn(Number(i), t))), K(i, e.padStart(2, "0"), n.padStart(2, "0"));
|
|
2019
2084
|
}
|
|
2020
2085
|
let i = /^(\d{4})-(\d{2})-(\d{2})$/.exec(n);
|
|
2021
|
-
if (i) return
|
|
2086
|
+
if (i) return K(i[1], i[2], i[3]);
|
|
2022
2087
|
let a = n.replace(/[^\d]/g, "");
|
|
2023
2088
|
if (a.length === 8) {
|
|
2024
2089
|
let e = Number(a.slice(0, 4));
|
|
2025
|
-
return e >= 1900 && e <= 2100 ?
|
|
2090
|
+
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));
|
|
2026
2091
|
}
|
|
2027
2092
|
if (a.length === 6) {
|
|
2028
|
-
let e =
|
|
2029
|
-
return
|
|
2093
|
+
let e = Kn(Number(a.slice(4, 6)), t);
|
|
2094
|
+
return K(String(e), a.slice(0, 2), a.slice(2, 4));
|
|
2030
2095
|
}
|
|
2031
2096
|
}
|
|
2032
|
-
function
|
|
2097
|
+
function qn(e) {
|
|
2033
2098
|
let t = e.trim();
|
|
2034
2099
|
if (!t || t === "@") return "";
|
|
2035
2100
|
if (/^(ANSI|AAMVA)\b/.test(t)) {
|
|
@@ -2038,14 +2103,14 @@ function Rn(e) {
|
|
|
2038
2103
|
}
|
|
2039
2104
|
return t;
|
|
2040
2105
|
}
|
|
2041
|
-
function
|
|
2042
|
-
return (e.startsWith("DL") || e.startsWith("ID") || e.startsWith("ZV")) && e.length >= 5 &&
|
|
2106
|
+
function Jn(e) {
|
|
2107
|
+
return (e.startsWith("DL") || e.startsWith("ID") || e.startsWith("ZV")) && e.length >= 5 && G.has(e.slice(2, 5)) ? e.slice(2) : e;
|
|
2043
2108
|
}
|
|
2044
|
-
function
|
|
2109
|
+
function Yn(e, t) {
|
|
2045
2110
|
let n = 0;
|
|
2046
2111
|
for (; n < e.length;) {
|
|
2047
2112
|
let r = e.slice(n, n + 3);
|
|
2048
|
-
if (!
|
|
2113
|
+
if (!G.has(r)) {
|
|
2049
2114
|
n += 1;
|
|
2050
2115
|
continue;
|
|
2051
2116
|
}
|
|
@@ -2053,14 +2118,14 @@ function Bn(e, t) {
|
|
|
2053
2118
|
let i = n;
|
|
2054
2119
|
for (; i < e.length;) {
|
|
2055
2120
|
let t = e.slice(i, i + 3);
|
|
2056
|
-
if (
|
|
2121
|
+
if (G.has(t) || e[i] === "\n" || e[i] === "\r" || e[i] === "") break;
|
|
2057
2122
|
i += 1;
|
|
2058
2123
|
}
|
|
2059
2124
|
let a = e.slice(n, i).trim();
|
|
2060
2125
|
(!(r in t) || a) && (t[r] = a), n = i, (e[n] === "\n" || e[n] === "\r" || e[n] === "") && (n += 1);
|
|
2061
2126
|
}
|
|
2062
2127
|
}
|
|
2063
|
-
function
|
|
2128
|
+
function Xn(e) {
|
|
2064
2129
|
let t = /(?:ANSI|AAMVA)\s?(\d{6})(\d{2})(\d{2})(\d{2})/.exec(e);
|
|
2065
2130
|
if (t) return {
|
|
2066
2131
|
iin: t[1],
|
|
@@ -2068,22 +2133,22 @@ function Vn(e) {
|
|
|
2068
2133
|
jurisdictionVersion: t[3]
|
|
2069
2134
|
};
|
|
2070
2135
|
}
|
|
2071
|
-
function
|
|
2136
|
+
function Zn(e) {
|
|
2072
2137
|
let t = e.replace(/\r\n/g, "\n").replace(/\r/g, "\n"), n = {}, r = t.split("\n").flatMap((e) => e.split(""));
|
|
2073
2138
|
if (r.some((e) => {
|
|
2074
|
-
let t =
|
|
2075
|
-
return
|
|
2139
|
+
let t = Jn(qn(e));
|
|
2140
|
+
return G.has(t.slice(0, 3));
|
|
2076
2141
|
})) {
|
|
2077
2142
|
for (let e of r) {
|
|
2078
|
-
let t =
|
|
2079
|
-
t &&
|
|
2143
|
+
let t = Jn(qn(e));
|
|
2144
|
+
t && Yn(t, n);
|
|
2080
2145
|
}
|
|
2081
2146
|
return n;
|
|
2082
2147
|
}
|
|
2083
|
-
return
|
|
2148
|
+
return Yn(t, n), n;
|
|
2084
2149
|
}
|
|
2085
|
-
function
|
|
2086
|
-
if (
|
|
2150
|
+
function Qn(e, t) {
|
|
2151
|
+
if (Wn.has(t)) return q(e, t === "dateOfBirth") ?? e.trim();
|
|
2087
2152
|
if (t === "issuerJurisdiction" || t === "country") return e.trim().toUpperCase();
|
|
2088
2153
|
if (t === "addressPostalCode") {
|
|
2089
2154
|
let t = e.trim();
|
|
@@ -2091,11 +2156,11 @@ function Un(e, t) {
|
|
|
2091
2156
|
}
|
|
2092
2157
|
return e.trim();
|
|
2093
2158
|
}
|
|
2094
|
-
function
|
|
2159
|
+
function $n(e) {
|
|
2095
2160
|
let t = {};
|
|
2096
2161
|
for (let [n, r] of Object.entries(e)) {
|
|
2097
|
-
let e =
|
|
2098
|
-
e && r.trim() && (t[e] || (t[e] =
|
|
2162
|
+
let e = Gn[n];
|
|
2163
|
+
e && r.trim() && (t[e] || (t[e] = Qn(r, e)));
|
|
2099
2164
|
}
|
|
2100
2165
|
if (!t.firstName && e.DCT?.trim()) {
|
|
2101
2166
|
let n = e.DCT.trim().split(/\s+/);
|
|
@@ -2103,29 +2168,29 @@ function Wn(e) {
|
|
|
2103
2168
|
}
|
|
2104
2169
|
return t;
|
|
2105
2170
|
}
|
|
2106
|
-
function
|
|
2107
|
-
let t =
|
|
2171
|
+
function er(e) {
|
|
2172
|
+
let t = Zn(e);
|
|
2108
2173
|
return {
|
|
2109
2174
|
rawElements: t,
|
|
2110
|
-
fields:
|
|
2111
|
-
header:
|
|
2175
|
+
fields: $n(t),
|
|
2176
|
+
header: Xn(e)
|
|
2112
2177
|
};
|
|
2113
2178
|
}
|
|
2114
|
-
function
|
|
2179
|
+
function tr() {
|
|
2115
2180
|
return {};
|
|
2116
2181
|
}
|
|
2117
|
-
function
|
|
2118
|
-
for (let r of
|
|
2182
|
+
function nr(e, t, n) {
|
|
2183
|
+
for (let r of Un) t[r] && (e[r] = n);
|
|
2119
2184
|
return e;
|
|
2120
2185
|
}
|
|
2121
2186
|
//#endregion
|
|
2122
2187
|
//#region src/sdk/face-model.ts
|
|
2123
|
-
var
|
|
2124
|
-
function
|
|
2188
|
+
var rr = /* @__PURE__ */ new Map(), ir = 8400;
|
|
2189
|
+
function ar(e, t) {
|
|
2125
2190
|
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));
|
|
2126
2191
|
return n / Math.max(1, e.width * e.height + t.width * t.height - n);
|
|
2127
2192
|
}
|
|
2128
|
-
function
|
|
2193
|
+
function or(e, t, n, r, i, a, o) {
|
|
2129
2194
|
return {
|
|
2130
2195
|
x: (e - n / 2) / i * a,
|
|
2131
2196
|
y: (t - r / 2) / i * o,
|
|
@@ -2133,39 +2198,39 @@ function Zn(e, t, n, r, i, a, o) {
|
|
|
2133
2198
|
height: r / i * o
|
|
2134
2199
|
};
|
|
2135
2200
|
}
|
|
2136
|
-
function
|
|
2201
|
+
function sr(e, t, n) {
|
|
2137
2202
|
let r = t.length === 3 ? t[1] : t[0], i = t.length === 3 ? t[2] : t[1];
|
|
2138
|
-
if (i !== 6 || r < 1) throw Error(`Face model expects [1, anchors, 6]. A 640 YOLOX-Nano face export is [1, ${
|
|
2203
|
+
if (i !== 6 || r < 1) throw Error(`Face model expects [1, anchors, 6]. A 640 YOLOX-Nano face export is [1, ${ir}, 6].`);
|
|
2139
2204
|
let a = n.confidence ?? .35, o = n.inputSize ?? 640, s = [];
|
|
2140
2205
|
for (let t = 0; t < r; t += 1) {
|
|
2141
2206
|
let r = t * i, c = e[r + 4] * e[r + 5];
|
|
2142
2207
|
c < a || s.push({
|
|
2143
2208
|
confidence: c,
|
|
2144
|
-
bbox:
|
|
2209
|
+
bbox: or(e[r], e[r + 1], e[r + 2], e[r + 3], o, n.imageWidth, n.imageHeight)
|
|
2145
2210
|
});
|
|
2146
2211
|
}
|
|
2147
|
-
return s.sort((e, t) => t.confidence - e.confidence).filter((e, t, n) => n.slice(0, t).every((t) =>
|
|
2212
|
+
return s.sort((e, t) => t.confidence - e.confidence).filter((e, t, n) => n.slice(0, t).every((t) => ar(e.bbox, t.bbox) < .45)).slice(0, 8);
|
|
2148
2213
|
}
|
|
2149
|
-
async function
|
|
2150
|
-
let i = await
|
|
2214
|
+
async function cr(e, n, r = .35) {
|
|
2215
|
+
let i = await M(e, { cloneCanvas: !1 }), a = await import("onnxruntime-web"), o = document.createElement("canvas");
|
|
2151
2216
|
o.width = 640, o.height = 640;
|
|
2152
2217
|
let s = o.getContext("2d", { willReadFrequently: !0 });
|
|
2153
2218
|
if (!s) throw t();
|
|
2154
2219
|
s.drawImage(i, 0, 0, 640, 640);
|
|
2155
2220
|
let c = s.getImageData(0, 0, 640, 640).data, l = 409600, u = new Float32Array(l * 3);
|
|
2156
2221
|
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;
|
|
2157
|
-
let d =
|
|
2222
|
+
let d = rr.get(n);
|
|
2158
2223
|
d || (d = a.InferenceSession.create(n, {
|
|
2159
2224
|
executionProviders: ["wasm"],
|
|
2160
2225
|
graphOptimizationLevel: "all"
|
|
2161
|
-
}),
|
|
2226
|
+
}), rr.set(n, d));
|
|
2162
2227
|
let f = await d, p = (await f.run({ [f.inputNames[0]]: new a.Tensor("float32", u, [
|
|
2163
2228
|
1,
|
|
2164
2229
|
3,
|
|
2165
2230
|
640,
|
|
2166
2231
|
640
|
|
2167
2232
|
]) }))[f.outputNames[0]];
|
|
2168
|
-
return
|
|
2233
|
+
return sr(p.data, p.dims.map(Number), {
|
|
2169
2234
|
confidence: r,
|
|
2170
2235
|
imageWidth: i.width,
|
|
2171
2236
|
imageHeight: i.height,
|
|
@@ -2174,7 +2239,7 @@ async function $n(e, n, r = .35) {
|
|
|
2174
2239
|
}
|
|
2175
2240
|
//#endregion
|
|
2176
2241
|
//#region src/sdk/field-model.ts
|
|
2177
|
-
var
|
|
2242
|
+
var lr = /* @__PURE__ */ new Map(), ur = [
|
|
2178
2243
|
"person_name",
|
|
2179
2244
|
"date_of_birth",
|
|
2180
2245
|
"address",
|
|
@@ -2182,19 +2247,19 @@ var q = /* @__PURE__ */ new Map(), er = [
|
|
|
2182
2247
|
"expiration_date",
|
|
2183
2248
|
"postal_code",
|
|
2184
2249
|
"state"
|
|
2185
|
-
],
|
|
2186
|
-
function
|
|
2250
|
+
], dr = 8400;
|
|
2251
|
+
function fr(e) {
|
|
2187
2252
|
return 5 + e;
|
|
2188
2253
|
}
|
|
2189
|
-
var
|
|
2190
|
-
function
|
|
2254
|
+
var pr = 640;
|
|
2255
|
+
function mr(e, t) {
|
|
2191
2256
|
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));
|
|
2192
2257
|
return n / Math.max(1, e.bbox.width * e.bbox.height + t.bbox.width * t.bbox.height - n);
|
|
2193
2258
|
}
|
|
2194
|
-
function
|
|
2195
|
-
return e.sort((e, t) => t.confidence - e.confidence).filter((e, t, n) => n.slice(0, t).every((t) => t.field !== e.field ||
|
|
2259
|
+
function hr(e) {
|
|
2260
|
+
return e.sort((e, t) => t.confidence - e.confidence).filter((e, t, n) => n.slice(0, t).every((t) => t.field !== e.field || mr(e, t) < .45)).slice(0, 30);
|
|
2196
2261
|
}
|
|
2197
|
-
function
|
|
2262
|
+
function gr(e, t, n, r, i, a, o) {
|
|
2198
2263
|
return {
|
|
2199
2264
|
x: (e - n / 2) / i * a,
|
|
2200
2265
|
y: (t - r / 2) / i * o,
|
|
@@ -2202,8 +2267,8 @@ function or(e, t, n, r, i, a, o) {
|
|
|
2202
2267
|
height: r / i * o
|
|
2203
2268
|
};
|
|
2204
2269
|
}
|
|
2205
|
-
function
|
|
2206
|
-
let n =
|
|
2270
|
+
function _r(e, t) {
|
|
2271
|
+
let n = fr(t);
|
|
2207
2272
|
return e.length === 3 && e[0] === 1 && e[2] === n && e[1] > e[2] ? {
|
|
2208
2273
|
anchors: e[1],
|
|
2209
2274
|
features: n
|
|
@@ -2212,15 +2277,15 @@ function sr(e, t) {
|
|
|
2212
2277
|
features: n
|
|
2213
2278
|
} : null;
|
|
2214
2279
|
}
|
|
2215
|
-
function
|
|
2280
|
+
function vr(e) {
|
|
2216
2281
|
return e.length === 3 && e[1] >= 5 && e[2] >= 1;
|
|
2217
2282
|
}
|
|
2218
|
-
function
|
|
2219
|
-
let t =
|
|
2220
|
-
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, ${
|
|
2283
|
+
function yr(e) {
|
|
2284
|
+
let t = fr(e);
|
|
2285
|
+
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, ${dr}, ${t}].`);
|
|
2221
2286
|
}
|
|
2222
|
-
function
|
|
2223
|
-
if (!
|
|
2287
|
+
function br(e, t, n, r, i, a, o) {
|
|
2288
|
+
if (!vr(t)) throw Error("Unsupported field-model YOLO output shape.");
|
|
2224
2289
|
let s = t[1], c = t[2], l = [];
|
|
2225
2290
|
for (let t = 0; t < c; t += 1) {
|
|
2226
2291
|
let u = 0, d = 0;
|
|
@@ -2232,14 +2297,14 @@ function ur(e, t, n, r, i, a, o) {
|
|
|
2232
2297
|
!f || u < r || l.push({
|
|
2233
2298
|
field: f,
|
|
2234
2299
|
confidence: u,
|
|
2235
|
-
bbox:
|
|
2300
|
+
bbox: gr(e[t], e[c + t], e[c * 2 + t], e[c * 3 + t], i, a, o)
|
|
2236
2301
|
});
|
|
2237
2302
|
}
|
|
2238
|
-
return
|
|
2303
|
+
return hr(l);
|
|
2239
2304
|
}
|
|
2240
|
-
function
|
|
2241
|
-
let s =
|
|
2242
|
-
if (!s) throw
|
|
2305
|
+
function xr(e, t, n, r, i, a, o) {
|
|
2306
|
+
let s = _r(t, n.length);
|
|
2307
|
+
if (!s) throw yr(n.length);
|
|
2243
2308
|
let c = [];
|
|
2244
2309
|
for (let t = 0; t < s.anchors; t += 1) {
|
|
2245
2310
|
let l = t * s.features, u = e[l + 4], d = 0, f = 0;
|
|
@@ -2251,25 +2316,25 @@ function dr(e, t, n, r, i, a, o) {
|
|
|
2251
2316
|
!p || m < r || c.push({
|
|
2252
2317
|
field: p,
|
|
2253
2318
|
confidence: m,
|
|
2254
|
-
bbox:
|
|
2319
|
+
bbox: gr(e[l], e[l + 1], e[l + 2], e[l + 3], i, a, o)
|
|
2255
2320
|
});
|
|
2256
2321
|
}
|
|
2257
|
-
return
|
|
2322
|
+
return hr(c);
|
|
2258
2323
|
}
|
|
2259
|
-
function
|
|
2260
|
-
let r = n.classes ??
|
|
2324
|
+
function Sr(e, t, n) {
|
|
2325
|
+
let r = n.classes ?? ur, i = n.confidence ?? .35, a = n.inputSize ?? pr, o = _r(t, r.length);
|
|
2261
2326
|
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.");
|
|
2262
|
-
return (n.layout ?? (o ? "yolox" : "yolov8")) === "yolox" ?
|
|
2327
|
+
return (n.layout ?? (o ? "yolox" : "yolov8")) === "yolox" ? xr(e, t, r, i, a, n.imageWidth, n.imageHeight) : br(e, t, r, i, a, n.imageWidth, n.imageHeight);
|
|
2263
2328
|
}
|
|
2264
|
-
async function
|
|
2265
|
-
let o = await
|
|
2329
|
+
async function Cr(e, n, r = ur, i = .35, a) {
|
|
2330
|
+
let o = await M(e, { cloneCanvas: !1 }), s = import("onnxruntime-web"), c = pr, l = document.createElement("canvas");
|
|
2266
2331
|
l.width = c, l.height = c;
|
|
2267
2332
|
let u = l.getContext("2d", { willReadFrequently: !0 });
|
|
2268
2333
|
if (!u) throw t();
|
|
2269
2334
|
u.drawImage(o, 0, 0, c, c);
|
|
2270
2335
|
let d = u.getImageData(0, 0, c, c).data, f = c * c, p = new Float32Array(f * 3);
|
|
2271
2336
|
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;
|
|
2272
|
-
let m =
|
|
2337
|
+
let m = lr.get(n);
|
|
2273
2338
|
m || (m = (async () => {
|
|
2274
2339
|
try {
|
|
2275
2340
|
let [e, t] = await Promise.all([s, ae(n)]);
|
|
@@ -2278,16 +2343,16 @@ async function pr(e, n, r = er, i = .35, a) {
|
|
|
2278
2343
|
graphOptimizationLevel: "all"
|
|
2279
2344
|
});
|
|
2280
2345
|
} catch (e) {
|
|
2281
|
-
throw
|
|
2346
|
+
throw lr.delete(n), e;
|
|
2282
2347
|
}
|
|
2283
|
-
})(),
|
|
2348
|
+
})(), lr.set(n, m));
|
|
2284
2349
|
let [h, g] = await Promise.all([s, m]), _ = (await g.run({ [g.inputNames[0]]: new h.Tensor("float32", p, [
|
|
2285
2350
|
1,
|
|
2286
2351
|
3,
|
|
2287
2352
|
c,
|
|
2288
2353
|
c
|
|
2289
2354
|
]) }))[g.outputNames[0]];
|
|
2290
|
-
return
|
|
2355
|
+
return Sr(_.data, _.dims.map(Number), {
|
|
2291
2356
|
classes: r,
|
|
2292
2357
|
confidence: i,
|
|
2293
2358
|
layout: a,
|
|
@@ -2298,12 +2363,12 @@ async function pr(e, n, r = er, i = .35, a) {
|
|
|
2298
2363
|
}
|
|
2299
2364
|
//#endregion
|
|
2300
2365
|
//#region src/sdk/redact.ts
|
|
2301
|
-
async function
|
|
2366
|
+
async function wr(e, n, r = {}) {
|
|
2302
2367
|
await x("redaction");
|
|
2303
|
-
let i = await
|
|
2368
|
+
let i = await M(e), a = i.getContext("2d");
|
|
2304
2369
|
if (!a) throw t();
|
|
2305
2370
|
for (let e of n) {
|
|
2306
|
-
let t =
|
|
2371
|
+
let t = Je(e, i.width, i.height);
|
|
2307
2372
|
if (t.width < 1 || t.height < 1) continue;
|
|
2308
2373
|
if ((e.mode ?? r.mode ?? "blackout") === "blackout") {
|
|
2309
2374
|
a.fillStyle = "#050706", a.fillRect(t.x, t.y, t.width, t.height);
|
|
@@ -2319,7 +2384,7 @@ async function mr(e, n, r = {}) {
|
|
|
2319
2384
|
}
|
|
2320
2385
|
return {
|
|
2321
2386
|
canvas: i,
|
|
2322
|
-
blob: await
|
|
2387
|
+
blob: await qe(i, r.mimeType ?? "image/png", r.quality)
|
|
2323
2388
|
};
|
|
2324
2389
|
}
|
|
2325
2390
|
//#endregion
|
|
@@ -2333,7 +2398,7 @@ function J(e) {
|
|
|
2333
2398
|
height: i - n
|
|
2334
2399
|
};
|
|
2335
2400
|
}
|
|
2336
|
-
function
|
|
2401
|
+
function Tr(e) {
|
|
2337
2402
|
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);
|
|
2338
2403
|
for (let e of n) {
|
|
2339
2404
|
let n = e.bbox.y + e.bbox.height / 2, r = t.find((t) => {
|
|
@@ -2355,7 +2420,7 @@ function Y(e, t, n = !1) {
|
|
|
2355
2420
|
function X(e) {
|
|
2356
2421
|
return e.reduce((e, t) => e + t.confidence, 0) / Math.max(1, e.length);
|
|
2357
2422
|
}
|
|
2358
|
-
function
|
|
2423
|
+
function Er(e, t) {
|
|
2359
2424
|
let n = e.mode, r = n === "case-insensitive", i = e.scope ?? "line", a;
|
|
2360
2425
|
if (n === "regex") {
|
|
2361
2426
|
let t = e.pattern ?? e.values?.[0];
|
|
@@ -2392,22 +2457,22 @@ function gr(e, t) {
|
|
|
2392
2457
|
}
|
|
2393
2458
|
return s;
|
|
2394
2459
|
}
|
|
2395
|
-
function
|
|
2460
|
+
function Dr(e, t) {
|
|
2396
2461
|
let n = e.labelMode !== "exact", r = Y(e.label, n, !0).split(" ");
|
|
2397
2462
|
for (let e of t) for (let t = 0; t <= e.words.length - r.length; t += 1) {
|
|
2398
2463
|
let i = e.words.slice(t, t + r.length);
|
|
2399
2464
|
if (i.every((e, t) => Y(e.text, n, !0) === r[t])) return i;
|
|
2400
2465
|
}
|
|
2401
2466
|
}
|
|
2402
|
-
function
|
|
2467
|
+
function Or(e, t, n, r, i, a) {
|
|
2403
2468
|
let o = a.window?.distance ?? .28, s = a.window?.crossAxis ?? .12, c = t.x + t.width / 2, l = t.y + t.height / 2;
|
|
2404
2469
|
return e.filter((e) => {
|
|
2405
2470
|
let a = e.bbox.x + e.bbox.width / 2, u = e.bbox.y + e.bbox.height / 2;
|
|
2406
2471
|
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;
|
|
2407
2472
|
});
|
|
2408
2473
|
}
|
|
2409
|
-
function
|
|
2410
|
-
let o =
|
|
2474
|
+
function kr(e, t, n, r, i, a = "label") {
|
|
2475
|
+
let o = Dr(e, n);
|
|
2411
2476
|
if (!o) return [];
|
|
2412
2477
|
let s = J(o), c = new Set(o), l = t.filter((e) => !c.has(e)), u = e.direction === "any" ? [
|
|
2413
2478
|
"right",
|
|
@@ -2416,7 +2481,7 @@ function yr(e, t, n, r, i, a = "label") {
|
|
|
2416
2481
|
"above"
|
|
2417
2482
|
] : [e.direction], d;
|
|
2418
2483
|
for (let t of u) {
|
|
2419
|
-
let n =
|
|
2484
|
+
let n = Tr(Or(l, s, t, r, i, e));
|
|
2420
2485
|
for (let t of n) {
|
|
2421
2486
|
if (e.valuePattern && !new RegExp(e.valuePattern, e.patternFlags).test(t.text)) continue;
|
|
2422
2487
|
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);
|
|
@@ -2437,7 +2502,7 @@ function yr(e, t, n, r, i, a = "label") {
|
|
|
2437
2502
|
confidence: Math.max(0, X(d.words) * (1 - Math.min(.5, d.distance)))
|
|
2438
2503
|
}];
|
|
2439
2504
|
}
|
|
2440
|
-
var
|
|
2505
|
+
var Ar = {
|
|
2441
2506
|
person_name: [
|
|
2442
2507
|
"LN",
|
|
2443
2508
|
"FN",
|
|
@@ -2474,10 +2539,10 @@ var br = {
|
|
|
2474
2539
|
"POSTAL"
|
|
2475
2540
|
],
|
|
2476
2541
|
state: ["STATE", "DAJ"]
|
|
2477
|
-
},
|
|
2542
|
+
}, jr = new Set(Object.values(Ar).flat()), Mr = /^(?:\d{2}[/-]\d{2}[/-]\d{2,4}|\d{4}[/-]\d{2}[/-]\d{2}|\d{6}|\d{8})$/, Nr = /\b(?:ST|STREET|AVE|AVENUE|RD|ROAD|BLVD|BOULEVARD|LN|LANE|DR|DRIVE|WAY|CT|COURT)\b/i, Pr = /\b(?:DRIVER|LICENSE|IDENTIFICATION|CARD|CLASS|SEX|EYES|HEIGHT|RESTRICTIONS)\b/i;
|
|
2478
2543
|
function Z(e, t) {
|
|
2479
2544
|
let n = t.trim();
|
|
2480
|
-
return n ? e === "date_of_birth" || e === "expiration_date" ?
|
|
2545
|
+
return n ? e === "date_of_birth" || e === "expiration_date" ? Mr.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) && !Pr.test(n) : /\d/.test(n) && /[A-Z]/i.test(n) : !1;
|
|
2481
2546
|
}
|
|
2482
2547
|
function Q(e, t, n, r, i = 1) {
|
|
2483
2548
|
return {
|
|
@@ -2489,17 +2554,17 @@ function Q(e, t, n, r, i = 1) {
|
|
|
2489
2554
|
confidence: Math.max(0, Math.min(1, X(n) * i))
|
|
2490
2555
|
};
|
|
2491
2556
|
}
|
|
2492
|
-
function
|
|
2493
|
-
let r =
|
|
2557
|
+
function Fr(e, t, n) {
|
|
2558
|
+
let r = Ar[e], i = [];
|
|
2494
2559
|
for (let a of n) for (let n = 0; n < a.words.length; n += 1) {
|
|
2495
2560
|
let o = a.words[n].text.toUpperCase().replace(/[^A-Z0-9]/g, ""), s = r.find((e) => o === e || o.startsWith(e));
|
|
2496
2561
|
if (!s) continue;
|
|
2497
2562
|
let c, l;
|
|
2498
|
-
o === s ? (c = a.words.slice(n + 1).filter((e) => !
|
|
2563
|
+
o === s ? (c = a.words.slice(n + 1).filter((e) => !jr.has(e.text.toUpperCase().replace(/[^A-Z0-9]/g, ""))), l = c.map((e) => e.text).join(" ")) : (c = [a.words[n]], l = a.words[n].text.replace(RegExp(`^${s}[:\\s-]*`, "i"), "")), c.length && Z(e, l) && i.push(Q(t, "alias", c, l, .98));
|
|
2499
2564
|
}
|
|
2500
2565
|
return i;
|
|
2501
2566
|
}
|
|
2502
|
-
function
|
|
2567
|
+
function Ir(e, t, n) {
|
|
2503
2568
|
let r = n.filter((e) => {
|
|
2504
2569
|
let t = e.text.replace(/\s/g, "");
|
|
2505
2570
|
return t.includes("<<") || /^[A-Z0-9<]{25,}$/.test(t);
|
|
@@ -2521,7 +2586,7 @@ function Er(e, t, n) {
|
|
|
2521
2586
|
}
|
|
2522
2587
|
return [];
|
|
2523
2588
|
}
|
|
2524
|
-
function
|
|
2589
|
+
function Lr(e) {
|
|
2525
2590
|
let t = e.replace(/\s/g, ""), n = t.match(/\d{4}/)?.[0];
|
|
2526
2591
|
if (n) return Number(n);
|
|
2527
2592
|
let r = t.match(/^\d{2}/)?.[0];
|
|
@@ -2529,16 +2594,16 @@ function Dr(e) {
|
|
|
2529
2594
|
let i = Number(r);
|
|
2530
2595
|
return i > (/* @__PURE__ */ new Date()).getFullYear() % 100 ? 1900 + i : 2e3 + i;
|
|
2531
2596
|
}
|
|
2532
|
-
function
|
|
2597
|
+
function Rr(e, t, n, r, i) {
|
|
2533
2598
|
if (e === "address") {
|
|
2534
|
-
let e = r.findIndex((e) => /\d/.test(e.text) &&
|
|
2599
|
+
let e = r.findIndex((e) => /\d/.test(e.text) && Nr.test(e.text));
|
|
2535
2600
|
if (e < 0) return [];
|
|
2536
2601
|
let n = [...r[e].words], i = r[e + 1];
|
|
2537
2602
|
return i && /(?:\b[A-Z]{2}\b.*\d{5}|\d{5})/i.test(i.text) && n.push(...i.words), [Q(t, "layout", n, void 0, .76)];
|
|
2538
2603
|
}
|
|
2539
2604
|
if (e === "person_name") {
|
|
2540
2605
|
let e = r.map((e) => {
|
|
2541
|
-
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 && !
|
|
2606
|
+
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 && !Pr.test(e.text) && !Nr.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);
|
|
2542
2607
|
return {
|
|
2543
2608
|
line: e,
|
|
2544
2609
|
score: r ? .45 + X(e.words) * .3 + a * .15 + (n < .65 ? .1 : 0) : 0
|
|
@@ -2547,9 +2612,9 @@ function Or(e, t, n, r, i) {
|
|
|
2547
2612
|
return !e.length || e[1] && e[0].score - e[1].score < .04 ? [] : [Q(t, "layout", e[0].line.words, void 0, e[0].score)];
|
|
2548
2613
|
}
|
|
2549
2614
|
if (e === "date_of_birth" || e === "expiration_date") {
|
|
2550
|
-
let r = (/* @__PURE__ */ new Date()).getFullYear(), i = n.filter((e) =>
|
|
2615
|
+
let r = (/* @__PURE__ */ new Date()).getFullYear(), i = n.filter((e) => Mr.test(e.text.replace(/\s/g, ""))).map((e) => ({
|
|
2551
2616
|
word: e,
|
|
2552
|
-
year:
|
|
2617
|
+
year: Lr(e.text)
|
|
2553
2618
|
})).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);
|
|
2554
2619
|
return a.sort((t, n) => e === "date_of_birth" ? t.year - n.year : n.year - t.year), a.length ? [Q(t, "layout", [a[0].word], void 0, .72)] : [];
|
|
2555
2620
|
}
|
|
@@ -2567,29 +2632,29 @@ function Or(e, t, n, r, i) {
|
|
|
2567
2632
|
}
|
|
2568
2633
|
return [];
|
|
2569
2634
|
}
|
|
2570
|
-
function
|
|
2635
|
+
function zr(e, t) {
|
|
2571
2636
|
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);
|
|
2572
2637
|
}
|
|
2573
|
-
function
|
|
2574
|
-
let i =
|
|
2575
|
-
return i.length || a.length ? [...i, ...a] :
|
|
2638
|
+
function Br(e, t, n, r) {
|
|
2639
|
+
let i = Fr(e.field, e.id, n), a = Ir(e.field, e.id, n);
|
|
2640
|
+
return i.length || a.length ? [...i, ...a] : Rr(e.field, e.id, t, n, r);
|
|
2576
2641
|
}
|
|
2577
|
-
function
|
|
2642
|
+
function Vr(e, t, n) {
|
|
2578
2643
|
let r = (n ?? []).filter((t) => t.field === e.field).sort((e, t) => t.confidence - e.confidence);
|
|
2579
2644
|
for (let n of r) {
|
|
2580
|
-
let r = t.filter((e) =>
|
|
2645
|
+
let r = t.filter((e) => zr(n.bbox, e.bbox) >= .3);
|
|
2581
2646
|
if (!r.length) continue;
|
|
2582
2647
|
let i = r.map((e) => e.text).join(" ");
|
|
2583
2648
|
if (Z(e.field, i)) return Q(e.id, "model", r, i, n.confidence);
|
|
2584
2649
|
}
|
|
2585
2650
|
}
|
|
2586
|
-
function
|
|
2587
|
-
let o =
|
|
2651
|
+
function Hr(e, t, n, r, i, a) {
|
|
2652
|
+
let o = Br(e, t, n, r);
|
|
2588
2653
|
if (e.detector !== "model" || !a) return o;
|
|
2589
|
-
let s =
|
|
2654
|
+
let s = Vr(e, t, i);
|
|
2590
2655
|
return s ? [s] : [];
|
|
2591
2656
|
}
|
|
2592
|
-
function
|
|
2657
|
+
function Ur(e, t, n, r) {
|
|
2593
2658
|
let i = (e) => Math.max(0, Math.min(1, e)), a = i(e.rect.x), o = i(e.rect.y);
|
|
2594
2659
|
return {
|
|
2595
2660
|
ruleId: `${t}.${e.id}`,
|
|
@@ -2604,19 +2669,19 @@ function Nr(e, t, n, r) {
|
|
|
2604
2669
|
confidence: 1
|
|
2605
2670
|
};
|
|
2606
2671
|
}
|
|
2607
|
-
function
|
|
2608
|
-
let n = t.imageWidth ?? e?.imageWidth ?? 0, r = t.imageHeight ?? e?.imageHeight ?? 0, i = e?.words ?? [], a =
|
|
2672
|
+
function Wr(e, t) {
|
|
2673
|
+
let n = t.imageWidth ?? e?.imageWidth ?? 0, r = t.imageHeight ?? e?.imageHeight ?? 0, i = e?.words ?? [], a = Tr(i), o = [], s = [];
|
|
2609
2674
|
for (let e of t.rules) {
|
|
2610
|
-
let c = e.strategy === "string" ?
|
|
2675
|
+
let c = e.strategy === "string" ? Er(e, a) : e.strategy === "label" ? kr(e, i, a, n, r) : Hr(e, i, a, r, t.semanticDetections, t.modelRequested === !0);
|
|
2611
2676
|
c.length ? o.push(...c) : s.push(e.id);
|
|
2612
2677
|
}
|
|
2613
2678
|
for (let e of t.template?.fields ?? []) {
|
|
2614
2679
|
let c = `${t.template.id}.${e.id}`;
|
|
2615
2680
|
if (e.strategy === "rect") {
|
|
2616
|
-
n && r ? o.push(
|
|
2681
|
+
n && r ? o.push(Ur(e, t.template.id, n, r)) : s.push(c);
|
|
2617
2682
|
continue;
|
|
2618
2683
|
}
|
|
2619
|
-
let l =
|
|
2684
|
+
let l = kr({
|
|
2620
2685
|
...e,
|
|
2621
2686
|
id: c,
|
|
2622
2687
|
strategy: "label"
|
|
@@ -2634,34 +2699,34 @@ function Pr(e, t) {
|
|
|
2634
2699
|
confidence: u
|
|
2635
2700
|
};
|
|
2636
2701
|
}
|
|
2637
|
-
function
|
|
2702
|
+
function Gr(e) {
|
|
2638
2703
|
return e.rules.length > 0 || e.template?.fields.some((e) => e.strategy === "anchor") === !0;
|
|
2639
2704
|
}
|
|
2640
|
-
function
|
|
2705
|
+
function Kr(e, t = !1) {
|
|
2641
2706
|
return t && !e.complete ? "unmatched" : e.complete ? "success" : "partial";
|
|
2642
2707
|
}
|
|
2643
|
-
async function
|
|
2708
|
+
async function qr(e, t) {
|
|
2644
2709
|
await x("redaction");
|
|
2645
|
-
let n = await
|
|
2646
|
-
|
|
2710
|
+
let n = await M(e, { cloneCanvas: !1 }), r = t.ocr;
|
|
2711
|
+
Gr(t) && !r && (r = await B(n, { includeWords: !0 }));
|
|
2647
2712
|
let i = t.semanticDetections, a = t.modelRequested === !0, o = "not-requested", s;
|
|
2648
2713
|
if (t.models?.fields) try {
|
|
2649
|
-
i = await
|
|
2714
|
+
i = await Cr(n, t.models.fields, t.models.fieldClasses, t.models.confidence, t.models.fieldLayout), a = !0, o = "loaded";
|
|
2650
2715
|
} catch (e) {
|
|
2651
2716
|
s = e instanceof Error ? e.message : "The field model could not load.";
|
|
2652
2717
|
let n = t.models.allowHeuristicFallback !== !1;
|
|
2653
2718
|
a = !n, o = n ? "fallback" : "failed";
|
|
2654
2719
|
}
|
|
2655
|
-
let c =
|
|
2720
|
+
let c = Wr(r, {
|
|
2656
2721
|
rules: t.rules,
|
|
2657
2722
|
template: t.template,
|
|
2658
2723
|
imageWidth: n.width,
|
|
2659
2724
|
imageHeight: n.height,
|
|
2660
2725
|
semanticDetections: i,
|
|
2661
2726
|
modelRequested: a
|
|
2662
|
-
}), l =
|
|
2727
|
+
}), l = Kr(c, t.requireAll), u = [], d = "not-requested", f;
|
|
2663
2728
|
if (t.models?.face) try {
|
|
2664
|
-
u = await
|
|
2729
|
+
u = await cr(n, t.models.face, t.models.faceConfidence), d = "loaded";
|
|
2665
2730
|
} catch (e) {
|
|
2666
2731
|
f = e instanceof Error ? e.message : "The face model could not load.", d = "failed";
|
|
2667
2732
|
}
|
|
@@ -2675,7 +2740,7 @@ async function Lr(e, t) {
|
|
|
2675
2740
|
faceStatus: d,
|
|
2676
2741
|
faceError: f
|
|
2677
2742
|
};
|
|
2678
|
-
let p = await
|
|
2743
|
+
let p = await wr(n, [...c.matches.map((e) => ({
|
|
2679
2744
|
...e.bbox,
|
|
2680
2745
|
mode: t.style?.mode
|
|
2681
2746
|
})), ...u.map((e) => ({
|
|
@@ -2697,7 +2762,7 @@ async function Lr(e, t) {
|
|
|
2697
2762
|
}
|
|
2698
2763
|
//#endregion
|
|
2699
2764
|
//#region src/sdk/driver-license.ts
|
|
2700
|
-
var
|
|
2765
|
+
var Jr = [
|
|
2701
2766
|
{
|
|
2702
2767
|
id: "issuerJurisdiction",
|
|
2703
2768
|
strategy: "semantic",
|
|
@@ -2734,11 +2799,11 @@ var Rr = [
|
|
|
2734
2799
|
field: "person_name"
|
|
2735
2800
|
}
|
|
2736
2801
|
];
|
|
2737
|
-
function
|
|
2802
|
+
function Yr(e, t, n) {
|
|
2738
2803
|
let r = n.trim();
|
|
2739
2804
|
if (r) {
|
|
2740
2805
|
if (t === "expirationDate" || t === "dateOfBirth" || t === "issueDate") {
|
|
2741
|
-
e[t] =
|
|
2806
|
+
e[t] = q(r, t === "dateOfBirth") ?? r;
|
|
2742
2807
|
return;
|
|
2743
2808
|
}
|
|
2744
2809
|
if (t === "issuerJurisdiction") {
|
|
@@ -2748,8 +2813,8 @@ function zr(e, t, n) {
|
|
|
2748
2813
|
e[t] = r;
|
|
2749
2814
|
}
|
|
2750
2815
|
}
|
|
2751
|
-
function
|
|
2752
|
-
let t = {}, n =
|
|
2816
|
+
function Xr(e) {
|
|
2817
|
+
let t = {}, n = Wr(e, { rules: Jr });
|
|
2753
2818
|
for (let e of n.matches) {
|
|
2754
2819
|
let n = e.text?.trim();
|
|
2755
2820
|
if (n) {
|
|
@@ -2758,29 +2823,29 @@ function Br(e) {
|
|
|
2758
2823
|
!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(" "));
|
|
2759
2824
|
continue;
|
|
2760
2825
|
}
|
|
2761
|
-
|
|
2826
|
+
Yr(t, e.ruleId, n);
|
|
2762
2827
|
}
|
|
2763
2828
|
}
|
|
2764
2829
|
return t;
|
|
2765
2830
|
}
|
|
2766
|
-
function
|
|
2767
|
-
let n = { ...e }, r =
|
|
2831
|
+
function Zr(e, t) {
|
|
2832
|
+
let n = { ...e }, r = nr(tr(), e, "barcode");
|
|
2768
2833
|
for (let [e, i] of Object.entries(t)) i && (n[e] || (n[e] = i, r[e] = "ocr"));
|
|
2769
2834
|
return {
|
|
2770
2835
|
fields: n,
|
|
2771
2836
|
sources: r
|
|
2772
2837
|
};
|
|
2773
2838
|
}
|
|
2774
|
-
async function
|
|
2775
|
-
return t?.status === "success" && t.corners ?
|
|
2839
|
+
async function Qr(e, t, n) {
|
|
2840
|
+
return t?.status === "success" && t.corners ? ut(e, t.corners, { maxOutputDimension: n?.maxOutputDimension }) : I(e, n);
|
|
2776
2841
|
}
|
|
2777
|
-
async function
|
|
2842
|
+
async function $r(e, t, n) {
|
|
2778
2843
|
if (!e.width || !e.height) return {
|
|
2779
2844
|
kind: "retry",
|
|
2780
2845
|
status: "frontFailed",
|
|
2781
2846
|
message: "The front photo was empty. Try again."
|
|
2782
2847
|
};
|
|
2783
|
-
let r = await
|
|
2848
|
+
let r = await Qr(e, t, n);
|
|
2784
2849
|
if (r.status !== "success" || !r.canvas) return {
|
|
2785
2850
|
kind: "retry",
|
|
2786
2851
|
status: "frontFailed",
|
|
@@ -2788,7 +2853,7 @@ async function Ur(e, t, n) {
|
|
|
2788
2853
|
};
|
|
2789
2854
|
let i;
|
|
2790
2855
|
try {
|
|
2791
|
-
i = await
|
|
2856
|
+
i = await B(r.canvas, { includeWords: !0 });
|
|
2792
2857
|
} catch {
|
|
2793
2858
|
i = void 0;
|
|
2794
2859
|
}
|
|
@@ -2804,7 +2869,7 @@ async function Ur(e, t, n) {
|
|
|
2804
2869
|
function $() {
|
|
2805
2870
|
return new DOMException("The barcode scan was cancelled.", "AbortError");
|
|
2806
2871
|
}
|
|
2807
|
-
function
|
|
2872
|
+
function ei(e, t) {
|
|
2808
2873
|
return new Promise((n, r) => {
|
|
2809
2874
|
if (t?.aborted) {
|
|
2810
2875
|
r($());
|
|
@@ -2818,21 +2883,21 @@ function Wr(e, t) {
|
|
|
2818
2883
|
t?.addEventListener("abort", a, { once: !0 });
|
|
2819
2884
|
});
|
|
2820
2885
|
}
|
|
2821
|
-
async function
|
|
2886
|
+
async function ti(e, t = {}) {
|
|
2822
2887
|
let n = t.intervalMs ?? 140;
|
|
2823
2888
|
for (;;) {
|
|
2824
2889
|
if (t.signal?.aborted) throw $();
|
|
2825
2890
|
try {
|
|
2826
2891
|
let t = await e();
|
|
2827
|
-
if (t?.width && t.height && (await
|
|
2892
|
+
if (t?.width && t.height && (await W(t))?.text) return t;
|
|
2828
2893
|
} catch (e) {
|
|
2829
2894
|
if (t.signal?.aborted) throw $();
|
|
2830
2895
|
if (e instanceof DOMException && e.name === "AbortError") throw e;
|
|
2831
2896
|
}
|
|
2832
|
-
await
|
|
2897
|
+
await ei(n, t.signal);
|
|
2833
2898
|
}
|
|
2834
2899
|
}
|
|
2835
|
-
async function
|
|
2900
|
+
async function ni(e, t) {
|
|
2836
2901
|
if (!e.width || !e.height) return {
|
|
2837
2902
|
status: "backFailed",
|
|
2838
2903
|
fields: {},
|
|
@@ -2842,23 +2907,23 @@ async function Kr(e, t) {
|
|
|
2842
2907
|
back: {},
|
|
2843
2908
|
message: "The back photo was empty. Try again."
|
|
2844
2909
|
};
|
|
2845
|
-
let n = (await
|
|
2910
|
+
let n = (await W(e))?.text, r = {
|
|
2846
2911
|
canvas: e,
|
|
2847
2912
|
barcodeText: n
|
|
2848
2913
|
};
|
|
2849
2914
|
if (!n) {
|
|
2850
|
-
let e = t.ocr ?
|
|
2915
|
+
let e = t.ocr ? Xr(t.ocr) : {};
|
|
2851
2916
|
return {
|
|
2852
2917
|
status: "barcodeUnreadable",
|
|
2853
2918
|
fields: e,
|
|
2854
2919
|
rawElements: {},
|
|
2855
|
-
sources:
|
|
2920
|
+
sources: nr(tr(), e, "ocr"),
|
|
2856
2921
|
front: t,
|
|
2857
2922
|
back: r,
|
|
2858
2923
|
message: "The PDF417 barcode on the back could not be read. Try again."
|
|
2859
2924
|
};
|
|
2860
2925
|
}
|
|
2861
|
-
let i =
|
|
2926
|
+
let i = er(n), a = t.ocr ? Xr(t.ocr) : {}, o = Zr(i.fields, a);
|
|
2862
2927
|
return {
|
|
2863
2928
|
status: "success",
|
|
2864
2929
|
fields: o.fields,
|
|
@@ -2868,21 +2933,21 @@ async function Kr(e, t) {
|
|
|
2868
2933
|
back: r
|
|
2869
2934
|
};
|
|
2870
2935
|
}
|
|
2871
|
-
function
|
|
2936
|
+
function ri(e) {
|
|
2872
2937
|
return e === "back" ? 0 : void 0;
|
|
2873
2938
|
}
|
|
2874
|
-
function
|
|
2939
|
+
function ii(e, t) {
|
|
2875
2940
|
return e === "front" ? {
|
|
2876
2941
|
title: "Scan a driver’s license",
|
|
2877
2942
|
headline: "Show the front of the license.",
|
|
2878
2943
|
detail: t ? "Take a photo of the front. There is no live document guide." : "Place the front of the license in the frame."
|
|
2879
2944
|
} : {
|
|
2880
2945
|
title: "Scan a driver’s license",
|
|
2881
|
-
headline: "
|
|
2882
|
-
detail: t ? "Take a photo of the PDF417 barcode
|
|
2946
|
+
headline: "Hold the whole barcode in view",
|
|
2947
|
+
detail: t ? "Take a photo of the entire PDF417 barcode. There is no document outline." : "Keep the entire PDF417 in the preview. Closer is fine if the whole code is visible."
|
|
2883
2948
|
};
|
|
2884
2949
|
}
|
|
2885
|
-
async function
|
|
2950
|
+
async function ai(e = {}) {
|
|
2886
2951
|
await x("scan"), await x("ocr");
|
|
2887
2952
|
let t = "front", n, r = !1;
|
|
2888
2953
|
return {
|
|
@@ -2896,10 +2961,10 @@ async function Yr(e = {}) {
|
|
|
2896
2961
|
message: "This license scan was cancelled."
|
|
2897
2962
|
};
|
|
2898
2963
|
if (t === "front") {
|
|
2899
|
-
let r = await
|
|
2964
|
+
let r = await $r(i, a, e.scan);
|
|
2900
2965
|
return r.kind === "need-back" && (n = r.front, t = "back"), r;
|
|
2901
2966
|
}
|
|
2902
|
-
let o = await
|
|
2967
|
+
let o = await ni(i, n ?? {});
|
|
2903
2968
|
return o.status === "backFailed" ? {
|
|
2904
2969
|
kind: "retry",
|
|
2905
2970
|
status: "backFailed",
|
|
@@ -2915,6 +2980,6 @@ async function Yr(e = {}) {
|
|
|
2915
2980
|
};
|
|
2916
2981
|
}
|
|
2917
2982
|
//#endregion
|
|
2918
|
-
export {
|
|
2983
|
+
export { b as $, I as A, ce as B, Nt as C, ut as D, Ye as E, De as F, le as G, ye as H, j as I, ve as J, ue as K, k as L, dt as M, _e as N, lt as O, ge as P, x as Q, se as R, jt as S, Rt as T, A as U, be as V, Le as W, a as X, re as Y, o as Z, Pt as _, ai as a, St as b, qr as c, er as d, y as et, V as f, Et as g, B as h, Zr as i, ft as j, Qe as k, wr as l, Pn as m, ri as n, t as nt, ti as o, W as p, Fe as q, ii as r, Wr as s, Xr as t, e as tt, q as u, Tt as v, xt as w, Mt as x, Ct as y, Ie as z };
|
|
2919
2984
|
|
|
2920
|
-
//# sourceMappingURL=driver-license-
|
|
2985
|
+
//# sourceMappingURL=driver-license-CBDCGp14.js.map
|