@tsocial/tvweb-sdk 5.38.4 → 5.38.5

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.
Files changed (26) hide show
  1. package/build/esm/{chunk-9803c4f4.js → chunk-4ba29034.js} +1 -1
  2. package/build/esm/{chunk-0d38d10a.js → chunk-5232d933.js} +1 -1
  3. package/build/esm/{chunk-65036591.js → chunk-5510f102.js} +1 -1
  4. package/build/esm/{chunk-c385606a.js → chunk-570905cb.js} +1 -1
  5. package/build/esm/{chunk-27713cdc.js → chunk-66453960.js} +154 -152
  6. package/build/esm/{chunk-99078e42.js → chunk-718c6bbe.js} +1 -1
  7. package/build/esm/{chunk-4f3a497a.js → chunk-7b4af7bc.js} +1 -1
  8. package/build/esm/{chunk-b9c073ce.js → chunk-8295b31d.js} +1 -1
  9. package/build/esm/{chunk-0042305b.js → chunk-8b522635.js} +1 -1
  10. package/build/esm/{chunk-ec2cd6ff.js → chunk-91fdcc39.js} +1 -1
  11. package/build/esm/{chunk-1ffc8702.js → chunk-9d2df04f.js} +1 -1
  12. package/build/esm/{chunk-d311aed8.js → chunk-9fd54d50.js} +1 -1
  13. package/build/esm/{chunk-89b09e98.js → chunk-a2b371b3.js} +35 -33
  14. package/build/esm/{chunk-67605c5a.js → chunk-b6640bda.js} +1 -1
  15. package/build/esm/{chunk-4f993a97.js → chunk-be242238.js} +1 -1
  16. package/build/esm/{chunk-788a3d4e.js → chunk-d51c5685.js} +1 -1
  17. package/build/esm/{chunk-9462231f.js → chunk-e68eb8a3.js} +1 -1
  18. package/build/esm/{chunk-77246947.js → chunk-f0b91c22.js} +1 -1
  19. package/build/esm/{chunk-cc109f43.js → chunk-fbb15c5b.js} +1 -1
  20. package/build/esm/chunk-fbc578b8.js +1 -0
  21. package/build/esm/tvweb-sdk.esm.min.js +1 -1
  22. package/build/tvweb-sdk.cjs.min.js +438 -434
  23. package/build/tvweb-sdk.standalone.js +452 -416
  24. package/build/tvweb-sdk.standalone.min.js +438 -434
  25. package/package.json +5 -5
  26. package/build/esm/chunk-3918125a.js +0 -1
