@aws-amplify/ui-react-liveness 1.0.5 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/dist/esm/components/FaceLivenessDetector/FaceLivenessDetector.mjs +1 -1
  2. package/dist/esm/components/FaceLivenessDetector/FaceLivenessDetectorCore.mjs +1 -0
  3. package/dist/esm/components/FaceLivenessDetector/LivenessCheck/LivenessCameraModule.mjs +1 -1
  4. package/dist/esm/components/FaceLivenessDetector/displayText.mjs +1 -1
  5. package/dist/esm/components/FaceLivenessDetector/service/machine/index.mjs +1 -1
  6. package/dist/esm/components/FaceLivenessDetector/service/types/error.mjs +1 -1
  7. package/dist/esm/components/FaceLivenessDetector/service/utils/blazefaceFaceDetection.mjs +1 -1
  8. package/dist/esm/components/FaceLivenessDetector/service/utils/liveness.mjs +1 -1
  9. package/dist/esm/components/FaceLivenessDetector/service/utils/streamProvider.mjs +1 -1
  10. package/dist/esm/components/FaceLivenessDetector/service/utils/videoRecorder.mjs +1 -1
  11. package/dist/esm/components/FaceLivenessDetector/shared/DefaultStartScreenComponents.mjs +1 -1
  12. package/dist/esm/components/FaceLivenessDetector/shared/FaceLivenessErrorModal.mjs +1 -1
  13. package/dist/esm/components/FaceLivenessDetector/shared/Hint.mjs +1 -1
  14. package/dist/esm/components/FaceLivenessDetector/shared/LandscapeErrorModal.mjs +1 -1
  15. package/dist/esm/components/FaceLivenessDetector/shared/LivenessIconWithPopover.mjs +1 -1
  16. package/dist/esm/components/FaceLivenessDetector/shared/Overlay.mjs +1 -1
  17. package/dist/esm/components/FaceLivenessDetector/shared/Toast.mjs +1 -1
  18. package/dist/esm/components/FaceLivenessDetector/types/classNames.mjs +1 -1
  19. package/dist/esm/components/FaceLivenessDetector/utils/getDisplayText.mjs +1 -1
  20. package/dist/esm/index.mjs +1 -1
  21. package/dist/esm/version.mjs +1 -1
  22. package/dist/index.js +1 -1
  23. package/dist/styles.css +129 -0
  24. package/dist/types/components/FaceLivenessDetector/FaceLivenessDetector.d.ts +1 -4
  25. package/dist/types/components/FaceLivenessDetector/FaceLivenessDetectorCore.d.ts +11 -0
  26. package/dist/types/components/FaceLivenessDetector/displayText.d.ts +2 -0
  27. package/dist/types/components/FaceLivenessDetector/index.d.ts +2 -0
  28. package/dist/types/components/FaceLivenessDetector/service/types/credentials.d.ts +16 -0
  29. package/dist/types/components/FaceLivenessDetector/service/types/error.d.ts +2 -1
  30. package/dist/types/components/FaceLivenessDetector/service/types/index.d.ts +1 -0
  31. package/dist/types/components/FaceLivenessDetector/service/types/liveness.d.ts +25 -5
  32. package/dist/types/components/FaceLivenessDetector/service/types/machine.d.ts +3 -3
  33. package/dist/types/components/FaceLivenessDetector/service/utils/blazefaceFaceDetection.d.ts +7 -0
  34. package/dist/types/components/FaceLivenessDetector/service/utils/liveness.d.ts +4 -1
  35. package/dist/types/components/FaceLivenessDetector/service/utils/streamProvider.d.ts +10 -1
  36. package/dist/types/components/FaceLivenessDetector/service/utils/videoRecorder.d.ts +1 -0
  37. package/dist/types/components/FaceLivenessDetector/shared/FaceLivenessErrorModal.d.ts +2 -0
  38. package/dist/types/components/FaceLivenessDetector/types/classNames.d.ts +21 -0
  39. package/dist/types/index.d.ts +1 -1
  40. package/dist/types/version.d.ts +1 -1
  41. package/package.json +7 -8
