@voltom.io/sdk 1.0.3 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/locales/ar.json +57 -9
- package/dist/assets/locales/ch.json +57 -9
- package/dist/assets/locales/de.json +57 -9
- package/dist/assets/locales/en.json +30 -5
- package/dist/assets/locales/es.json +56 -8
- package/dist/assets/locales/fr.json +56 -8
- package/dist/assets/locales/it.json +55 -7
- package/dist/assets/locales/ja.json +57 -9
- package/dist/assets/locales/pt.json +57 -9
- package/dist/assets/locales/ru.json +124 -0
- package/dist/assets/locales/zh.json +57 -9
- package/dist/sdk/PoseSilhouette-Bbwmry4Z.js +2 -0
- package/dist/sdk/PoseSuccess-C3aBF88E.js +2 -0
- package/dist/sdk/eyeLevelCamera-DY4onSBz.js +65 -0
- package/dist/sdk/facegate/global.d.ts +5 -0
- package/dist/sdk/facegate.d.ts +55 -0
- package/dist/sdk/facegate.dist.js +56 -0
- package/dist/sdk/facegate.js +2 -0
- package/dist/sdk/facekey.browser-CVJiBw1f.js +2 -0
- package/dist/sdk/facekey.d.ts +13 -17
- package/dist/sdk/facekey.dist.js +5 -4
- package/dist/sdk/facekey.js +1 -1
- package/dist/sdk/media-BRKPXpu3.js +2 -0
- package/dist/sdk/presentation-B-TOKUZ3.js +8 -0
- package/dist/sdk/presentation-BsnbDv0i.js +2 -0
- package/dist/sdk/verify.d.ts +30 -32
- package/dist/sdk/verify.dist.js +18 -18
- package/dist/sdk/verify.js +1 -1
- package/dist/sdk/view-Bfg8u_hZ.js +2 -0
- package/dist/sdk/view-CHSkN6gO.js +3 -0
- package/dist/sdk/view-DmGKdc3M.js +3 -0
- package/package.json +25 -16
- package/dist/sdk/DebugPanel-BJqGy2Dp.js +0 -2
- package/dist/sdk/faceMatch.shared-D6B1I2T0.js +0 -65
- package/dist/sdk/feedback-Cs09W_hs.js +0 -2
- package/dist/sdk/presentation-BrCGZT1u.js +0 -8
- package/dist/sdk/presentation-Jz2euuHa.js +0 -2
- package/dist/sdk/view-usv6rHIE.js +0 -3
- package/dist/sdk/view-vxhVZZc1.js +0 -2
package/dist/sdk/facekey.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/*! Copyright (c) 2026 VOLTOM. All rights reserved. Proprietary software. See LICENSE at https://voltom.io/license. */
|
|
2
|
-
import{$ as e,G as t,J as n,K as r,X as i,_ as a,c as o,dt as s,et as c,i as l,j as u,k as d,n as f,nt as p,q as m,r as h,rt as g,s as _,t as v,v as y}from"./faceMatch.shared-D6B1I2T0.js";import{n as b,t as x}from"./presentation-Jz2euuHa.js";var S=u({runtime:d}),C=f({runtime:d}),w=l({runtime:d}),T=h({runtime:d,imageFromImageBitmap:S}),E=v({runtime:d,...C,...w,...T,faceDetection:T}),D=e=>{if(typeof e.token!=`string`||e.token.length<32||e.token.length>128||e.userId!==void 0&&(typeof e.userId!=`string`||e.userId.length<1||e.userId.length>255))throw Error(c.INVALID_OPTIONS);return e},O=e=>e.length===512&&e.every(e=>Number.isFinite(e))&&Math.abs(Math.hypot(...e)-1)<.001?e:null,{detectDocumentBox:k,loadDocumentBoxDetector:A}=w,{detectPictureFaces:j,loadFaceDetector:M}=T,{imageBitmap:N,loadFaceMatch:P,preparedFaceEmbeddings:F,prepareFace:I,warmupFaceMatch:L}=E,R=({face:e})=>e?{left:e.blendshapes.eyeBlinkLeft??0,right:e.blendshapes.eyeBlinkRight??0}:null,z=({face:e,frame:t})=>e.boundingRect.height/Math.min(t.width,t.height)<.5?`FACE_TOO_SMALL`:null,B=({face:e,frame:t})=>{let n=e.boundingRect.x+e.boundingRect.width/2,r=e.boundingRect.y+e.boundingRect.height/2,i=Math.min(t.width,t.height);return Math.hypot(n-t.width/2,r-t.height/2)<=i*.08},V=async({frame:e,pose:t,signal:n})=>{let r=await j(e);n.throwIfAborted();let i=r.length===1?r[0]:null,s=i?await k(e):null;n.throwIfAborted();let c=!!(i&&s&&a({face:i,polygon:s.polygon})),l=i?z({face:i,frame:e}):null,u=!!(i&&B({face:i,frame:e})),d=i?o({...i,pose:t,options:y}):null,f=`Keep one face in view`;i&&(f=(c?`In polygon`:null)??l??(u?d:`Center your face in the circle`));let p=d;return u||(p=`FACE_NOT_CENTERED`),l&&(p=`FACE_TOO_SMALL`),c&&(p=`FACE_IN_POLYGON`),i||(p=`FACE_NOT_DETECTED`),{faces:r,face:i,faceInPolygon:c,framing:l,centered:u,poseRejection:d,reason:f,code:p}},H=async({capture:e,pose:t,signal:n,language:r})=>{let i=await N({blob:e});try{n.throwIfAborted();let e=await V({frame:i,pose:t,signal:n}),{face:a,poseRejection:o}=e,s=R({face:a}),l=o&&e.reason===o?b({pose:t,rejection:o,language:r}):e.reason;if(!a||l)return{vector:null,reason:l,eyeScores:s};let u=I({alignment:`eyes-nose-mouth`,face:a,frame:i}),d=u?await F({face:u}):null;if(n.throwIfAborted(),!d)return{vector:null,reason:c.FACE_NOT_USABLE,eyeScores:s};let f=O(d.grayscale);return{vector:f,reason:f?null:c.INVALID_MODEL_OUTPUT,eyeScores:s}}finally{i.close()}},U=class{options;view=null;useUi;display=x();events=new EventTarget;controller=null;operationId=``;modelsReady=null;prepared=!1;disposed=!1;subscriptions=new Set;constructor(e){if(this.useUi=e.ui??!e.video,!this.useUi&&!e.video)throw Error(c.INVALID_OPTIONS);this.options=Object.freeze({...e,capabilities:Object.freeze([...e.capabilities??[`enroll`,`unlock`,`forget`]])})}async prepare(){if(this.disposed)throw Error(c.SDK_NOT_READY);if(this.prepared)return;if(await e({language:this.options.language}),this.useUi&&!this.view){let{createFaceKeyView:e}=await import(`./view-vxhVZZc1.js`);if(this.disposed)throw Error(c.SDK_NOT_READY);this.view=e({options:this.options,display:this.display,events:this.events,onStop:()=>this.stop()})}if(!this.modelsReady){let e=this.options.capabilities.some(e=>e!==`forget`)?Promise.all([A(),M({faceDetector:`standard`}),P()]).then(async()=>{let e=document.createElement(`canvas`);e.width=640,e.height=480;let t=await createImageBitmap(e);try{await Promise.all([j(t),k(t),L()])}finally{t.close()}}):Promise.resolve();this.modelsReady=e}let t=this.modelsReady;try{if(await t,this.disposed)throw Error(c.SDK_NOT_READY);this.prepared=!0}catch(e){throw this.modelsReady===t&&(this.modelsReady=null),e}}async request({path:e,input:t,body:n,signal:r}){let i={authorization:`Bearer ${this.options.clientKey}`,"content-type":`application/json`},a=await fetch(`${(this.options.apiUrl??`https://api.voltom.io`).replace(/\/$/,``)}/facekey/${e}`,{method:`POST`,headers:i,body:JSON.stringify(n??t),signal:r}),o=await a.json();if(r.throwIfAborted(),!a.ok)throw Error(typeof o.code==`string`?o.code:c.INVALID_SERVICE_RESPONSE);return o}async capture({poses:e,signal:a,expiresAt:o,operation:s,input:l}){let u=this.useUi?this.view?.requiredVideo():this.options.video;if(!u)throw Error(c.INVALID_OPTIONS);let d=[];this.display.progress.value={completed:0,total:e.length};let f=null,h={userId:l.userId??``,matched:!1,matches:[],reason:null},g=l.token;a.throwIfAborted();let v=await m({facingMode:`user`,video:u,signal:a});a.throwIfAborted(),this.display.facingMode.value=v,this.display.phase.value=`capturing`;for(let[n,m]of e.entries()){let v=0,y=null;for(p(()=>{this.display.match.value=null,this.display.phase.value=`capturing`,this.display.instruction.value={pose:m,rejection:null,retry:null}});v<3;){if(await i({video:u,signal:a}),a.throwIfAborted(),Date.now()>=Date.parse(o))throw Error(c.FACEKEY_TOKEN_INVALID);if(u.readyState<HTMLMediaElement.HAVE_CURRENT_DATA)continue;let b=await createImageBitmap(u);try{let i=await V({frame:b,pose:m,signal:a}),{reason:u,code:x}=i;v=u===null?v+1:0;let S={...i,frame:b,operation:s,pose:m,stable:v};if(this.view?.collectCaptureDebug(S),this.display.instruction.value={pose:m,rejection:x,retry:y},v===3){let i=await t({frame:b});try{if(s===`unlock`){this.display.phase.value=`checking`;let t={token:g,userId:h.userId,poses:[m],faces:[await r({image:i})]},o=await this.request({path:`unlock/step`,input:{...l,token:g},body:t,signal:a});if(o.userId!==h.userId||o.matched&&(o.matches.length!==1||o.matches[0].pose!==m||!o.matches[0].matched))throw Error(c.INVALID_SERVICE_RESPONSE);if(this.display.match.value={accepted:o.matched,reason:o.reason,score:o.matches.length?o.matches[0].score:null},this.view?.collectCaptureDebug({...S,force:!0,reason:o.reason}),!o.matched){if(o.complete||!o.token)throw Error(c.INVALID_SERVICE_RESPONSE);g=o.token,v=0,y=`Face not recognized. Try this pose again.`,p(()=>{this.display.phase.value=`capturing`,this.display.instruction.value={pose:m,rejection:x,retry:y}}),await this.showFeedback({matched:!1,signal:a});continue}if(h={userId:o.userId,matched:o.complete,matches:[...h.matches,...o.matches],reason:o.reason},o.complete!==(n===e.length-1))throw Error(c.INVALID_SERVICE_RESPONSE);if(!o.complete){if(!o.token)throw Error(c.INVALID_SERVICE_RESPONSE);g=o.token}}else{let e=await H({capture:i,pose:m,signal:a,language:this.options.language}),t=e.vector;if(a.throwIfAborted(),Date.now()>=Date.parse(o))throw Error(c.FACEKEY_TOKEN_INVALID);let n=f&&t?_({first:f,second:t}):null,r=!!(t&&(n===null||n>.5)),s=e.reason??(r?null:c.POSE_IDENTITY_MISMATCH);if(this.display.match.value={accepted:r,reason:s,reference:!f&&r,score:n},this.view?.collectCaptureDebug({...S,force:!0,reason:s}),!t||!r){v=0,y=t?`Face does not match. Try this pose again.`:`Face not usable. Try this pose again.`,p(()=>{this.display.phase.value=`capturing`,this.display.instruction.value={pose:m,rejection:x,retry:y}}),t&&await this.showFeedback({matched:!1,signal:a});continue}f||=t}d.push(i)}catch(e){let t=e instanceof Error?e.message:`Capture failed`;throw this.display.match.value={accepted:!1,reason:t,score:null},this.view?.collectCaptureDebug({...S,force:!0,reason:t}),e}}}finally{b.close()}}this.display.progress.value={completed:n+1,total:e.length},await this.showFeedback({matched:!0,signal:a})}return n({video:u}),{captures:d,unlock:h}}async showFeedback({matched:e,signal:t}){t.throwIfAborted();let n=this.operationId;p(()=>{this.display.failures.value=e?0:this.display.failures.value+1,this.display.feedback.value={matched:e,animating:!0}});let r=Promise.withResolvers(),i=setTimeout(()=>r.resolve(),500),a=()=>r.resolve();t.addEventListener(`abort`,a,{once:!0});try{await r.promise,t.throwIfAborted()}finally{clearTimeout(i),t.removeEventListener(`abort`,a),this.operationId===n&&(this.display.feedback.value=e?null:{matched:!1,animating:!1})}}async run({operation:e,input:t,externalSignal:i,debug:a}){if(this.disposed||!this.prepared)throw Error(c.SDK_NOT_READY);if(!this.options.capabilities.includes(e))throw Error(c.SDK_CAPABILITY_NOT_CONFIGURED);if(this.controller)throw Error(c.INVALID_OPTIONS);let o=D(t);if(e!==`enroll`&&!o.userId)throw Error(c.INVALID_OPTIONS);let s=new AbortController;this.controller=s;let l=s.signal,u=()=>s.abort();i?.addEventListener(`abort`,u,{once:!0}),i?.aborted&&u();let d=[];this.operationId=crypto.randomUUID();try{if(e===`forget`)return await this.request({path:e,input:o,signal:l});p(()=>{this.display.operation.value=e,this.display.phase.value=`loading`,this.display.instruction.value=null,this.display.feedback.value=null,this.display.failures.value=0,this.display.error.value=null,this.display.debug.value=[],this.display.debugEnabled.value=a??this.options.debug??!1,this.display.match.value=null,this.display.progress.value={completed:0,total:1},this.display.facingMode.value=null}),this.view?.open();let t=await this.request({path:`challenge`,input:o,signal:l});if(t.operation!==e||o.userId&&t.userId!==o.userId)throw Error(c.FACEKEY_TOKEN_INVALID);let n=await this.capture({poses:t.poses,signal:l,expiresAt:t.expiresAt,operation:e,input:{...o,userId:t.userId}});d.push(...n.captures),l.throwIfAborted();let i=n.unlock;if(e===`enroll`){this.display.phase.value=`processing`;let n={token:o.token,userId:t.userId,poses:t.poses,faces:await Promise.all(d.map(e=>r({image:e})))};i=await this.request({path:e,input:o,body:n,signal:l})}let s=!(`matched`in i)||i.matched===!0;return this.display.phase.value=s?`success`:`failure`,await this.showFeedback({matched:s,signal:l}),i}catch(e){throw this.view?.dialog?.open&&p(()=>{this.display.phase.value=`failure`,this.display.error.value=e}),e}finally{i?.removeEventListener(`abort`,u),this.display.debugEnabled.value=this.options.debug??!1,d.length=0;let e=this.useUi?this.view?.dialog?.open?this.view.requiredVideo():null:this.options.video;e&&n({video:e}),this.view?.close(),this.controller=null}}async faceEnroll(e,{signal:t,debug:n}={}){return await this.run({operation:`enroll`,input:e,externalSignal:t,debug:n})}async faceUnlock(e,{signal:t,debug:n}={}){return await this.run({operation:`unlock`,input:e,externalSignal:t,debug:n})}async faceForget(e,{signal:t,debug:n}={}){return await this.run({operation:`forget`,input:e,externalSignal:t,debug:n})}stop(){this.controller&&this.controller.abort(new DOMException(c.VERIFICATION_CANCELLED,`AbortError`));let e=this.useUi?this.view?.dialog?.open?this.view.requiredVideo():null:this.options.video;e&&n({video:e}),this.view?.close()}dispose(){if(!this.disposed){this.disposed=!0,this.stop();for(let e of this.subscriptions)e();this.subscriptions.clear(),this.events=new EventTarget}}getState(){return{operation:this.display.operation.value,phase:this.display.phase.value,instruction:this.display.instruction.value,feedback:this.display.feedback.value,error:this.display.error.value,progress:this.display.progress.value,match:this.display.match.value,debug:this.display.debug.value}}subscribe(e){if(this.disposed)throw Error(c.SDK_NOT_READY);let t=g(()=>e(this.getState()));return this.subscriptions.add(t),()=>{t(),this.subscriptions.delete(t)}}};s({moduleUrl:import.meta.url});var W=U;export{U as VoltomFaceKey,W as default};
|
|
2
|
+
import{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};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! Copyright (c) 2026 VOLTOM. All rights reserved. Proprietary software. See LICENSE at https://voltom.io/license. */
|
|
2
|
+
var e=({moduleUrl:e})=>{let t=globalThis;t.__VOLTOM_ASSET_BASE_URL__||=new URL(`../`,e).href},t=({filename:e})=>{let t=globalThis.__VOLTOM_ASSET_BASE_URL__||globalThis.location?.href;if(!t)throw Error(`SDK_ASSET_BASE_URL_UNAVAILABLE`);return new URL(`assets/${e}`,t).href},n,r,i,a,o,s,c,l,u,d,f,p=Symbol.for(`pv`),m={},h=[],g=/^m(i|n|o|s|text|space)$/,_=Array.isArray,v=h.slice,y=Object.assign;function b(e){e&&e.parentNode&&e.remove()}function x(e,t,n){var r,i,a,o={},s=arguments.length;for(a in t)a==`key`?r=t[a]:a==`ref`&&typeof e!=`function`?i=t[a]:o[a]=t[a];return s>2&&(o.children=s>3?v.call(arguments,2):n),S(e,o,r,i,null)}function S(e,t,i,a,o){var s={type:e,props:t,key:i,ref:a,__k:null,__:null,__b:0,__e:null,__c:null,constructor:p,__v:o||++r,__i:-1,__u:0};return!o&&n.vnode&&n.vnode(s),s}function C(){return{current:null}}function w(e){return e.children}function T(e,t){this.props=e,this.context=t,this.__g=0}function E(e,t){if(t==null)return e.__&&E(e.__,e.__i+1);for(var n;t<e.__k.length;t++)if((n=e.__k[t])&&n.__e)return n.__e;return typeof e.type!=`function`||e.props.__P?null:E(e)}function D(e){if((e=e.__)&&e.__c&&!e.props.__P)return e.__e=null,e.__k.some(function(t){return t&&(e.__e=t.__e)}),D(e)}function O(e){(8&e.__g||(e.__g|=8,a.push(e),s++))&&o==n.debounceRendering||((o=n.debounceRendering)||queueMicrotask)(k)}function k(){var e,t,r,i,l,u,d,f,m;try{for(t=1;a.length;)a.length>t&&a.sort(c),e=a.shift(),t=a.length,8&e.__g&&(i=void 0,l=void 0,u=(l=(r=e).__v).__e,d=[],f=[],(m=r.__P)&&((i=y({constructor:p},l)).__v=l.__v+1,n.vnode&&n.vnode(i),I(m,i,l,r.__n,m.namespaceURI,32&l.__u?[u]:null,d,u||E(l),32&l.__u,f),i.__v=l.__v,i.__.__k[i.__i]=i,R(d,i,f),l.__=l.__e=null,i.__e!=u&&D(i)))}finally{(s=a.length)&&(o||queueMicrotask)(k)}}function ee(e,t,n,r,i,a,o,s,c,l,u){var d,f,p,g,_,v,y=r.__k||h,b=t.length;for(c=A(n,t,y,c,b),d=0;d<b;d++)(p=n.__k[d])!=null&&(f=~p.__i&&y[p.__i]||m,p.__i=d,v=I(e,p,f,i,a,o,s,c,l,u),g=p.__e,(f.ref!=p.ref||8&f.__u)&&(f.ref&&z(f.ref,null,p,f),p.ref&&u.push(p.ref,p.__c||g,p)),_||=g,4&p.__u?(c=j(p,c,e,!f.__v),f.__e&&(f.__e=null)):typeof p.type==`function`&&v!==void 0?c=v:g&&(c=g.nextSibling),p.__u&=-21);return n.__e=_,c}function A(e,t,n,r,i){var a,o,s,c,l,u,d,f,m,h=n.length,g=h,v=0,y=0,b=e.__k=Array(i);for(a=0;a<i;a++)(o=t[a])!=null&&typeof o!=`boolean`&&typeof o!=`function`?(typeof o!=`object`||o.constructor===String?o=b[a]=S(null,o):_(o)?o=b[a]=S(w,{children:o}):o.constructor===p&&o.__b?o=b[a]=S(o.type,o.props,o.key,o.ref,o.__v):b[a]=o,c=a+v,o.__=e,o.__b=e.__b+1,s=null,~(l=o.__i=M(o,n,c,g))&&(g--,(s=n[l])&&(s.__u|=2)),s&&s.__v?(o.__u|=16,l==c-1?v--:l==c+1?v++:l!=c&&(l>c?v--:v++,y=1)):(~l||(i>h?v--:i<h&&v++),typeof o.type!=`function`&&(o.__u|=4))):b[a]=null;if(y){for(u=[],d=[],a=0;a<i;a++)if((o=b[a])&&16&o.__u){for(v=0,f=u.length;v<f;)u[m=v+f>>1]<o.__i?v=m+1:f=m;u[v]=o.__i,d[a]=v+1}for(v=u.length;a--;)d[a]&&(d[a]==v?v--:b[a].__u|=4)}if(g)for(a=0;a<h;a++)!(s=n[a])||2&s.__u||(s.__e==r&&(r=E(s)),B(s,s));return r}function j(e,t,n,r){var i,a,o,s;if(typeof e.type==`function`){if(e.props.__P)return t;if(i=e.__k)for(a=0;a<i.length;a++)i[a]&&(i[a].__=e,t=j(i[a],t,n,!1));return t}for(t&&!t.parentNode&&(t=E(e))&&!t.parentNode&&(t=null),o=e.__e,s=t;s&&s.nodeType==8;)s=s.nextSibling;for(o!=s&&(!r&&n.moveBefore&&o.parentNode?n.moveBefore(o,t):n.insertBefore(o,t||null)),t=o;(t&&=t.nextSibling)&&t.nodeType==8&&!t.data.startsWith(`$s`););return t}function M(e,t,n,r){var i,a=e.key,o=e.type,s=t[n],c=s&&!(2&s.__u);if(s===null&&a==null||c&&a==s.key&&o==s.type)return n;if(r>+!!c){for(i=n-1;i>=0;i--)if((s=t[i])&&!(2&s.__u)&&a==s.key&&o==s.type)return i;for(i=n+1;i<t.length;i++)if((s=t[i])&&!(2&s.__u)&&a==s.key&&o==s.type)return i}return-1}function N(e,t,n){n??=``,t[0]==`-`?e.setProperty(t,n):e[t]=n}function P(e,t,n,r,i){var a,o;if(t==`style`){if(typeof n==`string`)e.style.cssText=n;else{if(typeof r==`string`&&(e.style.cssText=r=``),r)for(t in r)n&&t in n||N(e.style,t);if(n)for(t in n)r&&n[t]==r[t]||N(e.style,t,n[t])}}else if(t[0]==`o`&&t[1]==`n`)(e.__e||={})[t]=n,n&&r||(o=f[t]||(f[t]=F(t)),(e.__a||={})[t]=d,a=t!=(t=t.replace(u,`$1`)),(t=t.slice(2))[0]<`a`&&(t=t.toLowerCase()),n?e.addEventListener(t,o,a):e.removeEventListener(t,o,a));else{if(i==`http://www.w3.org/2000/svg`)t=t.replace(/xlink(H|:h)/,`h`).replace(/sName$/,`s`);else if(t!=`width`&&t!=`height`&&t!=`href`&&t!=`list`&&t!=`form`&&t!=`tabIndex`&&t!=`download`&&t!=`rowSpan`&&t!=`colSpan`&&t!=`role`&&t!=`popover`&&t in e)try{e[t]=n??``;return}catch{}if(typeof n==`function`)return;n==null||!1===n&&t[4]!=`-`?e.removeAttribute(t):e.setAttribute(t,t==`popover`&&n==1?``:n)}}function F(e){return function(t){var r=this.__e;if(r){if(r=r[e],t[l]==null)t[l]=d++;else if(t[l]<this.__a[e])return;return r(n.event?n.event(t):t)}}}function I(e,t,r,i,a,o,s,c,l,u){var d,f,m,g,v,x,S,C,D,O,k,A,j,M,N,P,F,I,R=t.type;if(t.constructor!==p)return null;128&r.__u&&(l=32&r.__u,d=r.__c.__z)&&(t.__u|=l,f=o=[],d.nodeType==8?c=L(d,o):o.push(d),c=o[0]||c),(d=n.__b)&&d(t);n:if(typeof R==`function`){m=s.length;try{if(C=t.props,D=(d=R.prototype)&&d.render,O=(d=R.contextType)&&i[d.__c],k=d?O?O.props.value:d.__:i,(g=r.__c)?(t.__c=g,2&g.__g&&(g.__g|=1)):(D?t.__c=g=new R(C,k):(t.__c=g=new T(C,k),g.constructor=R,g.render=re),O&&O.sub(g),g.state||(g.state={}),g.__n=i,g.__g|=8,g.__h=[],g.__k=[]),D&&(g.__s||(g.__s=g.state),R.getDerivedStateFromProps&&(g.__s==g.state&&(g.__s=y({},g.__s)),y(g.__s,R.getDerivedStateFromProps(C,g.__s)))),v=g.props,x=g.state,g.__v=t,r.__c){if(C!==v&&D&&!R.getDerivedStateFromProps&&g.componentWillReceiveProps&&g.componentWillReceiveProps(C,k),t.__v==r.__v&&!(8&g.__g)||!(4&g.__g)&&g.shouldComponentUpdate&&!1===g.shouldComponentUpdate(C,g.__s,k)){t.__v!=r.__v&&(g.props=C,g.state=g.__s,g.__g&=-9),t.__e=r.__e,t.__k=r.__k,t.__k.some(function(e){e&&(e.__=t)}),h.push.apply(g.__h,g.__k),g.__k=[],g.__h.length&&s.push(g),c=E(r);break n}g.componentWillUpdate&&g.componentWillUpdate(C,g.__s,k),D&&g.componentDidUpdate&&g.__h.push(function(){g.componentDidUpdate(v,x,S)})}else D&&!R.getDerivedStateFromProps&&g.componentWillMount&&g.componentWillMount(),D&&g.componentDidMount&&g.__h.push(g.componentDidMount);if(g.context=k,g.props=C,g.__P=e,g.__g&=-5,A=n.__r,j=0,D)g.state=g.__s,g.__g&=-9,A&&A(t),d=g.render(g.props,g.state,g.context),h.push.apply(g.__h,g.__k),g.__k=[];else do g.__g&=-9,A&&A(t),d=g.render(g.props,g.state,g.context),g.state=g.__s;while(8&g.__g&&++j<25);g.state=g.__s,g.getChildContext&&(i=y({},i,g.getChildContext())),D&&r.__c&&g.getSnapshotBeforeUpdate&&(S=g.getSnapshotBeforeUpdate(v,x)),M=d&&d.type===w&&d.key==null?d.props.children:d,C.__P&&(d=c,a=(e=C.__P).namespaceURI,l=o=null,r.props&&r.props.__P!=e&&(r.__k.some(function(e){e&&B(e,e)}),r.__k=null),c=r.__k?E(r,0):null),c=ee(e,_(M)?M:[M],t,r,i,a,o,s,c,l,u),C.__P&&(t.__e=null,c=d),t.__u&=-161,f&&f.some(b),g.__h.length&&s.push(g),1&g.__g&&(g.__g&=-4)}catch(e){if(s.length=m,t.__v=null,l||o){if(e.then){if(N=0,t.__u|=128|l,o){for(~(F=o.indexOf(c||void 0))||(F=o.length);(I=o[F-1])&&I.nodeType==8;)F--;for(;F<o.length;F++)if(I=o[F]){if(o[F]=null,I.nodeType==8){if(I.data.startsWith(`$s`))N++||(P=I);else if(N&&I.data.startsWith(`/$s`)&&!--N)break}else if(!N)break}}if(!P){for(;c&&c.nodeType==8&&c.nextSibling;)c=c.nextSibling;P=c}(d=L(P=t.__c.__z||(t.__c.__z=P)))?(t.__e=P,c=d):t.__e=c,c&&=c.nextSibling}else o&&o.some(b)}else t.__e=r.__e;t.__k||=r.__k||[],e.then||te(t),n.__e(e,t,r)}}else c=t.__e=ne(r.__e,t,r,i,a,o,s,l,u,e);return(d=n.diffed)&&d(t),c}function L(e,t){if(e&&e.nodeType==8&&e.data.startsWith(`$s`))for(var n=1;e=e.nextSibling;){if(e.nodeType==8){if(e.data.startsWith(`$s`))n++;else if(e.data.startsWith(`/$s`)&&!--n)return e}t&&t.push(e)}}function te(e){e&&(e.__c&&(e.__c.__g|=4),e.__k&&e.__k.some(te))}function R(e,t,r){for(var i=0;i<r.length;)z(r[i++],r[i++],r[i++]);n.__c&&n.__c(t,e),e.some(function(t){try{e=t.__h,t.__h=[],e.some(function(e){e.call(t)})}catch(e){n.__e(e,t.__v)}})}function ne(e,t,r,i,a,o,s,c,l,u){var d,f,p,h,y,x,S,C,w,T=r.props||m,D=t.props,O=t.type;if(O==`svg`?a=`http://www.w3.org/2000/svg`:O==`math`?a=`http://www.w3.org/1998/Math/MathML`:a||=`http://www.w3.org/1999/xhtml`,o){for(d=0;d<o.length;d++)if((y=o[d])&&(O?y.localName==O:y.nodeType==3)){e=y,o[d]=null;break}}if(!e){if(C=u.ownerDocument||document,!O)return C.createTextNode(D);e=C.createElementNS(a,O,D.is&&D),c&&=(n.__m&&n.__m(t,o),!1),o=null}if(O){if(u=O==`template`&&e.content||e,o=O==`textarea`&&D.defaultValue!=null?null:o&&v.call(u.childNodes),!c&&o)for(T={},d=0;d<e.attributes.length;d++)T[(y=e.attributes[d]).name]=y.value;for(d in T)y=T[d],d==`dangerouslySetInnerHTML`?p=y:d==`children`||d in D||d==`value`&&`defaultValue`in D||d==`checked`&&`defaultChecked`in D||P(e,d,null,y,a);for(d in w=1&r.__u,D)y=D[d],d==`children`?h=y:d==`dangerouslySetInnerHTML`?f=y:d==`value`?x=y:d==`checked`?S=y:c&&typeof y!=`function`||!(T[d]!==y||w&&y!=null)||P(e,d,y,T[d],a);f?(c||p&&(f.__html==p.__html||f.__html==e.innerHTML)||(e.innerHTML=f.__html),t.__k=[]):(p&&(e.textContent=``),(O==`foreignObject`||a==`http://www.w3.org/1998/Math/MathML`&&g.test(O))&&(a=`http://www.w3.org/1999/xhtml`),ee(u,_(h)?h:[h],t,r,i,a,o,s,o?o[0]:r.__k&&E(r,0),c,l),o&&o.some(b)),c&&O!=`textarea`||(d=`value`,O==`progress`&&x==null?e.removeAttribute(d):x==null||x===e[d]&&(O!=`progress`||x)||P(e,d,x,T[d],a),d=`checked`,S!=null&&S!=e[d]&&P(e,d,S,T[d],a))}else T===D||c&&e.data==D||(e.data=D);return e}function z(e,t,r,i){try{typeof e==`function`?t?t.__x=e(t)||1:(i&&=i.__c||i.__e)&&(t=i.__x)&&(i.__x=null,typeof t==`function`?t():e(null)):e.current=t}catch(e){n.__e(e,r)}}function B(e,t,r){var i,a,o,s;if(n.unmount&&n.unmount(e),!(i=e.ref)||i.current&&i.current!=e.__e||z(i,null,t,e),i=e.__c){if(i.componentWillUnmount)try{i.componentWillUnmount()}catch(e){n.__e(e,t)}i.__P=i.__n=null}if(i=e.__k)for(s=0;s<i.length;s++)i[s]&&B(i[s],t,typeof e.type!=`function`||r&&!e.props.__P);!r&&(i=e.__c)&&(i=i.__z)&&(a=L(i,o=[]))&&(i==e.__e&&o.some(b),b(a),b(i)),(i=e.__e)&&(r||b(i),i.__e&&(i.__e=null)),e.__e=e.__c=e.__=null}function re(e,t,n){return this.constructor(e,n)}function ie(e,t){var r,i,a,o;n.__&&n.__(e,t),t.nodeType==9&&(t=t.documentElement),i=(r=e&&32&e.__u)?null:t.__k,t.__k=S(w,{children:[e]}),a=[],o=[],I(t,t.__k,i||m,m,t.namespaceURI,i?null:t.firstChild?v.call(t.childNodes):null,a,i?i.__e:t.firstChild,r,o),R(a,t.__k,o),t.__k.props.children=null}n={__e:function(e,t,n,r){for(var i,a,o;t=t.__;)if((i=t.__c)&&!(1&i.__g)){i.__g|=4;try{if((o=(a=i.constructor)&&a.getDerivedStateFromError)&&i.setState(a.getDerivedStateFromError(e)),i.componentDidCatch&&(i.componentDidCatch(e,r||{}),o=1),o&&8&i.__g)return void(i.__g|=2)}catch(t){e=t}}throw s=0,e}},r=0,i=function(e){return e!=null&&e.constructor===p},T.prototype.setState=function(e,t){var n=this.__s;n&&n!=this.state||(n=this.__s=y({},this.state)),typeof e==`function`&&(e=e(y({},n),this.props)),e&&(y(n,e),this.__v&&(t&&this.__k.push(t),O(this)))},T.prototype.forceUpdate=function(e){this.__v&&(this.__g|=4,e&&this.__h.push(e),O(this))},T.prototype.render=w,a=[],s=0,c=function(e,t){return e.__v.__b-t.__v.__b},l=Symbol(),u=/(PointerCapture)$|Capture$/i,d=0,f={};var V,H,U,ae,W=Object.is,G=0,oe=[],K=[],q=n,se=q.__b,ce=q.__r,le=q.diffed,ue=q.__c,de=q.unmount,fe=q.__;function J(e,t){q.__h&&q.__h(H,e,G||t),G=0;var n=H.__H||(H.__H={__:[],__h:[]});return e>=n.__.length&&n.__.push({}),n.__[e]}function pe(e){return G=1,me(Se,e)}function me(e,t,n){var r=J(V++,2);if(r.t=e,!r.__c&&(r.__=[n?n(t):Se(void 0,t),function(e){var t=r.__N?r.__N[0]:r.__[0],n=r.t(t,e);W(t,n)||(r.__N=[n,r.__[1]],r.__c.setState({}))}],r.__c=H,!H.__f)){H.__f=!0;var i=H.shouldComponentUpdate;H.shouldComponentUpdate=function(e,t,n){var r=this.__H;if(!r)return!0;var a=!1,o=this.props!=e;if(r.__.some(function(e){e.__N&&(a=!0,W(e.__[0],e.__N[0])||(o=!0))}),i){var s=i.call(this,e,t,n);return a?s||o:s}return!a||o}}return r.__}function he(e,t){var n=J(V++,4);!q.__s&&xe(n.__H,t)&&(n.__P=!1,n.__=e,n.u=t,H.__h.push(n))}function ge(e,t){var n=J(V++,7);return xe(n.__H,t)&&(n.__=e(),n.__H=t),n.__}function _e(){var e;do{for(;e=K.shift();)try{Y(e)}catch(t){q.__e(t,{__:(e=e.__P)&&e.__v})}for(;e=oe.shift();){var t=e.__H;if(e.__P&&t)try{t.__h.some(Y),t.__h.some(X),t.__h=[]}catch(n){t.__h=[],q.__e(n,e.__v)}}}while(K.length)}q.__b=function(e){H=null,se&&se(e)},q.__=function(e,t){e&&t.__k&&t.__k.__m&&(e.__m=t.__k.__m),fe&&fe(e,t)},q.__r=function(e){ce&&ce(e),V=0;var t=(H=e.__c).__H;t&&(U==H?H.__h=[]:(t.__h.some(Y),t.__h.some(X),V=0),t.__h=[],t.__.some(function(e){e.__N&&(e.__=e.__N),e.u=e.__N=void 0})),U=H},q.diffed=function(e){le&&le(e);var t=e.__c;t&&t.__H&&(t.__H.__h.length&&be(oe.push(t)),t.__H.__.some(function(e){e.u&&(e.__H=e.u)})),U=H=null},q.__c=function(e,t){t.some(function(e){try{e.__h.some(Y),e.__h=e.__h.filter(function(e){return!e.__||X(e)})}catch(t){e.__h=[function(){throw t}]}}),ue&&ue(e,t)},q.unmount=function(e){de&&de(e);var t,n,r=e.__c;r&&r.__H&&(r.__H.__.some(function(r){try{if(r.__P&&r.__c){if(n===void 0){for(n=e.__;n&&(!n.__c||!n.__c.__P);)n=n.__;n&&=n.__c}r.__P=n,be(K.push(r))}else Y(r)}catch(e){t=e}}),r.__H=void 0,t&&q.__e(t,r.__v))};var ve=typeof requestAnimationFrame==`function`;function ye(e){var t,n=function(){clearTimeout(r),ve&&cancelAnimationFrame(t),setTimeout(e)},r=setTimeout(n,35);ve&&(t=requestAnimationFrame(n))}function be(e){e!=1&&ae==q.requestAnimationFrame||((ae=q.requestAnimationFrame)||ye)(_e)}function Y(e){var t=H,n=e.__c;typeof n==`function`&&(e.__c=void 0,n()),H=t}function X(e){var t=H;e.__c=e.__(),H=t}function xe(e,t){return!e||e.length!=t.length||t.some(function(t,n){return!W(t,e[n])})}function Se(e,t){return typeof t==`function`?t(e):t}var Z={INVALID_PDF:`INVALID_PDF`,PDF_PASSWORD_REQUIRED:`PDF_PASSWORD_REQUIRED`,PDF_LOAD_FAILED:`PDF_LOAD_FAILED`,CLIENT_KEY_REQUIRED:`CLIENT_KEY_REQUIRED`,CAMERA_INTERRUPTED:`CAMERA_INTERRUPTED`,CAMERA_NOT_FOUND:`CAMERA_NOT_FOUND`,CAMERA_PERMISSION_DENIED:`CAMERA_PERMISSION_DENIED`,CAMERA_UNAVAILABLE:`CAMERA_UNAVAILABLE`,CAMERA_UNSUPPORTED:`CAMERA_UNSUPPORTED`,CAPTURES_INCOMPLETE:`CAPTURES_INCOMPLETE`,DOCUMENT_BACK_CONTAINS_FACE:`DOCUMENT_BACK_CONTAINS_FACE`,DOCUMENT_BACK_NOT_DISTINCT:`DOCUMENT_BACK_NOT_DISTINCT`,DOCUMENT_BACK_REQUIRED:`DOCUMENT_BACK_REQUIRED`,DOCUMENT_BLURRY:`DOCUMENT_BLURRY`,DOCUMENT_FACE_GEOMETRY_INVALID:`DOCUMENT_FACE_GEOMETRY_INVALID`,DOCUMENT_FACE_NOT_CONTAINED:`DOCUMENT_FACE_NOT_CONTAINED`,DOCUMENT_FACE_NOT_FOUND:`DOCUMENT_FACE_NOT_FOUND`,DOCUMENT_NOT_FOUND:`DOCUMENT_NOT_FOUND`,DOCUMENT_NOT_RECOGNIZED:`DOCUMENT_NOT_RECOGNIZED`,DOCUMENT_TEXT_ALIGNMENT_INVALID:`DOCUMENT_TEXT_ALIGNMENT_INVALID`,DOCUMENT_TEXT_NOT_READABLE:`DOCUMENT_TEXT_NOT_READABLE`,DOCUMENT_VALIDATION_FAILED:`DOCUMENT_VALIDATION_FAILED`,FACEKEY_TOKEN_INVALID:`FACEKEY_TOKEN_INVALID`,FACEGATE_TOKEN_INVALID:`FACEGATE_TOKEN_INVALID`,FACEGATE_ABORTED:`FACEGATE_ABORTED`,FACEGATE_TIMEOUT:`FACEGATE_TIMEOUT`,FACE_NOT_FOUND:`FACE_NOT_FOUND`,FACE_MISMATCH:`FACE_MISMATCH`,FACE_NOT_USABLE:`FACE_NOT_USABLE`,IMAGE_ENCODE_FAILED:`IMAGE_ENCODE_FAILED`,IMAGE_PROCESSING_FAILED:`IMAGE_PROCESSING_FAILED`,INVALID_IMAGE:`INVALID_IMAGE`,INVALID_MODEL_OUTPUT:`INVALID_MODEL_OUTPUT`,INVALID_OPTIONS:`INVALID_OPTIONS`,INVALID_POSES:`INVALID_POSES`,INVALID_CLIENT_KEY:`INVALID_CLIENT_KEY`,INVALID_SERVICE_RESPONSE:`INVALID_SERVICE_RESPONSE`,MODEL_LOAD_FAILED:`MODEL_LOAD_FAILED`,NETWORK_ERROR:`NETWORK_ERROR`,REQUEST_TOO_LARGE:`REQUEST_TOO_LARGE`,NO_USABLE_CANDIDATES:`NO_USABLE_CANDIDATES`,NO_USABLE_REFERENCES:`NO_USABLE_REFERENCES`,POSE_BACKGROUND_MISMATCH:`POSE_BACKGROUND_MISMATCH`,POSE_IDENTITY_MISMATCH:`POSE_IDENTITY_MISMATCH`,SERVICE_UNAVAILABLE:`SERVICE_UNAVAILABLE`,SDK_NOT_READY:`SDK_NOT_READY`,SDK_CAPABILITY_NOT_CONFIGURED:`SDK_CAPABILITY_NOT_CONFIGURED`,UI_ELEMENT_NOT_FOUND:`UI_ELEMENT_NOT_FOUND`,VERIFICATION_CANCELLED:`VERIFICATION_CANCELLED`,VERIFICATION_SAVE_FAILED:`VERIFICATION_SAVE_FAILED`},Ce=new Set(Object.values(Z)),we=e=>typeof e==`string`&&Ce.has(e),Te=({error:e,fallback:t=Z.INVALID_SERVICE_RESPONSE})=>typeof e==`object`&&e&&`code`in e&&we(e.code)?e.code:e instanceof Error&&we(e.message)?e.message:we(e)?e:t,Ee=[`ar`,`ch`,`de`,`en`,`es`,`fr`,`it`,`ja`,`pt`,`ru`,`zh`],Q=new Map,De=new Map,Oe=async({language:e})=>{if(Q.has(e))return;let n=De.get(e);n||(n=fetch(t({filename:`locales/${e}.json`})).then(async e=>{if(!e.ok)throw Error(Z.INVALID_SERVICE_RESPONSE);return await e.json()}),De.set(e,n));try{Q.set(e,await n)}finally{De.delete(e)}},ke=async({language:e})=>{let t=e??Ae();await Promise.all([Oe({language:t}),...t===`en`?[]:[Oe({language:`en`})]])},Ae=()=>{let e=[navigator.language,...navigator.languages];for(let t of e){let e=t.toLowerCase();if(/^zh-(hk|mo|tw)\b/u.test(e))return`ch`;let n=e.split(`-`)[0];if(Ee.includes(n))return n}return`en`},je={[Z.CAMERA_PERMISSION_DENIED]:`cameraPermissionDenied`,[Z.CAMERA_NOT_FOUND]:`cameraNotFound`,[Z.CAMERA_UNAVAILABLE]:`cameraUnavailable`,[Z.CAMERA_UNSUPPORTED]:`cameraUnavailable`,[Z.CAMERA_INTERRUPTED]:`cameraUnavailable`,[Z.NETWORK_ERROR]:`networkError`,[Z.SERVICE_UNAVAILABLE]:`serviceUnavailable`,[Z.MODEL_LOAD_FAILED]:`modelLoadFailed`,[Z.FACE_NOT_FOUND]:`faceNotFound`,[Z.NO_USABLE_CANDIDATES]:`faceNotFound`,[Z.FACE_NOT_USABLE]:`faceNotUsable`,[Z.NO_USABLE_REFERENCES]:`faceNotUsable`,[Z.DOCUMENT_NOT_FOUND]:`frameDocument`,[Z.DOCUMENT_NOT_RECOGNIZED]:`invalidDocument`,[Z.DOCUMENT_TEXT_NOT_READABLE]:`documentNotReadable`,[Z.DOCUMENT_BLURRY]:`documentBlurry`,[Z.DOCUMENT_FACE_NOT_FOUND]:`faceNotVisibleInDocument`,[Z.DOCUMENT_FACE_NOT_CONTAINED]:`documentAlignmentInvalid`,[Z.DOCUMENT_FACE_GEOMETRY_INVALID]:`documentAlignmentInvalid`,[Z.DOCUMENT_TEXT_ALIGNMENT_INVALID]:`documentAlignmentInvalid`,[Z.DOCUMENT_BACK_REQUIRED]:`frameDocumentBack`,[Z.CAPTURES_INCOMPLETE]:`capturesIncomplete`,[Z.DOCUMENT_VALIDATION_FAILED]:`documentValidationFailed`,[Z.INVALID_OPTIONS]:`invalidOptions`,[Z.INVALID_POSES]:`invalidPoses`,[Z.INVALID_SERVICE_RESPONSE]:`invalidServiceResponse`,[Z.POSE_BACKGROUND_MISMATCH]:`poseBackgroundMismatch`,[Z.POSE_IDENTITY_MISMATCH]:`poseIdentityMismatch`,[Z.IMAGE_ENCODE_FAILED]:`imageEncodeFailed`,[Z.IMAGE_PROCESSING_FAILED]:`imageProcessingFailed`,[Z.INVALID_IMAGE]:`invalidImage`,[Z.INVALID_PDF]:`invalidPdf`,[Z.PDF_PASSWORD_REQUIRED]:`pdfPasswordRequired`,[Z.PDF_LOAD_FAILED]:`pdfLoadFailed`,[Z.CLIENT_KEY_REQUIRED]:`clientKeyRequired`,[Z.VERIFICATION_SAVE_FAILED]:`verificationSaveFailed`,[Z.FACEGATE_ABORTED]:`verificationCancelled`,[Z.VERIFICATION_CANCELLED]:`verificationCancelled`},Me=({language:e})=>{let t=e??Ae(),n=e=>{let n=Q.get(t),r=Q.get(`en`);return n?.[e]??r?.[e]??e};return{translate:n,translateError:({error:e})=>{let t=je[Te({error:e})]??`verificationFailed`;return n(t)}}},Ne=async({milliseconds:e})=>{let t=Promise.withResolvers();setTimeout(()=>t.resolve(),e),await t.promise},$=new WeakMap,Pe=async({video:e,signal:t})=>{t?.throwIfAborted();let n=Promise.withResolvers(),r=e,i=$.get(e)??new Set,a=null,o=null,s=!1,c=c=>{s||(s=!0,a!==null&&r.cancelVideoFrameCallback?.(a),o!==null&&cancelAnimationFrame(o),t?.removeEventListener(`abort`,u),i.delete(l),i.size||$.delete(e),c?n.reject(c):n.resolve())},l=()=>c(new DOMException(Z.VERIFICATION_CANCELLED,`AbortError`)),u=()=>c(new DOMException(Z.VERIFICATION_CANCELLED,`AbortError`));i.add(l),$.set(e,i),t?.addEventListener(`abort`,u,{once:!0}),r.requestVideoFrameCallback?a=r.requestVideoFrameCallback(()=>c()):o=requestAnimationFrame(()=>c()),await n.promise},Fe=()=>{let e=/Android|iPhone|iPad|iPod|Mobile/i.test(navigator.userAgent),t=navigator.platform===`MacIntel`&&navigator.maxTouchPoints>1;return e||t},Ie=async()=>{let e=[],t=(t,n)=>{n||e.push(t)};if(t(`navigator.mediaDevices.getUserMedia`,typeof navigator.mediaDevices==`object`&&typeof navigator.mediaDevices.getUserMedia==`function`),t(`navigator.mediaDevices.enumerateDevices`,typeof navigator.mediaDevices==`object`&&typeof navigator.mediaDevices.enumerateDevices==`function`),t(`MediaStream`,typeof MediaStream<`u`),t(`MediaStreamTrack`,typeof MediaStreamTrack<`u`),t(`HTMLVideoElement`,typeof HTMLVideoElement<`u`),t(`createImageBitmap`,typeof createImageBitmap==`function`),t(`OffscreenCanvas`,typeof OffscreenCanvas<`u`),t(`OffscreenCanvas.getContext`,typeof OffscreenCanvas<`u`&&typeof OffscreenCanvas.prototype.getContext==`function`),t(`OffscreenCanvas.convertToBlob`,typeof OffscreenCanvas<`u`&&typeof OffscreenCanvas.prototype.convertToBlob==`function`),t(`WebAssembly`,typeof WebAssembly<`u`),t(`fetch`,typeof fetch==`function`),t(`Blob`,typeof Blob<`u`),t(`File`,typeof File<`u`),t(`URL.createObjectURL`,typeof URL.createObjectURL==`function`),t(`URL.revokeObjectURL`,typeof URL.revokeObjectURL==`function`),!e.includes(`OffscreenCanvas`)&&!e.includes(`OffscreenCanvas.getContext`)&&!e.includes(`OffscreenCanvas.convertToBlob`))try{let e=new OffscreenCanvas(1,1),n=e.getContext(`2d`);if(t(`OffscreenCanvas 2D context`,n!==null),n&&typeof createImageBitmap==`function`){let n=await e.convertToBlob({type:`image/jpeg`});t(`JPEG encoding`,n.type===`image/jpeg`),n.type===`image/jpeg`&&((await createImageBitmap(n)).close(),t(`JPEG decoding`,!0))}else t(`JPEG encoding`,!1),t(`JPEG decoding`,!1)}catch{e.includes(`JPEG encoding`)||t(`JPEG encoding`,!1),t(`JPEG decoding`,!1)}else t(`JPEG encoding`,!1),t(`JPEG decoding`,!1);return{supported:e.length===0,unsupportedFeatures:e}},Le=({video:e})=>{for(let t of $.get(e)??[])t();let t=e.srcObject;if(t instanceof MediaStream)for(let e of t.getTracks())e.stop();e.srcObject=null},Re=async({facingMode:e,video:t,signal:n})=>{if(!navigator.mediaDevices||typeof navigator.mediaDevices.getUserMedia!=`function`)throw Error(Z.CAMERA_UNSUPPORTED);let r={facingMode:{ideal:e}};Fe()||(r.width={ideal:1280},r.height={ideal:720});let i=()=>Le({video:t});n?.addEventListener(`abort`,i,{once:!0});try{let i=await navigator.mediaDevices.getUserMedia({video:r,audio:!1});if(n?.aborted){for(let e of i.getTracks())e.stop();n.throwIfAborted()}t.srcObject=i;let a=(await navigator.mediaDevices.enumerateDevices()).filter(({kind:e})=>e===`videoinput`).length>1?e:`user`;return await t.play(),n?.throwIfAborted(),a}catch(e){if(Le({video:t}),n?.aborted)throw new DOMException(Z.VERIFICATION_CANCELLED,`AbortError`);let r=e instanceof Error?e.name:``,i=Z.CAMERA_UNAVAILABLE;throw(r===`NotAllowedError`||r===`SecurityError`)&&(i=Z.CAMERA_PERMISSION_DENIED),r===`NotFoundError`&&(i=Z.CAMERA_NOT_FOUND),r===`AbortError`&&(i=Z.CAMERA_INTERRUPTED),Error(i,{cause:e})}finally{n?.removeEventListener(`abort`,i)}},ze=({element:e})=>{let t=e.getContext(`2d`);if(!t)throw Error(Z.IMAGE_PROCESSING_FAILED);t.clearRect(0,0,e.width,e.height)},Be=async({canvas:e,quality:t})=>{try{let n=await e.convertToBlob({type:`image/jpeg`,quality:t});if(n.type!==`image/jpeg`)throw Error(Z.IMAGE_ENCODE_FAILED);return n}catch(e){throw Error(Z.IMAGE_ENCODE_FAILED,{cause:e})}},Ve=async({frame:e})=>{let t=new OffscreenCanvas(e.width,e.height),n=t.getContext(`2d`);if(!n)throw Error(Z.IMAGE_PROCESSING_FAILED);return n.drawImage(e,0,0),await Be({canvas:t})},He=async({blob:e})=>{let t;try{t=await createImageBitmap(e)}catch(e){throw Error(Z.INVALID_IMAGE,{cause:e})}try{let e=Math.min(1,900/Math.max(t.width,t.height)),n=new OffscreenCanvas(Math.max(1,Math.round(t.width*e)),Math.max(1,Math.round(t.height*e))),r=n.getContext(`2d`);if(!r)throw Error(Z.IMAGE_PROCESSING_FAILED);return r.drawImage(t,0,0,n.width,n.height),await Be({canvas:n,quality:.85})}finally{t.close()}},Ue=async({frame:e})=>{let t=Math.min(1,960/Math.max(e.width,e.height)),n=Math.max(1,Math.round(e.width*t)),r=Math.max(1,Math.round(e.height*t));return await createImageBitmap(e,{resizeWidth:n,resizeHeight:r})},We=async({image:e})=>{let t=new Uint8Array(await e.arrayBuffer()),n=``;for(let e=0;e<t.length;e+=32768)n+=String.fromCharCode(...t.subarray(e,e+32768));return`data:image/jpeg;base64,${btoa(n)}`};export{x as C,e as D,T as E,t as O,w as S,i as T,he as _,We as a,C as b,Le as c,Me as d,Ae as f,Te as g,Z as h,Ve as i,Ue as l,Ne as m,ze as n,Fe as o,ke as p,He as r,Re as s,Ie as t,Pe as u,pe as v,n as w,ie as x,ge as y};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/*! Copyright (c) 2026 VOLTOM. All rights reserved. Proprietary software. See LICENSE at https://voltom.io/license. */
|
|
2
|
+
import{$ as e,A as t,B as n,D as r,F as i,H as a,I as o,J as s,K as c,L as l,M as u,N as d,P as f,Q as p,R as m,V as h,W as g,X as _,Z as v,a as y,b,c as x,f as S,g as C,h as w,i as T,j as E,k as D,m as O,n as k,nt as A,o as j,p as M,q as N,r as ee,s as te,t as P,u as ne,v as re,z as ie}from"./eyeLevelCamera-DY4onSBz.js";import{O as ae,h as F,i as oe,m as se,n as ce,u as le}from"./media-BRKPXpu3.js";var ue=({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}},de=({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}},fe=.3,pe=.6,me=12,he=3,ge=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(p({error:e,fallback:v.INFERENCE_FAILED}),{cause:e})}finally{N({category:`inference`,duration:performance.now()-n,key:`ocr`}),t.dispose()}},_e=({text:e})=>e.normalize(`NFKC`).replace(/\r\n?/gu,`
|
|
3
|
+
`).replace(/[\t\f\v ]+/gu,` `).replace(/ *\n */gu,`
|
|
4
|
+
`).trim(),ve=({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}},ye=({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)<fe)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)<fe||(r[d]=1,a[c]=d,c+=1)}}let h=u-l+1,g=f-d+1;if(m<me||h<he||g<he||p/m<pe)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},be=({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}),xe=async({pixels:e,runtime:t,session:n})=>{let r=ve({pixels:e,runtime:t}),i=await ge({session:n,tensor:r.tensor});try{let e=Number(i.dims.at(-2)),t=Number(i.dims.at(-1)),n=ye({height:e,scores:i.data,width:t}),a=r.width/t,o=r.height/e;return be({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()}},Se=({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=de({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])},Ce=({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(``)},we=({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?Ce({text:c}):c},Te=({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})}),Ee=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 xe({pixels:o,runtime:e.runtime,session:n}),c=[];for(let n of s){let i=Se({pixels:ue({box:n,image:o}),runtime:e.runtime,model:t}),s=await ge({session:r,tensor:i}),l;try{l=we({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=Te({lines:c}),u=_e({text:l.map(e=>e.text).join(`
|
|
6
|
+
`)});return{engine:t.id,height:o.height,lines:l,text:u,width:o.width}}}},I=`odm.ort`,De={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:I,recognition:`orj.ort`,dictionary:`otj.txt`,recognitionHeight:48,channels:`bgr`,reverseArabic:!1},"chinese-simplified":{id:`chinese-simplified`,detection:I,recognition:`orcs.ort`,dictionary:`otcs.txt`,recognitionHeight:48,channels:`bgr`,reverseArabic:!1},"chinese-traditional":{id:`chinese-traditional`,detection:I,recognition:`orct.ort`,dictionary:`otct.txt`,recognitionHeight:48,channels:`bgr`,reverseArabic:!1},cyrillic:{id:`cyrillic`,detection:I,recognition:`orc.ort`,dictionary:`otc.txt`,recognitionHeight:48,channels:`bgr`,reverseArabic:!1},arabic:{id:`arabic`,detection:I,recognition:`ora.ort`,dictionary:`ota.txt`,recognitionHeight:48,channels:`bgr`,reverseArabic:!0}},Oe={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`},ke=({language:e})=>{let t=Oe[e.trim().toLowerCase()];if(!t)throw Error(v.OCR_LANGUAGE_UNSUPPORTED);return t},Ae={eng:`tiny`,latin:`tiny`,jpn:`japanese`,chi_sim:`chinese-simplified`,chi_tra:`chinese-traditional`,rus:`cyrillic`,ara:`arabic`},L=({language:e,engine:t=`auto`})=>{let n=ke({language:e}),r=De[t===`auto`?Ae[n]:t];if(!r)throw Error(v.OCR_MODEL_UNSUPPORTED);return r},je=({language:e,engine:t})=>{let n=L({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=L(r),a=n.get(i.id);a||(a=Ee({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,r=await ie.createImageBitmap(t);try{return n({frame:r})}finally{r.close()}},load:async e=>await Ne({cache:Pe,key:e,load:async()=>{try{let t=await fetch(s({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 g({filename:e}),runtime:_},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 r of e.lines)for(let e of r.words.length?r.words:[r]){let r=Ve[e.text.trim().toUpperCase()],{x:i,y:a,width:o,height:s}=e.box;if(e.confidence!==null&&e.confidence<=0||!r||i<0||a<0||i+o>t.width*.3||a+s>t.height*.35)continue;let c=Math.max(o,s);l({...t,xStart:Math.max(0,i-c)/t.width,xEnd:Math.min(t.width,i+o+c)/t.width,yStart:Math.max(0,a-c)/t.height,yEnd:Math.min(t.height,a+s+c)/t.height,predicate:(e,t,n)=>n>45&&n>e*1.08&&n>t*1.04})>=.15&&n.add(r)}return n.size===1?[...n][0]:null},U=({ocr:e,image:t})=>{if(m(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}),o=i&&/\p{L}/u.test(i)?i:null,s=a&&/\p{L}/u.test(a)?a:null,c=V({label:`3`,fragments:n})?.match(/^(\d{1,2}[./-]\d{1,2}[./-]\d{2,4}|\d{4}-\d{2}-\d{2})(?:\s+(.+))?$/u),l=H({allowTwoDigitYear:!0,text:c?c[1]:null}),u=c&&c[2]?.trim()||null,d=H({text:V({label:`4a`,fragments:n})}),f=H({text:V({label:`4b`,fragments:n})}),p=V({label:`4c`,fragments:n}),h=V({label:`5`,fragments:n}),g=We({ocr:e,image:t});return[o,s,l,u,d,f,p,h,g].some(Boolean)?E.parse({document:{source:`OCR`,type:`DRV`,issuing_country:g,issuing_authority:p,number:h,issue_date:d,expiry_date:f,optional_data:null},holder:{first_name:s,last_name:o,middle_name:null,birth_date:l,birth_place:u,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`:s({filename:`zxing-wasm/reader/index.js`}),Ke=async()=>{let e=await import(Ge());return globalThis.window!==void 0&&e.setZXingModuleOverrides({locateFile:e=>s({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 n=await(await qe()).readBarcodes(e,{formats:[`PDF417`],tryHarder:!0});for(let e of n)try{let n=t(e.text);return{type:`aamva`,code:e.text,payload:n}}catch{}return null},Xe=({runtime:e,detector:t,alignment:n,text:r,readImage:a})=>{let s=async({image:o,language:s,engine:c,scanBarcodes:l=!1})=>{let u=o instanceof Blob?o:new Blob([o]),d=await e.createImageBitmap(u);try{let o=await t.analyzeDocument({frame:d});if(!o.detection)throw Error(v.DOCUMENT_NOT_FOUND);let u=await n.orientDocumentFrame({frame:d,polygon:o.detection.polygon,orientation:o.detection.orientation});if(!u)throw Error(v.IMAGE_PROCESSING_FAILED);try{let t=i({image:a({frame:d}),polygon:o.detection.polygon,sourceOrientation:u.orientation.rotation}),n=await r.readRectifiedText({frame:u.frame,language:s,engine:c,image:t});if(!n)throw Error(v.DOCUMENT_TEXT_NOT_READABLE);let f=a({frame:u.frame}),p=null;if(l){let t=e.createImageData(f.width,f.height);t.data.set(f.data),p=await Ye({image:t})}return{ocr:n,codes:[D({result:n}),p].filter(e=>e!==null),pixels:f,signature:R({...a({frame:u.frame,width:32,height:32}),text:n.text}),blurry:o.isBlurry}}finally{u.frame.close()}}finally{d.close()}};return{classifyDocument:async({document_front:e,document_back:t,language:n,engine:r})=>{let i=await s({image:e,language:n,engine:r}),a=o({image:i.pixels,text:i.ocr.text,codes:i.codes});if(!a)throw Error(v.DOCUMENT_NOT_RECOGNIZED);let c=a.europeanDrivingLicense?U({ocr:i.ocr,image:i.pixels}):null,l=u({document:a.document})&&t?await s({image:t,language:a.europeanDrivingLicense?`latin`:n,engine:a.europeanDrivingLicense?`tiny`:r,scanBarcodes:!0}):null,d=f({classification:{...a,identity:c},front:i,back:l}),p=[...d.reasons],m=l?l.blurry:!1;return(i.blurry||m)&&p.push(v.DOCUMENT_BLURRY),l&&!B({front:i.signature,current:l.signature}).distinct&&p.push(v.DOCUMENT_BACK_NOT_DISTINCT),{identity:c,...a,...d,reasons:p,valid:p.length===0,document_front:i.ocr,document_back:l?l.ocr:null}},detectDocument:async({image:e,language:t})=>{let n=await s({image:e,language:t,scanBarcodes:!0}),r=o({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`),c=!!a||r.document===`id`&&!!i;return{identity:!c&&r.europeanDrivingLicense?U({ocr:n.ocr,image:n.pixels}):null,document_type:r.document===`driving_license`?`drv`:r.document,document_side:c?`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:n})=>{let r=`auto`,a=h({runtime:e}),s=async({engine:t=r,language:i=`eng`}={})=>{await n({environment:e.environment,engine:t,language:i})},c=async({classificationImage:t,engine:s=r,frame:c,language:l,image:u})=>{if(c.width<200||c.height<100)return null;let f=u??i({image:a({frame:c}),polygon:[{x:0,y:0},{x:c.width,y:0},{x:c.width,y:c.height},{x:0,y:c.height}]}),p=await(await n({environment:e.environment,engine:`tiny`,language:`latin`})).recognize({image:f}),m=D({result:p}),h=t??a({frame:c}),g=o({image:h,text:p.text,codes:m?[m]:[]}),_=g&&(g.document===`passport`||g.europeanDrivingLicense);if(g?.europeanDrivingLicense){let t=U({ocr:p,image:h});if(!d({identity:t})){let r=await(await n({environment:e.environment,engine:`small`,language:`latin`})).recognize({image:f}),i=U({ocr:r,image:h}),a=o({image:h,text:r.text,codes:[]});if(a?.europeanDrivingLicense&&d({identity:i}))p=r;else if(a?.europeanDrivingLicense){let e=nt({candidate:r,identity:t});if(e.length){let t=[...p.lines,...e];p={...p,lines:t,text:t.map(e=>e.text).join(`
|
|
8
|
+
`)}}}}}else if(!_){let t=ke({language:l??`eng`}),r=await n({environment:e.environment,engine:s,language:t});r.model!==`tiny`&&(p=await r.recognize({image:f}))}let v=c.width/p.width,y=c.height/p.height,b=({x:e,y:t,width:n,height:r})=>({x:e*v,y:t*y,width:n*v,height:r*y});return{...p,width:c.width,height:c.height,lines:p.lines.map(e=>({...e,box:b(e.box),words:e.words.map(e=>({...e,box:b(e.box)}))}))}},l=async e=>await c(e)??{height:e.frame.height,lines:[],text:``,width:e.frame.width};return{loadTextDetector:s,readRectifiedText:c,detectRectifiedText:l,detectDocumentText:async({engine:e=r,frame:n,language:i,polygon:a})=>{let o=await t({frame:n,polygon:a});if(!o)return{height:0,lines:[],rotation:0,text:``,width:0};try{return{...await l({engine:e,frame:o.frame,language:i}),rotation:o.orientation.rotation}}finally{o.frame.close()}}}},it=({runtime:e,documentAlignment:t,rectifiedDocumentFace:n,orientDocumentFrame:r,restoreRectifiedFace:s,analyzeDocument:l,faceDetection:u,faceMatch:p,textDetection:m})=>{let g=h({runtime:e}),_=({frame:t,text:n})=>{let r=e.createCanvas(32,32),i=r.getContext(`2d`,{willReadFrequently:!0});if(!i)throw Error(v.IMAGE_PROCESSING_FAILED);i.drawImage(t,0,0,r.width,r.height);let{data:o}=i.getImageData(0,0,r.width,r.height);return a({canvas:r}),R({data:o,height:32,text:n,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:r,ocr:i,options:a,documentAnalysis:o,document:c,text:l,prepareForMatch:f})=>{let m=o.detection,h=a.requiresFace??!0,g={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}]},y=h?await u.detectDocumentFaces({detection:g,frame:c.frame}):{faces:[],pictureFaces:[],hasPictureFace:await u.detectDocumentFacePresence({detection:g,frame:c.frame})},x=y.pictureFaces.map(e=>s({document:c,face:e})),S=_({frame:c.frame,text:l.text}),C=r.find(e=>e.type===`mrz`)??null,w=null;for(let g of y.faces.length?y.faces:[null]){let _=g?s({document:c,face:g}):null,T=g?n({face:g}):null,E=h&&m?u.faceIsInsideDocument({detection:m,face:_})&&x.every(e=>u.faceIsInsideDocument({detection:m,face:e})):!1,D=t({documentSize:{height:l.height,width:l.width},face:T,lines:l.lines,maxAngleDifference:a.maxDocumentTextAngleDifference,maxFaceAreaRatio:a.maxDocumentFaceAreaRatio,maxFaceHeightRatio:a.maxDocumentFaceHeightRatio,maxFaceWidthRatio:a.maxDocumentFaceWidthRatio,minFaceAreaRatio:a.minDocumentFaceAreaRatio,minFaceHeightRatio:a.minDocumentFaceHeightRatio,minFaceWidthRatio:a.minDocumentFaceWidthRatio}),O=b({alignment:D,detection:m,documentAnalysis:o,faceContained:E,requiresFace:h,text:l});h&&!e&&O.push(v.DOCUMENT_NOT_RECOGNIZED),e?.europeanDrivingLicense&&!d({identity:e.identity})&&O.push(v.DOCUMENT_VALIDATION_FAILED);let k=O.length===0,A=null,j=null;if(h&&k&&g){let e=p.prepareFace({alignment:a.alignment??`eyes-nose-mouth`,face:g,frame:c.frame});if(!e)k=!1,O.push(v.FACE_NOT_USABLE);else if(f){let t=await p.preparedFaceArtifacts({face:e});A=t?.embeddings??null,j=t?.images??null,t||(k=!1,O.push(v.INVALID_MODEL_OUTPUT))}}let M={identity:e?e.identity:null,orientation:c.orientation,ocr:i,mrz:C,alignment:D,detection:m,documentAnalysis:o,documentKind:e?e.document:null,europeanDrivingLicense:e?e.europeanDrivingLicense:!1,codes:r,documentToSource:c.toSource,embeddings:A,images:j,face:_,faceContained:E,hasPictureFace:y.hasPictureFace??x.length>0,failureReasons:O,pictureFaces:x,signature:S,text:l,valid:k};if(M.valid)return M;w??=M}if(!w)throw Error(v.INTERNAL_ERROR);return w},S=async({frame:n,options:a,documentAnalysis:s,prepareForMatch:l=!1})=>{let u=s.detection;if(!u){let e={height:0,lines:[],text:``,width:0},n=t({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:n,detection:u,documentAnalysis:s,documentKind:null,documentToSource:null,embeddings:null,face:null,faceContained:!1,failureReasons:b({alignment:n,detection:u,documentAnalysis:s,faceContained:!1,requiresFace:a.requiresFace??!0,text:e}),images:null,pictureFaces:[],hasPictureFace:!1,signature:null,text:e,valid:!1}}let d=await r({frame:n,polygon:u.polygon,orientation:u.orientation});if(!d)throw Error(v.IMAGE_PROCESSING_FAILED);try{let t=performance.now(),r=i({image:g({frame:n}),polygon:u.polygon,sourceOrientation:d.orientation.rotation}),f=a.requiresFace===!1?`back`:`front`;N({category:`stages`,key:`ocr.prepare.${f}`,duration:performance.now()-t});let p=g({frame:d.frame}),h=await m.readRectifiedText({classificationImage:p,engine:a.ocrEngine,frame:d.frame,language:a.language,image:r}),_=h??{height:d.height,lines:[],text:``,width:d.width},v=h?D({result:h}):null,y=null;if(a.requiresFace===!1){let t=e.createImageData(p.width,p.height);t.data.set(p.data),y=await c({key:`barcode.back`,operation:()=>Ye({image:t})})}let b=[v,y].filter(e=>e!==null),S=o({image:p,text:_.text,codes:b}),C=a.requiresFace!==!1&&S?.europeanDrivingLicense&&h?U({ocr:h,image:p}):null,w=S?{...S,identity:C}:null;return await x({ocr:h,classification:w,codes:b,options:a,documentAnalysis:s,document:d,prepareForMatch:l,text:_})}finally{d.frame.close()}},C=async({frame:e,options:t,prepareForMatch:n=!1})=>{let r=await l({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 f({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:t,readImage:n})=>async({image:r,timings:o})=>{let s=await e.createImageBitmap(new Blob([r]));try{let r=performance.now(),c=await t.analyzeDocument({frame:s});if(o&&(o.documentBoxDetectionMs=performance.now()-r),!c.detection)throw Error(v.DOCUMENT_NOT_FOUND);let{polygon:l,orientation:u}=c.detection,d=i({image:n({frame:s}),polygon:l,sourceOrientation:u?.rotation}),f=e.createCanvas(d.width,d.height);try{let t=f.getContext(`2d`);if(!t)throw Error(v.IMAGE_PROCESSING_FAILED);let n=e.createImageData(d.width,d.height);n.data.set(d.data),t.putImageData(n,0,0);let r=await f.convertToBlob({type:`image/png`});return new Uint8Array(await r.arrayBuffer())}finally{a({canvas:f})}}finally{s.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=h({runtime:e}),i=O({runtime:e}),a=C({runtime:e}),o=w({runtime:e,imageFromImageBitmap:r}),s=rt({runtime:e,getOcr:t,...i}),c=M({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:ie,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`];e(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`};e(Z),_t.map(e=>Z[e]),Y.map(e=>Z[e]);var yt=async()=>{let e=await fetch(ae({filename:`faceMeshLines.json`}));if(!e.ok)throw Error(F.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(F.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),ce({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),ce({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]:S({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=b({...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})||k({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:i})=>{let a=e.ref,o=({state:e})=>e.faceSequence[e.poseIndex]??`faceStraight`,s=({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},c=async({frame:c,session:l,state:u,options:d})=>{let f=performance.now(),p=null,m=!1;try{p=await It(c);let e=p?await Ft(c):null;if(m=!!(p&&e&&r({face:p,polygon:e.polygon})),!n({flow:`face`,session:l,state:u}))return!1;if(d.showFaceOverlay&&await Tt({element:a.mesh,meshLineColor:d.faceMeshColor,overlayColor:d.faceOverlayColor,result:p}),!p){u.poseStableFrames=0;let e=o({state:u});return t.feedback.value={flow:`face`,code:`FACE_NOT_DETECTED`,pose:e},!1}if(m)return u.poseStableFrames=0,t.feedback.value={flow:`face`,code:`FACE_IN_POLYGON`,pose:o({state:u})},!1;let f=o({state:u}),h=jt({face:p,frame:c});if(h)return u.poseStableFrames=0,t.feedback.value={flow:`face`,code:h,pose:f},!1;let g=s({face:p,frame:c});if(g)return u.poseStableFrames=0,t.feedback.value={flow:`face`,code:g,pose:f},!1;let _=k({pitch:p.pitch,pose:f,requireEyeLevelCamera:d.requireEyeLevelCamera,options:d});if(_)return u.poseStableFrames=0,u.guidanceCodeState=y(),u.correctiveState=T(),t.guidance.value=null,t.corrective.value=null,t.feedback.value={flow:`face`,code:_,pose:f},!1;let v={pitch:p.pitch,yaw:p.yaw,roll:p.roll},b=ee({alignment:v,blendshapes:p.blendshapes,neutral:u.neutralPose,pose:f,options:d});u.guidanceCodeState=te({state:u.guidanceCodeState,code:b.code,requiredFrames:3}),t.guidance.value=b;let S=b.code?$[b.code]:null,C=u.guidanceCodeState.published?$[u.guidanceCodeState.published]:null,w=x({pose:f,corrective:C?Ot({code:C}):null}).corrective,E=performance.now();if(u.correctiveState=j({label:w,now:E,state:u.correctiveState}),t.corrective.value=ne({label:w,now:E,state:u.correctiveState}),S)return u.poseStableFrames=0,t.feedback.value={flow:`face`,code:C,pose:f},!1;if(f===`faceStraight`&&(u.neutralPose=v),u.poseStableFrames+=1,u.poseStableFrames<d.requiredFaceStableFrames)return t.feedback.value={flow:`face`,code:`FACE_STABILITY_REQUIRED`,pose:f},!1;t.feedback.value={flow:`face`,code:null,pose:f};let D=await oe({frame:c}),O=await Pt({capture:D,pose:f,options:u.matchOptions,poseOptions:d,requireEyeLevelCamera:d.requireEyeLevelCamera});if(!n({flow:`face`,session:l,state:u}))return!1;if(!O)return u.poseStableFrames=0,t.feedback.value={flow:`face`,code:`FACE_STABILITY_REQUIRED`,pose:f},!1;let A=et({image:J.readImage({frame:c,width:32,height:32})}),M=u.previousPoseBackgroundSignature;if(M&&!tt({first:M,second:A}).matched)throw Error(F.POSE_BACKGROUND_MISMATCH);let N=u.faceEmbeddings.faceStraight;if(N&&re({first:N,second:O.embeddings})<=u.matchOptions.threshold)throw Error(F.POSE_IDENTITY_MISMATCH);let P=f;return u.captures[P]=D,u.preparedCaptures[P]=O.images,u.faceEmbeddings[P]=O.embeddings,u.previousPoseBackgroundSignature=A,i({state:u}),t.success.value=!0,await se({milliseconds:400}),t.success.value=!1,n({flow:`face`,session:l,state:u})?(u.poseIndex+=1,u.poseStableFrames=0,u.guidanceCodeState=y(),u.correctiveState=T(),t.corrective.value=null,t.progress.value={completed:u.poseIndex,total:u.faceSequence.length},u.poseIndex===u.faceSequence.length?(t.feedback.value=null,!0):(t.feedback.value={flow:`face`,pose:o({state:u}),code:null},!1)):!1}finally{n({flow:`face`,session:l,state:u})&&e.collectFaceDebug({face:p,faceInPolygon:m,processingTimeMilliseconds:performance.now()-f,state:u}),c.close()}};return{runFaceLoop:async({session:e,state:r,options:i})=>{for(;n({flow:`face`,session:e,state:r});){if(await le({video:a.video}),!n({flow:`face`,session:e,state:r}))return;let o=await createImageBitmap(a.video);if(await c({frame:o,session:e,state:r,options:i})){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(F.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(F.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(F.INVALID_POSES);let i=r.slice(1);return t?[`faceStraight`,...Bt({sequence:i})]:[`faceStraight`,...Vt({sequence:i})]},Ut=()=>({activity:A(null),error:A(null),retry:A(null),feedback:A(null),guidance:A(null),corrective:A(null),progress:A({completed:0,total:0}),success:A(!1),cameraSize:A(null),cameraFacingMode:A(null),debug:A([]),debugEnabled:A(!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};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! Copyright (c) 2026 VOLTOM. All rights reserved. Proprietary software. See LICENSE at https://voltom.io/license. */
|
|
2
|
+
import{nt as e}from"./eyeLevelCamera-DY4onSBz.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};
|
package/dist/sdk/verify.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type Mode = "
|
|
1
|
+
export type Mode = "hard";
|
|
2
2
|
|
|
3
3
|
export type Pose =
|
|
4
4
|
| "faceStraight"
|
|
@@ -28,9 +28,7 @@ export type FaceDetectorName = "high" | "standard" | "low";
|
|
|
28
28
|
export type VerificationCapability = "verifyHuman" | "verifyDocument" | "matchID" | "matchPicture";
|
|
29
29
|
|
|
30
30
|
export type VerificationOperationOptions = {
|
|
31
|
-
mode?: Mode;
|
|
32
31
|
poses?: Pose[] | "all";
|
|
33
|
-
posesCount?: number;
|
|
34
32
|
randomizeFaceSequence?: boolean;
|
|
35
33
|
showFaceOverlay?: boolean;
|
|
36
34
|
showDocumentOverlay?: boolean;
|
|
@@ -43,42 +41,41 @@ export type VoltomOptions = {
|
|
|
43
41
|
root?: HTMLElement;
|
|
44
42
|
video?: HTMLVideoElement;
|
|
45
43
|
ui?: boolean;
|
|
46
|
-
mode?: Mode;
|
|
47
44
|
language?: Language;
|
|
48
45
|
ocrEngine?: OcrEngine;
|
|
49
46
|
faceDetector?: FaceDetectorName;
|
|
50
47
|
clientKey: string;
|
|
48
|
+
requireEyeLevelCamera?: boolean;
|
|
51
49
|
apiUrl?: string;
|
|
52
|
-
threshold
|
|
50
|
+
threshold?: number;
|
|
53
51
|
poses?: Pose[] | "all";
|
|
54
|
-
posesCount?: number;
|
|
55
52
|
randomizeFaceSequence?: boolean;
|
|
56
|
-
requiredFaceStableFrames
|
|
57
|
-
requiredDocumentStableFrames
|
|
58
|
-
maxPitch
|
|
59
|
-
minPitch
|
|
60
|
-
maxYaw
|
|
61
|
-
minYaw
|
|
62
|
-
maxRoll
|
|
63
|
-
minDocumentFaceAreaRatio
|
|
64
|
-
maxDocumentFaceAreaRatio
|
|
65
|
-
minDocumentFaceWidthRatio
|
|
66
|
-
maxDocumentFaceWidthRatio
|
|
67
|
-
minDocumentFaceHeightRatio
|
|
68
|
-
maxDocumentFaceHeightRatio
|
|
69
|
-
minDocumentBoxRatio
|
|
70
|
-
maxDocumentTextAngleDifference
|
|
71
|
-
showDocumentOverlay
|
|
72
|
-
showFaceOverlay
|
|
73
|
-
faceOverlayColor
|
|
74
|
-
faceMeshColor
|
|
75
|
-
documentOverlayColor
|
|
76
|
-
documentBoxColor
|
|
77
|
-
documentFaceBoxColor
|
|
78
|
-
documentFaceMeshColor
|
|
79
|
-
showTextOverlay
|
|
80
|
-
textColor
|
|
81
|
-
debug
|
|
53
|
+
requiredFaceStableFrames?: number;
|
|
54
|
+
requiredDocumentStableFrames?: number;
|
|
55
|
+
maxPitch?: number;
|
|
56
|
+
minPitch?: number;
|
|
57
|
+
maxYaw?: number;
|
|
58
|
+
minYaw?: number;
|
|
59
|
+
maxRoll?: number;
|
|
60
|
+
minDocumentFaceAreaRatio?: number;
|
|
61
|
+
maxDocumentFaceAreaRatio?: number;
|
|
62
|
+
minDocumentFaceWidthRatio?: number;
|
|
63
|
+
maxDocumentFaceWidthRatio?: number;
|
|
64
|
+
minDocumentFaceHeightRatio?: number;
|
|
65
|
+
maxDocumentFaceHeightRatio?: number;
|
|
66
|
+
minDocumentBoxRatio?: number;
|
|
67
|
+
maxDocumentTextAngleDifference?: number;
|
|
68
|
+
showDocumentOverlay?: boolean;
|
|
69
|
+
showFaceOverlay?: boolean;
|
|
70
|
+
faceOverlayColor?: string;
|
|
71
|
+
faceMeshColor?: string;
|
|
72
|
+
documentOverlayColor?: string;
|
|
73
|
+
documentBoxColor?: string;
|
|
74
|
+
documentFaceBoxColor?: string;
|
|
75
|
+
documentFaceMeshColor?: string;
|
|
76
|
+
showTextOverlay?: boolean;
|
|
77
|
+
textColor?: string;
|
|
78
|
+
debug?: boolean;
|
|
82
79
|
capabilities?: VerificationCapability[];
|
|
83
80
|
};
|
|
84
81
|
|
|
@@ -185,6 +182,7 @@ declare class VoltomVerify {
|
|
|
185
182
|
verifyHuman(settings?: VerificationOperationOptions): Promise<VoltomVerificationResult>;
|
|
186
183
|
verifyDocument(settings?: VerificationOperationOptions): Promise<VoltomVerificationResult>;
|
|
187
184
|
matchID(settings?: VerificationOperationOptions): Promise<VoltomVerificationResult>;
|
|
185
|
+
/** Accepts images or PDFs up to 10 MB. PDFs use only page 1, rendered at up to 1200 pixels. */
|
|
188
186
|
matchPicture(picture: Blob, settings?: VerificationOperationOptions): Promise<VoltomVerificationResult>;
|
|
189
187
|
forgetHuman(): void;
|
|
190
188
|
forgetDocument(): void;
|