@incodetech/core 2.3.0-rc.1 → 2.3.0-rc.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{BrowserDiagnosticsCryptoProvider-CU6kBvqv.esm.js → BrowserDiagnosticsCryptoProvider-BuzqvbhN.esm.js} +6 -24
- package/dist/{FaceDetectionProvider-BfhWkK90.esm.js → FaceDetectionProvider-BZYHujqz.esm.js} +8 -8
- package/dist/{MotionSensorProvider-BgTYwg9L.esm.js → MotionSensorProvider-DyhbM4Si.esm.js} +1 -1
- package/dist/ae-signature.esm.js +1 -1
- package/dist/{apiError-Budb6m6w.esm.js → apiError-iTFZ5fiI.esm.js} +1 -1
- package/dist/authentication.d.ts +2 -2
- package/dist/authentication.esm.js +2 -2
- package/dist/{authenticationManager-CjXBjC-c.d.ts → authenticationManager-B23V74p7.d.ts} +1 -1
- package/dist/{authenticationManager-cMXhG70r.esm.js → authenticationManager-D22ju23T.esm.js} +4 -4
- package/dist/{authenticationStateMachine-MOYz4HCf.esm.js → authenticationStateMachine-TyFaCegB.esm.js} +3 -3
- package/dist/{backCameraStream-BOtyQowf.esm.js → backCameraStream-B0-YgP_y.esm.js} +1 -0
- package/dist/camera.esm.js +1 -1
- package/dist/consent.d.ts +1 -1
- package/dist/{consentManager-BhYFeKiG.d.ts → consentManager-uhDPdU6i.d.ts} +8 -8
- package/dist/{createCameraCycleOwnership-CX3hJGKc.esm.js → createCameraCycleOwnership-DnwTl1ad.esm.js} +6 -1
- package/dist/{deepsightLoader-DDv3vhXU.esm.js → deepsightLoader-DamOBrBJ.esm.js} +6 -6
- package/dist/document-capture.d.ts +1 -1
- package/dist/document-capture.esm.js +2 -2
- package/dist/{documentCaptureManager-CwAiM9WY.esm.js → documentCaptureManager-BRPxqYD2.esm.js} +1 -1
- package/dist/{documentCaptureManager-DensIj5F.d.ts → documentCaptureManager-lEtCM320.d.ts} +14 -0
- package/dist/{documentCaptureStateMachine-DfGOBapD.esm.js → documentCaptureStateMachine-D312sSIu.esm.js} +13 -8
- package/dist/dynamic-forms.esm.js +2 -2
- package/dist/{dynamicFormsManager-BbS-XMFc.esm.js → dynamicFormsManager-DKgiusbF.esm.js} +1 -1
- package/dist/{dynamicFormsStateMachine-D8zHBCh4.esm.js → dynamicFormsStateMachine-BV8yR5iN.esm.js} +1 -1
- package/dist/ekyb.esm.js +3 -3
- package/dist/{ekybManager-5aiac8wL.esm.js → ekybManager-8VUBu8VW.esm.js} +1 -1
- package/dist/{ekybStateMachine-Bn2IE9rx.esm.js → ekybStateMachine-Bnsefu9M.esm.js} +1 -1
- package/dist/electronic-signature.esm.js +1 -1
- package/dist/{electronicSignatureManager-BJJH0Tvi.esm.js → electronicSignatureManager--YFXVldr.esm.js} +1 -1
- package/dist/extensibility.d.ts +7 -7
- package/dist/extensibility.esm.js +13 -13
- package/dist/{faceCaptureManagerFactory-B7Ms6pSs.esm.js → faceCaptureManagerFactory-Bk6pVs6E.esm.js} +3 -3
- package/dist/{faceCaptureManagerFactory-BeUl8fl1.d.ts → faceCaptureManagerFactory-DMLstvui.d.ts} +80 -40
- package/dist/{faceCaptureSetup-bkAlr5d8.esm.js → faceCaptureSetup-CGQDK97m.esm.js} +267 -45
- package/dist/{feature-management-E0mq0pMs.esm.js → feature-management-C8OAO_CZ.esm.js} +1 -1
- package/dist/feature-management.esm.js +1 -1
- package/dist/fiscal-qr.esm.js +1 -1
- package/dist/{fiscalQrManager-BunLVFbd.esm.js → fiscalQrManager-DbCVMIBx.esm.js} +1 -1
- package/dist/flow.esm.js +3 -3
- package/dist/{flowCompletionService-DJp1odGN.esm.js → flowCompletionService-C0zcPnqK.esm.js} +1 -1
- package/dist/{flowServices-DjPFGs_D.esm.js → flowServices-G1FDrkLd.esm.js} +5 -5
- package/dist/geolocation.esm.js +2 -2
- package/dist/{geolocationManager-D5906YXx.esm.js → geolocationManager-DNixQOgf.esm.js} +1 -1
- package/dist/{geolocationStateMachine-BVOduc3y.esm.js → geolocationStateMachine-D1aZJ6eR.esm.js} +1 -1
- package/dist/id-selfie-flow.esm.js +9 -9
- package/dist/id.d.ts +2 -2
- package/dist/id.esm.js +4 -4
- package/dist/idCaptureDefaults-sJahGQgV.esm.js +282 -0
- package/dist/{idCaptureManager-rfV9dIXy.esm.js → idCaptureManager-B8lo-ksK.esm.js} +5 -5
- package/dist/{idCaptureManager-DKESug0R.d.ts → idCaptureManager-BaHEyQyr.d.ts} +23 -5
- package/dist/{idCaptureServices-i1KxugN7.esm.js → idCaptureServices-DLqls7Xv.esm.js} +60 -13
- package/dist/{idCaptureStateMachine-Ne_PXth_.esm.js → idCaptureStateMachine-CCPGFPRF.esm.js} +221 -76
- package/dist/index.d.ts +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/mandatory-consent.d.ts +1 -1
- package/dist/{mandatoryConsentManager-vhv1co_n.d.ts → mandatoryConsentManager-CJSyhTpi.d.ts} +4 -4
- package/dist/{multipartRecordingService-OEgIRvqC.esm.js → multipartRecordingService-YKu0Bd7S.esm.js} +490 -8
- package/dist/{permissionGuards-uYZYFu4J.esm.js → permissionGuards-D6TfVop2.esm.js} +1 -1
- package/dist/{permissionServices-Bj_fyWtv.esm.js → permissionServices-EY3_Vx6c.esm.js} +2 -2
- package/dist/qe-signature.esm.js +1 -1
- package/dist/{runChildModule-CI1gGWN1.esm.js → runChildModule-B3Z4iJnG.esm.js} +1 -1
- package/dist/{safeStorage-B-trhxg6.esm.js → safeStorage-BdU9_m2E.esm.js} +1 -1
- package/dist/{sdkVersion-BZh6dj53.esm.js → sdkVersion-CD9fJC2Y.esm.js} +1 -1
- package/dist/selfie.d.ts +2 -2
- package/dist/selfie.esm.js +7 -7
- package/dist/{selfieManager-4RRLi21P.d.ts → selfieManager-CDCTOrcg.d.ts} +1 -1
- package/dist/{selfieManager-B-2c1n_x.esm.js → selfieManager-DzOPNipB.esm.js} +4 -4
- package/dist/{selfieStateMachine-Bzx41R8d.esm.js → selfieStateMachine-CidiobBW.esm.js} +3 -3
- package/dist/{session-3LmvAU4S.esm.js → session-BABCfUhC.esm.js} +3 -3
- package/dist/session.esm.js +4 -4
- package/dist/{sessionInitializer-BFk33E67.esm.js → sessionInitializer-BK5NjMe0.esm.js} +4 -4
- package/dist/{setup-Cv-JM9QC.d.ts → setup-Cyko6cAn.d.ts} +6 -18
- package/dist/{setup-BWG-hivt.esm.js → setup-D4YCSH31.esm.js} +12 -200
- package/dist/{tri-4RsGrIt6.esm.js → tri-xzRLIIMN.esm.js} +0 -10
- package/dist/tri.esm.js +1 -1
- package/dist/{trueSightService-BN-Hzw82.esm.js → trueSightService-D8yZwF3G.esm.js} +189 -570
- package/dist/video-selfie.esm.js +5 -6
- package/dist/{videoSelfieCameraWarmer-B8PcYqmz.esm.js → videoSelfieCameraWarmer-C80ZPDZ8.esm.js} +6 -6
- package/dist/{warmup-CUUnwYxe.esm.js → warmup-ChDwHSel.esm.js} +5 -0
- package/dist/wasm.d.ts +1 -1
- package/dist/wasm.esm.js +3 -2
- package/dist/{wasmDsFlagSync-B2e8p268.esm.js → wasmDsFlagSync-DYrLUEII.esm.js} +1 -1
- package/dist/workflow.esm.js +15 -15
- package/package.json +1 -6
- package/dist/FaceDetectionProvider-LdZ47bWy.d.ts +0 -36
- package/dist/StreamCanvasProcessingSession-CBnbTnOr.esm.js +0 -42
- package/dist/idCaptureDefaults-CbPA-Auz.esm.js +0 -727
- package/dist/personhood.d.ts +0 -538
- package/dist/personhood.esm.js +0 -1574
- package/dist/types-BT_Oalip.d.ts +0 -1
|
@@ -1,727 +0,0 @@
|
|
|
1
|
-
import { b as resolveWasmSource, p as WASM_MODEL_FILES } from "./wasmWebClient-B7baE-Wf.esm.js";
|
|
2
|
-
import { p as getBarcodeEnhanceModelUrl } from "./setup-BWG-hivt.esm.js";
|
|
3
|
-
import { s as wasmRuntime, t as getResolvedModelSource } from "./warmup-CUUnwYxe.esm.js";
|
|
4
|
-
import { i as BaseWasmProvider } from "./safeStorage-B-trhxg6.esm.js";
|
|
5
|
-
import { t as IncodeCanvas } from "./canvas-BxFzWTt-.esm.js";
|
|
6
|
-
//#region ../infra/src/media/cameraCompositorWorker.ts
|
|
7
|
-
/**
|
|
8
|
-
* Whether the worker transport is available here. Every probe must hold;
|
|
9
|
-
* anything missing routes `CameraCompositor` to its main-thread path.
|
|
10
|
-
*/
|
|
11
|
-
function canUseCameraCompositorWorker() {
|
|
12
|
-
const g = globalThis;
|
|
13
|
-
return typeof g.MediaStreamTrackProcessor === "function" && typeof g.MediaStreamTrackGenerator === "function" && typeof g.Worker === "function" && typeof g.OffscreenCanvas === "function" && typeof g.VideoFrame === "function";
|
|
14
|
-
}
|
|
15
|
-
function createTrackProcessor(track) {
|
|
16
|
-
const Ctor = globalThis.MediaStreamTrackProcessor;
|
|
17
|
-
if (!Ctor) throw new Error("MediaStreamTrackProcessor unavailable");
|
|
18
|
-
return new Ctor({ track });
|
|
19
|
-
}
|
|
20
|
-
function createTrackGenerator() {
|
|
21
|
-
const Ctor = globalThis.MediaStreamTrackGenerator;
|
|
22
|
-
if (!Ctor) throw new Error("MediaStreamTrackGenerator unavailable");
|
|
23
|
-
return new Ctor({ kind: "video" });
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* The worker's entire logic. SELF-CONTAINED (serialized via toString into the
|
|
27
|
-
* blob): no module references. Frame loop: read → scale within the bound →
|
|
28
|
-
* write → close. The processor buffers at most one frame, so reads always
|
|
29
|
-
* yield the freshest frame; while paused, frames are still read and closed so
|
|
30
|
-
* the camera's frame pool stays healthy — an unclosed VideoFrame can stall the
|
|
31
|
-
* capture pipeline, which the recording must never do.
|
|
32
|
-
*/
|
|
33
|
-
function cameraCompositorWorkerMain(scope) {
|
|
34
|
-
const g = globalThis;
|
|
35
|
-
let maxLongEdge = 1280;
|
|
36
|
-
let maxShortEdge = 720;
|
|
37
|
-
let canvas = null;
|
|
38
|
-
let ctx = null;
|
|
39
|
-
let writer = null;
|
|
40
|
-
let activeReader = null;
|
|
41
|
-
let generation = 0;
|
|
42
|
-
let paused = false;
|
|
43
|
-
let announceNextFrame = false;
|
|
44
|
-
const boundedSize = (width, height) => {
|
|
45
|
-
const scale = Math.min(1, maxLongEdge / Math.max(width, height), maxShortEdge / Math.min(width, height));
|
|
46
|
-
return {
|
|
47
|
-
width: Math.max(1, Math.round(width * scale)),
|
|
48
|
-
height: Math.max(1, Math.round(height * scale))
|
|
49
|
-
};
|
|
50
|
-
};
|
|
51
|
-
const scaled = (frame) => {
|
|
52
|
-
const size = boundedSize(frame.displayWidth, frame.displayHeight);
|
|
53
|
-
if (!canvas || !ctx || size.width === frame.displayWidth && size.height === frame.displayHeight) return frame;
|
|
54
|
-
if (canvas.width !== size.width || canvas.height !== size.height) {
|
|
55
|
-
canvas.width = size.width;
|
|
56
|
-
canvas.height = size.height;
|
|
57
|
-
}
|
|
58
|
-
ctx.drawImage(frame, 0, 0, size.width, size.height);
|
|
59
|
-
const out = new g.VideoFrame(canvas, { timestamp: frame.timestamp });
|
|
60
|
-
frame.close();
|
|
61
|
-
return out;
|
|
62
|
-
};
|
|
63
|
-
const pump = async (readable, gen) => {
|
|
64
|
-
const reader = readable.getReader();
|
|
65
|
-
activeReader = reader;
|
|
66
|
-
try {
|
|
67
|
-
for (;;) {
|
|
68
|
-
const { value: frame, done } = await reader.read();
|
|
69
|
-
if (done) {
|
|
70
|
-
if (gen === generation) scope.postMessage({ type: "ended" });
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
if (gen !== generation) {
|
|
74
|
-
frame.close();
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
if (paused || !writer) {
|
|
78
|
-
frame.close();
|
|
79
|
-
continue;
|
|
80
|
-
}
|
|
81
|
-
await writer.write(scaled(frame));
|
|
82
|
-
if (announceNextFrame) {
|
|
83
|
-
announceNextFrame = false;
|
|
84
|
-
scope.postMessage({ type: "frame" });
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
} catch (error) {
|
|
88
|
-
if (gen === generation) scope.postMessage({
|
|
89
|
-
type: "fatal",
|
|
90
|
-
message: String(error)
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
const switchSource = (readable) => {
|
|
95
|
-
generation += 1;
|
|
96
|
-
const previous = activeReader;
|
|
97
|
-
activeReader = null;
|
|
98
|
-
previous?.cancel().catch(() => {});
|
|
99
|
-
pump(readable, generation);
|
|
100
|
-
};
|
|
101
|
-
scope.onmessage = (event) => {
|
|
102
|
-
const message = event.data;
|
|
103
|
-
switch (message.type) {
|
|
104
|
-
case "start":
|
|
105
|
-
maxLongEdge = message.maxLongEdge;
|
|
106
|
-
maxShortEdge = message.maxShortEdge;
|
|
107
|
-
canvas = new g.OffscreenCanvas(1, 1);
|
|
108
|
-
ctx = canvas.getContext("2d");
|
|
109
|
-
writer = message.writable.getWriter();
|
|
110
|
-
announceNextFrame = true;
|
|
111
|
-
switchSource(message.readable);
|
|
112
|
-
break;
|
|
113
|
-
case "source":
|
|
114
|
-
switchSource(message.readable);
|
|
115
|
-
break;
|
|
116
|
-
case "pause":
|
|
117
|
-
paused = true;
|
|
118
|
-
break;
|
|
119
|
-
case "resume":
|
|
120
|
-
paused = false;
|
|
121
|
-
announceNextFrame = true;
|
|
122
|
-
break;
|
|
123
|
-
default: break;
|
|
124
|
-
}
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
/** Assembles the classic-worker script from the serialized worker main. */
|
|
128
|
-
function buildCameraCompositorWorkerSource() {
|
|
129
|
-
return [`const workerMain = ${cameraCompositorWorkerMain.toString()};`, "workerMain(self);"].join("\n");
|
|
130
|
-
}
|
|
131
|
-
//#endregion
|
|
132
|
-
//#region ../infra/src/media/CameraCompositor.ts
|
|
133
|
-
const MAX_COMPOSITE_LONG_EDGE = 1280;
|
|
134
|
-
const MAX_COMPOSITE_SHORT_EDGE = 720;
|
|
135
|
-
const FRAME_INTERVAL_TOLERANCE_RATIO = .9;
|
|
136
|
-
const DEFAULT_RESUME_TIMEOUT_MS = 2e3;
|
|
137
|
-
/**
|
|
138
|
-
* Composites the *active* camera into a single, stable `MediaStream` to
|
|
139
|
-
* record. Switching cameras (front ↔ back) just repoints the source — the
|
|
140
|
-
* output stream and its audio track are never replaced — so a single
|
|
141
|
-
* `MediaRecorder` produces one continuous video that follows the camera
|
|
142
|
-
* switches (V1 parity), instead of restarting per camera.
|
|
143
|
-
*
|
|
144
|
-
* Two transports (ENG-55397):
|
|
145
|
-
* - **Worker (preferred, Chromium 94+):** camera track →
|
|
146
|
-
* `MediaStreamTrackProcessor` → worker scales on an `OffscreenCanvas` →
|
|
147
|
-
* `MediaStreamTrackGenerator`. The main thread is not in the frame path, so
|
|
148
|
-
* the recording stays at camera rate while the synchronous ID detection
|
|
149
|
-
* tick saturates the main thread (measured: 4–9 fps main-thread vs 30 fps
|
|
150
|
-
* worker on a Galaxy S21 under the same load).
|
|
151
|
-
* - **Main thread (fallback):** hidden `<video>` → rVFC/rAF → canvas →
|
|
152
|
-
* `captureStream`, for Safari, Firefox and strict-CSP hosts that block blob
|
|
153
|
-
* workers.
|
|
154
|
-
*
|
|
155
|
-
* A worker that dies mid-recording (GPU-process crash, OOM) is released at
|
|
156
|
-
* once; the composite track stays valid but receives no further frames, and
|
|
157
|
-
* the next `resume()` reports `timed-out` so the caller reacquires the camera
|
|
158
|
-
* instead of talking to a dead worker.
|
|
159
|
-
*
|
|
160
|
-
* The audio track from the initial stream is carried through unchanged across
|
|
161
|
-
* video switches, so there's no audio glitch when the camera flips.
|
|
162
|
-
*/
|
|
163
|
-
var CameraCompositor = class {
|
|
164
|
-
constructor(options = {}) {
|
|
165
|
-
this.canvas = null;
|
|
166
|
-
this.ctx = null;
|
|
167
|
-
this.video = null;
|
|
168
|
-
this.transport = null;
|
|
169
|
-
this.generator = null;
|
|
170
|
-
this.frameRequestId = null;
|
|
171
|
-
this.frameRequestKind = null;
|
|
172
|
-
this.sourceExceedsTargetFps = false;
|
|
173
|
-
this.lastDrawTimeMs = null;
|
|
174
|
-
this.lastVideoTimeSeconds = null;
|
|
175
|
-
this.audioTrack = null;
|
|
176
|
-
this.videoTrack = null;
|
|
177
|
-
this.composite = null;
|
|
178
|
-
this.fps = options.fps ?? 30;
|
|
179
|
-
this.frameIntervalMs = this.fps > 0 ? 1e3 / this.fps : 0;
|
|
180
|
-
this.resumeTimeoutMs = options.resumeTimeoutMs ?? DEFAULT_RESUME_TIMEOUT_MS;
|
|
181
|
-
}
|
|
182
|
-
/**
|
|
183
|
-
* Begin compositing `stream` and return the composite stream to record. The
|
|
184
|
-
* stream's audio track (if any) is carried through unchanged across later
|
|
185
|
-
* `switchVideo` calls.
|
|
186
|
-
*/
|
|
187
|
-
start(stream) {
|
|
188
|
-
this.audioTrack = stream.getAudioTracks()[0] ?? null;
|
|
189
|
-
const composite = this.startWorkerTransport(stream) ?? this.startMainThread(stream);
|
|
190
|
-
if (this.audioTrack) composite.addTrack(this.audioTrack);
|
|
191
|
-
this.composite = composite;
|
|
192
|
-
return composite;
|
|
193
|
-
}
|
|
194
|
-
/**
|
|
195
|
-
* Swap the camera feeding the composite without interrupting the composite
|
|
196
|
-
* stream. Pass a video-only stream (audio is kept from `start`). The previous
|
|
197
|
-
* video track is stopped.
|
|
198
|
-
*/
|
|
199
|
-
switchVideo(stream) {
|
|
200
|
-
if (!this.composite) return;
|
|
201
|
-
const previousVideoTrack = this.videoTrack;
|
|
202
|
-
if (this.transport) {
|
|
203
|
-
this.videoTrack = stream.getVideoTracks()[0] ?? null;
|
|
204
|
-
if (this.videoTrack) try {
|
|
205
|
-
const processor = createTrackProcessor(this.videoTrack);
|
|
206
|
-
this.postToWorker({
|
|
207
|
-
type: "source",
|
|
208
|
-
readable: processor.readable
|
|
209
|
-
}, [processor.readable]);
|
|
210
|
-
} catch {}
|
|
211
|
-
} else if (this.video) {
|
|
212
|
-
this.setVideoSource(stream);
|
|
213
|
-
this.startDrawLoop();
|
|
214
|
-
} else this.videoTrack = stream.getVideoTracks()[0] ?? null;
|
|
215
|
-
if (previousVideoTrack) previousVideoTrack.stop();
|
|
216
|
-
}
|
|
217
|
-
/** The composite stream being recorded, if compositing is active. */
|
|
218
|
-
get stream() {
|
|
219
|
-
return this.composite ?? void 0;
|
|
220
|
-
}
|
|
221
|
-
/** Pause source playback and drawing while the page is backgrounded. */
|
|
222
|
-
pause() {
|
|
223
|
-
this.finishResume("timed-out");
|
|
224
|
-
if (this.transport) {
|
|
225
|
-
this.postToWorker({ type: "pause" });
|
|
226
|
-
return;
|
|
227
|
-
}
|
|
228
|
-
this.cancelDrawLoop();
|
|
229
|
-
this.video?.pause();
|
|
230
|
-
}
|
|
231
|
-
/**
|
|
232
|
-
* Restart source playback and wait for a genuinely new camera frame to reach
|
|
233
|
-
* the stable composite stream. The caller must not resume encoding until
|
|
234
|
-
* this resolves with `resumed`.
|
|
235
|
-
*/
|
|
236
|
-
async resume(signal) {
|
|
237
|
-
const video = this.video;
|
|
238
|
-
if (!this.composite || !video && !this.transport) return "timed-out";
|
|
239
|
-
if (this.audioTrack?.readyState === "ended") return "audio-ended";
|
|
240
|
-
if (!this.videoTrack || this.videoTrack.readyState === "ended") return "video-ended";
|
|
241
|
-
if (signal?.aborted) return "timed-out";
|
|
242
|
-
if (video && !this.transport) {
|
|
243
|
-
try {
|
|
244
|
-
await video.play();
|
|
245
|
-
} catch {
|
|
246
|
-
return "timed-out";
|
|
247
|
-
}
|
|
248
|
-
if (signal?.aborted) return "timed-out";
|
|
249
|
-
}
|
|
250
|
-
this.finishResume("timed-out");
|
|
251
|
-
return new Promise((resolve) => {
|
|
252
|
-
const timeout = setTimeout(() => {
|
|
253
|
-
this.finishResume("timed-out");
|
|
254
|
-
}, this.resumeTimeoutMs);
|
|
255
|
-
if (signal) {
|
|
256
|
-
const onAbort = () => this.finishResume("timed-out");
|
|
257
|
-
this.resumeWaiter = {
|
|
258
|
-
resolve,
|
|
259
|
-
timeout,
|
|
260
|
-
signal,
|
|
261
|
-
onAbort
|
|
262
|
-
};
|
|
263
|
-
signal.addEventListener("abort", onAbort, { once: true });
|
|
264
|
-
if (signal.aborted) {
|
|
265
|
-
this.finishResume("timed-out");
|
|
266
|
-
return;
|
|
267
|
-
}
|
|
268
|
-
} else this.resumeWaiter = {
|
|
269
|
-
resolve,
|
|
270
|
-
timeout
|
|
271
|
-
};
|
|
272
|
-
if (this.transport) {
|
|
273
|
-
this.postToWorker({ type: "resume" });
|
|
274
|
-
return;
|
|
275
|
-
}
|
|
276
|
-
this.startDrawLoop(false);
|
|
277
|
-
});
|
|
278
|
-
}
|
|
279
|
-
/** Stop compositing and release the worker, canvas, audio and video tracks. */
|
|
280
|
-
stop() {
|
|
281
|
-
this.finishResume("timed-out");
|
|
282
|
-
this.cancelDrawLoop();
|
|
283
|
-
this.releaseWorker();
|
|
284
|
-
this.generator?.stop();
|
|
285
|
-
this.generator = null;
|
|
286
|
-
this.videoTrack?.stop();
|
|
287
|
-
this.audioTrack?.stop();
|
|
288
|
-
this.composite?.getTracks().forEach((track) => track.stop());
|
|
289
|
-
if (this.video) this.video.srcObject = null;
|
|
290
|
-
this.canvas = null;
|
|
291
|
-
this.ctx = null;
|
|
292
|
-
this.video = null;
|
|
293
|
-
this.videoTrack = null;
|
|
294
|
-
this.audioTrack = null;
|
|
295
|
-
this.composite = null;
|
|
296
|
-
}
|
|
297
|
-
/**
|
|
298
|
-
* Worker transport. Returns `null` — and leaves nothing behind — when the
|
|
299
|
-
* browser lacks insertable streams or a strict `worker-src` CSP blocks blob
|
|
300
|
-
* workers, so `start` falls through to the main-thread path. Never throws.
|
|
301
|
-
*/
|
|
302
|
-
startWorkerTransport(stream) {
|
|
303
|
-
const track = stream.getVideoTracks()[0];
|
|
304
|
-
if (!track || !canUseCameraCompositorWorker()) return null;
|
|
305
|
-
let worker = null;
|
|
306
|
-
let generator = null;
|
|
307
|
-
let blobUrl = null;
|
|
308
|
-
try {
|
|
309
|
-
const processor = createTrackProcessor(track);
|
|
310
|
-
generator = createTrackGenerator();
|
|
311
|
-
blobUrl = URL.createObjectURL(new Blob([buildCameraCompositorWorkerSource()], { type: "text/javascript" }));
|
|
312
|
-
worker = new Worker(blobUrl);
|
|
313
|
-
worker.onmessage = (event) => this.onWorkerMessage(event.data);
|
|
314
|
-
worker.onerror = (event) => this.onWorkerMessage({
|
|
315
|
-
type: "fatal",
|
|
316
|
-
message: event?.message || "worker error"
|
|
317
|
-
});
|
|
318
|
-
const message = {
|
|
319
|
-
type: "start",
|
|
320
|
-
readable: processor.readable,
|
|
321
|
-
writable: generator.writable,
|
|
322
|
-
maxLongEdge: MAX_COMPOSITE_LONG_EDGE,
|
|
323
|
-
maxShortEdge: MAX_COMPOSITE_SHORT_EDGE
|
|
324
|
-
};
|
|
325
|
-
worker.postMessage(message, [processor.readable, generator.writable]);
|
|
326
|
-
} catch {
|
|
327
|
-
worker?.terminate();
|
|
328
|
-
generator?.stop();
|
|
329
|
-
if (blobUrl) URL.revokeObjectURL(blobUrl);
|
|
330
|
-
return null;
|
|
331
|
-
}
|
|
332
|
-
this.videoTrack = track;
|
|
333
|
-
this.transport = {
|
|
334
|
-
worker,
|
|
335
|
-
blobUrl
|
|
336
|
-
};
|
|
337
|
-
this.generator = generator;
|
|
338
|
-
return new MediaStream([generator]);
|
|
339
|
-
}
|
|
340
|
-
/** Terminates the worker and frees its blob; idempotent. */
|
|
341
|
-
releaseWorker() {
|
|
342
|
-
if (!this.transport) return;
|
|
343
|
-
this.transport.worker.terminate();
|
|
344
|
-
URL.revokeObjectURL(this.transport.blobUrl);
|
|
345
|
-
this.transport = null;
|
|
346
|
-
}
|
|
347
|
-
startMainThread(stream) {
|
|
348
|
-
this.canvas = document.createElement("canvas");
|
|
349
|
-
this.ctx = this.canvas.getContext("2d");
|
|
350
|
-
this.video = document.createElement("video");
|
|
351
|
-
this.video.muted = true;
|
|
352
|
-
this.video.playsInline = true;
|
|
353
|
-
this.setVideoSource(stream);
|
|
354
|
-
const composite = this.canvas.captureStream(this.fps);
|
|
355
|
-
this.startDrawLoop();
|
|
356
|
-
return composite;
|
|
357
|
-
}
|
|
358
|
-
postToWorker(message, transfer = []) {
|
|
359
|
-
this.transport?.worker.postMessage(message, transfer);
|
|
360
|
-
}
|
|
361
|
-
onWorkerMessage(message) {
|
|
362
|
-
if (!this.transport) return;
|
|
363
|
-
switch (message.type) {
|
|
364
|
-
case "frame":
|
|
365
|
-
this.finishResume("resumed");
|
|
366
|
-
break;
|
|
367
|
-
case "ended":
|
|
368
|
-
this.finishResume("video-ended");
|
|
369
|
-
break;
|
|
370
|
-
case "fatal":
|
|
371
|
-
this.releaseWorker();
|
|
372
|
-
this.finishResume("timed-out");
|
|
373
|
-
break;
|
|
374
|
-
default: break;
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
setVideoSource(stream) {
|
|
378
|
-
this.videoTrack = stream.getVideoTracks()[0] ?? null;
|
|
379
|
-
const sourceFps = this.videoTrack && typeof this.videoTrack.getSettings === "function" ? this.videoTrack.getSettings().frameRate : void 0;
|
|
380
|
-
this.sourceExceedsTargetFps = typeof sourceFps === "number" && sourceFps > this.fps;
|
|
381
|
-
const video = this.video;
|
|
382
|
-
if (!video) return;
|
|
383
|
-
video.srcObject = new MediaStream(stream.getVideoTracks());
|
|
384
|
-
video.play().catch(() => {});
|
|
385
|
-
}
|
|
386
|
-
startDrawLoop(resetSourceTime = true) {
|
|
387
|
-
this.cancelDrawLoop();
|
|
388
|
-
this.lastDrawTimeMs = null;
|
|
389
|
-
if (resetSourceTime) this.lastVideoTimeSeconds = null;
|
|
390
|
-
const draw = (timeMs) => {
|
|
391
|
-
const elapsed = this.lastDrawTimeMs === null ? Infinity : timeMs - this.lastDrawTimeMs;
|
|
392
|
-
if ((!(this.frameIntervalMs > 0 && (this.frameRequestKind !== "video" || this.sourceExceedsTargetFps)) || elapsed >= this.frameIntervalMs * FRAME_INTERVAL_TOLERANCE_RATIO) && this.drawCurrentFrame()) {
|
|
393
|
-
this.lastDrawTimeMs = timeMs;
|
|
394
|
-
this.finishResume("resumed");
|
|
395
|
-
}
|
|
396
|
-
this.scheduleNextFrame(draw);
|
|
397
|
-
};
|
|
398
|
-
this.scheduleNextFrame(draw);
|
|
399
|
-
}
|
|
400
|
-
finishResume(result) {
|
|
401
|
-
const waiter = this.resumeWaiter;
|
|
402
|
-
if (!waiter) return;
|
|
403
|
-
this.resumeWaiter = void 0;
|
|
404
|
-
clearTimeout(waiter.timeout);
|
|
405
|
-
if ("signal" in waiter) waiter.signal.removeEventListener("abort", waiter.onAbort);
|
|
406
|
-
waiter.resolve(result);
|
|
407
|
-
}
|
|
408
|
-
scheduleNextFrame(callback) {
|
|
409
|
-
const video = this.video;
|
|
410
|
-
if (video && typeof video.requestVideoFrameCallback === "function") {
|
|
411
|
-
this.frameRequestKind = "video";
|
|
412
|
-
this.frameRequestId = video.requestVideoFrameCallback(callback);
|
|
413
|
-
return;
|
|
414
|
-
}
|
|
415
|
-
this.frameRequestKind = "animation";
|
|
416
|
-
this.frameRequestId = requestAnimationFrame(callback);
|
|
417
|
-
}
|
|
418
|
-
cancelDrawLoop() {
|
|
419
|
-
if (this.frameRequestId === null) return;
|
|
420
|
-
if (this.frameRequestKind === "video" && this.video && typeof this.video.cancelVideoFrameCallback === "function") this.video.cancelVideoFrameCallback(this.frameRequestId);
|
|
421
|
-
else cancelAnimationFrame(this.frameRequestId);
|
|
422
|
-
this.frameRequestId = null;
|
|
423
|
-
this.frameRequestKind = null;
|
|
424
|
-
}
|
|
425
|
-
drawCurrentFrame() {
|
|
426
|
-
const video = this.video;
|
|
427
|
-
const canvas = this.canvas;
|
|
428
|
-
const ctx = this.ctx;
|
|
429
|
-
if (!video || !canvas || !ctx || video.videoWidth <= 0) return false;
|
|
430
|
-
if (this.lastVideoTimeSeconds === video.currentTime) return false;
|
|
431
|
-
const dimensions = this.getBoundedDimensions(video.videoWidth, video.videoHeight);
|
|
432
|
-
if (canvas.width !== dimensions.width || canvas.height !== dimensions.height) {
|
|
433
|
-
canvas.width = dimensions.width;
|
|
434
|
-
canvas.height = dimensions.height;
|
|
435
|
-
}
|
|
436
|
-
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
|
|
437
|
-
this.lastVideoTimeSeconds = video.currentTime;
|
|
438
|
-
return true;
|
|
439
|
-
}
|
|
440
|
-
getBoundedDimensions(width, height) {
|
|
441
|
-
const longEdge = Math.max(width, height);
|
|
442
|
-
const shortEdge = Math.min(width, height);
|
|
443
|
-
const scale = Math.min(1, MAX_COMPOSITE_LONG_EDGE / longEdge, MAX_COMPOSITE_SHORT_EDGE / shortEdge);
|
|
444
|
-
return {
|
|
445
|
-
width: Math.max(1, Math.round(width * scale)),
|
|
446
|
-
height: Math.max(1, Math.round(height * scale))
|
|
447
|
-
};
|
|
448
|
-
}
|
|
449
|
-
};
|
|
450
|
-
//#endregion
|
|
451
|
-
//#region ../infra/src/wasm/idCaptureWasmApi.ts
|
|
452
|
-
var IdCaptureWasmApi = class {
|
|
453
|
-
constructor(runtime = wasmRuntime) {
|
|
454
|
-
this.runtime = runtime;
|
|
455
|
-
}
|
|
456
|
-
async setIdCaptureThresholds(type, blurThreshold, blurChangeThreshold, glareThreshold, clsThreshold, sideThreshold, iouThreshold, idDetectedTimeout, autocaptureTimeout, framesAggregationInterval) {
|
|
457
|
-
this.runtime.requireIdCaptureApi("Unable to set thresholds, cpp API hasn't been initialized").setIdCaptureThresholds(this.runtime.pipelineTypeToWasmEnum(type), blurThreshold, blurChangeThreshold, glareThreshold, clsThreshold, sideThreshold, iouThreshold, idDetectedTimeout, autocaptureTimeout, framesAggregationInterval);
|
|
458
|
-
}
|
|
459
|
-
async setIdCaptureCallbacks(type, onFarAway, onDetectionStarted, onMaskChange, onBlur, onGlare, onCapturing, onCapture, onBestFrame, onIDNotDetected, onSwitchToManualCapture, onIDTypeChange, onIDSideChange, onCapturingCounterValueChange) {
|
|
460
|
-
this.runtime.requireIdCaptureApi("Unable to set callbacks, cpp API hasn't been initialized").setIdCaptureCallbacks(this.runtime.pipelineTypeToWasmEnum(type), onFarAway, onDetectionStarted, onMaskChange, onBlur, onGlare, onCapturing, onCapture, onBestFrame, onIDNotDetected, onSwitchToManualCapture, onIDTypeChange, onIDSideChange, onCapturingCounterValueChange);
|
|
461
|
-
}
|
|
462
|
-
async setIdCaptureGeometryParams(type, areaDown, areaUp, areaIOSPassportUp, areaIOSPassportDown, widthIOSUp, widthIOSDown, widthDown, widthUp, windowOuterWidth, windowOuterHeight, windowInnerWidth, windowInnerHeight) {
|
|
463
|
-
this.runtime.requireIdCaptureApi("Unable to set geometry params, cpp API hasn't been initialized").setIdCaptureGeometryParams(this.runtime.pipelineTypeToWasmEnum(type), areaDown, areaUp, areaIOSPassportUp, areaIOSPassportDown, widthIOSUp, widthIOSDown, widthDown, widthUp, windowOuterWidth, windowOuterHeight, windowInnerWidth, windowInnerHeight);
|
|
464
|
-
}
|
|
465
|
-
async setIdCaptureConfigParams(type, isFixedMask, isIPhone14OrHigher, idType, isBlurCheckEnabled, isGlareCheckEnabled, _isIdFaceQualityCheckEnabled, isIouCheckEnabled, _isFPSLimitEnabled) {
|
|
466
|
-
this.runtime.requireIdCaptureApi("Unable to set config params, cpp API hasn't been initialized").setIdCaptureConfigParams(this.runtime.pipelineTypeToWasmEnum(type), isFixedMask, isIPhone14OrHigher, idType, isBlurCheckEnabled, isGlareCheckEnabled, isIouCheckEnabled);
|
|
467
|
-
}
|
|
468
|
-
setIdCaptureModelType(pipelineType, modelType) {
|
|
469
|
-
this.runtime.requireIdCaptureApi("Unable to set model type, cpp API hasn't been initialized").setIdCaptureModelType(this.runtime.pipelineTypeToWasmEnum(pipelineType), this.runtime.IdCaptureModelTypeToWasmEnum(modelType));
|
|
470
|
-
}
|
|
471
|
-
setIdBarcodeCaptureEnabled(pipelineType, enabled) {
|
|
472
|
-
this.runtime.requireIdCaptureApi("Unable to set barcode capture enabled, cpp API hasn't been initialized").setIdBarcodeCaptureEnabled(this.runtime.pipelineTypeToWasmEnum(pipelineType), enabled);
|
|
473
|
-
}
|
|
474
|
-
setIdBarcodeAutoCaptureOnDecode(pipelineType, enabled) {
|
|
475
|
-
this.runtime.requireIdCaptureApi("Unable to set barcode auto-capture-on-decode, cpp API hasn't been initialized").setIdBarcodeAutoCaptureOnDecode(this.runtime.pipelineTypeToWasmEnum(pipelineType), enabled);
|
|
476
|
-
}
|
|
477
|
-
setIdBarcodeDecodedCallback(pipelineType, onBarcodeDecoded) {
|
|
478
|
-
this.runtime.requireIdCaptureApi("Unable to set barcode decoded callback, cpp API hasn't been initialized").setIdBarcodeDecodedCallback(this.runtime.pipelineTypeToWasmEnum(pipelineType), onBarcodeDecoded);
|
|
479
|
-
}
|
|
480
|
-
async setIdBarcodeEnhancementModel(pipelineType, modelPath) {
|
|
481
|
-
const message = "Unable to set barcode enhancement model, cpp API hasn't been initialized";
|
|
482
|
-
this.runtime.requireIdCaptureApi(message);
|
|
483
|
-
const buffer = await resolveWasmSource(modelPath, "barcode model");
|
|
484
|
-
return this.runtime.requireIdCaptureApi(message).setBarcodeEnhancementModel(this.runtime.pipelineTypeToWasmEnum(pipelineType), buffer);
|
|
485
|
-
}
|
|
486
|
-
IdPerspectiveTransform(image, frameRect) {
|
|
487
|
-
return this.runtime.requireIdCaptureApi("Unable to perform perspective transform, cpp API hasn't been initialized").IdPerspectiveTransform(image, frameRect);
|
|
488
|
-
}
|
|
489
|
-
/**
|
|
490
|
-
* Kept-dead: mirrors upstream `wasmApi.runIdCapture`. Nothing in the SDK calls
|
|
491
|
-
* it; it exists so the mirror stays 1:1 with upstream at the pinned tag.
|
|
492
|
-
*/
|
|
493
|
-
async runIdCapture(image) {
|
|
494
|
-
const idCaptureWasmApi = this.runtime.requireIdCaptureApi("Unable to run Id Capture, cpp API hasn't been initialized");
|
|
495
|
-
if (image) {
|
|
496
|
-
await this.runtime.allocateImageBuffers(image.width, image.height);
|
|
497
|
-
this.runtime.writeFrame(image);
|
|
498
|
-
}
|
|
499
|
-
return idCaptureWasmApi.runIdCapture();
|
|
500
|
-
}
|
|
501
|
-
};
|
|
502
|
-
const idCaptureWasmApi = new IdCaptureWasmApi();
|
|
503
|
-
//#endregion
|
|
504
|
-
//#region ../infra/src/providers/wasm/IdCaptureProvider.ts
|
|
505
|
-
var IdCaptureProvider = class extends BaseWasmProvider {
|
|
506
|
-
constructor(protectedWorkflow) {
|
|
507
|
-
super(protectedWorkflow ?? 0);
|
|
508
|
-
this.lastProcessResult = null;
|
|
509
|
-
this.capturedCanvas = null;
|
|
510
|
-
this.originalCapturedCanvas = null;
|
|
511
|
-
this.lastDecodedBarcode = null;
|
|
512
|
-
this.barcodeEnhancementModelLoaded = false;
|
|
513
|
-
}
|
|
514
|
-
async initialize(config) {
|
|
515
|
-
if (config.videoSelfie === true) {
|
|
516
|
-
if (this.pipelineType !== 0) throw new Error("[Incode SDK] Protected ID workflows are unavailable for video selfie.");
|
|
517
|
-
this.pipelineType = 2;
|
|
518
|
-
await this.initializeBase(config, "videoSelfieId");
|
|
519
|
-
} else await this.initializeBase(config, "idCapture");
|
|
520
|
-
}
|
|
521
|
-
setCallbacks(callbacks) {
|
|
522
|
-
this.ensureInitialized();
|
|
523
|
-
const onCaptureWrapper = (canvas) => {
|
|
524
|
-
callbacks.onCapture?.(canvas);
|
|
525
|
-
};
|
|
526
|
-
idCaptureWasmApi.setIdCaptureCallbacks(this.getPipelineType(), callbacks.onFarAway ?? (() => {}), callbacks.onDetectionStarted ?? (() => {}), callbacks.onMaskChange ? (show, mask, top, orientation) => callbacks.onMaskChange?.(show, mask, top, orientation) : () => {}, callbacks.onBlur ?? (() => {}), callbacks.onGlare ?? (() => {}), callbacks.onCapturing ?? (() => {}), callbacks.onCapture ? onCaptureWrapper : () => {}, callbacks.onBestFrame ? (blur, glare, orientation) => callbacks.onBestFrame?.(blur, glare, orientation) : () => {}, callbacks.onIdNotDetected ?? (() => {}), callbacks.onSwitchToManualCapture ?? (() => {}), callbacks.onIdTypeChange ? (idType) => callbacks.onIdTypeChange?.(idType) : () => {}, callbacks.onIdSideChange ? (side) => callbacks.onIdSideChange?.(side) : () => {}, callbacks.onCapturingCounterValueChange ? (value) => callbacks.onCapturingCounterValueChange?.(value) : () => {});
|
|
527
|
-
if (callbacks.onBarcodeDecoded) {
|
|
528
|
-
const onBarcodeDecoded = callbacks.onBarcodeDecoded;
|
|
529
|
-
idCaptureWasmApi.setIdBarcodeDecodedCallback(this.getPipelineType(), (decoded) => {
|
|
530
|
-
this.lastDecodedBarcode = decoded;
|
|
531
|
-
onBarcodeDecoded(decoded);
|
|
532
|
-
});
|
|
533
|
-
} else idCaptureWasmApi.setIdBarcodeDecodedCallback(this.getPipelineType(), () => {});
|
|
534
|
-
}
|
|
535
|
-
setThresholds(thresholds) {
|
|
536
|
-
this.ensureInitialized();
|
|
537
|
-
idCaptureWasmApi.setIdCaptureThresholds(this.getPipelineType(), thresholds.blurThreshold, thresholds.blurChangeThreshold, thresholds.glareThreshold, thresholds.clsThreshold, thresholds.sideThreshold, thresholds.iouThreshold, thresholds.idDetectedTimeout, thresholds.autocaptureTimeout, thresholds.framesAggregationInterval);
|
|
538
|
-
}
|
|
539
|
-
setGeometry(geometry) {
|
|
540
|
-
this.ensureInitialized();
|
|
541
|
-
idCaptureWasmApi.setIdCaptureGeometryParams(this.getPipelineType(), geometry.areaDown, geometry.areaUp, geometry.areaIOSPassportUp, geometry.areaIOSPassportDown, geometry.widthIOSUp, geometry.widthIOSDown, geometry.widthDown, geometry.widthUp, geometry.windowOuterWidth, geometry.windowOuterHeight, geometry.windowInnerWidth, geometry.windowInnerHeight);
|
|
542
|
-
}
|
|
543
|
-
setSettings(settings) {
|
|
544
|
-
this.ensureInitialized();
|
|
545
|
-
idCaptureWasmApi.setIdCaptureConfigParams(this.getPipelineType(), settings.isFixedMask, settings.isIPhone14OrHigher, settings.idType, settings.blurCheckEnabled, settings.glareCheckEnabled, settings.faceQualityCheckEnabled, settings.iouCheckEnabled, settings.fpsLimitEnabled);
|
|
546
|
-
}
|
|
547
|
-
setModelType(modelType) {
|
|
548
|
-
this.ensureInitialized();
|
|
549
|
-
let wasmModelType;
|
|
550
|
-
switch (modelType) {
|
|
551
|
-
case "v1":
|
|
552
|
-
wasmModelType = 0;
|
|
553
|
-
break;
|
|
554
|
-
case "v2":
|
|
555
|
-
wasmModelType = 1;
|
|
556
|
-
break;
|
|
557
|
-
case "v3":
|
|
558
|
-
wasmModelType = 2;
|
|
559
|
-
break;
|
|
560
|
-
default: throw new Error(`Unknown model type: ${modelType}`);
|
|
561
|
-
}
|
|
562
|
-
idCaptureWasmApi.setIdCaptureModelType(this.getPipelineType(), wasmModelType);
|
|
563
|
-
}
|
|
564
|
-
setBarcodeCaptureEnabled(enabled) {
|
|
565
|
-
this.ensureInitialized();
|
|
566
|
-
idCaptureWasmApi.setIdBarcodeCaptureEnabled(this.getPipelineType(), enabled);
|
|
567
|
-
}
|
|
568
|
-
setBarcodeAutoCaptureOnDecode(enabled) {
|
|
569
|
-
this.ensureInitialized();
|
|
570
|
-
idCaptureWasmApi.setIdBarcodeAutoCaptureOnDecode(this.getPipelineType(), enabled);
|
|
571
|
-
}
|
|
572
|
-
async setBarcodeEnhancementModel() {
|
|
573
|
-
this.ensureInitialized();
|
|
574
|
-
if (this.barcodeEnhancementModelLoaded) return true;
|
|
575
|
-
const modelUrl = getResolvedModelSource(WASM_MODEL_FILES.barcode, "idCapture") ?? getBarcodeEnhanceModelUrl();
|
|
576
|
-
const applied = await idCaptureWasmApi.setIdBarcodeEnhancementModel(this.getPipelineType(), modelUrl);
|
|
577
|
-
this.barcodeEnhancementModelLoaded = applied;
|
|
578
|
-
return applied;
|
|
579
|
-
}
|
|
580
|
-
getLastDecodedBarcode() {
|
|
581
|
-
return this.lastDecodedBarcode;
|
|
582
|
-
}
|
|
583
|
-
/**
|
|
584
|
-
* Processes a frame through the WASM pipeline and stores the result.
|
|
585
|
-
*/
|
|
586
|
-
async processFrame(image) {
|
|
587
|
-
const result = await this.processFrameWasm(image);
|
|
588
|
-
const pipelineType = this.getPipelineType();
|
|
589
|
-
if (result && (pipelineType === 0 || pipelineType === 2)) this.lastProcessResult = result;
|
|
590
|
-
else this.lastProcessResult = null;
|
|
591
|
-
}
|
|
592
|
-
/**
|
|
593
|
-
* Gets the last process result from the most recent frame processing.
|
|
594
|
-
* @returns The last process result with quad coordinates, or null if not available
|
|
595
|
-
*/
|
|
596
|
-
getLastProcessResult() {
|
|
597
|
-
return this.lastProcessResult;
|
|
598
|
-
}
|
|
599
|
-
transformPerspective(canvas, frameRect) {
|
|
600
|
-
this.ensureInitialized();
|
|
601
|
-
const originalWidth = canvas.width();
|
|
602
|
-
const originalHeight = canvas.height();
|
|
603
|
-
try {
|
|
604
|
-
const imageData = canvas.getImageData();
|
|
605
|
-
if (!imageData) return canvas;
|
|
606
|
-
const transformedCanvas = idCaptureWasmApi.IdPerspectiveTransform(imageData, frameRect);
|
|
607
|
-
if (transformedCanvas) {
|
|
608
|
-
const wrappedCanvas = new IncodeCanvas(transformedCanvas);
|
|
609
|
-
const wrappedWidth = wrappedCanvas.width();
|
|
610
|
-
const wrappedHeight = wrappedCanvas.height();
|
|
611
|
-
if (wrappedWidth === originalWidth && wrappedHeight === originalHeight) {
|
|
612
|
-
const croppedCanvas = this.cropCanvasToRect(wrappedCanvas, {
|
|
613
|
-
x: Math.round(frameRect.x),
|
|
614
|
-
y: Math.round(frameRect.y),
|
|
615
|
-
w: Math.round(frameRect.w),
|
|
616
|
-
h: Math.round(frameRect.h)
|
|
617
|
-
});
|
|
618
|
-
if (croppedCanvas) return croppedCanvas;
|
|
619
|
-
}
|
|
620
|
-
return wrappedCanvas;
|
|
621
|
-
}
|
|
622
|
-
return canvas;
|
|
623
|
-
} catch (_error) {
|
|
624
|
-
return canvas;
|
|
625
|
-
}
|
|
626
|
-
}
|
|
627
|
-
/**
|
|
628
|
-
* Crops a canvas to the specified rectangle region.
|
|
629
|
-
* @param canvas - The canvas to crop
|
|
630
|
-
* @param rect - The rectangle to crop to (x, y, w, h)
|
|
631
|
-
* @returns A new IncodeCanvas with the cropped region, or null if cropping fails
|
|
632
|
-
*/
|
|
633
|
-
cropCanvasToRect(canvas, rect) {
|
|
634
|
-
const canvasWidth = canvas.width();
|
|
635
|
-
const canvasHeight = canvas.height();
|
|
636
|
-
if (!canvasWidth || !canvasHeight) return null;
|
|
637
|
-
const x = Math.max(0, Math.min(rect.x, canvasWidth));
|
|
638
|
-
const y = Math.max(0, Math.min(rect.y, canvasHeight));
|
|
639
|
-
const w = Math.max(1, Math.min(rect.w, canvasWidth - x));
|
|
640
|
-
const h = Math.max(1, Math.min(rect.h, canvasHeight - y));
|
|
641
|
-
const croppedCanvasElement = document.createElement("canvas");
|
|
642
|
-
croppedCanvasElement.width = w;
|
|
643
|
-
croppedCanvasElement.height = h;
|
|
644
|
-
const ctx = croppedCanvasElement.getContext("2d");
|
|
645
|
-
if (!ctx) return null;
|
|
646
|
-
ctx.drawImage(canvas.canvas, x, y, w, h, 0, 0, w, h);
|
|
647
|
-
return new IncodeCanvas(croppedCanvasElement);
|
|
648
|
-
}
|
|
649
|
-
/**
|
|
650
|
-
* Gets the captured canvas (transformed for preview).
|
|
651
|
-
* @returns The captured canvas, or null if not available
|
|
652
|
-
*/
|
|
653
|
-
getCapturedCanvas() {
|
|
654
|
-
return this.capturedCanvas;
|
|
655
|
-
}
|
|
656
|
-
/**
|
|
657
|
-
* Gets the original captured canvas (full frame for upload).
|
|
658
|
-
* @returns The original captured canvas, or null if not available
|
|
659
|
-
*/
|
|
660
|
-
getOriginalCapturedCanvas() {
|
|
661
|
-
return this.originalCapturedCanvas;
|
|
662
|
-
}
|
|
663
|
-
/**
|
|
664
|
-
* Sets the captured canvases (original and transformed).
|
|
665
|
-
* @param original - The original full-frame canvas (for upload)
|
|
666
|
-
* @param transformed - The transformed canvas (for preview)
|
|
667
|
-
*/
|
|
668
|
-
setCapturedCanvases(original, transformed) {
|
|
669
|
-
this.originalCapturedCanvas = original;
|
|
670
|
-
this.capturedCanvas = transformed;
|
|
671
|
-
}
|
|
672
|
-
/**
|
|
673
|
-
* Re-arms WASM detection without discarding the captured result.
|
|
674
|
-
*
|
|
675
|
-
* Detection-session teardown runs immediately after a successful capture.
|
|
676
|
-
* The captured canvases must remain available for the subsequent upload and
|
|
677
|
-
* are only replaced by `setCapturedCanvases()` or cleared by a full reset.
|
|
678
|
-
*/
|
|
679
|
-
resetDetectionState() {
|
|
680
|
-
super.reset();
|
|
681
|
-
this.lastProcessResult = null;
|
|
682
|
-
this.lastDecodedBarcode = null;
|
|
683
|
-
}
|
|
684
|
-
reset() {
|
|
685
|
-
this.resetDetectionState();
|
|
686
|
-
this.capturedCanvas = null;
|
|
687
|
-
this.originalCapturedCanvas = null;
|
|
688
|
-
}
|
|
689
|
-
async dispose() {
|
|
690
|
-
await super.dispose();
|
|
691
|
-
this.barcodeEnhancementModelLoaded = false;
|
|
692
|
-
}
|
|
693
|
-
};
|
|
694
|
-
//#endregion
|
|
695
|
-
//#region ../infra/src/wasm/idCaptureDefaults.ts
|
|
696
|
-
/**
|
|
697
|
-
* Default WASM thresholds for ID capture quality checks.
|
|
698
|
-
* Matches SDK 1's `wasmWorkflowsConfig.ts` production ID profile. Explicit
|
|
699
|
-
* consumer and experiment overrides still take precedence in Core.
|
|
700
|
-
*/
|
|
701
|
-
const DEFAULT_ID_CAPTURE_THRESHOLDS = {
|
|
702
|
-
blurThreshold: .2,
|
|
703
|
-
blurChangeThreshold: .2,
|
|
704
|
-
glareThreshold: .3,
|
|
705
|
-
clsThreshold: .98,
|
|
706
|
-
sideThreshold: .8,
|
|
707
|
-
iouThreshold: .8,
|
|
708
|
-
idDetectedTimeout: 1e4,
|
|
709
|
-
autocaptureTimeout: 5e3,
|
|
710
|
-
framesAggregationInterval: 1700
|
|
711
|
-
};
|
|
712
|
-
/**
|
|
713
|
-
* Default geometry parameters for ID detection.
|
|
714
|
-
* Window dimensions must be provided at runtime.
|
|
715
|
-
*/
|
|
716
|
-
const DEFAULT_ID_CAPTURE_GEOMETRY = {
|
|
717
|
-
areaDown: 25e3,
|
|
718
|
-
areaUp: 55e3,
|
|
719
|
-
areaIOSPassportUp: 3e4,
|
|
720
|
-
areaIOSPassportDown: 2e4,
|
|
721
|
-
widthIOSUp: 160,
|
|
722
|
-
widthIOSDown: 85,
|
|
723
|
-
widthDown: 110,
|
|
724
|
-
widthUp: 205
|
|
725
|
-
};
|
|
726
|
-
//#endregion
|
|
727
|
-
export { CameraCompositor as i, DEFAULT_ID_CAPTURE_THRESHOLDS as n, IdCaptureProvider as r, DEFAULT_ID_CAPTURE_GEOMETRY as t };
|