@exige/web-scanner-sdk 0.2.22 → 0.2.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/{finder-kHZVA7ug.js → finder-CLTG1caj.js} +128 -105
- package/dist/finder-CLTG1caj.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/react.js +24 -24
- package/dist/scanner-sdk.js +177 -177
- package/dist/scanner-sdk.js.map +1 -1
- package/dist/sdk/camera.d.ts +40 -3
- package/package.json +1 -1
- package/dist/finder-kHZVA7ug.js.map +0 -1
package/README.md
CHANGED
|
@@ -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. It requests an ideal 4K rear-camera stream,
|
|
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. It requests an ideal 4K rear-camera stream on Android and iOS (no 1080×1920 Android cap), shows that stream in the preview, and continuously mirrors the last non-black frame. Outside WebKit, 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
|
|
|
@@ -184,7 +184,7 @@ function ee(e) {
|
|
|
184
184
|
let t = Number(e.headers.get("content-length"));
|
|
185
185
|
return Number.isFinite(t) && t > 0 ? t : null;
|
|
186
186
|
}
|
|
187
|
-
function
|
|
187
|
+
function O() {
|
|
188
188
|
if (w.size === 0) return {
|
|
189
189
|
downloading: !1,
|
|
190
190
|
loaded: 0,
|
|
@@ -198,22 +198,22 @@ function te() {
|
|
|
198
198
|
total: n ? t : null
|
|
199
199
|
};
|
|
200
200
|
}
|
|
201
|
-
function
|
|
202
|
-
let e =
|
|
201
|
+
function k() {
|
|
202
|
+
let e = O();
|
|
203
203
|
for (let t of T) t(e);
|
|
204
204
|
}
|
|
205
|
-
function
|
|
206
|
-
return e(
|
|
205
|
+
function te(e) {
|
|
206
|
+
return e(O()), T.add(e), () => {
|
|
207
207
|
T.delete(e);
|
|
208
208
|
};
|
|
209
209
|
}
|
|
210
|
-
function
|
|
210
|
+
function A(e, t) {
|
|
211
211
|
t.done ? w.delete(e) : w.set(e, {
|
|
212
212
|
loaded: t.loaded,
|
|
213
213
|
total: t.total
|
|
214
|
-
}),
|
|
214
|
+
}), k();
|
|
215
215
|
}
|
|
216
|
-
async function
|
|
216
|
+
async function ne(e, t) {
|
|
217
217
|
let n = ee(e);
|
|
218
218
|
if (!e.body) {
|
|
219
219
|
let r = await e.arrayBuffer();
|
|
@@ -238,42 +238,42 @@ async function re(e, t) {
|
|
|
238
238
|
total: n
|
|
239
239
|
}), o.buffer;
|
|
240
240
|
}
|
|
241
|
-
async function
|
|
241
|
+
async function re(t, n) {
|
|
242
242
|
let r = E.get(t);
|
|
243
243
|
if (r) return r.slice(0);
|
|
244
244
|
let i = D.get(t);
|
|
245
245
|
if (i) return i.then((e) => e.slice(0));
|
|
246
246
|
let a = (async () => {
|
|
247
|
-
|
|
247
|
+
A(t, {
|
|
248
248
|
loaded: 0,
|
|
249
249
|
total: null
|
|
250
250
|
});
|
|
251
251
|
let r = await fetch(t, { cache: n?.cache });
|
|
252
252
|
if (!r.ok) throw new e("model-http", `Model request failed with HTTP ${r.status}.`);
|
|
253
|
-
return
|
|
253
|
+
return ne(r, (e) => A(t, e));
|
|
254
254
|
})();
|
|
255
255
|
D.set(t, a);
|
|
256
256
|
try {
|
|
257
257
|
let e = await a;
|
|
258
258
|
return E.set(t, e), e.slice(0);
|
|
259
259
|
} finally {
|
|
260
|
-
D.delete(t), w.has(t) && (w.delete(t),
|
|
260
|
+
D.delete(t), w.has(t) && (w.delete(t), k());
|
|
261
261
|
}
|
|
262
262
|
}
|
|
263
263
|
//#endregion
|
|
264
264
|
//#region src/sdk/ort-runtime.ts
|
|
265
|
-
var
|
|
266
|
-
function
|
|
265
|
+
var ie = new URL("./assets/ort-wasm-simd-threaded.jsep.wasm", import.meta.url), ae = new URL("./assets/ort-wasm-simd-threaded.jsep.mjs", import.meta.url);
|
|
266
|
+
function oe() {
|
|
267
267
|
return {
|
|
268
|
-
wasm:
|
|
269
|
-
mjs:
|
|
268
|
+
wasm: ie.href,
|
|
269
|
+
mjs: ae.href
|
|
270
270
|
};
|
|
271
271
|
}
|
|
272
272
|
function se(e) {
|
|
273
|
-
return typeof e == "string" ? e.trim() ||
|
|
273
|
+
return typeof e == "string" ? e.trim() || oe() : e?.wasm.trim() && e.mjs.trim() ? {
|
|
274
274
|
wasm: e.wasm.trim(),
|
|
275
275
|
mjs: e.mjs.trim()
|
|
276
|
-
} :
|
|
276
|
+
} : oe();
|
|
277
277
|
}
|
|
278
278
|
//#endregion
|
|
279
279
|
//#region src/sdk/image.ts
|
|
@@ -378,7 +378,7 @@ function _e(t, n, r, i) {
|
|
|
378
378
|
return new Promise((a, o) => {
|
|
379
379
|
P || (P = new Worker(new URL("./assets/document-worker.js", import.meta.url), { type: "module" }), P.onmessage = (t) => {
|
|
380
380
|
if (t.data.download?.url) {
|
|
381
|
-
|
|
381
|
+
A(t.data.download.url, t.data.download);
|
|
382
382
|
return;
|
|
383
383
|
}
|
|
384
384
|
let n = F.get(t.data.id);
|
|
@@ -700,30 +700,50 @@ function Me(e) {
|
|
|
700
700
|
let t = document.createElement("canvas");
|
|
701
701
|
return t.width = e.width, t.height = e.height, t.getContext("2d")?.drawImage(e, 0, 0), t;
|
|
702
702
|
}
|
|
703
|
-
function
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
703
|
+
function Ne(e) {
|
|
704
|
+
return e.engine === "blink";
|
|
705
|
+
}
|
|
706
|
+
function K(e = {}, t = B()) {
|
|
707
|
+
let n = { ideal: e.idealWidth ?? 3840 }, r = { ideal: e.idealHeight ?? 2160 };
|
|
708
|
+
e.maxWidth && (n.max = e.maxWidth), e.maxHeight && (r.max = e.maxHeight);
|
|
709
|
+
let i = {
|
|
710
|
+
facingMode: { ideal: e.facingMode ?? "environment" },
|
|
711
|
+
width: n,
|
|
712
|
+
height: r,
|
|
713
|
+
frameRate: {
|
|
714
|
+
ideal: e.maxFrameRate ?? 30,
|
|
715
|
+
max: e.maxFrameRate ?? 30
|
|
715
716
|
}
|
|
716
717
|
};
|
|
718
|
+
return Ne(t) && (i.resizeMode = { ideal: "none" }), {
|
|
719
|
+
audio: !1,
|
|
720
|
+
video: i
|
|
721
|
+
};
|
|
717
722
|
}
|
|
718
|
-
function
|
|
723
|
+
function q(e, t, n) {
|
|
719
724
|
let r = n ? Math.min(1, n / Math.max(e, t)) : 1;
|
|
720
725
|
return {
|
|
721
726
|
width: Math.max(1, Math.round(e * r)),
|
|
722
727
|
height: Math.max(1, Math.round(t * r))
|
|
723
728
|
};
|
|
724
729
|
}
|
|
725
|
-
var
|
|
730
|
+
var J = 4096;
|
|
731
|
+
function Pe(e, t) {
|
|
732
|
+
let n = e.width, r = e.height, i = t?.width?.max, a = t?.height?.max;
|
|
733
|
+
if (!n || !r || !i || !a) return;
|
|
734
|
+
let o = Math.min(i / n, a / r);
|
|
735
|
+
if (!(o <= 1.05)) return {
|
|
736
|
+
width: { ideal: Math.round(n * o) },
|
|
737
|
+
height: { ideal: Math.round(r * o) }
|
|
738
|
+
};
|
|
739
|
+
}
|
|
726
740
|
async function Fe(e) {
|
|
741
|
+
let t = Pe(e.getSettings(), typeof e.getCapabilities == "function" ? e.getCapabilities() : void 0);
|
|
742
|
+
if (t) try {
|
|
743
|
+
await e.applyConstraints(t);
|
|
744
|
+
} catch {}
|
|
745
|
+
}
|
|
746
|
+
async function Ie(e) {
|
|
727
747
|
let n = globalThis.ImageCapture;
|
|
728
748
|
if (!n) return;
|
|
729
749
|
let r = new n(e), i;
|
|
@@ -733,47 +753,48 @@ async function Fe(e) {
|
|
|
733
753
|
} catch {
|
|
734
754
|
i = await r.takePhoto();
|
|
735
755
|
}
|
|
736
|
-
let a = await createImageBitmap(i), o =
|
|
737
|
-
s.width =
|
|
756
|
+
let a = await createImageBitmap(i), o = q(a.width, a.height, J), s = document.createElement("canvas");
|
|
757
|
+
s.width = o.width, s.height = o.height;
|
|
738
758
|
let c = s.getContext("2d");
|
|
739
759
|
if (!c) throw a.close?.(), t();
|
|
740
|
-
return c.imageSmoothingEnabled =
|
|
760
|
+
return c.imageSmoothingEnabled = o.width !== a.width || o.height !== a.height, c.imageSmoothingQuality = "high", c.drawImage(a, 0, 0, s.width, s.height), a.close?.(), s;
|
|
741
761
|
}
|
|
742
|
-
function
|
|
762
|
+
function Y(e, n) {
|
|
743
763
|
if (!e.videoWidth || !e.videoHeight) throw Error("The camera is not ready to capture a frame.");
|
|
744
|
-
let r =
|
|
764
|
+
let r = q(e.videoWidth, e.videoHeight, n), i = document.createElement("canvas");
|
|
745
765
|
i.width = r.width, i.height = r.height;
|
|
746
766
|
let a = i.getContext("2d");
|
|
747
767
|
if (!a) throw t();
|
|
748
768
|
return a.drawImage(e, 0, 0, i.width, i.height), i;
|
|
749
769
|
}
|
|
750
|
-
function
|
|
751
|
-
|
|
770
|
+
function Le(e) {
|
|
771
|
+
let t = B();
|
|
772
|
+
return e.idealWidth || e.idealHeight || e.maxWidth || e.maxHeight ? [K(e, t)] : [
|
|
752
773
|
K({
|
|
753
774
|
...e,
|
|
754
775
|
idealWidth: 3840,
|
|
755
776
|
idealHeight: 2160
|
|
756
|
-
}),
|
|
777
|
+
}, t),
|
|
757
778
|
K({
|
|
758
779
|
...e,
|
|
759
780
|
idealWidth: 2560,
|
|
760
781
|
idealHeight: 1440
|
|
761
|
-
}),
|
|
782
|
+
}, t),
|
|
762
783
|
K({
|
|
763
784
|
...e,
|
|
764
785
|
idealWidth: 1920,
|
|
765
786
|
idealHeight: 1080
|
|
766
|
-
})
|
|
787
|
+
}, t)
|
|
767
788
|
];
|
|
768
789
|
}
|
|
769
|
-
async function
|
|
790
|
+
async function Re(t, n = {}) {
|
|
770
791
|
await x("scan");
|
|
771
792
|
let r = n.torch ?? "alwaysOff";
|
|
772
793
|
if (r !== "alwaysOff" && await x("torch"), !window.isSecureContext && location.hostname !== "localhost") throw new e("secure-context", "Camera access requires HTTPS.");
|
|
773
794
|
if (!navigator.mediaDevices?.getUserMedia) throw Error("Live camera access is unavailable. Use the native camera picker instead.");
|
|
774
795
|
t.muted = !0, t.autoplay = !0, t.playsInline = !0, t.setAttribute("playsinline", "");
|
|
775
796
|
let i, a;
|
|
776
|
-
for (let e of
|
|
797
|
+
for (let e of Le(n)) try {
|
|
777
798
|
i = await navigator.mediaDevices.getUserMedia(e);
|
|
778
799
|
break;
|
|
779
800
|
} catch (e) {
|
|
@@ -786,6 +807,7 @@ async function Le(t, n = {}) {
|
|
|
786
807
|
for (let e of i.getTracks()) e.stop();
|
|
787
808
|
throw Error("The camera did not provide a video track.");
|
|
788
809
|
}
|
|
810
|
+
await Fe(o);
|
|
789
811
|
let s = je(t), c = "ImageCapture" in globalThis, l = H(r, (typeof o.getCapabilities == "function" ? o.getCapabilities() : void 0)?.torch === !0), u = !1, d = async (e) => {
|
|
790
812
|
if (!l.supported || o.readyState !== "live") return !1;
|
|
791
813
|
try {
|
|
@@ -844,28 +866,29 @@ async function Le(t, n = {}) {
|
|
|
844
866
|
get torchOn() {
|
|
845
867
|
return l.on;
|
|
846
868
|
},
|
|
847
|
-
capture: (e) =>
|
|
869
|
+
capture: (e) => Y(t, e),
|
|
848
870
|
async capturePhoto() {
|
|
849
871
|
let e, n = 0;
|
|
850
872
|
try {
|
|
851
|
-
e =
|
|
873
|
+
e = Y(t), n = G(e);
|
|
852
874
|
} catch {
|
|
853
875
|
e = void 0;
|
|
854
876
|
}
|
|
855
877
|
let r = s.getFrame(), i, a = !1;
|
|
856
878
|
if (Ee(B(), c)) try {
|
|
857
|
-
i = await
|
|
879
|
+
i = await Ie(o);
|
|
858
880
|
} catch {
|
|
859
881
|
a = !0, i = void 0;
|
|
860
882
|
}
|
|
861
|
-
let l = i ? G(i) : 0
|
|
862
|
-
|
|
863
|
-
height: t.videoHeight
|
|
864
|
-
}));
|
|
865
|
-
if (i && l > 10 && u) return console.info("[exige-scanner] capture", {
|
|
883
|
+
let l = i ? G(i) : 0;
|
|
884
|
+
if (i && l > 10) return console.info("[exige-scanner] capture", {
|
|
866
885
|
method: "image-capture",
|
|
867
886
|
frame: `${i.width}×${i.height}`,
|
|
868
|
-
video: `${t.videoWidth}×${t.videoHeight}
|
|
887
|
+
video: `${t.videoWidth}×${t.videoHeight}`,
|
|
888
|
+
aspectMatch: Oe(i, {
|
|
889
|
+
width: t.videoWidth,
|
|
890
|
+
height: t.videoHeight
|
|
891
|
+
})
|
|
869
892
|
}), {
|
|
870
893
|
frame: i,
|
|
871
894
|
method: "image-capture",
|
|
@@ -873,20 +896,20 @@ async function Le(t, n = {}) {
|
|
|
873
896
|
luminance: l,
|
|
874
897
|
diagnostics: m()
|
|
875
898
|
};
|
|
876
|
-
let
|
|
877
|
-
if (!
|
|
878
|
-
let
|
|
899
|
+
let u = e && n > 10 ? e : void 0, d = u ?? (r ? Me(r) : void 0);
|
|
900
|
+
if (!d) throw Error("The camera preview produced no visible pixels. Keep the scanner on screen, wait for the preview, and retake.");
|
|
901
|
+
let f = i ? "image-capture-empty" : a ? "image-capture-failed" : u ? void 0 : "video-frame-empty";
|
|
879
902
|
return console.info("[exige-scanner] capture", {
|
|
880
|
-
method:
|
|
881
|
-
frame: `${
|
|
903
|
+
method: u ? "video-frame" : "live-mirror",
|
|
904
|
+
frame: `${d.width}×${d.height}`,
|
|
882
905
|
video: `${t.videoWidth}×${t.videoHeight}`,
|
|
883
|
-
fallbackReason:
|
|
906
|
+
fallbackReason: f
|
|
884
907
|
}), {
|
|
885
|
-
frame:
|
|
886
|
-
method:
|
|
908
|
+
frame: d,
|
|
909
|
+
method: u ? "video-frame" : "live-mirror",
|
|
887
910
|
settings: o.getSettings(),
|
|
888
|
-
fallbackReason:
|
|
889
|
-
luminance:
|
|
911
|
+
fallbackReason: f,
|
|
912
|
+
luminance: u ? n : s.getMirrorLuminance(),
|
|
890
913
|
diagnostics: m()
|
|
891
914
|
};
|
|
892
915
|
},
|
|
@@ -905,12 +928,12 @@ async function Le(t, n = {}) {
|
|
|
905
928
|
}
|
|
906
929
|
//#endregion
|
|
907
930
|
//#region src/sdk/lighting.ts
|
|
908
|
-
function
|
|
931
|
+
function ze(e, t) {
|
|
909
932
|
if (!e.length) return 0;
|
|
910
933
|
let n = [...e].sort((e, t) => e - t);
|
|
911
934
|
return n[Math.min(n.length - 1, Math.floor(n.length * t))];
|
|
912
935
|
}
|
|
913
|
-
function
|
|
936
|
+
function X(e, t, n, r = 12) {
|
|
914
937
|
if (!t || !n || e.length < t * n) return {
|
|
915
938
|
strong: !1,
|
|
916
939
|
strength: 0,
|
|
@@ -933,7 +956,7 @@ function J(e, t, n, r = 12) {
|
|
|
933
956
|
});
|
|
934
957
|
}
|
|
935
958
|
}
|
|
936
|
-
let s =
|
|
959
|
+
let s = ze(o.map((e) => e.mean), .8), c = o.map((e) => s - e.mean >= 24 && e.mean >= 35), l = new Uint8Array(o.length), u = [];
|
|
937
960
|
for (let e = 0; e < o.length; e += 1) {
|
|
938
961
|
if (!c[e] || l[e]) continue;
|
|
939
962
|
let t = [], n = [e];
|
|
@@ -981,11 +1004,11 @@ function J(e, t, n, r = 12) {
|
|
|
981
1004
|
}
|
|
982
1005
|
return d;
|
|
983
1006
|
}
|
|
984
|
-
function
|
|
1007
|
+
function Be(e, t, n, r, i, a, o) {
|
|
985
1008
|
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));
|
|
986
1009
|
return (e[c * t + u] - e[s * t + u] - e[c * t + l] + e[s * t + l]) / d;
|
|
987
1010
|
}
|
|
988
|
-
function
|
|
1011
|
+
function Ve(e, t, n) {
|
|
989
1012
|
let r = t + 1, i = new Uint32Array((t + 1) * (n + 1));
|
|
990
1013
|
for (let a = 1; a <= n; a += 1) {
|
|
991
1014
|
let n = 0;
|
|
@@ -996,23 +1019,23 @@ function X(e, t, n) {
|
|
|
996
1019
|
stride: r
|
|
997
1020
|
};
|
|
998
1021
|
}
|
|
999
|
-
function
|
|
1000
|
-
let { integral: i, stride: a } =
|
|
1022
|
+
function He(e, t, n, r = Math.max(12, Math.round(Math.max(t, n) / 32))) {
|
|
1023
|
+
let { integral: i, stride: a } = Ve(e, t, n), o = new Uint8Array(e.length);
|
|
1001
1024
|
for (let s = 0; s < n; s += 1) for (let c = 0; c < t; c += 1) {
|
|
1002
|
-
let l =
|
|
1025
|
+
let l = Be(i, a, t, n, c, s, r);
|
|
1003
1026
|
o[s * t + c] = Math.max(0, Math.min(255, Math.round(e[s * t + c] * 235 / Math.max(24, l))));
|
|
1004
1027
|
}
|
|
1005
1028
|
return o;
|
|
1006
1029
|
}
|
|
1007
|
-
function
|
|
1008
|
-
let { integral: a, stride: o } =
|
|
1030
|
+
function Ue(e, t, n, r = Math.max(8, Math.round(Math.max(t, n) / 64)), i = .12) {
|
|
1031
|
+
let { integral: a, stride: o } = Ve(e, t, n), s = new Uint8Array(e.length), c = 1 - i;
|
|
1009
1032
|
for (let i = 0; i < n; i += 1) for (let l = 0; l < t; l += 1) {
|
|
1010
|
-
let u =
|
|
1033
|
+
let u = Be(a, o, t, n, l, i, r);
|
|
1011
1034
|
s[i * t + l] = e[i * t + l] < u * c ? 0 : 255;
|
|
1012
1035
|
}
|
|
1013
1036
|
return s;
|
|
1014
1037
|
}
|
|
1015
|
-
function
|
|
1038
|
+
function We(e, t, n) {
|
|
1016
1039
|
let r = [
|
|
1017
1040
|
e.topLeft,
|
|
1018
1041
|
e.topRight,
|
|
@@ -1026,8 +1049,8 @@ function Ve(e, t, n) {
|
|
|
1026
1049
|
height: s - a
|
|
1027
1050
|
};
|
|
1028
1051
|
}
|
|
1029
|
-
function
|
|
1030
|
-
let n =
|
|
1052
|
+
function Ge(e, t) {
|
|
1053
|
+
let n = We(t, e.width, e.height);
|
|
1031
1054
|
if (n.width <= 0 || n.height <= 0) return {
|
|
1032
1055
|
strong: !1,
|
|
1033
1056
|
strength: 0,
|
|
@@ -1046,18 +1069,18 @@ function He(e, t) {
|
|
|
1046
1069
|
i.drawImage(e, n.left, n.top, n.width, n.height, 0, 0, r.width, r.height);
|
|
1047
1070
|
let a = i.getImageData(0, 0, r.width, r.height).data, o = new Uint8Array(r.width * r.height);
|
|
1048
1071
|
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);
|
|
1049
|
-
return
|
|
1072
|
+
return X(o, r.width, r.height);
|
|
1050
1073
|
}
|
|
1051
1074
|
//#endregion
|
|
1052
1075
|
//#region src/sdk/finder.ts
|
|
1053
|
-
function
|
|
1076
|
+
function Ke(e, t) {
|
|
1054
1077
|
return t.castShadow && (e.reason === "hold-still" || e.reason === "ready") ? t.hint ?? e.hint : e.hint;
|
|
1055
1078
|
}
|
|
1056
|
-
async function
|
|
1079
|
+
async function qe(e, t) {
|
|
1057
1080
|
let n = await e();
|
|
1058
1081
|
return t(), n;
|
|
1059
1082
|
}
|
|
1060
|
-
function
|
|
1083
|
+
function Je(e) {
|
|
1061
1084
|
return e === "alwaysOn" || e === "only" ? {
|
|
1062
1085
|
visible: !1,
|
|
1063
1086
|
checked: !0,
|
|
@@ -1080,7 +1103,7 @@ function Z(e) {
|
|
|
1080
1103
|
e.bottomLeft
|
|
1081
1104
|
];
|
|
1082
1105
|
}
|
|
1083
|
-
function
|
|
1106
|
+
function Ye(e, t) {
|
|
1084
1107
|
let n = e.status === "success" && e.modelStatus !== "failed", r = {
|
|
1085
1108
|
status: e.status,
|
|
1086
1109
|
confidence: Number(e.confidence.toFixed(3)),
|
|
@@ -1103,7 +1126,7 @@ function Ke(e, t) {
|
|
|
1103
1126
|
detail: r
|
|
1104
1127
|
};
|
|
1105
1128
|
}
|
|
1106
|
-
function
|
|
1129
|
+
function Xe(e) {
|
|
1107
1130
|
let t = 0;
|
|
1108
1131
|
for (let n = 0; n < e.length; n += 1) {
|
|
1109
1132
|
let r = e[n], i = e[(n + 1) % e.length];
|
|
@@ -1121,23 +1144,23 @@ var $ = {
|
|
|
1121
1144
|
areaFill: 0,
|
|
1122
1145
|
aspectRatio: 1
|
|
1123
1146
|
};
|
|
1124
|
-
function
|
|
1147
|
+
function Ze(e, t, n) {
|
|
1125
1148
|
let r = Z(e), i = r.map(({ x: e }) => e), a = r.map(({ y: e }) => e), o = (Math.max(...i) - Math.min(...i)) / Math.max(1, t), s = (Math.max(...a) - Math.min(...a)) / Math.max(1, n), [c, l, u, d] = r, f = Math.max(Q(c, l), Q(d, u)), p = Math.max(Q(c, d), Q(l, u));
|
|
1126
1149
|
return {
|
|
1127
1150
|
widthFill: o,
|
|
1128
1151
|
heightFill: s,
|
|
1129
1152
|
limitingFill: Math.max(o, s),
|
|
1130
|
-
areaFill:
|
|
1153
|
+
areaFill: Xe(r) / Math.max(1, t * n),
|
|
1131
1154
|
aspectRatio: Math.max(f, p) / Math.max(1, Math.min(f, p))
|
|
1132
1155
|
};
|
|
1133
1156
|
}
|
|
1134
|
-
function
|
|
1157
|
+
function Qe(e, t, n, r = {}) {
|
|
1135
1158
|
let i = t ? r.exitFillRatio ?? .64 : r.minFillRatio ?? .72, a = r.highAspectRatio ?? 2.2;
|
|
1136
1159
|
if (e.aspectRatio < a) return i;
|
|
1137
1160
|
let o = t ? r.highAspectExitFillRatio : r.highAspectFillRatio;
|
|
1138
1161
|
return Math.min(o ?? i + .08, 1 - n * 2);
|
|
1139
1162
|
}
|
|
1140
|
-
function
|
|
1163
|
+
function $e(e, t, n = {}) {
|
|
1141
1164
|
let r = n.confidenceThreshold ?? .72;
|
|
1142
1165
|
if (e.status !== "success" || !e.quad || e.confidence < r || !e.sourceWidth || !e.sourceHeight) return {
|
|
1143
1166
|
hint: "Place the document in the frame",
|
|
@@ -1146,7 +1169,7 @@ function Xe(e, t, n = {}) {
|
|
|
1146
1169
|
fill: $,
|
|
1147
1170
|
readyForAutoCapture: !1
|
|
1148
1171
|
};
|
|
1149
|
-
let i = Z(e.quad), a =
|
|
1172
|
+
let i = Z(e.quad), a = Ze(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;
|
|
1150
1173
|
if (i.some(({ x: t, y: n }) => t <= c || t >= e.sourceWidth - c || n <= l || n >= e.sourceHeight - l)) return {
|
|
1151
1174
|
hint: "Move farther away",
|
|
1152
1175
|
reason: "move-farther-away",
|
|
@@ -1161,7 +1184,7 @@ function Xe(e, t, n = {}) {
|
|
|
1161
1184
|
fillRatio: o,
|
|
1162
1185
|
fill: a,
|
|
1163
1186
|
readyForAutoCapture: !1
|
|
1164
|
-
} : o <
|
|
1187
|
+
} : o < Qe(a, t.previouslyReady === !0, s, n) ? {
|
|
1165
1188
|
hint: "Move closer",
|
|
1166
1189
|
reason: "move-closer",
|
|
1167
1190
|
fillRatio: o,
|
|
@@ -1175,7 +1198,7 @@ function Xe(e, t, n = {}) {
|
|
|
1175
1198
|
readyForAutoCapture: t.ready
|
|
1176
1199
|
};
|
|
1177
1200
|
}
|
|
1178
|
-
var
|
|
1201
|
+
var et = class {
|
|
1179
1202
|
previous;
|
|
1180
1203
|
count = 0;
|
|
1181
1204
|
ready = !1;
|
|
@@ -1203,14 +1226,14 @@ var Ze = class {
|
|
|
1203
1226
|
};
|
|
1204
1227
|
}
|
|
1205
1228
|
};
|
|
1206
|
-
function
|
|
1229
|
+
function tt(e, n) {
|
|
1207
1230
|
let r = Math.min(1, n / Math.max(e.width, e.height)), i = document.createElement("canvas");
|
|
1208
1231
|
i.width = Math.max(1, Math.round(e.width * r)), i.height = Math.max(1, Math.round(e.height * r));
|
|
1209
1232
|
let a = i.getContext("2d");
|
|
1210
1233
|
if (!a) throw t();
|
|
1211
1234
|
return a.drawImage(e, 0, 0, i.width, i.height), i;
|
|
1212
1235
|
}
|
|
1213
|
-
function
|
|
1236
|
+
function nt() {
|
|
1214
1237
|
let e = window.AudioContext ?? window.webkitAudioContext;
|
|
1215
1238
|
if (!e) return;
|
|
1216
1239
|
let t = new e(), n = Math.round(t.sampleRate * .09), r = t.createBuffer(1, n, t.sampleRate), i = r.getChannelData(0);
|
|
@@ -1221,13 +1244,13 @@ function $e() {
|
|
|
1221
1244
|
let a = t.createBufferSource(), o = t.createBiquadFilter(), s = t.createGain();
|
|
1222
1245
|
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();
|
|
1223
1246
|
}
|
|
1224
|
-
async function
|
|
1247
|
+
async function rt(e) {
|
|
1225
1248
|
let t = document.createElement("video");
|
|
1226
1249
|
return t.muted = !0, t.autoplay = !0, t.playsInline = !0, t.srcObject = e, await t.play(), t;
|
|
1227
1250
|
}
|
|
1228
|
-
async function
|
|
1251
|
+
async function it(t) {
|
|
1229
1252
|
await x("scan");
|
|
1230
|
-
let n =
|
|
1253
|
+
let n = Je(t.autoCapture), r = new et({
|
|
1231
1254
|
stableFrames: t.stableFrames ?? 4,
|
|
1232
1255
|
confidenceThreshold: t.confidenceThreshold ?? .72,
|
|
1233
1256
|
cornerTolerance: t.cornerTolerance ?? .024,
|
|
@@ -1236,7 +1259,7 @@ async function tt(t) {
|
|
|
1236
1259
|
minDimension: 220,
|
|
1237
1260
|
maxAnalysisDimension: 520,
|
|
1238
1261
|
...t.detection
|
|
1239
|
-
}, s = typeof MediaStream < "u" && t.source instanceof MediaStream ? await
|
|
1262
|
+
}, s = typeof MediaStream < "u" && t.source instanceof MediaStream ? await rt(t.source) : t.source, c = !0, l = !1, u = !1, d = 0, f, p = "", m = 0, h = {
|
|
1240
1263
|
state: "detecting",
|
|
1241
1264
|
confidence: 0,
|
|
1242
1265
|
guidance: {
|
|
@@ -1253,10 +1276,10 @@ async function tt(t) {
|
|
|
1253
1276
|
stableFrames: 0,
|
|
1254
1277
|
requiredStableFrames: t.stableFrames ?? 4,
|
|
1255
1278
|
autoCapture: { ...n }
|
|
1256
|
-
}, g = () => s instanceof HTMLCanvasElement ?
|
|
1279
|
+
}, g = () => s instanceof HTMLCanvasElement ? tt(s, i) : Y(s, i), _ = (e) => {
|
|
1257
1280
|
h = e, t.onStatus?.(e);
|
|
1258
1281
|
}, v = (e) => {
|
|
1259
|
-
let t =
|
|
1282
|
+
let t = Ye(e, s instanceof HTMLVideoElement ? {
|
|
1260
1283
|
width: s.videoWidth,
|
|
1261
1284
|
height: s.videoHeight
|
|
1262
1285
|
} : {
|
|
@@ -1271,11 +1294,11 @@ async function tt(t) {
|
|
|
1271
1294
|
l = !0;
|
|
1272
1295
|
let n;
|
|
1273
1296
|
try {
|
|
1274
|
-
n = await
|
|
1297
|
+
n = await qe(t.captureFrame ?? g, () => {
|
|
1275
1298
|
_({
|
|
1276
1299
|
...h,
|
|
1277
1300
|
state: "captured"
|
|
1278
|
-
}), t.playShutterSound !== !1 &&
|
|
1301
|
+
}), t.playShutterSound !== !1 && nt(), y();
|
|
1279
1302
|
});
|
|
1280
1303
|
} catch (e) {
|
|
1281
1304
|
throw l = !1, e instanceof Error ? e : /* @__PURE__ */ Error("The camera frame could not be captured.");
|
|
@@ -1291,7 +1314,7 @@ async function tt(t) {
|
|
|
1291
1314
|
try {
|
|
1292
1315
|
let e = g(), i = await Se(e, o);
|
|
1293
1316
|
f = i, v(i);
|
|
1294
|
-
let a = i.quad ?
|
|
1317
|
+
let a = i.quad ? Ge(e, i.quad) : {
|
|
1295
1318
|
strong: !1,
|
|
1296
1319
|
strength: 0
|
|
1297
1320
|
}, s = a.strong ? {
|
|
@@ -1301,7 +1324,7 @@ async function tt(t) {
|
|
|
1301
1324
|
} : {
|
|
1302
1325
|
castShadow: !1,
|
|
1303
1326
|
strength: a.strength
|
|
1304
|
-
}, c = r.update(i), l =
|
|
1327
|
+
}, c = r.update(i), l = $e(i, {
|
|
1305
1328
|
...c,
|
|
1306
1329
|
previouslyReady: u
|
|
1307
1330
|
}, {
|
|
@@ -1383,6 +1406,6 @@ async function tt(t) {
|
|
|
1383
1406
|
};
|
|
1384
1407
|
}
|
|
1385
1408
|
//#endregion
|
|
1386
|
-
export {
|
|
1409
|
+
export { re as A, Ce as C, le as D, we as E, b as F, y as I, e as L, a as M, o as N, ue as O, x as P, t as R, de as S, N as T, Ae as _, $e as a, Re as b, Ue as c, V as d, ke as f, Te as g, B as h, Ze as i, te as j, M as k, X as l, Y as m, Je as n, Ke as o, J as p, Qe as r, it as s, et as t, He as u, U as v, Se as w, H as x, K as y };
|
|
1387
1410
|
|
|
1388
|
-
//# sourceMappingURL=finder-
|
|
1411
|
+
//# sourceMappingURL=finder-CLTG1caj.js.map
|