@exige/web-scanner-sdk 0.2.25 → 0.2.26
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-Dcg3mVJM.js} +117 -101
- package/dist/finder-Dcg3mVJM.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 +13 -1
- package/dist/react.d.ts +1 -1
- package/dist/react.js +387 -280
- package/dist/react.js.map +1 -1
- package/dist/scanner-sdk.js +322 -322
- package/dist/scanner-sdk.js.map +1 -1
- package/dist/sdk/camera.d.ts +18 -1
- package/dist/sdk/scan.d.ts +10 -0
- package/package.json +1 -1
- package/dist/finder-B3t_3g6Z.js.map +0 -1
package/README.md
CHANGED
|
@@ -138,7 +138,7 @@ The demo hosts a trained checkpoint at `/models/id-fields-yolox-nano.onnx`. **Se
|
|
|
138
138
|
|
|
139
139
|
`detectDocument` runs DocAligner and returns an ordered `DocumentQuad` with `topLeft`, `topRight`, `bottomRight`, `bottomLeft`, plus typed `top`, `right`, `bottom`, and `left` line segments. Outcomes are `success`, `no-document`, `low-confidence`, or `low-quality`. `scanDocument` uses that same quad for a projective perspective warp and includes the quad in its result.
|
|
140
140
|
|
|
141
|
-
On touch/mobile-class devices, analysis defaults to a 560px working image (1280px on the long edge when the page is tall) and runs in a module Worker when supported. Perspective output is capped at 4096px by default, the same long-edge memory cap as `capturePhoto()`. Override `maxAnalysisDimension`, `maxOutputDimension`, or `useWorker` in `ScanOptions` when needed. Chrome `takePhoto()` cannot match the Android Camera app (no HDR+ / OEM ISP).
|
|
141
|
+
On touch/mobile-class devices, analysis defaults to a 560px working image (1280px on the long edge when the page is tall) and runs in a module Worker when supported. Perspective output is capped at 4096px by default, the same long-edge memory cap as `capturePhoto()`. Override `maxAnalysisDimension`, `maxOutputDimension`, or `useWorker` in `ScanOptions` when needed. Chrome `takePhoto()` cannot match the Android Camera app (no HDR+ / OEM ISP). On Android, `ScannerProvider` `captureMode="auto"` (the default) opens that Camera app through `pickNativeCameraStill()`, then `scanSystemCameraStill()` crops the most prominent document. Hosts that want the live overlay on Android pass `captureMode="live"`. Force the picker on any platform with `captureMode="system-camera"`.
|
|
142
142
|
|
|
143
143
|
## Live finder and auto-capture
|
|
144
144
|
|
|
@@ -215,7 +215,7 @@ await setLicenseKey(licenseKey)
|
|
|
215
215
|
</ScannerProvider>
|
|
216
216
|
```
|
|
217
217
|
|
|
218
|
-
`useScanner()` reads the session inside the provider. `useScannerRef()` gives the parent an imperative handle, passed as `apiRef`, the same idea as MUI's `useGridApiRef`. The camera covers the viewport, respects safe areas, shows finder/permission/error states, and keeps the existing auto-capture policies.
|
|
218
|
+
`useScanner()` reads the session inside the provider. `useScannerRef()` gives the parent an imperative handle, passed as `apiRef`, the same idea as MUI's `useGridApiRef`. The camera covers the viewport, respects safe areas, shows finder/permission/error states, and keeps the existing auto-capture policies. On Android, `captureMode="auto"` skips the live preview and opens the system Camera app; DocAligner then finds the most prominent document on that JPEG. A miss stays on screen with **Try again**. iOS keeps the live overlay and auto-capture. The live path requests an ideal 4K rear-camera stream (no 1080×1920 Android cap), shows that stream in the preview, and continuously mirrors the last non-black frame. Outside WebKit, live capture uses `ImageCapture.takePhoto()` at max photo size and keeps the still even when its aspect differs from the preview; a still longer than 4096px is scaled with high-quality smoothing. WebKit `takePhoto()` returns black stills, so iOS copies the live preview or the mirrored frame. A genuinely blank capture fails loudly instead of exporting black pixels. Finder analysis stays on a 520–1600 working copy. Render `ScannerDiagnostics` for a live diagnostics panel with engine/browser, video and track state, luminance, and the chosen capture path; **Copy report** pastes a shutter-time dump for support. Pass `theme` to `ScannerFrame` to recolor the camera. `primaryColorHex` replaces the yellowish-green accents (`#c8ff45`). `seekingColorHex` and `detectingColorHex` are the waiting box colors (both `#ef6a5b` unless set apart), `unstableColorHex` is `#ffbe40`, `readyColorHex` is `#8af25a`, and `capturedColorHex` is `#ffffff`. Omit `theme` or any field to keep that default. The [React camera guide](site/guide/react-camera-overlay.md#theme) lists what each field paints. The demo source screen chooses Default, Ocean, Violet, or Signal before the camera starts and passes that palette as `theme` on `ScannerFrame`. Capture results include the displayed quad and its bounded-analysis dimensions; use `mapDocumentCornersToFrame()` plus `cropDocument()` so the final crop matches what was on screen. The framework-free imperative APIs remain available from the root package.
|
|
219
219
|
|
|
220
220
|
## Run the demo
|
|
221
221
|
|
|
@@ -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,9 @@ async function We(t, n = {}) {
|
|
|
968
984
|
}
|
|
969
985
|
};
|
|
970
986
|
}
|
|
971
|
-
async function
|
|
987
|
+
async function Je() {
|
|
972
988
|
let e = document.createElement("input");
|
|
973
|
-
return e.type = "file", e.accept = "image/*", e.capture = "environment", e.setAttribute("capture", "environment"),
|
|
989
|
+
return e.type = "file", e.accept = "image/*", e.capture = "environment", e.setAttribute("capture", "environment"), We(await new Promise((t, n) => {
|
|
974
990
|
e.addEventListener("change", () => {
|
|
975
991
|
let r = e.files?.[0];
|
|
976
992
|
r ? t(r) : n(/* @__PURE__ */ Error("No photo was selected."));
|
|
@@ -981,12 +997,12 @@ async function Ge() {
|
|
|
981
997
|
}
|
|
982
998
|
//#endregion
|
|
983
999
|
//#region src/sdk/lighting.ts
|
|
984
|
-
function
|
|
1000
|
+
function Ye(e, t) {
|
|
985
1001
|
if (!e.length) return 0;
|
|
986
1002
|
let n = [...e].sort((e, t) => e - t);
|
|
987
1003
|
return n[Math.min(n.length - 1, Math.floor(n.length * t))];
|
|
988
1004
|
}
|
|
989
|
-
function
|
|
1005
|
+
function Xe(e, t, n, r = 12) {
|
|
990
1006
|
if (!t || !n || e.length < t * n) return {
|
|
991
1007
|
strong: !1,
|
|
992
1008
|
strength: 0,
|
|
@@ -1009,7 +1025,7 @@ function qe(e, t, n, r = 12) {
|
|
|
1009
1025
|
});
|
|
1010
1026
|
}
|
|
1011
1027
|
}
|
|
1012
|
-
let s =
|
|
1028
|
+
let s = Ye(o.map((e) => e.mean), .8), c = o.map((e) => s - e.mean >= 24 && e.mean >= 35), l = new Uint8Array(o.length), u = [];
|
|
1013
1029
|
for (let e = 0; e < o.length; e += 1) {
|
|
1014
1030
|
if (!c[e] || l[e]) continue;
|
|
1015
1031
|
let t = [], n = [e];
|
|
@@ -1057,11 +1073,11 @@ function qe(e, t, n, r = 12) {
|
|
|
1057
1073
|
}
|
|
1058
1074
|
return d;
|
|
1059
1075
|
}
|
|
1060
|
-
function
|
|
1076
|
+
function Ze(e, t, n, r, i, a, o) {
|
|
1061
1077
|
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
1078
|
return (e[c * t + u] - e[s * t + u] - e[c * t + l] + e[s * t + l]) / d;
|
|
1063
1079
|
}
|
|
1064
|
-
function
|
|
1080
|
+
function Qe(e, t, n) {
|
|
1065
1081
|
let r = t + 1, i = new Uint32Array((t + 1) * (n + 1));
|
|
1066
1082
|
for (let a = 1; a <= n; a += 1) {
|
|
1067
1083
|
let n = 0;
|
|
@@ -1072,23 +1088,23 @@ function Y(e, t, n) {
|
|
|
1072
1088
|
stride: r
|
|
1073
1089
|
};
|
|
1074
1090
|
}
|
|
1075
|
-
function
|
|
1076
|
-
let { integral: i, stride: a } =
|
|
1091
|
+
function $e(e, t, n, r = Math.max(12, Math.round(Math.max(t, n) / 32))) {
|
|
1092
|
+
let { integral: i, stride: a } = Qe(e, t, n), o = new Uint8Array(e.length);
|
|
1077
1093
|
for (let s = 0; s < n; s += 1) for (let c = 0; c < t; c += 1) {
|
|
1078
|
-
let l =
|
|
1094
|
+
let l = Ze(i, a, t, n, c, s, r);
|
|
1079
1095
|
o[s * t + c] = Math.max(0, Math.min(255, Math.round(e[s * t + c] * 235 / Math.max(24, l))));
|
|
1080
1096
|
}
|
|
1081
1097
|
return o;
|
|
1082
1098
|
}
|
|
1083
|
-
function
|
|
1084
|
-
let { integral: a, stride: o } =
|
|
1099
|
+
function et(e, t, n, r = Math.max(8, Math.round(Math.max(t, n) / 64)), i = .12) {
|
|
1100
|
+
let { integral: a, stride: o } = Qe(e, t, n), s = new Uint8Array(e.length), c = 1 - i;
|
|
1085
1101
|
for (let i = 0; i < n; i += 1) for (let l = 0; l < t; l += 1) {
|
|
1086
|
-
let u =
|
|
1102
|
+
let u = Ze(a, o, t, n, l, i, r);
|
|
1087
1103
|
s[i * t + l] = e[i * t + l] < u * c ? 0 : 255;
|
|
1088
1104
|
}
|
|
1089
1105
|
return s;
|
|
1090
1106
|
}
|
|
1091
|
-
function
|
|
1107
|
+
function tt(e, t, n) {
|
|
1092
1108
|
let r = [
|
|
1093
1109
|
e.topLeft,
|
|
1094
1110
|
e.topRight,
|
|
@@ -1102,8 +1118,8 @@ function Ze(e, t, n) {
|
|
|
1102
1118
|
height: s - a
|
|
1103
1119
|
};
|
|
1104
1120
|
}
|
|
1105
|
-
function
|
|
1106
|
-
let n =
|
|
1121
|
+
function nt(e, t) {
|
|
1122
|
+
let n = tt(t, e.width, e.height);
|
|
1107
1123
|
if (n.width <= 0 || n.height <= 0) return {
|
|
1108
1124
|
strong: !1,
|
|
1109
1125
|
strength: 0,
|
|
@@ -1122,18 +1138,18 @@ function Qe(e, t) {
|
|
|
1122
1138
|
i.drawImage(e, n.left, n.top, n.width, n.height, 0, 0, r.width, r.height);
|
|
1123
1139
|
let a = i.getImageData(0, 0, r.width, r.height).data, o = new Uint8Array(r.width * r.height);
|
|
1124
1140
|
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
|
|
1141
|
+
return Xe(o, r.width, r.height);
|
|
1126
1142
|
}
|
|
1127
1143
|
//#endregion
|
|
1128
1144
|
//#region src/sdk/finder.ts
|
|
1129
|
-
function
|
|
1145
|
+
function rt(e, t) {
|
|
1130
1146
|
return t.castShadow && (e.reason === "hold-still" || e.reason === "ready") ? t.hint ?? e.hint : e.hint;
|
|
1131
1147
|
}
|
|
1132
|
-
async function
|
|
1148
|
+
async function it(e, t) {
|
|
1133
1149
|
let n = await e();
|
|
1134
1150
|
return t(), n;
|
|
1135
1151
|
}
|
|
1136
|
-
function
|
|
1152
|
+
function at(e) {
|
|
1137
1153
|
return e === "alwaysOn" || e === "only" ? {
|
|
1138
1154
|
visible: !1,
|
|
1139
1155
|
checked: !0,
|
|
@@ -1156,7 +1172,7 @@ function X(e) {
|
|
|
1156
1172
|
e.bottomLeft
|
|
1157
1173
|
];
|
|
1158
1174
|
}
|
|
1159
|
-
function
|
|
1175
|
+
function ot(e, t) {
|
|
1160
1176
|
let n = e.status === "success" && e.modelStatus !== "failed", r = {
|
|
1161
1177
|
status: e.status,
|
|
1162
1178
|
confidence: Number(e.confidence.toFixed(3)),
|
|
@@ -1179,7 +1195,7 @@ function nt(e, t) {
|
|
|
1179
1195
|
detail: r
|
|
1180
1196
|
};
|
|
1181
1197
|
}
|
|
1182
|
-
function
|
|
1198
|
+
function st(e) {
|
|
1183
1199
|
let t = 0;
|
|
1184
1200
|
for (let n = 0; n < e.length; n += 1) {
|
|
1185
1201
|
let r = e[n], i = e[(n + 1) % e.length];
|
|
@@ -1197,23 +1213,23 @@ var Q = {
|
|
|
1197
1213
|
areaFill: 0,
|
|
1198
1214
|
aspectRatio: 1
|
|
1199
1215
|
};
|
|
1200
|
-
function
|
|
1216
|
+
function ct(e, t, n) {
|
|
1201
1217
|
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
1218
|
return {
|
|
1203
1219
|
widthFill: o,
|
|
1204
1220
|
heightFill: s,
|
|
1205
1221
|
limitingFill: Math.max(o, s),
|
|
1206
|
-
areaFill:
|
|
1222
|
+
areaFill: st(r) / Math.max(1, t * n),
|
|
1207
1223
|
aspectRatio: Math.max(f, p) / Math.max(1, Math.min(f, p))
|
|
1208
1224
|
};
|
|
1209
1225
|
}
|
|
1210
|
-
function
|
|
1226
|
+
function lt(e, t, n, r = {}) {
|
|
1211
1227
|
let i = t ? r.exitFillRatio ?? .64 : r.minFillRatio ?? .72, a = r.highAspectRatio ?? 2.2;
|
|
1212
1228
|
if (e.aspectRatio < a) return i;
|
|
1213
1229
|
let o = t ? r.highAspectExitFillRatio : r.highAspectFillRatio;
|
|
1214
1230
|
return Math.min(o ?? i + .08, 1 - n * 2);
|
|
1215
1231
|
}
|
|
1216
|
-
function
|
|
1232
|
+
function ut(e, t, n = {}) {
|
|
1217
1233
|
let r = n.confidenceThreshold ?? .72;
|
|
1218
1234
|
if (e.status !== "success" || !e.quad || e.confidence < r || !e.sourceWidth || !e.sourceHeight) return {
|
|
1219
1235
|
hint: "Place the document in the frame",
|
|
@@ -1222,7 +1238,7 @@ function ot(e, t, n = {}) {
|
|
|
1222
1238
|
fill: Q,
|
|
1223
1239
|
readyForAutoCapture: !1
|
|
1224
1240
|
};
|
|
1225
|
-
let i = X(e.quad), a =
|
|
1241
|
+
let i = X(e.quad), a = ct(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
1242
|
if (i.some(({ x: t, y: n }) => t <= c || t >= e.sourceWidth - c || n <= l || n >= e.sourceHeight - l)) return {
|
|
1227
1243
|
hint: "Move farther away",
|
|
1228
1244
|
reason: "move-farther-away",
|
|
@@ -1237,7 +1253,7 @@ function ot(e, t, n = {}) {
|
|
|
1237
1253
|
fillRatio: o,
|
|
1238
1254
|
fill: a,
|
|
1239
1255
|
readyForAutoCapture: !1
|
|
1240
|
-
} : o <
|
|
1256
|
+
} : o < lt(a, t.previouslyReady === !0, s, n) ? {
|
|
1241
1257
|
hint: "Move closer",
|
|
1242
1258
|
reason: "move-closer",
|
|
1243
1259
|
fillRatio: o,
|
|
@@ -1279,14 +1295,14 @@ var $ = class {
|
|
|
1279
1295
|
};
|
|
1280
1296
|
}
|
|
1281
1297
|
};
|
|
1282
|
-
function
|
|
1298
|
+
function dt(e, n) {
|
|
1283
1299
|
let r = Math.min(1, n / Math.max(e.width, e.height)), i = document.createElement("canvas");
|
|
1284
1300
|
i.width = Math.max(1, Math.round(e.width * r)), i.height = Math.max(1, Math.round(e.height * r));
|
|
1285
1301
|
let a = i.getContext("2d");
|
|
1286
1302
|
if (!a) throw t();
|
|
1287
1303
|
return a.drawImage(e, 0, 0, i.width, i.height), i;
|
|
1288
1304
|
}
|
|
1289
|
-
function
|
|
1305
|
+
function ft() {
|
|
1290
1306
|
let e = window.AudioContext ?? window.webkitAudioContext;
|
|
1291
1307
|
if (!e) return;
|
|
1292
1308
|
let t = new e(), n = Math.round(t.sampleRate * .09), r = t.createBuffer(1, n, t.sampleRate), i = r.getChannelData(0);
|
|
@@ -1297,13 +1313,13 @@ function ct() {
|
|
|
1297
1313
|
let a = t.createBufferSource(), o = t.createBiquadFilter(), s = t.createGain();
|
|
1298
1314
|
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
1315
|
}
|
|
1300
|
-
async function
|
|
1316
|
+
async function pt(e) {
|
|
1301
1317
|
let t = document.createElement("video");
|
|
1302
1318
|
return t.muted = !0, t.autoplay = !0, t.playsInline = !0, t.srcObject = e, await t.play(), t;
|
|
1303
1319
|
}
|
|
1304
|
-
async function
|
|
1320
|
+
async function mt(t) {
|
|
1305
1321
|
await x("scan");
|
|
1306
|
-
let n =
|
|
1322
|
+
let n = at(t.autoCapture), r = new $({
|
|
1307
1323
|
stableFrames: t.stableFrames ?? 4,
|
|
1308
1324
|
confidenceThreshold: t.confidenceThreshold ?? .72,
|
|
1309
1325
|
cornerTolerance: t.cornerTolerance ?? .024,
|
|
@@ -1312,7 +1328,7 @@ async function ut(t) {
|
|
|
1312
1328
|
minDimension: 220,
|
|
1313
1329
|
maxAnalysisDimension: 520,
|
|
1314
1330
|
...t.detection
|
|
1315
|
-
}, s = typeof MediaStream < "u" && t.source instanceof MediaStream ? await
|
|
1331
|
+
}, s = typeof MediaStream < "u" && t.source instanceof MediaStream ? await pt(t.source) : t.source, c = !0, l = !1, u = !1, d = 0, f, p = "", m = 0, h = {
|
|
1316
1332
|
state: "detecting",
|
|
1317
1333
|
confidence: 0,
|
|
1318
1334
|
guidance: {
|
|
@@ -1329,10 +1345,10 @@ async function ut(t) {
|
|
|
1329
1345
|
stableFrames: 0,
|
|
1330
1346
|
requiredStableFrames: t.stableFrames ?? 4,
|
|
1331
1347
|
autoCapture: { ...n }
|
|
1332
|
-
}, g = () => s instanceof HTMLCanvasElement ?
|
|
1348
|
+
}, g = () => s instanceof HTMLCanvasElement ? dt(s, i) : Y(s, i), _ = (e) => {
|
|
1333
1349
|
h = e, t.onStatus?.(e);
|
|
1334
1350
|
}, v = (e) => {
|
|
1335
|
-
let t =
|
|
1351
|
+
let t = ot(e, s instanceof HTMLVideoElement ? {
|
|
1336
1352
|
width: s.videoWidth,
|
|
1337
1353
|
height: s.videoHeight
|
|
1338
1354
|
} : {
|
|
@@ -1347,11 +1363,11 @@ async function ut(t) {
|
|
|
1347
1363
|
l = !0;
|
|
1348
1364
|
let n;
|
|
1349
1365
|
try {
|
|
1350
|
-
n = await
|
|
1366
|
+
n = await it(t.captureFrame ?? g, () => {
|
|
1351
1367
|
_({
|
|
1352
1368
|
...h,
|
|
1353
1369
|
state: "captured"
|
|
1354
|
-
}), t.playShutterSound !== !1 &&
|
|
1370
|
+
}), t.playShutterSound !== !1 && ft(), y();
|
|
1355
1371
|
});
|
|
1356
1372
|
} catch (e) {
|
|
1357
1373
|
throw l = !1, e instanceof Error ? e : /* @__PURE__ */ Error("The camera frame could not be captured.");
|
|
@@ -1367,7 +1383,7 @@ async function ut(t) {
|
|
|
1367
1383
|
try {
|
|
1368
1384
|
let e = g(), i = await R(e, o);
|
|
1369
1385
|
f = i, v(i);
|
|
1370
|
-
let a = i.quad ?
|
|
1386
|
+
let a = i.quad ? nt(e, i.quad) : {
|
|
1371
1387
|
strong: !1,
|
|
1372
1388
|
strength: 0
|
|
1373
1389
|
}, s = a.strong ? {
|
|
@@ -1377,7 +1393,7 @@ async function ut(t) {
|
|
|
1377
1393
|
} : {
|
|
1378
1394
|
castShadow: !1,
|
|
1379
1395
|
strength: a.strength
|
|
1380
|
-
}, c = r.update(i), l =
|
|
1396
|
+
}, c = r.update(i), l = ut(i, {
|
|
1381
1397
|
...c,
|
|
1382
1398
|
previouslyReady: u
|
|
1383
1399
|
}, {
|
|
@@ -1459,6 +1475,6 @@ async function ut(t) {
|
|
|
1459
1475
|
};
|
|
1460
1476
|
}
|
|
1461
1477
|
//#endregion
|
|
1462
|
-
export { A,
|
|
1478
|
+
export { we as A, b as B, qe as C, R as D, Ce as E, ie as F, e as H, ne as I, a as L, de as M, fe as N, j as O, A as P, o as R, Ee as S, pe as T, t as U, y as V, U as _, ut as a, J as b, et as c, G as d, je as f, Te as g, H as h, ct as i, B as j, z as k, Xe as l, Y as m, at as n, rt as o, ze as p, lt as r, mt as s, $ as t, $e as u, Me as v, K as w, Je as x, q as y, x as z };
|
|
1463
1479
|
|
|
1464
|
-
//# sourceMappingURL=finder-
|
|
1480
|
+
//# sourceMappingURL=finder-Dcg3mVJM.js.map
|