@sekyro/web 0.1.0-rc.38 → 0.1.0-rc.39
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/CHANGELOG.md +7 -0
- package/dist/{capture-session-doc-MGDYUASI.js → capture-session-doc-J4MIDQOS.js} +1 -1
- package/dist/{capture-session-v3-Z2KI_2p9.d.ts → capture-session-v3-BnRN9WuV.d.ts} +1 -1
- package/dist/{capture-session-v3-Dz-AQW52.d.cts → capture-session-v3-DjWqEJG0.d.cts} +1 -1
- package/dist/chunk-26XZRWBD.js +3 -0
- package/dist/chunk-3565JBSZ.js +1 -0
- package/dist/{chunk-TOISWBOX.js → chunk-3WQJI7UL.js} +1 -1
- package/dist/{chunk-PBWIMNSN.js → chunk-7FGOUBAN.js} +1 -1
- package/dist/{chunk-5AR5GTEJ.js → chunk-BRLQIJYF.js} +1 -1
- package/dist/{chunk-COZXZAD5.js → chunk-HMOOVRKA.js} +1 -1
- package/dist/{chunk-QTOMWAS6.js → chunk-P5OIQXVM.js} +1 -1
- package/dist/{chunk-TQQK7464.js → chunk-PNOGF72U.js} +1 -1
- package/dist/{chunk-IAKYKPL6.js → chunk-TGSMTRG5.js} +1 -1
- package/dist/{chunk-VMHFHHPP.js → chunk-UKYJYZZS.js} +1 -1
- package/dist/{chunk-XDB7L5KS.js → chunk-WI7GAUCH.js} +1 -1
- package/dist/client/index.cjs +1 -1
- package/dist/client/index.d.cts +3 -3
- package/dist/client/index.d.ts +3 -3
- package/dist/client/index.js +1 -1
- package/dist/core/index.cjs +1 -1
- package/dist/core/index.d.cts +3 -3
- package/dist/core/index.d.ts +3 -3
- package/dist/core/index.js +1 -1
- package/dist/create-document-capture-SMEKDBGF.js +1 -0
- package/dist/{create-verification-BG6A2iyO.d.cts → create-verification-BSOb3N6w.d.cts} +27 -4
- package/dist/{create-verification-2Qm_K28Y.d.ts → create-verification-C6Hoh_0h.d.ts} +27 -4
- package/dist/{detector-scanic-JC25DD3A.js → detector-scanic-P2RTEQUV.js} +1 -1
- package/dist/{icao-gate-QqtNED0V.d.ts → icao-gate-Bux2CcJc.d.ts} +1 -1
- package/dist/{icao-gate-Dyb0wGO3.d.cts → icao-gate-C-fkVe6r.d.cts} +1 -1
- package/dist/{icao-policy-iIBtqhbf.d.cts → icao-policy-B_daycJk.d.cts} +2 -2
- package/dist/{icao-policy-DsaRylAQ.d.ts → icao-policy-C5XcEwqj.d.ts} +2 -2
- package/dist/index.cjs +2 -2
- package/dist/index.d.cts +7 -7
- package/dist/index.d.ts +7 -7
- package/dist/index.js +1 -1
- package/dist/internal/index.cjs +2 -2
- package/dist/internal/index.d.cts +6 -6
- package/dist/internal/index.d.ts +6 -6
- package/dist/internal/index.js +1 -1
- package/dist/{plan-runner-NWK4LZFI.js → plan-runner-ZVYJ3UI3.js} +1 -1
- package/dist/{types-Cy_SJtPf.d.cts → types-BUnFqG97.d.cts} +11 -1
- package/dist/{types-Cy_SJtPf.d.ts → types-BUnFqG97.d.ts} +11 -1
- package/package.json +1 -1
- package/sbom.cdx.json +19 -19
- package/dist/chunk-C4XDRRU5.js +0 -1
- package/dist/chunk-IOCOIZKE.js +0 -3
- package/dist/create-document-capture-KISF6XD3.js +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# @sekyro/web
|
|
2
2
|
|
|
3
|
+
## 0.1.0-rc.39
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 9610931: Japan: the My Number card (Individual Number Card) is captured and read from its front only. Its back holds the My Number, which the law limits who may collect (My Number Act, Arts. 19-20), so the capture plan leaves it out and the server refuses a back sent anyway with the new retryable reason `document_side_not_read` (not billed, nothing kept), shown with its own retake line. The Japanese residence card and driving licence numbers people type are checked against their formats.
|
|
8
|
+
- 10715ba: Document capture: a method that serves only some countries (a population registry, a national eID) is a row on those countries' document type lists, listed first, and no longer a switch under another country's documents. After picking Senegal, no « Enter my Mauritanian NNI »; Mauritania lists Numéro national (NNI), Carte d'identité, Passeport, Carte de séjour. Choice options carry `countries` and `names` from the server; the row label comes from that data (`laneOptionsFor`, `optionNameFor` in @sekyro/web).
|
|
9
|
+
|
|
3
10
|
## 0.1.0-rc.38
|
|
4
11
|
|
|
5
12
|
### Patch Changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{A as b,B as c,C as d,D as e,E as f,F as g,G as h,H as i,I as j,J as k,z as a}from"./chunk-
|
|
1
|
+
import{A as b,B as c,C as d,D as e,E as f,F as g,G as h,H as i,I as j,J as k,z as a}from"./chunk-TGSMTRG5.js";import"./chunk-MQHTFHSN.js";import"./chunk-SMKCBUJL.js";import"./chunk-3WQJI7UL.js";import"./chunk-BRLQIJYF.js";import"./chunk-POIQGEZM.js";import"./chunk-CPUECYAJ.js";import"./chunk-FPXL63KZ.js";import"./chunk-HMOOVRKA.js";import"./chunk-WNBEOK5Q.js";export{k as CAPTURE_CANDIDATE_SPACING_MS,j as CAPTURE_EXTRA_CANDIDATES,h as CaptureSessionDoc,c as DOC_BLACK_FRAME_LUMA,d as DOC_BLACK_FRAME_TICKS,e as DOC_CADENCE_HZ,b as DOC_FIRST_FRAME_MS,f as DOC_SHUTTER_DEFAULTS,i as passportBandOf,g as resolveDocShutterTuning,a as warmDocDetector};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { bt as ScreenRampReport, bk as CaptureProvenance, bq as ScreenRampChallenge, br as ScreenRampPaint } from './types-
|
|
1
|
+
import { bt as ScreenRampReport, bk as CaptureProvenance, bq as ScreenRampChallenge, br as ScreenRampPaint } from './types-BUnFqG97.js';
|
|
2
2
|
import { F as FaceObservation, b as Detector, W as WorkerLike } from './detect-worker-CHqsPJoM.js';
|
|
3
3
|
|
|
4
4
|
/** MP4-first ladder: one container (H.264 MP4) covers iOS/macOS Safari + Chrome 130+.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { bt as ScreenRampReport, bk as CaptureProvenance, bq as ScreenRampChallenge, br as ScreenRampPaint } from './types-
|
|
1
|
+
import { bt as ScreenRampReport, bk as CaptureProvenance, bq as ScreenRampChallenge, br as ScreenRampPaint } from './types-BUnFqG97.cjs';
|
|
2
2
|
import { F as FaceObservation, b as Detector, W as WorkerLike } from './detect-worker-CHqsPJoM.cjs';
|
|
3
3
|
|
|
4
4
|
/** MP4-first ladder: one container (H.264 MP4) covers iOS/macOS Safari + Chrome 130+.
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{B as ft,C as mt,D as ht,E as yt,a as ot,b as rt,c as it,d as Z,e as J,f as ie,g as st,h as K,i as at,j as M,k as j,l as T,m as D,n as U,o as X,p as ut,q as z,r as se,s as ct,t as dt,u as lt,v as pt}from"./chunk-UKYJYZZS.js";import{n as et}from"./chunk-P5OIQXVM.js";import{a as ze}from"./chunk-7QZWBDI5.js";import{c as G,e as tt,g as nt,h as ae}from"./chunk-PNOGF72U.js";import{c as Je,d as ke}from"./chunk-TSA6GHUG.js";import{b as Xe}from"./chunk-HMOOVRKA.js";function gt(e){let t=e.now??(()=>Date.now()),n=e.setTimer??((h,p)=>setTimeout(h,p)),i=e.clearTimer??(h=>clearTimeout(h)),r=null,u=!1,s=!1,c=!1,f=0,S=null,_=()=>{S!==null&&i(S),S=null},A=()=>{let h=e.armRamp;h===void 0||u||s||c||t()<f||(u=!0,h().catch(()=>{}).then(p=>{if(u=!1,!c){if(p===void 0){f=t()+2e3;return}if(p.challenge===void 0){s=!0;return}r={challenge:p.challenge,expiresAt:p.expiresAt},_(),S=n(()=>{S=null,!c&&r!==null&&e.waiting()&&A()},Math.max(1e3,p.expiresAt-t()-2e4))}}))};return{arm(){r!==null&&r.expiresAt-t()>2e4||A()},take(){let h=r;return r=null,_(),h!==null&&h.expiresAt-t()>=12e3?h.challenge:void 0},stop(){c=!0,r=null,_()}}}function ue(e){return e.idNumberBound??e.nniBound}function ee(e){return e===void 0?void 0:e.idNumberFromDocument??e.nniFromDocument}function St(e){let t=e.idNumberMasked??e.nniMasked;return typeof t=="string"&&t!==""?t:void 0}var Xt="https://api.sekyro.ai",zt=5e3,en=24e4,tn=9e4,nn=25*6e4,on=20*6e4,rn=3,sn=3e3,an=1500,un=10;function _t(e){return e instanceof Error&&e.name==="ChallengeError"&&e.code||"challenge_failed"}var kt=new Set(["aborted","embedder_opaque","site_key_rejected"]);function cn(e){return new Promise(t=>setTimeout(t,e))}function dn(){let e=globalThis.crypto;if(e!==void 0&&typeof e.randomUUID=="function")return e.randomUUID();let t=new Uint8Array(16);if(e!==void 0&&typeof e.getRandomValues=="function")e.getRandomValues(t);else for(let i=0;i<16;i+=1)t[i]=Math.floor(Math.random()*256);t[6]=(t[6]??0)&15|64,t[8]=(t[8]??0)&63|128;let n=[...t].map(i=>i.toString(16).padStart(2,"0")).join("");return`${n.slice(0,8)}-${n.slice(8,12)}-${n.slice(12,16)}-${n.slice(16,20)}-${n.slice(20)}`}function Po(e){return ln(e,{})}function ln(e,t){let n=e.apiOrigin??Xt,i=e.autoRetry??!0,r=e.rearm??"auto",u=t.client??new nt({apiOrigin:n,sessionToken:e.clientToken,fetch:e.fetch,locale:e.locale}),s=new Proxy(u,{get(o,a){if(a==="submitCheck")return Bt;let d=Reflect.get(o,a,o);return typeof d=="function"?d.bind(o):d}}),c=t.sleep??cn,f=t.uuid??dn,S=t.getChallengeToken??((o,a)=>import("./challenge-frame-YBTLAQ5G.js").then(d=>d.executeChallenge({frameUrl:o.url,siteKey:o.siteKey,action:"liveness",subject:a.subject,signal:a.signal}))),_=ze(),A=null,h=null,p=!1,O=new AbortController,k=null,de=null,te=null,ne=()=>te??ct(k),oe=()=>dt(se(k),ne()),E=o=>{k=o,!M(o)&&(Be(on)||Dt(o))&&_e(o),_.emit("view",o),A?.onView(o)},x=()=>k!==null?Promise.resolve(k):(de??(de=s.getSession().then(o=>(E(o),o)).finally(()=>{de=null})),de),I=async()=>{let o=await s.getSession();return E(o),o},le=async(o,a)=>{o.plan!==void 0?E(o):await I()},pe=null,Me=async o=>{let a=await x();if(o||!a.consentRecorded){let d=await s.recordConsent(e.locale);d.plan!==void 0?E(d):k!==null&&E({...k,consentRecorded:!0})}re()&&_e(a)},F=o=>o?.force===!0?Me(!0):(pe??(pe=Me(!1).finally(()=>{pe=null})),pe),fe={client:s,ensureConsent:o=>F(o),sleep:c,uuid:f,...t.random!==void 0?{random:t.random}:{},onBusy:o=>{p||_.emit("busy",o)}},Oe=!1,Ee=null,me=o=>{if(o.status==="verified"||o.status==="not_verified"||o.status==="review"){if(Oe)return;Oe=!0}Ee=JSON.stringify(o),_.emit("result",o)},Nt=o=>{Ee!==JSON.stringify(o)&&me(o)},Ie=async o=>{let a=k;o&&(a=await I().catch(()=>k));let d=a===null?null:K(a);return d!==null&&!p&&_.emit("method",d),d!==null},ve=null,Te=!1,Ve=!1,Fe=()=>mt(fe,(o,a)=>o.submitCheck("population_registry",{},{idempotencyKey:a})),Ne=o=>ue(o)===!0||ee(T(o,"population_registry"))===!0,Ht=async()=>{try{let o=await x();if(M(o)||K(o)!==null||j(o)?.checkType!=="population_registry")return;if(!Ne(o)&&ee(T(o,"population_registry"))===void 0&&(o=await I()),!Ne(o)){Ve=!0;return}await F(),await le(await Fe(),"population_registry");let a=k===null?void 0:T(k,"population_registry");if(a?.state==="input_required"&&a.reason==="registry_unavailable"&&ie(a)>0){if(await c(zt),p)return;await le(await Fe(),"population_registry")}}catch(o){if(o instanceof G&&(o.code==="check_not_active"||o.code==="step_not_on_path")){await I().catch(()=>{});return}Te=!0;return}k!==null&&M(k)&&me(X(k,{autoRetry:i}))},He=()=>(ve??(ve=Ht()),ve),v=t.now??Date.now,q=null,Y,he,Lt=0,ye=(o,a)=>`${o.url}
|
|
2
|
+
${o.siteKey}
|
|
3
|
+
${a}`,Le=0,ge,Se=(o,a)=>{Le+=1;let d=v(),y=S(o,{signal:O.signal,subject:a}),m={key:ye(o,a),at:d,token:y};return y.then(()=>{m.issuedAt=v(),he=void 0},C=>{let g=_t(C);if(m.failed=g,p||g==="aborted")return;he=g;let{detail:b,readyMs:l}=C;W({check:"attestation",kind:"unavailable",engineKind:g,attempt:Lt++,challengeMs:v()-d,readyMs:l,detail:b,inApp:Xe()})}),y.catch(()=>{}),m},De=(o,a)=>o!==null&&o.key===a&&(o.issuedAt===void 0||v()-o.issuedAt<en),_e=(o,a={})=>{let d=o?.challenge??null;if(o===null||d===null||p)return;let y=D(o.sessionId),m=q;(a.replaceFailed===!0&&m?.failed!==void 0&&!kt.has(m.failed)||!De(m,ye(d,y)))&&(q=Se(d,y))},Ue=async(o,a)=>{let d=ye(o,a),y=q;q=null;let m=De(y,d)?y:Se(o,a),C=m===y?0:1,g,b=new Promise(l=>{g=setTimeout(()=>l("late"),tn)});try{for(;;){let l=await Promise.race([m.token.then(P=>({token:P}),P=>({error:_t(P)})),b]);if(l==="late")return!p&&q===null&&(q=m),{error:he??"timeout"};if("token"in l)return ge=Math.max(0,Math.round((m.issuedAt??v())-m.at)),l;if(p||kt.has(l.error)||C>=rn||C>0&&await Promise.race([c(sn*C),b])==="late")return l;if(p)return{error:"aborted"};C+=1,m=Se(o,a)}}finally{clearTimeout(g)}},H=null,Dt=o=>J(o).some(a=>(a.checkType==="phone_otp"||a.checkType==="email_otp")&&a.state!=="passed"&&a.state!=="skipped"),Be=o=>H===null||v()-H>=o,re=()=>Be(nn),Ut=o=>{let a=o.attestation;return typeof a?.turnstileToken=="string"&&a.turnstileToken.length>0},qe=new Map,Ge=async()=>{let o=await x(),a=o.challenge;if(a==null||o.simulation!==void 0)return;let d=await Ue(a,D(o.sessionId));if(!("token"in d))throw new G({status:400,code:"attestation_invalid",message:`browser check: ${d.error}`});return d.token},Bt=async(o,a,d={})=>{let y=a;if("attestation"in y)try{let l=await u.submitCheck(o,a,d);return Ut(y)&&(H=v()),l}catch(l){throw l instanceof G&&l.code==="attestation_invalid"&&(H=null),l}let m=(o==="phone_otp"||o==="email_otp")&&y.action!=="verify",C=d.idempotencyKey,g=C!==void 0?qe.get(C):void 0;g===void 0&&(m||re())&&(g=await Ge(),C!==void 0&&g!==void 0&&qe.set(C,g));let b=(l,P)=>l!==void 0?{...P,browserCheckToken:l}:P;try{let l=await u.submitCheck(o,a,b(g,d));return g!==void 0&&(H=v()),l}catch(l){if(!(l instanceof G)||l.code!=="attestation_invalid"||(H=null,g!==void 0))throw l;let P=await Ge(),L=C!==void 0?{...d,idempotencyKey:f()}:d,N=await u.submitCheck(o,a,b(P,L));return P!==void 0&&(H=v()),N}},Ke=async(o={})=>{if(Y=void 0,o.always!==!0&&!re())return{};let a=await x(),d=a.challenge;if(d==null)return{};let y=await Ue(d,D(a.sessionId));if("token"in y)return{channel:"hosted_web",turnstileToken:y.token};if(Y=y.error,a.simulation!==void 0)return{channel:"hosted_web"};throw new ft(y.error)},qt=()=>Y,Gt=()=>({checks:Math.min(50,Le),...ge!==void 0?{challengeMs:Math.min(6e5,ge)}:{}}),W=o=>{if(p)return;let a=s.reportCaptureIssue;if(a===void 0)return;let d=o.formFactor;try{d??(d=Je())}catch{}try{Promise.resolve(a.call(s,{...o,...d!==void 0?{formFactor:d}:{}})).catch(()=>{})}catch{}},R=null,$=null,je=new WeakMap,Ye=Promise.resolve(),Q=0,Kt=async()=>{let o=await x();for(let a=0;a<un&&!p&&!M(o)&&j(o)===void 0&&J(o).some(d=>d.state==="processing")&&(await c(an),!p);a+=1)o=await I();return o},jt=async(o,a,d)=>{let{capture:y}=o,m=()=>p,C=()=>o.alive&&o.attempt===d,g=l=>{C()&&y.setFlowState(l)},b=l=>{if(!m()&&(l.status==="unavailable"&&l.reasonCode!==void 0&&!ot(l.reasonCode)&&W({check:"liveness",kind:"unavailable",phase:"upload",engineKind:l.reasonCode,attempt:Math.max(0,o.issues.value)}),me(l),!!C())){if(l.status==="retry"&&r==="auto"){y.handle.retry();return}y.setFlowState("done")}};if(a.degraded==="NO_RECORDER"){let l=k?.sessionId??(await x().catch(()=>null))?.sessionId??"";b(U(l,"no_recorder"));return}g("uploading");try{if(await He(),m())return;let l=await x(),P;if(!M(l)&&K(l)!==null){await Ie(!1),b(U(l.sessionId,"method_required"));return}if(!M(l)){if(j(l)?.checkType==="population_registry"){b(U(l.sessionId,Ve?"nni_unbound":Te?"network":"registry_unavailable"));return}if(await F(),m())return;P=k??l;let L=await ht({...fe,artifacts:a,getAttestation:Ke,attestationError:qt,attestationFacts:Gt,clipKeys:{get:()=>je.get(a)??null,set:N=>{je.set(a,N)}},getView:()=>k??l,refreshView:I,applySubmit:le,onPhase:g,isCancelled:m,onKeyframePromoted:N=>{h=N}});if(m())return;if(L.kind==="unavailable"){L.reason==="attestation"&&($={bound:o,artifacts:a});let N=U(l.sessionId,L.reason),Ze=L.reason==="attestation"?Y:void 0;b(Ze!==void 0?{...N,attestationError:Ze}:N);return}if(L.kind==="resync"&&await I(),k!==null&&K(k)!==null){await Ie(!1),b(U(l.sessionId,"method_required"));return}l=await Kt()}b(X(l,{autoRetry:i,previous:P}))}catch{if(m())return;b(U(k?.sessionId??"","network"))}},We=(o,a)=>{let d=o.attempt;Q>0&&o.alive&&o.capture.setFlowState("uploading"),Q+=1,Ye=Ye.then(()=>jt(o,a,d)).finally(()=>{Q-=1,Q===0&&A?.onChainIdle()}).catch(()=>{})},$e=o=>{R?.capture.handle.destroy(),R!==null&&(R.alive=!1,R.ramp.stop());let a=gt({armRamp:typeof s.armRamp=="function"?()=>s.armRamp():void 0,waiting:()=>m.alive&&oe()==="self"&&(y.handle.state==="starting"||y.handle.state==="gating")}),d=Promise.resolve(),y=et(o,A?.captureInternals?.(o)??t.capture,()=>k?.capture?.liveness?.keyframe?.rank===!0,oe,()=>a.take()??k?.capture?.liveness?.screenRamp,{session:()=>se(k),onModeChange:g=>{te=g}}),m={capture:y,alive:!0,ramp:a,attempt:0,issues:it()};R=m,y.handle.on("error",g=>{W(rt("liveness",g,m.issues.value))}),y.handle.on("state",g=>{if(m.issues.note(g),g==="starting"){m.attempt+=1,$?.bound===m&&($=null),re()&&_e(k,{replaceFailed:!0});let b=k===null?void 0:j(k)?.checkType;d=b==="liveness"||b==="face_match"?F().catch(()=>{}):Promise.resolve()}(g==="starting"||g==="gating")&&oe()==="self"&&d.then(()=>{m.alive&&a.arm()})}),y.handle.on("captured",g=>{Promise.resolve().then(()=>We(m,g))});let C=y.handle;return{get state(){return C.state},get captureMode(){return C.captureMode},get facingMode(){return C.facingMode},on:(g,b)=>C.on(g,b),start:async g=>{if(k===null&&await x().catch(()=>{}),!!m.alive)return C.start(g)},retry:()=>{let g=$;if(g!==null&&g.bound===m&&m.alive){$=null,We(m,g.artifacts);return}C.retry()},switchCamera:()=>C.switchCamera(),canSwitchCaptureMode:()=>C.canSwitchCaptureMode(),setCaptureMode:g=>C.setCaptureMode(g),destroy:()=>{m.alive=!1,a.stop(),R===m&&(R=null),C.destroy()}}},Yt=async()=>{if(p)return null;try{let o=await x();return p?null:K(o)}catch{return null}},Wt=async()=>{if(p)return"self";try{let o=await x();if(p)return"self";let a=se(o);return a==="choice"?ne()??a:a}catch{return"self"}},$t=async()=>{if(p)return!1;try{let o=await x();return p||M(o)||ke()?!1:z(o,j(o))==="phone"||z(o,T(o,"liveness"))==="phone"}catch{return!1}},Qt=async()=>{if(p)return!1;try{let o=await x();return!p&&o.returning===!0}catch{return!1}},Zt=async o=>{let a=(await x()).plan?.choice,d=a?.options.find(m=>Z[m.service]===o);if(!d)throw new RangeError(`method ${String(o)} is not offered`);let y=await s.choose(a.nodeId,d.id);p||E(y)},Qe=null,Jt=()=>(Qe??(Qe=import("./plan-runner-ZVYJ3UI3.js").then(o=>{let a=o.createPlanRunner({runtime:fe,currentView:()=>k,cameraMode:oe,captureModeSwitch:{pick:ne,choose:d=>{te=d}},ensureView:x,refreshView:I,ensureConsent:()=>F(),liveness:$e,stopLiveness:()=>{R!==null&&(R.alive=!1,R.ramp.stop(),R.capture.handle.destroy(),R=null)},chainBusy:()=>Q>0,destroyed:()=>p,sleep:c,isMobile:ke,now:t.now??Date.now,keptFaceKey:()=>h,setView:E,baseCapture:t.capture,emitStep:d=>{p||_.emit("step",d)},emitResult:Nt,reportCaptureIssue:W,documentInternals:t.document,documentFacts:t.documentFacts,portraitInternals:t.portrait,livePhotoInternals:t.livePhoto,uploadInternals:t.upload,pageCameraInternals:t.pageCamera});return A=a,a})),Qe);return{consent:()=>F(),startRegistry:He,methodChoice:Yt,selectMethod:Zt,reportCameraUnavailable:async o=>{await F();let a=s.reportCameraUnavailable;if(a===void 0)throw new TypeError("this client cannot report a missing camera");let d=await a.call(s,o).catch(y=>{if(y instanceof G&&y.code==="check_out_of_order")return s.getSession();throw y});p||E(d)},reportCaptureIssue:W,testerGate:async o=>{let a=s.testerGate;if(a===void 0)throw new TypeError("this client cannot run the tester gate");let d=o.clip,y=tt(o.clipMime??"");if(d===void 0||!pt.includes(y))throw new TypeError("the capture has no clip");await F();let m=await lt(s,"clip",y,d.size,{engine:o.engine,durationMs:o.clipMs});await s.uploadToSpaces(m.uploadUrl,d,y);let{key:C}=await s.completeMedia(m.key),g=await Ke({always:!0}),b=await a.call(s,{clipKey:C,attestation:g,captureChannel:o.captureChannel,capture:{...yt(o),attestationError:Y}}),{bound:l,...P}=b;return p||(P.plan!==void 0?E(P):await I()),{bound:l===!0}},mobileRequired:$t,captureMode:Wt,chooseCaptureMode:o=>{te=o},get captureChoice(){return ne()},returning:Qt,liveness:$e,run:async()=>{if(p)throw new Error("verification destroyed");return(await Jt()).run()},currentStep:()=>A?.current()??null,voiceClips:async()=>{if(p)return null;try{let o=await x();return p?null:o.voice??null}catch{return null}},on:(o,a)=>_.on(o,a),destroy:()=>{p=!0,O.abort(),A?.destroy(),R!==null&&(R.alive=!1,R.capture.handle.destroy(),R=null),_.clear()}}}var Ct=["AD","AE","AF","AG","AI","AL","AM","AO","AQ","AR","AS","AT","AU","AW","AX","AZ","BA","BB","BD","BE","BF","BG","BH","BI","BJ","BL","BM","BN","BO","BQ","BR","BS","BT","BV","BW","BY","BZ","CA","CC","CD","CF","CG","CH","CI","CK","CL","CM","CN","CO","CR","CU","CV","CW","CX","CY","CZ","DE","DJ","DK","DM","DO","DZ","EC","EE","EG","EH","ER","ES","ET","FI","FJ","FK","FM","FO","FR","GA","GB","GD","GE","GF","GG","GH","GI","GL","GM","GN","GP","GQ","GR","GS","GT","GU","GW","GY","HK","HM","HN","HR","HT","HU","ID","IE","IL","IM","IN","IO","IQ","IR","IS","IT","JE","JM","JO","JP","KE","KG","KH","KI","KM","KN","KP","KR","KW","KY","KZ","LA","LB","LC","LI","LK","LR","LS","LT","LU","LV","LY","MA","MC","MD","ME","MF","MG","MH","MK","ML","MM","MN","MO","MP","MQ","MR","MS","MT","MU","MV","MW","MX","MY","MZ","NA","NC","NE","NF","NG","NI","NL","NO","NP","NR","NU","NZ","OM","PA","PE","PF","PG","PH","PK","PL","PM","PN","PR","PS","PT","PW","PY","QA","RE","RO","RS","RU","RW","SA","SB","SC","SD","SE","SG","SH","SI","SJ","SK","SL","SM","SN","SO","SR","SS","ST","SV","SX","SY","SZ","TC","TD","TF","TG","TH","TJ","TK","TL","TM","TN","TO","TR","TT","TV","TW","TZ","UA","UG","UM","US","UY","UZ","VA","VC","VE","VG","VI","VN","VU","WF","WS","XK","YE","YT","ZA","ZM","ZW"];var pn=["carte_identite","passport","residence_permit","drivers_license"],fn=["carte_identite","passport","residence_permit"];function mn(e,t){let n=e.byIssuer?.[t]??e.default;return pn.filter(i=>n==="*"?fn.includes(i):n.includes(i))}function Io(e,t=Ct){return[...new Set([...t,...Object.keys(e.byIssuer??{})])].filter(i=>mn(e,i).length>0).sort()}function bt(e){if(e.acceptedDocuments)return e.acceptedDocuments;let t=e.acceptedDocumentTypes?.length?[...e.acceptedDocumentTypes]:["carte_identite","passport"];return{default:[],byIssuer:{MR:t}}}function vo(e){return/^[A-Z]{2}$/.test(e)?String.fromCodePoint(...[...e].map(t=>127462+t.charCodeAt(0)-65)):""}var w={fullNameMin:2,fullName:200,email:254,occupation:120,shortText:120,longText:1e3,addressLine:120,addressLines:4,city:80,postcode:16,number:1e12,dateMin:"1900-01-01",dateMax:"2100-12-31"},hn=new Set(["full_name","birth_date","email","phone","address","country","occupation"]),yn=new Set(["short_text","long_text","single_choice","multiple_choice","yes_no","date","number"]),gn=new Set(["ar","fa","he","ur"]);function wt(e){return gn.has(e.split("-")[0]?.toLowerCase()??"")?"rtl":"ltr"}function At(e){if(typeof e!="object"||e===null)return null;let t=e;if(typeof t.locale!="string"||!Array.isArray(t.questions)||t.questions.length===0)return null;let n=t.consents??[];if(!Array.isArray(n))return null;for(let r of t.questions)if(!Sn(r))return null;for(let r of n)if(!_n(r))return null;let i={locale:t.locale,questions:t.questions,consents:n};return typeof t.title=="string"&&t.title.trim()!==""&&(i.title=t.title),typeof t.intro=="string"&&t.intro.trim()!==""&&(i.intro=t.intro),typeof t.prefill=="object"&&t.prefill!==null&&!Array.isArray(t.prefill)&&(i.prefill=t.prefill),i}function Sn(e){if(typeof e!="object"||e===null)return!1;let t=e;return typeof t.id!="string"||typeof t.required!="boolean"?!1:t.kind==="field"?typeof t.field=="string"&&hn.has(t.field):t.kind!=="custom"||typeof t.type!="string"||!yn.has(t.type)||typeof t.label!="string"?!1:t.type==="single_choice"||t.type==="multiple_choice"?Array.isArray(t.choices)&&t.choices.length>=2&&t.choices.every(n=>typeof n=="object"&&n!==null&&typeof n.value=="string"&&typeof n.label=="string"):!0}function _n(e){if(typeof e!="object"||e===null)return!1;let t=e;if(typeof t.id!="string"||typeof t.required!="boolean"||typeof t.text!="string")return!1;if(t.link===void 0)return!0;let n=t.link;return typeof n=="object"&&n!==null&&typeof n.url=="string"&&/^https:\/\//.test(n.url)&&typeof n.label=="string"}var kn=/^(\d{4})-(\d{2})-(\d{2})$/;function Cn(e){if(typeof e!="string")return!1;let t=kn.exec(e);return t===null?!1:new Date(Date.UTC(Number(t[1]),Number(t[2])-1,Number(t[3]))).toISOString().slice(0,10)===e&&e>=w.dateMin&&e<=w.dateMax}function bn(e){return typeof e=="number"&&Number.isFinite(e)&&Math.abs(e)<w.number&&Math.round(e*100)/100===e}function Rt(e){for(let t of e.matchAll(/\d[\d -]{11,}\d/g)){let n=t[0].replace(/[ -]/g,"");if(n.length>=13&&n.length<=19&&wn(n))return!0}return!1}function wn(e){let t=0;for(let n=0;n<e.length;n++){let i=Number(e[e.length-1-n]);n%2===1&&(i*=2,i>9&&(i-=9)),t+=i}return t%10===0}var An=/^[^\s@]+@[^\s@.]+(\.[^\s@.]+)+$/,Rn=/^\+[1-9]\d{6,14}$/,xt=/^[A-Z]{2}$/,xn=e=>e===void 0||typeof e=="string"&&e.trim()===""||Array.isArray(e)&&e.length===0;function Pn(e=Date.now()){return new Date(e).toISOString().slice(0,10)}function Vo(e,t,n=Pn()){let i=[];for(let r of e.questions){let u=t.answers[r.id];if(xn(u)){r.required&&i.push({id:r.id,code:"required"});continue}let s=r.kind==="field"?Mn(r.field,u,n):En(r,u,n);s!==null&&i.push({id:r.id,...s})}for(let r of e.consents)r.required&&t.consents[r.id]!==!0&&i.push({id:r.id,code:"consent_required"});return i}function ce(e,t,n=1){if(typeof e!="string")return{code:"required"};let i=e.trim();return[...i].length>t?{code:"too_long",params:{max:t}}:[...i].length<n?{code:"too_short",params:{min:n}}:Rt(i)?{code:"card_number"}:null}function Pt(e,t,n={}){return Cn(e)?n.period==="past"&&e>=t?{code:"date_not_past"}:n.period==="future"&&e<=t?{code:"date_not_future"}:n.min!==void 0&&e<n.min?{code:"date_too_early",params:{date:n.min}}:n.max!==void 0&&e>n.max?{code:"date_too_late",params:{date:n.max}}:null:{code:"date_invalid"}}function Mn(e,t,n){switch(e){case"full_name":return ce(t,w.fullName,w.fullNameMin);case"occupation":return ce(t,w.occupation);case"birth_date":return Pt(t,n,{period:"past"});case"email":return typeof t=="string"&&t.trim().length<=w.email&&An.test(t.trim())?null:{code:"email_invalid"};case"phone":return typeof t=="string"&&Rn.test(t)?null:{code:"phone_invalid"};case"country":return typeof t=="string"&&xt.test(t)?null:{code:"choice_invalid"};case"address":return On(t)?null:{code:"address_invalid"};default:return null}}function On(e){if(typeof e!="object"||e===null||Array.isArray(e))return!1;let t=e,n=Array.isArray(t.lines)?t.lines.filter(i=>typeof i=="string"&&i.trim()!==""):[];return typeof t.country=="string"&&xt.test(t.country)&&typeof t.city=="string"&&t.city.trim()!==""&&t.city.trim().length<=w.city&&n.length>=1&&n.length<=w.addressLines&&n.every(i=>i.trim().length<=w.addressLine&&!Rt(i))&&(t.postcode===void 0||typeof t.postcode=="string"&&t.postcode.trim().length<=w.postcode)}function En(e,t,n){let i=new Set((e.choices??[]).map(r=>r.value));switch(e.type){case"short_text":return ce(t,w.shortText);case"long_text":return ce(t,w.longText);case"single_choice":return typeof t=="string"&&i.has(t)?null:{code:"choice_invalid"};case"multiple_choice":return Array.isArray(t)&&t.length>0&&new Set(t).size===t.length&&t.every(r=>i.has(r))?null:{code:"choice_invalid"};case"yes_no":return typeof t=="boolean"?null:{code:"choice_invalid"};case"date":{let r=e.options??{};return Pt(t,n,{...typeof r.min=="string"?{min:r.min}:{},...typeof r.max=="string"?{max:r.max}:{},...r.period==="past"||r.period==="future"?{period:r.period}:{}})}case"number":{if(typeof t!="number"||!Number.isFinite(t)||Math.abs(t)>=w.number)return{code:"number_invalid"};let r=e.options??{};return r.integer===!0&&!Number.isInteger(t)?{code:"number_not_integer"}:bn(t)?typeof r.min=="number"&&t<r.min?{code:"number_too_small",params:{min:r.min}}:typeof r.max=="number"&&t>r.max?{code:"number_too_large",params:{max:r.max}}:null:{code:"number_decimals"}}default:return null}}var Fo={full_name:w.fullName,occupation:w.occupation,email:w.email,short_text:w.shortText,long_text:w.longText};var Mt=Object.freeze({nni_invalid:"id_number_invalid",nni_not_found:"registry_record_not_found",nni_recheck:"id_number_recheck",document_nni_mismatch:"document_id_number_mismatch",nni_locked:"id_number_locked",nni_unbound:"id_number_unbound",missing_nni:"missing_id_number",registry_needs_nni_source:"registry_needs_id_number_source"}),In=new Map(Object.entries(Mt)),Ho=new Map(Object.entries(Mt).map(([e,t])=>[t,e]));function Ot(e){return In.get(e)??e}var Yo=["national_number","document_photo","national_eid"],vn=new Set(["phone_otp","email_otp","national_eid","document","nfc","population_registry","supplied_identity","summary_confirm","liveness","portrait","face_match","aml_screening","face_dedup","age_estimation","proof_of_address","form"]),Tn=new Set(["supplied_identity","aml_screening","face_dedup","age_estimation"]),be=["document","population_registry","national_eid"],we=["phone_otp","email_otp"],vt={identity_method:be,contact:we},Vn=["population_registry","document"],Ae="platform_unsupported",Fn=new Set(["prefilled","user_entered","prefilled_or_entered"]),Nn={phone_otp:"contact",email_otp:"contact",eid_auth:"identity",doc_ocr:"identity",nfc_chip:"identity",population_registry:"identity",liveness:"live_photo",portrait_icao:"live_photo",face_match:"live_photo",poa:"documents",form:"form"};function V(e){return e.section??Nn[e.checkType]??null}function Hn(e,t){let n=e.plan?.choice;if(n===void 0||n.locked)return;let i=n.options.find(r=>r.id!==n.selected&&r.available!==!1&&t.includes(r.service));return i===void 0?void 0:{nodeId:n.nodeId,option:i}}function Wo(e,t){let n=e.options.filter(s=>s.id!==e.current);if(t===void 0)return{switchTo:n,methods:[]};let i=s=>s.countries!==void 0&&s.countries.length>0;if(t===null)return{switchTo:n.filter(s=>!i(s)),methods:[]};let r=t.toUpperCase(),u=s=>!i(s)||s.countries.includes(r);return{switchTo:n.filter(u),methods:n.filter(s=>i(s)&&u(s))}}function $o(e,t,n){let i=e.names?.[t.toUpperCase()],r=i?.[n]??i?.en;if(r!==void 0&&r!=="")return r;let u=e.nationalEid?.providerName;return u!==void 0&&u!==""?u:void 0}function Qo(e){return e===void 0?[]:[...new Set(e.options.filter(t=>t.id!==e.current).flatMap(t=>t.countries??[]).map(t=>t.toUpperCase()))]}function Re(e){let t=e.plan,n=t?.choice;if(t===void 0||n===void 0||n.locked||t.current===null||t.current===n.nodeId||M(e))return null;let i=vt[n.kind]??[...be,...we],r=n.options.flatMap(c=>{if(c.available===!1||!i.includes(c.service))return[];let f=c.nationalEid!=null?{id:c.id,service:c.service,nationalEid:c.nationalEid}:{id:c.id,service:c.service},S=c.countries??(c.nationalEid!=null?[c.nationalEid.country]:void 0);return S!==void 0&&S.length>0&&(f.countries=S),c.names!=null&&Object.keys(c.names).length>0&&(f.names=c.names),[f]}),u=t.steps.find(c=>c.id===t.current)?.service,s=n.selected??r.find(c=>c.service===u)?.id??null;return r.some(c=>c.id!==s)?{nodeId:n.nodeId,kind:n.kind,current:s,options:r}:null}function Tt(e){return e==null?[]:e.options.filter(t=>t.id!==e.current)}function Ln(e){let t=e.simulation;if(typeof t!="object"||t===null)return;let{otpCode:n,skipCapture:i}=t;if(typeof n!="string"||n===""||typeof i!="boolean")return;let r=ut(e);return r!==void 0?{otpCode:n,skipCapture:i,reason:r}:{otpCode:n,skipCapture:i}}function Dn(e){let t=e.levelTarget?.max;return typeof t=="number"&&t<=1?"contact":e.purpose??"identity"}function Un(e){let t=(e.plan?.sections??[]).map(s=>({id:s.id,state:s.state})),n={sessionId:D(e.sessionId),orgName:e.orgName,sandbox:e.sandbox===!0,returning:e.returning===!0,consentRecorded:e.consentRecorded,expiresAt:e.expiresAt,sections:t.map(s=>s.id),progress:t,purpose:e.purpose??"identity",levelName:Dn(e)};e.branding!==void 0&&(n.branding=e.branding),e.cameraUnavailableHandled===!0&&(n.cameraUnavailableHandled=!0);let i=Ln(e);i!==void 0&&(n.simulation=i);let r=e.testerGate;r?.offered===!0&&typeof r.attemptsLeft=="number"&&r.attemptsLeft>0&&(n.testerGate={attemptsLeft:r.attemptsLeft});let u=Re(e);return u!==null&&(n.switchable=u),n}function Bn(e){let t={attemptsRemaining:ie(e),attemptsExhausted:e.attempts.used>=e.attempts.max};return e.reason!==void 0&&(t.reason=e.reason),e.retakeHint!==void 0&&(t.retakeHint=e.retakeHint),t}var Vt={phone_otp:"phone",email_otp:"email"};function qn(e,t){let n=Hn(e,[t==="phone_otp"?"email_otp":"phone_otp"]);return n===void 0?void 0:Vt[n.option.service]}function Gn(e,t,n,i){let r=t.checkType==="email_otp",u=(r?t.emailOtp:t.otp)??{},s=r?t.emailOtp?.emailSource:t.otp?.numberSource,c=s!==void 0&&Fn.has(s)?s:r?"prefilled_or_entered":"user_entered",f=typeof u.sentToMasked=="string"&&u.sentToMasked.length>0,S=u.prefilled===!0,_=qn(e,r?"email_otp":"phone_otp"),A={key:t.checkType,context:n,section:V(t),phase:f?"verify":"send",canSwitch:_!==void 0,...i},h=r?{kind:"email_otp",...A,emailSource:c,needsEmail:c!=="prefilled"&&!S}:{kind:"phone_otp",...A,numberSource:c,needsPhone:c!=="prefilled"&&!S,channels:(t.otp?.channels??[]).filter(p=>p==="whatsapp"||p==="sms")};if(_!==void 0&&(h.switchChannel=_),S&&(h.prefilled=!0),f&&(h.sentToMasked=u.sentToMasked),!r&&t.otp?.channel!==void 0&&(h.channel=t.otp.channel),!r&&Array.isArray(t.phoneCountries)&&(h.phoneCountries=t.phoneCountries.filter(p=>typeof p=="string"&&/^[A-Z]{2}$/.test(p))),!r&&Array.isArray(t.phoneRules)){let p=h.phoneCountries??[];h.phoneRules=t.phoneRules.flatMap(O=>{let k=Yn(O);return k!==void 0&&p.includes(k.code)?[k]:[]})}return!r&&t.phoneInternational===!0&&(h.phoneInternational=!0),u.expiresAt!==void 0&&(h.codeExpiresAt=u.expiresAt),u.resendAvailableAt!==void 0&&(h.resendAvailableAt=u.resendAvailableAt),h}var Kn=/^[\d[\]\-|()?:^]{1,64}$/;function jn(e){try{return typeof e=="string"&&Kn.test(e)&&new RegExp(e)!==null}catch{return!1}}var Et=e=>typeof e=="number"&&Number.isInteger(e)&&e>=1&&e<=15;function Yn(e){let{code:t,dial:n,trunk:i,lengths:r,formats:u}=e??{};if(typeof t!="string"||typeof n!="string"||!/^\d{1,3}$/.test(n)||i!==void 0&&(typeof i!="string"||!/^\d{1,3}$/.test(i))||!Array.isArray(r)||r.length===0||!r.every(Et))return;let s={code:t,dial:n,lengths:[...r].sort((c,f)=>c-f)};if(i!==void 0&&(s.trunk=i),u!==void 0){if(!(Array.isArray(u)&&u.length<=8&&u.every(f=>jn(f?.leading)&&Array.isArray(f.groups)&&f.groups.every(Et)&&r.includes(f.groups.reduce((S,_)=>S+_,0)))))return;s.formats=u.map(f=>({leading:f.leading,groups:[...f.groups]}))}return s}function Wn(e,t,n,i){let r=ue(e)===!0?"bound":ee(t)===!0?"document":"typed",u=r==="typed"&&t.state==="input_required"&&t.reason!==void 0&&Ot(t.reason)==="id_number_recheck",s=Tt(Re(e)),c=!i.attemptsExhausted&&s.length===1&&s[0]?.service==="document";return{kind:"registry",key:"registry",context:n,section:V(t),state:t.state==="input_required"?"input_required":"pending",source:r,recheck:u,canUseDocument:c,...i}}function $n(e,t,n,i,r){let u=[...t.acceptedSides??[]],s={kind:"document",key:"document",context:n,section:V(t),side:u.includes("recto")?"verso":"recto",acceptedSides:u,documents:bt(e),photo:Pe(xe(e.documents),r),...i};return e.detectedCountry!==void 0&&(s.detectedCountry=e.detectedCountry),Jn(e)&&(s.ageStepUp=!0),s}function xe(e,t=!0){let n=e?.source==="upload"||e?.source==="choice"?e.source:"camera",i=e?.sourcePick==="camera"||e?.sourcePick==="upload"?e.sourcePick:null;return{source:n,pick:i,uploadOffered:t&&e?.uploadOffered===!0}}function Pe(e,t){return t?{...e,cameraOnPhone:!0}:e}var Qn=10*1024*1024;function Zn(e,t,n,i,r){let u=e.proofOfAddress,s=u?.pdf?.maxBytes,c=u?.phase==="holder_letter"?"holder_letter":"document";return{kind:"proof_of_address",key:"proof_of_address",context:n,section:V(t),phase:c,rule:u?.rule??{country:null,countryFrom:"global",source:"preset_global",kinds:[]},nameMatch:u?.nameMatch??"exact_person",photo:Pe(xe(u),r),maxPages:3,pdf:{maxBytes:typeof s=="number"&&s>0?s:Qn,maxPages:3},licenceAddressAccepted:c==="document"&&u?.licenceAddressAccepted===!0,...i}}function Jn(e){let t=J(e).find(i=>i.checkType==="age_estimation"),n=t?.reason;return t?.state==="failed"&&(n==="age_uncertain"||n==="age_unavailable")}function Xn(e){let t=T(e,"liveness");return t?.state==="passed"||t?.state==="review"}function It(e,t,n,i,r,u=!1){let s=t.icao?.report,c=e.portrait,f=r==="capture"?c?.pendingFix??null:null;f!==null&&(r="review");let S=Ft(e);return{kind:"portrait",key:`portrait:${r}`,context:n,section:V(t),phase:r,report:Array.isArray(s)?s:null,review:t.state==="review",tuning:e.capture?.icao??null,tuningVersion:e.capture?.tuningVersion??null,icao:ae(e),retakeOnly:r==="capture"&&t.state==="input_required"&&S===void 0&&e.capture?.livePhoto?.oneCapture===!0&&Xn(e),photo:Pe(xe(c,r==="capture"),u&&r==="capture"),pendingFix:f,...S!==void 0?{captureMode:S}:{},...c?.reuse?.pending===!0?{reuse:!0}:{},...i}}function Ft(e){let t=e.portrait?.captureMode;return t==="self"||t==="assisted"||t==="choice"?t:void 0}var Ce={minLongSidePx:1280,jpegQuality:.95};function zn(e,t){let n=e.capture?.livePhoto;if(n?.oneCapture!==!0)return null;let i=T(e,"portrait_icao"),r=n.still??Ce;return{icao:t==="liveness"&&ae(e)!==null&&Ft(e)===void 0&&i!==void 0&&i.state==="pending"&&i.reason===void 0,still:{minLongSidePx:r.minLongSidePx??Ce.minLongSidePx,jpegQuality:r.jpegQuality??Ce.jpegQuality}}}function eo(e,t,n,i){let r=t.eid,u=V(t);if(r===void 0||r.challenge!=="app_code")return{kind:"unsupported",key:"unsupported:eid_auth",context:n,section:u,checkType:"eid_auth",reason:"update_required"};let s=Tt(Re(e)),c=s.length===1&&Vn.includes(s[0]?.service??"")?s[0]:void 0,f=c===void 0?void 0:Z[c.service],S=f!==void 0,_={kind:"eid",key:"eid",context:n,section:u,provider:r.provider,providerName:r.providerName,country:r.country,challenge:"app_code",phase:r.awaiting==="code"?"code":"identifier",identifierBound:r.identifierBound===!0,canUseCamera:S,afterPass:r.afterPass==="continue"?"continue":"end",...i};return S&&(_.cameraMethod=f),r.expiresAt!==void 0&&(_.codeExpiresAt=r.expiresAt),r.resendAvailableAt!==void 0&&(_.resendAvailableAt=r.resendAvailableAt),r.resendsRemaining!==void 0&&(_.resendsRemaining=r.resendsRemaining),r.codeAttemptsRemaining!==void 0&&(_.codeAttemptsRemaining=r.codeAttemptsRemaining),_}function to(e,t){if(t.checkType!=="face_match"||t.reason!==void 0)return null;let n=T(e,"portrait_icao");return n!==void 0&&(n.state==="passed"||n.state==="review")?n:null}var no={rejected:"rejected",inconclusive:"inconclusive",unavailable:"unavailable",abandoned:"expired",not_opened:"expired",cancelled:"expired",superseded:"expired",policy:"policy"};function oo(e){return e.reasonCode===Ae?"platform_unsupported":e.status==="review_pending"?"review":e.status==="verified"?"verified":e.reasonCode==="device_cooldown"?"cooldown":e.reasonCode==="starter_credit_claimed"?"policy":(e.status==="not_verified"&&e.reason!==void 0?no[e.reason]:void 0)??"rejected"}function ro(e,t){let n=oo(e),i=n==="platform_unsupported"?{sessionId:D(e.sessionId),status:"unavailable",reasonCode:Ae}:X(e,{autoRetry:!1}),r={kind:"result",key:"result",context:t,section:null,display:n,result:i};return e.status==="not_verified"&&e.reason!==void 0&&(r.reason=e.reason),e.reasonCode!==void 0&&(r.reasonCode=e.reasonCode),e.status==="not_verified"&&e.step!==void 0&&(r.step=e.step),e.retryAfter!==void 0&&(r.retryAfter=e.retryAfter),r}function io(e,t,n){let i=e.identitySummary;if(i==null)return null;let r={kind:"identity_summary",key:"identity_summary",context:t,section:n??"identity",summaryKind:i.kind==="partial"?"partial":i.kind??"full",source:i.source,portraitAvailable:i.portrait?.available===!0,retakeAvailable:i.retakeAvailable===!0};for(let s of so){let c=i[s];typeof c=="string"&&c!==""&&(r[s]=c)}let u=St(i);return u!==void 0&&(r.idNumberMasked=u,r.nniMasked=u),r}var so=["fullName","birthDate","birthYear","nationality","documentType","documentNumberMasked","expiryDate","retakeTarget"];function B(e,t,n,i){return{kind:"unsupported",key:`unsupported:${n}`,context:e,section:t,checkType:n,reason:i}}function ao(e){return e.kind==="contact"?"contact":(e.kind==="identity_method","identity")}function uo(e,t){let n=vt[e.kind]??[...be,...we],i=ao(e),r=e.options.flatMap(s=>{if(s.available===!1||!n.includes(s.service))return[];let c={id:s.id,service:s.service};s.nationalEid!=null&&(c.nationalEid=s.nationalEid);let f=(s.channels??[]).filter(S=>S==="whatsapp"||S==="sms");return s.service==="phone_otp"&&f.length>0&&(c.channels=f),[c]});if(r.length===0){let s=e.options.length>0&&e.options.every(c=>c.service==="nfc");return B(t,i,"choice",s?"platform_unsupported":"update_required")}let u={nodeId:e.nodeId,kind:e.kind,selected:e.selected,options:r};if(e.kind==="identity_method"){let s={kind:"method",key:"method",context:t,section:i,options:r.map(f=>Z[f.service]),choice:u},c=r.find(f=>f.nationalEid!==void 0)?.nationalEid;return c!==void 0&&(s.nationalEid=c),s}return e.kind==="contact"?{kind:"contact_choice",key:"contact_choice",context:t,section:i,options:r.map(s=>Vt[s.service]),selected:null,locked:!1,choice:u}:{kind:"choice",key:`choice:${e.nodeId}`,context:t,section:i,choice:u}}function co(e,t,n,i){let r=e.nativeApp,u=typeof r=="object"&&r!==null?r:{},s={sekyroApp:u.sekyroApp===!0};return typeof u.link=="string"&&u.link!==""&&(s.link=u.link),s.sekyroApp&&typeof u.sekyroAppLink=="string"&&u.sekyroAppLink.startsWith("sekyro://")&&(s.sekyroAppLink=u.sekyroAppLink),{kind:"native_app_required",key:`native_app_required:${i}`,context:t,section:n,checkType:i,nativeApp:s}}function Zo(e,t={}){let n=Un(e);if(M(e)||e.reasonCode===Ae)return ro(e,n);let i=e.plan;if(i===void 0||!Array.isArray(i.sections))return B(n,null,"plan","update_required");let r=st(e);if(r!==null)return uo(r,n);let u=i.current===null?void 0:i.steps.find(h=>h.id===i.current),s=h=>{let p={kind:"processing",key:"processing",context:n,section:h!==void 0?V(h):i.sections.find(O=>O.state==="current")?.id??null,stalled:!1};return typeof h?.service=="string"&&h.service!==""&&(p.service=h.service),p};if(i.current===null)return s(i.steps.find(h=>h.state==="processing"));if(u===void 0)return B(n,null,"step","update_required");if(!vn.has(u.service))return u.interaction==="server"?s(u):B(n,V(u),u.service,"update_required");if(Tn.has(u.service)||!at(u))return s(u);let c=u,f=Bn(c),S=c.checkType,_=V(c);if(c.requiresNativeApp===!0)return co(e,n,_,S);let A=t.isMobile===!1?z(e,c):null;if(A==="phone")return{kind:"mobile_required",key:"mobile_required",context:n,section:_,checkType:S};switch(S){case"phone_otp":case"email_otp":return Gn(e,c,n,f);case"population_registry":return Wn(e,c,n,f);case"eid_auth":return eo(e,c,n,f);case"doc_ocr":return $n(e,c,n,f,A==="upload_or_phone");case"identity_confirm":return io(e,n,_)??s(c);case"portrait_icao":return It(e,c,n,f,"capture",A==="upload_or_phone");case"liveness":case"face_match":{let h=to(e,c);if(h!==null)return It(e,h,n,f,"match");let p=c.requiresMobile===!0,O=ae(e);return{kind:"liveness",key:"biometric",context:n,section:_,mode:S==="face_match"?"selfie":"liveness",requiresMobile:p,instructions:O===null?"standard":"icao",icao:O,livePhoto:zn(e,S),...f}}case"poa":return Zn(e,c,n,f,A==="upload_or_phone");case"form":{let h=At(c.form);return h===null?B(n,_,S,"update_required"):{kind:"form",key:"form",context:n,section:_,form:h,dir:wt(h.locale),...f}}case"nfc_chip":return B(n,_,S,"platform_unsupported");default:return B(n,_,S,"update_required")}}export{Xt as a,zt as b,an as c,un as d,dn as e,Po as f,ln as g,Ct as h,pn as i,mn as j,Io as k,bt as l,vo as m,w as n,wt as o,Cn as p,bn as q,Rt as r,Pn as s,Vo as t,Yo as u,Ae as v,V as w,Wo as x,$o as y,Qo as z,Re as A,Tt as B,to as C,Zo as D};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{C as Me,F as ve,G as ie,H as Te,I as N,J as Y,d as q,e as Ce,f as Pe,g as Ae,i as Re,j as re,l as $,m as oe,o as we,p as xe,q as Ee,u as Ie}from"./chunk-UKYJYZZS.js";import{c as _e,d as be,e as ke}from"./chunk-FPXL63KZ.js";import{c as j,h as J,i as Oe}from"./chunk-PNOGF72U.js";var Ne=["AD","AE","AF","AG","AI","AL","AM","AO","AQ","AR","AS","AT","AU","AW","AX","AZ","BA","BB","BD","BE","BF","BG","BH","BI","BJ","BL","BM","BN","BO","BQ","BR","BS","BT","BV","BW","BY","BZ","CA","CC","CD","CF","CG","CH","CI","CK","CL","CM","CN","CO","CR","CU","CV","CW","CX","CY","CZ","DE","DJ","DK","DM","DO","DZ","EC","EE","EG","EH","ER","ES","ET","FI","FJ","FK","FM","FO","FR","GA","GB","GD","GE","GF","GG","GH","GI","GL","GM","GN","GP","GQ","GR","GS","GT","GU","GW","GY","HK","HM","HN","HR","HT","HU","ID","IE","IL","IM","IN","IO","IQ","IR","IS","IT","JE","JM","JO","JP","KE","KG","KH","KI","KM","KN","KP","KR","KW","KY","KZ","LA","LB","LC","LI","LK","LR","LS","LT","LU","LV","LY","MA","MC","MD","ME","MF","MG","MH","MK","ML","MM","MN","MO","MP","MQ","MR","MS","MT","MU","MV","MW","MX","MY","MZ","NA","NC","NE","NF","NG","NI","NL","NO","NP","NR","NU","NZ","OM","PA","PE","PF","PG","PH","PK","PL","PM","PN","PR","PS","PT","PW","PY","QA","RE","RO","RS","RU","RW","SA","SB","SC","SD","SE","SG","SH","SI","SJ","SK","SL","SM","SN","SO","SR","SS","ST","SV","SX","SY","SZ","TC","TD","TF","TG","TH","TJ","TK","TL","TM","TN","TO","TR","TT","TV","TW","TZ","UA","UG","UM","US","UY","UZ","VA","VC","VE","VG","VI","VN","VU","WF","WS","XK","YE","YT","ZA","ZM","ZW"];var ut=["carte_identite","passport","residence_permit","drivers_license"],ct=["carte_identite","passport","residence_permit"];function dt(e,t){let n=e.byIssuer?.[t]??e.default;return ut.filter(i=>n==="*"?ct.includes(i):n.includes(i))}function Ln(e,t=Ne){return[...new Set([...t,...Object.keys(e.byIssuer??{})])].filter(i=>dt(e,i).length>0).sort()}function Le(e){if(e.acceptedDocuments)return e.acceptedDocuments;let t=e.acceptedDocumentTypes?.length?[...e.acceptedDocumentTypes]:["carte_identite","passport"];return{default:[],byIssuer:{MR:t}}}var lt=640,pt=new Set(["network_error","timeout","upload_failed","unknown_error","rate_limit_exceeded"]),Ve=6,Fe=1500,He={sharpness:1,exposure:1,meanLuma:128},De=null;function ft(e,t){try{De??(De=document.createElement("canvas"));let n=De,i=96/Math.max(1,t.width);n.width=Math.max(1,Math.round(t.width*i)),n.height=Math.max(1,Math.round(t.height*i));let r=n.getContext("2d");if(r===null)return He;r.drawImage(e,t.x,t.y,t.width,t.height,0,0,n.width,n.height);let a=r.getImageData(0,0,n.width,n.height);return{sharpness:be(a),exposure:ke(a),meanLuma:_e(a)}}catch{return He}}async function mt(e,t){let n=e.source;return"convertToBlob"in n?n.convertToBlob({type:"image/jpeg",quality:t}):new Promise((i,r)=>{n.toBlob(a=>a===null?r(new Error("encode failed")):i(a),"image/jpeg",t)})}function Gn(e,t={}){let n=t.now??(()=>performance.now()),i=t.setTimer??((m,k)=>setTimeout(m,k)),r=t.clearTimer??(m=>clearTimeout(m)),a=t.encode??mt,d=t.quality??ft,c=e.tuningVersion??null,l=new Set,h=!1,S=e.video??null,w=null,g=t.grabFrame??null,y=null,O=1e3/Ve,E=null,I=null,v=!1,V=!1,D=Number.NEGATIVE_INFINITY,x=null,U=0,F=null,K=null,te=Promise.all([import("./icao-gate-T3BTOKFJ.js"),import("./icao-tuning-4ETMF53W.js"),import("./create-portrait-capture-5VGYZUOK.js"),import("./landmarker-KB7LVXAU.js"),import("./background-monitor-A7FKJOAG.js")]).then(async([m,k,A,T,H])=>{let R=k.resolveIcaoTuning(e.tuning,e.tuningVersion??void 0);R.background.required&&(I=H.createBackgroundMonitor({tuning:R.backgroundCheck,assetBaseUrl:e.assetBaseUrl??"/models-v3",...t.createSegmenter!==void 0?{createSegmenter:t.createSegmenter}:{},now:n})),w=m.createIcaoGate(R,{policy:e.policy??"reject"}),g??(g=A.defaultGrabber()),y=A.observe,O=1e3/Math.min(Ve,R.cadenceHz);let M=(t.createLandmarker??T.createFaceLandmarker)(e.assetBaseUrl??"/models-v3"),o=await new Promise((s,u)=>{let p=setTimeout(()=>{u(new Error("landmarker init timeout")),M.then(f=>f.close(),()=>{})},T.LANDMARKER_INIT_TIMEOUT_MS);M.then(f=>{clearTimeout(p),s(f)},f=>{clearTimeout(p),u(f)})});h?o.close():E=o}).catch(()=>{v=!0}),Z=m=>{for(let k of l)k({holding:V||v,update:m})},G=()=>{if(x=null,!(h||E===null||w===null||g===null||y===null||S===null)){if(n()-D>Fe){Z(null);return}try{let m=g(S,lt);if(m!==null){let k=Math.max(n(),U+1);U=k;let A=E.detect(m.source,k),T=S.videoWidth||m.width,H=S.videoHeight||m.height,R=y(A,m,T,H);R.geometry!==null&&I!==null&&(R.backgroundCheck=I.measure(m,R.geometry.box,T,H));let M=w.push(R,n());V=M.ready,Z(M)}}catch{}x=i(G,O)}},ne=()=>{let m=n()-D>Fe;D=n(),m&&(w?.reset(),V=!1,F=null,K=null),x===null&&E!==null&&!h&&(x=i(G,0))},W=()=>{let m=g===null||S===null?null:g(S,null);if(m===null||w===null||Math.max(m.width,m.height)<e.still.minLongSidePx)return Promise.resolve(null);let k=w.summary();return a(m,e.still.jpegQuality).then(A=>({image:A,width:m.width,height:m.height,gate:k}),()=>null)},Q=null;return{engineOptions:{measureQuality:(m,k)=>{S=m,ne();let A=d(m,k);return V||v?A:{...A,sharpness:0}},telemetry:m=>{if(m.type!=="fired"||h)return;F=W();let k=Q;k!==null&&F.then(A=>A===null?void 0:k(A).catch(()=>{})),V=!1,x!==null&&r(x),x=null,D=Number.NEGATIVE_INFINITY}},decorate:m=>{let k=new WeakMap,A=new Map,T=o=>{let s=k.get(o);return s===void 0&&(s=(async()=>{let u=await Ie(m,"image","image/jpeg",o.image.size,{engine:"portrait"});return await m.uploadToSpaces(u.uploadUrl,o.image,"image/jpeg"),(await m.completeMedia(u.key)).key})(),s.catch(()=>k.delete(o)),k.set(o,s)),s};Q=T;let H=async o=>{let s;try{s=await T(o)}catch(u){let p=u?.code;if(typeof p=="string"&&pt.has(p))throw u;return null}return{media:{portrait:s},gate:Oe(o.gate),...c!==null?{tuningVersion:c}:{}}},R=m.submitCheck.bind(m),M=(async(o,s,u)=>{if(o!=="liveness")return R(o,s,u);let p=u?.idempotencyKey,f=p===void 0?void 0:A.get(p);if(f===void 0){let b=F;f=b===null?Promise.resolve(null):b.then(ye=>ye===null?null:H(ye)),p!==void 0&&(A.set(p,f),f.catch(()=>A.delete(p)))}let _=await f;if(_===null)return R("liveness",s,u);let P=await R("liveness",{...s,portraitIcao:_},u);return K=_,P});return new Proxy(m,{get(o,s){if(s==="submitCheck")return M;let u=Reflect.get(o,s);return typeof u=="function"?u.bind(o):u}})},onGate:m=>(l.add(m),()=>l.delete(m)),lastPortraitInput:()=>K,destroy:()=>{h=!0,F=null,K=null,x!==null&&r(x),x=null,l.clear(),te.then(()=>{E?.close(),E=null,I?.close(),I=null})}}}function Ge(e){return e.idNumberBound??e.nniBound}function Be(e){return e===void 0?void 0:e.idNumberFromDocument??e.nniFromDocument}function Ue(e){let t=e.idNumberMasked??e.nniMasked;return typeof t=="string"&&t!==""?t:void 0}var Ke=Object.freeze({nni_invalid:"id_number_invalid",nni_not_found:"registry_record_not_found",nni_recheck:"id_number_recheck",document_nni_mismatch:"document_id_number_mismatch",nni_locked:"id_number_locked",nni_unbound:"id_number_unbound",missing_nni:"missing_id_number",registry_needs_nni_source:"registry_needs_id_number_source"}),ht=new Map(Object.entries(Ke)),Kn=new Map(Object.entries(Ke).map(([e,t])=>[t,e]));function je(e){return ht.get(e)??e}var C={fullNameMin:2,fullName:200,email:254,occupation:120,shortText:120,longText:1e3,addressLine:120,addressLines:4,city:80,postcode:16,number:1e12,dateMin:"1900-01-01",dateMax:"2100-12-31"},gt=new Set(["full_name","birth_date","email","phone","address","country","occupation"]),St=new Set(["short_text","long_text","single_choice","multiple_choice","yes_no","date","number"]),yt=new Set(["ar","fa","he","ur"]);function qe(e){return yt.has(e.split("-")[0]?.toLowerCase()??"")?"rtl":"ltr"}function Ye(e){if(typeof e!="object"||e===null)return null;let t=e;if(typeof t.locale!="string"||!Array.isArray(t.questions)||t.questions.length===0)return null;let n=t.consents??[];if(!Array.isArray(n))return null;for(let r of t.questions)if(!_t(r))return null;for(let r of n)if(!bt(r))return null;let i={locale:t.locale,questions:t.questions,consents:n};return typeof t.title=="string"&&t.title.trim()!==""&&(i.title=t.title),typeof t.intro=="string"&&t.intro.trim()!==""&&(i.intro=t.intro),typeof t.prefill=="object"&&t.prefill!==null&&!Array.isArray(t.prefill)&&(i.prefill=t.prefill),i}function _t(e){if(typeof e!="object"||e===null)return!1;let t=e;return typeof t.id!="string"||typeof t.required!="boolean"?!1:t.kind==="field"?typeof t.field=="string"&>.has(t.field):t.kind!=="custom"||typeof t.type!="string"||!St.has(t.type)||typeof t.label!="string"?!1:t.type==="single_choice"||t.type==="multiple_choice"?Array.isArray(t.choices)&&t.choices.length>=2&&t.choices.every(n=>typeof n=="object"&&n!==null&&typeof n.value=="string"&&typeof n.label=="string"):!0}function bt(e){if(typeof e!="object"||e===null)return!1;let t=e;if(typeof t.id!="string"||typeof t.required!="boolean"||typeof t.text!="string")return!1;if(t.link===void 0)return!0;let n=t.link;return typeof n=="object"&&n!==null&&typeof n.url=="string"&&/^https:\/\//.test(n.url)&&typeof n.label=="string"}var kt=/^(\d{4})-(\d{2})-(\d{2})$/;function Ct(e){if(typeof e!="string")return!1;let t=kt.exec(e);return t===null?!1:new Date(Date.UTC(Number(t[1]),Number(t[2])-1,Number(t[3]))).toISOString().slice(0,10)===e&&e>=C.dateMin&&e<=C.dateMax}function Pt(e){return typeof e=="number"&&Number.isFinite(e)&&Math.abs(e)<C.number&&Math.round(e*100)/100===e}function Ze(e){for(let t of e.matchAll(/\d[\d -]{11,}\d/g)){let n=t[0].replace(/[ -]/g,"");if(n.length>=13&&n.length<=19&&At(n))return!0}return!1}function At(e){let t=0;for(let n=0;n<e.length;n++){let i=Number(e[e.length-1-n]);n%2===1&&(i*=2,i>9&&(i-=9)),t+=i}return t%10===0}var Rt=/^[^\s@]+@[^\s@.]+(\.[^\s@.]+)+$/,wt=/^\+[1-9]\d{6,14}$/,We=/^[A-Z]{2}$/,xt=e=>e===void 0||typeof e=="string"&&e.trim()===""||Array.isArray(e)&&e.length===0;function Qe(e=Date.now()){return new Date(e).toISOString().slice(0,10)}function X(e,t,n=Qe()){let i=[];for(let r of e.questions){let a=t.answers[r.id];if(xt(a)){r.required&&i.push({id:r.id,code:"required"});continue}let d=r.kind==="field"?Et(r.field,a,n):Mt(r,a,n);d!==null&&i.push({id:r.id,...d})}for(let r of e.consents)r.required&&t.consents[r.id]!==!0&&i.push({id:r.id,code:"consent_required"});return i}function z(e,t,n=1){if(typeof e!="string")return{code:"required"};let i=e.trim();return[...i].length>t?{code:"too_long",params:{max:t}}:[...i].length<n?{code:"too_short",params:{min:n}}:Ze(i)?{code:"card_number"}:null}function $e(e,t,n={}){return Ct(e)?n.period==="past"&&e>=t?{code:"date_not_past"}:n.period==="future"&&e<=t?{code:"date_not_future"}:n.min!==void 0&&e<n.min?{code:"date_too_early",params:{date:n.min}}:n.max!==void 0&&e>n.max?{code:"date_too_late",params:{date:n.max}}:null:{code:"date_invalid"}}function Et(e,t,n){switch(e){case"full_name":return z(t,C.fullName,C.fullNameMin);case"occupation":return z(t,C.occupation);case"birth_date":return $e(t,n,{period:"past"});case"email":return typeof t=="string"&&t.trim().length<=C.email&&Rt.test(t.trim())?null:{code:"email_invalid"};case"phone":return typeof t=="string"&&wt.test(t)?null:{code:"phone_invalid"};case"country":return typeof t=="string"&&We.test(t)?null:{code:"choice_invalid"};case"address":return It(t)?null:{code:"address_invalid"};default:return null}}function It(e){if(typeof e!="object"||e===null||Array.isArray(e))return!1;let t=e,n=Array.isArray(t.lines)?t.lines.filter(i=>typeof i=="string"&&i.trim()!==""):[];return typeof t.country=="string"&&We.test(t.country)&&typeof t.city=="string"&&t.city.trim()!==""&&t.city.trim().length<=C.city&&n.length>=1&&n.length<=C.addressLines&&n.every(i=>i.trim().length<=C.addressLine&&!Ze(i))&&(t.postcode===void 0||typeof t.postcode=="string"&&t.postcode.trim().length<=C.postcode)}function Mt(e,t,n){let i=new Set((e.choices??[]).map(r=>r.value));switch(e.type){case"short_text":return z(t,C.shortText);case"long_text":return z(t,C.longText);case"single_choice":return typeof t=="string"&&i.has(t)?null:{code:"choice_invalid"};case"multiple_choice":return Array.isArray(t)&&t.length>0&&new Set(t).size===t.length&&t.every(r=>i.has(r))?null:{code:"choice_invalid"};case"yes_no":return typeof t=="boolean"?null:{code:"choice_invalid"};case"date":{let r=e.options??{};return $e(t,n,{...typeof r.min=="string"?{min:r.min}:{},...typeof r.max=="string"?{max:r.max}:{},...r.period==="past"||r.period==="future"?{period:r.period}:{}})}case"number":{if(typeof t!="number"||!Number.isFinite(t)||Math.abs(t)>=C.number)return{code:"number_invalid"};let r=e.options??{};return r.integer===!0&&!Number.isInteger(t)?{code:"number_not_integer"}:Pt(t)?typeof r.min=="number"&&t<r.min?{code:"number_too_small",params:{min:r.min}}:typeof r.max=="number"&&t>r.max?{code:"number_too_large",params:{max:r.max}}:null:{code:"number_decimals"}}default:return null}}function Je(e,t,n,i=Qe()){let r=e?.errors;return Array.isArray(r)?r.flatMap(a=>{if(typeof a!="object"||a===null)return[];let{id:d,code:c}=a;return typeof d!="string"||typeof c!="string"?[]:[vt(d,c,t,n)]}):X(t,n,i)}var Ot={full_name:C.fullName,occupation:C.occupation,email:C.email,short_text:C.shortText,long_text:C.longText};function vt(e,t,n,i){let r=n.questions.find(l=>l.id===e),a=r===void 0?void 0:r.kind==="field"?r.field:r.type,d=i.answers[e],c=r!==void 0&&r.kind==="custom"?r.options??{}:{};switch(t){case"required":case"card_number":return{id:e,code:t};case"consent_required":return{id:e,code:"consent_required"};case"too_short":return{id:e,code:t,params:{min:a==="full_name"?C.fullNameMin:1}};case"too_long":{let l=a===void 0?void 0:Ot[a];return l===void 0?{id:e,code:t}:{id:e,code:t,params:{max:l}}}case"not_a_choice":return{id:e,code:"choice_invalid"};case"not_in_past":return{id:e,code:"date_not_past"};case"not_in_future":return{id:e,code:"date_not_future"};case"not_an_integer":return{id:e,code:"number_not_integer"};case"out_of_range":return Tt(e,a,d,c);case"invalid":return r===void 0?n.consents.some(l=>l.id===e)?{id:e,code:"consent_required"}:{id:e,code:t}:{id:e,code:Nt(a,d)};default:return{id:e,code:t}}}function Tt(e,t,n,i){if(t==="date"){let c=typeof i.min=="string"?i.min:void 0,l=typeof i.max=="string"?i.max:void 0;return l!==void 0&&(c===void 0||typeof n=="string"&&n>l)?{id:e,code:"date_too_late",params:{date:l}}:c!==void 0?{id:e,code:"date_too_early",params:{date:c}}:{id:e,code:"date_invalid"}}let r=typeof i.min=="number"?i.min:void 0,a=typeof i.max=="number"?i.max:void 0;return a!==void 0&&(r===void 0||typeof n=="number"&&n>a)?{id:e,code:"number_too_large",params:{max:a}}:r!==void 0?{id:e,code:"number_too_small",params:{min:r}}:{id:e,code:"number_invalid"}}function Nt(e,t){switch(e){case"email":return"email_invalid";case"phone":return"phone_invalid";case"birth_date":case"date":return"date_invalid";case"number":return typeof t=="number"&&Number.isFinite(t)&&Math.abs(t)<C.number?"number_decimals":"number_invalid";case"address":return"address_invalid";case"full_name":case"occupation":case"short_text":case"long_text":return"required";default:return"choice_invalid"}}var Lt=new Set(["phone_otp","email_otp","national_eid","document","nfc","population_registry","supplied_identity","summary_confirm","liveness","portrait","face_match","aml_screening","face_dedup","age_estimation","proof_of_address","form"]),Vt=new Set(["supplied_identity","aml_screening","face_dedup","age_estimation"]),ae=["document","population_registry","national_eid"],ue=["phone_otp","email_otp"],et={identity_method:ae,contact:ue},Ft=["population_registry","document"],ce="platform_unsupported",Ht=new Set(["prefilled","user_entered","prefilled_or_entered"]),Dt={phone_otp:"contact",email_otp:"contact",eid_auth:"identity",doc_ocr:"identity",nfc_chip:"identity",population_registry:"identity",liveness:"live_photo",portrait_icao:"live_photo",face_match:"live_photo",poa:"documents",form:"form"};function L(e){return e.section??Dt[e.checkType]??null}function de(e,t){let n=e.plan?.choice;if(n===void 0||n.locked)return;let i=n.options.find(r=>r.id!==n.selected&&r.available!==!1&&t.includes(r.service));return i===void 0?void 0:{nodeId:n.nodeId,option:i}}function le(e){let t=e.plan,n=t?.choice;if(t===void 0||n===void 0||n.locked||t.current===null||t.current===n.nodeId||re(e))return null;let i=et[n.kind]??[...ae,...ue],r=n.options.flatMap(c=>{if(c.available===!1||!i.includes(c.service))return[];let l=c.nationalEid!=null?{id:c.id,service:c.service,nationalEid:c.nationalEid}:{id:c.id,service:c.service},h=c.countries??(c.nationalEid!=null?[c.nationalEid.country]:void 0);return h!==void 0&&h.length>0&&(l.countries=h),c.names!=null&&Object.keys(c.names).length>0&&(l.names=c.names),[l]}),a=t.steps.find(c=>c.id===t.current)?.service,d=n.selected??r.find(c=>c.service===a)?.id??null;return r.some(c=>c.id!==d)?{nodeId:n.nodeId,kind:n.kind,current:d,options:r}:null}function tt(e){return e==null?[]:e.options.filter(t=>t.id!==e.current)}function Gt(e){let t=e.simulation;if(typeof t!="object"||t===null)return;let{otpCode:n,skipCapture:i}=t;if(typeof n!="string"||n===""||typeof i!="boolean")return;let r=xe(e);return r!==void 0?{otpCode:n,skipCapture:i,reason:r}:{otpCode:n,skipCapture:i}}function Bt(e){let t=e.levelTarget?.max;return typeof t=="number"&&t<=1?"contact":e.purpose??"identity"}function Ut(e){let t=(e.plan?.sections??[]).map(d=>({id:d.id,state:d.state})),n={sessionId:oe(e.sessionId),orgName:e.orgName,sandbox:e.sandbox===!0,returning:e.returning===!0,consentRecorded:e.consentRecorded,expiresAt:e.expiresAt,sections:t.map(d=>d.id),progress:t,purpose:e.purpose??"identity",levelName:Bt(e)};e.branding!==void 0&&(n.branding=e.branding),e.cameraUnavailableHandled===!0&&(n.cameraUnavailableHandled=!0);let i=Gt(e);i!==void 0&&(n.simulation=i);let r=e.testerGate;r?.offered===!0&&typeof r.attemptsLeft=="number"&&r.attemptsLeft>0&&(n.testerGate={attemptsLeft:r.attemptsLeft});let a=le(e);return a!==null&&(n.switchable=a),n}function Kt(e){let t={attemptsRemaining:Pe(e),attemptsExhausted:e.attempts.used>=e.attempts.max};return e.reason!==void 0&&(t.reason=e.reason),e.retakeHint!==void 0&&(t.retakeHint=e.retakeHint),t}var nt={phone_otp:"phone",email_otp:"email"};function jt(e,t){let n=de(e,[t==="phone_otp"?"email_otp":"phone_otp"]);return n===void 0?void 0:nt[n.option.service]}function qt(e,t,n,i){let r=t.checkType==="email_otp",a=(r?t.emailOtp:t.otp)??{},d=r?t.emailOtp?.emailSource:t.otp?.numberSource,c=d!==void 0&&Ht.has(d)?d:r?"prefilled_or_entered":"user_entered",l=typeof a.sentToMasked=="string"&&a.sentToMasked.length>0,h=a.prefilled===!0,S=jt(e,r?"email_otp":"phone_otp"),w={key:t.checkType,context:n,section:L(t),phase:l?"verify":"send",canSwitch:S!==void 0,...i},g=r?{kind:"email_otp",...w,emailSource:c,needsEmail:c!=="prefilled"&&!h}:{kind:"phone_otp",...w,numberSource:c,needsPhone:c!=="prefilled"&&!h,channels:(t.otp?.channels??[]).filter(y=>y==="whatsapp"||y==="sms")};if(S!==void 0&&(g.switchChannel=S),h&&(g.prefilled=!0),l&&(g.sentToMasked=a.sentToMasked),!r&&t.otp?.channel!==void 0&&(g.channel=t.otp.channel),!r&&Array.isArray(t.phoneCountries)&&(g.phoneCountries=t.phoneCountries.filter(y=>typeof y=="string"&&/^[A-Z]{2}$/.test(y))),!r&&Array.isArray(t.phoneRules)){let y=g.phoneCountries??[];g.phoneRules=t.phoneRules.flatMap(O=>{let E=Wt(O);return E!==void 0&&y.includes(E.code)?[E]:[]})}return!r&&t.phoneInternational===!0&&(g.phoneInternational=!0),a.expiresAt!==void 0&&(g.codeExpiresAt=a.expiresAt),a.resendAvailableAt!==void 0&&(g.resendAvailableAt=a.resendAvailableAt),g}var Yt=/^[\d[\]\-|()?:^]{1,64}$/;function Zt(e){try{return typeof e=="string"&&Yt.test(e)&&new RegExp(e)!==null}catch{return!1}}var ze=e=>typeof e=="number"&&Number.isInteger(e)&&e>=1&&e<=15;function Wt(e){let{code:t,dial:n,trunk:i,lengths:r,formats:a}=e??{};if(typeof t!="string"||typeof n!="string"||!/^\d{1,3}$/.test(n)||i!==void 0&&(typeof i!="string"||!/^\d{1,3}$/.test(i))||!Array.isArray(r)||r.length===0||!r.every(ze))return;let d={code:t,dial:n,lengths:[...r].sort((c,l)=>c-l)};if(i!==void 0&&(d.trunk=i),a!==void 0){if(!(Array.isArray(a)&&a.length<=8&&a.every(l=>Zt(l?.leading)&&Array.isArray(l.groups)&&l.groups.every(ze)&&r.includes(l.groups.reduce((h,S)=>h+S,0)))))return;d.formats=a.map(l=>({leading:l.leading,groups:[...l.groups]}))}return d}function Qt(e,t,n,i){let r=Ge(e)===!0?"bound":Be(t)===!0?"document":"typed",a=r==="typed"&&t.state==="input_required"&&t.reason!==void 0&&je(t.reason)==="id_number_recheck",d=tt(le(e)),c=!i.attemptsExhausted&&d.length===1&&d[0]?.service==="document";return{kind:"registry",key:"registry",context:n,section:L(t),state:t.state==="input_required"?"input_required":"pending",source:r,recheck:a,canUseDocument:c,...i}}function $t(e,t,n,i,r){let a=[...t.acceptedSides??[]],d={kind:"document",key:"document",context:n,section:L(t),side:a.includes("recto")?"verso":"recto",acceptedSides:a,documents:Le(e),photo:fe(pe(e.documents),r),...i};return e.detectedCountry!==void 0&&(d.detectedCountry=e.detectedCountry),Xt(e)&&(d.ageStepUp=!0),d}function pe(e,t=!0){let n=e?.source==="upload"||e?.source==="choice"?e.source:"camera",i=e?.sourcePick==="camera"||e?.sourcePick==="upload"?e.sourcePick:null;return{source:n,pick:i,uploadOffered:t&&e?.uploadOffered===!0}}function fe(e,t){return t?{...e,cameraOnPhone:!0}:e}var Jt=10*1024*1024;function zt(e,t,n,i,r){let a=e.proofOfAddress,d=a?.pdf?.maxBytes,c=a?.phase==="holder_letter"?"holder_letter":"document";return{kind:"proof_of_address",key:"proof_of_address",context:n,section:L(t),phase:c,rule:a?.rule??{country:null,countryFrom:"global",source:"preset_global",kinds:[]},nameMatch:a?.nameMatch??"exact_person",photo:fe(pe(a),r),maxPages:3,pdf:{maxBytes:typeof d=="number"&&d>0?d:Jt,maxPages:3},licenceAddressAccepted:c==="document"&&a?.licenceAddressAccepted===!0,...i}}function Xt(e){let t=Ce(e).find(i=>i.checkType==="age_estimation"),n=t?.reason;return t?.state==="failed"&&(n==="age_uncertain"||n==="age_unavailable")}function en(e){let t=$(e,"liveness");return t?.state==="passed"||t?.state==="review"}function Xe(e,t,n,i,r,a=!1){let d=t.icao?.report,c=e.portrait,l=r==="capture"?c?.pendingFix??null:null;l!==null&&(r="review");let h=rt(e);return{kind:"portrait",key:`portrait:${r}`,context:n,section:L(t),phase:r,report:Array.isArray(d)?d:null,review:t.state==="review",tuning:e.capture?.icao??null,tuningVersion:e.capture?.tuningVersion??null,icao:J(e),retakeOnly:r==="capture"&&t.state==="input_required"&&h===void 0&&e.capture?.livePhoto?.oneCapture===!0&&en(e),photo:fe(pe(c,r==="capture"),a&&r==="capture"),pendingFix:l,...h!==void 0?{captureMode:h}:{},...c?.reuse?.pending===!0?{reuse:!0}:{},...i}}function rt(e){let t=e.portrait?.captureMode;return t==="self"||t==="assisted"||t==="choice"?t:void 0}var se={minLongSidePx:1280,jpegQuality:.95};function tn(e,t){let n=e.capture?.livePhoto;if(n?.oneCapture!==!0)return null;let i=$(e,"portrait_icao"),r=n.still??se;return{icao:t==="liveness"&&J(e)!==null&&rt(e)===void 0&&i!==void 0&&i.state==="pending"&&i.reason===void 0,still:{minLongSidePx:r.minLongSidePx??se.minLongSidePx,jpegQuality:r.jpegQuality??se.jpegQuality}}}function nn(e,t,n,i){let r=t.eid,a=L(t);if(r===void 0||r.challenge!=="app_code")return{kind:"unsupported",key:"unsupported:eid_auth",context:n,section:a,checkType:"eid_auth",reason:"update_required"};let d=tt(le(e)),c=d.length===1&&Ft.includes(d[0]?.service??"")?d[0]:void 0,l=c===void 0?void 0:q[c.service],h=l!==void 0,S={kind:"eid",key:"eid",context:n,section:a,provider:r.provider,providerName:r.providerName,country:r.country,challenge:"app_code",phase:r.awaiting==="code"?"code":"identifier",identifierBound:r.identifierBound===!0,canUseCamera:h,afterPass:r.afterPass==="continue"?"continue":"end",...i};return h&&(S.cameraMethod=l),r.expiresAt!==void 0&&(S.codeExpiresAt=r.expiresAt),r.resendAvailableAt!==void 0&&(S.resendAvailableAt=r.resendAvailableAt),r.resendsRemaining!==void 0&&(S.resendsRemaining=r.resendsRemaining),r.codeAttemptsRemaining!==void 0&&(S.codeAttemptsRemaining=r.codeAttemptsRemaining),S}function rn(e,t){if(t.checkType!=="face_match"||t.reason!==void 0)return null;let n=$(e,"portrait_icao");return n!==void 0&&(n.state==="passed"||n.state==="review")?n:null}var on={rejected:"rejected",inconclusive:"inconclusive",unavailable:"unavailable",abandoned:"expired",not_opened:"expired",cancelled:"expired",superseded:"expired",policy:"policy"};function sn(e){return e.reasonCode===ce?"platform_unsupported":e.status==="review_pending"?"review":e.status==="verified"?"verified":e.reasonCode==="device_cooldown"?"cooldown":e.reasonCode==="starter_credit_claimed"?"policy":(e.status==="not_verified"&&e.reason!==void 0?on[e.reason]:void 0)??"rejected"}function an(e,t){let n=sn(e),i=n==="platform_unsupported"?{sessionId:oe(e.sessionId),status:"unavailable",reasonCode:ce}:we(e,{autoRetry:!1}),r={kind:"result",key:"result",context:t,section:null,display:n,result:i};return e.status==="not_verified"&&e.reason!==void 0&&(r.reason=e.reason),e.reasonCode!==void 0&&(r.reasonCode=e.reasonCode),e.status==="not_verified"&&e.step!==void 0&&(r.step=e.step),e.retryAfter!==void 0&&(r.retryAfter=e.retryAfter),r}function un(e,t,n){let i=e.identitySummary;if(i==null)return null;let r={kind:"identity_summary",key:"identity_summary",context:t,section:n??"identity",summaryKind:i.kind==="partial"?"partial":i.kind??"full",source:i.source,portraitAvailable:i.portrait?.available===!0,retakeAvailable:i.retakeAvailable===!0};for(let d of cn){let c=i[d];typeof c=="string"&&c!==""&&(r[d]=c)}let a=Ue(i);return a!==void 0&&(r.idNumberMasked=a,r.nniMasked=a),r}var cn=["fullName","birthDate","birthYear","nationality","documentType","documentNumberMasked","expiryDate","retakeTarget"];function B(e,t,n,i){return{kind:"unsupported",key:`unsupported:${n}`,context:e,section:t,checkType:n,reason:i}}function dn(e){return e.kind==="contact"?"contact":(e.kind==="identity_method","identity")}function ln(e,t){let n=et[e.kind]??[...ae,...ue],i=dn(e),r=e.options.flatMap(d=>{if(d.available===!1||!n.includes(d.service))return[];let c={id:d.id,service:d.service};d.nationalEid!=null&&(c.nationalEid=d.nationalEid);let l=(d.channels??[]).filter(h=>h==="whatsapp"||h==="sms");return d.service==="phone_otp"&&l.length>0&&(c.channels=l),[c]});if(r.length===0){let d=e.options.length>0&&e.options.every(c=>c.service==="nfc");return B(t,i,"choice",d?"platform_unsupported":"update_required")}let a={nodeId:e.nodeId,kind:e.kind,selected:e.selected,options:r};if(e.kind==="identity_method"){let d={kind:"method",key:"method",context:t,section:i,options:r.map(l=>q[l.service]),choice:a},c=r.find(l=>l.nationalEid!==void 0)?.nationalEid;return c!==void 0&&(d.nationalEid=c),d}return e.kind==="contact"?{kind:"contact_choice",key:"contact_choice",context:t,section:i,options:r.map(d=>nt[d.service]),selected:null,locked:!1,choice:a}:{kind:"choice",key:`choice:${e.nodeId}`,context:t,section:i,choice:a}}function pn(e,t,n,i){let r=e.nativeApp,a=typeof r=="object"&&r!==null?r:{},d={sekyroApp:a.sekyroApp===!0};return typeof a.link=="string"&&a.link!==""&&(d.link=a.link),d.sekyroApp&&typeof a.sekyroAppLink=="string"&&a.sekyroAppLink.startsWith("sekyro://")&&(d.sekyroAppLink=a.sekyroAppLink),{kind:"native_app_required",key:`native_app_required:${i}`,context:t,section:n,checkType:i,nativeApp:d}}function ee(e,t={}){let n=Ut(e);if(re(e)||e.reasonCode===ce)return an(e,n);let i=e.plan;if(i===void 0||!Array.isArray(i.sections))return B(n,null,"plan","update_required");let r=Ae(e);if(r!==null)return ln(r,n);let a=i.current===null?void 0:i.steps.find(g=>g.id===i.current),d=g=>{let y={kind:"processing",key:"processing",context:n,section:g!==void 0?L(g):i.sections.find(O=>O.state==="current")?.id??null,stalled:!1};return typeof g?.service=="string"&&g.service!==""&&(y.service=g.service),y};if(i.current===null)return d(i.steps.find(g=>g.state==="processing"));if(a===void 0)return B(n,null,"step","update_required");if(!Lt.has(a.service))return a.interaction==="server"?d(a):B(n,L(a),a.service,"update_required");if(Vt.has(a.service)||!Re(a))return d(a);let c=a,l=Kt(c),h=c.checkType,S=L(c);if(c.requiresNativeApp===!0)return pn(e,n,S,h);let w=t.isMobile===!1?Ee(e,c):null;if(w==="phone")return{kind:"mobile_required",key:"mobile_required",context:n,section:S,checkType:h};switch(h){case"phone_otp":case"email_otp":return qt(e,c,n,l);case"population_registry":return Qt(e,c,n,l);case"eid_auth":return nn(e,c,n,l);case"doc_ocr":return $t(e,c,n,l,w==="upload_or_phone");case"identity_confirm":return un(e,n,S)??d(c);case"portrait_icao":return Xe(e,c,n,l,"capture",w==="upload_or_phone");case"liveness":case"face_match":{let g=rn(e,c);if(g!==null)return Xe(e,g,n,l,"match");let y=c.requiresMobile===!0,O=J(e);return{kind:"liveness",key:"biometric",context:n,section:S,mode:h==="face_match"?"selfie":"liveness",requiresMobile:y,instructions:O===null?"standard":"icao",icao:O,livePhoto:tn(e,h),...l}}case"poa":return zt(e,c,n,l,w==="upload_or_phone");case"form":{let g=Ye(c.form);return g===null?B(n,S,h,"update_required"):{kind:"form",key:"form",context:n,section:S,form:g,dir:qe(g.locale),...l}}case"nfc_chip":return B(n,S,h,"platform_unsupported");default:return B(n,S,h,"update_required")}}var fn=/^[A-Z0-9][A-Z0-9 -]{0,39}$/,mn=Object.freeze({normalize:e=>e.trim().toUpperCase().replace(/\s+/g," "),check:e=>fn.test(e),registrySources:Object.freeze([]),describe:"number must be 1 to 40 letters, digits, spaces or hyphens"}),hn=/^[A-Z0-9]{4,20}$/,me=e=>e.trim().toUpperCase().replace(/[\s-]+/g,""),gn=Object.freeze({normalize:me,check:e=>hn.test(me(e)),registrySources:Object.freeze([]),describe:"number must be 4 to 20 letters or digits"});function Sn(e){return typeof e=="string"&&/^\d{10}$/.test(e)&&Number(e)%97===1}var yn={trim:e=>e.trim(),upper_single_space:e=>e.trim().toUpperCase().replace(/\s+/g," "),upper_no_space_or_hyphen:me},_n={mr_nni_mod97:e=>Sn(e)};function bn(e){let t=new RegExp(e.pattern,"u"),n=e.check===null?void 0:_n[e.check];return Object.freeze({normalize:yn[e.normalize],check:i=>t.test(i.trim())&&(n===void 0||n(i)),registrySources:Object.freeze([...e.registrySources]),describe:e.describe})}var kn=Object.freeze(Object.fromEntries(Object.entries(Te).map(([e,t])=>[e,bn(t)])));function he(e,t){return kn[`${e.toUpperCase()}:${t}`]??(t==="drivers_license"?gn:mn)}var Cn=Object.freeze({JPN:"JP",MRT:"MR"});function ot(e,t){let n=e.trim().toUpperCase();return he(Cn[n]??n,t)}function it(e){let t=ot(e.issuingCountry,e.type);return t.check(t.normalize(e.number))}function st(e){return he("MR","national_id").check(e)}function ge(e){let t="";for(let n of e){let i=n.codePointAt(0)??0;i>=1632&&i<=1641?t+=String(i-1632):i>=1776&&i<=1785?t+=String(i-1776):n!==" "&&n!=="-"&&n!==" "&&(t+=n)}return t}var Pn=[1e3,2e3,4e3,8e3,15e3],An=3e4,Rn=/^\+[1-9]\d{6,14}$/,wn=/^\d{6}$/,xn=/^\d{6}$/,En=/^[^\s@]+@[^\s@]+\.[^\s@]+$/,at=new Set(["session_not_active","check_not_found","check_already_finalized","check_out_of_order","identity_confirm_required","identity_confirm_locked","choice_locked","choice_option_unavailable","choice_not_found","step_not_on_path","check_not_active","native_app_required"]),In={simulatedCapture:!0},Mn=new Set(["network_error","timeout","upload_failed","unknown_error","rate_limit_exceeded"]);function pr(e){let t=!1,n=null,i="",r=!1,a=!1,d=!1,c={},l={},h=new Set,S=!1,w=!1,g=null,y="idle",O=new Map,E=new Map,I=(o,s,u)=>{let p=`${o}.${s}`,f=O.get(p);if(f!==void 0)return f;let _=E.get(o),P=(_===void 0?u():_.then(u)).finally(()=>{O.delete(p)});O.set(p,P);let b=P.then(()=>{},()=>{});return E.set(o,b),b.then(()=>{E.get(o)===b&&E.delete(o)}),P},v=async(o,s,u)=>{await e.ensureConsent();let p;try{p=await Me(e.runtime,s)}catch(_){if(_ instanceof j&&at.has(_.code)){await e.refreshView();return}throw _}if(u?.(p),e.destroyed())return;let f=p;f.plan!==void 0&&e.setView!==void 0?e.setView(f):await e.refreshView()},V=async o=>{await e.ensureConsent();let s;try{try{s=await o(e.runtime.client)}catch(u){if(!(u instanceof j)||u.code!=="consent_required")throw u;await e.runtime.ensureConsent({force:!0}),s=await o(e.runtime.client)}}catch(u){if(u instanceof j&&at.has(u.code)){await e.refreshView();return}throw u}e.destroyed()||(s!==void 0&&e.setView!==void 0?e.setView(s):await e.refreshView())},D=(o,s)=>I("choice",`${o}:${s}`,()=>V(u=>u.choose(o,s))),x=(o,s)=>o.options.some(u=>u.id===s)?D(o.nodeId,s):Promise.reject(new RangeError(`option ${String(s)} is not offered`)),U=(o,s)=>{let u=e.currentView(),p=u===null?void 0:de(u,o);return p===void 0?Promise.reject(new RangeError(`the ${s} is not offered`)):D(p.nodeId,p.option.id)},F=o=>I("identity",o,()=>V(s=>s.confirmIdentity===void 0?Promise.reject(new Error("identity confirmation is not available in this build")):s.confirmIdentity(o))),K=(o,s)=>{let u=X(o.form,s);if(u.length>0)return Promise.reject(new ie(u,"client"));let p={answers:{...s.answers},consents:{}};for(let f of o.form.consents)p.consents[f.id]=s.consents[f.id]===!0;return I("form","submit",()=>v("form",(f,_)=>f.submitCheck("form",p,{idempotencyKey:_})).catch(f=>{throw f instanceof j&&f.code===ve?new ie(Je(f.details,o.form,p),"server"):f}))},te=(o,s)=>{let u=o.kind,p=u==="phone_otp",f=p?"phone":"email",_={action:"send"};if(p?o.needsPhone:o.needsEmail){let P=s[f]??l[u],b=p?P?.replace(/[\s().-]/g,""):P?.trim();if(b!==void 0||o.phase!=="verify"){if(b===void 0||!(p?Rn:En).test(b))return Promise.reject(p?new N("phone","format"):new Y("email","format"));_[f]=b}}if(p){let P=o.channels,b=s.channel??(P.length===1?P[0]:void 0);if(P.length>0){if(b===void 0)return Promise.reject(new Y("channel","required"));if(!P.includes(b))return Promise.reject(new Y("channel","unavailable"))}b!==void 0&&(_.channel=b),_.phoneRules=1}return I(u,"send",()=>v(u,(P,b)=>P.submitCheck(u,_,{idempotencyKey:b}),P=>{vn(P,u)||(c[u]=e.now(),_[f]!==void 0&&(l[u]=_[f]))}))},Z=(o,s)=>wn.test(s)?I(o,"verify",()=>v(o,(u,p)=>u.submitCheck(o,{action:"verify",code:s},{idempotencyKey:p}))):Promise.reject(new N("code","format")),G=(o,s)=>I("eid_auth",o,()=>v("eid_auth",(u,p)=>u.submitCheck("eid_auth",s,{idempotencyKey:p}))),ne=(o,s)=>{if(o.identifierBound)return G("start",{action:"start"});let u=ge(s??"");if(o.country==="MR"){if(!/^\d{10}$/.test(u))return Promise.reject(new N("nni","format"));if(!st(u))return Promise.reject(new N("nni","check_digit"))}else if(u==="")return Promise.reject(new N("nni","format"));return G("start",{action:"start",identifier:u})},W=(o,s,u)=>{if(o.source!=="typed")return Promise.reject(new RangeError("this session already holds the ID number"));let p=ge(s);return/^\d{10}$/.test(p)?it({type:"national_id",issuingCountry:"MR",number:p})?I("population_registry","submitIdNumber",()=>v("population_registry",(f,_)=>f.submitCheck("population_registry",{idNumber:p,nni:p},{idempotencyKey:_}),()=>{g=`\u2022\u2022\u2022\u2022\u2022\u2022${p.slice(-4)}`})):Promise.reject(new N(u,"check_digit")):Promise.reject(new N(u,"format"))},Q=o=>(e.stopCameras?.(),I(o,"skipCapture",()=>v(o,(s,u)=>s.submitCheck(o,In,{idempotencyKey:u}),()=>{(o==="liveness"||o==="portrait_icao")&&(S=!0)}))),Se=o=>{if(o.kind==="result"||o.context.simulation?.skipCapture!==!0)return o;let s=On(o);return s===null?o:{...o,skipCapture:()=>Q(s)}},m=o=>((o.kind==="document"||o.kind==="portrait"||o.kind==="proof_of_address")&&o.photo?.cameraOnPhone===!0&&(o.refresh=async()=>{await e.refreshView()}),o),k=o=>{switch(o.kind){case"phone_otp":case"email_otp":{let s={...o,send:(p={})=>te(o,p),verify:p=>Z(o.kind,p),switchTo:()=>o.canSwitch&&o.switchChannel!==void 0?U([o.switchChannel==="email"?"email_otp":"phone_otp"],"other contact option"):Promise.reject(new RangeError("this session has no other contact option"))},u=c[o.kind];return s.resendAvailableAt===void 0&&u!==void 0&&(s.resendAvailableAt=new Date(u+An).toISOString()),s}case"eid":return{...o,start:s=>ne(o,s),verify:s=>xn.test(s)?G("verify",{action:"verify",code:s}):Promise.reject(new N("code","format")),resend:()=>o.resendsRemaining===0?Promise.reject(new RangeError("no new code can be sent for this session")):G("resend",{action:"resend"}),useCamera:()=>o.canUseCamera&&o.cameraMethod!==void 0?U(o.cameraMethod==="document_photo"?["document"]:["population_registry"],"camera path"):Promise.reject(new RangeError("the camera path is not offered"))};case"method":return{...o,select:s=>{let u=o.choice.options.find(p=>q[p.service]===s);return u!==void 0?x(o.choice,u.id):Promise.reject(new RangeError(`method ${String(s)} is not offered`))},choose:s=>x(o.choice,s)};case"choice":return{...o,choose:s=>x(o.choice,s)};case"registry":return{...o,submitIdNumber:s=>W(o,s,"idNumber"),submitNni:s=>W(o,s,"nni"),confirm:()=>I("population_registry","confirm",()=>v("population_registry",(s,u)=>s.submitCheck("population_registry",{},{idempotencyKey:u}))),useDocument:()=>o.canUseDocument?U(["document"],"document method"):Promise.reject(new RangeError("the document method is not offered"))};case"document":return e.bindDocument!==void 0?m(e.bindDocument(o,M)):{...o,issuer:null,documentType:null,captureSide:null,selectDocument:()=>{throw new Error("document capture is not available in this build")},capture:()=>{throw new Error("document capture is not available in this build")},uploadDocument:()=>Promise.reject(new Error("document upload is not available in this build"))};case"portrait":return e.bindPortrait!==void 0?m(e.bindPortrait(o,M)):{...o,uploadFailed:!1,resubmit:()=>Promise.resolve(),capture:()=>{throw new Error("portrait capture is not available in this build")},uploadPortrait:()=>Promise.reject(new Error("portrait upload is not available in this build")),confirmFix:()=>Promise.reject(new Error("portrait review is not available in this build"))};case"proof_of_address":return e.bindProofOfAddress!==void 0?m(e.bindProofOfAddress(o,M)):{...o,uploadPages:()=>Promise.reject(new Error("proof of address upload is not available in this build")),uploadHolderLetter:()=>Promise.reject(new Error("proof of address upload is not available in this build")),capturePage:()=>{throw new Error("proof of address capture is not available in this build")}};case"form":return{...o,validate:s=>X(o.form,s),submit:s=>K(o,s)};case"contact_choice":return{...o,select:s=>{let u=s==="phone"?"phone_otp":s==="email"?"email_otp":void 0,p=o.choice.options.find(f=>f.service===u);return p!==void 0?x(o.choice,p.id):Promise.reject(new RangeError(`contact ${String(s)} is not offered`))},choose:s=>x(o.choice,s)};case"identity_summary":return{...o,...o.idNumberMasked===void 0&&o.summaryKind==="partial"&&g!==null?{idNumberMasked:g,nniMasked:g}:{},portrait:async()=>{let s=e.runtime.client;if(!o.portraitAvailable||s.identityPortrait===void 0)return null;try{return await s.identityPortrait()}catch{return null}},confirm:()=>F("confirm"),retake:()=>o.retakeAvailable?F("retake"):Promise.reject(new RangeError("no retake is left"))};case"liveness":return{...o,capture:s=>e.liveness(s),onLivePhoto:s=>o.livePhoto?.icao===!0&&e.onLivePhoto!==void 0?e.onLivePhoto(s):()=>{}};case"mobile_required":case"native_app_required":case"processing":return{...o,refresh:async()=>{r=!1,await e.refreshView()}};case"unsupported":case"result":return{...o};default:{let s=o;throw new Error(`runner: unhandled step ${JSON.stringify(s)}`)}}},A=o=>Se(k(o)),T=async()=>{if(!a){a=!0;try{for(let o of Pn){if(await e.sleep(o),!t||e.destroyed())return;let s=await e.refreshView().catch(()=>null);if(s!==null&&ee(s,{isMobile:e.isMobile()}).kind!=="processing")return}r=!0,M()}finally{a=!1}}},H=o=>{if(o.kind!=="liveness"||o.mode!=="selfie")return null;let s={kind:"processing",key:"processing",context:o.context,section:o.section,stalled:!1};if(y==="inflight")return s;if(!w||y==="done")return null;let u=e.keptFaceKey?.()??null;return u===null?null:(y="inflight",v("face_match",(p,f)=>p.submitCheck("face_match",{imageKey:u},{idempotencyKey:f}),()=>{y="done"}).then(()=>{y==="inflight"&&(y="done",M())},()=>{y="done",M()}),s)},R=(o,s=!1)=>{if(!t||e.destroyed()||e.chainBusy())return;let u=ee(o,{isMobile:e.isMobile()});u.kind==="registry"&&u.recheck&&(w=!0,y="idle"),u=H(u)??u,u.kind==="processing"?u.stalled=r:r=!1;let p=A(u),f=u.kind==="result"?void 0:u.context.switchable,_=f===void 0?p:{...p,chooseOption:b=>x({nodeId:f.nodeId,kind:f.kind,selected:f.current,options:f.options},b)},P=JSON.stringify(_);u.kind==="registry"&&u.source==="document"&&u.state==="pending"&&!h.has("registry")&&(h.add("registry"),_.confirm().catch(b=>{(!(b instanceof j)||Mn.has(b.code))&&h.delete("registry")})),!(!s&&P===i)&&(i=P,n=_,e.emitStep(_),u.kind==="processing"&&!r&&y!=="inflight"&&T(),u.kind==="result"&&!d&&(d=!0,e.emitResult(u.result)))};function M(){let o=e.currentView();o!==null&&R(o,!0)}return{run:async()=>{if(e.destroyed())throw new Error("verification destroyed");t=!0;let o=await e.ensureView();return n===null&&R(o),n??A(ee(o,{isMobile:e.isMobile()}))},current:()=>n,onView:o=>R(o),onChainIdle:()=>{let o=e.currentView();o!==null&&R(o)},republish:M,submit:v,faceProbeSkipped:()=>S}}function On(e){switch(e.kind){case"document":return"doc_ocr";case"liveness":return e.mode==="selfie"?"face_match":"liveness";case"portrait":return e.phase==="capture"?"portrait_icao":null;case"proof_of_address":return"poa";case"mobile_required":case"native_app_required":return e.checkType;case"unsupported":return e.checkType==="nfc_chip"?"nfc_chip":null;default:return null}}function vn(e,t){let n=e,i=n?.plan?.steps??n?.steps;return Array.isArray(i)?i.some(r=>r.checkType===t&&typeof r.reason=="string"):!1}export{dt as a,Ln as b,Ve as c,Fe as d,Gn as e,rt as f,ee as g,Pn as h,An as i,pr as j};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{d as x}from"./chunk-
|
|
1
|
+
import{d as x}from"./chunk-BRLQIJYF.js";import{b}from"./chunk-FPXL63KZ.js";var T=480,y=Object.freeze({MIN_AREA_FRAC:.15,EDGE_CLIP_MARGIN_PX:4,STABLE_TICKS:3,IOU_STABLE_MIN:.85,RISE_PER_S:.9,FALL_PER_S:.25,GUIDE_EXPOSURE:.6,GUIDE_SHARPNESS:.35,ID3_BAND_MIN_WIDTH_FRAC:.55,ID3_BAND_ASPECT_MIN:4,ID3_BAND_ASPECT_MAX:40}),p=e=>Math.min(1,Math.max(0,e));function E(e,o,t){let n=[e.topLeft,e.topRight,e.bottomRight,e.bottomLeft],i=0;for(let s=0;s<4;s++){let r=n[s],c=n[(s+1)%4];i+=r.x*c.y-c.x*r.y}let a=o*t;return a>0?Math.abs(i/2)/a:0}function I(e,o){let t=D(e),n=D(o),i=Math.max(t.x1,n.x1),a=Math.max(t.y1,n.y1),s=Math.min(t.x2,n.x2),r=Math.min(t.y2,n.y2),c=Math.max(0,s-i)*Math.max(0,r-a),u=(t.x2-t.x1)*(t.y2-t.y1),_=(n.x2-n.x1)*(n.y2-n.y1),m=u+_-c;return m>0?c/m:0}function R(e){let o=D(e);return{width:o.x2-o.x1,height:o.y2-o.y1}}function D(e){let o=[e.topLeft,e.topRight,e.bottomRight,e.bottomLeft];return{x1:Math.min(...o.map(t=>t.x)),y1:Math.min(...o.map(t=>t.y)),x2:Math.max(...o.map(t=>t.x)),y2:Math.max(...o.map(t=>t.y))}}function M(e){let o=Math.hypot(e.topRight.x-e.topLeft.x,e.topRight.y-e.topLeft.y),t=Math.hypot(e.bottomRight.x-e.bottomLeft.x,e.bottomRight.y-e.bottomLeft.y),n=Math.hypot(e.bottomLeft.x-e.topLeft.x,e.bottomLeft.y-e.topLeft.y),i=Math.hypot(e.bottomRight.x-e.topRight.x,e.bottomRight.y-e.topRight.y),a=(o+t)/2,s=(n+i)/2;return a<=0||s<=0?0:Math.max(a,s)/Math.min(a,s)}var d=class{constructor(o,t={}){this.p=0;this.lastTickAt=null;this.lastQuad=null;this.streak=0;this.format=o,this.t={...y,...t}}reset(){this.p=0,this.lastTickAt=null,this.lastQuad=null,this.streak=0}tick(o){let{quad:t,quality:n,timestampMs:i}=o,a=this.lastTickAt===null?0:Math.max(0,(i-this.lastTickAt)/1e3);this.lastTickAt=i;let s=null;if(t===null)s="dcv1.no_doc";else if(this.format==="ID-3"){let h=R(t),f=h.height>0?h.width/h.height:0;h.width<this.t.ID3_BAND_MIN_WIDTH_FRAC*o.frameWidth?s="dcv1.come_closer":this.edgeClipped(t,o.frameWidth,o.frameHeight)?s="dcv1.fit_document":(f<this.t.ID3_BAND_ASPECT_MIN||f>this.t.ID3_BAND_ASPECT_MAX)&&(s="dcv1.wrong_shape")}else E(t,o.frameWidth,o.frameHeight)<this.t.MIN_AREA_FRAC?s="dcv1.come_closer":this.edgeClipped(t,o.frameWidth,o.frameHeight)?s="dcv1.fit_document":x(this.format,M(t))||(s="dcv1.wrong_shape");let r=s===null,c=p(n.exposure)>=this.t.GUIDE_EXPOSURE,u=p(n.sharpness)>=this.t.GUIDE_SHARPNESS,_=c&&u;if(r&&_&&t!==null){let h=this.lastQuad===null||I(t,this.lastQuad)>=this.t.IOU_STABLE_MIN;this.streak=h?this.streak+1:1}else this.streak=0;this.lastQuad=t;let m=r&&_;this.p=p(this.p+(m?this.t.RISE_PER_S:-this.t.FALL_PER_S)*a);let A=m&&this.streak>=this.t.STABLE_TICKS,l;if(s!==null)l=s;else if(c)u?l="dcv1.hold_still":l="dcv1.steady";else{let h=(b[0]+b[1])/2;l=n.meanLuma<h?"dcv1.more_light":"dcv1.too_bright"}return{at:i,quad:t,plausible:r,p:this.p,guidanceKey:l,ready:A,stableTicks:this.streak}}edgeClipped(o,t,n){let i=this.t.EDGE_CLIP_MARGIN_PX;return[o.topLeft,o.topRight,o.bottomRight,o.bottomLeft].some(s=>s.x<=i||s.y<=i||s.x>=t-i||s.y>=n-i)}};export{T as a,y as b,E as c,I as d,R as e,d as f};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as se,b as oe}from"./chunk-SX7TUC3V.js";import{b as J,c as ee}from"./chunk-W357WDNU.js";import{b as pe,c as he,d as me}from"./chunk-POIQGEZM.js";import{a as Z,c as Q,e as Y,g as j,h as R,k,m as $,n as re}from"./chunk-CPUECYAJ.js";import{b as x,c as fe,d as G,e as ve}from"./chunk-FPXL63KZ.js";import{c as ie,d as ne,e as ae}from"./chunk-U5TL63CG.js";import{a as W,c as q,d as z,e as X}from"./chunk-TSA6GHUG.js";import{d as te}from"./chunk-COZXZAD5.js";import{e as le,f as ce,h as P,j as ue,l as de}from"./chunk-FSSMUAKC.js";var Oe=[...Z.filter(n=>n.startsWith("video/mp4")),"video/webm;codecs=h264","video/webm;codecs=avc1","video/webm;codecs=vp8","video/webm;codecs=vp9","video/webm"],ge=new Set;function Pe(n){let e=/(?:Chrome|Chromium)\/(\d+)\./.exec(n??"");return e?Number(e[1]):null}function be(n=xe(),e=globalThis.navigator?.userAgent){if(n===void 0)return"";let t=Pe(e)===126;for(let r of Oe)if(!(ge.has(r)||t&&r.startsWith("video/mp4")))try{if(n(r))return r}catch{}return""}function L(n){n!==""&&ge.add(n)}function ye(n){return n.replace(/^video\/x-matroska/i,"video/webm")}function lt(n){let e=/codecs=["']?([^,;"']+)/i.exec(n);return e?e[1].trim():n.split(";")[0].trim()}function xe(){let n=globalThis.MediaRecorder;return n&&typeof n.isTypeSupported=="function"?e=>n.isTypeSupported(e):void 0}var V=2500,Ge=1e3,Le=1500,Te=25e5,Fe=100,Ve=700,Ne=20,Ue=1500,F=null;function He(){return F??(F=import("./clip-inspect-DLJXVKV6.js").catch(n=>{throw F=null,n})),F.catch(()=>null)}var T=class extends Error{constructor(e,t){super(t??e),this.kind=e}},Ke=100;function N(n,e){return n.stats===void 0?!1:n.stats===null?!0:n.stats.durationMs<e-Ke}function Ee(n,e){return n.stats?e.stats?n.stats.durationMs>e.stats.durationMs:!0:!1}var A=class{constructor(e={}){this.recorder=null;this.stream=null;this.chunks=[];this.bytes=0;this.hardStopTimer=null;this.graceTimer=null;this.pollTimer=null;this.settled=!1;this.now=e.now??(()=>globalThis.performance?.now?.()??Date.now())}clearTimers(){this.hardStopTimer&&clearTimeout(this.hardStopTimer),this.graceTimer&&clearTimeout(this.graceTimer),this.pollTimer&&clearInterval(this.pollTimer),this.hardStopTimer=null,this.graceTimer=null,this.pollTimer=null}record(e,t,r,i=V,a){let s=be(),o=He();return this.recordRaw(e,t,r,i,a,s).then(c=>Be(c,o),c=>{throw c instanceof T&&(c.requestedMimeType=s),c})}recordRaw(e,t,r,i,a,s){return this.recorder&&!this.settled?Promise.reject(new T("generic","record() called while a recording is in flight \u2014 ClipRecorder handles one recording at a time")):(this.recorder=null,this.clearTimers(),this.chunks=[],this.bytes=0,this.settled=!1,this.stream=e,new Promise((o,c)=>{let l;try{l=new MediaRecorder(e,s?{mimeType:s,videoBitsPerSecond:Te}:{videoBitsPerSecond:Te})}catch{try{l=new MediaRecorder(e)}catch{c(new T("unsupported"));return}}this.recorder=l;let d=h=>{this.settled||(this.settled=!0,this.clearTimers(),h())},u=()=>d(()=>{let h=ye(l.mimeType||s||Q),b=new Blob(this.chunks,{type:h});if(b.size===0){c(new T("generic","empty clip"));return}if(R(b)){c(new T("cliptoolarge"));return}o({blob:b,mimeType:h,requestedMimeType:s})});l.ondataavailable=h=>{h.data&&h.data.size&&(this.chunks.push(h.data),this.bytes+=h.data.size,this.bytes>j&&d(()=>{try{l.state!=="inactive"&&l.stop()}catch{}c(new T("cliptoolarge"))}))},l.onstop=u,l.onerror=()=>d(()=>c(new T("generic")));let p=this.now();if(r!==void 0||a!==void 0){let h=!1;l.onstart=()=>{if(!(h||this.settled)&&(h=!0,p=this.now(),r!==void 0))try{r()}catch{}}}try{l.start(Ge)}catch{d(()=>c(new T("generic")));return}let m=()=>{if(this.pollTimer&&clearInterval(this.pollTimer),this.pollTimer=null,this.hardStopTimer&&clearTimeout(this.hardStopTimer),this.hardStopTimer=null,this.settled||t?.(),l.state!=="inactive"){try{l.stop()}catch{u()}this.graceTimer=setTimeout(u,Le)}else u()},f=this.now();if(a===void 0){this.hardStopTimer=setTimeout(m,i);return}let g=null,M=!1;this.hardStopTimer=setTimeout(m,i+Ve),this.pollTimer=setInterval(()=>{if(this.settled||M)return;let h=null;try{h=a.latest()}catch{h=null}let b=h?.presentationTimeMs;b!==void 0&&Number.isFinite(b)&&b>=p&&g===null&&(g=b);let S=g!==null&&b!==void 0&&b-g>=i,I=g===null&&this.now()-f>=i;if(!(!S&&!I)){if(M=!0,this.pollTimer&&clearInterval(this.pollTimer),this.pollTimer=null,I){m();return}this.hardStopTimer&&clearTimeout(this.hardStopTimer),this.hardStopTimer=setTimeout(m,Fe)}},Ne)}))}stop(e){this.clearTimers();let t=this.recorder;if(t&&t.state!=="inactive")try{t.stop()}catch{}this.recorder=null,(e??this.stream)?.getTracks().forEach(i=>i.stop()),this.stream=null}};async function Be(n,e){let t,r=new Promise(l=>{t=setTimeout(()=>l(null),Ue)}),i=await Promise.race([e,r]);if(clearTimeout(t),i===null)return n;let a;try{a=await i.blobBytes(n.blob)}catch{return{...n,stats:null}}let s=i.inspectClipBytes(a);if(s?.container!=="webm")return{...n,stats:s};let o=i.withWebmDuration(a,s.durationMs);if(o===null)return{...n,stats:s};let c=i.inspectClipBytes(o);return c===null||c.frames!==s.frames||c.durationMs!==s.durationMs?{...n,stats:s}:{...n,blob:new Blob([o],{type:n.blob.type}),stats:s}}function Me(n,e,t=.92){return new Promise((r,i)=>{let a=n.videoWidth,s=n.videoHeight;if(!a||!s){i(new Error("video-not-ready"));return}let o=e.getContext("2d");if(!o){i(new Error("no-2d-context"));return}e.width=a,e.height=s,o.scale(-1,1),o.drawImage(n,-a,0),e.toBlob(c=>c?r(c):i(new Error("empty-keyframe")),"image/jpeg",t)})}var D=class{constructor(e){this.timer=null;this.frameCallbackId=null;this.running=!1;this.busy=!1;this.lastRunAt=Number.NEGATIVE_INFINITY;this.degradeCount=0;this.durations=[];this.options=e,this.periodMs=1e3/e.cadenceHz}start(){if(this.running)return;this.running=!0;let e=this.options.video;if(typeof e?.requestVideoFrameCallback=="function"){let t=()=>{this.running&&(this.frameCallbackId=e.requestVideoFrameCallback?.(()=>{this.frameCallbackId=null,this.now()-this.lastRunAt>=this.periodMs&&this.tick(),t()}))};t();return}this.timer=setInterval(()=>this.tick(),this.periodMs)}stop(){this.running=!1,this.timer!==null&&(clearInterval(this.timer),this.timer=null),this.frameCallbackId!==null&&(this.options.video?.cancelVideoFrameCallback?.(this.frameCallbackId),this.frameCallbackId=null)}stats(){let e=this.durations.length===0?0:this.durations.reduce((t,r)=>t+r,0)/this.durations.length;return{degradeCount:this.degradeCount,meanDetectMs:e}}now(){return this.options.now?.()??performance.now()}tick(){if(!this.running)return;if(this.busy){this.degradeCount+=1;return}this.busy=!0,this.lastRunAt=this.now();let e=this.now();this.options.run().catch(()=>{}).finally(()=>{this.busy=!1,this.durations.push(this.now()-e),this.durations.length>20&&this.durations.shift()})}};var We=Object.freeze({Q_GOOD:.6,RISE_PER_S:.9,FALL_PER_S:.25,CENTER_FALLOFF_IOD_MULTIPLE:1.35,BOX_EYE_OFFSET_FACTOR:.12,IOD_BOX_PROXY_FACTOR:.42,SIZE_IDEAL_MIN:.12,SIZE_IDEAL_MAX:.3,SIZE_HARD_MIN:.08,SIZE_HARD_MAX:.45,ROLL_MAX_DEG:25,MOTION_VELOCITY_IOD_PER_S:.5,MOTION_TAU_S:.4,MOTION_DEADBAND_IOD_PER_S:.1,READY_WINDOW_MS:500,GUIDE_SIZE:.6,GUIDE_CENTERING:.6,GUIDE_POSE:.6,GUIDE_EXPOSURE:.6,GUIDE_SHARPNESS:.35,GUIDE_MOTION:.5}),C=n=>Math.min(1,Math.max(0,n)),_=class{constructor(e={}){this.p=0;this.lastTickAt=null;this.lastCenter=null;this.velocityEma=0;this.qWindow=[];this.lastSizeDirection="ideal";this.t={...We,...e}}reset(){this.p=0,this.lastTickAt=null,this.lastCenter=null,this.velocityEma=0,this.qWindow=[],this.lastSizeDirection="ideal"}tick(e){let{observation:t,quality:r,timestampMs:i}=e,a=this.lastTickAt===null?0:Math.max(0,(i-this.lastTickAt)/1e3);this.lastTickAt=i;let s={presence:0,single:1,centering:0,size:0,pose:0,sharpness:C(r.sharpness),exposure:C(r.exposure),motion:1};if(t!==null){s.presence=1,s.single=(t.extraFaces??0)>0?0:1;let d=this.geometryOf(t,e);s.centering=d.centering,s.size=d.size,s.pose=d.pose,s.motion=this.motionOf(d.center,d.iod,i)}else this.lastCenter=null,this.velocityEma=0;let o=Math.min(s.presence,s.single,s.centering,s.size,s.pose,s.sharpness,s.exposure,s.motion);this.p=C(this.p+(o>=this.t.Q_GOOD?this.t.RISE_PER_S*o:-this.t.FALL_PER_S*(1-o))*a),this.qWindow.push({at:i,q:o}),this.qWindow=this.qWindow.filter(d=>d.at>=i-this.t.READY_WINDOW_MS);let c=this.qWindow.map(d=>d.q);if(c.length>=3){let d=Math.min(...c),u=c.indexOf(d);c=c.filter((p,m)=>m!==u)}let l=this.p>=1&&c.every(d=>d>=this.t.Q_GOOD);return{at:i,q:o,p:this.p,factors:s,guidanceKey:this.guidanceOf(s,r,o),ready:l,accepted:o>=this.t.Q_GOOD}}geometryOf(e,t){let{box:r,eyes:i}=e,a={x:t.frameWidth/2,y:t.frameHeight/2},s=Math.min(t.frameWidth,t.frameHeight),o=i!==void 0?{x:(i.left.x+i.right.x)/2,y:(i.left.y+i.right.y)/2}:{x:r.x+r.width/2,y:r.y+r.height/2-this.t.BOX_EYE_OFFSET_FACTOR*r.height},c=i!==void 0?Math.hypot(i.right.x-i.left.x,i.right.y-i.left.y):this.t.IOD_BOX_PROXY_FACTOR*r.width,l=Math.hypot(o.x-a.x,o.y-a.y),d=c<=0?0:1-C(l/(this.t.CENTER_FALLOFF_IOD_MULTIPLE*c)),u=s>0?c/s:0;this.lastSizeDirection=u<this.t.SIZE_IDEAL_MIN?"far":u>this.t.SIZE_IDEAL_MAX?"close":"ideal";let p;u<this.t.SIZE_HARD_MIN||u>this.t.SIZE_HARD_MAX?p=0:u<this.t.SIZE_IDEAL_MIN?p=(u-this.t.SIZE_HARD_MIN)/(this.t.SIZE_IDEAL_MIN-this.t.SIZE_HARD_MIN):u>this.t.SIZE_IDEAL_MAX?p=(this.t.SIZE_HARD_MAX-u)/(this.t.SIZE_HARD_MAX-this.t.SIZE_IDEAL_MAX):p=1;let m=1;if(i!==void 0){let f=Math.abs(Math.atan2(i.right.y-i.left.y,i.right.x-i.left.x))*180/Math.PI;m=1-C(f/this.t.ROLL_MAX_DEG)}return{center:o,iod:c,centering:d,size:p,pose:m}}motionOf(e,t,r){let i=this.lastCenter;if(this.lastCenter={...e,at:r},i===null||t<=0)return 1;let a=(r-i.at)/1e3;if(a<=0)return 1;let s=Math.hypot(e.x-i.x,e.y-i.y)/t/a;s<=this.t.MOTION_DEADBAND_IOD_PER_S&&(s=0);let o=1-Math.exp(-a/this.t.MOTION_TAU_S);return this.velocityEma=o*s+(1-o)*this.velocityEma,1-C(this.velocityEma/this.t.MOTION_VELOCITY_IOD_PER_S)}guidanceOf(e,t,r){if(e.presence<=0)return"fcv3.no_face";if(e.single<=0)return"fcv3.one_face";if(e.size<this.t.GUIDE_SIZE)return this.sizeGuidance();if(e.centering<this.t.GUIDE_CENTERING)return"fcv3.center_face";if(e.pose<this.t.GUIDE_POSE)return"fcv3.straighten";if(e.exposure<this.t.GUIDE_EXPOSURE)return this.exposureGuidance(t);if(e.sharpness<this.t.GUIDE_SHARPNESS)return"fcv3.steady_camera";if(e.motion<this.t.GUIDE_MOTION)return"fcv3.hold_still";if(r<this.t.Q_GOOD){let i=[["size",this.sizeGuidance()],["centering","fcv3.center_face"],["pose","fcv3.straighten"],["exposure",this.exposureGuidance(t)],["sharpness","fcv3.steady_camera"],["motion","fcv3.hold_still"]],a=i[0];for(let s of i)e[s[0]]<e[a[0]]&&(a=s);return a[1]}return"fcv3.hold_still"}sizeGuidance(){return this.lastSizeDirection==="far"?"fcv3.come_closer":"fcv3.move_back"}exposureGuidance(e){let t=(x[0]+x[1])/2;return e.meanLuma<t?"fcv3.more_light":"fcv3.too_bright"}};var qe=["single","size","centering","pose","exposure","sharpness","motion"];function ze(n){if(n.accepted)return null;if(n.factors.presence<=0)return"no_face";let e="single";for(let t of qe)n.factors[t]<n.factors[e]&&(e=t);return e}var w=class{constructor(){this.blocked={};this.acceptedMs=0;this.ticks=0;this.lastAt=null}record(e){let t=this.lastAt===null?0:Math.max(0,e.at-this.lastAt);this.lastAt=e.at,this.ticks+=1;let r=ze(e);if(r===null){this.acceptedMs+=t;return}let i=this.blocked[r]??{count:0,ms:0};i.count+=1,i.ms+=t,this.blocked[r]=i}summary(){let e={};for(let[t,r]of Object.entries(this.blocked))e[t]={count:r.count,ms:Math.round(r.ms)};return{blocked:e,acceptedMs:Math.round(this.acceptedMs),ticks:this.ticks}}};var Xe=["obs","manycam","virtual","snap camera","xsplit","droidcam","iriun","camo","fake_device","fake-capture-device"],Ze=[/^(front|back|rear)( [a-z ]+)? camera$/i,/^caméra (avant|arrière)\b/i,/^cámara (frontal|trasera|delantera)\b/i,/^câmera (frontal|traseira)\b/i,/^(front|rück)kamera\b/i,/^الكاميرا (الأمامية|الخلفية)/,/^camera2? ?\d+, facing (front|back|external)/i,/facetime/i,/\b(integrated|built-in|builtin) (web)?cam(era)?\b/i,/\b(hd )?web ?cam\b/i,/\([0-9a-f]{4}:[0-9a-f]{4}\)\s*$/i];function Qe(n){let e=(n??"").trim().toLowerCase();return e.length===0?"unknown":Xe.some(t=>e.includes(t))?"known_virtual":Ze.some(t=>t.test(e))?"platform":"unknown"}function Ce(n){if(typeof n!="function")return!1;try{return/\{\s*\[native code\]\s*\}\s*$/.test(Function.prototype.toString.call(n))}catch{return!1}}function Ye(n=globalThis){return Ce(n.navigator?.mediaDevices?.getUserMedia)&&Ce(n.MediaStreamTrack?.prototype?.getSettings)}async function je(n,e=globalThis){let t=e.crypto?.subtle?.digest;if(typeof t=="function")try{let r=new Uint8Array(await t.call(e.crypto?.subtle,"SHA-256",new TextEncoder().encode(n)));return Array.from(r.subarray(0,8),i=>i.toString(16).padStart(2,"0")).join("")}catch{return}}async function Se(n,e=globalThis){let t={};try{t=typeof n.getSettings=="function"?n.getSettings()??{}:{}}catch{t={}}let r={};if((t.facingMode==="user"||t.facingMode==="environment"||t.facingMode==="left"||t.facingMode==="right")&&(r.facingMode=t.facingMode),typeof t.frameRate=="number"&&Number.isFinite(t.frameRate)&&(r.frameRate=t.frameRate),typeof t.width=="number"&&Number.isFinite(t.width)&&(r.width=t.width),typeof t.height=="number"&&Number.isFinite(t.height)&&(r.height=t.height),typeof t.deviceId=="string"&&t.deviceId.length>0){let a=await je(t.deviceId,e);a!==void 0&&(r.deviceIdHash=a)}let i;try{i=n.label}catch{i=void 0}return{trackSettings:r,capabilitiesPresent:typeof n.getCapabilities=="function",labelClass:Qe(i),prototypesIntact:Ye(e)}}var U=n=>Math.round(n*100)/100;function ke(n){let e=n,t=typeof e?.requestVideoFrameCallback=="function",r=null,i=null,a=0,s=0,o=0,c=0,l=0,d=0,u=()=>{!t||e?.requestVideoFrameCallback===void 0||(r=e.requestVideoFrameCallback((p,m)=>{if(r=null,!t)return;let f=m.presentationTime;if(i!==null){let g=f-i.presentationTimeMs;s+=1;let M=g-o;o+=M/s,c+=M*(g-o)}typeof m.captureTime=="number"&&Number.isFinite(m.captureTime)&&(l+=f-m.captureTime,d+=1),a+=1,i={mediaTimeMs:m.mediaTime*1e3,presentationTimeMs:f},u()}))};return u(),{latest:()=>i,stats:()=>({n:a,meanGapMs:s===0?0:U(o),stdGapMs:s<2?0:U(Math.sqrt(c/(s-1))),captureLatencyMs:d===0?null:U(l/d)}),stop:()=>{t&&(t=!1,r!==null&&e?.cancelVideoFrameCallback?.(r),r=null)}}}function _e(n,e,t){return{...n,rvfc:e,rampPainter:t}}var $e=1e3,H="fcv3.hold_upright",Je=200,K=4,et=600,tt=1e3,we={sharpness:1,exposure:1,meanLuma:128};function rt(n,e){return e.width=n.videoWidth,e.height=n.videoHeight,e.getContext("2d").drawImage(n,0,0),new Promise((t,r)=>e.toBlob(i=>i?t(i):r(new Error("empty-keyframe")),"image/jpeg",.92))}function it(){return q()==="phone"}var Ie=class{constructor(e){this.handlers=new Map;this.stateValue="idle";this.attempt=0;this.stream=null;this.detector=null;this.scheduler=null;this.gate=null;this.profiler=null;this.lastGuidanceKey=null;this.positioningStartedAt=0;this.cameraRequestedAt=null;this.cameraReadyAt=null;this.faceAcquiredAt=null;this.captureCompleteAt=null;this.fired=!1;this.carriedDegrade=0;this.carriedMeans=[];this.blockStats=null;this.lastGateSnapshotAt=Number.NEGATIVE_INFINITY;this.uprightGuard=!1;this.trackProvenance=null;this.openEnvironment=null;this.ramp=null;this.snapshotCanvas=null;this.options=e,this.facing=e.facingMode??"user"}get state(){return this.stateValue}on(e,t){let r=this.handlers.get(e);return r||(r=new Set,this.handlers.set(e,r)),r.add(t),()=>r?.delete(t)}emit(e,t){for(let r of[...this.handlers.get(e)??[]])r(t)}async start(e={}){e.facingMode!==void 0&&(this.facing=e.facingMode),this.attempt+=1,await this.run(this.attempt)}get facingMode(){return this.facing}retry(){this.teardownAttempt(),this.start()}switchCamera(){this.facing=this.facing==="user"?"environment":"user",this.teardownAttempt(),this.start()}restart(e){this.facing=e,this.teardownAttempt(),this.start()}destroy(){this.attempt+=1,this.teardownAttempt(),this.detector?.destroy(),this.detector=null,this.options.video.srcObject=null}async run(e){let{options:t}=this;this.fired=!1,this.lastGuidanceKey=null,this.carriedDegrade=0,this.carriedMeans=[],this.cameraRequestedAt=null,this.cameraReadyAt=null,this.faceAcquiredAt=null,this.captureCompleteAt=null,this.uprightGuard=(t.isPhone??it)(),this.setState("preflight");let r=Y();if(r!=="OK"){this.fail(r==="INSECURE_CONTEXT"?"insecure":"unsupported",{phase:"preflight"});return}this.setState("acquiring");let i=t.getUserMedia??(l=>navigator.mediaDevices.getUserMedia(l)),a;this.cameraRequestedAt=this.now();try{let{facingMode:l,...d}=W(z(),this.facing).video;a=await oe(this.facing,d,{getUserMedia:i,enumerateDevices:st(t)})}catch(l){if(e!==this.attempt)return;if(l instanceof se){this.fail("backcamera",{phase:"acquiring",name:k(l)});return}this.fail($(l),{phase:"acquiring",name:k(l)});return}if(te(a),re(a),e!==this.attempt){for(let l of a.getTracks())l.stop();return}this.stream=a;let s=a.getVideoTracks?.()[0];if(this.trackProvenance=s===void 0?null:Se(s).catch(()=>null),this.openEnvironment=s===void 0?null:J(s).catch(()=>({})),this.facing=X(a)??this.facing,t.video.srcObject=a,await t.video.play().catch(()=>{}),e!==this.attempt)return;if(this.cameraReadyAt=this.now(),this.detector===null){let l={v3AssetBaseUrl:t.v3AssetBaseUrl},d=t.createDetector??(t.createWorker!==void 0&&ue()?async()=>{try{return await de.create(t.createWorker(),l)}catch{return P(l)}}:()=>P(l)),u;try{u=await d()}catch(p){e===this.attempt&&this.fail("models",{phase:"models",name:k(p)},p instanceof le?p.fallbackReason:at(p));return}if(e!==this.attempt){u.destroy();return}this.detector=u,this.options.telemetry?.({type:"detector",tier:u.tier,fallbackReason:u.fallbackReason})}let o=pe(),c=t.deviceClass??he(o);this.profiler=new me(c),this.options.telemetry?.({type:"profile",staticClass:c,activeClass:this.profiler.deviceClass,simd:o.simd}),this.gate=new _(t.thresholds??{}),this.blockStats=new w,this.lastGateSnapshotAt=this.now(),t.rankKeyframes?.()&&import("./keyframe-rank-YAJLYJYF.js").then(l=>B=l,()=>{}),this.setState("positioning"),this.positioningStartedAt=this.now(),this.startScheduler(e)}get animations(){return this.profiler?.profile.animations??"full"}startScheduler(e){let t=this.profiler;if(t===null)return;if(this.scheduler!==null){let i=this.scheduler.stats();this.carriedDegrade+=i.degradeCount,i.meanDetectMs>0&&this.carriedMeans.push(i.meanDetectMs),this.scheduler.stop()}let r=new D({cadenceHz:t.profile.cadenceHz,video:this.options.video,now:this.options.now,run:()=>this.detectTick(e)});this.scheduler=r,r.start()}async detectTick(e){let{detector:t,gate:r,profiler:i}=this,a=this.options.video;if(e!==this.attempt||t===null||r===null||i===null||this.fired||a.videoWidth===0)return;if(this.isLandscape()){this.holdUpright(e);return}let s=i.deviceClass,o=this.now(),c=this.options.makeSnapshot?.(a,i.profile.inputWidth)??this.defaultSnapshot(a,i.profile.inputWidth),l=null;try{l=await t.detect(c,a.videoWidth,a.videoHeight)}catch{l=null}if(e!==this.attempt||this.fired)return;i.record(this.now()-o),i.deviceClass!==s&&this.startScheduler(e);let d=l===null?we:this.options.measureQuality?.(a,l.box)??this.defaultQuality(a,l.box),u=r.tick({timestampMs:this.now(),observation:l,quality:d,frameWidth:a.videoWidth,frameHeight:a.videoHeight});u.accepted&&this.faceAcquiredAt===null&&(this.faceAcquiredAt=u.at),this.blockStats?.record(u),!u.ready&&u.at-this.lastGateSnapshotAt>=$e&&(this.lastGateSnapshotAt=u.at,this.reportGate(!1)),this.emit("checks",{engine:"v3",progress:u.p,q:u.q,factors:u.factors,attempt:e}),u.guidanceKey!==this.lastGuidanceKey&&(this.lastGuidanceKey=u.guidanceKey,this.emit("guidance",{key:u.guidanceKey})),u.ready&&this.stateValue==="positioning"&&(this.fired=!0,this.captureCompleteAt=u.at,this.fire(e))}async fire(e){let{options:t}=this,r=this.scheduler;r?.stop(),this.reportGate(!0);let i=r?.stats()??{degradeCount:0,meanDetectMs:0},a=[...this.carriedMeans,...i.meanDetectMs>0?[i.meanDetectMs]:[]];t.telemetry?.({type:"fired",timeToGateMs:this.now()-this.positioningStartedAt,degradeCount:this.carriedDegrade+i.degradeCount,meanDetectMs:a.length===0?0:a.reduce((y,v)=>y+v,0)/a.length});let s=t.mode??"clip",o=t.rankKeyframes?.()&&B?B.default(this,e).catch(()=>this.collectKeyframes(e)):this.collectKeyframes(e);if(s==="photo"){let y=this.watchRotation(e,null),v=await o;if(y(),e!==this.attempt)return;if(v===null){this.fail("generic",{phase:"keyframes"});return}let O=await this.provenance({n:0,meanGapMs:0,stdGapMs:0,captureLatencyMs:null},!1);if(e!==this.attempt)return;this.finishCapture({keyframe:v.blob,previewDataUrl:v.previewDataUrl,...O});return}this.setState("recording");let c=this.stream;if(c===null){this.fail("generic",{phase:"recording"});return}let l=t.screenRamp?.(),d=ie(l),u=null;o.then(y=>{u=y},()=>{});let p=()=>{e===this.attempt&&u!==null&&this.emit("frozen",{previewDataUrl:u.previewDataUrl})},m=ne(l,V),f=null,g,M=0;try{let y=this.recordTake(e,c,l,m,void 0).then(E=>E,E=>({failed:E})),[v,O]=await Promise.all([y,o]);if(g=O,e!==this.attempt)return;if("failed"in v){if(v.failed.kind==="cliptoolarge")throw v.failed;L(v.failed.requestedMimeType??"")}else f=v,N(v.clip,m)?v.clip.stats===null&&L(v.clip.requestedMimeType??""):p();if(f===null||N(f.clip,m)){M=1,t.telemetry?.({type:"clip_retake",reason:f===null?"error":f.clip.stats===null?"unreadable":"short"});let E=null;try{E=await this.recordTake(e,c,l,m,p)}catch(De){if(f===null)throw De}if(e!==this.attempt)return;E!==null&&(f===null||Ee(E.clip,f.clip))&&(f=E),E===null&&p()}}catch(y){if(e!==this.attempt)return;let v=y.kind;this.fail(v==="cliptoolarge"?"cliptoolarge":"recorder",{phase:"recording",name:k(y)});return}if(f===null){this.fail("recorder",{phase:"recording"});return}let{clip:h,rvfc:b,report:S,watched:I}=f;if(R(h.blob)){this.fail("cliptoolarge",{phase:"recording"});return}if(g===null){this.fail("generic",{phase:"keyframes"});return}let Ae=await this.provenance(b,d,I);e===this.attempt&&this.finishCapture({clip:h.blob,clipMimeType:h.mimeType,...h.stats?{clipStats:h.stats}:{},clipRetakes:M,keyframe:g.blob,previewDataUrl:g.previewDataUrl,...S!==void 0&&S.rendered.length>0?{screenRamp:S}:{},...Ae})}async recordTake(e,t,r,i,a){let s=this.options.createRecorder?.()??new A({now:()=>this.now()}),o=ke(this.options.video),c=ae(r,{paint:p=>{(p===null||e===this.attempt)&&this.emit("ramp",{colour:p})},now:()=>this.now(),frames:o.latest});this.ramp=c;let l=()=>{o.stop(),c.stop(),this.ramp===c&&(this.ramp=null)},d=this.watchRotation(e,s),u=ee();try{return{clip:await s.record(t,a,()=>c.started(this.now()),i,o),rvfc:o.stats(),report:c.report(),watched:u.stop()}}finally{u.stop(),d(),l()}}async provenance(e,t,r={}){let i=this.trackProvenance;if(i===null)return{};let a,s=new Promise(d=>{a=setTimeout(()=>d(null),tt)}),o=await Promise.race([i,s]),c=o===null?null:await Promise.race([this.openEnvironment,s]);if(clearTimeout(a),o===null)return{};let l={...c,...r};return{provenance:{..._e(o,e,t),...Object.keys(l).length>0?{env:l}:{}}}}isLandscape(){let e=this.options.video;return this.uprightGuard&&e.videoWidth>e.videoHeight}holdUpright(e){this.gate?.reset(),this.emit("checks",{engine:"v3",progress:0,q:0,factors:{presence:0,single:1,centering:0,size:0,pose:0,sharpness:0,exposure:0,motion:0},attempt:e}),this.lastGuidanceKey!==H&&(this.lastGuidanceKey=H,this.emit("guidance",{key:H}))}watchRotation(e,t){if(!this.uprightGuard)return()=>{};let r=this.options.video,i=()=>{if(e!==this.attempt||t!==null&&this.stateValue!=="recording"){o();return}r.videoWidth>0&&this.isLandscape()&&(o(),this.abortRecording(e,t))},a=setInterval(i,Je);r.addEventListener?.("resize",i);let s=!1;function o(){s||(s=!0,clearInterval(a),r.removeEventListener?.("resize",i))}return o}abortRecording(e,t){if(e!==this.attempt)return;this.attempt+=1;let r=this.attempt;try{t?.stop()}catch{}this.ramp?.stop(),this.ramp=null,this.fired=!1,this.captureCompleteAt=null,this.gate=new _(this.options.thresholds??{}),this.blockStats=new w,this.lastGateSnapshotAt=this.now(),this.lastGuidanceKey=null,this.setState("positioning"),this.positioningStartedAt=this.now(),this.holdUpright(r),this.startScheduler(r)}async collectKeyframes(e){let t=this.options.captureKeyframe??(a=>this.defaultKeyframe(a)),r=et/(K-1),i=null;for(let a=0;a<K;a+=1){if(e!==this.attempt)return i;try{let s=await t(this.options.video);(i===null||s.sharpness>i.sharpness)&&(i=s)}catch{}a<K-1&&await nt(r)}return i}finishCapture(e){this.stopTracks(),this.setState("captured");let t=this.captureTiming();this.emit("artifacts",t===void 0?e:{...e,timing:t})}captureTiming(){let e={},t=(r,i,a)=>{i!==null&&a!==null&&(e[r]=Math.max(0,Math.round(a-i)))};return t("cameraReadyMs",this.cameraRequestedAt,this.cameraReadyAt),t("faceAcquireMs",this.cameraReadyAt,this.faceAcquiredAt),t("captureMs",this.faceAcquiredAt,this.captureCompleteAt),Object.keys(e).length>0?e:void 0}async defaultKeyframe(e){let t=document.createElement("canvas"),r=await(this.facing==="user"?Me:rt)(e,t),i=t.toDataURL("image/jpeg",.92);return{blob:r,previewDataUrl:i,sharpness:this.centerSharpness(e)}}defaultSnapshot(e,t){try{let r=this.snapshotCanvas??document.createElement("canvas"),i=t/Math.max(1,e.videoWidth),a=Math.max(1,Math.round(e.videoWidth*i)),s=Math.max(1,Math.round(e.videoHeight*i)),o=r.getContext("2d");return o===null?e:(r.width!==a&&(r.width=a),r.height!==s&&(r.height=s),o.drawImage(e,0,0,a,s),this.snapshotCanvas=r,r)}catch{return e}}defaultQuality(e,t){let r=Re(e,t,96);return r===null?we:{sharpness:G(r),exposure:ve(r),meanLuma:fe(r)}}centerSharpness(e){let t=ce(e),r=Re(e,{x:t.width*.25,y:t.height*.25,width:t.width*.5,height:t.height*.5},96);return r===null?0:G(r)}teardownAttempt(){this.scheduler?.stop(),this.scheduler=null,this.reportGate(!0),this.gate=null,this.ramp?.stop(),this.ramp=null,this.stopTracks()}reportGate(e){let t=this.blockStats,r=this.profiler;if(t===null||r===null)return;let i=t.summary();e&&(this.blockStats=null),i.ticks!==0&&this.options.telemetry?.({type:"gate",final:e,activeClass:r.deviceClass,cadenceHz:r.profile.cadenceHz,...i})}stopTracks(){if(this.stream!==null){for(let e of this.stream.getTracks())e.stop();this.stream=null}}fail(e,t,r){this.scheduler?.stop(),this.reportGate(!0),this.stopTracks(),this.setState("error"),this.options.telemetry?.({type:"error",kind:e,fallbackReason:r});let{phase:i,name:a}=t;this.emit("error",{kind:e,retryable:e!=="insecure"&&e!=="unsupported",detail:a===void 0?{phase:i}:{phase:i,name:a}})}setState(e){this.stateValue=e,this.emit("statechange",{state:e})}now(){return this.options.now?.()??performance.now()}},B;function nt(n){return new Promise(e=>setTimeout(e,n))}function at(n){return n instanceof Error?n.message:String(n)}function Re(n,e,t){try{let r=document.createElement("canvas"),i=t/Math.max(1,e.width);r.width=Math.max(1,Math.round(e.width*i)),r.height=Math.max(1,Math.round(e.height*i));let a=r.getContext("2d");return a===null?null:(a.drawImage(n,e.x,e.y,e.width,e.height,0,0,r.width,r.height),a.getImageData(0,0,r.width,r.height))}catch{return null}}function st(n){if(n.enumerateDevices!==void 0)return n.enumerateDevices;if(n.getUserMedia===void 0&&!(typeof navigator>"u"||typeof navigator.mediaDevices?.enumerateDevices!="function"))return()=>navigator.mediaDevices.enumerateDevices()}export{lt as a,V as b,Ge as c,Le as d,Te as e,Fe as f,Ve as g,Ne as h,Ue as i,T as j,Ke as k,N as l,Ee as m,A as n,Me as o,D as p,We as q,_ as r,ze as s,w as t,$e as u,H as v,Je as w,K as x,et as y,tt as z,Ie as A};
|
|
1
|
+
import{a as se,b as oe}from"./chunk-SX7TUC3V.js";import{b as J,c as ee}from"./chunk-W357WDNU.js";import{b as pe,c as he,d as me}from"./chunk-POIQGEZM.js";import{a as Z,c as Q,e as Y,g as j,h as R,k,m as $,n as re}from"./chunk-CPUECYAJ.js";import{b as x,c as fe,d as G,e as ve}from"./chunk-FPXL63KZ.js";import{c as ie,d as ne,e as ae}from"./chunk-U5TL63CG.js";import{a as W,c as q,d as z,e as X}from"./chunk-TSA6GHUG.js";import{d as te}from"./chunk-HMOOVRKA.js";import{e as le,f as ce,h as P,j as ue,l as de}from"./chunk-FSSMUAKC.js";var Oe=[...Z.filter(n=>n.startsWith("video/mp4")),"video/webm;codecs=h264","video/webm;codecs=avc1","video/webm;codecs=vp8","video/webm;codecs=vp9","video/webm"],ge=new Set;function Pe(n){let e=/(?:Chrome|Chromium)\/(\d+)\./.exec(n??"");return e?Number(e[1]):null}function be(n=xe(),e=globalThis.navigator?.userAgent){if(n===void 0)return"";let t=Pe(e)===126;for(let r of Oe)if(!(ge.has(r)||t&&r.startsWith("video/mp4")))try{if(n(r))return r}catch{}return""}function L(n){n!==""&&ge.add(n)}function ye(n){return n.replace(/^video\/x-matroska/i,"video/webm")}function lt(n){let e=/codecs=["']?([^,;"']+)/i.exec(n);return e?e[1].trim():n.split(";")[0].trim()}function xe(){let n=globalThis.MediaRecorder;return n&&typeof n.isTypeSupported=="function"?e=>n.isTypeSupported(e):void 0}var V=2500,Ge=1e3,Le=1500,Te=25e5,Fe=100,Ve=700,Ne=20,Ue=1500,F=null;function He(){return F??(F=import("./clip-inspect-DLJXVKV6.js").catch(n=>{throw F=null,n})),F.catch(()=>null)}var T=class extends Error{constructor(e,t){super(t??e),this.kind=e}},Ke=100;function N(n,e){return n.stats===void 0?!1:n.stats===null?!0:n.stats.durationMs<e-Ke}function Ee(n,e){return n.stats?e.stats?n.stats.durationMs>e.stats.durationMs:!0:!1}var A=class{constructor(e={}){this.recorder=null;this.stream=null;this.chunks=[];this.bytes=0;this.hardStopTimer=null;this.graceTimer=null;this.pollTimer=null;this.settled=!1;this.now=e.now??(()=>globalThis.performance?.now?.()??Date.now())}clearTimers(){this.hardStopTimer&&clearTimeout(this.hardStopTimer),this.graceTimer&&clearTimeout(this.graceTimer),this.pollTimer&&clearInterval(this.pollTimer),this.hardStopTimer=null,this.graceTimer=null,this.pollTimer=null}record(e,t,r,i=V,a){let s=be(),o=He();return this.recordRaw(e,t,r,i,a,s).then(c=>Be(c,o),c=>{throw c instanceof T&&(c.requestedMimeType=s),c})}recordRaw(e,t,r,i,a,s){return this.recorder&&!this.settled?Promise.reject(new T("generic","record() called while a recording is in flight \u2014 ClipRecorder handles one recording at a time")):(this.recorder=null,this.clearTimers(),this.chunks=[],this.bytes=0,this.settled=!1,this.stream=e,new Promise((o,c)=>{let l;try{l=new MediaRecorder(e,s?{mimeType:s,videoBitsPerSecond:Te}:{videoBitsPerSecond:Te})}catch{try{l=new MediaRecorder(e)}catch{c(new T("unsupported"));return}}this.recorder=l;let d=h=>{this.settled||(this.settled=!0,this.clearTimers(),h())},u=()=>d(()=>{let h=ye(l.mimeType||s||Q),b=new Blob(this.chunks,{type:h});if(b.size===0){c(new T("generic","empty clip"));return}if(R(b)){c(new T("cliptoolarge"));return}o({blob:b,mimeType:h,requestedMimeType:s})});l.ondataavailable=h=>{h.data&&h.data.size&&(this.chunks.push(h.data),this.bytes+=h.data.size,this.bytes>j&&d(()=>{try{l.state!=="inactive"&&l.stop()}catch{}c(new T("cliptoolarge"))}))},l.onstop=u,l.onerror=()=>d(()=>c(new T("generic")));let p=this.now();if(r!==void 0||a!==void 0){let h=!1;l.onstart=()=>{if(!(h||this.settled)&&(h=!0,p=this.now(),r!==void 0))try{r()}catch{}}}try{l.start(Ge)}catch{d(()=>c(new T("generic")));return}let m=()=>{if(this.pollTimer&&clearInterval(this.pollTimer),this.pollTimer=null,this.hardStopTimer&&clearTimeout(this.hardStopTimer),this.hardStopTimer=null,this.settled||t?.(),l.state!=="inactive"){try{l.stop()}catch{u()}this.graceTimer=setTimeout(u,Le)}else u()},f=this.now();if(a===void 0){this.hardStopTimer=setTimeout(m,i);return}let g=null,M=!1;this.hardStopTimer=setTimeout(m,i+Ve),this.pollTimer=setInterval(()=>{if(this.settled||M)return;let h=null;try{h=a.latest()}catch{h=null}let b=h?.presentationTimeMs;b!==void 0&&Number.isFinite(b)&&b>=p&&g===null&&(g=b);let S=g!==null&&b!==void 0&&b-g>=i,I=g===null&&this.now()-f>=i;if(!(!S&&!I)){if(M=!0,this.pollTimer&&clearInterval(this.pollTimer),this.pollTimer=null,I){m();return}this.hardStopTimer&&clearTimeout(this.hardStopTimer),this.hardStopTimer=setTimeout(m,Fe)}},Ne)}))}stop(e){this.clearTimers();let t=this.recorder;if(t&&t.state!=="inactive")try{t.stop()}catch{}this.recorder=null,(e??this.stream)?.getTracks().forEach(i=>i.stop()),this.stream=null}};async function Be(n,e){let t,r=new Promise(l=>{t=setTimeout(()=>l(null),Ue)}),i=await Promise.race([e,r]);if(clearTimeout(t),i===null)return n;let a;try{a=await i.blobBytes(n.blob)}catch{return{...n,stats:null}}let s=i.inspectClipBytes(a);if(s?.container!=="webm")return{...n,stats:s};let o=i.withWebmDuration(a,s.durationMs);if(o===null)return{...n,stats:s};let c=i.inspectClipBytes(o);return c===null||c.frames!==s.frames||c.durationMs!==s.durationMs?{...n,stats:s}:{...n,blob:new Blob([o],{type:n.blob.type}),stats:s}}function Me(n,e,t=.92){return new Promise((r,i)=>{let a=n.videoWidth,s=n.videoHeight;if(!a||!s){i(new Error("video-not-ready"));return}let o=e.getContext("2d");if(!o){i(new Error("no-2d-context"));return}e.width=a,e.height=s,o.scale(-1,1),o.drawImage(n,-a,0),e.toBlob(c=>c?r(c):i(new Error("empty-keyframe")),"image/jpeg",t)})}var D=class{constructor(e){this.timer=null;this.frameCallbackId=null;this.running=!1;this.busy=!1;this.lastRunAt=Number.NEGATIVE_INFINITY;this.degradeCount=0;this.durations=[];this.options=e,this.periodMs=1e3/e.cadenceHz}start(){if(this.running)return;this.running=!0;let e=this.options.video;if(typeof e?.requestVideoFrameCallback=="function"){let t=()=>{this.running&&(this.frameCallbackId=e.requestVideoFrameCallback?.(()=>{this.frameCallbackId=null,this.now()-this.lastRunAt>=this.periodMs&&this.tick(),t()}))};t();return}this.timer=setInterval(()=>this.tick(),this.periodMs)}stop(){this.running=!1,this.timer!==null&&(clearInterval(this.timer),this.timer=null),this.frameCallbackId!==null&&(this.options.video?.cancelVideoFrameCallback?.(this.frameCallbackId),this.frameCallbackId=null)}stats(){let e=this.durations.length===0?0:this.durations.reduce((t,r)=>t+r,0)/this.durations.length;return{degradeCount:this.degradeCount,meanDetectMs:e}}now(){return this.options.now?.()??performance.now()}tick(){if(!this.running)return;if(this.busy){this.degradeCount+=1;return}this.busy=!0,this.lastRunAt=this.now();let e=this.now();this.options.run().catch(()=>{}).finally(()=>{this.busy=!1,this.durations.push(this.now()-e),this.durations.length>20&&this.durations.shift()})}};var We=Object.freeze({Q_GOOD:.6,RISE_PER_S:.9,FALL_PER_S:.25,CENTER_FALLOFF_IOD_MULTIPLE:1.35,BOX_EYE_OFFSET_FACTOR:.12,IOD_BOX_PROXY_FACTOR:.42,SIZE_IDEAL_MIN:.12,SIZE_IDEAL_MAX:.3,SIZE_HARD_MIN:.08,SIZE_HARD_MAX:.45,ROLL_MAX_DEG:25,MOTION_VELOCITY_IOD_PER_S:.5,MOTION_TAU_S:.4,MOTION_DEADBAND_IOD_PER_S:.1,READY_WINDOW_MS:500,GUIDE_SIZE:.6,GUIDE_CENTERING:.6,GUIDE_POSE:.6,GUIDE_EXPOSURE:.6,GUIDE_SHARPNESS:.35,GUIDE_MOTION:.5}),C=n=>Math.min(1,Math.max(0,n)),_=class{constructor(e={}){this.p=0;this.lastTickAt=null;this.lastCenter=null;this.velocityEma=0;this.qWindow=[];this.lastSizeDirection="ideal";this.t={...We,...e}}reset(){this.p=0,this.lastTickAt=null,this.lastCenter=null,this.velocityEma=0,this.qWindow=[],this.lastSizeDirection="ideal"}tick(e){let{observation:t,quality:r,timestampMs:i}=e,a=this.lastTickAt===null?0:Math.max(0,(i-this.lastTickAt)/1e3);this.lastTickAt=i;let s={presence:0,single:1,centering:0,size:0,pose:0,sharpness:C(r.sharpness),exposure:C(r.exposure),motion:1};if(t!==null){s.presence=1,s.single=(t.extraFaces??0)>0?0:1;let d=this.geometryOf(t,e);s.centering=d.centering,s.size=d.size,s.pose=d.pose,s.motion=this.motionOf(d.center,d.iod,i)}else this.lastCenter=null,this.velocityEma=0;let o=Math.min(s.presence,s.single,s.centering,s.size,s.pose,s.sharpness,s.exposure,s.motion);this.p=C(this.p+(o>=this.t.Q_GOOD?this.t.RISE_PER_S*o:-this.t.FALL_PER_S*(1-o))*a),this.qWindow.push({at:i,q:o}),this.qWindow=this.qWindow.filter(d=>d.at>=i-this.t.READY_WINDOW_MS);let c=this.qWindow.map(d=>d.q);if(c.length>=3){let d=Math.min(...c),u=c.indexOf(d);c=c.filter((p,m)=>m!==u)}let l=this.p>=1&&c.every(d=>d>=this.t.Q_GOOD);return{at:i,q:o,p:this.p,factors:s,guidanceKey:this.guidanceOf(s,r,o),ready:l,accepted:o>=this.t.Q_GOOD}}geometryOf(e,t){let{box:r,eyes:i}=e,a={x:t.frameWidth/2,y:t.frameHeight/2},s=Math.min(t.frameWidth,t.frameHeight),o=i!==void 0?{x:(i.left.x+i.right.x)/2,y:(i.left.y+i.right.y)/2}:{x:r.x+r.width/2,y:r.y+r.height/2-this.t.BOX_EYE_OFFSET_FACTOR*r.height},c=i!==void 0?Math.hypot(i.right.x-i.left.x,i.right.y-i.left.y):this.t.IOD_BOX_PROXY_FACTOR*r.width,l=Math.hypot(o.x-a.x,o.y-a.y),d=c<=0?0:1-C(l/(this.t.CENTER_FALLOFF_IOD_MULTIPLE*c)),u=s>0?c/s:0;this.lastSizeDirection=u<this.t.SIZE_IDEAL_MIN?"far":u>this.t.SIZE_IDEAL_MAX?"close":"ideal";let p;u<this.t.SIZE_HARD_MIN||u>this.t.SIZE_HARD_MAX?p=0:u<this.t.SIZE_IDEAL_MIN?p=(u-this.t.SIZE_HARD_MIN)/(this.t.SIZE_IDEAL_MIN-this.t.SIZE_HARD_MIN):u>this.t.SIZE_IDEAL_MAX?p=(this.t.SIZE_HARD_MAX-u)/(this.t.SIZE_HARD_MAX-this.t.SIZE_IDEAL_MAX):p=1;let m=1;if(i!==void 0){let f=Math.abs(Math.atan2(i.right.y-i.left.y,i.right.x-i.left.x))*180/Math.PI;m=1-C(f/this.t.ROLL_MAX_DEG)}return{center:o,iod:c,centering:d,size:p,pose:m}}motionOf(e,t,r){let i=this.lastCenter;if(this.lastCenter={...e,at:r},i===null||t<=0)return 1;let a=(r-i.at)/1e3;if(a<=0)return 1;let s=Math.hypot(e.x-i.x,e.y-i.y)/t/a;s<=this.t.MOTION_DEADBAND_IOD_PER_S&&(s=0);let o=1-Math.exp(-a/this.t.MOTION_TAU_S);return this.velocityEma=o*s+(1-o)*this.velocityEma,1-C(this.velocityEma/this.t.MOTION_VELOCITY_IOD_PER_S)}guidanceOf(e,t,r){if(e.presence<=0)return"fcv3.no_face";if(e.single<=0)return"fcv3.one_face";if(e.size<this.t.GUIDE_SIZE)return this.sizeGuidance();if(e.centering<this.t.GUIDE_CENTERING)return"fcv3.center_face";if(e.pose<this.t.GUIDE_POSE)return"fcv3.straighten";if(e.exposure<this.t.GUIDE_EXPOSURE)return this.exposureGuidance(t);if(e.sharpness<this.t.GUIDE_SHARPNESS)return"fcv3.steady_camera";if(e.motion<this.t.GUIDE_MOTION)return"fcv3.hold_still";if(r<this.t.Q_GOOD){let i=[["size",this.sizeGuidance()],["centering","fcv3.center_face"],["pose","fcv3.straighten"],["exposure",this.exposureGuidance(t)],["sharpness","fcv3.steady_camera"],["motion","fcv3.hold_still"]],a=i[0];for(let s of i)e[s[0]]<e[a[0]]&&(a=s);return a[1]}return"fcv3.hold_still"}sizeGuidance(){return this.lastSizeDirection==="far"?"fcv3.come_closer":"fcv3.move_back"}exposureGuidance(e){let t=(x[0]+x[1])/2;return e.meanLuma<t?"fcv3.more_light":"fcv3.too_bright"}};var qe=["single","size","centering","pose","exposure","sharpness","motion"];function ze(n){if(n.accepted)return null;if(n.factors.presence<=0)return"no_face";let e="single";for(let t of qe)n.factors[t]<n.factors[e]&&(e=t);return e}var w=class{constructor(){this.blocked={};this.acceptedMs=0;this.ticks=0;this.lastAt=null}record(e){let t=this.lastAt===null?0:Math.max(0,e.at-this.lastAt);this.lastAt=e.at,this.ticks+=1;let r=ze(e);if(r===null){this.acceptedMs+=t;return}let i=this.blocked[r]??{count:0,ms:0};i.count+=1,i.ms+=t,this.blocked[r]=i}summary(){let e={};for(let[t,r]of Object.entries(this.blocked))e[t]={count:r.count,ms:Math.round(r.ms)};return{blocked:e,acceptedMs:Math.round(this.acceptedMs),ticks:this.ticks}}};var Xe=["obs","manycam","virtual","snap camera","xsplit","droidcam","iriun","camo","fake_device","fake-capture-device"],Ze=[/^(front|back|rear)( [a-z ]+)? camera$/i,/^caméra (avant|arrière)\b/i,/^cámara (frontal|trasera|delantera)\b/i,/^câmera (frontal|traseira)\b/i,/^(front|rück)kamera\b/i,/^الكاميرا (الأمامية|الخلفية)/,/^camera2? ?\d+, facing (front|back|external)/i,/facetime/i,/\b(integrated|built-in|builtin) (web)?cam(era)?\b/i,/\b(hd )?web ?cam\b/i,/\([0-9a-f]{4}:[0-9a-f]{4}\)\s*$/i];function Qe(n){let e=(n??"").trim().toLowerCase();return e.length===0?"unknown":Xe.some(t=>e.includes(t))?"known_virtual":Ze.some(t=>t.test(e))?"platform":"unknown"}function Ce(n){if(typeof n!="function")return!1;try{return/\{\s*\[native code\]\s*\}\s*$/.test(Function.prototype.toString.call(n))}catch{return!1}}function Ye(n=globalThis){return Ce(n.navigator?.mediaDevices?.getUserMedia)&&Ce(n.MediaStreamTrack?.prototype?.getSettings)}async function je(n,e=globalThis){let t=e.crypto?.subtle?.digest;if(typeof t=="function")try{let r=new Uint8Array(await t.call(e.crypto?.subtle,"SHA-256",new TextEncoder().encode(n)));return Array.from(r.subarray(0,8),i=>i.toString(16).padStart(2,"0")).join("")}catch{return}}async function Se(n,e=globalThis){let t={};try{t=typeof n.getSettings=="function"?n.getSettings()??{}:{}}catch{t={}}let r={};if((t.facingMode==="user"||t.facingMode==="environment"||t.facingMode==="left"||t.facingMode==="right")&&(r.facingMode=t.facingMode),typeof t.frameRate=="number"&&Number.isFinite(t.frameRate)&&(r.frameRate=t.frameRate),typeof t.width=="number"&&Number.isFinite(t.width)&&(r.width=t.width),typeof t.height=="number"&&Number.isFinite(t.height)&&(r.height=t.height),typeof t.deviceId=="string"&&t.deviceId.length>0){let a=await je(t.deviceId,e);a!==void 0&&(r.deviceIdHash=a)}let i;try{i=n.label}catch{i=void 0}return{trackSettings:r,capabilitiesPresent:typeof n.getCapabilities=="function",labelClass:Qe(i),prototypesIntact:Ye(e)}}var U=n=>Math.round(n*100)/100;function ke(n){let e=n,t=typeof e?.requestVideoFrameCallback=="function",r=null,i=null,a=0,s=0,o=0,c=0,l=0,d=0,u=()=>{!t||e?.requestVideoFrameCallback===void 0||(r=e.requestVideoFrameCallback((p,m)=>{if(r=null,!t)return;let f=m.presentationTime;if(i!==null){let g=f-i.presentationTimeMs;s+=1;let M=g-o;o+=M/s,c+=M*(g-o)}typeof m.captureTime=="number"&&Number.isFinite(m.captureTime)&&(l+=f-m.captureTime,d+=1),a+=1,i={mediaTimeMs:m.mediaTime*1e3,presentationTimeMs:f},u()}))};return u(),{latest:()=>i,stats:()=>({n:a,meanGapMs:s===0?0:U(o),stdGapMs:s<2?0:U(Math.sqrt(c/(s-1))),captureLatencyMs:d===0?null:U(l/d)}),stop:()=>{t&&(t=!1,r!==null&&e?.cancelVideoFrameCallback?.(r),r=null)}}}function _e(n,e,t){return{...n,rvfc:e,rampPainter:t}}var $e=1e3,H="fcv3.hold_upright",Je=200,K=4,et=600,tt=1e3,we={sharpness:1,exposure:1,meanLuma:128};function rt(n,e){return e.width=n.videoWidth,e.height=n.videoHeight,e.getContext("2d").drawImage(n,0,0),new Promise((t,r)=>e.toBlob(i=>i?t(i):r(new Error("empty-keyframe")),"image/jpeg",.92))}function it(){return q()==="phone"}var Ie=class{constructor(e){this.handlers=new Map;this.stateValue="idle";this.attempt=0;this.stream=null;this.detector=null;this.scheduler=null;this.gate=null;this.profiler=null;this.lastGuidanceKey=null;this.positioningStartedAt=0;this.cameraRequestedAt=null;this.cameraReadyAt=null;this.faceAcquiredAt=null;this.captureCompleteAt=null;this.fired=!1;this.carriedDegrade=0;this.carriedMeans=[];this.blockStats=null;this.lastGateSnapshotAt=Number.NEGATIVE_INFINITY;this.uprightGuard=!1;this.trackProvenance=null;this.openEnvironment=null;this.ramp=null;this.snapshotCanvas=null;this.options=e,this.facing=e.facingMode??"user"}get state(){return this.stateValue}on(e,t){let r=this.handlers.get(e);return r||(r=new Set,this.handlers.set(e,r)),r.add(t),()=>r?.delete(t)}emit(e,t){for(let r of[...this.handlers.get(e)??[]])r(t)}async start(e={}){e.facingMode!==void 0&&(this.facing=e.facingMode),this.attempt+=1,await this.run(this.attempt)}get facingMode(){return this.facing}retry(){this.teardownAttempt(),this.start()}switchCamera(){this.facing=this.facing==="user"?"environment":"user",this.teardownAttempt(),this.start()}restart(e){this.facing=e,this.teardownAttempt(),this.start()}destroy(){this.attempt+=1,this.teardownAttempt(),this.detector?.destroy(),this.detector=null,this.options.video.srcObject=null}async run(e){let{options:t}=this;this.fired=!1,this.lastGuidanceKey=null,this.carriedDegrade=0,this.carriedMeans=[],this.cameraRequestedAt=null,this.cameraReadyAt=null,this.faceAcquiredAt=null,this.captureCompleteAt=null,this.uprightGuard=(t.isPhone??it)(),this.setState("preflight");let r=Y();if(r!=="OK"){this.fail(r==="INSECURE_CONTEXT"?"insecure":"unsupported",{phase:"preflight"});return}this.setState("acquiring");let i=t.getUserMedia??(l=>navigator.mediaDevices.getUserMedia(l)),a;this.cameraRequestedAt=this.now();try{let{facingMode:l,...d}=W(z(),this.facing).video;a=await oe(this.facing,d,{getUserMedia:i,enumerateDevices:st(t)})}catch(l){if(e!==this.attempt)return;if(l instanceof se){this.fail("backcamera",{phase:"acquiring",name:k(l)});return}this.fail($(l),{phase:"acquiring",name:k(l)});return}if(te(a),re(a),e!==this.attempt){for(let l of a.getTracks())l.stop();return}this.stream=a;let s=a.getVideoTracks?.()[0];if(this.trackProvenance=s===void 0?null:Se(s).catch(()=>null),this.openEnvironment=s===void 0?null:J(s).catch(()=>({})),this.facing=X(a)??this.facing,t.video.srcObject=a,await t.video.play().catch(()=>{}),e!==this.attempt)return;if(this.cameraReadyAt=this.now(),this.detector===null){let l={v3AssetBaseUrl:t.v3AssetBaseUrl},d=t.createDetector??(t.createWorker!==void 0&&ue()?async()=>{try{return await de.create(t.createWorker(),l)}catch{return P(l)}}:()=>P(l)),u;try{u=await d()}catch(p){e===this.attempt&&this.fail("models",{phase:"models",name:k(p)},p instanceof le?p.fallbackReason:at(p));return}if(e!==this.attempt){u.destroy();return}this.detector=u,this.options.telemetry?.({type:"detector",tier:u.tier,fallbackReason:u.fallbackReason})}let o=pe(),c=t.deviceClass??he(o);this.profiler=new me(c),this.options.telemetry?.({type:"profile",staticClass:c,activeClass:this.profiler.deviceClass,simd:o.simd}),this.gate=new _(t.thresholds??{}),this.blockStats=new w,this.lastGateSnapshotAt=this.now(),t.rankKeyframes?.()&&import("./keyframe-rank-YAJLYJYF.js").then(l=>B=l,()=>{}),this.setState("positioning"),this.positioningStartedAt=this.now(),this.startScheduler(e)}get animations(){return this.profiler?.profile.animations??"full"}startScheduler(e){let t=this.profiler;if(t===null)return;if(this.scheduler!==null){let i=this.scheduler.stats();this.carriedDegrade+=i.degradeCount,i.meanDetectMs>0&&this.carriedMeans.push(i.meanDetectMs),this.scheduler.stop()}let r=new D({cadenceHz:t.profile.cadenceHz,video:this.options.video,now:this.options.now,run:()=>this.detectTick(e)});this.scheduler=r,r.start()}async detectTick(e){let{detector:t,gate:r,profiler:i}=this,a=this.options.video;if(e!==this.attempt||t===null||r===null||i===null||this.fired||a.videoWidth===0)return;if(this.isLandscape()){this.holdUpright(e);return}let s=i.deviceClass,o=this.now(),c=this.options.makeSnapshot?.(a,i.profile.inputWidth)??this.defaultSnapshot(a,i.profile.inputWidth),l=null;try{l=await t.detect(c,a.videoWidth,a.videoHeight)}catch{l=null}if(e!==this.attempt||this.fired)return;i.record(this.now()-o),i.deviceClass!==s&&this.startScheduler(e);let d=l===null?we:this.options.measureQuality?.(a,l.box)??this.defaultQuality(a,l.box),u=r.tick({timestampMs:this.now(),observation:l,quality:d,frameWidth:a.videoWidth,frameHeight:a.videoHeight});u.accepted&&this.faceAcquiredAt===null&&(this.faceAcquiredAt=u.at),this.blockStats?.record(u),!u.ready&&u.at-this.lastGateSnapshotAt>=$e&&(this.lastGateSnapshotAt=u.at,this.reportGate(!1)),this.emit("checks",{engine:"v3",progress:u.p,q:u.q,factors:u.factors,attempt:e}),u.guidanceKey!==this.lastGuidanceKey&&(this.lastGuidanceKey=u.guidanceKey,this.emit("guidance",{key:u.guidanceKey})),u.ready&&this.stateValue==="positioning"&&(this.fired=!0,this.captureCompleteAt=u.at,this.fire(e))}async fire(e){let{options:t}=this,r=this.scheduler;r?.stop(),this.reportGate(!0);let i=r?.stats()??{degradeCount:0,meanDetectMs:0},a=[...this.carriedMeans,...i.meanDetectMs>0?[i.meanDetectMs]:[]];t.telemetry?.({type:"fired",timeToGateMs:this.now()-this.positioningStartedAt,degradeCount:this.carriedDegrade+i.degradeCount,meanDetectMs:a.length===0?0:a.reduce((y,v)=>y+v,0)/a.length});let s=t.mode??"clip",o=t.rankKeyframes?.()&&B?B.default(this,e).catch(()=>this.collectKeyframes(e)):this.collectKeyframes(e);if(s==="photo"){let y=this.watchRotation(e,null),v=await o;if(y(),e!==this.attempt)return;if(v===null){this.fail("generic",{phase:"keyframes"});return}let O=await this.provenance({n:0,meanGapMs:0,stdGapMs:0,captureLatencyMs:null},!1);if(e!==this.attempt)return;this.finishCapture({keyframe:v.blob,previewDataUrl:v.previewDataUrl,...O});return}this.setState("recording");let c=this.stream;if(c===null){this.fail("generic",{phase:"recording"});return}let l=t.screenRamp?.(),d=ie(l),u=null;o.then(y=>{u=y},()=>{});let p=()=>{e===this.attempt&&u!==null&&this.emit("frozen",{previewDataUrl:u.previewDataUrl})},m=ne(l,V),f=null,g,M=0;try{let y=this.recordTake(e,c,l,m,void 0).then(E=>E,E=>({failed:E})),[v,O]=await Promise.all([y,o]);if(g=O,e!==this.attempt)return;if("failed"in v){if(v.failed.kind==="cliptoolarge")throw v.failed;L(v.failed.requestedMimeType??"")}else f=v,N(v.clip,m)?v.clip.stats===null&&L(v.clip.requestedMimeType??""):p();if(f===null||N(f.clip,m)){M=1,t.telemetry?.({type:"clip_retake",reason:f===null?"error":f.clip.stats===null?"unreadable":"short"});let E=null;try{E=await this.recordTake(e,c,l,m,p)}catch(De){if(f===null)throw De}if(e!==this.attempt)return;E!==null&&(f===null||Ee(E.clip,f.clip))&&(f=E),E===null&&p()}}catch(y){if(e!==this.attempt)return;let v=y.kind;this.fail(v==="cliptoolarge"?"cliptoolarge":"recorder",{phase:"recording",name:k(y)});return}if(f===null){this.fail("recorder",{phase:"recording"});return}let{clip:h,rvfc:b,report:S,watched:I}=f;if(R(h.blob)){this.fail("cliptoolarge",{phase:"recording"});return}if(g===null){this.fail("generic",{phase:"keyframes"});return}let Ae=await this.provenance(b,d,I);e===this.attempt&&this.finishCapture({clip:h.blob,clipMimeType:h.mimeType,...h.stats?{clipStats:h.stats}:{},clipRetakes:M,keyframe:g.blob,previewDataUrl:g.previewDataUrl,...S!==void 0&&S.rendered.length>0?{screenRamp:S}:{},...Ae})}async recordTake(e,t,r,i,a){let s=this.options.createRecorder?.()??new A({now:()=>this.now()}),o=ke(this.options.video),c=ae(r,{paint:p=>{(p===null||e===this.attempt)&&this.emit("ramp",{colour:p})},now:()=>this.now(),frames:o.latest});this.ramp=c;let l=()=>{o.stop(),c.stop(),this.ramp===c&&(this.ramp=null)},d=this.watchRotation(e,s),u=ee();try{return{clip:await s.record(t,a,()=>c.started(this.now()),i,o),rvfc:o.stats(),report:c.report(),watched:u.stop()}}finally{u.stop(),d(),l()}}async provenance(e,t,r={}){let i=this.trackProvenance;if(i===null)return{};let a,s=new Promise(d=>{a=setTimeout(()=>d(null),tt)}),o=await Promise.race([i,s]),c=o===null?null:await Promise.race([this.openEnvironment,s]);if(clearTimeout(a),o===null)return{};let l={...c,...r};return{provenance:{..._e(o,e,t),...Object.keys(l).length>0?{env:l}:{}}}}isLandscape(){let e=this.options.video;return this.uprightGuard&&e.videoWidth>e.videoHeight}holdUpright(e){this.gate?.reset(),this.emit("checks",{engine:"v3",progress:0,q:0,factors:{presence:0,single:1,centering:0,size:0,pose:0,sharpness:0,exposure:0,motion:0},attempt:e}),this.lastGuidanceKey!==H&&(this.lastGuidanceKey=H,this.emit("guidance",{key:H}))}watchRotation(e,t){if(!this.uprightGuard)return()=>{};let r=this.options.video,i=()=>{if(e!==this.attempt||t!==null&&this.stateValue!=="recording"){o();return}r.videoWidth>0&&this.isLandscape()&&(o(),this.abortRecording(e,t))},a=setInterval(i,Je);r.addEventListener?.("resize",i);let s=!1;function o(){s||(s=!0,clearInterval(a),r.removeEventListener?.("resize",i))}return o}abortRecording(e,t){if(e!==this.attempt)return;this.attempt+=1;let r=this.attempt;try{t?.stop()}catch{}this.ramp?.stop(),this.ramp=null,this.fired=!1,this.captureCompleteAt=null,this.gate=new _(this.options.thresholds??{}),this.blockStats=new w,this.lastGateSnapshotAt=this.now(),this.lastGuidanceKey=null,this.setState("positioning"),this.positioningStartedAt=this.now(),this.holdUpright(r),this.startScheduler(r)}async collectKeyframes(e){let t=this.options.captureKeyframe??(a=>this.defaultKeyframe(a)),r=et/(K-1),i=null;for(let a=0;a<K;a+=1){if(e!==this.attempt)return i;try{let s=await t(this.options.video);(i===null||s.sharpness>i.sharpness)&&(i=s)}catch{}a<K-1&&await nt(r)}return i}finishCapture(e){this.stopTracks(),this.setState("captured");let t=this.captureTiming();this.emit("artifacts",t===void 0?e:{...e,timing:t})}captureTiming(){let e={},t=(r,i,a)=>{i!==null&&a!==null&&(e[r]=Math.max(0,Math.round(a-i)))};return t("cameraReadyMs",this.cameraRequestedAt,this.cameraReadyAt),t("faceAcquireMs",this.cameraReadyAt,this.faceAcquiredAt),t("captureMs",this.faceAcquiredAt,this.captureCompleteAt),Object.keys(e).length>0?e:void 0}async defaultKeyframe(e){let t=document.createElement("canvas"),r=await(this.facing==="user"?Me:rt)(e,t),i=t.toDataURL("image/jpeg",.92);return{blob:r,previewDataUrl:i,sharpness:this.centerSharpness(e)}}defaultSnapshot(e,t){try{let r=this.snapshotCanvas??document.createElement("canvas"),i=t/Math.max(1,e.videoWidth),a=Math.max(1,Math.round(e.videoWidth*i)),s=Math.max(1,Math.round(e.videoHeight*i)),o=r.getContext("2d");return o===null?e:(r.width!==a&&(r.width=a),r.height!==s&&(r.height=s),o.drawImage(e,0,0,a,s),this.snapshotCanvas=r,r)}catch{return e}}defaultQuality(e,t){let r=Re(e,t,96);return r===null?we:{sharpness:G(r),exposure:ve(r),meanLuma:fe(r)}}centerSharpness(e){let t=ce(e),r=Re(e,{x:t.width*.25,y:t.height*.25,width:t.width*.5,height:t.height*.5},96);return r===null?0:G(r)}teardownAttempt(){this.scheduler?.stop(),this.scheduler=null,this.reportGate(!0),this.gate=null,this.ramp?.stop(),this.ramp=null,this.stopTracks()}reportGate(e){let t=this.blockStats,r=this.profiler;if(t===null||r===null)return;let i=t.summary();e&&(this.blockStats=null),i.ticks!==0&&this.options.telemetry?.({type:"gate",final:e,activeClass:r.deviceClass,cadenceHz:r.profile.cadenceHz,...i})}stopTracks(){if(this.stream!==null){for(let e of this.stream.getTracks())e.stop();this.stream=null}}fail(e,t,r){this.scheduler?.stop(),this.reportGate(!0),this.stopTracks(),this.setState("error"),this.options.telemetry?.({type:"error",kind:e,fallbackReason:r});let{phase:i,name:a}=t;this.emit("error",{kind:e,retryable:e!=="insecure"&&e!=="unsupported",detail:a===void 0?{phase:i}:{phase:i,name:a}})}setState(e){this.stateValue=e,this.emit("statechange",{state:e})}now(){return this.options.now?.()??performance.now()}},B;function nt(n){return new Promise(e=>setTimeout(e,n))}function at(n){return n instanceof Error?n.message:String(n)}function Re(n,e,t){try{let r=document.createElement("canvas"),i=t/Math.max(1,e.width);r.width=Math.max(1,Math.round(e.width*i)),r.height=Math.max(1,Math.round(e.height*i));let a=r.getContext("2d");return a===null?null:(a.drawImage(n,e.x,e.y,e.width,e.height,0,0,r.width,r.height),a.getImageData(0,0,r.width,r.height))}catch{return null}}function st(n){if(n.enumerateDevices!==void 0)return n.enumerateDevices;if(n.getUserMedia===void 0&&!(typeof navigator>"u"||typeof navigator.mediaDevices?.enumerateDevices!="function"))return()=>navigator.mediaDevices.enumerateDevices()}export{lt as a,V as b,Ge as c,Le as d,Te as e,Fe as f,Ve as g,Ne as h,Ue as i,T as j,Ke as k,N as l,Ee as m,A as n,Me as o,D as p,We as q,_ as r,ze as s,w as t,$e as u,H as v,Je as w,K as x,et as y,tt as z,Ie as A};
|