@voltom.io/sdk 1.0.5 → 1.0.6
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/sdk/{PoseSilhouette-Bbwmry4Z.js → PoseSilhouette-V9BxuMwo.js} +1 -1
- package/dist/sdk/{PoseSuccess-C3aBF88E.js → PoseSuccess-DDx23oJD.js} +1 -1
- package/dist/sdk/eyeLevelCamera-aDRPs63K.js +65 -0
- package/dist/sdk/facegate/global.d.ts +1 -1
- package/dist/sdk/facegate.d.ts +23 -6
- package/dist/sdk/facegate.dist.js +5 -5
- package/dist/sdk/facegate.js +1 -1
- package/dist/sdk/facekey.browser-bs8vp3ON.js +2 -0
- package/dist/sdk/facekey.d.ts +37 -23
- package/dist/sdk/facekey.dist.js +6 -6
- package/dist/sdk/facekey.js +1 -1
- package/dist/sdk/media-Cejmtltt.js +2 -0
- package/dist/sdk/{presentation-BsnbDv0i.js → presentation-B4P1537m.js} +1 -1
- package/dist/sdk/presentation-Cg1Ec60l.js +8 -0
- package/dist/sdk/verify.d.ts +23 -6
- package/dist/sdk/verify.dist.js +18 -18
- package/dist/sdk/verify.js +1 -1
- package/dist/sdk/view-DTvcOVnH.js +3 -0
- package/dist/sdk/view-ObOGpVdZ.js +3 -0
- package/dist/sdk/view-iMF-mWfw.js +2 -0
- package/package.json +5 -4
- package/dist/sdk/eyeLevelCamera-DY4onSBz.js +0 -65
- package/dist/sdk/facekey.browser-CVJiBw1f.js +0 -2
- package/dist/sdk/media-BRKPXpu3.js +0 -2
- package/dist/sdk/presentation-B-TOKUZ3.js +0 -8
- package/dist/sdk/view-Bfg8u_hZ.js +0 -2
- package/dist/sdk/view-CHSkN6gO.js +0 -3
- package/dist/sdk/view-DmGKdc3M.js +0 -3
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{D as e,O as t,Y as n,a as r,d as i,et as a,f as o,i as s,l as c,n as l,o as u,r as d,s as f,t as p,tt as m,u as h,y as g}from"./eyeLevelCamera-DY4onSBz.js";import{D as _,a as v,c as y,d as b,h as x,i as S,p as C,s as w,t as T,u as E}from"./media-BRKPXpu3.js";import{n as D,r as O,t as k}from"./facekey.browser-CVJiBw1f.js";import{t as A}from"./presentation-BsnbDv0i.js";var j=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(x.INVALID_OPTIONS);return e},M=e=>e.length===512&&e.every(e=>Number.isFinite(e))&&Math.abs(Math.hypot(...e)-1)<.001?e:null,N=({pose:e,rejection:t,language:n})=>{let{translate:r}=b({language:n});return r(t?o({code:t}):i({pose:e}).primary)},{detectDocumentBox:P,loadDocumentBoxDetector:F}=k,{detectPictureFaces:I,loadFaceDetector:L}=D,{imageBitmap:R,loadFaceMatch:z,preparedFaceGrayscaleEmbedding:B,prepareFace:V,warmupFaceMatch:H}=O,U=({face:e})=>e?{left:e.blendshapes.eyeBlinkLeft??0,right:e.blendshapes.eyeBlinkRight??0}:null,W=({face:e,frame:t})=>e.boundingRect.height/Math.min(t.width,t.height)<.5?`FACE_TOO_SMALL`:null,G=({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},K=async({frame:n,pose:r,signal:i,neutral:a,requireEyeLevelCamera:o,language:s})=>{let c=await I(n);i.throwIfAborted();let u=c.length===1?c[0]:null,f=u?await P(n):null;i.throwIfAborted();let m=!!(u&&f&&e({face:u,polygon:f.polygon})),h=!!(u&&W({face:u,frame:n})),g=!!(u&&G({face:u,frame:n})),_=u?{pitch:u.pitch,yaw:u.yaw,roll:u.roll}:null,v=_?d({alignment:_,blendshapes:u?.blendshapes??{},neutral:a,pose:r,options:t}):null,y=u?l({pitch:u.pitch,pose:r,requireEyeLevelCamera:o,options:t}):null,x=null,S=`Keep one face in view`;if(u&&(S=null,m?S=`In polygon`:h?S=`Face too small`:g?v?.code&&(S=v.code):S=`Center your face in the circle`),!u)x=`FACE_NOT_DETECTED`;else if(m)x=`FACE_IN_POLYGON`;else if(h)x=`FACE_TOO_SMALL`;else if(!g)x=`FACE_NOT_CENTERED`;else if(y){let{translate:e}=b({language:s});x=y,S=e(p())}return{faces:c,face:u,faceInPolygon:m,centered:g,framing:x,guidance:v,alignment:_,reason:S}},q=async({capture:e,requireEyeLevelCamera:t,neutral:n,pose:r,signal:i,language:a})=>{let o=await R({blob:e});try{i.throwIfAborted();let e=await K({frame:o,pose:r,signal:i,neutral:n,requireEyeLevelCamera:t,language:a}),{face:s,guidance:c}=e,l=U({face:s}),u=c?.code&&e.reason===c.code?N({pose:r,rejection:c.code,language:a}):e.reason;if(!s||u)return{vector:null,reason:u,eyeScores:l};let d=V({alignment:`eyes-nose-mouth`,face:s,frame:o}),f=d?await B({face:d}):null;if(i.throwIfAborted(),!f)return{vector:null,reason:x.FACE_NOT_USABLE,eyeScores:l};let p=M(f);return{vector:p,reason:p?null:x.INVALID_MODEL_OUTPUT,eyeScores:l}}finally{o.close()}},J=class{options;view=null;useUi;display=A();events=new EventTarget;controller=null;operationId=``;neutralPose=null;guidanceCodeState=r();correctiveState=s();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(x.INVALID_OPTIONS);this.options=Object.freeze({...e,requireEyeLevelCamera:e.requireEyeLevelCamera??!1,capabilities:Object.freeze([...e.capabilities??[`enroll`,`unlock`]])})}async caniuse(){return await T()}async preload(){if(this.disposed)throw Error(x.SDK_NOT_READY);if(this.preloading)return this.preloading;let e=(async()=>{await C({language:this.options.language}),this.options.capabilities.length>0&&await n({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(x.SDK_NOT_READY)}catch(t){throw this.preloading===e&&(this.preloading=null),t}}async prepare(){if(this.disposed)throw Error(x.SDK_NOT_READY);if(this.prepared)return;if(await this.preload(),this.useUi&&!this.view){let{createFaceKeyView:e}=await import(`./view-CHSkN6gO.js`);if(this.disposed)throw Error(x.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([F(),L({faceDetector:`standard`}),z()]).then(async()=>{let e=document.createElement(`canvas`);e.width=640,e.height=480;let t=await createImageBitmap(e);try{await Promise.all([I(t),P(t),H()])}finally{t.close()}}):Promise.resolve();this.modelsReady=e}let e=this.modelsReady;try{if(await e,this.disposed)throw Error(x.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:x.INVALID_SERVICE_RESPONSE);return o}async capture({poses:e,signal:t,expiresAt:n,operation:i,input:o}){let l=this.useUi?this.view?.requiredVideo():this.options.video;if(!l)throw Error(x.INVALID_OPTIONS);let{translate:d}=b({language:this.options.language}),p=[];this.display.progress.value={completed:0,total:e.length},this.neutralPose=null,this.guidanceCodeState=r(),this.correctiveState=s();let m=null,_={userId:o.userId??``,matched:!1,matches:[],reason:null},C=o.token;t.throwIfAborted();let T=await w({facingMode:`user`,video:l,signal:t});t.throwIfAborted(),this.display.facingMode.value=T,this.display.phase.value=`capturing`;for(let[y,b]of e.entries()){let w=0,T=null;for(this.guidanceCodeState=r(),this.correctiveState=s(),a(()=>{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 E({video:l,signal:t}),t.throwIfAborted(),Date.now()>=Date.parse(n))throw Error(x.FACEKEY_TOKEN_INVALID);if(l.readyState<HTMLMediaElement.HAVE_CURRENT_DATA)continue;let r=await createImageBitmap(l);try{let s=await K({frame:r,pose:b,signal:t,neutral:this.neutralPose,requireEyeLevelCamera:this.options.requireEyeLevelCamera??!1,language:this.options.language}),{framing:l,guidance:E}=s,D=E?.code??null;if(w=l===null&&D===null?w+1:0,b===`faceStraight`&&D===null&&l===null&&(this.neutralPose=s.alignment),E){this.guidanceCodeState=f({state:this.guidanceCodeState,code:E.code,requiredFrames:3});let e=this.guidanceCodeState.published,t=c({pose:b,code:e}).corrective,n=performance.now();this.correctiveState=u({label:t,now:n,state:this.correctiveState}),this.display.guidance.value={...E,code:e},this.display.corrective.value=h({label:t,now:n,state:this.correctiveState})}let O={...s,frame:r,operation:i,pose:b,poseRejection:D,stable:w};if(this.view?.collectCaptureDebug(O),this.display.instruction.value={framing:l,retry:T},w===3){let s=await S({frame:r});try{if(i===`unlock`){this.display.phase.value=`checking`;let n={token:C,userId:_.userId,poses:[b],faces:[await v({image:s})]},r=await this.request({path:`unlock/step`,input:{...o,token:C},body:n,signal:t});if(r.userId!==_.userId||r.matched&&(r.matches.length!==1||r.matches[0].pose!==b||!r.matches[0].matched))throw Error(x.INVALID_SERVICE_RESPONSE);if(this.display.match.value={accepted:r.matched,reason:r.reason,score:r.matches.length?r.matches[0].score:null},this.view?.collectCaptureDebug({...O,force:!0,reason:r.reason}),!r.matched){if(r.complete||!r.token)throw Error(x.INVALID_SERVICE_RESPONSE);C=r.token,w=0,T=d(`faceRetryPose`),a(()=>{this.display.phase.value=`capturing`,this.display.instruction.value={framing:l,retry:T}}),await this.showFeedback({matched:!1,signal:t});continue}if(_={userId:r.userId,matched:r.complete,matches:[..._.matches,...r.matches],reason:r.reason},r.complete!==(y===e.length-1))throw Error(x.INVALID_SERVICE_RESPONSE);if(!r.complete){if(!r.token)throw Error(x.INVALID_SERVICE_RESPONSE);C=r.token}}else{let e=await q({capture:s,requireEyeLevelCamera:this.options.requireEyeLevelCamera??!1,pose:b,signal:t,language:this.options.language,neutral:this.neutralPose}),r=e.vector;if(t.throwIfAborted(),Date.now()>=Date.parse(n))throw Error(x.FACEKEY_TOKEN_INVALID);let i=m&&r?g({first:m,second:r}):null,o=!!(r&&(i===null||i>.5)),c=e.reason??(o?null:x.POSE_IDENTITY_MISMATCH);if(this.display.match.value={accepted:o,reason:c,reference:!m&&o,score:i},this.view?.collectCaptureDebug({...O,force:!0,reason:c}),!r||!o){w=0,T=d(r?`faceRetryMatch`:`faceRetryUsable`),a(()=>{this.display.phase.value=`capturing`,this.display.instruction.value={framing:l,retry:T}}),r&&await this.showFeedback({matched:!1,signal:t});continue}m||=r}p.push(s)}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{r.close()}}this.display.progress.value={completed:y+1,total:e.length},await this.showFeedback({matched:!0,signal:t})}return y({video:l}),{captures:p,unlock:_}}async showFeedback({matched:e,signal:t}){t.throwIfAborted();let n=this.operationId;a(()=>{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),o=()=>r.resolve();t.addEventListener(`abort`,o,{once:!0});try{await r.promise,t.throwIfAborted()}finally{clearTimeout(i),t.removeEventListener(`abort`,o),this.operationId===n&&(this.display.feedback.value=e?null:{matched:!1,animating:!1})}}async run({operation:e,input:t,externalSignal:n,debug:r}){if(this.disposed||!this.prepared)throw Error(x.SDK_NOT_READY);if(!this.options.capabilities.includes(e))throw Error(x.SDK_CAPABILITY_NOT_CONFIGURED);if(this.controller)throw Error(x.INVALID_OPTIONS);let i=j(t);if(e!==`enroll`&&!i.userId)throw Error(x.INVALID_OPTIONS);let o=new AbortController;this.controller=o;let s=o.signal,c=()=>o.abort();n?.addEventListener(`abort`,c,{once:!0}),n?.aborted&&c();let l=[];this.operationId=crypto.randomUUID();try{a(()=>{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=r??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:i,signal:s});if(t.operation!==e||i.userId&&t.userId!==i.userId)throw Error(x.FACEKEY_TOKEN_INVALID);let n=await this.capture({poses:t.poses,signal:s,expiresAt:t.expiresAt,operation:e,input:{...i,userId:t.userId}});l.push(...n.captures),s.throwIfAborted();let o=n.unlock;if(e===`enroll`){this.display.phase.value=`processing`;let n={token:i.token,userId:t.userId,poses:t.poses,faces:await Promise.all(l.map(e=>v({image:e})))};o=await this.request({path:e,input:i,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&&a(()=>{this.display.phase.value=`failure`,this.display.error.value=e}),e}finally{n?.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&&y({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(x.VERIFICATION_CANCELLED,`AbortError`));let e=this.useUi?this.view?.dialog?.open?this.view.requiredVideo():null:this.options.video;e&&y({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(x.SDK_NOT_READY);let t=m(()=>e(this.getState()));return this.subscriptions.add(t),()=>{t(),this.subscriptions.delete(t)}}};_({moduleUrl:import.meta.url});var Y=J;export{J as VoltomFaceKey,Y as default};
|
|
2
|
+
import{$ as e,C as t,E as n,Q as r,T as i,a,d as o,f as s,i as c,l,n as u,o as d,q as f,r as p,s as m,t as h,u as g,y as _}from"./eyeLevelCamera-aDRPs63K.js";import{O as v,a as y,c as b,f as x,g as S,i as C,m as w,s as T,t as E,u as D}from"./media-Cejmtltt.js";import{n as O,r as k,t as A}from"./facekey.browser-bs8vp3ON.js";import{t as j}from"./presentation-B4P1537m.js";var M=e=>e===`enroll`||e===`unlock`,N=e=>{if(typeof e.token!=`string`||e.token.length<32||e.token.length>128||!M(e.action)||typeof e.subjectId!=`string`||e.subjectId.length<1||e.subjectId.length>255)throw Error(S.INVALID_OPTIONS);let n=e.poses??[...t];if(!Array.isArray(n)||n.length<1||n.length>t.length)throw Error(S.INVALID_OPTIONS);return{...e,poses:n}},P=e=>e.length===512&&e.every(e=>Number.isFinite(e))&&Math.abs(Math.hypot(...e)-1)<.001?e:null,F=({pose:e,rejection:t,language:n})=>{let{translate:r}=x({language:n});return r(t?s({code:t}):o({pose:e}).primary)},{detectDocumentBox:I,loadDocumentBoxDetector:L}=A,{detectPictureFaces:R,loadFaceDetector:z}=O,{imageBitmap:B,loadFaceMatch:V,preparedFaceGrayscaleEmbedding:H,prepareFace:U,warmupFaceMatch:W}=k,G=({face:e})=>e?{left:e.blendshapes.eyeBlinkLeft??0,right:e.blendshapes.eyeBlinkRight??0}:null,K=({face:e,frame:t})=>e.boundingRect.height/Math.min(t.width,t.height)<.5?`FACE_TOO_SMALL`:null,q=({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},J=async({frame:e,pose:t,signal:r,neutral:a,requireEyeLevelCamera:o,language:s})=>{let c=await R(e);r.throwIfAborted();let l=c.length===1?c[0]:null,d=l?await I(e):null;r.throwIfAborted();let f=!!(l&&d&&i({face:l,polygon:d.polygon})),m=!!(l&&K({face:l,frame:e})),g=!!(l&&q({face:l,frame:e})),_=l?{pitch:l.pitch,yaw:l.yaw,roll:l.roll}:null,v=_?p({alignment:_,blendshapes:l?.blendshapes??{},neutral:a,pose:t,options:n}):null,y=l?u({pitch:l.pitch,pose:t,requireEyeLevelCamera:o,options:n}):null,b=null,S=`Keep one face in view`;if(l&&(S=null,f?S=`In polygon`:m?S=`Face too small`:g?v?.code&&(S=v.code):S=`Center your face in the circle`),!l)b=`FACE_NOT_DETECTED`;else if(f)b=`FACE_IN_POLYGON`;else if(m)b=`FACE_TOO_SMALL`;else if(!g)b=`FACE_NOT_CENTERED`;else if(y){let{translate:e}=x({language:s});b=y,S=e(h())}return{faces:c,face:l,faceInPolygon:f,centered:g,framing:b,guidance:v,alignment:_,reason:S}},Y=async({capture:e,requireEyeLevelCamera:t,neutral:n,pose:r,signal:i,language:a})=>{let o=await B({blob:e});try{i.throwIfAborted();let e=await J({frame:o,pose:r,signal:i,neutral:n,requireEyeLevelCamera:t,language:a}),{face:s,guidance:c}=e,l=G({face:s}),u=c?.code&&e.reason===c.code?F({pose:r,rejection:c.code,language:a}):e.reason;if(!s||u)return{vector:null,reason:u,eyeScores:l};let d=U({alignment:`eyes-nose-mouth`,face:s,frame:o}),f=d?await H({face:d}):null;if(i.throwIfAborted(),!f)return{vector:null,reason:S.FACE_NOT_USABLE,eyeScores:l};let p=P(f);return{vector:p,reason:p?null:S.INVALID_MODEL_OUTPUT,eyeScores:l}}finally{o.close()}},X=class{options;view=null;display=j();events=new EventTarget;controller=null;operationId=``;neutralPose=null;guidanceCodeState=a();correctiveState=c();modelsReady=null;preloading=null;prepared=!1;disposed=!1;subscriptions=new Set;constructor(e){let{prepare:t=!0,...n}=e;this.options=Object.freeze({...n,requireEyeLevelCamera:n.requireEyeLevelCamera??!1,capabilities:Object.freeze([...n.capabilities??[`enroll`,`unlock`]])}),t&&this.prepare().catch(e=>console.error(e))}async caniuse(){return await E()}async preload(){if(this.disposed)throw Error(S.SDK_NOT_READY);if(this.preloading)return this.preloading;let e=(async()=>{await w({language:this.options.language}),this.options.capabilities.length>0&&await f({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(S.SDK_NOT_READY)}catch(t){throw this.preloading===e&&(this.preloading=null),t}}async prepare(){if(this.disposed)throw Error(S.SDK_NOT_READY);if(this.prepared)return;if(await this.preload(),!this.view){let{createFaceKeyView:e}=await import(`./view-DTvcOVnH.js`);if(this.disposed)throw Error(S.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([L(),z({faceDetector:`standard`}),V()]).then(async()=>{let e=document.createElement(`canvas`);e.width=640,e.height=480;let t=await createImageBitmap(e);try{await Promise.all([R(t),I(t),W()])}finally{t.close()}}):Promise.resolve();this.modelsReady=e}let e=this.modelsReady;try{if(await e,this.disposed)throw Error(S.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:S.INVALID_SERVICE_RESPONSE);return o}async capture({poses:e,signal:t,expiresAt:n,operation:i}){let o=this.view?.requiredVideo();if(!o)throw Error(S.INVALID_OPTIONS);let{translate:s}=x({language:this.options.language}),u=[];this.display.progress.value={completed:0,total:e.length},this.neutralPose=null,this.guidanceCodeState=a(),this.correctiveState=c();let f=null;t.throwIfAborted();let p=await T({facingMode:`user`,video:o,signal:t});t.throwIfAborted(),this.display.facingMode.value=p,this.display.phase.value=`capturing`;for(let[p,h]of e.entries()){let v=0,y=null;for(this.guidanceCodeState=a(),this.correctiveState=c(),r(()=>{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}});v<3;){if(await D({video:o,signal:t}),t.throwIfAborted(),Date.now()>=Date.parse(n))throw Error(S.FACEKEY_TOKEN_INVALID);if(o.readyState<HTMLMediaElement.HAVE_CURRENT_DATA)continue;let e=await createImageBitmap(o);try{let a=await J({frame:e,pose:h,signal:t,neutral:this.neutralPose,requireEyeLevelCamera:this.options.requireEyeLevelCamera??!1,language:this.options.language}),{framing:o,guidance:c}=a,p=c?.code??null;if(v=o===null&&p===null?v+1:0,h===`faceStraight`&&p===null&&o===null&&(this.neutralPose=a.alignment),c){this.guidanceCodeState=m({state:this.guidanceCodeState,code:c.code,requiredFrames:3});let e=this.guidanceCodeState.published,t=l({pose:h,code:e}).corrective,n=performance.now();this.correctiveState=d({label:t,now:n,state:this.correctiveState}),this.display.guidance.value={...c,code:e},this.display.corrective.value=g({label:t,now:n,state:this.correctiveState})}let b={...a,frame:e,operation:i,pose:h,poseRejection:p,stable:v};if(this.view?.collectCaptureDebug(b),this.display.instruction.value={framing:o,retry:y},v===3){let i=await C({frame:e});try{let e=await Y({capture:i,requireEyeLevelCamera:this.options.requireEyeLevelCamera??!1,pose:h,signal:t,language:this.options.language,neutral:this.neutralPose}),a=e.vector;if(t.throwIfAborted(),Date.now()>=Date.parse(n))throw Error(S.FACEKEY_TOKEN_INVALID);let c=f&&a?_({first:f,second:a}):null,l=!!(a&&(c===null||c>.5)),d=e.reason??(l?null:S.POSE_IDENTITY_MISMATCH);if(this.display.match.value={accepted:l,reason:d,reference:!f&&l,score:c},this.view?.collectCaptureDebug({...b,force:!0,reason:d}),!a||!l){v=0,y=s(a?`faceRetryMatch`:`faceRetryUsable`),r(()=>{this.display.phase.value=`capturing`,this.display.instruction.value={framing:o,retry:y}}),a&&await this.showFeedback({matched:!1,signal:t});continue}f||=a,u.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({...b,force:!0,reason:t}),e}}}finally{e.close()}}this.display.progress.value={completed:p+1,total:e.length},await this.showFeedback({matched:!0,signal:t})}return b({video:o}),{captures:u}}async showFeedback({matched:e,signal:t}){t.throwIfAborted();let n=this.operationId;r(()=>{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===n&&(this.display.feedback.value=e?null:{matched:!1,animating:!1})}}async run({operation:e,input:t,externalSignal:n,debug:i}){if(this.disposed)throw Error(S.SDK_NOT_READY);if(await this.prepare(),!this.options.capabilities.includes(e))throw Error(S.SDK_CAPABILITY_NOT_CONFIGURED);if(this.controller)throw Error(S.INVALID_OPTIONS);let a=N(t);if(a.action!==e)throw Error(S.FACEKEY_TOKEN_INVALID);let o=new AbortController;this.controller=o;let s=o.signal,c=()=>o.abort();n?.addEventListener(`abort`,c,{once:!0}),n?.aborted&&c();let l=[];this.operationId=crypto.randomUUID();try{r(()=>{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.capture({poses:a.poses,signal:s,expiresAt:a.expiresAt,operation:e});l.push(...t.captures),s.throwIfAborted(),this.display.phase.value=`processing`;let n={token:a.token,subjectId:a.subjectId,poses:a.poses,faces:await Promise.all(l.map(e=>y({image:e})))},o=await this.request({path:e,input:{token:a.token,subjectId:a.subjectId},body:n,signal:s});`matched`in o&&(this.display.match.value={accepted:o.matched,reason:o.reason,score:o.matches[0]?.score??null});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&&r(()=>{this.display.phase.value=`failure`,this.display.error.value=e}),e}finally{n?.removeEventListener(`abort`,c),this.display.debugEnabled.value=this.options.debug??!1,l.length=0;let e=this.view?.dialog?.open?this.view.requiredVideo():null;e&&b({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(S.VERIFICATION_CANCELLED,`AbortError`));let e=this.view?.dialog?.open?this.view.requiredVideo():null;e&&b({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(S.SDK_NOT_READY);let n=e(()=>t(this.getState()));return this.subscriptions.add(n),()=>{n(),this.subscriptions.delete(n)}}};v({moduleUrl:import.meta.url});var Z=X;export{X as VoltomFaceKey,Z 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,L(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&&R(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)),ie(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,L=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=te(d,o):o.push(d),c=o[0]||c),(d=n.__b)&&d(t);n:if(typeof L==`function`){m=s.length;try{if(C=t.props,D=(d=L.prototype)&&d.render,O=(d=L.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 L(C,k):(t.__c=g=new T(C,k),g.constructor=L,g.render=ae),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),L.getDerivedStateFromProps&&(g.__s==g.state&&(g.__s=y({},g.__s)),y(g.__s,L.getDerivedStateFromProps(C,g.__s)))),v=g.props,x=g.state,g.__v=t,r.__c){if(C!==v&&D&&!L.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&&!L.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&&ie(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=te(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||ne(t),n.__e(e,t,r)}}else c=t.__e=re(r.__e,t,r,i,a,o,s,l,u,e);return(d=n.diffed)&&d(t),c}function te(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 ne(e){e&&(e.__c&&(e.__c.__g|=4),e.__k&&e.__k.some(ne))}function L(e,t,r){for(var i=0;i<r.length;)R(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 re(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 R(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 ie(e,t,r){var i,a,o,s;if(n.unmount&&n.unmount(e),!(i=e.ref)||i.current&&i.current!=e.__e||R(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]&&ie(i[s],t,typeof e.type!=`function`||r&&!e.props.__P);!r&&(i=e.__c)&&(i=i.__z)&&(a=te(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 ae(e,t,n){return this.constructor(e,n)}function oe(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),L(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 z,B,V,se,H=Object.is,U=0,ce=[],W=[],G=n,le=G.__b,ue=G.__r,de=G.diffed,fe=G.__c,pe=G.unmount,me=G.__;function K(e,t){G.__h&&G.__h(B,e,U||t),U=0;var n=B.__H||(B.__H={__:[],__h:[]});return e>=n.__.length&&n.__.push({}),n.__[e]}function he(e){return U=1,ge(we,e)}function ge(e,t,n){var r=K(z++,2);if(r.t=e,!r.__c&&(r.__=[n?n(t):we(void 0,t),function(e){var t=r.__N?r.__N[0]:r.__[0],n=r.t(t,e);H(t,n)||(r.__N=[n,r.__[1]],r.__c.setState({}))}],r.__c=B,!B.__f)){B.__f=!0;var i=B.shouldComponentUpdate;B.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,H(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 _e(e,t){var n=K(z++,4);!G.__s&&Ce(n.__H,t)&&(n.__P=!1,n.__=e,n.u=t,B.__h.push(n))}function ve(e,t){var n=K(z++,7);return Ce(n.__H,t)&&(n.__=e(),n.__H=t),n.__}function ye(){var e;do{for(;e=W.shift();)try{q(e)}catch(t){G.__e(t,{__:(e=e.__P)&&e.__v})}for(;e=ce.shift();){var t=e.__H;if(e.__P&&t)try{t.__h.some(q),t.__h.some(J),t.__h=[]}catch(n){t.__h=[],G.__e(n,e.__v)}}}while(W.length)}G.__b=function(e){B=null,le&&le(e)},G.__=function(e,t){e&&t.__k&&t.__k.__m&&(e.__m=t.__k.__m),me&&me(e,t)},G.__r=function(e){ue&&ue(e),z=0;var t=(B=e.__c).__H;t&&(V==B?B.__h=[]:(t.__h.some(q),t.__h.some(J),z=0),t.__h=[],t.__.some(function(e){e.__N&&(e.__=e.__N),e.u=e.__N=void 0})),V=B},G.diffed=function(e){de&&de(e);var t=e.__c;t&&t.__H&&(t.__H.__h.length&&Se(ce.push(t)),t.__H.__.some(function(e){e.u&&(e.__H=e.u)})),V=B=null},G.__c=function(e,t){t.some(function(e){try{e.__h.some(q),e.__h=e.__h.filter(function(e){return!e.__||J(e)})}catch(t){e.__h=[function(){throw t}]}}),fe&&fe(e,t)},G.unmount=function(e){pe&&pe(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,Se(W.push(r))}else q(r)}catch(e){t=e}}),r.__H=void 0,t&&G.__e(t,r.__v))};var be=typeof requestAnimationFrame==`function`;function xe(e){var t,n=function(){clearTimeout(r),be&&cancelAnimationFrame(t),setTimeout(e)},r=setTimeout(n,35);be&&(t=requestAnimationFrame(n))}function Se(e){e!=1&&se==G.requestAnimationFrame||((se=G.requestAnimationFrame)||xe)(ye)}function q(e){var t=B,n=e.__c;typeof n==`function`&&(e.__c=void 0,n()),B=t}function J(e){var t=B;e.__c=e.__(),B=t}function Ce(e,t){return!e||e.length!=t.length||t.some(function(t,n){return!H(t,e[n])})}function we(e,t){return typeof t==`function`?t(e):t}var Y={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`},Te=new Set(Object.values(Y)),X=e=>typeof e==`string`&&Te.has(e),Ee=({error:e,fallback:t=Y.INVALID_SERVICE_RESPONSE})=>typeof e==`object`&&e&&`code`in e&&X(e.code)?e.code:e instanceof Error&&X(e.message)?e.message:X(e)?e:t,De=[`ar`,`ch`,`de`,`en`,`es`,`fr`,`it`,`ja`,`pt`,`ru`,`zh`],Z=new Map,Oe=new Map,ke=async({language:e})=>{if(Z.has(e))return;let n=Oe.get(e);n||(n=fetch(t({filename:`locales/${e}.json`})).then(async e=>{if(!e.ok)throw Error(Y.INVALID_SERVICE_RESPONSE);return await e.json()}),Oe.set(e,n));try{Z.set(e,await n)}finally{Oe.delete(e)}},Ae=async({language:e})=>{let t=e??Q();await Promise.all([ke({language:t}),...t===`en`?[]:[ke({language:`en`})]])},je=({element:e,theme:t})=>{t&&(e.dataset.theme=t)},Q=()=>{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(De.includes(n))return n}return`en`},Me={[Y.CAMERA_PERMISSION_DENIED]:`cameraPermissionDenied`,[Y.CAMERA_NOT_FOUND]:`cameraNotFound`,[Y.CAMERA_UNAVAILABLE]:`cameraUnavailable`,[Y.CAMERA_UNSUPPORTED]:`cameraUnavailable`,[Y.CAMERA_INTERRUPTED]:`cameraUnavailable`,[Y.NETWORK_ERROR]:`networkError`,[Y.SERVICE_UNAVAILABLE]:`serviceUnavailable`,[Y.MODEL_LOAD_FAILED]:`modelLoadFailed`,[Y.FACE_NOT_FOUND]:`faceNotFound`,[Y.NO_USABLE_CANDIDATES]:`faceNotFound`,[Y.FACE_NOT_USABLE]:`faceNotUsable`,[Y.NO_USABLE_REFERENCES]:`faceNotUsable`,[Y.DOCUMENT_NOT_FOUND]:`frameDocument`,[Y.DOCUMENT_NOT_RECOGNIZED]:`invalidDocument`,[Y.DOCUMENT_TEXT_NOT_READABLE]:`documentNotReadable`,[Y.DOCUMENT_BLURRY]:`documentBlurry`,[Y.DOCUMENT_FACE_NOT_FOUND]:`faceNotVisibleInDocument`,[Y.DOCUMENT_FACE_NOT_CONTAINED]:`documentAlignmentInvalid`,[Y.DOCUMENT_FACE_GEOMETRY_INVALID]:`documentAlignmentInvalid`,[Y.DOCUMENT_TEXT_ALIGNMENT_INVALID]:`documentAlignmentInvalid`,[Y.DOCUMENT_BACK_REQUIRED]:`frameDocumentBack`,[Y.CAPTURES_INCOMPLETE]:`capturesIncomplete`,[Y.DOCUMENT_VALIDATION_FAILED]:`documentValidationFailed`,[Y.INVALID_OPTIONS]:`invalidOptions`,[Y.INVALID_POSES]:`invalidPoses`,[Y.INVALID_SERVICE_RESPONSE]:`invalidServiceResponse`,[Y.POSE_BACKGROUND_MISMATCH]:`poseBackgroundMismatch`,[Y.POSE_IDENTITY_MISMATCH]:`poseIdentityMismatch`,[Y.IMAGE_ENCODE_FAILED]:`imageEncodeFailed`,[Y.IMAGE_PROCESSING_FAILED]:`imageProcessingFailed`,[Y.INVALID_IMAGE]:`invalidImage`,[Y.INVALID_PDF]:`invalidPdf`,[Y.PDF_PASSWORD_REQUIRED]:`pdfPasswordRequired`,[Y.PDF_LOAD_FAILED]:`pdfLoadFailed`,[Y.CLIENT_KEY_REQUIRED]:`clientKeyRequired`,[Y.VERIFICATION_SAVE_FAILED]:`verificationSaveFailed`,[Y.FACEGATE_ABORTED]:`verificationCancelled`,[Y.VERIFICATION_CANCELLED]:`verificationCancelled`},Ne=({language:e})=>{let t=e??Q(),n=e=>{let n=Z.get(t),r=Z.get(`en`);return n?.[e]??r?.[e]??e};return{translate:n,translateError:({error:e})=>{let t=Me[Ee({error:e})]??`verificationFailed`;return n(t)}}},Pe=async({milliseconds:e})=>{let t=Promise.withResolvers();setTimeout(()=>t.resolve(),e),await t.promise},$=new WeakMap,Fe=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(Y.VERIFICATION_CANCELLED,`AbortError`)),u=()=>c(new DOMException(Y.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},Ie=()=>{let e=/Android|iPhone|iPad|iPod|Mobile/i.test(navigator.userAgent),t=navigator.platform===`MacIntel`&&navigator.maxTouchPoints>1;return e||t},Le=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}},Re=({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},ze=async({facingMode:e,video:t,signal:n})=>{if(!navigator.mediaDevices||typeof navigator.mediaDevices.getUserMedia!=`function`)throw Error(Y.CAMERA_UNSUPPORTED);let r={facingMode:{ideal:e}};Ie()||(r.width={ideal:1280},r.height={ideal:720});let i=()=>Re({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(Re({video:t}),n?.aborted)throw new DOMException(Y.VERIFICATION_CANCELLED,`AbortError`);let r=e instanceof Error?e.name:``,i=Y.CAMERA_UNAVAILABLE;throw(r===`NotAllowedError`||r===`SecurityError`)&&(i=Y.CAMERA_PERMISSION_DENIED),r===`NotFoundError`&&(i=Y.CAMERA_NOT_FOUND),r===`AbortError`&&(i=Y.CAMERA_INTERRUPTED),Error(i,{cause:e})}finally{n?.removeEventListener(`abort`,i)}},Be=({element:e})=>{let t=e.getContext(`2d`);if(!t)throw Error(Y.IMAGE_PROCESSING_FAILED);t.clearRect(0,0,e.width,e.height)},Ve=async({canvas:e,quality:t})=>{try{let n=await e.convertToBlob({type:`image/jpeg`,quality:t});if(n.type!==`image/jpeg`)throw Error(Y.IMAGE_ENCODE_FAILED);return n}catch(e){throw Error(Y.IMAGE_ENCODE_FAILED,{cause:e})}},He=async({frame:e})=>{let t=new OffscreenCanvas(e.width,e.height),n=t.getContext(`2d`);if(!n)throw Error(Y.IMAGE_PROCESSING_FAILED);return n.drawImage(e,0,0),await Ve({canvas:t})},Ue=async({blob:e})=>{let t;try{t=await createImageBitmap(e)}catch(e){throw Error(Y.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(Y.IMAGE_PROCESSING_FAILED);return r.drawImage(t,0,0,n.width,n.height),await Ve({canvas:n,quality:.85})}finally{t.close()}},We=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})},Ge=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{w as C,T as D,i as E,e as O,oe as S,n as T,Ee as _,Ge as a,ve as b,Re as c,je as d,Ne as f,Y as g,Pe as h,He as i,t as k,We as l,Ae as m,Be as n,Ie as o,Q as p,Ue as r,ze as s,Le as t,Fe as u,_e as v,x as w,C as x,he as y};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/*! Copyright (c) 2026 VOLTOM. All rights reserved. Proprietary software. See LICENSE at https://voltom.io/license. */
|
|
2
|
-
import{
|
|
2
|
+
import{et as e}from"./eyeLevelCamera-aDRPs63K.js";var t=()=>({operation:e(`enroll`),phase:e(`loading`),instruction:e(null),guidance:e(null),corrective:e(null),progress:e({completed:0,total:1}),feedback:e(null),failures:e(0),error:e(null),debug:e([]),debugEnabled:e(!1),match:e(null),facingMode:e(null)});export{t};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/*! Copyright (c) 2026 VOLTOM. All rights reserved. Proprietary software. See LICENSE at https://voltom.io/license. */
|
|
2
|
+
import{A as e,B as t,D as n,F as r,G as i,H as a,I as o,J as s,K as c,L as l,M as u,N as d,O as f,P as p,R as m,T as h,W as g,X as _,Y as v,Z as y,a as b,b as x,c as S,et as C,f as w,g as T,h as E,i as D,j as O,k,m as A,n as j,o as M,p as N,r as ee,s as te,t as P,u as ne,v as re,z as F}from"./eyeLevelCamera-aDRPs63K.js";import{g as I,h as ie,i as ae,k as oe,n as se,u as ce}from"./media-Cejmtltt.js";var le=({box:e,image:t})=>{let n=Math.max(0,Math.floor(e.left)),r=Math.max(0,Math.floor(e.top)),i=Math.min(t.width,Math.ceil(e.right)),a=Math.min(t.height,Math.ceil(e.bottom)),o=Math.max(1,i-n),s=Math.max(1,a-r),c=new Uint8ClampedArray(o*s*4);for(let e=0;e<s;e+=1){let i=((r+e)*t.width+n)*4,a=e*o*4;c.set(t.data.subarray(i,i+o*4),a)}return{data:c,height:s,width:o}},ue=({height:e,image:t,width:n})=>{let r=new Uint8ClampedArray(n*e*4),i=t.width/n,a=t.height/e;for(let o=0;o<e;o+=1){let e=Math.min(t.height-1,Math.floor((o+.5)*a));for(let a=0;a<n;a+=1){let s=Math.min(t.width-1,Math.floor((a+.5)*i)),c=(e*t.width+s)*4,l=(o*n+a)*4;r[l]=t.data[c]??0,r[l+1]=t.data[c+1]??0,r[l+2]=t.data[c+2]??0,r[l+3]=255}}return{data:r,height:e,width:n}},de=.3,fe=.6,pe=12,me=3,he=async({session:e,tensor:t})=>{let n=performance.now();try{let n=await e.run({[e.inputNames[0]]:t}),r=n[e.outputNames[0]];if(!r){for(let e of Object.values(n))e.dispose();throw Error(v.INVALID_MODEL_OUTPUT)}for(let e of Object.values(n))e!==r&&e.dispose();return r}catch(e){throw Error(_({error:e,fallback:v.INFERENCE_FAILED}),{cause:e})}finally{i({category:`inference`,duration:performance.now()-n,key:`ocr`}),t.dispose()}},ge=({text:e})=>e.normalize(`NFKC`).replace(/\r\n?/gu,`
|
|
3
|
+
`).replace(/[\t\f\v ]+/gu,` `).replace(/ *\n */gu,`
|
|
4
|
+
`).trim(),_e=({pixels:e,runtime:t})=>{let n=Math.max(32,Math.ceil(e.width/32)*32),r=Math.max(32,Math.ceil(e.height/32)*32),i=new Float32Array(3*n*r),a=[.485,.456,.406],o=[.229,.224,.225];for(let e=0;e<3;e+=1)i.fill((1-(a[e]??0))/(o[e]??1),e*n*r,(e+1)*n*r);for(let t=0;t<e.height;t+=1)for(let s=0;s<e.width;s+=1){let c=(t*e.width+s)*4,l=t*n+s;for(let t=0;t<3;t+=1){let s=(e.data[c+t]??0)/255;i[t*n*r+l]=(s-(a[t]??0))/(o[t]??1)}}return{height:r,tensor:new t.Tensor(`float32`,i,[1,3,r,n]),width:n}},ve=({height:e,scores:t,width:n})=>{let r=new Uint8Array(n*e),i=[],a=new Int32Array(n*e);for(let o=0;o<t.length;o+=1){if(r[o]||(t[o]??0)<de)continue;let s=0,c=1,l=o%n,u=l,d=Math.floor(o/n),f=d,p=0,m=0;for(a[0]=o,r[o]=1;s<c;){let i=a[s]??0;s+=1;let o=i%n,h=Math.floor(i/n);l=Math.min(l,o),u=Math.max(u,o),d=Math.min(d,h),f=Math.max(f,h),p+=t[i]??0,m+=1;for(let i=-1;i<=1;i+=1)for(let s=-1;s<=1;s+=1){let l=o+s,u=h+i;if(l<0||l>=n||u<0||u>=e)continue;let d=u*n+l;r[d]||(t[d]??0)<de||(r[d]=1,a[c]=d,c+=1)}}let h=u-l+1,g=f-d+1;if(m<pe||h<me||g<me||p/m<fe)continue;let _=h*.25,v=g*.35;i.push({bottom:f+1+v,left:l-_,right:u+1+_,score:p/m,top:d-v})}return i},ye=({boxes:e})=>e.sort((e,t)=>{let n=e.bottom-e.top,r=t.bottom-t.top,i=Math.max(n,r)*.6;return Math.abs(e.top-t.top)<=i?e.left-t.left:e.top-t.top}),be=async({pixels:e,runtime:t,session:n})=>{let r=_e({pixels:e,runtime:t}),i=await he({session:n,tensor:r.tensor});try{let e=Number(i.dims.at(-2)),t=Number(i.dims.at(-1)),n=ve({height:e,scores:i.data,width:t}),a=r.width/t,o=r.height/e;return ye({boxes:n.map(({bottom:e,left:t,right:n,top:r})=>({bottom:e*o,left:t*a,right:n*a,top:r*o}))})}finally{i.dispose()}},xe=({pixels:e,runtime:t,model:n})=>{let r=n.recognitionHeight,i=Math.max(1,Math.round(e.width/e.height*r)),a=Math.max(32,Math.ceil(i/32)*32),o=ue({height:r,image:e,width:i}),s=new Float32Array(3*a*r);for(let e=0;e<r;e+=1)for(let t=0;t<i;t+=1){let c=(e*i+t)*4,l=e*a+t,u=o.data[c],d=o.data[c+1],f=o.data[c+2],p=u*.299+d*.587+f*.114;s[l]=((n.channels===`grayscale`?p:f)/255-.5)/.5,s[a*r+l]=((n.channels===`grayscale`?p:d)/255-.5)/.5,s[2*a*r+l]=((n.channels===`grayscale`?p:u)/255-.5)/.5}return new t.Tensor(`float32`,s,[1,3,r,a])},Se=({text:e})=>{let t=[],n=``;for(let r of e)/[a-zA-Z0-9 :*./%+-]/u.test(r)?n+=r:(n&&t.push(n),t.push(r),n=``);return n&&t.push(n),t.reverse().join(``)},Ce=({dictionary:e,output:t,reverse:n})=>{let r=Number(t.dims.at(-1)),i=Number(t.dims.at(-2)),a=e[0]===``?[...e]:[``,...e];if(a.length===r-1&&a.push(` `),a.length!==r)throw Error(v.OCR_DICTIONARY_MISMATCH);let o=-1,s=``;for(let e=0;e<i;e+=1){let n=e*r,i=0,c=t.data[n]??-1/0;for(let e=1;e<r;e+=1){let r=t.data[n+e]??-1/0;r<=c||(i=e,c=r)}i!==0&&i!==o&&(s+=a[i]??``),o=i}let c=s.trim();return n?Se({text:c}):c},we=({lines:e})=>e.filter((t,n)=>{let r=t.box.width*t.box.height;return!e.some((e,i)=>{if(i===n||!e.text.endsWith(t.text))return!1;let a=e.box.width*e.box.height;if(a<r||e.text.length===t.text.length&&a===r&&i>n)return!1;let o=Math.max(0,Math.min(t.box.x+t.box.width,e.box.x+e.box.width)-Math.max(t.box.x,e.box.x)),s=Math.max(0,Math.min(t.box.y+t.box.height,e.box.y+e.box.height)-Math.max(t.box.y,e.box.y));return r>0&&o*s>=r*.95})}),Te=async({adapter:e,model:t})=>{let[n,r,i]=await Promise.all([e.session(t.detection),e.session(t.recognition),e.load(t.dictionary)]),a=new TextDecoder().decode(i).replace(/\r/gu,``).split(`
|
|
5
|
+
`);for(;a.at(-1)===``;)a.pop();return{model:t.id,assets:[t.detection,t.recognition,t.dictionary],recognize:async({image:i})=>{let o=await e.decode(i),s=await be({pixels:o,runtime:e.runtime,session:n}),c=[];for(let n of s){let i=xe({pixels:le({box:n,image:o}),runtime:e.runtime,model:t}),s=await he({session:r,tensor:i}),l;try{l=Ce({dictionary:a,output:s,reverse:t.reverseArabic})}finally{s.dispose()}if(!l)continue;let u={height:Math.max(0,Math.min(o.height,n.bottom)-Math.max(0,n.top)),width:Math.max(0,Math.min(o.width,n.right)-Math.max(0,n.left)),x:Math.max(0,n.left),y:Math.max(0,n.top)};c.push({angle:0,box:u,confidence:null,text:l,words:[{box:u,confidence:null,text:l}]})}let l=we({lines:c}),u=ge({text:l.map(e=>e.text).join(`
|
|
6
|
+
`)});return{engine:t.id,height:o.height,lines:l,text:u,width:o.width}}}},L=`odm.ort`,Ee={tiny:{id:`tiny`,detection:`od.ort`,recognition:`or.ort`,dictionary:`ot.txt`,recognitionHeight:48,channels:`grayscale`,reverseArabic:!1},small:{id:`small`,detection:`ods.ort`,recognition:`ors.ort`,dictionary:`ots.txt`,recognitionHeight:48,channels:`grayscale`,reverseArabic:!1},japanese:{id:`japanese`,detection:L,recognition:`orj.ort`,dictionary:`otj.txt`,recognitionHeight:48,channels:`bgr`,reverseArabic:!1},"chinese-simplified":{id:`chinese-simplified`,detection:L,recognition:`orcs.ort`,dictionary:`otcs.txt`,recognitionHeight:48,channels:`bgr`,reverseArabic:!1},"chinese-traditional":{id:`chinese-traditional`,detection:L,recognition:`orct.ort`,dictionary:`otct.txt`,recognitionHeight:48,channels:`bgr`,reverseArabic:!1},cyrillic:{id:`cyrillic`,detection:L,recognition:`orc.ort`,dictionary:`otc.txt`,recognitionHeight:48,channels:`bgr`,reverseArabic:!1},arabic:{id:`arabic`,detection:L,recognition:`ora.ort`,dictionary:`ota.txt`,recognitionHeight:48,channels:`bgr`,reverseArabic:!0}},De={eng:`eng`,en:`eng`,english:`eng`,latin:`latin`,deu:`latin`,de:`latin`,fra:`latin`,fr:`latin`,ita:`latin`,it:`latin`,por:`latin`,pt:`latin`,spa:`latin`,es:`latin`,jpn:`jpn`,ja:`jpn`,japan:`jpn`,chi_sim:`chi_sim`,zh:`chi_sim`,"zh-cn":`chi_sim`,"zh-hans":`chi_sim`,chi_tra:`chi_tra`,ch:`chi_tra`,"zh-tw":`chi_tra`,"zh-hant":`chi_tra`,rus:`rus`,ru:`rus`,ara:`ara`,ar:`ara`},Oe=({language:e})=>{let t=De[e.trim().toLowerCase()];if(!t)throw Error(v.OCR_LANGUAGE_UNSUPPORTED);return t},ke={eng:`tiny`,latin:`tiny`,jpn:`japanese`,chi_sim:`chinese-simplified`,chi_tra:`chinese-traditional`,rus:`cyrillic`,ara:`arabic`},Ae=({language:e,engine:t=`auto`})=>{let n=Oe({language:e}),r=Ee[t===`auto`?ke[n]:t];if(!r)throw Error(v.OCR_MODEL_UNSUPPORTED);return r},je=({language:e,engine:t})=>{let n=Ae({environment:`browser`,language:e,engine:t});return[n.detection,n.recognition,n.dictionary]},Me=({adapter:e,environment:t})=>{let n=new Map,r=async r=>{if(r.environment!==t)throw Error(v.OCR_ENVIRONMENT_MISMATCH);let i=Ae(r),a=n.get(i.id);a||(a=Te({adapter:e,model:i}),n.set(i.id,a));try{return await a}catch(e){throw n.get(i.id)===a&&n.delete(i.id),e}};return{getOcr:r,ocr:async({image:e,language:n=`eng`,engine:i})=>await(await r({environment:t,language:n,engine:i})).recognize({image:e})}},Ne=async({cache:e,key:t,load:n})=>{let r=e.get(t);r||(r=n(),e.set(t,r));try{return await r}catch(n){throw e.get(t)===r&&e.delete(t),n}},Pe=new Map,{getOcr:Fe,ocr:Ie}=Me({adapter:{decode:async e=>{if(!(e instanceof Blob)&&!(e instanceof Uint8Array))return e;let t=e instanceof Uint8Array?new Blob([e]):e,n=await l.createImageBitmap(t);try{return m({frame:n})}finally{n.close()}},load:async e=>await Ne({cache:Pe,key:e,load:async()=>{try{let t=await fetch(c({filename:e}));if(!t.ok)throw Error(v.MODEL_LOAD_FAILED);return new Uint8Array(await t.arrayBuffer())}catch(e){throw Error(v.MODEL_LOAD_FAILED,{cause:e})}}}),session:async e=>await a({filename:e}),runtime:s},environment:`browser`}),Le=.24,Re=.7,ze=.16,R=({data:e,height:t,text:n,width:r})=>{let i=new Uint8Array(r*t);for(let t=0;t<i.length;t+=1){let n=t*4;i[t]=Math.round((e[n]??0)*.299+(e[n+1]??0)*.587+(e[n+2]??0)*.114)}let a=[];for(let e=0;e<t;e+=1)for(let n=0;n<r;n+=1){let o=e*r+n,s=i[o]??0;n+1<r&&a.push(s>=(i[o+1]??0)),e+1<t&&a.push(s>=(i[o+r]??0))}let o=new Uint8Array(Math.ceil(a.length/8));for(let[e,t]of a.entries())t&&(o[Math.floor(e/8)]|=1<<e%8);let s=[];for(let e=0;e<8;e+=1)for(let n=0;n<8;n+=1){let a=0,o=0;for(let s=Math.floor(e*t/8);s<Math.floor((e+1)*t/8);s+=1)for(let e=Math.floor(n*r/8);e<Math.floor((n+1)*r/8);e+=1)a+=i[s*r+e]??0,o+=1;s.push(o?a/o:0)}let c=s.reduce((e,t)=>e+t,0)/s.length,l=new Uint8Array(Math.ceil(s.length/8));for(let[e,t]of s.entries())t>=c&&(l[Math.floor(e/8)]|=1<<e%8);return{edgeHash:o,appearanceHash:l,textTokens:[...new Set(n.toUpperCase().normalize(`NFKC`).split(/[^\p{L}\d]+/u).filter(e=>e.length>=3))]}},z=({value:e})=>{let t=0,n=e;for(;n;)t+=n&1,n>>>=1;return t},B=({front:e,current:t})=>{if(!e||!t||e.edgeHash.length!==t.edgeHash.length||e.appearanceHash.length!==t.appearanceHash.length)return{distinct:!1,imageDistance:null,textOverlap:null};let n=e.edgeHash.reduce((e,n,r)=>e+z({value:n^(t.edgeHash[r]??0)}),0)/(e.edgeHash.length*8),r=e.appearanceHash.reduce((e,n,r)=>e+z({value:n^(t.appearanceHash[r]??0)}),0)/(e.appearanceHash.length*8),i=t.textTokens.filter(t=>e.textTokens.includes(t)).length,a=Math.min(e.textTokens.length,t.textTokens.length),o=e.textTokens.length>=3&&t.textTokens.length>=3?i/a:null;return{distinct:n>=Le&&r>=ze&&(o===null||o<Re),imageDistance:n,textOverlap:o}},Be=({text:e})=>{let t=e.toUpperCase().normalize(`NFKC`).split(`
|
|
7
|
+
`).map(e=>e.replace(/\s+/g,``)),n=t.findIndex(e=>e.startsWith(`P<`)&&e.length>=44&&(e.match(/</g)||[]).length>=2);if(n>=0&&t.slice(n+1).find(e=>/^[A-Z0-9<]{44}$/u.test(e)))return!0;let r=t.findIndex(e=>/^[A-Z0-9]<[A-Z]{3}/u.test(e)&&e.length>=30);return r<0?!1:t.slice(r+1).filter(e=>/^[A-Z0-9<]{30}$/u.test(e)).length>=2},Ve={A:`AUT`,B:`BEL`,BG:`BGR`,CY:`CYP`,CZ:`CZE`,D:`DEU`,DK:`DNK`,E:`ESP`,EST:`EST`,F:`FRA`,FIN:`FIN`,GR:`GRC`,H:`HUN`,HR:`HRV`,I:`ITA`,IRL:`IRL`,L:`LUX`,LT:`LTU`,LV:`LVA`,M:`MLT`,NL:`NLD`,P:`PRT`,PL:`POL`,RO:`ROU`,S:`SWE`,SK:`SVK`,SLO:`SVN`},He=({line:e,start:t,end:n})=>{let r=[],i=0;for(let a of e.words){let o=e.text.indexOf(a.text,i);if(o<0||!a.text.length)continue;i=o+a.text.length;let s=Math.max(t,o),c=Math.min(n,i);c<=s||r.push({...a.box,x:a.box.x+a.box.width*(s-o)/a.text.length,width:a.box.width*(c-s)/a.text.length})}if(!r.length)return{...e.box,x:e.box.x+e.box.width*t/e.text.length,width:e.box.width*(n-t)/e.text.length};let a=Math.min(...r.map(e=>e.x)),o=Math.min(...r.map(e=>e.y));return{x:a,y:o,width:Math.max(...r.map(e=>e.x+e.width))-a,height:Math.max(...r.map(e=>e.y+e.height))-o}},Ue=({line:e})=>{let t=e.text;if(!t.trim()||e.confidence!==null&&e.confidence<=0)return[];if(/^\s*\d{1,2}[./-]\d{1,2}[./-]\d{2,4}\s*$/u.test(t))return[{text:t.trim(),box:e.box,label:null}];let n=[...t.matchAll(/(?:^|\s)(4[a-d]|1[0-4]|[1-9])(?:[.:)]\s*|\s+|$|(?=\d{1,2}[./-]\d))/giu)];if(!n.length)return[{text:t,box:e.box,label:null}];let r=[],i=n[0].index;i>0&&r.push({text:t.slice(0,i).trim(),box:He({line:e,start:0,end:i}),label:null});for(let[i,a]of n.entries()){let o=a.index+a[0].indexOf(a[1]),s=n[i+1]?.index??t.length,c=t.slice(a.index+a[0].length,s).trim(),l=He({line:e,start:o,end:s});r.push({text:c,box:l,label:a[1].toLowerCase()})}return r},V=({label:e,fragments:t})=>{let n=t.filter(t=>t.label===e);if(n.length!==1)return null;let r=n[0],i=r.box.height,a=r.text?[r]:[],o=t.filter(e=>e.label&&e!==r);for(let e of t){if(e.label||!e.text)continue;let t=e.box.y-r.box.y,n=Math.abs(t)<Math.max(i,e.box.height)*.5,s=t>=i*.5&&t<=i*2.5;(n||s)&&(e.box.x<r.box.x-i*.5||n&&r.text||o.some(t=>{let n=Math.abs(t.box.y-r.box.y)<i*.5&&t.box.x>r.box.x&&e.box.x>=t.box.x-i*.25,a=t.box.y>r.box.y+i*.5&&t.box.y<=e.box.y+e.box.height*.5&&Math.abs(t.box.x-r.box.x)<i*3;return n||a})||o.some(n=>{let a=e.box.y-n.box.y,o=a>=-i*.5&&a<=i*2.5&&e.box.x>=n.box.x-i*.5,s=Math.abs(t)+Math.abs(e.box.x-r.box.x),c=Math.abs(a)+Math.abs(e.box.x-n.box.x);return o&&c<=s})||a.push(e))}return a.sort((e,t)=>Math.abs(e.box.y-t.box.y)<i*.5?e.box.x-t.box.x:e.box.y-t.box.y),a.map(e=>e.text).join(` `).trim()||null},H=({text:e,allowTwoDigitYear:t=!1})=>{if(!e)return null;let n=e.match(/^(?:(\d{1,2})([./-])(\d{1,2})\2(\d{2,4})|(\d{4})-(\d{2})-(\d{2}))$/u);if(!n)return null;let r=n[4]??n[5],i=Number(n[3]??n[6]),a=Number(n[1]??n[7]),o=Number(r);if(r.length===2){if(!t)return null;let e=new Date,n=e.getUTCFullYear(),r=e.getUTCMonth()+1,s=e.getUTCDate(),c=[1900+o,2e3+o].filter(e=>{let t=n-e-+(r<i||r===i&&s<a);return t>=16&&t<=100});if(c.length!==1)return null;o=c[0]}return o<1e3||i<1||i>12||a<1||a>new Date(Date.UTC(o,i,0)).getUTCDate()?null:`${o}-${String(i).padStart(2,`0`)}-${String(a).padStart(2,`0`)}`},We=({ocr:e,image:t})=>{let n=new Set;for(let i of e.lines)for(let e of i.words.length?i.words:[i]){let i=Ve[e.text.trim().toUpperCase()],{x:a,y:o,width:s,height:c}=e.box;if(e.confidence!==null&&e.confidence<=0||!i||a<0||o<0||a+s>t.width*.3||o+c>t.height*.35)continue;let l=Math.max(s,c);r({...t,xStart:Math.max(0,a-l)/t.width,xEnd:Math.min(t.width,a+s+l)/t.width,yStart:Math.max(0,o-l)/t.height,yEnd:Math.min(t.height,o+c+l)/t.height,predicate:(e,t,n)=>n>45&&n>e*1.08&&n>t*1.04})>=.15&&n.add(i)}return n.size===1?[...n][0]:null},U=({ocr:e,image:t})=>{if(o(e))return null;let n=e.lines.flatMap(e=>Ue({line:e})),r=new Set(n.map(e=>e.label));if(!(r.has(`1`)||r.has(`2`))||![`3`,`4a`,`4b`,`5`].some(e=>r.has(e)))return null;let i=V({label:`1`,fragments:n}),a=V({label:`2`,fragments:n}),s=i&&/\p{L}/u.test(i)?i:null,c=a&&/\p{L}/u.test(a)?a:null,l=V({label:`3`,fragments:n})?.match(/^(\d{1,2}[./-]\d{1,2}[./-]\d{2,4}|\d{4}-\d{2}-\d{2})(?:\s+(.+))?$/u),u=H({allowTwoDigitYear:!0,text:l?l[1]:null}),d=l&&l[2]?.trim()||null,f=H({text:V({label:`4a`,fragments:n})}),p=H({text:V({label:`4b`,fragments:n})}),m=V({label:`4c`,fragments:n}),h=V({label:`5`,fragments:n}),g=We({ocr:e,image:t});return[s,c,u,d,f,p,m,h,g].some(Boolean)?k.parse({document:{source:`OCR`,type:`DRV`,issuing_country:g,issuing_authority:m,number:h,issue_date:f,expiry_date:p,optional_data:null},holder:{first_name:c,last_name:s,middle_name:null,birth_date:u,birth_place:d,sex:null,nationality:null,personal_number:null},address:null,raw_data:{mrz_lines:[],aamva_version:null}}):null},W=null,Ge=()=>globalThis.window===void 0?`zxing-wasm/reader`:c({filename:`zxing-wasm/reader/index.js`}),Ke=async()=>{let e=await import(Ge());return globalThis.window!==void 0&&e.setZXingModuleOverrides({locateFile:e=>c({filename:`zxing-wasm/reader/${e}`})}),e},qe=async()=>{W??=Ke();try{return await W}catch(e){throw W=null,e}},Je=async()=>{await(await qe()).prepareZXingModule({fireImmediately:!0})},Ye=async({image:e})=>{let t=await(await qe()).readBarcodes(e,{formats:[`PDF417`],tryHarder:!0});for(let e of t)try{let t=f(e.text);return{type:`aamva`,code:e.text,payload:t}}catch{}return null},Xe=({runtime:t,detector:r,alignment:i,text:a,readImage:o})=>{let s=async({image:e,language:s,engine:c,scanBarcodes:l=!1})=>{let u=e instanceof Blob?e:new Blob([e]),f=await t.createImageBitmap(u);try{let e=await r.analyzeDocument({frame:f});if(!e.detection)throw Error(v.DOCUMENT_NOT_FOUND);let u=await i.orientDocumentFrame({frame:f,polygon:e.detection.polygon,orientation:e.detection.orientation});if(!u)throw Error(v.IMAGE_PROCESSING_FAILED);try{let r=d({image:o({frame:f}),polygon:e.detection.polygon,sourceOrientation:u.orientation.rotation}),i=await a.readRectifiedText({frame:u.frame,language:s,engine:c,image:r});if(!i)throw Error(v.DOCUMENT_TEXT_NOT_READABLE);let p=o({frame:u.frame}),m=null;if(l){let e=t.createImageData(p.width,p.height);e.data.set(p.data),m=await Ye({image:e})}return{ocr:i,codes:[n({result:i}),m].filter(e=>e!==null),pixels:p,signature:R({...o({frame:u.frame,width:32,height:32}),text:i.text}),blurry:e.isBlurry}}finally{u.frame.close()}}finally{f.close()}};return{classifyDocument:async({document_front:t,document_back:n,language:r,engine:i})=>{let a=await s({image:t,language:r,engine:i}),o=p({image:a.pixels,text:a.ocr.text,codes:a.codes});if(!o)throw Error(v.DOCUMENT_NOT_RECOGNIZED);let c=o.europeanDrivingLicense?U({ocr:a.ocr,image:a.pixels}):null,l=e({document:o.document})&&n?await s({image:n,language:o.europeanDrivingLicense?`latin`:r,engine:o.europeanDrivingLicense?`tiny`:i,scanBarcodes:!0}):null,d=u({classification:{...o,identity:c},front:a,back:l}),f=[...d.reasons],m=l?l.blurry:!1;return(a.blurry||m)&&f.push(v.DOCUMENT_BLURRY),l&&!B({front:a.signature,current:l.signature}).distinct&&f.push(v.DOCUMENT_BACK_NOT_DISTINCT),{identity:c,...o,...d,reasons:f,valid:f.length===0,document_front:a.ocr,document_back:l?l.ocr:null}},detectDocument:async({image:e,language:t})=>{let n=await s({image:e,language:t,scanBarcodes:!0}),r=p({image:n.pixels,text:n.ocr.text,codes:n.codes});if(!r)throw Error(v.DOCUMENT_NOT_RECOGNIZED);let i=n.codes.find(e=>e.type===`mrz`),a=n.codes.find(e=>e.type===`aamva`),o=!!a||r.document===`id`&&!!i;return{identity:!o&&r.europeanDrivingLicense?U({ocr:n.ocr,image:n.pixels}):null,document_type:r.document===`driving_license`?`drv`:r.document,document_side:o?`back`:`front`,mrz_code:i?i.code:null,ammva_code:a?a.code:null}},extractDocumentCodes:async({images:e})=>{let t=[];for(let n of e){let e=await s({image:n,scanBarcodes:!0});t.push(...e.codes)}return[...new Map(t.map(e=>[`${e.type}:${e.code}`,e])).values()]}}},G=8,Ze=.16,Qe=({x:e,y:t,width:n,height:r})=>{let i=e/n,a=t/r;return i<.2||i>=.8||a<.2||a>=.8},$e=({value:e})=>{let t=0,n=e;for(;n;)t+=n&1,n>>>=1;return t},et=({image:e})=>{let t=[];for(let n=0;n<G;n+=1)for(let r=0;r<G;r+=1){let i=0,a=0,o=Math.floor(n*e.height/G),s=Math.floor((n+1)*e.height/G),c=Math.floor(r*e.width/G),l=Math.floor((r+1)*e.width/G);for(let t=o;t<s;t+=1)for(let n=c;n<l;n+=1){if(!Qe({height:e.height,width:e.width,x:n,y:t}))continue;let r=(t*e.width+n)*4;i+=(e.data[r]??0)*.299+(e.data[r+1]??0)*.587+(e.data[r+2]??0)*.114,a+=1}t.push(a?i/a:0)}let n=t.reduce((e,t)=>e+t,0)/t.length,r=new Uint8Array(Math.ceil(t.length/8));for(let[e,i]of t.entries())i>=n&&(r[Math.floor(e/8)]|=1<<e%8);return{appearanceHash:r}},tt=({first:e,second:t})=>{if(e.appearanceHash.length!==t.appearanceHash.length)return{distance:1,matched:!1};let n=e.appearanceHash.reduce((e,n,r)=>e+$e({value:n^(t.appearanceHash[r]??0)}),0)/(e.appearanceHash.length*8);return{distance:n,matched:n<=Ze}},nt=({candidate:e,identity:t})=>[{missing:!t?.holder.last_name,pattern:/^\s*1[.:)]\s+\p{L}/u},{missing:!t?.holder.first_name,pattern:/^\s*2[.:)]\s+\p{L}/u},{missing:!t?.holder.birth_date,pattern:/^\s*3[.:)]\s+\d{1,2}[./-]\d{1,2}[./-]\d{2,4}/u},{missing:!t?.document.number,pattern:/^\s*5[.:)]\s+[A-Z0-9]/u}].flatMap(({missing:t,pattern:n})=>{if(!t)return[];let r=e.lines.find(e=>n.test(e.text));return r?[r]:[]}),rt=({runtime:e,orientDocumentFrame:t,getOcr:r})=>{let i=`auto`,a=F({runtime:e}),o=async({engine:t=i,language:n=`eng`}={})=>{await r({environment:e.environment,engine:t,language:n})},s=async({classificationImage:t,engine:o=i,frame:s,language:c,image:l})=>{if(s.width<200||s.height<100)return null;let u=l??d({image:a({frame:s}),polygon:[{x:0,y:0},{x:s.width,y:0},{x:s.width,y:s.height},{x:0,y:s.height}]}),f=await(await r({environment:e.environment,engine:`tiny`,language:`latin`})).recognize({image:u}),m=n({result:f}),h=t??a({frame:s}),g=p({image:h,text:f.text,codes:m?[m]:[]}),_=g&&(g.document===`passport`||g.europeanDrivingLicense);if(g?.europeanDrivingLicense){let t=U({ocr:f,image:h});if(!O({identity:t})){let n=await(await r({environment:e.environment,engine:`small`,language:`latin`})).recognize({image:u}),i=U({ocr:n,image:h}),a=p({image:h,text:n.text,codes:[]});if(a?.europeanDrivingLicense&&O({identity:i}))f=n;else if(a?.europeanDrivingLicense){let e=nt({candidate:n,identity:t});if(e.length){let t=[...f.lines,...e];f={...f,lines:t,text:t.map(e=>e.text).join(`
|
|
8
|
+
`)}}}}}else if(!_){let t=Oe({language:c??`eng`}),n=await r({environment:e.environment,engine:o,language:t});n.model!==`tiny`&&(f=await n.recognize({image:u}))}let v=s.width/f.width,y=s.height/f.height,b=({x:e,y:t,width:n,height:r})=>({x:e*v,y:t*y,width:n*v,height:r*y});return{...f,width:s.width,height:s.height,lines:f.lines.map(e=>({...e,box:b(e.box),words:e.words.map(e=>({...e,box:b(e.box)}))}))}},c=async e=>await s(e)??{height:e.frame.height,lines:[],text:``,width:e.frame.width};return{loadTextDetector:o,readRectifiedText:s,detectRectifiedText:c,detectDocumentText:async({engine:e=i,frame:n,language:r,polygon:a})=>{let o=await t({frame:n,polygon:a});if(!o)return{height:0,lines:[],rotation:0,text:``,width:0};try{return{...await c({engine:e,frame:o.frame,language:r}),rotation:o.orientation.rotation}}finally{o.frame.close()}}}},it=({runtime:e,documentAlignment:r,rectifiedDocumentFace:a,orientDocumentFrame:o,restoreRectifiedFace:s,analyzeDocument:c,faceDetection:l,faceMatch:f,textDetection:m})=>{let h=F({runtime:e}),_=({frame:n,text:r})=>{let i=e.createCanvas(32,32),a=i.getContext(`2d`,{willReadFrequently:!0});if(!a)throw Error(v.IMAGE_PROCESSING_FAILED);a.drawImage(n,0,0,i.width,i.height);let{data:o}=a.getImageData(0,0,i.width,i.height);return t({canvas:i}),R({data:o,height:32,text:r,width:32})},y=({current:e,front:t})=>{let n=B({current:e.signature,front:t}),r=[],i=e.signature?.textTokens.length??0,a=Be({text:e.text.text})||e.text.lines.length>=2&&i>=2;return e.detection||r.push(v.DOCUMENT_NOT_FOUND),e.documentAnalysis.isBlurry&&r.push(v.DOCUMENT_BLURRY),e.hasPictureFace&&r.push(v.DOCUMENT_BACK_CONTAINS_FACE),a||r.push(v.DOCUMENT_TEXT_NOT_READABLE),n.distinct||r.push(v.DOCUMENT_BACK_NOT_DISTINCT),{distinct:n.distinct,imageDistance:n.imageDistance,reasons:r,textOverlap:n.textOverlap,valid:r.length===0}},b=({alignment:e,detection:t,documentAnalysis:n,faceContained:r,requiresFace:i,text:a})=>{let o=[];return t||o.push(v.DOCUMENT_NOT_FOUND),n.isBlurry&&o.push(v.DOCUMENT_BLURRY),i&&!r&&o.push(v.DOCUMENT_FACE_NOT_CONTAINED),(!a.text||a.lines.length<2)&&o.push(v.DOCUMENT_TEXT_NOT_READABLE),!i||e.faceAreaValid&&e.faceDimensionsValid||o.push(v.DOCUMENT_FACE_GEOMETRY_INVALID),i&&(e.faceAdjacentTextLineCount<2||!e.textParallel||e.textSide!==`right`)&&o.push(v.DOCUMENT_TEXT_ALIGNMENT_INVALID),o},x=async({classification:e,codes:t,ocr:n,options:i,documentAnalysis:o,document:c,text:u,prepareForMatch:d})=>{let p=o.detection,m=i.requiresFace??!0,h={boundingRect:{height:c.height,width:c.width,x:0,y:0},polygon:[{x:0,y:0},{x:c.width,y:0},{x:c.width,y:c.height},{x:0,y:c.height}]},g=m?await l.detectDocumentFaces({detection:h,frame:c.frame}):{faces:[],pictureFaces:[],hasPictureFace:await l.detectDocumentFacePresence({detection:h,frame:c.frame})},y=g.pictureFaces.map(e=>s({document:c,face:e})),x=_({frame:c.frame,text:u.text}),S=t.find(e=>e.type===`mrz`)??null,C=null;for(let h of g.faces.length?g.faces:[null]){let _=h?s({document:c,face:h}):null,w=h?a({face:h}):null,T=m&&p?l.faceIsInsideDocument({detection:p,face:_})&&y.every(e=>l.faceIsInsideDocument({detection:p,face:e})):!1,E=r({documentSize:{height:u.height,width:u.width},face:w,lines:u.lines,maxAngleDifference:i.maxDocumentTextAngleDifference,maxFaceAreaRatio:i.maxDocumentFaceAreaRatio,maxFaceHeightRatio:i.maxDocumentFaceHeightRatio,maxFaceWidthRatio:i.maxDocumentFaceWidthRatio,minFaceAreaRatio:i.minDocumentFaceAreaRatio,minFaceHeightRatio:i.minDocumentFaceHeightRatio,minFaceWidthRatio:i.minDocumentFaceWidthRatio}),D=b({alignment:E,detection:p,documentAnalysis:o,faceContained:T,requiresFace:m,text:u});m&&!e&&D.push(v.DOCUMENT_NOT_RECOGNIZED),e?.europeanDrivingLicense&&!O({identity:e.identity})&&D.push(v.DOCUMENT_VALIDATION_FAILED);let k=D.length===0,A=null,j=null;if(m&&k&&h){let e=f.prepareFace({alignment:i.alignment??`eyes-nose-mouth`,face:h,frame:c.frame});if(!e)k=!1,D.push(v.FACE_NOT_USABLE);else if(d){let t=await f.preparedFaceArtifacts({face:e});A=t?.embeddings??null,j=t?.images??null,t||(k=!1,D.push(v.INVALID_MODEL_OUTPUT))}}let M={identity:e?e.identity:null,orientation:c.orientation,ocr:n,mrz:S,alignment:E,detection:p,documentAnalysis:o,documentKind:e?e.document:null,europeanDrivingLicense:e?e.europeanDrivingLicense:!1,codes:t,documentToSource:c.toSource,embeddings:A,images:j,face:_,faceContained:T,hasPictureFace:g.hasPictureFace??y.length>0,failureReasons:D,pictureFaces:y,signature:x,text:u,valid:k};if(M.valid)return M;C??=M}if(!C)throw Error(v.INTERNAL_ERROR);return C},S=async({frame:t,options:a,documentAnalysis:s,prepareForMatch:c=!1})=>{let l=s.detection;if(!l){let e={height:0,lines:[],text:``,width:0},t=r({documentSize:{height:e.height,width:e.width},face:null,lines:e.lines,maxAngleDifference:a.maxDocumentTextAngleDifference,maxFaceAreaRatio:a.maxDocumentFaceAreaRatio,maxFaceHeightRatio:a.maxDocumentFaceHeightRatio,maxFaceWidthRatio:a.maxDocumentFaceWidthRatio,minFaceAreaRatio:a.minDocumentFaceAreaRatio,minFaceHeightRatio:a.minDocumentFaceHeightRatio,minFaceWidthRatio:a.minDocumentFaceWidthRatio});return{identity:null,orientation:null,ocr:null,mrz:null,codes:[],europeanDrivingLicense:!1,alignment:t,detection:l,documentAnalysis:s,documentKind:null,documentToSource:null,embeddings:null,face:null,faceContained:!1,failureReasons:b({alignment:t,detection:l,documentAnalysis:s,faceContained:!1,requiresFace:a.requiresFace??!0,text:e}),images:null,pictureFaces:[],hasPictureFace:!1,signature:null,text:e,valid:!1}}let u=await o({frame:t,polygon:l.polygon,orientation:l.orientation});if(!u)throw Error(v.IMAGE_PROCESSING_FAILED);try{let r=performance.now(),o=d({image:h({frame:t}),polygon:l.polygon,sourceOrientation:u.orientation.rotation}),f=a.requiresFace===!1?`back`:`front`;i({category:`stages`,key:`ocr.prepare.${f}`,duration:performance.now()-r});let _=h({frame:u.frame}),v=await m.readRectifiedText({classificationImage:_,engine:a.ocrEngine,frame:u.frame,language:a.language,image:o}),y=v??{height:u.height,lines:[],text:``,width:u.width},b=v?n({result:v}):null,S=null;if(a.requiresFace===!1){let t=e.createImageData(_.width,_.height);t.data.set(_.data),S=await g({key:`barcode.back`,operation:()=>Ye({image:t})})}let C=[b,S].filter(e=>e!==null),w=p({image:_,text:y.text,codes:C}),T=a.requiresFace!==!1&&w?.europeanDrivingLicense&&v?U({ocr:v,image:_}):null,E=w?{...w,identity:T}:null;return await x({ocr:v,classification:E,codes:C,options:a,documentAnalysis:s,document:u,prepareForMatch:c,text:y})}finally{u.frame.close()}},C=async({frame:e,options:t,prepareForMatch:n=!1})=>{let r=await c({frame:e,minDocumentBoxRatio:t.minDocumentBoxRatio});return await S({frame:e,options:t,documentAnalysis:r,prepareForMatch:n})},w=({analysis:e,isBack:t,front:n})=>{if(!e.ocr)return[v.DOCUMENT_TEXT_NOT_READABLE];if(t&&!n)return[v.CAPTURES_INCOMPLETE];if(!t&&!e.documentKind)return[v.DOCUMENT_NOT_RECOGNIZED];let r={ocr:e.ocr,codes:e.codes},i=t&&n?n:{document:e.documentKind,europeanDrivingLicense:e.europeanDrivingLicense,identity:e.identity};return u({classification:i,front:t&&n?n:r,back:t?r:null}).reasons.filter(e=>t||e!==v.DOCUMENT_BACK_REQUIRED)};return{validateDocumentBack:y,analyzeDocumentFrame:C,hasValidDocumentSideData:e=>w(e).length===0,documentSideFailureReasons:w}},at=({runtime:e,document:n,readImage:r})=>async({image:i,timings:a})=>{let o=await e.createImageBitmap(new Blob([i]));try{let i=performance.now(),s=await n.analyzeDocument({frame:o});if(a&&(a.documentBoxDetectionMs=performance.now()-i),!s.detection)throw Error(v.DOCUMENT_NOT_FOUND);let{polygon:c,orientation:l}=s.detection,u=d({image:r({frame:o}),polygon:c,sourceOrientation:l?.rotation}),f=e.createCanvas(u.width,u.height);try{let t=f.getContext(`2d`);if(!t)throw Error(v.IMAGE_PROCESSING_FAILED);let n=e.createImageData(u.width,u.height);n.data.set(u.data),t.putImageData(n,0,0);let r=await f.convertToBlob({type:`image/png`});return new Uint8Array(await r.arrayBuffer())}finally{t({canvas:f})}}finally{o.close()}},{alignment:ot,document:K,face:q,text:st,match:J,flow:ct,classify:lt,prepareOcrImage:ut,warmup:dt}=(({runtime:e,getOcr:t,faceMatcher:n})=>{let r=F({runtime:e}),i=A({runtime:e}),a=T({runtime:e}),o=E({runtime:e,imageFromImageBitmap:r}),s=rt({runtime:e,getOcr:t,...i}),c=N({runtime:e,...i,...a,...o,faceDetection:o,faceMatcher:n});return{alignment:i,document:a,face:o,text:s,match:c,flow:it({runtime:e,...i,...a,faceDetection:o,faceMatch:c,textDetection:s}),classify:Xe({runtime:e,detector:a,alignment:i,text:s,readImage:r}),prepareOcrImage:at({runtime:e,document:a,readImage:r}),warmup:async()=>{await Promise.all([o.loadFaceDetector({faceDetector:`standard`}),c.loadFaceMatch(),a.loadDocumentBoxDetector(),a.loadDocumentOrientationDetector(),s.loadTextDetector({engine:`tiny`,language:`latin`}),Je()])}}})({runtime:l,getOcr:Fe}),{classifyDocument:ft,detectDocument:pt,extractDocumentCodes:mt}=lt,{detectDocumentOrientation:ht,loadDocumentOrientationDetector:gt}=K,_t=[`faceStraight`,`faceUp`,`faceDown`,`faceLeft`,`faceRight`],Y=[`faceStraight`,`faceUp`,`faceLeft`,`faceRight`],X=[..._t,`faceSmile`,`faceWinkLeft`,`faceTiltLeft`,`faceTiltRight`];y(X);var vt={faceStraight:0,faceLeft:1,faceRight:1,faceUp:2,faceDown:2,faceTiltLeft:3,faceTiltRight:3,faceSmile:4,faceWinkLeft:5},Z={faceStraight:`face_straight`,faceUp:`face_up`,faceDown:`face_down`,faceLeft:`face_left`,faceRight:`face_right`,faceSmile:`face_smile`,faceWinkLeft:`face_wink_left`,faceTiltLeft:`face_tilt_left`,faceTiltRight:`face_tilt_right`};y(Z),_t.map(e=>Z[e]),Y.map(e=>Z[e]);var yt=async()=>{let e=await fetch(oe({filename:`faceMeshLines.json`}));if(!e.ok)throw Error(I.INVALID_SERVICE_RESPONSE);return await e.json()},bt=async()=>{await yt()},{transformPoint:xt}=ot,St=[`tessellation`,`contours`,`faceOval`,`lips`,`leftEye`,`rightEye`,`leftEyebrow`,`rightEyebrow`,`leftIris`,`rightIris`],Ct=async({color:e,context:t,result:n})=>{let r=await yt();t.beginPath();for(let e of St)for(let{start:i,end:a}of r[e]){let e=n.mesh.landmarks[i],r=n.mesh.landmarks[a];e&&r&&(t.moveTo(e.x,e.y),t.lineTo(r.x,r.y))}t.strokeStyle=e,t.lineWidth=1,t.stroke()},wt=({backgroundColor:e,color:t,context:n,line:r,toSource:i})=>{if(!r.text)return;let{x:a,y:o,width:s,height:c}=r.box,l=[{x:a,y:o},{x:a+s,y:o},{x:a+s,y:o+c},{x:a,y:o+c}].map(e=>xt({homography:i,point:e})),u=l[0],d=l[1],f=l[3];if(!u||!d||!f)return;let p=Math.hypot(d.x-u.x,d.y-u.y),m=Math.hypot(f.x-u.x,f.y-u.y),h=Math.max(8,Math.min(16,m*.7)),g=Math.max(0,p-4),_=Math.atan2(d.y-u.y,d.x-u.x);n.beginPath(),n.moveTo(u.x,u.y);for(let e of l.slice(1))n.lineTo(e.x,e.y);n.closePath(),n.strokeStyle=t,n.lineWidth=1,n.stroke(),n.save(),n.clip(),n.translate(u.x+2,u.y+2),n.rotate(_),n.font=`${h}px sans-serif`,n.textBaseline=`top`,n.lineWidth=3,n.strokeStyle=e,n.strokeText(r.text,0,0,g),n.fillStyle=t,n.fillText(r.text,0,0,g),n.restore()},Tt=async({element:e,meshLineColor:t,overlayColor:n=`transparent`,result:r})=>{let i=e.getContext(`2d`);if(!i)throw Error(I.IMAGE_PROCESSING_FAILED);let a=r?.mesh.width??e.width,o=r?.mesh.height??e.height;e.width!==a&&(e.width=a),e.height!==o&&(e.height=o),se({element:e}),n!==`transparent`&&(i.fillStyle=n,i.fillRect(0,0,a,o)),r&&await Ct({color:t,context:i,result:r})},Et=async({documentFaceBoxColor:e,documentFaceMeshColor:t,documentBoxColor:n,element:r,detection:i,face:a,height:o,ocrLines:s=[],ocrToSource:c=null,overlayColor:l=`transparent`,textColor:u,width:d})=>{let f=r.getContext(`2d`);if(f&&d&&o){if(r.width!==d&&(r.width=d),r.height!==o&&(r.height=o),se({element:r}),l!==`transparent`&&(f.fillStyle=l,f.fillRect(0,0,d,o)),i){f.strokeStyle=n,f.lineWidth=3,f.beginPath();for(let[e,t]of i.polygon.entries())e?f.lineTo(t.x,t.y):f.moveTo(t.x,t.y);f.closePath(),f.stroke()}if(a&&(f.strokeStyle=e,f.lineWidth=2,f.strokeRect(a.boundingRect.x,a.boundingRect.y,a.boundingRect.width,a.boundingRect.height),await Ct({color:t,context:f,result:a})),c){let e=getComputedStyle(r).color;for(let t of s)wt({backgroundColor:e,color:u,context:f,line:t,toSource:c})}}},Q={documentTargets:{front:`frameDocument`,back:`frameDocumentBack`,passport:`framePassport`},rejections:{FACE_NOT_DETECTED:`faceNotFound`,FACE_IN_POLYGON:`faceInPolygon`,FACE_TOO_SMALL:`faceTooSmall`,FACE_CENTER_MOVE_LEFT:`faceCenterMoveLeft`,FACE_CENTER_MOVE_RIGHT:`faceCenterMoveRight`,FACE_CENTER_MOVE_UP:`faceCenterMoveUp`,FACE_CENTER_MOVE_DOWN:`faceCenterMoveDown`,FACE_STABILITY_REQUIRED:`stayStill`,DOCUMENT_NOT_DETECTED:`documentNotDetected`,DOCUMENT_BOX_TOO_SMALL:`documentBoxTooSmall`,DOCUMENT_BOX_TOO_LARGE:`documentBoxTooLarge`,DOCUMENT_BOX_NEAR_EDGE:`documentBoxNearEdge`,DOCUMENT_BOX_TOUCHES_EDGES:`documentBoxTouchesEdges`,DOCUMENT_SHAPE_INVALID:`documentShapeInvalid`,DOCUMENT_NOT_SUPPORTED:`documentNotSupported`,DOCUMENT_BLURRY:`documentBlurry`,DOCUMENT_FRONT_FACE_NOT_DETECTED:`faceNotVisibleInDocument`,DOCUMENT_FRONT_FACE_NOT_CONTAINED:`faceNotVisibleInDocument`,DOCUMENT_FRONT_FACE_TOO_SMALL:`documentPhotoTooSmall`,DOCUMENT_FRONT_FACE_SIZE_INVALID:`documentAlignmentInvalid`,DOCUMENT_FRONT_LAYOUT_INVALID:`documentAlignmentInvalid`,DOCUMENT_TEXT_NOT_READABLE:`documentNotReadable`,DOCUMENT_NOT_RECOGNIZED:`invalidDocument`,DOCUMENT_CODE_NOT_READABLE:`passportMrzNotReadable`,DOCUMENT_BACK_HAS_FACE:`documentBackHasFace`,DOCUMENT_BACK_SAME_AS_FRONT:`documentBackSameAsFront`,DOCUMENT_STABILITY_REQUIRED:`holdDocumentStill`,DOCUMENT_VALIDATION_FAILED:`documentValidationFailed`}},Dt=({target:e})=>Q.documentTargets[e],Ot=({code:e})=>e===`FACE_CAMERA_ALIGNMENT_REQUIRED`?P():e in Q.rejections?Q.rejections[e]:w({code:e}),{detectPictureFaces:kt}=q,$={FACEKEY_LOWER_HEAD:`FACE_PITCH_LOOK_DOWN`,FACEKEY_LOWER_HEAD_LESS:`FACE_PITCH_LOWER_LESS`,FACEKEY_RAISE_HEAD:`FACE_PITCH_LOOK_UP`,FACEKEY_RAISE_HEAD_LESS:`FACE_PITCH_RAISE_LESS`,FACEKEY_TILT_HEAD_LEFT:`FACE_ROLL_TILT_LEFT`,FACEKEY_TILT_HEAD_LESS:`FACE_ROLL_TILT_LESS`,FACEKEY_TILT_HEAD_RIGHT:`FACE_ROLL_TILT_RIGHT`,FACEKEY_TURN_HEAD_LEFT:`FACE_YAW_TURN_LEFT`,FACEKEY_TURN_HEAD_LESS:`FACE_YAW_TURN_LESS`,FACEKEY_TURN_HEAD_RIGHT:`FACE_YAW_TURN_RIGHT`,FACEKEY_SMILE_REQUIRED:`FACE_SMILE_REQUIRED`,FACEKEY_WINK_LEFT_REQUIRED:`FACE_WINK_LEFT_REQUIRED`},At=({face:e,name:t})=>e.blendshapes[t]??0,jt=({face:e,frame:t})=>e.boundingRect.height/t.height<.4?`FACE_TOO_SMALL`:null,Mt=({face:e,pose:t,options:n})=>{let r=x({...e,pose:t,options:n});return r?$[r]:null},Nt=({face:e,pose:t,options:n})=>Mt({face:e,pose:t,options:n})===null,Pt=async({capture:e,pose:t,options:n,poseOptions:r,requireEyeLevelCamera:i})=>{let a=await J.imageBitmap({blob:e});try{let e=await kt(a),o=e.length===1?e[0]:null;if(!o||!Nt({face:o,pose:t,options:r})||j({pitch:o.pitch,pose:t,requireEyeLevelCamera:i,options:r}))return null;let s=J.prepareFace({alignment:n.alignment,face:o,frame:a});return s?await J.preparedFaceArtifacts({face:s}):null}finally{a.close()}},{detectDocumentBox:Ft}=K,{detectFace:It}=q,Lt=({view:e,display:t,isActive:n,notifyCapturesChanged:r})=>{let i=e.ref,a=({state:e})=>e.faceSequence[e.poseIndex]??`faceStraight`,o=({face:e,frame:n})=>{let r=e.boundingRect.x+e.boundingRect.width/2,i=e.boundingRect.y+e.boundingRect.height/2,a=(t.cameraFacingMode.value===`user`?n.width-r:r)/n.width,o=i/n.height;return a<.4?`FACE_CENTER_MOVE_RIGHT`:a>.6?`FACE_CENTER_MOVE_LEFT`:o<.4?`FACE_CENTER_MOVE_DOWN`:o>.6?`FACE_CENTER_MOVE_UP`:null},s=async({frame:s,session:c,state:l,options:u})=>{let d=performance.now(),f=null,p=!1;try{f=await It(s);let e=f?await Ft(s):null;if(p=!!(f&&e&&h({face:f,polygon:e.polygon})),!n({flow:`face`,session:c,state:l}))return!1;if(u.showFaceOverlay&&await Tt({element:i.mesh,meshLineColor:u.faceMeshColor,overlayColor:u.faceOverlayColor,result:f}),!f){l.poseStableFrames=0;let e=a({state:l});return t.feedback.value={flow:`face`,code:`FACE_NOT_DETECTED`,pose:e},!1}if(p)return l.poseStableFrames=0,t.feedback.value={flow:`face`,code:`FACE_IN_POLYGON`,pose:a({state:l})},!1;let d=a({state:l}),m=jt({face:f,frame:s});if(m)return l.poseStableFrames=0,t.feedback.value={flow:`face`,code:m,pose:d},!1;let g=o({face:f,frame:s});if(g)return l.poseStableFrames=0,t.feedback.value={flow:`face`,code:g,pose:d},!1;let _=j({pitch:f.pitch,pose:d,requireEyeLevelCamera:u.requireEyeLevelCamera,options:u});if(_)return l.poseStableFrames=0,l.guidanceCodeState=b(),l.correctiveState=D(),t.guidance.value=null,t.corrective.value=null,t.feedback.value={flow:`face`,code:_,pose:d},!1;let v={pitch:f.pitch,yaw:f.yaw,roll:f.roll},y=ee({alignment:v,blendshapes:f.blendshapes,neutral:l.neutralPose,pose:d,options:u});l.guidanceCodeState=te({state:l.guidanceCodeState,code:y.code,requiredFrames:3}),t.guidance.value=y;let x=y.code?$[y.code]:null,C=l.guidanceCodeState.published?$[l.guidanceCodeState.published]:null,w=S({pose:d,corrective:C?Ot({code:C}):null}).corrective,T=performance.now();if(l.correctiveState=M({label:w,now:T,state:l.correctiveState}),t.corrective.value=ne({label:w,now:T,state:l.correctiveState}),x)return l.poseStableFrames=0,t.feedback.value={flow:`face`,code:C,pose:d},!1;if(d===`faceStraight`&&(l.neutralPose=v),l.poseStableFrames+=1,l.poseStableFrames<u.requiredFaceStableFrames)return t.feedback.value={flow:`face`,code:`FACE_STABILITY_REQUIRED`,pose:d},!1;t.feedback.value={flow:`face`,code:null,pose:d};let E=await ae({frame:s}),O=await Pt({capture:E,pose:d,options:l.matchOptions,poseOptions:u,requireEyeLevelCamera:u.requireEyeLevelCamera});if(!n({flow:`face`,session:c,state:l}))return!1;if(!O)return l.poseStableFrames=0,t.feedback.value={flow:`face`,code:`FACE_STABILITY_REQUIRED`,pose:d},!1;let k=et({image:J.readImage({frame:s,width:32,height:32})}),A=l.previousPoseBackgroundSignature;if(A&&!tt({first:A,second:k}).matched)throw Error(I.POSE_BACKGROUND_MISMATCH);let N=l.faceEmbeddings.faceStraight;if(N&&re({first:N,second:O.embeddings})<=l.matchOptions.threshold)throw Error(I.POSE_IDENTITY_MISMATCH);let P=d;return l.captures[P]=E,l.preparedCaptures[P]=O.images,l.faceEmbeddings[P]=O.embeddings,l.previousPoseBackgroundSignature=k,r({state:l}),t.success.value=!0,await ie({milliseconds:400}),t.success.value=!1,n({flow:`face`,session:c,state:l})?(l.poseIndex+=1,l.poseStableFrames=0,l.guidanceCodeState=b(),l.correctiveState=D(),t.corrective.value=null,t.progress.value={completed:l.poseIndex,total:l.faceSequence.length},l.poseIndex===l.faceSequence.length?(t.feedback.value=null,!0):(t.feedback.value={flow:`face`,pose:a({state:l}),code:null},!1)):!1}finally{n({flow:`face`,session:c,state:l})&&e.collectFaceDebug({face:f,faceInPolygon:p,processingTimeMilliseconds:performance.now()-d,state:l}),s.close()}};return{runFaceLoop:async({session:e,state:r,options:a})=>{for(;n({flow:`face`,session:e,state:r});){if(await ce({video:i.video}),!n({flow:`face`,session:e,state:r}))return;let o=await createImageBitmap(i.video);if(await s({frame:o,session:e,state:r,options:a})){r.flow=null,t.debug.value=[],t.guidance.value=null;return}}}}},Rt=({captures:e,state:t})=>t.faceSequence.every(n=>!!(e[n]&&t.preparedCaptures[n]&&t.faceEmbeddings[n])),zt=({captures:e,state:t})=>{if(!Rt({captures:e,state:t}))throw Error(I.CAPTURES_INCOMPLETE);let n=[...t.faceSequence];return{faces:n.map(t=>e[t]).filter(e=>!!e),poses:n,embeddings:n.map(e=>t.faceEmbeddings[e]).filter(e=>!!e)}},Bt=({sequence:e})=>{let t=[...e];for(let e=t.length-1;e>0;--e){let n=Math.floor(Math.random()*(e+1));[t[e],t[n]]=[t[n],t[e]]}return t},Vt=({sequence:e})=>[...e].sort((e,t)=>vt[e]-vt[t]),Ht=({poses:e,randomize:t})=>{let n=e===`all`?[...X]:e??Y;if(!n.length)throw Error(I.INVALID_POSES);let r=[...new Set(n)];if(r.length!==n.length||r.some(e=>!X.includes(e))||r[0]!==`faceStraight`||Y.some(e=>!r.includes(e)))throw Error(I.INVALID_POSES);let i=r.slice(1);return t?[`faceStraight`,...Bt({sequence:i})]:[`faceStraight`,...Vt({sequence:i})]},Ut=()=>({activity:C(null),error:C(null),retry:C(null),feedback:C(null),guidance:C(null),corrective:C(null),progress:C({completed:0,total:0}),success:C(!1),cameraSize:C(null),cameraFacingMode:C(null),debug:C([]),debugEnabled:C(!1)});export{J as _,Rt as a,B as b,Ot as c,Z as d,Y as f,gt as g,ct as h,zt as i,Et as l,q as m,Lt as n,Ht as o,K as p,At as r,Dt as s,Ut as t,bt as u,st as v,je as x,Je as y};
|
package/dist/sdk/verify.d.ts
CHANGED
|
@@ -11,7 +11,9 @@ export type Pose =
|
|
|
11
11
|
| "faceTiltLeft"
|
|
12
12
|
| "faceTiltRight";
|
|
13
13
|
|
|
14
|
-
export type Language = "ar" | "ch" | "de" | "en" | "es" | "fr" | "it" | "ja" | "pt" | "zh";
|
|
14
|
+
export type Language = "ar" | "ch" | "de" | "en" | "es" | "fr" | "it" | "ja" | "pt" | "ru" | "zh";
|
|
15
|
+
|
|
16
|
+
export type Theme = "light" | "dark";
|
|
15
17
|
|
|
16
18
|
export type OcrEngine =
|
|
17
19
|
| "auto"
|
|
@@ -27,6 +29,15 @@ export type FaceDetectorName = "high" | "standard" | "low";
|
|
|
27
29
|
|
|
28
30
|
export type VerificationCapability = "verifyHuman" | "verifyDocument" | "matchID" | "matchPicture";
|
|
29
31
|
|
|
32
|
+
export type VerificationAction = "human" | "document" | "match_id" | "match_picture";
|
|
33
|
+
|
|
34
|
+
export type AuthorizedVerifyIntent = {
|
|
35
|
+
resultId: string;
|
|
36
|
+
token: string;
|
|
37
|
+
expiresAt: string;
|
|
38
|
+
action: string;
|
|
39
|
+
};
|
|
40
|
+
|
|
30
41
|
export type VerificationOperationOptions = {
|
|
31
42
|
poses?: Pose[] | "all";
|
|
32
43
|
randomizeFaceSequence?: boolean;
|
|
@@ -41,10 +52,13 @@ export type VoltomOptions = {
|
|
|
41
52
|
root?: HTMLElement;
|
|
42
53
|
video?: HTMLVideoElement;
|
|
43
54
|
ui?: boolean;
|
|
55
|
+
prepare?: boolean;
|
|
44
56
|
language?: Language;
|
|
57
|
+
theme?: Theme;
|
|
45
58
|
ocrEngine?: OcrEngine;
|
|
46
59
|
faceDetector?: FaceDetectorName;
|
|
47
60
|
clientKey: string;
|
|
61
|
+
authorize?: (input: { action: string }) => Promise<AuthorizedVerifyIntent>;
|
|
48
62
|
requireEyeLevelCamera?: boolean;
|
|
49
63
|
apiUrl?: string;
|
|
50
64
|
threshold?: number;
|
|
@@ -118,6 +132,8 @@ export type IdentityPayload = {
|
|
|
118
132
|
raw_data: { mrz_lines: string[]; aamva_version: string | null };
|
|
119
133
|
};
|
|
120
134
|
|
|
135
|
+
export type VoltomIdentity = Omit<IdentityPayload, "raw_data">;
|
|
136
|
+
|
|
121
137
|
export type DocumentCode = { code: string; payload: IdentityPayload; type: "mrz" | "aamva" | "ocr" };
|
|
122
138
|
|
|
123
139
|
export type OcrLine = {
|
|
@@ -150,16 +166,16 @@ export type VoltomCaptureResult = {
|
|
|
150
166
|
};
|
|
151
167
|
|
|
152
168
|
export type VoltomVerificationResult = {
|
|
153
|
-
|
|
169
|
+
resultId: string;
|
|
154
170
|
mode: Mode;
|
|
155
|
-
|
|
156
|
-
outcome: "
|
|
171
|
+
action: VerificationAction;
|
|
172
|
+
outcome: "pass" | "fail" | "error" | null;
|
|
157
173
|
matched: boolean | null;
|
|
158
174
|
score: number | null;
|
|
159
175
|
threshold: number | null;
|
|
160
176
|
reason: string | null;
|
|
161
|
-
|
|
162
|
-
identity:
|
|
177
|
+
documentCode: string | null;
|
|
178
|
+
identity: VoltomIdentity | null;
|
|
163
179
|
completedAt: string | null;
|
|
164
180
|
createdAt: string;
|
|
165
181
|
};
|
|
@@ -177,6 +193,7 @@ export type VerificationPresentationState = {
|
|
|
177
193
|
|
|
178
194
|
declare class VoltomVerify {
|
|
179
195
|
constructor(options: VoltomOptions);
|
|
196
|
+
preload(): Promise<void>;
|
|
180
197
|
prepare(): Promise<void>;
|
|
181
198
|
caniuse(): Promise<VoltomBrowserSupport>;
|
|
182
199
|
verifyHuman(settings?: VerificationOperationOptions): Promise<VoltomVerificationResult>;
|