@voltom.io/sdk 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/locales/ar.json +51 -6
- package/dist/assets/locales/ch.json +51 -6
- package/dist/assets/locales/de.json +51 -6
- package/dist/assets/locales/en.json +24 -2
- package/dist/assets/locales/es.json +51 -6
- package/dist/assets/locales/fr.json +51 -6
- package/dist/assets/locales/it.json +50 -5
- package/dist/assets/locales/ja.json +51 -6
- package/dist/assets/locales/pt.json +51 -6
- package/dist/assets/locales/ru.json +121 -0
- package/dist/assets/locales/zh.json +51 -6
- package/dist/sdk/PoseSilhouette-CTZ5kqI_.js +2 -0
- package/dist/sdk/PoseSuccess-CxL2ugaZ.js +2 -0
- package/dist/sdk/facegate/global.d.ts +5 -0
- package/dist/sdk/facegate.d.ts +51 -0
- package/dist/sdk/facegate.dist.js +56 -0
- package/dist/sdk/facegate.js +2 -0
- package/dist/sdk/facekey.browser-D_vfob8H.js +2 -0
- package/dist/sdk/facekey.d.ts +2 -3
- package/dist/sdk/facekey.dist.js +3 -2
- package/dist/sdk/facekey.js +1 -1
- package/dist/sdk/media-KU3CWepq.js +2 -0
- package/dist/sdk/poseGuidance-DLg3Dm3T.js +65 -0
- package/dist/sdk/presentation-BCIQkuw0.js +2 -0
- package/dist/sdk/presentation-D9v4ITH0.js +8 -0
- package/dist/sdk/verify.d.ts +2 -5
- package/dist/sdk/verify.dist.js +18 -18
- package/dist/sdk/verify.js +1 -1
- package/dist/sdk/view-CsOmx3ht.js +3 -0
- package/dist/sdk/view-Dgrm0mpZ.js +3 -0
- package/dist/sdk/view-WiNYUW9A.js +2 -0
- package/package.json +23 -14
- package/dist/sdk/DebugPanel-BJqGy2Dp.js +0 -2
- package/dist/sdk/faceMatch.shared-D6B1I2T0.js +0 -65
- package/dist/sdk/feedback-Cs09W_hs.js +0 -2
- package/dist/sdk/presentation-BrCGZT1u.js +0 -8
- package/dist/sdk/presentation-Jz2euuHa.js +0 -2
- package/dist/sdk/view-usv6rHIE.js +0 -3
- package/dist/sdk/view-vxhVZZc1.js +0 -2
package/dist/sdk/facekey.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/*! Copyright (c) 2026 VOLTOM. All rights reserved. Proprietary software. See LICENSE at https://voltom.io/license. */
|
|
2
|
-
import{$ as e,G as t,J as n,K as r,X as i,_ as a,c as o,dt as s,et as c,i as l,j as u,k as d,n as f,nt as p,q as m,r as h,rt as g,s as _,t as v,v as y}from"./faceMatch.shared-D6B1I2T0.js";import{n as b,t as x}from"./presentation-Jz2euuHa.js";var S=u({runtime:d}),C=f({runtime:d}),w=l({runtime:d}),T=h({runtime:d,imageFromImageBitmap:S}),E=v({runtime:d,...C,...w,...T,faceDetection:T}),D=e=>{if(typeof e.token!=`string`||e.token.length<32||e.token.length>128||e.userId!==void 0&&(typeof e.userId!=`string`||e.userId.length<1||e.userId.length>255))throw Error(c.INVALID_OPTIONS);return e},O=e=>e.length===512&&e.every(e=>Number.isFinite(e))&&Math.abs(Math.hypot(...e)-1)<.001?e:null,{detectDocumentBox:k,loadDocumentBoxDetector:A}=w,{detectPictureFaces:j,loadFaceDetector:M}=T,{imageBitmap:N,loadFaceMatch:P,preparedFaceEmbeddings:F,prepareFace:I,warmupFaceMatch:L}=E,R=({face:e})=>e?{left:e.blendshapes.eyeBlinkLeft??0,right:e.blendshapes.eyeBlinkRight??0}:null,z=({face:e,frame:t})=>e.boundingRect.height/Math.min(t.width,t.height)<.5?`FACE_TOO_SMALL`:null,B=({face:e,frame:t})=>{let n=e.boundingRect.x+e.boundingRect.width/2,r=e.boundingRect.y+e.boundingRect.height/2,i=Math.min(t.width,t.height);return Math.hypot(n-t.width/2,r-t.height/2)<=i*.08},V=async({frame:e,pose:t,signal:n})=>{let r=await j(e);n.throwIfAborted();let i=r.length===1?r[0]:null,s=i?await k(e):null;n.throwIfAborted();let c=!!(i&&s&&a({face:i,polygon:s.polygon})),l=i?z({face:i,frame:e}):null,u=!!(i&&B({face:i,frame:e})),d=i?o({...i,pose:t,options:y}):null,f=`Keep one face in view`;i&&(f=(c?`In polygon`:null)??l??(u?d:`Center your face in the circle`));let p=d;return u||(p=`FACE_NOT_CENTERED`),l&&(p=`FACE_TOO_SMALL`),c&&(p=`FACE_IN_POLYGON`),i||(p=`FACE_NOT_DETECTED`),{faces:r,face:i,faceInPolygon:c,framing:l,centered:u,poseRejection:d,reason:f,code:p}},H=async({capture:e,pose:t,signal:n,language:r})=>{let i=await N({blob:e});try{n.throwIfAborted();let e=await V({frame:i,pose:t,signal:n}),{face:a,poseRejection:o}=e,s=R({face:a}),l=o&&e.reason===o?b({pose:t,rejection:o,language:r}):e.reason;if(!a||l)return{vector:null,reason:l,eyeScores:s};let u=I({alignment:`eyes-nose-mouth`,face:a,frame:i}),d=u?await F({face:u}):null;if(n.throwIfAborted(),!d)return{vector:null,reason:c.FACE_NOT_USABLE,eyeScores:s};let f=O(d.grayscale);return{vector:f,reason:f?null:c.INVALID_MODEL_OUTPUT,eyeScores:s}}finally{i.close()}},U=class{options;view=null;useUi;display=x();events=new EventTarget;controller=null;operationId=``;modelsReady=null;prepared=!1;disposed=!1;subscriptions=new Set;constructor(e){if(this.useUi=e.ui??!e.video,!this.useUi&&!e.video)throw Error(c.INVALID_OPTIONS);this.options=Object.freeze({...e,capabilities:Object.freeze([...e.capabilities??[`enroll`,`unlock`,`forget`]])})}async prepare(){if(this.disposed)throw Error(c.SDK_NOT_READY);if(this.prepared)return;if(await e({language:this.options.language}),this.useUi&&!this.view){let{createFaceKeyView:e}=await import(`./view-vxhVZZc1.js`);if(this.disposed)throw Error(c.SDK_NOT_READY);this.view=e({options:this.options,display:this.display,events:this.events,onStop:()=>this.stop()})}if(!this.modelsReady){let e=this.options.capabilities.some(e=>e!==`forget`)?Promise.all([A(),M({faceDetector:`standard`}),P()]).then(async()=>{let e=document.createElement(`canvas`);e.width=640,e.height=480;let t=await createImageBitmap(e);try{await Promise.all([j(t),k(t),L()])}finally{t.close()}}):Promise.resolve();this.modelsReady=e}let t=this.modelsReady;try{if(await t,this.disposed)throw Error(c.SDK_NOT_READY);this.prepared=!0}catch(e){throw this.modelsReady===t&&(this.modelsReady=null),e}}async request({path:e,input:t,body:n,signal:r}){let i={authorization:`Bearer ${this.options.clientKey}`,"content-type":`application/json`},a=await fetch(`${(this.options.apiUrl??`https://api.voltom.io`).replace(/\/$/,``)}/facekey/${e}`,{method:`POST`,headers:i,body:JSON.stringify(n??t),signal:r}),o=await a.json();if(r.throwIfAborted(),!a.ok)throw Error(typeof o.code==`string`?o.code:c.INVALID_SERVICE_RESPONSE);return o}async capture({poses:e,signal:a,expiresAt:o,operation:s,input:l}){let u=this.useUi?this.view?.requiredVideo():this.options.video;if(!u)throw Error(c.INVALID_OPTIONS);let d=[];this.display.progress.value={completed:0,total:e.length};let f=null,h={userId:l.userId??``,matched:!1,matches:[],reason:null},g=l.token;a.throwIfAborted();let v=await m({facingMode:`user`,video:u,signal:a});a.throwIfAborted(),this.display.facingMode.value=v,this.display.phase.value=`capturing`;for(let[n,m]of e.entries()){let v=0,y=null;for(p(()=>{this.display.match.value=null,this.display.phase.value=`capturing`,this.display.instruction.value={pose:m,rejection:null,retry:null}});v<3;){if(await i({video:u,signal:a}),a.throwIfAborted(),Date.now()>=Date.parse(o))throw Error(c.FACEKEY_TOKEN_INVALID);if(u.readyState<HTMLMediaElement.HAVE_CURRENT_DATA)continue;let b=await createImageBitmap(u);try{let i=await V({frame:b,pose:m,signal:a}),{reason:u,code:x}=i;v=u===null?v+1:0;let S={...i,frame:b,operation:s,pose:m,stable:v};if(this.view?.collectCaptureDebug(S),this.display.instruction.value={pose:m,rejection:x,retry:y},v===3){let i=await t({frame:b});try{if(s===`unlock`){this.display.phase.value=`checking`;let t={token:g,userId:h.userId,poses:[m],faces:[await r({image:i})]},o=await this.request({path:`unlock/step`,input:{...l,token:g},body:t,signal:a});if(o.userId!==h.userId||o.matched&&(o.matches.length!==1||o.matches[0].pose!==m||!o.matches[0].matched))throw Error(c.INVALID_SERVICE_RESPONSE);if(this.display.match.value={accepted:o.matched,reason:o.reason,score:o.matches.length?o.matches[0].score:null},this.view?.collectCaptureDebug({...S,force:!0,reason:o.reason}),!o.matched){if(o.complete||!o.token)throw Error(c.INVALID_SERVICE_RESPONSE);g=o.token,v=0,y=`Face not recognized. Try this pose again.`,p(()=>{this.display.phase.value=`capturing`,this.display.instruction.value={pose:m,rejection:x,retry:y}}),await this.showFeedback({matched:!1,signal:a});continue}if(h={userId:o.userId,matched:o.complete,matches:[...h.matches,...o.matches],reason:o.reason},o.complete!==(n===e.length-1))throw Error(c.INVALID_SERVICE_RESPONSE);if(!o.complete){if(!o.token)throw Error(c.INVALID_SERVICE_RESPONSE);g=o.token}}else{let e=await H({capture:i,pose:m,signal:a,language:this.options.language}),t=e.vector;if(a.throwIfAborted(),Date.now()>=Date.parse(o))throw Error(c.FACEKEY_TOKEN_INVALID);let n=f&&t?_({first:f,second:t}):null,r=!!(t&&(n===null||n>.5)),s=e.reason??(r?null:c.POSE_IDENTITY_MISMATCH);if(this.display.match.value={accepted:r,reason:s,reference:!f&&r,score:n},this.view?.collectCaptureDebug({...S,force:!0,reason:s}),!t||!r){v=0,y=t?`Face does not match. Try this pose again.`:`Face not usable. Try this pose again.`,p(()=>{this.display.phase.value=`capturing`,this.display.instruction.value={pose:m,rejection:x,retry:y}}),t&&await this.showFeedback({matched:!1,signal:a});continue}f||=t}d.push(i)}catch(e){let t=e instanceof Error?e.message:`Capture failed`;throw this.display.match.value={accepted:!1,reason:t,score:null},this.view?.collectCaptureDebug({...S,force:!0,reason:t}),e}}}finally{b.close()}}this.display.progress.value={completed:n+1,total:e.length},await this.showFeedback({matched:!0,signal:a})}return n({video:u}),{captures:d,unlock:h}}async showFeedback({matched:e,signal:t}){t.throwIfAborted();let n=this.operationId;p(()=>{this.display.failures.value=e?0:this.display.failures.value+1,this.display.feedback.value={matched:e,animating:!0}});let r=Promise.withResolvers(),i=setTimeout(()=>r.resolve(),500),a=()=>r.resolve();t.addEventListener(`abort`,a,{once:!0});try{await r.promise,t.throwIfAborted()}finally{clearTimeout(i),t.removeEventListener(`abort`,a),this.operationId===n&&(this.display.feedback.value=e?null:{matched:!1,animating:!1})}}async run({operation:e,input:t,externalSignal:i,debug:a}){if(this.disposed||!this.prepared)throw Error(c.SDK_NOT_READY);if(!this.options.capabilities.includes(e))throw Error(c.SDK_CAPABILITY_NOT_CONFIGURED);if(this.controller)throw Error(c.INVALID_OPTIONS);let o=D(t);if(e!==`enroll`&&!o.userId)throw Error(c.INVALID_OPTIONS);let s=new AbortController;this.controller=s;let l=s.signal,u=()=>s.abort();i?.addEventListener(`abort`,u,{once:!0}),i?.aborted&&u();let d=[];this.operationId=crypto.randomUUID();try{if(e===`forget`)return await this.request({path:e,input:o,signal:l});p(()=>{this.display.operation.value=e,this.display.phase.value=`loading`,this.display.instruction.value=null,this.display.feedback.value=null,this.display.failures.value=0,this.display.error.value=null,this.display.debug.value=[],this.display.debugEnabled.value=a??this.options.debug??!1,this.display.match.value=null,this.display.progress.value={completed:0,total:1},this.display.facingMode.value=null}),this.view?.open();let t=await this.request({path:`challenge`,input:o,signal:l});if(t.operation!==e||o.userId&&t.userId!==o.userId)throw Error(c.FACEKEY_TOKEN_INVALID);let n=await this.capture({poses:t.poses,signal:l,expiresAt:t.expiresAt,operation:e,input:{...o,userId:t.userId}});d.push(...n.captures),l.throwIfAborted();let i=n.unlock;if(e===`enroll`){this.display.phase.value=`processing`;let n={token:o.token,userId:t.userId,poses:t.poses,faces:await Promise.all(d.map(e=>r({image:e})))};i=await this.request({path:e,input:o,body:n,signal:l})}let s=!(`matched`in i)||i.matched===!0;return this.display.phase.value=s?`success`:`failure`,await this.showFeedback({matched:s,signal:l}),i}catch(e){throw this.view?.dialog?.open&&p(()=>{this.display.phase.value=`failure`,this.display.error.value=e}),e}finally{i?.removeEventListener(`abort`,u),this.display.debugEnabled.value=this.options.debug??!1,d.length=0;let e=this.useUi?this.view?.dialog?.open?this.view.requiredVideo():null:this.options.video;e&&n({video:e}),this.view?.close(),this.controller=null}}async faceEnroll(e,{signal:t,debug:n}={}){return await this.run({operation:`enroll`,input:e,externalSignal:t,debug:n})}async faceUnlock(e,{signal:t,debug:n}={}){return await this.run({operation:`unlock`,input:e,externalSignal:t,debug:n})}async faceForget(e,{signal:t,debug:n}={}){return await this.run({operation:`forget`,input:e,externalSignal:t,debug:n})}stop(){this.controller&&this.controller.abort(new DOMException(c.VERIFICATION_CANCELLED,`AbortError`));let e=this.useUi?this.view?.dialog?.open?this.view.requiredVideo():null:this.options.video;e&&n({video:e}),this.view?.close()}dispose(){if(!this.disposed){this.disposed=!0,this.stop();for(let e of this.subscriptions)e();this.subscriptions.clear(),this.events=new EventTarget}}getState(){return{operation:this.display.operation.value,phase:this.display.phase.value,instruction:this.display.instruction.value,feedback:this.display.feedback.value,error:this.display.error.value,progress:this.display.progress.value,match:this.display.match.value,debug:this.display.debug.value}}subscribe(e){if(this.disposed)throw Error(c.SDK_NOT_READY);let t=g(()=>e(this.getState()));return this.subscriptions.add(t),()=>{t(),this.subscriptions.delete(t)}}};s({moduleUrl:import.meta.url});var W=U;export{U as VoltomFaceKey,W as default};
|
|
2
|
+
import{$ as e,E as t,Q as n,T as r,_ as i,a,c as o,i as s,l as c,n as l,q as u,r as d,s as f,t as p,u as m}from"./poseGuidance-DLg3Dm3T.js";import{E as h,a as g,f as _,i as v,l as y,m as b,o as x,s as S,t as C,u as w}from"./media-KU3CWepq.js";import{n as T,r as E,t as D}from"./facekey.browser-D_vfob8H.js";import{t as O}from"./presentation-BCIQkuw0.js";var k=e=>{if(typeof e.token!=`string`||e.token.length<32||e.token.length>128||e.userId!==void 0&&(typeof e.userId!=`string`||e.userId.length<1||e.userId.length>255))throw Error(b.INVALID_OPTIONS);return e},A=e=>e.length===512&&e.every(e=>Number.isFinite(e))&&Math.abs(Math.hypot(...e)-1)<.001?e:null,j=({pose:e,rejection:t,language:n})=>{let{translate:r}=w({language:n});return r(t?m({code:t}):c({pose:e}).primary)},{detectDocumentBox:M,loadDocumentBoxDetector:N}=D,{detectPictureFaces:P,loadFaceDetector:F}=T,{imageBitmap:I,loadFaceMatch:L,preparedFaceGrayscaleEmbedding:R,prepareFace:z,warmupFaceMatch:B}=E,V=({face:e})=>e?{left:e.blendshapes.eyeBlinkLeft??0,right:e.blendshapes.eyeBlinkRight??0}:null,H=({face:e,frame:t})=>e.boundingRect.height/Math.min(t.width,t.height)<.5?`FACE_TOO_SMALL`:null,U=({face:e,frame:t})=>{let n=e.boundingRect.x+e.boundingRect.width/2,r=e.boundingRect.y+e.boundingRect.height/2,i=Math.min(t.width,t.height);return Math.hypot(n-t.width/2,r-t.height/2)<=i*.08},W=async({frame:e,pose:n,signal:i,neutral:a})=>{let o=await P(e);i.throwIfAborted();let s=o.length===1?o[0]:null,c=s?await M(e):null;i.throwIfAborted();let l=!!(s&&c&&r({face:s,polygon:c.polygon})),u=!!(s&&H({face:s,frame:e})),d=!!(s&&U({face:s,frame:e})),f=s?{pitch:s.pitch,yaw:s.yaw,roll:s.roll}:null,m=f?p({alignment:f,blendshapes:s?.blendshapes??{},neutral:a,pose:n,options:t}):null,h=null,g=`Keep one face in view`;return s&&(g=null,l?g=`In polygon`:u?g=`Face too small`:d?m?.code&&(g=m.code):g=`Center your face in the circle`),s?l?h=`FACE_IN_POLYGON`:u?h=`FACE_TOO_SMALL`:d||(h=`FACE_NOT_CENTERED`):h=`FACE_NOT_DETECTED`,{faces:o,face:s,faceInPolygon:l,centered:d,framing:h,guidance:m,alignment:f,reason:g}},G=async({capture:e,neutral:t,pose:n,signal:r,language:i})=>{let a=await I({blob:e});try{r.throwIfAborted();let e=await W({frame:a,pose:n,signal:r,neutral:t}),{face:o,guidance:s}=e,c=V({face:o}),l=s?.code&&e.reason===s.code?j({pose:n,rejection:s.code,language:i}):e.reason;if(!o||l)return{vector:null,reason:l,eyeScores:c};let u=z({alignment:`eyes-nose-mouth`,face:o,frame:a}),d=u?await R({face:u}):null;if(r.throwIfAborted(),!d)return{vector:null,reason:b.FACE_NOT_USABLE,eyeScores:c};let f=A(d);return{vector:f,reason:f?null:b.INVALID_MODEL_OUTPUT,eyeScores:c}}finally{a.close()}},K=class{options;view=null;useUi;display=O();events=new EventTarget;controller=null;operationId=``;neutralPose=null;guidanceCodeState=d();correctiveState=l();modelsReady=null;preloading=null;prepared=!1;disposed=!1;subscriptions=new Set;constructor(e){if(this.useUi=e.ui??!e.video,!this.useUi&&!e.video)throw Error(b.INVALID_OPTIONS);this.options=Object.freeze({...e,capabilities:Object.freeze([...e.capabilities??[`enroll`,`unlock`]])})}async caniuse(){return await C()}async preload(){if(this.disposed)throw Error(b.SDK_NOT_READY);if(this.preloading)return this.preloading;let e=(async()=>{await _({language:this.options.language}),this.options.capabilities.length>0&&await u({filenames:[`dd.ort`,`fd.ort`,`fl.ort`,`fe.ort`,`fmu.ort`,`ort-wasm-simd-threaded.mjs`,`ort-wasm-simd-threaded.wasm`]})})();this.preloading=e;try{if(await e,this.disposed)throw Error(b.SDK_NOT_READY)}catch(t){throw this.preloading===e&&(this.preloading=null),t}}async prepare(){if(this.disposed)throw Error(b.SDK_NOT_READY);if(this.prepared)return;if(await this.preload(),this.useUi&&!this.view){let{createFaceKeyView:e}=await import(`./view-Dgrm0mpZ.js`);if(this.disposed)throw Error(b.SDK_NOT_READY);this.view=e({options:this.options,display:this.display,events:this.events,onStop:()=>this.stop()})}if(!this.modelsReady){let e=this.options.capabilities.length>0?Promise.all([N(),F({faceDetector:`standard`}),L()]).then(async()=>{let e=document.createElement(`canvas`);e.width=640,e.height=480;let t=await createImageBitmap(e);try{await Promise.all([P(t),M(t),B()])}finally{t.close()}}):Promise.resolve();this.modelsReady=e}let e=this.modelsReady;try{if(await e,this.disposed)throw Error(b.SDK_NOT_READY);this.prepared=!0}catch(t){throw this.modelsReady===e&&(this.modelsReady=null),t}}async request({path:e,input:t,body:n,signal:r}){let i={authorization:`Bearer ${this.options.clientKey}`,"content-type":`application/json`},a=await fetch(`${(this.options.apiUrl??`https://api.voltom.io`).replace(/\/$/,``)}/facekey/${e}`,{method:`POST`,headers:i,body:JSON.stringify(n??t),signal:r}),o=await a.json();if(r.throwIfAborted(),!a.ok)throw Error(typeof o.code==`string`?o.code:b.INVALID_SERVICE_RESPONSE);return o}async capture({poses:e,signal:t,expiresAt:r,operation:c,input:u}){let p=this.useUi?this.view?.requiredVideo():this.options.video;if(!p)throw Error(b.INVALID_OPTIONS);let{translate:m}=w({language:this.options.language}),h=[];this.display.progress.value={completed:0,total:e.length},this.neutralPose=null,this.guidanceCodeState=d(),this.correctiveState=l();let _=null,C={userId:u.userId??``,matched:!1,matches:[],reason:null},T=u.token;t.throwIfAborted();let E=await x({facingMode:`user`,video:p,signal:t});t.throwIfAborted(),this.display.facingMode.value=E,this.display.phase.value=`capturing`;for(let[x,S]of e.entries()){let w=0,E=null;for(this.guidanceCodeState=d(),this.correctiveState=l(),n(()=>{this.display.match.value=null,this.display.phase.value=`capturing`,this.display.guidance.value=null,this.display.corrective.value=null,this.display.instruction.value={framing:null,retry:null}});w<3;){if(await y({video:p,signal:t}),t.throwIfAborted(),Date.now()>=Date.parse(r))throw Error(b.FACEKEY_TOKEN_INVALID);if(p.readyState<HTMLMediaElement.HAVE_CURRENT_DATA)continue;let l=await createImageBitmap(p);try{let d=await W({frame:l,pose:S,signal:t,neutral:this.neutralPose}),{framing:p,guidance:y}=d,D=y?.code??null;if(w=p===null&&D===null?w+1:0,S===`faceStraight`&&!this.neutralPose&&D===null&&p===null&&(this.neutralPose=d.alignment),y){this.guidanceCodeState=a({state:this.guidanceCodeState,code:y.code,requiredFrames:3});let e=this.guidanceCodeState.published,t=f({pose:S,code:e}).corrective,n=performance.now();this.correctiveState=s({label:t,now:n,state:this.correctiveState}),this.display.guidance.value={...y,code:e},this.display.corrective.value=o({label:t,now:n,state:this.correctiveState})}let O={...d,frame:l,operation:c,pose:S,poseRejection:D,stable:w};if(this.view?.collectCaptureDebug(O),this.display.instruction.value={framing:p,retry:E},w===3){let a=await v({frame:l});try{if(c===`unlock`){this.display.phase.value=`checking`;let r={token:T,userId:C.userId,poses:[S],faces:[await g({image:a})]},i=await this.request({path:`unlock/step`,input:{...u,token:T},body:r,signal:t});if(i.userId!==C.userId||i.matched&&(i.matches.length!==1||i.matches[0].pose!==S||!i.matches[0].matched))throw Error(b.INVALID_SERVICE_RESPONSE);if(this.display.match.value={accepted:i.matched,reason:i.reason,score:i.matches.length?i.matches[0].score:null},this.view?.collectCaptureDebug({...O,force:!0,reason:i.reason}),!i.matched){if(i.complete||!i.token)throw Error(b.INVALID_SERVICE_RESPONSE);T=i.token,w=0,E=m(`faceRetryPose`),n(()=>{this.display.phase.value=`capturing`,this.display.instruction.value={framing:p,retry:E}}),await this.showFeedback({matched:!1,signal:t});continue}if(C={userId:i.userId,matched:i.complete,matches:[...C.matches,...i.matches],reason:i.reason},i.complete!==(x===e.length-1))throw Error(b.INVALID_SERVICE_RESPONSE);if(!i.complete){if(!i.token)throw Error(b.INVALID_SERVICE_RESPONSE);T=i.token}}else{let e=await G({capture:a,pose:S,signal:t,language:this.options.language,neutral:this.neutralPose}),o=e.vector;if(t.throwIfAborted(),Date.now()>=Date.parse(r))throw Error(b.FACEKEY_TOKEN_INVALID);let s=_&&o?i({first:_,second:o}):null,c=!!(o&&(s===null||s>.5)),l=e.reason??(c?null:b.POSE_IDENTITY_MISMATCH);if(this.display.match.value={accepted:c,reason:l,reference:!_&&c,score:s},this.view?.collectCaptureDebug({...O,force:!0,reason:l}),!o||!c){w=0,E=m(o?`faceRetryMatch`:`faceRetryUsable`),n(()=>{this.display.phase.value=`capturing`,this.display.instruction.value={framing:p,retry:E}}),o&&await this.showFeedback({matched:!1,signal:t});continue}_||=o}h.push(a)}catch(e){let t=e instanceof Error?e.message:`Capture failed`;throw this.display.match.value={accepted:!1,reason:t,score:null},this.view?.collectCaptureDebug({...O,force:!0,reason:t}),e}}}finally{l.close()}}this.display.progress.value={completed:x+1,total:e.length},await this.showFeedback({matched:!0,signal:t})}return S({video:p}),{captures:h,unlock:C}}async showFeedback({matched:e,signal:t}){t.throwIfAborted();let r=this.operationId;n(()=>{this.display.failures.value=e?0:this.display.failures.value+1,this.display.feedback.value={matched:e,animating:!0}});let i=Promise.withResolvers(),a=setTimeout(()=>i.resolve(),500),o=()=>i.resolve();t.addEventListener(`abort`,o,{once:!0});try{await i.promise,t.throwIfAborted()}finally{clearTimeout(a),t.removeEventListener(`abort`,o),this.operationId===r&&(this.display.feedback.value=e?null:{matched:!1,animating:!1})}}async run({operation:e,input:t,externalSignal:r,debug:i}){if(this.disposed||!this.prepared)throw Error(b.SDK_NOT_READY);if(!this.options.capabilities.includes(e))throw Error(b.SDK_CAPABILITY_NOT_CONFIGURED);if(this.controller)throw Error(b.INVALID_OPTIONS);let a=k(t);if(e!==`enroll`&&!a.userId)throw Error(b.INVALID_OPTIONS);let o=new AbortController;this.controller=o;let s=o.signal,c=()=>o.abort();r?.addEventListener(`abort`,c,{once:!0}),r?.aborted&&c();let l=[];this.operationId=crypto.randomUUID();try{n(()=>{this.display.operation.value=e,this.display.phase.value=`loading`,this.display.instruction.value=null,this.display.guidance.value=null,this.display.corrective.value=null,this.display.feedback.value=null,this.display.failures.value=0,this.display.error.value=null,this.display.debug.value=[],this.display.debugEnabled.value=i??this.options.debug??!1,this.display.match.value=null,this.display.progress.value={completed:0,total:1},this.display.facingMode.value=null}),this.view?.open();let t=await this.request({path:`challenge`,input:a,signal:s});if(t.operation!==e||a.userId&&t.userId!==a.userId)throw Error(b.FACEKEY_TOKEN_INVALID);let r=await this.capture({poses:t.poses,signal:s,expiresAt:t.expiresAt,operation:e,input:{...a,userId:t.userId}});l.push(...r.captures),s.throwIfAborted();let o=r.unlock;if(e===`enroll`){this.display.phase.value=`processing`;let n={token:a.token,userId:t.userId,poses:t.poses,faces:await Promise.all(l.map(e=>g({image:e})))};o=await this.request({path:e,input:a,body:n,signal:s})}let c=!(`matched`in o)||o.matched===!0;return this.display.phase.value=c?`success`:`failure`,await this.showFeedback({matched:c,signal:s}),o}catch(e){throw this.view?.dialog?.open&&n(()=>{this.display.phase.value=`failure`,this.display.error.value=e}),e}finally{r?.removeEventListener(`abort`,c),this.display.debugEnabled.value=this.options.debug??!1,l.length=0;let e=this.useUi?this.view?.dialog?.open?this.view.requiredVideo():null:this.options.video;e&&S({video:e}),this.view?.close(),this.controller=null}}async faceEnroll(e,{signal:t,debug:n}={}){return await this.run({operation:`enroll`,input:e,externalSignal:t,debug:n})}async faceUnlock(e,{signal:t,debug:n}={}){return await this.run({operation:`unlock`,input:e,externalSignal:t,debug:n})}stop(){this.controller&&this.controller.abort(new DOMException(b.VERIFICATION_CANCELLED,`AbortError`));let e=this.useUi?this.view?.dialog?.open?this.view.requiredVideo():null:this.options.video;e&&S({video:e}),this.view?.close()}dispose(){if(!this.disposed){this.disposed=!0,this.stop();for(let e of this.subscriptions)e();this.subscriptions.clear(),this.events=new EventTarget}}getState(){return{operation:this.display.operation.value,phase:this.display.phase.value,instruction:this.display.instruction.value,feedback:this.display.feedback.value,error:this.display.error.value,progress:this.display.progress.value,match:this.display.match.value,debug:this.display.debug.value}}subscribe(t){if(this.disposed)throw Error(b.SDK_NOT_READY);let n=e(()=>t(this.getState()));return this.subscriptions.add(n),()=>{n(),this.subscriptions.delete(n)}}};h({moduleUrl:import.meta.url});var q=K;export{K as VoltomFaceKey,q as default};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! Copyright (c) 2026 VOLTOM. All rights reserved. Proprietary software. See LICENSE at https://voltom.io/license. */
|
|
2
|
+
var e=({moduleUrl:e})=>{let t=globalThis;t.__VOLTOM_ASSET_BASE_URL__||=new URL(`../`,e).href},t=({filename:e})=>{let t=globalThis.__VOLTOM_ASSET_BASE_URL__||globalThis.location?.href;if(!t)throw Error(`SDK_ASSET_BASE_URL_UNAVAILABLE`);return new URL(`assets/${e}`,t).href},n,r,i,a,o,s,c,l,u,d,f,p=Symbol.for(`pv`),m={},h=[],g=/^m(i|n|o|s|text|space)$/,_=Array.isArray,v=h.slice,y=Object.assign;function b(e){e&&e.parentNode&&e.remove()}function x(e,t,n){var r,i,a,o={},s=arguments.length;for(a in t)a==`key`?r=t[a]:a==`ref`&&typeof e!=`function`?i=t[a]:o[a]=t[a];return s>2&&(o.children=s>3?v.call(arguments,2):n),S(e,o,r,i,null)}function S(e,t,i,a,o){var s={type:e,props:t,key:i,ref:a,__k:null,__:null,__b:0,__e:null,__c:null,constructor:p,__v:o||++r,__i:-1,__u:0};return!o&&n.vnode&&n.vnode(s),s}function C(){return{current:null}}function w(e){return e.children}function T(e,t){this.props=e,this.context=t,this.__g=0}function E(e,t){if(t==null)return e.__&&E(e.__,e.__i+1);for(var n;t<e.__k.length;t++)if((n=e.__k[t])&&n.__e)return n.__e;return typeof e.type!=`function`||e.props.__P?null:E(e)}function D(e){if((e=e.__)&&e.__c&&!e.props.__P)return e.__e=null,e.__k.some(function(t){return t&&(e.__e=t.__e)}),D(e)}function O(e){(8&e.__g||(e.__g|=8,a.push(e),s++))&&o==n.debounceRendering||((o=n.debounceRendering)||queueMicrotask)(k)}function k(){var e,t,r,i,l,u,d,f,m;try{for(t=1;a.length;)a.length>t&&a.sort(c),e=a.shift(),t=a.length,8&e.__g&&(i=void 0,l=void 0,u=(l=(r=e).__v).__e,d=[],f=[],(m=r.__P)&&((i=y({constructor:p},l)).__v=l.__v+1,n.vnode&&n.vnode(i),I(m,i,l,r.__n,m.namespaceURI,32&l.__u?[u]:null,d,u||E(l),32&l.__u,f),i.__v=l.__v,i.__.__k[i.__i]=i,R(d,i,f),l.__=l.__e=null,i.__e!=u&&D(i)))}finally{(s=a.length)&&(o||queueMicrotask)(k)}}function ee(e,t,n,r,i,a,o,s,c,l,u){var d,f,p,g,_,v,y=r.__k||h,b=t.length;for(c=A(n,t,y,c,b),d=0;d<b;d++)(p=n.__k[d])!=null&&(f=~p.__i&&y[p.__i]||m,p.__i=d,v=I(e,p,f,i,a,o,s,c,l,u),g=p.__e,(f.ref!=p.ref||8&f.__u)&&(f.ref&&z(f.ref,null,p,f),p.ref&&u.push(p.ref,p.__c||g,p)),_||=g,4&p.__u?(c=j(p,c,e,!f.__v),f.__e&&(f.__e=null)):typeof p.type==`function`&&v!==void 0?c=v:g&&(c=g.nextSibling),p.__u&=-21);return n.__e=_,c}function A(e,t,n,r,i){var a,o,s,c,l,u,d,f,m,h=n.length,g=h,v=0,y=0,b=e.__k=Array(i);for(a=0;a<i;a++)(o=t[a])!=null&&typeof o!=`boolean`&&typeof o!=`function`?(typeof o!=`object`||o.constructor===String?o=b[a]=S(null,o):_(o)?o=b[a]=S(w,{children:o}):o.constructor===p&&o.__b?o=b[a]=S(o.type,o.props,o.key,o.ref,o.__v):b[a]=o,c=a+v,o.__=e,o.__b=e.__b+1,s=null,~(l=o.__i=M(o,n,c,g))&&(g--,(s=n[l])&&(s.__u|=2)),s&&s.__v?(o.__u|=16,l==c-1?v--:l==c+1?v++:l!=c&&(l>c?v--:v++,y=1)):(~l||(i>h?v--:i<h&&v++),typeof o.type!=`function`&&(o.__u|=4))):b[a]=null;if(y){for(u=[],d=[],a=0;a<i;a++)if((o=b[a])&&16&o.__u){for(v=0,f=u.length;v<f;)u[m=v+f>>1]<o.__i?v=m+1:f=m;u[v]=o.__i,d[a]=v+1}for(v=u.length;a--;)d[a]&&(d[a]==v?v--:b[a].__u|=4)}if(g)for(a=0;a<h;a++)!(s=n[a])||2&s.__u||(s.__e==r&&(r=E(s)),B(s,s));return r}function j(e,t,n,r){var i,a,o,s;if(typeof e.type==`function`){if(e.props.__P)return t;if(i=e.__k)for(a=0;a<i.length;a++)i[a]&&(i[a].__=e,t=j(i[a],t,n,!1));return t}for(t&&!t.parentNode&&(t=E(e))&&!t.parentNode&&(t=null),o=e.__e,s=t;s&&s.nodeType==8;)s=s.nextSibling;for(o!=s&&(!r&&n.moveBefore&&o.parentNode?n.moveBefore(o,t):n.insertBefore(o,t||null)),t=o;(t&&=t.nextSibling)&&t.nodeType==8&&!t.data.startsWith(`$s`););return t}function M(e,t,n,r){var i,a=e.key,o=e.type,s=t[n],c=s&&!(2&s.__u);if(s===null&&a==null||c&&a==s.key&&o==s.type)return n;if(r>+!!c){for(i=n-1;i>=0;i--)if((s=t[i])&&!(2&s.__u)&&a==s.key&&o==s.type)return i;for(i=n+1;i<t.length;i++)if((s=t[i])&&!(2&s.__u)&&a==s.key&&o==s.type)return i}return-1}function N(e,t,n){n??=``,t[0]==`-`?e.setProperty(t,n):e[t]=n}function P(e,t,n,r,i){var a,o;if(t==`style`){if(typeof n==`string`)e.style.cssText=n;else{if(typeof r==`string`&&(e.style.cssText=r=``),r)for(t in r)n&&t in n||N(e.style,t);if(n)for(t in n)r&&n[t]==r[t]||N(e.style,t,n[t])}}else if(t[0]==`o`&&t[1]==`n`)(e.__e||={})[t]=n,n&&r||(o=f[t]||(f[t]=F(t)),(e.__a||={})[t]=d,a=t!=(t=t.replace(u,`$1`)),(t=t.slice(2))[0]<`a`&&(t=t.toLowerCase()),n?e.addEventListener(t,o,a):e.removeEventListener(t,o,a));else{if(i==`http://www.w3.org/2000/svg`)t=t.replace(/xlink(H|:h)/,`h`).replace(/sName$/,`s`);else if(t!=`width`&&t!=`height`&&t!=`href`&&t!=`list`&&t!=`form`&&t!=`tabIndex`&&t!=`download`&&t!=`rowSpan`&&t!=`colSpan`&&t!=`role`&&t!=`popover`&&t in e)try{e[t]=n??``;return}catch{}if(typeof n==`function`)return;n==null||!1===n&&t[4]!=`-`?e.removeAttribute(t):e.setAttribute(t,t==`popover`&&n==1?``:n)}}function F(e){return function(t){var r=this.__e;if(r){if(r=r[e],t[l]==null)t[l]=d++;else if(t[l]<this.__a[e])return;return r(n.event?n.event(t):t)}}}function I(e,t,r,i,a,o,s,c,l,u){var d,f,m,g,v,x,S,C,D,O,k,A,j,M,N,P,F,I,R=t.type;if(t.constructor!==p)return null;128&r.__u&&(l=32&r.__u,d=r.__c.__z)&&(t.__u|=l,f=o=[],d.nodeType==8?c=L(d,o):o.push(d),c=o[0]||c),(d=n.__b)&&d(t);n:if(typeof R==`function`){m=s.length;try{if(C=t.props,D=(d=R.prototype)&&d.render,O=(d=R.contextType)&&i[d.__c],k=d?O?O.props.value:d.__:i,(g=r.__c)?(t.__c=g,2&g.__g&&(g.__g|=1)):(D?t.__c=g=new R(C,k):(t.__c=g=new T(C,k),g.constructor=R,g.render=re),O&&O.sub(g),g.state||(g.state={}),g.__n=i,g.__g|=8,g.__h=[],g.__k=[]),D&&(g.__s||(g.__s=g.state),R.getDerivedStateFromProps&&(g.__s==g.state&&(g.__s=y({},g.__s)),y(g.__s,R.getDerivedStateFromProps(C,g.__s)))),v=g.props,x=g.state,g.__v=t,r.__c){if(C!==v&&D&&!R.getDerivedStateFromProps&&g.componentWillReceiveProps&&g.componentWillReceiveProps(C,k),t.__v==r.__v&&!(8&g.__g)||!(4&g.__g)&&g.shouldComponentUpdate&&!1===g.shouldComponentUpdate(C,g.__s,k)){t.__v!=r.__v&&(g.props=C,g.state=g.__s,g.__g&=-9),t.__e=r.__e,t.__k=r.__k,t.__k.some(function(e){e&&(e.__=t)}),h.push.apply(g.__h,g.__k),g.__k=[],g.__h.length&&s.push(g),c=E(r);break n}g.componentWillUpdate&&g.componentWillUpdate(C,g.__s,k),D&&g.componentDidUpdate&&g.__h.push(function(){g.componentDidUpdate(v,x,S)})}else D&&!R.getDerivedStateFromProps&&g.componentWillMount&&g.componentWillMount(),D&&g.componentDidMount&&g.__h.push(g.componentDidMount);if(g.context=k,g.props=C,g.__P=e,g.__g&=-5,A=n.__r,j=0,D)g.state=g.__s,g.__g&=-9,A&&A(t),d=g.render(g.props,g.state,g.context),h.push.apply(g.__h,g.__k),g.__k=[];else do g.__g&=-9,A&&A(t),d=g.render(g.props,g.state,g.context),g.state=g.__s;while(8&g.__g&&++j<25);g.state=g.__s,g.getChildContext&&(i=y({},i,g.getChildContext())),D&&r.__c&&g.getSnapshotBeforeUpdate&&(S=g.getSnapshotBeforeUpdate(v,x)),M=d&&d.type===w&&d.key==null?d.props.children:d,C.__P&&(d=c,a=(e=C.__P).namespaceURI,l=o=null,r.props&&r.props.__P!=e&&(r.__k.some(function(e){e&&B(e,e)}),r.__k=null),c=r.__k?E(r,0):null),c=ee(e,_(M)?M:[M],t,r,i,a,o,s,c,l,u),C.__P&&(t.__e=null,c=d),t.__u&=-161,f&&f.some(b),g.__h.length&&s.push(g),1&g.__g&&(g.__g&=-4)}catch(e){if(s.length=m,t.__v=null,l||o){if(e.then){if(N=0,t.__u|=128|l,o){for(~(F=o.indexOf(c||void 0))||(F=o.length);(I=o[F-1])&&I.nodeType==8;)F--;for(;F<o.length;F++)if(I=o[F]){if(o[F]=null,I.nodeType==8){if(I.data.startsWith(`$s`))N++||(P=I);else if(N&&I.data.startsWith(`/$s`)&&!--N)break}else if(!N)break}}if(!P){for(;c&&c.nodeType==8&&c.nextSibling;)c=c.nextSibling;P=c}(d=L(P=t.__c.__z||(t.__c.__z=P)))?(t.__e=P,c=d):t.__e=c,c&&=c.nextSibling}else o&&o.some(b)}else t.__e=r.__e;t.__k||=r.__k||[],e.then||te(t),n.__e(e,t,r)}}else c=t.__e=ne(r.__e,t,r,i,a,o,s,l,u,e);return(d=n.diffed)&&d(t),c}function L(e,t){if(e&&e.nodeType==8&&e.data.startsWith(`$s`))for(var n=1;e=e.nextSibling;){if(e.nodeType==8){if(e.data.startsWith(`$s`))n++;else if(e.data.startsWith(`/$s`)&&!--n)return e}t&&t.push(e)}}function te(e){e&&(e.__c&&(e.__c.__g|=4),e.__k&&e.__k.some(te))}function R(e,t,r){for(var i=0;i<r.length;)z(r[i++],r[i++],r[i++]);n.__c&&n.__c(t,e),e.some(function(t){try{e=t.__h,t.__h=[],e.some(function(e){e.call(t)})}catch(e){n.__e(e,t.__v)}})}function ne(e,t,r,i,a,o,s,c,l,u){var d,f,p,h,y,x,S,C,w,T=r.props||m,D=t.props,O=t.type;if(O==`svg`?a=`http://www.w3.org/2000/svg`:O==`math`?a=`http://www.w3.org/1998/Math/MathML`:a||=`http://www.w3.org/1999/xhtml`,o){for(d=0;d<o.length;d++)if((y=o[d])&&(O?y.localName==O:y.nodeType==3)){e=y,o[d]=null;break}}if(!e){if(C=u.ownerDocument||document,!O)return C.createTextNode(D);e=C.createElementNS(a,O,D.is&&D),c&&=(n.__m&&n.__m(t,o),!1),o=null}if(O){if(u=O==`template`&&e.content||e,o=O==`textarea`&&D.defaultValue!=null?null:o&&v.call(u.childNodes),!c&&o)for(T={},d=0;d<e.attributes.length;d++)T[(y=e.attributes[d]).name]=y.value;for(d in T)y=T[d],d==`dangerouslySetInnerHTML`?p=y:d==`children`||d in D||d==`value`&&`defaultValue`in D||d==`checked`&&`defaultChecked`in D||P(e,d,null,y,a);for(d in w=1&r.__u,D)y=D[d],d==`children`?h=y:d==`dangerouslySetInnerHTML`?f=y:d==`value`?x=y:d==`checked`?S=y:c&&typeof y!=`function`||!(T[d]!==y||w&&y!=null)||P(e,d,y,T[d],a);f?(c||p&&(f.__html==p.__html||f.__html==e.innerHTML)||(e.innerHTML=f.__html),t.__k=[]):(p&&(e.textContent=``),(O==`foreignObject`||a==`http://www.w3.org/1998/Math/MathML`&&g.test(O))&&(a=`http://www.w3.org/1999/xhtml`),ee(u,_(h)?h:[h],t,r,i,a,o,s,o?o[0]:r.__k&&E(r,0),c,l),o&&o.some(b)),c&&O!=`textarea`||(d=`value`,O==`progress`&&x==null?e.removeAttribute(d):x==null||x===e[d]&&(O!=`progress`||x)||P(e,d,x,T[d],a),d=`checked`,S!=null&&S!=e[d]&&P(e,d,S,T[d],a))}else T===D||c&&e.data==D||(e.data=D);return e}function z(e,t,r,i){try{typeof e==`function`?t?t.__x=e(t)||1:(i&&=i.__c||i.__e)&&(t=i.__x)&&(i.__x=null,typeof t==`function`?t():e(null)):e.current=t}catch(e){n.__e(e,r)}}function B(e,t,r){var i,a,o,s;if(n.unmount&&n.unmount(e),!(i=e.ref)||i.current&&i.current!=e.__e||z(i,null,t,e),i=e.__c){if(i.componentWillUnmount)try{i.componentWillUnmount()}catch(e){n.__e(e,t)}i.__P=i.__n=null}if(i=e.__k)for(s=0;s<i.length;s++)i[s]&&B(i[s],t,typeof e.type!=`function`||r&&!e.props.__P);!r&&(i=e.__c)&&(i=i.__z)&&(a=L(i,o=[]))&&(i==e.__e&&o.some(b),b(a),b(i)),(i=e.__e)&&(r||b(i),i.__e&&(i.__e=null)),e.__e=e.__c=e.__=null}function re(e,t,n){return this.constructor(e,n)}function ie(e,t){var r,i,a,o;n.__&&n.__(e,t),t.nodeType==9&&(t=t.documentElement),i=(r=e&&32&e.__u)?null:t.__k,t.__k=S(w,{children:[e]}),a=[],o=[],I(t,t.__k,i||m,m,t.namespaceURI,i?null:t.firstChild?v.call(t.childNodes):null,a,i?i.__e:t.firstChild,r,o),R(a,t.__k,o),t.__k.props.children=null}n={__e:function(e,t,n,r){for(var i,a,o;t=t.__;)if((i=t.__c)&&!(1&i.__g)){i.__g|=4;try{if((o=(a=i.constructor)&&a.getDerivedStateFromError)&&i.setState(a.getDerivedStateFromError(e)),i.componentDidCatch&&(i.componentDidCatch(e,r||{}),o=1),o&&8&i.__g)return void(i.__g|=2)}catch(t){e=t}}throw s=0,e}},r=0,i=function(e){return e!=null&&e.constructor===p},T.prototype.setState=function(e,t){var n=this.__s;n&&n!=this.state||(n=this.__s=y({},this.state)),typeof e==`function`&&(e=e(y({},n),this.props)),e&&(y(n,e),this.__v&&(t&&this.__k.push(t),O(this)))},T.prototype.forceUpdate=function(e){this.__v&&(this.__g|=4,e&&this.__h.push(e),O(this))},T.prototype.render=w,a=[],s=0,c=function(e,t){return e.__v.__b-t.__v.__b},l=Symbol(),u=/(PointerCapture)$|Capture$/i,d=0,f={};var V,H,U,ae,W=Object.is,G=0,oe=[],K=[],q=n,se=q.__b,ce=q.__r,le=q.diffed,ue=q.__c,de=q.unmount,fe=q.__;function J(e,t){q.__h&&q.__h(H,e,G||t),G=0;var n=H.__H||(H.__H={__:[],__h:[]});return e>=n.__.length&&n.__.push({}),n.__[e]}function pe(e){return G=1,me(Se,e)}function me(e,t,n){var r=J(V++,2);if(r.t=e,!r.__c&&(r.__=[n?n(t):Se(void 0,t),function(e){var t=r.__N?r.__N[0]:r.__[0],n=r.t(t,e);W(t,n)||(r.__N=[n,r.__[1]],r.__c.setState({}))}],r.__c=H,!H.__f)){H.__f=!0;var i=H.shouldComponentUpdate;H.shouldComponentUpdate=function(e,t,n){var r=this.__H;if(!r)return!0;var a=!1,o=this.props!=e;if(r.__.some(function(e){e.__N&&(a=!0,W(e.__[0],e.__N[0])||(o=!0))}),i){var s=i.call(this,e,t,n);return a?s||o:s}return!a||o}}return r.__}function he(e,t){var n=J(V++,4);!q.__s&&xe(n.__H,t)&&(n.__P=!1,n.__=e,n.u=t,H.__h.push(n))}function ge(e,t){var n=J(V++,7);return xe(n.__H,t)&&(n.__=e(),n.__H=t),n.__}function _e(){var e;do{for(;e=K.shift();)try{Y(e)}catch(t){q.__e(t,{__:(e=e.__P)&&e.__v})}for(;e=oe.shift();){var t=e.__H;if(e.__P&&t)try{t.__h.some(Y),t.__h.some(X),t.__h=[]}catch(n){t.__h=[],q.__e(n,e.__v)}}}while(K.length)}q.__b=function(e){H=null,se&&se(e)},q.__=function(e,t){e&&t.__k&&t.__k.__m&&(e.__m=t.__k.__m),fe&&fe(e,t)},q.__r=function(e){ce&&ce(e),V=0;var t=(H=e.__c).__H;t&&(U==H?H.__h=[]:(t.__h.some(Y),t.__h.some(X),V=0),t.__h=[],t.__.some(function(e){e.__N&&(e.__=e.__N),e.u=e.__N=void 0})),U=H},q.diffed=function(e){le&&le(e);var t=e.__c;t&&t.__H&&(t.__H.__h.length&&be(oe.push(t)),t.__H.__.some(function(e){e.u&&(e.__H=e.u)})),U=H=null},q.__c=function(e,t){t.some(function(e){try{e.__h.some(Y),e.__h=e.__h.filter(function(e){return!e.__||X(e)})}catch(t){e.__h=[function(){throw t}]}}),ue&&ue(e,t)},q.unmount=function(e){de&&de(e);var t,n,r=e.__c;r&&r.__H&&(r.__H.__.some(function(r){try{if(r.__P&&r.__c){if(n===void 0){for(n=e.__;n&&(!n.__c||!n.__c.__P);)n=n.__;n&&=n.__c}r.__P=n,be(K.push(r))}else Y(r)}catch(e){t=e}}),r.__H=void 0,t&&q.__e(t,r.__v))};var ve=typeof requestAnimationFrame==`function`;function ye(e){var t,n=function(){clearTimeout(r),ve&&cancelAnimationFrame(t),setTimeout(e)},r=setTimeout(n,35);ve&&(t=requestAnimationFrame(n))}function be(e){e!=1&&ae==q.requestAnimationFrame||((ae=q.requestAnimationFrame)||ye)(_e)}function Y(e){var t=H,n=e.__c;typeof n==`function`&&(e.__c=void 0,n()),H=t}function X(e){var t=H;e.__c=e.__(),H=t}function xe(e,t){return!e||e.length!=t.length||t.some(function(t,n){return!W(t,e[n])})}function Se(e,t){return typeof t==`function`?t(e):t}var Z={INVALID_PDF:`INVALID_PDF`,PDF_PASSWORD_REQUIRED:`PDF_PASSWORD_REQUIRED`,PDF_LOAD_FAILED:`PDF_LOAD_FAILED`,CLIENT_KEY_REQUIRED:`CLIENT_KEY_REQUIRED`,CAMERA_INTERRUPTED:`CAMERA_INTERRUPTED`,CAMERA_NOT_FOUND:`CAMERA_NOT_FOUND`,CAMERA_PERMISSION_DENIED:`CAMERA_PERMISSION_DENIED`,CAMERA_UNAVAILABLE:`CAMERA_UNAVAILABLE`,CAMERA_UNSUPPORTED:`CAMERA_UNSUPPORTED`,CAPTURES_INCOMPLETE:`CAPTURES_INCOMPLETE`,DOCUMENT_BACK_CONTAINS_FACE:`DOCUMENT_BACK_CONTAINS_FACE`,DOCUMENT_BACK_NOT_DISTINCT:`DOCUMENT_BACK_NOT_DISTINCT`,DOCUMENT_BACK_REQUIRED:`DOCUMENT_BACK_REQUIRED`,DOCUMENT_BLURRY:`DOCUMENT_BLURRY`,DOCUMENT_FACE_GEOMETRY_INVALID:`DOCUMENT_FACE_GEOMETRY_INVALID`,DOCUMENT_FACE_NOT_CONTAINED:`DOCUMENT_FACE_NOT_CONTAINED`,DOCUMENT_FACE_NOT_FOUND:`DOCUMENT_FACE_NOT_FOUND`,DOCUMENT_NOT_FOUND:`DOCUMENT_NOT_FOUND`,DOCUMENT_NOT_RECOGNIZED:`DOCUMENT_NOT_RECOGNIZED`,DOCUMENT_TEXT_ALIGNMENT_INVALID:`DOCUMENT_TEXT_ALIGNMENT_INVALID`,DOCUMENT_TEXT_NOT_READABLE:`DOCUMENT_TEXT_NOT_READABLE`,DOCUMENT_VALIDATION_FAILED:`DOCUMENT_VALIDATION_FAILED`,FACEKEY_TOKEN_INVALID:`FACEKEY_TOKEN_INVALID`,FACEGATE_TOKEN_INVALID:`FACEGATE_TOKEN_INVALID`,FACEGATE_ABORTED:`FACEGATE_ABORTED`,FACEGATE_TIMEOUT:`FACEGATE_TIMEOUT`,FACE_NOT_FOUND:`FACE_NOT_FOUND`,FACE_MISMATCH:`FACE_MISMATCH`,FACE_NOT_USABLE:`FACE_NOT_USABLE`,IMAGE_ENCODE_FAILED:`IMAGE_ENCODE_FAILED`,IMAGE_PROCESSING_FAILED:`IMAGE_PROCESSING_FAILED`,INVALID_IMAGE:`INVALID_IMAGE`,INVALID_MODEL_OUTPUT:`INVALID_MODEL_OUTPUT`,INVALID_OPTIONS:`INVALID_OPTIONS`,INVALID_POSES:`INVALID_POSES`,INVALID_CLIENT_KEY:`INVALID_CLIENT_KEY`,INVALID_SERVICE_RESPONSE:`INVALID_SERVICE_RESPONSE`,MODEL_LOAD_FAILED:`MODEL_LOAD_FAILED`,NETWORK_ERROR:`NETWORK_ERROR`,REQUEST_TOO_LARGE:`REQUEST_TOO_LARGE`,NO_USABLE_CANDIDATES:`NO_USABLE_CANDIDATES`,NO_USABLE_REFERENCES:`NO_USABLE_REFERENCES`,POSE_BACKGROUND_MISMATCH:`POSE_BACKGROUND_MISMATCH`,POSE_IDENTITY_MISMATCH:`POSE_IDENTITY_MISMATCH`,SERVICE_UNAVAILABLE:`SERVICE_UNAVAILABLE`,SDK_NOT_READY:`SDK_NOT_READY`,SDK_CAPABILITY_NOT_CONFIGURED:`SDK_CAPABILITY_NOT_CONFIGURED`,UI_ELEMENT_NOT_FOUND:`UI_ELEMENT_NOT_FOUND`,VERIFICATION_CANCELLED:`VERIFICATION_CANCELLED`,VERIFICATION_SAVE_FAILED:`VERIFICATION_SAVE_FAILED`},Ce=new Set(Object.values(Z)),we=e=>typeof e==`string`&&Ce.has(e),Te=({error:e,fallback:t=Z.INVALID_SERVICE_RESPONSE})=>typeof e==`object`&&e&&`code`in e&&we(e.code)?e.code:e instanceof Error&&we(e.message)?e.message:we(e)?e:t,Ee=[`ar`,`ch`,`de`,`en`,`es`,`fr`,`it`,`ja`,`pt`,`ru`,`zh`],Q=new Map,De=new Map,Oe=async({language:e})=>{if(Q.has(e))return;let n=De.get(e);n||(n=fetch(t({filename:`locales/${e}.json`})).then(async e=>{if(!e.ok)throw Error(Z.INVALID_SERVICE_RESPONSE);return await e.json()}),De.set(e,n));try{Q.set(e,await n)}finally{De.delete(e)}},ke=async({language:e})=>{let t=e??Ae();await Promise.all([Oe({language:t}),...t===`en`?[]:[Oe({language:`en`})]])},Ae=()=>{let e=[navigator.language,...navigator.languages];for(let t of e){let e=t.toLowerCase();if(/^zh-(hk|mo|tw)\b/u.test(e))return`ch`;let n=e.split(`-`)[0];if(Ee.includes(n))return n}return`en`},je={[Z.CAMERA_PERMISSION_DENIED]:`cameraPermissionDenied`,[Z.CAMERA_NOT_FOUND]:`cameraNotFound`,[Z.CAMERA_UNAVAILABLE]:`cameraUnavailable`,[Z.CAMERA_UNSUPPORTED]:`cameraUnavailable`,[Z.CAMERA_INTERRUPTED]:`cameraUnavailable`,[Z.NETWORK_ERROR]:`networkError`,[Z.SERVICE_UNAVAILABLE]:`serviceUnavailable`,[Z.MODEL_LOAD_FAILED]:`modelLoadFailed`,[Z.FACE_NOT_FOUND]:`faceNotFound`,[Z.NO_USABLE_CANDIDATES]:`faceNotFound`,[Z.FACE_NOT_USABLE]:`faceNotUsable`,[Z.NO_USABLE_REFERENCES]:`faceNotUsable`,[Z.DOCUMENT_NOT_FOUND]:`frameDocument`,[Z.DOCUMENT_NOT_RECOGNIZED]:`invalidDocument`,[Z.DOCUMENT_TEXT_NOT_READABLE]:`documentNotReadable`,[Z.DOCUMENT_BLURRY]:`documentBlurry`,[Z.DOCUMENT_FACE_NOT_FOUND]:`faceNotVisibleInDocument`,[Z.DOCUMENT_FACE_NOT_CONTAINED]:`documentAlignmentInvalid`,[Z.DOCUMENT_FACE_GEOMETRY_INVALID]:`documentAlignmentInvalid`,[Z.DOCUMENT_TEXT_ALIGNMENT_INVALID]:`documentAlignmentInvalid`,[Z.DOCUMENT_BACK_REQUIRED]:`frameDocumentBack`,[Z.CAPTURES_INCOMPLETE]:`capturesIncomplete`,[Z.DOCUMENT_VALIDATION_FAILED]:`documentValidationFailed`,[Z.INVALID_OPTIONS]:`invalidOptions`,[Z.INVALID_POSES]:`invalidPoses`,[Z.INVALID_SERVICE_RESPONSE]:`invalidServiceResponse`,[Z.POSE_BACKGROUND_MISMATCH]:`poseBackgroundMismatch`,[Z.POSE_IDENTITY_MISMATCH]:`poseIdentityMismatch`,[Z.IMAGE_ENCODE_FAILED]:`imageEncodeFailed`,[Z.IMAGE_PROCESSING_FAILED]:`imageProcessingFailed`,[Z.INVALID_IMAGE]:`invalidImage`,[Z.INVALID_PDF]:`invalidPdf`,[Z.PDF_PASSWORD_REQUIRED]:`pdfPasswordRequired`,[Z.PDF_LOAD_FAILED]:`pdfLoadFailed`,[Z.CLIENT_KEY_REQUIRED]:`clientKeyRequired`,[Z.VERIFICATION_SAVE_FAILED]:`verificationSaveFailed`},Me=({language:e})=>{let t=e??Ae(),n=e=>{let n=Q.get(t),r=Q.get(`en`);return n?.[e]??r?.[e]??e};return{translate:n,translateError:({error:e})=>{let t=je[Te({error:e})]??`verificationFailed`;return n(t)}}},Ne=async({milliseconds:e})=>{let t=Promise.withResolvers();setTimeout(()=>t.resolve(),e),await t.promise},$=new WeakMap,Pe=async({video:e,signal:t})=>{t?.throwIfAborted();let n=Promise.withResolvers(),r=e,i=$.get(e)??new Set,a=null,o=null,s=!1,c=c=>{s||(s=!0,a!==null&&r.cancelVideoFrameCallback?.(a),o!==null&&cancelAnimationFrame(o),t?.removeEventListener(`abort`,u),i.delete(l),i.size||$.delete(e),c?n.reject(c):n.resolve())},l=()=>c(new DOMException(Z.VERIFICATION_CANCELLED,`AbortError`)),u=()=>c(new DOMException(Z.VERIFICATION_CANCELLED,`AbortError`));i.add(l),$.set(e,i),t?.addEventListener(`abort`,u,{once:!0}),r.requestVideoFrameCallback?a=r.requestVideoFrameCallback(()=>c()):o=requestAnimationFrame(()=>c()),await n.promise},Fe=()=>{let e=/Android|iPhone|iPad|iPod|Mobile/i.test(navigator.userAgent),t=navigator.platform===`MacIntel`&&navigator.maxTouchPoints>1;return e||t},Ie=async()=>{let e=[],t=(t,n)=>{n||e.push(t)};if(t(`navigator.mediaDevices.getUserMedia`,typeof navigator.mediaDevices==`object`&&typeof navigator.mediaDevices.getUserMedia==`function`),t(`navigator.mediaDevices.enumerateDevices`,typeof navigator.mediaDevices==`object`&&typeof navigator.mediaDevices.enumerateDevices==`function`),t(`MediaStream`,typeof MediaStream<`u`),t(`MediaStreamTrack`,typeof MediaStreamTrack<`u`),t(`HTMLVideoElement`,typeof HTMLVideoElement<`u`),t(`createImageBitmap`,typeof createImageBitmap==`function`),t(`OffscreenCanvas`,typeof OffscreenCanvas<`u`),t(`OffscreenCanvas.getContext`,typeof OffscreenCanvas<`u`&&typeof OffscreenCanvas.prototype.getContext==`function`),t(`OffscreenCanvas.convertToBlob`,typeof OffscreenCanvas<`u`&&typeof OffscreenCanvas.prototype.convertToBlob==`function`),t(`WebAssembly`,typeof WebAssembly<`u`),t(`fetch`,typeof fetch==`function`),t(`Blob`,typeof Blob<`u`),t(`File`,typeof File<`u`),t(`URL.createObjectURL`,typeof URL.createObjectURL==`function`),t(`URL.revokeObjectURL`,typeof URL.revokeObjectURL==`function`),!e.includes(`OffscreenCanvas`)&&!e.includes(`OffscreenCanvas.getContext`)&&!e.includes(`OffscreenCanvas.convertToBlob`))try{let e=new OffscreenCanvas(1,1),n=e.getContext(`2d`);if(t(`OffscreenCanvas 2D context`,n!==null),n&&typeof createImageBitmap==`function`){let n=await e.convertToBlob({type:`image/jpeg`});t(`JPEG encoding`,n.type===`image/jpeg`),n.type===`image/jpeg`&&((await createImageBitmap(n)).close(),t(`JPEG decoding`,!0))}else t(`JPEG encoding`,!1),t(`JPEG decoding`,!1)}catch{e.includes(`JPEG encoding`)||t(`JPEG encoding`,!1),t(`JPEG decoding`,!1)}else t(`JPEG encoding`,!1),t(`JPEG decoding`,!1);return{supported:e.length===0,unsupportedFeatures:e}},Le=({video:e})=>{for(let t of $.get(e)??[])t();let t=e.srcObject;if(t instanceof MediaStream)for(let e of t.getTracks())e.stop();e.srcObject=null},Re=async({facingMode:e,video:t,signal:n})=>{if(!navigator.mediaDevices||typeof navigator.mediaDevices.getUserMedia!=`function`)throw Error(Z.CAMERA_UNSUPPORTED);let r={facingMode:{ideal:e}};Fe()||(r.width={ideal:1280},r.height={ideal:720});let i=()=>Le({video:t});n?.addEventListener(`abort`,i,{once:!0});try{let i=await navigator.mediaDevices.getUserMedia({video:r,audio:!1});if(n?.aborted){for(let e of i.getTracks())e.stop();n.throwIfAborted()}t.srcObject=i;let a=(await navigator.mediaDevices.enumerateDevices()).filter(({kind:e})=>e===`videoinput`).length>1?e:`user`;return await t.play(),n?.throwIfAborted(),a}catch(e){if(Le({video:t}),n?.aborted)throw new DOMException(Z.VERIFICATION_CANCELLED,`AbortError`);let r=e instanceof Error?e.name:``,i=Z.CAMERA_UNAVAILABLE;throw(r===`NotAllowedError`||r===`SecurityError`)&&(i=Z.CAMERA_PERMISSION_DENIED),r===`NotFoundError`&&(i=Z.CAMERA_NOT_FOUND),r===`AbortError`&&(i=Z.CAMERA_INTERRUPTED),Error(i,{cause:e})}finally{n?.removeEventListener(`abort`,i)}},ze=({element:e})=>{let t=e.getContext(`2d`);if(!t)throw Error(Z.IMAGE_PROCESSING_FAILED);t.clearRect(0,0,e.width,e.height)},Be=async({canvas:e,quality:t})=>{try{let n=await e.convertToBlob({type:`image/jpeg`,quality:t});if(n.type!==`image/jpeg`)throw Error(Z.IMAGE_ENCODE_FAILED);return n}catch(e){throw Error(Z.IMAGE_ENCODE_FAILED,{cause:e})}},Ve=async({frame:e})=>{let t=new OffscreenCanvas(e.width,e.height),n=t.getContext(`2d`);if(!n)throw Error(Z.IMAGE_PROCESSING_FAILED);return n.drawImage(e,0,0),await Be({canvas:t})},He=async({blob:e})=>{let t;try{t=await createImageBitmap(e)}catch(e){throw Error(Z.INVALID_IMAGE,{cause:e})}try{let e=Math.min(1,900/Math.max(t.width,t.height)),n=new OffscreenCanvas(Math.max(1,Math.round(t.width*e)),Math.max(1,Math.round(t.height*e))),r=n.getContext(`2d`);if(!r)throw Error(Z.IMAGE_PROCESSING_FAILED);return r.drawImage(t,0,0,n.width,n.height),await Be({canvas:n,quality:.85})}finally{t.close()}},Ue=async({frame:e})=>{let t=Math.min(1,960/Math.max(e.width,e.height)),n=Math.max(1,Math.round(e.width*t)),r=Math.max(1,Math.round(e.height*t));return await createImageBitmap(e,{resizeWidth:n,resizeHeight:r})},We=async({image:e})=>{let t=new Uint8Array(await e.arrayBuffer()),n=``;for(let e=0;e<t.length;e+=32768)n+=String.fromCharCode(...t.subarray(e,e+32768));return`data:image/jpeg;base64,${btoa(n)}`};export{n as C,t as D,e as E,x as S,T,pe as _,We as a,ie as b,Ue as c,Ae as d,ke as f,he as g,Te as h,Ve as i,Pe as l,Z as m,ze as n,Re as o,Ne as p,He as r,Le as s,Ie as t,Me as u,ge as v,i as w,w as x,C as y};
|