face-validator-sdk 1.2.0 → 1.2.1

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 CHANGED
@@ -5,6 +5,19 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [1.2.1] – 2026-02-18
9
+
10
+ ### Fixed
11
+
12
+ - **ReactSelfieCapture**: Fixed circular import dependency that caused `ValidationStatus` to be undefined on load.
13
+ - **Message throttling**: Implemented proper delay between instruction messages (1.5s minimum) to improve readability and user experience. Previous implementation was canceling timeouts preventing the delay from working correctly.
14
+ - **Message display logic**: Messages now stay visible for a minimum configurable time (`MESSAGE_DELAY_MS`), with critical statuses (SUCCESS, ERROR, CAPTURING, INITIALIZING) still displaying immediately.
15
+
16
+ ### Changed
17
+
18
+ - **Smooth transitions**: Added CSS transitions (`0.4s ease-in-out`) to message banner for smoother visual updates.
19
+ - **Import structure**: Changed ReactSelfieCapture imports to use direct module paths instead of index barrel to avoid circular dependencies.
20
+
8
21
  ## [1.1.0] – 2026-02-06
9
22
 
10
23
  ### Changed
@@ -1,3 +1,3 @@
1
1
  /*! For license information please see face-validator-sdk.cjs.js.LICENSE.txt */
