@exige/web-scanner-sdk 0.2.25 → 0.2.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/{finder-B3t_3g6Z.js → finder-BlN89ZeT.js} +121 -101
- package/dist/finder-BlN89ZeT.js.map +1 -0
- package/dist/index.d.ts +3 -3
- package/dist/react/context.d.ts +1 -1
- package/dist/react/types.d.ts +17 -1
- package/dist/react.d.ts +1 -1
- package/dist/react.js +400 -267
- package/dist/react.js.map +1 -1
- package/dist/scanner-sdk.js +176 -176
- package/dist/scanner-sdk.js.map +1 -1
- package/dist/sdk/camera.d.ts +24 -4
- package/dist/sdk/scan.d.ts +10 -0
- package/package.json +1 -1
- package/dist/finder-B3t_3g6Z.js.map +0 -1
|
@@ -536,7 +536,7 @@ async function Ce(e, t, n = {}) {
|
|
|
536
536
|
canvas: L(r, t, i)
|
|
537
537
|
};
|
|
538
538
|
}
|
|
539
|
-
async function
|
|
539
|
+
async function z(e, t = {}) {
|
|
540
540
|
await x("scan");
|
|
541
541
|
let n = await A(e, { cloneCanvas: !1 }), r = await I(n, t);
|
|
542
542
|
if (r.status !== "success" || !r.corners) return r;
|
|
@@ -547,9 +547,19 @@ async function we(e, t = {}) {
|
|
|
547
547
|
message: "Four document edges detected and perspective-corrected."
|
|
548
548
|
};
|
|
549
549
|
}
|
|
550
|
+
function B(e) {
|
|
551
|
+
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})` : ""}`;
|
|
552
|
+
}
|
|
553
|
+
async function we(e, t = {}) {
|
|
554
|
+
let n = await z(e, t);
|
|
555
|
+
return n.status === "success" ? n : {
|
|
556
|
+
...n,
|
|
557
|
+
message: B(n)
|
|
558
|
+
};
|
|
559
|
+
}
|
|
550
560
|
//#endregion
|
|
551
561
|
//#region src/sdk/camera.ts
|
|
552
|
-
function
|
|
562
|
+
function V(e, t) {
|
|
553
563
|
let { engine: n } = t;
|
|
554
564
|
return [
|
|
555
565
|
`${e}:`,
|
|
@@ -566,7 +576,7 @@ function z(e, t) {
|
|
|
566
576
|
}
|
|
567
577
|
function Te(e) {
|
|
568
578
|
let t = ["Exige scanner capture report", `time: ${e.capturedAt ?? (/* @__PURE__ */ new Date()).toISOString()}`];
|
|
569
|
-
if (e.error && t.push(`error: ${e.error}`), e.captureMethod && t.push(`method: ${e.captureMethod}`), e.luminance !== void 0 && t.push(`luminance: ${e.luminance.toFixed(1)}`), e.fallbackReason && t.push(`fallback: ${e.fallbackReason}`), e.shutter && t.push(
|
|
579
|
+
if (e.error && t.push(`error: ${e.error}`), e.captureMethod && t.push(`method: ${e.captureMethod}`), e.luminance !== void 0 && t.push(`luminance: ${e.luminance.toFixed(1)}`), e.fallbackReason && t.push(`fallback: ${e.fallbackReason}`), e.shutter && t.push(V("shutter", e.shutter)), e.live && t.push(V("live", e.live)), e.finder) {
|
|
570
580
|
let n = e.finder;
|
|
571
581
|
t.push([
|
|
572
582
|
"finder:",
|
|
@@ -583,7 +593,7 @@ function Te(e) {
|
|
|
583
593
|
}
|
|
584
594
|
return `${t.join("\n")}\n`;
|
|
585
595
|
}
|
|
586
|
-
function
|
|
596
|
+
function H(e = typeof navigator > "u" ? "" : navigator.userAgent, t = typeof navigator > "u" ? 0 : navigator.maxTouchPoints) {
|
|
587
597
|
let n = /CriOS|Chrome/i.test(e) ? "chrome" : /EdgiOS|Edg/i.test(e) ? "edge" : /FxiOS|Firefox/i.test(e) ? "firefox" : /Safari/i.test(e) ? "safari" : "unknown", r = /iPhone|iPad|iPod/i.test(e) || /Macintosh/i.test(e) && t > 1, i = /CriOS|EdgiOS|FxiOS|OPiOS|Mercury/i.test(e), a = r || i;
|
|
588
598
|
return {
|
|
589
599
|
engine: a || /AppleWebKit/i.test(e) && !/Chrome|Chromium|Edg/i.test(e) ? "webkit" : /Chrome|Chromium|Edg/i.test(e) ? "blink" : /Gecko\//i.test(e) ? "gecko" : "unknown",
|
|
@@ -592,31 +602,37 @@ function B(e = typeof navigator > "u" ? "" : navigator.userAgent, t = typeof nav
|
|
|
592
602
|
userAgent: e
|
|
593
603
|
};
|
|
594
604
|
}
|
|
595
|
-
function
|
|
605
|
+
function U(e) {
|
|
606
|
+
return /Android/i.test(e.userAgent) && !e.iosWebKit;
|
|
607
|
+
}
|
|
608
|
+
function Ee(e = "auto", t = H()) {
|
|
609
|
+
return e === "system-camera" || e !== "live" && U(t);
|
|
610
|
+
}
|
|
611
|
+
function De(e, t) {
|
|
596
612
|
return t && !e.iosWebKit;
|
|
597
613
|
}
|
|
598
|
-
function
|
|
614
|
+
function W(e, t) {
|
|
599
615
|
if (!e || !Number.isFinite(e)) return;
|
|
600
616
|
let n = t?.max;
|
|
601
617
|
if (!n || !Number.isFinite(n)) return Math.round(e);
|
|
602
618
|
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;
|
|
603
619
|
return Math.round(Math.min(n, Math.max(r, a)));
|
|
604
620
|
}
|
|
605
|
-
function
|
|
606
|
-
let t =
|
|
621
|
+
function Oe(e) {
|
|
622
|
+
let t = W(e?.imageWidth?.max ?? 0, e?.imageWidth), n = W(e?.imageHeight?.max ?? 0, e?.imageHeight);
|
|
607
623
|
if (t && n) return t >= n ? { imageWidth: t } : { imageHeight: n };
|
|
608
624
|
if (t) return { imageWidth: t };
|
|
609
625
|
if (n) return { imageHeight: n };
|
|
610
626
|
}
|
|
611
|
-
function
|
|
627
|
+
function ke(e, t) {
|
|
612
628
|
return !e.width || !e.height || !t.width || !t.height ? !1 : e.width * e.height > t.width * t.height * 1.15;
|
|
613
629
|
}
|
|
614
|
-
function
|
|
630
|
+
function Ae(e, t) {
|
|
615
631
|
if (!e.width || !e.height || !t.width || !t.height) return !1;
|
|
616
632
|
let n = e.width / e.height / (t.width / t.height);
|
|
617
633
|
return n > .97 && n < 1.03;
|
|
618
634
|
}
|
|
619
|
-
var
|
|
635
|
+
var je = 10, G = class {
|
|
620
636
|
on = !1;
|
|
621
637
|
darkCount = 0;
|
|
622
638
|
brightCount = 0;
|
|
@@ -639,7 +655,7 @@ var Ae = 10, H = class {
|
|
|
639
655
|
return this.on;
|
|
640
656
|
}
|
|
641
657
|
};
|
|
642
|
-
function
|
|
658
|
+
function K(e, t) {
|
|
643
659
|
return t ? e === "alwaysOn" || e === "alwaysOff" ? {
|
|
644
660
|
mode: e,
|
|
645
661
|
supported: !0,
|
|
@@ -663,37 +679,37 @@ function U(e, t) {
|
|
|
663
679
|
automatic: e === "auto"
|
|
664
680
|
};
|
|
665
681
|
}
|
|
666
|
-
function
|
|
682
|
+
function q(e) {
|
|
667
683
|
let t = Math.floor(e.length / 4);
|
|
668
684
|
if (!t) return 0;
|
|
669
685
|
let n = 0;
|
|
670
686
|
for (let r = 0; r < t * 4; r += 4) n += e[r] * .299 + e[r + 1] * .587 + e[r + 2] * .114;
|
|
671
687
|
return n / t;
|
|
672
688
|
}
|
|
673
|
-
function
|
|
689
|
+
function Me(e, t = 10) {
|
|
674
690
|
if (e.length < 4) return !0;
|
|
675
691
|
let n = Math.floor(e.length / 4), r = 0;
|
|
676
692
|
for (let i = 0; i < n * 4; i += 4) e[i] * .299 + e[i + 1] * .587 + e[i + 2] * .114 > t * 2 && (r += 1);
|
|
677
|
-
return
|
|
693
|
+
return q(e) <= t && r / n < .01;
|
|
678
694
|
}
|
|
679
|
-
function
|
|
695
|
+
function Ne(e, t, n) {
|
|
680
696
|
if (!t || !n) return 0;
|
|
681
697
|
let r = document.createElement("canvas");
|
|
682
698
|
r.width = Math.min(32, t), r.height = Math.min(32, n);
|
|
683
699
|
let i = r.getContext("2d", { willReadFrequently: !0 });
|
|
684
|
-
return i ? (i.drawImage(e, 0, 0, r.width, r.height),
|
|
700
|
+
return i ? (i.drawImage(e, 0, 0, r.width, r.height), q(i.getImageData(0, 0, r.width, r.height).data)) : 0;
|
|
685
701
|
}
|
|
686
|
-
function
|
|
687
|
-
return
|
|
702
|
+
function Pe(e) {
|
|
703
|
+
return Ne(e, e.width, e.height);
|
|
688
704
|
}
|
|
689
|
-
function
|
|
705
|
+
function Fe(e, t = 120) {
|
|
690
706
|
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 = () => {
|
|
691
707
|
a && (o = i ? e.requestVideoFrameCallback(f) : requestAnimationFrame(f));
|
|
692
708
|
};
|
|
693
709
|
function f() {
|
|
694
710
|
if (!a) return;
|
|
695
711
|
let { videoWidth: i, videoHeight: o } = e, f = performance.now();
|
|
696
|
-
r && i && o && f - s >= t && (s = f, l =
|
|
712
|
+
r && i && o && f - s >= t && (s = f, l = Ne(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();
|
|
697
713
|
}
|
|
698
714
|
return d(), {
|
|
699
715
|
stop() {
|
|
@@ -705,14 +721,14 @@ function Me(e, t = 120) {
|
|
|
705
721
|
getMirrorAgeMs: () => c ? performance.now() - c : Infinity
|
|
706
722
|
};
|
|
707
723
|
}
|
|
708
|
-
function
|
|
724
|
+
function Ie(e) {
|
|
709
725
|
let t = document.createElement("canvas");
|
|
710
726
|
return t.width = e.width, t.height = e.height, t.getContext("2d")?.drawImage(e, 0, 0), t;
|
|
711
727
|
}
|
|
712
|
-
function
|
|
728
|
+
function Le(e) {
|
|
713
729
|
return e.engine === "blink";
|
|
714
730
|
}
|
|
715
|
-
function
|
|
731
|
+
function J(e = {}, t = H()) {
|
|
716
732
|
let n = { ideal: e.idealWidth ?? 3840 }, r = { ideal: e.idealHeight ?? 2160 };
|
|
717
733
|
e.maxWidth && (n.max = e.maxWidth), e.maxHeight && (r.max = e.maxHeight);
|
|
718
734
|
let i = {
|
|
@@ -724,20 +740,20 @@ function q(e = {}, t = B()) {
|
|
|
724
740
|
max: e.maxFrameRate ?? 30
|
|
725
741
|
}
|
|
726
742
|
};
|
|
727
|
-
return
|
|
743
|
+
return Le(t) && (i.resizeMode = { ideal: "none" }), {
|
|
728
744
|
audio: !1,
|
|
729
745
|
video: i
|
|
730
746
|
};
|
|
731
747
|
}
|
|
732
|
-
function
|
|
748
|
+
function Re(e, t, n) {
|
|
733
749
|
let r = n ? Math.min(1, n / Math.max(e, t)) : 1;
|
|
734
750
|
return {
|
|
735
751
|
width: Math.max(1, Math.round(e * r)),
|
|
736
752
|
height: Math.max(1, Math.round(t * r))
|
|
737
753
|
};
|
|
738
754
|
}
|
|
739
|
-
var
|
|
740
|
-
function
|
|
755
|
+
var ze = 4096;
|
|
756
|
+
function Be(e, t) {
|
|
741
757
|
let n = e.width, r = e.height, i = t?.width?.max, a = t?.height?.max;
|
|
742
758
|
if (!n || !r || !i || !a) return;
|
|
743
759
|
let o = Math.min(i / n, a / r);
|
|
@@ -746,13 +762,13 @@ function Le(e, t) {
|
|
|
746
762
|
height: { ideal: Math.round(r * o) }
|
|
747
763
|
};
|
|
748
764
|
}
|
|
749
|
-
async function
|
|
750
|
-
let t =
|
|
765
|
+
async function Ve(e) {
|
|
766
|
+
let t = Be(e.getSettings(), typeof e.getCapabilities == "function" ? e.getCapabilities() : void 0);
|
|
751
767
|
if (t) try {
|
|
752
768
|
await e.applyConstraints(t);
|
|
753
769
|
} catch {}
|
|
754
770
|
}
|
|
755
|
-
async function
|
|
771
|
+
async function He(e) {
|
|
756
772
|
try {
|
|
757
773
|
return await createImageBitmap(e, {
|
|
758
774
|
imageOrientation: "from-image",
|
|
@@ -762,7 +778,7 @@ async function ze(e) {
|
|
|
762
778
|
return await createImageBitmap(e);
|
|
763
779
|
}
|
|
764
780
|
}
|
|
765
|
-
async function
|
|
781
|
+
async function Ue(e) {
|
|
766
782
|
try {
|
|
767
783
|
await e.applyConstraints({ advanced: [{ pointsOfInterest: [{
|
|
768
784
|
x: .5,
|
|
@@ -770,25 +786,25 @@ async function Be(e) {
|
|
|
770
786
|
}] }] }), await new Promise((e) => window.setTimeout(e, 180));
|
|
771
787
|
} catch {}
|
|
772
788
|
}
|
|
773
|
-
async function
|
|
774
|
-
let n = await
|
|
789
|
+
async function We(e) {
|
|
790
|
+
let n = await He(e), r = Re(n.width, n.height, ze), i = document.createElement("canvas");
|
|
775
791
|
i.width = r.width, i.height = r.height;
|
|
776
792
|
let a = i.getContext("2d");
|
|
777
793
|
if (!a) throw n.close?.(), t();
|
|
778
794
|
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;
|
|
779
795
|
}
|
|
780
|
-
async function
|
|
796
|
+
async function Ge(e) {
|
|
781
797
|
let t = globalThis.ImageCapture;
|
|
782
798
|
if (!t) return;
|
|
783
|
-
await
|
|
784
|
-
let n = new t(e), r = n.getPhotoCapabilities ? await n.getPhotoCapabilities() : void 0, i =
|
|
799
|
+
await Ue(e);
|
|
800
|
+
let n = new t(e), r = n.getPhotoCapabilities ? await n.getPhotoCapabilities() : void 0, i = Oe(r), a;
|
|
785
801
|
try {
|
|
786
802
|
a = await n.takePhoto(i);
|
|
787
803
|
} catch {
|
|
788
804
|
a = await n.takePhoto();
|
|
789
805
|
}
|
|
790
806
|
return {
|
|
791
|
-
frame: await
|
|
807
|
+
frame: await We(a),
|
|
792
808
|
requested: i,
|
|
793
809
|
photoMax: {
|
|
794
810
|
width: r?.imageWidth?.max,
|
|
@@ -796,42 +812,42 @@ async function He(e) {
|
|
|
796
812
|
}
|
|
797
813
|
};
|
|
798
814
|
}
|
|
799
|
-
function
|
|
815
|
+
function Y(e, n) {
|
|
800
816
|
if (!e.videoWidth || !e.videoHeight) throw Error("The camera is not ready to capture a frame.");
|
|
801
|
-
let r =
|
|
817
|
+
let r = Re(e.videoWidth, e.videoHeight, n), i = document.createElement("canvas");
|
|
802
818
|
i.width = r.width, i.height = r.height;
|
|
803
819
|
let a = i.getContext("2d");
|
|
804
820
|
if (!a) throw t();
|
|
805
821
|
return a.drawImage(e, 0, 0, i.width, i.height), i;
|
|
806
822
|
}
|
|
807
|
-
function
|
|
808
|
-
let t =
|
|
809
|
-
return e.idealWidth || e.idealHeight || e.maxWidth || e.maxHeight ? [
|
|
810
|
-
|
|
823
|
+
function Ke(e) {
|
|
824
|
+
let t = H();
|
|
825
|
+
return e.idealWidth || e.idealHeight || e.maxWidth || e.maxHeight ? [J(e, t)] : [
|
|
826
|
+
J({
|
|
811
827
|
...e,
|
|
812
828
|
idealWidth: 3840,
|
|
813
829
|
idealHeight: 2160
|
|
814
830
|
}, t),
|
|
815
|
-
|
|
831
|
+
J({
|
|
816
832
|
...e,
|
|
817
833
|
idealWidth: 2560,
|
|
818
834
|
idealHeight: 1440
|
|
819
835
|
}, t),
|
|
820
|
-
|
|
836
|
+
J({
|
|
821
837
|
...e,
|
|
822
838
|
idealWidth: 1920,
|
|
823
839
|
idealHeight: 1080
|
|
824
840
|
}, t)
|
|
825
841
|
];
|
|
826
842
|
}
|
|
827
|
-
async function
|
|
843
|
+
async function qe(t, n = {}) {
|
|
828
844
|
await x("scan");
|
|
829
845
|
let r = n.torch ?? "alwaysOff";
|
|
830
846
|
if (r !== "alwaysOff" && await x("torch"), !window.isSecureContext && location.hostname !== "localhost") throw new e("secure-context", "Camera access requires HTTPS.");
|
|
831
847
|
if (!navigator.mediaDevices?.getUserMedia) throw Error("Live camera access is unavailable. Use the native camera picker instead.");
|
|
832
848
|
t.muted = !0, t.autoplay = !0, t.playsInline = !0, t.setAttribute("playsinline", "");
|
|
833
849
|
let i, a;
|
|
834
|
-
for (let e of
|
|
850
|
+
for (let e of Ke(n)) try {
|
|
835
851
|
i = await navigator.mediaDevices.getUserMedia(e);
|
|
836
852
|
break;
|
|
837
853
|
} catch (e) {
|
|
@@ -844,8 +860,8 @@ async function We(t, n = {}) {
|
|
|
844
860
|
for (let e of i.getTracks()) e.stop();
|
|
845
861
|
throw Error("The camera did not provide a video track.");
|
|
846
862
|
}
|
|
847
|
-
await
|
|
848
|
-
let s =
|
|
863
|
+
await Ve(o);
|
|
864
|
+
let s = Fe(t), c = "ImageCapture" in globalThis, l = K(r, (typeof o.getCapabilities == "function" ? o.getCapabilities() : void 0)?.torch === !0), u = !1, d = async (e) => {
|
|
849
865
|
if (!l.supported || o.readyState !== "live") return !1;
|
|
850
866
|
try {
|
|
851
867
|
return await o.applyConstraints({ advanced: [{ torch: e }] }), l = {
|
|
@@ -863,7 +879,7 @@ async function We(t, n = {}) {
|
|
|
863
879
|
}
|
|
864
880
|
};
|
|
865
881
|
l.on && await d(!0);
|
|
866
|
-
let f = r === "auto" && l.supported ? new
|
|
882
|
+
let f = r === "auto" && l.supported ? new G() : void 0, p = f ? window.setInterval(() => {
|
|
867
883
|
if (u || !l.supported) return;
|
|
868
884
|
let e = f.update(s.getLiveLuminance());
|
|
869
885
|
e !== void 0 && e !== l.on && (u = !0, d(e).finally(() => {
|
|
@@ -889,7 +905,7 @@ async function We(t, n = {}) {
|
|
|
889
905
|
torchSupported: l.supported,
|
|
890
906
|
torchOn: l.on,
|
|
891
907
|
torch: { ...l },
|
|
892
|
-
engine:
|
|
908
|
+
engine: H()
|
|
893
909
|
};
|
|
894
910
|
};
|
|
895
911
|
return {
|
|
@@ -903,17 +919,17 @@ async function We(t, n = {}) {
|
|
|
903
919
|
get torchOn() {
|
|
904
920
|
return l.on;
|
|
905
921
|
},
|
|
906
|
-
capture: (e) =>
|
|
922
|
+
capture: (e) => Y(t, e),
|
|
907
923
|
async capturePhoto() {
|
|
908
924
|
let e, n = 0;
|
|
909
925
|
try {
|
|
910
|
-
e =
|
|
926
|
+
e = Y(t), n = Pe(e);
|
|
911
927
|
} catch {
|
|
912
928
|
e = void 0;
|
|
913
929
|
}
|
|
914
930
|
let r = s.getFrame(), i, a = !1, l = !1, u, d;
|
|
915
|
-
if (
|
|
916
|
-
let e = await
|
|
931
|
+
if (De(H(), c)) try {
|
|
932
|
+
let e = await Ge(o);
|
|
917
933
|
i = e?.frame, u = e?.requested, d = e?.photoMax;
|
|
918
934
|
} catch {
|
|
919
935
|
a = !0, i = void 0;
|
|
@@ -921,14 +937,14 @@ async function We(t, n = {}) {
|
|
|
921
937
|
let f = {
|
|
922
938
|
width: t.videoWidth,
|
|
923
939
|
height: t.videoHeight
|
|
924
|
-
}, p = i ?
|
|
940
|
+
}, p = i ? Pe(i) : 0, h = !!(i && p > 10 && ke(i, f));
|
|
925
941
|
if (i && p > 10 && !h && (l = !0), h && i) return console.info("[exige-scanner] capture", {
|
|
926
942
|
method: "image-capture",
|
|
927
943
|
frame: `${i.width}×${i.height}`,
|
|
928
944
|
video: `${t.videoWidth}×${t.videoHeight}`,
|
|
929
945
|
photoMax: d ? `${d.width ?? "—"}×${d.height ?? "—"}` : void 0,
|
|
930
946
|
photoRequest: u,
|
|
931
|
-
aspectMatch:
|
|
947
|
+
aspectMatch: Ae(i, f)
|
|
932
948
|
}), {
|
|
933
949
|
frame: i,
|
|
934
950
|
method: "image-capture",
|
|
@@ -936,7 +952,7 @@ async function We(t, n = {}) {
|
|
|
936
952
|
luminance: p,
|
|
937
953
|
diagnostics: m()
|
|
938
954
|
};
|
|
939
|
-
let g = e && n > 10 ? e : void 0, _ = g ?? (r ?
|
|
955
|
+
let g = e && n > 10 ? e : void 0, _ = g ?? (r ? Ie(r) : void 0);
|
|
940
956
|
if (!_) throw Error("The camera preview produced no visible pixels. Keep the scanner on screen, wait for the preview, and retake.");
|
|
941
957
|
let v = l ? "image-capture-preview-size" : i ? "image-capture-empty" : a ? "image-capture-failed" : g ? void 0 : "video-frame-empty";
|
|
942
958
|
return console.info("[exige-scanner] capture", {
|
|
@@ -968,9 +984,13 @@ async function We(t, n = {}) {
|
|
|
968
984
|
}
|
|
969
985
|
};
|
|
970
986
|
}
|
|
971
|
-
|
|
987
|
+
function Je() {
|
|
988
|
+
let e = typeof navigator > "u" ? void 0 : navigator.userActivation;
|
|
989
|
+
return !e || e.isActive;
|
|
990
|
+
}
|
|
991
|
+
async function Ye() {
|
|
972
992
|
let e = document.createElement("input");
|
|
973
|
-
return e.type = "file", e.accept = "image/*", e.capture = "environment", e.setAttribute("capture", "environment"),
|
|
993
|
+
return e.type = "file", e.accept = "image/*", e.capture = "environment", e.setAttribute("capture", "environment"), We(await new Promise((t, n) => {
|
|
974
994
|
e.addEventListener("change", () => {
|
|
975
995
|
let r = e.files?.[0];
|
|
976
996
|
r ? t(r) : n(/* @__PURE__ */ Error("No photo was selected."));
|
|
@@ -981,12 +1001,12 @@ async function Ge() {
|
|
|
981
1001
|
}
|
|
982
1002
|
//#endregion
|
|
983
1003
|
//#region src/sdk/lighting.ts
|
|
984
|
-
function
|
|
1004
|
+
function Xe(e, t) {
|
|
985
1005
|
if (!e.length) return 0;
|
|
986
1006
|
let n = [...e].sort((e, t) => e - t);
|
|
987
1007
|
return n[Math.min(n.length - 1, Math.floor(n.length * t))];
|
|
988
1008
|
}
|
|
989
|
-
function
|
|
1009
|
+
function Ze(e, t, n, r = 12) {
|
|
990
1010
|
if (!t || !n || e.length < t * n) return {
|
|
991
1011
|
strong: !1,
|
|
992
1012
|
strength: 0,
|
|
@@ -1009,7 +1029,7 @@ function qe(e, t, n, r = 12) {
|
|
|
1009
1029
|
});
|
|
1010
1030
|
}
|
|
1011
1031
|
}
|
|
1012
|
-
let s =
|
|
1032
|
+
let s = Xe(o.map((e) => e.mean), .8), c = o.map((e) => s - e.mean >= 24 && e.mean >= 35), l = new Uint8Array(o.length), u = [];
|
|
1013
1033
|
for (let e = 0; e < o.length; e += 1) {
|
|
1014
1034
|
if (!c[e] || l[e]) continue;
|
|
1015
1035
|
let t = [], n = [e];
|
|
@@ -1057,11 +1077,11 @@ function qe(e, t, n, r = 12) {
|
|
|
1057
1077
|
}
|
|
1058
1078
|
return d;
|
|
1059
1079
|
}
|
|
1060
|
-
function
|
|
1080
|
+
function Qe(e, t, n, r, i, a, o) {
|
|
1061
1081
|
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));
|
|
1062
1082
|
return (e[c * t + u] - e[s * t + u] - e[c * t + l] + e[s * t + l]) / d;
|
|
1063
1083
|
}
|
|
1064
|
-
function
|
|
1084
|
+
function $e(e, t, n) {
|
|
1065
1085
|
let r = t + 1, i = new Uint32Array((t + 1) * (n + 1));
|
|
1066
1086
|
for (let a = 1; a <= n; a += 1) {
|
|
1067
1087
|
let n = 0;
|
|
@@ -1072,23 +1092,23 @@ function Y(e, t, n) {
|
|
|
1072
1092
|
stride: r
|
|
1073
1093
|
};
|
|
1074
1094
|
}
|
|
1075
|
-
function
|
|
1076
|
-
let { integral: i, stride: a } =
|
|
1095
|
+
function et(e, t, n, r = Math.max(12, Math.round(Math.max(t, n) / 32))) {
|
|
1096
|
+
let { integral: i, stride: a } = $e(e, t, n), o = new Uint8Array(e.length);
|
|
1077
1097
|
for (let s = 0; s < n; s += 1) for (let c = 0; c < t; c += 1) {
|
|
1078
|
-
let l =
|
|
1098
|
+
let l = Qe(i, a, t, n, c, s, r);
|
|
1079
1099
|
o[s * t + c] = Math.max(0, Math.min(255, Math.round(e[s * t + c] * 235 / Math.max(24, l))));
|
|
1080
1100
|
}
|
|
1081
1101
|
return o;
|
|
1082
1102
|
}
|
|
1083
|
-
function
|
|
1084
|
-
let { integral: a, stride: o } =
|
|
1103
|
+
function tt(e, t, n, r = Math.max(8, Math.round(Math.max(t, n) / 64)), i = .12) {
|
|
1104
|
+
let { integral: a, stride: o } = $e(e, t, n), s = new Uint8Array(e.length), c = 1 - i;
|
|
1085
1105
|
for (let i = 0; i < n; i += 1) for (let l = 0; l < t; l += 1) {
|
|
1086
|
-
let u =
|
|
1106
|
+
let u = Qe(a, o, t, n, l, i, r);
|
|
1087
1107
|
s[i * t + l] = e[i * t + l] < u * c ? 0 : 255;
|
|
1088
1108
|
}
|
|
1089
1109
|
return s;
|
|
1090
1110
|
}
|
|
1091
|
-
function
|
|
1111
|
+
function nt(e, t, n) {
|
|
1092
1112
|
let r = [
|
|
1093
1113
|
e.topLeft,
|
|
1094
1114
|
e.topRight,
|
|
@@ -1102,8 +1122,8 @@ function Ze(e, t, n) {
|
|
|
1102
1122
|
height: s - a
|
|
1103
1123
|
};
|
|
1104
1124
|
}
|
|
1105
|
-
function
|
|
1106
|
-
let n =
|
|
1125
|
+
function rt(e, t) {
|
|
1126
|
+
let n = nt(t, e.width, e.height);
|
|
1107
1127
|
if (n.width <= 0 || n.height <= 0) return {
|
|
1108
1128
|
strong: !1,
|
|
1109
1129
|
strength: 0,
|
|
@@ -1122,18 +1142,18 @@ function Qe(e, t) {
|
|
|
1122
1142
|
i.drawImage(e, n.left, n.top, n.width, n.height, 0, 0, r.width, r.height);
|
|
1123
1143
|
let a = i.getImageData(0, 0, r.width, r.height).data, o = new Uint8Array(r.width * r.height);
|
|
1124
1144
|
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);
|
|
1125
|
-
return
|
|
1145
|
+
return Ze(o, r.width, r.height);
|
|
1126
1146
|
}
|
|
1127
1147
|
//#endregion
|
|
1128
1148
|
//#region src/sdk/finder.ts
|
|
1129
|
-
function
|
|
1149
|
+
function it(e, t) {
|
|
1130
1150
|
return t.castShadow && (e.reason === "hold-still" || e.reason === "ready") ? t.hint ?? e.hint : e.hint;
|
|
1131
1151
|
}
|
|
1132
|
-
async function
|
|
1152
|
+
async function at(e, t) {
|
|
1133
1153
|
let n = await e();
|
|
1134
1154
|
return t(), n;
|
|
1135
1155
|
}
|
|
1136
|
-
function
|
|
1156
|
+
function ot(e) {
|
|
1137
1157
|
return e === "alwaysOn" || e === "only" ? {
|
|
1138
1158
|
visible: !1,
|
|
1139
1159
|
checked: !0,
|
|
@@ -1156,7 +1176,7 @@ function X(e) {
|
|
|
1156
1176
|
e.bottomLeft
|
|
1157
1177
|
];
|
|
1158
1178
|
}
|
|
1159
|
-
function
|
|
1179
|
+
function st(e, t) {
|
|
1160
1180
|
let n = e.status === "success" && e.modelStatus !== "failed", r = {
|
|
1161
1181
|
status: e.status,
|
|
1162
1182
|
confidence: Number(e.confidence.toFixed(3)),
|
|
@@ -1179,7 +1199,7 @@ function nt(e, t) {
|
|
|
1179
1199
|
detail: r
|
|
1180
1200
|
};
|
|
1181
1201
|
}
|
|
1182
|
-
function
|
|
1202
|
+
function ct(e) {
|
|
1183
1203
|
let t = 0;
|
|
1184
1204
|
for (let n = 0; n < e.length; n += 1) {
|
|
1185
1205
|
let r = e[n], i = e[(n + 1) % e.length];
|
|
@@ -1197,23 +1217,23 @@ var Q = {
|
|
|
1197
1217
|
areaFill: 0,
|
|
1198
1218
|
aspectRatio: 1
|
|
1199
1219
|
};
|
|
1200
|
-
function
|
|
1220
|
+
function lt(e, t, n) {
|
|
1201
1221
|
let r = X(e), i = r.map(({ x: e }) => e), a = r.map(({ y: e }) => e), o = (Math.max(...i) - Math.min(...i)) / Math.max(1, t), s = (Math.max(...a) - Math.min(...a)) / Math.max(1, n), [c, l, u, d] = r, f = Math.max(Z(c, l), Z(d, u)), p = Math.max(Z(c, d), Z(l, u));
|
|
1202
1222
|
return {
|
|
1203
1223
|
widthFill: o,
|
|
1204
1224
|
heightFill: s,
|
|
1205
1225
|
limitingFill: Math.max(o, s),
|
|
1206
|
-
areaFill:
|
|
1226
|
+
areaFill: ct(r) / Math.max(1, t * n),
|
|
1207
1227
|
aspectRatio: Math.max(f, p) / Math.max(1, Math.min(f, p))
|
|
1208
1228
|
};
|
|
1209
1229
|
}
|
|
1210
|
-
function
|
|
1230
|
+
function ut(e, t, n, r = {}) {
|
|
1211
1231
|
let i = t ? r.exitFillRatio ?? .64 : r.minFillRatio ?? .72, a = r.highAspectRatio ?? 2.2;
|
|
1212
1232
|
if (e.aspectRatio < a) return i;
|
|
1213
1233
|
let o = t ? r.highAspectExitFillRatio : r.highAspectFillRatio;
|
|
1214
1234
|
return Math.min(o ?? i + .08, 1 - n * 2);
|
|
1215
1235
|
}
|
|
1216
|
-
function
|
|
1236
|
+
function dt(e, t, n = {}) {
|
|
1217
1237
|
let r = n.confidenceThreshold ?? .72;
|
|
1218
1238
|
if (e.status !== "success" || !e.quad || e.confidence < r || !e.sourceWidth || !e.sourceHeight) return {
|
|
1219
1239
|
hint: "Place the document in the frame",
|
|
@@ -1222,7 +1242,7 @@ function ot(e, t, n = {}) {
|
|
|
1222
1242
|
fill: Q,
|
|
1223
1243
|
readyForAutoCapture: !1
|
|
1224
1244
|
};
|
|
1225
|
-
let i = X(e.quad), a =
|
|
1245
|
+
let i = X(e.quad), a = lt(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;
|
|
1226
1246
|
if (i.some(({ x: t, y: n }) => t <= c || t >= e.sourceWidth - c || n <= l || n >= e.sourceHeight - l)) return {
|
|
1227
1247
|
hint: "Move farther away",
|
|
1228
1248
|
reason: "move-farther-away",
|
|
@@ -1237,7 +1257,7 @@ function ot(e, t, n = {}) {
|
|
|
1237
1257
|
fillRatio: o,
|
|
1238
1258
|
fill: a,
|
|
1239
1259
|
readyForAutoCapture: !1
|
|
1240
|
-
} : o <
|
|
1260
|
+
} : o < ut(a, t.previouslyReady === !0, s, n) ? {
|
|
1241
1261
|
hint: "Move closer",
|
|
1242
1262
|
reason: "move-closer",
|
|
1243
1263
|
fillRatio: o,
|
|
@@ -1279,14 +1299,14 @@ var $ = class {
|
|
|
1279
1299
|
};
|
|
1280
1300
|
}
|
|
1281
1301
|
};
|
|
1282
|
-
function
|
|
1302
|
+
function ft(e, n) {
|
|
1283
1303
|
let r = Math.min(1, n / Math.max(e.width, e.height)), i = document.createElement("canvas");
|
|
1284
1304
|
i.width = Math.max(1, Math.round(e.width * r)), i.height = Math.max(1, Math.round(e.height * r));
|
|
1285
1305
|
let a = i.getContext("2d");
|
|
1286
1306
|
if (!a) throw t();
|
|
1287
1307
|
return a.drawImage(e, 0, 0, i.width, i.height), i;
|
|
1288
1308
|
}
|
|
1289
|
-
function
|
|
1309
|
+
function pt() {
|
|
1290
1310
|
let e = window.AudioContext ?? window.webkitAudioContext;
|
|
1291
1311
|
if (!e) return;
|
|
1292
1312
|
let t = new e(), n = Math.round(t.sampleRate * .09), r = t.createBuffer(1, n, t.sampleRate), i = r.getChannelData(0);
|
|
@@ -1297,13 +1317,13 @@ function ct() {
|
|
|
1297
1317
|
let a = t.createBufferSource(), o = t.createBiquadFilter(), s = t.createGain();
|
|
1298
1318
|
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();
|
|
1299
1319
|
}
|
|
1300
|
-
async function
|
|
1320
|
+
async function mt(e) {
|
|
1301
1321
|
let t = document.createElement("video");
|
|
1302
1322
|
return t.muted = !0, t.autoplay = !0, t.playsInline = !0, t.srcObject = e, await t.play(), t;
|
|
1303
1323
|
}
|
|
1304
|
-
async function
|
|
1324
|
+
async function ht(t) {
|
|
1305
1325
|
await x("scan");
|
|
1306
|
-
let n =
|
|
1326
|
+
let n = ot(t.autoCapture), r = new $({
|
|
1307
1327
|
stableFrames: t.stableFrames ?? 4,
|
|
1308
1328
|
confidenceThreshold: t.confidenceThreshold ?? .72,
|
|
1309
1329
|
cornerTolerance: t.cornerTolerance ?? .024,
|
|
@@ -1312,7 +1332,7 @@ async function ut(t) {
|
|
|
1312
1332
|
minDimension: 220,
|
|
1313
1333
|
maxAnalysisDimension: 520,
|
|
1314
1334
|
...t.detection
|
|
1315
|
-
}, s = typeof MediaStream < "u" && t.source instanceof MediaStream ? await
|
|
1335
|
+
}, s = typeof MediaStream < "u" && t.source instanceof MediaStream ? await mt(t.source) : t.source, c = !0, l = !1, u = !1, d = 0, f, p = "", m = 0, h = {
|
|
1316
1336
|
state: "detecting",
|
|
1317
1337
|
confidence: 0,
|
|
1318
1338
|
guidance: {
|
|
@@ -1329,10 +1349,10 @@ async function ut(t) {
|
|
|
1329
1349
|
stableFrames: 0,
|
|
1330
1350
|
requiredStableFrames: t.stableFrames ?? 4,
|
|
1331
1351
|
autoCapture: { ...n }
|
|
1332
|
-
}, g = () => s instanceof HTMLCanvasElement ?
|
|
1352
|
+
}, g = () => s instanceof HTMLCanvasElement ? ft(s, i) : Y(s, i), _ = (e) => {
|
|
1333
1353
|
h = e, t.onStatus?.(e);
|
|
1334
1354
|
}, v = (e) => {
|
|
1335
|
-
let t =
|
|
1355
|
+
let t = st(e, s instanceof HTMLVideoElement ? {
|
|
1336
1356
|
width: s.videoWidth,
|
|
1337
1357
|
height: s.videoHeight
|
|
1338
1358
|
} : {
|
|
@@ -1347,11 +1367,11 @@ async function ut(t) {
|
|
|
1347
1367
|
l = !0;
|
|
1348
1368
|
let n;
|
|
1349
1369
|
try {
|
|
1350
|
-
n = await
|
|
1370
|
+
n = await at(t.captureFrame ?? g, () => {
|
|
1351
1371
|
_({
|
|
1352
1372
|
...h,
|
|
1353
1373
|
state: "captured"
|
|
1354
|
-
}), t.playShutterSound !== !1 &&
|
|
1374
|
+
}), t.playShutterSound !== !1 && pt(), y();
|
|
1355
1375
|
});
|
|
1356
1376
|
} catch (e) {
|
|
1357
1377
|
throw l = !1, e instanceof Error ? e : /* @__PURE__ */ Error("The camera frame could not be captured.");
|
|
@@ -1367,7 +1387,7 @@ async function ut(t) {
|
|
|
1367
1387
|
try {
|
|
1368
1388
|
let e = g(), i = await R(e, o);
|
|
1369
1389
|
f = i, v(i);
|
|
1370
|
-
let a = i.quad ?
|
|
1390
|
+
let a = i.quad ? rt(e, i.quad) : {
|
|
1371
1391
|
strong: !1,
|
|
1372
1392
|
strength: 0
|
|
1373
1393
|
}, s = a.strong ? {
|
|
@@ -1377,7 +1397,7 @@ async function ut(t) {
|
|
|
1377
1397
|
} : {
|
|
1378
1398
|
castShadow: !1,
|
|
1379
1399
|
strength: a.strength
|
|
1380
|
-
}, c = r.update(i), l =
|
|
1400
|
+
}, c = r.update(i), l = dt(i, {
|
|
1381
1401
|
...c,
|
|
1382
1402
|
previouslyReady: u
|
|
1383
1403
|
}, {
|
|
@@ -1459,6 +1479,6 @@ async function ut(t) {
|
|
|
1459
1479
|
};
|
|
1460
1480
|
}
|
|
1461
1481
|
//#endregion
|
|
1462
|
-
export { A,
|
|
1482
|
+
export { z as A, x as B, Ee as C, Ce as D, pe as E, A as F, y as H, ie as I, ne as L, B as M, de as N, R as O, fe as P, a as R, Ye as S, K as T, e as U, b as V, t as W, Je as _, dt as a, q as b, tt as c, G as d, je as f, Te as g, H as h, lt as i, we as j, j as k, Ze as l, Y as m, ot as n, it as o, ze as p, ut as r, ht as s, $ as t, et as u, U as v, qe as w, J as x, Me as y, o as z };
|
|
1463
1483
|
|
|
1464
|
-
//# sourceMappingURL=finder-
|
|
1484
|
+
//# sourceMappingURL=finder-BlN89ZeT.js.map
|