@idmission/websdk-core 0.2.0-rc.2 → 0.5.0
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 +27 -1
- package/dist/attestation/clientAttestation.d.ts +5 -0
- package/dist/attestation/clientAttestation.d.ts.map +1 -1
- package/dist/attestation/clientAttestation.js +4 -4
- package/dist/attestation/collectClientAttestation.d.ts +3 -1
- package/dist/attestation/collectClientAttestation.d.ts.map +1 -1
- package/dist/attestation/collectClientAttestation.js +4 -3
- package/dist/camera/acquireCamera.d.ts +5 -0
- package/dist/camera/acquireCamera.d.ts.map +1 -1
- package/dist/camera/acquireCamera.js +25 -5
- package/dist/captureProgress/actor.d.ts +30 -0
- package/dist/captureProgress/actor.d.ts.map +1 -0
- package/dist/captureProgress/actor.js +754 -0
- package/dist/captureProgress/encoder.d.ts +7 -0
- package/dist/captureProgress/encoder.d.ts.map +1 -0
- package/dist/captureProgress/encoder.js +195 -0
- package/dist/captureProgress/index.d.ts +4 -0
- package/dist/captureProgress/index.d.ts.map +1 -0
- package/dist/captureProgress/index.js +45 -0
- package/dist/captureProgress/internal.d.ts +3 -0
- package/dist/captureProgress/internal.d.ts.map +1 -0
- package/dist/captureProgress/internal.js +1 -0
- package/dist/captureProgress/protocol.d.ts +224 -0
- package/dist/captureProgress/protocol.d.ts.map +1 -0
- package/dist/captureProgress/protocol.js +106 -0
- package/dist/captureProgress/recorder.d.ts +32 -0
- package/dist/captureProgress/recorder.d.ts.map +1 -0
- package/dist/captureProgress/recorder.js +554 -0
- package/dist/captureProgress/transport.d.ts +33 -0
- package/dist/captureProgress/transport.d.ts.map +1 -0
- package/dist/captureProgress/transport.js +109 -0
- package/dist/captureProgress/types.d.ts +35 -0
- package/dist/captureProgress/types.d.ts.map +1 -0
- package/dist/captureProgress/types.js +27 -0
- package/dist/client/IdmissionClient.d.ts +8 -1
- package/dist/client/IdmissionClient.d.ts.map +1 -1
- package/dist/client/IdmissionClient.js +96 -27
- package/dist/client/approval.d.ts +15 -0
- package/dist/client/approval.d.ts.map +1 -0
- package/dist/client/approval.js +19 -0
- package/dist/client/artifacts.d.ts +2 -0
- package/dist/client/artifacts.d.ts.map +1 -1
- package/dist/client/documentFileMetadata.d.ts +13 -0
- package/dist/client/documentFileMetadata.d.ts.map +1 -0
- package/dist/client/documentFileMetadata.js +51 -0
- package/dist/client/index.d.ts +3 -0
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +2 -0
- package/dist/client/payload.d.ts +3 -0
- package/dist/client/payload.d.ts.map +1 -1
- package/dist/client/payload.js +3 -1
- package/dist/client/submissionMetadata.d.ts +4 -1
- package/dist/client/submissionMetadata.d.ts.map +1 -1
- package/dist/client/submissionMetadata.js +13 -8
- package/dist/client/types.d.ts +8 -0
- package/dist/client/types.d.ts.map +1 -1
- package/dist/client/validateSession.d.ts +2 -0
- package/dist/client/validateSession.d.ts.map +1 -1
- package/dist/client/validateSession.js +53 -24
- package/dist/documentCapture/autoCaptureEngine.d.ts +106 -0
- package/dist/documentCapture/autoCaptureEngine.d.ts.map +1 -0
- package/dist/documentCapture/autoCaptureEngine.js +475 -0
- package/dist/documentCapture/autoCaptureGeometry.d.ts +514 -0
- package/dist/documentCapture/autoCaptureGeometry.d.ts.map +1 -0
- package/dist/documentCapture/autoCaptureGeometry.js +475 -0
- package/dist/documentCapture/autoCaptureGuidance.d.ts +61 -0
- package/dist/documentCapture/autoCaptureGuidance.d.ts.map +1 -0
- package/dist/documentCapture/autoCaptureGuidance.js +73 -0
- package/dist/documentCapture/autoCaptureMetadata.d.ts +193 -0
- package/dist/documentCapture/autoCaptureMetadata.d.ts.map +1 -0
- package/dist/documentCapture/autoCaptureMetadata.js +200 -0
- package/dist/documentCapture/autoCaptureOptions.d.ts +211 -0
- package/dist/documentCapture/autoCaptureOptions.d.ts.map +1 -0
- package/dist/documentCapture/autoCaptureOptions.js +177 -0
- package/dist/documentCapture/autoCaptureShutter.d.ts +162 -0
- package/dist/documentCapture/autoCaptureShutter.d.ts.map +1 -0
- package/dist/documentCapture/autoCaptureShutter.js +183 -0
- package/dist/documentCapture/controller.d.ts +38 -1
- package/dist/documentCapture/controller.d.ts.map +1 -1
- package/dist/documentCapture/controller.js +620 -40
- package/dist/documentCapture/index.d.ts +8 -2
- package/dist/documentCapture/index.d.ts.map +1 -1
- package/dist/documentCapture/index.js +6 -0
- package/dist/documentCapture/reducer.d.ts +26 -1
- package/dist/documentCapture/reducer.d.ts.map +1 -1
- package/dist/documentCapture/reducer.js +43 -0
- package/dist/documentCapture/state.d.ts +118 -0
- package/dist/documentCapture/state.d.ts.map +1 -1
- package/dist/documentCapture/state.js +24 -0
- package/dist/idCapture/controller.d.ts +24 -1
- package/dist/idCapture/controller.d.ts.map +1 -1
- package/dist/idCapture/controller.js +111 -13
- package/dist/idCapture/index.d.ts +1 -1
- package/dist/idCapture/index.d.ts.map +1 -1
- package/dist/idCapture/index.js +12 -1
- package/dist/idCapture/pipeline.d.ts +30 -0
- package/dist/idCapture/pipeline.d.ts.map +1 -1
- package/dist/idCapture/pipeline.js +33 -10
- package/dist/idCapture/state.d.ts +1 -3
- package/dist/idCapture/state.d.ts.map +1 -1
- package/dist/idCapture/submit.d.ts.map +1 -1
- package/dist/idCapture/submit.js +35 -1
- package/dist/idCapture/types.d.ts +2 -0
- package/dist/idCapture/types.d.ts.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/liveness/challengeGeometry.d.ts +48 -17
- package/dist/liveness/challengeGeometry.d.ts.map +1 -1
- package/dist/liveness/challengeGeometry.js +101 -54
- package/dist/models/DocumentDetection.d.ts +29 -1
- package/dist/models/DocumentDetection.d.ts.map +1 -1
- package/dist/models/DocumentDetection.js +75 -7
- package/dist/models/defaults/DocumentDetectorLiteRT.d.ts +2 -2
- package/dist/models/defaults/DocumentDetectorLiteRT.d.ts.map +1 -1
- package/dist/models/defaults/DocumentDetectorLiteRT.js +27 -2
- package/dist/models/defaults/HandLandmarkLiteRT.d.ts +3 -0
- package/dist/models/defaults/HandLandmarkLiteRT.d.ts.map +1 -0
- package/dist/models/defaults/HandLandmarkLiteRT.js +5 -0
- package/dist/models/defaults/IrisLandmarkLiteRT.d.ts +3 -0
- package/dist/models/defaults/IrisLandmarkLiteRT.d.ts.map +1 -0
- package/dist/models/defaults/IrisLandmarkLiteRT.js +5 -0
- package/dist/models/defaults/PalmDetectionLiteRT.d.ts +3 -0
- package/dist/models/defaults/PalmDetectionLiteRT.d.ts.map +1 -0
- package/dist/models/defaults/PalmDetectionLiteRT.js +5 -0
- package/dist/models/defaults/PoaDocumentDetectorLiteRT.d.ts +3 -0
- package/dist/models/defaults/PoaDocumentDetectorLiteRT.d.ts.map +1 -0
- package/dist/models/defaults/PoaDocumentDetectorLiteRT.js +19 -0
- package/dist/models/defaults/index.d.ts +13 -1
- package/dist/models/defaults/index.d.ts.map +1 -1
- package/dist/models/defaults/index.js +16 -0
- package/dist/models/preloadModels.d.ts +24 -16
- package/dist/models/preloadModels.d.ts.map +1 -1
- package/dist/models/preloadModels.js +33 -3
- package/dist/models/providers/litert/FaceLandmarker.d.ts +8 -1
- package/dist/models/providers/litert/FaceLandmarker.d.ts.map +1 -1
- package/dist/models/providers/litert/FaceLandmarker.js +95 -3
- package/dist/models/providers/litert/HandOverFaceDetector.d.ts +27 -0
- package/dist/models/providers/litert/HandOverFaceDetector.d.ts.map +1 -0
- package/dist/models/providers/litert/HandOverFaceDetector.js +162 -0
- package/dist/models/providers/litert/blazeFacePrePost.js +4 -2
- package/dist/models/providers/litert/docDetectPrePost.d.ts.map +1 -1
- package/dist/models/providers/litert/docDetectPrePost.js +20 -3
- package/dist/models/providers/litert/handLandmarkPrePost.d.ts +20 -0
- package/dist/models/providers/litert/handLandmarkPrePost.d.ts.map +1 -0
- package/dist/models/providers/litert/handLandmarkPrePost.js +72 -0
- package/dist/models/providers/litert/handOverFace.d.ts +44 -0
- package/dist/models/providers/litert/handOverFace.d.ts.map +1 -0
- package/dist/models/providers/litert/handOverFace.js +139 -0
- package/dist/models/providers/litert/irisPrePost.d.ts +38 -0
- package/dist/models/providers/litert/irisPrePost.d.ts.map +1 -0
- package/dist/models/providers/litert/irisPrePost.js +101 -0
- package/dist/models/providers/litert/palmPrePost.d.ts +55 -0
- package/dist/models/providers/litert/palmPrePost.d.ts.map +1 -0
- package/dist/models/providers/litert/palmPrePost.js +151 -0
- package/dist/sdkVersions.d.ts +18 -0
- package/dist/sdkVersions.d.ts.map +1 -0
- package/dist/sdkVersions.js +8 -0
- package/dist/selfieCapture/captureQuality.d.ts +43 -0
- package/dist/selfieCapture/captureQuality.d.ts.map +1 -0
- package/dist/selfieCapture/captureQuality.js +87 -0
- package/dist/selfieCapture/challengeRunner.d.ts +9 -2
- package/dist/selfieCapture/challengeRunner.d.ts.map +1 -1
- package/dist/selfieCapture/challengeRunner.js +2 -5
- package/dist/selfieCapture/controller.d.ts +62 -1
- package/dist/selfieCapture/controller.d.ts.map +1 -1
- package/dist/selfieCapture/controller.js +470 -105
- package/dist/selfieCapture/faceTracking.d.ts +69 -1
- package/dist/selfieCapture/faceTracking.d.ts.map +1 -1
- package/dist/selfieCapture/faceTracking.js +134 -6
- package/dist/selfieCapture/guidance.d.ts +64 -0
- package/dist/selfieCapture/guidance.d.ts.map +1 -1
- package/dist/selfieCapture/guidance.js +74 -0
- package/dist/selfieCapture/index.d.ts +4 -3
- package/dist/selfieCapture/index.d.ts.map +1 -1
- package/dist/selfieCapture/index.js +2 -2
- package/dist/selfieCapture/livenessMachine.d.ts +2 -0
- package/dist/selfieCapture/livenessMachine.d.ts.map +1 -1
- package/dist/selfieCapture/livenessMachine.js +8 -0
- package/dist/selfieCapture/pipeline.d.ts +8 -0
- package/dist/selfieCapture/pipeline.d.ts.map +1 -1
- package/dist/selfieCapture/pipeline.js +2 -2
- package/dist/selfieCapture/reducer.d.ts +7 -0
- package/dist/selfieCapture/reducer.d.ts.map +1 -1
- package/dist/selfieCapture/reducer.js +45 -4
- package/dist/selfieCapture/state.d.ts +6 -0
- package/dist/selfieCapture/state.d.ts.map +1 -1
- package/dist/selfieCapture/state.js +1 -0
- package/dist/signature/frameDecode.d.ts.map +1 -1
- package/dist/signature/frameDecode.js +29 -0
- package/dist/signature/metadata.d.ts +10 -1
- package/dist/signature/metadata.d.ts.map +1 -1
- package/dist/signature/quality.d.ts +14 -6
- package/dist/signature/quality.d.ts.map +1 -1
- package/dist/signature/quality.js +13 -4
- package/dist/signatureCapture/controller.d.ts +2 -1
- package/dist/signatureCapture/controller.d.ts.map +1 -1
- package/dist/signatureCapture/controller.js +118 -23
- package/dist/signatureCapture/pipeline.d.ts +14 -2
- package/dist/signatureCapture/pipeline.d.ts.map +1 -1
- package/dist/signatureCapture/pipeline.js +36 -8
- package/dist/signatureCapture/state.d.ts +15 -0
- package/dist/signatureCapture/state.d.ts.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +1 -1
- package/dist/videoIdCapture/controller.d.ts.map +1 -1
- package/dist/videoIdCapture/controller.js +64 -3
- package/package.json +10 -2
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
// The one place auto-capture defaults are applied (#340).
|
|
2
|
+
//
|
|
3
|
+
// This repo has had FOUR cascade-default incidents — `specific ?? general ??
|
|
4
|
+
// default` dying silently the moment the specific operand picks up a
|
|
5
|
+
// non-`undefined` default of its own — and every one of them passed review. The
|
|
6
|
+
// structure here is chosen so the hazard is absent rather than policed: the
|
|
7
|
+
// per-document `autoCapture` bag is the ONLY source of behavioural and
|
|
8
|
+
// threshold overrides, the engine knobs are a disjoint set on
|
|
9
|
+
// `DocumentCaptureControllerConfig`, and there is exactly one function that
|
|
10
|
+
// turns an all-optional bag into a total one.
|
|
11
|
+
//
|
|
12
|
+
// The rule that goes with it, which reviewers must hold:
|
|
13
|
+
//
|
|
14
|
+
// Defaults live in `resolveAutoCapture` and nowhere else. Banned everywhere
|
|
15
|
+
// else: React prop-destructure defaults, `= {}` parameter defaults, `??
|
|
16
|
+
// <value>` in the compat mapper, and any `autoCapture` value in a Storybook
|
|
17
|
+
// `meta.args`.
|
|
18
|
+
import { warn } from '../utils/logger';
|
|
19
|
+
import { POA_FILL_MAX, POA_FILL_MIN, POA_FOCUS_THRESHOLDS, POA_MIN_SCORE, POA_TARGET_LABELS, } from './autoCaptureGeometry';
|
|
20
|
+
/** Frames the IoU window holds before a stability verdict is possible. */
|
|
21
|
+
export const DEFAULT_STABILITY_FRAMES = 12;
|
|
22
|
+
/**
|
|
23
|
+
* Minimum pairwise IoU across the stability window.
|
|
24
|
+
*
|
|
25
|
+
* Seeded from `defaultDocumentDetectionThresholds.stability.singlePage` and
|
|
26
|
+
* left there by #380: stability resolves in ~690 ms of not moving, so it is
|
|
27
|
+
* rarely the binding gate.
|
|
28
|
+
*/
|
|
29
|
+
export const DEFAULT_STABILITY_IOU = 0.5;
|
|
30
|
+
/**
|
|
31
|
+
* ms of sustained gate failure before the manual shutter is offered (#345).
|
|
32
|
+
*
|
|
33
|
+
* RAISED FROM 8000 ON FIELD EVIDENCE. The 8 s value was inherited from
|
|
34
|
+
* `idCapture`'s `allowOverrideWrongDocumentTypeAfterMs`, tuned for the
|
|
35
|
+
* wrong-document-type case, with no POA number behind it — and its own note
|
|
36
|
+
* predicted this outcome:
|
|
37
|
+
*
|
|
38
|
+
* > The hard recording first-captures at 11.5 s, so on hard-but-recoverable
|
|
39
|
+
* > framings the dialog will be offered BEFORE the loop succeeds. That is
|
|
40
|
+
* > harmless by construction — the loop stays armed until the applicant
|
|
41
|
+
* > accepts — but the dialog will be common, and nobody has watched a real
|
|
42
|
+
* > applicant react to it.
|
|
43
|
+
*
|
|
44
|
+
* Someone has now watched, and it pops while the loop is still converging.
|
|
45
|
+
* "Harmless by construction" was true of the CAPTURE and false of the
|
|
46
|
+
* experience: being offered a way out mid-attempt reads as the SDK giving up.
|
|
47
|
+
*
|
|
48
|
+
* 30 s clears the 11.5 s hard-recording first-capture with room, so the offer
|
|
49
|
+
* arrives after the loop has plainly failed rather than during its slowest
|
|
50
|
+
* success. Still an operating point rather than a measurement — what would
|
|
51
|
+
* move it is a distribution of real time-to-capture, not another guess.
|
|
52
|
+
*/
|
|
53
|
+
export const DEFAULT_MANUAL_FALLBACK_AFTER_MS = 30_000;
|
|
54
|
+
/**
|
|
55
|
+
* Camera width worth requesting for auto-capture, as a RECOMMENDATION.
|
|
56
|
+
*
|
|
57
|
+
* An A4 page filling the portrait guide on the default 1920-wide 16:9 stream
|
|
58
|
+
* spans about 764x1080 pixels, so it lands near 90 DPI — 6pt print about two
|
|
59
|
+
* pixels tall. That is a sampling limit, not blur, and no focus threshold
|
|
60
|
+
* recovers it. The same page on 2560 is about 1018x1440.
|
|
61
|
+
*
|
|
62
|
+
* NOT APPLIED AUTOMATICALLY, and that is the finding rather than an oversight.
|
|
63
|
+
* It was, briefly, and it made captures materially harder to land: the loop
|
|
64
|
+
* draws every frame at the stream's size, so a bigger frame costs more per
|
|
65
|
+
* frame, and both the stability and fill windows are twelve FRAMES — a slower
|
|
66
|
+
* loop stretches the hold-still the applicant has to sustain. Some devices
|
|
67
|
+
* also answer a larger width with a lower-frame-rate capture mode, which
|
|
68
|
+
* compounds it.
|
|
69
|
+
*
|
|
70
|
+
* So this is a number to pass deliberately, per integration, after watching
|
|
71
|
+
* `frameRate` on the tuning overlay:
|
|
72
|
+
*
|
|
73
|
+
* <DocumentCapture camera={{ maxVideoWidth: AUTO_CAPTURE_VIDEO_WIDTH }} … />
|
|
74
|
+
*
|
|
75
|
+
* Re-landing it as a default needs a frame-rate measurement across the target
|
|
76
|
+
* device range, not another guess.
|
|
77
|
+
*/
|
|
78
|
+
export const AUTO_CAPTURE_VIDEO_WIDTH = 2560;
|
|
79
|
+
/**
|
|
80
|
+
* ms to keep looking for a sharper frame after the gates first go green.
|
|
81
|
+
*
|
|
82
|
+
* WHY THIS EXISTS. Two of the three gates are windowed and slow-moving — fill
|
|
83
|
+
* is a 12-frame mean and stability is a 12-frame IoU — so they ratchet into
|
|
84
|
+
* satisfaction and stay there. Focus is the only single-frame gate. Firing on
|
|
85
|
+
* the first satisfied frame therefore fires the instant FOCUS first crosses
|
|
86
|
+
* its threshold, and that threshold is deliberately permissive: #380 lowered
|
|
87
|
+
* it to 0.5 because 0.6 was rejecting 4.8% of live frames.
|
|
88
|
+
*
|
|
89
|
+
* A first-crossing rule on a noisy signal is biased toward the threshold by
|
|
90
|
+
* construction — it catches marginal upward excursions. So the shutter was
|
|
91
|
+
* systematically capturing near the floor on exactly the holds where focus was
|
|
92
|
+
* the binding gate, which is the motion blur this addresses.
|
|
93
|
+
*
|
|
94
|
+
* Expressed in MILLISECONDS and converted through the measured frame rate,
|
|
95
|
+
* like `manualFallbackAfterMs`, so the pause is the same length of time on a
|
|
96
|
+
* fast phone and a slow one. A fixed frame count would be 200 ms at 30 fps and
|
|
97
|
+
* 750 ms at 8 fps — the device that can least afford the wait would wait
|
|
98
|
+
* longest.
|
|
99
|
+
*
|
|
100
|
+
* 300 ms is #383's `mean of 6` translated into time: six frames at the ~20 fps
|
|
101
|
+
* this loop runs at. It is an operating point, not a measurement.
|
|
102
|
+
*/
|
|
103
|
+
export const DEFAULT_BURST_WINDOW_MS = 300;
|
|
104
|
+
/**
|
|
105
|
+
* The same idea pointed at the applicant's tap, and longer on purpose.
|
|
106
|
+
*
|
|
107
|
+
* Pressing a phone's screen moves the phone. The frame the tap lands on is
|
|
108
|
+
* therefore among the WORST frames available — the finger has already made
|
|
109
|
+
* contact and the transient has not damped — so saving it is sampling the
|
|
110
|
+
* blur rather than avoiding it. This is the one complaint about hand-held
|
|
111
|
+
* manual capture that no amount of guidance can fix, because the guidance is
|
|
112
|
+
* correct right up until the moment the applicant acts on it.
|
|
113
|
+
*
|
|
114
|
+
* The window opens AT the tap and never reaches backwards. Frames from before
|
|
115
|
+
* it are sharper still, and deliberately out of scope: the tap is the
|
|
116
|
+
* applicant's intent expressed at a moment of their choosing, and submitting
|
|
117
|
+
* pixels from before it would be a different photo than the one they took.
|
|
118
|
+
* What the window buys is the settle on the far side.
|
|
119
|
+
*
|
|
120
|
+
* Longer than `burstWindowMs` because it has different work to do. That one
|
|
121
|
+
* picks the best of frames the gates have already certified; this one has to
|
|
122
|
+
* OUTLIVE a physical transient, and a window that ends inside the jostle has
|
|
123
|
+
* only jostled frames to choose between. 400 ms covers the damping on a
|
|
124
|
+
* hand-held phone with room on either side. It is an operating point, not a
|
|
125
|
+
* measurement — if it reads as lag, this is the number to turn down.
|
|
126
|
+
*/
|
|
127
|
+
export const DEFAULT_MANUAL_BURST_WINDOW_MS = 400;
|
|
128
|
+
/**
|
|
129
|
+
* Pin the document detector to the runtime that can actually run the POA
|
|
130
|
+
* artifact.
|
|
131
|
+
*
|
|
132
|
+
* The artifact's input tensor is uint8, and the mediapipe provider cannot load
|
|
133
|
+
* a raw `.tflite` at all — so `'mediapipe'` is downgraded with a warning rather
|
|
134
|
+
* than left to fail at the first frame, where it reads as a broken camera.
|
|
135
|
+
*
|
|
136
|
+
* The WebGPU half of this hazard is already closed one layer down:
|
|
137
|
+
* `providers/litert/DocumentDetection.ts` forces the `'wasm'` accelerator
|
|
138
|
+
* unconditionally, because LiteRT.js's WebGPU backend cannot allocate uint8
|
|
139
|
+
* tensor buffers and throws at the first `model.run()`. No knob on this surface
|
|
140
|
+
* can reach WebGPU, which is also why the Adreno/Snapdragon WebGPU hazard is
|
|
141
|
+
* moot here — it returns only if a future export drops uint8.
|
|
142
|
+
*/
|
|
143
|
+
export function resolveDocumentDetectorRuntime(requested) {
|
|
144
|
+
if (requested && requested !== 'litert') {
|
|
145
|
+
warn(`[documentCapture] auto-capture ignores documentDetectorRuntime="${requested}" ` +
|
|
146
|
+
'and runs on "litert": the POA detector is a uint8-input .tflite that ' +
|
|
147
|
+
'the mediapipe provider cannot load.');
|
|
148
|
+
}
|
|
149
|
+
return 'litert';
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Turn an all-optional `autoCapture` bag into a total one.
|
|
153
|
+
*
|
|
154
|
+
* Both parameters are `| undefined` and the return type has no optional
|
|
155
|
+
* members, which is the whole point: there is exactly one `??` per value, in
|
|
156
|
+
* one file, against one constant.
|
|
157
|
+
*/
|
|
158
|
+
export function resolveAutoCapture(options, environment) {
|
|
159
|
+
const onMobile = environment?.onMobile === true;
|
|
160
|
+
const focusBranch = onMobile ? 'mobile' : 'desktop';
|
|
161
|
+
return {
|
|
162
|
+
targetLabels: options?.targetLabels ?? POA_TARGET_LABELS,
|
|
163
|
+
minScore: options?.minScore ?? POA_MIN_SCORE,
|
|
164
|
+
stabilityFrames: options?.stabilityFrames ?? DEFAULT_STABILITY_FRAMES,
|
|
165
|
+
manualFallbackAfterMs: options?.manualFallbackAfterMs ?? DEFAULT_MANUAL_FALLBACK_AFTER_MS,
|
|
166
|
+
burstWindowMs: options?.burstWindowMs ?? DEFAULT_BURST_WINDOW_MS,
|
|
167
|
+
manualBurstWindowMs: options?.manualBurstWindowMs ?? DEFAULT_MANUAL_BURST_WINDOW_MS,
|
|
168
|
+
thresholds: {
|
|
169
|
+
fillMin: options?.thresholds?.fillMin ?? POA_FILL_MIN,
|
|
170
|
+
fillMax: options?.thresholds?.fillMax ?? POA_FILL_MAX,
|
|
171
|
+
stability: options?.thresholds?.stability ?? DEFAULT_STABILITY_IOU,
|
|
172
|
+
focus: options?.thresholds?.focus ?? POA_FOCUS_THRESHOLDS[focusBranch],
|
|
173
|
+
},
|
|
174
|
+
focusBranch,
|
|
175
|
+
documentDetectorRuntime: resolveDocumentDetectorRuntime(environment?.documentDetectorRuntime),
|
|
176
|
+
};
|
|
177
|
+
}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/** Per-document shutter state. Nothing here is shared between documents. */
|
|
2
|
+
export type AutoCaptureShutterState = {
|
|
3
|
+
/**
|
|
4
|
+
* Frames that failed at least one gate since this document's budget started.
|
|
5
|
+
*
|
|
6
|
+
* EVERY unsatisfied frame spends the budget, including frames with no box at
|
|
7
|
+
* all. Counting only frames that had a target and failed a gate would
|
|
8
|
+
* protect the slow starter, but it leaves an applicant the detector cannot
|
|
9
|
+
* see (dark paper, bad light) in a permanent dead-end. A premature offer can
|
|
10
|
+
* be ignored; a dead-end cannot.
|
|
11
|
+
*/
|
|
12
|
+
unsatisfiedFrames: number;
|
|
13
|
+
/**
|
|
14
|
+
* The applicant may tap to capture.
|
|
15
|
+
*
|
|
16
|
+
* STICKY, including across `retry()`. Once the SDK has conceded that it
|
|
17
|
+
* cannot frame this document unaided, taking the button back because the
|
|
18
|
+
* applicant retried would answer a struggle with a demotion.
|
|
19
|
+
*
|
|
20
|
+
* THERE IS NO LONGER A DIALOG IN FRONT OF THIS. The escape used to be a two
|
|
21
|
+
* step — offer a sheet, hand the shutter over on accept — and the sheet was
|
|
22
|
+
* the problem: it covered the guidance pill, which is the one thing on screen
|
|
23
|
+
* that tells the applicant how to fix the framing it was asking them about.
|
|
24
|
+
* A prompt that hides the answer to its own question is worse than no prompt,
|
|
25
|
+
* so the budget running out now reveals the button directly, with a caption
|
|
26
|
+
* beside it saying why it appeared.
|
|
27
|
+
*
|
|
28
|
+
* Revealing the shutter does not drop the gate. This diverges from
|
|
29
|
+
* `idCapture`, whose dialog removes the blocking gate outright. For POA the
|
|
30
|
+
* blocking gate IS the product requirement: dropping the fill window means
|
|
31
|
+
* auto-capturing a crop with no human intent behind it, stamped
|
|
32
|
+
* `autoCapture: 'Y'`, which is indistinguishable from the failure this whole
|
|
33
|
+
* workstream exists to fix. A human choosing to submit that framing is a
|
|
34
|
+
* categorically different event, and the only one that yields an honest 'N'.
|
|
35
|
+
*
|
|
36
|
+
* Auto-capture also STAYS ARMED, which the accept-step version could not do:
|
|
37
|
+
* it had to disarm, because firing out from under someone who had explicitly
|
|
38
|
+
* chosen manual would stamp 'Y' on them and corrupt the metric. Nobody
|
|
39
|
+
* chooses anything now, so there is no choice to contradict — the button is
|
|
40
|
+
* an addition, and a frame the model can still certify beats a tap.
|
|
41
|
+
*/
|
|
42
|
+
manualShutterAvailable: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Frames left in the burst window, or null when no burst is open.
|
|
45
|
+
*
|
|
46
|
+
* Opened by the first satisfied frame and counted down on EVERY frame after
|
|
47
|
+
* it, satisfied or not — it is a length of time expressed in frames, not a
|
|
48
|
+
* streak. That is deliberate: the shutter must tolerate gaps of at least 3
|
|
49
|
+
* frames, and requiring continued satisfaction would reintroduce exactly the
|
|
50
|
+
* streak rule #383 measured at 5.2 seconds.
|
|
51
|
+
*/
|
|
52
|
+
burstFramesRemaining: number | null;
|
|
53
|
+
/**
|
|
54
|
+
* Frames left in a burst the APPLICANT opened by tapping, or null.
|
|
55
|
+
*
|
|
56
|
+
* Separate from `burstFramesRemaining` because it means something different.
|
|
57
|
+
* That window picks the sharpest of frames the gates have already certified;
|
|
58
|
+
* this one exists because pressing a phone's screen moves the phone, so the
|
|
59
|
+
* frame the tap landed on is among the worst available. It outlives a
|
|
60
|
+
* physical transient rather than sampling a certified one.
|
|
61
|
+
*
|
|
62
|
+
* While it is open the auto window is closed and auto-capture cannot fire —
|
|
63
|
+
* the tap has taken this shot, and two shutters racing for one slot would
|
|
64
|
+
* mean the applicant sometimes gets a photo they did not take.
|
|
65
|
+
*/
|
|
66
|
+
manualBurstFramesRemaining: number | null;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* How many frames a burst window is worth at this frame rate.
|
|
70
|
+
*
|
|
71
|
+
* Same conversion as `escapeBudgetFrames`, and for the same reason: the window
|
|
72
|
+
* is a length of TIME, so it has to be the same length of time on a phone
|
|
73
|
+
* running at 8 fps and one running at 30. Counting raw frames would make the
|
|
74
|
+
* slowest device wait longest.
|
|
75
|
+
*/
|
|
76
|
+
export declare function burstWindowFrames(burstWindowMs: number, frameRate: number): number;
|
|
77
|
+
/** The frame data the shutter decides on. */
|
|
78
|
+
export type AutoCaptureShutterFrame = {
|
|
79
|
+
/** `isAutoCaptureSatisfied` for this frame. */
|
|
80
|
+
satisfied: boolean;
|
|
81
|
+
/** ms since the loop started, from the frame's own diagnostics. */
|
|
82
|
+
timeRunning: number;
|
|
83
|
+
/** Measured detections/second over the recent window. */
|
|
84
|
+
frameRate: number;
|
|
85
|
+
};
|
|
86
|
+
export type AutoCaptureShutterDecision = {
|
|
87
|
+
state: AutoCaptureShutterState;
|
|
88
|
+
/** Fire the shutter on this frame. */
|
|
89
|
+
capture: boolean;
|
|
90
|
+
/** The applicant's own burst closed on this frame. Save it as `'Manual'`. */
|
|
91
|
+
captureManual: boolean;
|
|
92
|
+
/**
|
|
93
|
+
* The frame the manual shutter appears on — true exactly once per document,
|
|
94
|
+
* since the grant is sticky and nothing clears it.
|
|
95
|
+
*/
|
|
96
|
+
revealManualShutter: boolean;
|
|
97
|
+
};
|
|
98
|
+
export declare function createAutoCaptureShutterState(): AutoCaptureShutterState;
|
|
99
|
+
/**
|
|
100
|
+
* How many unsatisfied frames the escape budget is worth at this frame rate.
|
|
101
|
+
*
|
|
102
|
+
* The mechanism is better than `idCapture`'s prop docs suggest, and this is
|
|
103
|
+
* the half worth porting: it does NOT run a wall clock. It converts the ms into
|
|
104
|
+
* a frame count via the measured rate and counts frames that actually
|
|
105
|
+
* exhibited the blocking condition. A slow model load, a fumbled start, dropped
|
|
106
|
+
* frames — none spend the budget. Only evidence that the loop is stuck does,
|
|
107
|
+
* which removes the "when does the clock start" problem a wall clock creates.
|
|
108
|
+
*/
|
|
109
|
+
export declare function escapeBudgetFrames(manualFallbackAfterMs: number, frameRate: number): number;
|
|
110
|
+
/**
|
|
111
|
+
* Advance the shutter by one frame.
|
|
112
|
+
*
|
|
113
|
+
* The first satisfied frame OPENS A BURST WINDOW rather than firing. The
|
|
114
|
+
* window is a length of time (`burstWindowMs`, converted through the measured
|
|
115
|
+
* frame rate), and the shutter fires when it closes — by which point the
|
|
116
|
+
* caller has had a chance to bank the sharpest frame it saw.
|
|
117
|
+
*
|
|
118
|
+
* This reopens #383, whose own note nominated `mean of 6` if it ever did. The
|
|
119
|
+
* reason it reopened: two of the three gates are windowed and slow-moving, so
|
|
120
|
+
* they ratchet into satisfaction and stay there, leaving focus — the only
|
|
121
|
+
* single-frame gate — to decide the moment. Firing on first satisfaction
|
|
122
|
+
* therefore fired the instant focus first crossed a deliberately permissive
|
|
123
|
+
* threshold, and a first-crossing rule on a noisy signal sits near the
|
|
124
|
+
* threshold by construction. That is motion blur the hold could have avoided.
|
|
125
|
+
*
|
|
126
|
+
* THE 3-FRAME-GAP GUARANTEE IS INTACT, and it is why the window counts down on
|
|
127
|
+
* every frame rather than only on satisfied ones. A window that reset on an
|
|
128
|
+
* unsatisfied frame would be the consecutive-frame streak #383 measured at 5.2
|
|
129
|
+
* seconds; this one cannot be reset by a focus excursion, only outlived.
|
|
130
|
+
*
|
|
131
|
+
* `idCapture`'s 3-second integrator is still rejected: this does not stack a
|
|
132
|
+
* second aggregation on the gates, it delays the trigger by a fixed short
|
|
133
|
+
* interval after they agree.
|
|
134
|
+
*/
|
|
135
|
+
export declare function advanceAutoCaptureShutter(state: AutoCaptureShutterState, frame: AutoCaptureShutterFrame, manualFallbackAfterMs: number, burstWindowMs?: number): AutoCaptureShutterDecision;
|
|
136
|
+
/**
|
|
137
|
+
* The applicant tapped: hold the shutter open for `manualBurstWindowMs`.
|
|
138
|
+
*
|
|
139
|
+
* Returns the state unchanged when there is no window to open — a zero
|
|
140
|
+
* setting, or no measured frame rate to convert one with — and the caller is
|
|
141
|
+
* expected to read `manualBurstFramesRemaining` to tell the two apart. Saving
|
|
142
|
+
* the frame the tap landed on is the correct fallback there: it is what this
|
|
143
|
+
* flow did before the window existed, and a window that never closes is a
|
|
144
|
+
* shutter that never fires.
|
|
145
|
+
*
|
|
146
|
+
* Closes any open AUTO window. Auto-capture firing inside the pause the
|
|
147
|
+
* applicant's own tap opened would hand them a photo they did not take, and
|
|
148
|
+
* stamp `autoCapture: 'Y'` on it.
|
|
149
|
+
*/
|
|
150
|
+
export declare function openManualBurst(state: AutoCaptureShutterState, frameRate: number, manualBurstWindowMs: number): AutoCaptureShutterState;
|
|
151
|
+
/**
|
|
152
|
+
* `retry()` restarts the budget for the SAME document.
|
|
153
|
+
*
|
|
154
|
+
* What survives is the BUTTON — see `manualShutterAvailable`. Everything that
|
|
155
|
+
* measures resets, because a retry is a fresh framing attempt and the old
|
|
156
|
+
* attempt's evidence says nothing about it.
|
|
157
|
+
*
|
|
158
|
+
* A FRESH document gets a fresh state, button included: a second document is a
|
|
159
|
+
* fresh framing problem, and the model may well handle it unaided.
|
|
160
|
+
*/
|
|
161
|
+
export declare function retryAutoCaptureShutter(state: AutoCaptureShutterState): AutoCaptureShutterState;
|
|
162
|
+
//# sourceMappingURL=autoCaptureShutter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"autoCaptureShutter.d.ts","sourceRoot":"","sources":["../../src/documentCapture/autoCaptureShutter.ts"],"names":[],"mappings":"AAaA,4EAA4E;AAC5E,MAAM,MAAM,uBAAuB,GAAG;IACpC;;;;;;;;OAQG;IACH,iBAAiB,EAAE,MAAM,CAAA;IACzB;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BG;IACH,sBAAsB,EAAE,OAAO,CAAA;IAC/B;;;;;;;;OAQG;IACH,oBAAoB,EAAE,MAAM,GAAG,IAAI,CAAA;IACnC;;;;;;;;;;;;OAYG;IACH,0BAA0B,EAAE,MAAM,GAAG,IAAI,CAAA;CAC1C,CAAA;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAC/B,aAAa,EAAE,MAAM,EACrB,SAAS,EAAE,MAAM,GAChB,MAAM,CAGR;AAED,6CAA6C;AAC7C,MAAM,MAAM,uBAAuB,GAAG;IACpC,+CAA+C;IAC/C,SAAS,EAAE,OAAO,CAAA;IAClB,mEAAmE;IACnE,WAAW,EAAE,MAAM,CAAA;IACnB,yDAAyD;IACzD,SAAS,EAAE,MAAM,CAAA;CAClB,CAAA;AAED,MAAM,MAAM,0BAA0B,GAAG;IACvC,KAAK,EAAE,uBAAuB,CAAA;IAC9B,sCAAsC;IACtC,OAAO,EAAE,OAAO,CAAA;IAChB,6EAA6E;IAC7E,aAAa,EAAE,OAAO,CAAA;IACtB;;;OAGG;IACH,mBAAmB,EAAE,OAAO,CAAA;CAC7B,CAAA;AAYD,wBAAgB,6BAA6B,IAAI,uBAAuB,CAOvE;AAED;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAChC,qBAAqB,EAAE,MAAM,EAC7B,SAAS,EAAE,MAAM,GAChB,MAAM,CAGR;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,uBAAuB,EAC9B,KAAK,EAAE,uBAAuB,EAC9B,qBAAqB,EAAE,MAAM,EAC7B,aAAa,SAAI,GAChB,0BAA0B,CA0D5B;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,uBAAuB,EAC9B,SAAS,EAAE,MAAM,EACjB,mBAAmB,EAAE,MAAM,GAC1B,uBAAuB,CAQzB;AAED;;;;;;;;;GASG;AACH,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,uBAAuB,GAC7B,uBAAuB,CAUzB"}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
// The shutter and its escape hatch (#345), as a pure per-frame reducer.
|
|
2
|
+
//
|
|
3
|
+
// Auto-capture is ASSISTANCE, not enforcement. The original framing assumed
|
|
4
|
+
// enforcement — gate the shutter, re-enable it after a timeout — and that
|
|
5
|
+
// framing does not survive its own escape hatch: if the fallback has to exist,
|
|
6
|
+
// and the box-spill false positive makes it a correctness requirement, then
|
|
7
|
+
// enforcement was never a property of the system, only a delay. The job is to
|
|
8
|
+
// get a better frame than a tap would, and to concede when it cannot.
|
|
9
|
+
//
|
|
10
|
+
// Everything here is driven by data carried ON the frame — `satisfied`,
|
|
11
|
+
// `timeRunning`, `frameRate` — and never by a clock read, which is what makes
|
|
12
|
+
// the escape testable without fake timers.
|
|
13
|
+
/**
|
|
14
|
+
* How many frames a burst window is worth at this frame rate.
|
|
15
|
+
*
|
|
16
|
+
* Same conversion as `escapeBudgetFrames`, and for the same reason: the window
|
|
17
|
+
* is a length of TIME, so it has to be the same length of time on a phone
|
|
18
|
+
* running at 8 fps and one running at 30. Counting raw frames would make the
|
|
19
|
+
* slowest device wait longest.
|
|
20
|
+
*/
|
|
21
|
+
export function burstWindowFrames(burstWindowMs, frameRate) {
|
|
22
|
+
if (burstWindowMs <= 0 || frameRate <= 0)
|
|
23
|
+
return 0;
|
|
24
|
+
return Math.ceil((burstWindowMs / 1000) * frameRate);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* The loop must have been running this long before the shutter can appear.
|
|
28
|
+
*
|
|
29
|
+
* Ported from `idCapture`'s `hasBeenRunningForLongEnough`. It exists because
|
|
30
|
+
* `frameRate` is meaningless over the first handful of frames, and a threshold
|
|
31
|
+
* computed from a garbage rate would either reveal the shutter instantly or
|
|
32
|
+
* never.
|
|
33
|
+
*/
|
|
34
|
+
const MIN_RUNNING_MS_BEFORE_ESCAPE = 1000;
|
|
35
|
+
export function createAutoCaptureShutterState() {
|
|
36
|
+
return {
|
|
37
|
+
unsatisfiedFrames: 0,
|
|
38
|
+
manualShutterAvailable: false,
|
|
39
|
+
burstFramesRemaining: null,
|
|
40
|
+
manualBurstFramesRemaining: null,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* How many unsatisfied frames the escape budget is worth at this frame rate.
|
|
45
|
+
*
|
|
46
|
+
* The mechanism is better than `idCapture`'s prop docs suggest, and this is
|
|
47
|
+
* the half worth porting: it does NOT run a wall clock. It converts the ms into
|
|
48
|
+
* a frame count via the measured rate and counts frames that actually
|
|
49
|
+
* exhibited the blocking condition. A slow model load, a fumbled start, dropped
|
|
50
|
+
* frames — none spend the budget. Only evidence that the loop is stuck does,
|
|
51
|
+
* which removes the "when does the clock start" problem a wall clock creates.
|
|
52
|
+
*/
|
|
53
|
+
export function escapeBudgetFrames(manualFallbackAfterMs, frameRate) {
|
|
54
|
+
if (manualFallbackAfterMs <= 0 || frameRate <= 0)
|
|
55
|
+
return 0;
|
|
56
|
+
return Math.ceil((manualFallbackAfterMs / 1000) * frameRate);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Advance the shutter by one frame.
|
|
60
|
+
*
|
|
61
|
+
* The first satisfied frame OPENS A BURST WINDOW rather than firing. The
|
|
62
|
+
* window is a length of time (`burstWindowMs`, converted through the measured
|
|
63
|
+
* frame rate), and the shutter fires when it closes — by which point the
|
|
64
|
+
* caller has had a chance to bank the sharpest frame it saw.
|
|
65
|
+
*
|
|
66
|
+
* This reopens #383, whose own note nominated `mean of 6` if it ever did. The
|
|
67
|
+
* reason it reopened: two of the three gates are windowed and slow-moving, so
|
|
68
|
+
* they ratchet into satisfaction and stay there, leaving focus — the only
|
|
69
|
+
* single-frame gate — to decide the moment. Firing on first satisfaction
|
|
70
|
+
* therefore fired the instant focus first crossed a deliberately permissive
|
|
71
|
+
* threshold, and a first-crossing rule on a noisy signal sits near the
|
|
72
|
+
* threshold by construction. That is motion blur the hold could have avoided.
|
|
73
|
+
*
|
|
74
|
+
* THE 3-FRAME-GAP GUARANTEE IS INTACT, and it is why the window counts down on
|
|
75
|
+
* every frame rather than only on satisfied ones. A window that reset on an
|
|
76
|
+
* unsatisfied frame would be the consecutive-frame streak #383 measured at 5.2
|
|
77
|
+
* seconds; this one cannot be reset by a focus excursion, only outlived.
|
|
78
|
+
*
|
|
79
|
+
* `idCapture`'s 3-second integrator is still rejected: this does not stack a
|
|
80
|
+
* second aggregation on the gates, it delays the trigger by a fixed short
|
|
81
|
+
* interval after they agree.
|
|
82
|
+
*/
|
|
83
|
+
export function advanceAutoCaptureShutter(state, frame, manualFallbackAfterMs, burstWindowMs = 0) {
|
|
84
|
+
const unsatisfiedFrames = frame.satisfied
|
|
85
|
+
? state.unsatisfiedFrames
|
|
86
|
+
: state.unsatisfiedFrames + 1;
|
|
87
|
+
const budget = escapeBudgetFrames(manualFallbackAfterMs, frame.frameRate);
|
|
88
|
+
const revealManualShutter = !state.manualShutterAvailable &&
|
|
89
|
+
budget > 0 &&
|
|
90
|
+
frame.timeRunning > MIN_RUNNING_MS_BEFORE_ESCAPE &&
|
|
91
|
+
unsatisfiedFrames >= budget;
|
|
92
|
+
let burstFramesRemaining = state.burstFramesRemaining;
|
|
93
|
+
let manualBurstFramesRemaining = state.manualBurstFramesRemaining;
|
|
94
|
+
let capture = false;
|
|
95
|
+
let captureManual = false;
|
|
96
|
+
if (manualBurstFramesRemaining !== null) {
|
|
97
|
+
// The tap owns this shot. `openManualBurst` already closed the auto
|
|
98
|
+
// window; this keeps it closed for the rest of the tap's window, so a
|
|
99
|
+
// frame going satisfied mid-settle cannot open a second one behind it.
|
|
100
|
+
burstFramesRemaining = null;
|
|
101
|
+
manualBurstFramesRemaining -= 1;
|
|
102
|
+
if (manualBurstFramesRemaining <= 0) {
|
|
103
|
+
captureManual = true;
|
|
104
|
+
manualBurstFramesRemaining = null;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
else if (burstFramesRemaining !== null) {
|
|
108
|
+
// Counting down. NOT gated on `frame.satisfied` — see the header.
|
|
109
|
+
burstFramesRemaining -= 1;
|
|
110
|
+
if (burstFramesRemaining <= 0) {
|
|
111
|
+
capture = true;
|
|
112
|
+
burstFramesRemaining = null;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
else if (frame.satisfied) {
|
|
116
|
+
const window = burstWindowFrames(burstWindowMs, frame.frameRate);
|
|
117
|
+
if (window <= 0) {
|
|
118
|
+
// No window asked for, or no measured frame rate to convert it with:
|
|
119
|
+
// fall back to firing on this frame, which is the pre-burst behaviour.
|
|
120
|
+
capture = true;
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
burstFramesRemaining = window;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return {
|
|
127
|
+
state: {
|
|
128
|
+
...state,
|
|
129
|
+
unsatisfiedFrames,
|
|
130
|
+
manualShutterAvailable: state.manualShutterAvailable || revealManualShutter,
|
|
131
|
+
burstFramesRemaining,
|
|
132
|
+
manualBurstFramesRemaining,
|
|
133
|
+
},
|
|
134
|
+
capture,
|
|
135
|
+
captureManual,
|
|
136
|
+
revealManualShutter,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* The applicant tapped: hold the shutter open for `manualBurstWindowMs`.
|
|
141
|
+
*
|
|
142
|
+
* Returns the state unchanged when there is no window to open — a zero
|
|
143
|
+
* setting, or no measured frame rate to convert one with — and the caller is
|
|
144
|
+
* expected to read `manualBurstFramesRemaining` to tell the two apart. Saving
|
|
145
|
+
* the frame the tap landed on is the correct fallback there: it is what this
|
|
146
|
+
* flow did before the window existed, and a window that never closes is a
|
|
147
|
+
* shutter that never fires.
|
|
148
|
+
*
|
|
149
|
+
* Closes any open AUTO window. Auto-capture firing inside the pause the
|
|
150
|
+
* applicant's own tap opened would hand them a photo they did not take, and
|
|
151
|
+
* stamp `autoCapture: 'Y'` on it.
|
|
152
|
+
*/
|
|
153
|
+
export function openManualBurst(state, frameRate, manualBurstWindowMs) {
|
|
154
|
+
const window = burstWindowFrames(manualBurstWindowMs, frameRate);
|
|
155
|
+
if (window <= 0)
|
|
156
|
+
return state;
|
|
157
|
+
return {
|
|
158
|
+
...state,
|
|
159
|
+
manualBurstFramesRemaining: window,
|
|
160
|
+
burstFramesRemaining: null,
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* `retry()` restarts the budget for the SAME document.
|
|
165
|
+
*
|
|
166
|
+
* What survives is the BUTTON — see `manualShutterAvailable`. Everything that
|
|
167
|
+
* measures resets, because a retry is a fresh framing attempt and the old
|
|
168
|
+
* attempt's evidence says nothing about it.
|
|
169
|
+
*
|
|
170
|
+
* A FRESH document gets a fresh state, button included: a second document is a
|
|
171
|
+
* fresh framing problem, and the model may well handle it unaided.
|
|
172
|
+
*/
|
|
173
|
+
export function retryAutoCaptureShutter(state) {
|
|
174
|
+
return {
|
|
175
|
+
...state,
|
|
176
|
+
unsatisfiedFrames: 0,
|
|
177
|
+
// A window left open across a retry would fire on the new attempt's first
|
|
178
|
+
// frames, before the gates have had anything to say about them. The same
|
|
179
|
+
// goes for a tap the applicant has already seen the result of.
|
|
180
|
+
burstFramesRemaining: null,
|
|
181
|
+
manualBurstFramesRemaining: null,
|
|
182
|
+
};
|
|
183
|
+
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { acquireCamera, type AcquireCameraOptions } from '../camera/acquireCamera';
|
|
2
2
|
import type { SubmissionArtifacts } from '../client/artifacts';
|
|
3
3
|
import type { IdmissionClient } from '../client/IdmissionClient';
|
|
4
|
+
import { createAutoCaptureEngine, type AutoCaptureEngineConfig } from './autoCaptureEngine';
|
|
5
|
+
import type { AutoCaptureDiagnostics } from './autoCaptureGeometry';
|
|
4
6
|
import { type CapturedDocument, type DocumentCaptureCompleteHandler, type DocumentCaptureControllerState, type DocumentCaptureInput } from './state';
|
|
5
7
|
export type DocumentCaptureControllerConfig = {
|
|
6
8
|
client: IdmissionClient;
|
|
@@ -11,14 +13,31 @@ export type DocumentCaptureControllerConfig = {
|
|
|
11
13
|
camera?: AcquireCameraOptions;
|
|
12
14
|
/** Skip acquiring the camera during attach(); call actions.requestCamera() later. */
|
|
13
15
|
deferCameraAcquisition?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Engine knobs for the auto-capture detection loop, mirroring
|
|
18
|
+
* `IdCaptureControllerConfig`'s names (#340). Whether the loop runs at all is
|
|
19
|
+
* decided per-document by `DocumentCaptureInput.autoCapture`; these only say
|
|
20
|
+
* how. Deliberately NOT on the 2.x façade day one.
|
|
21
|
+
*/
|
|
22
|
+
autoCaptureEngine?: Omit<AutoCaptureEngineConfig, 'autoCapture' | 'onDiagnostics' | 'onModelsChanged'>;
|
|
14
23
|
onDocumentCaptured?: (document: CapturedDocument, index: number) => void;
|
|
15
24
|
onDocumentUploaded?: (document: CapturedDocument, index: number) => void;
|
|
16
25
|
onAllDocumentsUploaded?: DocumentCaptureCompleteHandler;
|
|
26
|
+
/** Test seams; production defaults. */
|
|
17
27
|
io?: {
|
|
18
28
|
now?: () => Date;
|
|
19
29
|
acquireCamera?: typeof acquireCamera;
|
|
20
30
|
createObjectUrl?: (blob: Blob) => string;
|
|
21
|
-
|
|
31
|
+
/**
|
|
32
|
+
* Grabs and encodes the frame. `aspectRatio` is the opted-in document's
|
|
33
|
+
* guide aspect, passed so a custom grab can see the guide box; the default
|
|
34
|
+
* saves the whole frame and does not use it.
|
|
35
|
+
*/
|
|
36
|
+
captureFrame?: (source: CaptureFrameSource, aspectRatio?: number) => Promise<Blob | null>;
|
|
37
|
+
/** Mirrors idCapture's `io.createPipeline`: the whole ML half, injectable. */
|
|
38
|
+
createAutoCaptureEngine?: typeof createAutoCaptureEngine;
|
|
39
|
+
/** Backs the banked best-frame canvas; production default. */
|
|
40
|
+
createCanvas?: () => HTMLCanvasElement;
|
|
22
41
|
};
|
|
23
42
|
};
|
|
24
43
|
export type DocumentCaptureController = {
|
|
@@ -26,6 +45,12 @@ export type DocumentCaptureController = {
|
|
|
26
45
|
detach(): void;
|
|
27
46
|
getState(): DocumentCaptureControllerState;
|
|
28
47
|
subscribe(cb: (state: DocumentCaptureControllerState) => void): () => void;
|
|
48
|
+
/**
|
|
49
|
+
* The auto-capture diagnostics ring buffer, oldest frame first. Empty unless
|
|
50
|
+
* `autoCaptureEngine.debugMode` was set at construction. This — not the
|
|
51
|
+
* on-glass text — is the deliverable of a tuning session (#341).
|
|
52
|
+
*/
|
|
53
|
+
getAutoCaptureLog(): AutoCaptureDiagnostics[];
|
|
29
54
|
collectArtifacts(): SubmissionArtifacts;
|
|
30
55
|
actions: {
|
|
31
56
|
requestCamera(): Promise<void>;
|
|
@@ -34,5 +59,17 @@ export type DocumentCaptureController = {
|
|
|
34
59
|
upload(): Promise<void>;
|
|
35
60
|
};
|
|
36
61
|
};
|
|
62
|
+
/**
|
|
63
|
+
* The pixels a capture is cropped from, with the dimensions they measure.
|
|
64
|
+
*
|
|
65
|
+
* Not always the video element: an auto-capture saves the frame the detector
|
|
66
|
+
* and focus model actually GRADED, which by then is one inference round-trip
|
|
67
|
+
* behind the live feed. See `captureSource`.
|
|
68
|
+
*/
|
|
69
|
+
export type CaptureFrameSource = {
|
|
70
|
+
image: CanvasImageSource;
|
|
71
|
+
width: number;
|
|
72
|
+
height: number;
|
|
73
|
+
};
|
|
37
74
|
export declare function createDocumentCaptureController(config: DocumentCaptureControllerConfig): DocumentCaptureController;
|
|
38
75
|
//# sourceMappingURL=controller.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../src/documentCapture/controller.ts"],"names":[],"mappings":"AAiBA,OAAO,EACL,aAAa,EACb,KAAK,oBAAoB,EAE1B,MAAM,yBAAyB,CAAA;AAChC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAA;AAC9D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAA;
|
|
1
|
+
{"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../src/documentCapture/controller.ts"],"names":[],"mappings":"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"}
|