2
- (()=>{"use strict";var e={20(e,t,n){var a=n(953),i=Symbol.for("react.element"),o=Symbol.for("react.fragment"),s=Object.prototype.hasOwnProperty,r=a.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,l={key:!0,ref:!0,__self:!0,__source:!0};function c(e,t,n){var a,o={},c=null,d=null;for(a in void 0!==n&&(c=""+n),void 0!==t.key&&(c=""+t.key),void 0!==t.ref&&(d=t.ref),t)s.call(t,a)&&!l.hasOwnProperty(a)&&(o[a]=t[a]);if(e&&e.defaultProps)for(a in t=e.defaultProps)void 0===o[a]&&(o[a]=t[a]);return{$$typeof:i,type:e,key:c,ref:d,props:o,_owner:r.current}}t.Fragment=o,t.jsx=c,t.jsxs=c},848(e,t,n){e.exports=n(20)},953(e){e.exports=require("react")}},t={};function n(a){var i=t[a];if(void 0!==i)return i.exports;var o=t[a]={exports:{}};return e[a](o,o.exports,n),o.exports}n.d=(e,t)=>{for(var a in t)n.o(t,a)&&!n.o(e,a)&&Object.defineProperty(e,a,{enumerable:!0,get:t[a]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var a={};n.r(a),n.d(a,{FaceValidator:()=>S,ReactSelfieCapture:()=>O,ValidationStatus:()=>o,default:()=>v,getLoadingModelsMessage:()=>d,getMessage:()=>c,getValidationMessages:()=>l});const i=require("@mediapipe/tasks-vision");var o;!function(e){e.INITIALIZING="INITIALIZING",e.NO_FACE_DETECTED="NO_FACE_DETECTED",e.FACE_DETECTED="FACE_DETECTED",e.TOO_CLOSE="TOO_CLOSE",e.TOO_FAR="TOO_FAR",e.OFF_CENTER="OFF_CENTER",e.FACE_OBSTRUCTED="FACE_OBSTRUCTED",e.HEAD_NOT_STRAIGHT="HEAD_NOT_STRAIGHT",e.MULTIPLE_FACES="MULTIPLE_FACES",e.POOR_ILLUMINATION="POOR_ILLUMINATION",e.NOT_NEUTRAL_EXPRESSION="NOT_NEUTRAL_EXPRESSION",e.DARK_GLASSES="DARK_GLASSES",e.STAY_STILL="STAY_STILL",e.CAPTURING="CAPTURING",e.SUCCESS="SUCCESS",e.ERROR="ERROR"}(o||(o={}));const s={"pt-BR":{[o.INITIALIZING]:"Inicializando câmera e detector...",[o.NO_FACE_DETECTED]:"Posicione seu rosto no centro do oval.",[o.FACE_DETECTED]:"Analisando...",[o.TOO_CLOSE]:"Afaste-se um pouco",[o.TOO_FAR]:"Aproxime-se da câmera",[o.OFF_CENTER]:"Centralize o rosto no centro do oval",[o.FACE_OBSTRUCTED]:"Mantenha o rosto totalmente visível. Remova as mãos do rosto.",[o.HEAD_NOT_STRAIGHT]:"Olhe diretamente para a câmera e mantenha a cabeça reta.",[o.MULTIPLE_FACES]:"Mantenha apenas uma pessoa no quadro.",[o.POOR_ILLUMINATION]:"Procure um ambiente com boa iluminação.",[o.NOT_NEUTRAL_EXPRESSION]:"Mantenha expressão neutra: boca fechada, sem sorrir e olhos abertos.",[o.DARK_GLASSES]:"Remova os óculos escuros. Óculos de grau são permitidos.",[o.STAY_STILL]:"Fique imóvel para capturar a foto",[o.CAPTURING]:"Capturando...",[o.SUCCESS]:"Captura realizada!",[o.ERROR]:"Ocorreu um erro."},en:{[o.INITIALIZING]:"Initializing camera and detector...",[o.NO_FACE_DETECTED]:"Position your face in the center of the oval.",[o.FACE_DETECTED]:"Analyzing...",[o.TOO_CLOSE]:"Move back a little",[o.TOO_FAR]:"Move closer to the camera",[o.OFF_CENTER]:"Center your face in the center of the oval",[o.FACE_OBSTRUCTED]:"Keep your face fully visible. Remove your hands from your face.",[o.HEAD_NOT_STRAIGHT]:"Look directly at the camera and keep your head straight.",[o.MULTIPLE_FACES]:"Keep only one person in the frame.",[o.POOR_ILLUMINATION]:"Find a well-lit environment and center your face in the oval.",[o.NOT_NEUTRAL_EXPRESSION]:"Keep a neutral expression: mouth closed, no smiling, and eyes open.",[o.DARK_GLASSES]:"Remove sunglasses. Prescription glasses are allowed.",[o.STAY_STILL]:"Stay still to capture the photo",[o.CAPTURING]:"Capturing...",[o.SUCCESS]:"Capture complete!",[o.ERROR]:"An error occurred."},es:{[o.INITIALIZING]:"Inicializando cámara y detector...",[o.NO_FACE_DETECTED]:"Coloque su rostro en el centro del óvalo.",[o.FACE_DETECTED]:"Analizando...",[o.TOO_CLOSE]:"Aléjese un poco",[o.TOO_FAR]:"Acérquese a la cámara",[o.OFF_CENTER]:"Centre el rostro en el centro del óvalo",[o.FACE_OBSTRUCTED]:"Mantenga el rostro totalmente visible. Quite las manos del rostro.",[o.HEAD_NOT_STRAIGHT]:"Mire directamente a la cámara y mantenga la cabeza recta.",[o.MULTIPLE_FACES]:"Mantenga solo una persona en el encuadre.",[o.POOR_ILLUMINATION]:"Busque un ambiente con buena iluminación y centre su rostro en el óvalo.",[o.NOT_NEUTRAL_EXPRESSION]:"Mantenga expresión neutra: boca cerrada, sin sonreír y ojos abiertos.",[o.DARK_GLASSES]:"Quite las gafas de sol. Las gafas graduadas están permitidas.",[o.STAY_STILL]:"Permanezca quieto para capturar la foto",[o.CAPTURING]:"Capturando...",[o.SUCCESS]:"¡Captura realizada!",[o.ERROR]:"Ocurrió un error."}},r={"pt-BR":"Status desconhecido.",en:"Unknown status.",es:"Estado desconhecido."};function l(e){return Object.assign({},s[e])}function c(e,t){var n;return null!==(n=s[t][e])&&void 0!==n?n:r[t]}function d(e){return{"pt-BR":"Carregando...",en:"Loading...",es:"Cargando..."}[e]}function h(e){const t=e.data;let n=0;for(let e=0;e<t.length;e+=4)n+=.2126*t[e]+.7152*t[e+1]+.0722*t[e+2];return n/(t.length/4)}const u=[33,133,159,145],m=[263,362,386,374],f=[61,291,0,17,39,269,270,409],g=.34;var E=function(e,t,n,a){return new(n||(n=Promise))(function(i,o){function s(e){try{l(a.next(e))}catch(e){o(e)}}function r(e){try{l(a.throw(e))}catch(e){o(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(s,r)}l((a=a.apply(e,t||[])).next())})};const p={overlayCanvasElement:void 0,videoWidth:512,videoHeight:384,minDetectionConfidence:.4,minIlluminationThreshold:50,minFaceSizeFactor:.15,maxFaceSizeFactor:.75,stabilizationTimeThreshold:1e3,stabilityMovementThreshold:5,minFaceVisibilityScore:.4,maxHeadTiltDegrees:30,maxHandFaceDistance:.15,debugMode:!1,locale:"en",customMessages:{}};class S{constructor(e){this.faceLandmarker=null,this.handLandmarker=null,this.animationFrameId=null,this.lastDetection=null,this.stableSince=null,this.isCapturing=!1,this.options=this.resolveOptions(e),this.setStatus(o.INITIALIZING),this.init()}resolveOptions(e){const t=e.modelPath||"https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@latest/wasm";return Object.assign(Object.assign(Object.assign({},p),e),{modelPath:t,locale:e.locale||"en",customMessages:e.customMessages||{}})}init(){return E(this,void 0,void 0,function*(){try{const e=d(this.options.locale);this.setStatus(o.INITIALIZING,void 0,e);const t=yield i.FilesetResolver.forVisionTasks(this.options.modelPath);this.faceLandmarker=yield i.FaceLandmarker.createFromOptions(t,{baseOptions:{modelAssetPath:"https://storage.googleapis.com/mediapipe-models/face_landmarker/face_landmarker/float16/1/face_landmarker.task",delegate:"GPU"},runningMode:"VIDEO",numFaces:2,minFaceDetectionConfidence:this.options.minDetectionConfidence,minFacePresenceConfidence:this.options.minFaceVisibilityScore,minTrackingConfidence:this.options.minFaceVisibilityScore}),this.handLandmarker=yield i.HandLandmarker.createFromOptions(t,{baseOptions:{modelAssetPath:"https://storage.googleapis.com/mediapipe-models/hand_landmarker/hand_landmarker/float16/1/hand_landmarker.task",delegate:"GPU"},runningMode:"VIDEO",numHands:2,minHandDetectionConfidence:.5,minHandPresenceConfidence:.5,minTrackingConfidence:.5}),this.startDetectionLoop()}catch(e){const t=e instanceof Error?e:new Error(String(e));this.setStatus(o.ERROR,t)}})}getMessageForStatus(e,t){return t||(this.options.customMessages[e]?this.options.customMessages[e]:c(e,this.options.locale))}setStatus(e,t,n){const a=this.getMessageForStatus(e,n);this.options.onStatusUpdate(e,a),e===o.ERROR&&t&&this.options.onError(e,t)}startDetectionLoop(){const e=this.options.videoElement,t=this.options.videoWidth||640,n=this.options.videoHeight||480,a=()=>E(this,void 0,void 0,function*(){var i;if(this.faceLandmarker&&this.handLandmarker&&e.videoWidth){try{const a=performance.now();let s=o.NO_FACE_DETECTED,r=null,l=[];const c=this.faceLandmarker.detectForVideo(e,a),d=this.handLandmarker.detectForVideo(e,a);if(d.landmarks&&d.landmarks.length>0&&(l=d.landmarks.map((e,t)=>{var n,a,i;return{landmarks:e,handedness:(null===(i=null===(a=null===(n=d.handednesses)||void 0===n?void 0:n[t])||void 0===a?void 0:a[0])||void 0===i?void 0:i.categoryName)||"Unknown"}})),c.faceLandmarks&&c.faceLandmarks.length>1){s=o.MULTIPLE_FACES,this.stableSince=null;const e=c.faceLandmarks[0],t=(null===(i=c.faceBlendshapes)||void 0===i?void 0:i[0])?this.estimateBoundingBox(e):null;t&&(r={boundingBox:t,landmarks:e,timestamp:a})}else if(c.faceLandmarks&&1===c.faceLandmarks.length){const i=c.faceLandmarks[0],d=this.estimateBoundingBox(i);r={boundingBox:d,landmarks:i,timestamp:a};const E=function(e,t=.18,n=.7){const a=e.width;return a<t?"TOO_FAR":a>n?"TOO_CLOSE":"OK"}(d,this.options.minFaceSizeFactor,this.options.maxFaceSizeFactor);if("OK"!==E)s="TOO_CLOSE"===E?o.TOO_CLOSE:o.TOO_FAR,this.stableSince=null;else{const c=i[4],E=function(e,t,n,a){const i=(e*n-n/2)/(.2*n),o=(t*a-a/2)/(a*g);return i*i+o*o<=.6}(c.x,c.y,t,n),p=function(e,t,n){const a=t/2,i=n/2,o=.2*t,s=n*g,r=e.xMin*t,l=(e.xMin+e.width)*t,c=e.yMin*n,d=(e.yMin+e.height)*n,h=((r+l)/2-a)/o,u=((c+d)/2-i)/s;if(h*h+u*u>1)return!1;const m=[{x:r,y:c},{x:l,y:c},{x:r,y:d},{x:l,y:d}];let f=0;for(const e of m){const t=(e.x-a)/o,n=(e.y-i)/s;t*t+n*n>1&&f++}return 0===f}(d,t,n);if(E&&p)if(function(e,t){if(e.length<478)return!1;const n=e[4],a=f.map(t=>e[t]),i=a.reduce((e,t)=>e+t.y,0)/a.length,o=Math.min(...a.map(e=>e.y)),s=Math.max(...a.map(e=>e.y))-o,r=t.height;return!(i<n.y-.01||i-n.y<.06*r||s<.02*r)}(i,d))if(function(e,t=25){if(e.length<478)return!1;const n=e[u[0]],a=e[m[0]],i=e[4],o=e[13],s=e[14],r=e[152],l=e[10],c=Math.abs(n.y-a.y),d=Math.abs(n.x-a.x);if(d<.01)return!1;const h=c/d;if(Math.atan(h)*(180/Math.PI)>t)return!1;const f=(n.x+a.x)/2,g=i.x-f,E=Math.abs(n.x-a.x);if(E<.01)return!1;const p=Math.abs(g)/E;if(Math.atan(p)*(180/Math.PI)>t)return!1;if(!function(e){if(e.length<478)return!1;const t=e[234],n=e[454],a=e[4],i=Math.abs(t.x-a.x),o=Math.abs(n.x-a.x);return!((i>.01&&o>.01?Math.max(i,o)/Math.min(i,o):1)>1.4||void 0!==t.z&&void 0!==n.z&&Math.abs(t.z-n.z)>.05)}(e))return!1;const S=(n.y+a.y)/2,y=(o.y+s.y)/2,T=r.y-l.y;if(T<.1)return!1;if(l.y>S+.02)return!1;if(S>i.y+.02)return!1;if(i.y>y+.02)return!1;if(y>=r.y)return!1;const b=(S-l.y)/T,O=(i.y-S)/T,v=(y-i.y)/T,I=(r.y-y)/T;return!(b<.06||b>.38||O<.03||O>.3||v<.02||v>.25||I<.04||I>.38)}(i,this.options.maxHeadTiltDegrees))if(l.length>0&&function(e,t,n=.15){const a=t.xMin+t.width/2,i=t.yMin+t.height/2;for(const t of e.landmarks){const e=t.x-a,o=t.y-i;if(Math.sqrt(e*e+o*o)<n)return!0}return!1}(l[0],d,this.options.maxHandFaceDistance))s=o.FACE_OBSTRUCTED,this.stableSince=null;else if(function(e){if(e.length<478)return!1;const t=e[159],n=e[144],a=e[386],i=e[373],o=Math.abs(t.y-n.y),s=Math.abs(a.y-i.y);if(o<.01||s<.01)return!1;const r=e[13],l=e[14];if(Math.abs(r.y-l.y)>.025)return!1;const c=e[61],d=e[291],h=e[4];return!((c.y+d.y)/2-h.y<.05)}(i))if(function(e,t){if(t.length<478)return!1;try{const n=document.createElement("canvas"),a=n.getContext("2d");if(!a)return!1;const i=e.videoWidth,o=e.videoHeight,s=[t[33],t[133],t[159],t[144],t[145]],r=[t[263],t[362],t[386],t[373],t[374]],l=e=>{const t=e.map(e=>e.x*i),n=e.map(e=>e.y*o),a=Math.max(0,Math.min(...t)-5),s=Math.min(i,Math.max(...t)+5),r=Math.max(0,Math.min(...n)-5);return{x:a,y:r,width:s-a,height:Math.min(o,Math.max(...n)+5)-r}},c=t=>(n.width=t.width,n.height=t.height,a.drawImage(e,t.x,t.y,t.width,t.height,0,0,t.width,t.height),h(a.getImageData(0,0,t.width,t.height))),d=l(s),u=l(r);return(c(d)+c(u))/2<35}catch(e){return console.warn("Erro ao detectar óculos escuros:",e),!1}}(e,i))s=o.DARK_GLASSES,this.stableSince=null;else{const i=document.createElement("canvas"),l=d.xMin*e.videoWidth,c=d.yMin*e.videoHeight,u=d.width*e.videoWidth,m=d.height*e.videoHeight;i.width=u,i.height=m;const f=i.getContext("2d",{willReadFrequently:!0});if(f){f.drawImage(e,l,c,u,m,0,0,u,m);h(f.getImageData(0,0,i.width,i.height))<this.options.minIlluminationThreshold?(s=o.POOR_ILLUMINATION,this.stableSince=null):function(e,t,n=5,a=512,i=384){if(!e||!t)return!1;const o=(e.boundingBox.xMin+e.boundingBox.width/2)*a,s=(e.boundingBox.yMin+e.boundingBox.height/2)*i,r=(t.boundingBox.xMin+t.boundingBox.width/2)*a,l=(t.boundingBox.yMin+t.boundingBox.height/2)*i,c=Math.abs(o-r),d=Math.abs(s-l),h=Math.abs(e.boundingBox.width-t.boundingBox.width)*a,u=Math.abs(e.boundingBox.height-t.boundingBox.height)*i;return c<=n&&d<=n&&h<=2*n&&u<=2*n}(r,this.lastDetection,this.options.stabilityMovementThreshold,t,n)?(this.stableSince||(this.stableSince=a),s=a-this.stableSince>=this.options.stabilizationTimeThreshold?o.CAPTURING:o.STAY_STILL):(this.stableSince=null,s=o.STAY_STILL)}else s=o.FACE_DETECTED,this.stableSince=null}else s=o.NOT_NEUTRAL_EXPRESSION,this.stableSince=null;else s=o.HEAD_NOT_STRAIGHT,this.stableSince=null;else s=o.FACE_OBSTRUCTED,this.stableSince=null;else s=o.OFF_CENTER,this.stableSince=null}}else this.lastDetection=null,this.stableSince=null;if(this.lastDetection=r,this.setStatus(s),this.options.overlayCanvasElement&&function(e,t,n,a,i){const s=e.getContext("2d");if(!s)return;const r=e.width,l=e.height,c=r/2,d=l/2;s.clearRect(0,0,r,l);const h=.2*r,f=l*g;if(s.fillStyle="rgba(255, 255, 255, 0.35)",s.fillRect(0,0,r,l),s.save(),s.beginPath(),s.ellipse(c,d,h,f,0,0,2*Math.PI),s.closePath(),s.globalCompositeOperation="destination-out",s.fill(),s.restore(),s.strokeStyle="rgba(255, 255, 255, 0.9)",s.lineWidth=3,s.beginPath(),s.ellipse(c,d,h,f,0,0,2*Math.PI),s.stroke(),s.strokeStyle="rgba(255, 255, 255, 0.45)",s.lineWidth=1,s.beginPath(),s.moveTo(c-6,d),s.lineTo(c+6,d),s.moveTo(c,d-6),s.lineTo(c,d+6),s.stroke(),t&&a){const e=a.landmarks;if(e.length>=478){const t=e[10],a=e[152],i=e[234],c=e[454],d=e.map(e=>e.x),h=e.map(e=>e.y),f=Math.min(...d),g=Math.max(...d),E=Math.min(...h),p=g-f,S=Math.max(...h)-E,y=.08,T=(f-p*y)*r,b=(E-S*y)*l,O=p*(1+2*y)*r,v=S*(1+2*y)*l;let I="red";n===o.STAY_STILL||n===o.CAPTURING?I="lime":n===o.FACE_DETECTED&&(I="yellow"),s.strokeStyle=I,s.lineWidth=3,s.strokeRect(T,b,O,v);const C=e[4];e[u[0]],e[m[0]],s.fillStyle="cyan",s.beginPath(),s.arc(C.x*r,C.y*l,5,0,2*Math.PI),s.fill(),s.fillStyle="magenta",s.beginPath(),s.arc(t.x*r,t.y*l,4,0,2*Math.PI),s.fill(),s.fillStyle="lime",s.beginPath(),s.arc(a.x*r,a.y*l,4,0,2*Math.PI),s.fill(),s.fillStyle="yellow",[e[33],e[133],e[159],e[144],e[145]].forEach(e=>{s.beginPath(),s.arc(e.x*r,e.y*l,3,0,2*Math.PI),s.fill()}),s.fillStyle="yellow",[e[263],e[362],e[386],e[373],e[374]].forEach(e=>{s.beginPath(),s.arc(e.x*r,e.y*l,3,0,2*Math.PI),s.fill()}),s.fillStyle="purple",s.beginPath(),s.arc(i.x*r,i.y*l,3,0,2*Math.PI),s.fill(),s.beginPath(),s.arc(c.x*r,c.y*l,3,0,2*Math.PI),s.fill()}}t&&i&&i.length>0&&i.forEach(e=>{s.fillStyle="orange",e.landmarks.forEach(e=>{s.beginPath(),s.arc(e.x*r,e.y*l,3,0,2*Math.PI),s.fill()})})}(this.options.overlayCanvasElement,this.options.debugMode||!1,s,r||void 0,l.length>0?l:void 0),s===o.CAPTURING&&!this.isCapturing)return this.isCapturing=!0,yield this.captureImage(),this.setStatus(o.SUCCESS),void this.stop()}catch(e){const t=e instanceof Error?e:new Error(String(e));this.setStatus(o.ERROR,t)}this.animationFrameId=requestAnimationFrame(a)}else this.animationFrameId=requestAnimationFrame(a)});this.animationFrameId=requestAnimationFrame(a)}estimateBoundingBox(e){const t=e.map(e=>e.x),n=e.map(e=>e.y),a=Math.min(...t),i=Math.max(...t),o=Math.min(...n);return{xMin:a,yMin:o,width:i-a,height:Math.max(...n)-o}}captureImage(){return E(this,void 0,void 0,function*(){const e=this.options.videoElement,t=document.createElement("canvas");t.width=e.videoWidth,t.height=e.videoHeight;const n=t.getContext("2d");n?(n.drawImage(e,0,0,t.width,t.height),t.toBlob(e=>{e?this.options.onCaptureSuccess(e):this.setStatus(o.ERROR,new Error("Failed to generate image blob"))},"image/jpeg",.95)):this.setStatus(o.ERROR,new Error("Failed to get canvas context"))})}stop(){null!==this.animationFrameId&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=null),this.faceLandmarker&&this.faceLandmarker.close(),this.handLandmarker&&this.handLandmarker.close()}}var y=n(848),T=n(953);const b={"pt-BR":{previewQuestion:"O que você achou?",savePhoto:"Salvar foto",tryAgain:"Tentar novamente",cancel:"Cancelar"},en:{previewQuestion:"What do you think?",savePhoto:"Save photo",tryAgain:"Try again",cancel:"Cancel"},es:{previewQuestion:"¿Qué te pareció?",savePhoto:"Guardar foto",tryAgain:"Intentar de nuevo",cancel:"Cancelar"}},O=({onCapture:e,onDismiss:t,locale:n,videoWidth:a=512,videoHeight:i=384,debugMode:s=!1,modelPath:r,styles:l,labels:d})=>{const h=(e=>{if(!e)return"pt-BR";const t=e.toLowerCase();return t.startsWith("en")?"en":t.startsWith("es")?"es":"pt-BR"})(n),u=b[h],m=Object.assign(Object.assign({},u),null!=d?d:{}),f=(0,T.useRef)(null),g=(0,T.useRef)(null),E=(0,T.useRef)(null),[p,O]=(0,T.useState)(o.INITIALIZING),[v,I]=(0,T.useState)(c(o.INITIALIZING,h)),[C,R]=(0,T.useState)(!0),[_,x]=(0,T.useState)(null),A=(0,T.useCallback)((e,t)=>{O(e),I(t)},[]),M=(0,T.useCallback)(e=>{var t;O(o.SUCCESS),I(c(o.SUCCESS,h)),(t=e,new Promise((e,n)=>{const a=new FileReader;a.onloadend=()=>e(a.result),a.onerror=n,a.readAsDataURL(t)})).then(e=>{x(e),R(!1)})},[h]),L=(0,T.useCallback)(()=>{e(null!=_?_:null),null==t||t()},[e,t,_]),F=(0,T.useCallback)(()=>{x(null),O(o.INITIALIZING),I(c(o.INITIALIZING,h)),R(!0)},[h]),N=(0,T.useCallback)((e,t)=>{I(t.message),O(o.ERROR)},[]);(0,T.useEffect)(()=>{const e=f.current;if(!C)return E.current&&(E.current.stop(),E.current=null),void(e&&e.srcObject&&(e.srcObject.getTracks().forEach(e=>e.stop()),e.srcObject=null));if(!e)return;let t=!1;return(n=void 0,l=void 0,c=void 0,d=function*(){var n;try{if(!e.srcObject){const n=yield navigator.mediaDevices.getUserMedia({video:{width:a,height:i}});if(t)return;e.srcObject=n,yield e.play()}const o=g.current;if(o){const t=e.videoWidth||a,n=e.videoHeight||i;o.width=t,o.height=n}if(E.current||t)return;const l={videoElement:e,overlayCanvasElement:null!==(n=g.current)&&void 0!==n?n:void 0,locale:h,debugMode:s,onStatusUpdate:A,onCaptureSuccess:M,onError:N,videoWidth:a,videoHeight:i};r&&(l.modelPath=r);const c=new S(l);E.current=c}catch(e){if(t)return;I(e.message),O(o.ERROR)}},new(c||(c=Promise))(function(e,t){function a(e){try{o(d.next(e))}catch(e){t(e)}}function i(e){try{o(d.throw(e))}catch(e){t(e)}}function o(t){var n;t.done?e(t.value):(n=t.value,n instanceof c?n:new c(function(e){e(n)})).then(a,i)}o((d=d.apply(n,l||[])).next())})).catch(()=>{}),()=>{t=!0,E.current&&(E.current.stop(),E.current=null),e&&e.srcObject&&(e.srcObject.getTracks().forEach(e=>e.stop()),e.srcObject=null)};var n,l,c,d},[C,h,a,i,s,r,A,M,N]);const P=!C&&Boolean(_),k=C,w=Object.assign({width:"100%",maxWidth:640,boxSizing:"border-box"},null==l?void 0:l.container),D=Object.assign({textAlign:"center",display:"flex",alignItems:"center",justifyContent:"center",fontSize:16,padding:"10px 12px",marginBottom:10,borderRadius:10,fontWeight:600,marginTop:30,height:52,boxSizing:"border-box"},null==l?void 0:l.messageBanner),j=Object.assign(Object.assign({},D),{backgroundColor:"#fff7df",color:"#b67219"});k&&(p===o.SUCCESS?(j.backgroundColor="#e0ffdf",j.color="#26c026"):p===o.ERROR&&(j.backgroundColor="#ffdfdf",j.color="#c02626"));const U=Object.assign({width:"100%",maxWidth:512,height:384,margin:"0 auto",borderRadius:10,overflow:"hidden",position:"relative",backgroundColor:"#1a1a1a"},null==l?void 0:l.media),B={display:"block",width:"100%",padding:"8px 12px",borderRadius:4,border:"1px solid #d9d9d9",backgroundColor:"#ffffff",cursor:"pointer",fontSize:14},G=Object.assign(Object.assign(Object.assign({},B),{backgroundColor:"#1dbe32",color:"#ffffff",borderColor:"#1dbe32"}),null==l?void 0:l.primaryButton),H=Object.assign(Object.assign({},B),null==l?void 0:l.secondaryButton);return(0,y.jsxs)("div",{style:w,children:[(0,y.jsx)("div",{style:j,children:P?m.previewQuestion:v}),(0,y.jsx)("div",{style:U,children:k?(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)("video",{ref:f,autoPlay:!0,playsInline:!0,muted:!0,style:{width:"100%",height:"100%",objectFit:"cover",transform:"scaleX(-1)"}}),(0,y.jsx)("canvas",{ref:g,style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",pointerEvents:"none",transform:"scaleX(-1)"}})]}):P&&_?(0,y.jsx)("img",{src:_,alt:"Selfie preview",style:{display:"block",width:"100%",height:"100%",objectFit:"cover",transform:"scaleX(-1)",backgroundColor:"transparent",border:"none"}}):(0,y.jsx)("div",{"aria-hidden":!0})}),(0,y.jsx)("div",{style:{marginTop:10},children:P?(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)("button",{type:"button",onClick:F,style:H,children:m.tryAgain}),(0,y.jsx)("div",{style:{height:8}}),(0,y.jsx)("button",{type:"button",onClick:L,disabled:!_,style:Object.assign(Object.assign({},G),{opacity:_?1:.6,cursor:_?"pointer":"not-allowed"}),children:m.savePhoto})]}):(0,y.jsx)("button",{type:"button",onClick:()=>{null==t||t(),e(null),R(!1)},style:H,children:m.cancel})})]})},v=S;module.exports=a})();
2
+ (()=>{"use strict";var e={20(e,t,n){var a=n(953),i=Symbol.for("react.element"),o=Symbol.for("react.fragment"),r=Object.prototype.hasOwnProperty,s=a.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,l={key:!0,ref:!0,__self:!0,__source:!0};function c(e,t,n){var a,o={},c=null,d=null;for(a in void 0!==n&&(c=""+n),void 0!==t.key&&(c=""+t.key),void 0!==t.ref&&(d=t.ref),t)r.call(t,a)&&!l.hasOwnProperty(a)&&(o[a]=t[a]);if(e&&e.defaultProps)for(a in t=e.defaultProps)void 0===o[a]&&(o[a]=t[a]);return{$$typeof:i,type:e,key:c,ref:d,props:o,_owner:s.current}}t.Fragment=o,t.jsx=c,t.jsxs=c},848(e,t,n){e.exports=n(20)},953(e){e.exports=require("react")}},t={};function n(a){var i=t[a];if(void 0!==i)return i.exports;var o=t[a]={exports:{}};return e[a](o,o.exports,n),o.exports}n.d=(e,t)=>{for(var a in t)n.o(t,a)&&!n.o(e,a)&&Object.defineProperty(e,a,{enumerable:!0,get:t[a]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var a={};n.r(a),n.d(a,{FaceValidator:()=>S,ReactSelfieCapture:()=>v,ValidationStatus:()=>o,default:()=>I,getLoadingModelsMessage:()=>d,getMessage:()=>c,getValidationMessages:()=>l});const i=require("@mediapipe/tasks-vision");var o;!function(e){e.INITIALIZING="INITIALIZING",e.NO_FACE_DETECTED="NO_FACE_DETECTED",e.FACE_DETECTED="FACE_DETECTED",e.TOO_CLOSE="TOO_CLOSE",e.TOO_FAR="TOO_FAR",e.OFF_CENTER="OFF_CENTER",e.FACE_OBSTRUCTED="FACE_OBSTRUCTED",e.HEAD_NOT_STRAIGHT="HEAD_NOT_STRAIGHT",e.MULTIPLE_FACES="MULTIPLE_FACES",e.POOR_ILLUMINATION="POOR_ILLUMINATION",e.NOT_NEUTRAL_EXPRESSION="NOT_NEUTRAL_EXPRESSION",e.DARK_GLASSES="DARK_GLASSES",e.STAY_STILL="STAY_STILL",e.CAPTURING="CAPTURING",e.SUCCESS="SUCCESS",e.ERROR="ERROR"}(o||(o={}));const r={"pt-BR":{[o.INITIALIZING]:"Inicializando câmera e detector...",[o.NO_FACE_DETECTED]:"Posicione seu rosto no centro do oval.",[o.FACE_DETECTED]:"Analisando...",[o.TOO_CLOSE]:"Afaste-se um pouco",[o.TOO_FAR]:"Aproxime-se da câmera",[o.OFF_CENTER]:"Centralize o rosto no centro do oval",[o.FACE_OBSTRUCTED]:"Mantenha o rosto totalmente visível. Remova as mãos do rosto.",[o.HEAD_NOT_STRAIGHT]:"Olhe diretamente para a câmera e mantenha a cabeça reta.",[o.MULTIPLE_FACES]:"Mantenha apenas uma pessoa no quadro.",[o.POOR_ILLUMINATION]:"Procure um ambiente com boa iluminação.",[o.NOT_NEUTRAL_EXPRESSION]:"Mantenha expressão neutra: boca fechada, sem sorrir e olhos abertos.",[o.DARK_GLASSES]:"Remova os óculos escuros. Óculos de grau são permitidos.",[o.STAY_STILL]:"Fique imóvel para capturar a foto",[o.CAPTURING]:"Capturando...",[o.SUCCESS]:"Captura realizada!",[o.ERROR]:"Ocorreu um erro."},en:{[o.INITIALIZING]:"Initializing camera and detector...",[o.NO_FACE_DETECTED]:"Position your face in the center of the oval.",[o.FACE_DETECTED]:"Analyzing...",[o.TOO_CLOSE]:"Move back a little",[o.TOO_FAR]:"Move closer to the camera",[o.OFF_CENTER]:"Center your face in the center of the oval",[o.FACE_OBSTRUCTED]:"Keep your face fully visible. Remove your hands from your face.",[o.HEAD_NOT_STRAIGHT]:"Look directly at the camera and keep your head straight.",[o.MULTIPLE_FACES]:"Keep only one person in the frame.",[o.POOR_ILLUMINATION]:"Find a well-lit environment and center your face in the oval.",[o.NOT_NEUTRAL_EXPRESSION]:"Keep a neutral expression: mouth closed, no smiling, and eyes open.",[o.DARK_GLASSES]:"Remove sunglasses. Prescription glasses are allowed.",[o.STAY_STILL]:"Stay still to capture the photo",[o.CAPTURING]:"Capturing...",[o.SUCCESS]:"Capture complete!",[o.ERROR]:"An error occurred."},es:{[o.INITIALIZING]:"Inicializando cámara y detector...",[o.NO_FACE_DETECTED]:"Coloque su rostro en el centro del óvalo.",[o.FACE_DETECTED]:"Analizando...",[o.TOO_CLOSE]:"Aléjese un poco",[o.TOO_FAR]:"Acérquese a la cámara",[o.OFF_CENTER]:"Centre el rostro en el centro del óvalo",[o.FACE_OBSTRUCTED]:"Mantenga el rostro totalmente visible. Quite las manos del rostro.",[o.HEAD_NOT_STRAIGHT]:"Mire directamente a la cámara y mantenga la cabeza recta.",[o.MULTIPLE_FACES]:"Mantenga solo una persona en el encuadre.",[o.POOR_ILLUMINATION]:"Busque un ambiente con buena iluminación y centre su rostro en el óvalo.",[o.NOT_NEUTRAL_EXPRESSION]:"Mantenga expresión neutra: boca cerrada, sin sonreír y ojos abiertos.",[o.DARK_GLASSES]:"Quite las gafas de sol. Las gafas graduadas están permitidas.",[o.STAY_STILL]:"Permanezca quieto para capturar la foto",[o.CAPTURING]:"Capturando...",[o.SUCCESS]:"¡Captura realizada!",[o.ERROR]:"Ocurrió un error."}},s={"pt-BR":"Status desconhecido.",en:"Unknown status.",es:"Estado desconhecido."};function l(e){return Object.assign({},r[e])}function c(e,t){var n;return null!==(n=r[t][e])&&void 0!==n?n:s[t]}function d(e){return{"pt-BR":"Carregando...",en:"Loading...",es:"Cargando..."}[e]}function u(e){const t=e.data;let n=0;for(let e=0;e<t.length;e+=4)n+=.2126*t[e]+.7152*t[e+1]+.0722*t[e+2];return n/(t.length/4)}const h=[33,133,159,145],m=[263,362,386,374],f=[61,291,0,17,39,269,270,409],g=.34;var E=function(e,t,n,a){return new(n||(n=Promise))(function(i,o){function r(e){try{l(a.next(e))}catch(e){o(e)}}function s(e){try{l(a.throw(e))}catch(e){o(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(r,s)}l((a=a.apply(e,t||[])).next())})};const p={overlayCanvasElement:void 0,videoWidth:512,videoHeight:384,minDetectionConfidence:.4,minIlluminationThreshold:50,minFaceSizeFactor:.15,maxFaceSizeFactor:.75,stabilizationTimeThreshold:1e3,stabilityMovementThreshold:5,minFaceVisibilityScore:.4,maxHeadTiltDegrees:30,maxHandFaceDistance:.15,debugMode:!1,locale:"en",customMessages:{}};class S{constructor(e){this.faceLandmarker=null,this.handLandmarker=null,this.animationFrameId=null,this.lastDetection=null,this.stableSince=null,this.isCapturing=!1,this.options=this.resolveOptions(e),this.setStatus(o.INITIALIZING),this.init()}resolveOptions(e){const t=e.modelPath||"https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@latest/wasm";return Object.assign(Object.assign(Object.assign({},p),e),{modelPath:t,locale:e.locale||"en",customMessages:e.customMessages||{}})}init(){return E(this,void 0,void 0,function*(){try{const e=d(this.options.locale);this.setStatus(o.INITIALIZING,void 0,e);const t=yield i.FilesetResolver.forVisionTasks(this.options.modelPath);this.faceLandmarker=yield i.FaceLandmarker.createFromOptions(t,{baseOptions:{modelAssetPath:"https://storage.googleapis.com/mediapipe-models/face_landmarker/face_landmarker/float16/1/face_landmarker.task",delegate:"GPU"},runningMode:"VIDEO",numFaces:2,minFaceDetectionConfidence:this.options.minDetectionConfidence,minFacePresenceConfidence:this.options.minFaceVisibilityScore,minTrackingConfidence:this.options.minFaceVisibilityScore}),this.handLandmarker=yield i.HandLandmarker.createFromOptions(t,{baseOptions:{modelAssetPath:"https://storage.googleapis.com/mediapipe-models/hand_landmarker/hand_landmarker/float16/1/hand_landmarker.task",delegate:"GPU"},runningMode:"VIDEO",numHands:2,minHandDetectionConfidence:.5,minHandPresenceConfidence:.5,minTrackingConfidence:.5}),this.startDetectionLoop()}catch(e){const t=e instanceof Error?e:new Error(String(e));this.setStatus(o.ERROR,t)}})}getMessageForStatus(e,t){return t||(this.options.customMessages[e]?this.options.customMessages[e]:c(e,this.options.locale))}setStatus(e,t,n){const a=this.getMessageForStatus(e,n);this.options.onStatusUpdate(e,a),e===o.ERROR&&t&&this.options.onError(e,t)}startDetectionLoop(){const e=this.options.videoElement,t=this.options.videoWidth||640,n=this.options.videoHeight||480,a=()=>E(this,void 0,void 0,function*(){var i;if(this.faceLandmarker&&this.handLandmarker&&e.videoWidth){try{const a=performance.now();let r=o.NO_FACE_DETECTED,s=null,l=[];const c=this.faceLandmarker.detectForVideo(e,a),d=this.handLandmarker.detectForVideo(e,a);if(d.landmarks&&d.landmarks.length>0&&(l=d.landmarks.map((e,t)=>{var n,a,i;return{landmarks:e,handedness:(null===(i=null===(a=null===(n=d.handednesses)||void 0===n?void 0:n[t])||void 0===a?void 0:a[0])||void 0===i?void 0:i.categoryName)||"Unknown"}})),c.faceLandmarks&&c.faceLandmarks.length>1){r=o.MULTIPLE_FACES,this.stableSince=null;const e=c.faceLandmarks[0],t=(null===(i=c.faceBlendshapes)||void 0===i?void 0:i[0])?this.estimateBoundingBox(e):null;t&&(s={boundingBox:t,landmarks:e,timestamp:a})}else if(c.faceLandmarks&&1===c.faceLandmarks.length){const i=c.faceLandmarks[0],d=this.estimateBoundingBox(i);s={boundingBox:d,landmarks:i,timestamp:a};const E=function(e,t=.18,n=.7){const a=e.width;return a<t?"TOO_FAR":a>n?"TOO_CLOSE":"OK"}(d,this.options.minFaceSizeFactor,this.options.maxFaceSizeFactor);if("OK"!==E)r="TOO_CLOSE"===E?o.TOO_CLOSE:o.TOO_FAR,this.stableSince=null;else{const c=i[4],E=function(e,t,n,a){const i=(e*n-n/2)/(.2*n),o=(t*a-a/2)/(a*g);return i*i+o*o<=.6}(c.x,c.y,t,n),p=function(e,t,n){const a=t/2,i=n/2,o=.2*t,r=n*g,s=e.xMin*t,l=(e.xMin+e.width)*t,c=e.yMin*n,d=(e.yMin+e.height)*n,u=((s+l)/2-a)/o,h=((c+d)/2-i)/r;if(u*u+h*h>1)return!1;const m=[{x:s,y:c},{x:l,y:c},{x:s,y:d},{x:l,y:d}];let f=0;for(const e of m){const t=(e.x-a)/o,n=(e.y-i)/r;t*t+n*n>1&&f++}return 0===f}(d,t,n);if(E&&p)if(function(e,t){if(e.length<478)return!1;const n=e[4],a=f.map(t=>e[t]),i=a.reduce((e,t)=>e+t.y,0)/a.length,o=Math.min(...a.map(e=>e.y)),r=Math.max(...a.map(e=>e.y))-o,s=t.height;return!(i<n.y-.01||i-n.y<.06*s||r<.02*s)}(i,d))if(function(e,t=25){if(e.length<478)return!1;const n=e[h[0]],a=e[m[0]],i=e[4],o=e[13],r=e[14],s=e[152],l=e[10],c=Math.abs(n.y-a.y),d=Math.abs(n.x-a.x);if(d<.01)return!1;const u=c/d;if(Math.atan(u)*(180/Math.PI)>t)return!1;const f=(n.x+a.x)/2,g=i.x-f,E=Math.abs(n.x-a.x);if(E<.01)return!1;const p=Math.abs(g)/E;if(Math.atan(p)*(180/Math.PI)>t)return!1;if(!function(e){if(e.length<478)return!1;const t=e[234],n=e[454],a=e[4],i=Math.abs(t.x-a.x),o=Math.abs(n.x-a.x);return!((i>.01&&o>.01?Math.max(i,o)/Math.min(i,o):1)>1.4||void 0!==t.z&&void 0!==n.z&&Math.abs(t.z-n.z)>.05)}(e))return!1;const S=(n.y+a.y)/2,T=(o.y+r.y)/2,y=s.y-l.y;if(y<.1)return!1;if(l.y>S+.02)return!1;if(S>i.y+.02)return!1;if(i.y>T+.02)return!1;if(T>=s.y)return!1;const b=(S-l.y)/y,O=(i.y-S)/y,v=(T-i.y)/y,I=(s.y-T)/y;return!(b<.06||b>.38||O<.03||O>.3||v<.02||v>.25||I<.04||I>.38)}(i,this.options.maxHeadTiltDegrees))if(l.length>0&&function(e,t,n=.15){const a=t.xMin+t.width/2,i=t.yMin+t.height/2;for(const t of e.landmarks){const e=t.x-a,o=t.y-i;if(Math.sqrt(e*e+o*o)<n)return!0}return!1}(l[0],d,this.options.maxHandFaceDistance))r=o.FACE_OBSTRUCTED,this.stableSince=null;else if(function(e){if(e.length<478)return!1;const t=e[159],n=e[144],a=e[386],i=e[373],o=Math.abs(t.y-n.y),r=Math.abs(a.y-i.y);if(o<.01||r<.01)return!1;const s=e[13],l=e[14];if(Math.abs(s.y-l.y)>.025)return!1;const c=e[61],d=e[291],u=e[4];return!((c.y+d.y)/2-u.y<.05)}(i))if(function(e,t){if(t.length<478)return!1;try{const n=document.createElement("canvas"),a=n.getContext("2d");if(!a)return!1;const i=e.videoWidth,o=e.videoHeight,r=[t[33],t[133],t[159],t[144],t[145]],s=[t[263],t[362],t[386],t[373],t[374]],l=e=>{const t=e.map(e=>e.x*i),n=e.map(e=>e.y*o),a=Math.max(0,Math.min(...t)-5),r=Math.min(i,Math.max(...t)+5),s=Math.max(0,Math.min(...n)-5);return{x:a,y:s,width:r-a,height:Math.min(o,Math.max(...n)+5)-s}},c=t=>(n.width=t.width,n.height=t.height,a.drawImage(e,t.x,t.y,t.width,t.height,0,0,t.width,t.height),u(a.getImageData(0,0,t.width,t.height))),d=l(r),h=l(s);return(c(d)+c(h))/2<35}catch(e){return console.warn("Erro ao detectar óculos escuros:",e),!1}}(e,i))r=o.DARK_GLASSES,this.stableSince=null;else{const i=document.createElement("canvas"),l=d.xMin*e.videoWidth,c=d.yMin*e.videoHeight,h=d.width*e.videoWidth,m=d.height*e.videoHeight;i.width=h,i.height=m;const f=i.getContext("2d",{willReadFrequently:!0});if(f){f.drawImage(e,l,c,h,m,0,0,h,m);u(f.getImageData(0,0,i.width,i.height))<this.options.minIlluminationThreshold?(r=o.POOR_ILLUMINATION,this.stableSince=null):function(e,t,n=5,a=512,i=384){if(!e||!t)return!1;const o=(e.boundingBox.xMin+e.boundingBox.width/2)*a,r=(e.boundingBox.yMin+e.boundingBox.height/2)*i,s=(t.boundingBox.xMin+t.boundingBox.width/2)*a,l=(t.boundingBox.yMin+t.boundingBox.height/2)*i,c=Math.abs(o-s),d=Math.abs(r-l),u=Math.abs(e.boundingBox.width-t.boundingBox.width)*a,h=Math.abs(e.boundingBox.height-t.boundingBox.height)*i;return c<=n&&d<=n&&u<=2*n&&h<=2*n}(s,this.lastDetection,this.options.stabilityMovementThreshold,t,n)?(this.stableSince||(this.stableSince=a),r=a-this.stableSince>=this.options.stabilizationTimeThreshold?o.CAPTURING:o.STAY_STILL):(this.stableSince=null,r=o.STAY_STILL)}else r=o.FACE_DETECTED,this.stableSince=null}else r=o.NOT_NEUTRAL_EXPRESSION,this.stableSince=null;else r=o.HEAD_NOT_STRAIGHT,this.stableSince=null;else r=o.FACE_OBSTRUCTED,this.stableSince=null;else r=o.OFF_CENTER,this.stableSince=null}}else this.lastDetection=null,this.stableSince=null;if(this.lastDetection=s,this.setStatus(r),this.options.overlayCanvasElement&&function(e,t,n,a,i){const r=e.getContext("2d");if(!r)return;const s=e.width,l=e.height,c=s/2,d=l/2;r.clearRect(0,0,s,l);const u=.2*s,f=l*g;if(r.fillStyle="rgba(255, 255, 255, 0.35)",r.fillRect(0,0,s,l),r.save(),r.beginPath(),r.ellipse(c,d,u,f,0,0,2*Math.PI),r.closePath(),r.globalCompositeOperation="destination-out",r.fill(),r.restore(),r.strokeStyle="rgba(255, 255, 255, 0.9)",r.lineWidth=3,r.beginPath(),r.ellipse(c,d,u,f,0,0,2*Math.PI),r.stroke(),r.strokeStyle="rgba(255, 255, 255, 0.45)",r.lineWidth=1,r.beginPath(),r.moveTo(c-6,d),r.lineTo(c+6,d),r.moveTo(c,d-6),r.lineTo(c,d+6),r.stroke(),t&&a){const e=a.landmarks;if(e.length>=478){const t=e[10],a=e[152],i=e[234],c=e[454],d=e.map(e=>e.x),u=e.map(e=>e.y),f=Math.min(...d),g=Math.max(...d),E=Math.min(...u),p=g-f,S=Math.max(...u)-E,T=.08,y=(f-p*T)*s,b=(E-S*T)*l,O=p*(1+2*T)*s,v=S*(1+2*T)*l;let I="red";n===o.STAY_STILL||n===o.CAPTURING?I="lime":n===o.FACE_DETECTED&&(I="yellow"),r.strokeStyle=I,r.lineWidth=3,r.strokeRect(y,b,O,v);const C=e[4];e[h[0]],e[m[0]],r.fillStyle="cyan",r.beginPath(),r.arc(C.x*s,C.y*l,5,0,2*Math.PI),r.fill(),r.fillStyle="magenta",r.beginPath(),r.arc(t.x*s,t.y*l,4,0,2*Math.PI),r.fill(),r.fillStyle="lime",r.beginPath(),r.arc(a.x*s,a.y*l,4,0,2*Math.PI),r.fill(),r.fillStyle="yellow",[e[33],e[133],e[159],e[144],e[145]].forEach(e=>{r.beginPath(),r.arc(e.x*s,e.y*l,3,0,2*Math.PI),r.fill()}),r.fillStyle="yellow",[e[263],e[362],e[386],e[373],e[374]].forEach(e=>{r.beginPath(),r.arc(e.x*s,e.y*l,3,0,2*Math.PI),r.fill()}),r.fillStyle="purple",r.beginPath(),r.arc(i.x*s,i.y*l,3,0,2*Math.PI),r.fill(),r.beginPath(),r.arc(c.x*s,c.y*l,3,0,2*Math.PI),r.fill()}}t&&i&&i.length>0&&i.forEach(e=>{r.fillStyle="orange",e.landmarks.forEach(e=>{r.beginPath(),r.arc(e.x*s,e.y*l,3,0,2*Math.PI),r.fill()})})}(this.options.overlayCanvasElement,this.options.debugMode||!1,r,s||void 0,l.length>0?l:void 0),r===o.CAPTURING&&!this.isCapturing)return this.isCapturing=!0,yield this.captureImage(),this.setStatus(o.SUCCESS),void this.stop()}catch(e){const t=e instanceof Error?e:new Error(String(e));this.setStatus(o.ERROR,t)}this.animationFrameId=requestAnimationFrame(a)}else this.animationFrameId=requestAnimationFrame(a)});this.animationFrameId=requestAnimationFrame(a)}estimateBoundingBox(e){const t=e.map(e=>e.x),n=e.map(e=>e.y),a=Math.min(...t),i=Math.max(...t),o=Math.min(...n);return{xMin:a,yMin:o,width:i-a,height:Math.max(...n)-o}}captureImage(){return E(this,void 0,void 0,function*(){const e=this.options.videoElement,t=document.createElement("canvas");t.width=e.videoWidth,t.height=e.videoHeight;const n=t.getContext("2d");n?(n.drawImage(e,0,0,t.width,t.height),t.toBlob(e=>{e?this.options.onCaptureSuccess(e):this.setStatus(o.ERROR,new Error("Failed to generate image blob"))},"image/jpeg",.95)):this.setStatus(o.ERROR,new Error("Failed to get canvas context"))})}stop(){null!==this.animationFrameId&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=null),this.faceLandmarker&&this.faceLandmarker.close(),this.handLandmarker&&this.handLandmarker.close()}}var T=n(848),y=n(953);const b=[o.SUCCESS,o.ERROR,o.CAPTURING,o.INITIALIZING],O={"pt-BR":{previewQuestion:"O que você achou?",savePhoto:"Salvar foto",tryAgain:"Tentar novamente",cancel:"Cancelar"},en:{previewQuestion:"What do you think?",savePhoto:"Save photo",tryAgain:"Try again",cancel:"Cancel"},es:{previewQuestion:"¿Qué te pareció?",savePhoto:"Guardar foto",tryAgain:"Intentar de nuevo",cancel:"Cancelar"}},v=({onCapture:e,onDismiss:t,locale:n,videoWidth:a=512,videoHeight:i=384,debugMode:r=!1,modelPath:s,styles:l,labels:d})=>{const u=(e=>{if(!e)return"pt-BR";const t=e.toLowerCase();return t.startsWith("en")?"en":t.startsWith("es")?"es":"pt-BR"})(n),h=O[u],m=Object.assign(Object.assign({},h),null!=d?d:{}),f=(0,y.useRef)(null),g=(0,y.useRef)(null),E=(0,y.useRef)(null),p=(0,y.useRef)(null),v=(0,y.useRef)(0),I=(0,y.useRef)(""),[C,R]=(0,y.useState)(o.INITIALIZING),[_,x]=(0,y.useState)(c(o.INITIALIZING,u)),[A,M]=(0,y.useState)(c(o.INITIALIZING,u)),[L,F]=(0,y.useState)(!0),[N,P]=(0,y.useState)(null),k=(0,y.useCallback)((e,t)=>{R(e),x(t)},[]);(0,y.useEffect)(()=>{if(I.current=_,_===A)return;if(b.includes(C))return p.current&&(clearTimeout(p.current),p.current=null),M(_),void(v.current=Date.now());const e=Date.now(),t=e-v.current;if(t>=1500)return M(_),void(v.current=e);if(p.current)return;const n=1500-t;p.current=setTimeout(()=>{M(I.current),v.current=Date.now(),p.current=null},n)},[_,C,A]);const w=(0,y.useCallback)(e=>{var t;R(o.SUCCESS),x(c(o.SUCCESS,u)),(t=e,new Promise((e,n)=>{const a=new FileReader;a.onloadend=()=>e(a.result),a.onerror=n,a.readAsDataURL(t)})).then(e=>{P(e),F(!1)})},[u]),D=(0,y.useCallback)(()=>{e(null!=N?N:null),null==t||t()},[e,t,N]),j=(0,y.useCallback)(()=>{P(null),R(o.INITIALIZING),x(c(o.INITIALIZING,u)),F(!0)},[u]),U=(0,y.useCallback)((e,t)=>{x(t.message),R(o.ERROR)},[]);(0,y.useEffect)(()=>{const e=f.current;if(!L)return E.current&&(E.current.stop(),E.current=null),void(e&&e.srcObject&&(e.srcObject.getTracks().forEach(e=>e.stop()),e.srcObject=null));if(!e)return;let t=!1;return(n=void 0,l=void 0,c=void 0,d=function*(){var n;try{if(!e.srcObject){const n=yield navigator.mediaDevices.getUserMedia({video:{width:a,height:i}});if(t)return;e.srcObject=n,yield e.play()}const o=g.current;if(o){const t=e.videoWidth||a,n=e.videoHeight||i;o.width=t,o.height=n}if(E.current||t)return;const l={videoElement:e,overlayCanvasElement:null!==(n=g.current)&&void 0!==n?n:void 0,locale:u,debugMode:r,onStatusUpdate:k,onCaptureSuccess:w,onError:U,videoWidth:a,videoHeight:i};s&&(l.modelPath=s);const c=new S(l);E.current=c}catch(e){if(t)return;x(e.message),R(o.ERROR)}},new(c||(c=Promise))(function(e,t){function a(e){try{o(d.next(e))}catch(e){t(e)}}function i(e){try{o(d.throw(e))}catch(e){t(e)}}function o(t){var n;t.done?e(t.value):(n=t.value,n instanceof c?n:new c(function(e){e(n)})).then(a,i)}o((d=d.apply(n,l||[])).next())})).catch(()=>{}),()=>{t=!0,E.current&&(E.current.stop(),E.current=null),e&&e.srcObject&&(e.srcObject.getTracks().forEach(e=>e.stop()),e.srcObject=null)};var n,l,c,d},[L,u,a,i,r,s,k,w,U]);const B=!L&&Boolean(N),G=L,H=Object.assign({width:"100%",maxWidth:640,boxSizing:"border-box"},null==l?void 0:l.container),z=Object.assign({textAlign:"center",display:"flex",alignItems:"center",justifyContent:"center",fontSize:16,padding:"10px 12px",marginBottom:10,borderRadius:10,fontWeight:600,marginTop:30,height:52,boxSizing:"border-box",transition:"all 0.4s ease-in-out"},null==l?void 0:l.messageBanner),W=Object.assign(Object.assign({},z),{backgroundColor:"#fff7df",color:"#b67219"});G&&(C===o.SUCCESS?(W.backgroundColor="#e0ffdf",W.color="#26c026"):C===o.ERROR&&(W.backgroundColor="#ffdfdf",W.color="#c02626"));const q=Object.assign({width:"100%",maxWidth:512,height:384,margin:"0 auto",borderRadius:10,overflow:"hidden",position:"relative",backgroundColor:"#1a1a1a"},null==l?void 0:l.media),Z={display:"block",width:"100%",padding:"8px 12px",borderRadius:4,border:"1px solid #d9d9d9",backgroundColor:"#ffffff",cursor:"pointer",fontSize:14},K=Object.assign(Object.assign(Object.assign({},Z),{backgroundColor:"#1dbe32",color:"#ffffff",borderColor:"#1dbe32"}),null==l?void 0:l.primaryButton),V=Object.assign(Object.assign({},Z),null==l?void 0:l.secondaryButton);return(0,T.jsxs)("div",{style:H,children:[(0,T.jsx)("div",{style:W,children:B?m.previewQuestion:A}),(0,T.jsx)("div",{style:q,children:G?(0,T.jsxs)(T.Fragment,{children:[(0,T.jsx)("video",{ref:f,autoPlay:!0,playsInline:!0,muted:!0,style:{width:"100%",height:"100%",objectFit:"cover",transform:"scaleX(-1)"}}),(0,T.jsx)("canvas",{ref:g,style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",pointerEvents:"none",transform:"scaleX(-1)"}})]}):B&&N?(0,T.jsx)("img",{src:N,alt:"Selfie preview",style:{display:"block",width:"100%",height:"100%",objectFit:"cover",transform:"scaleX(-1)",backgroundColor:"transparent",border:"none"}}):(0,T.jsx)("div",{"aria-hidden":!0})}),(0,T.jsx)("div",{style:{marginTop:10},children:B?(0,T.jsxs)(T.Fragment,{children:[(0,T.jsx)("button",{type:"button",onClick:j,style:V,children:m.tryAgain}),(0,T.jsx)("div",{style:{height:8}}),(0,T.jsx)("button",{type:"button",onClick:D,disabled:!N,style:Object.assign(Object.assign({},K),{opacity:N?1:.6,cursor:N?"pointer":"not-allowed"}),children:m.savePhoto})]}):(0,T.jsx)("button",{type:"button",onClick:()=>{null==t||t(),e(null),F(!1)},style:V,children:m.cancel})})]})},I=S;module.exports=a})();
3
3
  //# sourceMappingURL=face-validator-sdk.cjs.js.map