face-validator-sdk 1.2.0 → 1.3.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/CHANGELOG.md +13 -0
- package/core.d.ts +2 -0
- package/core.js +1 -0
- package/dist/face-validator-sdk-core.cjs.js +2 -0
- package/dist/face-validator-sdk-core.cjs.js.map +1 -0
- package/dist/face-validator-sdk-core.esm.js +2 -0
- package/dist/face-validator-sdk-core.esm.js.map +1 -0
- package/dist/face-validator-sdk-core.umd.js +2 -0
- package/dist/face-validator-sdk-core.umd.js.map +1 -0
- package/dist/face-validator-sdk.cjs.js +1 -1
- package/dist/face-validator-sdk.cjs.js.map +1 -1
- package/dist/face-validator-sdk.esm.js +1 -1
- package/dist/face-validator-sdk.esm.js.map +1 -1
- package/dist/face-validator-sdk.umd.js +1 -1
- package/dist/face-validator-sdk.umd.js.map +1 -1
- package/dist/types/ReactSelfieCapture.d.ts +1 -1
- package/dist/types/core/FaceValidator.d.ts +30 -0
- package/dist/types/core/core.d.ts +7 -0
- package/dist/types/core/i18n.d.ts +14 -0
- package/dist/types/core/types.d.ts +91 -0
- package/dist/types/core/utils.d.ts +57 -0
- package/dist/types/core.d.ts +7 -0
- package/package.json +24 -2
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { NormalizedLandmark } from '@mediapipe/tasks-vision';
|
|
2
|
+
export declare enum ValidationStatus {
|
|
3
|
+
INITIALIZING = "INITIALIZING",
|
|
4
|
+
NO_FACE_DETECTED = "NO_FACE_DETECTED",
|
|
5
|
+
FACE_DETECTED = "FACE_DETECTED",
|
|
6
|
+
TOO_CLOSE = "TOO_CLOSE",
|
|
7
|
+
TOO_FAR = "TOO_FAR",
|
|
8
|
+
OFF_CENTER = "OFF_CENTER",
|
|
9
|
+
FACE_OBSTRUCTED = "FACE_OBSTRUCTED",
|
|
10
|
+
HEAD_NOT_STRAIGHT = "HEAD_NOT_STRAIGHT",
|
|
11
|
+
MULTIPLE_FACES = "MULTIPLE_FACES",
|
|
12
|
+
POOR_ILLUMINATION = "POOR_ILLUMINATION",
|
|
13
|
+
NOT_NEUTRAL_EXPRESSION = "NOT_NEUTRAL_EXPRESSION",
|
|
14
|
+
DARK_GLASSES = "DARK_GLASSES",
|
|
15
|
+
STAY_STILL = "STAY_STILL",
|
|
16
|
+
CAPTURING = "CAPTURING",
|
|
17
|
+
SUCCESS = "SUCCESS",
|
|
18
|
+
ERROR = "ERROR"
|
|
19
|
+
}
|
|
20
|
+
export type SupportedLocale = 'pt-BR' | 'en' | 'es';
|
|
21
|
+
export interface FaceValidatorOptions {
|
|
22
|
+
/** Optional path to MediaPipe models WASM files. Default: auto-detected from CDN */
|
|
23
|
+
modelPath?: string;
|
|
24
|
+
/** Video element for the camera stream. */
|
|
25
|
+
videoElement: HTMLVideoElement;
|
|
26
|
+
/** Optional canvas for visual feedback (e.g. face outline). */
|
|
27
|
+
overlayCanvasElement?: HTMLCanvasElement | null;
|
|
28
|
+
/** Optional video width. Default: 640 */
|
|
29
|
+
videoWidth?: number;
|
|
30
|
+
/** Optional video height. Default: 480 */
|
|
31
|
+
videoHeight?: number;
|
|
32
|
+
/** UI language. Default: 'en' */
|
|
33
|
+
locale?: SupportedLocale;
|
|
34
|
+
/** Optional override for specific status messages. */
|
|
35
|
+
customMessages?: Partial<Record<ValidationStatus, string>>;
|
|
36
|
+
/** Callback on each validation status update. */
|
|
37
|
+
onStatusUpdate: (status: ValidationStatus, message: string) => void;
|
|
38
|
+
/** Callback when selfie is successfully captured (receives Blob). */
|
|
39
|
+
onCaptureSuccess: (imageBlob: Blob) => void;
|
|
40
|
+
/** Callback on error. */
|
|
41
|
+
onError: (errorType: ValidationStatus, error: Error) => void;
|
|
42
|
+
/** Optional min detection confidence (0–1). Default: 0.5 */
|
|
43
|
+
minDetectionConfidence?: number;
|
|
44
|
+
/** Optional min brightness (0–255). Default: 70 */
|
|
45
|
+
minIlluminationThreshold?: number;
|
|
46
|
+
/** Optional min face size factor. Default: 0.25 */
|
|
47
|
+
minFaceSizeFactor?: number;
|
|
48
|
+
/** Optional max face size factor. Default: 0.65 */
|
|
49
|
+
maxFaceSizeFactor?: number;
|
|
50
|
+
/** Optional stable time before capture (ms). Default: 1000 */
|
|
51
|
+
stabilizationTimeThreshold?: number;
|
|
52
|
+
/** Optional movement tolerance (px). Default: 5 */
|
|
53
|
+
stabilityMovementThreshold?: number;
|
|
54
|
+
/** Min face visibility score to accept (below = FACE_OBSTRUCTED). Default: 0.5 */
|
|
55
|
+
minFaceVisibilityScore?: number;
|
|
56
|
+
/** Max head tilt in degrees (roll and yaw only). Default: 28 */
|
|
57
|
+
maxHeadTiltDegrees?: number;
|
|
58
|
+
/** Max distance from hand to face (normalized, 0-1). Default: 0.15 */
|
|
59
|
+
maxHandFaceDistance?: number;
|
|
60
|
+
/** Optional debug mode. Default: false */
|
|
61
|
+
debugMode?: boolean;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Bounding box structure compatible with MediaPipe (normalized 0-1 coords)
|
|
65
|
+
*/
|
|
66
|
+
export interface BoundingBox {
|
|
67
|
+
xMin: number;
|
|
68
|
+
yMin: number;
|
|
69
|
+
width: number;
|
|
70
|
+
height: number;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Detected face data from MediaPipe FaceLandmarker
|
|
74
|
+
*/
|
|
75
|
+
export interface DetectedFaceData {
|
|
76
|
+
/** Bounding box (normalized coordinates 0-1) */
|
|
77
|
+
boundingBox: BoundingBox;
|
|
78
|
+
/** 478 face landmarks (normalized coordinates) */
|
|
79
|
+
landmarks: NormalizedLandmark[];
|
|
80
|
+
/** Detection timestamp */
|
|
81
|
+
timestamp: number;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Detected hand data from MediaPipe HandLandmarker
|
|
85
|
+
*/
|
|
86
|
+
export interface DetectedHandData {
|
|
87
|
+
/** 21 hand landmarks (normalized coordinates) */
|
|
88
|
+
landmarks: NormalizedLandmark[];
|
|
89
|
+
/** Hand classification (Left/Right) */
|
|
90
|
+
handedness: string;
|
|
91
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { NormalizedLandmark } from '@mediapipe/tasks-vision';
|
|
2
|
+
import { DetectedFaceData, DetectedHandData, ValidationStatus, BoundingBox } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Calcula o brilho médio de uma região da imagem (0-255).
|
|
5
|
+
*/
|
|
6
|
+
export declare function calculateAverageBrightness(imageData: ImageData): number;
|
|
7
|
+
/**
|
|
8
|
+
* Verifica se a face está na distância adequada (baseado no tamanho do bounding box).
|
|
9
|
+
*/
|
|
10
|
+
export declare function checkFaceDistance(boundingBox: BoundingBox, minFaceSizeFactor?: number, maxFaceSizeFactor?: number): 'OK' | 'TOO_FAR' | 'TOO_CLOSE';
|
|
11
|
+
/**
|
|
12
|
+
* Verifica se um ponto (normalizado 0-1) está dentro do oval de enquadramento.
|
|
13
|
+
*/
|
|
14
|
+
export declare function isPointInsideOval(pointX: number, pointY: number, frameWidth: number, frameHeight: number): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Verifica se o bounding box da face cabe dentro do oval de enquadramento.
|
|
17
|
+
* Versão simplificada: verifica apenas o centro e limites principais sem margem excessiva.
|
|
18
|
+
*/
|
|
19
|
+
export declare function isFaceBoundingBoxInsideOval(boundingBox: BoundingBox, frameWidth: number, frameHeight: number): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Verifica se a cabeça está reta (sem inclinação lateral, horizontal ou vertical).
|
|
22
|
+
* MediaPipe: usa landmarks dos olhos, nariz e boca.
|
|
23
|
+
*/
|
|
24
|
+
export declare function isHeadStraight(landmarks: NormalizedLandmark[], maxTiltDegrees?: number): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Verifica se a geometria do rosto é plausível (boca visível, não obstruída por mão).
|
|
27
|
+
* MediaPipe: analisa distância nariz-boca e extensão vertical da boca.
|
|
28
|
+
*/
|
|
29
|
+
export declare function isFaceGeometryPlausible(landmarks: NormalizedLandmark[], boundingBox: BoundingBox): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Detecta se a pessoa está usando óculos escuros através da análise de luminosidade dos olhos.
|
|
32
|
+
* Óculos de grau geralmente não bloqueiam completamente a luz, permitindo ver os olhos.
|
|
33
|
+
*/
|
|
34
|
+
export declare function hasDarkGlasses(video: HTMLVideoElement, landmarks: NormalizedLandmark[]): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Verifica se a expressão facial é neutra (sem sorriso, boca fechada, olhos abertos).
|
|
37
|
+
* Rejeita: sorriso, boca aberta, olhos fechados.
|
|
38
|
+
*/
|
|
39
|
+
export declare function isNeutralExpression(landmarks: NormalizedLandmark[]): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Verifica yaw (inclinação lateral) usando visibilidade das orelhas.
|
|
42
|
+
* Quando o rosto está virado para o lado, uma orelha fica mais visível que a outra.
|
|
43
|
+
*/
|
|
44
|
+
export declare function isYawAcceptable(landmarks: NormalizedLandmark[]): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Verifica se a face está estável (sem movimento significativo entre frames).
|
|
47
|
+
*/
|
|
48
|
+
export declare function isFaceStable(currentFace: DetectedFaceData | null, previousFace: DetectedFaceData | null, movementThreshold?: number, frameWidth?: number, frameHeight?: number): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Calcula distância entre um ponto da mão e o centro do rosto (normalizado).
|
|
51
|
+
* Retorna true se a mão estiver próxima ao rosto (indicando possível obstrução).
|
|
52
|
+
*/
|
|
53
|
+
export declare function isHandNearFace(handData: DetectedHandData, faceBoundingBox: BoundingBox, maxDistance?: number): boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Desenha overlay de feedback visual (oval, status, debug info).
|
|
56
|
+
*/
|
|
57
|
+
export declare function drawOverlay(canvas: HTMLCanvasElement, debugMode: boolean, status: ValidationStatus, faceData?: DetectedFaceData, handData?: DetectedHandData[]): void;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { FaceValidator } from './FaceValidator';
|
|
2
|
+
import { ValidationStatus, type FaceValidatorOptions, type DetectedFaceData, type DetectedHandData, type SupportedLocale, type BoundingBox } from './types';
|
|
3
|
+
import { getValidationMessages, getMessage, getLoadingModelsMessage } from './i18n';
|
|
4
|
+
export { FaceValidator };
|
|
5
|
+
export { ValidationStatus, FaceValidatorOptions, DetectedFaceData, DetectedHandData, BoundingBox, SupportedLocale, };
|
|
6
|
+
export { getValidationMessages, getMessage, getLoadingModelsMessage };
|
|
7
|
+
export default FaceValidator;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "face-validator-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Real-time selfie validation SDK with face detection, i18n (pt-BR, en, es). Built on MediaPipe.",
|
|
5
5
|
"main": "dist/face-validator-sdk.cjs.js",
|
|
6
6
|
"module": "dist/face-validator-sdk.esm.js",
|
|
@@ -19,13 +19,25 @@
|
|
|
19
19
|
"browser": "./dist/face-validator-sdk.umd.js",
|
|
20
20
|
"default": "./dist/face-validator-sdk.cjs.js"
|
|
21
21
|
},
|
|
22
|
+
"./core": {
|
|
23
|
+
"import": {
|
|
24
|
+
"types": "./dist/types/core/core.d.ts",
|
|
25
|
+
"default": "./dist/face-validator-sdk-core.esm.js"
|
|
26
|
+
},
|
|
27
|
+
"require": {
|
|
28
|
+
"types": "./dist/types/core/core.d.ts",
|
|
29
|
+
"default": "./dist/face-validator-sdk-core.cjs.js"
|
|
30
|
+
},
|
|
31
|
+
"browser": "./dist/face-validator-sdk-core.umd.js",
|
|
32
|
+
"default": "./dist/face-validator-sdk-core.cjs.js"
|
|
33
|
+
},
|
|
22
34
|
"./package.json": "./package.json"
|
|
23
35
|
},
|
|
24
36
|
"scripts": {
|
|
25
37
|
"start": "webpack serve --config webpack.demo.js --mode development",
|
|
26
38
|
"demo": "webpack serve --config webpack.demo.js --mode development",
|
|
27
39
|
"dev": "webpack serve --config webpack.demo.js --mode development",
|
|
28
|
-
"build": "rimraf dist && webpack --mode production && tsc --emitDeclarationOnly --outDir dist/types",
|
|
40
|
+
"build": "rimraf dist && webpack --mode production && tsc --emitDeclarationOnly --outDir dist/types && tsc --project tsconfig.core.json --emitDeclarationOnly",
|
|
29
41
|
"build:demo": "rimraf demo/dist && webpack --config webpack.demo-prod.js --mode production && cp demo/public/index.html demo/dist/index.html",
|
|
30
42
|
"build:watch": "webpack --watch --mode development",
|
|
31
43
|
"lint": "eslint . --ext .ts --report-unused-disable-directives --max-warnings 0",
|
|
@@ -48,6 +60,8 @@
|
|
|
48
60
|
],
|
|
49
61
|
"files": [
|
|
50
62
|
"dist",
|
|
63
|
+
"core.js",
|
|
64
|
+
"core.d.ts",
|
|
51
65
|
"LICENSE",
|
|
52
66
|
"README.md",
|
|
53
67
|
"CHANGELOG.md"
|
|
@@ -59,6 +73,14 @@
|
|
|
59
73
|
"react": ">=17.0.0",
|
|
60
74
|
"react-dom": ">=17.0.0"
|
|
61
75
|
},
|
|
76
|
+
"peerDependenciesMeta": {
|
|
77
|
+
"react": {
|
|
78
|
+
"optional": true
|
|
79
|
+
},
|
|
80
|
+
"react-dom": {
|
|
81
|
+
"optional": true
|
|
82
|
+
}
|
|
83
|
+
},
|
|
62
84
|
"devDependencies": {
|
|
63
85
|
"@types/jest": "^29.5.12",
|
|
64
86
|
"@typescript-eslint/eslint-plugin": "^7.10.0",
|