@daboss2003/liveness-web 1.0.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.
@@ -0,0 +1,98 @@
1
+ export type LivenessCallbacks = {
2
+ onChallengeChanged?: (stepIndex: number, stepLabel: string) => void;
3
+ onFailure?: (reason: string) => void;
4
+ onSuccess?: (imageBase64: string) => void;
5
+ onFaceInOval?: (inside: boolean, reason?: string) => void;
6
+ onDebugFrame?: (info: {
7
+ hasFace: boolean;
8
+ metrics: Metrics | null;
9
+ step: string;
10
+ }) => void;
11
+ };
12
+ export type LivenessSoundOptions = {
13
+ baseUrl?: string;
14
+ left?: string;
15
+ blink?: string;
16
+ right?: string;
17
+ nod?: string;
18
+ mouth?: string;
19
+ good?: string;
20
+ capture?: string;
21
+ };
22
+ export type LivenessOptions = {
23
+ videoElement: HTMLVideoElement;
24
+ canvasElement: HTMLCanvasElement;
25
+ modelUrl?: string;
26
+ wasmUrl?: string;
27
+ callbacks?: LivenessCallbacks;
28
+ sounds?: LivenessSoundOptions;
29
+ };
30
+ export declare const DEFAULT_MODEL_URL = "https://storage.googleapis.com/mediapipe-models/face_landmarker/face_landmarker/float16/1/face_landmarker.task";
31
+ export declare const DEFAULT_WASM_URL = "https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@latest/wasm";
32
+ /** Error code when CDN/assets are unavailable after retries (internet confirmed). */
33
+ export declare const LIVENESS_ERROR_CDN_NOT_AVAILABLE: "cdnNotAvailable";
34
+ /** Error code when the user has no internet connection. */
35
+ export declare const LIVENESS_ERROR_OFFLINE: "offline";
36
+ export declare function isCdnNotAvailableError(reason: string): boolean;
37
+ export declare function isOfflineError(reason: string): boolean;
38
+ export declare class LivenessError extends Error {
39
+ readonly code: typeof LIVENESS_ERROR_CDN_NOT_AVAILABLE | typeof LIVENESS_ERROR_OFFLINE;
40
+ constructor(code: typeof LIVENESS_ERROR_CDN_NOT_AVAILABLE | typeof LIVENESS_ERROR_OFFLINE, message: string);
41
+ }
42
+ export type Metrics = {
43
+ yaw: number;
44
+ pitch: number;
45
+ ear: number;
46
+ mar: number;
47
+ blinkScore: number;
48
+ mouthScore: number;
49
+ faceCx: number;
50
+ faceCy: number;
51
+ faceSize: number;
52
+ };
53
+ export declare const LIVENESS_STEP_COUNT: number;
54
+ export declare class LivenessEngine {
55
+ private opts;
56
+ private landmarker;
57
+ private running;
58
+ private rafId;
59
+ private stream;
60
+ private stepIndex;
61
+ private stepStart;
62
+ private baselineYaw;
63
+ private baselinePitch;
64
+ private baselineSamples;
65
+ private blinkState;
66
+ private blinkCloseTs;
67
+ private nodState;
68
+ private holdStart;
69
+ private latestMetrics;
70
+ private nodPeakDPitch;
71
+ private lastDetectTs;
72
+ private lastOvalState;
73
+ private stepSoundPlayedForCurrentStep;
74
+ private currentStepAudio;
75
+ private currentStepAudioCleanup;
76
+ private sessionTimeoutId;
77
+ constructor(opts: LivenessOptions);
78
+ private playSound;
79
+ private getSoundUrl;
80
+ private playStepSound;
81
+ private stopStepSound;
82
+ private clearSessionTimeout;
83
+ private playGoodSound;
84
+ private playCaptureSound;
85
+ start(): Promise<void>;
86
+ stop(): void;
87
+ private stopDetectionOnly;
88
+ private ensureVideo;
89
+ private createLandmarker;
90
+ private loop;
91
+ private checkFaceInOval;
92
+ private resetStepState;
93
+ private updateState;
94
+ private advanceStep;
95
+ private fail;
96
+ private scheduleCapture;
97
+ private captureImage;
98
+ }