@aws-amplify/ui-react-liveness 2.0.6 → 2.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/components/FaceLivenessDetector/LivenessCheck/LivenessCheck.mjs +1 -1
- package/dist/esm/components/FaceLivenessDetector/service/machine/index.mjs +1 -1
- package/dist/esm/components/FaceLivenessDetector/service/utils/CustomWebSocketFetchHandler.mjs +1 -0
- package/dist/esm/components/FaceLivenessDetector/service/utils/constants.mjs +1 -1
- package/dist/esm/components/FaceLivenessDetector/service/utils/streamProvider.mjs +1 -1
- package/dist/esm/components/FaceLivenessDetector/service/utils/videoRecorder.mjs +1 -1
- package/dist/esm/version.mjs +1 -1
- package/dist/index.js +1 -1
- package/dist/styles.css +83 -166
- package/dist/types/components/FaceLivenessDetector/LivenessCheck/LivenessCheck.d.ts +0 -3
- package/dist/types/components/FaceLivenessDetector/service/utils/CustomWebSocketFetchHandler.d.ts +37 -0
- package/dist/types/components/FaceLivenessDetector/service/utils/constants.d.ts +8 -0
- package/dist/types/components/FaceLivenessDetector/service/utils/streamProvider.d.ts +1 -1
- package/dist/types/components/FaceLivenessDetector/service/utils/videoRecorder.d.ts +4 -1
- package/dist/types/version.d.ts +1 -1
- package/package.json +5 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
import*as e from"react";import{Flex as t,Text as r,Button as s,View as i}from"@aws-amplify/ui-react";import"../service/machine/index.mjs";import"../service/types/liveness.mjs";import{LivenessErrorState as o}from"../service/types/error.mjs";import"tslib";import"@tensorflow/tfjs-core";import"@tensorflow-models/blazeface";import"@tensorflow/tfjs-backend-wasm";import"@tensorflow/tfjs-backend-cpu";import"@aws-amplify/core";import"../service/utils/liveness.mjs";import"../service/utils/streamProvider.mjs";import"../service/utils/freshnessColorDisplay.mjs";import{LivenessCameraModule as a}from"./LivenessCameraModule.mjs";import{useLivenessActor as n}from"../hooks/useLivenessActor.mjs";import{useLivenessSelector as m,createLivenessSelector as c}from"../hooks/useLivenessSelector.mjs";import"@aws-amplify/ui";import{isMobileScreen as p,getLandscapeMediaQuery as l}from"../utils/device.mjs";import{CancelButton as d}from"../shared/CancelButton.mjs";import{defaultErrorDisplayText as
|
|
1
|
+
import*as e from"react";import{Flex as t,Text as r,Button as s,View as i}from"@aws-amplify/ui-react";import"../service/machine/index.mjs";import"../service/types/liveness.mjs";import{LivenessErrorState as o}from"../service/types/error.mjs";import"tslib";import"@tensorflow/tfjs-core";import"@tensorflow-models/blazeface";import"@tensorflow/tfjs-backend-wasm";import"@tensorflow/tfjs-backend-cpu";import"@aws-amplify/core";import"../service/utils/liveness.mjs";import"../service/utils/streamProvider.mjs";import"../service/utils/freshnessColorDisplay.mjs";import{LivenessCameraModule as a}from"./LivenessCameraModule.mjs";import{useLivenessActor as n}from"../hooks/useLivenessActor.mjs";import{useLivenessSelector as m,createLivenessSelector as c}from"../hooks/useLivenessSelector.mjs";import"@aws-amplify/ui";import{isMobileScreen as p,getLandscapeMediaQuery as l}from"../utils/device.mjs";import{CancelButton as d}from"../shared/CancelButton.mjs";import{defaultErrorDisplayText as f}from"../displayText.mjs";import{LandscapeErrorModal as u}from"../shared/LandscapeErrorModal.mjs";import{selectErrorState as E}from"../shared/Hint.mjs";import"../types/classNames.mjs";const y="liveness-detector-check",g=c((e=>e.context.isRecordingStopped)),h=({hintDisplayText:c,cameraDisplayText:h,streamDisplayText:x,errorDisplayText:j,components:R})=>{const[T,A]=n(),v=m(E),C=m(g),M=T.matches("permissionDenied"),b=p(),L=()=>{A({type:"RETRY_CAMERA_CHECK"})},{cameraMinSpecificationsHeadingText:k,cameraMinSpecificationsMessageText:D,cameraNotFoundHeadingText:w,cameraNotFoundMessageText:_,retryCameraPermissionsText:N}=h,{cancelLivenessCheckText:S}=x;e.useLayoutEffect((()=>{if(b){const e=e=>{e&&A({type:"MOBILE_LANDSCAPE_WARNING"})},t=l();return e(t.matches),t.addEventListener("change",(t=>{e(t.matches)})),()=>{t.removeEventListener("change",(t=>e(t.matches)))}}}),[b,A]);return e.createElement(t,{direction:"column",position:"relative",testId:y,className:y},(()=>{if(v===o.MOBILE_LANDSCAPE_ERROR){const r=Object.assign(Object.assign({},f),j),{landscapeHeaderText:s,portraitMessageText:i,landscapeMessageText:o,tryAgainText:a}=r;return e.createElement(t,{backgroundColor:"background.primary",direction:"column",textAlign:"center",alignItems:"center",justifyContent:"center",position:"absolute",width:"100%"},e.createElement(u,{header:s,portraitMessage:i,landscapeMessage:o,tryAgainText:a,onRetry:()=>{A({type:"CANCEL"})}}))}return M?e.createElement(t,{backgroundColor:"background.primary",direction:"column",textAlign:"center",alignItems:"center",justifyContent:"center",width:"100%",height:480},e.createElement(r,{fontSize:"large",fontWeight:"bold"},v===o.CAMERA_FRAMERATE_ERROR?k:w),e.createElement(r,{maxWidth:300},v===o.CAMERA_FRAMERATE_ERROR?D:_),e.createElement(s,{variation:"primary",type:"button",onClick:L},N),e.createElement(i,{position:"absolute",top:"medium",right:"medium"},e.createElement(d,{ariaLabel:S}))):e.createElement(a,{isMobileScreen:b,isRecordingStopped:C,streamDisplayText:x,hintDisplayText:c,errorDisplayText:j,components:R})})())};export{h as LivenessCheck};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__awaiter as e,__asyncValues as t}from"tslib";import{createMachine as a,assign as o,spawn as r,actions as i}from"xstate";import{getBoundingBox as s,getColorsSequencesFromSessionInformation as n,isCameraDeviceVirtual as c,getFaceMatchState as d,isFaceDistanceBelowThreshold as l,estimateIllumination as v,getOvalDetailsFromSessionInformation as h,generateBboxFromLandmarks as m,drawLivenessOvalInCanvas as g,getOvalBoundingBox as f,getIntersectionOverUnion as u,getFaceMatchStateInLivenessOval as S,getStaticLivenessOvalDetails as p}from"../utils/liveness.mjs";import{FaceMatchState as F}from"../types/liveness.mjs";import{LivenessErrorState as D}from"../types/error.mjs";import{BlazeFaceFaceDetection as E}from"../utils/blazefaceFaceDetection.mjs";import{LivenessStreamProvider as A}from"../utils/streamProvider.mjs";import{FreshnessColorDisplay as M}from"../utils/freshnessColorDisplay.mjs";import{nanoid as R}from"nanoid";import{isServerSesssionInformationEvent as P,isDisconnectionEvent as C,isValidationExceptionEvent as T,isInternalServerExceptionEvent as O,isThrottlingExceptionEvent as w,isServiceQuotaExceededExceptionEvent as y,isInvalidSignatureRegionException as I}from"../utils/eventUtils.mjs";import{STATIC_VIDEO_CONSTRAINTS as b}from"../../StartLiveness/helpers.mjs";const k=500;let B;const j=a({id:"livenessMachine",initial:"start",predictableActionArguments:!0,context:{challengeId:R(),maxFailedAttempts:0,failedAttempts:0,componentProps:void 0,serverSessionInformation:void 0,videoAssociatedParams:{videoConstraints:b},ovalAssociatedParams:void 0,faceMatchAssociatedParams:{illuminationState:void 0,faceMatchState:void 0,faceMatchPercentage:25,currentDetectedFace:void 0,startFace:void 0,endFace:void 0,initialFaceMatchTime:void 0},freshnessColorAssociatedParams:{freshnessColorEl:void 0,freshnessColors:[],freshnessColorsComplete:!1,freshnessColorDisplay:void 0},errorState:void 0,livenessStreamProvider:void 0,responseStreamActorRef:void 0,shouldDisconnect:!1,faceMatchStateBeforeStart:void 0,isFaceFarEnoughBeforeRecording:void 0,isRecordingStopped:!1},on:{CANCEL:"userCancel",TIMEOUT:{target:"retryableTimeout",actions:"updateErrorStateForTimeout"},SET_SESSION_INFO:{internal:!0,actions:"updateSessionInfo"},DISCONNECT_EVENT:{internal:!0,actions:"updateShouldDisconnect"},SET_DOM_AND_CAMERA_DETAILS:{actions:"setDOMAndCameraDetails"},SERVER_ERROR:{target:"error",actions:"updateErrorStateForServer"},RUNTIME_ERROR:{target:"error"},MOBILE_LANDSCAPE_WARNING:{target:"mobileLandscapeWarning",actions:"updateErrorStateForServer"}},states:{start:{on:{BEGIN:"cameraCheck"}},cameraCheck:{entry:["resetErrorState","initializeFaceDetector"],invoke:{src:"checkVirtualCameraAndGetStream",onDone:{target:"waitForDOMAndCameraDetails",actions:["updateVideoMediaStream"]},onError:{target:"permissionDenied"}}},waitForDOMAndCameraDetails:{after:{0:{target:"detectFaceBeforeStart",cond:"hasDOMAndCameraDetails"},500:{target:"waitForDOMAndCameraDetails"}}},detectFaceBeforeStart:{invoke:{src:"detectFace",onDone:{target:"checkFaceDetectedBeforeStart",actions:["updateFaceMatchBeforeStartDetails"]}}},checkFaceDetectedBeforeStart:{after:{0:{target:"detectFaceDistanceBeforeRecording",cond:"hasSingleFaceBeforeStart"},100:{target:"detectFaceBeforeStart"}}},detectFaceDistanceBeforeRecording:{invoke:{src:"detectFaceDistance",onDone:{target:"checkFaceDistanceBeforeRecording",actions:["updateFaceDistanceBeforeRecording"]}}},checkFaceDistanceBeforeRecording:{after:{0:{target:"initializeLivenessStream",cond:"hasEnoughFaceDistanceBeforeRecording"},100:{target:"detectFaceDistanceBeforeRecording"}}},initializeLivenessStream:{invoke:{src:"openLivenessStreamConnection",onDone:{target:"notRecording",actions:["updateLivenessStreamProvider","spawnResponseStreamActor"]}}},notRecording:{on:{START_RECORDING:"recording"},initial:"waitForSessionInfo",states:{waitForSessionInfo:{after:{0:{target:"#livenessMachine.recording",cond:"hasServerSessionInfo"},100:{target:"detectFaceDistanceDuringLoading"}}},detectFaceDistanceDuringLoading:{invoke:{src:"detectFaceDistanceWhileLoading",onDone:{target:"checkFaceDistanceDuringLoading",actions:["updateFaceDistanceWhileLoading"]}}},checkFaceDistanceDuringLoading:{always:[{target:"failure",cond:"hasNotEnoughFaceDistanceBeforeRecording"},{target:"waitForSessionInfo"}]},failure:{entry:"sendTimeoutAfterFaceDistanceDelay",type:"final"}}},recording:{entry:["clearErrorState","startRecording"],initial:"ovalDrawing",states:{ovalDrawing:{entry:["sendTimeoutAfterOvalDrawingDelay"],invoke:{src:"detectInitialFaceAndDrawOval",onDone:{target:"checkFaceDetected",actions:["updateOvalAndFaceDetailsPostDraw","sendTimeoutAfterOvalMatchDelay"]},onError:{target:"#livenessMachine.error",actions:"updateErrorStateForRuntime"}}},checkFaceDetected:{after:{0:{target:"checkRecordingStarted",cond:"hasSingleFace"},100:{target:"ovalDrawing"}}},checkRecordingStarted:{after:{0:{target:"ovalMatching",cond:"hasRecordingStarted",actions:["updateRecordingStartTimestampMs"]},100:{target:"checkRecordingStarted"}}},ovalMatching:{entry:["cancelOvalDrawingTimeout"],invoke:{src:"detectFaceAndMatchOval",onDone:{target:"checkMatch",actions:"updateFaceDetailsPostMatch"}}},checkMatch:{after:{0:{target:"flashFreshnessColors",cond:"hasFaceMatchedInOvalWithMinTime",actions:["updateEndFaceMatch","setupFlashFreshnessColors","cancelOvalMatchTimeout","cancelOvalDrawingTimeout"]},.1:{target:"ovalMatching",cond:"hasFaceMatchedInOval",actions:"setFaceMatchTimeAndStartFace"},1:{target:"ovalMatching",cond:"hasNotFaceMatchedInOval"}}},flashFreshnessColors:{invoke:{src:"flashColors",onDone:[{target:"success",cond:"hasFreshnessColorShown"},{target:"flashFreshnessColors",actions:"updateFreshnessDetails"}]}},success:{entry:["stopRecording"],type:"final"}},onDone:"uploading"},uploading:{initial:"pending",states:{pending:{entry:["sendTimeoutAfterWaitingForDisconnect","pauseVideoStream"],invoke:{src:"stopVideo",onDone:"waitForDisconnectEvent",onError:{target:"#livenessMachine.error",actions:"updateErrorStateForRuntime"}}},waitForDisconnectEvent:{after:{0:{target:"getLivenessResult",cond:"getShouldDisconnect"},100:{target:"waitForDisconnectEvent"}}},getLivenessResult:{entry:["cancelWaitForDisconnectTimeout","freezeStream"],invoke:{src:"getLiveness",onError:{target:"#livenessMachine.error",actions:"updateErrorStateForServer"}}}}},retryableTimeout:{entry:"updateFailedAttempts",always:[{target:"timeout",cond:"shouldTimeoutOnFailedAttempts"},{target:"notRecording"}]},permissionDenied:{entry:"callUserPermissionDeniedCallback",on:{RETRY_CAMERA_CHECK:"cameraCheck"}},mobileLandscapeWarning:{entry:"callMobileLandscapeWarningCallback",always:[{target:"error"}]},timeout:{entry:["cleanUpResources","callUserTimeoutCallback","freezeStream"]},error:{entry:["cleanUpResources","callErrorCallback","cancelOvalDrawingTimeout","cancelWaitForDisconnectTimeout","cancelOvalMatchTimeout","freezeStream"]},userCancel:{entry:["cleanUpResources","callUserCancelCallback","resetContext"],always:[{target:"start"}]}}},{actions:{spawnResponseStreamActor:o({responseStreamActorRef:()=>r(_)}),updateFailedAttempts:o({failedAttempts:e=>e.failedAttempts+1}),updateVideoMediaStream:o({videoAssociatedParams:(e,t)=>{var a;return Object.assign(Object.assign({},e.videoAssociatedParams),{videoMediaStream:null===(a=t.data)||void 0===a?void 0:a.stream})}}),initializeFaceDetector:o({ovalAssociatedParams:e=>{const{componentProps:t}=e,{faceModelUrl:a,binaryPath:o}=t.config,r=new E(o,a);return r.triggerModelLoading(),Object.assign(Object.assign({},e.ovalAssociatedParams),{faceDetector:r})}}),updateLivenessStreamProvider:o({livenessStreamProvider:(e,t)=>{var a;return null===(a=t.data)||void 0===a?void 0:a.livenessStreamProvider}}),setDOMAndCameraDetails:o({videoAssociatedParams:(e,t)=>{var a,o,r;return Object.assign(Object.assign({},e.videoAssociatedParams),{videoEl:null===(a=t.data)||void 0===a?void 0:a.videoEl,canvasEl:null===(o=t.data)||void 0===o?void 0:o.canvasEl,isMobile:null===(r=t.data)||void 0===r?void 0:r.isMobile})},freshnessColorAssociatedParams:(e,t)=>{var a;return Object.assign(Object.assign({},e.freshnessColorAssociatedParams),{freshnessColorEl:null===(a=t.data)||void 0===a?void 0:a.freshnessColorEl})}}),updateRecordingStartTimestampMs:o({videoAssociatedParams:e=>{const{challengeId:t,videoAssociatedParams:a,ovalAssociatedParams:o,livenessStreamProvider:r}=e,{recordingStartApiTimestamp:i,recorderStartTimestamp:n}=r.videoRecorder,{videoMediaStream:c}=a,{initialFace:d}=o,l=Math.round(.73*(n-i)+i),{width:v,height:h}=c.getTracks()[0].getSettings(),m=v-d.left-d.width;return e.livenessStreamProvider.sendClientInfo({Challenge:{FaceMovementAndLightChallenge:{ChallengeId:t,VideoStartTimestamp:l,InitialFace:{InitialFaceDetectedTimestamp:d.timestampMs,BoundingBox:s({deviceHeight:h,deviceWidth:v,height:d.height,width:d.width,top:d.top,left:m})}}}}),Object.assign(Object.assign({},e.videoAssociatedParams),{recordingStartTimestampMs:l})}}),startRecording:o({videoAssociatedParams:e=>{if(!e.serverSessionInformation)throw new Error("Session information was not received from response stream");return e.livenessStreamProvider.videoRecorder&&"recording"!==e.livenessStreamProvider.videoRecorder.getState()&&e.livenessStreamProvider.startRecordingLivenessVideo(),Object.assign({},e.videoAssociatedParams)}}),stopRecording:e=>{},updateFaceMatchBeforeStartDetails:o({faceMatchStateBeforeStart:(e,t)=>t.data.faceMatchState}),updateFaceDistanceBeforeRecording:o({isFaceFarEnoughBeforeRecording:(e,t)=>t.data.isFaceFarEnoughBeforeRecording}),updateFaceDistanceWhileLoading:o({isFaceFarEnoughBeforeRecording:(e,t)=>t.data.isFaceFarEnoughBeforeRecording,errorState:(e,t)=>{var a;return null===(a=t.data)||void 0===a?void 0:a.error}}),updateOvalAndFaceDetailsPostDraw:o({ovalAssociatedParams:(e,t)=>Object.assign(Object.assign({},e.ovalAssociatedParams),{initialFace:t.data.initialFace,ovalDetails:t.data.ovalDetails,scaleFactor:t.data.scaleFactor}),faceMatchAssociatedParams:(e,t)=>Object.assign(Object.assign({},e.faceMatchAssociatedParams),{faceMatchState:t.data.faceMatchState,illuminationState:t.data.illuminationState})}),updateFaceDetailsPostMatch:o({faceMatchAssociatedParams:(e,t)=>Object.assign(Object.assign({},e.faceMatchAssociatedParams),{faceMatchState:t.data.faceMatchState,faceMatchPercentage:t.data.faceMatchPercentage,illuminationState:t.data.illuminationState,currentDetectedFace:t.data.detectedFace})}),updateEndFaceMatch:o({faceMatchAssociatedParams:e=>Object.assign(Object.assign({},e.faceMatchAssociatedParams),{endFace:e.faceMatchAssociatedParams.currentDetectedFace})}),setFaceMatchTimeAndStartFace:o({faceMatchAssociatedParams:e=>Object.assign(Object.assign({},e.faceMatchAssociatedParams),{startFace:void 0===e.faceMatchAssociatedParams.startFace?e.faceMatchAssociatedParams.currentDetectedFace:e.faceMatchAssociatedParams.startFace,initialFaceMatchTime:void 0===e.faceMatchAssociatedParams.initialFaceMatchTime?Date.now():e.faceMatchAssociatedParams.initialFaceMatchTime})}),resetErrorState:o({errorState:e=>{}}),updateErrorStateForTimeout:o({errorState:(e,t)=>{var a;return(null===(a=t.data)||void 0===a?void 0:a.errorState)||D.TIMEOUT}}),updateErrorStateForRuntime:o({errorState:(e,t)=>{var a;return(null===(a=t.data)||void 0===a?void 0:a.errorState)||D.RUNTIME_ERROR}}),updateErrorStateForServer:o({errorState:e=>D.SERVER_ERROR}),clearErrorState:o({errorState:e=>{}}),updateSessionInfo:o({serverSessionInformation:(e,t)=>t.data.sessionInfo}),updateShouldDisconnect:o({shouldDisconnect:e=>!0}),updateFreshnessDetails:o({freshnessColorAssociatedParams:(e,t)=>Object.assign(Object.assign({},e.freshnessColorAssociatedParams),{freshnessColorsComplete:t.data.freshnessColorsComplete})}),setupFlashFreshnessColors:o({freshnessColorAssociatedParams:e=>{const{serverSessionInformation:t}=e,a=n(t),o=new M(e,a);return Object.assign(Object.assign({},e.freshnessColorAssociatedParams),{freshnessColorDisplay:o})}}),sendTimeoutAfterOvalDrawingDelay:i.send({type:"TIMEOUT"},{delay:5e3,id:"ovalDrawingTimeout"}),cancelOvalDrawingTimeout:i.cancel("ovalDrawingTimeout"),sendTimeoutAfterOvalMatchDelay:i.send({type:"TIMEOUT"},{delay:7e3,id:"ovalMatchTimeout"}),cancelOvalMatchTimeout:i.cancel("ovalMatchTimeout"),sendTimeoutAfterWaitingForDisconnect:i.send({type:"TIMEOUT",data:{errorState:D.SERVER_ERROR}},{delay:2e4,id:"waitForDisconnectTimeout"}),cancelWaitForDisconnectTimeout:i.cancel("waitForDisconnectTimeout"),sendTimeoutAfterFaceDistanceDelay:i.send({type:"RUNTIME_ERROR",data:new Error("Avoid moving closer during countdown and ensure only one face is in front of camera.")},{delay:0,id:"faceDistanceTimeout"}),cancelFaceDistanceTimeout:i.cancel("faceDistanceTimeout"),callUserPermissionDeniedCallback:o({errorState:(e,t)=>{var a,o;let r;r=t.data.message.includes("15 fps")?D.CAMERA_FRAMERATE_ERROR:D.CAMERA_ACCESS_ERROR;const i=t.data.message||t.data.Message,s={state:r,error:new Error(i)};return null===(o=(a=e.componentProps).onError)||void 0===o||o.call(a,s),r}}),callMobileLandscapeWarningCallback:o({errorState:e=>D.MOBILE_LANDSCAPE_ERROR}),callUserCancelCallback:t=>e(void 0,void 0,void 0,(function*(){var e,a;null===(a=(e=t.componentProps).onUserCancel)||void 0===a||a.call(e)})),callUserTimeoutCallback:t=>e(void 0,void 0,void 0,(function*(){var e,a;const o=new Error("Client Timeout");o.name=t.errorState;const r={state:t.errorState,error:o};null===(a=(e=t.componentProps).onError)||void 0===a||a.call(e,r)})),callErrorCallback:(t,a)=>e(void 0,void 0,void 0,(function*(){var e,o,r;const i={state:t.errorState,error:(null===(e=a.data)||void 0===e?void 0:e.error)||a.data};null===(r=(o=t.componentProps).onError)||void 0===r||r.call(o,i)})),cleanUpResources:t=>e(void 0,void 0,void 0,(function*(){var e;const{freshnessColorEl:a}=t.freshnessColorAssociatedParams;a&&(a.style.display="none"),yield null===(e=t.livenessStreamProvider)||void 0===e?void 0:e.endStream()})),freezeStream:t=>e(void 0,void 0,void 0,(function*(){const{videoMediaStream:e,videoEl:a}=t.videoAssociatedParams;t.isRecordingStopped=!0,null==a||a.pause(),null==e||e.getTracks().forEach((function(e){e.stop()}))})),pauseVideoStream:t=>e(void 0,void 0,void 0,(function*(){const{videoEl:e}=t.videoAssociatedParams;t.isRecordingStopped=!0,e.pause()})),resetContext:o({challengeId:R(),maxFailedAttempts:0,failedAttempts:0,componentProps:e=>e.componentProps,serverSessionInformation:e=>{},videoAssociatedParams:e=>({videoConstraints:b}),ovalAssociatedParams:e=>{},errorState:e=>{},livenessStreamProvider:e=>{},responseStreamActorRef:e=>{},shouldDisconnect:!1,faceMatchStateBeforeStart:e=>{},isFaceFarEnoughBeforeRecording:e=>{},isRecordingStopped:!1})},guards:{shouldTimeoutOnFailedAttempts:e=>e.failedAttempts>=e.maxFailedAttempts,hasFaceMatchedInOvalWithMinTime:e=>{const{faceMatchState:t,initialFaceMatchTime:a}=e.faceMatchAssociatedParams,o=Date.now()-a;return t===F.MATCHED&&o>=500},hasFaceMatchedInOval:e=>e.faceMatchAssociatedParams.faceMatchState===F.MATCHED,hasNotFaceMatchedInOval:e=>e.faceMatchAssociatedParams.faceMatchState!==F.MATCHED,hasSingleFace:e=>e.faceMatchAssociatedParams.faceMatchState===F.FACE_IDENTIFIED,hasSingleFaceBeforeStart:e=>e.faceMatchStateBeforeStart===F.FACE_IDENTIFIED,hasEnoughFaceDistanceBeforeRecording:e=>e.isFaceFarEnoughBeforeRecording,hasNotEnoughFaceDistanceBeforeRecording:e=>!e.isFaceFarEnoughBeforeRecording,hasLivenessCheckSucceeded:(e,t,a)=>a.state.event.data.isLive,hasFreshnessColorShown:e=>e.freshnessColorAssociatedParams.freshnessColorsComplete,hasServerSessionInfo:e=>void 0!==e.serverSessionInformation,hasDOMAndCameraDetails:e=>void 0!==e.videoAssociatedParams.videoEl&&void 0!==e.videoAssociatedParams.canvasEl&&void 0!==e.freshnessColorAssociatedParams.freshnessColorEl,getShouldDisconnect:e=>!!e.shouldDisconnect,hasRecordingStarted:e=>void 0!==e.livenessStreamProvider.videoRecorder.firstChunkTimestamp},services:{checkVirtualCameraAndGetStream(t){return e(this,void 0,void 0,(function*(){const{videoConstraints:e}=t.videoAssociatedParams,a=yield navigator.mediaDevices.getUserMedia({video:e,audio:!1}),o=(yield navigator.mediaDevices.enumerateDevices()).filter((e=>"videoinput"===e.kind)).filter((e=>!c(e)));if(!o.length)throw new Error("No real video devices found");const r=a.getTracks().filter((e=>e.getSettings().frameRate>=15));if(r.length<1)throw new Error("No camera found with more than 15 fps");const i=r[0].getSettings().deviceId;let s=a;return o.some((e=>e.deviceId===i))||(s=yield navigator.mediaDevices.getUserMedia({video:Object.assign(Object.assign({},e),{deviceId:{exact:o[0].deviceId}}),audio:!1})),{stream:s}}))},openLivenessStreamConnection(t){return e(this,void 0,void 0,(function*(){const{config:e}=t.componentProps,{credentialProvider:a}=e,o=new A({sessionId:t.componentProps.sessionId,region:t.componentProps.region,stream:t.videoAssociatedParams.videoMediaStream,videoEl:t.videoAssociatedParams.videoEl,credentialProvider:a});return B=o.getResponseStream(),{livenessStreamProvider:o}}))},detectFace(t){return e(this,void 0,void 0,(function*(){const{videoEl:e}=t.videoAssociatedParams,{faceDetector:a}=t.ovalAssociatedParams;try{yield a.modelLoadingPromise}catch(e){console.log({err:e})}return{faceMatchState:yield d(a,e)}}))},detectFaceDistance(t){return e(this,void 0,void 0,(function*(){const{isFaceFarEnoughBeforeRecording:e}=t,{videoEl:a,videoMediaStream:o,isMobile:r}=t.videoAssociatedParams,{faceDetector:i}=t.ovalAssociatedParams,{width:s,height:n}=o.getTracks()[0].getSettings(),c=p({width:s,height:n}),{isDistanceBelowThreshold:d}=yield l({faceDetector:i,videoEl:a,ovalDetails:c,reduceThreshold:e,isMobile:r});return{isFaceFarEnoughBeforeRecording:d}}))},detectFaceDistanceWhileLoading(t){return e(this,void 0,void 0,(function*(){const{isFaceFarEnoughBeforeRecording:e}=t,{videoEl:a,videoMediaStream:o,isMobile:r}=t.videoAssociatedParams,{faceDetector:i}=t.ovalAssociatedParams,{width:s,height:n}=o.getTracks()[0].getSettings(),c=p({width:s,height:n}),{isDistanceBelowThreshold:d,error:v}=yield l({faceDetector:i,videoEl:a,ovalDetails:c,reduceThreshold:e,isMobile:r});return{isFaceFarEnoughBeforeRecording:d,error:v}}))},detectInitialFaceAndDrawOval(t){return e(this,void 0,void 0,(function*(){const{serverSessionInformation:e,livenessStreamProvider:a}=t,{videoEl:o,canvasEl:r,isMobile:i}=t.videoAssociatedParams,{faceDetector:s}=t.ovalAssociatedParams;try{yield s.modelLoadingPromise,yield a.videoRecorder.recorderStarted}catch(e){console.log({err:e})}const n=yield s.detectFaces(o);let c,d,l;switch(n.length){case 0:d=F.CANT_IDENTIFY,l=v(o);break;case 1:d=F.FACE_IDENTIFIED,c=n[0];break;default:d=F.TOO_MANY}if(!c)return{faceMatchState:d,illuminationState:l};const{width:f,height:u}=o.getBoundingClientRect();i?(r.width=window.innerWidth,r.height=window.innerHeight):(r.width=f,r.height=u);const S=f/o.videoWidth,p=h({sessionInformation:e,videoWidth:o.width}),D=m(c,p);return c.top=D.top,c.left=D.left,c.height=D.bottom-D.top,c.width=D.right-D.left,g({canvas:r,oval:p,scaleFactor:S,videoEl:o}),{faceMatchState:d,ovalDetails:p,scaleFactor:S,initialFace:c}}))},detectFaceAndMatchOval(t){return e(this,void 0,void 0,(function*(){const{serverSessionInformation:e}=t,{videoEl:a}=t.videoAssociatedParams,{faceDetector:o,ovalDetails:r,initialFace:i}=t.ovalAssociatedParams,s=yield o.detectFaces(a);let n,c,d,l=0;const h=m(i,r),{ovalBoundingBox:g}=f(r),p=u(h,g);switch(s.length){case 0:n=F.CANT_IDENTIFY,d=v(a);break;case 1:{c=s[0];const{faceMatchState:t,faceMatchPercentage:a}=S(c,r,p,e);n=t,l=a;break}default:n=F.TOO_MANY}return{faceMatchState:n,faceMatchPercentage:l,illuminationState:d,detectedFace:c}}))},flashColors(t){return e(this,void 0,void 0,(function*(){const{freshnessColorsComplete:e,freshnessColorDisplay:a}=t.freshnessColorAssociatedParams;if(e)return;return{freshnessColorsComplete:yield a.displayColorTick()}}))},stopVideo(t){return e(this,void 0,void 0,(function*(){const{challengeId:e,livenessStreamProvider:a}=t,{videoMediaStream:o}=t.videoAssociatedParams,{initialFace:r,ovalDetails:i}=t.ovalAssociatedParams,{startFace:n,endFace:c}=t.faceMatchAssociatedParams,{width:d,height:l}=o.getTracks()[0].getSettings(),v=d-r.left-r.width;yield a.stopVideo();const h={Challenge:{FaceMovementAndLightChallenge:{ChallengeId:e,InitialFace:{InitialFaceDetectedTimestamp:r.timestampMs,BoundingBox:s({deviceHeight:l,deviceWidth:d,height:r.height,width:r.width,top:r.top,left:v})},TargetFace:{FaceDetectedInTargetPositionStartTimestamp:n.timestampMs,FaceDetectedInTargetPositionEndTimestamp:c.timestampMs,BoundingBox:s({deviceHeight:l,deviceWidth:d,height:i.height,width:i.width,top:i.centerY-i.height/2,left:i.centerX-i.width/2})},VideoEndTimestamp:a.videoRecorder.recorderEndTimestamp}}};if(0===a.videoRecorder.getVideoChunkSize())throw new Error("Video chunks not recorded successfully.");a.sendClientInfo(h),yield a.dispatchStopVideoEvent()}))},getLiveness(t){return e(this,void 0,void 0,(function*(){const{onAnalysisComplete:e}=t.componentProps;yield e()}))}}}),_=a=>e(void 0,void 0,void 0,(function*(){var e,o,r,i;try{const d=yield B;try{for(var s,n=!0,c=t(d);!(e=(s=yield c.next()).done);){i=s.value,n=!1;try{const e=i;P(e)?a({type:"SET_SESSION_INFO",data:{sessionInfo:e.ServerSessionInformationEvent.SessionInformation}}):C(e)?a({type:"DISCONNECT_EVENT"}):T(e)?a({type:"SERVER_ERROR",data:{error:Object.assign({},e.ValidationException)}}):O(e)?a({type:"SERVER_ERROR",data:{error:Object.assign({},e.InternalServerException)}}):w(e)?a({type:"SERVER_ERROR",data:{error:Object.assign({},e.ThrottlingException)}}):y(e)&&a({type:"SERVER_ERROR",data:{error:Object.assign({},e.ServiceQuotaExceededException)}})}finally{n=!0}}}catch(e){o={error:e}}finally{try{n||e||!(r=c.return)||(yield r.call(c))}finally{if(o)throw o.error}}}catch(e){let t=e;I(e)&&(t=new Error("Invalid region in FaceLivenessDetector or credentials are scoped to the wrong region.")),t instanceof Error&&a({type:"SERVER_ERROR",data:{error:t}})}}));export{k as MIN_FACE_MATCH_TIME,j as livenessMachine};
|
|
1
|
+
import{__awaiter as e,__asyncValues as t}from"tslib";import{createMachine as a,assign as o,spawn as r,actions as i}from"xstate";import{getBoundingBox as s,getColorsSequencesFromSessionInformation as n,isCameraDeviceVirtual as c,getFaceMatchState as d,isFaceDistanceBelowThreshold as l,estimateIllumination as v,getOvalDetailsFromSessionInformation as m,generateBboxFromLandmarks as h,drawLivenessOvalInCanvas as g,getOvalBoundingBox as f,getIntersectionOverUnion as u,getFaceMatchStateInLivenessOval as S,getStaticLivenessOvalDetails as p}from"../utils/liveness.mjs";import{FaceMatchState as E}from"../types/liveness.mjs";import{LivenessErrorState as F}from"../types/error.mjs";import{BlazeFaceFaceDetection as D}from"../utils/blazefaceFaceDetection.mjs";import{LivenessStreamProvider as R}from"../utils/streamProvider.mjs";import{FreshnessColorDisplay as A}from"../utils/freshnessColorDisplay.mjs";import{nanoid as M}from"nanoid";import{isServerSesssionInformationEvent as C,isDisconnectionEvent as T,isValidationExceptionEvent as P,isInternalServerExceptionEvent as O,isThrottlingExceptionEvent as I,isServiceQuotaExceededExceptionEvent as w,isInvalidSignatureRegionException as y}from"../utils/eventUtils.mjs";import{STATIC_VIDEO_CONSTRAINTS as b}from"../../StartLiveness/helpers.mjs";import{WS_CLOSURE_CODE as k}from"../utils/constants.mjs";const _=500;let B;const N=a({id:"livenessMachine",initial:"start",predictableActionArguments:!0,context:{challengeId:M(),maxFailedAttempts:0,failedAttempts:0,componentProps:void 0,serverSessionInformation:void 0,videoAssociatedParams:{videoConstraints:b},ovalAssociatedParams:void 0,faceMatchAssociatedParams:{illuminationState:void 0,faceMatchState:void 0,faceMatchPercentage:25,currentDetectedFace:void 0,startFace:void 0,endFace:void 0,initialFaceMatchTime:void 0},freshnessColorAssociatedParams:{freshnessColorEl:void 0,freshnessColors:[],freshnessColorsComplete:!1,freshnessColorDisplay:void 0},errorState:void 0,livenessStreamProvider:void 0,responseStreamActorRef:void 0,shouldDisconnect:!1,faceMatchStateBeforeStart:void 0,isFaceFarEnoughBeforeRecording:void 0,isRecordingStopped:!1},on:{CANCEL:"userCancel",TIMEOUT:{target:"retryableTimeout",actions:"updateErrorStateForTimeout"},SET_SESSION_INFO:{internal:!0,actions:"updateSessionInfo"},DISCONNECT_EVENT:{internal:!0,actions:"updateShouldDisconnect"},SET_DOM_AND_CAMERA_DETAILS:{actions:"setDOMAndCameraDetails"},SERVER_ERROR:{target:"error",actions:"updateErrorStateForServer"},RUNTIME_ERROR:{target:"error"},MOBILE_LANDSCAPE_WARNING:{target:"mobileLandscapeWarning",actions:"updateErrorStateForServer"}},states:{start:{on:{BEGIN:"cameraCheck"}},cameraCheck:{entry:["resetErrorState","initializeFaceDetector"],invoke:{src:"checkVirtualCameraAndGetStream",onDone:{target:"waitForDOMAndCameraDetails",actions:["updateVideoMediaStream"]},onError:{target:"permissionDenied"}}},waitForDOMAndCameraDetails:{after:{0:{target:"detectFaceBeforeStart",cond:"hasDOMAndCameraDetails"},500:{target:"waitForDOMAndCameraDetails"}}},detectFaceBeforeStart:{invoke:{src:"detectFace",onDone:{target:"checkFaceDetectedBeforeStart",actions:["updateFaceMatchBeforeStartDetails"]}}},checkFaceDetectedBeforeStart:{after:{0:{target:"detectFaceDistanceBeforeRecording",cond:"hasSingleFaceBeforeStart"},100:{target:"detectFaceBeforeStart"}}},detectFaceDistanceBeforeRecording:{invoke:{src:"detectFaceDistance",onDone:{target:"checkFaceDistanceBeforeRecording",actions:["updateFaceDistanceBeforeRecording"]}}},checkFaceDistanceBeforeRecording:{after:{0:{target:"initializeLivenessStream",cond:"hasEnoughFaceDistanceBeforeRecording"},100:{target:"detectFaceDistanceBeforeRecording"}}},initializeLivenessStream:{invoke:{src:"openLivenessStreamConnection",onDone:{target:"notRecording",actions:["updateLivenessStreamProvider","spawnResponseStreamActor"]}}},notRecording:{on:{START_RECORDING:"recording"},initial:"waitForSessionInfo",states:{waitForSessionInfo:{after:{0:{target:"#livenessMachine.recording",cond:"hasServerSessionInfo"},100:{target:"detectFaceDistanceDuringLoading"}}},detectFaceDistanceDuringLoading:{invoke:{src:"detectFaceDistanceWhileLoading",onDone:{target:"checkFaceDistanceDuringLoading",actions:["updateFaceDistanceWhileLoading"]}}},checkFaceDistanceDuringLoading:{always:[{target:"failure",cond:"hasNotEnoughFaceDistanceBeforeRecording"},{target:"waitForSessionInfo"}]},failure:{entry:"sendTimeoutAfterFaceDistanceDelay",type:"final"}}},recording:{entry:["clearErrorState","startRecording"],initial:"ovalDrawing",states:{ovalDrawing:{entry:["sendTimeoutAfterOvalDrawingDelay"],invoke:{src:"detectInitialFaceAndDrawOval",onDone:{target:"checkFaceDetected",actions:["updateOvalAndFaceDetailsPostDraw","sendTimeoutAfterOvalMatchDelay"]},onError:{target:"#livenessMachine.error",actions:"updateErrorStateForRuntime"}}},checkFaceDetected:{after:{0:{target:"checkRecordingStarted",cond:"hasSingleFace"},100:{target:"ovalDrawing"}}},checkRecordingStarted:{after:{0:{target:"ovalMatching",cond:"hasRecordingStarted",actions:["updateRecordingStartTimestampMs"]},100:{target:"checkRecordingStarted"}}},ovalMatching:{entry:["cancelOvalDrawingTimeout"],invoke:{src:"detectFaceAndMatchOval",onDone:{target:"checkMatch",actions:"updateFaceDetailsPostMatch"}}},checkMatch:{after:{0:{target:"flashFreshnessColors",cond:"hasFaceMatchedInOvalWithMinTime",actions:["updateEndFaceMatch","setupFlashFreshnessColors","cancelOvalMatchTimeout","cancelOvalDrawingTimeout"]},.1:{target:"ovalMatching",cond:"hasFaceMatchedInOval",actions:"setFaceMatchTimeAndStartFace"},1:{target:"ovalMatching",cond:"hasNotFaceMatchedInOval"}}},flashFreshnessColors:{invoke:{src:"flashColors",onDone:[{target:"success",cond:"hasFreshnessColorShown"},{target:"flashFreshnessColors",actions:"updateFreshnessDetails"}]}},success:{entry:["stopRecording"],type:"final"}},onDone:"uploading"},uploading:{initial:"pending",states:{pending:{entry:["sendTimeoutAfterWaitingForDisconnect","pauseVideoStream"],invoke:{src:"stopVideo",onDone:"waitForDisconnectEvent",onError:{target:"#livenessMachine.error",actions:"updateErrorStateForRuntime"}}},waitForDisconnectEvent:{after:{0:{target:"getLivenessResult",cond:"getShouldDisconnect"},100:{target:"waitForDisconnectEvent"}}},getLivenessResult:{entry:["cancelWaitForDisconnectTimeout","freezeStream"],invoke:{src:"getLiveness",onError:{target:"#livenessMachine.error",actions:"updateErrorStateForServer"}}}}},retryableTimeout:{entry:"updateFailedAttempts",always:[{target:"timeout",cond:"shouldTimeoutOnFailedAttempts"},{target:"notRecording"}]},permissionDenied:{entry:"callUserPermissionDeniedCallback",on:{RETRY_CAMERA_CHECK:"cameraCheck"}},mobileLandscapeWarning:{entry:"callMobileLandscapeWarningCallback",always:[{target:"error"}]},timeout:{entry:["cleanUpResources","callUserTimeoutCallback","freezeStream"]},error:{entry:["cleanUpResources","callErrorCallback","cancelOvalDrawingTimeout","cancelWaitForDisconnectTimeout","cancelOvalMatchTimeout","freezeStream"]},userCancel:{entry:["cleanUpResources","callUserCancelCallback","resetContext"],always:[{target:"start"}]}}},{actions:{spawnResponseStreamActor:o({responseStreamActorRef:()=>r(L)}),updateFailedAttempts:o({failedAttempts:e=>e.failedAttempts+1}),updateVideoMediaStream:o({videoAssociatedParams:(e,t)=>{var a;return Object.assign(Object.assign({},e.videoAssociatedParams),{videoMediaStream:null===(a=t.data)||void 0===a?void 0:a.stream})}}),initializeFaceDetector:o({ovalAssociatedParams:e=>{const{componentProps:t}=e,{faceModelUrl:a,binaryPath:o}=t.config,r=new D(o,a);return r.triggerModelLoading(),Object.assign(Object.assign({},e.ovalAssociatedParams),{faceDetector:r})}}),updateLivenessStreamProvider:o({livenessStreamProvider:(e,t)=>{var a;return null===(a=t.data)||void 0===a?void 0:a.livenessStreamProvider}}),setDOMAndCameraDetails:o({videoAssociatedParams:(e,t)=>{var a,o,r;return Object.assign(Object.assign({},e.videoAssociatedParams),{videoEl:null===(a=t.data)||void 0===a?void 0:a.videoEl,canvasEl:null===(o=t.data)||void 0===o?void 0:o.canvasEl,isMobile:null===(r=t.data)||void 0===r?void 0:r.isMobile})},freshnessColorAssociatedParams:(e,t)=>{var a;return Object.assign(Object.assign({},e.freshnessColorAssociatedParams),{freshnessColorEl:null===(a=t.data)||void 0===a?void 0:a.freshnessColorEl})}}),updateRecordingStartTimestampMs:o({videoAssociatedParams:e=>{const{challengeId:t,videoAssociatedParams:a,ovalAssociatedParams:o,livenessStreamProvider:r}=e,{recordingStartApiTimestamp:i,recorderStartTimestamp:n}=r.videoRecorder,{videoMediaStream:c}=a,{initialFace:d}=o,l=Math.round(.73*(n-i)+i),{width:v,height:m}=c.getTracks()[0].getSettings(),h=v-d.left-d.width;return e.livenessStreamProvider.sendClientInfo({Challenge:{FaceMovementAndLightChallenge:{ChallengeId:t,VideoStartTimestamp:l,InitialFace:{InitialFaceDetectedTimestamp:d.timestampMs,BoundingBox:s({deviceHeight:m,deviceWidth:v,height:d.height,width:d.width,top:d.top,left:h})}}}}),Object.assign(Object.assign({},e.videoAssociatedParams),{recordingStartTimestampMs:l})}}),startRecording:o({videoAssociatedParams:e=>{if(!e.serverSessionInformation)throw new Error("Session information was not received from response stream");return e.livenessStreamProvider.videoRecorder&&"recording"!==e.livenessStreamProvider.videoRecorder.getState()&&e.livenessStreamProvider.startRecordingLivenessVideo(),Object.assign({},e.videoAssociatedParams)}}),stopRecording:e=>{},updateFaceMatchBeforeStartDetails:o({faceMatchStateBeforeStart:(e,t)=>t.data.faceMatchState}),updateFaceDistanceBeforeRecording:o({isFaceFarEnoughBeforeRecording:(e,t)=>t.data.isFaceFarEnoughBeforeRecording}),updateFaceDistanceWhileLoading:o({isFaceFarEnoughBeforeRecording:(e,t)=>t.data.isFaceFarEnoughBeforeRecording,errorState:(e,t)=>{var a;return null===(a=t.data)||void 0===a?void 0:a.error}}),updateOvalAndFaceDetailsPostDraw:o({ovalAssociatedParams:(e,t)=>Object.assign(Object.assign({},e.ovalAssociatedParams),{initialFace:t.data.initialFace,ovalDetails:t.data.ovalDetails,scaleFactor:t.data.scaleFactor}),faceMatchAssociatedParams:(e,t)=>Object.assign(Object.assign({},e.faceMatchAssociatedParams),{faceMatchState:t.data.faceMatchState,illuminationState:t.data.illuminationState})}),updateFaceDetailsPostMatch:o({faceMatchAssociatedParams:(e,t)=>Object.assign(Object.assign({},e.faceMatchAssociatedParams),{faceMatchState:t.data.faceMatchState,faceMatchPercentage:t.data.faceMatchPercentage,illuminationState:t.data.illuminationState,currentDetectedFace:t.data.detectedFace})}),updateEndFaceMatch:o({faceMatchAssociatedParams:e=>Object.assign(Object.assign({},e.faceMatchAssociatedParams),{endFace:e.faceMatchAssociatedParams.currentDetectedFace})}),setFaceMatchTimeAndStartFace:o({faceMatchAssociatedParams:e=>Object.assign(Object.assign({},e.faceMatchAssociatedParams),{startFace:void 0===e.faceMatchAssociatedParams.startFace?e.faceMatchAssociatedParams.currentDetectedFace:e.faceMatchAssociatedParams.startFace,initialFaceMatchTime:void 0===e.faceMatchAssociatedParams.initialFaceMatchTime?Date.now():e.faceMatchAssociatedParams.initialFaceMatchTime})}),resetErrorState:o({errorState:e=>{}}),updateErrorStateForTimeout:o({errorState:(e,t)=>{var a;return(null===(a=t.data)||void 0===a?void 0:a.errorState)||F.TIMEOUT}}),updateErrorStateForRuntime:o({errorState:(e,t)=>{var a;return(null===(a=t.data)||void 0===a?void 0:a.errorState)||F.RUNTIME_ERROR}}),updateErrorStateForServer:o({errorState:e=>F.SERVER_ERROR}),clearErrorState:o({errorState:e=>{}}),updateSessionInfo:o({serverSessionInformation:(e,t)=>t.data.sessionInfo}),updateShouldDisconnect:o({shouldDisconnect:e=>!0}),updateFreshnessDetails:o({freshnessColorAssociatedParams:(e,t)=>Object.assign(Object.assign({},e.freshnessColorAssociatedParams),{freshnessColorsComplete:t.data.freshnessColorsComplete})}),setupFlashFreshnessColors:o({freshnessColorAssociatedParams:e=>{const{serverSessionInformation:t}=e,a=n(t),o=new A(e,a);return Object.assign(Object.assign({},e.freshnessColorAssociatedParams),{freshnessColorDisplay:o})}}),sendTimeoutAfterOvalDrawingDelay:i.send({type:"TIMEOUT"},{delay:5e3,id:"ovalDrawingTimeout"}),cancelOvalDrawingTimeout:i.cancel("ovalDrawingTimeout"),sendTimeoutAfterOvalMatchDelay:i.send({type:"TIMEOUT"},{delay:e=>{var t,a,o,r;return(null===(r=null===(o=null===(a=null===(t=e.serverSessionInformation)||void 0===t?void 0:t.Challenge)||void 0===a?void 0:a.FaceMovementAndLightChallenge)||void 0===o?void 0:o.ChallengeConfig)||void 0===r?void 0:r.OvalFitTimeout)||7e3},id:"ovalMatchTimeout"}),cancelOvalMatchTimeout:i.cancel("ovalMatchTimeout"),sendTimeoutAfterWaitingForDisconnect:i.send({type:"TIMEOUT",data:{errorState:F.SERVER_ERROR}},{delay:2e4,id:"waitForDisconnectTimeout"}),cancelWaitForDisconnectTimeout:i.cancel("waitForDisconnectTimeout"),sendTimeoutAfterFaceDistanceDelay:i.send({type:"RUNTIME_ERROR",data:new Error("Avoid moving closer during countdown and ensure only one face is in front of camera.")},{delay:0,id:"faceDistanceTimeout"}),cancelFaceDistanceTimeout:i.cancel("faceDistanceTimeout"),callUserPermissionDeniedCallback:o({errorState:(e,t)=>{var a,o;let r;r=t.data.message.includes("15 fps")?F.CAMERA_FRAMERATE_ERROR:F.CAMERA_ACCESS_ERROR;const i=t.data.message||t.data.Message,s={state:r,error:new Error(i)};return null===(o=(a=e.componentProps).onError)||void 0===o||o.call(a,s),r}}),callMobileLandscapeWarningCallback:o({errorState:e=>F.MOBILE_LANDSCAPE_ERROR}),callUserCancelCallback:t=>e(void 0,void 0,void 0,(function*(){var e,a;null===(a=(e=t.componentProps).onUserCancel)||void 0===a||a.call(e)})),callUserTimeoutCallback:t=>e(void 0,void 0,void 0,(function*(){var e,a;const o=new Error("Client Timeout");o.name=t.errorState;const r={state:t.errorState,error:o};null===(a=(e=t.componentProps).onError)||void 0===a||a.call(e,r)})),callErrorCallback:(t,a)=>e(void 0,void 0,void 0,(function*(){var e,o,r;const i={state:t.errorState,error:(null===(e=a.data)||void 0===e?void 0:e.error)||a.data};null===(r=(o=t.componentProps).onError)||void 0===r||r.call(o,i)})),cleanUpResources:t=>e(void 0,void 0,void 0,(function*(){var e;const{freshnessColorEl:a}=t.freshnessColorAssociatedParams;a&&(a.style.display="none");let o=k.DEFAULT_ERROR_CODE;t.errorState===F.TIMEOUT?o=k.FACE_FIT_TIMEOUT:t.errorState===F.RUNTIME_ERROR?o=k.RUNTIME_ERROR:t.errorState===F.FACE_DISTANCE_ERROR||t.errorState===F.MULTIPLE_FACES_ERROR?o=k.USER_ERROR_DURING_CONNECTION:void 0===t.errorState&&(o=k.USER_CANCEL),yield null===(e=t.livenessStreamProvider)||void 0===e?void 0:e.endStreamWithCode(o)})),freezeStream:t=>e(void 0,void 0,void 0,(function*(){const{videoMediaStream:e,videoEl:a}=t.videoAssociatedParams;t.isRecordingStopped=!0,null==a||a.pause(),null==e||e.getTracks().forEach((function(e){e.stop()}))})),pauseVideoStream:t=>e(void 0,void 0,void 0,(function*(){const{videoEl:e}=t.videoAssociatedParams;t.isRecordingStopped=!0,e.pause()})),resetContext:o({challengeId:M(),maxFailedAttempts:0,failedAttempts:0,componentProps:e=>e.componentProps,serverSessionInformation:e=>{},videoAssociatedParams:e=>({videoConstraints:b}),ovalAssociatedParams:e=>{},errorState:e=>{},livenessStreamProvider:e=>{},responseStreamActorRef:e=>{},shouldDisconnect:!1,faceMatchStateBeforeStart:e=>{},isFaceFarEnoughBeforeRecording:e=>{},isRecordingStopped:!1})},guards:{shouldTimeoutOnFailedAttempts:e=>e.failedAttempts>=e.maxFailedAttempts,hasFaceMatchedInOvalWithMinTime:e=>{const{faceMatchState:t,initialFaceMatchTime:a}=e.faceMatchAssociatedParams,o=Date.now()-a;return t===E.MATCHED&&o>=500},hasFaceMatchedInOval:e=>e.faceMatchAssociatedParams.faceMatchState===E.MATCHED,hasNotFaceMatchedInOval:e=>e.faceMatchAssociatedParams.faceMatchState!==E.MATCHED,hasSingleFace:e=>e.faceMatchAssociatedParams.faceMatchState===E.FACE_IDENTIFIED,hasSingleFaceBeforeStart:e=>e.faceMatchStateBeforeStart===E.FACE_IDENTIFIED,hasEnoughFaceDistanceBeforeRecording:e=>e.isFaceFarEnoughBeforeRecording,hasNotEnoughFaceDistanceBeforeRecording:e=>!e.isFaceFarEnoughBeforeRecording,hasLivenessCheckSucceeded:(e,t,a)=>a.state.event.data.isLive,hasFreshnessColorShown:e=>e.freshnessColorAssociatedParams.freshnessColorsComplete,hasServerSessionInfo:e=>void 0!==e.serverSessionInformation,hasDOMAndCameraDetails:e=>void 0!==e.videoAssociatedParams.videoEl&&void 0!==e.videoAssociatedParams.canvasEl&&void 0!==e.freshnessColorAssociatedParams.freshnessColorEl,getShouldDisconnect:e=>!!e.shouldDisconnect,hasRecordingStarted:e=>void 0!==e.livenessStreamProvider.videoRecorder.firstChunkTimestamp},services:{checkVirtualCameraAndGetStream(t){return e(this,void 0,void 0,(function*(){const{videoConstraints:e}=t.videoAssociatedParams,a=yield navigator.mediaDevices.getUserMedia({video:e,audio:!1}),o=(yield navigator.mediaDevices.enumerateDevices()).filter((e=>"videoinput"===e.kind)).filter((e=>!c(e)));if(!o.length)throw new Error("No real video devices found");const r=a.getTracks().filter((e=>e.getSettings().frameRate>=15));if(r.length<1)throw new Error("No camera found with more than 15 fps");const i=r[0].getSettings().deviceId;let s=a;return o.some((e=>e.deviceId===i))||(s=yield navigator.mediaDevices.getUserMedia({video:Object.assign(Object.assign({},e),{deviceId:{exact:o[0].deviceId}}),audio:!1})),{stream:s}}))},openLivenessStreamConnection(t){return e(this,void 0,void 0,(function*(){const{config:e}=t.componentProps,{credentialProvider:a}=e,o=new R({sessionId:t.componentProps.sessionId,region:t.componentProps.region,stream:t.videoAssociatedParams.videoMediaStream,videoEl:t.videoAssociatedParams.videoEl,credentialProvider:a});return B=o.getResponseStream(),{livenessStreamProvider:o}}))},detectFace(t){return e(this,void 0,void 0,(function*(){const{videoEl:e}=t.videoAssociatedParams,{faceDetector:a}=t.ovalAssociatedParams;try{yield a.modelLoadingPromise}catch(e){console.log({err:e})}return{faceMatchState:yield d(a,e)}}))},detectFaceDistance(t){return e(this,void 0,void 0,(function*(){const{isFaceFarEnoughBeforeRecording:e}=t,{videoEl:a,videoMediaStream:o,isMobile:r}=t.videoAssociatedParams,{faceDetector:i}=t.ovalAssociatedParams,{width:s,height:n}=o.getTracks()[0].getSettings(),c=p({width:s,height:n}),{isDistanceBelowThreshold:d}=yield l({faceDetector:i,videoEl:a,ovalDetails:c,reduceThreshold:e,isMobile:r});return{isFaceFarEnoughBeforeRecording:d}}))},detectFaceDistanceWhileLoading(t){return e(this,void 0,void 0,(function*(){const{isFaceFarEnoughBeforeRecording:e}=t,{videoEl:a,videoMediaStream:o,isMobile:r}=t.videoAssociatedParams,{faceDetector:i}=t.ovalAssociatedParams,{width:s,height:n}=o.getTracks()[0].getSettings(),c=p({width:s,height:n}),{isDistanceBelowThreshold:d,error:v}=yield l({faceDetector:i,videoEl:a,ovalDetails:c,reduceThreshold:e,isMobile:r});return{isFaceFarEnoughBeforeRecording:d,error:v}}))},detectInitialFaceAndDrawOval(t){return e(this,void 0,void 0,(function*(){const{serverSessionInformation:e,livenessStreamProvider:a}=t,{videoEl:o,canvasEl:r,isMobile:i}=t.videoAssociatedParams,{faceDetector:s}=t.ovalAssociatedParams;try{yield s.modelLoadingPromise,yield a.videoRecorder.recorderStarted}catch(e){console.log({err:e})}const n=yield s.detectFaces(o);let c,d,l;switch(n.length){case 0:d=E.CANT_IDENTIFY,l=v(o);break;case 1:d=E.FACE_IDENTIFIED,c=n[0];break;default:d=E.TOO_MANY}if(!c)return{faceMatchState:d,illuminationState:l};const{width:f,height:u}=o.getBoundingClientRect();i?(r.width=window.innerWidth,r.height=window.innerHeight):(r.width=f,r.height=u);const S=f/o.videoWidth,p=m({sessionInformation:e,videoWidth:o.width}),F=h(c,p);return c.top=F.top,c.left=F.left,c.height=F.bottom-F.top,c.width=F.right-F.left,g({canvas:r,oval:p,scaleFactor:S,videoEl:o}),{faceMatchState:d,ovalDetails:p,scaleFactor:S,initialFace:c}}))},detectFaceAndMatchOval(t){return e(this,void 0,void 0,(function*(){const{serverSessionInformation:e}=t,{videoEl:a}=t.videoAssociatedParams,{faceDetector:o,ovalDetails:r,initialFace:i}=t.ovalAssociatedParams,s=yield o.detectFaces(a);let n,c,d,l=0;const m=h(i,r),{ovalBoundingBox:g}=f(r),p=u(m,g);switch(s.length){case 0:n=E.CANT_IDENTIFY,d=v(a);break;case 1:{c=s[0];const{faceMatchState:t,faceMatchPercentage:a}=S(c,r,p,e);n=t,l=a;break}default:n=E.TOO_MANY}return{faceMatchState:n,faceMatchPercentage:l,illuminationState:d,detectedFace:c}}))},flashColors(t){return e(this,void 0,void 0,(function*(){const{freshnessColorsComplete:e,freshnessColorDisplay:a}=t.freshnessColorAssociatedParams;if(e)return;return{freshnessColorsComplete:yield a.displayColorTick()}}))},stopVideo(t){return e(this,void 0,void 0,(function*(){const{challengeId:e,livenessStreamProvider:a}=t,{videoMediaStream:o}=t.videoAssociatedParams,{initialFace:r,ovalDetails:i}=t.ovalAssociatedParams,{startFace:n,endFace:c}=t.faceMatchAssociatedParams,{width:d,height:l}=o.getTracks()[0].getSettings(),v=d-r.left-r.width;yield a.stopVideo();const m={Challenge:{FaceMovementAndLightChallenge:{ChallengeId:e,InitialFace:{InitialFaceDetectedTimestamp:r.timestampMs,BoundingBox:s({deviceHeight:l,deviceWidth:d,height:r.height,width:r.width,top:r.top,left:v})},TargetFace:{FaceDetectedInTargetPositionStartTimestamp:n.timestampMs,FaceDetectedInTargetPositionEndTimestamp:c.timestampMs,BoundingBox:s({deviceHeight:l,deviceWidth:d,height:i.height,width:i.width,top:i.centerY-i.height/2,left:i.centerX-i.width/2})},VideoEndTimestamp:a.videoRecorder.recorderEndTimestamp}}};if(0===a.videoRecorder.getVideoChunkSize())throw new Error("Video chunks not recorded successfully.");a.sendClientInfo(m),yield a.dispatchStopVideoEvent()}))},getLiveness(t){return e(this,void 0,void 0,(function*(){const{onAnalysisComplete:e}=t.componentProps;yield e()}))}}}),L=a=>e(void 0,void 0,void 0,(function*(){var e,o,r,i;try{const d=yield B;try{for(var s,n=!0,c=t(d);!(e=(s=yield c.next()).done);){i=s.value,n=!1;try{const e=i;C(e)?a({type:"SET_SESSION_INFO",data:{sessionInfo:e.ServerSessionInformationEvent.SessionInformation}}):T(e)?a({type:"DISCONNECT_EVENT"}):P(e)?a({type:"SERVER_ERROR",data:{error:Object.assign({},e.ValidationException)}}):O(e)?a({type:"SERVER_ERROR",data:{error:Object.assign({},e.InternalServerException)}}):I(e)?a({type:"SERVER_ERROR",data:{error:Object.assign({},e.ThrottlingException)}}):w(e)&&a({type:"SERVER_ERROR",data:{error:Object.assign({},e.ServiceQuotaExceededException)}})}finally{n=!0}}}catch(e){o={error:e}}finally{try{n||e||!(r=c.return)||(yield r.call(c))}finally{if(o)throw o.error}}}catch(e){let t=e;y(e)&&(t=new Error("Invalid region in FaceLivenessDetector or credentials are scoped to the wrong region.")),t instanceof Error&&a({type:"SERVER_ERROR",data:{error:t}})}}));export{_ as MIN_FACE_MATCH_TIME,N as livenessMachine};
|
package/dist/esm/components/FaceLivenessDetector/service/utils/CustomWebSocketFetchHandler.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{__awaiter as t,__asyncGenerator as e,__await as o,__asyncValues as s}from"tslib";import{formatUrl as r}from"@aws-sdk/util-format-url";import{readableStreamtoIterable as n,iterableToReadableStream as i}from"@smithy/eventstream-serde-browser";import{FetchHttpHandler as c}from"@smithy/fetch-http-handler";import{HttpResponse as a}from"@smithy/protocol-http";import{WS_CLOSURE_CODE as l}from"./constants.mjs";const d=2e3,h=t=>{return t[Symbol.asyncIterator]?t:(s=t,"function"==typeof ReadableStream&&s instanceof ReadableStream?n(t):{[Symbol.asyncIterator]:function(){return e(this,arguments,(function*(){yield yield o(t)}))}});var s};class f{constructor(t,e=new c){this.metadata={handlerProtocol:"websocket/h1.1"},this.sockets={},this.utf8decoder=new TextDecoder,this.httpHandler=e,this.configPromise="function"==typeof t?t().then((t=>null!=t?t:{})):Promise.resolve(null!=t?t:{})}destroy(){for(const[t,e]of Object.entries(this.sockets)){for(const t of e)t.close(1e3,"Socket closed through destroy() call");delete this.sockets[t]}}handle(e){return t(this,void 0,void 0,(function*(){if(!(t=>"ws:"===t.protocol||"wss:"===t.protocol)(e))return this.httpHandler.handle(e);const t=r(e),o=new WebSocket(t);this.sockets[t]||(this.sockets[t]=[]),this.sockets[t].push(o),o.binaryType="arraybuffer";const{connectionTimeout:s=d}=yield this.configPromise;yield this.waitForReady(o,s);const{body:n}=e,c=h(n),l=(t=>"function"==typeof ReadableStream?i(t):t)(this.connect(o,c));return{response:new a({statusCode:200,body:l})}}))}removeNotUsableSockets(t){var e;this.sockets[t]=(null!==(e=this.sockets[t])&&void 0!==e?e:[]).filter((t=>![WebSocket.CLOSING,WebSocket.CLOSED].includes(t.readyState)))}waitForReady(t,e){return new Promise(((o,s)=>{const r=setTimeout((()=>{this.removeNotUsableSockets(t.url),s({$metadata:{httpStatusCode:500}})}),e);t.onopen=()=>{clearTimeout(r),o()}}))}connect(e,o){let r,n=!1,i=()=>{},c=()=>{};e.onmessage=t=>{c({done:!1,value:new Uint8Array(t.data)})},e.onerror=t=>{n=!0,e.close(),i(t)},e.onclose=()=>{this.removeNotUsableSockets(e.url),n||(r?i(r):c({done:!0,value:void 0}))};const a={[Symbol.asyncIterator]:()=>({next:()=>new Promise(((t,e)=>{c=t,i=e}))})};return(()=>{t(this,void 0,void 0,(function*(){var t,n,i,c;try{try{for(var a,d=!0,h=s(o);!(t=(a=yield h.next()).done);){c=a.value,d=!1;try{const t=c,o=this.utf8decoder.decode(t);if(o.includes("closeCode")){const t=o.match(/"closeCode":([0-9]*)/);if(t){const o=t[1];e.close(parseInt(o))}continue}e.send(t)}finally{d=!0}}}catch(t){n={error:t}}finally{try{d||t||!(i=h.return)||(yield i.call(h))}finally{if(n)throw n.error}}}catch(t){r=t}finally{e.close(l.SUCCESS_CODE)}}))})(),a}}export{f as CustomWebSocketFetchHandler};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const
|
|
1
|
+
const E=.32,R=.4,_=.37,C={SUCCESS_CODE:1e3,DEFAULT_ERROR_CODE:4e3,FACE_FIT_TIMEOUT:4001,USER_CANCEL:4003,RUNTIME_ERROR:4005,USER_ERROR_DURING_CONNECTION:4007};export{E as FACE_DISTANCE_THRESHOLD,R as REDUCED_THRESHOLD,_ as REDUCED_THRESHOLD_MOBILE,C as WS_CLOSURE_CODE};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__awaiter as e,__asyncGenerator as i,__await as t}from"tslib";import{Credentials as o,getAmplifyUserAgent as
|
|
1
|
+
import{__awaiter as e,__asyncGenerator as i,__await as t}from"tslib";import{Credentials as o,getAmplifyUserAgent as n}from"@aws-amplify/core";import{AmazonAIInterpretPredictionsProvider as r}from"@aws-amplify/predictions";import{RekognitionStreamingClient as s,StartFaceLivenessSessionCommand as d}from"@aws-sdk/client-rekognitionstreaming";import{VideoRecorder as a}from"./videoRecorder.mjs";import{getLivenessUserAgent as l}from"../../utils/platform.mjs";import{CustomWebSocketFetchHandler as c}from"./CustomWebSocketFetchHandler.mjs";const h=process.env.NEXT_PUBLIC_STREAMING_API_URL,v=1e3;function m(e){return void 0!==e.Challenge}function u(e){return void 0!==e.code}class f extends r{constructor({sessionId:e,region:i,stream:t,videoEl:o,credentialProvider:n}){super(),this.sessionId=e,this.region=i,this._stream=t,this.videoEl=o,this.videoRecorder=new a(t),this.credentialProvider=n,this.initPromise=this.init()}getResponseStream(){return e(this,void 0,void 0,(function*(){return yield this.initPromise,this.responseStream}))}startRecordingLivenessVideo(){this.videoRecorder.start(1e3)}sendClientInfo(e){this.videoRecorder.dispatch(new MessageEvent("clientSesssionInfo",{data:{clientInfo:e}}))}stopVideo(){return e(this,void 0,void 0,(function*(){yield this.videoRecorder.stop()}))}dispatchStopVideoEvent(){this.videoRecorder.dispatch(new Event("stopVideo"))}endStreamWithCode(i){return e(this,void 0,void 0,(function*(){"recording"===this.videoRecorder.getState()&&(yield this.stopVideo()),this.videoRecorder.dispatch(new MessageEvent("endStreamWithCode",{data:{code:i}}))}))}init(){var i;return e(this,void 0,void 0,(function*(){const e=null!==(i=this.credentialProvider)&&void 0!==i?i:yield o.get();if(!e)throw new Error("No credentials");const t={credentials:e,region:this.region,customUserAgent:`${n()} ${l()}`,requestHandler:new c({connectionTimeout:1e4})};h&&(t.endpointProvider=()=>({url:new URL(h)})),this._client=new s(t),this.responseStream=yield this.startLivenessVideoConnection()}))}getAsyncGeneratorFromReadableStream(e){const o=this;return this._reader=e.getReader(),function(){return i(this,arguments,(function*(){for(;;){const{done:e,value:i}=yield t(o._reader.read());if(e)return yield t(void 0);if("stopVideo"===i)yield yield t({VideoEvent:{VideoChunk:[],TimestampMillis:Date.now()}});else if(void 0!==i.arrayBuffer){const e=yield t(i.arrayBuffer()),o=new Uint8Array(e);o.length>0&&(yield yield t({VideoEvent:{VideoChunk:o,TimestampMillis:Date.now()}}))}else m(i)?yield yield t({ClientSessionInformationEvent:{Challenge:i.Challenge}}):u(i)&&(yield yield t({VideoEvent:{VideoChunk:[],TimestampMillis:{closeCode:i.code}}}))}}))}}startLivenessVideoConnection(){return e(this,void 0,void 0,(function*(){const e=this.getAsyncGeneratorFromReadableStream(this.videoRecorder.videoStream)();return(yield this._client.send(new d({ChallengeVersions:"FaceMovementAndLightChallenge_1.0.0",SessionId:this.sessionId,LivenessRequestStream:e,VideoWidth:this.videoEl.videoWidth.toString(),VideoHeight:this.videoEl.videoHeight.toString()}))).LivenessResponseStream}))}}export{f as LivenessStreamProvider,v as TIME_SLICE};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__awaiter as e}from"tslib";class t{constructor(e,t={}){if("undefined"==typeof MediaRecorder)throw Error("MediaRecorder is not supported by this browser");this._stream=e,this._options=t,this._chunks=[],this._recorder=new MediaRecorder(e,{bitsPerSecond:1e6}),this._setupCallbacks()}getState(){return this._recorder.state}start(e){this.clearRecordedData(),this.recordingStartApiTimestamp=Date.now(),this._recorder.start(e)}stop(){return e(this,void 0,void 0,(function*(){return"recording"===this.getState()&&this._recorder.stop(),this._recorderStopped}))}pause(){this._recorder.pause()}clearRecordedData(){this._chunks=[]}dispatch(e){this._recorder.dispatchEvent(e)}getVideoChunkSize(){return this._chunks.length}_setupCallbacks(){this.videoStream=new ReadableStream({start:e=>{this._recorder&&(this._recorder.ondataavailable=t=>{t.data&&t.data.size>0&&(0===this._chunks.length&&(this.firstChunkTimestamp=Date.now()),this._chunks.push(t.data),e.enqueue(t.data))},this._recorder.addEventListener("clientSesssionInfo",(t=>{e.enqueue(t.data.clientInfo)})),this._recorder.addEventListener("stopVideo",(()=>{e.enqueue("stopVideo")})),this._recorder.addEventListener("endStream",(()=>{e.close()})))}}),this.recorderStarted=new Promise((e=>{this._recorder.onstart=()=>{this.recorderStartTimestamp=Date.now(),e()}})),this._recorderStopped=new Promise((e=>{this._recorder.onstop=()=>{this.recorderEndTimestamp=Date.now(),e()}})),this._recorder.onerror=()=>{"stopped"!==this.getState()&&this.stop()}}}export{t as VideoRecorder};
|
|
1
|
+
import{__awaiter as e}from"tslib";class t{constructor(e,t={}){if("undefined"==typeof MediaRecorder)throw Error("MediaRecorder is not supported by this browser");this._stream=e,this._options=t,this._chunks=[],this._recorder=new MediaRecorder(e,{bitsPerSecond:1e6}),this._setupCallbacks()}getState(){return this._recorder.state}start(e){this.clearRecordedData(),this.recordingStartApiTimestamp=Date.now(),this._recorder.start(e)}stop(){return e(this,void 0,void 0,(function*(){return"recording"===this.getState()&&this._recorder.stop(),this._recorderStopped}))}pause(){this._recorder.pause()}clearRecordedData(){this._chunks=[]}dispatch(e){this._recorder.dispatchEvent(e)}getVideoChunkSize(){return this._chunks.length}_setupCallbacks(){this.videoStream=new ReadableStream({start:e=>{this._recorder&&(this._recorder.ondataavailable=t=>{t.data&&t.data.size>0&&(0===this._chunks.length&&(this.firstChunkTimestamp=Date.now()),this._chunks.push(t.data),e.enqueue(t.data))},this._recorder.addEventListener("clientSesssionInfo",(t=>{e.enqueue(t.data.clientInfo)})),this._recorder.addEventListener("stopVideo",(()=>{e.enqueue("stopVideo")})),this._recorder.addEventListener("endStream",(()=>{e.close()})),this._recorder.addEventListener("endStreamWithCode",(t=>{e.enqueue({type:"endStreamWithCode",code:t.data.code})})))}}),this.recorderStarted=new Promise((e=>{this._recorder.onstart=()=>{this.recorderStartTimestamp=Date.now(),e()}})),this._recorderStopped=new Promise((e=>{this._recorder.onstop=()=>{this.recorderEndTimestamp=Date.now(),e()}})),this._recorder.onerror=()=>{"stopped"!==this.getState()&&this.stop()}}}export{t as VideoRecorder};
|
package/dist/esm/version.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const o="2.0.
|
|
1
|
+
const o="2.0.7";export{o as VERSION};
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("tslib"),t=require("react"),a=require("@aws-amplify/core"),i=require("@xstate/react"),r=require("xstate"),n=require("@tensorflow/tfjs-core"),o=require("@tensorflow-models/blazeface"),s=require("@tensorflow/tfjs-backend-wasm");require("@tensorflow/tfjs-backend-cpu");var c=require("@aws-amplify/predictions"),l=require("@aws-sdk/client-rekognitionstreaming"),d=require("@aws-sdk/middleware-websocket"),h=require("nanoid"),u=require("@aws-amplify/ui-react"),m=require("@aws-amplify/ui-react/internal"),f=require("@aws-amplify/ui"),v=require("classnames");function g(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function p(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(a){if("default"!==a){var i=Object.getOwnPropertyDescriptor(e,a);Object.defineProperty(t,a,i.get?i:{enumerable:!0,get:function(){return e[a]}})}})),t.default=e,Object.freeze(t)}var E,T,C,S=g(t),F=p(t),x=p(n),y=p(o),R=p(s),M=g(v);class A{triggerModelLoading(){this.modelLoadingPromise=this.loadModels()}}!function(e){e.DARK="dark",e.BRIGHT="bright",e.NORMAL="normal"}(E||(E={})),function(e){e.MATCHED="MATCHED",e.TOO_FAR="TOO FAR",e.TOO_CLOSE="TOO CLOSE",e.CANT_IDENTIFY="CANNOT IDENTIFY",e.FACE_IDENTIFIED="ONE FACE IDENTIFIED",e.TOO_MANY="TOO MANY FACES"}(T||(T={})),function(e){e.TIMEOUT="TIMEOUT",e.RUNTIME_ERROR="RUNTIME_ERROR",e.FRESHNESS_TIMEOUT="FRESHNESS_TIMEOUT",e.SERVER_ERROR="SERVER_ERROR",e.CAMERA_FRAMERATE_ERROR="CAMERA_FRAMERATE_ERROR",e.CAMERA_ACCESS_ERROR="CAMERA_ACCESS_ERROR",e.FACE_DISTANCE_ERROR="FACE_DISTANCE_ERROR",e.MOBILE_LANDSCAPE_ERROR="MOBILE_LANDSCAPE_ERROR",e.MULTIPLE_FACES_ERROR="MULTIPLE_FACES_ERROR"}(C||(C={}));function w(e,t,a){return e*(a-t)+t}function _(e){const t=e.flippedCenterX-e.width/2,a=e.flippedCenterX+e.width/2,i=e.centerY-e.height/2,r=e.centerY+e.height/2;return{ovalBoundingBox:{left:t,top:i,right:a,bottom:r},minOvalX:t,maxOvalX:a,minOvalY:i,maxOvalY:r}}function D(e,t){const a=Math.max(e.left,t.left),i=Math.max(e.top,t.top),r=Math.min(e.right,t.right),n=Math.min(e.bottom,t.bottom),o=Math.abs(Math.max(0,r-a)*Math.max(0,n-i));if(0===o)return 0;return o/(Math.abs((e.right-e.left)*(e.bottom-e.top))+Math.abs((t.right-t.left)*(t.bottom-t.top))-o)}function O({width:e,height:t,widthSeed:a=1,centerXSeed:i=.5,centerYSeed:r=.5}){const n=t;let o=e;const s=.8*a,c=Math.floor(7*e/16),l=Math.floor(9*e/16),d=Math.floor(7*t/16),h=Math.floor(9*t/16),u=w(i,c,l),m=w(r,d,h);e>=t&&(o=3/4*n);const f=s*o,v=1.618*f;return{flippedCenterX:Math.floor(o-u),centerX:Math.floor(u),centerY:Math.floor(m),width:Math.floor(f),height:Math.floor(v)}}function I(e){const{leftEye:t,rightEye:a,mouth:i}=e,r=[];r[0]=(t[0]+a[0])/2,r[1]=(t[1]+a[1])/2;return{pupilDistance:Math.sqrt(Math.pow(t[0]-a[0],2)+Math.pow(t[1]-a[1],2)),faceHeight:Math.sqrt(Math.pow(r[0]-i[0],2)+Math.pow(r[1]-i[1],2))}}function b(e,t){const{leftEye:a,rightEye:i,nose:r}=e,{height:n,centerY:o}=t,s=o-n/2,c=[];c[0]=(a[0]+i[0])/2,c[1]=(a[1]+i[1])/2;const{pupilDistance:l,faceHeight:d}=I(e),h=(2*l+1.8*d)/2,u=1.618*h;let m,f;c[1]<=(s+n)/2?(m=(c[0]+r[0])/2,f=(c[1]+r[1])/2):(m=c[0],f=c[1]);const v=m-h/2,g=f-u/2;return{left:v,top:g,right:v+h,bottom:g+u}}function P(e){const t=document.createElement("canvas");t.width=e.videoWidth,t.height=e.videoHeight;const a=t.getContext("2d");if(a){a.drawImage(e,0,0,t.width,t.height);const i=a.getImageData(0,0,t.width,t.height).data,r=8,n=new Array(r).fill(0);for(let e=0;e<i.length;e++){n[Math.round(.2126*i[e++]+.7152*i[e++]+.0722*i[e++])%32]++}let o=-1,s=0;for(let e=0;e<r;e++)n[e]>s&&(s=n[e],o=e);return t.remove(),0===o?E.DARK:o===r?E.BRIGHT:E.NORMAL}throw new Error("Cannot find Video Element.")}C.RUNTIME_ERROR,C.SERVER_ERROR,C.TIMEOUT,C.FACE_DISTANCE_ERROR,C.MULTIPLE_FACES_ERROR,C.CAMERA_FRAMERATE_ERROR,C.CAMERA_ACCESS_ERROR,C.MOBILE_LANDSCAPE_ERROR,C.FRESHNESS_TIMEOUT;function L({ctx:e,prevColor:t,nextColor:a,fraction:i}){const r=e.canvas.width,n=e.canvas.height;e.fillStyle=a,e.fillRect(0,0,r,n*i),1!==i&&(e.fillStyle=t,e.fillRect(0,n*i,r,n*(1-i)))}const k=e=>!!e;function N(e){return e.slice(e.indexOf("(")+1,e.indexOf(")")).split(",").map((e=>parseInt(e)))}function H({faceDetector:t,videoEl:a,ovalDetails:i,reduceThreshold:r=!1,isMobile:n=!1}){return e.__awaiter(this,void 0,void 0,(function*(){const e=yield t.detectFaces(a);let o,s,c=!1;switch(e.length){case 0:s=C.FACE_DISTANCE_ERROR;break;case 1:{o=e[0];const t=i.width,{pupilDistance:a,faceHeight:l}=I(o),d=2;t&&(c=(d*a+1.8*l)/2/d/t<(r?n?.37:.4:.32),c||(s=C.FACE_DISTANCE_ERROR));break}default:s=C.MULTIPLE_FACES_ERROR}return{isDistanceBelowThreshold:c,error:s}}))}function B({deviceHeight:e,deviceWidth:t,height:a,width:i,top:r,left:n}){return{Height:a/e,Width:i/t,Top:r/e,Left:n/t}}const V=`https://cdn.liveness.rekognition.amazonaws.com/face-detection/tensorflow/tfjs-backend-wasm/${R.version_wasm}/`;class W extends A{constructor(e,t){super(),this.faceModelUrl=null!=t?t:"https://cdn.liveness.rekognition.amazonaws.com/face-detection/tensorflow-models/blazeface/0.0.7/model/model.json",this.binaryPath=null!=e?e:V}loadModels(){return e.__awaiter(this,void 0,void 0,(function*(){!function(){try{return!(!window.WebAssembly||!window.WebAssembly.compile&&!window.WebAssembly.compileStreaming)}catch(e){return!1}}()?yield this._loadCPUBackend():yield this._loadWebAssemblyBackend();try{yield x.ready(),this._model=yield a.jitteredExponentialRetry(y.load,[{modelUrl:this.faceModelUrl}])}catch(e){throw new Error("There was an error loading the blazeface model. If you are using a custom blazeface model url ensure that it is a fully qualified url that returns a json file.")}}))}detectFaces(t){return e.__awaiter(this,void 0,void 0,(function*(){const e=yield this._model.estimateFaces(t,!1,!0,!0),a=Date.now();return e.filter((e=>!!e.landmarks)).map((e=>{const{topLeft:t,bottomRight:i,probability:r,landmarks:n}=e,[o,s]=t,[c,l]=i,d=Math.abs(o-c),h=Math.abs(l-s),u=n[0],m=n[1],f=n[2],v=n[3];return{top:s,left:c,width:d,height:h,timestampMs:a,probability:r[0],rightEye:u,leftEye:m,mouth:v,nose:f}}))}))}_loadWebAssemblyBackend(){return e.__awaiter(this,void 0,void 0,(function*(){try{R.setWasmPaths(this.binaryPath),yield a.jitteredExponentialRetry((()=>e.__awaiter(this,void 0,void 0,(function*(){if(!(yield x.setBackend("wasm")))throw new Error("Initialization of backend wasm failed")}))),[]),this.modelBackend="wasm"}catch(e){throw new Error('There was an error loading the TFJS WASM backend. If you are using a custom WASM path ensure that it ends with "/" and that it is not the full URL as @tensorflow/tfjs-backend-wasm will append the wasm binary file name. Read more: https://github.com/tensorflow/tfjs/blob/master/tfjs-backend-wasm/src/backend_wasm.ts#L475.')}}))}_loadCPUBackend(){return e.__awaiter(this,void 0,void 0,(function*(){yield x.setBackend("cpu"),this.modelBackend="cpu"}))}}class j{constructor(e,t={}){if("undefined"==typeof MediaRecorder)throw Error("MediaRecorder is not supported by this browser");this._stream=e,this._options=t,this._chunks=[],this._recorder=new MediaRecorder(e,{bitsPerSecond:1e6}),this._setupCallbacks()}getState(){return this._recorder.state}start(e){this.clearRecordedData(),this.recordingStartApiTimestamp=Date.now(),this._recorder.start(e)}stop(){return e.__awaiter(this,void 0,void 0,(function*(){return"recording"===this.getState()&&this._recorder.stop(),this._recorderStopped}))}pause(){this._recorder.pause()}clearRecordedData(){this._chunks=[]}dispatch(e){this._recorder.dispatchEvent(e)}getVideoChunkSize(){return this._chunks.length}_setupCallbacks(){this.videoStream=new ReadableStream({start:e=>{this._recorder&&(this._recorder.ondataavailable=t=>{t.data&&t.data.size>0&&(0===this._chunks.length&&(this.firstChunkTimestamp=Date.now()),this._chunks.push(t.data),e.enqueue(t.data))},this._recorder.addEventListener("clientSesssionInfo",(t=>{e.enqueue(t.data.clientInfo)})),this._recorder.addEventListener("stopVideo",(()=>{e.enqueue("stopVideo")})),this._recorder.addEventListener("endStream",(()=>{e.close()})))}}),this.recorderStarted=new Promise((e=>{this._recorder.onstart=()=>{this.recorderStartTimestamp=Date.now(),e()}})),this._recorderStopped=new Promise((e=>{this._recorder.onstop=()=>{this.recorderEndTimestamp=Date.now(),e()}})),this._recorder.onerror=()=>{"stopped"!==this.getState()&&this.stop()}}}const z=process.env.NEXT_PUBLIC_STREAMING_API_URL;function q(e){return void 0!==e.Challenge}class U extends c.AmazonAIInterpretPredictionsProvider{constructor({sessionId:e,region:t,stream:a,videoEl:i,credentialProvider:r}){super(),this.sessionId=e,this.region=t,this._stream=a,this.videoEl=i,this.videoRecorder=new j(a),this.credentialProvider=r,this.initPromise=this.init()}getResponseStream(){return e.__awaiter(this,void 0,void 0,(function*(){return yield this.initPromise,this.responseStream}))}startRecordingLivenessVideo(){this.videoRecorder.start(1e3)}sendClientInfo(e){this.videoRecorder.dispatch(new MessageEvent("clientSesssionInfo",{data:{clientInfo:e}}))}stopVideo(){return e.__awaiter(this,void 0,void 0,(function*(){yield this.videoRecorder.stop()}))}dispatchStopVideoEvent(){this.videoRecorder.dispatch(new Event("stopVideo"))}endStream(){return e.__awaiter(this,void 0,void 0,(function*(){if("recording"===this.videoRecorder.getState()&&(yield this.stopVideo(),this.dispatchStopVideoEvent()),this._reader)return yield this._reader.cancel(),this._reader.closed}))}init(){var t;return e.__awaiter(this,void 0,void 0,(function*(){const e=null!==(t=this.credentialProvider)&&void 0!==t?t:yield a.Credentials.get();if(!e)throw new Error("No credentials");const i={credentials:e,region:this.region,customUserAgent:`${a.getAmplifyUserAgent()} ui-react-liveness/2.0.6`,requestHandler:new d.WebSocketFetchHandler({connectionTimeout:1e4})};z&&(i.endpointProvider=()=>({url:new URL(z)})),this._client=new l.RekognitionStreamingClient(i),this.responseStream=yield this.startLivenessVideoConnection()}))}getAsyncGeneratorFromReadableStream(t){const a=this;return this._reader=t.getReader(),function(){return e.__asyncGenerator(this,arguments,(function*(){for(;;){const{done:t,value:i}=yield e.__await(a._reader.read());if(t)return yield e.__await(void 0);if("stopVideo"===i)yield yield e.__await({VideoEvent:{VideoChunk:[],TimestampMillis:Date.now()}});else if(void 0!==i.arrayBuffer){const t=yield e.__await(i.arrayBuffer()),a=new Uint8Array(t);a.length>0&&(yield yield e.__await({VideoEvent:{VideoChunk:a,TimestampMillis:Date.now()}}))}else q(i)&&(yield yield e.__await({ClientSessionInformationEvent:{Challenge:i.Challenge}}))}}))}}startLivenessVideoConnection(){return e.__awaiter(this,void 0,void 0,(function*(){const e=this.getAsyncGeneratorFromReadableStream(this.videoRecorder.videoStream)();return(yield this._client.send(new l.StartFaceLivenessSessionCommand({ChallengeVersions:"FaceMovementAndLightChallenge_1.0.0",SessionId:this.sessionId,LivenessRequestStream:e,VideoWidth:this.videoEl.videoWidth.toString(),VideoHeight:this.videoEl.videoHeight.toString()}))).LivenessResponseStream}))}}var Y;!function(e){e.SCROLLING="SCROLLING",e.FLAT="FLAT"}(Y||(Y={}));class ${constructor(e,t){this.context=e,this.freshnessColorsSequence=t,this.isFirstTick=!0}displayColorTick(){return e.__awaiter(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{setTimeout((()=>{this.displayNextColorTick(e,t)}),Math.min(10))}))}))}init(){this.stageIndex=0,this.currColorIndex=0,this.currColorSequence=this.freshnessColorsSequence[0],this.prevColorSequence=this.freshnessColorsSequence[0],this.stage=Y.FLAT,this.timeLastFlatOrScrollChange=Date.now(),this.timeLastFaceMatchChecked=Date.now()}displayNextColorTick(e,t){const{freshnessColorEl:a}=this.context.freshnessColorAssociatedParams,{ovalDetails:i,scaleFactor:r}=this.context.ovalAssociatedParams,{videoEl:n}=this.context.videoAssociatedParams,o=Date.now();this.isFirstTick&&(this.init(),this.isFirstTick=!1,this.sendColorStartTime({tickStartTime:o,currColor:this.currColorSequence.color,prevColor:this.currColorSequence.color,currColorIndex:this.stageIndex}));let s=o-this.timeLastFlatOrScrollChange;if(a.style.display="block",(this.stage===Y.FLAT&&s>=this.currColorSequence.flatDisplayDuration||this.stage===Y.SCROLLING&&s>=this.currColorSequence.downscrollDuration)&&(this.incrementStageIndex(o),s=0),this.currColorIndex<this.freshnessColorsSequence.length){const t=s/(this.stage===Y.SCROLLING?this.currColorSequence.downscrollDuration:this.currColorSequence.flatDisplayDuration);!function({overlayCanvas:e,prevColor:t,nextColor:a,videoEl:i,ovalDetails:r,heightFraction:n,scaleFactor:o}){const{x:s,y:c}=i.getBoundingClientRect(),{flippedCenterX:l,centerY:d,width:h,height:u}=r,m=l*o+s,f=d*o+c,v=e.width,g=e.height,p=e.getContext("2d");if(!p)throw new Error("Cannot find Overlay Canvas.");p.canvas.width=window.innerWidth,p.canvas.height=window.innerHeight,p.clearRect(0,0,v,g),L({ctx:p,prevColor:t,nextColor:a,fraction:n}),p.save(),p.beginPath(),p.rect(0,0,v,g),p.clip(),p.clearRect(0,0,v,g),p.globalAlpha=.9,L({ctx:p,prevColor:t,nextColor:a,fraction:n}),p.beginPath(),p.ellipse(m,f,h*o/2,u*o/2,0,0,2*Math.PI),p.strokeStyle="white",p.lineWidth=8,p.stroke(),p.clip(),p.clearRect(0,0,v,g),p.globalAlpha=.75,L({ctx:p,prevColor:t,nextColor:a,fraction:n}),p.restore()}({overlayCanvas:a,prevColor:this.prevColorSequence.color,nextColor:this.currColorSequence.color,videoEl:n,ovalDetails:i,heightFraction:t,scaleFactor:r}),e(!1)}else a.style.display="none",e(!0)}incrementStageIndex(e){if(this.stageIndex+=1,this.prevColorSequence=this.freshnessColorsSequence[this.currColorIndex],this.stage===Y.FLAT)this.currColorIndex+=1,this.stage=Y.SCROLLING;else if(this.stage===Y.SCROLLING){this.freshnessColorsSequence[this.currColorIndex].flatDisplayDuration>0?this.stage=Y.FLAT:(this.stage=Y.SCROLLING,this.currColorIndex+=1)}this.currColorSequence=this.freshnessColorsSequence[this.currColorIndex],this.timeLastFlatOrScrollChange=Date.now(),this.currColorSequence&&this.sendColorStartTime({tickStartTime:e,currColor:this.currColorSequence.color,prevColor:this.prevColorSequence.color,currColorIndex:this.stageIndex})}sendColorStartTime({tickStartTime:e,currColor:t,prevColor:a,currColorIndex:i}){const{livenessStreamProvider:r,challengeId:n}=this.context;r.sendClientInfo({Challenge:{FaceMovementAndLightChallenge:{ChallengeId:n,ColorDisplayed:{CurrentColor:{RGB:N(t)},PreviousColor:{RGB:N(a)},SequenceNumber:i,CurrentColorStartTimestamp:e}}}})}}const G=e=>!!(null==e?void 0:e.DisconnectionEvent),X=e=>!!(null==e?void 0:e.ValidationException),Z=e=>!!(null==e?void 0:e.InternalServerException),K=e=>!!(null==e?void 0:e.ThrottlingException),Q=e=>!!(null==e?void 0:e.ServiceQuotaExceededException),J={width:{min:320,ideal:640},height:{min:240,ideal:480},frameRate:{min:15,ideal:30,max:30},facingMode:"user"};let ee;const te=r.createMachine({id:"livenessMachine",initial:"start",predictableActionArguments:!0,context:{challengeId:h.nanoid(),maxFailedAttempts:0,failedAttempts:0,componentProps:void 0,serverSessionInformation:void 0,videoAssociatedParams:{videoConstraints:J},ovalAssociatedParams:void 0,faceMatchAssociatedParams:{illuminationState:void 0,faceMatchState:void 0,faceMatchPercentage:25,currentDetectedFace:void 0,startFace:void 0,endFace:void 0,initialFaceMatchTime:void 0},freshnessColorAssociatedParams:{freshnessColorEl:void 0,freshnessColors:[],freshnessColorsComplete:!1,freshnessColorDisplay:void 0},errorState:void 0,livenessStreamProvider:void 0,responseStreamActorRef:void 0,shouldDisconnect:!1,faceMatchStateBeforeStart:void 0,isFaceFarEnoughBeforeRecording:void 0,isRecordingStopped:!1},on:{CANCEL:"userCancel",TIMEOUT:{target:"retryableTimeout",actions:"updateErrorStateForTimeout"},SET_SESSION_INFO:{internal:!0,actions:"updateSessionInfo"},DISCONNECT_EVENT:{internal:!0,actions:"updateShouldDisconnect"},SET_DOM_AND_CAMERA_DETAILS:{actions:"setDOMAndCameraDetails"},SERVER_ERROR:{target:"error",actions:"updateErrorStateForServer"},RUNTIME_ERROR:{target:"error"},MOBILE_LANDSCAPE_WARNING:{target:"mobileLandscapeWarning",actions:"updateErrorStateForServer"}},states:{start:{on:{BEGIN:"cameraCheck"}},cameraCheck:{entry:["resetErrorState","initializeFaceDetector"],invoke:{src:"checkVirtualCameraAndGetStream",onDone:{target:"waitForDOMAndCameraDetails",actions:["updateVideoMediaStream"]},onError:{target:"permissionDenied"}}},waitForDOMAndCameraDetails:{after:{0:{target:"detectFaceBeforeStart",cond:"hasDOMAndCameraDetails"},500:{target:"waitForDOMAndCameraDetails"}}},detectFaceBeforeStart:{invoke:{src:"detectFace",onDone:{target:"checkFaceDetectedBeforeStart",actions:["updateFaceMatchBeforeStartDetails"]}}},checkFaceDetectedBeforeStart:{after:{0:{target:"detectFaceDistanceBeforeRecording",cond:"hasSingleFaceBeforeStart"},100:{target:"detectFaceBeforeStart"}}},detectFaceDistanceBeforeRecording:{invoke:{src:"detectFaceDistance",onDone:{target:"checkFaceDistanceBeforeRecording",actions:["updateFaceDistanceBeforeRecording"]}}},checkFaceDistanceBeforeRecording:{after:{0:{target:"initializeLivenessStream",cond:"hasEnoughFaceDistanceBeforeRecording"},100:{target:"detectFaceDistanceBeforeRecording"}}},initializeLivenessStream:{invoke:{src:"openLivenessStreamConnection",onDone:{target:"notRecording",actions:["updateLivenessStreamProvider","spawnResponseStreamActor"]}}},notRecording:{on:{START_RECORDING:"recording"},initial:"waitForSessionInfo",states:{waitForSessionInfo:{after:{0:{target:"#livenessMachine.recording",cond:"hasServerSessionInfo"},100:{target:"detectFaceDistanceDuringLoading"}}},detectFaceDistanceDuringLoading:{invoke:{src:"detectFaceDistanceWhileLoading",onDone:{target:"checkFaceDistanceDuringLoading",actions:["updateFaceDistanceWhileLoading"]}}},checkFaceDistanceDuringLoading:{always:[{target:"failure",cond:"hasNotEnoughFaceDistanceBeforeRecording"},{target:"waitForSessionInfo"}]},failure:{entry:"sendTimeoutAfterFaceDistanceDelay",type:"final"}}},recording:{entry:["clearErrorState","startRecording"],initial:"ovalDrawing",states:{ovalDrawing:{entry:["sendTimeoutAfterOvalDrawingDelay"],invoke:{src:"detectInitialFaceAndDrawOval",onDone:{target:"checkFaceDetected",actions:["updateOvalAndFaceDetailsPostDraw","sendTimeoutAfterOvalMatchDelay"]},onError:{target:"#livenessMachine.error",actions:"updateErrorStateForRuntime"}}},checkFaceDetected:{after:{0:{target:"checkRecordingStarted",cond:"hasSingleFace"},100:{target:"ovalDrawing"}}},checkRecordingStarted:{after:{0:{target:"ovalMatching",cond:"hasRecordingStarted",actions:["updateRecordingStartTimestampMs"]},100:{target:"checkRecordingStarted"}}},ovalMatching:{entry:["cancelOvalDrawingTimeout"],invoke:{src:"detectFaceAndMatchOval",onDone:{target:"checkMatch",actions:"updateFaceDetailsPostMatch"}}},checkMatch:{after:{0:{target:"flashFreshnessColors",cond:"hasFaceMatchedInOvalWithMinTime",actions:["updateEndFaceMatch","setupFlashFreshnessColors","cancelOvalMatchTimeout","cancelOvalDrawingTimeout"]},.1:{target:"ovalMatching",cond:"hasFaceMatchedInOval",actions:"setFaceMatchTimeAndStartFace"},1:{target:"ovalMatching",cond:"hasNotFaceMatchedInOval"}}},flashFreshnessColors:{invoke:{src:"flashColors",onDone:[{target:"success",cond:"hasFreshnessColorShown"},{target:"flashFreshnessColors",actions:"updateFreshnessDetails"}]}},success:{entry:["stopRecording"],type:"final"}},onDone:"uploading"},uploading:{initial:"pending",states:{pending:{entry:["sendTimeoutAfterWaitingForDisconnect","pauseVideoStream"],invoke:{src:"stopVideo",onDone:"waitForDisconnectEvent",onError:{target:"#livenessMachine.error",actions:"updateErrorStateForRuntime"}}},waitForDisconnectEvent:{after:{0:{target:"getLivenessResult",cond:"getShouldDisconnect"},100:{target:"waitForDisconnectEvent"}}},getLivenessResult:{entry:["cancelWaitForDisconnectTimeout","freezeStream"],invoke:{src:"getLiveness",onError:{target:"#livenessMachine.error",actions:"updateErrorStateForServer"}}}}},retryableTimeout:{entry:"updateFailedAttempts",always:[{target:"timeout",cond:"shouldTimeoutOnFailedAttempts"},{target:"notRecording"}]},permissionDenied:{entry:"callUserPermissionDeniedCallback",on:{RETRY_CAMERA_CHECK:"cameraCheck"}},mobileLandscapeWarning:{entry:"callMobileLandscapeWarningCallback",always:[{target:"error"}]},timeout:{entry:["cleanUpResources","callUserTimeoutCallback","freezeStream"]},error:{entry:["cleanUpResources","callErrorCallback","cancelOvalDrawingTimeout","cancelWaitForDisconnectTimeout","cancelOvalMatchTimeout","freezeStream"]},userCancel:{entry:["cleanUpResources","callUserCancelCallback","resetContext"],always:[{target:"start"}]}}},{actions:{spawnResponseStreamActor:r.assign({responseStreamActorRef:()=>r.spawn(ae)}),updateFailedAttempts:r.assign({failedAttempts:e=>e.failedAttempts+1}),updateVideoMediaStream:r.assign({videoAssociatedParams:(e,t)=>{var a;return Object.assign(Object.assign({},e.videoAssociatedParams),{videoMediaStream:null===(a=t.data)||void 0===a?void 0:a.stream})}}),initializeFaceDetector:r.assign({ovalAssociatedParams:e=>{const{componentProps:t}=e,{faceModelUrl:a,binaryPath:i}=t.config,r=new W(i,a);return r.triggerModelLoading(),Object.assign(Object.assign({},e.ovalAssociatedParams),{faceDetector:r})}}),updateLivenessStreamProvider:r.assign({livenessStreamProvider:(e,t)=>{var a;return null===(a=t.data)||void 0===a?void 0:a.livenessStreamProvider}}),setDOMAndCameraDetails:r.assign({videoAssociatedParams:(e,t)=>{var a,i,r;return Object.assign(Object.assign({},e.videoAssociatedParams),{videoEl:null===(a=t.data)||void 0===a?void 0:a.videoEl,canvasEl:null===(i=t.data)||void 0===i?void 0:i.canvasEl,isMobile:null===(r=t.data)||void 0===r?void 0:r.isMobile})},freshnessColorAssociatedParams:(e,t)=>{var a;return Object.assign(Object.assign({},e.freshnessColorAssociatedParams),{freshnessColorEl:null===(a=t.data)||void 0===a?void 0:a.freshnessColorEl})}}),updateRecordingStartTimestampMs:r.assign({videoAssociatedParams:e=>{const{challengeId:t,videoAssociatedParams:a,ovalAssociatedParams:i,livenessStreamProvider:r}=e,{recordingStartApiTimestamp:n,recorderStartTimestamp:o}=r.videoRecorder,{videoMediaStream:s}=a,{initialFace:c}=i,l=Math.round(.73*(o-n)+n),{width:d,height:h}=s.getTracks()[0].getSettings(),u=d-c.left-c.width;return e.livenessStreamProvider.sendClientInfo({Challenge:{FaceMovementAndLightChallenge:{ChallengeId:t,VideoStartTimestamp:l,InitialFace:{InitialFaceDetectedTimestamp:c.timestampMs,BoundingBox:B({deviceHeight:h,deviceWidth:d,height:c.height,width:c.width,top:c.top,left:u})}}}}),Object.assign(Object.assign({},e.videoAssociatedParams),{recordingStartTimestampMs:l})}}),startRecording:r.assign({videoAssociatedParams:e=>{if(!e.serverSessionInformation)throw new Error("Session information was not received from response stream");return e.livenessStreamProvider.videoRecorder&&"recording"!==e.livenessStreamProvider.videoRecorder.getState()&&e.livenessStreamProvider.startRecordingLivenessVideo(),Object.assign({},e.videoAssociatedParams)}}),stopRecording:e=>{},updateFaceMatchBeforeStartDetails:r.assign({faceMatchStateBeforeStart:(e,t)=>t.data.faceMatchState}),updateFaceDistanceBeforeRecording:r.assign({isFaceFarEnoughBeforeRecording:(e,t)=>t.data.isFaceFarEnoughBeforeRecording}),updateFaceDistanceWhileLoading:r.assign({isFaceFarEnoughBeforeRecording:(e,t)=>t.data.isFaceFarEnoughBeforeRecording,errorState:(e,t)=>{var a;return null===(a=t.data)||void 0===a?void 0:a.error}}),updateOvalAndFaceDetailsPostDraw:r.assign({ovalAssociatedParams:(e,t)=>Object.assign(Object.assign({},e.ovalAssociatedParams),{initialFace:t.data.initialFace,ovalDetails:t.data.ovalDetails,scaleFactor:t.data.scaleFactor}),faceMatchAssociatedParams:(e,t)=>Object.assign(Object.assign({},e.faceMatchAssociatedParams),{faceMatchState:t.data.faceMatchState,illuminationState:t.data.illuminationState})}),updateFaceDetailsPostMatch:r.assign({faceMatchAssociatedParams:(e,t)=>Object.assign(Object.assign({},e.faceMatchAssociatedParams),{faceMatchState:t.data.faceMatchState,faceMatchPercentage:t.data.faceMatchPercentage,illuminationState:t.data.illuminationState,currentDetectedFace:t.data.detectedFace})}),updateEndFaceMatch:r.assign({faceMatchAssociatedParams:e=>Object.assign(Object.assign({},e.faceMatchAssociatedParams),{endFace:e.faceMatchAssociatedParams.currentDetectedFace})}),setFaceMatchTimeAndStartFace:r.assign({faceMatchAssociatedParams:e=>Object.assign(Object.assign({},e.faceMatchAssociatedParams),{startFace:void 0===e.faceMatchAssociatedParams.startFace?e.faceMatchAssociatedParams.currentDetectedFace:e.faceMatchAssociatedParams.startFace,initialFaceMatchTime:void 0===e.faceMatchAssociatedParams.initialFaceMatchTime?Date.now():e.faceMatchAssociatedParams.initialFaceMatchTime})}),resetErrorState:r.assign({errorState:e=>{}}),updateErrorStateForTimeout:r.assign({errorState:(e,t)=>{var a;return(null===(a=t.data)||void 0===a?void 0:a.errorState)||C.TIMEOUT}}),updateErrorStateForRuntime:r.assign({errorState:(e,t)=>{var a;return(null===(a=t.data)||void 0===a?void 0:a.errorState)||C.RUNTIME_ERROR}}),updateErrorStateForServer:r.assign({errorState:e=>C.SERVER_ERROR}),clearErrorState:r.assign({errorState:e=>{}}),updateSessionInfo:r.assign({serverSessionInformation:(e,t)=>t.data.sessionInfo}),updateShouldDisconnect:r.assign({shouldDisconnect:e=>!0}),updateFreshnessDetails:r.assign({freshnessColorAssociatedParams:(e,t)=>Object.assign(Object.assign({},e.freshnessColorAssociatedParams),{freshnessColorsComplete:t.data.freshnessColorsComplete})}),setupFlashFreshnessColors:r.assign({freshnessColorAssociatedParams:e=>{const{serverSessionInformation:t}=e,a=(t.Challenge.FaceMovementAndLightChallenge.ColorSequences||[]).map((({FreshnessColor:e,DownscrollDuration:t,FlatDisplayDuration:a})=>{const i=e.RGB,r=`rgb(${i[0]},${i[1]},${i[2]})`;return void 0!==r&&void 0!==t&&void 0!==a?{color:r,downscrollDuration:t,flatDisplayDuration:a}:void 0})).filter(k);const i=new $(e,a);return Object.assign(Object.assign({},e.freshnessColorAssociatedParams),{freshnessColorDisplay:i})}}),sendTimeoutAfterOvalDrawingDelay:r.actions.send({type:"TIMEOUT"},{delay:5e3,id:"ovalDrawingTimeout"}),cancelOvalDrawingTimeout:r.actions.cancel("ovalDrawingTimeout"),sendTimeoutAfterOvalMatchDelay:r.actions.send({type:"TIMEOUT"},{delay:7e3,id:"ovalMatchTimeout"}),cancelOvalMatchTimeout:r.actions.cancel("ovalMatchTimeout"),sendTimeoutAfterWaitingForDisconnect:r.actions.send({type:"TIMEOUT",data:{errorState:C.SERVER_ERROR}},{delay:2e4,id:"waitForDisconnectTimeout"}),cancelWaitForDisconnectTimeout:r.actions.cancel("waitForDisconnectTimeout"),sendTimeoutAfterFaceDistanceDelay:r.actions.send({type:"RUNTIME_ERROR",data:new Error("Avoid moving closer during countdown and ensure only one face is in front of camera.")},{delay:0,id:"faceDistanceTimeout"}),cancelFaceDistanceTimeout:r.actions.cancel("faceDistanceTimeout"),callUserPermissionDeniedCallback:r.assign({errorState:(e,t)=>{var a,i;let r;r=t.data.message.includes("15 fps")?C.CAMERA_FRAMERATE_ERROR:C.CAMERA_ACCESS_ERROR;const n=t.data.message||t.data.Message,o={state:r,error:new Error(n)};return null===(i=(a=e.componentProps).onError)||void 0===i||i.call(a,o),r}}),callMobileLandscapeWarningCallback:r.assign({errorState:e=>C.MOBILE_LANDSCAPE_ERROR}),callUserCancelCallback:t=>e.__awaiter(void 0,void 0,void 0,(function*(){var e,a;null===(a=(e=t.componentProps).onUserCancel)||void 0===a||a.call(e)})),callUserTimeoutCallback:t=>e.__awaiter(void 0,void 0,void 0,(function*(){var e,a;const i=new Error("Client Timeout");i.name=t.errorState;const r={state:t.errorState,error:i};null===(a=(e=t.componentProps).onError)||void 0===a||a.call(e,r)})),callErrorCallback:(t,a)=>e.__awaiter(void 0,void 0,void 0,(function*(){var e,i,r;const n={state:t.errorState,error:(null===(e=a.data)||void 0===e?void 0:e.error)||a.data};null===(r=(i=t.componentProps).onError)||void 0===r||r.call(i,n)})),cleanUpResources:t=>e.__awaiter(void 0,void 0,void 0,(function*(){var e;const{freshnessColorEl:a}=t.freshnessColorAssociatedParams;a&&(a.style.display="none"),yield null===(e=t.livenessStreamProvider)||void 0===e?void 0:e.endStream()})),freezeStream:t=>e.__awaiter(void 0,void 0,void 0,(function*(){const{videoMediaStream:e,videoEl:a}=t.videoAssociatedParams;t.isRecordingStopped=!0,null==a||a.pause(),null==e||e.getTracks().forEach((function(e){e.stop()}))})),pauseVideoStream:t=>e.__awaiter(void 0,void 0,void 0,(function*(){const{videoEl:e}=t.videoAssociatedParams;t.isRecordingStopped=!0,e.pause()})),resetContext:r.assign({challengeId:h.nanoid(),maxFailedAttempts:0,failedAttempts:0,componentProps:e=>e.componentProps,serverSessionInformation:e=>{},videoAssociatedParams:e=>({videoConstraints:J}),ovalAssociatedParams:e=>{},errorState:e=>{},livenessStreamProvider:e=>{},responseStreamActorRef:e=>{},shouldDisconnect:!1,faceMatchStateBeforeStart:e=>{},isFaceFarEnoughBeforeRecording:e=>{},isRecordingStopped:!1})},guards:{shouldTimeoutOnFailedAttempts:e=>e.failedAttempts>=e.maxFailedAttempts,hasFaceMatchedInOvalWithMinTime:e=>{const{faceMatchState:t,initialFaceMatchTime:a}=e.faceMatchAssociatedParams,i=Date.now()-a;return t===T.MATCHED&&i>=500},hasFaceMatchedInOval:e=>e.faceMatchAssociatedParams.faceMatchState===T.MATCHED,hasNotFaceMatchedInOval:e=>e.faceMatchAssociatedParams.faceMatchState!==T.MATCHED,hasSingleFace:e=>e.faceMatchAssociatedParams.faceMatchState===T.FACE_IDENTIFIED,hasSingleFaceBeforeStart:e=>e.faceMatchStateBeforeStart===T.FACE_IDENTIFIED,hasEnoughFaceDistanceBeforeRecording:e=>e.isFaceFarEnoughBeforeRecording,hasNotEnoughFaceDistanceBeforeRecording:e=>!e.isFaceFarEnoughBeforeRecording,hasLivenessCheckSucceeded:(e,t,a)=>a.state.event.data.isLive,hasFreshnessColorShown:e=>e.freshnessColorAssociatedParams.freshnessColorsComplete,hasServerSessionInfo:e=>void 0!==e.serverSessionInformation,hasDOMAndCameraDetails:e=>void 0!==e.videoAssociatedParams.videoEl&&void 0!==e.videoAssociatedParams.canvasEl&&void 0!==e.freshnessColorAssociatedParams.freshnessColorEl,getShouldDisconnect:e=>!!e.shouldDisconnect,hasRecordingStarted:e=>void 0!==e.livenessStreamProvider.videoRecorder.firstChunkTimestamp},services:{checkVirtualCameraAndGetStream(t){return e.__awaiter(this,void 0,void 0,(function*(){const{videoConstraints:e}=t.videoAssociatedParams,a=yield navigator.mediaDevices.getUserMedia({video:e,audio:!1}),i=(yield navigator.mediaDevices.enumerateDevices()).filter((e=>"videoinput"===e.kind)).filter((e=>!function(e){return e.label.toLowerCase().includes("virtual")}(e)));if(!i.length)throw new Error("No real video devices found");const r=a.getTracks().filter((e=>e.getSettings().frameRate>=15));if(r.length<1)throw new Error("No camera found with more than 15 fps");const n=r[0].getSettings().deviceId;let o=a;return i.some((e=>e.deviceId===n))||(o=yield navigator.mediaDevices.getUserMedia({video:Object.assign(Object.assign({},e),{deviceId:{exact:i[0].deviceId}}),audio:!1})),{stream:o}}))},openLivenessStreamConnection(t){return e.__awaiter(this,void 0,void 0,(function*(){const{config:e}=t.componentProps,{credentialProvider:a}=e,i=new U({sessionId:t.componentProps.sessionId,region:t.componentProps.region,stream:t.videoAssociatedParams.videoMediaStream,videoEl:t.videoAssociatedParams.videoEl,credentialProvider:a});return ee=i.getResponseStream(),{livenessStreamProvider:i}}))},detectFace(t){return e.__awaiter(this,void 0,void 0,(function*(){const{videoEl:a}=t.videoAssociatedParams,{faceDetector:i}=t.ovalAssociatedParams;try{yield i.modelLoadingPromise}catch(e){console.log({err:e})}const r=yield function(t,a){return e.__awaiter(this,void 0,void 0,(function*(){let e;switch((yield t.detectFaces(a)).length){case 0:e=T.CANT_IDENTIFY;break;case 1:e=T.FACE_IDENTIFIED;break;default:e=T.TOO_MANY}return e}))}(i,a);return{faceMatchState:r}}))},detectFaceDistance(t){return e.__awaiter(this,void 0,void 0,(function*(){const{isFaceFarEnoughBeforeRecording:e}=t,{videoEl:a,videoMediaStream:i,isMobile:r}=t.videoAssociatedParams,{faceDetector:n}=t.ovalAssociatedParams,{width:o,height:s}=i.getTracks()[0].getSettings(),c=O({width:o,height:s}),{isDistanceBelowThreshold:l}=yield H({faceDetector:n,videoEl:a,ovalDetails:c,reduceThreshold:e,isMobile:r});return{isFaceFarEnoughBeforeRecording:l}}))},detectFaceDistanceWhileLoading(t){return e.__awaiter(this,void 0,void 0,(function*(){const{isFaceFarEnoughBeforeRecording:e}=t,{videoEl:a,videoMediaStream:i,isMobile:r}=t.videoAssociatedParams,{faceDetector:n}=t.ovalAssociatedParams,{width:o,height:s}=i.getTracks()[0].getSettings(),c=O({width:o,height:s}),{isDistanceBelowThreshold:l,error:d}=yield H({faceDetector:n,videoEl:a,ovalDetails:c,reduceThreshold:e,isMobile:r});return{isFaceFarEnoughBeforeRecording:l,error:d}}))},detectInitialFaceAndDrawOval(t){return e.__awaiter(this,void 0,void 0,(function*(){const{serverSessionInformation:e,livenessStreamProvider:a}=t,{videoEl:i,canvasEl:r,isMobile:n}=t.videoAssociatedParams,{faceDetector:o}=t.ovalAssociatedParams;try{yield o.modelLoadingPromise,yield a.videoRecorder.recorderStarted}catch(e){console.log({err:e})}const s=yield o.detectFaces(i);let c,l,d;switch(s.length){case 0:l=T.CANT_IDENTIFY,d=P(i);break;case 1:l=T.FACE_IDENTIFIED,c=s[0];break;default:l=T.TOO_MANY}if(!c)return{faceMatchState:l,illuminationState:d};const{width:h,height:u}=i.getBoundingClientRect();n?(r.width=window.innerWidth,r.height=window.innerHeight):(r.width=h,r.height=u);const m=h/i.videoWidth,f=function({sessionInformation:e,videoWidth:t}){var a,i;const r=null===(i=null===(a=null==e?void 0:e.Challenge)||void 0===a?void 0:a.FaceMovementAndLightChallenge)||void 0===i?void 0:i.OvalParameters;if(!(r&&r.CenterX&&r.CenterY&&r.Width&&r.Height))throw new Error("Oval parameters not returned from session information.");return{flippedCenterX:t-r.CenterX,centerX:r.CenterX,centerY:r.CenterY,width:r.Width,height:r.Height}}({sessionInformation:e,videoWidth:i.width}),v=b(c,f);return c.top=v.top,c.left=v.left,c.height=v.bottom-v.top,c.width=v.right-v.left,function({canvas:e,oval:t,scaleFactor:a,videoEl:i}){const{flippedCenterX:r,centerY:n,width:o,height:s}=t,{width:c,height:l}=e.getBoundingClientRect(),d=e.getContext("2d");if(!d)throw new Error("Cannot find Canvas.");{d.clearRect(0,0,c,l),d.fillStyle="rgba(255, 255, 255, 1.0)",d.fillRect(0,0,c,l);const e={width:i.videoWidth,height:i.videoHeight},t={x:(c-e.width*a)/2,y:(l-e.height*a)/2};d.setTransform(a,0,0,a,t.x,t.y),d.beginPath(),d.ellipse(r,n,o/2,s/2,0,0,2*Math.PI),d.strokeStyle="#AEB3B7",d.lineWidth=3,d.stroke(),d.clip(),d.setTransform(1,0,0,1,0,0),d.clearRect(0,0,c,l)}}({canvas:r,oval:f,scaleFactor:m,videoEl:i}),{faceMatchState:l,ovalDetails:f,scaleFactor:m,initialFace:c}}))},detectFaceAndMatchOval(t){return e.__awaiter(this,void 0,void 0,(function*(){const{serverSessionInformation:e}=t,{videoEl:a}=t.videoAssociatedParams,{faceDetector:i,ovalDetails:r,initialFace:n}=t.ovalAssociatedParams,o=yield i.detectFaces(a);let s,c,l,d=0;const h=b(n,r),{ovalBoundingBox:u}=_(r),m=D(h,u);switch(o.length){case 0:s=T.CANT_IDENTIFY,l=P(a);break;case 1:{c=o[0];const{faceMatchState:t,faceMatchPercentage:a}=function(e,t,a,i){var r,n;let o;const s=null===(n=null===(r=null==i?void 0:i.Challenge)||void 0===r?void 0:r.FaceMovementAndLightChallenge)||void 0===n?void 0:n.ChallengeConfig;if(!(s&&s.OvalIouThreshold&&s.OvalIouHeightThreshold&&s.OvalIouWidthThreshold&&s.FaceIouHeightThreshold&&s.FaceIouWidthThreshold))throw new Error("Challenge information not returned from session information.");const{OvalIouThreshold:c,OvalIouHeightThreshold:l,OvalIouWidthThreshold:d,FaceIouHeightThreshold:h,FaceIouWidthThreshold:u}=s,m=b(e,t),f=m.left,v=m.right,g=m.top,p=m.bottom,{ovalBoundingBox:E,minOvalX:C,minOvalY:S,maxOvalX:F,maxOvalY:x}=_(t),y=D(m,E),R=c,M=t.width*d,A=t.height*l,w=t.width*u,O=t.height*h,I=100*Math.max(Math.min(1,.75*(y-a)/(R-a)+.25),0);return o=y>R&&Math.abs(C-f)<M&&Math.abs(F-v)<M&&Math.abs(x-p)<A?T.MATCHED:S-g>O||p-x>O||C-f>w&&v-F>w?T.TOO_CLOSE:T.TOO_FAR,{faceMatchState:o,faceMatchPercentage:I}}(c,r,m,e);s=t,d=a;break}default:s=T.TOO_MANY}return{faceMatchState:s,faceMatchPercentage:d,illuminationState:l,detectedFace:c}}))},flashColors(t){return e.__awaiter(this,void 0,void 0,(function*(){const{freshnessColorsComplete:e,freshnessColorDisplay:a}=t.freshnessColorAssociatedParams;if(e)return;return{freshnessColorsComplete:yield a.displayColorTick()}}))},stopVideo(t){return e.__awaiter(this,void 0,void 0,(function*(){const{challengeId:e,livenessStreamProvider:a}=t,{videoMediaStream:i}=t.videoAssociatedParams,{initialFace:r,ovalDetails:n}=t.ovalAssociatedParams,{startFace:o,endFace:s}=t.faceMatchAssociatedParams,{width:c,height:l}=i.getTracks()[0].getSettings(),d=c-r.left-r.width;yield a.stopVideo();const h={Challenge:{FaceMovementAndLightChallenge:{ChallengeId:e,InitialFace:{InitialFaceDetectedTimestamp:r.timestampMs,BoundingBox:B({deviceHeight:l,deviceWidth:c,height:r.height,width:r.width,top:r.top,left:d})},TargetFace:{FaceDetectedInTargetPositionStartTimestamp:o.timestampMs,FaceDetectedInTargetPositionEndTimestamp:s.timestampMs,BoundingBox:B({deviceHeight:l,deviceWidth:c,height:n.height,width:n.width,top:n.centerY-n.height/2,left:n.centerX-n.width/2})},VideoEndTimestamp:a.videoRecorder.recorderEndTimestamp}}};if(0===a.videoRecorder.getVideoChunkSize())throw new Error("Video chunks not recorded successfully.");a.sendClientInfo(h),yield a.dispatchStopVideoEvent()}))},getLiveness(t){return e.__awaiter(this,void 0,void 0,(function*(){const{onAnalysisComplete:e}=t.componentProps;yield e()}))}}}),ae=t=>e.__awaiter(void 0,void 0,void 0,(function*(){var a,i,r,n,o;try{const d=yield ee;try{for(var s,c=!0,l=e.__asyncValues(d);!(a=(s=yield l.next()).done);){n=s.value,c=!1;try{const e=n;(null==(o=e)?void 0:o.ServerSessionInformationEvent)?t({type:"SET_SESSION_INFO",data:{sessionInfo:e.ServerSessionInformationEvent.SessionInformation}}):G(e)?t({type:"DISCONNECT_EVENT"}):X(e)?t({type:"SERVER_ERROR",data:{error:Object.assign({},e.ValidationException)}}):Z(e)?t({type:"SERVER_ERROR",data:{error:Object.assign({},e.InternalServerException)}}):K(e)?t({type:"SERVER_ERROR",data:{error:Object.assign({},e.ThrottlingException)}}):Q(e)&&t({type:"SERVER_ERROR",data:{error:Object.assign({},e.ServiceQuotaExceededException)}})}finally{c=!0}}}catch(e){i={error:e}}finally{try{c||a||!(r=l.return)||(yield r.call(l))}finally{if(i)throw i.error}}}catch(e){let a=e;(e=>{const{message:t,name:a}=e;return"InvalidSignatureException"===a&&t.includes("valid region")})(e)&&(a=new Error("Invalid region in FaceLivenessDetector or credentials are scoped to the wrong region.")),a instanceof Error&&t({type:"SERVER_ERROR",data:{error:a}})}})),ie=S.default.createContext(null);function re(t){var{children:a}=t,i=e.__rest(t,["children"]);return S.default.createElement(ie.Provider,{value:i},a)}function ne(){const e=S.default.useContext(ie);if(null===e)throw new Error("useFaceLivenessDetector must be used within a FaceLivenessDetectorProvider");return e}function oe(){const{service:e}=ne();return i.useActor(e)}function se(e){const{service:t}=ne();return i.useSelector(t,e)}var ce;!function(e){e.CameraModule="amplify-liveness-camera-module",e.CancelContainer="amplify-liveness-cancel-container",e.CancelButton="amplify-liveness-cancel-button",e.CountdownContainer="amplify-liveness-countdown-container",e.DescriptionBullet="amplify-liveness-description-bullet",e.DescriptionBulletIndex="amplify-liveness-description-bullet__index",e.DescriptionBulletIndexText="amplify-liveness-description-bullet__index__text",e.DescriptionBulletMessage="amplify-liveness-description-bullet__message",e.ErrorModal="amplify-liveness-error-modal",e.ErrorModalHeading="amplify-liveness-error-modal__heading",e.FadeOut="amplify-liveness-fade-out",e.FreshnessCanvas="amplify-liveness-freshness-canvas",e.InstructionList="amplify-liveness-instruction-list",e.InstructionOverlay="amplify-liveness-instruction-overlay",e.Figure="amplify-liveness-figure",e.FigureCaption="amplify-liveness-figure__caption",e.FigureIcon="amplify-liveness-figure__icon",e.FigureImage="amplify-liveness-figure__image",e.Figures="amplify-liveness-figures",e.Hint="amplify-liveness-hint",e.HintText="amplify-liveness-hint__text",e.LandscapeErrorModal="amplify-liveness-landscape-error-modal",e.LandscapeErrorModalButton="amplify-liveness-landscape-error-modal__button",e.LandscapeErrorModalHeader="amplify-liveness-landscape-error-modal__header",e.Loader="amplify-liveness-loader",e.MatchIndicator="amplify-liveness-match-indicator",e.OvalCanvas="amplify-liveness-oval-canvas",e.OpaqueOverlay="amplify-liveness-overlay-opaque",e.Overlay="amplify-liveness-overlay",e.Popover="amplify-liveness-popover",e.PopoverContainer="amplify-liveness-popover__container",e.PopoverAnchor="amplify-liveness-popover__anchor",e.PopoverAnchorSecondary="amplify-liveness-popover__anchor-secondary",e.RecordingIconContainer="amplify-liveness-recording-icon-container",e.RecordingIcon="amplify-liveness-recording-icon",e.StartScreenHeader="amplify-liveness-start-screen-header",e.StartScreenHeaderBody="amplify-liveness-start-screen-header__body",e.StartScreenHeaderHeading="amplify-liveness-start-screen-header__heading",e.StartScreenWarning="amplify-liveness-start-screen-warning",e.StartScreenInstructions="amplify-liveness-start-screen-instructions",e.StartScreenInstructionsHeading="amplify-liveness-start-screen-instructions__heading",e.Toast="amplify-liveness-toast",e.ToastContainer="amplify-liveness-toast__container",e.ToastMessage="amplify-liveness-toast__message",e.Video="amplify-liveness-video",e.VideoAnchor="amplify-liveness-video-anchor"}(ce||(ce={}));const le=({ariaLabel:e})=>{const[t,a]=oe();return t.done?null:S.default.createElement(u.Button,{autoFocus:!0,variation:"link",onClick:()=>{a({type:"CANCEL"})},size:"large",className:ce.CancelButton,"aria-label":e},S.default.createElement(m.IconClose,{"aria-hidden":"true","data-testid":"close-icon"}))},de=t=>{var{variation:a="default",size:i="medium",children:r}=t,n=e.__rest(t,["variation","size","children"]);return F.createElement(u.View,Object.assign({className:`${ce.Toast} ${ce.Toast}--${a} ${ce.Toast}--${i}`,maxWidth:{base:"100%",small:"70%"}},n),F.createElement(u.Flex,{className:ce.ToastContainer},F.createElement(u.Flex,{className:ce.ToastMessage},r)))},he=t=>{var{children:a,anchorOrigin:i={horizontal:"center",vertical:"center"},className:r}=t,n=e.__rest(t,["children","anchorOrigin","className"]);return F.createElement(u.Flex,Object.assign({className:`${ce.Overlay} ${r}`,alignItems:i.horizontal,justifyContent:i.vertical},n),a)},ue=e=>e.context.errorState,me=e=>e.context.faceMatchAssociatedParams.faceMatchState,fe=e=>e.context.faceMatchAssociatedParams.illuminationState,ve=e=>e.context.isFaceFarEnoughBeforeRecording,ge=e=>e.context.faceMatchStateBeforeStart,pe=({hintDisplayText:e})=>{const[t]=oe(),a=se(ue),i=se(me),r=se(fe),n=se(ge),o=se(ve),s=t.matches("checkFaceDetectedBeforeStart"),c=t.matches("checkFaceDistanceBeforeRecording"),l=t.matches("recording"),d=t.matches("notRecording"),h=t.matches("uploading"),m=t.matches("checkSucceeded"),f=t.matches("checkFailed"),v=t.matches({recording:"flashFreshnessColors"}),g={[T.CANT_IDENTIFY]:e.hintCanNotIdentifyText,[T.FACE_IDENTIFIED]:e.hintTooFarText,[T.TOO_MANY]:e.hintTooManyFacesText,[T.TOO_CLOSE]:e.hintTooCloseText,[T.TOO_FAR]:e.hintTooFarText,[T.MATCHED]:e.hintHoldFaceForFreshnessText},p={[E.BRIGHT]:e.hintIlluminationTooBrightText,[E.DARK]:e.hintIlluminationTooDarkText,[E.NORMAL]:e.hintIlluminationNormalText},C=(()=>{if(!(a||f||m)){if(!l){if(s)return n===T.TOO_MANY?F.createElement(de,null,g[n]):F.createElement(de,null,e.hintMoveFaceFrontOfCameraText);if(c&&!1===o)return F.createElement(de,null,e.hintTooCloseText);if(d)return F.createElement(de,null,F.createElement(u.Flex,{className:ce.HintText},F.createElement(u.Loader,null),F.createElement(u.View,null,e.hintConnectingText)));if(h)return F.createElement(he,{className:ce.OpaqueOverlay,anchorOrigin:{horizontal:"center",vertical:"end"}},F.createElement(de,null,F.createElement(u.Flex,{className:ce.HintText},F.createElement(u.Loader,null),F.createElement(u.View,null,e.hintVerifyingText))));if(r&&r!==E.NORMAL)return F.createElement(de,null,p[r])}return v?F.createElement(de,{size:"large",variation:"primary"},e.hintHoldFaceForFreshnessText):l&&!v?F.createElement(de,{size:"large",variation:i===T.TOO_CLOSE?"error":"primary"},i===T.TOO_CLOSE?g[T.TOO_CLOSE]:g[T.TOO_FAR]):null}})();return C||null},Ee=({children:e})=>S.default.createElement(u.Flex,{className:ce.RecordingIcon},S.default.createElement(u.Flex,{"data-testid":"rec-icon",justifyContent:"center"},S.default.createElement(u.Icon,{viewBox:{width:20,height:20},width:"20",height:"20"},S.default.createElement("circle",{cx:"10",cy:"10",r:"8",fill:"red"}))),S.default.createElement(u.Text,{as:"span",fontWeight:"bold"},e)),Te=t=>{var{children:a,caption:i,variation:r="default"}=t,n=e.__rest(t,["children","caption","variation"]);return S.default.createElement(u.Flex,Object.assign({as:"figure",className:`${ce.Figure} ${ce.Figure}--${r}`},n),S.default.createElement(u.View,{className:`${ce.FigureImage} ${ce.FigureImage}--${r}`},"success"===r?S.default.createElement("svg",{className:ce.FigureIcon,"aria-hidden":"true",width:"24",height:"24"},S.default.createElement("g",{fill:"none"},S.default.createElement("path",{fill:"#365E3D",d:"M0 0h24v24H0z"}),S.default.createElement("path",{fill:"#FFF",d:"m9.435 15.62-4.054-4.055L4 12.936l5.435 5.435L21.101 6.704l-1.37-1.371z"}))):null,"error"===r?S.default.createElement("svg",{className:ce.FigureIcon,"aria-hidden":"true",width:"24",height:"24"},S.default.createElement("g",{fill:"none"},S.default.createElement("path",{fill:"#600",d:"M0 0h24v24H0z"}),S.default.createElement("path",{fill:"#FFF",d:"M19 6.41 17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"}))):null,a),S.default.createElement(u.View,{as:"figcaption",className:`${ce.FigureCaption} ${ce.FigureCaption}--${r}`},i))},Ce=({title:e,testId:t})=>S.default.createElement("svg",{width:"150",height:"150","data-testid":t},S.default.createElement("title",null,e),S.default.createElement("g",{fill:"none",fillRule:"evenodd",transform:"translate(0 -.001)"},S.default.createElement("path",{fill:"#5B361E",fillRule:"nonzero",d:"M124.655 0c9.173 8.155 9.394 17.812 13.258 32.385l.053.336.108.726.11.796.112.864.114.931.174 1.515.117 1.087.18 1.739.12 1.23.183 1.944.123 1.36.186 2.13.187 2.232.313 3.928.25 3.31.25 3.443.31 4.463.245 3.679.36 5.658.345 5.778.33 5.841.26 4.876.199 3.883.187 3.849.217 4.738.16 3.712.178 4.515.097 2.63v34.977L.519 150 .517 41.97c3-13.353 9.664-29.4 23.841-41.97h100.297Z"}),S.default.createElement("path",{fill:"#FCDDCC",fillRule:"nonzero",stroke:"#000",d:"m50.469 18.849.145.153c9.021 9.393 22.62 16.197 36.089 21.996l2.1.897 1.05.443 2.089.876 8.176 3.385 1.979.825 1.944.82c7.782 3.3 14.617 6.491 19.213 10.006 3.57 2.73 5.793 5.645 5.924 8.999v20.474l-.008.624-.016.669-.04 1.089-.04.777-.047.815-.06.853-.068.887-.08.918-.093.95-.104.978-.057.496-.123 1.016-.066.513-.144 1.049-.076.527-.165 1.077c-.057.36-.116.724-.178 1.086l-.193 1.103-.21 1.116-.11.557-.233 1.13c-.12.564-.247 1.13-.38 1.694l-.275 1.14c-1.037 4.147-2.426 8.3-4.271 11.978-6.17 9.34-12.996 16.035-19.28 20.691l-.8.584-.794.562-.784.539-1.165.77-1.147.724-.755.459c-.249.148-.497.294-.74.434l-.73.416-1.078.588-.702.367-1.033.517-.671.321-.657.303-.643.285-.541.23H68.149a75.81 75.81 0 0 1-.81-.284l-.918-.336a75.953 75.953 0 0 1-.935-.355l-.963-.382a85.513 85.513 0 0 1-1.988-.83l-1.032-.455c-.52-.233-1.05-.475-1.585-.727l-1.087-.517-1.113-.547c-.935-.465-1.893-.959-2.873-1.482l-1.193-.644a141.053 141.053 0 0 1-6.297-3.669l-1.33-.83c-17.11-10.783-22.636-33.458-23.66-49.98l-.071-1.267c-.02-.417-.038-.83-.053-1.235l-.037-1.212a86.317 86.317 0 0 1 .042-5.559l.047-1.002.06-.96.064-.843c1.09-2.51 2.164-4.304 3.296-5.882l.408-.558.415-.545.421-.538 2.026-2.492.481-.597.493-.624.507-.656.518-.69a61.722 61.722 0 0 0 3.769-5.754c4.03-6.917 7.127-14.806 9.544-21.668l.566-1.623.802-2.344 2.077-6.175.416-1.205.395-1.109.373-1.007.267-.682.253-.612c.47-.943.8-1.531 1.06-1.876l-.035.047Z"}),S.default.createElement("path",{fill:"#000",fillRule:"nonzero",d:"m94.566 121.353.722.895c-6.828 5.51-14.13 7.462-21.382 6.447-5.417-.758-10.535-3.2-13.987-6.186l-.318-.282.77-.854c3.285 2.964 8.343 5.434 13.694 6.183 6.797.95 13.632-.819 20.089-5.876l.412-.327Z"}),S.default.createElement("ellipse",{cx:"51.331",cy:"80.698",fill:"#000",fillRule:"nonzero",rx:"4.886",ry:"6.707"}),S.default.createElement("path",{fill:"#000",fillRule:"nonzero",d:"M42.539 63.719c4.453-2.586 11.355-3.268 17.22-.195l.35.19-.556 1.005c-5.437-3.01-11.946-2.479-16.175-.153l-.262.148-.577-.995Z"}),S.default.createElement("ellipse",{cx:"103.281",cy:"80.698",fill:"#000",fillRule:"nonzero",rx:"4.886",ry:"6.707"}),S.default.createElement("path",{fill:"#000",fillRule:"nonzero",d:"M94.492 63.719c4.453-2.586 11.355-3.268 17.22-.195l.35.19-.557 1.005c-5.436-3.01-11.946-2.479-16.174-.153l-.262.148-.577-.995Zm-22.972 32.9c0 4.216 2.006 7.72 5.831 7.48l.232-.018.115 1.144c-4.774.477-7.239-3.571-7.326-8.345l-.003-.26 1.15-.001h.001Z"}),S.default.createElement("path",{fill:"#FFF",fillRule:"nonzero",d:"M75.002.001H0v150h150v-150H75.002Zm0 0c25.627 0 46.402 33.579 46.402 75s-20.775 75-46.402 75c-25.627 0-46.402-33.579-46.402-75s20.775-75 46.402-75Z"}),S.default.createElement("path",{stroke:"#AEB3B7",strokeWidth:"2",d:"M120.921 75.001c0 20.555-5.214 39.117-13.589 52.507-8.386 13.406-19.838 21.493-32.313 21.493-12.476 0-23.928-8.087-32.312-21.493-8.377-13.39-13.59-31.952-13.59-52.507 0-20.555 5.214-39.116 13.589-52.507C51.091 9.09 62.543 1.001 75.018 1.001c12.476 0 23.928 8.088 32.314 21.493 8.375 13.39 13.588 31.952 13.588 52.507h.001Z"}))),Se=({title:e,testId:t})=>S.default.createElement("svg",{width:"150",height:"150","data-testid":t},S.default.createElement("title",null,e),S.default.createElement("defs",null,S.default.createElement("linearGradient",{id:"a",x1:"50%",x2:"50%",y1:"0%",y2:"100%"},S.default.createElement("stop",{offset:"0%",stopColor:"#C2C2C2"}),S.default.createElement("stop",{offset:"100%",stopColor:"#C2C2C2",stopOpacity:"0"}))),S.default.createElement("g",{fill:"none",fillRule:"evenodd",transform:"translate(2)"},S.default.createElement("path",{fill:"#FFF",fillRule:"nonzero",d:"M3.997 0h136v150h-136z"}),S.default.createElement("path",{fill:"url(#a)",fillRule:"nonzero",d:"M4.333 0h138v150h-138z"}),S.default.createElement("path",{fill:"#5B361E",fillRule:"nonzero",stroke:"#000",strokeWidth:"1.353",d:"m22.515 58.137-1.895 82.434 98.784-2.343c0-8.798.813-16.271.813-31.497 0-15.748-2.345-55.36-3.766-64.125C108.16 11.338 74.737 5.03 56.707 11.04c-28.425 9.475-33.64 35.095-34.192 47.097Z"}),S.default.createElement("path",{fill:"#EF992A",fillRule:"nonzero",d:"M38.104 138.228c8.339-3.98 5.1-1.525 15.916-3.104H90.5c5.448 0 9.541 3.104 28.904 3.104 6.391 0 5.987 8.988-2.473 8.988-24.315 1.08-66.07 1.08-78.281 0-77.975-6.896-10.97-4.014-.546-8.988Z"}),S.default.createElement("path",{fill:"#FCDDCC",fillRule:"nonzero",stroke:"#000",strokeWidth:"1.353",d:"m54.306 134.26 2.645-21.765h30.498l3.05 21.765c-15.778 14.791-30.703 6.163-36.193 0zm-27.59-54.458C25.42 66.68 33.467 67.18 37.653 69.07l2.837 25.314c-10.328-2.228-13.772-12.961-13.772-14.58zm89.512-.81c4.05-15.067-3.984-15.998-8.506-14.58L105.9 91.75c10.328-8.505 9.113-12.758 10.328-12.758z"}),S.default.createElement("path",{fill:"#FCDDCC",fillRule:"nonzero",stroke:"#000",strokeWidth:"1.353",d:"M53.564 109.804c-14.195-8.986-16.116-30.658-15.302-40.37 2.24-5.21 4.37-5.723 7.958-11.909 6.3-10.86 9.028-25.451 10.579-25.009 14.241 16.008 50.215 20.259 50.649 31.708v13.023c0 4.178-.911 14.358-4.558 21.65-8.986 13.674-20.131 18.612-24.58 19.372-2.334.922-10.55.521-24.746-8.465Z"}),S.default.createElement("path",{fill:"#000",fillRule:"nonzero",d:"m83.935 98.402.85 1.052c-7.974 6.435-17.2 5.243-23.018.18l-.23-.204.905-1.004c5.273 4.756 13.744 5.998 21.175.227l.318-.251Z"}),S.default.createElement("ellipse",{cx:"56.448",cy:"72.613",fill:"#000",fillRule:"nonzero",rx:"3.128",ry:"4.294"}),S.default.createElement("path",{fill:"#000",fillRule:"nonzero",d:"M50.664 61.476c2.917-1.694 7.404-2.147 11.244-.172l.31.165-.655 1.183c-3.348-1.854-7.361-1.545-9.985-.137l-.234.13-.68-1.17Z"}),S.default.createElement("ellipse",{cx:"89.709",cy:"72.613",fill:"#000",fillRule:"nonzero",rx:"3.128",ry:"4.294"}),S.default.createElement("path",{fill:"#000",fillRule:"nonzero",d:"M83.926 61.476c2.917-1.694 7.404-2.147 11.244-.172l.31.165-.655 1.183c-3.348-1.854-7.361-1.545-9.985-.137l-.234.13-.68-1.17Z"}),S.default.createElement("path",{stroke:"#000",strokeWidth:"1.353",d:"M69.005 82.806c0 1.858.859 5.487 4.287 5.144"}),S.default.createElement("path",{fill:"#FFF",d:"M73.004 0H0v150h146V0H73.004Zm.496 0C98.629 0 119 33.579 119 75s-20.371 75-45.5 75S28 116.421 28 75 48.371 0 73.5 0Z"}),S.default.createElement("path",{stroke:"#AEB3B7",strokeWidth:"2",d:"M118.4 75c0 20.555-5.156 39.117-13.441 52.507C96.665 140.913 85.338 149 72.999 149c-12.34 0-23.667-8.087-31.961-21.493C32.753 114.117 27.597 95.555 27.597 75c0-20.555 5.156-39.117 13.44-52.507C49.333 9.087 60.66 1 72.999 1c12.34 0 23.667 8.087 31.961 21.493C113.244 35.883 118.4 54.445 118.4 75Z"}))),Fe=({children:e})=>{const t=m.useThemeBreakpoint(),[a,i]=F.useState(!1),r=F.useRef(null),n="base"===t;return F.useEffect((()=>{function e(e){a&&r.current&&!r.current.contains(e.target)&&i(!1)}return document.addEventListener("mousedown",e),()=>{document.removeEventListener("mousedown",e)}}),[r,a]),F.createElement(u.Flex,{className:ce.Popover,onClick:()=>i(!a),ref:r,testId:"popover-icon"},F.createElement(m.AlertIcon,{ariaHidden:!0,variation:"info"}),a&&F.createElement(F.Fragment,null,F.createElement(u.Flex,{className:ce.PopoverAnchor}),F.createElement(u.Flex,{className:ce.PopoverAnchorSecondary}),F.createElement(u.Flex,{className:ce.PopoverContainer,left:n?-190:-108,"data-testid":"popover-text"},e)))};Fe.displayName="LivenessIconWithPopover";const xe=({headingText:e,bodyText:t})=>S.default.createElement(u.View,{className:ce.StartScreenHeader},S.default.createElement(u.View,{className:ce.StartScreenHeaderHeading},e),S.default.createElement(u.View,{className:ce.StartScreenHeaderBody},t)),ye=({headingText:e,bodyText:t,infoText:a})=>S.default.createElement(u.Flex,{className:`${u.ComponentClassNames.Alert} ${ce.StartScreenWarning}`},S.default.createElement(u.View,{flex:"1"},S.default.createElement(u.View,{className:u.ComponentClassNames.AlertHeading},e),S.default.createElement(u.View,{className:u.ComponentClassNames.AlertBody},t)),S.default.createElement(Fe,null,a)),Re=({headingText:e,goodFitCaptionText:t,goodFitAltText:a,tooFarCaptionText:i,tooFarAltText:r,steps:n})=>S.default.createElement(u.Flex,{direction:"column"},S.default.createElement(u.Text,{className:ce.StartScreenInstructionsHeading},e),S.default.createElement(u.Flex,{className:ce.Figures},S.default.createElement(Te,{variation:"success",caption:t},S.default.createElement(Ce,{title:a})),S.default.createElement(Te,{variation:"error",caption:i},S.default.createElement(Se,{title:r}))),S.default.createElement(u.Flex,{as:"ol",className:ce.InstructionList},n.map(((e,t)=>S.default.createElement(u.Flex,{as:"li",key:t+1},S.default.createElement(u.Text,{as:"span","aria-hidden":"true"},t+1,"."),S.default.createElement(u.Text,{as:"span"},e)))))),Me="liveness-detector-start";function Ae(e){const{beginLivenessCheck:t,components:a,instructionDisplayText:i}=e;return F.createElement(u.Card,{className:Me,"data-testid":Me},F.createElement(u.Flex,{direction:"column"},(null==a?void 0:a.Header)?F.createElement(a.Header,null):F.createElement(xe,{headingText:i.instructionsHeaderHeadingText,bodyText:i.instructionsHeaderBodyText}),(null==a?void 0:a.PhotosensitiveWarning)?F.createElement(a.PhotosensitiveWarning,null):F.createElement(ye,{headingText:i.photosensitivyWarningHeadingText,bodyText:i.photosensitivyWarningBodyText,infoText:i.photosensitivyWarningInfoText}),(null==a?void 0:a.Instructions)?F.createElement(a.Instructions,null):F.createElement(Re,{headingText:i.instructionListHeadingText,goodFitCaptionText:i.goodFitCaptionText,goodFitAltText:i.goodFitAltText,tooFarCaptionText:i.tooFarCaptionText,tooFarAltText:i.tooFarAltText,steps:[i.instructionListStepOneText,i.instructionListStepTwoText,i.instructionListStepThreeText,i.instructionListStepFourText]}),F.createElement(u.Flex,{justifyContent:"center"},F.createElement(u.Button,{variation:"primary",type:"button",onClick:t},i.instructionsBeginCheckText))))}const we={timeoutHeaderText:"Time out",timeoutMessageText:"Face didn't fit inside oval in time limit. Try again and completely fill the oval with face in it.",faceDistanceHeaderText:"Forward movement detected",faceDistanceMessageText:"Avoid moving closer when connecting.",multipleFacesHeaderText:"Multiple faces detected",multipleFacesMessageText:"Ensure only one face is present in front of the camera when connecting.",clientHeaderText:"Client error",clientMessageText:"Check failed due to client issue",serverHeaderText:"Server issue",serverMessageText:"Cannot complete check due to server issue",landscapeHeaderText:"Landscape orientation not supported",landscapeMessageText:"Rotate your device to portrait (vertical) orientation.",portraitMessageText:"Ensure your device remains in portrait (vertical) orientation for the check’s duration.",tryAgainText:"Try again"},_e=Object.assign({instructionsHeaderHeadingText:"Liveness check",instructionsHeaderBodyText:"You will go through a face verification process to prove that you are a real person.",instructionsBeginCheckText:"Begin check",photosensitivyWarningHeadingText:"Photosensitivity warning",photosensitivyWarningBodyText:"This check displays colored lights. Use caution if you are photosensitive.",photosensitivyWarningInfoText:"A small percentage of individuals may experience epileptic seizures when exposed to colored lights. Use caution if you, or anyone in your family, have an epileptic condition.",instructionListHeadingText:"Follow the instructions to complete the check:",goodFitCaptionText:"Good fit",goodFitAltText:"Ilustration of a person's face, perfectly fitting inside of an oval.",tooFarCaptionText:"Too far",tooFarAltText:"Illustration of a person's face inside of an oval; there is a gap between the perimeter of the face and the boundaries of the oval.",instructionListStepOneText:"When an oval appears, follow the instructions to fit your face in it.",instructionListStepTwoText:"Maximize your screen's brightness.",instructionListStepThreeText:"Make sure your face is not covered with sunglasses or a mask.",instructionListStepFourText:"Move to a well-lit place that is not in direct sunlight.",cameraMinSpecificationsHeadingText:"Camera does not meet minimum specifications",cameraMinSpecificationsMessageText:"Camera must support at least 320*240 resolution and 15 frames per second.",cameraNotFoundHeadingText:"Camera not accessible.",cameraNotFoundMessageText:"Check that camera is connected and camera permissions are enabled in settings before retrying.",retryCameraPermissionsText:"Retry",cancelLivenessCheckText:"Cancel Liveness check",recordingIndicatorText:"Rec",hintMoveFaceFrontOfCameraText:"Move face in front of camera",hintTooManyFacesText:"Ensure only one face is in front of camera",hintFaceDetectedText:"Face detected",hintCanNotIdentifyText:"Move face in front of camera",hintTooCloseText:"Move back",hintTooFarText:"Move closer",hintHoldFacePositionCountdownText:"Hold face position during countdown",hintConnectingText:"Connecting...",hintVerifyingText:"Verifying...",hintIlluminationTooBrightText:"Move to dimmer area",hintIlluminationTooDarkText:"Move to brighter area",hintIlluminationNormalText:"Lighting conditions normal",hintHoldFaceForFreshnessText:"Hold still"},we),De=({errorState:e,overrideErrorDisplayText:t})=>{const a=Object.assign(Object.assign({},we),t);return e===C.CAMERA_ACCESS_ERROR||e===C.CAMERA_FRAMERATE_ERROR||e===C.MOBILE_LANDSCAPE_ERROR?null:(e=>{const{error:t,displayText:a}=e,{timeoutHeaderText:i,timeoutMessageText:r,faceDistanceHeaderText:n,faceDistanceMessageText:o,multipleFacesHeaderText:s,multipleFacesMessageText:c,clientHeaderText:l,clientMessageText:d,serverHeaderText:h,serverMessageText:f}=a;let v,g;switch(t){case C.TIMEOUT:v=i,g=r;break;case C.FACE_DISTANCE_ERROR:v=n,g=o;break;case C.MULTIPLE_FACES_ERROR:v=s,g=c;break;case C.RUNTIME_ERROR:v=l,g=d;break;case C.SERVER_ERROR:default:v=h,g=f}return S.default.createElement(S.default.Fragment,null,S.default.createElement(u.Flex,{className:ce.ErrorModal},S.default.createElement(m.AlertIcon,{ariaHidden:!0,variation:"error"}),S.default.createElement(u.Text,{className:ce.ErrorModalHeading},v)),g)})({error:e,displayText:a})},Oe=e=>{const{children:t,onRetry:a,displayText:i}=e,r=Object.assign(Object.assign({},we),i),{tryAgainText:n}=r;return S.default.createElement(he,{className:ce.OpaqueOverlay},S.default.createElement(de,null,t,S.default.createElement(u.Flex,{justifyContent:"center"},S.default.createElement(u.Button,{variation:"primary",type:"button",onClick:a},n))))},Ie=e=>{var t;return null===(t=e.context.videoAssociatedParams)||void 0===t?void 0:t.videoMediaStream},be=e=>e.context.faceMatchAssociatedParams.faceMatchPercentage,Pe=e=>e.context.faceMatchAssociatedParams.faceMatchState,Le=S.default.createElement(u.Loader,{size:"large",className:ce.Loader,"data-testid":"centered-loader"}),ke=S.default.memo((({percentage:e,initialPercentage:t=25,testId:a})=>{const[i,r]=S.default.useState(t);S.default.useEffect((()=>{r(e<0?0:e>100?100:e)}),[e]);const n={"--percentage":`${i}%`};return S.default.createElement("div",{className:ce.MatchIndicator,"data-testid":a},S.default.createElement("div",{className:`${ce.MatchIndicator}__bar`,style:n}))})),Ne=e=>{const{isMobileScreen:a,isRecordingStopped:i,streamDisplayText:r,hintDisplayText:n,errorDisplayText:o,components:s,testId:c}=e,{cancelLivenessCheckText:l,recordingIndicatorText:d}=r,{ErrorView:h=Oe}=null!=s?s:{},[m,v]=oe(),g=se(Ie),p=se(be),E=se(Pe),C=se(ue),F=[T.TOO_FAR,T.CANT_IDENTIFY,T.FACE_IDENTIFIED,T.MATCHED],{videoRef:x,videoWidth:y,videoHeight:R}=function(e){const a=J.height.ideal,i=J.width.ideal,r=t.useRef(null),[n,o]=t.useState(a),[s,c]=t.useState(i);return t.useEffect((()=>{if(e){f.isObject(r.current)&&(r.current.srcObject=e);const{height:t,width:a}=e.getTracks()[0].getSettings();o(t),c(a)}return()=>{e&&e.getTracks().forEach((t=>{e.removeTrack(t),t.stop()}))}}),[e]),{videoRef:r,videoHeight:n,videoWidth:s}}(g),A=t.useRef(null),w=t.useRef(null),[_,D]=t.useState(!1),O=m.matches("cameraCheck"),I=m.matches("recording"),b=m.matches("checkSucceeded"),P=m.matches({recording:"flashFreshnessColors"}),[L,k]=t.useState(y),[N,H]=t.useState(R),[B,V]=t.useState((()=>y&&R?y/R:0));S.default.useLayoutEffect((()=>{_&&v({type:"SET_DOM_AND_CAMERA_DETAILS",data:{videoEl:x.current,canvasEl:A.current,freshnessColorEl:w.current,isMobile:a}}),x.current&&(k(x.current.videoWidth),H(x.current.videoHeight),V(x.current.videoWidth/x.current.videoHeight))}),[v,x,_,a]);return O?S.default.createElement(u.Flex,{height:R,width:"100%",position:"relative"},Le):S.default.createElement(u.Flex,{className:M.default(ce.CameraModule,a&&`${ce.CameraModule}--mobile`),"data-testid":c},!_&&Le,S.default.createElement(u.View,{as:"canvas",ref:w,className:ce.FreshnessCanvas,hidden:!0}),S.default.createElement(u.View,{className:ce.VideoAnchor,style:{aspectRatio:`${B}`}},S.default.createElement("video",{ref:x,muted:!0,autoPlay:!0,playsInline:!0,style:{transform:"scaleX(-1)"},width:L,height:N,onCanPlay:()=>{D(!0)},"data-testid":"video",className:ce.Video}),S.default.createElement(u.Flex,{className:M.default(ce.OvalCanvas,a&&`${ce.OvalCanvas}--mobile`,i&&ce.FadeOut)},S.default.createElement(u.View,{as:"canvas",width:"100%",height:"100%",ref:A})),I&&S.default.createElement(u.View,{className:ce.RecordingIconContainer},S.default.createElement(Ee,null,d)),!b&&S.default.createElement(u.View,{className:ce.CancelContainer},S.default.createElement(le,{ariaLabel:l})),S.default.createElement(he,{anchorOrigin:{horizontal:"center",vertical:I&&!P?"start":"space-between"},className:ce.InstructionOverlay},S.default.createElement(pe,{hintDisplayText:n}),C&&S.default.createElement(h,{onRetry:()=>{v({type:"CANCEL"})}},De({errorState:C,overrideErrorDisplayText:o})),I&&!P&&F.includes(E)?S.default.createElement(ke,{percentage:Math.ceil(p)}):null)))};function He(){return/Android|iPhone|iPad/i.test(navigator.userAgent)||/Macintosh/i.test(navigator.userAgent)&&!!navigator.maxTouchPoints&&navigator.maxTouchPoints>1}function Be(){return window.matchMedia("(orientation: landscape)")}const Ve=e=>{const{onRetry:t,header:a,portraitMessage:i,landscapeMessage:r,tryAgainText:n}=e,[o,s]=F.useState(!0);return F.useLayoutEffect((()=>{const e=Be();return s(e.matches),e.addEventListener("change",(e=>{s(e.matches)})),()=>{e.removeEventListener("change",(e=>s(e.matches)))}}),[]),F.createElement(u.Flex,{className:ce.LandscapeErrorModal,height:o?"auto":480},F.createElement(u.Text,{className:ce.LandscapeErrorModalHeader},a),F.createElement(u.Text,null,o?r:i),o?null:F.createElement(u.Flex,{className:ce.LandscapeErrorModalButton},F.createElement(u.Button,{variation:"primary",type:"button",onClick:t},n)))},We="liveness-detector-check",je=e=>e.context.errorState,ze=e=>e.context.isRecordingStopped,qe=({hintDisplayText:e,cameraDisplayText:t,streamDisplayText:a,errorDisplayText:i,components:r})=>{const[n,o]=oe(),s=se(je),c=se(ze),l=n.matches("permissionDenied"),d=He(),h=()=>{o({type:"RETRY_CAMERA_CHECK"})},{cameraMinSpecificationsHeadingText:m,cameraMinSpecificationsMessageText:f,cameraNotFoundHeadingText:v,cameraNotFoundMessageText:g,retryCameraPermissionsText:p}=t,{cancelLivenessCheckText:E}=a;F.useLayoutEffect((()=>{if(d){const e=e=>{e&&o({type:"MOBILE_LANDSCAPE_WARNING"})},t=Be();return e(t.matches),t.addEventListener("change",(t=>{e(t.matches)})),()=>{t.removeEventListener("change",(t=>e(t.matches)))}}}),[d,o]);return F.createElement(u.Flex,{direction:"column",position:"relative",testId:We,className:We},(()=>{if(s===C.MOBILE_LANDSCAPE_ERROR){const e=Object.assign(Object.assign({},we),i),{landscapeHeaderText:t,portraitMessageText:a,landscapeMessageText:r,tryAgainText:n}=e;return F.createElement(u.Flex,{backgroundColor:"background.primary",direction:"column",textAlign:"center",alignItems:"center",justifyContent:"center",position:"absolute",width:"100%"},F.createElement(Ve,{header:t,portraitMessage:a,landscapeMessage:r,tryAgainText:n,onRetry:()=>{o({type:"CANCEL"})}}))}return l?F.createElement(u.Flex,{backgroundColor:"background.primary",direction:"column",textAlign:"center",alignItems:"center",justifyContent:"center",width:"100%",height:480},F.createElement(u.Text,{fontSize:"large",fontWeight:"bold"},s===C.CAMERA_FRAMERATE_ERROR?m:v),F.createElement(u.Text,{maxWidth:300},s===C.CAMERA_FRAMERATE_ERROR?f:g),F.createElement(u.Button,{variation:"primary",type:"button",onClick:h},p),F.createElement(u.View,{position:"absolute",top:"medium",right:"medium"},F.createElement(le,{ariaLabel:E}))):F.createElement(Ne,{isMobileScreen:d,isRecordingStopped:c,streamDisplayText:a,hintDisplayText:e,errorDisplayText:i,components:r})})())};const Ue="liveness-detector";function Ye(e){const{disableInstructionScreen:t=!1,components:a,config:r,displayText:n}=e,o=F.useRef(null),{hintDisplayText:s,cameraDisplayText:c,instructionDisplayText:l,streamDisplayText:d,errorDisplayText:h}=function(e){const t=Object.assign(Object.assign({},_e),e),{instructionsHeaderHeadingText:a,instructionsHeaderBodyText:i,instructionsBeginCheckText:r,photosensitivyWarningHeadingText:n,photosensitivyWarningBodyText:o,photosensitivyWarningInfoText:s,instructionListHeadingText:c,goodFitCaptionText:l,goodFitAltText:d,tooFarCaptionText:h,tooFarAltText:u,instructionListStepOneText:m,instructionListStepTwoText:f,instructionListStepThreeText:v,instructionListStepFourText:g,cameraMinSpecificationsHeadingText:p,cameraMinSpecificationsMessageText:E,cameraNotFoundHeadingText:T,cameraNotFoundMessageText:C,retryCameraPermissionsText:S,cancelLivenessCheckText:F,recordingIndicatorText:x,hintMoveFaceFrontOfCameraText:y,hintTooManyFacesText:R,hintFaceDetectedText:M,hintCanNotIdentifyText:A,hintTooCloseText:w,hintTooFarText:_,hintHoldFacePositionCountdownText:D,hintConnectingText:O,hintVerifyingText:I,hintIlluminationTooBrightText:b,hintIlluminationTooDarkText:P,hintIlluminationNormalText:L,hintHoldFaceForFreshnessText:k,timeoutHeaderText:N,timeoutMessageText:H,faceDistanceHeaderText:B,faceDistanceMessageText:V,multipleFacesHeaderText:W,multipleFacesMessageText:j,clientHeaderText:z,clientMessageText:q,serverHeaderText:U,serverMessageText:Y,landscapeHeaderText:$,landscapeMessageText:G,portraitMessageText:X,tryAgainText:Z}=t;return{hintDisplayText:{hintMoveFaceFrontOfCameraText:y,hintTooManyFacesText:R,hintFaceDetectedText:M,hintCanNotIdentifyText:A,hintTooCloseText:w,hintTooFarText:_,hintHoldFacePositionCountdownText:D,hintConnectingText:O,hintVerifyingText:I,hintIlluminationTooBrightText:b,hintIlluminationTooDarkText:P,hintIlluminationNormalText:L,hintHoldFaceForFreshnessText:k},cameraDisplayText:{cameraMinSpecificationsHeadingText:p,cameraMinSpecificationsMessageText:E,cameraNotFoundHeadingText:T,cameraNotFoundMessageText:C,retryCameraPermissionsText:S},instructionDisplayText:{instructionsHeaderHeadingText:a,instructionsHeaderBodyText:i,instructionsBeginCheckText:r,photosensitivyWarningHeadingText:n,photosensitivyWarningBodyText:o,photosensitivyWarningInfoText:s,instructionListHeadingText:c,goodFitCaptionText:l,goodFitAltText:d,tooFarCaptionText:h,tooFarAltText:u,instructionListStepOneText:m,instructionListStepTwoText:f,instructionListStepThreeText:v,instructionListStepFourText:g},streamDisplayText:{cancelLivenessCheckText:F,recordingIndicatorText:x},errorDisplayText:{timeoutHeaderText:N,timeoutMessageText:H,faceDistanceHeaderText:B,faceDistanceMessageText:V,multipleFacesHeaderText:W,multipleFacesMessageText:j,clientHeaderText:z,clientMessageText:q,serverHeaderText:U,serverMessageText:Y,landscapeHeaderText:$,landscapeMessageText:G,portraitMessageText:X,tryAgainText:Z}}}(n),m=i.useInterpret(te,{devTools:"development"===process.env.NODE_ENV,context:{componentProps:Object.assign(Object.assign({},e),{config:null!=r?r:{}})}}),[f,v]=i.useActor(m),g=f.matches("start")||f.matches("userCancel"),p=F.useCallback((()=>{v({type:"BEGIN"})}),[v]);return F.useLayoutEffect((()=>{t&&g&&p()}),[p,t,g]),F.createElement(u.View,{className:Ue,testId:Ue},F.createElement(re,{componentProps:e,service:m},F.createElement(u.Flex,{direction:"column",ref:o},g?F.createElement(Ae,{beginLivenessCheck:p,components:a,instructionDisplayText:l}):F.createElement(qe,{hintDisplayText:s,cameraDisplayText:c,streamDisplayText:d,errorDisplayText:h,components:a}))))}const $e=()=>e.__awaiter(void 0,void 0,void 0,(function*(){return yield a.Credentials.get()}));exports.FaceLivenessDetector=function(t){const{config:a}=t,i=e.__rest(t,["config"]);return F.createElement(Ye,Object.assign({},i,{config:Object.assign({credentialProvider:$e},a)}))},exports.FaceLivenessDetectorCore=Ye;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("tslib"),t=require("react"),a=require("@aws-amplify/core"),i=require("@xstate/react"),r=require("xstate"),n=require("@tensorflow/tfjs-core"),o=require("@tensorflow-models/blazeface"),s=require("@tensorflow/tfjs-backend-wasm");require("@tensorflow/tfjs-backend-cpu");var c=require("@aws-amplify/predictions"),l=require("@aws-sdk/client-rekognitionstreaming"),d=require("@aws-sdk/util-format-url"),h=require("@smithy/eventstream-serde-browser"),u=require("@smithy/fetch-http-handler"),m=require("@smithy/protocol-http"),f=require("nanoid"),v=require("@aws-amplify/ui-react"),g=require("@aws-amplify/ui-react/internal"),p=require("@aws-amplify/ui"),E=require("classnames");function T(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function C(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(a){if("default"!==a){var i=Object.getOwnPropertyDescriptor(e,a);Object.defineProperty(t,a,i.get?i:{enumerable:!0,get:function(){return e[a]}})}})),t.default=e,Object.freeze(t)}var S,y,F,x=T(t),R=C(t),M=C(n),A=C(o),w=C(s),_=T(E);class D{triggerModelLoading(){this.modelLoadingPromise=this.loadModels()}}!function(e){e.DARK="dark",e.BRIGHT="bright",e.NORMAL="normal"}(S||(S={})),function(e){e.MATCHED="MATCHED",e.TOO_FAR="TOO FAR",e.TOO_CLOSE="TOO CLOSE",e.CANT_IDENTIFY="CANNOT IDENTIFY",e.FACE_IDENTIFIED="ONE FACE IDENTIFIED",e.TOO_MANY="TOO MANY FACES"}(y||(y={})),function(e){e.TIMEOUT="TIMEOUT",e.RUNTIME_ERROR="RUNTIME_ERROR",e.FRESHNESS_TIMEOUT="FRESHNESS_TIMEOUT",e.SERVER_ERROR="SERVER_ERROR",e.CAMERA_FRAMERATE_ERROR="CAMERA_FRAMERATE_ERROR",e.CAMERA_ACCESS_ERROR="CAMERA_ACCESS_ERROR",e.FACE_DISTANCE_ERROR="FACE_DISTANCE_ERROR",e.MOBILE_LANDSCAPE_ERROR="MOBILE_LANDSCAPE_ERROR",e.MULTIPLE_FACES_ERROR="MULTIPLE_FACES_ERROR"}(F||(F={}));const I=1e3,O=4e3,b=4001,P=4003,k=4005,L=4007;function N(e,t,a){return e*(a-t)+t}function H(e){const t=e.flippedCenterX-e.width/2,a=e.flippedCenterX+e.width/2,i=e.centerY-e.height/2,r=e.centerY+e.height/2;return{ovalBoundingBox:{left:t,top:i,right:a,bottom:r},minOvalX:t,maxOvalX:a,minOvalY:i,maxOvalY:r}}function B(e,t){const a=Math.max(e.left,t.left),i=Math.max(e.top,t.top),r=Math.min(e.right,t.right),n=Math.min(e.bottom,t.bottom),o=Math.abs(Math.max(0,r-a)*Math.max(0,n-i));if(0===o)return 0;return o/(Math.abs((e.right-e.left)*(e.bottom-e.top))+Math.abs((t.right-t.left)*(t.bottom-t.top))-o)}function W({width:e,height:t,widthSeed:a=1,centerXSeed:i=.5,centerYSeed:r=.5}){const n=t;let o=e;const s=.8*a,c=Math.floor(7*e/16),l=Math.floor(9*e/16),d=Math.floor(7*t/16),h=Math.floor(9*t/16),u=N(i,c,l),m=N(r,d,h);e>=t&&(o=3/4*n);const f=s*o,v=1.618*f;return{flippedCenterX:Math.floor(o-u),centerX:Math.floor(u),centerY:Math.floor(m),width:Math.floor(f),height:Math.floor(v)}}function V(e){const{leftEye:t,rightEye:a,mouth:i}=e,r=[];r[0]=(t[0]+a[0])/2,r[1]=(t[1]+a[1])/2;return{pupilDistance:Math.sqrt(Math.pow(t[0]-a[0],2)+Math.pow(t[1]-a[1],2)),faceHeight:Math.sqrt(Math.pow(r[0]-i[0],2)+Math.pow(r[1]-i[1],2))}}function j(e,t){const{leftEye:a,rightEye:i,nose:r}=e,{height:n,centerY:o}=t,s=o-n/2,c=[];c[0]=(a[0]+i[0])/2,c[1]=(a[1]+i[1])/2;const{pupilDistance:l,faceHeight:d}=V(e),h=(2*l+1.8*d)/2,u=1.618*h;let m,f;c[1]<=(s+n)/2?(m=(c[0]+r[0])/2,f=(c[1]+r[1])/2):(m=c[0],f=c[1]);const v=m-h/2,g=f-u/2;return{left:v,top:g,right:v+h,bottom:g+u}}function z(e){const t=document.createElement("canvas");t.width=e.videoWidth,t.height=e.videoHeight;const a=t.getContext("2d");if(a){a.drawImage(e,0,0,t.width,t.height);const i=a.getImageData(0,0,t.width,t.height).data,r=8,n=new Array(r).fill(0);for(let e=0;e<i.length;e++){n[Math.round(.2126*i[e++]+.7152*i[e++]+.0722*i[e++])%32]++}let o=-1,s=0;for(let e=0;e<r;e++)n[e]>s&&(s=n[e],o=e);return t.remove(),0===o?S.DARK:o===r?S.BRIGHT:S.NORMAL}throw new Error("Cannot find Video Element.")}F.RUNTIME_ERROR,F.SERVER_ERROR,F.TIMEOUT,F.FACE_DISTANCE_ERROR,F.MULTIPLE_FACES_ERROR,F.CAMERA_FRAMERATE_ERROR,F.CAMERA_ACCESS_ERROR,F.MOBILE_LANDSCAPE_ERROR,F.FRESHNESS_TIMEOUT;function U({ctx:e,prevColor:t,nextColor:a,fraction:i}){const r=e.canvas.width,n=e.canvas.height;e.fillStyle=a,e.fillRect(0,0,r,n*i),1!==i&&(e.fillStyle=t,e.fillRect(0,n*i,r,n*(1-i)))}const q=e=>!!e;function Y(e){return e.slice(e.indexOf("(")+1,e.indexOf(")")).split(",").map((e=>parseInt(e)))}function $({faceDetector:t,videoEl:a,ovalDetails:i,reduceThreshold:r=!1,isMobile:n=!1}){return e.__awaiter(this,void 0,void 0,(function*(){const e=yield t.detectFaces(a);let o,s,c=!1;switch(e.length){case 0:s=F.FACE_DISTANCE_ERROR;break;case 1:{o=e[0];const t=i.width,{pupilDistance:a,faceHeight:l}=V(o),d=2;t&&(c=(d*a+1.8*l)/2/d/t<(r?n?.37:.4:.32),c||(s=F.FACE_DISTANCE_ERROR));break}default:s=F.MULTIPLE_FACES_ERROR}return{isDistanceBelowThreshold:c,error:s}}))}function G({deviceHeight:e,deviceWidth:t,height:a,width:i,top:r,left:n}){return{Height:a/e,Width:i/t,Top:r/e,Left:n/t}}const X=`https://cdn.liveness.rekognition.amazonaws.com/face-detection/tensorflow/tfjs-backend-wasm/${w.version_wasm}/`;class Z extends D{constructor(e,t){super(),this.faceModelUrl=null!=t?t:"https://cdn.liveness.rekognition.amazonaws.com/face-detection/tensorflow-models/blazeface/0.0.7/model/model.json",this.binaryPath=null!=e?e:X}loadModels(){return e.__awaiter(this,void 0,void 0,(function*(){!function(){try{return!(!window.WebAssembly||!window.WebAssembly.compile&&!window.WebAssembly.compileStreaming)}catch(e){return!1}}()?yield this._loadCPUBackend():yield this._loadWebAssemblyBackend();try{yield M.ready(),this._model=yield a.jitteredExponentialRetry(A.load,[{modelUrl:this.faceModelUrl}])}catch(e){throw new Error("There was an error loading the blazeface model. If you are using a custom blazeface model url ensure that it is a fully qualified url that returns a json file.")}}))}detectFaces(t){return e.__awaiter(this,void 0,void 0,(function*(){const e=yield this._model.estimateFaces(t,!1,!0,!0),a=Date.now();return e.filter((e=>!!e.landmarks)).map((e=>{const{topLeft:t,bottomRight:i,probability:r,landmarks:n}=e,[o,s]=t,[c,l]=i,d=Math.abs(o-c),h=Math.abs(l-s),u=n[0],m=n[1],f=n[2],v=n[3];return{top:s,left:c,width:d,height:h,timestampMs:a,probability:r[0],rightEye:u,leftEye:m,mouth:v,nose:f}}))}))}_loadWebAssemblyBackend(){return e.__awaiter(this,void 0,void 0,(function*(){try{w.setWasmPaths(this.binaryPath),yield a.jitteredExponentialRetry((()=>e.__awaiter(this,void 0,void 0,(function*(){if(!(yield M.setBackend("wasm")))throw new Error("Initialization of backend wasm failed")}))),[]),this.modelBackend="wasm"}catch(e){throw new Error('There was an error loading the TFJS WASM backend. If you are using a custom WASM path ensure that it ends with "/" and that it is not the full URL as @tensorflow/tfjs-backend-wasm will append the wasm binary file name. Read more: https://github.com/tensorflow/tfjs/blob/master/tfjs-backend-wasm/src/backend_wasm.ts#L475.')}}))}_loadCPUBackend(){return e.__awaiter(this,void 0,void 0,(function*(){yield M.setBackend("cpu"),this.modelBackend="cpu"}))}}class K{constructor(e,t={}){if("undefined"==typeof MediaRecorder)throw Error("MediaRecorder is not supported by this browser");this._stream=e,this._options=t,this._chunks=[],this._recorder=new MediaRecorder(e,{bitsPerSecond:1e6}),this._setupCallbacks()}getState(){return this._recorder.state}start(e){this.clearRecordedData(),this.recordingStartApiTimestamp=Date.now(),this._recorder.start(e)}stop(){return e.__awaiter(this,void 0,void 0,(function*(){return"recording"===this.getState()&&this._recorder.stop(),this._recorderStopped}))}pause(){this._recorder.pause()}clearRecordedData(){this._chunks=[]}dispatch(e){this._recorder.dispatchEvent(e)}getVideoChunkSize(){return this._chunks.length}_setupCallbacks(){this.videoStream=new ReadableStream({start:e=>{this._recorder&&(this._recorder.ondataavailable=t=>{t.data&&t.data.size>0&&(0===this._chunks.length&&(this.firstChunkTimestamp=Date.now()),this._chunks.push(t.data),e.enqueue(t.data))},this._recorder.addEventListener("clientSesssionInfo",(t=>{e.enqueue(t.data.clientInfo)})),this._recorder.addEventListener("stopVideo",(()=>{e.enqueue("stopVideo")})),this._recorder.addEventListener("endStream",(()=>{e.close()})),this._recorder.addEventListener("endStreamWithCode",(t=>{e.enqueue({type:"endStreamWithCode",code:t.data.code})})))}}),this.recorderStarted=new Promise((e=>{this._recorder.onstart=()=>{this.recorderStartTimestamp=Date.now(),e()}})),this._recorderStopped=new Promise((e=>{this._recorder.onstop=()=>{this.recorderEndTimestamp=Date.now(),e()}})),this._recorder.onerror=()=>{"stopped"!==this.getState()&&this.stop()}}}const Q=2e3,J=t=>{return t[Symbol.asyncIterator]?t:(a=t,"function"==typeof ReadableStream&&a instanceof ReadableStream?h.readableStreamtoIterable(t):{[Symbol.asyncIterator]:function(){return e.__asyncGenerator(this,arguments,(function*(){yield yield e.__await(t)}))}});var a};class ee{constructor(e,t=new u.FetchHttpHandler){this.metadata={handlerProtocol:"websocket/h1.1"},this.sockets={},this.utf8decoder=new TextDecoder,this.httpHandler=t,this.configPromise="function"==typeof e?e().then((e=>null!=e?e:{})):Promise.resolve(null!=e?e:{})}destroy(){for(const[e,t]of Object.entries(this.sockets)){for(const e of t)e.close(1e3,"Socket closed through destroy() call");delete this.sockets[e]}}handle(t){return e.__awaiter(this,void 0,void 0,(function*(){if(!(e=>"ws:"===e.protocol||"wss:"===e.protocol)(t))return this.httpHandler.handle(t);const e=d.formatUrl(t),a=new WebSocket(e);this.sockets[e]||(this.sockets[e]=[]),this.sockets[e].push(a),a.binaryType="arraybuffer";const{connectionTimeout:i=Q}=yield this.configPromise;yield this.waitForReady(a,i);const{body:r}=t,n=J(r),o=(e=>"function"==typeof ReadableStream?h.iterableToReadableStream(e):e)(this.connect(a,n));return{response:new m.HttpResponse({statusCode:200,body:o})}}))}removeNotUsableSockets(e){var t;this.sockets[e]=(null!==(t=this.sockets[e])&&void 0!==t?t:[]).filter((e=>![WebSocket.CLOSING,WebSocket.CLOSED].includes(e.readyState)))}waitForReady(e,t){return new Promise(((a,i)=>{const r=setTimeout((()=>{this.removeNotUsableSockets(e.url),i({$metadata:{httpStatusCode:500}})}),t);e.onopen=()=>{clearTimeout(r),a()}}))}connect(t,a){let i,r=!1,n=()=>{},o=()=>{};t.onmessage=e=>{o({done:!1,value:new Uint8Array(e.data)})},t.onerror=e=>{r=!0,t.close(),n(e)},t.onclose=()=>{this.removeNotUsableSockets(t.url),r||(i?n(i):o({done:!0,value:void 0}))};const s={[Symbol.asyncIterator]:()=>({next:()=>new Promise(((e,t)=>{o=e,n=t}))})};return(()=>{e.__awaiter(this,void 0,void 0,(function*(){var r,n,o,s;try{try{for(var c,l=!0,d=e.__asyncValues(a);!(r=(c=yield d.next()).done);){s=c.value,l=!1;try{const e=s,a=this.utf8decoder.decode(e);if(a.includes("closeCode")){const e=a.match(/"closeCode":([0-9]*)/);if(e){const a=e[1];t.close(parseInt(a))}continue}t.send(e)}finally{l=!0}}}catch(e){n={error:e}}finally{try{l||r||!(o=d.return)||(yield o.call(d))}finally{if(n)throw n.error}}}catch(e){i=e}finally{t.close(I)}}))})(),s}}const te=process.env.NEXT_PUBLIC_STREAMING_API_URL;function ae(e){return void 0!==e.Challenge}function ie(e){return void 0!==e.code}class re extends c.AmazonAIInterpretPredictionsProvider{constructor({sessionId:e,region:t,stream:a,videoEl:i,credentialProvider:r}){super(),this.sessionId=e,this.region=t,this._stream=a,this.videoEl=i,this.videoRecorder=new K(a),this.credentialProvider=r,this.initPromise=this.init()}getResponseStream(){return e.__awaiter(this,void 0,void 0,(function*(){return yield this.initPromise,this.responseStream}))}startRecordingLivenessVideo(){this.videoRecorder.start(1e3)}sendClientInfo(e){this.videoRecorder.dispatch(new MessageEvent("clientSesssionInfo",{data:{clientInfo:e}}))}stopVideo(){return e.__awaiter(this,void 0,void 0,(function*(){yield this.videoRecorder.stop()}))}dispatchStopVideoEvent(){this.videoRecorder.dispatch(new Event("stopVideo"))}endStreamWithCode(t){return e.__awaiter(this,void 0,void 0,(function*(){"recording"===this.videoRecorder.getState()&&(yield this.stopVideo()),this.videoRecorder.dispatch(new MessageEvent("endStreamWithCode",{data:{code:t}}))}))}init(){var t;return e.__awaiter(this,void 0,void 0,(function*(){const e=null!==(t=this.credentialProvider)&&void 0!==t?t:yield a.Credentials.get();if(!e)throw new Error("No credentials");const i={credentials:e,region:this.region,customUserAgent:`${a.getAmplifyUserAgent()} ui-react-liveness/2.0.7`,requestHandler:new ee({connectionTimeout:1e4})};te&&(i.endpointProvider=()=>({url:new URL(te)})),this._client=new l.RekognitionStreamingClient(i),this.responseStream=yield this.startLivenessVideoConnection()}))}getAsyncGeneratorFromReadableStream(t){const a=this;return this._reader=t.getReader(),function(){return e.__asyncGenerator(this,arguments,(function*(){for(;;){const{done:t,value:i}=yield e.__await(a._reader.read());if(t)return yield e.__await(void 0);if("stopVideo"===i)yield yield e.__await({VideoEvent:{VideoChunk:[],TimestampMillis:Date.now()}});else if(void 0!==i.arrayBuffer){const t=yield e.__await(i.arrayBuffer()),a=new Uint8Array(t);a.length>0&&(yield yield e.__await({VideoEvent:{VideoChunk:a,TimestampMillis:Date.now()}}))}else ae(i)?yield yield e.__await({ClientSessionInformationEvent:{Challenge:i.Challenge}}):ie(i)&&(yield yield e.__await({VideoEvent:{VideoChunk:[],TimestampMillis:{closeCode:i.code}}}))}}))}}startLivenessVideoConnection(){return e.__awaiter(this,void 0,void 0,(function*(){const e=this.getAsyncGeneratorFromReadableStream(this.videoRecorder.videoStream)();return(yield this._client.send(new l.StartFaceLivenessSessionCommand({ChallengeVersions:"FaceMovementAndLightChallenge_1.0.0",SessionId:this.sessionId,LivenessRequestStream:e,VideoWidth:this.videoEl.videoWidth.toString(),VideoHeight:this.videoEl.videoHeight.toString()}))).LivenessResponseStream}))}}var ne;!function(e){e.SCROLLING="SCROLLING",e.FLAT="FLAT"}(ne||(ne={}));class oe{constructor(e,t){this.context=e,this.freshnessColorsSequence=t,this.isFirstTick=!0}displayColorTick(){return e.__awaiter(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{setTimeout((()=>{this.displayNextColorTick(e,t)}),Math.min(10))}))}))}init(){this.stageIndex=0,this.currColorIndex=0,this.currColorSequence=this.freshnessColorsSequence[0],this.prevColorSequence=this.freshnessColorsSequence[0],this.stage=ne.FLAT,this.timeLastFlatOrScrollChange=Date.now(),this.timeLastFaceMatchChecked=Date.now()}displayNextColorTick(e,t){const{freshnessColorEl:a}=this.context.freshnessColorAssociatedParams,{ovalDetails:i,scaleFactor:r}=this.context.ovalAssociatedParams,{videoEl:n}=this.context.videoAssociatedParams,o=Date.now();this.isFirstTick&&(this.init(),this.isFirstTick=!1,this.sendColorStartTime({tickStartTime:o,currColor:this.currColorSequence.color,prevColor:this.currColorSequence.color,currColorIndex:this.stageIndex}));let s=o-this.timeLastFlatOrScrollChange;if(a.style.display="block",(this.stage===ne.FLAT&&s>=this.currColorSequence.flatDisplayDuration||this.stage===ne.SCROLLING&&s>=this.currColorSequence.downscrollDuration)&&(this.incrementStageIndex(o),s=0),this.currColorIndex<this.freshnessColorsSequence.length){const t=s/(this.stage===ne.SCROLLING?this.currColorSequence.downscrollDuration:this.currColorSequence.flatDisplayDuration);!function({overlayCanvas:e,prevColor:t,nextColor:a,videoEl:i,ovalDetails:r,heightFraction:n,scaleFactor:o}){const{x:s,y:c}=i.getBoundingClientRect(),{flippedCenterX:l,centerY:d,width:h,height:u}=r,m=l*o+s,f=d*o+c,v=e.width,g=e.height,p=e.getContext("2d");if(!p)throw new Error("Cannot find Overlay Canvas.");p.canvas.width=window.innerWidth,p.canvas.height=window.innerHeight,p.clearRect(0,0,v,g),U({ctx:p,prevColor:t,nextColor:a,fraction:n}),p.save(),p.beginPath(),p.rect(0,0,v,g),p.clip(),p.clearRect(0,0,v,g),p.globalAlpha=.9,U({ctx:p,prevColor:t,nextColor:a,fraction:n}),p.beginPath(),p.ellipse(m,f,h*o/2,u*o/2,0,0,2*Math.PI),p.strokeStyle="white",p.lineWidth=8,p.stroke(),p.clip(),p.clearRect(0,0,v,g),p.globalAlpha=.75,U({ctx:p,prevColor:t,nextColor:a,fraction:n}),p.restore()}({overlayCanvas:a,prevColor:this.prevColorSequence.color,nextColor:this.currColorSequence.color,videoEl:n,ovalDetails:i,heightFraction:t,scaleFactor:r}),e(!1)}else a.style.display="none",e(!0)}incrementStageIndex(e){if(this.stageIndex+=1,this.prevColorSequence=this.freshnessColorsSequence[this.currColorIndex],this.stage===ne.FLAT)this.currColorIndex+=1,this.stage=ne.SCROLLING;else if(this.stage===ne.SCROLLING){this.freshnessColorsSequence[this.currColorIndex].flatDisplayDuration>0?this.stage=ne.FLAT:(this.stage=ne.SCROLLING,this.currColorIndex+=1)}this.currColorSequence=this.freshnessColorsSequence[this.currColorIndex],this.timeLastFlatOrScrollChange=Date.now(),this.currColorSequence&&this.sendColorStartTime({tickStartTime:e,currColor:this.currColorSequence.color,prevColor:this.prevColorSequence.color,currColorIndex:this.stageIndex})}sendColorStartTime({tickStartTime:e,currColor:t,prevColor:a,currColorIndex:i}){const{livenessStreamProvider:r,challengeId:n}=this.context;r.sendClientInfo({Challenge:{FaceMovementAndLightChallenge:{ChallengeId:n,ColorDisplayed:{CurrentColor:{RGB:Y(t)},PreviousColor:{RGB:Y(a)},SequenceNumber:i,CurrentColorStartTimestamp:e}}}})}}const se=e=>!!(null==e?void 0:e.DisconnectionEvent),ce=e=>!!(null==e?void 0:e.ValidationException),le=e=>!!(null==e?void 0:e.InternalServerException),de=e=>!!(null==e?void 0:e.ThrottlingException),he=e=>!!(null==e?void 0:e.ServiceQuotaExceededException),ue={width:{min:320,ideal:640},height:{min:240,ideal:480},frameRate:{min:15,ideal:30,max:30},facingMode:"user"};let me;const fe=r.createMachine({id:"livenessMachine",initial:"start",predictableActionArguments:!0,context:{challengeId:f.nanoid(),maxFailedAttempts:0,failedAttempts:0,componentProps:void 0,serverSessionInformation:void 0,videoAssociatedParams:{videoConstraints:ue},ovalAssociatedParams:void 0,faceMatchAssociatedParams:{illuminationState:void 0,faceMatchState:void 0,faceMatchPercentage:25,currentDetectedFace:void 0,startFace:void 0,endFace:void 0,initialFaceMatchTime:void 0},freshnessColorAssociatedParams:{freshnessColorEl:void 0,freshnessColors:[],freshnessColorsComplete:!1,freshnessColorDisplay:void 0},errorState:void 0,livenessStreamProvider:void 0,responseStreamActorRef:void 0,shouldDisconnect:!1,faceMatchStateBeforeStart:void 0,isFaceFarEnoughBeforeRecording:void 0,isRecordingStopped:!1},on:{CANCEL:"userCancel",TIMEOUT:{target:"retryableTimeout",actions:"updateErrorStateForTimeout"},SET_SESSION_INFO:{internal:!0,actions:"updateSessionInfo"},DISCONNECT_EVENT:{internal:!0,actions:"updateShouldDisconnect"},SET_DOM_AND_CAMERA_DETAILS:{actions:"setDOMAndCameraDetails"},SERVER_ERROR:{target:"error",actions:"updateErrorStateForServer"},RUNTIME_ERROR:{target:"error"},MOBILE_LANDSCAPE_WARNING:{target:"mobileLandscapeWarning",actions:"updateErrorStateForServer"}},states:{start:{on:{BEGIN:"cameraCheck"}},cameraCheck:{entry:["resetErrorState","initializeFaceDetector"],invoke:{src:"checkVirtualCameraAndGetStream",onDone:{target:"waitForDOMAndCameraDetails",actions:["updateVideoMediaStream"]},onError:{target:"permissionDenied"}}},waitForDOMAndCameraDetails:{after:{0:{target:"detectFaceBeforeStart",cond:"hasDOMAndCameraDetails"},500:{target:"waitForDOMAndCameraDetails"}}},detectFaceBeforeStart:{invoke:{src:"detectFace",onDone:{target:"checkFaceDetectedBeforeStart",actions:["updateFaceMatchBeforeStartDetails"]}}},checkFaceDetectedBeforeStart:{after:{0:{target:"detectFaceDistanceBeforeRecording",cond:"hasSingleFaceBeforeStart"},100:{target:"detectFaceBeforeStart"}}},detectFaceDistanceBeforeRecording:{invoke:{src:"detectFaceDistance",onDone:{target:"checkFaceDistanceBeforeRecording",actions:["updateFaceDistanceBeforeRecording"]}}},checkFaceDistanceBeforeRecording:{after:{0:{target:"initializeLivenessStream",cond:"hasEnoughFaceDistanceBeforeRecording"},100:{target:"detectFaceDistanceBeforeRecording"}}},initializeLivenessStream:{invoke:{src:"openLivenessStreamConnection",onDone:{target:"notRecording",actions:["updateLivenessStreamProvider","spawnResponseStreamActor"]}}},notRecording:{on:{START_RECORDING:"recording"},initial:"waitForSessionInfo",states:{waitForSessionInfo:{after:{0:{target:"#livenessMachine.recording",cond:"hasServerSessionInfo"},100:{target:"detectFaceDistanceDuringLoading"}}},detectFaceDistanceDuringLoading:{invoke:{src:"detectFaceDistanceWhileLoading",onDone:{target:"checkFaceDistanceDuringLoading",actions:["updateFaceDistanceWhileLoading"]}}},checkFaceDistanceDuringLoading:{always:[{target:"failure",cond:"hasNotEnoughFaceDistanceBeforeRecording"},{target:"waitForSessionInfo"}]},failure:{entry:"sendTimeoutAfterFaceDistanceDelay",type:"final"}}},recording:{entry:["clearErrorState","startRecording"],initial:"ovalDrawing",states:{ovalDrawing:{entry:["sendTimeoutAfterOvalDrawingDelay"],invoke:{src:"detectInitialFaceAndDrawOval",onDone:{target:"checkFaceDetected",actions:["updateOvalAndFaceDetailsPostDraw","sendTimeoutAfterOvalMatchDelay"]},onError:{target:"#livenessMachine.error",actions:"updateErrorStateForRuntime"}}},checkFaceDetected:{after:{0:{target:"checkRecordingStarted",cond:"hasSingleFace"},100:{target:"ovalDrawing"}}},checkRecordingStarted:{after:{0:{target:"ovalMatching",cond:"hasRecordingStarted",actions:["updateRecordingStartTimestampMs"]},100:{target:"checkRecordingStarted"}}},ovalMatching:{entry:["cancelOvalDrawingTimeout"],invoke:{src:"detectFaceAndMatchOval",onDone:{target:"checkMatch",actions:"updateFaceDetailsPostMatch"}}},checkMatch:{after:{0:{target:"flashFreshnessColors",cond:"hasFaceMatchedInOvalWithMinTime",actions:["updateEndFaceMatch","setupFlashFreshnessColors","cancelOvalMatchTimeout","cancelOvalDrawingTimeout"]},.1:{target:"ovalMatching",cond:"hasFaceMatchedInOval",actions:"setFaceMatchTimeAndStartFace"},1:{target:"ovalMatching",cond:"hasNotFaceMatchedInOval"}}},flashFreshnessColors:{invoke:{src:"flashColors",onDone:[{target:"success",cond:"hasFreshnessColorShown"},{target:"flashFreshnessColors",actions:"updateFreshnessDetails"}]}},success:{entry:["stopRecording"],type:"final"}},onDone:"uploading"},uploading:{initial:"pending",states:{pending:{entry:["sendTimeoutAfterWaitingForDisconnect","pauseVideoStream"],invoke:{src:"stopVideo",onDone:"waitForDisconnectEvent",onError:{target:"#livenessMachine.error",actions:"updateErrorStateForRuntime"}}},waitForDisconnectEvent:{after:{0:{target:"getLivenessResult",cond:"getShouldDisconnect"},100:{target:"waitForDisconnectEvent"}}},getLivenessResult:{entry:["cancelWaitForDisconnectTimeout","freezeStream"],invoke:{src:"getLiveness",onError:{target:"#livenessMachine.error",actions:"updateErrorStateForServer"}}}}},retryableTimeout:{entry:"updateFailedAttempts",always:[{target:"timeout",cond:"shouldTimeoutOnFailedAttempts"},{target:"notRecording"}]},permissionDenied:{entry:"callUserPermissionDeniedCallback",on:{RETRY_CAMERA_CHECK:"cameraCheck"}},mobileLandscapeWarning:{entry:"callMobileLandscapeWarningCallback",always:[{target:"error"}]},timeout:{entry:["cleanUpResources","callUserTimeoutCallback","freezeStream"]},error:{entry:["cleanUpResources","callErrorCallback","cancelOvalDrawingTimeout","cancelWaitForDisconnectTimeout","cancelOvalMatchTimeout","freezeStream"]},userCancel:{entry:["cleanUpResources","callUserCancelCallback","resetContext"],always:[{target:"start"}]}}},{actions:{spawnResponseStreamActor:r.assign({responseStreamActorRef:()=>r.spawn(ve)}),updateFailedAttempts:r.assign({failedAttempts:e=>e.failedAttempts+1}),updateVideoMediaStream:r.assign({videoAssociatedParams:(e,t)=>{var a;return Object.assign(Object.assign({},e.videoAssociatedParams),{videoMediaStream:null===(a=t.data)||void 0===a?void 0:a.stream})}}),initializeFaceDetector:r.assign({ovalAssociatedParams:e=>{const{componentProps:t}=e,{faceModelUrl:a,binaryPath:i}=t.config,r=new Z(i,a);return r.triggerModelLoading(),Object.assign(Object.assign({},e.ovalAssociatedParams),{faceDetector:r})}}),updateLivenessStreamProvider:r.assign({livenessStreamProvider:(e,t)=>{var a;return null===(a=t.data)||void 0===a?void 0:a.livenessStreamProvider}}),setDOMAndCameraDetails:r.assign({videoAssociatedParams:(e,t)=>{var a,i,r;return Object.assign(Object.assign({},e.videoAssociatedParams),{videoEl:null===(a=t.data)||void 0===a?void 0:a.videoEl,canvasEl:null===(i=t.data)||void 0===i?void 0:i.canvasEl,isMobile:null===(r=t.data)||void 0===r?void 0:r.isMobile})},freshnessColorAssociatedParams:(e,t)=>{var a;return Object.assign(Object.assign({},e.freshnessColorAssociatedParams),{freshnessColorEl:null===(a=t.data)||void 0===a?void 0:a.freshnessColorEl})}}),updateRecordingStartTimestampMs:r.assign({videoAssociatedParams:e=>{const{challengeId:t,videoAssociatedParams:a,ovalAssociatedParams:i,livenessStreamProvider:r}=e,{recordingStartApiTimestamp:n,recorderStartTimestamp:o}=r.videoRecorder,{videoMediaStream:s}=a,{initialFace:c}=i,l=Math.round(.73*(o-n)+n),{width:d,height:h}=s.getTracks()[0].getSettings(),u=d-c.left-c.width;return e.livenessStreamProvider.sendClientInfo({Challenge:{FaceMovementAndLightChallenge:{ChallengeId:t,VideoStartTimestamp:l,InitialFace:{InitialFaceDetectedTimestamp:c.timestampMs,BoundingBox:G({deviceHeight:h,deviceWidth:d,height:c.height,width:c.width,top:c.top,left:u})}}}}),Object.assign(Object.assign({},e.videoAssociatedParams),{recordingStartTimestampMs:l})}}),startRecording:r.assign({videoAssociatedParams:e=>{if(!e.serverSessionInformation)throw new Error("Session information was not received from response stream");return e.livenessStreamProvider.videoRecorder&&"recording"!==e.livenessStreamProvider.videoRecorder.getState()&&e.livenessStreamProvider.startRecordingLivenessVideo(),Object.assign({},e.videoAssociatedParams)}}),stopRecording:e=>{},updateFaceMatchBeforeStartDetails:r.assign({faceMatchStateBeforeStart:(e,t)=>t.data.faceMatchState}),updateFaceDistanceBeforeRecording:r.assign({isFaceFarEnoughBeforeRecording:(e,t)=>t.data.isFaceFarEnoughBeforeRecording}),updateFaceDistanceWhileLoading:r.assign({isFaceFarEnoughBeforeRecording:(e,t)=>t.data.isFaceFarEnoughBeforeRecording,errorState:(e,t)=>{var a;return null===(a=t.data)||void 0===a?void 0:a.error}}),updateOvalAndFaceDetailsPostDraw:r.assign({ovalAssociatedParams:(e,t)=>Object.assign(Object.assign({},e.ovalAssociatedParams),{initialFace:t.data.initialFace,ovalDetails:t.data.ovalDetails,scaleFactor:t.data.scaleFactor}),faceMatchAssociatedParams:(e,t)=>Object.assign(Object.assign({},e.faceMatchAssociatedParams),{faceMatchState:t.data.faceMatchState,illuminationState:t.data.illuminationState})}),updateFaceDetailsPostMatch:r.assign({faceMatchAssociatedParams:(e,t)=>Object.assign(Object.assign({},e.faceMatchAssociatedParams),{faceMatchState:t.data.faceMatchState,faceMatchPercentage:t.data.faceMatchPercentage,illuminationState:t.data.illuminationState,currentDetectedFace:t.data.detectedFace})}),updateEndFaceMatch:r.assign({faceMatchAssociatedParams:e=>Object.assign(Object.assign({},e.faceMatchAssociatedParams),{endFace:e.faceMatchAssociatedParams.currentDetectedFace})}),setFaceMatchTimeAndStartFace:r.assign({faceMatchAssociatedParams:e=>Object.assign(Object.assign({},e.faceMatchAssociatedParams),{startFace:void 0===e.faceMatchAssociatedParams.startFace?e.faceMatchAssociatedParams.currentDetectedFace:e.faceMatchAssociatedParams.startFace,initialFaceMatchTime:void 0===e.faceMatchAssociatedParams.initialFaceMatchTime?Date.now():e.faceMatchAssociatedParams.initialFaceMatchTime})}),resetErrorState:r.assign({errorState:e=>{}}),updateErrorStateForTimeout:r.assign({errorState:(e,t)=>{var a;return(null===(a=t.data)||void 0===a?void 0:a.errorState)||F.TIMEOUT}}),updateErrorStateForRuntime:r.assign({errorState:(e,t)=>{var a;return(null===(a=t.data)||void 0===a?void 0:a.errorState)||F.RUNTIME_ERROR}}),updateErrorStateForServer:r.assign({errorState:e=>F.SERVER_ERROR}),clearErrorState:r.assign({errorState:e=>{}}),updateSessionInfo:r.assign({serverSessionInformation:(e,t)=>t.data.sessionInfo}),updateShouldDisconnect:r.assign({shouldDisconnect:e=>!0}),updateFreshnessDetails:r.assign({freshnessColorAssociatedParams:(e,t)=>Object.assign(Object.assign({},e.freshnessColorAssociatedParams),{freshnessColorsComplete:t.data.freshnessColorsComplete})}),setupFlashFreshnessColors:r.assign({freshnessColorAssociatedParams:e=>{const{serverSessionInformation:t}=e,a=(t.Challenge.FaceMovementAndLightChallenge.ColorSequences||[]).map((({FreshnessColor:e,DownscrollDuration:t,FlatDisplayDuration:a})=>{const i=e.RGB,r=`rgb(${i[0]},${i[1]},${i[2]})`;return void 0!==r&&void 0!==t&&void 0!==a?{color:r,downscrollDuration:t,flatDisplayDuration:a}:void 0})).filter(q);const i=new oe(e,a);return Object.assign(Object.assign({},e.freshnessColorAssociatedParams),{freshnessColorDisplay:i})}}),sendTimeoutAfterOvalDrawingDelay:r.actions.send({type:"TIMEOUT"},{delay:5e3,id:"ovalDrawingTimeout"}),cancelOvalDrawingTimeout:r.actions.cancel("ovalDrawingTimeout"),sendTimeoutAfterOvalMatchDelay:r.actions.send({type:"TIMEOUT"},{delay:e=>{var t,a,i,r;return(null===(r=null===(i=null===(a=null===(t=e.serverSessionInformation)||void 0===t?void 0:t.Challenge)||void 0===a?void 0:a.FaceMovementAndLightChallenge)||void 0===i?void 0:i.ChallengeConfig)||void 0===r?void 0:r.OvalFitTimeout)||7e3},id:"ovalMatchTimeout"}),cancelOvalMatchTimeout:r.actions.cancel("ovalMatchTimeout"),sendTimeoutAfterWaitingForDisconnect:r.actions.send({type:"TIMEOUT",data:{errorState:F.SERVER_ERROR}},{delay:2e4,id:"waitForDisconnectTimeout"}),cancelWaitForDisconnectTimeout:r.actions.cancel("waitForDisconnectTimeout"),sendTimeoutAfterFaceDistanceDelay:r.actions.send({type:"RUNTIME_ERROR",data:new Error("Avoid moving closer during countdown and ensure only one face is in front of camera.")},{delay:0,id:"faceDistanceTimeout"}),cancelFaceDistanceTimeout:r.actions.cancel("faceDistanceTimeout"),callUserPermissionDeniedCallback:r.assign({errorState:(e,t)=>{var a,i;let r;r=t.data.message.includes("15 fps")?F.CAMERA_FRAMERATE_ERROR:F.CAMERA_ACCESS_ERROR;const n=t.data.message||t.data.Message,o={state:r,error:new Error(n)};return null===(i=(a=e.componentProps).onError)||void 0===i||i.call(a,o),r}}),callMobileLandscapeWarningCallback:r.assign({errorState:e=>F.MOBILE_LANDSCAPE_ERROR}),callUserCancelCallback:t=>e.__awaiter(void 0,void 0,void 0,(function*(){var e,a;null===(a=(e=t.componentProps).onUserCancel)||void 0===a||a.call(e)})),callUserTimeoutCallback:t=>e.__awaiter(void 0,void 0,void 0,(function*(){var e,a;const i=new Error("Client Timeout");i.name=t.errorState;const r={state:t.errorState,error:i};null===(a=(e=t.componentProps).onError)||void 0===a||a.call(e,r)})),callErrorCallback:(t,a)=>e.__awaiter(void 0,void 0,void 0,(function*(){var e,i,r;const n={state:t.errorState,error:(null===(e=a.data)||void 0===e?void 0:e.error)||a.data};null===(r=(i=t.componentProps).onError)||void 0===r||r.call(i,n)})),cleanUpResources:t=>e.__awaiter(void 0,void 0,void 0,(function*(){var e;const{freshnessColorEl:a}=t.freshnessColorAssociatedParams;a&&(a.style.display="none");let i=O;t.errorState===F.TIMEOUT?i=b:t.errorState===F.RUNTIME_ERROR?i=k:t.errorState===F.FACE_DISTANCE_ERROR||t.errorState===F.MULTIPLE_FACES_ERROR?i=L:void 0===t.errorState&&(i=P),yield null===(e=t.livenessStreamProvider)||void 0===e?void 0:e.endStreamWithCode(i)})),freezeStream:t=>e.__awaiter(void 0,void 0,void 0,(function*(){const{videoMediaStream:e,videoEl:a}=t.videoAssociatedParams;t.isRecordingStopped=!0,null==a||a.pause(),null==e||e.getTracks().forEach((function(e){e.stop()}))})),pauseVideoStream:t=>e.__awaiter(void 0,void 0,void 0,(function*(){const{videoEl:e}=t.videoAssociatedParams;t.isRecordingStopped=!0,e.pause()})),resetContext:r.assign({challengeId:f.nanoid(),maxFailedAttempts:0,failedAttempts:0,componentProps:e=>e.componentProps,serverSessionInformation:e=>{},videoAssociatedParams:e=>({videoConstraints:ue}),ovalAssociatedParams:e=>{},errorState:e=>{},livenessStreamProvider:e=>{},responseStreamActorRef:e=>{},shouldDisconnect:!1,faceMatchStateBeforeStart:e=>{},isFaceFarEnoughBeforeRecording:e=>{},isRecordingStopped:!1})},guards:{shouldTimeoutOnFailedAttempts:e=>e.failedAttempts>=e.maxFailedAttempts,hasFaceMatchedInOvalWithMinTime:e=>{const{faceMatchState:t,initialFaceMatchTime:a}=e.faceMatchAssociatedParams,i=Date.now()-a;return t===y.MATCHED&&i>=500},hasFaceMatchedInOval:e=>e.faceMatchAssociatedParams.faceMatchState===y.MATCHED,hasNotFaceMatchedInOval:e=>e.faceMatchAssociatedParams.faceMatchState!==y.MATCHED,hasSingleFace:e=>e.faceMatchAssociatedParams.faceMatchState===y.FACE_IDENTIFIED,hasSingleFaceBeforeStart:e=>e.faceMatchStateBeforeStart===y.FACE_IDENTIFIED,hasEnoughFaceDistanceBeforeRecording:e=>e.isFaceFarEnoughBeforeRecording,hasNotEnoughFaceDistanceBeforeRecording:e=>!e.isFaceFarEnoughBeforeRecording,hasLivenessCheckSucceeded:(e,t,a)=>a.state.event.data.isLive,hasFreshnessColorShown:e=>e.freshnessColorAssociatedParams.freshnessColorsComplete,hasServerSessionInfo:e=>void 0!==e.serverSessionInformation,hasDOMAndCameraDetails:e=>void 0!==e.videoAssociatedParams.videoEl&&void 0!==e.videoAssociatedParams.canvasEl&&void 0!==e.freshnessColorAssociatedParams.freshnessColorEl,getShouldDisconnect:e=>!!e.shouldDisconnect,hasRecordingStarted:e=>void 0!==e.livenessStreamProvider.videoRecorder.firstChunkTimestamp},services:{checkVirtualCameraAndGetStream(t){return e.__awaiter(this,void 0,void 0,(function*(){const{videoConstraints:e}=t.videoAssociatedParams,a=yield navigator.mediaDevices.getUserMedia({video:e,audio:!1}),i=(yield navigator.mediaDevices.enumerateDevices()).filter((e=>"videoinput"===e.kind)).filter((e=>!function(e){return e.label.toLowerCase().includes("virtual")}(e)));if(!i.length)throw new Error("No real video devices found");const r=a.getTracks().filter((e=>e.getSettings().frameRate>=15));if(r.length<1)throw new Error("No camera found with more than 15 fps");const n=r[0].getSettings().deviceId;let o=a;return i.some((e=>e.deviceId===n))||(o=yield navigator.mediaDevices.getUserMedia({video:Object.assign(Object.assign({},e),{deviceId:{exact:i[0].deviceId}}),audio:!1})),{stream:o}}))},openLivenessStreamConnection(t){return e.__awaiter(this,void 0,void 0,(function*(){const{config:e}=t.componentProps,{credentialProvider:a}=e,i=new re({sessionId:t.componentProps.sessionId,region:t.componentProps.region,stream:t.videoAssociatedParams.videoMediaStream,videoEl:t.videoAssociatedParams.videoEl,credentialProvider:a});return me=i.getResponseStream(),{livenessStreamProvider:i}}))},detectFace(t){return e.__awaiter(this,void 0,void 0,(function*(){const{videoEl:a}=t.videoAssociatedParams,{faceDetector:i}=t.ovalAssociatedParams;try{yield i.modelLoadingPromise}catch(e){console.log({err:e})}const r=yield function(t,a){return e.__awaiter(this,void 0,void 0,(function*(){let e;switch((yield t.detectFaces(a)).length){case 0:e=y.CANT_IDENTIFY;break;case 1:e=y.FACE_IDENTIFIED;break;default:e=y.TOO_MANY}return e}))}(i,a);return{faceMatchState:r}}))},detectFaceDistance(t){return e.__awaiter(this,void 0,void 0,(function*(){const{isFaceFarEnoughBeforeRecording:e}=t,{videoEl:a,videoMediaStream:i,isMobile:r}=t.videoAssociatedParams,{faceDetector:n}=t.ovalAssociatedParams,{width:o,height:s}=i.getTracks()[0].getSettings(),c=W({width:o,height:s}),{isDistanceBelowThreshold:l}=yield $({faceDetector:n,videoEl:a,ovalDetails:c,reduceThreshold:e,isMobile:r});return{isFaceFarEnoughBeforeRecording:l}}))},detectFaceDistanceWhileLoading(t){return e.__awaiter(this,void 0,void 0,(function*(){const{isFaceFarEnoughBeforeRecording:e}=t,{videoEl:a,videoMediaStream:i,isMobile:r}=t.videoAssociatedParams,{faceDetector:n}=t.ovalAssociatedParams,{width:o,height:s}=i.getTracks()[0].getSettings(),c=W({width:o,height:s}),{isDistanceBelowThreshold:l,error:d}=yield $({faceDetector:n,videoEl:a,ovalDetails:c,reduceThreshold:e,isMobile:r});return{isFaceFarEnoughBeforeRecording:l,error:d}}))},detectInitialFaceAndDrawOval(t){return e.__awaiter(this,void 0,void 0,(function*(){const{serverSessionInformation:e,livenessStreamProvider:a}=t,{videoEl:i,canvasEl:r,isMobile:n}=t.videoAssociatedParams,{faceDetector:o}=t.ovalAssociatedParams;try{yield o.modelLoadingPromise,yield a.videoRecorder.recorderStarted}catch(e){console.log({err:e})}const s=yield o.detectFaces(i);let c,l,d;switch(s.length){case 0:l=y.CANT_IDENTIFY,d=z(i);break;case 1:l=y.FACE_IDENTIFIED,c=s[0];break;default:l=y.TOO_MANY}if(!c)return{faceMatchState:l,illuminationState:d};const{width:h,height:u}=i.getBoundingClientRect();n?(r.width=window.innerWidth,r.height=window.innerHeight):(r.width=h,r.height=u);const m=h/i.videoWidth,f=function({sessionInformation:e,videoWidth:t}){var a,i;const r=null===(i=null===(a=null==e?void 0:e.Challenge)||void 0===a?void 0:a.FaceMovementAndLightChallenge)||void 0===i?void 0:i.OvalParameters;if(!(r&&r.CenterX&&r.CenterY&&r.Width&&r.Height))throw new Error("Oval parameters not returned from session information.");return{flippedCenterX:t-r.CenterX,centerX:r.CenterX,centerY:r.CenterY,width:r.Width,height:r.Height}}({sessionInformation:e,videoWidth:i.width}),v=j(c,f);return c.top=v.top,c.left=v.left,c.height=v.bottom-v.top,c.width=v.right-v.left,function({canvas:e,oval:t,scaleFactor:a,videoEl:i}){const{flippedCenterX:r,centerY:n,width:o,height:s}=t,{width:c,height:l}=e.getBoundingClientRect(),d=e.getContext("2d");if(!d)throw new Error("Cannot find Canvas.");{d.clearRect(0,0,c,l),d.fillStyle="rgba(255, 255, 255, 1.0)",d.fillRect(0,0,c,l);const e={width:i.videoWidth,height:i.videoHeight},t={x:(c-e.width*a)/2,y:(l-e.height*a)/2};d.setTransform(a,0,0,a,t.x,t.y),d.beginPath(),d.ellipse(r,n,o/2,s/2,0,0,2*Math.PI),d.strokeStyle="#AEB3B7",d.lineWidth=3,d.stroke(),d.clip(),d.setTransform(1,0,0,1,0,0),d.clearRect(0,0,c,l)}}({canvas:r,oval:f,scaleFactor:m,videoEl:i}),{faceMatchState:l,ovalDetails:f,scaleFactor:m,initialFace:c}}))},detectFaceAndMatchOval(t){return e.__awaiter(this,void 0,void 0,(function*(){const{serverSessionInformation:e}=t,{videoEl:a}=t.videoAssociatedParams,{faceDetector:i,ovalDetails:r,initialFace:n}=t.ovalAssociatedParams,o=yield i.detectFaces(a);let s,c,l,d=0;const h=j(n,r),{ovalBoundingBox:u}=H(r),m=B(h,u);switch(o.length){case 0:s=y.CANT_IDENTIFY,l=z(a);break;case 1:{c=o[0];const{faceMatchState:t,faceMatchPercentage:a}=function(e,t,a,i){var r,n;let o;const s=null===(n=null===(r=null==i?void 0:i.Challenge)||void 0===r?void 0:r.FaceMovementAndLightChallenge)||void 0===n?void 0:n.ChallengeConfig;if(!(s&&s.OvalIouThreshold&&s.OvalIouHeightThreshold&&s.OvalIouWidthThreshold&&s.FaceIouHeightThreshold&&s.FaceIouWidthThreshold))throw new Error("Challenge information not returned from session information.");const{OvalIouThreshold:c,OvalIouHeightThreshold:l,OvalIouWidthThreshold:d,FaceIouHeightThreshold:h,FaceIouWidthThreshold:u}=s,m=j(e,t),f=m.left,v=m.right,g=m.top,p=m.bottom,{ovalBoundingBox:E,minOvalX:T,minOvalY:C,maxOvalX:S,maxOvalY:F}=H(t),x=B(m,E),R=c,M=t.width*d,A=t.height*l,w=t.width*u,_=t.height*h,D=100*Math.max(Math.min(1,.75*(x-a)/(R-a)+.25),0);return o=x>R&&Math.abs(T-f)<M&&Math.abs(S-v)<M&&Math.abs(F-p)<A?y.MATCHED:C-g>_||p-F>_||T-f>w&&v-S>w?y.TOO_CLOSE:y.TOO_FAR,{faceMatchState:o,faceMatchPercentage:D}}(c,r,m,e);s=t,d=a;break}default:s=y.TOO_MANY}return{faceMatchState:s,faceMatchPercentage:d,illuminationState:l,detectedFace:c}}))},flashColors(t){return e.__awaiter(this,void 0,void 0,(function*(){const{freshnessColorsComplete:e,freshnessColorDisplay:a}=t.freshnessColorAssociatedParams;if(e)return;return{freshnessColorsComplete:yield a.displayColorTick()}}))},stopVideo(t){return e.__awaiter(this,void 0,void 0,(function*(){const{challengeId:e,livenessStreamProvider:a}=t,{videoMediaStream:i}=t.videoAssociatedParams,{initialFace:r,ovalDetails:n}=t.ovalAssociatedParams,{startFace:o,endFace:s}=t.faceMatchAssociatedParams,{width:c,height:l}=i.getTracks()[0].getSettings(),d=c-r.left-r.width;yield a.stopVideo();const h={Challenge:{FaceMovementAndLightChallenge:{ChallengeId:e,InitialFace:{InitialFaceDetectedTimestamp:r.timestampMs,BoundingBox:G({deviceHeight:l,deviceWidth:c,height:r.height,width:r.width,top:r.top,left:d})},TargetFace:{FaceDetectedInTargetPositionStartTimestamp:o.timestampMs,FaceDetectedInTargetPositionEndTimestamp:s.timestampMs,BoundingBox:G({deviceHeight:l,deviceWidth:c,height:n.height,width:n.width,top:n.centerY-n.height/2,left:n.centerX-n.width/2})},VideoEndTimestamp:a.videoRecorder.recorderEndTimestamp}}};if(0===a.videoRecorder.getVideoChunkSize())throw new Error("Video chunks not recorded successfully.");a.sendClientInfo(h),yield a.dispatchStopVideoEvent()}))},getLiveness(t){return e.__awaiter(this,void 0,void 0,(function*(){const{onAnalysisComplete:e}=t.componentProps;yield e()}))}}}),ve=t=>e.__awaiter(void 0,void 0,void 0,(function*(){var a,i,r,n,o;try{const d=yield me;try{for(var s,c=!0,l=e.__asyncValues(d);!(a=(s=yield l.next()).done);){n=s.value,c=!1;try{const e=n;(null==(o=e)?void 0:o.ServerSessionInformationEvent)?t({type:"SET_SESSION_INFO",data:{sessionInfo:e.ServerSessionInformationEvent.SessionInformation}}):se(e)?t({type:"DISCONNECT_EVENT"}):ce(e)?t({type:"SERVER_ERROR",data:{error:Object.assign({},e.ValidationException)}}):le(e)?t({type:"SERVER_ERROR",data:{error:Object.assign({},e.InternalServerException)}}):de(e)?t({type:"SERVER_ERROR",data:{error:Object.assign({},e.ThrottlingException)}}):he(e)&&t({type:"SERVER_ERROR",data:{error:Object.assign({},e.ServiceQuotaExceededException)}})}finally{c=!0}}}catch(e){i={error:e}}finally{try{c||a||!(r=l.return)||(yield r.call(l))}finally{if(i)throw i.error}}}catch(e){let a=e;(e=>{const{message:t,name:a}=e;return"InvalidSignatureException"===a&&t.includes("valid region")})(e)&&(a=new Error("Invalid region in FaceLivenessDetector or credentials are scoped to the wrong region.")),a instanceof Error&&t({type:"SERVER_ERROR",data:{error:a}})}})),ge=x.default.createContext(null);function pe(t){var{children:a}=t,i=e.__rest(t,["children"]);return x.default.createElement(ge.Provider,{value:i},a)}function Ee(){const e=x.default.useContext(ge);if(null===e)throw new Error("useFaceLivenessDetector must be used within a FaceLivenessDetectorProvider");return e}function Te(){const{service:e}=Ee();return i.useActor(e)}function Ce(e){const{service:t}=Ee();return i.useSelector(t,e)}var Se;!function(e){e.CameraModule="amplify-liveness-camera-module",e.CancelContainer="amplify-liveness-cancel-container",e.CancelButton="amplify-liveness-cancel-button",e.CountdownContainer="amplify-liveness-countdown-container",e.DescriptionBullet="amplify-liveness-description-bullet",e.DescriptionBulletIndex="amplify-liveness-description-bullet__index",e.DescriptionBulletIndexText="amplify-liveness-description-bullet__index__text",e.DescriptionBulletMessage="amplify-liveness-description-bullet__message",e.ErrorModal="amplify-liveness-error-modal",e.ErrorModalHeading="amplify-liveness-error-modal__heading",e.FadeOut="amplify-liveness-fade-out",e.FreshnessCanvas="amplify-liveness-freshness-canvas",e.InstructionList="amplify-liveness-instruction-list",e.InstructionOverlay="amplify-liveness-instruction-overlay",e.Figure="amplify-liveness-figure",e.FigureCaption="amplify-liveness-figure__caption",e.FigureIcon="amplify-liveness-figure__icon",e.FigureImage="amplify-liveness-figure__image",e.Figures="amplify-liveness-figures",e.Hint="amplify-liveness-hint",e.HintText="amplify-liveness-hint__text",e.LandscapeErrorModal="amplify-liveness-landscape-error-modal",e.LandscapeErrorModalButton="amplify-liveness-landscape-error-modal__button",e.LandscapeErrorModalHeader="amplify-liveness-landscape-error-modal__header",e.Loader="amplify-liveness-loader",e.MatchIndicator="amplify-liveness-match-indicator",e.OvalCanvas="amplify-liveness-oval-canvas",e.OpaqueOverlay="amplify-liveness-overlay-opaque",e.Overlay="amplify-liveness-overlay",e.Popover="amplify-liveness-popover",e.PopoverContainer="amplify-liveness-popover__container",e.PopoverAnchor="amplify-liveness-popover__anchor",e.PopoverAnchorSecondary="amplify-liveness-popover__anchor-secondary",e.RecordingIconContainer="amplify-liveness-recording-icon-container",e.RecordingIcon="amplify-liveness-recording-icon",e.StartScreenHeader="amplify-liveness-start-screen-header",e.StartScreenHeaderBody="amplify-liveness-start-screen-header__body",e.StartScreenHeaderHeading="amplify-liveness-start-screen-header__heading",e.StartScreenWarning="amplify-liveness-start-screen-warning",e.StartScreenInstructions="amplify-liveness-start-screen-instructions",e.StartScreenInstructionsHeading="amplify-liveness-start-screen-instructions__heading",e.Toast="amplify-liveness-toast",e.ToastContainer="amplify-liveness-toast__container",e.ToastMessage="amplify-liveness-toast__message",e.Video="amplify-liveness-video",e.VideoAnchor="amplify-liveness-video-anchor"}(Se||(Se={}));const ye=({ariaLabel:e})=>{const[t,a]=Te();return t.done?null:x.default.createElement(v.Button,{autoFocus:!0,variation:"link",onClick:()=>{a({type:"CANCEL"})},size:"large",className:Se.CancelButton,"aria-label":e},x.default.createElement(g.IconClose,{"aria-hidden":"true","data-testid":"close-icon"}))},Fe=t=>{var{variation:a="default",size:i="medium",children:r}=t,n=e.__rest(t,["variation","size","children"]);return R.createElement(v.View,Object.assign({className:`${Se.Toast} ${Se.Toast}--${a} ${Se.Toast}--${i}`,maxWidth:{base:"100%",small:"70%"}},n),R.createElement(v.Flex,{className:Se.ToastContainer},R.createElement(v.Flex,{className:Se.ToastMessage},r)))},xe=t=>{var{children:a,anchorOrigin:i={horizontal:"center",vertical:"center"},className:r}=t,n=e.__rest(t,["children","anchorOrigin","className"]);return R.createElement(v.Flex,Object.assign({className:`${Se.Overlay} ${r}`,alignItems:i.horizontal,justifyContent:i.vertical},n),a)},Re=e=>e.context.errorState,Me=e=>e.context.faceMatchAssociatedParams.faceMatchState,Ae=e=>e.context.faceMatchAssociatedParams.illuminationState,we=e=>e.context.isFaceFarEnoughBeforeRecording,_e=e=>e.context.faceMatchStateBeforeStart,De=({hintDisplayText:e})=>{const[t]=Te(),a=Ce(Re),i=Ce(Me),r=Ce(Ae),n=Ce(_e),o=Ce(we),s=t.matches("checkFaceDetectedBeforeStart"),c=t.matches("checkFaceDistanceBeforeRecording"),l=t.matches("recording"),d=t.matches("notRecording"),h=t.matches("uploading"),u=t.matches("checkSucceeded"),m=t.matches("checkFailed"),f=t.matches({recording:"flashFreshnessColors"}),g={[y.CANT_IDENTIFY]:e.hintCanNotIdentifyText,[y.FACE_IDENTIFIED]:e.hintTooFarText,[y.TOO_MANY]:e.hintTooManyFacesText,[y.TOO_CLOSE]:e.hintTooCloseText,[y.TOO_FAR]:e.hintTooFarText,[y.MATCHED]:e.hintHoldFaceForFreshnessText},p={[S.BRIGHT]:e.hintIlluminationTooBrightText,[S.DARK]:e.hintIlluminationTooDarkText,[S.NORMAL]:e.hintIlluminationNormalText},E=(()=>{if(!(a||m||u)){if(!l){if(s)return n===y.TOO_MANY?R.createElement(Fe,null,g[n]):R.createElement(Fe,null,e.hintMoveFaceFrontOfCameraText);if(c&&!1===o)return R.createElement(Fe,null,e.hintTooCloseText);if(d)return R.createElement(Fe,null,R.createElement(v.Flex,{className:Se.HintText},R.createElement(v.Loader,null),R.createElement(v.View,null,e.hintConnectingText)));if(h)return R.createElement(xe,{className:Se.OpaqueOverlay,anchorOrigin:{horizontal:"center",vertical:"end"}},R.createElement(Fe,null,R.createElement(v.Flex,{className:Se.HintText},R.createElement(v.Loader,null),R.createElement(v.View,null,e.hintVerifyingText))));if(r&&r!==S.NORMAL)return R.createElement(Fe,null,p[r])}return f?R.createElement(Fe,{size:"large",variation:"primary"},e.hintHoldFaceForFreshnessText):l&&!f?R.createElement(Fe,{size:"large",variation:i===y.TOO_CLOSE?"error":"primary"},i===y.TOO_CLOSE?g[y.TOO_CLOSE]:g[y.TOO_FAR]):null}})();return E||null},Ie=({children:e})=>x.default.createElement(v.Flex,{className:Se.RecordingIcon},x.default.createElement(v.Flex,{"data-testid":"rec-icon",justifyContent:"center"},x.default.createElement(v.Icon,{viewBox:{width:20,height:20},width:"20",height:"20"},x.default.createElement("circle",{cx:"10",cy:"10",r:"8",fill:"red"}))),x.default.createElement(v.Text,{as:"span",fontWeight:"bold"},e)),Oe=t=>{var{children:a,caption:i,variation:r="default"}=t,n=e.__rest(t,["children","caption","variation"]);return x.default.createElement(v.Flex,Object.assign({as:"figure",className:`${Se.Figure} ${Se.Figure}--${r}`},n),x.default.createElement(v.View,{className:`${Se.FigureImage} ${Se.FigureImage}--${r}`},"success"===r?x.default.createElement("svg",{className:Se.FigureIcon,"aria-hidden":"true",width:"24",height:"24"},x.default.createElement("g",{fill:"none"},x.default.createElement("path",{fill:"#365E3D",d:"M0 0h24v24H0z"}),x.default.createElement("path",{fill:"#FFF",d:"m9.435 15.62-4.054-4.055L4 12.936l5.435 5.435L21.101 6.704l-1.37-1.371z"}))):null,"error"===r?x.default.createElement("svg",{className:Se.FigureIcon,"aria-hidden":"true",width:"24",height:"24"},x.default.createElement("g",{fill:"none"},x.default.createElement("path",{fill:"#600",d:"M0 0h24v24H0z"}),x.default.createElement("path",{fill:"#FFF",d:"M19 6.41 17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"}))):null,a),x.default.createElement(v.View,{as:"figcaption",className:`${Se.FigureCaption} ${Se.FigureCaption}--${r}`},i))},be=({title:e,testId:t})=>x.default.createElement("svg",{width:"150",height:"150","data-testid":t},x.default.createElement("title",null,e),x.default.createElement("g",{fill:"none",fillRule:"evenodd",transform:"translate(0 -.001)"},x.default.createElement("path",{fill:"#5B361E",fillRule:"nonzero",d:"M124.655 0c9.173 8.155 9.394 17.812 13.258 32.385l.053.336.108.726.11.796.112.864.114.931.174 1.515.117 1.087.18 1.739.12 1.23.183 1.944.123 1.36.186 2.13.187 2.232.313 3.928.25 3.31.25 3.443.31 4.463.245 3.679.36 5.658.345 5.778.33 5.841.26 4.876.199 3.883.187 3.849.217 4.738.16 3.712.178 4.515.097 2.63v34.977L.519 150 .517 41.97c3-13.353 9.664-29.4 23.841-41.97h100.297Z"}),x.default.createElement("path",{fill:"#FCDDCC",fillRule:"nonzero",stroke:"#000",d:"m50.469 18.849.145.153c9.021 9.393 22.62 16.197 36.089 21.996l2.1.897 1.05.443 2.089.876 8.176 3.385 1.979.825 1.944.82c7.782 3.3 14.617 6.491 19.213 10.006 3.57 2.73 5.793 5.645 5.924 8.999v20.474l-.008.624-.016.669-.04 1.089-.04.777-.047.815-.06.853-.068.887-.08.918-.093.95-.104.978-.057.496-.123 1.016-.066.513-.144 1.049-.076.527-.165 1.077c-.057.36-.116.724-.178 1.086l-.193 1.103-.21 1.116-.11.557-.233 1.13c-.12.564-.247 1.13-.38 1.694l-.275 1.14c-1.037 4.147-2.426 8.3-4.271 11.978-6.17 9.34-12.996 16.035-19.28 20.691l-.8.584-.794.562-.784.539-1.165.77-1.147.724-.755.459c-.249.148-.497.294-.74.434l-.73.416-1.078.588-.702.367-1.033.517-.671.321-.657.303-.643.285-.541.23H68.149a75.81 75.81 0 0 1-.81-.284l-.918-.336a75.953 75.953 0 0 1-.935-.355l-.963-.382a85.513 85.513 0 0 1-1.988-.83l-1.032-.455c-.52-.233-1.05-.475-1.585-.727l-1.087-.517-1.113-.547c-.935-.465-1.893-.959-2.873-1.482l-1.193-.644a141.053 141.053 0 0 1-6.297-3.669l-1.33-.83c-17.11-10.783-22.636-33.458-23.66-49.98l-.071-1.267c-.02-.417-.038-.83-.053-1.235l-.037-1.212a86.317 86.317 0 0 1 .042-5.559l.047-1.002.06-.96.064-.843c1.09-2.51 2.164-4.304 3.296-5.882l.408-.558.415-.545.421-.538 2.026-2.492.481-.597.493-.624.507-.656.518-.69a61.722 61.722 0 0 0 3.769-5.754c4.03-6.917 7.127-14.806 9.544-21.668l.566-1.623.802-2.344 2.077-6.175.416-1.205.395-1.109.373-1.007.267-.682.253-.612c.47-.943.8-1.531 1.06-1.876l-.035.047Z"}),x.default.createElement("path",{fill:"#000",fillRule:"nonzero",d:"m94.566 121.353.722.895c-6.828 5.51-14.13 7.462-21.382 6.447-5.417-.758-10.535-3.2-13.987-6.186l-.318-.282.77-.854c3.285 2.964 8.343 5.434 13.694 6.183 6.797.95 13.632-.819 20.089-5.876l.412-.327Z"}),x.default.createElement("ellipse",{cx:"51.331",cy:"80.698",fill:"#000",fillRule:"nonzero",rx:"4.886",ry:"6.707"}),x.default.createElement("path",{fill:"#000",fillRule:"nonzero",d:"M42.539 63.719c4.453-2.586 11.355-3.268 17.22-.195l.35.19-.556 1.005c-5.437-3.01-11.946-2.479-16.175-.153l-.262.148-.577-.995Z"}),x.default.createElement("ellipse",{cx:"103.281",cy:"80.698",fill:"#000",fillRule:"nonzero",rx:"4.886",ry:"6.707"}),x.default.createElement("path",{fill:"#000",fillRule:"nonzero",d:"M94.492 63.719c4.453-2.586 11.355-3.268 17.22-.195l.35.19-.557 1.005c-5.436-3.01-11.946-2.479-16.174-.153l-.262.148-.577-.995Zm-22.972 32.9c0 4.216 2.006 7.72 5.831 7.48l.232-.018.115 1.144c-4.774.477-7.239-3.571-7.326-8.345l-.003-.26 1.15-.001h.001Z"}),x.default.createElement("path",{fill:"#FFF",fillRule:"nonzero",d:"M75.002.001H0v150h150v-150H75.002Zm0 0c25.627 0 46.402 33.579 46.402 75s-20.775 75-46.402 75c-25.627 0-46.402-33.579-46.402-75s20.775-75 46.402-75Z"}),x.default.createElement("path",{stroke:"#AEB3B7",strokeWidth:"2",d:"M120.921 75.001c0 20.555-5.214 39.117-13.589 52.507-8.386 13.406-19.838 21.493-32.313 21.493-12.476 0-23.928-8.087-32.312-21.493-8.377-13.39-13.59-31.952-13.59-52.507 0-20.555 5.214-39.116 13.589-52.507C51.091 9.09 62.543 1.001 75.018 1.001c12.476 0 23.928 8.088 32.314 21.493 8.375 13.39 13.588 31.952 13.588 52.507h.001Z"}))),Pe=({title:e,testId:t})=>x.default.createElement("svg",{width:"150",height:"150","data-testid":t},x.default.createElement("title",null,e),x.default.createElement("defs",null,x.default.createElement("linearGradient",{id:"a",x1:"50%",x2:"50%",y1:"0%",y2:"100%"},x.default.createElement("stop",{offset:"0%",stopColor:"#C2C2C2"}),x.default.createElement("stop",{offset:"100%",stopColor:"#C2C2C2",stopOpacity:"0"}))),x.default.createElement("g",{fill:"none",fillRule:"evenodd",transform:"translate(2)"},x.default.createElement("path",{fill:"#FFF",fillRule:"nonzero",d:"M3.997 0h136v150h-136z"}),x.default.createElement("path",{fill:"url(#a)",fillRule:"nonzero",d:"M4.333 0h138v150h-138z"}),x.default.createElement("path",{fill:"#5B361E",fillRule:"nonzero",stroke:"#000",strokeWidth:"1.353",d:"m22.515 58.137-1.895 82.434 98.784-2.343c0-8.798.813-16.271.813-31.497 0-15.748-2.345-55.36-3.766-64.125C108.16 11.338 74.737 5.03 56.707 11.04c-28.425 9.475-33.64 35.095-34.192 47.097Z"}),x.default.createElement("path",{fill:"#EF992A",fillRule:"nonzero",d:"M38.104 138.228c8.339-3.98 5.1-1.525 15.916-3.104H90.5c5.448 0 9.541 3.104 28.904 3.104 6.391 0 5.987 8.988-2.473 8.988-24.315 1.08-66.07 1.08-78.281 0-77.975-6.896-10.97-4.014-.546-8.988Z"}),x.default.createElement("path",{fill:"#FCDDCC",fillRule:"nonzero",stroke:"#000",strokeWidth:"1.353",d:"m54.306 134.26 2.645-21.765h30.498l3.05 21.765c-15.778 14.791-30.703 6.163-36.193 0zm-27.59-54.458C25.42 66.68 33.467 67.18 37.653 69.07l2.837 25.314c-10.328-2.228-13.772-12.961-13.772-14.58zm89.512-.81c4.05-15.067-3.984-15.998-8.506-14.58L105.9 91.75c10.328-8.505 9.113-12.758 10.328-12.758z"}),x.default.createElement("path",{fill:"#FCDDCC",fillRule:"nonzero",stroke:"#000",strokeWidth:"1.353",d:"M53.564 109.804c-14.195-8.986-16.116-30.658-15.302-40.37 2.24-5.21 4.37-5.723 7.958-11.909 6.3-10.86 9.028-25.451 10.579-25.009 14.241 16.008 50.215 20.259 50.649 31.708v13.023c0 4.178-.911 14.358-4.558 21.65-8.986 13.674-20.131 18.612-24.58 19.372-2.334.922-10.55.521-24.746-8.465Z"}),x.default.createElement("path",{fill:"#000",fillRule:"nonzero",d:"m83.935 98.402.85 1.052c-7.974 6.435-17.2 5.243-23.018.18l-.23-.204.905-1.004c5.273 4.756 13.744 5.998 21.175.227l.318-.251Z"}),x.default.createElement("ellipse",{cx:"56.448",cy:"72.613",fill:"#000",fillRule:"nonzero",rx:"3.128",ry:"4.294"}),x.default.createElement("path",{fill:"#000",fillRule:"nonzero",d:"M50.664 61.476c2.917-1.694 7.404-2.147 11.244-.172l.31.165-.655 1.183c-3.348-1.854-7.361-1.545-9.985-.137l-.234.13-.68-1.17Z"}),x.default.createElement("ellipse",{cx:"89.709",cy:"72.613",fill:"#000",fillRule:"nonzero",rx:"3.128",ry:"4.294"}),x.default.createElement("path",{fill:"#000",fillRule:"nonzero",d:"M83.926 61.476c2.917-1.694 7.404-2.147 11.244-.172l.31.165-.655 1.183c-3.348-1.854-7.361-1.545-9.985-.137l-.234.13-.68-1.17Z"}),x.default.createElement("path",{stroke:"#000",strokeWidth:"1.353",d:"M69.005 82.806c0 1.858.859 5.487 4.287 5.144"}),x.default.createElement("path",{fill:"#FFF",d:"M73.004 0H0v150h146V0H73.004Zm.496 0C98.629 0 119 33.579 119 75s-20.371 75-45.5 75S28 116.421 28 75 48.371 0 73.5 0Z"}),x.default.createElement("path",{stroke:"#AEB3B7",strokeWidth:"2",d:"M118.4 75c0 20.555-5.156 39.117-13.441 52.507C96.665 140.913 85.338 149 72.999 149c-12.34 0-23.667-8.087-31.961-21.493C32.753 114.117 27.597 95.555 27.597 75c0-20.555 5.156-39.117 13.44-52.507C49.333 9.087 60.66 1 72.999 1c12.34 0 23.667 8.087 31.961 21.493C113.244 35.883 118.4 54.445 118.4 75Z"}))),ke=({children:e})=>{const t=g.useThemeBreakpoint(),[a,i]=R.useState(!1),r=R.useRef(null),n="base"===t;return R.useEffect((()=>{function e(e){a&&r.current&&!r.current.contains(e.target)&&i(!1)}return document.addEventListener("mousedown",e),()=>{document.removeEventListener("mousedown",e)}}),[r,a]),R.createElement(v.Flex,{className:Se.Popover,onClick:()=>i(!a),ref:r,testId:"popover-icon"},R.createElement(g.AlertIcon,{ariaHidden:!0,variation:"info"}),a&&R.createElement(R.Fragment,null,R.createElement(v.Flex,{className:Se.PopoverAnchor}),R.createElement(v.Flex,{className:Se.PopoverAnchorSecondary}),R.createElement(v.Flex,{className:Se.PopoverContainer,left:n?-190:-108,"data-testid":"popover-text"},e)))};ke.displayName="LivenessIconWithPopover";const Le=({headingText:e,bodyText:t})=>x.default.createElement(v.View,{className:Se.StartScreenHeader},x.default.createElement(v.View,{className:Se.StartScreenHeaderHeading},e),x.default.createElement(v.View,{className:Se.StartScreenHeaderBody},t)),Ne=({headingText:e,bodyText:t,infoText:a})=>x.default.createElement(v.Flex,{className:`${v.ComponentClassNames.Alert} ${Se.StartScreenWarning}`},x.default.createElement(v.View,{flex:"1"},x.default.createElement(v.View,{className:v.ComponentClassNames.AlertHeading},e),x.default.createElement(v.View,{className:v.ComponentClassNames.AlertBody},t)),x.default.createElement(ke,null,a)),He=({headingText:e,goodFitCaptionText:t,goodFitAltText:a,tooFarCaptionText:i,tooFarAltText:r,steps:n})=>x.default.createElement(v.Flex,{direction:"column"},x.default.createElement(v.Text,{className:Se.StartScreenInstructionsHeading},e),x.default.createElement(v.Flex,{className:Se.Figures},x.default.createElement(Oe,{variation:"success",caption:t},x.default.createElement(be,{title:a})),x.default.createElement(Oe,{variation:"error",caption:i},x.default.createElement(Pe,{title:r}))),x.default.createElement(v.Flex,{as:"ol",className:Se.InstructionList},n.map(((e,t)=>x.default.createElement(v.Flex,{as:"li",key:t+1},x.default.createElement(v.Text,{as:"span","aria-hidden":"true"},t+1,"."),x.default.createElement(v.Text,{as:"span"},e)))))),Be="liveness-detector-start";function We(e){const{beginLivenessCheck:t,components:a,instructionDisplayText:i}=e;return R.createElement(v.Card,{className:Be,"data-testid":Be},R.createElement(v.Flex,{direction:"column"},(null==a?void 0:a.Header)?R.createElement(a.Header,null):R.createElement(Le,{headingText:i.instructionsHeaderHeadingText,bodyText:i.instructionsHeaderBodyText}),(null==a?void 0:a.PhotosensitiveWarning)?R.createElement(a.PhotosensitiveWarning,null):R.createElement(Ne,{headingText:i.photosensitivyWarningHeadingText,bodyText:i.photosensitivyWarningBodyText,infoText:i.photosensitivyWarningInfoText}),(null==a?void 0:a.Instructions)?R.createElement(a.Instructions,null):R.createElement(He,{headingText:i.instructionListHeadingText,goodFitCaptionText:i.goodFitCaptionText,goodFitAltText:i.goodFitAltText,tooFarCaptionText:i.tooFarCaptionText,tooFarAltText:i.tooFarAltText,steps:[i.instructionListStepOneText,i.instructionListStepTwoText,i.instructionListStepThreeText,i.instructionListStepFourText]}),R.createElement(v.Flex,{justifyContent:"center"},R.createElement(v.Button,{variation:"primary",type:"button",onClick:t},i.instructionsBeginCheckText))))}const Ve={timeoutHeaderText:"Time out",timeoutMessageText:"Face didn't fit inside oval in time limit. Try again and completely fill the oval with face in it.",faceDistanceHeaderText:"Forward movement detected",faceDistanceMessageText:"Avoid moving closer when connecting.",multipleFacesHeaderText:"Multiple faces detected",multipleFacesMessageText:"Ensure only one face is present in front of the camera when connecting.",clientHeaderText:"Client error",clientMessageText:"Check failed due to client issue",serverHeaderText:"Server issue",serverMessageText:"Cannot complete check due to server issue",landscapeHeaderText:"Landscape orientation not supported",landscapeMessageText:"Rotate your device to portrait (vertical) orientation.",portraitMessageText:"Ensure your device remains in portrait (vertical) orientation for the check’s duration.",tryAgainText:"Try again"},je=Object.assign({instructionsHeaderHeadingText:"Liveness check",instructionsHeaderBodyText:"You will go through a face verification process to prove that you are a real person.",instructionsBeginCheckText:"Begin check",photosensitivyWarningHeadingText:"Photosensitivity warning",photosensitivyWarningBodyText:"This check displays colored lights. Use caution if you are photosensitive.",photosensitivyWarningInfoText:"A small percentage of individuals may experience epileptic seizures when exposed to colored lights. Use caution if you, or anyone in your family, have an epileptic condition.",instructionListHeadingText:"Follow the instructions to complete the check:",goodFitCaptionText:"Good fit",goodFitAltText:"Ilustration of a person's face, perfectly fitting inside of an oval.",tooFarCaptionText:"Too far",tooFarAltText:"Illustration of a person's face inside of an oval; there is a gap between the perimeter of the face and the boundaries of the oval.",instructionListStepOneText:"When an oval appears, follow the instructions to fit your face in it.",instructionListStepTwoText:"Maximize your screen's brightness.",instructionListStepThreeText:"Make sure your face is not covered with sunglasses or a mask.",instructionListStepFourText:"Move to a well-lit place that is not in direct sunlight.",cameraMinSpecificationsHeadingText:"Camera does not meet minimum specifications",cameraMinSpecificationsMessageText:"Camera must support at least 320*240 resolution and 15 frames per second.",cameraNotFoundHeadingText:"Camera not accessible.",cameraNotFoundMessageText:"Check that camera is connected and camera permissions are enabled in settings before retrying.",retryCameraPermissionsText:"Retry",cancelLivenessCheckText:"Cancel Liveness check",recordingIndicatorText:"Rec",hintMoveFaceFrontOfCameraText:"Move face in front of camera",hintTooManyFacesText:"Ensure only one face is in front of camera",hintFaceDetectedText:"Face detected",hintCanNotIdentifyText:"Move face in front of camera",hintTooCloseText:"Move back",hintTooFarText:"Move closer",hintHoldFacePositionCountdownText:"Hold face position during countdown",hintConnectingText:"Connecting...",hintVerifyingText:"Verifying...",hintIlluminationTooBrightText:"Move to dimmer area",hintIlluminationTooDarkText:"Move to brighter area",hintIlluminationNormalText:"Lighting conditions normal",hintHoldFaceForFreshnessText:"Hold still"},Ve),ze=({errorState:e,overrideErrorDisplayText:t})=>{const a=Object.assign(Object.assign({},Ve),t);return e===F.CAMERA_ACCESS_ERROR||e===F.CAMERA_FRAMERATE_ERROR||e===F.MOBILE_LANDSCAPE_ERROR?null:(e=>{const{error:t,displayText:a}=e,{timeoutHeaderText:i,timeoutMessageText:r,faceDistanceHeaderText:n,faceDistanceMessageText:o,multipleFacesHeaderText:s,multipleFacesMessageText:c,clientHeaderText:l,clientMessageText:d,serverHeaderText:h,serverMessageText:u}=a;let m,f;switch(t){case F.TIMEOUT:m=i,f=r;break;case F.FACE_DISTANCE_ERROR:m=n,f=o;break;case F.MULTIPLE_FACES_ERROR:m=s,f=c;break;case F.RUNTIME_ERROR:m=l,f=d;break;case F.SERVER_ERROR:default:m=h,f=u}return x.default.createElement(x.default.Fragment,null,x.default.createElement(v.Flex,{className:Se.ErrorModal},x.default.createElement(g.AlertIcon,{ariaHidden:!0,variation:"error"}),x.default.createElement(v.Text,{className:Se.ErrorModalHeading},m)),f)})({error:e,displayText:a})},Ue=e=>{const{children:t,onRetry:a,displayText:i}=e,r=Object.assign(Object.assign({},Ve),i),{tryAgainText:n}=r;return x.default.createElement(xe,{className:Se.OpaqueOverlay},x.default.createElement(Fe,null,t,x.default.createElement(v.Flex,{justifyContent:"center"},x.default.createElement(v.Button,{variation:"primary",type:"button",onClick:a},n))))},qe=e=>{var t;return null===(t=e.context.videoAssociatedParams)||void 0===t?void 0:t.videoMediaStream},Ye=e=>e.context.faceMatchAssociatedParams.faceMatchPercentage,$e=e=>e.context.faceMatchAssociatedParams.faceMatchState,Ge=x.default.createElement(v.Loader,{size:"large",className:Se.Loader,"data-testid":"centered-loader"}),Xe=x.default.memo((({percentage:e,initialPercentage:t=25,testId:a})=>{const[i,r]=x.default.useState(t);x.default.useEffect((()=>{r(e<0?0:e>100?100:e)}),[e]);const n={"--percentage":`${i}%`};return x.default.createElement("div",{className:Se.MatchIndicator,"data-testid":a},x.default.createElement("div",{className:`${Se.MatchIndicator}__bar`,style:n}))})),Ze=e=>{const{isMobileScreen:a,isRecordingStopped:i,streamDisplayText:r,hintDisplayText:n,errorDisplayText:o,components:s,testId:c}=e,{cancelLivenessCheckText:l,recordingIndicatorText:d}=r,{ErrorView:h=Ue}=null!=s?s:{},[u,m]=Te(),f=Ce(qe),g=Ce(Ye),E=Ce($e),T=Ce(Re),C=[y.TOO_FAR,y.CANT_IDENTIFY,y.FACE_IDENTIFIED,y.MATCHED],{videoRef:S,videoWidth:F,videoHeight:R}=function(e){const a=ue.height.ideal,i=ue.width.ideal,r=t.useRef(null),[n,o]=t.useState(a),[s,c]=t.useState(i);return t.useEffect((()=>{if(e){p.isObject(r.current)&&(r.current.srcObject=e);const{height:t,width:a}=e.getTracks()[0].getSettings();o(t),c(a)}return()=>{e&&e.getTracks().forEach((t=>{e.removeTrack(t),t.stop()}))}}),[e]),{videoRef:r,videoHeight:n,videoWidth:s}}(f),M=t.useRef(null),A=t.useRef(null),[w,D]=t.useState(!1),I=u.matches("cameraCheck"),O=u.matches("recording"),b=u.matches("checkSucceeded"),P=u.matches({recording:"flashFreshnessColors"}),[k,L]=t.useState(F),[N,H]=t.useState(R),[B,W]=t.useState((()=>F&&R?F/R:0));x.default.useLayoutEffect((()=>{w&&m({type:"SET_DOM_AND_CAMERA_DETAILS",data:{videoEl:S.current,canvasEl:M.current,freshnessColorEl:A.current,isMobile:a}}),S.current&&(L(S.current.videoWidth),H(S.current.videoHeight),W(S.current.videoWidth/S.current.videoHeight))}),[m,S,w,a]);return I?x.default.createElement(v.Flex,{height:R,width:"100%",position:"relative"},Ge):x.default.createElement(v.Flex,{className:_.default(Se.CameraModule,a&&`${Se.CameraModule}--mobile`),"data-testid":c},!w&&Ge,x.default.createElement(v.View,{as:"canvas",ref:A,className:Se.FreshnessCanvas,hidden:!0}),x.default.createElement(v.View,{className:Se.VideoAnchor,style:{aspectRatio:`${B}`}},x.default.createElement("video",{ref:S,muted:!0,autoPlay:!0,playsInline:!0,style:{transform:"scaleX(-1)"},width:k,height:N,onCanPlay:()=>{D(!0)},"data-testid":"video",className:Se.Video}),x.default.createElement(v.Flex,{className:_.default(Se.OvalCanvas,a&&`${Se.OvalCanvas}--mobile`,i&&Se.FadeOut)},x.default.createElement(v.View,{as:"canvas",width:"100%",height:"100%",ref:M})),O&&x.default.createElement(v.View,{className:Se.RecordingIconContainer},x.default.createElement(Ie,null,d)),!b&&x.default.createElement(v.View,{className:Se.CancelContainer},x.default.createElement(ye,{ariaLabel:l})),x.default.createElement(xe,{anchorOrigin:{horizontal:"center",vertical:O&&!P?"start":"space-between"},className:Se.InstructionOverlay},x.default.createElement(De,{hintDisplayText:n}),T&&x.default.createElement(h,{onRetry:()=>{m({type:"CANCEL"})}},ze({errorState:T,overrideErrorDisplayText:o})),O&&!P&&C.includes(E)?x.default.createElement(Xe,{percentage:Math.ceil(g)}):null)))};function Ke(){return/Android|iPhone|iPad/i.test(navigator.userAgent)||/Macintosh/i.test(navigator.userAgent)&&!!navigator.maxTouchPoints&&navigator.maxTouchPoints>1}function Qe(){return window.matchMedia("(orientation: landscape)")}const Je=e=>{const{onRetry:t,header:a,portraitMessage:i,landscapeMessage:r,tryAgainText:n}=e,[o,s]=R.useState(!0);return R.useLayoutEffect((()=>{const e=Qe();return s(e.matches),e.addEventListener("change",(e=>{s(e.matches)})),()=>{e.removeEventListener("change",(e=>s(e.matches)))}}),[]),R.createElement(v.Flex,{className:Se.LandscapeErrorModal,height:o?"auto":480},R.createElement(v.Text,{className:Se.LandscapeErrorModalHeader},a),R.createElement(v.Text,null,o?r:i),o?null:R.createElement(v.Flex,{className:Se.LandscapeErrorModalButton},R.createElement(v.Button,{variation:"primary",type:"button",onClick:t},n)))},et="liveness-detector-check",tt=e=>e.context.isRecordingStopped,at=({hintDisplayText:e,cameraDisplayText:t,streamDisplayText:a,errorDisplayText:i,components:r})=>{const[n,o]=Te(),s=Ce(Re),c=Ce(tt),l=n.matches("permissionDenied"),d=Ke(),h=()=>{o({type:"RETRY_CAMERA_CHECK"})},{cameraMinSpecificationsHeadingText:u,cameraMinSpecificationsMessageText:m,cameraNotFoundHeadingText:f,cameraNotFoundMessageText:g,retryCameraPermissionsText:p}=t,{cancelLivenessCheckText:E}=a;R.useLayoutEffect((()=>{if(d){const e=e=>{e&&o({type:"MOBILE_LANDSCAPE_WARNING"})},t=Qe();return e(t.matches),t.addEventListener("change",(t=>{e(t.matches)})),()=>{t.removeEventListener("change",(t=>e(t.matches)))}}}),[d,o]);return R.createElement(v.Flex,{direction:"column",position:"relative",testId:et,className:et},(()=>{if(s===F.MOBILE_LANDSCAPE_ERROR){const e=Object.assign(Object.assign({},Ve),i),{landscapeHeaderText:t,portraitMessageText:a,landscapeMessageText:r,tryAgainText:n}=e;return R.createElement(v.Flex,{backgroundColor:"background.primary",direction:"column",textAlign:"center",alignItems:"center",justifyContent:"center",position:"absolute",width:"100%"},R.createElement(Je,{header:t,portraitMessage:a,landscapeMessage:r,tryAgainText:n,onRetry:()=>{o({type:"CANCEL"})}}))}return l?R.createElement(v.Flex,{backgroundColor:"background.primary",direction:"column",textAlign:"center",alignItems:"center",justifyContent:"center",width:"100%",height:480},R.createElement(v.Text,{fontSize:"large",fontWeight:"bold"},s===F.CAMERA_FRAMERATE_ERROR?u:f),R.createElement(v.Text,{maxWidth:300},s===F.CAMERA_FRAMERATE_ERROR?m:g),R.createElement(v.Button,{variation:"primary",type:"button",onClick:h},p),R.createElement(v.View,{position:"absolute",top:"medium",right:"medium"},R.createElement(ye,{ariaLabel:E}))):R.createElement(Ze,{isMobileScreen:d,isRecordingStopped:c,streamDisplayText:a,hintDisplayText:e,errorDisplayText:i,components:r})})())};const it="liveness-detector";function rt(e){const{disableInstructionScreen:t=!1,components:a,config:r,displayText:n}=e,o=R.useRef(null),{hintDisplayText:s,cameraDisplayText:c,instructionDisplayText:l,streamDisplayText:d,errorDisplayText:h}=function(e){const t=Object.assign(Object.assign({},je),e),{instructionsHeaderHeadingText:a,instructionsHeaderBodyText:i,instructionsBeginCheckText:r,photosensitivyWarningHeadingText:n,photosensitivyWarningBodyText:o,photosensitivyWarningInfoText:s,instructionListHeadingText:c,goodFitCaptionText:l,goodFitAltText:d,tooFarCaptionText:h,tooFarAltText:u,instructionListStepOneText:m,instructionListStepTwoText:f,instructionListStepThreeText:v,instructionListStepFourText:g,cameraMinSpecificationsHeadingText:p,cameraMinSpecificationsMessageText:E,cameraNotFoundHeadingText:T,cameraNotFoundMessageText:C,retryCameraPermissionsText:S,cancelLivenessCheckText:y,recordingIndicatorText:F,hintMoveFaceFrontOfCameraText:x,hintTooManyFacesText:R,hintFaceDetectedText:M,hintCanNotIdentifyText:A,hintTooCloseText:w,hintTooFarText:_,hintHoldFacePositionCountdownText:D,hintConnectingText:I,hintVerifyingText:O,hintIlluminationTooBrightText:b,hintIlluminationTooDarkText:P,hintIlluminationNormalText:k,hintHoldFaceForFreshnessText:L,timeoutHeaderText:N,timeoutMessageText:H,faceDistanceHeaderText:B,faceDistanceMessageText:W,multipleFacesHeaderText:V,multipleFacesMessageText:j,clientHeaderText:z,clientMessageText:U,serverHeaderText:q,serverMessageText:Y,landscapeHeaderText:$,landscapeMessageText:G,portraitMessageText:X,tryAgainText:Z}=t;return{hintDisplayText:{hintMoveFaceFrontOfCameraText:x,hintTooManyFacesText:R,hintFaceDetectedText:M,hintCanNotIdentifyText:A,hintTooCloseText:w,hintTooFarText:_,hintHoldFacePositionCountdownText:D,hintConnectingText:I,hintVerifyingText:O,hintIlluminationTooBrightText:b,hintIlluminationTooDarkText:P,hintIlluminationNormalText:k,hintHoldFaceForFreshnessText:L},cameraDisplayText:{cameraMinSpecificationsHeadingText:p,cameraMinSpecificationsMessageText:E,cameraNotFoundHeadingText:T,cameraNotFoundMessageText:C,retryCameraPermissionsText:S},instructionDisplayText:{instructionsHeaderHeadingText:a,instructionsHeaderBodyText:i,instructionsBeginCheckText:r,photosensitivyWarningHeadingText:n,photosensitivyWarningBodyText:o,photosensitivyWarningInfoText:s,instructionListHeadingText:c,goodFitCaptionText:l,goodFitAltText:d,tooFarCaptionText:h,tooFarAltText:u,instructionListStepOneText:m,instructionListStepTwoText:f,instructionListStepThreeText:v,instructionListStepFourText:g},streamDisplayText:{cancelLivenessCheckText:y,recordingIndicatorText:F},errorDisplayText:{timeoutHeaderText:N,timeoutMessageText:H,faceDistanceHeaderText:B,faceDistanceMessageText:W,multipleFacesHeaderText:V,multipleFacesMessageText:j,clientHeaderText:z,clientMessageText:U,serverHeaderText:q,serverMessageText:Y,landscapeHeaderText:$,landscapeMessageText:G,portraitMessageText:X,tryAgainText:Z}}}(n),u=i.useInterpret(fe,{devTools:"development"===process.env.NODE_ENV,context:{componentProps:Object.assign(Object.assign({},e),{config:null!=r?r:{}})}}),[m,f]=i.useActor(u),g=m.matches("start")||m.matches("userCancel"),p=R.useCallback((()=>{f({type:"BEGIN"})}),[f]);return R.useLayoutEffect((()=>{t&&g&&p()}),[p,t,g]),R.createElement(v.View,{className:it,testId:it},R.createElement(pe,{componentProps:e,service:u},R.createElement(v.Flex,{direction:"column",ref:o},g?R.createElement(We,{beginLivenessCheck:p,components:a,instructionDisplayText:l}):R.createElement(at,{hintDisplayText:s,cameraDisplayText:c,streamDisplayText:d,errorDisplayText:h,components:a}))))}const nt=()=>e.__awaiter(void 0,void 0,void 0,(function*(){return yield a.Credentials.get()}));exports.FaceLivenessDetector=function(t){const{config:a}=t,i=e.__rest(t,["config"]);return R.createElement(rt,Object.assign({},i,{config:Object.assign({credentialProvider:nt},a)}))},exports.FaceLivenessDetectorCore=rt;
|
package/dist/styles.css
CHANGED
|
@@ -1670,14 +1670,10 @@ strong.amplify-text {
|
|
|
1670
1670
|
font-weight: var(--amplify-components-button-font-weight);
|
|
1671
1671
|
justify-content: center;
|
|
1672
1672
|
line-height: var(--amplify-components-button-line-height);
|
|
1673
|
-
-
|
|
1674
|
-
|
|
1675
|
-
-
|
|
1676
|
-
|
|
1677
|
-
-webkit-padding-start: var(--amplify-components-button-padding-inline-start);
|
|
1678
|
-
padding-inline-start: var(--amplify-components-button-padding-inline-start);
|
|
1679
|
-
-webkit-padding-end: var(--amplify-components-button-padding-inline-end);
|
|
1680
|
-
padding-inline-end: var(--amplify-components-button-padding-inline-end);
|
|
1673
|
+
padding-block-start: var(--amplify-components-button-padding-block-start);
|
|
1674
|
+
padding-block-end: var(--amplify-components-button-padding-block-end);
|
|
1675
|
+
padding-inline-start: var(--amplify-components-button-padding-inline-start);
|
|
1676
|
+
padding-inline-end: var(--amplify-components-button-padding-inline-end);
|
|
1681
1677
|
transition: all var(--amplify-components-button-transition-duration);
|
|
1682
1678
|
-webkit-user-select: none;
|
|
1683
1679
|
-moz-user-select: none;
|
|
@@ -2686,25 +2682,17 @@ strong.amplify-text {
|
|
|
2686
2682
|
}
|
|
2687
2683
|
.amplify-button--small {
|
|
2688
2684
|
font-size: var(--amplify-components-button-small-font-size);
|
|
2689
|
-
-
|
|
2690
|
-
|
|
2691
|
-
-
|
|
2692
|
-
|
|
2693
|
-
-webkit-padding-start: var(--amplify-components-button-small-padding-inline-start);
|
|
2694
|
-
padding-inline-start: var(--amplify-components-button-small-padding-inline-start);
|
|
2695
|
-
-webkit-padding-end: var(--amplify-components-button-small-padding-inline-end);
|
|
2696
|
-
padding-inline-end: var(--amplify-components-button-small-padding-inline-end);
|
|
2685
|
+
padding-block-start: var(--amplify-components-button-small-padding-block-start);
|
|
2686
|
+
padding-block-end: var(--amplify-components-button-small-padding-block-end);
|
|
2687
|
+
padding-inline-start: var(--amplify-components-button-small-padding-inline-start);
|
|
2688
|
+
padding-inline-end: var(--amplify-components-button-small-padding-inline-end);
|
|
2697
2689
|
}
|
|
2698
2690
|
.amplify-button--large {
|
|
2699
2691
|
font-size: var(--amplify-components-button-large-font-size);
|
|
2700
|
-
-
|
|
2701
|
-
|
|
2702
|
-
-
|
|
2703
|
-
|
|
2704
|
-
-webkit-padding-start: var(--amplify-components-button-large-padding-inline-start);
|
|
2705
|
-
padding-inline-start: var(--amplify-components-button-large-padding-inline-start);
|
|
2706
|
-
-webkit-padding-end: var(--amplify-components-button-large-padding-inline-end);
|
|
2707
|
-
padding-inline-end: var(--amplify-components-button-large-padding-inline-end);
|
|
2692
|
+
padding-block-start: var(--amplify-components-button-large-padding-block-start);
|
|
2693
|
+
padding-block-end: var(--amplify-components-button-large-padding-block-end);
|
|
2694
|
+
padding-inline-start: var(--amplify-components-button-large-padding-inline-start);
|
|
2695
|
+
padding-inline-end: var(--amplify-components-button-large-padding-inline-end);
|
|
2708
2696
|
}
|
|
2709
2697
|
.amplify-button--disabled {
|
|
2710
2698
|
background-color: var(--amplify-internal-button-disabled-background-color);
|
|
@@ -2895,14 +2883,10 @@ strong.amplify-text {
|
|
|
2895
2883
|
color: var(--amplify-components-fieldcontrol-color);
|
|
2896
2884
|
font-size: var(--amplify-components-fieldcontrol-font-size);
|
|
2897
2885
|
line-height: var(--amplify-components-fieldcontrol-line-height);
|
|
2898
|
-
-
|
|
2899
|
-
|
|
2900
|
-
-
|
|
2901
|
-
|
|
2902
|
-
-webkit-padding-start: var(--amplify-components-fieldcontrol-padding-inline-start);
|
|
2903
|
-
padding-inline-start: var(--amplify-components-fieldcontrol-padding-inline-start);
|
|
2904
|
-
-webkit-padding-end: var(--amplify-components-fieldcontrol-padding-inline-end);
|
|
2905
|
-
padding-inline-end: var(--amplify-components-fieldcontrol-padding-inline-end);
|
|
2886
|
+
padding-block-start: var(--amplify-components-fieldcontrol-padding-block-start);
|
|
2887
|
+
padding-block-end: var(--amplify-components-fieldcontrol-padding-block-end);
|
|
2888
|
+
padding-inline-start: var(--amplify-components-fieldcontrol-padding-inline-start);
|
|
2889
|
+
padding-inline-end: var(--amplify-components-fieldcontrol-padding-inline-end);
|
|
2906
2890
|
transition: all var(--amplify-components-fieldcontrol-transition-duration);
|
|
2907
2891
|
width: 100%;
|
|
2908
2892
|
border-color: var(--amplify-components-fieldcontrol-border-color);
|
|
@@ -2936,25 +2920,17 @@ strong.amplify-text {
|
|
|
2936
2920
|
}
|
|
2937
2921
|
.amplify-input--small {
|
|
2938
2922
|
font-size: var(--amplify-components-fieldcontrol-small-font-size);
|
|
2939
|
-
-
|
|
2940
|
-
|
|
2941
|
-
-
|
|
2942
|
-
|
|
2943
|
-
-webkit-padding-start: var(--amplify-components-fieldcontrol-small-padding-inline-start);
|
|
2944
|
-
padding-inline-start: var(--amplify-components-fieldcontrol-small-padding-inline-start);
|
|
2945
|
-
-webkit-padding-end: var(--amplify-components-fieldcontrol-small-padding-inline-end);
|
|
2946
|
-
padding-inline-end: var(--amplify-components-fieldcontrol-small-padding-inline-end);
|
|
2923
|
+
padding-block-start: var(--amplify-components-fieldcontrol-small-padding-block-start);
|
|
2924
|
+
padding-block-end: var(--amplify-components-fieldcontrol-small-padding-block-end);
|
|
2925
|
+
padding-inline-start: var(--amplify-components-fieldcontrol-small-padding-inline-start);
|
|
2926
|
+
padding-inline-end: var(--amplify-components-fieldcontrol-small-padding-inline-end);
|
|
2947
2927
|
}
|
|
2948
2928
|
.amplify-input--large {
|
|
2949
2929
|
font-size: var(--amplify-components-fieldcontrol-large-font-size);
|
|
2950
|
-
-
|
|
2951
|
-
|
|
2952
|
-
-
|
|
2953
|
-
|
|
2954
|
-
-webkit-padding-start: var(--amplify-components-fieldcontrol-large-padding-inline-start);
|
|
2955
|
-
padding-inline-start: var(--amplify-components-fieldcontrol-large-padding-inline-start);
|
|
2956
|
-
-webkit-padding-end: var(--amplify-components-fieldcontrol-large-padding-inline-end);
|
|
2957
|
-
padding-inline-end: var(--amplify-components-fieldcontrol-large-padding-inline-end);
|
|
2930
|
+
padding-block-start: var(--amplify-components-fieldcontrol-large-padding-block-start);
|
|
2931
|
+
padding-block-end: var(--amplify-components-fieldcontrol-large-padding-block-end);
|
|
2932
|
+
padding-inline-start: var(--amplify-components-fieldcontrol-large-padding-inline-start);
|
|
2933
|
+
padding-inline-end: var(--amplify-components-fieldcontrol-large-padding-inline-end);
|
|
2958
2934
|
}
|
|
2959
2935
|
.amplify-input--error {
|
|
2960
2936
|
border-color: var(--amplify-components-fieldcontrol-error-border-color);
|
|
@@ -2970,12 +2946,9 @@ strong.amplify-text {
|
|
|
2970
2946
|
background-color: var(--amplify-components-fieldcontrol-disabled-background-color);
|
|
2971
2947
|
}
|
|
2972
2948
|
.amplify-input--quiet {
|
|
2973
|
-
-
|
|
2974
|
-
|
|
2975
|
-
-
|
|
2976
|
-
border-inline-start: var(--amplify-components-fieldcontrol-quiet-border-inline-start);
|
|
2977
|
-
-webkit-border-end: var(--amplify-components-fieldcontrol-quiet-border-inline-end);
|
|
2978
|
-
border-inline-end: var(--amplify-components-fieldcontrol-quiet-border-inline-end);
|
|
2949
|
+
border-block-start: var(--amplify-components-fieldcontrol-quiet-border-block-start);
|
|
2950
|
+
border-inline-start: var(--amplify-components-fieldcontrol-quiet-border-inline-start);
|
|
2951
|
+
border-inline-end: var(--amplify-components-fieldcontrol-quiet-border-inline-end);
|
|
2979
2952
|
border-radius: var(--amplify-components-fieldcontrol-quiet-border-radius);
|
|
2980
2953
|
}
|
|
2981
2954
|
.amplify-input--quiet:focus {
|
|
@@ -2994,14 +2967,10 @@ strong.amplify-text {
|
|
|
2994
2967
|
color: var(--amplify-components-fieldcontrol-color);
|
|
2995
2968
|
font-size: var(--amplify-components-fieldcontrol-font-size);
|
|
2996
2969
|
line-height: var(--amplify-components-fieldcontrol-line-height);
|
|
2997
|
-
-
|
|
2998
|
-
|
|
2999
|
-
-
|
|
3000
|
-
|
|
3001
|
-
-webkit-padding-start: var(--amplify-components-fieldcontrol-padding-inline-start);
|
|
3002
|
-
padding-inline-start: var(--amplify-components-fieldcontrol-padding-inline-start);
|
|
3003
|
-
-webkit-padding-end: var(--amplify-components-fieldcontrol-padding-inline-end);
|
|
3004
|
-
padding-inline-end: var(--amplify-components-fieldcontrol-padding-inline-end);
|
|
2970
|
+
padding-block-start: var(--amplify-components-fieldcontrol-padding-block-start);
|
|
2971
|
+
padding-block-end: var(--amplify-components-fieldcontrol-padding-block-end);
|
|
2972
|
+
padding-inline-start: var(--amplify-components-fieldcontrol-padding-inline-start);
|
|
2973
|
+
padding-inline-end: var(--amplify-components-fieldcontrol-padding-inline-end);
|
|
3005
2974
|
transition: all var(--amplify-components-fieldcontrol-transition-duration);
|
|
3006
2975
|
width: 100%;
|
|
3007
2976
|
border-color: var(--amplify-components-fieldcontrol-border-color);
|
|
@@ -3023,25 +2992,17 @@ strong.amplify-text {
|
|
|
3023
2992
|
}
|
|
3024
2993
|
.amplify-textarea--small {
|
|
3025
2994
|
font-size: var(--amplify-components-fieldcontrol-small-font-size);
|
|
3026
|
-
-
|
|
3027
|
-
|
|
3028
|
-
-
|
|
3029
|
-
|
|
3030
|
-
-webkit-padding-start: var(--amplify-components-fieldcontrol-small-padding-inline-start);
|
|
3031
|
-
padding-inline-start: var(--amplify-components-fieldcontrol-small-padding-inline-start);
|
|
3032
|
-
-webkit-padding-end: var(--amplify-components-fieldcontrol-small-padding-inline-end);
|
|
3033
|
-
padding-inline-end: var(--amplify-components-fieldcontrol-small-padding-inline-end);
|
|
2995
|
+
padding-block-start: var(--amplify-components-fieldcontrol-small-padding-block-start);
|
|
2996
|
+
padding-block-end: var(--amplify-components-fieldcontrol-small-padding-block-end);
|
|
2997
|
+
padding-inline-start: var(--amplify-components-fieldcontrol-small-padding-inline-start);
|
|
2998
|
+
padding-inline-end: var(--amplify-components-fieldcontrol-small-padding-inline-end);
|
|
3034
2999
|
}
|
|
3035
3000
|
.amplify-textarea--large {
|
|
3036
3001
|
font-size: var(--amplify-components-fieldcontrol-large-font-size);
|
|
3037
|
-
-
|
|
3038
|
-
|
|
3039
|
-
-
|
|
3040
|
-
|
|
3041
|
-
-webkit-padding-start: var(--amplify-components-fieldcontrol-large-padding-inline-start);
|
|
3042
|
-
padding-inline-start: var(--amplify-components-fieldcontrol-large-padding-inline-start);
|
|
3043
|
-
-webkit-padding-end: var(--amplify-components-fieldcontrol-large-padding-inline-end);
|
|
3044
|
-
padding-inline-end: var(--amplify-components-fieldcontrol-large-padding-inline-end);
|
|
3002
|
+
padding-block-start: var(--amplify-components-fieldcontrol-large-padding-block-start);
|
|
3003
|
+
padding-block-end: var(--amplify-components-fieldcontrol-large-padding-block-end);
|
|
3004
|
+
padding-inline-start: var(--amplify-components-fieldcontrol-large-padding-inline-start);
|
|
3005
|
+
padding-inline-end: var(--amplify-components-fieldcontrol-large-padding-inline-end);
|
|
3045
3006
|
}
|
|
3046
3007
|
.amplify-textarea--error {
|
|
3047
3008
|
border-color: var(--amplify-components-fieldcontrol-error-border-color);
|
|
@@ -3057,12 +3018,9 @@ strong.amplify-text {
|
|
|
3057
3018
|
background-color: var(--amplify-components-fieldcontrol-disabled-background-color);
|
|
3058
3019
|
}
|
|
3059
3020
|
.amplify-textarea--quiet {
|
|
3060
|
-
-
|
|
3061
|
-
|
|
3062
|
-
-
|
|
3063
|
-
border-inline-start: var(--amplify-components-fieldcontrol-quiet-border-inline-start);
|
|
3064
|
-
-webkit-border-end: var(--amplify-components-fieldcontrol-quiet-border-inline-end);
|
|
3065
|
-
border-inline-end: var(--amplify-components-fieldcontrol-quiet-border-inline-end);
|
|
3021
|
+
border-block-start: var(--amplify-components-fieldcontrol-quiet-border-block-start);
|
|
3022
|
+
border-inline-start: var(--amplify-components-fieldcontrol-quiet-border-inline-start);
|
|
3023
|
+
border-inline-end: var(--amplify-components-fieldcontrol-quiet-border-inline-end);
|
|
3066
3024
|
border-radius: var(--amplify-components-fieldcontrol-quiet-border-radius);
|
|
3067
3025
|
}
|
|
3068
3026
|
.amplify-textarea--quiet:focus {
|
|
@@ -3339,8 +3297,7 @@ strong.amplify-text {
|
|
|
3339
3297
|
position: absolute;
|
|
3340
3298
|
z-index: 999999;
|
|
3341
3299
|
width: var(--amplify-components-autocomplete-menu-width);
|
|
3342
|
-
-
|
|
3343
|
-
margin-block-start: var(--amplify-components-autocomplete-menu-margin-block-start);
|
|
3300
|
+
margin-block-start: var(--amplify-components-autocomplete-menu-margin-block-start);
|
|
3344
3301
|
background-color: var(--amplify-components-autocomplete-menu-background-color);
|
|
3345
3302
|
border-color: var(--amplify-components-autocomplete-menu-border-color);
|
|
3346
3303
|
border-width: var(--amplify-components-autocomplete-menu-border-width);
|
|
@@ -3783,10 +3740,8 @@ strong.amplify-text {
|
|
|
3783
3740
|
flex: 1;
|
|
3784
3741
|
display: flex;
|
|
3785
3742
|
min-height: var(--amplify-components-expander-trigger-min-height);
|
|
3786
|
-
-
|
|
3787
|
-
|
|
3788
|
-
-webkit-padding-end: var(--amplify-components-expander-trigger-padding-inline-end);
|
|
3789
|
-
padding-inline-end: var(--amplify-components-expander-trigger-padding-inline-end);
|
|
3743
|
+
padding-inline-start: var(--amplify-components-expander-trigger-padding-inline-start);
|
|
3744
|
+
padding-inline-end: var(--amplify-components-expander-trigger-padding-inline-end);
|
|
3790
3745
|
align-items: var(--amplify-components-expander-trigger-align-items);
|
|
3791
3746
|
justify-content: var(--amplify-components-expander-trigger-justify-content);
|
|
3792
3747
|
}
|
|
@@ -3796,10 +3751,8 @@ strong.amplify-text {
|
|
|
3796
3751
|
|
|
3797
3752
|
.amplify-expander__content {
|
|
3798
3753
|
display: block;
|
|
3799
|
-
-
|
|
3800
|
-
|
|
3801
|
-
-webkit-padding-end: var(--amplify-components-expander-content-padding-inline-end);
|
|
3802
|
-
padding-inline-end: var(--amplify-components-expander-content-padding-inline-end);
|
|
3754
|
+
padding-inline-start: var(--amplify-components-expander-content-padding-inline-start);
|
|
3755
|
+
padding-inline-end: var(--amplify-components-expander-content-padding-inline-end);
|
|
3803
3756
|
}
|
|
3804
3757
|
.amplify-expander__content[data-state=open] {
|
|
3805
3758
|
animation-name: amplify-expander-slide-down;
|
|
@@ -3815,10 +3768,8 @@ strong.amplify-text {
|
|
|
3815
3768
|
.amplify-expander__content__text {
|
|
3816
3769
|
display: block;
|
|
3817
3770
|
color: var(--amplify-components-expander-content-text-color);
|
|
3818
|
-
-
|
|
3819
|
-
|
|
3820
|
-
-webkit-padding-after: var(--amplify-components-expander-content-text-padding-block-end);
|
|
3821
|
-
padding-block-end: var(--amplify-components-expander-content-text-padding-block-end);
|
|
3771
|
+
padding-block-start: var(--amplify-components-expander-content-text-padding-block-start);
|
|
3772
|
+
padding-block-end: var(--amplify-components-expander-content-text-padding-block-end);
|
|
3822
3773
|
}
|
|
3823
3774
|
|
|
3824
3775
|
.amplify-expander__icon {
|
|
@@ -3976,13 +3927,11 @@ html[dir=rtl] .amplify-field-group__inner-start {
|
|
|
3976
3927
|
}
|
|
3977
3928
|
|
|
3978
3929
|
.amplify-field-group--has-inner-end .amplify-input {
|
|
3979
|
-
-
|
|
3980
|
-
padding-inline-end: calc(var(--amplify-components-fieldcontrol-padding-inline-end) * 3);
|
|
3930
|
+
padding-inline-end: calc(var(--amplify-components-fieldcontrol-padding-inline-end) * 3);
|
|
3981
3931
|
}
|
|
3982
3932
|
|
|
3983
3933
|
.amplify-field-group--has-inner-start .amplify-input {
|
|
3984
|
-
-
|
|
3985
|
-
padding-inline-start: calc(var(--amplify-components-fieldcontrol-padding-inline-start) * 3);
|
|
3934
|
+
padding-inline-start: calc(var(--amplify-components-fieldcontrol-padding-inline-start) * 3);
|
|
3986
3935
|
}
|
|
3987
3936
|
|
|
3988
3937
|
/**
|
|
@@ -3990,10 +3939,8 @@ html[dir=rtl] .amplify-field-group__inner-start {
|
|
|
3990
3939
|
*/
|
|
3991
3940
|
.amplify-field-group__icon:not(.amplify-field-group__icon-button) {
|
|
3992
3941
|
display: flex;
|
|
3993
|
-
-
|
|
3994
|
-
|
|
3995
|
-
-webkit-padding-end: var(--amplify-components-fieldcontrol-padding-inline-start);
|
|
3996
|
-
padding-inline-end: var(--amplify-components-fieldcontrol-padding-inline-start);
|
|
3942
|
+
padding-inline-start: var(--amplify-components-fieldcontrol-padding-inline-start);
|
|
3943
|
+
padding-inline-end: var(--amplify-components-fieldcontrol-padding-inline-start);
|
|
3997
3944
|
flex-direction: column;
|
|
3998
3945
|
justify-content: center;
|
|
3999
3946
|
height: 100%;
|
|
@@ -4584,10 +4531,8 @@ html[dir=rtl] .amplify-field-group__inner-start {
|
|
|
4584
4531
|
|
|
4585
4532
|
.amplify-menu-content__item {
|
|
4586
4533
|
min-height: var(--amplify-components-menu-item-min-height);
|
|
4587
|
-
-
|
|
4588
|
-
|
|
4589
|
-
-webkit-padding-end: var(--amplify-components-menu-item-padding-inline-end);
|
|
4590
|
-
padding-inline-end: var(--amplify-components-menu-item-padding-inline-end);
|
|
4534
|
+
padding-inline-start: var(--amplify-components-menu-item-padding-inline-start);
|
|
4535
|
+
padding-inline-end: var(--amplify-components-menu-item-padding-inline-end);
|
|
4591
4536
|
}
|
|
4592
4537
|
|
|
4593
4538
|
.amplify-menu-content__item:not(:first-child):not(:last-child) {
|
|
@@ -4724,8 +4669,7 @@ html[dir=rtl] .amplify-field-group__inner-start {
|
|
|
4724
4669
|
}
|
|
4725
4670
|
|
|
4726
4671
|
.amplify-message__dismiss {
|
|
4727
|
-
-
|
|
4728
|
-
margin-inline-start: auto;
|
|
4672
|
+
margin-inline-start: auto;
|
|
4729
4673
|
gap: var(--amplify-components-message-dismiss-gap);
|
|
4730
4674
|
}
|
|
4731
4675
|
|
|
@@ -4748,10 +4692,8 @@ html[dir=rtl] .amplify-field-group__inner-start {
|
|
|
4748
4692
|
justify-content: center;
|
|
4749
4693
|
font-weight: initial;
|
|
4750
4694
|
color: var(--amplify-components-pagination-button-color);
|
|
4751
|
-
-
|
|
4752
|
-
|
|
4753
|
-
-webkit-padding-end: var(--amplify-components-pagination-button-padding-inline-end);
|
|
4754
|
-
padding-inline-end: var(--amplify-components-pagination-button-padding-inline-end);
|
|
4695
|
+
padding-inline-start: var(--amplify-components-pagination-button-padding-inline-start);
|
|
4696
|
+
padding-inline-end: var(--amplify-components-pagination-button-padding-inline-end);
|
|
4755
4697
|
transition-property: var(--amplify-components-pagination-button-transition-property);
|
|
4756
4698
|
transition-duration: var(--amplify-components-pagination-button-transition-duration);
|
|
4757
4699
|
}
|
|
@@ -4774,10 +4716,8 @@ html[dir=rtl] .amplify-field-group__inner-start {
|
|
|
4774
4716
|
.amplify-pagination__item-ellipsis {
|
|
4775
4717
|
align-items: var(--amplify-components-pagination-ellipsis-align-items);
|
|
4776
4718
|
justify-content: var(--amplify-components-pagination-ellipsis-justify-content);
|
|
4777
|
-
-
|
|
4778
|
-
|
|
4779
|
-
-webkit-padding-end: var(--amplify-components-pagination-ellipsis-padding-inline-end);
|
|
4780
|
-
padding-inline-end: var(--amplify-components-pagination-ellipsis-padding-inline-end);
|
|
4719
|
+
padding-inline-start: var(--amplify-components-pagination-ellipsis-padding-inline-start);
|
|
4720
|
+
padding-inline-end: var(--amplify-components-pagination-ellipsis-padding-inline-end);
|
|
4781
4721
|
}
|
|
4782
4722
|
|
|
4783
4723
|
.amplify-passwordfield {
|
|
@@ -5086,14 +5026,10 @@ html[dir=rtl] .amplify-field-group__inner-start {
|
|
|
5086
5026
|
color: var(--amplify-components-fieldcontrol-color);
|
|
5087
5027
|
font-size: var(--amplify-components-fieldcontrol-font-size);
|
|
5088
5028
|
line-height: var(--amplify-components-fieldcontrol-line-height);
|
|
5089
|
-
-
|
|
5090
|
-
|
|
5091
|
-
-
|
|
5092
|
-
|
|
5093
|
-
-webkit-padding-start: var(--amplify-components-fieldcontrol-padding-inline-start);
|
|
5094
|
-
padding-inline-start: var(--amplify-components-fieldcontrol-padding-inline-start);
|
|
5095
|
-
-webkit-padding-end: var(--amplify-components-fieldcontrol-padding-inline-end);
|
|
5096
|
-
padding-inline-end: var(--amplify-components-fieldcontrol-padding-inline-end);
|
|
5029
|
+
padding-block-start: var(--amplify-components-fieldcontrol-padding-block-start);
|
|
5030
|
+
padding-block-end: var(--amplify-components-fieldcontrol-padding-block-end);
|
|
5031
|
+
padding-inline-start: var(--amplify-components-fieldcontrol-padding-inline-start);
|
|
5032
|
+
padding-inline-end: var(--amplify-components-fieldcontrol-padding-inline-end);
|
|
5097
5033
|
transition: all var(--amplify-components-fieldcontrol-transition-duration);
|
|
5098
5034
|
width: 100%;
|
|
5099
5035
|
border-color: var(--amplify-components-fieldcontrol-border-color);
|
|
@@ -5105,8 +5041,7 @@ html[dir=rtl] .amplify-field-group__inner-start {
|
|
|
5105
5041
|
outline-width: var(--amplify-components-fieldcontrol-outline-width);
|
|
5106
5042
|
outline-offset: var(--amplify-components-fieldcontrol-outline-offset);
|
|
5107
5043
|
min-width: var(--amplify-components-select-min-width);
|
|
5108
|
-
-
|
|
5109
|
-
padding-inline-end: var(--amplify-components-select-padding-inline-end);
|
|
5044
|
+
padding-inline-end: var(--amplify-components-select-padding-inline-end);
|
|
5110
5045
|
white-space: var(--amplify-components-select-white-space);
|
|
5111
5046
|
}
|
|
5112
5047
|
.amplify-select:focus {
|
|
@@ -5115,25 +5050,17 @@ html[dir=rtl] .amplify-field-group__inner-start {
|
|
|
5115
5050
|
}
|
|
5116
5051
|
.amplify-select--small {
|
|
5117
5052
|
font-size: var(--amplify-components-fieldcontrol-small-font-size);
|
|
5118
|
-
-
|
|
5119
|
-
|
|
5120
|
-
-
|
|
5121
|
-
|
|
5122
|
-
-webkit-padding-start: var(--amplify-components-fieldcontrol-small-padding-inline-start);
|
|
5123
|
-
padding-inline-start: var(--amplify-components-fieldcontrol-small-padding-inline-start);
|
|
5124
|
-
-webkit-padding-end: var(--amplify-components-fieldcontrol-small-padding-inline-end);
|
|
5125
|
-
padding-inline-end: var(--amplify-components-fieldcontrol-small-padding-inline-end);
|
|
5053
|
+
padding-block-start: var(--amplify-components-fieldcontrol-small-padding-block-start);
|
|
5054
|
+
padding-block-end: var(--amplify-components-fieldcontrol-small-padding-block-end);
|
|
5055
|
+
padding-inline-start: var(--amplify-components-fieldcontrol-small-padding-inline-start);
|
|
5056
|
+
padding-inline-end: var(--amplify-components-fieldcontrol-small-padding-inline-end);
|
|
5126
5057
|
}
|
|
5127
5058
|
.amplify-select--large {
|
|
5128
5059
|
font-size: var(--amplify-components-fieldcontrol-large-font-size);
|
|
5129
|
-
-
|
|
5130
|
-
|
|
5131
|
-
-
|
|
5132
|
-
|
|
5133
|
-
-webkit-padding-start: var(--amplify-components-fieldcontrol-large-padding-inline-start);
|
|
5134
|
-
padding-inline-start: var(--amplify-components-fieldcontrol-large-padding-inline-start);
|
|
5135
|
-
-webkit-padding-end: var(--amplify-components-fieldcontrol-large-padding-inline-end);
|
|
5136
|
-
padding-inline-end: var(--amplify-components-fieldcontrol-large-padding-inline-end);
|
|
5060
|
+
padding-block-start: var(--amplify-components-fieldcontrol-large-padding-block-start);
|
|
5061
|
+
padding-block-end: var(--amplify-components-fieldcontrol-large-padding-block-end);
|
|
5062
|
+
padding-inline-start: var(--amplify-components-fieldcontrol-large-padding-inline-start);
|
|
5063
|
+
padding-inline-end: var(--amplify-components-fieldcontrol-large-padding-inline-end);
|
|
5137
5064
|
}
|
|
5138
5065
|
.amplify-select--error {
|
|
5139
5066
|
border-color: var(--amplify-components-fieldcontrol-error-border-color);
|
|
@@ -5149,12 +5076,9 @@ html[dir=rtl] .amplify-field-group__inner-start {
|
|
|
5149
5076
|
background-color: var(--amplify-components-fieldcontrol-disabled-background-color);
|
|
5150
5077
|
}
|
|
5151
5078
|
.amplify-select--quiet {
|
|
5152
|
-
-
|
|
5153
|
-
|
|
5154
|
-
-
|
|
5155
|
-
border-inline-start: var(--amplify-components-fieldcontrol-quiet-border-inline-start);
|
|
5156
|
-
-webkit-border-end: var(--amplify-components-fieldcontrol-quiet-border-inline-end);
|
|
5157
|
-
border-inline-end: var(--amplify-components-fieldcontrol-quiet-border-inline-end);
|
|
5079
|
+
border-block-start: var(--amplify-components-fieldcontrol-quiet-border-block-start);
|
|
5080
|
+
border-inline-start: var(--amplify-components-fieldcontrol-quiet-border-inline-start);
|
|
5081
|
+
border-inline-end: var(--amplify-components-fieldcontrol-quiet-border-inline-end);
|
|
5158
5082
|
border-radius: var(--amplify-components-fieldcontrol-quiet-border-radius);
|
|
5159
5083
|
}
|
|
5160
5084
|
.amplify-select--quiet:focus {
|
|
@@ -5181,13 +5105,11 @@ html[dir=rtl] .amplify-field-group__inner-start {
|
|
|
5181
5105
|
}
|
|
5182
5106
|
.amplify-select--small {
|
|
5183
5107
|
min-width: var(--amplify-components-select-small-min-width);
|
|
5184
|
-
-
|
|
5185
|
-
padding-inline-end: var(--amplify-components-select-small-padding-inline-end);
|
|
5108
|
+
padding-inline-end: var(--amplify-components-select-small-padding-inline-end);
|
|
5186
5109
|
}
|
|
5187
5110
|
.amplify-select--large {
|
|
5188
5111
|
min-width: var(--amplify-components-select-large-min-width);
|
|
5189
|
-
-
|
|
5190
|
-
padding-inline-end: var(--amplify-components-select-large-padding-inline-end);
|
|
5112
|
+
padding-inline-end: var(--amplify-components-select-large-padding-inline-end);
|
|
5191
5113
|
}
|
|
5192
5114
|
|
|
5193
5115
|
.amplify-selectfield {
|
|
@@ -5411,13 +5333,11 @@ html[dir=rtl] .amplify-field-group__inner-start {
|
|
|
5411
5333
|
}
|
|
5412
5334
|
|
|
5413
5335
|
.amplify-stepperfield__button--decrease[data-invalid=true] {
|
|
5414
|
-
-
|
|
5415
|
-
border-inline-end: none;
|
|
5336
|
+
border-inline-end: none;
|
|
5416
5337
|
}
|
|
5417
5338
|
|
|
5418
5339
|
.amplify-stepperfield__button--increase[data-invalid=true] {
|
|
5419
|
-
-
|
|
5420
|
-
border-inline-start: none;
|
|
5340
|
+
border-inline-start: none;
|
|
5421
5341
|
}
|
|
5422
5342
|
|
|
5423
5343
|
.amplify-stepperfield__input {
|
|
@@ -5429,10 +5349,8 @@ html[dir=rtl] .amplify-field-group__inner-start {
|
|
|
5429
5349
|
margin: 0;
|
|
5430
5350
|
}
|
|
5431
5351
|
.amplify-stepperfield__input:not(:focus, [aria-invalid=true]) {
|
|
5432
|
-
-
|
|
5433
|
-
|
|
5434
|
-
-webkit-border-end: none;
|
|
5435
|
-
border-inline-end: none;
|
|
5352
|
+
border-inline-start: none;
|
|
5353
|
+
border-inline-end: none;
|
|
5436
5354
|
}
|
|
5437
5355
|
|
|
5438
5356
|
.amplify-switchfield {
|
|
@@ -6041,8 +5959,7 @@ html[dir=rtl] .amplify-field-group__inner-start {
|
|
|
6041
5959
|
z-index: 2;
|
|
6042
5960
|
}
|
|
6043
5961
|
.amplify-togglebuttongroup .amplify-togglebutton:not(:first-of-type) {
|
|
6044
|
-
-
|
|
6045
|
-
margin-inline-start: calc(-1 * var(--amplify-components-button-border-width));
|
|
5962
|
+
margin-inline-start: calc(-1 * var(--amplify-components-button-border-width));
|
|
6046
5963
|
border-start-start-radius: 0;
|
|
6047
5964
|
border-end-start-radius: 0;
|
|
6048
5965
|
}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { LivenessErrorState } from '../service';
|
|
3
2
|
import { HintDisplayText, CameraDisplayText, StreamDisplayText, ErrorDisplayText } from '../displayText';
|
|
4
3
|
import { CheckScreenComponents } from '../shared/FaceLivenessErrorModal';
|
|
5
|
-
export declare const selectErrorState: import("../hooks").LivenessSelectorFn<LivenessErrorState | undefined>;
|
|
6
|
-
export declare const selectIsRecordingStopped: import("../hooks").LivenessSelectorFn<boolean | undefined>;
|
|
7
4
|
interface LivenessCheckProps {
|
|
8
5
|
hintDisplayText: Required<HintDisplayText>;
|
|
9
6
|
cameraDisplayText: Required<CameraDisplayText>;
|
package/dist/types/components/FaceLivenessDetector/service/utils/CustomWebSocketFetchHandler.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { HttpRequest, HttpResponse } from '@smithy/protocol-http';
|
|
2
|
+
import { Provider, RequestHandler, RequestHandlerMetadata } from '@smithy/types';
|
|
3
|
+
export interface WebSocketFetchHandlerOptions {
|
|
4
|
+
/**
|
|
5
|
+
* The maximum time in milliseconds that the connection phase of a request
|
|
6
|
+
* may take before the connection attempt is abandoned.
|
|
7
|
+
*/
|
|
8
|
+
connectionTimeout?: number;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Base handler for websocket requests and HTTP request. By default, the request input and output
|
|
12
|
+
* body will be in a ReadableStream, because of interface consistency among middleware.
|
|
13
|
+
* If ReadableStream is not available, like in React-Native, the response body
|
|
14
|
+
* will be an async iterable.
|
|
15
|
+
*/
|
|
16
|
+
export declare class CustomWebSocketFetchHandler {
|
|
17
|
+
readonly metadata: RequestHandlerMetadata;
|
|
18
|
+
private readonly configPromise;
|
|
19
|
+
private readonly httpHandler;
|
|
20
|
+
private readonly sockets;
|
|
21
|
+
private readonly utf8decoder;
|
|
22
|
+
constructor(options?: WebSocketFetchHandlerOptions | Provider<WebSocketFetchHandlerOptions>, httpHandler?: RequestHandler<any, any>);
|
|
23
|
+
/**
|
|
24
|
+
* Destroys the WebSocketHandler.
|
|
25
|
+
* Closes all sockets from the socket pool.
|
|
26
|
+
*/
|
|
27
|
+
destroy(): void;
|
|
28
|
+
handle(request: HttpRequest): Promise<{
|
|
29
|
+
response: HttpResponse;
|
|
30
|
+
}>;
|
|
31
|
+
/**
|
|
32
|
+
* Removes all closing/closed sockets from the socket pool for URL.
|
|
33
|
+
*/
|
|
34
|
+
private removeNotUsableSockets;
|
|
35
|
+
private waitForReady;
|
|
36
|
+
private connect;
|
|
37
|
+
}
|
|
@@ -1,3 +1,11 @@
|
|
|
1
1
|
export declare const FACE_DISTANCE_THRESHOLD = 0.32;
|
|
2
2
|
export declare const REDUCED_THRESHOLD = 0.4;
|
|
3
3
|
export declare const REDUCED_THRESHOLD_MOBILE = 0.37;
|
|
4
|
+
export declare const WS_CLOSURE_CODE: {
|
|
5
|
+
SUCCESS_CODE: number;
|
|
6
|
+
DEFAULT_ERROR_CODE: number;
|
|
7
|
+
FACE_FIT_TIMEOUT: number;
|
|
8
|
+
USER_CANCEL: number;
|
|
9
|
+
RUNTIME_ERROR: number;
|
|
10
|
+
USER_ERROR_DURING_CONNECTION: number;
|
|
11
|
+
};
|
|
@@ -39,7 +39,7 @@ export declare class LivenessStreamProvider extends AmazonAIInterpretPredictions
|
|
|
39
39
|
sendClientInfo(clientInfo: ClientSessionInformationEvent): void;
|
|
40
40
|
stopVideo(): Promise<void>;
|
|
41
41
|
dispatchStopVideoEvent(): void;
|
|
42
|
-
|
|
42
|
+
endStreamWithCode(code?: number): Promise<undefined>;
|
|
43
43
|
private init;
|
|
44
44
|
private getAsyncGeneratorFromReadableStream;
|
|
45
45
|
private startLivenessVideoConnection;
|
|
@@ -7,7 +7,10 @@ export interface VideoRecorderOptions {
|
|
|
7
7
|
* Helper wrapper class over the native MediaRecorder.
|
|
8
8
|
*/
|
|
9
9
|
export declare class VideoRecorder {
|
|
10
|
-
videoStream: ReadableStream<Blob | string
|
|
10
|
+
videoStream: ReadableStream<Blob | string | {
|
|
11
|
+
type: string;
|
|
12
|
+
code: number;
|
|
13
|
+
}>;
|
|
11
14
|
recordingStartApiTimestamp: number | undefined;
|
|
12
15
|
recorderStartTimestamp: number | undefined;
|
|
13
16
|
recorderEndTimestamp: number | undefined;
|
package/dist/types/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "2.0.
|
|
1
|
+
export declare const VERSION = "2.0.7";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-amplify/ui-react-liveness",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.7",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "dist/esm/index.mjs",
|
|
6
6
|
"exports": {
|
|
@@ -50,7 +50,8 @@
|
|
|
50
50
|
"dependencies": {
|
|
51
51
|
"@aws-amplify/ui": "5.8.0",
|
|
52
52
|
"@aws-amplify/ui-react": "5.3.0",
|
|
53
|
-
"@aws-sdk/client-rekognitionstreaming": "3.
|
|
53
|
+
"@aws-sdk/client-rekognitionstreaming": "3.398.0",
|
|
54
|
+
"@smithy/eventstream-serde-browser": "^2.0.4",
|
|
54
55
|
"@tensorflow-models/blazeface": "0.0.7",
|
|
55
56
|
"@tensorflow/tfjs-backend-cpu": "3.11.0",
|
|
56
57
|
"@tensorflow/tfjs-backend-wasm": "3.11.0",
|
|
@@ -78,7 +79,9 @@
|
|
|
78
79
|
"eslint": "^8.44.0",
|
|
79
80
|
"jest": "^27.0.4",
|
|
80
81
|
"jest-canvas-mock": "^2.4.0",
|
|
82
|
+
"jest-websocket-mock": "^2.4.1",
|
|
81
83
|
"jest-when": "^3.5.1",
|
|
84
|
+
"mock-socket": "^9.2.1",
|
|
82
85
|
"react": "^17.0.2",
|
|
83
86
|
"react-dom": "^17.0.2",
|
|
84
87
|
"rimraf": "^3.0.2",
|