@@ -1 +1 @@
1
- import*as e from"react";import{useInterpret as t,useActor as s}from"@xstate/react";import{livenessMachine as r}from"./service/machine/index.mjs";import"./service/types/liveness.mjs";import"./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{View as o,Flex as i}from"@aws-amplify/ui-react";import{FaceLivenessDetectorProvider as m}from"./providers/FaceLivenessDetectorProvider.mjs";import{StartLiveness as n}from"./StartLiveness/StartLiveness.mjs";import{LivenessCheck as a}from"./LivenessCheck/LivenessCheck.mjs";import{getVideoConstraints as c}from"./StartLiveness/helpers.mjs";import{getDisplayText as p}from"./utils/getDisplayText.mjs";const l="liveness-detector";function f(f){const{disableInstructionScreen:v=!1,components:u,config:y,displayText:d}=f,j=e.useRef(null),{hintDisplayText:x,cameraDisplayText:D,instructionDisplayText:T,streamDisplayText:h,errorDisplayText:b}=p(d),E=t(r,{devTools:"development"===process.env.NODE_ENV,context:{componentProps:Object.assign(Object.assign({},f),{config:null!=y?y:{}})}}),[L,w]=s(E),C=L.matches("start")||L.matches("userCancel"),g=e.useCallback((()=>{const e=c();w({type:"BEGIN",data:{videoConstraints:e}})}),[w]);return e.useLayoutEffect((()=>{v&&C&&g()}),[g,v,C]),e.createElement(o,{className:l,testId:l},e.createElement(m,{componentProps:f,service:E},e.createElement(i,{direction:"column",ref:j},C?e.createElement(n,{beginLivenessCheck:g,components:u,instructionDisplayText:T}):e.createElement(a,{hintDisplayText:x,cameraDisplayText:D,streamDisplayText:h,errorDisplayText:b,components:u}))))}export{f as default};
1
+ import{__rest as e,__awaiter as o}from"tslib";import*as t from"react";import{Credentials as r}from"@aws-amplify/core";import i from"./FaceLivenessDetectorCore.mjs";const n=()=>o(void 0,void 0,void 0,(function*(){return yield r.get()}));function c(o){const{config:r}=o,c=e(o,["config"]);return t.createElement(i,Object.assign({},c,{config:Object.assign({credentialProvider:n},r)}))}export{c as default};
@@ -0,0 +1 @@
1
+ import*as e from"react";import{useInterpret as t,useActor as s}from"@xstate/react";import{livenessMachine as r}from"./service/machine/index.mjs";import"./service/types/liveness.mjs";import"./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{View as o,Flex as i}from"@aws-amplify/ui-react";import{FaceLivenessDetectorProvider as m}from"./providers/FaceLivenessDetectorProvider.mjs";import{StartLiveness as n}from"./StartLiveness/StartLiveness.mjs";import{LivenessCheck as a}from"./LivenessCheck/LivenessCheck.mjs";import{getVideoConstraints as c}from"./StartLiveness/helpers.mjs";import{getDisplayText as p}from"./utils/getDisplayText.mjs";const l="liveness-detector";function f(f){const{disableInstructionScreen:v=!1,components:u,config:y,displayText:d}=f,j=e.useRef(null),{hintDisplayText:x,cameraDisplayText:D,instructionDisplayText:T,streamDisplayText:h,errorDisplayText:b}=p(d),E=t(r,{devTools:"development"===process.env.NODE_ENV,context:{componentProps:Object.assign(Object.assign({},f),{config:null!=y?y:{}})}}),[L,w]=s(E),C=L.matches("start")||L.matches("userCancel"),g=e.useCallback((()=>{const e=c();w({type:"BEGIN",data:{videoConstraints:e}})}),[w]);return e.useLayoutEffect((()=>{v&&C&&g()}),[g,v,C]),e.createElement(o,{className:l,testId:l},e.createElement(m,{componentProps:f,service:E},e.createElement(i,{direction:"column",ref:j},C?e.createElement(n,{beginLivenessCheck:g,components:u,instructionDisplayText:T}):e.createElement(a,{hintDisplayText:x,cameraDisplayText:D,streamDisplayText:h,errorDisplayText:b,components:u}))))}export{f as default};
@@ -1 +1 @@
1
- import e,{useRef as t,useState as r}from"react";import a from"react-countdown-circle-timer";import o from"classnames";import{Loader as s,useTheme as i,Flex as n,View as c,Text as m}from"@aws-amplify/ui-react";import"../service/machine/index.mjs";import{FaceMatchState as l}from"../service/types/liveness.mjs";import"../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{useLivenessActor as d}from"../hooks/useLivenessActor.mjs";import{useLivenessSelector as p,createLivenessSelector as h}from"../hooks/useLivenessSelector.mjs";import{useMediaStreamInVideo as v}from"../hooks/useMediaStreamInVideo.mjs";import{CancelButton as u}from"../shared/CancelButton.mjs";import{selectErrorState as f,Hint as E}from"../shared/Hint.mjs";import{MatchIndicator as C}from"../shared/MatchIndicator.mjs";import{Overlay as y}from"../shared/Overlay.mjs";import{RecordingIcon as g}from"../shared/RecordingIcon.mjs";import{LivenessClassNames as j}from"../types/classNames.mjs";import{renderErrorModal as T,FaceLivenessErrorModal as w}from"../shared/FaceLivenessErrorModal.mjs";const N=h((e=>{var t;return null===(t=e.context.videoAssociatedParams)||void 0===t?void 0:t.videoConstraints})),x=h((e=>{var t;return null===(t=e.context.videoAssociatedParams)||void 0===t?void 0:t.videoMediaStream})),A=h((e=>e.context.faceMatchAssociatedParams.faceMatchPercentage)),I=h((e=>e.context.faceMatchAssociatedParams.faceMatchState)),M=e.createElement(s,{size:"large",className:j.Loader,"data-testid":"centered-loader"}),D=s=>{const{isMobileScreen:h,isRecordingStopped:D,streamDisplayText:b,hintDisplayText:k,errorDisplayText:R,components:S,testId:O}=s,{cancelLivenessCheckText:L,recordingIndicatorText:P}=b,{ErrorView:F=w}=null!=S?S:{},{tokens:_}=i(),[z,H]=d(),W=p(x),V=p(N),$=p(A),B=p(I),G=p(f),X=[l.TOO_FAR,l.CANT_IDENTIFY,l.FACE_IDENTIFIED,l.MATCHED],{videoRef:Y,videoWidth:q,videoHeight:J}=v(W,V),K=t(null),Q=t(null),[U,Z]=r(!1),[ee,te]=r(!1),re=z.matches("cameraCheck"),ae=z.matches("notRecording"),oe=z.matches("recording"),se=z.matches("checkSucceeded"),ie=z.matches({recording:"flashFreshnessColors"}),[ne,ce]=r(q),[me,le]=r(J),[de,pe]=r((()=>q&&J?q/J:0));e.useLayoutEffect((()=>{ee&&H({type:"SET_DOM_AND_CAMERA_DETAILS",data:{videoEl:Y.current,canvasEl:K.current,freshnessColorEl:Q.current,isMobile:h}}),Y.current&&(ce(Y.current.videoWidth),le(Y.current.videoHeight),pe(Y.current.videoWidth/Y.current.videoHeight))}),[H,Y,ee,h]);return re?e.createElement(n,{height:J,width:"100%",position:"relative"},M):e.createElement(n,{className:o(j.CameraModule,h&&`${j.CameraModule}--mobile`),"data-testid":O},!ee&&M,e.createElement(c,{as:"canvas",ref:Q,className:j.FreshnessCanvas,hidden:!0}),e.createElement(c,{className:j.VideoAnchor,style:{aspectRatio:`${de}`}},e.createElement("video",{ref:Y,muted:!0,autoPlay:!0,playsInline:!0,style:{transform:"scaleX(-1)"},width:ne,height:me,onCanPlay:()=>{te(!0),Z(!0)},"data-testid":"video",className:j.Video}),e.createElement(n,{className:o(j.OvalCanvas,h&&`${j.OvalCanvas}--mobile`,D&&j.FadeOut)},e.createElement(c,{as:"canvas",width:"100%",height:"100%",ref:K})),oe&&e.createElement(c,{className:j.RecordingIconContainer},e.createElement(g,null,P)),!se&&e.createElement(c,{className:j.CancelContainer},e.createElement(u,{ariaLabel:L})),U&&e.createElement(y,{anchorOrigin:{horizontal:"center",vertical:oe&&!ie?"start":"space-between"},className:j.InstructionOverlay},e.createElement(E,{hintDisplayText:k}),G&&e.createElement(F,{onRetry:()=>{H({type:"CANCEL"})}},T({errorState:G,overrideErrorDisplayText:R})),oe&&!ie&&X.includes(B)?e.createElement(C,{percentage:$}):null,ae&&e.createElement(c,{className:j.CountdownContainer,testId:"liveness-camera-countdown-timer"},e.createElement(a.CountdownCircleTimer,{isPlaying:ae,size:85,strokeWidth:8,duration:3,rotation:"counterclockwise",colors:"#40aabf",trailColor:`${_.colors.background.primary}`,onComplete:()=>{H({type:"START_RECORDING"})}},(({remainingTime:t})=>e.createElement(m,{fontSize:"xxxl",fontWeight:"bold"},t)))))))};export{D as LivenessCameraModule,A as selectFaceMatchPercentage,I as selectFaceMatchState,N as selectVideoConstraints,x as selectVideoStream};
1
+ import e,{useRef as t,useState as r}from"react";import a from"classnames";import{Loader as s,Flex as o,View as i}from"@aws-amplify/ui-react";import"../service/machine/index.mjs";import{FaceMatchState as c}from"../service/types/liveness.mjs";import"../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{useLivenessActor as n}from"../hooks/useLivenessActor.mjs";import{useLivenessSelector as m,createLivenessSelector as l}from"../hooks/useLivenessSelector.mjs";import{useMediaStreamInVideo as d}from"../hooks/useMediaStreamInVideo.mjs";import{CancelButton as h}from"../shared/CancelButton.mjs";import{selectErrorState as p,Hint as v}from"../shared/Hint.mjs";import{MatchIndicator as f}from"../shared/MatchIndicator.mjs";import{Overlay as u}from"../shared/Overlay.mjs";import{RecordingIcon as E}from"../shared/RecordingIcon.mjs";import{LivenessClassNames as y}from"../types/classNames.mjs";import{renderErrorModal as C,FaceLivenessErrorModal as j}from"../shared/FaceLivenessErrorModal.mjs";const g=l((e=>{var t;return null===(t=e.context.videoAssociatedParams)||void 0===t?void 0:t.videoConstraints})),M=l((e=>{var t;return null===(t=e.context.videoAssociatedParams)||void 0===t?void 0:t.videoMediaStream})),A=l((e=>e.context.faceMatchAssociatedParams.faceMatchPercentage)),N=l((e=>e.context.faceMatchAssociatedParams.faceMatchState)),I=e.createElement(s,{size:"large",className:y.Loader,"data-testid":"centered-loader"}),T=e.memo(f),x=s=>{const{isMobileScreen:l,isRecordingStopped:f,streamDisplayText:x,hintDisplayText:D,errorDisplayText:w,components:b,testId:S}=s,{cancelLivenessCheckText:L,recordingIndicatorText:O}=x,{ErrorView:k=j}=null!=b?b:{},[F,P]=n(),R=m(M),_=m(g),H=m(A),V=m(N),z=m(p),W=[c.TOO_FAR,c.CANT_IDENTIFY,c.FACE_IDENTIFIED,c.MATCHED],{videoRef:$,videoWidth:B,videoHeight:X}=d(R,_),Y=t(null),q=t(null),[G,J]=r(!1),K=F.matches("cameraCheck"),Q=F.matches("recording"),U=F.matches("checkSucceeded"),Z=F.matches({recording:"flashFreshnessColors"}),[ee,te]=r(B),[re,ae]=r(X),[se,oe]=r((()=>B&&X?B/X:0));e.useLayoutEffect((()=>{G&&P({type:"SET_DOM_AND_CAMERA_DETAILS",data:{videoEl:$.current,canvasEl:Y.current,freshnessColorEl:q.current,isMobile:l}}),$.current&&(te($.current.videoWidth),ae($.current.videoHeight),oe($.current.videoWidth/$.current.videoHeight))}),[P,$,G,l]);return K?e.createElement(o,{height:X,width:"100%",position:"relative"},I):e.createElement(o,{className:a(y.CameraModule,l&&`${y.CameraModule}--mobile`),"data-testid":S},!G&&I,e.createElement(i,{as:"canvas",ref:q,className:y.FreshnessCanvas,hidden:!0}),e.createElement(i,{className:y.VideoAnchor,style:{aspectRatio:`${se}`}},e.createElement("video",{ref:$,muted:!0,autoPlay:!0,playsInline:!0,style:{transform:"scaleX(-1)"},width:ee,height:re,onCanPlay:()=>{J(!0)},"data-testid":"video",className:y.Video}),e.createElement(o,{className:a(y.OvalCanvas,l&&`${y.OvalCanvas}--mobile`,f&&y.FadeOut)},e.createElement(i,{as:"canvas",width:"100%",height:"100%",ref:Y})),Q&&e.createElement(i,{className:y.RecordingIconContainer},e.createElement(E,null,O)),!U&&e.createElement(i,{className:y.CancelContainer},e.createElement(h,{ariaLabel:L})),e.createElement(u,{anchorOrigin:{horizontal:"center",vertical:Q&&!Z?"start":"space-between"},className:y.InstructionOverlay},e.createElement(v,{hintDisplayText:D}),z&&e.createElement(k,{onRetry:()=>{P({type:"CANCEL"})}},C({errorState:z,overrideErrorDisplayText:w})),Q&&!Z&&W.includes(V)?e.createElement(T,{percentage:Math.ceil(H)}):null)))};export{x as LivenessCameraModule,A as selectFaceMatchPercentage,N as selectFaceMatchState,g as selectVideoConstraints,M as selectVideoStream};
@@ -1 +1 @@
1
- const e={timeoutHeaderText:"Time out",timeoutMessageText:"Face didn't fill oval within time limit. Try again and completely fill oval with face within 7 seconds.",faceDistanceHeaderText:"Check failed during countdown",faceDistanceMessageText:"Avoid moving closer during countdown and ensure only one face is in front of camera.",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"},t=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, fill the oval with your face within 7 seconds.",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"},e);export{e as defaultErrorDisplayText,t as defaultLivenessDisplayText};
1
+ const e={timeoutHeaderText:"Time out",timeoutMessageText:"Face didn't fill oval within time limit. Try again and completely fill oval with face within 7 seconds.",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"},t=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, fill the oval with your face within 7 seconds.",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"},e);export{e as defaultErrorDisplayText,t as defaultLivenessDisplayText};
@@ -1 +1 @@
1
- import{__awaiter as e,__asyncValues as t}from"tslib";import{createMachine as a,assign as o,spawn as i,actions as r}from"xstate";import{getBoundingBox as s,getColorsSequencesFromSessionInformation as n,LivenessErrorStateStringMap as c,isCameraDeviceVirtual as d,getFaceMatchState as l,isFaceDistanceBelowThreshold as v,estimateIllumination as m,getOvalDetailsFromSessionInformation as h,generateBboxFromLandmarks as g,drawLivenessOvalInCanvas as f,getOvalBoundingBox as u,getIntersectionOverUnion as S,getFaceMatchStateInLivenessOval as p,getStaticLivenessOvalDetails as F}from"../utils/liveness.mjs";import{FaceMatchState as D}from"../types/liveness.mjs";import{LivenessErrorState as E}from"../types/error.mjs";import{BlazeFaceFaceDetection as A}from"../utils/blazefaceFaceDetection.mjs";import{LivenessStreamProvider as M}from"../utils/streamProvider.mjs";import{FreshnessColorDisplay as R}from"../utils/freshnessColorDisplay.mjs";import{nanoid as C}from"nanoid";import{isServerSesssionInformationEvent as P,isDisconnectionEvent as T,isValidationExceptionEvent as O,isInternalServerExceptionEvent as I,isThrottlingExceptionEvent as w,isServiceQuotaExceededExceptionEvent as y,isInvalidSignatureRegionException as b}from"../utils/eventUtils.mjs";const k=500;let B;const j=a({id:"livenessMachine",initial:"start",predictableActionArguments:!0,context:{challengeId:C(),maxFailedAttempts:0,failedAttempts:0,componentProps:void 0,serverSessionInformation:void 0,videoAssociatedParams:void 0,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"},MOBILE_LANDSCAPE_WARNING:{target:"mobileLandscapeWarning",actions:"updateErrorStateForServer"}},states:{start:{on:{BEGIN:"cameraCheck"}},cameraCheck:{entry:["resetErrorState","setVideoConstraints","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:"waitForSessionInfo",actions:["updateLivenessStreamProvider","spawnResponseStreamActor"]}}},waitForSessionInfo:{after:{0:{target:"notRecording",cond:"hasServerSessionInfo"},100:{target:"waitForSessionInfo"}}},notRecording:{on:{START_RECORDING:"recording"},initial:"detectFaceDistanceDuringCountdown",states:{detectFaceDistanceDuringCountdown:{invoke:{src:"detectFaceDistance",onDone:{target:"checkFaceDistanceDuringCountdown",actions:["updateFaceDistanceBeforeRecording"]}}},checkFaceDistanceDuringCountdown:{after:{0:{target:"failure",cond:"hasNotEnoughFaceDistanceBeforeRecording"},200:{target:"detectFaceDistanceDuringCountdown"}}},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:()=>i(_)}),updateFailedAttempts:o({failedAttempts:e=>e.failedAttempts+1}),setVideoConstraints:o({videoAssociatedParams:(e,t)=>{var a,o;return Object.assign(Object.assign({},e.videoAssociatedParams),{videoConstraints:(null===(a=t.data)||void 0===a?void 0:a.videoConstraints)||(null===(o=e.videoAssociatedParams)||void 0===o?void 0:o.videoConstraints)})}}),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,i=new A(o,a);return i.triggerModelLoading(),Object.assign(Object.assign({},e.ovalAssociatedParams),{faceDetector:i})}}),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,i;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===(i=t.data)||void 0===i?void 0:i.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:i}=e,{recordingStartApiTimestamp:r,recorderStartTimestamp:n}=i.videoRecorder,{videoMediaStream:c}=a,{initialFace:d}=o,l=Math.round(.73*(n-r)+r),{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}),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)||E.TIMEOUT}}),updateErrorStateForRuntime:o({errorState:e=>E.RUNTIME_ERROR}),updateErrorStateForServer:o({errorState:e=>E.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 R(e,a);return Object.assign(Object.assign({},e.freshnessColorAssociatedParams),{freshnessColorDisplay:o})}}),sendTimeoutAfterOvalDrawingDelay:r.send({type:"TIMEOUT"},{delay:5e3,id:"ovalDrawingTimeout"}),cancelOvalDrawingTimeout:r.cancel("ovalDrawingTimeout"),sendTimeoutAfterOvalMatchDelay:r.send({type:"TIMEOUT"},{delay:7e3,id:"ovalMatchTimeout"}),cancelOvalMatchTimeout:r.cancel("ovalMatchTimeout"),sendTimeoutAfterWaitingForDisconnect:r.send({type:"TIMEOUT",data:{errorState:E.SERVER_ERROR}},{delay:2e4,id:"waitForDisconnectTimeout"}),cancelWaitForDisconnectTimeout:r.cancel("waitForDisconnectTimeout"),sendTimeoutAfterFaceDistanceDelay:r.send({type:"TIMEOUT",data:{errorState:E.FACE_DISTANCE_ERROR}},{delay:0,id:"faceDistanceTimeout"}),cancelFaceDistanceTimeout:r.cancel("faceDistanceTimeout"),callUserPermissionDeniedCallback:o({errorState:(e,t)=>{var a,o;let i;i=t.data.message.includes("15 fps")?E.CAMERA_FRAMERATE_ERROR:E.CAMERA_ACCESS_ERROR;const r=t.data.message||t.data.Message,s=new Error(r);return s.name=i,null===(o=(a=e.componentProps).onError)||void 0===o||o.call(a,s),i}}),callMobileLandscapeWarningCallback:o({errorState:e=>E.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(c[t.errorState]);o.name=t.errorState,null===(a=(e=t.componentProps).onError)||void 0===a||a.call(e,o)})),callErrorCallback:(t,a)=>e(void 0,void 0,void 0,(function*(){var e,o,i,r,s,n;const c=(null===(o=null===(e=a.data)||void 0===e?void 0:e.error)||void 0===o?void 0:o.message)||(null===(r=null===(i=a.data)||void 0===i?void 0:i.error)||void 0===r?void 0:r.Message),d=new Error(c);d.name=t.errorState,null===(n=(s=t.componentProps).onError)||void 0===n||n.call(s,d)})),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:C(),maxFailedAttempts:0,failedAttempts:0,componentProps:e=>e.componentProps,serverSessionInformation:e=>{},videoAssociatedParams:e=>{},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===D.MATCHED&&o>=500},hasFaceMatchedInOval:e=>e.faceMatchAssociatedParams.faceMatchState===D.MATCHED,hasNotFaceMatchedInOval:e=>e.faceMatchAssociatedParams.faceMatchState!==D.MATCHED,hasSingleFace:e=>e.faceMatchAssociatedParams.faceMatchState===D.FACE_IDENTIFIED,hasSingleFaceBeforeStart:e=>e.faceMatchStateBeforeStart===D.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=>!d(e)));if(!o.length)throw new Error("No real video devices found");const i=a.getTracks().filter((e=>e.getSettings().frameRate>=15));if(i.length<1)throw new Error("No camera found with more than 15 fps");const r=i[0].getSettings().deviceId;let s=a;return o.some((e=>e.deviceId===r))||(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 e=new M(t.componentProps.sessionId,t.componentProps.region,t.videoAssociatedParams.videoMediaStream,t.videoAssociatedParams.videoEl);return B=e.getResponseStream(),{livenessStreamProvider:e}}))},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 l(a,e)}}))},detectFaceDistance(t){return e(this,void 0,void 0,(function*(){const{isFaceFarEnoughBeforeRecording:e}=t,{videoEl:a,videoMediaStream:o,isMobile:i}=t.videoAssociatedParams,{faceDetector:r}=t.ovalAssociatedParams,{width:s,height:n}=o.getTracks()[0].getSettings(),c=F({width:s,height:n});return{isFaceFarEnoughBeforeRecording:yield v({faceDetector:r,videoEl:a,ovalDetails:c,reduceThreshold:e,isMobile:i})}}))},detectInitialFaceAndDrawOval(t){return e(this,void 0,void 0,(function*(){const{serverSessionInformation:e,livenessStreamProvider:a}=t,{videoEl:o,canvasEl:i,isMobile:r}=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=D.CANT_IDENTIFY,l=m(o);break;case 1:d=D.FACE_IDENTIFIED,c=n[0];break;default:d=D.TOO_MANY}if(!c)return{faceMatchState:d,illuminationState:l};const{width:v,height:u}=o.getBoundingClientRect();r?(i.width=window.innerWidth,i.height=window.innerHeight):(i.width=v,i.height=u);const S=v/o.videoWidth,p=h({sessionInformation:e,videoWidth:o.width}),F=g(c,p);return c.top=F.top,c.left=F.left,c.height=F.bottom-F.top,c.width=F.right-F.left,f({canvas:i,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:i,initialFace:r}=t.ovalAssociatedParams,s=yield o.detectFaces(a);let n,c,d,l=0;const v=g(r,i),{ovalBoundingBox:h}=u(i),f=S(v,h);switch(s.length){case 0:n=D.CANT_IDENTIFY,d=m(a);break;case 1:{c=s[0];const{faceMatchState:t,faceMatchPercentage:a}=p(c,i,f,e);n=t,l=a;break}default:n=D.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:i,ovalDetails:r}=t.ovalAssociatedParams,{startFace:n,endFace:c}=t.faceMatchAssociatedParams,{width:d,height:l}=o.getTracks()[0].getSettings(),v=d-i.left-i.width;yield a.stopVideo();const m={Challenge:{FaceMovementAndLightChallenge:{ChallengeId:e,InitialFace:{InitialFaceDetectedTimestamp:i.timestampMs,BoundingBox:s({deviceHeight:l,deviceWidth:d,height:i.height,width:i.width,top:i.top,left:v})},TargetFace:{FaceDetectedInTargetPositionStartTimestamp:n.timestampMs,FaceDetectedInTargetPositionEndTimestamp:c.timestampMs,BoundingBox:s({deviceHeight:l,deviceWidth:d,height:r.height,width:r.width,top:r.centerY-r.height/2,left:r.centerX-r.width/2})},VideoEndTimestamp:a.videoRecorder.recorderEndTimestamp}}};a.sendClientInfo(m),yield a.dispatchStopVideoEvent()}))},getLiveness(t){return e(this,void 0,void 0,(function*(){const{livenessStreamProvider:e}=t,{onAnalysisComplete:a}=t.componentProps;e.endStream(),yield a()}))}}}),_=a=>e(void 0,void 0,void 0,(function*(){var e,o,i,r;try{const d=yield B;try{for(var s,n=!0,c=t(d);!(e=(s=yield c.next()).done);){r=s.value,n=!1;try{const e=r;P(e)?a({type:"SET_SESSION_INFO",data:{sessionInfo:e.ServerSessionInformationEvent.SessionInformation}}):T(e)?a({type:"DISCONNECT_EVENT"}):O(e)?a({type:"SERVER_ERROR",data:{error:Object.assign({},e.ValidationException)}}):I(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||!(i=c.return)||(yield i.call(c))}finally{if(o)throw o.error}}}catch(e){let t=e;b(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 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";const b=500;let k;const B=a({id:"livenessMachine",initial:"start",predictableActionArguments:!0,context:{challengeId:R(),maxFailedAttempts:0,failedAttempts:0,componentProps:void 0,serverSessionInformation:void 0,videoAssociatedParams:void 0,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","setVideoConstraints","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(j)}),updateFailedAttempts:o({failedAttempts:e=>e.failedAttempts+1}),setVideoConstraints:o({videoAssociatedParams:(e,t)=>{var a,o;return Object.assign(Object.assign({},e.videoAssociatedParams),{videoConstraints:(null===(a=t.data)||void 0===a?void 0:a.videoConstraints)||(null===(o=e.videoAssociatedParams)||void 0===o?void 0:o.videoConstraints)})}}),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: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)||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=>{},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 k=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=m({sessionInformation:e,videoWidth:o.width}),D=h(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 m=h(i,r),{ovalBoundingBox:g}=f(r),p=u(m,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 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()}))}}}),j=a=>e(void 0,void 0,void 0,(function*(){var e,o,r,i;try{const d=yield k;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{b as MIN_FACE_MATCH_TIME,B as livenessMachine};
@@ -1 +1 @@
1
- var R;!function(R){R.TIMEOUT="TIMEOUT",R.RUNTIME_ERROR="RUNTIME_ERROR",R.FRESHNESS_TIMEOUT="FRESHNESS_TIMEOUT",R.SERVER_ERROR="SERVER_ERROR",R.CAMERA_FRAMERATE_ERROR="CAMERA_FRAMERATE_ERROR",R.CAMERA_ACCESS_ERROR="CAMERA_ACCESS_ERROR",R.FACE_DISTANCE_ERROR="FACE_DISTANCE_ERROR",R.MOBILE_LANDSCAPE_ERROR="MOBILE_LANDSCAPE_ERROR"}(R||(R={}));export{R as LivenessErrorState};
1
+ var R;!function(R){R.TIMEOUT="TIMEOUT",R.RUNTIME_ERROR="RUNTIME_ERROR",R.FRESHNESS_TIMEOUT="FRESHNESS_TIMEOUT",R.SERVER_ERROR="SERVER_ERROR",R.CAMERA_FRAMERATE_ERROR="CAMERA_FRAMERATE_ERROR",R.CAMERA_ACCESS_ERROR="CAMERA_ACCESS_ERROR",R.FACE_DISTANCE_ERROR="FACE_DISTANCE_ERROR",R.MOBILE_LANDSCAPE_ERROR="MOBILE_LANDSCAPE_ERROR",R.MULTIPLE_FACES_ERROR="MULTIPLE_FACES_ERROR"}(R||(R={}));export{R as LivenessErrorState};
@@ -1 +1 @@
1
- import{__awaiter as t}from"tslib";import*as e from"@tensorflow/tfjs-core";import*as o from"@tensorflow-models/blazeface";import*as s from"@tensorflow/tfjs-backend-wasm";import"@tensorflow/tfjs-backend-cpu";import{jitteredExponentialRetry as a}from"@aws-amplify/core";import{isWebAssemblySupported as r}from"./support.mjs";import{FaceDetection as i}from"../types/faceDetection.mjs";import"../types/liveness.mjs";import"../types/error.mjs";class n extends i{constructor(t,e){super(),this.faceModelUrl=e,this.binaryPath=null!=t?t:`https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-backend-wasm@${s.version_wasm}/dist/`}loadModels(){return t(this,void 0,void 0,(function*(){r()?yield this._loadWebAssemblyBackend():yield this._loadCPUBackend();try{yield e.ready(),this._model=yield a(o.load,[{modelUrl:this.faceModelUrl}])}catch(t){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(e){return t(this,void 0,void 0,(function*(){const t=yield this._model.estimateFaces(e,!1,!0,!0),o=Date.now();return t.filter((t=>!!t.landmarks)).map((t=>{const{topLeft:e,bottomRight:s,probability:a,landmarks:r}=t,[i,n]=e,[l,d]=s,m=Math.abs(i-l),c=Math.abs(d-n),f=r[0],h=r[1],u=r[2],p=r[3];return{top:n,left:l,width:m,height:c,timestampMs:o,probability:a[0],rightEye:f,leftEye:h,mouth:p,nose:u}}))}))}_loadWebAssemblyBackend(){return t(this,void 0,void 0,(function*(){try{s.setWasmPaths(this.binaryPath),yield a((()=>t(this,void 0,void 0,(function*(){if(!(yield e.setBackend("wasm")))throw new Error("Initialization of backend wasm failed")}))),[]),this.modelBackend="wasm"}catch(t){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 t(this,void 0,void 0,(function*(){yield e.setBackend("cpu"),this.modelBackend="cpu"}))}}export{n as BlazeFaceFaceDetection};
1
+ import{__awaiter as e}from"tslib";import*as t from"@tensorflow/tfjs-core";import*as o from"@tensorflow-models/blazeface";import*as s from"@tensorflow/tfjs-backend-wasm";import"@tensorflow/tfjs-backend-cpu";import{jitteredExponentialRetry as a}from"@aws-amplify/core";import{isWebAssemblySupported as i}from"./support.mjs";import{FaceDetection as r}from"../types/faceDetection.mjs";import"../types/liveness.mjs";import"../types/error.mjs";const n="0.0.7",l=`https://cdn.liveness.rekognition.amazonaws.com/face-detection/tensorflow-models/blazeface/${n}/model/model.json`,d=`https://cdn.liveness.rekognition.amazonaws.com/face-detection/tensorflow/tfjs-backend-wasm/${s.version_wasm}/`;class m extends r{constructor(e,t){super(),this.faceModelUrl=null!=t?t:l,this.binaryPath=null!=e?e:d}loadModels(){return e(this,void 0,void 0,(function*(){i()?yield this._loadWebAssemblyBackend():yield this._loadCPUBackend();try{yield t.ready(),this._model=yield a(o.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(this,void 0,void 0,(function*(){const e=yield this._model.estimateFaces(t,!1,!0,!0),o=Date.now();return e.filter((e=>!!e.landmarks)).map((e=>{const{topLeft:t,bottomRight:s,probability:a,landmarks:i}=e,[r,n]=t,[l,d]=s,m=Math.abs(r-l),c=Math.abs(d-n),f=i[0],h=i[1],u=i[2],p=i[3];return{top:n,left:l,width:m,height:c,timestampMs:o,probability:a[0],rightEye:f,leftEye:h,mouth:p,nose:u}}))}))}_loadWebAssemblyBackend(){return e(this,void 0,void 0,(function*(){try{s.setWasmPaths(this.binaryPath),yield a((()=>e(this,void 0,void 0,(function*(){if(!(yield t.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(this,void 0,void 0,(function*(){yield t.setBackend("cpu"),this.modelBackend="cpu"}))}}export{n as BLAZEFACE_VERSION,m as BlazeFaceFaceDetection,l as DEFAULT_BLAZEFACE_URL,d as DEFAULT_TFJS_WASM_URL};
@@ -1 +1 @@
1
- import{__awaiter as t}from"tslib";import{FaceMatchState as e,IlluminationState as o}from"../types/liveness.mjs";import{LivenessErrorState as n}from"../types/error.mjs";import{FACE_DISTANCE_THRESHOLD as i,REDUCED_THRESHOLD_MOBILE as r,REDUCED_THRESHOLD as a}from"./constants.mjs";function h(t,e,o){return t*(o-e)+e}function l(t){const e=t.flippedCenterX-t.width/2,o=t.flippedCenterX+t.width/2,n=t.centerY-t.height/2,i=t.centerY+t.height/2;return{ovalBoundingBox:{left:e,top:n,right:o,bottom:i},minOvalX:e,maxOvalX:o,minOvalY:n,maxOvalY:i}}function c(t,e){const o=Math.max(t.left,e.left),n=Math.max(t.top,e.top),i=Math.min(t.right,e.right),r=Math.min(t.bottom,e.bottom),a=Math.abs(Math.max(0,i-o)*Math.max(0,r-n));if(0===a)return 0;return a/(Math.abs((t.right-t.left)*(t.bottom-t.top))+Math.abs((e.right-e.left)*(e.bottom-e.top))-a)}function s({sessionInformation:t,videoWidth:e}){var o,n;const i=null===(n=null===(o=null==t?void 0:t.Challenge)||void 0===o?void 0:o.FaceMovementAndLightChallenge)||void 0===n?void 0:n.OvalParameters;if(!(i&&i.CenterX&&i.CenterY&&i.Width&&i.Height))throw new Error("Oval parameters not returned from session information.");return{flippedCenterX:e-i.CenterX,centerX:i.CenterX,centerY:i.CenterY,width:i.Width,height:i.Height}}function d({width:t,height:e,widthSeed:o=1,centerXSeed:n=.5,centerYSeed:i=.5}){const r=e;let a=t;const l=.8*o,c=Math.floor(7*t/16),s=Math.floor(9*t/16),d=Math.floor(7*e/16),f=Math.floor(9*e/16),g=h(n,c,s),u=h(i,d,f);t>=e&&(a=3/4*r);const v=l*a,R=1.618*v;return{flippedCenterX:Math.floor(a-g),centerX:Math.floor(g),centerY:Math.floor(u),width:Math.floor(v),height:Math.floor(R)}}function f({canvas:t,oval:e,scaleFactor:o,videoEl:n}){const{flippedCenterX:i,centerY:r,width:a,height:h}=e,{width:l,height:c}=t.getBoundingClientRect(),s=t.getContext("2d");if(!s)throw new Error("Cannot find Canvas.");{s.clearRect(0,0,l,c),s.fillStyle="rgba(255, 255, 255, 1.0)",s.fillRect(0,0,l,c);const t={width:n.videoWidth,height:n.videoHeight},e={x:(l-t.width*o)/2,y:(c-t.height*o)/2};s.setTransform(o,0,0,o,e.x,e.y),s.beginPath(),s.ellipse(i,r,a/2,h/2,0,0,2*Math.PI),s.strokeStyle="#AEB3B7",s.lineWidth=3,s.stroke(),s.clip(),s.setTransform(1,0,0,1,0,0),s.clearRect(0,0,l,c)}}function g(t,o,n,i){var r,a;let h;const s=null===(a=null===(r=null==i?void 0:i.Challenge)||void 0===r?void 0:r.FaceMovementAndLightChallenge)||void 0===a?void 0:a.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:d,OvalIouHeightThreshold:f,OvalIouWidthThreshold:g,FaceIouHeightThreshold:u,FaceIouWidthThreshold:R}=s,E=v(t,o),C=E.left,p=E.right,m=E.top,M=E.bottom,{ovalBoundingBox:w,minOvalX:O,minOvalY:A,maxOvalX:T,maxOvalY:I}=l(o),x=c(E,w),b=d,S=o.width*g,_=o.height*f,F=o.width*R,D=o.height*u,y=100*Math.max(Math.min(1,.75*(x-n)/(b-n)+.25),0);return h=x>b&&Math.abs(O-C)<S&&Math.abs(T-p)<S&&Math.abs(I-M)<_?e.MATCHED:A-m>D||M-I>D||O-C>F&&p-T>F?e.TOO_CLOSE:e.TOO_FAR,{faceMatchState:h,faceMatchPercentage:y}}function u(t){const{leftEye:e,rightEye:o,mouth:n}=t,i=[];i[0]=(e[0]+o[0])/2,i[1]=(e[1]+o[1])/2;return{pupilDistance:Math.sqrt(Math.pow(e[0]-o[0],2)+Math.pow(e[1]-o[1],2)),faceHeight:Math.sqrt(Math.pow(i[0]-n[0],2)+Math.pow(i[1]-n[1],2))}}function v(t,e){const{leftEye:o,rightEye:n,nose:i}=t,{height:r,centerY:a}=e,h=a-r/2,l=[];l[0]=(o[0]+n[0])/2,l[1]=(o[1]+n[1])/2;const{pupilDistance:c,faceHeight:s}=u(t),d=(2*c+1.8*s)/2,f=1.618*d;let g,v;l[1]<=(h+r)/2?(g=(l[0]+i[0])/2,v=(l[1]+i[1])/2):(g=l[0],v=l[1]);const R=g-d/2,E=v-f/2;return{left:R,top:E,right:R+d,bottom:E+f}}function R(t){const e=document.createElement("canvas");e.width=t.videoWidth,e.height=t.videoHeight;const n=e.getContext("2d");if(n){n.drawImage(t,0,0,e.width,e.height);const i=n.getImageData(0,0,e.width,e.height).data,r=8,a=new Array(r).fill(0);for(let t=0;t<i.length;t++){a[Math.round(.2126*i[t++]+.7152*i[t++]+.0722*i[t++])%32]++}let h=-1,l=0;for(let t=0;t<r;t++)a[t]>l&&(l=a[t],h=t);return e.remove(),0===h?o.DARK:h===r?o.BRIGHT:o.NORMAL}throw new Error("Cannot find Video Element.")}function E(t){return t.label.toLowerCase().includes("virtual")}const C={[n.RUNTIME_ERROR]:"RUNTIME_ERROR",[n.SERVER_ERROR]:"SERVER_ERROR",[n.TIMEOUT]:"TIMEOUT",[n.FACE_DISTANCE_ERROR]:"FACE_DISTANCE_ERROR",[n.CAMERA_FRAMERATE_ERROR]:"CAMERA_FRAMERATE_ERROR",[n.CAMERA_ACCESS_ERROR]:"CAMERA_ACCESS_ERROR",[n.MOBILE_LANDSCAPE_ERROR]:"MOBILE_LANDSCAPE_ERROR",[n.FRESHNESS_TIMEOUT]:"FRESHNESS_TIMEOUT"};function p({ctx:t,prevColor:e,nextColor:o,fraction:n}){const i=t.canvas.width,r=t.canvas.height;t.fillStyle=o,t.fillRect(0,0,i,r*n),1!==n&&(t.fillStyle=e,t.fillRect(0,r*n,i,r*(1-n)))}function m({overlayCanvas:t,prevColor:e,nextColor:o,videoEl:n,ovalDetails:i,heightFraction:r,scaleFactor:a}){const{x:h,y:l}=n.getBoundingClientRect(),{flippedCenterX:c,centerY:s,width:d,height:f}=i,g=c*a+h,u=s*a+l,v=t.width,R=t.height,E=t.getContext("2d");if(!E)throw new Error("Cannot find Overlay Canvas.");E.canvas.width=window.innerWidth,E.canvas.height=window.innerHeight,E.clearRect(0,0,v,R),p({ctx:E,prevColor:e,nextColor:o,fraction:r}),E.save(),E.beginPath(),E.rect(0,0,v,R),E.clip(),E.clearRect(0,0,v,R),E.globalAlpha=.9,p({ctx:E,prevColor:e,nextColor:o,fraction:r}),E.beginPath(),E.ellipse(g,u,d*a/2,f*a/2,0,0,2*Math.PI),E.strokeStyle="white",E.lineWidth=8,E.stroke(),E.clip(),E.clearRect(0,0,v,R),E.globalAlpha=.75,p({ctx:E,prevColor:e,nextColor:o,fraction:r}),E.restore()}const M=t=>!!t;function w(t){return(t.Challenge.FaceMovementAndLightChallenge.ColorSequences||[]).map((({FreshnessColor:t,DownscrollDuration:e,FlatDisplayDuration:o})=>{const n=t.RGB,i=`rgb(${n[0]},${n[1]},${n[2]})`;return void 0!==i&&void 0!==e&&void 0!==o?{color:i,downscrollDuration:e,flatDisplayDuration:o}:void 0})).filter(M)}function O(t){return t.slice(t.indexOf("(")+1,t.indexOf(")")).split(",").map((t=>parseInt(t)))}function A(o,n){return t(this,void 0,void 0,(function*(){let t;switch((yield o.detectFaces(n)).length){case 0:t=e.CANT_IDENTIFY;break;case 1:t=e.FACE_IDENTIFIED;break;default:t=e.TOO_MANY}return t}))}function T({faceDetector:e,videoEl:o,ovalDetails:n,reduceThreshold:h=!1,isMobile:l=!1}){return t(this,void 0,void 0,(function*(){const t=yield e.detectFaces(o);let c,s=!1;switch(t.length){case 0:break;case 1:{c=t[0];const e=n.width,{pupilDistance:o,faceHeight:d}=u(c),f=2;e&&(s=(f*o+1.8*d)/2/f/e<(h?l?r:a:i));break}}return s}))}function I({deviceHeight:t,deviceWidth:e,height:o,width:n,top:i,left:r}){return{Height:o/t,Width:n/e,Top:i/t,Left:r/e}}export{C as LivenessErrorStateStringMap,f as drawLivenessOvalInCanvas,R as estimateIllumination,m as fillOverlayCanvasFractional,v as generateBboxFromLandmarks,I as getBoundingBox,w as getColorsSequencesFromSessionInformation,A as getFaceMatchState,g as getFaceMatchStateInLivenessOval,c as getIntersectionOverUnion,l as getOvalBoundingBox,s as getOvalDetailsFromSessionInformation,O as getRGBArrayFromColorString,d as getStaticLivenessOvalDetails,E as isCameraDeviceVirtual,M as isClientFreshnessColorSequence,T as isFaceDistanceBelowThreshold};
1
+ import{__awaiter as t}from"tslib";import{FaceMatchState as e,IlluminationState as o}from"../types/liveness.mjs";import{LivenessErrorState as n}from"../types/error.mjs";import{FACE_DISTANCE_THRESHOLD as i,REDUCED_THRESHOLD_MOBILE as r,REDUCED_THRESHOLD as a}from"./constants.mjs";function h(t,e,o){return t*(o-e)+e}function l(t){const e=t.flippedCenterX-t.width/2,o=t.flippedCenterX+t.width/2,n=t.centerY-t.height/2,i=t.centerY+t.height/2;return{ovalBoundingBox:{left:e,top:n,right:o,bottom:i},minOvalX:e,maxOvalX:o,minOvalY:n,maxOvalY:i}}function c(t,e){const o=Math.max(t.left,e.left),n=Math.max(t.top,e.top),i=Math.min(t.right,e.right),r=Math.min(t.bottom,e.bottom),a=Math.abs(Math.max(0,i-o)*Math.max(0,r-n));if(0===a)return 0;return a/(Math.abs((t.right-t.left)*(t.bottom-t.top))+Math.abs((e.right-e.left)*(e.bottom-e.top))-a)}function s({sessionInformation:t,videoWidth:e}){var o,n;const i=null===(n=null===(o=null==t?void 0:t.Challenge)||void 0===o?void 0:o.FaceMovementAndLightChallenge)||void 0===n?void 0:n.OvalParameters;if(!(i&&i.CenterX&&i.CenterY&&i.Width&&i.Height))throw new Error("Oval parameters not returned from session information.");return{flippedCenterX:e-i.CenterX,centerX:i.CenterX,centerY:i.CenterY,width:i.Width,height:i.Height}}function d({width:t,height:e,widthSeed:o=1,centerXSeed:n=.5,centerYSeed:i=.5}){const r=e;let a=t;const l=.8*o,c=Math.floor(7*t/16),s=Math.floor(9*t/16),d=Math.floor(7*e/16),f=Math.floor(9*e/16),g=h(n,c,s),u=h(i,d,f);t>=e&&(a=3/4*r);const v=l*a,C=1.618*v;return{flippedCenterX:Math.floor(a-g),centerX:Math.floor(g),centerY:Math.floor(u),width:Math.floor(v),height:Math.floor(C)}}function f({canvas:t,oval:e,scaleFactor:o,videoEl:n}){const{flippedCenterX:i,centerY:r,width:a,height:h}=e,{width:l,height:c}=t.getBoundingClientRect(),s=t.getContext("2d");if(!s)throw new Error("Cannot find Canvas.");{s.clearRect(0,0,l,c),s.fillStyle="rgba(255, 255, 255, 1.0)",s.fillRect(0,0,l,c);const t={width:n.videoWidth,height:n.videoHeight},e={x:(l-t.width*o)/2,y:(c-t.height*o)/2};s.setTransform(o,0,0,o,e.x,e.y),s.beginPath(),s.ellipse(i,r,a/2,h/2,0,0,2*Math.PI),s.strokeStyle="#AEB3B7",s.lineWidth=3,s.stroke(),s.clip(),s.setTransform(1,0,0,1,0,0),s.clearRect(0,0,l,c)}}function g(t,o,n,i){var r,a;let h;const s=null===(a=null===(r=null==i?void 0:i.Challenge)||void 0===r?void 0:r.FaceMovementAndLightChallenge)||void 0===a?void 0:a.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:d,OvalIouHeightThreshold:f,OvalIouWidthThreshold:g,FaceIouHeightThreshold:u,FaceIouWidthThreshold:C}=s,p=v(t,o),m=p.left,E=p.right,R=p.top,M=p.bottom,{ovalBoundingBox:w,minOvalX:O,minOvalY:T,maxOvalX:A,maxOvalY:I}=l(o),x=c(p,w),b=d,F=o.width*g,D=o.height*f,_=o.width*C,S=o.height*u,y=100*Math.max(Math.min(1,.75*(x-n)/(b-n)+.25),0);return h=x>b&&Math.abs(O-m)<F&&Math.abs(A-E)<F&&Math.abs(I-M)<D?e.MATCHED:T-R>S||M-I>S||O-m>_&&E-A>_?e.TOO_CLOSE:e.TOO_FAR,{faceMatchState:h,faceMatchPercentage:y}}function u(t){const{leftEye:e,rightEye:o,mouth:n}=t,i=[];i[0]=(e[0]+o[0])/2,i[1]=(e[1]+o[1])/2;return{pupilDistance:Math.sqrt(Math.pow(e[0]-o[0],2)+Math.pow(e[1]-o[1],2)),faceHeight:Math.sqrt(Math.pow(i[0]-n[0],2)+Math.pow(i[1]-n[1],2))}}function v(t,e){const{leftEye:o,rightEye:n,nose:i}=t,{height:r,centerY:a}=e,h=a-r/2,l=[];l[0]=(o[0]+n[0])/2,l[1]=(o[1]+n[1])/2;const{pupilDistance:c,faceHeight:s}=u(t),d=(2*c+1.8*s)/2,f=1.618*d;let g,v;l[1]<=(h+r)/2?(g=(l[0]+i[0])/2,v=(l[1]+i[1])/2):(g=l[0],v=l[1]);const C=g-d/2,p=v-f/2;return{left:C,top:p,right:C+d,bottom:p+f}}function C(t){const e=document.createElement("canvas");e.width=t.videoWidth,e.height=t.videoHeight;const n=e.getContext("2d");if(n){n.drawImage(t,0,0,e.width,e.height);const i=n.getImageData(0,0,e.width,e.height).data,r=8,a=new Array(r).fill(0);for(let t=0;t<i.length;t++){a[Math.round(.2126*i[t++]+.7152*i[t++]+.0722*i[t++])%32]++}let h=-1,l=0;for(let t=0;t<r;t++)a[t]>l&&(l=a[t],h=t);return e.remove(),0===h?o.DARK:h===r?o.BRIGHT:o.NORMAL}throw new Error("Cannot find Video Element.")}function p(t){return t.label.toLowerCase().includes("virtual")}n.RUNTIME_ERROR,n.SERVER_ERROR,n.TIMEOUT,n.FACE_DISTANCE_ERROR,n.MULTIPLE_FACES_ERROR,n.CAMERA_FRAMERATE_ERROR,n.CAMERA_ACCESS_ERROR,n.MOBILE_LANDSCAPE_ERROR,n.FRESHNESS_TIMEOUT;function m({ctx:t,prevColor:e,nextColor:o,fraction:n}){const i=t.canvas.width,r=t.canvas.height;t.fillStyle=o,t.fillRect(0,0,i,r*n),1!==n&&(t.fillStyle=e,t.fillRect(0,r*n,i,r*(1-n)))}function E({overlayCanvas:t,prevColor:e,nextColor:o,videoEl:n,ovalDetails:i,heightFraction:r,scaleFactor:a}){const{x:h,y:l}=n.getBoundingClientRect(),{flippedCenterX:c,centerY:s,width:d,height:f}=i,g=c*a+h,u=s*a+l,v=t.width,C=t.height,p=t.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,C),m({ctx:p,prevColor:e,nextColor:o,fraction:r}),p.save(),p.beginPath(),p.rect(0,0,v,C),p.clip(),p.clearRect(0,0,v,C),p.globalAlpha=.9,m({ctx:p,prevColor:e,nextColor:o,fraction:r}),p.beginPath(),p.ellipse(g,u,d*a/2,f*a/2,0,0,2*Math.PI),p.strokeStyle="white",p.lineWidth=8,p.stroke(),p.clip(),p.clearRect(0,0,v,C),p.globalAlpha=.75,m({ctx:p,prevColor:e,nextColor:o,fraction:r}),p.restore()}const R=t=>!!t;function M(t){return(t.Challenge.FaceMovementAndLightChallenge.ColorSequences||[]).map((({FreshnessColor:t,DownscrollDuration:e,FlatDisplayDuration:o})=>{const n=t.RGB,i=`rgb(${n[0]},${n[1]},${n[2]})`;return void 0!==i&&void 0!==e&&void 0!==o?{color:i,downscrollDuration:e,flatDisplayDuration:o}:void 0})).filter(R)}function w(t){return t.slice(t.indexOf("(")+1,t.indexOf(")")).split(",").map((t=>parseInt(t)))}function O(o,n){return t(this,void 0,void 0,(function*(){let t;switch((yield o.detectFaces(n)).length){case 0:t=e.CANT_IDENTIFY;break;case 1:t=e.FACE_IDENTIFIED;break;default:t=e.TOO_MANY}return t}))}function T({faceDetector:e,videoEl:o,ovalDetails:h,reduceThreshold:l=!1,isMobile:c=!1}){return t(this,void 0,void 0,(function*(){const t=yield e.detectFaces(o);let s,d,f=!1;switch(t.length){case 0:d=n.FACE_DISTANCE_ERROR;break;case 1:{s=t[0];const e=h.width,{pupilDistance:o,faceHeight:g}=u(s),v=2;e&&(f=(v*o+1.8*g)/2/v/e<(l?c?r:a:i),f||(d=n.FACE_DISTANCE_ERROR));break}default:d=n.MULTIPLE_FACES_ERROR}return{isDistanceBelowThreshold:f,error:d}}))}function A({deviceHeight:t,deviceWidth:e,height:o,width:n,top:i,left:r}){return{Height:o/t,Width:n/e,Top:i/t,Left:r/e}}export{f as drawLivenessOvalInCanvas,C as estimateIllumination,E as fillOverlayCanvasFractional,v as generateBboxFromLandmarks,A as getBoundingBox,M as getColorsSequencesFromSessionInformation,O as getFaceMatchState,g as getFaceMatchStateInLivenessOval,c as getIntersectionOverUnion,l as getOvalBoundingBox,s as getOvalDetailsFromSessionInformation,w as getRGBArrayFromColorString,d as getStaticLivenessOvalDetails,p as isCameraDeviceVirtual,R as isClientFreshnessColorSequence,T as isFaceDistanceBelowThreshold};
@@ -1 +1 @@
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{WebSocketFetchHandler as a}from"@aws-sdk/middleware-websocket";import{VideoRecorder as l}from"./videoRecorder.mjs";import{getLivenessUserAgent as h}from"../../utils/platform.mjs";const c=process.env.NEXT_PUBLIC_STREAMING_API_URL,m=1e3;function v(e){return void 0!==e.Challenge}class u extends r{constructor(e,i,t,o){super(),this.sessionId=e,this.region=i,this._stream=t,this.videoEl=o,this.videoRecorder=new l(t),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"))}endStream(){return e(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(){return e(this,void 0,void 0,(function*(){const e=yield o.get();if(!e)throw new Error("No credentials");const i={credentials:e,region:this.region,customUserAgent:`${n()} ${h}`,requestHandler:new a({connectionTimeout:1e4})};c&&(i.endpointProvider=()=>({url:new URL(c)})),this._client=new s(i),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 v(i)&&(yield yield t({ClientSessionInformationEvent:{Challenge:i.Challenge}}))}}))}}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{u as LivenessStreamProvider,m as TIME_SLICE};
1
+ import{__awaiter as e,__asyncGenerator as i,__await as t}from"tslib";import{Credentials as o,getAmplifyUserAgent as r}from"@aws-amplify/core";import{AmazonAIInterpretPredictionsProvider as n}from"@aws-amplify/predictions";import{RekognitionStreamingClient as s,StartFaceLivenessSessionCommand as d}from"@aws-sdk/client-rekognitionstreaming";import{WebSocketFetchHandler as a}from"@aws-sdk/middleware-websocket";import{VideoRecorder as l}from"./videoRecorder.mjs";import{getLivenessUserAgent as c}from"../../utils/platform.mjs";const h=process.env.NEXT_PUBLIC_STREAMING_API_URL,v=1e3;function m(e){return void 0!==e.Challenge}class u extends n{constructor({sessionId:e,region:i,stream:t,videoEl:o,credentialProvider:r}){super(),this.sessionId=e,this.region=i,this._stream=t,this.videoEl=o,this.videoRecorder=new l(t),this.credentialProvider=r,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"))}endStream(){return e(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 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:`${r()} ${c()}`,requestHandler:new a({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}}))}}))}}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{u 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)}_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.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 +1 @@
1
- import e from"react";import{View as t,Flex as r,ComponentClassNames as o,Text as a}from"@aws-amplify/ui-react";import"@aws-amplify/ui-react/internal";import"@xstate/react";import"../providers/FaceLivenessDetectorProvider.mjs";import"@aws-amplify/ui";import{LivenessClassNames as i}from"../types/classNames.mjs";import"../service/machine/index.mjs";import"../service/types/liveness.mjs";import"../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{StartScreenFigure as s}from"./StartScreenFigure.mjs";import{GoodFitIllustration as m}from"./GoodFitIllustration.mjs";import{TooFarIllustration as l}from"./TooFarIllustration.mjs";import{LivenessIconWithPopover as n}from"./LivenessIconWithPopover.mjs";const c=({headingText:r,bodyText:o})=>e.createElement(t,{flex:"1"},e.createElement(t,{color:"font.primary",fontWeight:"bold"},r),e.createElement(t,{color:"font.primary"},o)),p=({headingText:a,bodyText:i,infoText:s})=>e.createElement(r,{className:o.Alert,color:"orange.80",backgroundColor:"orange.20",alignItems:"center"},e.createElement(t,{flex:"1"},e.createElement(t,{className:o.AlertHeading},a),e.createElement(t,{className:o.AlertBody},i)),e.createElement(n,null,s)),f=({headingText:t,goodFitCaptionText:o,goodFitAltText:n,tooFarCaptionText:c,tooFarAltText:p,steps:f})=>e.createElement(r,{direction:"column"},e.createElement(a,{color:"font.primary",fontWeight:"bold"},t),e.createElement(r,{className:i.Figures},e.createElement(s,{variation:"success",caption:o},e.createElement(m,{title:n})),e.createElement(s,{variation:"error",caption:c},e.createElement(l,{title:p}))),e.createElement(r,{as:"ol",className:i.InstructionList},f.map(((t,o)=>e.createElement(r,{as:"li",key:o+1},e.createElement(a,{as:"span","aria-hidden":"true"},o+1,"."),e.createElement(a,{as:"span"},t))))));export{c as DefaultHeader,f as DefaultInstructions,p as DefaultPhotosensitiveWarning};
1
+ import e from"react";import{View as t,Flex as r,ComponentClassNames as a,Text as s}from"@aws-amplify/ui-react";import"@aws-amplify/ui-react/internal";import"@xstate/react";import"../providers/FaceLivenessDetectorProvider.mjs";import"@aws-amplify/ui";import{LivenessClassNames as i}from"../types/classNames.mjs";import"../service/machine/index.mjs";import"../service/types/liveness.mjs";import"../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{StartScreenFigure as o}from"./StartScreenFigure.mjs";import{GoodFitIllustration as m}from"./GoodFitIllustration.mjs";import{TooFarIllustration as n}from"./TooFarIllustration.mjs";import{LivenessIconWithPopover as l}from"./LivenessIconWithPopover.mjs";const c=({headingText:r,bodyText:a})=>e.createElement(t,{className:i.StartScreenHeader},e.createElement(t,{className:i.StartScreenHeaderHeading},r),e.createElement(t,{className:i.StartScreenHeaderBody},a)),p=({headingText:s,bodyText:o,infoText:m})=>e.createElement(r,{className:`${a.Alert} ${i.StartScreenWarning}`},e.createElement(t,{flex:"1"},e.createElement(t,{className:a.AlertHeading},s),e.createElement(t,{className:a.AlertBody},o)),e.createElement(l,null,m)),d=({headingText:t,goodFitCaptionText:a,goodFitAltText:l,tooFarCaptionText:c,tooFarAltText:p,steps:d})=>e.createElement(r,{direction:"column"},e.createElement(s,{className:i.StartScreenInstructionsHeading},t),e.createElement(r,{className:i.Figures},e.createElement(o,{variation:"success",caption:a},e.createElement(m,{title:l})),e.createElement(o,{variation:"error",caption:c},e.createElement(n,{title:p}))),e.createElement(r,{as:"ol",className:i.InstructionList},d.map(((t,a)=>e.createElement(r,{as:"li",key:a+1},e.createElement(s,{as:"span","aria-hidden":"true"},a+1,"."),e.createElement(s,{as:"span"},t))))));export{c as DefaultHeader,d as DefaultInstructions,p as DefaultPhotosensitiveWarning};
@@ -1 +1 @@
1
- import e from"react";import{Flex as t,Text as r,Button as s}from"@aws-amplify/ui-react";import{AlertIcon as a}from"@aws-amplify/ui-react/internal";import"../service/machine/index.mjs";import"../service/types/liveness.mjs";import{LivenessErrorState as i}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{Toast as o}from"./Toast.mjs";import{Overlay as n}from"./Overlay.mjs";import{defaultErrorDisplayText as m}from"../displayText.mjs";const c=({errorState:s,overrideErrorDisplayText:o})=>{const n=Object.assign(Object.assign({},m),o);return s===i.CAMERA_ACCESS_ERROR||s===i.CAMERA_FRAMERATE_ERROR||s===i.MOBILE_LANDSCAPE_ERROR?null:(s=>{const{error:o,displayText:n}=s,{timeoutHeaderText:m,timeoutMessageText:c,faceDistanceHeaderText:l,faceDistanceMessageText:p,clientHeaderText:E,clientMessageText:f,serverHeaderText:R,serverMessageText:d}=n;let T,u;switch(o){case i.TIMEOUT:T=m,u=c;break;case i.FACE_DISTANCE_ERROR:T=l,u=p;break;case i.RUNTIME_ERROR:T=E,u=f;break;case i.SERVER_ERROR:default:T=R,u=d}return e.createElement(e.Fragment,null,e.createElement(t,{gap:"xs",alignItems:"center",justifyContent:"center",color:"font.error"},e.createElement(a,{ariaHidden:!0,variation:"error"}),e.createElement(r,{fontWeight:"bold"},T)),u)})({error:s,displayText:n})},l=r=>{const{children:a,onRetry:i,displayText:c}=r,l=Object.assign(Object.assign({},m),c),{tryAgainText:p}=l;return e.createElement(n,{backgroundColor:"overlay.40"},e.createElement(o,null,a,e.createElement(t,{justifyContent:"center"},e.createElement(s,{variation:"primary",type:"button",onClick:i},p))))};export{l as FaceLivenessErrorModal,c as renderErrorModal};
1
+ import e from"react";import{Flex as r,Text as t,Button as s}from"@aws-amplify/ui-react";import{AlertIcon as a}from"@aws-amplify/ui-react/internal";import"../service/machine/index.mjs";import"../service/types/liveness.mjs";import{LivenessErrorState as i}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{Toast as o}from"./Toast.mjs";import{Overlay as m}from"./Overlay.mjs";import{defaultErrorDisplayText as l}from"../displayText.mjs";import{LivenessClassNames as c}from"../types/classNames.mjs";const n=({errorState:s,overrideErrorDisplayText:o})=>{const m=Object.assign(Object.assign({},l),o);return s===i.CAMERA_ACCESS_ERROR||s===i.CAMERA_FRAMERATE_ERROR||s===i.MOBILE_LANDSCAPE_ERROR?null:(s=>{const{error:o,displayText:m}=s,{timeoutHeaderText:l,timeoutMessageText:n,faceDistanceHeaderText:p,faceDistanceMessageText:E,multipleFacesHeaderText:R,multipleFacesMessageText:f,clientHeaderText:T,clientMessageText:d,serverHeaderText:u,serverMessageText:y}=m;let j,x;switch(o){case i.TIMEOUT:j=l,x=n;break;case i.FACE_DISTANCE_ERROR:j=p,x=E;break;case i.MULTIPLE_FACES_ERROR:j=R,x=f;break;case i.RUNTIME_ERROR:j=T,x=d;break;case i.SERVER_ERROR:default:j=u,x=y}return e.createElement(e.Fragment,null,e.createElement(r,{className:c.ErrorModal},e.createElement(a,{ariaHidden:!0,variation:"error"}),e.createElement(t,{className:c.ErrorModalHeading},j)),x)})({error:s,displayText:m})},p=t=>{const{children:a,onRetry:i,displayText:n}=t,p=Object.assign(Object.assign({},l),n),{tryAgainText:E}=p;return e.createElement(m,{className:c.OpaqueOverlay},e.createElement(o,null,a,e.createElement(r,{justifyContent:"center"},e.createElement(s,{variation:"primary",type:"button",onClick:i},E))))};export{p as FaceLivenessErrorModal,n as renderErrorModal};
@@ -1 +1 @@
1
- import*as e from"react";import{Flex as t,Loader as r,View as o}from"@aws-amplify/ui-react";import"../service/machine/index.mjs";import{FaceMatchState as n,IlluminationState as i}from"../service/types/liveness.mjs";import"../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{useLivenessActor as a}from"../hooks/useLivenessActor.mjs";import{createLivenessSelector as s,useLivenessSelector as c}from"../hooks/useLivenessSelector.mjs";import"@aws-amplify/ui";import{Toast as l}from"./Toast.mjs";import{Overlay as m}from"./Overlay.mjs";const h=s((e=>e.context.errorState)),f=s((e=>e.context.faceMatchAssociatedParams.faceMatchState)),u=s((e=>e.context.faceMatchAssociatedParams.illuminationState)),T=s((e=>e.context.isFaceFarEnoughBeforeRecording)),p=s((e=>e.context.faceMatchStateBeforeStart)),E=({hintDisplayText:s})=>{const[E]=a(),x=c(h),O=c(f),d=c(u),F=c(p),g=c(T),v=E.matches("checkFaceDetectedBeforeStart"),C=E.matches("checkFaceDistanceBeforeRecording"),y=E.matches("recording"),j=E.matches("notRecording"),A=E.matches("waitForSessionInfo"),I=E.matches("uploading"),S=E.matches("checkSucceeded"),M=E.matches("checkFailed"),k=E.matches({recording:"flashFreshnessColors"}),w={[n.CANT_IDENTIFY]:s.hintCanNotIdentifyText,[n.FACE_IDENTIFIED]:s.hintTooFarText,[n.TOO_MANY]:s.hintTooManyFacesText,[n.TOO_CLOSE]:s.hintTooCloseText,[n.TOO_FAR]:s.hintTooFarText,[n.MATCHED]:s.hintHoldFaceForFreshnessText},D={[i.BRIGHT]:s.hintIlluminationTooBrightText,[i.DARK]:s.hintIlluminationTooDarkText,[i.NORMAL]:s.hintIlluminationNormalText},_=(()=>{if(!(x||M||S)){if(!y){if(v)return F===n.TOO_MANY?e.createElement(l,null,w[F]):e.createElement(l,null,s.hintMoveFaceFrontOfCameraText);if(C&&!1===g)return e.createElement(l,null,s.hintTooCloseText);if(j)return e.createElement(l,null,s.hintHoldFacePositionCountdownText);if(A)return e.createElement(l,null,e.createElement(t,{alignItems:"center",gap:"xs"},e.createElement(r,null),e.createElement(o,null,s.hintConnectingText)));if(I)return e.createElement(m,{backgroundColor:"overlay.40",anchorOrigin:{horizontal:"center",vertical:"end"}},e.createElement(l,null,e.createElement(t,{alignItems:"center",gap:"xs"},e.createElement(r,null),e.createElement(o,null,s.hintVerifyingText))));if(d&&d!==i.NORMAL)return e.createElement(l,null,D[d])}return k?e.createElement(l,{size:"large",variation:"primary"},s.hintHoldFaceForFreshnessText):y&&!k?e.createElement(l,{size:"large",variation:O===n.TOO_CLOSE?"error":"primary"},O===n.TOO_CLOSE?w[n.TOO_CLOSE]:w[n.TOO_FAR]):null}})();return _||null};export{E as Hint,h as selectErrorState,f as selectFaceMatchState,p as selectFaceMatchStateBeforeStart,u as selectIlluminationState,T as selectIsFaceFarEnoughBeforeRecording};
1
+ import*as e from"react";import{Flex as t,Loader as r,View as o}from"@aws-amplify/ui-react";import"../service/machine/index.mjs";import{FaceMatchState as a,IlluminationState as n}from"../service/types/liveness.mjs";import"../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{useLivenessActor as i}from"../hooks/useLivenessActor.mjs";import{createLivenessSelector as s,useLivenessSelector as c}from"../hooks/useLivenessSelector.mjs";import"@aws-amplify/ui";import{Toast as l}from"./Toast.mjs";import{Overlay as m}from"./Overlay.mjs";import{LivenessClassNames as h}from"../types/classNames.mjs";const f=s((e=>e.context.errorState)),T=s((e=>e.context.faceMatchAssociatedParams.faceMatchState)),u=s((e=>e.context.faceMatchAssociatedParams.illuminationState)),p=s((e=>e.context.isFaceFarEnoughBeforeRecording)),O=s((e=>e.context.faceMatchStateBeforeStart)),E=({hintDisplayText:s})=>{const[E]=i(),x=c(f),F=c(T),d=c(u),v=c(O),y=c(p),j=E.matches("checkFaceDetectedBeforeStart"),C=E.matches("checkFaceDistanceBeforeRecording"),g=E.matches("recording"),A=E.matches("notRecording"),N=E.matches("uploading"),S=E.matches("checkSucceeded"),M=E.matches("checkFailed"),D=E.matches({recording:"flashFreshnessColors"}),I={[a.CANT_IDENTIFY]:s.hintCanNotIdentifyText,[a.FACE_IDENTIFIED]:s.hintTooFarText,[a.TOO_MANY]:s.hintTooManyFacesText,[a.TOO_CLOSE]:s.hintTooCloseText,[a.TOO_FAR]:s.hintTooFarText,[a.MATCHED]:s.hintHoldFaceForFreshnessText},_={[n.BRIGHT]:s.hintIlluminationTooBrightText,[n.DARK]:s.hintIlluminationTooDarkText,[n.NORMAL]:s.hintIlluminationNormalText},k=(()=>{if(!(x||M||S)){if(!g){if(j)return v===a.TOO_MANY?e.createElement(l,null,I[v]):e.createElement(l,null,s.hintMoveFaceFrontOfCameraText);if(C&&!1===y)return e.createElement(l,null,s.hintTooCloseText);if(A)return e.createElement(l,null,e.createElement(t,{className:h.HintText},e.createElement(r,null),e.createElement(o,null,s.hintConnectingText)));if(N)return e.createElement(m,{className:h.OpaqueOverlay,anchorOrigin:{horizontal:"center",vertical:"end"}},e.createElement(l,null,e.createElement(t,{className:h.HintText},e.createElement(r,null),e.createElement(o,null,s.hintVerifyingText))));if(d&&d!==n.NORMAL)return e.createElement(l,null,_[d])}return D?e.createElement(l,{size:"large",variation:"primary"},s.hintHoldFaceForFreshnessText):g&&!D?e.createElement(l,{size:"large",variation:F===a.TOO_CLOSE?"error":"primary"},F===a.TOO_CLOSE?I[a.TOO_CLOSE]:I[a.TOO_FAR]):null}})();return k||null};export{E as Hint,f as selectErrorState,T as selectFaceMatchState,O as selectFaceMatchStateBeforeStart,u as selectIlluminationState,p as selectIsFaceFarEnoughBeforeRecording};
@@ -1 +1 @@
1
- import*as e from"react";import{Flex as t,Text as n,Button as r}from"@aws-amplify/ui-react";import{getLandscapeMediaQuery as a}from"../utils/device.mjs";const o=o=>{const{onRetry:c,header:i,portraitMessage:s,landscapeMessage:m,tryAgainText:l}=o,[u,g]=e.useState(!0);return e.useLayoutEffect((()=>{const e=a();return g(e.matches),e.addEventListener("change",(e=>{g(e.matches)})),()=>{e.removeEventListener("change",(e=>g(e.matches)))}}),[]),e.createElement(t,{backgroundColor:"background.primary",direction:"column",textAlign:"center",alignItems:"center",justifyContent:"center",width:"100%",height:u?"auto":480},e.createElement(n,{fontSize:"large",fontWeight:"bold"},i),e.createElement(n,null,u?m:s),u?null:e.createElement(t,{justifyContent:"center"},e.createElement(r,{variation:"primary",type:"button",onClick:c},l)))};export{o as LandscapeErrorModal};
1
+ import*as e from"react";import{Flex as t,Text as a,Button as r}from"@aws-amplify/ui-react";import{getLandscapeMediaQuery as s}from"../utils/device.mjs";import{LivenessClassNames as n}from"../types/classNames.mjs";const o=o=>{const{onRetry:c,header:m,portraitMessage:l,landscapeMessage:i,tryAgainText:p}=o,[d,u]=e.useState(!0);return e.useLayoutEffect((()=>{const e=s();return u(e.matches),e.addEventListener("change",(e=>{u(e.matches)})),()=>{e.removeEventListener("change",(e=>u(e.matches)))}}),[]),e.createElement(t,{className:n.LandscapeErrorModal,height:d?"auto":480},e.createElement(a,{className:n.LandscapeErrorModalHeader},m),e.createElement(a,null,d?i:l),d?null:e.createElement(t,{className:n.LandscapeErrorModalButton},e.createElement(r,{variation:"primary",type:"button",onClick:c},p)))};export{o as LandscapeErrorModal};
@@ -1 +1 @@
1
- import*as e from"react";import{useTheme as r,Flex as t}from"@aws-amplify/ui-react";import{useThemeBreakpoint as o,AlertIcon as n}from"@aws-amplify/ui-react/internal";const a=({children:a})=>{const{tokens:s}=r(),i=o(),[l,d]=e.useState(!1),p=e.useRef(null),c="base"===i;return e.useEffect((()=>{function e(e){l&&p.current&&!p.current.contains(e.target)&&d(!1)}return document.addEventListener("mousedown",e),()=>{document.removeEventListener("mousedown",e)}}),[p,l]),e.createElement(t,{position:"relative",onClick:()=>d(!l),ref:p,style:{cursor:"pointer"},testId:"popover-icon"},e.createElement(n,{ariaHidden:!0,variation:"info"}),l&&e.createElement(e.Fragment,null,e.createElement(t,{position:"absolute",top:26,left:3,style:{zIndex:3,borderStyle:"solid",borderWidth:"0 9px 9px 9px",borderColor:`transparent transparent ${s.colors.background.primary} transparent`}}),e.createElement(t,{position:"absolute",top:24,left:2,style:{zIndex:2,borderStyle:"solid",borderWidth:"0 10px 10px 10px",borderColor:`transparent transparent ${s.colors.border.secondary} transparent`}}),e.createElement(t,{position:"absolute",backgroundColor:`${s.colors.background.primary}`,color:`${s.colors.font.primary}`,direction:"row",fontSize:s.fontSizes.xs,padding:s.space.small,top:33,minWidth:240,left:c?-190:-108,border:`1px solid ${s.colors.border.secondary}`,borderRadius:2,"data-testid":"popover-text"},a)))};a.displayName="LivenessIconWithPopover";export{a as LivenessIconWithPopover};
1
+ import*as e from"react";import{Flex as t}from"@aws-amplify/ui-react";import{useThemeBreakpoint as r,AlertIcon as o}from"@aws-amplify/ui-react/internal";import{LivenessClassNames as n}from"../types/classNames.mjs";const a=({children:a})=>{const s=r(),[c,m]=e.useState(!1),i=e.useRef(null),l="base"===s;return e.useEffect((()=>{function e(e){c&&i.current&&!i.current.contains(e.target)&&m(!1)}return document.addEventListener("mousedown",e),()=>{document.removeEventListener("mousedown",e)}}),[i,c]),e.createElement(t,{className:n.Popover,onClick:()=>m(!c),ref:i,testId:"popover-icon"},e.createElement(o,{ariaHidden:!0,variation:"info"}),c&&e.createElement(e.Fragment,null,e.createElement(t,{className:n.PopoverAnchor}),e.createElement(t,{className:n.PopoverAnchorSecondary}),e.createElement(t,{className:n.PopoverContainer,left:l?-190:-108,"data-testid":"popover-text"},a)))};a.displayName="LivenessIconWithPopover";export{a as LivenessIconWithPopover};
@@ -1 +1 @@
1
- import{__rest as t}from"tslib";import*as i from"react";import{Flex as r}from"@aws-amplify/ui-react";const e=e=>{var{children:n,anchorOrigin:o={horizontal:"center",vertical:"center"}}=e,a=t(e,["children","anchorOrigin"]);return i.createElement(r,Object.assign({direction:"column",position:"absolute",left:"0",top:"0",alignItems:o.horizontal,justifyContent:o.vertical,width:"100%",height:"100%",padding:"xl"},a),n)};export{e as Overlay};
1
+ import{__rest as r}from"tslib";import*as e from"react";import{Flex as a}from"@aws-amplify/ui-react";import{LivenessClassNames as t}from"../types/classNames.mjs";const i=i=>{var{children:s,anchorOrigin:c={horizontal:"center",vertical:"center"},className:n}=i,o=r(i,["children","anchorOrigin","className"]);return e.createElement(a,Object.assign({className:`${t.Overlay} ${n}`,alignItems:c.horizontal,justifyContent:c.vertical},o),s)};export{i as Overlay};
@@ -1 +1 @@
1
- import{__rest as e}from"tslib";import*as a from"react";import{View as t,Flex as s}from"@aws-amplify/ui-react";import{LivenessClassNames as i}from"../types/classNames.mjs";const m=m=>{var{variation:r="default",size:o="medium",children:l}=m,n=e(m,["variation","size","children"]);return a.createElement(t,Object.assign({padding:"small",borderRadius:"medium",className:`${i.Toast} ${i.Toast}--${r} ${i.Toast}--${o}`,maxWidth:{base:"100%",small:"70%"}},n),a.createElement(s,{gap:"xs",direction:"column",alignItems:"center"},a.createElement(s,{className:`${i.Toast}__message`,textAlign:"center",direction:"column"},l)))};export{m as Toast};
1
+ import{__rest as a}from"tslib";import*as e from"react";import{View as s,Flex as t}from"@aws-amplify/ui-react";import{LivenessClassNames as r}from"../types/classNames.mjs";const m=m=>{var{variation:i="default",size:o="medium",children:l}=m,c=a(m,["variation","size","children"]);return e.createElement(s,Object.assign({className:`${r.Toast} ${r.Toast}--${i} ${r.Toast}--${o}`,maxWidth:{base:"100%",small:"70%"}},c),e.createElement(t,{className:r.ToastContainer},e.createElement(t,{className:r.ToastMessage},l)))};export{m as Toast};
@@ -1 +1 @@
1
- var e;!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.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.Loader="amplify-liveness-loader",e.MatchIndicator="amplify-liveness-match-indicator",e.OvalCanvas="amplify-liveness-oval-canvas",e.RecordingIconContainer="amplify-liveness-recording-icon-container",e.RecordingIcon="amplify-liveness-recording-icon",e.Toast="amplify-liveness-toast",e.Video="amplify-liveness-video",e.VideoAnchor="amplify-liveness-video-anchor"}(e||(e={}));export{e as LivenessClassNames};
1
+ var e;!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"}(e||(e={}));export{e as LivenessClassNames};
@@ -1 +1 @@
1
- import{defaultLivenessDisplayText as e}from"../displayText.mjs";function t(t){const i=Object.assign(Object.assign({},e),t),{instructionsHeaderHeadingText:n,instructionsHeaderBodyText:a,instructionsBeginCheckText:o,photosensitivyWarningHeadingText:s,photosensitivyWarningBodyText:T,photosensitivyWarningInfoText:r,instructionListHeadingText:x,goodFitCaptionText:c,goodFitAltText:d,tooFarCaptionText:g,tooFarAltText:h,instructionListStepOneText:l,instructionListStepTwoText:u,instructionListStepThreeText:p,instructionListStepFourText:F,cameraMinSpecificationsHeadingText:m,cameraMinSpecificationsMessageText:H,cameraNotFoundHeadingText:y,cameraNotFoundMessageText:M,retryCameraPermissionsText:C,cancelLivenessCheckText:f,recordingIndicatorText:v,hintMoveFaceFrontOfCameraText:D,hintTooManyFacesText:I,hintFaceDetectedText:L,hintCanNotIdentifyText:S,hintTooCloseText:B,hintTooFarText:N,hintHoldFacePositionCountdownText:k,hintConnectingText:A,hintVerifyingText:O,hintIlluminationTooBrightText:W,hintIlluminationTooDarkText:w,hintIlluminationNormalText:P,hintHoldFaceForFreshnessText:j,timeoutHeaderText:b,timeoutMessageText:V,faceDistanceHeaderText:q,faceDistanceMessageText:z,clientHeaderText:E,clientMessageText:G,serverHeaderText:J,serverMessageText:K,landscapeHeaderText:Q,landscapeMessageText:R,portraitMessageText:U,tryAgainText:X}=i;return{hintDisplayText:{hintMoveFaceFrontOfCameraText:D,hintTooManyFacesText:I,hintFaceDetectedText:L,hintCanNotIdentifyText:S,hintTooCloseText:B,hintTooFarText:N,hintHoldFacePositionCountdownText:k,hintConnectingText:A,hintVerifyingText:O,hintIlluminationTooBrightText:W,hintIlluminationTooDarkText:w,hintIlluminationNormalText:P,hintHoldFaceForFreshnessText:j},cameraDisplayText:{cameraMinSpecificationsHeadingText:m,cameraMinSpecificationsMessageText:H,cameraNotFoundHeadingText:y,cameraNotFoundMessageText:M,retryCameraPermissionsText:C},instructionDisplayText:{instructionsHeaderHeadingText:n,instructionsHeaderBodyText:a,instructionsBeginCheckText:o,photosensitivyWarningHeadingText:s,photosensitivyWarningBodyText:T,photosensitivyWarningInfoText:r,instructionListHeadingText:x,goodFitCaptionText:c,goodFitAltText:d,tooFarCaptionText:g,tooFarAltText:h,instructionListStepOneText:l,instructionListStepTwoText:u,instructionListStepThreeText:p,instructionListStepFourText:F},streamDisplayText:{cancelLivenessCheckText:f,recordingIndicatorText:v},errorDisplayText:{timeoutHeaderText:b,timeoutMessageText:V,faceDistanceHeaderText:q,faceDistanceMessageText:z,clientHeaderText:E,clientMessageText:G,serverHeaderText:J,serverMessageText:K,landscapeHeaderText:Q,landscapeMessageText:R,portraitMessageText:U,tryAgainText:X}}}export{t as getDisplayText};
1
+ import{defaultLivenessDisplayText as e}from"../displayText.mjs";function t(t){const i=Object.assign(Object.assign({},e),t),{instructionsHeaderHeadingText:n,instructionsHeaderBodyText:a,instructionsBeginCheckText:o,photosensitivyWarningHeadingText:s,photosensitivyWarningBodyText:T,photosensitivyWarningInfoText:r,instructionListHeadingText:x,goodFitCaptionText:c,goodFitAltText:d,tooFarCaptionText:g,tooFarAltText:l,instructionListStepOneText:h,instructionListStepTwoText:u,instructionListStepThreeText:p,instructionListStepFourText:F,cameraMinSpecificationsHeadingText:m,cameraMinSpecificationsMessageText:H,cameraNotFoundHeadingText:y,cameraNotFoundMessageText:M,retryCameraPermissionsText:C,cancelLivenessCheckText:f,recordingIndicatorText:v,hintMoveFaceFrontOfCameraText:D,hintTooManyFacesText:I,hintFaceDetectedText:L,hintCanNotIdentifyText:S,hintTooCloseText:B,hintTooFarText:N,hintHoldFacePositionCountdownText:k,hintConnectingText:A,hintVerifyingText:O,hintIlluminationTooBrightText:W,hintIlluminationTooDarkText:w,hintIlluminationNormalText:P,hintHoldFaceForFreshnessText:j,timeoutHeaderText:b,timeoutMessageText:V,faceDistanceHeaderText:q,faceDistanceMessageText:z,multipleFacesHeaderText:E,multipleFacesMessageText:G,clientHeaderText:J,clientMessageText:K,serverHeaderText:Q,serverMessageText:R,landscapeHeaderText:U,landscapeMessageText:X,portraitMessageText:Y,tryAgainText:Z}=i;return{hintDisplayText:{hintMoveFaceFrontOfCameraText:D,hintTooManyFacesText:I,hintFaceDetectedText:L,hintCanNotIdentifyText:S,hintTooCloseText:B,hintTooFarText:N,hintHoldFacePositionCountdownText:k,hintConnectingText:A,hintVerifyingText:O,hintIlluminationTooBrightText:W,hintIlluminationTooDarkText:w,hintIlluminationNormalText:P,hintHoldFaceForFreshnessText:j},cameraDisplayText:{cameraMinSpecificationsHeadingText:m,cameraMinSpecificationsMessageText:H,cameraNotFoundHeadingText:y,cameraNotFoundMessageText:M,retryCameraPermissionsText:C},instructionDisplayText:{instructionsHeaderHeadingText:n,instructionsHeaderBodyText:a,instructionsBeginCheckText:o,photosensitivyWarningHeadingText:s,photosensitivyWarningBodyText:T,photosensitivyWarningInfoText:r,instructionListHeadingText:x,goodFitCaptionText:c,goodFitAltText:d,tooFarCaptionText:g,tooFarAltText:l,instructionListStepOneText:h,instructionListStepTwoText:u,instructionListStepThreeText:p,instructionListStepFourText:F},streamDisplayText:{cancelLivenessCheckText:f,recordingIndicatorText:v},errorDisplayText:{timeoutHeaderText:b,timeoutMessageText:V,faceDistanceHeaderText:q,faceDistanceMessageText:z,multipleFacesHeaderText:E,multipleFacesMessageText:G,clientHeaderText:J,clientMessageText:K,serverHeaderText:Q,serverMessageText:R,landscapeHeaderText:U,landscapeMessageText:X,portraitMessageText:Y,tryAgainText:Z}}}export{t as getDisplayText};
@@ -1 +1 @@
1
- export{default as FaceLivenessDetector}from"./components/FaceLivenessDetector/FaceLivenessDetector.mjs";
1
+ export{default as FaceLivenessDetector}from"./components/FaceLivenessDetector/FaceLivenessDetector.mjs";export{default as FaceLivenessDetectorCore}from"./components/FaceLivenessDetector/FaceLivenessDetectorCore.mjs";
@@ -1 +1 @@
1
- const o="1.0.5";export{o as VERSION};
1
+ const o="2.0.0";export{o as VERSION};