@exige/web-scanner-sdk 0.2.22 → 0.2.24
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-B3kHQ2Jh.js} +132 -110
- package/dist/finder-B3kHQ2Jh.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 +52 -4
- 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);
|
|
@@ -596,11 +596,10 @@ function Ee(e, t) {
|
|
|
596
596
|
return t && !e.iosWebKit;
|
|
597
597
|
}
|
|
598
598
|
function De(e) {
|
|
599
|
-
let t = e?.imageWidth?.max, n = e?.imageHeight?.max;
|
|
600
|
-
if (
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
};
|
|
599
|
+
let t = e?.imageWidth?.max, n = e?.imageHeight?.max, r = t && Number.isFinite(t) ? Math.round(t) : void 0, i = n && Number.isFinite(n) ? Math.round(n) : void 0;
|
|
600
|
+
if (r && i) return r >= i ? { imageWidth: r } : { imageHeight: i };
|
|
601
|
+
if (r) return { imageWidth: r };
|
|
602
|
+
if (i) return { imageHeight: i };
|
|
604
603
|
}
|
|
605
604
|
function Oe(e, t) {
|
|
606
605
|
if (!e.width || !e.height || !t.width || !t.height) return !1;
|
|
@@ -700,30 +699,50 @@ function Me(e) {
|
|
|
700
699
|
let t = document.createElement("canvas");
|
|
701
700
|
return t.width = e.width, t.height = e.height, t.getContext("2d")?.drawImage(e, 0, 0), t;
|
|
702
701
|
}
|
|
703
|
-
function
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
702
|
+
function Ne(e) {
|
|
703
|
+
return e.engine === "blink";
|
|
704
|
+
}
|
|
705
|
+
function K(e = {}, t = B()) {
|
|
706
|
+
let n = { ideal: e.idealWidth ?? 3840 }, r = { ideal: e.idealHeight ?? 2160 };
|
|
707
|
+
e.maxWidth && (n.max = e.maxWidth), e.maxHeight && (r.max = e.maxHeight);
|
|
708
|
+
let i = {
|
|
709
|
+
facingMode: { ideal: e.facingMode ?? "environment" },
|
|
710
|
+
width: n,
|
|
711
|
+
height: r,
|
|
712
|
+
frameRate: {
|
|
713
|
+
ideal: e.maxFrameRate ?? 30,
|
|
714
|
+
max: e.maxFrameRate ?? 30
|
|
715
715
|
}
|
|
716
716
|
};
|
|
717
|
+
return Ne(t) && (i.resizeMode = { ideal: "none" }), {
|
|
718
|
+
audio: !1,
|
|
719
|
+
video: i
|
|
720
|
+
};
|
|
717
721
|
}
|
|
718
|
-
function
|
|
722
|
+
function q(e, t, n) {
|
|
719
723
|
let r = n ? Math.min(1, n / Math.max(e, t)) : 1;
|
|
720
724
|
return {
|
|
721
725
|
width: Math.max(1, Math.round(e * r)),
|
|
722
726
|
height: Math.max(1, Math.round(t * r))
|
|
723
727
|
};
|
|
724
728
|
}
|
|
725
|
-
var
|
|
729
|
+
var J = 4096;
|
|
730
|
+
function Pe(e, t) {
|
|
731
|
+
let n = e.width, r = e.height, i = t?.width?.max, a = t?.height?.max;
|
|
732
|
+
if (!n || !r || !i || !a) return;
|
|
733
|
+
let o = Math.min(i / n, a / r);
|
|
734
|
+
if (!(o <= 1.05)) return {
|
|
735
|
+
width: { ideal: Math.round(n * o) },
|
|
736
|
+
height: { ideal: Math.round(r * o) }
|
|
737
|
+
};
|
|
738
|
+
}
|
|
726
739
|
async function Fe(e) {
|
|
740
|
+
let t = Pe(e.getSettings(), typeof e.getCapabilities == "function" ? e.getCapabilities() : void 0);
|
|
741
|
+
if (t) try {
|
|
742
|
+
await e.applyConstraints(t);
|
|
743
|
+
} catch {}
|
|
744
|
+
}
|
|
745
|
+
async function Ie(e) {
|
|
727
746
|
let n = globalThis.ImageCapture;
|
|
728
747
|
if (!n) return;
|
|
729
748
|
let r = new n(e), i;
|
|
@@ -733,47 +752,48 @@ async function Fe(e) {
|
|
|
733
752
|
} catch {
|
|
734
753
|
i = await r.takePhoto();
|
|
735
754
|
}
|
|
736
|
-
let a = await createImageBitmap(i), o =
|
|
737
|
-
s.width =
|
|
755
|
+
let a = await createImageBitmap(i), o = q(a.width, a.height, J), s = document.createElement("canvas");
|
|
756
|
+
s.width = o.width, s.height = o.height;
|
|
738
757
|
let c = s.getContext("2d");
|
|
739
758
|
if (!c) throw a.close?.(), t();
|
|
740
|
-
return c.imageSmoothingEnabled =
|
|
759
|
+
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
760
|
}
|
|
742
|
-
function
|
|
761
|
+
function Y(e, n) {
|
|
743
762
|
if (!e.videoWidth || !e.videoHeight) throw Error("The camera is not ready to capture a frame.");
|
|
744
|
-
let r =
|
|
763
|
+
let r = q(e.videoWidth, e.videoHeight, n), i = document.createElement("canvas");
|
|
745
764
|
i.width = r.width, i.height = r.height;
|
|
746
765
|
let a = i.getContext("2d");
|
|
747
766
|
if (!a) throw t();
|
|
748
767
|
return a.drawImage(e, 0, 0, i.width, i.height), i;
|
|
749
768
|
}
|
|
750
|
-
function
|
|
751
|
-
|
|
769
|
+
function Le(e) {
|
|
770
|
+
let t = B();
|
|
771
|
+
return e.idealWidth || e.idealHeight || e.maxWidth || e.maxHeight ? [K(e, t)] : [
|
|
752
772
|
K({
|
|
753
773
|
...e,
|
|
754
774
|
idealWidth: 3840,
|
|
755
775
|
idealHeight: 2160
|
|
756
|
-
}),
|
|
776
|
+
}, t),
|
|
757
777
|
K({
|
|
758
778
|
...e,
|
|
759
779
|
idealWidth: 2560,
|
|
760
780
|
idealHeight: 1440
|
|
761
|
-
}),
|
|
781
|
+
}, t),
|
|
762
782
|
K({
|
|
763
783
|
...e,
|
|
764
784
|
idealWidth: 1920,
|
|
765
785
|
idealHeight: 1080
|
|
766
|
-
})
|
|
786
|
+
}, t)
|
|
767
787
|
];
|
|
768
788
|
}
|
|
769
|
-
async function
|
|
789
|
+
async function Re(t, n = {}) {
|
|
770
790
|
await x("scan");
|
|
771
791
|
let r = n.torch ?? "alwaysOff";
|
|
772
792
|
if (r !== "alwaysOff" && await x("torch"), !window.isSecureContext && location.hostname !== "localhost") throw new e("secure-context", "Camera access requires HTTPS.");
|
|
773
793
|
if (!navigator.mediaDevices?.getUserMedia) throw Error("Live camera access is unavailable. Use the native camera picker instead.");
|
|
774
794
|
t.muted = !0, t.autoplay = !0, t.playsInline = !0, t.setAttribute("playsinline", "");
|
|
775
795
|
let i, a;
|
|
776
|
-
for (let e of
|
|
796
|
+
for (let e of Le(n)) try {
|
|
777
797
|
i = await navigator.mediaDevices.getUserMedia(e);
|
|
778
798
|
break;
|
|
779
799
|
} catch (e) {
|
|
@@ -786,6 +806,7 @@ async function Le(t, n = {}) {
|
|
|
786
806
|
for (let e of i.getTracks()) e.stop();
|
|
787
807
|
throw Error("The camera did not provide a video track.");
|
|
788
808
|
}
|
|
809
|
+
await Fe(o);
|
|
789
810
|
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
811
|
if (!l.supported || o.readyState !== "live") return !1;
|
|
791
812
|
try {
|
|
@@ -844,28 +865,29 @@ async function Le(t, n = {}) {
|
|
|
844
865
|
get torchOn() {
|
|
845
866
|
return l.on;
|
|
846
867
|
},
|
|
847
|
-
capture: (e) =>
|
|
868
|
+
capture: (e) => Y(t, e),
|
|
848
869
|
async capturePhoto() {
|
|
849
870
|
let e, n = 0;
|
|
850
871
|
try {
|
|
851
|
-
e =
|
|
872
|
+
e = Y(t), n = G(e);
|
|
852
873
|
} catch {
|
|
853
874
|
e = void 0;
|
|
854
875
|
}
|
|
855
876
|
let r = s.getFrame(), i, a = !1;
|
|
856
877
|
if (Ee(B(), c)) try {
|
|
857
|
-
i = await
|
|
878
|
+
i = await Ie(o);
|
|
858
879
|
} catch {
|
|
859
880
|
a = !0, i = void 0;
|
|
860
881
|
}
|
|
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", {
|
|
882
|
+
let l = i ? G(i) : 0;
|
|
883
|
+
if (i && l > 10) return console.info("[exige-scanner] capture", {
|
|
866
884
|
method: "image-capture",
|
|
867
885
|
frame: `${i.width}×${i.height}`,
|
|
868
|
-
video: `${t.videoWidth}×${t.videoHeight}
|
|
886
|
+
video: `${t.videoWidth}×${t.videoHeight}`,
|
|
887
|
+
aspectMatch: Oe(i, {
|
|
888
|
+
width: t.videoWidth,
|
|
889
|
+
height: t.videoHeight
|
|
890
|
+
})
|
|
869
891
|
}), {
|
|
870
892
|
frame: i,
|
|
871
893
|
method: "image-capture",
|
|
@@ -873,20 +895,20 @@ async function Le(t, n = {}) {
|
|
|
873
895
|
luminance: l,
|
|
874
896
|
diagnostics: m()
|
|
875
897
|
};
|
|
876
|
-
let
|
|
877
|
-
if (!
|
|
878
|
-
let
|
|
898
|
+
let u = e && n > 10 ? e : void 0, d = u ?? (r ? Me(r) : void 0);
|
|
899
|
+
if (!d) throw Error("The camera preview produced no visible pixels. Keep the scanner on screen, wait for the preview, and retake.");
|
|
900
|
+
let f = i ? "image-capture-empty" : a ? "image-capture-failed" : u ? void 0 : "video-frame-empty";
|
|
879
901
|
return console.info("[exige-scanner] capture", {
|
|
880
|
-
method:
|
|
881
|
-
frame: `${
|
|
902
|
+
method: u ? "video-frame" : "live-mirror",
|
|
903
|
+
frame: `${d.width}×${d.height}`,
|
|
882
904
|
video: `${t.videoWidth}×${t.videoHeight}`,
|
|
883
|
-
fallbackReason:
|
|
905
|
+
fallbackReason: f
|
|
884
906
|
}), {
|
|
885
|
-
frame:
|
|
886
|
-
method:
|
|
907
|
+
frame: d,
|
|
908
|
+
method: u ? "video-frame" : "live-mirror",
|
|
887
909
|
settings: o.getSettings(),
|
|
888
|
-
fallbackReason:
|
|
889
|
-
luminance:
|
|
910
|
+
fallbackReason: f,
|
|
911
|
+
luminance: u ? n : s.getMirrorLuminance(),
|
|
890
912
|
diagnostics: m()
|
|
891
913
|
};
|
|
892
914
|
},
|
|
@@ -905,12 +927,12 @@ async function Le(t, n = {}) {
|
|
|
905
927
|
}
|
|
906
928
|
//#endregion
|
|
907
929
|
//#region src/sdk/lighting.ts
|
|
908
|
-
function
|
|
930
|
+
function ze(e, t) {
|
|
909
931
|
if (!e.length) return 0;
|
|
910
932
|
let n = [...e].sort((e, t) => e - t);
|
|
911
933
|
return n[Math.min(n.length - 1, Math.floor(n.length * t))];
|
|
912
934
|
}
|
|
913
|
-
function
|
|
935
|
+
function X(e, t, n, r = 12) {
|
|
914
936
|
if (!t || !n || e.length < t * n) return {
|
|
915
937
|
strong: !1,
|
|
916
938
|
strength: 0,
|
|
@@ -933,7 +955,7 @@ function J(e, t, n, r = 12) {
|
|
|
933
955
|
});
|
|
934
956
|
}
|
|
935
957
|
}
|
|
936
|
-
let s =
|
|
958
|
+
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
959
|
for (let e = 0; e < o.length; e += 1) {
|
|
938
960
|
if (!c[e] || l[e]) continue;
|
|
939
961
|
let t = [], n = [e];
|
|
@@ -981,11 +1003,11 @@ function J(e, t, n, r = 12) {
|
|
|
981
1003
|
}
|
|
982
1004
|
return d;
|
|
983
1005
|
}
|
|
984
|
-
function
|
|
1006
|
+
function Be(e, t, n, r, i, a, o) {
|
|
985
1007
|
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
1008
|
return (e[c * t + u] - e[s * t + u] - e[c * t + l] + e[s * t + l]) / d;
|
|
987
1009
|
}
|
|
988
|
-
function
|
|
1010
|
+
function Ve(e, t, n) {
|
|
989
1011
|
let r = t + 1, i = new Uint32Array((t + 1) * (n + 1));
|
|
990
1012
|
for (let a = 1; a <= n; a += 1) {
|
|
991
1013
|
let n = 0;
|
|
@@ -996,23 +1018,23 @@ function X(e, t, n) {
|
|
|
996
1018
|
stride: r
|
|
997
1019
|
};
|
|
998
1020
|
}
|
|
999
|
-
function
|
|
1000
|
-
let { integral: i, stride: a } =
|
|
1021
|
+
function He(e, t, n, r = Math.max(12, Math.round(Math.max(t, n) / 32))) {
|
|
1022
|
+
let { integral: i, stride: a } = Ve(e, t, n), o = new Uint8Array(e.length);
|
|
1001
1023
|
for (let s = 0; s < n; s += 1) for (let c = 0; c < t; c += 1) {
|
|
1002
|
-
let l =
|
|
1024
|
+
let l = Be(i, a, t, n, c, s, r);
|
|
1003
1025
|
o[s * t + c] = Math.max(0, Math.min(255, Math.round(e[s * t + c] * 235 / Math.max(24, l))));
|
|
1004
1026
|
}
|
|
1005
1027
|
return o;
|
|
1006
1028
|
}
|
|
1007
|
-
function
|
|
1008
|
-
let { integral: a, stride: o } =
|
|
1029
|
+
function Ue(e, t, n, r = Math.max(8, Math.round(Math.max(t, n) / 64)), i = .12) {
|
|
1030
|
+
let { integral: a, stride: o } = Ve(e, t, n), s = new Uint8Array(e.length), c = 1 - i;
|
|
1009
1031
|
for (let i = 0; i < n; i += 1) for (let l = 0; l < t; l += 1) {
|
|
1010
|
-
let u =
|
|
1032
|
+
let u = Be(a, o, t, n, l, i, r);
|
|
1011
1033
|
s[i * t + l] = e[i * t + l] < u * c ? 0 : 255;
|
|
1012
1034
|
}
|
|
1013
1035
|
return s;
|
|
1014
1036
|
}
|
|
1015
|
-
function
|
|
1037
|
+
function We(e, t, n) {
|
|
1016
1038
|
let r = [
|
|
1017
1039
|
e.topLeft,
|
|
1018
1040
|
e.topRight,
|
|
@@ -1026,8 +1048,8 @@ function Ve(e, t, n) {
|
|
|
1026
1048
|
height: s - a
|
|
1027
1049
|
};
|
|
1028
1050
|
}
|
|
1029
|
-
function
|
|
1030
|
-
let n =
|
|
1051
|
+
function Ge(e, t) {
|
|
1052
|
+
let n = We(t, e.width, e.height);
|
|
1031
1053
|
if (n.width <= 0 || n.height <= 0) return {
|
|
1032
1054
|
strong: !1,
|
|
1033
1055
|
strength: 0,
|
|
@@ -1046,18 +1068,18 @@ function He(e, t) {
|
|
|
1046
1068
|
i.drawImage(e, n.left, n.top, n.width, n.height, 0, 0, r.width, r.height);
|
|
1047
1069
|
let a = i.getImageData(0, 0, r.width, r.height).data, o = new Uint8Array(r.width * r.height);
|
|
1048
1070
|
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
|
|
1071
|
+
return X(o, r.width, r.height);
|
|
1050
1072
|
}
|
|
1051
1073
|
//#endregion
|
|
1052
1074
|
//#region src/sdk/finder.ts
|
|
1053
|
-
function
|
|
1075
|
+
function Ke(e, t) {
|
|
1054
1076
|
return t.castShadow && (e.reason === "hold-still" || e.reason === "ready") ? t.hint ?? e.hint : e.hint;
|
|
1055
1077
|
}
|
|
1056
|
-
async function
|
|
1078
|
+
async function qe(e, t) {
|
|
1057
1079
|
let n = await e();
|
|
1058
1080
|
return t(), n;
|
|
1059
1081
|
}
|
|
1060
|
-
function
|
|
1082
|
+
function Je(e) {
|
|
1061
1083
|
return e === "alwaysOn" || e === "only" ? {
|
|
1062
1084
|
visible: !1,
|
|
1063
1085
|
checked: !0,
|
|
@@ -1080,7 +1102,7 @@ function Z(e) {
|
|
|
1080
1102
|
e.bottomLeft
|
|
1081
1103
|
];
|
|
1082
1104
|
}
|
|
1083
|
-
function
|
|
1105
|
+
function Ye(e, t) {
|
|
1084
1106
|
let n = e.status === "success" && e.modelStatus !== "failed", r = {
|
|
1085
1107
|
status: e.status,
|
|
1086
1108
|
confidence: Number(e.confidence.toFixed(3)),
|
|
@@ -1103,7 +1125,7 @@ function Ke(e, t) {
|
|
|
1103
1125
|
detail: r
|
|
1104
1126
|
};
|
|
1105
1127
|
}
|
|
1106
|
-
function
|
|
1128
|
+
function Xe(e) {
|
|
1107
1129
|
let t = 0;
|
|
1108
1130
|
for (let n = 0; n < e.length; n += 1) {
|
|
1109
1131
|
let r = e[n], i = e[(n + 1) % e.length];
|
|
@@ -1121,23 +1143,23 @@ var $ = {
|
|
|
1121
1143
|
areaFill: 0,
|
|
1122
1144
|
aspectRatio: 1
|
|
1123
1145
|
};
|
|
1124
|
-
function
|
|
1146
|
+
function Ze(e, t, n) {
|
|
1125
1147
|
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
1148
|
return {
|
|
1127
1149
|
widthFill: o,
|
|
1128
1150
|
heightFill: s,
|
|
1129
1151
|
limitingFill: Math.max(o, s),
|
|
1130
|
-
areaFill:
|
|
1152
|
+
areaFill: Xe(r) / Math.max(1, t * n),
|
|
1131
1153
|
aspectRatio: Math.max(f, p) / Math.max(1, Math.min(f, p))
|
|
1132
1154
|
};
|
|
1133
1155
|
}
|
|
1134
|
-
function
|
|
1156
|
+
function Qe(e, t, n, r = {}) {
|
|
1135
1157
|
let i = t ? r.exitFillRatio ?? .64 : r.minFillRatio ?? .72, a = r.highAspectRatio ?? 2.2;
|
|
1136
1158
|
if (e.aspectRatio < a) return i;
|
|
1137
1159
|
let o = t ? r.highAspectExitFillRatio : r.highAspectFillRatio;
|
|
1138
1160
|
return Math.min(o ?? i + .08, 1 - n * 2);
|
|
1139
1161
|
}
|
|
1140
|
-
function
|
|
1162
|
+
function $e(e, t, n = {}) {
|
|
1141
1163
|
let r = n.confidenceThreshold ?? .72;
|
|
1142
1164
|
if (e.status !== "success" || !e.quad || e.confidence < r || !e.sourceWidth || !e.sourceHeight) return {
|
|
1143
1165
|
hint: "Place the document in the frame",
|
|
@@ -1146,7 +1168,7 @@ function Xe(e, t, n = {}) {
|
|
|
1146
1168
|
fill: $,
|
|
1147
1169
|
readyForAutoCapture: !1
|
|
1148
1170
|
};
|
|
1149
|
-
let i = Z(e.quad), a =
|
|
1171
|
+
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
1172
|
if (i.some(({ x: t, y: n }) => t <= c || t >= e.sourceWidth - c || n <= l || n >= e.sourceHeight - l)) return {
|
|
1151
1173
|
hint: "Move farther away",
|
|
1152
1174
|
reason: "move-farther-away",
|
|
@@ -1161,7 +1183,7 @@ function Xe(e, t, n = {}) {
|
|
|
1161
1183
|
fillRatio: o,
|
|
1162
1184
|
fill: a,
|
|
1163
1185
|
readyForAutoCapture: !1
|
|
1164
|
-
} : o <
|
|
1186
|
+
} : o < Qe(a, t.previouslyReady === !0, s, n) ? {
|
|
1165
1187
|
hint: "Move closer",
|
|
1166
1188
|
reason: "move-closer",
|
|
1167
1189
|
fillRatio: o,
|
|
@@ -1175,7 +1197,7 @@ function Xe(e, t, n = {}) {
|
|
|
1175
1197
|
readyForAutoCapture: t.ready
|
|
1176
1198
|
};
|
|
1177
1199
|
}
|
|
1178
|
-
var
|
|
1200
|
+
var et = class {
|
|
1179
1201
|
previous;
|
|
1180
1202
|
count = 0;
|
|
1181
1203
|
ready = !1;
|
|
@@ -1203,14 +1225,14 @@ var Ze = class {
|
|
|
1203
1225
|
};
|
|
1204
1226
|
}
|
|
1205
1227
|
};
|
|
1206
|
-
function
|
|
1228
|
+
function tt(e, n) {
|
|
1207
1229
|
let r = Math.min(1, n / Math.max(e.width, e.height)), i = document.createElement("canvas");
|
|
1208
1230
|
i.width = Math.max(1, Math.round(e.width * r)), i.height = Math.max(1, Math.round(e.height * r));
|
|
1209
1231
|
let a = i.getContext("2d");
|
|
1210
1232
|
if (!a) throw t();
|
|
1211
1233
|
return a.drawImage(e, 0, 0, i.width, i.height), i;
|
|
1212
1234
|
}
|
|
1213
|
-
function
|
|
1235
|
+
function nt() {
|
|
1214
1236
|
let e = window.AudioContext ?? window.webkitAudioContext;
|
|
1215
1237
|
if (!e) return;
|
|
1216
1238
|
let t = new e(), n = Math.round(t.sampleRate * .09), r = t.createBuffer(1, n, t.sampleRate), i = r.getChannelData(0);
|
|
@@ -1221,13 +1243,13 @@ function $e() {
|
|
|
1221
1243
|
let a = t.createBufferSource(), o = t.createBiquadFilter(), s = t.createGain();
|
|
1222
1244
|
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
1245
|
}
|
|
1224
|
-
async function
|
|
1246
|
+
async function rt(e) {
|
|
1225
1247
|
let t = document.createElement("video");
|
|
1226
1248
|
return t.muted = !0, t.autoplay = !0, t.playsInline = !0, t.srcObject = e, await t.play(), t;
|
|
1227
1249
|
}
|
|
1228
|
-
async function
|
|
1250
|
+
async function it(t) {
|
|
1229
1251
|
await x("scan");
|
|
1230
|
-
let n =
|
|
1252
|
+
let n = Je(t.autoCapture), r = new et({
|
|
1231
1253
|
stableFrames: t.stableFrames ?? 4,
|
|
1232
1254
|
confidenceThreshold: t.confidenceThreshold ?? .72,
|
|
1233
1255
|
cornerTolerance: t.cornerTolerance ?? .024,
|
|
@@ -1236,7 +1258,7 @@ async function tt(t) {
|
|
|
1236
1258
|
minDimension: 220,
|
|
1237
1259
|
maxAnalysisDimension: 520,
|
|
1238
1260
|
...t.detection
|
|
1239
|
-
}, s = typeof MediaStream < "u" && t.source instanceof MediaStream ? await
|
|
1261
|
+
}, 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
1262
|
state: "detecting",
|
|
1241
1263
|
confidence: 0,
|
|
1242
1264
|
guidance: {
|
|
@@ -1253,10 +1275,10 @@ async function tt(t) {
|
|
|
1253
1275
|
stableFrames: 0,
|
|
1254
1276
|
requiredStableFrames: t.stableFrames ?? 4,
|
|
1255
1277
|
autoCapture: { ...n }
|
|
1256
|
-
}, g = () => s instanceof HTMLCanvasElement ?
|
|
1278
|
+
}, g = () => s instanceof HTMLCanvasElement ? tt(s, i) : Y(s, i), _ = (e) => {
|
|
1257
1279
|
h = e, t.onStatus?.(e);
|
|
1258
1280
|
}, v = (e) => {
|
|
1259
|
-
let t =
|
|
1281
|
+
let t = Ye(e, s instanceof HTMLVideoElement ? {
|
|
1260
1282
|
width: s.videoWidth,
|
|
1261
1283
|
height: s.videoHeight
|
|
1262
1284
|
} : {
|
|
@@ -1271,11 +1293,11 @@ async function tt(t) {
|
|
|
1271
1293
|
l = !0;
|
|
1272
1294
|
let n;
|
|
1273
1295
|
try {
|
|
1274
|
-
n = await
|
|
1296
|
+
n = await qe(t.captureFrame ?? g, () => {
|
|
1275
1297
|
_({
|
|
1276
1298
|
...h,
|
|
1277
1299
|
state: "captured"
|
|
1278
|
-
}), t.playShutterSound !== !1 &&
|
|
1300
|
+
}), t.playShutterSound !== !1 && nt(), y();
|
|
1279
1301
|
});
|
|
1280
1302
|
} catch (e) {
|
|
1281
1303
|
throw l = !1, e instanceof Error ? e : /* @__PURE__ */ Error("The camera frame could not be captured.");
|
|
@@ -1291,7 +1313,7 @@ async function tt(t) {
|
|
|
1291
1313
|
try {
|
|
1292
1314
|
let e = g(), i = await Se(e, o);
|
|
1293
1315
|
f = i, v(i);
|
|
1294
|
-
let a = i.quad ?
|
|
1316
|
+
let a = i.quad ? Ge(e, i.quad) : {
|
|
1295
1317
|
strong: !1,
|
|
1296
1318
|
strength: 0
|
|
1297
1319
|
}, s = a.strong ? {
|
|
@@ -1301,7 +1323,7 @@ async function tt(t) {
|
|
|
1301
1323
|
} : {
|
|
1302
1324
|
castShadow: !1,
|
|
1303
1325
|
strength: a.strength
|
|
1304
|
-
}, c = r.update(i), l =
|
|
1326
|
+
}, c = r.update(i), l = $e(i, {
|
|
1305
1327
|
...c,
|
|
1306
1328
|
previouslyReady: u
|
|
1307
1329
|
}, {
|
|
@@ -1383,6 +1405,6 @@ async function tt(t) {
|
|
|
1383
1405
|
};
|
|
1384
1406
|
}
|
|
1385
1407
|
//#endregion
|
|
1386
|
-
export {
|
|
1408
|
+
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
1409
|
|
|
1388
|
-
//# sourceMappingURL=finder-
|
|
1410
|
+
//# sourceMappingURL=finder-B3kHQ2Jh.js.map
|