@@ -1 +1 @@
1
- import{r as e,n as t,u as a,aG as s,s as n,c as i,a9 as r,d as l,I as c,f as o,b as u,aJ as _,aK as m,F as g,L as d,W as f,M as h,D as b,au as v,k as p,aA as w,j as k}from"./chunk-27713cdc.js";import{t as y}from"./chunk-67605c5a.js";import{n as F,t as T,u as L,o as R,q as C,r as B,v as S,s as x,y as I}from"./chunk-65036591.js";import{m as M}from"./chunk-9803c4f4.js";import{u as D}from"./chunk-788a3d4e.js";let E=s.faceTracker(),P=new _,{FaceDirection:j,Errors:A,Messages:W,TrackLivenessEvents:V}=n,N={enable:!1,framesIntervalTime:180,framesBatchLength:0},U={[n.FaceDirection.UP]:{delayTime:0},[n.FaceDirection.LEFT]:{delayTime:0},[n.FaceDirection.RIGHT]:{delayTime:0},[n.FaceDirection.FRONTAL]:{delayTime:2e3}},O=()=>{},z=()=>{},K=()=>{};function q({apiCheck:_,bgCameraMask:k,bgCameraMaskRed:G,surroundStyle:Z,cropAreaDimension:J,customInstructions:H,customIcon:X,customDirectionIcon:Q,customStepTimeConstraints:Y=U,onLivenessDetectionDone:$,onError:ee,frontalMinSize:et,waitingTimeToGetBetterFrames:ea=500,captureFrameSettings:es=N,setRemainingTime:en=O,onProcessing:ei=K,customErrors:er,customMessages:el,apiCredentials:ec={},onFramesCaptured:eo=z,initFirstGestureTimeout:eu=2e3,outputEncryptionSettings:e_,cameraScale:em=1,passiveModeAuto:eg=!1,sendCustomEvent:ed,serviceSettings:ef,currentOrientation:eh,onReset:eb}={}){let[ev,ep]=e.useState(!1),[ew,ek]=e.useState(!1),[ey,eF]=e.useState(!1),[eT,eL]=e.useState(!1),eR=e.useRef(null),{lang:eC,assetRoot:eB,customUrls:eS,exifKey:ex}=i.useSDKSettings(),eI=r.useSDKLocale(),{apiClient:eM}=l.useApiClient({apiCredentials:ec}),[,eD]=e.useReducer(e=>e+1,0),eE=e.useRef(null),[eP,ej]=e.useState(!1),eA=e.useRef({}),{sendEvent:eW}=c.useSDKTracking(),[eV,eN]=e.useState(3),[eU,eO]=e.useState(!1),ez=e.useRef(!1),eK=e.useCallback(e=>{eO(e),ez.current=e},[]),eq=e.useRef(null),eG=e.useRef([]),eZ=e.useRef(null),eJ=e.useRef(),eH=e.useRef(null);null===eH.current&&(eH.current=s.initFaceVerificationData({assetRoot:eB,customInstructions:H,customIcon:X,customDirectionIcon:Q,customStepTimeConstraints:Y,Locale:eI,lang:eC}));let[eX,eQ]=e.useState(),eY=e.useCallback(e=>{eQ(e)},[]),e$=e.useMemo(()=>y(eY,500),[eY]),e0=e.useRef([]),e1=e.useRef(),e4=D(),{flowIntervalTimeMs:e2,limitTimeLivenessCheck:e3,terminateIfNoFace:e5,closeEyeDetectorSettings:e7,exifDataSettings:e6,recordVideo:e8,autoCaptureSettings:e9,manualCaptureSettings:te,blurCheckSettings:tt,webIsRequiredFrontalFace:ta,waitBeforeStartFlowMs:ts,resetFlowOnOrientationChange:tn,captureFrameSettings:ti}=function({clientSettings:s,captureFrameSettingsProp:n}){return e.useMemo(()=>{let e,i=M({},F,s),r={enable:t(i,"data.settings.sdk_settings.passive_liveness_settings.auto_capture.enable"),showCaptureButton:t(i,"data.settings.sdk_settings.passive_liveness_settings.auto_capture.show_capture_button"),showCountdown:t(i,"data.settings.sdk_settings.passive_liveness_settings.auto_capture.show_countdown"),waitForBestImageTimeMsWeb:t(i,"data.settings.sdk_settings.passive_liveness_settings.auto_capture.wait_for_best_image_time_ms_web")},l={showCountdown:t(i,"data.settings.sdk_settings.passive_liveness_settings.manual_capture.show_countdown"),waitForBestImageTimeMsWeb:t(i,"data.settings.sdk_settings.passive_liveness_settings.manual_capture.wait_for_best_image_time_ms_web")},c={enable:t(i,"data.settings.sdk_settings.passive_liveness_settings.blur_check.enable"),webBlurryThreshold:t(i,"data.settings.sdk_settings.passive_liveness_settings.blur_check.web_blurry_threshold")},o={enable:t(i,"data.settings.sdk_settings.passive_liveness_settings.close_eye_detector.enable"),webThreshold:t(i,"data.settings.sdk_settings.passive_liveness_settings.close_eye_detector.web_threshold"),webTimeout:t(i,"data.settings.sdk_settings.passive_liveness_settings.close_eye_detector.web_timeout"),forceCheck:t(i,"data.settings.sdk_settings.passive_liveness_settings.close_eye_detector.force_check")},u=t(i,"data.settings.sdk_settings.passive_liveness_settings.web_is_required_frontal_face"),_=a.getWebSetting(i,"data.settings.sdk_settings.active_liveness_settings.limit_time_liveness_check.max_retry_count"),m={enable:t(i,"data.settings.sdk_settings.active_liveness_settings.limit_time_liveness_check.enable"),limitTimeSecond:t(i,"data.settings.sdk_settings.active_liveness_settings.limit_time_liveness_check.limit_time_second"),remainTimeShow:t(i,"data.settings.sdk_settings.active_liveness_settings.limit_time_liveness_check.remain_time_show"),format:t(i,"data.settings.sdk_settings.active_liveness_settings.limit_time_liveness_check.format"),enableMaxRetries:_>0,totalMaxRetries:_,interruptible:!a.getWebSetting(i,"data.settings.sdk_settings.active_liveness_settings.limit_time_liveness_check.non_stoppable")},g={enable:t(i,"data.settings.sdk_settings.active_liveness_settings.terminate_if_no_face.enable"),maxInvalidFrame:t(i,"data.settings.sdk_settings.active_liveness_settings.terminate_if_no_face.max_invalid_frame"),maxTimeMs:t(i,"data.settings.sdk_settings.active_liveness_settings.terminate_if_no_face.max_time_ms")},d={enable:t(i,"data.settings.sdk_settings.active_liveness_settings.exif_data_settings.enable")},f={enable:t(i,"data.settings.sdk_settings.active_liveness_settings.record_video.enable")},h=t(i,"data.settings.sdk_settings.active_liveness_settings.wait_before_start_flow_ms"),b=t(i,"data.settings.sdk_settings.active_liveness_settings.reset_flow_on_orientation_change"),v=t(i,"data.settings.sdk_settings.active_liveness_settings.flow_interval_time_ms"),p=t(s,"data.settings.sdk_settings.active_liveness_settings.save_encoded_frames");return{autoCaptureSettings:r,manualCaptureSettings:l,blurCheckSettings:c,closeEyeDetectorSettings:o,webIsRequiredFrontalFace:u,limitTimeLivenessCheck:m,terminateIfNoFace:g,exifDataSettings:d,recordVideo:f,waitBeforeStartFlowMs:h,resetFlowOnOrientationChange:b,flowIntervalTimeMs:v,captureFrameSettings:e=p?{enable:p.enable,enableLogging:p.enable_logging,framesBatchLength:p.frames_batch_len,framesIntervalTime:p.frames_interval_ms}:n}},[s,n])}({clientSettings:e4,captureFrameSettingsProp:es}),tr=e9?.enable?e9?.waitForBestImageTimeMsWeb:te?.waitForBestImageTimeMsWeb,tl=e8?.enable,tc=e.useMemo(()=>o.getEnabledServices(ef,e4),[e4,ef]),to=e.useRef(""),tu=e.useCallback(e=>{if(e?.event){if(e.event===V?.show_alert){let t=e.log?.alert;if(t===to.current)return;to.current=t}eW(e),ed&&ed(e)}},[ed,eW]),t_=e.useMemo(()=>y(e=>{tu(e)},2e3),[tu]),tm=e.useRef(0),tg=e.useRef(),td=e.useRef();e.useEffect(()=>{tu({tag:"selfie",event:V?.start_camera,log:{}})},[tu]),e.useEffect(()=>(P.start(),()=>{P.stop()}),[]),e.useEffect(()=>{let e=!1;return async function t(){!eP&&(e1.current=performance.now(),eA.current=await m(eS),await g.initTensorFlow({preferredBackends:["wasm","webgl","cpu"]}),e||(ej(!0),tu({tag:"selfie",event:V?.show_warmup,log:{}}),tu({tag:"selfie",event:V?.finish_load_model,log:{status:"success",time_in_ms:performance.now()-e1.current}}),e1.current=null))}(),()=>{e=!0}},[eP,eS,tu]);let tf=e.useRef(!1),th=e.useCallback(()=>{eH.current.curStepIndex=eH.current.steps.length,tf.current=!0,eF(!1),td.current?.discardRecording(),clearInterval(eq.current)},[]),tb=e.useCallback(()=>{eH.current=s.initFaceVerificationData({assetRoot:eB,customInstructions:H,customIcon:X,customDirectionIcon:Q,Locale:eI,lang:eC}),tm.current=0,tg.current=null,e0.current=[],eL(!1),eQ(null),x(),td.current?.start(),tf.current=!1,eK(!1),eN(3),eZ.current=null,eG.current=[],eJ.current=null,"function"==typeof eb&&eb(),eD()},[eI,eB,Q,X,H,eK,eC,eb]),tv=e.useCallback(()=>{th(),setTimeout(()=>{tb()},e2)},[e2,tb,th]),tp=e.useMemo(()=>({...A,...er}),[er]),tw=e.useMemo(()=>({...W,...el}),[el]),tk=e.useCallback(()=>{let e={};Object.keys(tp.liveness_terminated_time_out?.msg).forEach(t=>{let a=T(tp.liveness_terminated_time_out?.msg[t]);e[t]=a({x:e3.limitTimeSecond})}),eQ({...tp.liveness_terminated_time_out,msg:e,duration:.95*e2}),tu({tag:"selfie",event:V?.show_alert,log:{alert:"liveness_terminated_time_out,"}}),P.stop(),en(""),th()},[tp.liveness_terminated_time_out,e2,e3.limitTimeSecond,th,tu,en]),ty=e.useCallback(({remainTime:e})=>{if(e>0&&e<=e3.remainTimeShow){let t=T(tw.REMAIN_TIME[eC]),a=e;switch(e3.format){case"mm:ss":a=e.toString().padStart(5,"00:00");break;case"ss":a=e.toString().padStart(2,"0")}en(t({x:a}))}},[eC,e3.format,e3.remainTimeShow,tw.REMAIN_TIME,en]),tF=e.useCallback(({attemptCount:e,fromBackground:t})=>{e3.enableMaxRetries&&e>=e3.totalMaxRetries&&ee(n.Errors.max_retry_reached),t&&th(),P.start(),tb()},[e3.enableMaxRetries,e3.totalMaxRetries,ee,tb,th]),{stopTimer:tT}=L({totalTime:e3.limitTimeSecond,totalDelayBetweenReset:e2/1e3,interruptible:e3.interruptible,shouldStart:ew&&e3.enable&&eP,onTimesUp:tk,onTick:ty,onReset:tF}),tL=e.useCallback(({clientWidth:e,clientHeight:t,videoAreaWidth:a,videoAreaHeight:s,lostX:n,lostY:i})=>{let r,l;u.isMobile?l=r=a:r=l=s-200;let c=Math.floor((a-r)/2)+n;eE.current={x:c,y:5+i,width:r,height:l,image:k,surroundStyle:Z},"object"==typeof J?eE.current={...eE.current,...J}:"function"==typeof J&&(eE.current={...eE.current,...J({clientWidth:e,clientHeight:t,videoAreaWidth:a,videoAreaHeight:s,lostX:n,lostY:i,isMobile:u.isMobile,width:r,height:l})}),eD(),ek(!0)},[k,Z,J]),tR=e.useCallback(()=>{eN(3),clearInterval(eq.current),eK(!0);let e=async e=>{if(e-1==0){let e;P.stop(),tT(),clearInterval(eq.current),ei(),await td.current?.stopVideoRecording(),ep(!0),d.addExifData("user_action",{start_selfie:Date.now()-1e3*P.duration("from_1st_frame"),end_selfie:Date.now()});let t=(e=e9.enable?[eZ.current]:eG.current).map(e=>f.resizeBlobImg(e.blob,400,400)),a=(await Promise.all(t)).map((t,a)=>{let s=d.parseLivenessImg({...e[a],gesture:"frontal"});return d.writeCurrentExif({imageData:{blob:t},enableExifData:e6.enable,additionalData:s})}),s=await Promise.all(a),n={};if(e_&&e_.key){let{key:e}=e_,t=s.map(t=>h.encrypt({blob:t,key:e}));n={frontalFacesEncrypted:await Promise.all(t)}}let i=[...e0.current];if(e_&&e_.key){let e=await Promise.all(i.map(e=>e?.base64));if(i=i.map((t,a)=>({...t,base64:e[a]})),ti.enable&&ti.framesBatchLength>0&&i.length%ti.framesBatchLength>0){let e=i.slice(-1*(i.length%ti.framesBatchLength));eo(e),_&&tc.enableUploadFrames&&R(e_,e,eM,i.length===ti.framesBatchLength)}}else ti.enable&&ti.framesBatchLength>0&&i.length%ti.framesBatchLength>0&&(eo(i.slice(-1*(i.length%ti.framesBatchLength)).map(({base64:e,label:t,index:a})=>({base64:e,label:t,index:a}))),_&&tc.enableUploadFrames&&R(e_,i.slice(-1*(i.length%ti.framesBatchLength)),eM));if(_&&tc.enableUploadImages){let t=e=>({label:"portrait",metadata:JSON.stringify({gesture_score:e,gesture:j.FRONTAL})}),a=e.map((e,a)=>eM.uploadImage({file:s[a],...t(e.leftRightScore)}));e_&&e_.key&&(a=e.map((e,a)=>{let s=new Blob([n.frontalFacesEncrypted[a].hex]);return eM.uploadImage({file:s,...t(e.leftRightScore)},{"X-TV-Key":e_.key})}));try{let t=await Promise.all(a),s=null;tc.enableVerifyFaceLiveness&&(s=eM.verifyFaceLiveness({images:t.map(e=>({id:e.data.image_id})),videos:[{frames:i}]}));let n=null;tc.enableVerifySanityPortrait&&(n=eM.requestVerifyPortrait({image:{id:t?.[t.length-1]?.data?.image_id}}));let[r,l]=await Promise.all([s,n]);$({apiCheckPassed:r?.data.is_live??!1,verifyFaceLivenessResult:r?.data??null,verifyFacePortraitResult:l?.data??null,frontalFaces:t.map((t,a)=>({id:t?.data?.image_id,blob:e?.[a]?.blob}))})}catch(e){ee({error:e})}}else $({frontalFaces:s,...n,capturedFrames:i,video:C()}),B()}};eq.current=setInterval(()=>{eN(t=>(e(t),t-1))},tr/3)},[eK,tr,tT,ei,e9.enable,e_,ti.enable,ti.framesBatchLength,_,tc.enableUploadImages,tc.enableUploadFrames,tc.enableVerifyFaceLiveness,tc.enableVerifySanityPortrait,e6.enable,eo,eM,$,ee]),tC=e.useRef({});e.useEffect(()=>{tC.current.isFirstValidFrameFoundRef=eT},[eT]),e.useEffect(()=>{let e,t=eR.current;async function a({faceDirection:e,canvas:t,leftRightScore:a,blurScore:s,isEyeClosed:n}){if(!0===ez.current&&(ta&&e===j.FRONTAL||!ta)){let e=await b.takePicture({canvas:t});e9?.enable&&Date.now()-eJ.current<e9?.waitForBestImageTimeMsWeb?(eZ.current||(eZ.current={blob:e,blurScore:s,isEyeClosed:n,captureTime:Date.now()}),tt?.enable&&(eZ.current=I({incomingFrame:{blob:e,blurScore:s,isEyeClosed:n,captureTime:Date.now()},currentBestFrame:eZ.current}))):eG.current.length<1&&eG.current.push({blob:e,leftRightScore:a,captureTime:Date.now(),blurScore:s})}}async function i(r,l){let c,o;if(l?.width===0||l?.height===0)return;let{isFirstValidFrameFoundRef:u}=tC.current,{cropX:m,cropY:g,cropWidth:d,cropHeight:f}=r;l.getContext("2d").drawImage(t,m,g,d,f,-((400*em-400)/2)/em,-((400*em-400)/2)/em,400,400);let{blazefaceModel:h,closeEyesModel:b}=eA.current,[y,F]=await Promise.all([v.calculateBlurScore(l),p.getModelPredictions({model:h,sCanvas:l})]),{error:T,fullFace:L,faceRatio:C,faceNotFrontalMinThreshold:B}=await s.validatePredictions({predictions:F,width:p.SIZE,height:p.SIZE});c=T,eE.current.image=k;let S=null,x=null,I=null,{curStepIndex:M,steps:D}=eH.current;if(L){I=L.landmarks;let e=await s.calculateFaceDirection({landmarks:I,getPerfectFrontal:!0});e&&(S=e.gesture,x=e.leftRightScore);let t=e7?.webTimeout+Y[n.FaceDirection.FRONTAL].delayTime/1e3;if(e7?.enable&&(-1===P.duration("limit_close_eye")||P.duration("limit_close_eye")<t)){e7?.forceCheck||-1!==P.duration("limit_close_eye")||P.start("limit_close_eye");let{isEyeClose:e}=await b.predict(l,I,e7?.webThreshold);e&&!c&&(c=A.close_eye)}}let W=c?.code==="no_face"||c?.code==="partial_face",N=M<D.length;if(!function({noFace:e,isFirstValidFrameFoundRef:t}){if(!e5.enable||!t)return;let{max_time_ms:a}=e5;tg.current&&e||(tg.current={time:Date.now(),frame:0}),e&&tg.current.frame++;let{time:s}=tg.current;e&&Date.now()-s>=a&&(eQ({...tp.liveness_terminated_no_face,duration:e2}),tu({tag:"selfie",event:V?.show_alert,log:{alert:"liveness_terminated_no_face"}}),tv())}({noFace:W&&N,isFirstValidFrameFoundRef:u}),c?.code&&t_({tag:"selfie",event:V?.show_alert,log:{alert:c.code}}),!c||"face_too_small"===c.code&&S!==j.FRONTAL&&C>=B){if(!function(e,t,a,s){if(e0.current.length&&Date.now()-e0.current[e0.current.length-1].time<ti.framesIntervalTime)return;if(ti.enable&&!0){let{topLeft:s,bottomRight:n}=e,i=[...s,...n],{score:r,time:l}=E(e,0===e0.current.length),c={label:"portrait",base64:t.toDataURL("image/jpeg",.8).split(",")[1],landmarks:a,original_landmarks:a,score:r,time:l,index:e0.current.length,bbox:i,original_bbox:i};if(e_&&e_.key){if(c.base64=w.encryptFrameBase64(c.base64,e_.key),e0.current.push(c),ti.framesBatchLength>0&&e0.current.length%ti.framesBatchLength==0&&eo){let e=e0.current.slice(-ti.framesBatchLength);Promise.all(e.map(e=>e?.base64)).then(t=>{eo(e.map(({label:e,index:a},s)=>({base64:t[s],label:e,index:a}))),_&&tc.enableUploadFrames&&R(e_,e.map(({label:e,index:a},s)=>({base64:t[s],label:e,index:a})),eM,e0.current.length===ti.framesBatchLength)})}}else e0.current.push(c),ti.framesBatchLength>0&&e0.current.length%ti.framesBatchLength==0&&eo&&(eo(e0.current.slice(-ti.framesBatchLength).map(({base64:e,label:t,index:a})=>({base64:e,label:t,index:a}))),_&&tc.enableUploadFrames&&R(e_,e0.current.slice(-ti.framesBatchLength),eM,e0.current.length===ti.framesBatchLength));return};}(F[0],l,I),S!==j.FRONTAL&&ta)o=tp.not_frontal_face,eE.current.image=G;else if(!c){u||(eL(!0),P.start("from_1st_frame"));let e=e9?.enable&&!ez.current&&0===eG.current.length;tt?.enable?null!==y&&y>tt?.webBlurryThreshold?(o=null,e&&(eJ.current=Date.now(),tR())):ez.current||(o=tp.liveness_blurry):e&&(eJ.current=Date.now(),tR());let{isEyeClose:t}=await b.predict(l,I,e7?.webThreshold);await a({faceDirection:S,canvas:l,leftRightScore:x,blurScore:y,...null!==t?{isEyeClosed:t}:{}})}}else M<D.length&&(o=tp[c.code],eE.current.image=G);e$(o),-1!==e&&(e=requestAnimationFrame(()=>i(r,l)))}async function r(){let e=b.analyzeVideoAndWindowSizes(t,eE.current),a=document.createElement("canvas");a.width=400,a.height=400;let s=a.getContext("2d");s.translate(400,0),s.scale(-1*em,+em);let{mediaRecorder:n}=tl&&t?await S({outputImagesSize:400,videoEl:t,resultAnalyzeVideoAndWindowSizes:e}):{};td.current=n,td.current&&td.current.start(),i(e,a)}return ew&&eP&&setTimeout(()=>{r()},ts??eu),()=>{cancelAnimationFrame(e),e=-1}},[eh,ts,ta,tt?.enable,tt?.webBlurryThreshold,e9?.enable,e9?.waitForBestImageTimeMsWeb,eu,ew,eC,eM,_,k,G,$,ee,et,ea,ti,ei,e3.enable,en,e$,Y,e2,tv,e5,tp,eP,tu,eo,e_,em,tR,eg,e7?.enable,e7?.webThreshold,e7?.webTimeout,e7?.forceCheck,e6.enable,ex,t_,ti.framesBatchLength,tl,tc.enableUploadFrames]),e.useEffect(()=>{eX&&(eX?.code!==tp?.liveness_terminated_time_out&&eX?.code!==tp?.liveness_terminated_no_face&&e9?.enable&&ez.current||(clearInterval(eq.current),eK(!1),eZ.current=null,eG.current=[],eJ.current=null))},[e9?.enable,eX,eK,tp]);let{curStepIndex:tB,steps:tS}=eH.current,tx=eT&&!eX&&!eg&&(!e9?.enable||e9?.showCaptureButton),tI=eU&&!tf.current&&(e9?.enable?e9?.showCountdown:te?.showCountdown);return{resetFlowOnOrientationChange:tn,countdownToTakePicture:eV,cropArea:eE,curStepIndex:tB,faceDetectionError:eX,resetFlow:tv,handleTriggerPassiveMode:tR,handleVideoPlayed:tL,refVideo:eR,refIsReseting:tf,showCountdown:eU,steps:tS,videoPlayed:ew,activeCapturing:ey,isFirstValidFrameFound:eT,warmupDone:eP,showLoading:ev,showCaptureButton:tx,shouldShowCountdown:tI}}function G({className:e="",fillColor:t=null}){return k.jsxs("svg",{className:e,width:"38px",height:"32px",viewBox:"0 0 24 21","data-testid":"camera-icon",children:[k.jsx("title",{children:"FA45C15C-1E21-4D7B-9585-07FB9F999CB8"}),k.jsx("desc",{children:"Created with sketchtool."}),k.jsx("g",{id:"Web-demo",stroke:"none",strokeWidth:"1",fill:"none",fillRule:"evenodd",children:k.jsx("g",{id:"step1",transform:"translate(-950.000000, -380.000000)",fill:t??"currentColor",fillRule:"nonzero",children:k.jsx("g",{id:"Group",transform:"translate(950.000000, 380.000000)",children:k.jsx("g",{id:"Group-2",children:k.jsx("g",{id:"camera",children:k.jsx("path",{d:"M21,3 L17,3 L15,0 L9,0 L7,3 L3,3 C1.34314575,3 0,4.34314575 0,6 L0,18 C0,19.6568542 1.34314575,21 3,21 L21,21 C22.6568542,21 24,19.6568542 24,18 L24,6 C24,4.34314575 22.6568542,3 21,3 Z M12,17 C9.23857625,17 7,14.7614237 7,12 C7,9.23857625 9.23857625,7 12,7 C14.7614237,7 17,9.23857625 17,12 C17,14.7614237 14.7614237,17 12,17 L12,17 Z",id:"Shape"})})})})})})]})}export{G as C,q as u};
1
+ import{r as e,n as t,u as a,aG as s,s as n,c as i,a9 as r,d as l,I as c,f as o,b as u,aJ as _,aK as m,F as g,L as d,W as f,M as h,D as b,au as v,k as p,aA as w,j as k}from"./chunk-66453960.js";import{t as y}from"./chunk-b6640bda.js";import{n as F,t as T,u as L,o as R,q as C,r as B,v as S,s as x,y as I}from"./chunk-5510f102.js";import{m as M}from"./chunk-4ba29034.js";import{u as D}from"./chunk-d51c5685.js";let E=s.faceTracker(),P=new _,{FaceDirection:j,Errors:A,Messages:W,TrackLivenessEvents:V}=n,N={enable:!1,framesIntervalTime:180,framesBatchLength:0},U={[n.FaceDirection.UP]:{delayTime:0},[n.FaceDirection.LEFT]:{delayTime:0},[n.FaceDirection.RIGHT]:{delayTime:0},[n.FaceDirection.FRONTAL]:{delayTime:2e3}},O=()=>{},z=()=>{},K=()=>{};function q({apiCheck:_,bgCameraMask:k,bgCameraMaskRed:G,surroundStyle:Z,cropAreaDimension:J,customInstructions:H,customIcon:X,customDirectionIcon:Q,customStepTimeConstraints:Y=U,onLivenessDetectionDone:$,onError:ee,frontalMinSize:et,waitingTimeToGetBetterFrames:ea=500,captureFrameSettings:es=N,setRemainingTime:en=O,onProcessing:ei=K,customErrors:er,customMessages:el,apiCredentials:ec={},onFramesCaptured:eo=z,initFirstGestureTimeout:eu=2e3,outputEncryptionSettings:e_,cameraScale:em=1,passiveModeAuto:eg=!1,sendCustomEvent:ed,serviceSettings:ef,currentOrientation:eh,onReset:eb}={}){let[ev,ep]=e.useState(!1),[ew,ek]=e.useState(!1),[ey,eF]=e.useState(!1),[eT,eL]=e.useState(!1),eR=e.useRef(null),{lang:eC,assetRoot:eB,customUrls:eS,exifKey:ex}=i.useSDKSettings(),eI=r.useSDKLocale(),{apiClient:eM}=l.useApiClient({apiCredentials:ec}),[,eD]=e.useReducer(e=>e+1,0),eE=e.useRef(null),[eP,ej]=e.useState(!1),eA=e.useRef({}),{sendEvent:eW}=c.useSDKTracking(),[eV,eN]=e.useState(3),[eU,eO]=e.useState(!1),ez=e.useRef(!1),eK=e.useCallback(e=>{eO(e),ez.current=e},[]),eq=e.useRef(null),eG=e.useRef([]),eZ=e.useRef(null),eJ=e.useRef(),eH=e.useRef(null);null===eH.current&&(eH.current=s.initFaceVerificationData({assetRoot:eB,customInstructions:H,customIcon:X,customDirectionIcon:Q,customStepTimeConstraints:Y,Locale:eI,lang:eC}));let[eX,eQ]=e.useState(),eY=e.useCallback(e=>{eQ(e)},[]),e$=e.useMemo(()=>y(eY,500),[eY]),e0=e.useRef([]),e1=e.useRef(),e4=D(),{flowIntervalTimeMs:e2,limitTimeLivenessCheck:e3,terminateIfNoFace:e5,closeEyeDetectorSettings:e7,exifDataSettings:e6,recordVideo:e8,autoCaptureSettings:e9,manualCaptureSettings:te,blurCheckSettings:tt,webIsRequiredFrontalFace:ta,waitBeforeStartFlowMs:ts,resetFlowOnOrientationChange:tn,captureFrameSettings:ti}=function({clientSettings:s,captureFrameSettingsProp:n}){return e.useMemo(()=>{let e,i=M({},F,s),r={enable:t(i,"data.settings.sdk_settings.passive_liveness_settings.auto_capture.enable"),showCaptureButton:t(i,"data.settings.sdk_settings.passive_liveness_settings.auto_capture.show_capture_button"),showCountdown:t(i,"data.settings.sdk_settings.passive_liveness_settings.auto_capture.show_countdown"),waitForBestImageTimeMsWeb:t(i,"data.settings.sdk_settings.passive_liveness_settings.auto_capture.wait_for_best_image_time_ms_web")},l={showCountdown:t(i,"data.settings.sdk_settings.passive_liveness_settings.manual_capture.show_countdown"),waitForBestImageTimeMsWeb:t(i,"data.settings.sdk_settings.passive_liveness_settings.manual_capture.wait_for_best_image_time_ms_web")},c={enable:t(i,"data.settings.sdk_settings.passive_liveness_settings.blur_check.enable"),webBlurryThreshold:t(i,"data.settings.sdk_settings.passive_liveness_settings.blur_check.web_blurry_threshold")},o={enable:t(i,"data.settings.sdk_settings.passive_liveness_settings.close_eye_detector.enable"),webThreshold:t(i,"data.settings.sdk_settings.passive_liveness_settings.close_eye_detector.web_threshold"),webTimeout:t(i,"data.settings.sdk_settings.passive_liveness_settings.close_eye_detector.web_timeout"),forceCheck:t(i,"data.settings.sdk_settings.passive_liveness_settings.close_eye_detector.force_check")},u=t(i,"data.settings.sdk_settings.passive_liveness_settings.web_is_required_frontal_face"),_=a.getWebSetting(i,"data.settings.sdk_settings.active_liveness_settings.limit_time_liveness_check.max_retry_count"),m={enable:t(i,"data.settings.sdk_settings.active_liveness_settings.limit_time_liveness_check.enable"),limitTimeSecond:t(i,"data.settings.sdk_settings.active_liveness_settings.limit_time_liveness_check.limit_time_second"),remainTimeShow:t(i,"data.settings.sdk_settings.active_liveness_settings.limit_time_liveness_check.remain_time_show"),format:t(i,"data.settings.sdk_settings.active_liveness_settings.limit_time_liveness_check.format"),enableMaxRetries:_>0,totalMaxRetries:_,interruptible:!a.getWebSetting(i,"data.settings.sdk_settings.active_liveness_settings.limit_time_liveness_check.non_stoppable")},g={enable:t(i,"data.settings.sdk_settings.active_liveness_settings.terminate_if_no_face.enable"),maxInvalidFrame:t(i,"data.settings.sdk_settings.active_liveness_settings.terminate_if_no_face.max_invalid_frame"),maxTimeMs:t(i,"data.settings.sdk_settings.active_liveness_settings.terminate_if_no_face.max_time_ms")},d={enable:t(i,"data.settings.sdk_settings.active_liveness_settings.exif_data_settings.enable")},f={enable:t(i,"data.settings.sdk_settings.active_liveness_settings.record_video.enable")},h=t(i,"data.settings.sdk_settings.active_liveness_settings.wait_before_start_flow_ms"),b=t(i,"data.settings.sdk_settings.active_liveness_settings.reset_flow_on_orientation_change"),v=t(i,"data.settings.sdk_settings.active_liveness_settings.flow_interval_time_ms"),p=t(s,"data.settings.sdk_settings.active_liveness_settings.save_encoded_frames");return{autoCaptureSettings:r,manualCaptureSettings:l,blurCheckSettings:c,closeEyeDetectorSettings:o,webIsRequiredFrontalFace:u,limitTimeLivenessCheck:m,terminateIfNoFace:g,exifDataSettings:d,recordVideo:f,waitBeforeStartFlowMs:h,resetFlowOnOrientationChange:b,flowIntervalTimeMs:v,captureFrameSettings:e=p?{enable:p.enable,enableLogging:p.enable_logging,framesBatchLength:p.frames_batch_len,framesIntervalTime:p.frames_interval_ms}:n}},[s,n])}({clientSettings:e4,captureFrameSettingsProp:es}),tr=e9?.enable?e9?.waitForBestImageTimeMsWeb:te?.waitForBestImageTimeMsWeb,tl=e8?.enable,tc=e.useMemo(()=>o.getEnabledServices(ef,e4),[e4,ef]),to=e.useRef(""),tu=e.useCallback(e=>{if(e?.event){if(e.event===V?.show_alert){let t=e.log?.alert;if(t===to.current)return;to.current=t}eW(e),ed&&ed(e)}},[ed,eW]),t_=e.useMemo(()=>y(e=>{tu(e)},2e3),[tu]),tm=e.useRef(0),tg=e.useRef(),td=e.useRef();e.useEffect(()=>{tu({tag:"selfie",event:V?.start_camera,log:{}})},[tu]),e.useEffect(()=>(P.start(),()=>{P.stop()}),[]),e.useEffect(()=>{let e=!1;return async function t(){!eP&&(e1.current=performance.now(),eA.current=await m(eS),await g.initTensorFlow({preferredBackends:["wasm","webgl","cpu"]}),e||(ej(!0),tu({tag:"selfie",event:V?.show_warmup,log:{}}),tu({tag:"selfie",event:V?.finish_load_model,log:{status:"success",time_in_ms:performance.now()-e1.current}}),e1.current=null))}(),()=>{e=!0}},[eP,eS,tu]);let tf=e.useRef(!1),th=e.useCallback(()=>{eH.current.curStepIndex=eH.current.steps.length,tf.current=!0,eF(!1),td.current?.discardRecording(),clearInterval(eq.current)},[]),tb=e.useCallback(()=>{eH.current=s.initFaceVerificationData({assetRoot:eB,customInstructions:H,customIcon:X,customDirectionIcon:Q,Locale:eI,lang:eC}),tm.current=0,tg.current=null,e0.current=[],eL(!1),eQ(null),x(),td.current?.start(),tf.current=!1,eK(!1),eN(3),eZ.current=null,eG.current=[],eJ.current=null,"function"==typeof eb&&eb(),eD()},[eI,eB,Q,X,H,eK,eC,eb]),tv=e.useCallback(()=>{th(),setTimeout(()=>{tb()},e2)},[e2,tb,th]),tp=e.useMemo(()=>({...A,...er}),[er]),tw=e.useMemo(()=>({...W,...el}),[el]),tk=e.useCallback(()=>{let e={};Object.keys(tp.liveness_terminated_time_out?.msg).forEach(t=>{let a=T(tp.liveness_terminated_time_out?.msg[t]);e[t]=a({x:e3.limitTimeSecond})}),eQ({...tp.liveness_terminated_time_out,msg:e,duration:.95*e2}),tu({tag:"selfie",event:V?.show_alert,log:{alert:"liveness_terminated_time_out,"}}),P.stop(),en(""),th()},[tp.liveness_terminated_time_out,e2,e3.limitTimeSecond,th,tu,en]),ty=e.useCallback(({remainTime:e})=>{if(e>0&&e<=e3.remainTimeShow){let t=T(tw.REMAIN_TIME[eC]),a=e;switch(e3.format){case"mm:ss":a=e.toString().padStart(5,"00:00");break;case"ss":a=e.toString().padStart(2,"0")}en(t({x:a}))}},[eC,e3.format,e3.remainTimeShow,tw.REMAIN_TIME,en]),tF=e.useCallback(({attemptCount:e,fromBackground:t})=>{e3.enableMaxRetries&&e>=e3.totalMaxRetries&&ee(n.Errors.max_retry_reached),t&&th(),P.start(),tb()},[e3.enableMaxRetries,e3.totalMaxRetries,ee,tb,th]),{stopTimer:tT}=L({totalTime:e3.limitTimeSecond,totalDelayBetweenReset:e2/1e3,interruptible:e3.interruptible,shouldStart:ew&&e3.enable&&eP,onTimesUp:tk,onTick:ty,onReset:tF}),tL=e.useCallback(({clientWidth:e,clientHeight:t,videoAreaWidth:a,videoAreaHeight:s,lostX:n,lostY:i})=>{let r,l;u.isMobile?l=r=a:r=l=s-200;let c=Math.floor((a-r)/2)+n;eE.current={x:c,y:5+i,width:r,height:l,image:k,surroundStyle:Z},"object"==typeof J?eE.current={...eE.current,...J}:"function"==typeof J&&(eE.current={...eE.current,...J({clientWidth:e,clientHeight:t,videoAreaWidth:a,videoAreaHeight:s,lostX:n,lostY:i,isMobile:u.isMobile,width:r,height:l})}),eD(),ek(!0)},[k,Z,J]),tR=e.useCallback(()=>{eN(3),clearInterval(eq.current),eK(!0);let e=async e=>{if(e-1==0){let e;P.stop(),tT(),clearInterval(eq.current),ei(),await td.current?.stopVideoRecording(),ep(!0),d.addExifData("user_action",{start_selfie:Date.now()-1e3*P.duration("from_1st_frame"),end_selfie:Date.now()});let t=(e=e9.enable?[eZ.current]:eG.current).map(e=>f.resizeBlobImg(e.blob,400,400)),a=(await Promise.all(t)).map((t,a)=>{let s=d.parseLivenessImg({...e[a],gesture:"frontal"});return d.writeCurrentExif({imageData:{blob:t},enableExifData:e6.enable,additionalData:s})}),s=await Promise.all(a),n={};if(e_&&e_.key){let{key:e}=e_,t=s.map(t=>h.encrypt({blob:t,key:e}));n={frontalFacesEncrypted:await Promise.all(t)}}let i=[...e0.current];if(e_&&e_.key){let e=await Promise.all(i.map(e=>e?.base64));if(i=i.map((t,a)=>({...t,base64:e[a]})),ti.enable&&ti.framesBatchLength>0&&i.length%ti.framesBatchLength>0){let e=i.slice(-1*(i.length%ti.framesBatchLength));eo(e),_&&tc.enableUploadFrames&&R(e_,e,eM,i.length===ti.framesBatchLength)}}else ti.enable&&ti.framesBatchLength>0&&i.length%ti.framesBatchLength>0&&(eo(i.slice(-1*(i.length%ti.framesBatchLength)).map(({base64:e,label:t,index:a})=>({base64:e,label:t,index:a}))),_&&tc.enableUploadFrames&&R(e_,i.slice(-1*(i.length%ti.framesBatchLength)),eM));if(_&&tc.enableUploadImages){let t=e=>({label:"portrait",metadata:JSON.stringify({gesture_score:e,gesture:j.FRONTAL})}),a=e.map((e,a)=>eM.uploadImage({file:s[a],...t(e.leftRightScore)}));e_&&e_.key&&(a=e.map((e,a)=>{let s=new Blob([n.frontalFacesEncrypted[a].hex]);return eM.uploadImage({file:s,...t(e.leftRightScore)},{"X-TV-Key":e_.key})}));try{let t=await Promise.all(a),s=null;tc.enableVerifyFaceLiveness&&(s=eM.verifyFaceLiveness({images:t.map(e=>({id:e.data.image_id})),videos:[{frames:i}]}));let n=null;tc.enableVerifySanityPortrait&&(n=eM.requestVerifyPortrait({image:{id:t?.[t.length-1]?.data?.image_id}}));let[r,l]=await Promise.all([s,n]);$({apiCheckPassed:r?.data.is_live??!1,verifyFaceLivenessResult:r?.data??null,verifyFacePortraitResult:l?.data??null,frontalFaces:t.map((t,a)=>({id:t?.data?.image_id,blob:e?.[a]?.blob}))})}catch(e){ee({error:e})}}else $({frontalFaces:s,...n,capturedFrames:i,video:C()}),B()}};eq.current=setInterval(()=>{eN(t=>(e(t),t-1))},tr/3)},[eK,tr,tT,ei,e9.enable,e_,ti.enable,ti.framesBatchLength,_,tc.enableUploadImages,tc.enableUploadFrames,tc.enableVerifyFaceLiveness,tc.enableVerifySanityPortrait,e6.enable,eo,eM,$,ee]),tC=e.useRef({});e.useEffect(()=>{tC.current.isFirstValidFrameFoundRef=eT},[eT]),e.useEffect(()=>{let e,t=eR.current;async function a({faceDirection:e,canvas:t,leftRightScore:a,blurScore:s,isEyeClosed:n}){if(!0===ez.current&&(ta&&e===j.FRONTAL||!ta)){let e=await b.takePicture({canvas:t});e9?.enable&&Date.now()-eJ.current<e9?.waitForBestImageTimeMsWeb?(eZ.current||(eZ.current={blob:e,blurScore:s,isEyeClosed:n,captureTime:Date.now()}),tt?.enable&&(eZ.current=I({incomingFrame:{blob:e,blurScore:s,isEyeClosed:n,captureTime:Date.now()},currentBestFrame:eZ.current}))):eG.current.length<1&&eG.current.push({blob:e,leftRightScore:a,captureTime:Date.now(),blurScore:s})}}async function i(r,l){let c,o;if(l?.width===0||l?.height===0)return;let{isFirstValidFrameFoundRef:u}=tC.current,{cropX:m,cropY:g,cropWidth:d,cropHeight:f}=r;l.getContext("2d").drawImage(t,m,g,d,f,-((400*em-400)/2)/em,-((400*em-400)/2)/em,400,400);let{blazefaceModel:h,closeEyesModel:b}=eA.current,[y,F]=await Promise.all([v.calculateBlurScore(l),p.getModelPredictions({model:h,sCanvas:l})]),{error:T,fullFace:L,faceRatio:C,faceNotFrontalMinThreshold:B}=await s.validatePredictions({predictions:F,width:p.SIZE,height:p.SIZE});c=T,eE.current.image=k;let S=null,x=null,I=null,{curStepIndex:M,steps:D}=eH.current;if(L){I=L.landmarks;let e=await s.calculateFaceDirection({landmarks:I,getPerfectFrontal:!0});e&&(S=e.gesture,x=e.leftRightScore);let t=e7?.webTimeout+Y[n.FaceDirection.FRONTAL].delayTime/1e3;if(e7?.enable&&(-1===P.duration("limit_close_eye")||P.duration("limit_close_eye")<t)){e7?.forceCheck||-1!==P.duration("limit_close_eye")||P.start("limit_close_eye");let{isEyeClose:e}=await b.predict(l,I,e7?.webThreshold);e&&!c&&(c=A.close_eye)}}let W=c?.code==="no_face"||c?.code==="partial_face",N=M<D.length;if(!function({noFace:e,isFirstValidFrameFoundRef:t}){if(!e5.enable||!t)return;let{max_time_ms:a}=e5;tg.current&&e||(tg.current={time:Date.now(),frame:0}),e&&tg.current.frame++;let{time:s}=tg.current;e&&Date.now()-s>=a&&(eQ({...tp.liveness_terminated_no_face,duration:e2}),tu({tag:"selfie",event:V?.show_alert,log:{alert:"liveness_terminated_no_face"}}),tv())}({noFace:W&&N,isFirstValidFrameFoundRef:u}),c?.code&&t_({tag:"selfie",event:V?.show_alert,log:{alert:c.code}}),!c||"face_too_small"===c.code&&S!==j.FRONTAL&&C>=B){if(!function(e,t,a,s){if(e0.current.length&&Date.now()-e0.current[e0.current.length-1].time<ti.framesIntervalTime)return;if(ti.enable&&!0){let{topLeft:s,bottomRight:n}=e,i=[...s,...n],{score:r,time:l}=E(e,0===e0.current.length),c={label:"portrait",base64:t.toDataURL("image/jpeg",.8).split(",")[1],landmarks:a,original_landmarks:a,score:r,time:l,index:e0.current.length,bbox:i,original_bbox:i};if(e_&&e_.key){if(c.base64=w.encryptFrameBase64(c.base64,e_.key),e0.current.push(c),ti.framesBatchLength>0&&e0.current.length%ti.framesBatchLength==0&&eo){let e=e0.current.slice(-ti.framesBatchLength);Promise.all(e.map(e=>e?.base64)).then(t=>{eo(e.map(({label:e,index:a},s)=>({base64:t[s],label:e,index:a}))),_&&tc.enableUploadFrames&&R(e_,e.map(({label:e,index:a},s)=>({base64:t[s],label:e,index:a})),eM,e0.current.length===ti.framesBatchLength)})}}else e0.current.push(c),ti.framesBatchLength>0&&e0.current.length%ti.framesBatchLength==0&&eo&&(eo(e0.current.slice(-ti.framesBatchLength).map(({base64:e,label:t,index:a})=>({base64:e,label:t,index:a}))),_&&tc.enableUploadFrames&&R(e_,e0.current.slice(-ti.framesBatchLength),eM,e0.current.length===ti.framesBatchLength));return};}(F[0],l,I),S!==j.FRONTAL&&ta)o=tp.not_frontal_face,eE.current.image=G;else if(!c){u||(eL(!0),P.start("from_1st_frame"));let e=e9?.enable&&!ez.current&&0===eG.current.length;tt?.enable?null!==y&&y>tt?.webBlurryThreshold?(o=null,e&&(eJ.current=Date.now(),tR())):ez.current||(o=tp.liveness_blurry):e&&(eJ.current=Date.now(),tR());let{isEyeClose:t}=await b.predict(l,I,e7?.webThreshold);await a({faceDirection:S,canvas:l,leftRightScore:x,blurScore:y,...null!==t?{isEyeClosed:t}:{}})}}else M<D.length&&(o=tp[c.code],eE.current.image=G);e$(o),-1!==e&&(e=requestAnimationFrame(()=>i(r,l)))}async function r(){let e=b.analyzeVideoAndWindowSizes(t,eE.current),a=document.createElement("canvas");a.width=400,a.height=400;let s=a.getContext("2d");s.translate(400,0),s.scale(-1*em,+em);let{mediaRecorder:n}=tl&&t?await S({outputImagesSize:400,videoEl:t,resultAnalyzeVideoAndWindowSizes:e}):{};td.current=n,td.current&&td.current.start(),i(e,a)}return ew&&eP&&setTimeout(()=>{r()},ts??eu),()=>{cancelAnimationFrame(e),e=-1}},[eh,ts,ta,tt?.enable,tt?.webBlurryThreshold,e9?.enable,e9?.waitForBestImageTimeMsWeb,eu,ew,eC,eM,_,k,G,$,ee,et,ea,ti,ei,e3.enable,en,e$,Y,e2,tv,e5,tp,eP,tu,eo,e_,em,tR,eg,e7?.enable,e7?.webThreshold,e7?.webTimeout,e7?.forceCheck,e6.enable,ex,t_,ti.framesBatchLength,tl,tc.enableUploadFrames]),e.useEffect(()=>{eX&&(eX?.code!==tp?.liveness_terminated_time_out&&eX?.code!==tp?.liveness_terminated_no_face&&e9?.enable&&ez.current||(clearInterval(eq.current),eK(!1),eZ.current=null,eG.current=[],eJ.current=null))},[e9?.enable,eX,eK,tp]);let{curStepIndex:tB,steps:tS}=eH.current,tx=eT&&!eX&&!eg&&(!e9?.enable||e9?.showCaptureButton),tI=eU&&!tf.current&&(e9?.enable?e9?.showCountdown:te?.showCountdown);return{resetFlowOnOrientationChange:tn,countdownToTakePicture:eV,cropArea:eE,curStepIndex:tB,faceDetectionError:eX,resetFlow:tv,handleTriggerPassiveMode:tR,handleVideoPlayed:tL,refVideo:eR,refIsReseting:tf,showCountdown:eU,steps:tS,videoPlayed:ew,activeCapturing:ey,isFirstValidFrameFound:eT,warmupDone:eP,showLoading:ev,showCaptureButton:tx,shouldShowCountdown:tI}}function G({className:e="",fillColor:t=null}){return k.jsxs("svg",{className:e,width:"38px",height:"32px",viewBox:"0 0 24 21","data-testid":"camera-icon",children:[k.jsx("title",{children:"FA45C15C-1E21-4D7B-9585-07FB9F999CB8"}),k.jsx("desc",{children:"Created with sketchtool."}),k.jsx("g",{id:"Web-demo",stroke:"none",strokeWidth:"1",fill:"none",fillRule:"evenodd",children:k.jsx("g",{id:"step1",transform:"translate(-950.000000, -380.000000)",fill:t??"currentColor",fillRule:"nonzero",children:k.jsx("g",{id:"Group",transform:"translate(950.000000, 380.000000)",children:k.jsx("g",{id:"Group-2",children:k.jsx("g",{id:"camera",children:k.jsx("path",{d:"M21,3 L17,3 L15,0 L9,0 L7,3 L3,3 C1.34314575,3 0,4.34314575 0,6 L0,18 C0,19.6568542 1.34314575,21 3,21 L21,21 C22.6568542,21 24,19.6568542 24,18 L24,6 C24,4.34314575 22.6568542,3 21,3 Z M12,17 C9.23857625,17 7,14.7614237 7,12 C7,9.23857625 9.23857625,7 12,7 C14.7614237,7 17,9.23857625 17,12 C17,14.7614237 14.7614237,17 12,17 L12,17 Z",id:"Shape"})})})})})})]})}export{G as C,q as u};
@@ -1 +1 @@
1
- let e,t;import{n as n,s as a,d as s,r as r,P as i,aa as o,j as l,f as u,c as c,u as f,p as p,g as d}from"./chunk-27713cdc.js";import{L as g,C as m,S as h,u as v}from"./chunk-788a3d4e.js";import{W as A}from"./chunk-9803c4f4.js";var C,S,b,y,F,T,E,I,x,_={exports:{}};function M(){if(C)return _.exports;C=1;var e="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof window.msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto);if(e){var t=new Uint8Array(16);_.exports=function(){return e(t),t}}else{var n=Array(16);_.exports=function(){for(var e,t=0;t<16;t++)(3&t)==0&&(e=0x100000000*Math.random()),n[t]=e>>>((3&t)<<3)&255;return n}}return _.exports}function D(){if(b)return S;b=1;for(var e=[],t=0;t<256;++t)e[t]=(t+256).toString(16).substr(1);return S=function(t,n){var a=n||0;return""+e[t[a++]]+e[t[a++]]+e[t[a++]]+e[t[a++]]+"-"+e[t[a++]]+e[t[a++]]+"-"+e[t[a++]]+e[t[a++]]+"-"+e[t[a++]]+e[t[a++]]+"-"+e[t[a++]]+e[t[a++]]+e[t[a++]]+e[t[a++]]+e[t[a++]]+e[t[a++]]}}var U=function(){if(x)return I;x=1;var e=function(){if(F)return y;F=1;var e,t,n=M(),a=D(),s=0,r=0;return y=function(i,o,l){var u=o&&l||0,c=o||[],f=(i=i||{}).node||e,p=void 0!==i.clockseq?i.clockseq:t;if(null==f||null==p){var d=n();null==f&&(f=e=[1|d[0],d[1],d[2],d[3],d[4],d[5]]),null==p&&(p=t=(d[6]<<8|d[7])&16383)}var g=void 0!==i.msecs?i.msecs:new Date().getTime(),m=void 0!==i.nsecs?i.nsecs:r+1,h=g-s+(m-r)/1e4;if(h<0&&void 0===i.clockseq&&(p=p+1&16383),(h<0||g>s)&&void 0===i.nsecs&&(m=0),m>=1e4)throw Error("uuid.v1(): Can't create more than 10M uuids/sec");s=g,r=m,t=p;var v=((0xfffffff&(g+=122192928e5))*1e4+m)%0x100000000;c[u++]=v>>>24&255,c[u++]=v>>>16&255,c[u++]=v>>>8&255,c[u++]=255&v;var A=g/0x100000000*1e4&0xfffffff;c[u++]=A>>>8&255,c[u++]=255&A,c[u++]=A>>>24&15|16,c[u++]=A>>>16&255,c[u++]=p>>>8|128,c[u++]=255&p;for(var C=0;C<6;++C)c[u+C]=f[C];return o||a(c)}}(),t=function(){if(E)return T;E=1;var e=M(),t=D();return T=function(n,a,s){var r=a&&s||0;"string"==typeof n&&(a="binary"===n?Array(16):null,n=null);var i=(n=n||{}).random||(n.rng||e)();if(i[6]=15&i[6]|64,i[8]=63&i[8]|128,a)for(var o=0;o<16;++o)a[r+o]=i[o];return a||t(i)}}();return t.v1=e,t.v4=t,I=t}();let k=e=>{let t={};return Object.entries(e).forEach(([e,n])=>{if(n){if("customerUserId"===e){t.cus_user_id=n;return}if("faces"===e){t.faces=n.map(e=>({id:e.id}));return}if("gestureFaces"===e){t.gesture_faces=n.map(e=>({gesture:e.gesture,images:e.images.map(e=>({id:e.id}))}));return}if("videos"===e){t.videos=n;return}t[e.replace(/[A-Z]/g,e=>`_${e.toLowerCase()}`)]=n}}),t},R={enableVerifySanityPortrait:!1,enableVerifyFaceLiveness:!1};function w(e){let{apiCheck:t,mode:i,authType:o,authMethod:g,apiCredentials:m,onDone:h,onError:C,onClose:S,onReset:b,captureFrameSettings:y,onFramesCaptured:F,clientSettings:T,outputEncryptionSettings:E,logCredentials:I,flowId:x,serviceSettings:_,cameraScale:M,offsetFaceY:D,frontalMinSize:w,customTheme:N,livenessDetectionComponent:j,customComponent:V,customTexts:H,extraConfig:L}=e,B=v(),G=r.useMemo(()=>{let e={..._,...R};return u.getEnabledServices(e,B)},[B,_]),{FaceAuthenticationLoading:O}=V,[P,K]=r.useState(!1),{registerFace:W,authenFace:q}=function({apiCredentials:e,authMethod:t,enabledServices:a,authType:i}){let{apiClient:o}=s.useApiClient({apiCredentials:e}),l=r.useCallback(async e=>{let n=e.frontalFaces?.map(e=>({id:e.id}))??[],s=e.steps?.map(e=>({gesture:e.name,images:[{id:e.id}]})),r=[];return{selfieType:t,faces:n,gestureFaces:s,videos:r=a.enableUploadFrames?e.uploadFramesResult??[]:e.capturedFrames??[]}},[t,a.enableUploadFrames]),u=r.useCallback(async({sdkResult:e})=>{let t=await l(e),s=U.v4();t={...t,faceType:"selfie",customerUserId:s};let r=null;if(a.enableRegisterFace){let e=k(t);"success"===n(r=await o.httpClient.post("/v1/face_auth_register",e),"data.status")&&localStorage.setItem("tv:cus-user-id",s)}return{...t,apiResult:r}},[o.httpClient,l,a.enableRegisterFace]);return{registerFace:u,authenFace:r.useCallback(async({sdkResult:e})=>{let t=await l(e),n=localStorage.getItem("tv:cus-user-id");t={...t,customerUserId:n,authType:i};let s=null;if(a.enableAuthenticateFace){let e=k(t);s=await o.httpClient.post("/v1/face_auth",e)}return{...t,apiResult:s}},[o.httpClient,i,l,a.enableAuthenticateFace])}}({apiCredentials:m,authMethod:g,enabledServices:G,authType:o}),{billingSettings:z,enableBilling:Y}=c.useSDKSettings(),Z=f.getWebSetting(B,"data.settings.sdk_settings.billing_settings.billing_config"),$=f.getWebSetting(B,"data.settings.sdk_settings.billing_settings.url"),J=p.buildBillingInput(e),{submitBilling:Q}=d({enable:Y,onError:C,billingSettings:z??{json:Z??{}},billingUrl:$}),X=r.useCallback(e=>{let t={sdkStatus:a.BillingStatus.success,result:p.buildBillingOutput(e)};Q({service:a.BillingService.faceAuth,input:J,output:t}),h&&h(e)},[J,h,Q]),ee=r.useCallback(e=>{if(a.ErrorsWithoutBilling.includes(e.code))return void C(e);let t={error:e,sdkStatus:a.BillingStatus.fail};Q({service:a.BillingService.faceAuth,input:J,output:t}),C&&C(e)},[J,C,Q]),et=r.useCallback(e=>{var t,s;let r,l,u,c=(s={...e,frontalFaces:(r=n(t=e,"frontalFaces",[]),l=n(t,"frontalFacesEncrypted",[]),r.map((e,t)=>({blob:e,encrypted:l[t]??null})))},u={},u.faces=n(s,"frontalFaces"),u.videos=Array.isArray(n(s,"capturedFrames"))&&n(s,"capturedFrames").length>0?[{frames:n(s,"capturedFrames")}]:null,u.gestureFaces=Array.isArray(n(s,"steps"))&&n(s,"steps").length>0?n(s,"steps").map(e=>{let{name:t}=e;return{gesture:t,images:[{...e?.image}]}}):null,u);i===a.FaceAuthenticationMode.REGISTRATION&&(c={...c,customerUserID:U.v4(),faceType:"selfie",selfieType:g}),i===a.FaceAuthenticationMode.AUTHENTICATION&&(c={...c,selfieType:g,authType:o}),X(c)},[i,X,g,o]),en=r.useCallback(async e=>{if(!t||!G.enableUploadImages)return void et(e);try{let t;K(!0),i===a.FaceAuthenticationMode.REGISTRATION&&(t=await W({sdkResult:e})),i===a.FaceAuthenticationMode.AUTHENTICATION&&(t=await q({sdkResult:e})),X(t)}catch(e){console.error(e),ee({...a.Errors.api_call_error,details:e})}finally{K(!1)}},[t,G.enableUploadImages,et,i,X,W,q,ee]);return l.jsxs(A,{isWrappedBy:"face_authen",children:[l.jsx(j,{mode:(e=>{switch(e){case a.FaceAuthMethod.STANDARD_AUTHEN:return a.Mode.PASSIVE;case a.FaceAuthMethod.ADVANCED_AUTHEN_ACTIVE:return a.Mode.ACTIVE;case a.FaceAuthMethod.EDGE_AUTHEN:return a.Mode.FLASH_EDGE;case a.FaceAuthMethod.ADVANCED_AUTHEN_FLASH:return a.Mode.FLASH_ADVANCED;case a.FaceAuthMethod.LIGHT_AUTHEN:return a.Mode.PASSIVE;default:return e}})(g),cameraScale:M,offsetFaceY:D,frontalMinSize:w,captureFrameSettings:y,logCredentials:I,onLivenessDetectionDone:en,outputEncryptionSettings:E,onFramesCaptured:F,onError:C,onClose:S,onReset:b,clientSettings:T,customTheme:N,extraConfig:L,customComponent:V,apiCheck:t,apiCredentials:m,serviceSettings:G,flowId:x,customTexts:H}),l.jsx(O,{loading:P})]})}w.propTypes={apiCheck:i.bool,mode:i.string,authMethod:i.string,authType:i.string,onDone:i.func,onError:i.func,onClose:i.func,outputEncryptionSettings:i.shape({}),captureFrameSettings:i.shape({enable:i.bool,framesIntervalTime:i.number,framesBatchLength:i.number}),cameraScale:i.number,offsetFaceY:i.number,frontalMinSize:i.number,apiCredentials:i.shape({accessKey:i.string,secretKey:i.string,apiUrl:i.string}),logCredentials:i.shape({}),customTheme:i.shape({}),serviceSettings:i.shape({}),flowId:i.string,clientSettings:i.shape({}),livenessDetectionComponent:i.elementType,customComponent:i.shape({FaceAuthenticationLoading:i.elementType}),extraConfig:i.shape({}),onReset:i.func,onFramesCaptured:i.func,customTexts:i.shape({})},w.defaultProps={apiCheck:!1,mode:a.FaceAuthenticationMode.REGISTRATION,authMethod:a.FaceAuthMethod.EDGE_AUTHEN,authType:"transfer",onDone:()=>{},onError:()=>{},onClose:()=>{},outputEncryptionSettings:null,captureFrameSettings:{enable:!0,framesIntervalTime:180,framesBatchLength:15},cameraScale:1,offsetFaceY:0,frontalMinSize:null,apiCredentials:{accessKey:"",secretKey:"",apiUrl:""},logCredentials:null,customTheme:null,serviceSettings:{enableUploadFrames:!0,enableUploadImages:!0,enableRegisterFace:!0,enableAuthenticateFace:!0},flowId:"face_authen",clientSettings:null,livenessDetectionComponent:g,customComponent:{FaceAuthenticationLoading:o},extraConfig:null,onReset:()=>{},onFramesCaptured:()=>{},customTexts:{}};var N=(e=w,t=function(t){let{customTexts:n}=t;return l.jsx(h,{customTexts:n,children:l.jsx(e,{...t})})},function(e){let{apiCheck:n,apiCredentials:a,serviceSettings:s,flowId:r,clientSettings:i}=e,o=n&&(s?.enableGetClientSettings??!0);return l.jsx(m,{enableGetClientSettings:o,clientSettings:i,apiCredentials:a,flowId:r,children:l.jsx(t,{...e})})});function j(e){return l.jsx(N,{...e})}j.propTypes={logCredentials:i.shape({}),clientSettings:i.shape({})},j.defaultProps={logCredentials:null,clientSettings:null};export{j as default};
1
+ let e,t;import{n as n,s as a,d as s,r as r,P as i,aa as o,j as l,f as u,c as c,u as f,p as p,g as d}from"./chunk-66453960.js";import{L as g,C as m,S as h,u as v}from"./chunk-d51c5685.js";import{W as A}from"./chunk-4ba29034.js";var C,S,b,y,F,T,E,I,x,_={exports:{}};function M(){if(C)return _.exports;C=1;var e="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof window.msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto);if(e){var t=new Uint8Array(16);_.exports=function(){return e(t),t}}else{var n=Array(16);_.exports=function(){for(var e,t=0;t<16;t++)(3&t)==0&&(e=0x100000000*Math.random()),n[t]=e>>>((3&t)<<3)&255;return n}}return _.exports}function D(){if(b)return S;b=1;for(var e=[],t=0;t<256;++t)e[t]=(t+256).toString(16).substr(1);return S=function(t,n){var a=n||0;return""+e[t[a++]]+e[t[a++]]+e[t[a++]]+e[t[a++]]+"-"+e[t[a++]]+e[t[a++]]+"-"+e[t[a++]]+e[t[a++]]+"-"+e[t[a++]]+e[t[a++]]+"-"+e[t[a++]]+e[t[a++]]+e[t[a++]]+e[t[a++]]+e[t[a++]]+e[t[a++]]}}var U=function(){if(x)return I;x=1;var e=function(){if(F)return y;F=1;var e,t,n=M(),a=D(),s=0,r=0;return y=function(i,o,l){var u=o&&l||0,c=o||[],f=(i=i||{}).node||e,p=void 0!==i.clockseq?i.clockseq:t;if(null==f||null==p){var d=n();null==f&&(f=e=[1|d[0],d[1],d[2],d[3],d[4],d[5]]),null==p&&(p=t=(d[6]<<8|d[7])&16383)}var g=void 0!==i.msecs?i.msecs:new Date().getTime(),m=void 0!==i.nsecs?i.nsecs:r+1,h=g-s+(m-r)/1e4;if(h<0&&void 0===i.clockseq&&(p=p+1&16383),(h<0||g>s)&&void 0===i.nsecs&&(m=0),m>=1e4)throw Error("uuid.v1(): Can't create more than 10M uuids/sec");s=g,r=m,t=p;var v=((0xfffffff&(g+=122192928e5))*1e4+m)%0x100000000;c[u++]=v>>>24&255,c[u++]=v>>>16&255,c[u++]=v>>>8&255,c[u++]=255&v;var A=g/0x100000000*1e4&0xfffffff;c[u++]=A>>>8&255,c[u++]=255&A,c[u++]=A>>>24&15|16,c[u++]=A>>>16&255,c[u++]=p>>>8|128,c[u++]=255&p;for(var C=0;C<6;++C)c[u+C]=f[C];return o||a(c)}}(),t=function(){if(E)return T;E=1;var e=M(),t=D();return T=function(n,a,s){var r=a&&s||0;"string"==typeof n&&(a="binary"===n?Array(16):null,n=null);var i=(n=n||{}).random||(n.rng||e)();if(i[6]=15&i[6]|64,i[8]=63&i[8]|128,a)for(var o=0;o<16;++o)a[r+o]=i[o];return a||t(i)}}();return t.v1=e,t.v4=t,I=t}();let k=e=>{let t={};return Object.entries(e).forEach(([e,n])=>{if(n){if("customerUserId"===e){t.cus_user_id=n;return}if("faces"===e){t.faces=n.map(e=>({id:e.id}));return}if("gestureFaces"===e){t.gesture_faces=n.map(e=>({gesture:e.gesture,images:e.images.map(e=>({id:e.id}))}));return}if("videos"===e){t.videos=n;return}t[e.replace(/[A-Z]/g,e=>`_${e.toLowerCase()}`)]=n}}),t},R={enableVerifySanityPortrait:!1,enableVerifyFaceLiveness:!1};function w(e){let{apiCheck:t,mode:i,authType:o,authMethod:g,apiCredentials:m,onDone:h,onError:C,onClose:S,onReset:b,captureFrameSettings:y,onFramesCaptured:F,clientSettings:T,outputEncryptionSettings:E,logCredentials:I,flowId:x,serviceSettings:_,cameraScale:M,offsetFaceY:D,frontalMinSize:w,customTheme:N,livenessDetectionComponent:j,customComponent:V,customTexts:H,extraConfig:L}=e,B=v(),G=r.useMemo(()=>{let e={..._,...R};return u.getEnabledServices(e,B)},[B,_]),{FaceAuthenticationLoading:O}=V,[P,K]=r.useState(!1),{registerFace:W,authenFace:q}=function({apiCredentials:e,authMethod:t,enabledServices:a,authType:i}){let{apiClient:o}=s.useApiClient({apiCredentials:e}),l=r.useCallback(async e=>{let n=e.frontalFaces?.map(e=>({id:e.id}))??[],s=e.steps?.map(e=>({gesture:e.name,images:[{id:e.id}]})),r=[];return{selfieType:t,faces:n,gestureFaces:s,videos:r=a.enableUploadFrames?e.uploadFramesResult??[]:e.capturedFrames??[]}},[t,a.enableUploadFrames]),u=r.useCallback(async({sdkResult:e})=>{let t=await l(e),s=U.v4();t={...t,faceType:"selfie",customerUserId:s};let r=null;if(a.enableRegisterFace){let e=k(t);"success"===n(r=await o.httpClient.post("/v1/face_auth_register",e),"data.status")&&localStorage.setItem("tv:cus-user-id",s)}return{...t,apiResult:r}},[o.httpClient,l,a.enableRegisterFace]);return{registerFace:u,authenFace:r.useCallback(async({sdkResult:e})=>{let t=await l(e),n=localStorage.getItem("tv:cus-user-id");t={...t,customerUserId:n,authType:i};let s=null;if(a.enableAuthenticateFace){let e=k(t);s=await o.httpClient.post("/v1/face_auth",e)}return{...t,apiResult:s}},[o.httpClient,i,l,a.enableAuthenticateFace])}}({apiCredentials:m,authMethod:g,enabledServices:G,authType:o}),{billingSettings:z,enableBilling:Y}=c.useSDKSettings(),Z=f.getWebSetting(B,"data.settings.sdk_settings.billing_settings.billing_config"),$=f.getWebSetting(B,"data.settings.sdk_settings.billing_settings.url"),J=p.buildBillingInput(e),{submitBilling:Q}=d({enable:Y,onError:C,billingSettings:z??{json:Z??{}},billingUrl:$}),X=r.useCallback(e=>{let t={sdkStatus:a.BillingStatus.success,result:p.buildBillingOutput(e)};Q({service:a.BillingService.faceAuth,input:J,output:t}),h&&h(e)},[J,h,Q]),ee=r.useCallback(e=>{if(a.ErrorsWithoutBilling.includes(e.code))return void C(e);let t={error:e,sdkStatus:a.BillingStatus.fail};Q({service:a.BillingService.faceAuth,input:J,output:t}),C&&C(e)},[J,C,Q]),et=r.useCallback(e=>{var t,s;let r,l,u,c=(s={...e,frontalFaces:(r=n(t=e,"frontalFaces",[]),l=n(t,"frontalFacesEncrypted",[]),r.map((e,t)=>({blob:e,encrypted:l[t]??null})))},u={},u.faces=n(s,"frontalFaces"),u.videos=Array.isArray(n(s,"capturedFrames"))&&n(s,"capturedFrames").length>0?[{frames:n(s,"capturedFrames")}]:null,u.gestureFaces=Array.isArray(n(s,"steps"))&&n(s,"steps").length>0?n(s,"steps").map(e=>{let{name:t}=e;return{gesture:t,images:[{...e?.image}]}}):null,u);i===a.FaceAuthenticationMode.REGISTRATION&&(c={...c,customerUserID:U.v4(),faceType:"selfie",selfieType:g}),i===a.FaceAuthenticationMode.AUTHENTICATION&&(c={...c,selfieType:g,authType:o}),X(c)},[i,X,g,o]),en=r.useCallback(async e=>{if(!t||!G.enableUploadImages)return void et(e);try{let t;K(!0),i===a.FaceAuthenticationMode.REGISTRATION&&(t=await W({sdkResult:e})),i===a.FaceAuthenticationMode.AUTHENTICATION&&(t=await q({sdkResult:e})),X(t)}catch(e){console.error(e),ee({...a.Errors.api_call_error,details:e})}finally{K(!1)}},[t,G.enableUploadImages,et,i,X,W,q,ee]);return l.jsxs(A,{isWrappedBy:"face_authen",children:[l.jsx(j,{mode:(e=>{switch(e){case a.FaceAuthMethod.STANDARD_AUTHEN:return a.Mode.PASSIVE;case a.FaceAuthMethod.ADVANCED_AUTHEN_ACTIVE:return a.Mode.ACTIVE;case a.FaceAuthMethod.EDGE_AUTHEN:return a.Mode.FLASH_EDGE;case a.FaceAuthMethod.ADVANCED_AUTHEN_FLASH:return a.Mode.FLASH_ADVANCED;case a.FaceAuthMethod.LIGHT_AUTHEN:return a.Mode.PASSIVE;default:return e}})(g),cameraScale:M,offsetFaceY:D,frontalMinSize:w,captureFrameSettings:y,logCredentials:I,onLivenessDetectionDone:en,outputEncryptionSettings:E,onFramesCaptured:F,onError:C,onClose:S,onReset:b,clientSettings:T,customTheme:N,extraConfig:L,customComponent:V,apiCheck:t,apiCredentials:m,serviceSettings:G,flowId:x,customTexts:H}),l.jsx(O,{loading:P})]})}w.propTypes={apiCheck:i.bool,mode:i.string,authMethod:i.string,authType:i.string,onDone:i.func,onError:i.func,onClose:i.func,outputEncryptionSettings:i.shape({}),captureFrameSettings:i.shape({enable:i.bool,framesIntervalTime:i.number,framesBatchLength:i.number}),cameraScale:i.number,offsetFaceY:i.number,frontalMinSize:i.number,apiCredentials:i.shape({accessKey:i.string,secretKey:i.string,apiUrl:i.string}),logCredentials:i.shape({}),customTheme:i.shape({}),serviceSettings:i.shape({}),flowId:i.string,clientSettings:i.shape({}),livenessDetectionComponent:i.elementType,customComponent:i.shape({FaceAuthenticationLoading:i.elementType}),extraConfig:i.shape({}),onReset:i.func,onFramesCaptured:i.func,customTexts:i.shape({})},w.defaultProps={apiCheck:!1,mode:a.FaceAuthenticationMode.REGISTRATION,authMethod:a.FaceAuthMethod.EDGE_AUTHEN,authType:"transfer",onDone:()=>{},onError:()=>{},onClose:()=>{},outputEncryptionSettings:null,captureFrameSettings:{enable:!0,framesIntervalTime:180,framesBatchLength:15},cameraScale:1,offsetFaceY:0,frontalMinSize:null,apiCredentials:{accessKey:"",secretKey:"",apiUrl:""},logCredentials:null,customTheme:null,serviceSettings:{enableUploadFrames:!0,enableUploadImages:!0,enableRegisterFace:!0,enableAuthenticateFace:!0},flowId:"face_authen",clientSettings:null,livenessDetectionComponent:g,customComponent:{FaceAuthenticationLoading:o},extraConfig:null,onReset:()=>{},onFramesCaptured:()=>{},customTexts:{}};var N=(e=w,t=function(t){let{customTexts:n}=t;return l.jsx(h,{customTexts:n,children:l.jsx(e,{...t})})},function(e){let{apiCheck:n,apiCredentials:a,serviceSettings:s,flowId:r,clientSettings:i}=e,o=n&&(s?.enableGetClientSettings??!0);return l.jsx(m,{enableGetClientSettings:o,clientSettings:i,apiCredentials:a,flowId:r,children:l.jsx(t,{...e})})});function j(e){return l.jsx(N,{...e})}j.propTypes={logCredentials:i.shape({}),clientSettings:i.shape({})},j.defaultProps={logCredentials:null,clientSettings:null};export{j as default};
@@ -1,4 +1,4 @@
1
- import{o as e,P as t,j as n,B as o,r as r,V as i,aT as a,a0 as u,e as l,c as s,z as c,b as d,n as p,aU as f}from"./chunk-27713cdc.js";let h=e.table`
1
+ import{o as e,P as t,j as n,B as o,r as r,V as i,aT as a,a0 as u,e as l,c as s,z as c,b as d,n as p,aU as f}from"./chunk-66453960.js";let h=e.table`
2
2
  width: 100%;
3
3
  height: 100%;
4
4
  td {
@@ -1 +1 @@
1
- import{x as e,y as r,Q as s,r as a,e as n,c as t,s as o,j as i,a2 as c,ay as l,n as u,P as p,b as d}from"./chunk-27713cdc.js";import{p as m,g as f,S as g,a as h,O as C,C as y,E as j,b as D,B as x,c as F,L as S}from"./chunk-65036591.js";import{u as b,C as I}from"./chunk-99078e42.js";import{M as T,O as E,W as k,C as R}from"./chunk-b9c073ce.js";import{D as L}from"./chunk-4f993a97.js";import{u as v}from"./chunk-9803c4f4.js";import"./chunk-67605c5a.js";import"./chunk-788a3d4e.js";let P=d.isMobile?{width:{ideal:640}}:null;function A(p){let{apiCheck:d,onLivenessDetectionDone:L,captureFrameSettings:A,onFramesCaptured:M,frontCamera:H,flipVideoHorizontal:O,customDirectionIcon:w,customStepTimeConstraints:U,onProcessing:V,customErrors:$,apiCredentials:_,outputEncryptionSettings:B,cameraScale:K,defaultCameraId:N,passiveModeAuto:z,offsetFaceY:G,styledComponent:Y,serviceSettings:W,onReset:Q,isLoading:q}=p,J=e(),{onErrorCallback:X,onCloseCallback:Z}=v(),ee=r.useAsset("bg_camera_mask.png"),er=r.useAsset("bg_camera_mask_red.png"),es=s("IDCapturing.loadingIcon.src","ic_loading.gif"),[ea,en]=a.useState({}),{yFaceDetectionError:et,yFaceVerificationStepsWrapper:eo}=ea,[ei,ec]=a.useState(""),[el,eu]=a.useState(),ep=a.useMemo(()=>({backgroundColor:n("Selfie.backgroundColor")({theme:J})}),[J]),ed=a.useCallback(({lostY:e,height:r,clientHeight:s})=>{let a=e+25,n=a+30;en({yFaceDetectionError:a,yFaceVerificationStepsWrapper:n+r+20});let t=Math.floor(e),o=Math.floor(s-e),i=Math.floor(n);return 0!==G&&(i+G<t||i+G+r>o)?X({code:`offsetFaceY must be in [-${i-t}, ${o-r-i}]`}):i+=G,{y:i}},[G,X]),{shouldResetFlowOnOrientationChange:em,countdownToTakePicture:ef,cropArea:eg,curStepIndex:eh,faceDetectionError:eC,resetFlow:ey,handleTriggerPassiveMode:ej,handleVideoPlayed:eD,refVideo:ex,showCountdown:eF,steps:eS,refIsReseting:eb,videoPlayed:eI,warmupDone:eT,showCaptureButton:eE,shouldShowCountdown:ek,showLoading:eR}=b({currentOrientation:el,apiCheck:d,bgCameraMask:ee,bgCameraMaskRed:er,surroundStyle:ep,onLivenessDetectionDone:L,onError:X,cropAreaDimension:ed,customDirectionIcon:w,captureFrameSettings:A,onFramesCaptured:M,setRemainingTime:ec,customStepTimeConstraints:U,onProcessing:V,customErrors:$,apiCredentials:_,outputEncryptionSettings:B,cameraScale:K,passiveModeAuto:z,serviceSettings:W,onReset:Q});a.useEffect(()=>{"string"==typeof eS[0]?.directionIcon&&Promise.all(eS.map(e=>m(e.directionIcon)))},[eS]);let{CloseCameraButton:eL}=Y,ev=f(p,J),eP=eb.current?0:eh/eS.length*100,{lang:eA}=t.useSDKSettings(),eM=a.useRef(0),eH=a.useRef({}),eO=a.useRef(o.ErrorDuration.SHORT),ew=a.useMemo(()=>{let{msg:e,duration:r=o.ErrorDuration.SHORT}=eC||{},s=e?.[eA];return Date.now()-eM.current>=eO.current&&(eM.current=Date.now(),eO.current=r,eH.current=s),eH.current},[eC,eh]),eU=a.useCallback(e=>{eu(e),em?ey():e===T.LANDSCAPE?ex.current?.pause():ex.current?.play()},[ex,ey,em]);return i.jsx(E,{onOrientationChange:eU,children:i.jsxs(c,{frontCamera:H,onVideoPlayed:eD,onClose:Z,flipHorizontal:O??H,ref:ex,videoSettings:P,onError:X,scale:K,defaultCameraId:N,closeButton:eL||i.jsx(l,{}),children:[!eT&&i.jsx(k,{}),eI?i.jsxs(i.Fragment,{children:["string"==typeof ew?i.jsx(g,{top:et-15,className:"face-detection-error",children:ew}):null,eg.current?i.jsxs(R,{x:`${eg.current.x}px`,y:`${eg.current.y}px`,width:`${eg.current.width}px`,height:`${eg.current.height}px`,surroundStyle:eg.current.surroundStyle,children:[i.jsx(h,{}),i.jsx(C,{...ev,progress:eP,showErrorRing:!!eC&&n("Selfie.progressCircle.showErrorRing")({theme:J})}),ek?i.jsx(y,{children:ef}):null,eC&&i.jsx(j,{})]}):null,ei&&i.jsx(D,{top:eo-30,children:ei}),eE?i.jsx(x,{children:i.jsx(F,{onClick:ej,disabled:eF,children:u(J,"Selfie.captureIcon.src")?i.jsx("img",{src:u(J,"Selfie.captureIcon.src"),alt:""}):i.jsx(I,{fillColor:"rgba(193, 197, 204, 1)"})})}):null]}):null,(eR||q)&&i.jsx(S,{children:i.jsx("img",{src:es,alt:""})})]})})}A.propTypes={apiCheck:p.bool,mode:p.string,onLivenessDetectionDone:p.func,onClose:p.func,onError:p.func,onReset:p.func,captureFrameSettings:p.shape({}),onFramesCaptured:p.func,frontCamera:p.bool,isLoading:p.bool,flipVideoHorizontal:p.bool,customDirectionIcon:p.shape({}),customStepTimeConstraints:p.shape({}),onProcessing:p.func,customErrors:p.shape({}),apiCredentials:p.shape({accessKey:p.string,secretKey:p.string,apiUrl:p.string}),outputEncryptionSettings:p.shape({}),cameraScale:p.number,defaultCameraId:p.string,passiveModeAuto:p.bool,offsetFaceY:p.number,styledComponent:p.shape({CloseCameraButton:p.node}),serviceSettings:p.shape({})},A.defaultProps={apiCheck:!1,mode:null,onLivenessDetectionDone:null,onClose:null,onError:()=>{},onReset:()=>{},captureFrameSettings:{enable:!1,framesIntervalTime:180,framesBatchLength:0},onFramesCaptured:()=>{},frontCamera:!0,isLoading:!1,flipVideoHorizontal:null,customDirectionIcon:{[o.FaceDirection.LEFT]:i.jsx(L,{type:o.FaceDirection.LEFT}),[o.FaceDirection.RIGHT]:i.jsx(L,{type:o.FaceDirection.RIGHT}),[o.FaceDirection.UP]:i.jsx(L,{type:o.FaceDirection.UP}),[o.FaceDirection.FRONTAL]:i.jsx(L,{type:o.FaceDirection.FRONTAL})},customStepTimeConstraints:{[o.FaceDirection.UP]:{delayTime:0},[o.FaceDirection.LEFT]:{delayTime:0},[o.FaceDirection.RIGHT]:{delayTime:0},[o.FaceDirection.FRONTAL]:{delayTime:2e3}},onProcessing:()=>{},customErrors:null,apiCredentials:{accessKey:"",secretKey:"",apiUrl:""},outputEncryptionSettings:null,cameraScale:1,defaultCameraId:void 0,passiveModeAuto:!1,offsetFaceY:0,styledComponent:{CloseCameraButton:null},serviceSettings:{enableUploadFrames:!0,enableUploadImages:!0,enableVerifySanityPortrait:!0,enableVerifySanityIDCard:!0,enableVerifyFaceLiveness:!0,enableDetectIDCardTampering:!0,enableReadIDCardInfo:!0}};export{A as default};
1
+ import{x as e,y as r,Q as s,r as a,e as n,c as t,s as o,j as i,a2 as c,ay as l,n as u,P as p,b as d}from"./chunk-66453960.js";import{p as m,g as f,S as g,a as h,O as C,C as y,E as j,b as D,B as x,c as F,L as S}from"./chunk-5510f102.js";import{u as b,C as I}from"./chunk-718c6bbe.js";import{M as T,O as E,W as k,C as R}from"./chunk-8295b31d.js";import{D as L}from"./chunk-be242238.js";import{u as v}from"./chunk-4ba29034.js";import"./chunk-b6640bda.js";import"./chunk-d51c5685.js";let P=d.isMobile?{width:{ideal:640}}:null;function A(p){let{apiCheck:d,onLivenessDetectionDone:L,captureFrameSettings:A,onFramesCaptured:M,frontCamera:H,flipVideoHorizontal:O,customDirectionIcon:w,customStepTimeConstraints:U,onProcessing:V,customErrors:$,apiCredentials:_,outputEncryptionSettings:B,cameraScale:K,defaultCameraId:N,passiveModeAuto:z,offsetFaceY:G,styledComponent:Y,serviceSettings:W,onReset:Q,isLoading:q}=p,J=e(),{onErrorCallback:X,onCloseCallback:Z}=v(),ee=r.useAsset("bg_camera_mask.png"),er=r.useAsset("bg_camera_mask_red.png"),es=s("IDCapturing.loadingIcon.src","ic_loading.gif"),[ea,en]=a.useState({}),{yFaceDetectionError:et,yFaceVerificationStepsWrapper:eo}=ea,[ei,ec]=a.useState(""),[el,eu]=a.useState(),ep=a.useMemo(()=>({backgroundColor:n("Selfie.backgroundColor")({theme:J})}),[J]),ed=a.useCallback(({lostY:e,height:r,clientHeight:s})=>{let a=e+25,n=a+30;en({yFaceDetectionError:a,yFaceVerificationStepsWrapper:n+r+20});let t=Math.floor(e),o=Math.floor(s-e),i=Math.floor(n);return 0!==G&&(i+G<t||i+G+r>o)?X({code:`offsetFaceY must be in [-${i-t}, ${o-r-i}]`}):i+=G,{y:i}},[G,X]),{shouldResetFlowOnOrientationChange:em,countdownToTakePicture:ef,cropArea:eg,curStepIndex:eh,faceDetectionError:eC,resetFlow:ey,handleTriggerPassiveMode:ej,handleVideoPlayed:eD,refVideo:ex,showCountdown:eF,steps:eS,refIsReseting:eb,videoPlayed:eI,warmupDone:eT,showCaptureButton:eE,shouldShowCountdown:ek,showLoading:eR}=b({currentOrientation:el,apiCheck:d,bgCameraMask:ee,bgCameraMaskRed:er,surroundStyle:ep,onLivenessDetectionDone:L,onError:X,cropAreaDimension:ed,customDirectionIcon:w,captureFrameSettings:A,onFramesCaptured:M,setRemainingTime:ec,customStepTimeConstraints:U,onProcessing:V,customErrors:$,apiCredentials:_,outputEncryptionSettings:B,cameraScale:K,passiveModeAuto:z,serviceSettings:W,onReset:Q});a.useEffect(()=>{"string"==typeof eS[0]?.directionIcon&&Promise.all(eS.map(e=>m(e.directionIcon)))},[eS]);let{CloseCameraButton:eL}=Y,ev=f(p,J),eP=eb.current?0:eh/eS.length*100,{lang:eA}=t.useSDKSettings(),eM=a.useRef(0),eH=a.useRef({}),eO=a.useRef(o.ErrorDuration.SHORT),ew=a.useMemo(()=>{let{msg:e,duration:r=o.ErrorDuration.SHORT}=eC||{},s=e?.[eA];return Date.now()-eM.current>=eO.current&&(eM.current=Date.now(),eO.current=r,eH.current=s),eH.current},[eC,eh]),eU=a.useCallback(e=>{eu(e),em?ey():e===T.LANDSCAPE?ex.current?.pause():ex.current?.play()},[ex,ey,em]);return i.jsx(E,{onOrientationChange:eU,children:i.jsxs(c,{frontCamera:H,onVideoPlayed:eD,onClose:Z,flipHorizontal:O??H,ref:ex,videoSettings:P,onError:X,scale:K,defaultCameraId:N,closeButton:eL||i.jsx(l,{}),children:[!eT&&i.jsx(k,{}),eI?i.jsxs(i.Fragment,{children:["string"==typeof ew?i.jsx(g,{top:et-15,className:"face-detection-error",children:ew}):null,eg.current?i.jsxs(R,{x:`${eg.current.x}px`,y:`${eg.current.y}px`,width:`${eg.current.width}px`,height:`${eg.current.height}px`,surroundStyle:eg.current.surroundStyle,children:[i.jsx(h,{}),i.jsx(C,{...ev,progress:eP,showErrorRing:!!eC&&n("Selfie.progressCircle.showErrorRing")({theme:J})}),ek?i.jsx(y,{children:ef}):null,eC&&i.jsx(j,{})]}):null,ei&&i.jsx(D,{top:eo-30,children:ei}),eE?i.jsx(x,{children:i.jsx(F,{onClick:ej,disabled:eF,children:u(J,"Selfie.captureIcon.src")?i.jsx("img",{src:u(J,"Selfie.captureIcon.src"),alt:""}):i.jsx(I,{fillColor:"rgba(193, 197, 204, 1)"})})}):null]}):null,(eR||q)&&i.jsx(S,{children:i.jsx("img",{src:es,alt:""})})]})})}A.propTypes={apiCheck:p.bool,mode:p.string,onLivenessDetectionDone:p.func,onClose:p.func,onError:p.func,onReset:p.func,captureFrameSettings:p.shape({}),onFramesCaptured:p.func,frontCamera:p.bool,isLoading:p.bool,flipVideoHorizontal:p.bool,customDirectionIcon:p.shape({}),customStepTimeConstraints:p.shape({}),onProcessing:p.func,customErrors:p.shape({}),apiCredentials:p.shape({accessKey:p.string,secretKey:p.string,apiUrl:p.string}),outputEncryptionSettings:p.shape({}),cameraScale:p.number,defaultCameraId:p.string,passiveModeAuto:p.bool,offsetFaceY:p.number,styledComponent:p.shape({CloseCameraButton:p.node}),serviceSettings:p.shape({})},A.defaultProps={apiCheck:!1,mode:null,onLivenessDetectionDone:null,onClose:null,onError:()=>{},onReset:()=>{},captureFrameSettings:{enable:!1,framesIntervalTime:180,framesBatchLength:0},onFramesCaptured:()=>{},frontCamera:!0,isLoading:!1,flipVideoHorizontal:null,customDirectionIcon:{[o.FaceDirection.LEFT]:i.jsx(L,{type:o.FaceDirection.LEFT}),[o.FaceDirection.RIGHT]:i.jsx(L,{type:o.FaceDirection.RIGHT}),[o.FaceDirection.UP]:i.jsx(L,{type:o.FaceDirection.UP}),[o.FaceDirection.FRONTAL]:i.jsx(L,{type:o.FaceDirection.FRONTAL})},customStepTimeConstraints:{[o.FaceDirection.UP]:{delayTime:0},[o.FaceDirection.LEFT]:{delayTime:0},[o.FaceDirection.RIGHT]:{delayTime:0},[o.FaceDirection.FRONTAL]:{delayTime:2e3}},onProcessing:()=>{},customErrors:null,apiCredentials:{accessKey:"",secretKey:"",apiUrl:""},outputEncryptionSettings:null,cameraScale:1,defaultCameraId:void 0,passiveModeAuto:!1,offsetFaceY:0,styledComponent:{CloseCameraButton:null},serviceSettings:{enableUploadFrames:!0,enableUploadImages:!0,enableVerifySanityPortrait:!0,enableVerifySanityIDCard:!0,enableVerifyFaceLiveness:!0,enableDetectIDCardTampering:!0,enableReadIDCardInfo:!0}};export{A as default};
@@ -1 +1 @@
1
- import{x as e,y as r,Q as s,r as t,e as n,aH as a,n as o,c as i,s as c,j as l,a2 as u,ay as m,a5 as p,U as d,P as h,b as f,aI as g}from"./chunk-27713cdc.js";import{M as x,O as j,W as y,C as C}from"./chunk-b9c073ce.js";import{u as F}from"./chunk-d311aed8.js";import{D as D}from"./chunk-4f993a97.js";import{p as S,d as b,e as v,A as T,f as I,I as k,h as E,F as _,i as V,j as L,T as R,L as w,k as H,l as P,S as A}from"./chunk-65036591.js";import{u as N}from"./chunk-9803c4f4.js";import"./chunk-3918125a.js";import"./chunk-67605c5a.js";import"./chunk-788a3d4e.js";let M=f.isMobile?{width:{ideal:640}}:null,U=({stepNumber:e,type:r,theme:s})=>{let t=g(`instruction_${r}.svg`),n=o(s,`Selfie.Active.imageHolder.${r}`);return null===n?l.jsx(l.Fragment,{}):"string"==typeof n&&""!==n?l.jsx("img",{src:n,alt:""}):"v1"===o(s,"themeVersion")?l.jsx("span",{children:e}):l.jsx("img",{src:t,alt:""})};function $(h){var g,D;let{apiCheck:$,onLivenessDetectionDone:O,captureFrameSettings:B,onFramesCaptured:K,frontCamera:z,flipVideoHorizontal:G,customDirectionIcon:W,customStepTimeConstraints:Y,onProcessing:Q,customErrors:q,apiCredentials:J,outputEncryptionSettings:X,cameraScale:Z,defaultCameraId:ee,offsetFaceY:er,isLoading:es,serviceSettings:et,onReset:en}=h,ea=e(),{onErrorCallback:eo,onCloseCallback:ei}=N(),ec=r.useAsset("bg_camera_mask.png"),el=r.useAsset("bg_camera_mask_red.png"),eu=s("IDCapturing.loadingIcon.src","ic_loading.gif"),[em,ep]=t.useState({}),{yFaceVerificationStepsWrapper:ed,yFaceDetectionError:eh,yCountdown:ef}=em,[eg,ex]=t.useState(""),[ej,ey]=t.useState(),eC=t.useMemo(()=>({backgroundColor:n("Selfie.backgroundColor")({theme:ea})}),[ea]);a(o(ea,"themeVersion"),"up_arrow.gif"),a(o(ea,"themeVersion"),"left_arrow.gif"),a(o(ea,"themeVersion"),"right_arrow.gif"),a(o(ea,"themeVersion"),"frontal_arrow.svg"),a(o(ea,"themeVersion"),"instruction_up.svg"),a(o(ea,"themeVersion"),"instruction_left.svg"),a(o(ea,"themeVersion"),"instruction_right.svg"),a(o(ea,"themeVersion"),"instruction_frontal.svg");let eF=t.useCallback(({lostY:e,height:r,clientHeight:s})=>{let t=f.isMobile?e:e+80,n=t+r+20,a=n+110;ep({yFaceDetectionError:a+30,yCountdown:a,yFaceVerificationStepsWrapper:n});let o=Math.floor(e),i=Math.floor(s-e),c=Math.floor(t);return 0!==er&&(c+er<o||c+er+r>i)?eo({code:`offsetFaceY must be in [-${c-o}, ${i-r-c}]`}):c+=er,{y:c}},[er,eo]),{shouldResetFlowOnOrientationChange:eD,cropArea:eS,curStepIndex:eb,directionIcon:ev,directionIconAnimation:eT,faceDetectionError:eI,resetFlow:ek,handleVideoPlayed:eE,instructions:e_,refVideo:eV,refIsReseting:eL,steps:eR,videoPlayed:ew,activeCapturing:eH,warmupDone:eP,showLoading:eA}=F({currentOrientation:ej,apiCheck:$,bgCameraMask:ec,bgCameraMaskRed:el,surroundStyle:eC,onLivenessDetectionDone:O,onError:eo,cropAreaDimension:eF,customDirectionIcon:W,captureFrameSettings:B,onFramesCaptured:K,setRemainingTime:ex,customStepTimeConstraints:Y,onProcessing:Q,customErrors:q,apiCredentials:J,outputEncryptionSettings:X,cameraScale:Z,serviceSettings:et,onReset:en});t.useEffect(()=>{"string"==typeof eR[0]?.directionIcon&&Promise.all(eR.map(e=>S(e.directionIcon)))},[eR]);let eN=b(h,ea),eM=eL.current?0:eb/eR.length*100,{lang:eU}=i.useSDKSettings(),e$=t.useRef(0),eO=t.useRef({}),eB=t.useRef(c.ErrorDuration.SHORT),eK=t.useMemo(()=>{let{msg:e,duration:r=c.ErrorDuration.SHORT}=eI||{},s=e?.[eU];return Date.now()-e$.current>=eB.current&&(e$.current=Date.now(),eB.current=r,eO.current=s),eO.current},[eI,eb]),ez=t.useCallback(e=>{ey(e),eD?ek():e===x.LANDSCAPE?eV.current?.pause():eV.current?.play()},[eV,ek,eD]);return l.jsx(j,{onOrientationChange:ez,children:l.jsxs(u,{frontCamera:z,onVideoPlayed:eE,onClose:ei,flipHorizontal:G??z,ref:eV,videoSettings:M,onError:eo,scale:Z,defaultCameraId:ee,closeButton:l.jsx(m,{}),children:[!eP&&l.jsx(y,{}),ew?l.jsxs(l.Fragment,{children:[eS.current?l.jsxs(C,{x:`${eS.current.x}px`,y:`${eS.current.y}px`,width:`${eS.current.width}px`,height:`${eS.current.height}px`,surroundStyle:eS.current.surroundStyle,children:[l.jsx(v,{padding:T}),l.jsx(I,{...eN,progress:eM,showErrorRing:!!eI}),l.jsx(k,{children:(g=ev,D=eT,g?"string"==typeof g?l.jsx("img",{className:D,src:g,alt:"",style:{maxWidth:"98px",maxHeight:"98px",marginBottom:"25px"}}):g:null)}),eH&&l.jsx(E,{})]}):null,e_?l.jsxs(l.Fragment,{children:[l.jsx(_,{top:ed+5,className:"instructions",children:e_}),l.jsx(V,{top:ed+40,children:eR.map((e,r)=>{let{name:s,image:{objUrl:t}}=e;return l.jsx(L,{active:eb>=r,className:"step-item",children:t?l.jsx("img",{className:"image_preview",src:t,alt:""}):l.jsx(U,{stepNumber:r+1,type:s,theme:ea})},s)})})]}):null]}):null,l.jsx(R,{y:"20px",children:l.jsx(p,{id:"flash_liveness.title"})}),(eA||es)&&l.jsx(w,{children:l.jsx("img",{src:eu,alt:""})}),eg&&l.jsxs(H,{top:ef,children:[l.jsx(d,{color:n("Selfie.countdown.color")({theme:ea})}),l.jsx(P,{children:eg})]}),"string"==typeof eK?l.jsx(A,{top:eh,className:"face-detection-error",children:eK}):null]})})}$.propTypes={apiCheck:h.bool,onLivenessDetectionDone:h.func,onClose:h.func,onError:h.func,onReset:h.func,captureFrameSettings:h.shape({}),onFramesCaptured:h.func,flipVideoHorizontal:h.bool,frontCamera:h.bool,isLoading:h.bool,customDirectionIcon:h.shape({}),customStepTimeConstraints:h.shape({}),onProcessing:h.func,customErrors:h.shape({}),apiCredentials:h.shape({accessKey:h.string,secretKey:h.string,apiUrl:h.string}),outputEncryptionSettings:h.shape({}),cameraScale:h.number,defaultCameraId:h.string,offsetFaceY:h.number,styledComponent:h.shape({CloseCameraButton:h.node}),serviceSettings:h.shape({})},$.defaultProps={apiCheck:!1,onLivenessDetectionDone:null,onClose:null,onError:()=>{},onReset:()=>{},captureFrameSettings:{enable:!1,framesIntervalTime:180,framesBatchLength:0},onFramesCaptured:()=>{},flipVideoHorizontal:null,frontCamera:!0,isLoading:!1,customDirectionIcon:{[c.FaceDirection.LEFT]:l.jsx(D,{type:c.FaceDirection.LEFT}),[c.FaceDirection.RIGHT]:l.jsx(D,{type:c.FaceDirection.RIGHT}),[c.FaceDirection.UP]:l.jsx(D,{type:c.FaceDirection.UP}),[c.FaceDirection.FRONTAL]:l.jsx(D,{type:c.FaceDirection.FRONTAL})},customStepTimeConstraints:{[c.FaceDirection.UP]:{delayTime:0},[c.FaceDirection.LEFT]:{delayTime:0},[c.FaceDirection.RIGHT]:{delayTime:0},[c.FaceDirection.FRONTAL]:{delayTime:2e3}},onProcessing:()=>{},customErrors:null,apiCredentials:{accessKey:"",secretKey:"",apiUrl:""},outputEncryptionSettings:null,cameraScale:1,defaultCameraId:void 0,offsetFaceY:0,styledComponent:{CloseCameraButton:null},serviceSettings:{enableUploadFrames:!0,enableUploadImages:!0,enableVerifySanityPortrait:!0,enableVerifySanityIDCard:!0,enableVerifyFaceLiveness:!0,enableDetectIDCardTampering:!0,enableReadIDCardInfo:!0}};export{$ as default};
1
+ import{x as e,y as r,Q as s,r as t,e as n,aH as a,n as o,c as i,s as c,j as l,a2 as u,ay as m,a5 as p,U as d,P as h,b as f,aI as g}from"./chunk-66453960.js";import{M as x,O as j,W as y,C as C}from"./chunk-8295b31d.js";import{u as F}from"./chunk-9fd54d50.js";import{D as D}from"./chunk-be242238.js";import{p as S,d as b,e as v,A as T,f as I,I as k,h as E,F as _,i as V,j as L,T as R,L as w,k as H,l as P,S as A}from"./chunk-5510f102.js";import{u as N}from"./chunk-4ba29034.js";import"./chunk-fbc578b8.js";import"./chunk-b6640bda.js";import"./chunk-d51c5685.js";let M=f.isMobile?{width:{ideal:640}}:null,U=({stepNumber:e,type:r,theme:s})=>{let t=g(`instruction_${r}.svg`),n=o(s,`Selfie.Active.imageHolder.${r}`);return null===n?l.jsx(l.Fragment,{}):"string"==typeof n&&""!==n?l.jsx("img",{src:n,alt:""}):"v1"===o(s,"themeVersion")?l.jsx("span",{children:e}):l.jsx("img",{src:t,alt:""})};function $(h){var g,D;let{apiCheck:$,onLivenessDetectionDone:O,captureFrameSettings:B,onFramesCaptured:K,frontCamera:z,flipVideoHorizontal:G,customDirectionIcon:W,customStepTimeConstraints:Y,onProcessing:Q,customErrors:q,apiCredentials:J,outputEncryptionSettings:X,cameraScale:Z,defaultCameraId:ee,offsetFaceY:er,isLoading:es,serviceSettings:et,onReset:en}=h,ea=e(),{onErrorCallback:eo,onCloseCallback:ei}=N(),ec=r.useAsset("bg_camera_mask.png"),el=r.useAsset("bg_camera_mask_red.png"),eu=s("IDCapturing.loadingIcon.src","ic_loading.gif"),[em,ep]=t.useState({}),{yFaceVerificationStepsWrapper:ed,yFaceDetectionError:eh,yCountdown:ef}=em,[eg,ex]=t.useState(""),[ej,ey]=t.useState(),eC=t.useMemo(()=>({backgroundColor:n("Selfie.backgroundColor")({theme:ea})}),[ea]);a(o(ea,"themeVersion"),"up_arrow.gif"),a(o(ea,"themeVersion"),"left_arrow.gif"),a(o(ea,"themeVersion"),"right_arrow.gif"),a(o(ea,"themeVersion"),"frontal_arrow.svg"),a(o(ea,"themeVersion"),"instruction_up.svg"),a(o(ea,"themeVersion"),"instruction_left.svg"),a(o(ea,"themeVersion"),"instruction_right.svg"),a(o(ea,"themeVersion"),"instruction_frontal.svg");let eF=t.useCallback(({lostY:e,height:r,clientHeight:s})=>{let t=f.isMobile?e:e+80,n=t+r+20,a=n+110;ep({yFaceDetectionError:a+30,yCountdown:a,yFaceVerificationStepsWrapper:n});let o=Math.floor(e),i=Math.floor(s-e),c=Math.floor(t);return 0!==er&&(c+er<o||c+er+r>i)?eo({code:`offsetFaceY must be in [-${c-o}, ${i-r-c}]`}):c+=er,{y:c}},[er,eo]),{shouldResetFlowOnOrientationChange:eD,cropArea:eS,curStepIndex:eb,directionIcon:ev,directionIconAnimation:eT,faceDetectionError:eI,resetFlow:ek,handleVideoPlayed:eE,instructions:e_,refVideo:eV,refIsReseting:eL,steps:eR,videoPlayed:ew,activeCapturing:eH,warmupDone:eP,showLoading:eA}=F({currentOrientation:ej,apiCheck:$,bgCameraMask:ec,bgCameraMaskRed:el,surroundStyle:eC,onLivenessDetectionDone:O,onError:eo,cropAreaDimension:eF,customDirectionIcon:W,captureFrameSettings:B,onFramesCaptured:K,setRemainingTime:ex,customStepTimeConstraints:Y,onProcessing:Q,customErrors:q,apiCredentials:J,outputEncryptionSettings:X,cameraScale:Z,serviceSettings:et,onReset:en});t.useEffect(()=>{"string"==typeof eR[0]?.directionIcon&&Promise.all(eR.map(e=>S(e.directionIcon)))},[eR]);let eN=b(h,ea),eM=eL.current?0:eb/eR.length*100,{lang:eU}=i.useSDKSettings(),e$=t.useRef(0),eO=t.useRef({}),eB=t.useRef(c.ErrorDuration.SHORT),eK=t.useMemo(()=>{let{msg:e,duration:r=c.ErrorDuration.SHORT}=eI||{},s=e?.[eU];return Date.now()-e$.current>=eB.current&&(e$.current=Date.now(),eB.current=r,eO.current=s),eO.current},[eI,eb]),ez=t.useCallback(e=>{ey(e),eD?ek():e===x.LANDSCAPE?eV.current?.pause():eV.current?.play()},[eV,ek,eD]);return l.jsx(j,{onOrientationChange:ez,children:l.jsxs(u,{frontCamera:z,onVideoPlayed:eE,onClose:ei,flipHorizontal:G??z,ref:eV,videoSettings:M,onError:eo,scale:Z,defaultCameraId:ee,closeButton:l.jsx(m,{}),children:[!eP&&l.jsx(y,{}),ew?l.jsxs(l.Fragment,{children:[eS.current?l.jsxs(C,{x:`${eS.current.x}px`,y:`${eS.current.y}px`,width:`${eS.current.width}px`,height:`${eS.current.height}px`,surroundStyle:eS.current.surroundStyle,children:[l.jsx(v,{padding:T}),l.jsx(I,{...eN,progress:eM,showErrorRing:!!eI}),l.jsx(k,{children:(g=ev,D=eT,g?"string"==typeof g?l.jsx("img",{className:D,src:g,alt:"",style:{maxWidth:"98px",maxHeight:"98px",marginBottom:"25px"}}):g:null)}),eH&&l.jsx(E,{})]}):null,e_?l.jsxs(l.Fragment,{children:[l.jsx(_,{top:ed+5,className:"instructions",children:e_}),l.jsx(V,{top:ed+40,children:eR.map((e,r)=>{let{name:s,image:{objUrl:t}}=e;return l.jsx(L,{active:eb>=r,className:"step-item",children:t?l.jsx("img",{className:"image_preview",src:t,alt:""}):l.jsx(U,{stepNumber:r+1,type:s,theme:ea})},s)})})]}):null]}):null,l.jsx(R,{y:"20px",children:l.jsx(p,{id:"flash_liveness.title"})}),(eA||es)&&l.jsx(w,{children:l.jsx("img",{src:eu,alt:""})}),eg&&l.jsxs(H,{top:ef,children:[l.jsx(d,{color:n("Selfie.countdown.color")({theme:ea})}),l.jsx(P,{children:eg})]}),"string"==typeof eK?l.jsx(A,{top:eh,className:"face-detection-error",children:eK}):null]})})}$.propTypes={apiCheck:h.bool,onLivenessDetectionDone:h.func,onClose:h.func,onError:h.func,onReset:h.func,captureFrameSettings:h.shape({}),onFramesCaptured:h.func,flipVideoHorizontal:h.bool,frontCamera:h.bool,isLoading:h.bool,customDirectionIcon:h.shape({}),customStepTimeConstraints:h.shape({}),onProcessing:h.func,customErrors:h.shape({}),apiCredentials:h.shape({accessKey:h.string,secretKey:h.string,apiUrl:h.string}),outputEncryptionSettings:h.shape({}),cameraScale:h.number,defaultCameraId:h.string,offsetFaceY:h.number,styledComponent:h.shape({CloseCameraButton:h.node}),serviceSettings:h.shape({})},$.defaultProps={apiCheck:!1,onLivenessDetectionDone:null,onClose:null,onError:()=>{},onReset:()=>{},captureFrameSettings:{enable:!1,framesIntervalTime:180,framesBatchLength:0},onFramesCaptured:()=>{},flipVideoHorizontal:null,frontCamera:!0,isLoading:!1,customDirectionIcon:{[c.FaceDirection.LEFT]:l.jsx(D,{type:c.FaceDirection.LEFT}),[c.FaceDirection.RIGHT]:l.jsx(D,{type:c.FaceDirection.RIGHT}),[c.FaceDirection.UP]:l.jsx(D,{type:c.FaceDirection.UP}),[c.FaceDirection.FRONTAL]:l.jsx(D,{type:c.FaceDirection.FRONTAL})},customStepTimeConstraints:{[c.FaceDirection.UP]:{delayTime:0},[c.FaceDirection.LEFT]:{delayTime:0},[c.FaceDirection.RIGHT]:{delayTime:0},[c.FaceDirection.FRONTAL]:{delayTime:2e3}},onProcessing:()=>{},customErrors:null,apiCredentials:{accessKey:"",secretKey:"",apiUrl:""},outputEncryptionSettings:null,cameraScale:1,defaultCameraId:void 0,offsetFaceY:0,styledComponent:{CloseCameraButton:null},serviceSettings:{enableUploadFrames:!0,enableUploadImages:!0,enableVerifySanityPortrait:!0,enableVerifySanityIDCard:!0,enableVerifyFaceLiveness:!0,enableDetectIDCardTampering:!0,enableReadIDCardInfo:!0}};export{$ as default};
@@ -1 +1 @@
1
- import{r as e,s as t,P as s,j as a,n as n,u as i,b as r,x as l,e as o,ao as _,ap as g,J as c,L as d,aq as f,ar as h,as as u,at as m,au as b,av as p,aw as v,ax as y,ay as S,D as k,N as C,d as F,f as x,M as E,az as w,aA as M,W as L}from"./chunk-27713cdc.js";import{d as R}from"./chunk-3918125a.js";import{t as W}from"./chunk-67605c5a.js";import{C as I,O as A}from"./chunk-b9c073ce.js";import{u as D,S as T,a as q,F as B,b as O,c as P,d as j,n as Q,l as V,e as N,s as U,f as H,R as $,g as G,h as J,i as z,j as K,W as X,k as Y,m as Z,o as ee,p as et,q as es,r as ea,A as en,O as ei}from"./chunk-77246947.js";import{m as er,u as el,a as eo}from"./chunk-9803c4f4.js";import{u as e_}from"./chunk-788a3d4e.js";let eg=e.createContext(t.Mode.FLASH_ADVANCED),ec=({flashMode:e,children:s})=>{let n=e===t.Mode.FLASH||e.startsWith("flash_")?e:t.Mode.FLASH;return a.jsx(eg.Provider,{value:n,children:s})};ec.defaultProps={flashMode:t.Mode.FLASH_ADVANCED},ec.propTypes={flashMode(e,t,s){if(!/(^flash_|^flash$)/.test(e[t]))return Error(`Invalid prop \`${t}\` of value \`${e[t]}\` supplied to \`${s}\`. \`${t}\` is either 'flash' or begins with 'flash_'. Falling back to 'flash'.`)},children:s.node.isRequired};let ed=()=>{let t=e.useContext(eg);if(void 0===t)throw Error("useFlashMode must be used within a FlashModeProvider");return t},ef=0,eh=1,eu={data:{settings:{flashing_modes:{flash:{frames_per_color:8,frames_per_color_web:8,colors:"r r rrr",colors_web:"r r rrr"}},sdk_settings:{flash_liveness_settings:{frontal_face_check:{enable:!0,up_down_bound_min:.35,up_down_bound_max:.7},capture_frame_settings:{enable:!1,frames_batch_length:10,frames_interval_time:0,frame_quality:.8,frame_scale:1,auto_capture_min_frames:0,auto_capture_min_frames_far:0,auto_capture_min_frames_close:0},not_qualified_settings:{enable_far:!1,enable_close:!1,threshold_far:.11,threshold_close:.11},close_eyes_settings:{enable:!1,timeout:5,force_check:!1},face_settings:{close_face_ratio:.82,max_far_face_ratio:.9,min_far_face_ratio:.8,mobile:{close_face_ratio:.95,max_far_face_ratio:.9,min_far_face_ratio:.85}},flash_settings:{colors_length:10,flash_color:"rgb(255, 0, 0)",secondary_flash_color:"rgba(0,0,0,0.6)",delay_between_colors:120,flash_intensity:1,frames_per_color:4,use_face_detector_when_flashing:!1,flash_frame_interval:0},liveness_settings:{enable_far_step:!0},timeout_settings:{enable:!0,total:30,countdown:10,max_retry_count:0,non_stoppable:!1},exif_data_settings:{enable:!0},mask_settings:{chin_to_mask_bottom_padding:20,large_scale:.85,mobile:{chin_to_mask_bottom_padding:20,large_scale:.9,oval_padding:{bottom:20,left:20,right:20,top:0},oval_vertical_offset:60,small_scale:.65},oval_padding:{bottom:20,left:30,right:30,top:0},oval_vertical_offset:0,small_scale:.6},image_settings:{valid_face_ratio:.6,image_quality:1,crop_center_far:!0,crop_center_close:!1,detection_to_whole_face_ratio:.8},blur_far_settings:{enable:!0,blurry_threshold:.4,wait_for_best_image_time_ms:1e3},blur_close_settings:{enable:!0,blurry_threshold:.4,wait_for_best_image_time_ms:1e3},brightness_detection_far_settings:{enable_too_bright_check:!1,enable_too_dark_check:!1,too_bright_threshold:.83,too_dark_threshold:.195},brightness_detection_close_settings:{enable_too_bright_check:!1,enable_too_dark_check:!1,too_bright_threshold:.83,too_dark_threshold:.195},output_image_settings:{image_ordering:["close","far"]},auto_gen_frame_ids:{enable:!1,max_items:50}}}}}},em=()=>{let s=e_(),a=ed();return e.useMemo(()=>{let e=er({},eu,s),l=n(e,`data.settings.flashing_modes.${t.Mode.FLASH}`),o=n(e,`data.settings.flashing_modes.${a}`,l),_={enable:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.capture_frame_settings.enable"),framesIntervalTime:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.capture_frame_settings.frames_interval_time"),framesBatchLength:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.capture_frame_settings.frames_batch_length"),frameScale:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.capture_frame_settings.frame_scale"),frameQuality:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.capture_frame_settings.frame_quality"),autoCaptureMinFramesFar:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.capture_frame_settings.auto_capture_min_frames_far"),autoCaptureMinFramesClose:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.capture_frame_settings.auto_capture_min_frames_close")},g={enableFarStep:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.liveness_settings.enable_far_step")},c={flashColor:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.flash_settings.flash_color"),secondaryFlashColor:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.flash_settings.secondary_flash_color"),colors:i.getWebSetting(o,"colors"),delayBetweenColors:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.flash_settings.delay_between_colors"),framesPerColor:i.getWebSetting(o,"frames_per_color"),flashIntensity:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.flash_settings.flash_intensity"),useFaceDetectorWhenFlashing:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.flash_settings.use_face_detector_when_flashing"),flashFrameInterval:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.flash_settings.flash_frame_interval")},d={smallScale:i.getWebSetting(e,r.isMobile?"data.settings.sdk_settings.flash_liveness_settings.mask_settings.mobile.small_scale":"data.settings.sdk_settings.flash_liveness_settings.mask_settings.small_scale"),largeScale:i.getWebSetting(e,r.isMobile?"data.settings.sdk_settings.flash_liveness_settings.mask_settings.mobile.large_scale":"data.settings.sdk_settings.flash_liveness_settings.mask_settings.large_scale"),ovalPadding:{left:i.getWebSetting(e,r.isMobile?"data.settings.sdk_settings.flash_liveness_settings.mask_settings.mobile.oval_padding.left":"data.settings.sdk_settings.flash_liveness_settings.mask_settings.oval_padding.left"),right:i.getWebSetting(e,r.isMobile?"data.settings.sdk_settings.flash_liveness_settings.mask_settings.mobile.oval_padding.right":"data.settings.sdk_settings.flash_liveness_settings.mask_settings.oval_padding.right"),top:i.getWebSetting(e,r.isMobile?"data.settings.sdk_settings.flash_liveness_settings.mask_settings.mobile.oval_padding.top":"data.settings.sdk_settings.flash_liveness_settings.mask_settings.oval_padding.top"),bottom:i.getWebSetting(e,r.isMobile?"data.settings.sdk_settings.flash_liveness_settings.mask_settings.mobile.oval_padding.bottom":"data.settings.sdk_settings.flash_liveness_settings.mask_settings.oval_padding.bottom")},ovalVerticalOffset:i.getWebSetting(e,r.isMobile?"data.settings.sdk_settings.flash_liveness_settings.mask_settings.mobile.oval_vertical_offset":"data.settings.sdk_settings.flash_liveness_settings.mask_settings.oval_vertical_offset"),chinToMaskBottomPadding:i.getWebSetting(e,r.isMobile?"data.settings.sdk_settings.flash_liveness_settings.mask_settings.mobile.chin_to_mask_bottom_padding":"data.settings.sdk_settings.flash_liveness_settings.mask_settings.chin_to_mask_bottom_padding")},f={minFarFaceRatio:i.getWebSetting(e,r.isMobile?"data.settings.sdk_settings.flash_liveness_settings.face_settings.mobile.min_far_face_ratio":"data.settings.sdk_settings.flash_liveness_settings.face_settings.min_far_face_ratio"),maxFarFaceRatio:i.getWebSetting(e,r.isMobile?"data.settings.sdk_settings.flash_liveness_settings.face_settings.mobile.max_far_face_ratio":"data.settings.sdk_settings.flash_liveness_settings.face_settings.max_far_face_ratio"),closeFaceRatio:i.getWebSetting(e,r.isMobile?"data.settings.sdk_settings.flash_liveness_settings.face_settings.mobile.close_face_ratio":"data.settings.sdk_settings.flash_liveness_settings.face_settings.close_face_ratio")},h={enable:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.close_eyes_settings.enable"),timeout:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.close_eyes_settings.timeout"),forceCheck:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.close_eyes_settings.force_check")},u={enable:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.exif_data_settings.enable")},m={imageQuality:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.image_settings.image_quality"),validFaceRatio:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.image_settings.valid_face_ratio"),enableCropCenterFar:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.image_settings.crop_center_far"),enableCropCenterClose:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.image_settings.crop_center_close"),detectionToWholeFaceRatio:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.image_settings.detection_to_whole_face_ratio")},b=i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.timeout_settings.max_retry_count"),p={enable:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.timeout_settings.enable"),total:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.timeout_settings.total"),countdown:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.timeout_settings.countdown"),enableMaxRetryCount:b>0,maxRetryCount:b,interruptible:!i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.timeout_settings.non_stoppable")},v={enable:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.blur_far_settings.enable"),threshold:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.blur_far_settings.blurry_threshold"),duration:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.blur_far_settings.wait_for_best_image_time_ms")},y={enable:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.blur_close_settings.enable"),threshold:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.blur_close_settings.blurry_threshold"),duration:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.blur_close_settings.wait_for_best_image_time_ms")},S={enable:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.not_qualified_settings.enable_far"),threshold:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.not_qualified_settings.threshold_far")},k={enable:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.not_qualified_settings.enable_close"),threshold:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.not_qualified_settings.threshold_close")},C={enableTooBrightCheck:n(e,"data.settings.sdk_settings.flash_liveness_settings.brightness_detection_far_settings.enable_too_bright_check"),enableTooDarkCheck:n(e,"data.settings.sdk_settings.flash_liveness_settings.brightness_detection_far_settings.enable_too_dark_check"),tooBrightThreshold:n(e,"data.settings.sdk_settings.flash_liveness_settings.brightness_detection_far_settings.too_bright_threshold"),tooDarkThreshold:n(e,"data.settings.sdk_settings.flash_liveness_settings.brightness_detection_far_settings.too_dark_threshold")},F={enableTooBrightCheck:n(e,"data.settings.sdk_settings.flash_liveness_settings.brightness_detection_close_settings.enable_too_bright_check"),enableTooDarkCheck:n(e,"data.settings.sdk_settings.flash_liveness_settings.brightness_detection_close_settings.enable_too_dark_check"),tooBrightThreshold:n(e,"data.settings.sdk_settings.flash_liveness_settings.brightness_detection_close_settings.too_bright_threshold"),tooDarkThreshold:n(e,"data.settings.sdk_settings.flash_liveness_settings.brightness_detection_close_settings.too_dark_threshold")},x={imageOrdering:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.output_image_settings.image_ordering"),farImageOrder:eh,closeImageOrder:ef};Array.isArray(x.imageOrdering)&&2===x.imageOrdering.length&&"far"===x.imageOrdering[0]&&"close"===x.imageOrdering[1]&&(x.farImageOrder=0,x.closeImageOrder=1);let E={enable:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.auto_gen_frame_ids.enable")&&p.enable,maxItems:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.auto_gen_frame_ids.max_items")};return{captureFrameSettings:_,livenessSettings:g,flashSettings:c,maskSettings:d,faceSettings:f,closeEyesSettings:h,exifSettings:u,imageSettings:m,timeoutSettings:p,blurCheckFarSettings:v,blurCheckCloseSettings:y,notQualifiedFarSettings:S,notQualifiedCloseSettings:k,brightnessDetectionFarSettings:C,brightnessDetectionCloseSettings:F,outputImageSettings:x,autoGenFrameIds:E,frontalFaceCheckSettings:{enable:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.frontal_face_check.enable"),upDownBoundMin:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.frontal_face_check.up_down_bound_min"),upDownBoundMax:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.frontal_face_check.up_down_bound_max")}}},[s,a])},eb=r.isMobile?{width:{ideal:640},whiteBalanceMode:"none"}:{width:{ideal:9999},whiteBalanceMode:"none"},ep=(e,t)=>""===t.faceError&&(!!e.isEyeClosed&&!t.isEyeClosed||(!!e.isEyeClosed||!t.isEyeClosed)&&(!!m.hasBetterBrightnessScore(t.brightnessScore,e.brightnessScore)||!!m.hasSameBrightnessScore(t.brightnessScore,e.brightnessScore)&&b.hasBetterBlurScore(t.blurScore,e.blurScore)));function ev(s){let{onReset:n,onFlashDone:i,frontCamera:r,styledComponent:m,onFramesCaptured:b,customComponent:F,extraConfig:x,onImageCaptured:E}=s,{onCloseCallback:w,onErrorCallback:M}=el(),L=em(),A=F?.FlashLivenessBody??p,ee=F?.FlashLivenessOverlay??v,et=F?.FlashLivenessError??y,es=F?.FlashLivenessCloseIcon??S,{maskSettings:ea,flashSettings:en,faceSettings:ei,livenessSettings:er,captureFrameSettings:e_,imageSettings:eg,timeoutSettings:ec,blurCheckFarSettings:ef,blurCheckCloseSettings:eh,exifSettings:eu,autoGenFrameIds:ev}=L;if(ea.smallScale>ea.largeScale)throw Error("smallScale must be smaller than largeScale");let ey=e.useRef(),eS=D(),ek=eo(),{framesPerColor:eC,delayBetweenColors:eF,useFaceDetectorWhenFlashing:ex,flashIntensity:eE,flashColor:ew,colors:eM,flashFrameInterval:eL,secondaryFlashColor:eR}=en,[eW,eI]=e.useState(""),eA=e.useMemo(()=>W(eI,1e3),[]),[eD,eT]=e.useState(!1),[eq,eB]=e.useState(T.LOADING),eO=l(),eP={width:o("FlashLiveness.mask.width")({theme:eO}),height:o("FlashLiveness.mask.height")({theme:eO}),strokeColor:(eq===T.FAR_FACE||eq===T.CLOSE_FACE)&&eW&&!eD?o("FlashLiveness.mask.strokeColorError")({theme:eO}):o("FlashLiveness.mask.strokeColor")({theme:eO}),strokeWidth:2*o("FlashLiveness.mask.strokeWidth")({theme:eO}),path:o("FlashLiveness.mask.path")({theme:eO}),backgroundColor:o("FlashLiveness.maskFill")({theme:eO})},ej=e.useRef(null),[eQ,eV,eN,eU]=q(),[eH,e$]=e.useState(0),[eG,eJ]=e.useState(!1),ez=e.useRef({frames:[],total:{[B.FAR_FACE]:0,[B.CLOSE_FACE]:0}}),eK=e.useRef(!1),eX=e.useRef(!1),eY=e.useRef(!1),eZ=O({compareFn:ep,duration:ef.duration,minFrames:e_.autoCaptureMinFramesFar}),e0=O({compareFn:ep,duration:eh.duration,minFrames:e_.autoCaptureMinFramesClose}),e1=ed(),[e2,e3]=e.useState(!1),{sessionId:e5,updateSessionId:e8}=P(),e9=e.useRef(_.createSingleUUID()),{onVideoPlayed:e6,cropArea:e4,isPlaying:e7}=j({}),{smallScale:te,largeScale:tt}=Q(ea,{width:eP.width,height:eP.height},{width:e4.width,height:e4.height}),ts=e.useRef(null),ta=e.useRef(null),tn=1e3*ec.total/e_.framesIntervalTime+eM.length*eC,{uuids:ti,getNextUUID:tr,reset:tl}=g({total:Math.min(ev.maxItems,Math.ceil(tn/e_.framesBatchLength))}),to=e.useCallback(e=>{let t=e[e.length-1];try{let e=JSON.parse(t.metadata);ev.enable&&(e.global_batch_id=tr()),e.global_session_id=e9.current,t.metadata=JSON.stringify(e)}catch(e){console.error("Unable to process last frame metadata",e)}},[ev.enable,tr]),{playVoice:t_}=c.useVoicePlayer(),tg=e.useMemo(()=>R(({reason:e})=>{if(eY.current=!1,ez.current.frames=[],ez.current.total[B.FAR_FACE]=0,ez.current.total[B.CLOSE_FACE]=0,eK.current=!1,eX.current=!1,ts.current=null,ta.current=null,er.enableFarStep?(e$(te),eB(T.FAR_FACE),t_("move_face_into_frame")):t_("move_face_closer"),e8(),ev.enable){let e=tl();d.addExifData("frame_batch_ids",e)}n({reason:e})},200,{leading:!0}),[er.enableFarStep,e8,ev.enable,n,te,t_,tl]),tc=V({offset:ea.ovalVerticalOffset,ovalPadding:ea.ovalPadding,largeScale:tt,maskHeight:e4.height,ovalHeight:eP.height}),{flashingColors:td,currentColor:tf,colorIndex:th,startFlashing:tu,goToNextColor:tm,colorInfoRef:tb,checkIsLastColor:tp}=(({colors:s="",onFlashDone:a,onErrorCallback:n,framesPerColor:i,flashColor:r,secondaryFlashColor:l})=>{let[o,_]=e.useState(null),g=e.useRef({colorIndex:null,frameIndex:null,colorStringIndex:null}),c=e.useMemo(()=>s.split("").reduce((e,t)=>e+t.repeat(i),""),[s,i]),d=" "===c[o]?l:r,f=e.useCallback(()=>g.current.colorStringIndex===c.length-1,[c.length]),h=e.useCallback(()=>{if(g.current.colorIndex+=Math.floor((g.current.frameIndex+1)/i),g.current.frameIndex=(g.current.frameIndex+1)%i,g.current.colorStringIndex+=1,!(g.current.colorStringIndex>c.length)){if(g.current.colorStringIndex<c.length)return void _(e=>e+1);_(null),g.current={colorIndex:null,frameIndex:null,colorStringIndex:null},"function"==typeof a&&a()}},[c.length,i,a]),u=e.useCallback(()=>{_(0),g.current={colorIndex:0,frameIndex:0,colorStringIndex:0}},[]);return e.useEffect(()=>{0===c.length&&"function"==typeof n&&n(t.Errors.flashing_color_error)},[c.length,n]),{flashingColors:c,colorIndex:o,currentColor:d,goToNextColor:h,startFlashing:u,colorInfoRef:g,checkIsLastColor:f}})({colors:eM,onFlashDone:e.useCallback(async()=>{eB(T.STOP_DECTECTING),eS("selfie_flash","user_activity.finish_flash"),eS("selfie_flash","user_activity",({lastTimeLog:e})=>({flash_liveness_in_ms:e-ey.current}));let{frames:e}=ez.current;if(e_.enable&&e_.framesBatchLength>0){let t=e.length%e_.framesBatchLength;if(0!==t){let s=e.slice(-1*t);to(s),"function"==typeof b&&b(s)}}try{"function"==typeof i&&await i({frames:ez.current.frames})}catch(e){M({error:e})}},[eS,e_.enable,e_.framesBatchLength,to,b,i,M]),onErrorCallback:M,framesPerColor:eC,flashColor:ew,secondaryFlashColor:eR}),tv=e.useCallback(()=>{!er.enableFarStep||(0===ez.current.total[B.FAR_FACE]&&(eY.current=!0),e_.enable&&(ez.current.total[B.FAR_FACE]+=1))},[e_.enable,er.enableFarStep]),ty=e.useMemo(()=>({x:Math.max(eV?.left,0),y:Math.max(eV?.top,0),width:Math.min(eV?.right-eV?.left,e4.width),height:Math.min(eV?.bottom-eV?.top,e4.height)}),[e4.height,e4.width,eV?.bottom,eV?.left,eV?.right,eV?.top]),tS=e.useCallback(({frame:e,prediction:t,originalRatio:s})=>{if(eK.current)return;let a=e=>{let t=Y({maskBoundingBox:ty,faceRatio:e.faceRatio,validFaceRatio:eg.validFaceRatio,video:ej.current,shouldCropCenterSquare:eg.enableCropCenterFar,cropArea:e4,frame:e.snapshot,facePrediction:e.facePrediction,detectionToWholeFaceRatio:eg.detectionToWholeFaceRatio}),s={blob:k.takePicture({canvas:t,quality:eg.imageQuality}),gesture:"frontal",captureTime:e.captureTime,selfieLabel:B.FAR_FACE,qualifyScore:e.qualifyScore,blurScore:e.blurScore,brightnessScore:e.brightnessScore,realQualifyScore:e.realQualifyScore,qualifyModelMessage:e.qualifyModelMessage};eK.current=!0,d.addExifData("flash_liveness.number_of_frames.far_frames",ez.current.total[B.FAR_FACE]),d.addExifData("model_score.face_blurry_score",s.blurScore),d.addExifData("model_score.face_brightness_score",s.brightnessScore),d.addExifData("model_score.face_qualify_score",s.qualifyScore),d.addExifData("debug_log.face_real_qualify_score",s.realQualifyScore),d.addExifData("debug_log.face_qualify_model_message",s.qualifyModelMessage),d.addExifData("selfie_label",s.selfieLabel),d.addExifData("capture_time",s.captureTime),d.addExifData("type",s.gesture),E(s),eI(""),e$(tt),eU(!0),eB(T.CLOSE_FACE),t_("move_face_closer")},n={qualifyScore:e.qualifyScore,blurScore:e.blurScore,isEyeClosed:e.isEyeClosed,faceRatio:e.faceRatio,snapshot:N(ej.current),captureTime:Date.now(),facePrediction:U(t,s),brightnessScore:e.brightnessScore,faceError:e.faceError,realQualifyScore:e.realQualifyScore,qualifyModelMessage:e.qualifyModelMessage};if(!ef.enable)return void a(n);if(!eZ.isAutoCapturing()){eT(!0),eZ.startCapturing({onDone:e=>{eT(!1),a(e)},initialFrame:n});return}eZ.captureFrame(n)},[ef.enable,eZ,ty,eg.validFaceRatio,eg.enableCropCenterFar,eg.detectionToWholeFaceRatio,eg.imageQuality,e4,E,tt,eU,t_]),tk=e.useCallback(({frame:e,prediction:t,originalRatio:s})=>{if(eX.current)return;let a=e=>{let t=Y({maskBoundingBox:ty,faceRatio:e.faceRatio,validFaceRatio:eg.validFaceRatio,video:ej.current,shouldCropCenterSquare:eg.enableCropCenterClose,cropArea:e4,frame:e.snapshot,facePrediction:e.facePrediction,detectionToWholeFaceRatio:eg.detectionToWholeFaceRatio}),s={blob:k.takePicture({canvas:t,quality:eg.imageQuality}),gesture:"frontal",captureTime:e.captureTime,selfieLabel:B.CLOSE_FACE,qualifyScore:e.qualifyScore,blurScore:e.blurScore,brightnessScore:e.brightnessScore,realQualifyScore:e.realQualifyScore,qualifyModelMessage:e.qualifyModelMessage};eX.current=!0,d.addExifData("flash_liveness.number_of_frames.close_frames",ez.current.total[B.CLOSE_FACE]),d.addExifData("model_score.face_blurry_score",s.blurScore),d.addExifData("model_score.face_brightness_score",s.brightnessScore),d.addExifData("model_score.face_qualify_score",s.qualifyScore),d.addExifData("debug_log.face_real_qualify_score",s.realQualifyScore),d.addExifData("debug_log.face_qualify_model_message",s.qualifyModelMessage),d.addExifData("selfie_label",s.selfieLabel),d.addExifData("capture_time",s.captureTime),d.addExifData("type",s.gesture),E(s),eI(""),eJ(!1),eB(T.START_FLASHING),tu()},n={qualifyScore:e.qualifyScore,blurScore:e.blurScore,isEyeClosed:e.isEyeClosed,faceRatio:e.faceRatio,snapshot:N(ej.current),captureTime:Date.now(),facePrediction:U(t,s),brightnessScore:e.brightnessScore,faceError:e.faceError,realQualifyScore:e.realQualifyScore,qualifyModelMessage:e.qualifyModelMessage};if(!eh.enable)return void a(n);if(!e0.isAutoCapturing()){t_("please_hold_still"),eT(!0),e0.startCapturing({onDone:e=>{eT(!1),a(e)},initialFrame:n});return}e0.captureFrame(n)},[eh.enable,e0,ty,eg.validFaceRatio,eg.enableCropCenterClose,eg.detectionToWholeFaceRatio,eg.imageQuality,e4,E,tu,t_]),tC=e.useMemo(()=>{if("number"==typeof th&&th%eC==0){let e=td[th-1];return e===td[th]?eL:Math.max(eF,eL)}return eL},[th,eF,eL,td,eC]),tF=null!==th&&eq===T.START_FLASHING,tx=e.useRef(!1),tE=e.useCallback(({prediction:e,canvas:t})=>{if(!tF||tx.current||null===tb.current.colorIndex||null===tb.current.frameIndex)return;if(!e_.enable)return void tm();let s=performance.now();if(null!==ta.current&&s-ta.current<tC)return;ta.current=s;let{frames:a}=ez.current,n=H({prediction:e,canvas:t,index:a.length,quality:e_.frameQuality}),i={color:tf,type:B.FLASHING,time:Math.round(performance.now()),colorIndex:tb.current.colorIndex,frameIndex:tb.current.frameIndex,colorStringIndex:tb.current.colorStringIndex,pattern:eM,session_id:e5},r=tp();if(r&&eu.enable&&(d.addExifData("flash_liveness.flash_liveness_in_ms",Math.round(performance.now()-ey.current)),i.exif=d.getCurrentExif()),n.metadata=JSON.stringify(i),a.push(n),e_.framesBatchLength>0&&a.length%e_.framesBatchLength==0){let e=a.slice(-1*e_.framesBatchLength);to(e),"function"==typeof b&&b(e)}r&&(tx.current=!0),tm()},[tF,e_.enable,e_.frameQuality,e_.framesBatchLength,tC,tf,tb,eM,e5,tp,eu.enable,tm,to,b]),tw=e.useCallback(({error:e})=>{eA(e),("no_face"===e||"multiple_faces"===e)&&"no_face"===e&&eY.current&&!eD&&tg({reason:$.no_face})},[eD,tg,eA]),{warmupDone:tM}=G({onError:M,isVideoPlaying:e7,step:eq,cropArea:e4,videoRef:ej,onFarFaceDetected:tv,onFarFullFaceDetected:tS,onCloseFaceDetected:e.useCallback(({prediction:e,canvas:t})=>{let{frames:s}=ez.current;if(er.enableFarStep||0!==s.length||(eY.current=!0),!e_.enable)return;let a=performance.now();if(null!==ta.current&&a-ta.current<e_.framesIntervalTime)return;ta.current=a;let n=H({prediction:e,canvas:t,index:s.length,quality:e_.frameQuality});if(n.metadata=JSON.stringify({color:"",type:B.CLOSE_FACE,time:Math.round(performance.now()),colorIndex:tb.current.colorIndex,pattern:eM,session_id:e5}),ez.current.total[B.CLOSE_FACE]+=1,s.push(n),e_.framesBatchLength>0&&s.length%e_.framesBatchLength==0){let e=s.slice(-1*e_.framesBatchLength);to(e),"function"==typeof b&&b(e)}},[er.enableFarStep,e_.enable,e_.framesIntervalTime,e_.frameQuality,e_.framesBatchLength,tb,eM,e5,to,b]),onCloseFullFaceDetected:tk,onFlashingFramesCaptured:tE,useFaceDetectorWhenFlashing:ex,onFaceError:tw,maskBoundingRect:eV,shouldPauseFaceDetection:eN||e2,faceDetectionSettings:L,shouldContinueOnError:eD,debug:ek});J(ej.current);z(()=>{!async function(){let{resourceReport:e,measureReport:t}=await C.reportAll();Object.values(e).forEach(e=>{eS("selfie_flash","sdk.download_model",e)}),Object.values(t).forEach(e=>{eS("selfie_flash","sdk.init_model",e)})}()},tM),z(()=>{er.enableFarStep?(t_("move_face_into_frame"),eB(T.FAR_FACE),e$(te)):(t_("move_face_closer"),eB(T.CLOSE_FACE),e$(tt)),eJ(!0),d.addExifData("selfie_type",e1),d.addExifData("flash_liveness",{flash_settings:{delay_between_colors:en.delayBetweenColors,flash_color:en.flashColor,secondary_flash_color:en.secondaryFlashColor},face_settings:{close_face_ratio:ei.closeFaceRatio,max_far_face_ratio:ei.maxFarFaceRatio,min_far_face_ratio:ei.minFarFaceRatio},mask_settings:{oval_vertical_offset:ea.ovalVerticalOffset,small_scale:ea.smallScale,large_scale:ea.largeScale},image_settings:{valid_face_ratio:eg.validFaceRatio}}),d.addExifData("global_session_id",e9.current),d.addExifData("pattern",eM),ev.enable&&d.addExifData("frame_batch_ids",ti),ey.current||(ey.current=performance.now())},tM&&e7),z(()=>eS("selfie_flash","user_activity.start"),!0),z(()=>eS("selfie_flash","user_activity.start_far"),eq===T.FAR_FACE),z(()=>eS("selfie_flash","user_activity.start_close"),eq===T.CLOSE_FACE),z(()=>eS("selfie_flash","user_activity.start_flash"),eq===T.START_FLASHING);let tL=null===th?0:Math.min(Math.round((th+1)/(eM.length*eC)*100),100),{Loading:tR}=m,tW=e.useCallback(()=>{eT(!1),eZ.stopCapturing(),e0.stopCapturing(),e3(!0)},[e0,eZ]),tI=e.useCallback(()=>{e3(!1),tg({reason:$.timeout})},[tg]),{remaining:tA}=K({shouldStart:eG&&ec.enable,onTimeout:tW,onDelayEnd:tI,onError:M,totalTime:ec.total,totalDelay:3,maxRetriesSettings:{enable:ec.enableMaxRetryCount,total:ec.maxRetryCount},interruptible:ec.interruptible}),tD=Z(eW),tT=e4.y+e4.height/2+tc;return a.jsxs(a.Fragment,{children:[a.jsx(f,{frontCamera:r,onVideoPlayed:e6,onClose:w,flipHorizontal:r,ref:ej,onError:M,videoSettings:eb,closeButton:a.jsx(es,{}),children:a.jsxs(X,{overlay:!tM||!e7,loadingComponent:tR,children:[""!==eW&&a.jsx(h,{}),a.jsx(I,{x:`${Math.round(e4.x)}px`,y:`${Math.round(e4.y)}px`,width:`${e4.width}px`,height:`${e4.height}px`,surroundStyle:{background:o("FlashLiveness.maskFill")({theme:eO})},children:a.jsx(u,{ref:eQ,scale:eH,debug:ek,width:e4.width,height:e4.height,padding:ea.ovalPadding,verticalOffset:tc,mask:eP})}),!eD&&""!==tD&&"start_flashing"!==eq&&a.jsx(et,{errorY:tT,errorMessage:tD})]})}),a.jsx(A,{step:eq,currentProgress:tL,errorCode:eW,timeoutProps:{remaining:tA,warningThreshold:ec.countdown,total:ec.total,shouldStart:eG&&ec.enable},isFlashingColor:tf===ew,isAutoCapturing:eD,extraConfig:x}),a.jsx(ee,{step:eq,currentColor:tf,flashIntensity:eE,flashColor:ew,secondaryFlashColor:eR})]})}let ey=s=>{let{apiCheck:n,onLivenessDetectionDone:i,frontalMinSize:r,serviceSettings:l,apiCredentials:o,..._}=s,g=_.customComponent?.FlashLivenessLoading??w,[c,f]=e.useState(!1),h=ee(),u=ed(),m=e_(),b=x.getEnabledServices(l,m),{verifyFlashLiveness:p,uploadImage:v}=function({outputEncryptionSettings:t,selfieType:s,enabledServices:a,apiCredentials:n}){let{apiClient:i}=F.useApiClient({apiCredentials:n}),r=e.useCallback(async e=>{if(!t.enable)return i.uploadImage({label:"portrait",file:e.blob,metadata:JSON.stringify({label:e.selfieLabel})});let s=new Blob([e.encrypted.hex]);return i.uploadImage({file:s,label:"portrait",metadata:JSON.stringify({label:e.selfieLabel})},{"X-TV-Key":t.key})},[i,t.enable,t.key]);return{verifyFlashLiveness:e.useCallback(async({videos:e,uploadedImages:t,metadata:n})=>{try{let r=null;a.enableVerifyFaceLiveness&&(r=i.verifyFaceLiveness({images:t.map(e=>({id:e?.data?.image_id,label:"portrait"})),videos:e,metadata:n,selfie_type:s}));let l=null;a.enableVerifySanityPortrait&&(l=i.requestVerifyPortrait({image:{id:t[t.length-1]?.data?.image_id},selfie_type:s}));let[o,_]=await Promise.all([r,l]);return{uploadedImages:t,faceLivenessResult:o,portraitResult:_}}catch(e){return console.error(e),{}}},[i,a.enableVerifyFaceLiveness,a.enableVerifySanityPortrait,s]),uploadImage:r}}({outputEncryptionSettings:h,selfieType:u,enabledServices:b,apiCredentials:o}),{captureFrameSettings:y,flashSettings:S,exifSettings:k,outputImageSettings:C}=em(),{framesIntervalTime:R}=y,{onFramesCaptured:W,onReset:I}=s,{onErrorCallback:A}=el(),D=et(),T=e.useRef([]),q=e.useRef([]),O=async e=>{let t=e;if(h.enable&&(t=await M.encryptFrames(t,h.key)),"function"==typeof W&&W(t),n&&b.enableUploadFrames){let e={};h.enable&&(e["X-TV-Key"]=h.key),es.uploadFrameBatch(ea(t),D,e)}},P=e.useCallback(async e=>{let t,s=e.selfieLabel===B.FAR_FACE?C.farImageOrder:C.closeImageOrder;if(T.current[s])return;let a=new Promise(e=>{t=e});q.current.push(a);let i={...e,blob:await e.blob},r=await d.writeCurrentExif({imageData:i,enableExifData:k.enable});i.blob=r,h.enable&&(i.encrypted=await E.encrypt({blob:i.blob,key:h.key})),T.current[s]={image:i,uploadPromise:n&&b.enableUploadImages?v(i):null},t()},[n,b.enableUploadImages,k.enable,h.enable,h.key,C.closeImageOrder,C.farImageOrder,v]),j=async e=>{f(!0),await Promise.all(q.current);let s={flash_color:S.flashColor,colors:S.colors,frames_per_color:S.framesPerColor,frame_interval:R,delay_between_colors:S.delayBetweenColors,use_face_detector_when_flashing:S.useFaceDetectorWhenFlashing};T.current=T.current.filter(e=>!!e);let a=T.current.map(e=>e.image).filter(e=>"frontal"===e.gesture),l=a.map(e=>e.blob),o=a.map(e=>e.encrypted),_=l[l.length-1],g=_&&"number"==typeof r?await L.scaleImage(_,{minsize:r}):null,c=e.frames;if(h.enable&&(c=await M.encryptFrames(c,h.key)),!n||!b.enableUploadImages){await i({capturedFrames:c,frontalFaces:l,frontalFacesEncrypted:o,frontalScaledImage:g,steps:[],metadata:s}),f(!1);return}try{let e=null;e=y.enable?await es.getAllUploadedBatches():[{frames:ea(c)}];let t=await Promise.all(T.current.map(e=>e.uploadPromise)),{faceLivenessResult:a,portraitResult:n}=await p({videos:e,uploadedImages:t,metadata:s});if(es.resetUploadBatches(),f(!1),a?.errors)throw a.errors;if(n?.errors)throw n.errors;await i({capturedFrames:c,steps:[],frontalFaces:l.map((e,s)=>({blob:e,id:t?.[s]?.data?.image_id})),frontalFacesEncrypted:o,frontalScaledImage:g,apiCheckPassed:a?.data.is_live??!1,verifyFaceLivenessResult:a?.data??null,verifyPortraitResult:n?.data??null,uploadFramesResult:e})}catch(e){console.error(e),f(!1),A({...t.Errors.api_call_error,details:e})}};return a.jsxs(a.Fragment,{children:[a.jsx(ev,{..._,apiCheck:n,onFlashDone:j,onFramesCaptured:O,onReset:()=>{T.current=[],q.current=[],es.resetUploadBatches(),"function"==typeof I&&I()},onImageCaptured:P}),a.jsx(g,{loading:c})]})},eS=e=>{let{apiCredentials:t,outputEncryptionSettings:s,mode:n}=e;return a.jsx(A,{version:"v2",unmountOnHidden:!0,children:a.jsx(en,{apiCredentials:t,children:a.jsx(ec,{flashMode:n,children:a.jsx(ei,{settings:s,children:a.jsx(ey,{...e})})})})})};eS.propTypes={apiCheck:s.bool,apiCredentials:s.shape({accessKey:s.string,secretKey:s.string,apiUrl:s.string}),onReset:s.func,onLivenessDetectionDone:s.func,onClose:s.func,onError:s.func,onFramesCaptured:s.func,frontCamera:s.bool,styledComponent:s.shape({CloseCameraButton:s.node}),outputEncryptionSettings:s.shape({key:s.string}),frontalMinSize:s.number,serviceSettings:s.shape({enableGetClientSettings:s.bool,enableUploadFrames:s.bool,enableUploadImages:s.bool,enableVerifySanityPortrait:s.bool,enableVerifyFaceLiveness:s.bool}),mode:s.string,flowId:s.string,customTexts:s.shape({}),customComponents:s.shape({FlashLivenessBody:s.elementType,FlashLivenessOverlay:s.elementType}),extraConfig:s.shape({})},eS.defaultProps={apiCheck:!1,apiCredentials:{},onReset:()=>{},onLivenessDetectionDone:()=>{},onClose:()=>{},onError:()=>{},onFramesCaptured:()=>{},frontCamera:!0,styledComponent:{CloseCameraButton:null},outputEncryptionSettings:{key:""},frontalMinSize:null,serviceSettings:{enableGetClientSettings:!0,enableUploadFrames:!0,enableUploadImages:!0,enableVerifySanityPortrait:!0,enableVerifyFaceLiveness:!0},mode:t.Mode.FLASH_ADVANCED,flowId:"",customTexts:{},customComponents:{FlashLivenessBody:null,FlashLivenessOverlay:null},extraConfig:null};export{eS as default};
1
+ import{r as e,s as t,P as s,j as a,n as n,u as i,b as r,x as l,e as o,ao as _,ap as g,J as c,L as d,aq as f,ar as h,as as u,at as m,au as b,av as p,aw as v,ax as y,ay as S,D as k,N as C,d as F,f as x,M as E,az as w,aA as M,W as L}from"./chunk-66453960.js";import{d as R}from"./chunk-fbc578b8.js";import{t as W}from"./chunk-b6640bda.js";import{C as I,O as A}from"./chunk-8295b31d.js";import{u as D,S as T,a as q,F as B,b as O,c as P,d as j,n as Q,l as V,e as N,s as U,f as H,R as $,g as G,h as J,i as z,j as K,W as X,k as Y,m as Z,o as ee,p as et,q as es,r as ea,A as en,O as ei}from"./chunk-f0b91c22.js";import{m as er,u as el,a as eo}from"./chunk-4ba29034.js";import{u as e_}from"./chunk-d51c5685.js";let eg=e.createContext(t.Mode.FLASH_ADVANCED),ec=({flashMode:e,children:s})=>{let n=e===t.Mode.FLASH||e.startsWith("flash_")?e:t.Mode.FLASH;return a.jsx(eg.Provider,{value:n,children:s})};ec.defaultProps={flashMode:t.Mode.FLASH_ADVANCED},ec.propTypes={flashMode(e,t,s){if(!/(^flash_|^flash$)/.test(e[t]))return Error(`Invalid prop \`${t}\` of value \`${e[t]}\` supplied to \`${s}\`. \`${t}\` is either 'flash' or begins with 'flash_'. Falling back to 'flash'.`)},children:s.node.isRequired};let ed=()=>{let t=e.useContext(eg);if(void 0===t)throw Error("useFlashMode must be used within a FlashModeProvider");return t},ef=0,eh=1,eu={data:{settings:{flashing_modes:{flash:{frames_per_color:8,frames_per_color_web:8,colors:"r r rrr",colors_web:"r r rrr"}},sdk_settings:{flash_liveness_settings:{frontal_face_check:{enable:!0,up_down_bound_min:.35,up_down_bound_max:.7},capture_frame_settings:{enable:!1,frames_batch_length:10,frames_interval_time:0,frame_quality:.8,frame_scale:1,auto_capture_min_frames:0,auto_capture_min_frames_far:0,auto_capture_min_frames_close:0},not_qualified_settings:{enable_far:!1,enable_close:!1,threshold_far:.11,threshold_close:.11},close_eyes_settings:{enable:!1,timeout:5,force_check:!1},face_settings:{close_face_ratio:.82,max_far_face_ratio:.9,min_far_face_ratio:.8,mobile:{close_face_ratio:.95,max_far_face_ratio:.9,min_far_face_ratio:.85}},flash_settings:{colors_length:10,flash_color:"rgb(255, 0, 0)",secondary_flash_color:"rgba(0,0,0,0.6)",delay_between_colors:120,flash_intensity:1,frames_per_color:4,use_face_detector_when_flashing:!1,flash_frame_interval:0},liveness_settings:{enable_far_step:!0},timeout_settings:{enable:!0,total:30,countdown:10,max_retry_count:0,non_stoppable:!1},exif_data_settings:{enable:!0},mask_settings:{chin_to_mask_bottom_padding:20,large_scale:.85,mobile:{chin_to_mask_bottom_padding:20,large_scale:.9,oval_padding:{bottom:20,left:20,right:20,top:0},oval_vertical_offset:60,small_scale:.65},oval_padding:{bottom:20,left:30,right:30,top:0},oval_vertical_offset:0,small_scale:.6},image_settings:{valid_face_ratio:.6,image_quality:1,crop_center_far:!0,crop_center_close:!1,detection_to_whole_face_ratio:.8},blur_far_settings:{enable:!0,blurry_threshold:.4,wait_for_best_image_time_ms:1e3},blur_close_settings:{enable:!0,blurry_threshold:.4,wait_for_best_image_time_ms:1e3},brightness_detection_far_settings:{enable_too_bright_check:!1,enable_too_dark_check:!1,too_bright_threshold:.83,too_dark_threshold:.195},brightness_detection_close_settings:{enable_too_bright_check:!1,enable_too_dark_check:!1,too_bright_threshold:.83,too_dark_threshold:.195},output_image_settings:{image_ordering:["close","far"]},auto_gen_frame_ids:{enable:!1,max_items:50}}}}}},em=()=>{let s=e_(),a=ed();return e.useMemo(()=>{let e=er({},eu,s),l=n(e,`data.settings.flashing_modes.${t.Mode.FLASH}`),o=n(e,`data.settings.flashing_modes.${a}`,l),_={enable:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.capture_frame_settings.enable"),framesIntervalTime:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.capture_frame_settings.frames_interval_time"),framesBatchLength:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.capture_frame_settings.frames_batch_length"),frameScale:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.capture_frame_settings.frame_scale"),frameQuality:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.capture_frame_settings.frame_quality"),autoCaptureMinFramesFar:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.capture_frame_settings.auto_capture_min_frames_far"),autoCaptureMinFramesClose:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.capture_frame_settings.auto_capture_min_frames_close")},g={enableFarStep:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.liveness_settings.enable_far_step")},c={flashColor:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.flash_settings.flash_color"),secondaryFlashColor:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.flash_settings.secondary_flash_color"),colors:i.getWebSetting(o,"colors"),delayBetweenColors:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.flash_settings.delay_between_colors"),framesPerColor:i.getWebSetting(o,"frames_per_color"),flashIntensity:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.flash_settings.flash_intensity"),useFaceDetectorWhenFlashing:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.flash_settings.use_face_detector_when_flashing"),flashFrameInterval:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.flash_settings.flash_frame_interval")},d={smallScale:i.getWebSetting(e,r.isMobile?"data.settings.sdk_settings.flash_liveness_settings.mask_settings.mobile.small_scale":"data.settings.sdk_settings.flash_liveness_settings.mask_settings.small_scale"),largeScale:i.getWebSetting(e,r.isMobile?"data.settings.sdk_settings.flash_liveness_settings.mask_settings.mobile.large_scale":"data.settings.sdk_settings.flash_liveness_settings.mask_settings.large_scale"),ovalPadding:{left:i.getWebSetting(e,r.isMobile?"data.settings.sdk_settings.flash_liveness_settings.mask_settings.mobile.oval_padding.left":"data.settings.sdk_settings.flash_liveness_settings.mask_settings.oval_padding.left"),right:i.getWebSetting(e,r.isMobile?"data.settings.sdk_settings.flash_liveness_settings.mask_settings.mobile.oval_padding.right":"data.settings.sdk_settings.flash_liveness_settings.mask_settings.oval_padding.right"),top:i.getWebSetting(e,r.isMobile?"data.settings.sdk_settings.flash_liveness_settings.mask_settings.mobile.oval_padding.top":"data.settings.sdk_settings.flash_liveness_settings.mask_settings.oval_padding.top"),bottom:i.getWebSetting(e,r.isMobile?"data.settings.sdk_settings.flash_liveness_settings.mask_settings.mobile.oval_padding.bottom":"data.settings.sdk_settings.flash_liveness_settings.mask_settings.oval_padding.bottom")},ovalVerticalOffset:i.getWebSetting(e,r.isMobile?"data.settings.sdk_settings.flash_liveness_settings.mask_settings.mobile.oval_vertical_offset":"data.settings.sdk_settings.flash_liveness_settings.mask_settings.oval_vertical_offset"),chinToMaskBottomPadding:i.getWebSetting(e,r.isMobile?"data.settings.sdk_settings.flash_liveness_settings.mask_settings.mobile.chin_to_mask_bottom_padding":"data.settings.sdk_settings.flash_liveness_settings.mask_settings.chin_to_mask_bottom_padding")},f={minFarFaceRatio:i.getWebSetting(e,r.isMobile?"data.settings.sdk_settings.flash_liveness_settings.face_settings.mobile.min_far_face_ratio":"data.settings.sdk_settings.flash_liveness_settings.face_settings.min_far_face_ratio"),maxFarFaceRatio:i.getWebSetting(e,r.isMobile?"data.settings.sdk_settings.flash_liveness_settings.face_settings.mobile.max_far_face_ratio":"data.settings.sdk_settings.flash_liveness_settings.face_settings.max_far_face_ratio"),closeFaceRatio:i.getWebSetting(e,r.isMobile?"data.settings.sdk_settings.flash_liveness_settings.face_settings.mobile.close_face_ratio":"data.settings.sdk_settings.flash_liveness_settings.face_settings.close_face_ratio")},h={enable:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.close_eyes_settings.enable"),timeout:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.close_eyes_settings.timeout"),forceCheck:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.close_eyes_settings.force_check")},u={enable:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.exif_data_settings.enable")},m={imageQuality:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.image_settings.image_quality"),validFaceRatio:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.image_settings.valid_face_ratio"),enableCropCenterFar:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.image_settings.crop_center_far"),enableCropCenterClose:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.image_settings.crop_center_close"),detectionToWholeFaceRatio:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.image_settings.detection_to_whole_face_ratio")},b=i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.timeout_settings.max_retry_count"),p={enable:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.timeout_settings.enable"),total:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.timeout_settings.total"),countdown:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.timeout_settings.countdown"),enableMaxRetryCount:b>0,maxRetryCount:b,interruptible:!i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.timeout_settings.non_stoppable")},v={enable:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.blur_far_settings.enable"),threshold:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.blur_far_settings.blurry_threshold"),duration:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.blur_far_settings.wait_for_best_image_time_ms")},y={enable:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.blur_close_settings.enable"),threshold:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.blur_close_settings.blurry_threshold"),duration:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.blur_close_settings.wait_for_best_image_time_ms")},S={enable:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.not_qualified_settings.enable_far"),threshold:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.not_qualified_settings.threshold_far")},k={enable:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.not_qualified_settings.enable_close"),threshold:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.not_qualified_settings.threshold_close")},C={enableTooBrightCheck:n(e,"data.settings.sdk_settings.flash_liveness_settings.brightness_detection_far_settings.enable_too_bright_check"),enableTooDarkCheck:n(e,"data.settings.sdk_settings.flash_liveness_settings.brightness_detection_far_settings.enable_too_dark_check"),tooBrightThreshold:n(e,"data.settings.sdk_settings.flash_liveness_settings.brightness_detection_far_settings.too_bright_threshold"),tooDarkThreshold:n(e,"data.settings.sdk_settings.flash_liveness_settings.brightness_detection_far_settings.too_dark_threshold")},F={enableTooBrightCheck:n(e,"data.settings.sdk_settings.flash_liveness_settings.brightness_detection_close_settings.enable_too_bright_check"),enableTooDarkCheck:n(e,"data.settings.sdk_settings.flash_liveness_settings.brightness_detection_close_settings.enable_too_dark_check"),tooBrightThreshold:n(e,"data.settings.sdk_settings.flash_liveness_settings.brightness_detection_close_settings.too_bright_threshold"),tooDarkThreshold:n(e,"data.settings.sdk_settings.flash_liveness_settings.brightness_detection_close_settings.too_dark_threshold")},x={imageOrdering:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.output_image_settings.image_ordering"),farImageOrder:eh,closeImageOrder:ef};Array.isArray(x.imageOrdering)&&2===x.imageOrdering.length&&"far"===x.imageOrdering[0]&&"close"===x.imageOrdering[1]&&(x.farImageOrder=0,x.closeImageOrder=1);let E={enable:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.auto_gen_frame_ids.enable")&&p.enable,maxItems:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.auto_gen_frame_ids.max_items")};return{captureFrameSettings:_,livenessSettings:g,flashSettings:c,maskSettings:d,faceSettings:f,closeEyesSettings:h,exifSettings:u,imageSettings:m,timeoutSettings:p,blurCheckFarSettings:v,blurCheckCloseSettings:y,notQualifiedFarSettings:S,notQualifiedCloseSettings:k,brightnessDetectionFarSettings:C,brightnessDetectionCloseSettings:F,outputImageSettings:x,autoGenFrameIds:E,frontalFaceCheckSettings:{enable:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.frontal_face_check.enable"),upDownBoundMin:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.frontal_face_check.up_down_bound_min"),upDownBoundMax:i.getWebSetting(e,"data.settings.sdk_settings.flash_liveness_settings.frontal_face_check.up_down_bound_max")}}},[s,a])},eb=r.isMobile?{width:{ideal:640},whiteBalanceMode:"none"}:{width:{ideal:9999},whiteBalanceMode:"none"},ep=(e,t)=>""===t.faceError&&(!!e.isEyeClosed&&!t.isEyeClosed||(!!e.isEyeClosed||!t.isEyeClosed)&&(!!m.hasBetterBrightnessScore(t.brightnessScore,e.brightnessScore)||!!m.hasSameBrightnessScore(t.brightnessScore,e.brightnessScore)&&b.hasBetterBlurScore(t.blurScore,e.blurScore)));function ev(s){let{onReset:n,onFlashDone:i,frontCamera:r,styledComponent:m,onFramesCaptured:b,customComponent:F,extraConfig:x,onImageCaptured:E}=s,{onCloseCallback:w,onErrorCallback:M}=el(),L=em(),A=F?.FlashLivenessBody??p,ee=F?.FlashLivenessOverlay??v,et=F?.FlashLivenessError??y,es=F?.FlashLivenessCloseIcon??S,{maskSettings:ea,flashSettings:en,faceSettings:ei,livenessSettings:er,captureFrameSettings:e_,imageSettings:eg,timeoutSettings:ec,blurCheckFarSettings:ef,blurCheckCloseSettings:eh,exifSettings:eu,autoGenFrameIds:ev}=L;if(ea.smallScale>ea.largeScale)throw Error("smallScale must be smaller than largeScale");let ey=e.useRef(),eS=D(),ek=eo(),{framesPerColor:eC,delayBetweenColors:eF,useFaceDetectorWhenFlashing:ex,flashIntensity:eE,flashColor:ew,colors:eM,flashFrameInterval:eL,secondaryFlashColor:eR}=en,[eW,eI]=e.useState(""),eA=e.useMemo(()=>W(eI,1e3),[]),[eD,eT]=e.useState(!1),[eq,eB]=e.useState(T.LOADING),eO=l(),eP={width:o("FlashLiveness.mask.width")({theme:eO}),height:o("FlashLiveness.mask.height")({theme:eO}),strokeColor:(eq===T.FAR_FACE||eq===T.CLOSE_FACE)&&eW&&!eD?o("FlashLiveness.mask.strokeColorError")({theme:eO}):o("FlashLiveness.mask.strokeColor")({theme:eO}),strokeWidth:2*o("FlashLiveness.mask.strokeWidth")({theme:eO}),path:o("FlashLiveness.mask.path")({theme:eO}),backgroundColor:o("FlashLiveness.maskFill")({theme:eO})},ej=e.useRef(null),[eQ,eV,eN,eU]=q(),[eH,e$]=e.useState(0),[eG,eJ]=e.useState(!1),ez=e.useRef({frames:[],total:{[B.FAR_FACE]:0,[B.CLOSE_FACE]:0}}),eK=e.useRef(!1),eX=e.useRef(!1),eY=e.useRef(!1),eZ=O({compareFn:ep,duration:ef.duration,minFrames:e_.autoCaptureMinFramesFar}),e0=O({compareFn:ep,duration:eh.duration,minFrames:e_.autoCaptureMinFramesClose}),e1=ed(),[e2,e3]=e.useState(!1),{sessionId:e5,updateSessionId:e8}=P(),e9=e.useRef(_.createSingleUUID()),{onVideoPlayed:e6,cropArea:e4,isPlaying:e7}=j({}),{smallScale:te,largeScale:tt}=Q(ea,{width:eP.width,height:eP.height},{width:e4.width,height:e4.height}),ts=e.useRef(null),ta=e.useRef(null),tn=1e3*ec.total/e_.framesIntervalTime+eM.length*eC,{uuids:ti,getNextUUID:tr,reset:tl}=g({total:Math.min(ev.maxItems,Math.ceil(tn/e_.framesBatchLength))}),to=e.useCallback(e=>{let t=e[e.length-1];try{let e=JSON.parse(t.metadata);ev.enable&&(e.global_batch_id=tr()),e.global_session_id=e9.current,t.metadata=JSON.stringify(e)}catch(e){console.error("Unable to process last frame metadata",e)}},[ev.enable,tr]),{playVoice:t_}=c.useVoicePlayer(),tg=e.useMemo(()=>R(({reason:e})=>{if(eY.current=!1,ez.current.frames=[],ez.current.total[B.FAR_FACE]=0,ez.current.total[B.CLOSE_FACE]=0,eK.current=!1,eX.current=!1,ts.current=null,ta.current=null,er.enableFarStep?(e$(te),eB(T.FAR_FACE),t_("move_face_into_frame")):t_("move_face_closer"),e8(),ev.enable){let e=tl();d.addExifData("frame_batch_ids",e)}n({reason:e})},200,{leading:!0}),[er.enableFarStep,e8,ev.enable,n,te,t_,tl]),tc=V({offset:ea.ovalVerticalOffset,ovalPadding:ea.ovalPadding,largeScale:tt,maskHeight:e4.height,ovalHeight:eP.height}),{flashingColors:td,currentColor:tf,colorIndex:th,startFlashing:tu,goToNextColor:tm,colorInfoRef:tb,checkIsLastColor:tp}=(({colors:s="",onFlashDone:a,onErrorCallback:n,framesPerColor:i,flashColor:r,secondaryFlashColor:l})=>{let[o,_]=e.useState(null),g=e.useRef({colorIndex:null,frameIndex:null,colorStringIndex:null}),c=e.useMemo(()=>s.split("").reduce((e,t)=>e+t.repeat(i),""),[s,i]),d=" "===c[o]?l:r,f=e.useCallback(()=>g.current.colorStringIndex===c.length-1,[c.length]),h=e.useCallback(()=>{if(g.current.colorIndex+=Math.floor((g.current.frameIndex+1)/i),g.current.frameIndex=(g.current.frameIndex+1)%i,g.current.colorStringIndex+=1,!(g.current.colorStringIndex>c.length)){if(g.current.colorStringIndex<c.length)return void _(e=>e+1);_(null),g.current={colorIndex:null,frameIndex:null,colorStringIndex:null},"function"==typeof a&&a()}},[c.length,i,a]),u=e.useCallback(()=>{_(0),g.current={colorIndex:0,frameIndex:0,colorStringIndex:0}},[]);return e.useEffect(()=>{0===c.length&&"function"==typeof n&&n(t.Errors.flashing_color_error)},[c.length,n]),{flashingColors:c,colorIndex:o,currentColor:d,goToNextColor:h,startFlashing:u,colorInfoRef:g,checkIsLastColor:f}})({colors:eM,onFlashDone:e.useCallback(async()=>{eB(T.STOP_DECTECTING),eS("selfie_flash","user_activity.finish_flash"),eS("selfie_flash","user_activity",({lastTimeLog:e})=>({flash_liveness_in_ms:e-ey.current}));let{frames:e}=ez.current;if(e_.enable&&e_.framesBatchLength>0){let t=e.length%e_.framesBatchLength;if(0!==t){let s=e.slice(-1*t);to(s),"function"==typeof b&&b(s)}}try{"function"==typeof i&&await i({frames:ez.current.frames})}catch(e){M({error:e})}},[eS,e_.enable,e_.framesBatchLength,to,b,i,M]),onErrorCallback:M,framesPerColor:eC,flashColor:ew,secondaryFlashColor:eR}),tv=e.useCallback(()=>{!er.enableFarStep||(0===ez.current.total[B.FAR_FACE]&&(eY.current=!0),e_.enable&&(ez.current.total[B.FAR_FACE]+=1))},[e_.enable,er.enableFarStep]),ty=e.useMemo(()=>({x:Math.max(eV?.left,0),y:Math.max(eV?.top,0),width:Math.min(eV?.right-eV?.left,e4.width),height:Math.min(eV?.bottom-eV?.top,e4.height)}),[e4.height,e4.width,eV?.bottom,eV?.left,eV?.right,eV?.top]),tS=e.useCallback(({frame:e,prediction:t,originalRatio:s})=>{if(eK.current)return;let a=e=>{let t=Y({maskBoundingBox:ty,faceRatio:e.faceRatio,validFaceRatio:eg.validFaceRatio,video:ej.current,shouldCropCenterSquare:eg.enableCropCenterFar,cropArea:e4,frame:e.snapshot,facePrediction:e.facePrediction,detectionToWholeFaceRatio:eg.detectionToWholeFaceRatio}),s={blob:k.takePicture({canvas:t,quality:eg.imageQuality}),gesture:"frontal",captureTime:e.captureTime,selfieLabel:B.FAR_FACE,qualifyScore:e.qualifyScore,blurScore:e.blurScore,brightnessScore:e.brightnessScore,realQualifyScore:e.realQualifyScore,qualifyModelMessage:e.qualifyModelMessage};eK.current=!0,d.addExifData("flash_liveness.number_of_frames.far_frames",ez.current.total[B.FAR_FACE]),d.addExifData("model_score.face_blurry_score",s.blurScore),d.addExifData("model_score.face_brightness_score",s.brightnessScore),d.addExifData("model_score.face_qualify_score",s.qualifyScore),d.addExifData("debug_log.face_real_qualify_score",s.realQualifyScore),d.addExifData("debug_log.face_qualify_model_message",s.qualifyModelMessage),d.addExifData("selfie_label",s.selfieLabel),d.addExifData("capture_time",s.captureTime),d.addExifData("type",s.gesture),E(s),eI(""),e$(tt),eU(!0),eB(T.CLOSE_FACE),t_("move_face_closer")},n={qualifyScore:e.qualifyScore,blurScore:e.blurScore,isEyeClosed:e.isEyeClosed,faceRatio:e.faceRatio,snapshot:N(ej.current),captureTime:Date.now(),facePrediction:U(t,s),brightnessScore:e.brightnessScore,faceError:e.faceError,realQualifyScore:e.realQualifyScore,qualifyModelMessage:e.qualifyModelMessage};if(!ef.enable)return void a(n);if(!eZ.isAutoCapturing()){eT(!0),eZ.startCapturing({onDone:e=>{eT(!1),a(e)},initialFrame:n});return}eZ.captureFrame(n)},[ef.enable,eZ,ty,eg.validFaceRatio,eg.enableCropCenterFar,eg.detectionToWholeFaceRatio,eg.imageQuality,e4,E,tt,eU,t_]),tk=e.useCallback(({frame:e,prediction:t,originalRatio:s})=>{if(eX.current)return;let a=e=>{let t=Y({maskBoundingBox:ty,faceRatio:e.faceRatio,validFaceRatio:eg.validFaceRatio,video:ej.current,shouldCropCenterSquare:eg.enableCropCenterClose,cropArea:e4,frame:e.snapshot,facePrediction:e.facePrediction,detectionToWholeFaceRatio:eg.detectionToWholeFaceRatio}),s={blob:k.takePicture({canvas:t,quality:eg.imageQuality}),gesture:"frontal",captureTime:e.captureTime,selfieLabel:B.CLOSE_FACE,qualifyScore:e.qualifyScore,blurScore:e.blurScore,brightnessScore:e.brightnessScore,realQualifyScore:e.realQualifyScore,qualifyModelMessage:e.qualifyModelMessage};eX.current=!0,d.addExifData("flash_liveness.number_of_frames.close_frames",ez.current.total[B.CLOSE_FACE]),d.addExifData("model_score.face_blurry_score",s.blurScore),d.addExifData("model_score.face_brightness_score",s.brightnessScore),d.addExifData("model_score.face_qualify_score",s.qualifyScore),d.addExifData("debug_log.face_real_qualify_score",s.realQualifyScore),d.addExifData("debug_log.face_qualify_model_message",s.qualifyModelMessage),d.addExifData("selfie_label",s.selfieLabel),d.addExifData("capture_time",s.captureTime),d.addExifData("type",s.gesture),E(s),eI(""),eJ(!1),eB(T.START_FLASHING),tu()},n={qualifyScore:e.qualifyScore,blurScore:e.blurScore,isEyeClosed:e.isEyeClosed,faceRatio:e.faceRatio,snapshot:N(ej.current),captureTime:Date.now(),facePrediction:U(t,s),brightnessScore:e.brightnessScore,faceError:e.faceError,realQualifyScore:e.realQualifyScore,qualifyModelMessage:e.qualifyModelMessage};if(!eh.enable)return void a(n);if(!e0.isAutoCapturing()){t_("please_hold_still"),eT(!0),e0.startCapturing({onDone:e=>{eT(!1),a(e)},initialFrame:n});return}e0.captureFrame(n)},[eh.enable,e0,ty,eg.validFaceRatio,eg.enableCropCenterClose,eg.detectionToWholeFaceRatio,eg.imageQuality,e4,E,tu,t_]),tC=e.useMemo(()=>{if("number"==typeof th&&th%eC==0){let e=td[th-1];return e===td[th]?eL:Math.max(eF,eL)}return eL},[th,eF,eL,td,eC]),tF=null!==th&&eq===T.START_FLASHING,tx=e.useRef(!1),tE=e.useCallback(({prediction:e,canvas:t})=>{if(!tF||tx.current||null===tb.current.colorIndex||null===tb.current.frameIndex)return;if(!e_.enable)return void tm();let s=performance.now();if(null!==ta.current&&s-ta.current<tC)return;ta.current=s;let{frames:a}=ez.current,n=H({prediction:e,canvas:t,index:a.length,quality:e_.frameQuality}),i={color:tf,type:B.FLASHING,time:Math.round(performance.now()),colorIndex:tb.current.colorIndex,frameIndex:tb.current.frameIndex,colorStringIndex:tb.current.colorStringIndex,pattern:eM,session_id:e5},r=tp();if(r&&eu.enable&&(d.addExifData("flash_liveness.flash_liveness_in_ms",Math.round(performance.now()-ey.current)),i.exif=d.getCurrentExif()),n.metadata=JSON.stringify(i),a.push(n),e_.framesBatchLength>0&&a.length%e_.framesBatchLength==0){let e=a.slice(-1*e_.framesBatchLength);to(e),"function"==typeof b&&b(e)}r&&(tx.current=!0),tm()},[tF,e_.enable,e_.frameQuality,e_.framesBatchLength,tC,tf,tb,eM,e5,tp,eu.enable,tm,to,b]),tw=e.useCallback(({error:e})=>{eA(e),("no_face"===e||"multiple_faces"===e)&&"no_face"===e&&eY.current&&!eD&&tg({reason:$.no_face})},[eD,tg,eA]),{warmupDone:tM}=G({onError:M,isVideoPlaying:e7,step:eq,cropArea:e4,videoRef:ej,onFarFaceDetected:tv,onFarFullFaceDetected:tS,onCloseFaceDetected:e.useCallback(({prediction:e,canvas:t})=>{let{frames:s}=ez.current;if(er.enableFarStep||0!==s.length||(eY.current=!0),!e_.enable)return;let a=performance.now();if(null!==ta.current&&a-ta.current<e_.framesIntervalTime)return;ta.current=a;let n=H({prediction:e,canvas:t,index:s.length,quality:e_.frameQuality});if(n.metadata=JSON.stringify({color:"",type:B.CLOSE_FACE,time:Math.round(performance.now()),colorIndex:tb.current.colorIndex,pattern:eM,session_id:e5}),ez.current.total[B.CLOSE_FACE]+=1,s.push(n),e_.framesBatchLength>0&&s.length%e_.framesBatchLength==0){let e=s.slice(-1*e_.framesBatchLength);to(e),"function"==typeof b&&b(e)}},[er.enableFarStep,e_.enable,e_.framesIntervalTime,e_.frameQuality,e_.framesBatchLength,tb,eM,e5,to,b]),onCloseFullFaceDetected:tk,onFlashingFramesCaptured:tE,useFaceDetectorWhenFlashing:ex,onFaceError:tw,maskBoundingRect:eV,shouldPauseFaceDetection:eN||e2,faceDetectionSettings:L,shouldContinueOnError:eD,debug:ek});J(ej.current);z(()=>{!async function(){let{resourceReport:e,measureReport:t}=await C.reportAll();Object.values(e).forEach(e=>{eS("selfie_flash","sdk.download_model",e)}),Object.values(t).forEach(e=>{eS("selfie_flash","sdk.init_model",e)})}()},tM),z(()=>{er.enableFarStep?(t_("move_face_into_frame"),eB(T.FAR_FACE),e$(te)):(t_("move_face_closer"),eB(T.CLOSE_FACE),e$(tt)),eJ(!0),d.addExifData("selfie_type",e1),d.addExifData("flash_liveness",{flash_settings:{delay_between_colors:en.delayBetweenColors,flash_color:en.flashColor,secondary_flash_color:en.secondaryFlashColor},face_settings:{close_face_ratio:ei.closeFaceRatio,max_far_face_ratio:ei.maxFarFaceRatio,min_far_face_ratio:ei.minFarFaceRatio},mask_settings:{oval_vertical_offset:ea.ovalVerticalOffset,small_scale:ea.smallScale,large_scale:ea.largeScale},image_settings:{valid_face_ratio:eg.validFaceRatio}}),d.addExifData("global_session_id",e9.current),d.addExifData("pattern",eM),ev.enable&&d.addExifData("frame_batch_ids",ti),ey.current||(ey.current=performance.now())},tM&&e7),z(()=>eS("selfie_flash","user_activity.start"),!0),z(()=>eS("selfie_flash","user_activity.start_far"),eq===T.FAR_FACE),z(()=>eS("selfie_flash","user_activity.start_close"),eq===T.CLOSE_FACE),z(()=>eS("selfie_flash","user_activity.start_flash"),eq===T.START_FLASHING);let tL=null===th?0:Math.min(Math.round((th+1)/(eM.length*eC)*100),100),{Loading:tR}=m,tW=e.useCallback(()=>{eT(!1),eZ.stopCapturing(),e0.stopCapturing(),e3(!0)},[e0,eZ]),tI=e.useCallback(()=>{e3(!1),tg({reason:$.timeout})},[tg]),{remaining:tA}=K({shouldStart:eG&&ec.enable,onTimeout:tW,onDelayEnd:tI,onError:M,totalTime:ec.total,totalDelay:3,maxRetriesSettings:{enable:ec.enableMaxRetryCount,total:ec.maxRetryCount},interruptible:ec.interruptible}),tD=Z(eW),tT=e4.y+e4.height/2+tc;return a.jsxs(a.Fragment,{children:[a.jsx(f,{frontCamera:r,onVideoPlayed:e6,onClose:w,flipHorizontal:r,ref:ej,onError:M,videoSettings:eb,closeButton:a.jsx(es,{}),children:a.jsxs(X,{overlay:!tM||!e7,loadingComponent:tR,children:[""!==eW&&a.jsx(h,{}),a.jsx(I,{x:`${Math.round(e4.x)}px`,y:`${Math.round(e4.y)}px`,width:`${e4.width}px`,height:`${e4.height}px`,surroundStyle:{background:o("FlashLiveness.maskFill")({theme:eO})},children:a.jsx(u,{ref:eQ,scale:eH,debug:ek,width:e4.width,height:e4.height,padding:ea.ovalPadding,verticalOffset:tc,mask:eP})}),!eD&&""!==tD&&"start_flashing"!==eq&&a.jsx(et,{errorY:tT,errorMessage:tD})]})}),a.jsx(A,{step:eq,currentProgress:tL,errorCode:eW,timeoutProps:{remaining:tA,warningThreshold:ec.countdown,total:ec.total,shouldStart:eG&&ec.enable},isFlashingColor:tf===ew,isAutoCapturing:eD,extraConfig:x}),a.jsx(ee,{step:eq,currentColor:tf,flashIntensity:eE,flashColor:ew,secondaryFlashColor:eR})]})}let ey=s=>{let{apiCheck:n,onLivenessDetectionDone:i,frontalMinSize:r,serviceSettings:l,apiCredentials:o,..._}=s,g=_.customComponent?.FlashLivenessLoading??w,[c,f]=e.useState(!1),h=ee(),u=ed(),m=e_(),b=x.getEnabledServices(l,m),{verifyFlashLiveness:p,uploadImage:v}=function({outputEncryptionSettings:t,selfieType:s,enabledServices:a,apiCredentials:n}){let{apiClient:i}=F.useApiClient({apiCredentials:n}),r=e.useCallback(async e=>{if(!t.enable)return i.uploadImage({label:"portrait",file:e.blob,metadata:JSON.stringify({label:e.selfieLabel})});let s=new Blob([e.encrypted.hex]);return i.uploadImage({file:s,label:"portrait",metadata:JSON.stringify({label:e.selfieLabel})},{"X-TV-Key":t.key})},[i,t.enable,t.key]);return{verifyFlashLiveness:e.useCallback(async({videos:e,uploadedImages:t,metadata:n})=>{try{let r=null;a.enableVerifyFaceLiveness&&(r=i.verifyFaceLiveness({images:t.map(e=>({id:e?.data?.image_id,label:"portrait"})),videos:e,metadata:n,selfie_type:s}));let l=null;a.enableVerifySanityPortrait&&(l=i.requestVerifyPortrait({image:{id:t[t.length-1]?.data?.image_id},selfie_type:s}));let[o,_]=await Promise.all([r,l]);return{uploadedImages:t,faceLivenessResult:o,portraitResult:_}}catch(e){return console.error(e),{}}},[i,a.enableVerifyFaceLiveness,a.enableVerifySanityPortrait,s]),uploadImage:r}}({outputEncryptionSettings:h,selfieType:u,enabledServices:b,apiCredentials:o}),{captureFrameSettings:y,flashSettings:S,exifSettings:k,outputImageSettings:C}=em(),{framesIntervalTime:R}=y,{onFramesCaptured:W,onReset:I}=s,{onErrorCallback:A}=el(),D=et(),T=e.useRef([]),q=e.useRef([]),O=async e=>{let t=e;if(h.enable&&(t=await M.encryptFrames(t,h.key)),"function"==typeof W&&W(t),n&&b.enableUploadFrames){let e={};h.enable&&(e["X-TV-Key"]=h.key),es.uploadFrameBatch(ea(t),D,e)}},P=e.useCallback(async e=>{let t,s=e.selfieLabel===B.FAR_FACE?C.farImageOrder:C.closeImageOrder;if(T.current[s])return;let a=new Promise(e=>{t=e});q.current.push(a);let i={...e,blob:await e.blob},r=await d.writeCurrentExif({imageData:i,enableExifData:k.enable});i.blob=r,h.enable&&(i.encrypted=await E.encrypt({blob:i.blob,key:h.key})),T.current[s]={image:i,uploadPromise:n&&b.enableUploadImages?v(i):null},t()},[n,b.enableUploadImages,k.enable,h.enable,h.key,C.closeImageOrder,C.farImageOrder,v]),j=async e=>{f(!0),await Promise.all(q.current);let s={flash_color:S.flashColor,colors:S.colors,frames_per_color:S.framesPerColor,frame_interval:R,delay_between_colors:S.delayBetweenColors,use_face_detector_when_flashing:S.useFaceDetectorWhenFlashing};T.current=T.current.filter(e=>!!e);let a=T.current.map(e=>e.image).filter(e=>"frontal"===e.gesture),l=a.map(e=>e.blob),o=a.map(e=>e.encrypted),_=l[l.length-1],g=_&&"number"==typeof r?await L.scaleImage(_,{minsize:r}):null,c=e.frames;if(h.enable&&(c=await M.encryptFrames(c,h.key)),!n||!b.enableUploadImages){await i({capturedFrames:c,frontalFaces:l,frontalFacesEncrypted:o,frontalScaledImage:g,steps:[],metadata:s}),f(!1);return}try{let e=null;e=y.enable?await es.getAllUploadedBatches():[{frames:ea(c)}];let t=await Promise.all(T.current.map(e=>e.uploadPromise)),{faceLivenessResult:a,portraitResult:n}=await p({videos:e,uploadedImages:t,metadata:s});if(es.resetUploadBatches(),f(!1),a?.errors)throw a.errors;if(n?.errors)throw n.errors;await i({capturedFrames:c,steps:[],frontalFaces:l.map((e,s)=>({blob:e,id:t?.[s]?.data?.image_id})),frontalFacesEncrypted:o,frontalScaledImage:g,apiCheckPassed:a?.data.is_live??!1,verifyFaceLivenessResult:a?.data??null,verifyPortraitResult:n?.data??null,uploadFramesResult:e})}catch(e){console.error(e),f(!1),A({...t.Errors.api_call_error,details:e})}};return a.jsxs(a.Fragment,{children:[a.jsx(ev,{..._,apiCheck:n,onFlashDone:j,onFramesCaptured:O,onReset:()=>{T.current=[],q.current=[],es.resetUploadBatches(),"function"==typeof I&&I()},onImageCaptured:P}),a.jsx(g,{loading:c})]})},eS=e=>{let{apiCredentials:t,outputEncryptionSettings:s,mode:n}=e;return a.jsx(A,{version:"v2",unmountOnHidden:!0,children:a.jsx(en,{apiCredentials:t,children:a.jsx(ec,{flashMode:n,children:a.jsx(ei,{settings:s,children:a.jsx(ey,{...e})})})})})};eS.propTypes={apiCheck:s.bool,apiCredentials:s.shape({accessKey:s.string,secretKey:s.string,apiUrl:s.string}),onReset:s.func,onLivenessDetectionDone:s.func,onClose:s.func,onError:s.func,onFramesCaptured:s.func,frontCamera:s.bool,styledComponent:s.shape({CloseCameraButton:s.node}),outputEncryptionSettings:s.shape({key:s.string}),frontalMinSize:s.number,serviceSettings:s.shape({enableGetClientSettings:s.bool,enableUploadFrames:s.bool,enableUploadImages:s.bool,enableVerifySanityPortrait:s.bool,enableVerifyFaceLiveness:s.bool}),mode:s.string,flowId:s.string,customTexts:s.shape({}),customComponents:s.shape({FlashLivenessBody:s.elementType,FlashLivenessOverlay:s.elementType}),extraConfig:s.shape({})},eS.defaultProps={apiCheck:!1,apiCredentials:{},onReset:()=>{},onLivenessDetectionDone:()=>{},onClose:()=>{},onError:()=>{},onFramesCaptured:()=>{},frontCamera:!0,styledComponent:{CloseCameraButton:null},outputEncryptionSettings:{key:""},frontalMinSize:null,serviceSettings:{enableGetClientSettings:!0,enableUploadFrames:!0,enableUploadImages:!0,enableVerifySanityPortrait:!0,enableVerifyFaceLiveness:!0},mode:t.Mode.FLASH_ADVANCED,flowId:"",customTexts:{},customComponents:{FlashLivenessBody:null,FlashLivenessOverlay:null},extraConfig:null};export{eS as default};
@@ -1 +1 @@
1
- import{r as e,n as t,u as a,aG as n,s as s,c as i,a9 as r,d as l,I as c,ap as o,ao as m,f as g,L as u,b as _,aJ as f,aK as d,F as b,W as h,D as p,M as v,au as F,k as k,aA as w}from"./chunk-27713cdc.js";import{d as y}from"./chunk-3918125a.js";import{t as I}from"./chunk-67605c5a.js";import{w as T,m as R,n as S,t as L,u as x,o as B,q as D,r as E,v as A,s as M,x as O}from"./chunk-65036591.js";import{m as N}from"./chunk-9803c4f4.js";import{u as P}from"./chunk-788a3d4e.js";let C=async({steps:e,apiClient:t,FaceDirection:a,outputEncryptionSettings:n,video:s})=>{let i=[];e.forEach(e=>{let{name:s,image:r,frontalFaceImage:l}=e;if(s!==a.FRONTAL){let e={label:"portrait",metadata:JSON.stringify({gesture_score:r.leftRightScore,gesture:s})};if(n&&n.key){let a=new Blob([r.encrypted.hex]);i.push(t.uploadImage({file:a,...e},{"X-TV-Key":n.key}))}else i.push(t.uploadImage({file:r.blob,...e}))}else i.push(Promise.resolve({data:{image_id:null}}));if(l.blob){let e={label:"portrait",metadata:JSON.stringify({gesture_score:l.leftRightScore,gesture:a.FRONTAL})};if(n&&n.key){let a=new Blob([l.encrypted.hex]);i.push(t.uploadImage({file:a,...e},{"X-TV-Key":n.key}))}else i.push(t.uploadImage({file:l.blob,...e}))}else i.push(Promise.resolve({data:{image_id:null}}))});let r=s?t.uploadFile({file:s,label:"video"}):Promise.resolve({data:{file_id:null}}),[l,...c]=await Promise.all([r,...i]);return e.forEach((e,t)=>{e.image.imageId=c[2*t].data.image_id,e.frontalFaceImage.imageId=c[2*t+1].data.image_id}),l},U=async({apiClient:e,faceVerificationFlowData:t,onLivenessDetectionDone:a,captureFrameSettings:n,FaceDirection:s,onError:i,outputEncryptionSettings:r,video:l,enabledServices:c,capturedFrames:o})=>{try{let i=t.current.steps;await C({steps:i,apiClient:e,FaceDirection:s,outputEncryptionSettings:r,video:l});let m=i.filter(e=>e.frontalFaceImage.imageId);if(0===m.length)a({error:"wrong_face_movement"});else{await T();let t=R(n);if(t){let n=null;c.enableVerifyFaceLiveness&&(n=e.verifyFaceLiveness({images:m.map(e=>({id:e.frontalFaceImage.imageId})),gesture_images:i.filter(e=>e.image.imageId&&e.name!==s.FRONTAL).map(({name:e,image:{imageId:t}})=>({gesture:e,images:[{id:t}]})),videos:t}));let r=null;c.enableVerifySanityPortrait&&(r=e.requestVerifyPortrait({image:{id:m[m.length-1].frontalFaceImage.imageId}}));let[l,g]=await Promise.all([n,r]),u=l?.data.is_live===!0;a({apiCheckPassed:u,verifyFaceLivenessResult:l?.data??null,verifyFacePortraitResult:g?.data??null,frontalFaces:m.map(e=>({id:e.frontalFaceImage.imageId,blob:e.frontalFaceImage.blob})),steps:i.filter(e=>e.image.imageId&&e.name!==s.FRONTAL).map(({name:e,image:t})=>({name:e,blob:t.blob,id:t.imageId})),uploadFramesResult:t,capturedFrames:o})}else a({error:"network_error"})}}catch(e){i({error:e})}},j=n.faceTracker(),V=new f,{FaceDirection:W,Errors:J,Messages:K,TrackLivenessEvents:$}=s,z={enable:!1,framesIntervalTime:180,framesBatchLength:0},q={[s.FaceDirection.UP]:{delayTime:0},[s.FaceDirection.LEFT]:{delayTime:0},[s.FaceDirection.RIGHT]:{delayTime:0},[s.FaceDirection.FRONTAL]:{delayTime:2e3}},G=()=>{},H=()=>{},X=()=>{};function Z({apiCheck:f,bgCameraMask:T,bgCameraMaskRed:R,surroundStyle:C,cropAreaDimension:Q,customInstructions:Y,customIcon:ee,customDirectionIcon:et,customStepTimeConstraints:ea=q,onLivenessDetectionDone:en,onError:es,frontalMinSize:ei,waitingTimeToGetBetterFrames:er=500,captureFrameSettings:el=z,setRemainingTime:ec=G,onProcessing:eo=X,customErrors:em,customMessages:eg,apiCredentials:eu={},onFramesCaptured:e_=H,initFirstGestureTimeout:ef=2e3,outputEncryptionSettings:ed,cameraScale:eb=1,sendCustomEvent:eh,serviceSettings:ep,currentOrientation:ev,onReset:eF}={}){let[ek,ew]=e.useState(!1),[ey,eI]=e.useState(!1),[eT,eR]=e.useState(!1),[eS,eL]=e.useState(!1),ex=e.useRef(null),{lang:eB,assetRoot:eD,customUrls:eE,exifKey:eA}=i.useSDKSettings(),eM=r.useSDKLocale(),{apiClient:eO}=l.useApiClient({apiCredentials:eu}),[,eN]=e.useReducer(e=>e+1,0),eP=e.useRef(null),eC=e.useRef(!1),[eU,ej]=e.useState(!1),eV=e.useRef({}),{sendEvent:eW}=c.useSDKTracking(),eJ=e.useRef(null);null===eJ.current&&(eJ.current=n.initFaceVerificationData({assetRoot:eD,customInstructions:Y,customIcon:ee,customDirectionIcon:et,customStepTimeConstraints:ea,Locale:eM,lang:eB}));let[eK,e$]=e.useState(),ez=e.useCallback(e=>{e$(e)},[]),eq=e.useMemo(()=>I(ez,500),[ez]),eG=e.useRef([]),eH=e.useRef(),eX=P(),{faceTrackingSetting:eZ,flowIntervalTimeMs:eQ,limitTimeLivenessCheck:eY,terminateIfNoFace:e0,closeEyeSettings:e1,captureFrameSettings:e4,exifDataSettings:e6,recordVideo:e2,waitBeforeStartFlowMs:e3,resetFlowOnOrientationChange:e5,autoGenFrameIds:e8}=function({captureFrameSettingsProp:n,clientSettings:s}){return e.useMemo(()=>{let e,i=N({},S,s),r={enable:t(i,"data.settings.sdk_settings.active_liveness_settings.face_tracking_setting.enable"),webTerminateThreshold:t(i,"data.settings.sdk_settings.active_liveness_settings.face_tracking_setting.web_terminate_threshold"),webWarningThreshold:t(i,"data.settings.sdk_settings.active_liveness_settings.face_tracking_setting.web_warning_threshold"),limitFor:t(i,"data.settings.sdk_settings.active_liveness_settings.face_tracking_setting.limit_for"),maxWarningTime:t(i,"data.settings.sdk_settings.active_liveness_settings.face_tracking_setting.max_warning_time")},l=t(i,"data.settings.sdk_settings.active_liveness_settings.reset_flow_on_orientation_change"),c=t(i,"data.settings.sdk_settings.active_liveness_settings.wait_before_start_flow_ms"),o=t(i,"data.settings.sdk_settings.active_liveness_settings.flow_interval_time_ms"),m=t(i,"data.settings.sdk_settings.active_liveness_settings.take_one_picture_time_ms"),g=a.getWebSetting(i,"data.settings.sdk_settings.active_liveness_settings.limit_time_liveness_check.max_retry_count"),u={enable:t(i,"data.settings.sdk_settings.active_liveness_settings.limit_time_liveness_check.enable"),limitTimeSecond:t(i,"data.settings.sdk_settings.active_liveness_settings.limit_time_liveness_check.limit_time_second"),remainTimeShow:t(i,"data.settings.sdk_settings.active_liveness_settings.limit_time_liveness_check.remain_time_show"),format:t(i,"data.settings.sdk_settings.active_liveness_settings.limit_time_liveness_check.format"),enableMaxRetries:g>0,totalMaxRetries:g,interruptible:!a.getWebSetting(i,"data.settings.sdk_settings.active_liveness_settings.limit_time_liveness_check.non_stoppable")},_={enable:t(i,"data.settings.sdk_settings.active_liveness_settings.terminate_if_no_face.enable"),maxInvalidFrame:t(i,"data.settings.sdk_settings.active_liveness_settings.terminate_if_no_face.max_invalid_frame"),maxTimeMs:t(i,"data.settings.sdk_settings.active_liveness_settings.terminate_if_no_face.max_time_ms")},f={enable:t(i,"data.settings.sdk_settings.active_liveness_settings.close_eye_detector.enable"),webThreshold:t(i,"data.settings.sdk_settings.active_liveness_settings.close_eye_detector.web_threshold"),webTimeout:t(i,"data.settings.sdk_settings.active_liveness_settings.close_eye_detector.web_timeout"),forceCheck:t(i,"data.settings.sdk_settings.active_liveness_settings.close_eye_detector.force_check")},d={enable:t(i,"data.settings.sdk_settings.active_liveness_settings.exif_data_settings.enable")},b={enable:t(i,"data.settings.sdk_settings.active_liveness_settings.record_video.enable")},h=t(s,"data.settings.sdk_settings.active_liveness_settings.save_encoded_frames");e=h?{enable:h.enable,enableLogging:h.enable_logging,framesBatchLength:h.frames_batch_len,framesIntervalTime:h.frames_interval_ms}:n;let p={enable:a.getWebSetting(i,"data.settings.sdk_settings.active_liveness_settings.auto_gen_frame_ids.enable")&&u.enable,maxItems:a.getWebSetting(i,"data.settings.sdk_settings.active_liveness_settings.auto_gen_frame_ids.max_items")};return{faceTrackingSetting:r,resetFlowOnOrientationChange:l,waitBeforeStartFlowMs:c,flowIntervalTimeMs:o,takeOnePictureTimeMs:m,limitTimeLivenessCheck:u,terminateIfNoFace:_,closeEyeSettings:f,exifDataSettings:d,recordVideo:b,captureFrameSettings:e,autoGenFrameIds:p}},[n,s])}({captureFrameSettingsProp:el,clientSettings:eX}),e9=1e3*eY.limitTimeSecond/e4.framesIntervalTime,{uuids:e7,getNextUUID:te,reset:tt}=o({total:Math.min(e8.maxItems,Math.ceil(e9/e4.framesBatchLength*1.2))}),ta=e.useRef(m.createSingleUUID()),tn=e.useCallback(e=>{let t=e[e.length-1];try{let e=JSON.parse(t.metadata);e8.enable&&(e.global_batch_id=te()),e.global_session_id=ta.current,t.metadata=JSON.stringify(e)}catch(e){console.error("Unable to process last frame metadata",e)}},[e8.enable,te]),ts=e2?.enable,ti=e.useMemo(()=>g.getEnabledServices(ep,eX),[eX,ep]),tr=e.useRef(""),tl=e.useCallback(e=>{if(e?.event){if(e.event===$?.show_alert){let t=e.log?.alert;if(t===tr.current)return;tr.current=t}eW(e),eh&&eh(e)}},[eh,eW]),tc=e.useMemo(()=>I(e=>{tl(e)},2e3),[tl]),to=e.useRef(0),tm=e.useRef(),tg=e.useRef();e.useEffect(()=>{tl({tag:"selfie",event:$?.start_camera,log:{}})},[tl]),e.useEffect(()=>(V.start(),()=>{V.stop()}),[]),e.useEffect(()=>{let e=!1;return async function t(){!eU&&(eH.current=performance.now(),eV.current=await d(eE),await b.initTensorFlow({preferredBackends:["wasm","webgl","cpu"]}),e||(ej(!0),tl({tag:"selfie",event:$?.show_warmup,log:{}}),tl({tag:"selfie",event:$?.finish_load_model,log:{status:"success",time_in_ms:performance.now()-eH.current}}),eH.current=null))}(),()=>{e=!0}},[eU,eE,tl]);let tu=e.useRef(!1),t_=e.useCallback(()=>{eJ.current.curStepIndex=eJ.current.steps.length,tu.current=!0,eR(!1),tg.current?.discardRecording()},[]),tf=e.useCallback(()=>{if(eJ.current=n.initFaceVerificationData({assetRoot:eD,customInstructions:Y,customIcon:ee,customDirectionIcon:et,Locale:eM,lang:eB}),to.current=0,tm.current=null,eG.current=[],eL(!1),e$(null),M(),tg.current?.start(),tu.current=!1,e8.enable){let e=tt();u.addExifData("frame_batch_ids",e)}"function"==typeof eF&&eF(),eN()},[eM,eD,e8.enable,et,ee,Y,eB,eF,tt]),td=e.useCallback(()=>{t_(),setTimeout(()=>{tf()},eQ)},[t_,eQ,tf]),tb=e.useMemo(()=>({...J,...em}),[em]),th=e.useMemo(()=>({...K,...eg}),[eg]),tp=e.useCallback(({remainTime:e})=>{if(e>0&&e<=eY.remainTimeShow){let t=L(th.REMAIN_TIME[eB]),a=e;switch(eY.format){case"mm:ss":a=e.toString().padStart(5,"00:00");break;case"ss":a=e.toString().padStart(2,"0")}ec(t({x:a}))}},[eB,eY.format,eY.remainTimeShow,th.REMAIN_TIME,ec]),tv=e.useCallback(()=>{let e={};Object.keys(tb.liveness_terminated_time_out?.msg).forEach(t=>{let a=L(tb.liveness_terminated_time_out?.msg[t]);e[t]=a({x:eY.limitTimeSecond})}),e$({...tb.liveness_terminated_time_out,msg:e,duration:.95*eQ}),tl({tag:"selfie",event:$?.show_alert,log:{alert:"liveness_terminated_time_out,"}}),V.stop(),ec(""),t_()},[tb.liveness_terminated_time_out,eQ,eY.limitTimeSecond,t_,tl,ec]),tF=e.useCallback(({attemptCount:e,fromBackground:t})=>{eY.enableMaxRetries&&e>=eY.totalMaxRetries&&es(s.Errors.max_retry_reached),t&&t_(),V.start(),tf()},[eY.enableMaxRetries,eY.totalMaxRetries,es,tf,t_]),{stopTimer:tk}=x({totalTime:eY.limitTimeSecond,totalDelayBetweenReset:eQ/1e3,interruptible:eY.interruptible,shouldStart:ey&&eY.enable&&eU,onTimesUp:tv,onTick:tp,onReset:tF}),tw=e.useCallback(({clientWidth:e,clientHeight:t,videoAreaWidth:a,videoAreaHeight:n,lostX:s,lostY:i})=>{let r,l;_.isMobile?l=r=a-40:(l=450,r=450);let c=Math.floor((a-r)/2)+s;eP.current={x:c,y:5+i,width:r,height:l,image:T,surroundStyle:C},"object"==typeof Q?eP.current={...eP.current,...Q}:"function"==typeof Q&&(eP.current={...eP.current,...Q({clientWidth:e,clientHeight:t,videoAreaWidth:a,videoAreaHeight:n,lostX:s,lostY:i,isMobile:_.isMobile,width:r,height:l})}),eN(),eI(!0)},[T,C,Q]),ty=e.useRef({});e.useEffect(()=>{ty.current.isFirstValidFrameFoundRef=eS},[eS]),e.useEffect(()=>{let e,t=ex.current,a=async()=>{let{steps:e}=eJ.current,t=[];e.map(e=>(t.push({name:e.name,blob:e.image.blob,captureTime:e.image.captureTime,gesture:e.name}),e.frontalFaceImage.blob&&t.push({name:e.name,blob:e.frontalFaceImage.blob,captureTime:e.frontalFaceImage.captureTime,gesture:W.FRONTAL}),0));let a=t.map(e=>h.resizeBlobImg(e.blob,400,400)),n=await Promise.all(a),s="0";if(e4.framesBatchLength>0){let e=`${Math.floor(eG.current.length/e4.framesBatchLength)}x${e4.framesBatchLength}`,t=eG.current.length%e4.framesBatchLength>0?`+${eG.current.length%e4.framesBatchLength}`:"";s=`${eG.current.length}:${e}${t}`}let i=n.map((e,a)=>{let n=u.parseLivenessImg({...t[a],frames:s});return u.writeCurrentExif({imageData:{blob:e},enableExifData:e6.enable,additionalData:n})}),r=await Promise.all(i),l=t.map((e,t)=>({name:e.name,blob:r[t]}));await Promise.all(e.map(async(t,a)=>{let n=l.filter(e=>e.name===t.name);if(e[a].image.blob=n[0].blob,t.frontalFaceImage.blob&&(e[a].frontalFaceImage.blob=n[1].blob),ed&&ed.key){let{key:s}=ed;e[a].image.encrypted=await v.encrypt({blob:n[0].blob,key:s}),t.frontalFaceImage.blob&&(e[a].frontalFaceImage.encrypted=await v.encrypt({blob:n[1].blob,key:s}))}return 0}))},i=async()=>{let{steps:e}=eJ.current,t=e[eJ.current.curStepIndex];if((t&&tl({tag:"selfie",event:{[s.FaceDirection.UP]:$?.capture_up_face,[s.FaceDirection.LEFT]:$?.capture_left_face,[s.FaceDirection.RIGHT]:$?.capture_right_face,[s.FaceDirection.FRONTAL]:$?.capture_frontal_face}[t.name],log:{time_capture_in_seconds:((performance.now()-eH.current)/1e3).toFixed(1)}}),eJ.current.curStepIndex++,eH.current=performance.now(),eZ.enable&&"each_gesture"===eZ.limitFor&&(to.current=0),eJ.current.curStepIndex===e.length)&&(eY.enable&&(V.stop(),tk(),ec("")),en)){let t=eG.current;if(ed&&ed.key){let e=await Promise.all(t.map(e=>e?.base64));if(t=t.map((t,a)=>({...t,base64:e[a]})),e4.enable&&e4.framesBatchLength>0&&t.length%e4.framesBatchLength>0){let e=t.slice(-1*(t.length%e4.framesBatchLength));e_(e),f&&B(ed,e,eO,t.length===e4.framesBatchLength)}}else if(e4.enable&&e4.framesBatchLength>0&&t.length%e4.framesBatchLength>0){let e=t.slice(-1*(t.length%e4.framesBatchLength));tn(e),e_(e.map(({base64:e,label:t,index:a,metadata:n})=>({base64:e,label:t,index:a,metadata:n}))),f&&ti.enableUploadFrames&&B(ed,e,eO)}tl({tag:"selfie",event:$?.finish_capture,log:{time_capture_in_seconds:V.duration("from_1st_frame")}}),eo(),await tg.current?.stopVideoRecording(),ew(!0),u.addExifData("user_action",{start_selfie:Date.now()-1e3*V.duration("from_1st_frame"),end_selfie:Date.now()}),u.addExifData("global_session_id",ta.current),e8.enable&&u.addExifData("frame_batch_ids",e7),await a();let n=eG.current;if(ed&&ed.key){let e=await Promise.all(n.map(e=>e?.base64));n=n.map((t,a)=>({...t,base64:e[a]}))}if(f&&ti.enableUploadImages)await U({apiClient:eO,faceVerificationFlowData:eJ,onLivenessDetectionDone:en,captureFrameSettings:e4,FaceDirection:W,onError:es,outputEncryptionSettings:ed,video:D().length?D()[0]:null,enabledServices:ti,capturedFrames:n});else{let t=e.filter(e=>e.name!==W.FRONTAL).map(e=>({name:e.name,image:{blob:e.image.blob,encrypted:e.image.encrypted}})),a=e.filter(e=>e.name!==W.FRONTAL).map(e=>e.frontalFaceImage.blob).filter(e=>null!==e),s=e.filter(e=>e.name!==W.FRONTAL).map(e=>e.frontalFaceImage.encrypted).filter(e=>e&&e.hex),i=e.find(e=>e.name===W.FRONTAL)?.image?.blob,r=e.find(e=>e.name===W.FRONTAL)?.image?.encrypted,l=i&&ei?await h.scaleImage(i,{minSize:ei}):null;i&&a.push(i),r&&s.push(r),tl({tag:"result",event:$?.liveness_detection_done,log:{result_object:{steps:t,frontalFaces:a,frontalScaledImage:l}}}),en({steps:t,frontalFaces:a,frontalFacesEncrypted:s,frontalScaledImage:l,capturedFrames:n,video:D().length?D()[0]:null}),E()}ew(!1)}eN()},r=y(()=>{let{curStepIndex:e,steps:t}=eJ.current,a=t[e],n=a?.image.blob!==null,s=a?.frontalFaceImage.blob!==null,r=t.filter(e=>e.frontalFaceImage.blob).length,l=!1;return n&&(s||![1].includes(e)||r>=1)?(eC.current=!1,i(),l=!0):n&&!s?eC.current=!0:eC.current=!1,eR(!1),l},er);async function l({faceDirection:e,canvas:t,blurScore:a,leftRightScore:n,isEyeClose:s}){let{curStepIndex:l,steps:c}=eJ.current;if(l<c.length){let o=c[l];if(O({faceDirection:e,curStep:o})||s)return;if(e===W.FRONTAL&&(null===o.frontalFaceImage.blurScore||F.hasBetterBlurScore(a,o.frontalFaceImage.blurScore))){o.frontalFaceImage.blurScore=a;let e=await p.takePicture({canvas:t});o.frontalFaceImage.blob=e,o.frontalFaceImage.leftRightScore=n,o.frontalFaceImage.captureTime=Date.now(),eC.current&&(eC.current=!1,i())}if(o.name===e&&(null===o.image.blurScore||F.hasBetterBlurScore(a,o.image.blurScore))){eR(!0),o.image.blurScore=a;let e=await p.takePicture({canvas:t});o.image.blob=e,o.image.leftRightScore=n,o.image.captureTime=Date.now(),o.image.objUrl&&URL.revokeObjectURL(o.image.objUrl),o.image.objUrl=URL.createObjectURL(e),r()}}}async function c(a,i){let r,o;if(i?.width===0||i?.height===0)return;let{isFirstValidFrameFoundRef:m}=ty.current,{cropX:g,cropY:u,cropWidth:_,cropHeight:d}=a;i.getContext("2d").drawImage(t,g,u,_,d,-((400*eb-400)/2)/eb,-((400*eb-400)/2)/eb,400,400);let{blazefaceModel:b,closeEyesModel:h}=eV.current,[p,v]=await Promise.all([F.calculateBlurScore(i),k.getModelPredictions({model:b,sCanvas:i})]),{error:y,fullFace:I,faceRatio:S,faceNotFrontalMinThreshold:L}=await n.validatePredictions({predictions:v,width:k.SIZE,height:k.SIZE});r=y,eP.current.image=T;let x=null,D=null,E=null,A=null,{curStepIndex:M,steps:O}=eJ.current;if(I){let e=O[M],t=e&&e.name===W.FRONTAL;E=I.landmarks;let a=await n.calculateFaceDirection({landmarks:E,getPerfectFrontal:t});a&&(x=a.gesture,D=a.leftRightScore);let l=e1?.webTimeout+ea[s.FaceDirection.FRONTAL].delayTime/1e3;if(t&&e1?.enable&&(-1===V.duration("limit_close_eye")||V.duration("limit_close_eye")<l)){e1?.forceCheck||-1!==V.duration("limit_close_eye")||V.start("limit_close_eye");let{isEyeClose:e}=await h.predict(i,E,e1?.webThreshold);(A=e)&&!r&&(r=J.close_eye)}}let N=r?.code==="no_face"||r?.code==="partial_face",P=M<O.length;!function({noFace:e,isFirstValidFrameFoundRef:t}){if(!e0.enable||!t)return;let{maxTimeMs:a}=e0;tm.current&&e||(tm.current={time:Date.now(),frame:0}),e&&tm.current.frame++;let{time:n}=tm.current;e&&Date.now()-n>=a&&(e$({...tb.liveness_terminated_no_face,duration:eQ}),tl({tag:"selfie",event:$?.show_alert,log:{alert:"liveness_terminated_no_face"}}),td())}({noFace:N&&P,isFirstValidFrameFoundRef:m}),r?.code&&tc({tag:"selfie",event:$?.show_alert,log:{alert:r.code}}),!r||"face_too_small"===r.code&&x!==W.FRONTAL&&S>=L?(m||(eL(!0),eH.current=performance.now(),V.start("from_1st_frame")),function({trackingScore:e,isFirstValidFrameFoundRef:t}){if(!eZ.enable||null===e||!t)return!0;let{webWarningThreshold:a,webTerminateThreshold:n,maxWarningTime:s}=eZ;return!!(e<a)||(e<n&&to.current<s?(to.current++,to.current===s?(e$({...tb.liveness_terminated_face_tracking,duration:eQ}),tl({tag:"selfie",event:$?.show_alert,log:{alert:"liveness_terminated_face_tracking"}})):e$({...tb.liveness_too_fast,duration:1500}),!0):(e$({...tb.liveness_terminated,duration:eQ}),tl({tag:"selfie",event:$?.show_alert,log:{alert:"liveness_terminated"}}),td(),!1))}({trackingScore:function(e,t,a,n){if(eG.current.length&&Date.now()-eG.current[eG.current.length-1].time<e4.framesIntervalTime)return null;if(e4.enable&&!n){let{topLeft:n,bottomRight:s}=e,i=[...n,...s],{score:r,time:l}=j(e,0===eG.current.length),c={label:"portrait",base64:t.toDataURL("image/jpeg",.8).split(",")[1],landmarks:a,original_landmarks:a,score:r,time:l,index:eG.current.length,bbox:i,original_bbox:i,metadata:JSON.stringify({})};if(ed&&ed.key){if(c.base64=w.encryptFrameBase64(c.base64,ed.key),eG.current.push(c),e4.framesBatchLength>0&&eG.current.length%e4.framesBatchLength==0&&e_){let e=eG.current.slice(-e4.framesBatchLength);Promise.all(e.map(e=>e?.base64)).then(t=>{e_(e.map(({label:e,index:a},n)=>({base64:t[n],label:e,index:a}))),f&&ti.enableUploadFrames&&B(ed,e.map(({label:e,index:a},n)=>({base64:t[n],label:e,index:a})),eO,eG.current.length===e4.framesBatchLength)})}}else if(eG.current.push(c),e4.framesBatchLength>0&&eG.current.length%e4.framesBatchLength==0&&e_){let e=eG.current.slice(-e4.framesBatchLength);tn(e),e_(e.map(({base64:e,label:t,index:a,metadata:n})=>({base64:e,label:t,index:a,metadata:n}))),f&&ti.enableUploadFrames&&B(ed,e,eO,eG.current.length===e4.framesBatchLength)}return r}return null}(v[0],i,E,M>=O.length),isFirstValidFrameFoundRef:m})&&await l({faceDirection:x,canvas:i,blurScore:p,leftRightScore:D,isEyeClose:A})):M<O.length&&(o=tb[r.code],eP.current.image=R),eq(o),-1!==e&&(e=requestAnimationFrame(()=>c(a,i)))}async function o(){let e=p.analyzeVideoAndWindowSizes(t,eP.current),a=document.createElement("canvas");a.width=400,a.height=400;let n=a.getContext("2d");n.translate(400,0),n.scale(-1*eb,+eb);let{mediaRecorder:s}=ts&&t?await A({outputImagesSize:400,videoEl:t,resultAnalyzeVideoAndWindowSizes:e}):{};tg.current=s,tg.current&&tg.current.start(),c(e,a)}return ey&&eU&&setTimeout(()=>{o()},e3??ef),()=>{cancelAnimationFrame(e),e=-1}},[ev,e3,ef,ey,eB,eO,f,T,R,en,es,ei,er,e4,eo,eZ,eY.enable,ec,eq,ea,eQ,td,e0,tb,eU,tl,e_,ed,eb,e1?.enable,e1?.webThreshold,e1?.webTimeout,e1?.forceCheck,e6.enable,eA,tc,ts,ti,tk,e7,tn,e8.enable]);let{curStepIndex:tI,steps:tT}=eJ.current,tR=e.useMemo(()=>tT.find(e=>e.name===s.FaceDirection.FRONTAL),[tT]),tS=eC.current?tR:tT[tI],tL=tS&&eS?tS.instructions[eB]:null,tx=tS&&eS?tS.directionIcon:"";return{resetFlowOnOrientationChange:e5,cropArea:eP,curStepIndex:tI,directionIcon:tx,directionIconAnimation:tS?tS.directionIconAnimation:"",faceDetectionError:eK,resetFlow:td,handleVideoPlayed:tw,instructions:tL,refVideo:ex,refIsReseting:tu,steps:tT,videoPlayed:ey,activeCapturing:eT,isFirstValidFrameFound:eS,warmupDone:eU,showLoading:ek}}export{Z as u};
1
+ import{r as e,n as t,u as a,aG as n,s as s,c as i,a9 as r,d as l,I as c,ap as o,ao as m,f as g,L as u,b as _,aJ as f,aK as d,F as b,W as h,D as p,M as v,au as F,k as k,aA as w}from"./chunk-66453960.js";import{d as y}from"./chunk-fbc578b8.js";import{t as I}from"./chunk-b6640bda.js";import{w as T,m as R,n as S,t as L,u as x,o as B,q as D,r as E,v as A,s as M,x as O}from"./chunk-5510f102.js";import{m as N}from"./chunk-4ba29034.js";import{u as P}from"./chunk-d51c5685.js";let C=async({steps:e,apiClient:t,FaceDirection:a,outputEncryptionSettings:n,video:s})=>{let i=[];e.forEach(e=>{let{name:s,image:r,frontalFaceImage:l}=e;if(s!==a.FRONTAL){let e={label:"portrait",metadata:JSON.stringify({gesture_score:r.leftRightScore,gesture:s})};if(n&&n.key){let a=new Blob([r.encrypted.hex]);i.push(t.uploadImage({file:a,...e},{"X-TV-Key":n.key}))}else i.push(t.uploadImage({file:r.blob,...e}))}else i.push(Promise.resolve({data:{image_id:null}}));if(l.blob){let e={label:"portrait",metadata:JSON.stringify({gesture_score:l.leftRightScore,gesture:a.FRONTAL})};if(n&&n.key){let a=new Blob([l.encrypted.hex]);i.push(t.uploadImage({file:a,...e},{"X-TV-Key":n.key}))}else i.push(t.uploadImage({file:l.blob,...e}))}else i.push(Promise.resolve({data:{image_id:null}}))});let r=s?t.uploadFile({file:s,label:"video"}):Promise.resolve({data:{file_id:null}}),[l,...c]=await Promise.all([r,...i]);return e.forEach((e,t)=>{e.image.imageId=c[2*t].data.image_id,e.frontalFaceImage.imageId=c[2*t+1].data.image_id}),l},U=async({apiClient:e,faceVerificationFlowData:t,onLivenessDetectionDone:a,captureFrameSettings:n,FaceDirection:s,onError:i,outputEncryptionSettings:r,video:l,enabledServices:c,capturedFrames:o})=>{try{let i=t.current.steps;await C({steps:i,apiClient:e,FaceDirection:s,outputEncryptionSettings:r,video:l});let m=i.filter(e=>e.frontalFaceImage.imageId);if(0===m.length)a({error:"wrong_face_movement"});else{await T();let t=R(n);if(t){let n=null;c.enableVerifyFaceLiveness&&(n=e.verifyFaceLiveness({images:m.map(e=>({id:e.frontalFaceImage.imageId})),gesture_images:i.filter(e=>e.image.imageId&&e.name!==s.FRONTAL).map(({name:e,image:{imageId:t}})=>({gesture:e,images:[{id:t}]})),videos:t}));let r=null;c.enableVerifySanityPortrait&&(r=e.requestVerifyPortrait({image:{id:m[m.length-1].frontalFaceImage.imageId}}));let[l,g]=await Promise.all([n,r]),u=l?.data.is_live===!0;a({apiCheckPassed:u,verifyFaceLivenessResult:l?.data??null,verifyFacePortraitResult:g?.data??null,frontalFaces:m.map(e=>({id:e.frontalFaceImage.imageId,blob:e.frontalFaceImage.blob})),steps:i.filter(e=>e.image.imageId&&e.name!==s.FRONTAL).map(({name:e,image:t})=>({name:e,blob:t.blob,id:t.imageId})),uploadFramesResult:t,capturedFrames:o})}else a({error:"network_error"})}}catch(e){i({error:e})}},j=n.faceTracker(),V=new f,{FaceDirection:W,Errors:J,Messages:K,TrackLivenessEvents:$}=s,z={enable:!1,framesIntervalTime:180,framesBatchLength:0},q={[s.FaceDirection.UP]:{delayTime:0},[s.FaceDirection.LEFT]:{delayTime:0},[s.FaceDirection.RIGHT]:{delayTime:0},[s.FaceDirection.FRONTAL]:{delayTime:2e3}},G=()=>{},H=()=>{},X=()=>{};function Z({apiCheck:f,bgCameraMask:T,bgCameraMaskRed:R,surroundStyle:C,cropAreaDimension:Q,customInstructions:Y,customIcon:ee,customDirectionIcon:et,customStepTimeConstraints:ea=q,onLivenessDetectionDone:en,onError:es,frontalMinSize:ei,waitingTimeToGetBetterFrames:er=500,captureFrameSettings:el=z,setRemainingTime:ec=G,onProcessing:eo=X,customErrors:em,customMessages:eg,apiCredentials:eu={},onFramesCaptured:e_=H,initFirstGestureTimeout:ef=2e3,outputEncryptionSettings:ed,cameraScale:eb=1,sendCustomEvent:eh,serviceSettings:ep,currentOrientation:ev,onReset:eF}={}){let[ek,ew]=e.useState(!1),[ey,eI]=e.useState(!1),[eT,eR]=e.useState(!1),[eS,eL]=e.useState(!1),ex=e.useRef(null),{lang:eB,assetRoot:eD,customUrls:eE,exifKey:eA}=i.useSDKSettings(),eM=r.useSDKLocale(),{apiClient:eO}=l.useApiClient({apiCredentials:eu}),[,eN]=e.useReducer(e=>e+1,0),eP=e.useRef(null),eC=e.useRef(!1),[eU,ej]=e.useState(!1),eV=e.useRef({}),{sendEvent:eW}=c.useSDKTracking(),eJ=e.useRef(null);null===eJ.current&&(eJ.current=n.initFaceVerificationData({assetRoot:eD,customInstructions:Y,customIcon:ee,customDirectionIcon:et,customStepTimeConstraints:ea,Locale:eM,lang:eB}));let[eK,e$]=e.useState(),ez=e.useCallback(e=>{e$(e)},[]),eq=e.useMemo(()=>I(ez,500),[ez]),eG=e.useRef([]),eH=e.useRef(),eX=P(),{faceTrackingSetting:eZ,flowIntervalTimeMs:eQ,limitTimeLivenessCheck:eY,terminateIfNoFace:e0,closeEyeSettings:e1,captureFrameSettings:e4,exifDataSettings:e6,recordVideo:e2,waitBeforeStartFlowMs:e3,resetFlowOnOrientationChange:e5,autoGenFrameIds:e8}=function({captureFrameSettingsProp:n,clientSettings:s}){return e.useMemo(()=>{let e,i=N({},S,s),r={enable:t(i,"data.settings.sdk_settings.active_liveness_settings.face_tracking_setting.enable"),webTerminateThreshold:t(i,"data.settings.sdk_settings.active_liveness_settings.face_tracking_setting.web_terminate_threshold"),webWarningThreshold:t(i,"data.settings.sdk_settings.active_liveness_settings.face_tracking_setting.web_warning_threshold"),limitFor:t(i,"data.settings.sdk_settings.active_liveness_settings.face_tracking_setting.limit_for"),maxWarningTime:t(i,"data.settings.sdk_settings.active_liveness_settings.face_tracking_setting.max_warning_time")},l=t(i,"data.settings.sdk_settings.active_liveness_settings.reset_flow_on_orientation_change"),c=t(i,"data.settings.sdk_settings.active_liveness_settings.wait_before_start_flow_ms"),o=t(i,"data.settings.sdk_settings.active_liveness_settings.flow_interval_time_ms"),m=t(i,"data.settings.sdk_settings.active_liveness_settings.take_one_picture_time_ms"),g=a.getWebSetting(i,"data.settings.sdk_settings.active_liveness_settings.limit_time_liveness_check.max_retry_count"),u={enable:t(i,"data.settings.sdk_settings.active_liveness_settings.limit_time_liveness_check.enable"),limitTimeSecond:t(i,"data.settings.sdk_settings.active_liveness_settings.limit_time_liveness_check.limit_time_second"),remainTimeShow:t(i,"data.settings.sdk_settings.active_liveness_settings.limit_time_liveness_check.remain_time_show"),format:t(i,"data.settings.sdk_settings.active_liveness_settings.limit_time_liveness_check.format"),enableMaxRetries:g>0,totalMaxRetries:g,interruptible:!a.getWebSetting(i,"data.settings.sdk_settings.active_liveness_settings.limit_time_liveness_check.non_stoppable")},_={enable:t(i,"data.settings.sdk_settings.active_liveness_settings.terminate_if_no_face.enable"),maxInvalidFrame:t(i,"data.settings.sdk_settings.active_liveness_settings.terminate_if_no_face.max_invalid_frame"),maxTimeMs:t(i,"data.settings.sdk_settings.active_liveness_settings.terminate_if_no_face.max_time_ms")},f={enable:t(i,"data.settings.sdk_settings.active_liveness_settings.close_eye_detector.enable"),webThreshold:t(i,"data.settings.sdk_settings.active_liveness_settings.close_eye_detector.web_threshold"),webTimeout:t(i,"data.settings.sdk_settings.active_liveness_settings.close_eye_detector.web_timeout"),forceCheck:t(i,"data.settings.sdk_settings.active_liveness_settings.close_eye_detector.force_check")},d={enable:t(i,"data.settings.sdk_settings.active_liveness_settings.exif_data_settings.enable")},b={enable:t(i,"data.settings.sdk_settings.active_liveness_settings.record_video.enable")},h=t(s,"data.settings.sdk_settings.active_liveness_settings.save_encoded_frames");e=h?{enable:h.enable,enableLogging:h.enable_logging,framesBatchLength:h.frames_batch_len,framesIntervalTime:h.frames_interval_ms}:n;let p={enable:a.getWebSetting(i,"data.settings.sdk_settings.active_liveness_settings.auto_gen_frame_ids.enable")&&u.enable,maxItems:a.getWebSetting(i,"data.settings.sdk_settings.active_liveness_settings.auto_gen_frame_ids.max_items")};return{faceTrackingSetting:r,resetFlowOnOrientationChange:l,waitBeforeStartFlowMs:c,flowIntervalTimeMs:o,takeOnePictureTimeMs:m,limitTimeLivenessCheck:u,terminateIfNoFace:_,closeEyeSettings:f,exifDataSettings:d,recordVideo:b,captureFrameSettings:e,autoGenFrameIds:p}},[n,s])}({captureFrameSettingsProp:el,clientSettings:eX}),e9=1e3*eY.limitTimeSecond/e4.framesIntervalTime,{uuids:e7,getNextUUID:te,reset:tt}=o({total:Math.min(e8.maxItems,Math.ceil(e9/e4.framesBatchLength*1.2))}),ta=e.useRef(m.createSingleUUID()),tn=e.useCallback(e=>{let t=e[e.length-1];try{let e=JSON.parse(t.metadata);e8.enable&&(e.global_batch_id=te()),e.global_session_id=ta.current,t.metadata=JSON.stringify(e)}catch(e){console.error("Unable to process last frame metadata",e)}},[e8.enable,te]),ts=e2?.enable,ti=e.useMemo(()=>g.getEnabledServices(ep,eX),[eX,ep]),tr=e.useRef(""),tl=e.useCallback(e=>{if(e?.event){if(e.event===$?.show_alert){let t=e.log?.alert;if(t===tr.current)return;tr.current=t}eW(e),eh&&eh(e)}},[eh,eW]),tc=e.useMemo(()=>I(e=>{tl(e)},2e3),[tl]),to=e.useRef(0),tm=e.useRef(),tg=e.useRef();e.useEffect(()=>{tl({tag:"selfie",event:$?.start_camera,log:{}})},[tl]),e.useEffect(()=>(V.start(),()=>{V.stop()}),[]),e.useEffect(()=>{let e=!1;return async function t(){!eU&&(eH.current=performance.now(),eV.current=await d(eE),await b.initTensorFlow({preferredBackends:["wasm","webgl","cpu"]}),e||(ej(!0),tl({tag:"selfie",event:$?.show_warmup,log:{}}),tl({tag:"selfie",event:$?.finish_load_model,log:{status:"success",time_in_ms:performance.now()-eH.current}}),eH.current=null))}(),()=>{e=!0}},[eU,eE,tl]);let tu=e.useRef(!1),t_=e.useCallback(()=>{eJ.current.curStepIndex=eJ.current.steps.length,tu.current=!0,eR(!1),tg.current?.discardRecording()},[]),tf=e.useCallback(()=>{if(eJ.current=n.initFaceVerificationData({assetRoot:eD,customInstructions:Y,customIcon:ee,customDirectionIcon:et,Locale:eM,lang:eB}),to.current=0,tm.current=null,eG.current=[],eL(!1),e$(null),M(),tg.current?.start(),tu.current=!1,e8.enable){let e=tt();u.addExifData("frame_batch_ids",e)}"function"==typeof eF&&eF(),eN()},[eM,eD,e8.enable,et,ee,Y,eB,eF,tt]),td=e.useCallback(()=>{t_(),setTimeout(()=>{tf()},eQ)},[t_,eQ,tf]),tb=e.useMemo(()=>({...J,...em}),[em]),th=e.useMemo(()=>({...K,...eg}),[eg]),tp=e.useCallback(({remainTime:e})=>{if(e>0&&e<=eY.remainTimeShow){let t=L(th.REMAIN_TIME[eB]),a=e;switch(eY.format){case"mm:ss":a=e.toString().padStart(5,"00:00");break;case"ss":a=e.toString().padStart(2,"0")}ec(t({x:a}))}},[eB,eY.format,eY.remainTimeShow,th.REMAIN_TIME,ec]),tv=e.useCallback(()=>{let e={};Object.keys(tb.liveness_terminated_time_out?.msg).forEach(t=>{let a=L(tb.liveness_terminated_time_out?.msg[t]);e[t]=a({x:eY.limitTimeSecond})}),e$({...tb.liveness_terminated_time_out,msg:e,duration:.95*eQ}),tl({tag:"selfie",event:$?.show_alert,log:{alert:"liveness_terminated_time_out,"}}),V.stop(),ec(""),t_()},[tb.liveness_terminated_time_out,eQ,eY.limitTimeSecond,t_,tl,ec]),tF=e.useCallback(({attemptCount:e,fromBackground:t})=>{eY.enableMaxRetries&&e>=eY.totalMaxRetries&&es(s.Errors.max_retry_reached),t&&t_(),V.start(),tf()},[eY.enableMaxRetries,eY.totalMaxRetries,es,tf,t_]),{stopTimer:tk}=x({totalTime:eY.limitTimeSecond,totalDelayBetweenReset:eQ/1e3,interruptible:eY.interruptible,shouldStart:ey&&eY.enable&&eU,onTimesUp:tv,onTick:tp,onReset:tF}),tw=e.useCallback(({clientWidth:e,clientHeight:t,videoAreaWidth:a,videoAreaHeight:n,lostX:s,lostY:i})=>{let r,l;_.isMobile?l=r=a-40:(l=450,r=450);let c=Math.floor((a-r)/2)+s;eP.current={x:c,y:5+i,width:r,height:l,image:T,surroundStyle:C},"object"==typeof Q?eP.current={...eP.current,...Q}:"function"==typeof Q&&(eP.current={...eP.current,...Q({clientWidth:e,clientHeight:t,videoAreaWidth:a,videoAreaHeight:n,lostX:s,lostY:i,isMobile:_.isMobile,width:r,height:l})}),eN(),eI(!0)},[T,C,Q]),ty=e.useRef({});e.useEffect(()=>{ty.current.isFirstValidFrameFoundRef=eS},[eS]),e.useEffect(()=>{let e,t=ex.current,a=async()=>{let{steps:e}=eJ.current,t=[];e.map(e=>(t.push({name:e.name,blob:e.image.blob,captureTime:e.image.captureTime,gesture:e.name}),e.frontalFaceImage.blob&&t.push({name:e.name,blob:e.frontalFaceImage.blob,captureTime:e.frontalFaceImage.captureTime,gesture:W.FRONTAL}),0));let a=t.map(e=>h.resizeBlobImg(e.blob,400,400)),n=await Promise.all(a),s="0";if(e4.framesBatchLength>0){let e=`${Math.floor(eG.current.length/e4.framesBatchLength)}x${e4.framesBatchLength}`,t=eG.current.length%e4.framesBatchLength>0?`+${eG.current.length%e4.framesBatchLength}`:"";s=`${eG.current.length}:${e}${t}`}let i=n.map((e,a)=>{let n=u.parseLivenessImg({...t[a],frames:s});return u.writeCurrentExif({imageData:{blob:e},enableExifData:e6.enable,additionalData:n})}),r=await Promise.all(i),l=t.map((e,t)=>({name:e.name,blob:r[t]}));await Promise.all(e.map(async(t,a)=>{let n=l.filter(e=>e.name===t.name);if(e[a].image.blob=n[0].blob,t.frontalFaceImage.blob&&(e[a].frontalFaceImage.blob=n[1].blob),ed&&ed.key){let{key:s}=ed;e[a].image.encrypted=await v.encrypt({blob:n[0].blob,key:s}),t.frontalFaceImage.blob&&(e[a].frontalFaceImage.encrypted=await v.encrypt({blob:n[1].blob,key:s}))}return 0}))},i=async()=>{let{steps:e}=eJ.current,t=e[eJ.current.curStepIndex];if((t&&tl({tag:"selfie",event:{[s.FaceDirection.UP]:$?.capture_up_face,[s.FaceDirection.LEFT]:$?.capture_left_face,[s.FaceDirection.RIGHT]:$?.capture_right_face,[s.FaceDirection.FRONTAL]:$?.capture_frontal_face}[t.name],log:{time_capture_in_seconds:((performance.now()-eH.current)/1e3).toFixed(1)}}),eJ.current.curStepIndex++,eH.current=performance.now(),eZ.enable&&"each_gesture"===eZ.limitFor&&(to.current=0),eJ.current.curStepIndex===e.length)&&(eY.enable&&(V.stop(),tk(),ec("")),en)){let t=eG.current;if(ed&&ed.key){let e=await Promise.all(t.map(e=>e?.base64));if(t=t.map((t,a)=>({...t,base64:e[a]})),e4.enable&&e4.framesBatchLength>0&&t.length%e4.framesBatchLength>0){let e=t.slice(-1*(t.length%e4.framesBatchLength));e_(e),f&&B(ed,e,eO,t.length===e4.framesBatchLength)}}else if(e4.enable&&e4.framesBatchLength>0&&t.length%e4.framesBatchLength>0){let e=t.slice(-1*(t.length%e4.framesBatchLength));tn(e),e_(e.map(({base64:e,label:t,index:a,metadata:n})=>({base64:e,label:t,index:a,metadata:n}))),f&&ti.enableUploadFrames&&B(ed,e,eO)}tl({tag:"selfie",event:$?.finish_capture,log:{time_capture_in_seconds:V.duration("from_1st_frame")}}),eo(),await tg.current?.stopVideoRecording(),ew(!0),u.addExifData("user_action",{start_selfie:Date.now()-1e3*V.duration("from_1st_frame"),end_selfie:Date.now()}),u.addExifData("global_session_id",ta.current),e8.enable&&u.addExifData("frame_batch_ids",e7),await a();let n=eG.current;if(ed&&ed.key){let e=await Promise.all(n.map(e=>e?.base64));n=n.map((t,a)=>({...t,base64:e[a]}))}if(f&&ti.enableUploadImages)await U({apiClient:eO,faceVerificationFlowData:eJ,onLivenessDetectionDone:en,captureFrameSettings:e4,FaceDirection:W,onError:es,outputEncryptionSettings:ed,video:D().length?D()[0]:null,enabledServices:ti,capturedFrames:n});else{let t=e.filter(e=>e.name!==W.FRONTAL).map(e=>({name:e.name,image:{blob:e.image.blob,encrypted:e.image.encrypted}})),a=e.filter(e=>e.name!==W.FRONTAL).map(e=>e.frontalFaceImage.blob).filter(e=>null!==e),s=e.filter(e=>e.name!==W.FRONTAL).map(e=>e.frontalFaceImage.encrypted).filter(e=>e&&e.hex),i=e.find(e=>e.name===W.FRONTAL)?.image?.blob,r=e.find(e=>e.name===W.FRONTAL)?.image?.encrypted,l=i&&ei?await h.scaleImage(i,{minSize:ei}):null;i&&a.push(i),r&&s.push(r),tl({tag:"result",event:$?.liveness_detection_done,log:{result_object:{steps:t,frontalFaces:a,frontalScaledImage:l}}}),en({steps:t,frontalFaces:a,frontalFacesEncrypted:s,frontalScaledImage:l,capturedFrames:n,video:D().length?D()[0]:null}),E()}ew(!1)}eN()},r=y(()=>{let{curStepIndex:e,steps:t}=eJ.current,a=t[e],n=a?.image.blob!==null,s=a?.frontalFaceImage.blob!==null,r=t.filter(e=>e.frontalFaceImage.blob).length,l=!1;return n&&(s||![1].includes(e)||r>=1)?(eC.current=!1,i(),l=!0):n&&!s?eC.current=!0:eC.current=!1,eR(!1),l},er);async function l({faceDirection:e,canvas:t,blurScore:a,leftRightScore:n,isEyeClose:s}){let{curStepIndex:l,steps:c}=eJ.current;if(l<c.length){let o=c[l];if(O({faceDirection:e,curStep:o})||s)return;if(e===W.FRONTAL&&(null===o.frontalFaceImage.blurScore||F.hasBetterBlurScore(a,o.frontalFaceImage.blurScore))){o.frontalFaceImage.blurScore=a;let e=await p.takePicture({canvas:t});o.frontalFaceImage.blob=e,o.frontalFaceImage.leftRightScore=n,o.frontalFaceImage.captureTime=Date.now(),eC.current&&(eC.current=!1,i())}if(o.name===e&&(null===o.image.blurScore||F.hasBetterBlurScore(a,o.image.blurScore))){eR(!0),o.image.blurScore=a;let e=await p.takePicture({canvas:t});o.image.blob=e,o.image.leftRightScore=n,o.image.captureTime=Date.now(),o.image.objUrl&&URL.revokeObjectURL(o.image.objUrl),o.image.objUrl=URL.createObjectURL(e),r()}}}async function c(a,i){let r,o;if(i?.width===0||i?.height===0)return;let{isFirstValidFrameFoundRef:m}=ty.current,{cropX:g,cropY:u,cropWidth:_,cropHeight:d}=a;i.getContext("2d").drawImage(t,g,u,_,d,-((400*eb-400)/2)/eb,-((400*eb-400)/2)/eb,400,400);let{blazefaceModel:b,closeEyesModel:h}=eV.current,[p,v]=await Promise.all([F.calculateBlurScore(i),k.getModelPredictions({model:b,sCanvas:i})]),{error:y,fullFace:I,faceRatio:S,faceNotFrontalMinThreshold:L}=await n.validatePredictions({predictions:v,width:k.SIZE,height:k.SIZE});r=y,eP.current.image=T;let x=null,D=null,E=null,A=null,{curStepIndex:M,steps:O}=eJ.current;if(I){let e=O[M],t=e&&e.name===W.FRONTAL;E=I.landmarks;let a=await n.calculateFaceDirection({landmarks:E,getPerfectFrontal:t});a&&(x=a.gesture,D=a.leftRightScore);let l=e1?.webTimeout+ea[s.FaceDirection.FRONTAL].delayTime/1e3;if(t&&e1?.enable&&(-1===V.duration("limit_close_eye")||V.duration("limit_close_eye")<l)){e1?.forceCheck||-1!==V.duration("limit_close_eye")||V.start("limit_close_eye");let{isEyeClose:e}=await h.predict(i,E,e1?.webThreshold);(A=e)&&!r&&(r=J.close_eye)}}let N=r?.code==="no_face"||r?.code==="partial_face",P=M<O.length;!function({noFace:e,isFirstValidFrameFoundRef:t}){if(!e0.enable||!t)return;let{maxTimeMs:a}=e0;tm.current&&e||(tm.current={time:Date.now(),frame:0}),e&&tm.current.frame++;let{time:n}=tm.current;e&&Date.now()-n>=a&&(e$({...tb.liveness_terminated_no_face,duration:eQ}),tl({tag:"selfie",event:$?.show_alert,log:{alert:"liveness_terminated_no_face"}}),td())}({noFace:N&&P,isFirstValidFrameFoundRef:m}),r?.code&&tc({tag:"selfie",event:$?.show_alert,log:{alert:r.code}}),!r||"face_too_small"===r.code&&x!==W.FRONTAL&&S>=L?(m||(eL(!0),eH.current=performance.now(),V.start("from_1st_frame")),function({trackingScore:e,isFirstValidFrameFoundRef:t}){if(!eZ.enable||null===e||!t)return!0;let{webWarningThreshold:a,webTerminateThreshold:n,maxWarningTime:s}=eZ;return!!(e<a)||(e<n&&to.current<s?(to.current++,to.current===s?(e$({...tb.liveness_terminated_face_tracking,duration:eQ}),tl({tag:"selfie",event:$?.show_alert,log:{alert:"liveness_terminated_face_tracking"}})):e$({...tb.liveness_too_fast,duration:1500}),!0):(e$({...tb.liveness_terminated,duration:eQ}),tl({tag:"selfie",event:$?.show_alert,log:{alert:"liveness_terminated"}}),td(),!1))}({trackingScore:function(e,t,a,n){if(eG.current.length&&Date.now()-eG.current[eG.current.length-1].time<e4.framesIntervalTime)return null;if(e4.enable&&!n){let{topLeft:n,bottomRight:s}=e,i=[...n,...s],{score:r,time:l}=j(e,0===eG.current.length),c={label:"portrait",base64:t.toDataURL("image/jpeg",.8).split(",")[1],landmarks:a,original_landmarks:a,score:r,time:l,index:eG.current.length,bbox:i,original_bbox:i,metadata:JSON.stringify({})};if(ed&&ed.key){if(c.base64=w.encryptFrameBase64(c.base64,ed.key),eG.current.push(c),e4.framesBatchLength>0&&eG.current.length%e4.framesBatchLength==0&&e_){let e=eG.current.slice(-e4.framesBatchLength);Promise.all(e.map(e=>e?.base64)).then(t=>{e_(e.map(({label:e,index:a},n)=>({base64:t[n],label:e,index:a}))),f&&ti.enableUploadFrames&&B(ed,e.map(({label:e,index:a},n)=>({base64:t[n],label:e,index:a})),eO,eG.current.length===e4.framesBatchLength)})}}else if(eG.current.push(c),e4.framesBatchLength>0&&eG.current.length%e4.framesBatchLength==0&&e_){let e=eG.current.slice(-e4.framesBatchLength);tn(e),e_(e.map(({base64:e,label:t,index:a,metadata:n})=>({base64:e,label:t,index:a,metadata:n}))),f&&ti.enableUploadFrames&&B(ed,e,eO,eG.current.length===e4.framesBatchLength)}return r}return null}(v[0],i,E,M>=O.length),isFirstValidFrameFoundRef:m})&&await l({faceDirection:x,canvas:i,blurScore:p,leftRightScore:D,isEyeClose:A})):M<O.length&&(o=tb[r.code],eP.current.image=R),eq(o),-1!==e&&(e=requestAnimationFrame(()=>c(a,i)))}async function o(){let e=p.analyzeVideoAndWindowSizes(t,eP.current),a=document.createElement("canvas");a.width=400,a.height=400;let n=a.getContext("2d");n.translate(400,0),n.scale(-1*eb,+eb);let{mediaRecorder:s}=ts&&t?await A({outputImagesSize:400,videoEl:t,resultAnalyzeVideoAndWindowSizes:e}):{};tg.current=s,tg.current&&tg.current.start(),c(e,a)}return ey&&eU&&setTimeout(()=>{o()},e3??ef),()=>{cancelAnimationFrame(e),e=-1}},[ev,e3,ef,ey,eB,eO,f,T,R,en,es,ei,er,e4,eo,eZ,eY.enable,ec,eq,ea,eQ,td,e0,tb,eU,tl,e_,ed,eb,e1?.enable,e1?.webThreshold,e1?.webTimeout,e1?.forceCheck,e6.enable,eA,tc,ts,ti,tk,e7,tn,e8.enable]);let{curStepIndex:tI,steps:tT}=eJ.current,tR=e.useMemo(()=>tT.find(e=>e.name===s.FaceDirection.FRONTAL),[tT]),tS=eC.current?tR:tT[tI],tL=tS&&eS?tS.instructions[eB]:null,tx=tS&&eS?tS.directionIcon:"";return{resetFlowOnOrientationChange:e5,cropArea:eP,curStepIndex:tI,directionIcon:tx,directionIconAnimation:tS?tS.directionIconAnimation:"",faceDetectionError:eK,resetFlow:td,handleVideoPlayed:tw,instructions:tL,refVideo:ex,refIsReseting:tu,steps:tT,videoPlayed:ey,activeCapturing:eT,isFirstValidFrameFound:eS,warmupDone:eU,showLoading:ek}}export{Z as u};