@sekyro/web 0.1.0-rc.22 → 0.1.0-rc.22.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/background-monitor-GCMNCJMG.js +1 -0
  3. package/dist/camera-trait-HVV5ZEDI.js +1 -0
  4. package/dist/{capture-session-doc-YDUKUN3P.js → capture-session-doc-VSUEDAEN.js} +1 -1
  5. package/dist/{capture-session-v3-CkcuPKSD.d.ts → capture-session-v3-C-Q-21Fm.d.ts} +1 -1
  6. package/dist/{capture-session-v3-TJL-0Muv.d.cts → capture-session-v3-DD-MXSU4.d.cts} +1 -1
  7. package/dist/{chunk-PZYVSLPG.js → chunk-6RJTKX5I.js} +1 -1
  8. package/dist/{chunk-VWGKUQ3C.js → chunk-ACP2ZOVW.js} +1 -1
  9. package/dist/{chunk-MXWLCDFX.js → chunk-AXJ2VWIK.js} +1 -1
  10. package/dist/{chunk-G6LKLN4U.js → chunk-EKEHAFEK.js} +1 -1
  11. package/dist/{chunk-HYGINGDC.js → chunk-FSJPKOCC.js} +1 -1
  12. package/dist/{chunk-Z5D7SZUW.js → chunk-H6REKPZ4.js} +1 -1
  13. package/dist/{chunk-A3FUGHAH.js → chunk-HFCVN6AG.js} +1 -1
  14. package/dist/{chunk-7XT5YDSC.js → chunk-J5IQ6THP.js} +1 -1
  15. package/dist/{chunk-RALQBQPT.js → chunk-NHXLIDQJ.js} +1 -1
  16. package/dist/chunk-PVSYKKMP.js +1 -0
  17. package/dist/{chunk-SX7TUC3V.js → chunk-RJZ5SARR.js} +1 -1
  18. package/dist/{chunk-TJUM65FN.js → chunk-TTD5LQG2.js} +1 -1
  19. package/dist/{chunk-RI3E7GBN.js → chunk-TYJA2XJR.js} +1 -1
  20. package/dist/chunk-V4VFZ7NQ.js +1 -0
  21. package/dist/chunk-XK4CCTLL.js +1 -0
  22. package/dist/{chunk-33KKMPJ5.js → chunk-XLYHT4ZQ.js} +1 -1
  23. package/dist/{chunk-2KTSNAVR.js → chunk-ZGDUIZC2.js} +1 -1
  24. package/dist/client/index.cjs +1 -1
  25. package/dist/client/index.d.cts +3 -3
  26. package/dist/client/index.d.ts +3 -3
  27. package/dist/client/index.js +1 -1
  28. package/dist/core/index.cjs +1 -1
  29. package/dist/core/index.d.cts +3 -3
  30. package/dist/core/index.d.ts +3 -3
  31. package/dist/core/index.js +1 -1
  32. package/dist/core/ocr/worker.js +1 -1
  33. package/dist/core/v3/detect-worker.js +1 -1
  34. package/dist/create-document-capture-D7GUVFWF.js +1 -0
  35. package/dist/create-portrait-capture-VRZZOMJS.js +1 -0
  36. package/dist/{create-verification-DnyHCSu6.d.cts → create-verification-BsZ038gI.d.cts} +3 -3
  37. package/dist/{create-verification-DoISHOqL.d.ts → create-verification-CfSZiPSN.d.ts} +3 -3
  38. package/dist/{detector-scanic-YCDNLCGV.js → detector-scanic-F3Y5X3DF.js} +1 -1
  39. package/dist/{icao-gate-lZ_fHE7k.d.ts → icao-gate-BrnPW_gd.d.ts} +1 -1
  40. package/dist/{icao-gate-BFlSZYCZ.d.cts → icao-gate-Bw0Fxd30.d.cts} +1 -1
  41. package/dist/icao-gate-SO6YJ7RV.js +1 -0
  42. package/dist/{icao-policy-BOcutYdD.d.ts → icao-policy-C14ZKZ7r.d.ts} +2 -2
  43. package/dist/{icao-policy-JZH0UdmD.d.cts → icao-policy-DcaumEDt.d.cts} +2 -2
  44. package/dist/icao-tuning-DCZCMCEQ.js +1 -0
  45. package/dist/index.cjs +1 -1
  46. package/dist/index.d.cts +7 -7
  47. package/dist/index.d.ts +7 -7
  48. package/dist/index.js +1 -1
  49. package/dist/internal/index.cjs +1 -1
  50. package/dist/internal/index.d.cts +16 -12
  51. package/dist/internal/index.d.ts +16 -12
  52. package/dist/internal/index.js +1 -1
  53. package/dist/{landmarker-KB7LVXAU.js → landmarker-3BBP3RBY.js} +1 -1
  54. package/dist/mrz-band-DCXFWDBD.js +1 -0
  55. package/dist/{plan-runner-3ZMV7SFQ.js → plan-runner-5UZYQ2XH.js} +1 -1
  56. package/dist/popup/index.js +1 -1
  57. package/dist/{print-SEWS3VHQ.js → print-4WOMNRBE.js} +1 -1
  58. package/dist/{turnstile-2J3LUHCG.js → turnstile-MX6YN4YH.js} +1 -1
  59. package/dist/{types-DwfyBTte.d.ts → types-ChKVytm_.d.cts} +4 -4
  60. package/dist/{types-DwfyBTte.d.cts → types-ChKVytm_.d.ts} +4 -4
  61. package/package.json +1 -1
  62. package/sbom.cdx.json +10 -10
  63. package/dist/background-monitor-A7FKJOAG.js +0 -1
  64. package/dist/camera-trait-V4UAOPIQ.js +0 -1
  65. package/dist/chunk-32ELI5BZ.js +0 -1
  66. package/dist/chunk-BATJN3VQ.js +0 -1
  67. package/dist/chunk-Z2BIZYZQ.js +0 -1
  68. package/dist/create-document-capture-K6EHRCWN.js +0 -1
  69. package/dist/create-portrait-capture-5VGYZUOK.js +0 -1
  70. package/dist/icao-gate-T3BTOKFJ.js +0 -1
  71. package/dist/icao-tuning-4ETMF53W.js +0 -1
  72. package/dist/mrz-band-VYHOTDHY.js +0 -1
  73. /package/dist/{chunk-53POX7U4.js → chunk-25TEJBSB.js} +0 -0
  74. /package/dist/{chunk-CPUECYAJ.js → chunk-7KXJEF7P.js} +0 -0
  75. /package/dist/{chunk-LJYMZQY2.js → chunk-7TGVXBW6.js} +0 -0
  76. /package/dist/{chunk-TDLIXFDT.js → chunk-BPKDXDDH.js} +0 -0
  77. /package/dist/{chunk-TSA6GHUG.js → chunk-CDDYFUER.js} +0 -0
  78. /package/dist/{chunk-7QZWBDI5.js → chunk-CPK5FYNJ.js} +0 -0
  79. /package/dist/{chunk-FPXL63KZ.js → chunk-FK2DJADA.js} +0 -0
  80. /package/dist/{chunk-GI3UFGRQ.js → chunk-LL3YYUKR.js} +0 -0
  81. /package/dist/{chunk-DK5YPBDQ.js → chunk-LYYLXNA4.js} +0 -0
  82. /package/dist/{chunk-SMKCBUJL.js → chunk-NYRFUVAR.js} +0 -0
  83. /package/dist/{chunk-FSSMUAKC.js → chunk-UBRNDTTD.js} +0 -0
  84. /package/dist/{chunk-POIQGEZM.js → chunk-V5P5P3HY.js} +0 -0
  85. /package/dist/{chunk-DFTCAWMP.js → chunk-VP37FW6C.js} +0 -0
  86. /package/dist/{chunk-2LDOXGY3.js → chunk-XB4KLBHY.js} +0 -0
  87. /package/dist/{chunk-CJHMFPL6.js → chunk-YH7DR3PF.js} +0 -0
  88. /package/dist/{clip-inspect-DLJXVKV6.js → clip-inspect-HZ7N2YOP.js} +0 -0
  89. /package/dist/{keyframe-rank-YAJLYJYF.js → keyframe-rank-R4NPQGN3.js} +0 -0
  90. /package/dist/{scanic-ml-stub-KW7IZHUT.js → scanic-ml-stub-XPNKT2N3.js} +0 -0
  91. /package/dist/{segmenter-USLNBX65.js → segmenter-3CVPTZMM.js} +0 -0
  92. /package/dist/{upload-file-UYXOHCRG.js → upload-file-C4MFKLT3.js} +0 -0
@@ -1 +1 @@
1
- import{a as re,b as ne}from"./chunk-SX7TUC3V.js";import{b as le,c as ce,d as ue}from"./chunk-POIQGEZM.js";import{a as Q,c as Y,e as j,g as $,h as A,k as R,m as J,n as te}from"./chunk-CPUECYAJ.js";import{b as G,c as de,d as L,e as pe}from"./chunk-FPXL63KZ.js";import{a as q,c as z,d as X,e as Z}from"./chunk-TSA6GHUG.js";import{d as ee}from"./chunk-BATJN3VQ.js";import{e as ie,f as ae,h as x,j as se,l as oe}from"./chunk-FSSMUAKC.js";var Ie=[...Q.filter(i=>i.startsWith("video/mp4")),"video/webm;codecs=h264","video/webm;codecs=avc1","video/webm;codecs=vp8","video/webm;codecs=vp9","video/webm"],me=new Set;function De(i){let e=/(?:Chrome|Chromium)\/(\d+)\./.exec(i??"");return e?Number(e[1]):null}function he(i=Oe(),e=globalThis.navigator?.userAgent){if(i===void 0)return"";let t=De(e)===126;for(let r of Ie)if(!(me.has(r)||t&&r.startsWith("video/mp4")))try{if(i(r))return r}catch{}return""}function F(i){i!==""&&me.add(i)}function fe(i){return i.replace(/^video\/x-matroska/i,"video/webm")}function ut(i){let e=/codecs=["']?([^,;"']+)/i.exec(i);return e?e[1].trim():i.split(";")[0].trim()}function Oe(){let i=globalThis.MediaRecorder;return i&&typeof i.isTypeSupported=="function"?e=>i.isTypeSupported(e):void 0}var N=2500,Pe=1e3,xe=1500,ve=25e5,Ge=100,Le=700,Fe=20,Ve=1500,V=null;function Ne(){return V??(V=import("./clip-inspect-DLJXVKV6.js").catch(i=>{throw V=null,i})),V.catch(()=>null)}var S=class extends Error{constructor(e,t){super(t??e),this.kind=e}},Ue=100;function U(i,e){return i.stats===void 0?!1:i.stats===null?!0:i.stats.durationMs<e-Ue}function ge(i,e){return i.stats?e.stats?i.stats.durationMs>e.stats.durationMs:!0:!1}var I=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,n=N,a){let s=he(),o=Ne();return this.recordRaw(e,t,r,n,a,s).then(c=>He(c,o),c=>{throw c instanceof S&&(c.requestedMimeType=s),c})}recordRaw(e,t,r,n,a,s){return this.recorder&&!this.settled?Promise.reject(new S("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:ve}:{videoBitsPerSecond:ve})}catch{try{l=new MediaRecorder(e)}catch{c(new S("unsupported"));return}}this.recorder=l;let d=h=>{this.settled||(this.settled=!0,this.clearTimers(),h())},u=()=>d(()=>{let h=fe(l.mimeType||s||Y),b=new Blob(this.chunks,{type:h});if(b.size===0){c(new S("generic","empty clip"));return}if(A(b)){c(new S("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>$&&d(()=>{try{l.state!=="inactive"&&l.stop()}catch{}c(new S("cliptoolarge"))}))},l.onstop=u,l.onerror=()=>d(()=>c(new S("generic")));let f=this.now();if(r!==void 0||a!==void 0){let h=!1;l.onstart=()=>{if(!(h||this.settled)&&(h=!0,f=this.now(),r!==void 0))try{r()}catch{}}}try{l.start(Pe)}catch{d(()=>c(new S("generic")));return}let v=()=>{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,xe)}else u()},p=this.now();if(a===void 0){this.hardStopTimer=setTimeout(v,n);return}let m=null,y=!1;this.hardStopTimer=setTimeout(v,n+Le),this.pollTimer=setInterval(()=>{if(this.settled||y)return;let h=null;try{h=a.latest()}catch{h=null}let b=h?.presentationTimeMs;b!==void 0&&Number.isFinite(b)&&b>=f&&m===null&&(m=b);let C=m!==null&&b!==void 0&&b-m>=n,E=m===null&&this.now()-p>=n;if(!(!C&&!E)){if(y=!0,this.pollTimer&&clearInterval(this.pollTimer),this.pollTimer=null,E){v();return}this.hardStopTimer&&clearTimeout(this.hardStopTimer),this.hardStopTimer=setTimeout(v,Ge)}},Fe)}))}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(n=>n.stop()),this.stream=null}};async function He(i,e){let t,r=new Promise(l=>{t=setTimeout(()=>l(null),Ve)}),n=await Promise.race([e,r]);if(clearTimeout(t),n===null)return i;let a;try{a=await n.blobBytes(i.blob)}catch{return{...i,stats:null}}let s=n.inspectClipBytes(a);if(s?.container!=="webm")return{...i,stats:s};let o=n.withWebmDuration(a,s.durationMs);if(o===null)return{...i,stats:s};let c=n.inspectClipBytes(o);return c===null||c.frames!==s.frames||c.durationMs!==s.durationMs?{...i,stats:s}:{...i,blob:new Blob([o],{type:i.blob.type}),stats:s}}var Ke=["magenta","yellow","green","blue"];var Be={magenta:"rgb(255, 72, 150)",yellow:"rgb(255, 190, 0)",green:"rgb(0, 238, 175)",blue:"rgb(25, 150, 255)",dark:"rgb(0, 0, 0)"};function ft(i){return Be[i]}var We=4,qe=4,D=i=>typeof i=="number"&&Number.isFinite(i);function be(i){if(typeof i!="object"||i===null)return!1;let e=i;if(typeof e.nonce!="string"||e.nonce.length===0||!Array.isArray(e.colours)||e.colours.length<1||e.colours.length>8||!e.colours.every(r=>Ke.includes(r))||!Array.isArray(e.onsetsMs)||e.onsetsMs.length!==e.colours.length)return!1;let t=-1;for(let r of e.onsetsMs){if(!D(r)||r<0||r<=t)return!1;t=r}return!(!D(e.holdMs)||e.holdMs<=0||!D(e.endMs)||e.endMs<=t||!D(e.clipMs)||e.clipMs<e.endMs||e.clipMs>8e3)}function ye(i,e){return be(i)?Math.max(e,Math.ceil(i.clipMs)):e}function Me(i,e){let t=e.now??(()=>performance.now()),r=be(i)?i:void 0,n=[],a=null,s=null,o=null,c=!1,l=null,d=p=>{l=p;try{e.paint(p)}catch{}},u=p=>{let m=e.frames?.()??null;return m!==null&&o!==null?m.mediaTimeMs+(p-m.presentationTimeMs)-o:p-(s??p)},f=(p,m,y=0)=>{if(c)return;let h=Math.max(0,p-u(t()));a=setTimeout(()=>{if(a=null,!c){if(y<We&&u(t())<p-qe){f(p,m,y+1);return}m()}},h)},v=p=>{if(r===void 0)return;let m=r.endMs;if(p>=r.colours.length){f(m,()=>d(null));return}let y=r.onsetsMs[p],h=p+1<r.onsetsMs.length?r.onsetsMs[p+1]:m;f(y,()=>{let b=u(t());if(b>m){l!==null&&d(null);return}let C=r.colours[p];d(C);let E=n.length===0?0:n[n.length-1].tMs;n.push({tMs:Math.max(E,Math.round(b)),colour:C});let M=y+r.holdMs;if(M<h){f(M,()=>{if(u(t())>m){l!==null&&d(null);return}d("dark"),v(p+1)});return}v(p+1)})};return{started(p){if(r===void 0||c||s!==null)return;s=p;let m=e.frames?.()??null;o=m===null?null:m.mediaTimeMs+(p-m.presentationTimeMs),v(0)},stop(){c||(c=!0,a!==null&&clearTimeout(a),a=null,l!==null&&d(null))},report(){return r===void 0?void 0:{nonce:r.nonce,rendered:[...n]}}}}function Se(i,e,t=.92){return new Promise((r,n)=>{let a=i.videoWidth,s=i.videoHeight;if(!a||!s){n(new Error("video-not-ready"));return}let o=e.getContext("2d");if(!o){n(new Error("no-2d-context"));return}e.width=a,e.height=s,o.scale(-1,1),o.drawImage(i,-a,0),e.toBlob(c=>c?r(c):n(new Error("empty-keyframe")),"image/jpeg",t)})}var O=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 ze=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}),_=i=>Math.min(1,Math.max(0,i)),k=class{constructor(e={}){this.p=0;this.lastTickAt=null;this.lastCenter=null;this.velocityEma=0;this.qWindow=[];this.lastSizeDirection="ideal";this.t={...ze,...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:n}=e,a=this.lastTickAt===null?0:Math.max(0,(n-this.lastTickAt)/1e3);this.lastTickAt=n;let s={presence:0,single:1,centering:0,size:0,pose:0,sharpness:_(r.sharpness),exposure:_(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,n)}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=_(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:n,q:o}),this.qWindow=this.qWindow.filter(d=>d.at>=n-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((f,v)=>v!==u)}let l=this.p>=1&&c.every(d=>d>=this.t.Q_GOOD);return{at:n,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:n}=e,a={x:t.frameWidth/2,y:t.frameHeight/2},s=Math.min(t.frameWidth,t.frameHeight),o=n!==void 0?{x:(n.left.x+n.right.x)/2,y:(n.left.y+n.right.y)/2}:{x:r.x+r.width/2,y:r.y+r.height/2-this.t.BOX_EYE_OFFSET_FACTOR*r.height},c=n!==void 0?Math.hypot(n.right.x-n.left.x,n.right.y-n.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-_(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 f;u<this.t.SIZE_HARD_MIN||u>this.t.SIZE_HARD_MAX?f=0:u<this.t.SIZE_IDEAL_MIN?f=(u-this.t.SIZE_HARD_MIN)/(this.t.SIZE_IDEAL_MIN-this.t.SIZE_HARD_MIN):u>this.t.SIZE_IDEAL_MAX?f=(this.t.SIZE_HARD_MAX-u)/(this.t.SIZE_HARD_MAX-this.t.SIZE_IDEAL_MAX):f=1;let v=1;if(n!==void 0){let p=Math.abs(Math.atan2(n.right.y-n.left.y,n.right.x-n.left.x))*180/Math.PI;v=1-_(p/this.t.ROLL_MAX_DEG)}return{center:o,iod:c,centering:d,size:f,pose:v}}motionOf(e,t,r){let n=this.lastCenter;if(this.lastCenter={...e,at:r},n===null||t<=0)return 1;let a=(r-n.at)/1e3;if(a<=0)return 1;let s=Math.hypot(e.x-n.x,e.y-n.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-_(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 n=[["size",this.sizeGuidance()],["centering","fcv3.center_face"],["pose","fcv3.straighten"],["exposure",this.exposureGuidance(t)],["sharpness","fcv3.steady_camera"],["motion","fcv3.hold_still"]],a=n[0];for(let s of n)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=(G[0]+G[1])/2;return e.meanLuma<t?"fcv3.more_light":"fcv3.too_bright"}};var Xe=["single","size","centering","pose","exposure","sharpness","motion"];function Ze(i){if(i.accepted)return null;if(i.factors.presence<=0)return"no_face";let e="single";for(let t of Xe)i.factors[t]<i.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 n=this.blocked[r]??{count:0,ms:0};n.count+=1,n.ms+=t,this.blocked[r]=n}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 Qe=["obs","manycam","virtual","snap camera","xsplit","droidcam","iriun","camo"],Ye=[/^(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 je(i){let e=(i??"").trim().toLowerCase();return e.length===0?"unknown":Qe.some(t=>e.includes(t))?"known_virtual":Ye.some(t=>t.test(e))?"platform":"unknown"}function Te(i){if(typeof i!="function")return!1;try{return/\{\s*\[native code\]\s*\}\s*$/.test(Function.prototype.toString.call(i))}catch{return!1}}function $e(i=globalThis){return Te(i.navigator?.mediaDevices?.getUserMedia)&&Te(i.MediaStreamTrack?.prototype?.getSettings)}async function Je(i,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(i)));return Array.from(r.subarray(0,8),n=>n.toString(16).padStart(2,"0")).join("")}catch{return}}async function Ce(i,e=globalThis){let t={};try{t=typeof i.getSettings=="function"?i.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 n;try{n=i.label}catch{n=void 0}return{trackSettings:r,capabilitiesPresent:typeof i.getCapabilities=="function",labelClass:je(n),prototypesIntact:$e(e)}}var H=i=>Math.round(i*100)/100;function Ee(i){let e=i,t=typeof e?.requestVideoFrameCallback=="function",r=null,n=null,a=0,s=0,o=0,c=0,l=0,d=0,u=()=>{!t||e?.requestVideoFrameCallback===void 0||(r=e.requestVideoFrameCallback((f,v)=>{if(r=null,!t)return;let p=v.presentationTime;if(n!==null){let m=p-n.presentationTimeMs;s+=1;let y=m-o;o+=y/s,c+=y*(m-o)}typeof v.captureTime=="number"&&Number.isFinite(v.captureTime)&&(l+=p-v.captureTime,d+=1),a+=1,n={mediaTimeMs:v.mediaTime*1e3,presentationTimeMs:p},u()}))};return u(),{latest:()=>n,stats:()=>({n:a,meanGapMs:s===0?0:H(o),stdGapMs:s<2?0:H(Math.sqrt(c/(s-1))),captureLatencyMs:d===0?null:H(l/d)}),stop:()=>{t&&(t=!1,r!==null&&e?.cancelVideoFrameCallback?.(r),r=null)}}}function _e(i,e,t){return{...i,rvfc:e,rampPainter:t}}var et=1e3,K="fcv3.hold_upright",tt=200,B=4,rt=600,nt=1e3,Re={sharpness:1,exposure:1,meanLuma:128};function it(i,e){return e.width=i.videoWidth,e.height=i.videoHeight,e.getContext("2d").drawImage(i,0,0),new Promise((t,r)=>e.toBlob(n=>n?t(n):r(new Error("empty-keyframe")),"image/jpeg",.92))}function at(){return z()==="phone"}var ke=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.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??at)(),this.setState("preflight");let r=j();if(r!=="OK"){this.fail(r==="INSECURE_CONTEXT"?"insecure":"unsupported",{phase:"preflight"});return}this.setState("acquiring");let n=t.getUserMedia??(l=>navigator.mediaDevices.getUserMedia(l)),a;this.cameraRequestedAt=this.now();try{let{facingMode:l,...d}=q(X(),this.facing).video;a=await ne(this.facing,d,{getUserMedia:n,enumerateDevices:lt(t)})}catch(l){if(e!==this.attempt)return;if(l instanceof re){this.fail("backcamera",{phase:"acquiring",name:R(l)});return}this.fail(J(l),{phase:"acquiring",name:R(l)});return}if(ee(a),te(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:Ce(s).catch(()=>null),this.facing=Z(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&&se()?async()=>{try{return await oe.create(t.createWorker(),l)}catch{return x(l)}}:()=>x(l)),u;try{u=await d()}catch(f){e===this.attempt&&this.fail("models",{phase:"models",name:R(f)},f instanceof ie?f.fallbackReason:ot(f));return}if(e!==this.attempt){u.destroy();return}this.detector=u,this.options.telemetry?.({type:"detector",tier:u.tier,fallbackReason:u.fallbackReason})}let o=le(),c=t.deviceClass??ce(o);this.profiler=new ue(c),this.options.telemetry?.({type:"profile",staticClass:c,activeClass:this.profiler.deviceClass,simd:o.simd}),this.gate=new k(t.thresholds??{}),this.blockStats=new w,this.lastGateSnapshotAt=this.now(),t.rankKeyframes?.()&&import("./keyframe-rank-YAJLYJYF.js").then(l=>W=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 n=this.scheduler.stats();this.carriedDegrade+=n.degradeCount,n.meanDetectMs>0&&this.carriedMeans.push(n.meanDetectMs),this.scheduler.stop()}let r=new O({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:n}=this,a=this.options.video;if(e!==this.attempt||t===null||r===null||n===null||this.fired||a.videoWidth===0)return;if(this.isLandscape()){this.holdUpright(e);return}let s=n.deviceClass,o=this.now(),c=this.options.makeSnapshot?.(a,n.profile.inputWidth)??this.defaultSnapshot(a,n.profile.inputWidth),l=null;try{l=await t.detect(c,a.videoWidth,a.videoHeight)}catch{l=null}if(e!==this.attempt||this.fired)return;n.record(this.now()-o),n.deviceClass!==s&&this.startScheduler(e);let d=l===null?Re: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>=et&&(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 n=r?.stats()??{degradeCount:0,meanDetectMs:0},a=[...this.carriedMeans,...n.meanDetectMs>0?[n.meanDetectMs]:[]];t.telemetry?.({type:"fired",timeToGateMs:this.now()-this.positioningStartedAt,degradeCount:this.carriedDegrade+n.degradeCount,meanDetectMs:a.length===0?0:a.reduce((M,g)=>M+g,0)/a.length});let s=t.mode??"clip",o=t.rankKeyframes?.()&&W?W.default(this,e).catch(()=>this.collectKeyframes(e)):this.collectKeyframes(e);if(s==="photo"){let M=this.watchRotation(e,null),g=await o;if(M(),e!==this.attempt)return;if(g===null){this.fail("generic",{phase:"keyframes"});return}let P=await this.provenance({n:0,meanGapMs:0,stdGapMs:0,captureLatencyMs:null},!1);if(e!==this.attempt)return;this.finishCapture({keyframe:g.blob,previewDataUrl:g.previewDataUrl,...P});return}this.setState("recording");let c=this.stream;if(c===null){this.fail("generic",{phase:"recording"});return}let l=t.screenRamp?.(),d=l!==void 0,u=null;o.then(M=>{u=M},()=>{});let f=()=>{e===this.attempt&&u!==null&&this.emit("frozen",{previewDataUrl:u.previewDataUrl})},v=ye(l,N),p=null,m,y=0;try{let M=this.recordTake(e,c,l,v,void 0).then(T=>T,T=>({failed:T})),[g,P]=await Promise.all([M,o]);if(m=P,e!==this.attempt)return;if("failed"in g){if(g.failed.kind==="cliptoolarge")throw g.failed;F(g.failed.requestedMimeType??"")}else p=g,U(g.clip,v)?g.clip.stats===null&&F(g.clip.requestedMimeType??""):f();if(p===null||U(p.clip,v)){y=1,t.telemetry?.({type:"clip_retake",reason:p===null?"error":p.clip.stats===null?"unreadable":"short"});let T=null;try{T=await this.recordTake(e,c,l,v,f)}catch(Ae){if(p===null)throw Ae}if(e!==this.attempt)return;T!==null&&(p===null||ge(T.clip,p.clip))&&(p=T),T===null&&f()}}catch(M){if(e!==this.attempt)return;let g=M.kind;this.fail(g==="cliptoolarge"?"cliptoolarge":"recorder",{phase:"recording",name:R(M)});return}if(p===null){this.fail("recorder",{phase:"recording"});return}let{clip:h,rvfc:b,report:C}=p;if(A(h.blob)){this.fail("cliptoolarge",{phase:"recording"});return}if(m===null){this.fail("generic",{phase:"keyframes"});return}let E=await this.provenance(b,d);e===this.attempt&&this.finishCapture({clip:h.blob,clipMimeType:h.mimeType,...h.stats?{clipStats:h.stats}:{},clipRetakes:y,keyframe:m.blob,previewDataUrl:m.previewDataUrl,...C!==void 0&&C.rendered.length>0?{screenRamp:C}:{},...E})}async recordTake(e,t,r,n,a){let s=this.options.createRecorder?.()??new I({now:()=>this.now()}),o=Ee(this.options.video),c=Me(r,{paint:u=>{(u===null||e===this.attempt)&&this.emit("ramp",{colour:u})},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);try{return{clip:await s.record(t,a,()=>c.started(this.now()),n,o),rvfc:o.stats(),report:c.report()}}finally{d(),l()}}async provenance(e,t){let r=this.trackProvenance;if(r===null)return{};let n,a=new Promise(o=>{n=setTimeout(()=>o(null),nt)}),s=await Promise.race([r,a]);return clearTimeout(n),s===null?{}:{provenance:_e(s,e,t)}}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!==K&&(this.lastGuidanceKey=K,this.emit("guidance",{key:K}))}watchRotation(e,t){if(!this.uprightGuard)return()=>{};let r=this.options.video,n=()=>{if(e!==this.attempt||t!==null&&this.stateValue!=="recording"){o();return}r.videoWidth>0&&this.isLandscape()&&(o(),this.abortRecording(e,t))},a=setInterval(n,tt);r.addEventListener?.("resize",n);let s=!1;function o(){s||(s=!0,clearInterval(a),r.removeEventListener?.("resize",n))}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 k(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=rt/(B-1),n=null;for(let a=0;a<B;a+=1){if(e!==this.attempt)return n;try{let s=await t(this.options.video);(n===null||s.sharpness>n.sharpness)&&(n=s)}catch{}a<B-1&&await st(r)}return n}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,n,a)=>{n!==null&&a!==null&&(e[r]=Math.max(0,Math.round(a-n)))};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"?Se:it)(e,t),n=t.toDataURL("image/jpeg",.92);return{blob:r,previewDataUrl:n,sharpness:this.centerSharpness(e)}}defaultSnapshot(e,t){try{let r=this.snapshotCanvas??document.createElement("canvas"),n=t/Math.max(1,e.videoWidth),a=Math.max(1,Math.round(e.videoWidth*n)),s=Math.max(1,Math.round(e.videoHeight*n)),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=we(e,t,96);return r===null?Re:{sharpness:L(r),exposure:pe(r),meanLuma:de(r)}}centerSharpness(e){let t=ae(e),r=we(e,{x:t.width*.25,y:t.height*.25,width:t.width*.5,height:t.height*.5},96);return r===null?0:L(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 n=t.summary();e&&(this.blockStats=null),n.ticks!==0&&this.options.telemetry?.({type:"gate",final:e,activeClass:r.deviceClass,cadenceHz:r.profile.cadenceHz,...n})}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:n,name:a}=t;this.emit("error",{kind:e,retryable:e!=="insecure"&&e!=="unsupported",detail:a===void 0?{phase:n}:{phase:n,name:a}})}setState(e){this.stateValue=e,this.emit("statechange",{state:e})}now(){return this.options.now?.()??performance.now()}},W;function st(i){return new Promise(e=>setTimeout(e,i))}function ot(i){return i instanceof Error?i.message:String(i)}function we(i,e,t){try{let r=document.createElement("canvas"),n=t/Math.max(1,e.width);r.width=Math.max(1,Math.round(e.width*n)),r.height=Math.max(1,Math.round(e.height*n));let a=r.getContext("2d");return a===null?null:(a.drawImage(i,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 lt(i){if(i.enumerateDevices!==void 0)return i.enumerateDevices;if(i.getUserMedia===void 0&&!(typeof navigator>"u"||typeof navigator.mediaDevices?.enumerateDevices!="function"))return()=>navigator.mediaDevices.enumerateDevices()}export{ut as a,N as b,Pe as c,xe as d,ve as e,Ge as f,Le as g,Fe as h,Ve as i,S as j,Ue as k,U as l,ge as m,I as n,Ke as o,ft as p,Se as q,O as r,ze as s,k as t,Ze as u,w as v,et as w,K as x,tt as y,B as z,rt as A,nt as B,ke as C};
1
+ import{a as re,b as ne}from"./chunk-RJZ5SARR.js";import{b as le,c as ce,d as ue}from"./chunk-V5P5P3HY.js";import{a as Q,c as Y,e as j,g as $,h as A,k as R,m as J,n as te}from"./chunk-7KXJEF7P.js";import{b as G,c as de,d as L,e as pe}from"./chunk-FK2DJADA.js";import{a as q,c as z,d as X,e as Z}from"./chunk-CDDYFUER.js";import{d as ee}from"./chunk-XK4CCTLL.js";import{e as ie,f as ae,h as x,j as se,l as oe}from"./chunk-UBRNDTTD.js";var Ie=[...Q.filter(i=>i.startsWith("video/mp4")),"video/webm;codecs=h264","video/webm;codecs=avc1","video/webm;codecs=vp8","video/webm;codecs=vp9","video/webm"],me=new Set;function De(i){let e=/(?:Chrome|Chromium)\/(\d+)\./.exec(i??"");return e?Number(e[1]):null}function he(i=Oe(),e=globalThis.navigator?.userAgent){if(i===void 0)return"";let t=De(e)===126;for(let r of Ie)if(!(me.has(r)||t&&r.startsWith("video/mp4")))try{if(i(r))return r}catch{}return""}function F(i){i!==""&&me.add(i)}function fe(i){return i.replace(/^video\/x-matroska/i,"video/webm")}function ut(i){let e=/codecs=["']?([^,;"']+)/i.exec(i);return e?e[1].trim():i.split(";")[0].trim()}function Oe(){let i=globalThis.MediaRecorder;return i&&typeof i.isTypeSupported=="function"?e=>i.isTypeSupported(e):void 0}var N=2500,Pe=1e3,xe=1500,ve=25e5,Ge=100,Le=700,Fe=20,Ve=1500,V=null;function Ne(){return V??(V=import("./clip-inspect-HZ7N2YOP.js").catch(i=>{throw V=null,i})),V.catch(()=>null)}var S=class extends Error{constructor(e,t){super(t??e),this.kind=e}},Ue=100;function U(i,e){return i.stats===void 0?!1:i.stats===null?!0:i.stats.durationMs<e-Ue}function ge(i,e){return i.stats?e.stats?i.stats.durationMs>e.stats.durationMs:!0:!1}var I=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,n=N,a){let s=he(),o=Ne();return this.recordRaw(e,t,r,n,a,s).then(c=>He(c,o),c=>{throw c instanceof S&&(c.requestedMimeType=s),c})}recordRaw(e,t,r,n,a,s){return this.recorder&&!this.settled?Promise.reject(new S("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:ve}:{videoBitsPerSecond:ve})}catch{try{l=new MediaRecorder(e)}catch{c(new S("unsupported"));return}}this.recorder=l;let d=h=>{this.settled||(this.settled=!0,this.clearTimers(),h())},u=()=>d(()=>{let h=fe(l.mimeType||s||Y),b=new Blob(this.chunks,{type:h});if(b.size===0){c(new S("generic","empty clip"));return}if(A(b)){c(new S("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>$&&d(()=>{try{l.state!=="inactive"&&l.stop()}catch{}c(new S("cliptoolarge"))}))},l.onstop=u,l.onerror=()=>d(()=>c(new S("generic")));let f=this.now();if(r!==void 0||a!==void 0){let h=!1;l.onstart=()=>{if(!(h||this.settled)&&(h=!0,f=this.now(),r!==void 0))try{r()}catch{}}}try{l.start(Pe)}catch{d(()=>c(new S("generic")));return}let v=()=>{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,xe)}else u()},p=this.now();if(a===void 0){this.hardStopTimer=setTimeout(v,n);return}let m=null,y=!1;this.hardStopTimer=setTimeout(v,n+Le),this.pollTimer=setInterval(()=>{if(this.settled||y)return;let h=null;try{h=a.latest()}catch{h=null}let b=h?.presentationTimeMs;b!==void 0&&Number.isFinite(b)&&b>=f&&m===null&&(m=b);let C=m!==null&&b!==void 0&&b-m>=n,E=m===null&&this.now()-p>=n;if(!(!C&&!E)){if(y=!0,this.pollTimer&&clearInterval(this.pollTimer),this.pollTimer=null,E){v();return}this.hardStopTimer&&clearTimeout(this.hardStopTimer),this.hardStopTimer=setTimeout(v,Ge)}},Fe)}))}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(n=>n.stop()),this.stream=null}};async function He(i,e){let t,r=new Promise(l=>{t=setTimeout(()=>l(null),Ve)}),n=await Promise.race([e,r]);if(clearTimeout(t),n===null)return i;let a;try{a=await n.blobBytes(i.blob)}catch{return{...i,stats:null}}let s=n.inspectClipBytes(a);if(s?.container!=="webm")return{...i,stats:s};let o=n.withWebmDuration(a,s.durationMs);if(o===null)return{...i,stats:s};let c=n.inspectClipBytes(o);return c===null||c.frames!==s.frames||c.durationMs!==s.durationMs?{...i,stats:s}:{...i,blob:new Blob([o],{type:i.blob.type}),stats:s}}var Ke=["magenta","yellow","green","blue"];var Be={magenta:"rgb(255, 72, 150)",yellow:"rgb(255, 190, 0)",green:"rgb(0, 238, 175)",blue:"rgb(25, 150, 255)",dark:"rgb(0, 0, 0)"};function ft(i){return Be[i]}var We=4,qe=4,D=i=>typeof i=="number"&&Number.isFinite(i);function be(i){if(typeof i!="object"||i===null)return!1;let e=i;if(typeof e.nonce!="string"||e.nonce.length===0||!Array.isArray(e.colours)||e.colours.length<1||e.colours.length>8||!e.colours.every(r=>Ke.includes(r))||!Array.isArray(e.onsetsMs)||e.onsetsMs.length!==e.colours.length)return!1;let t=-1;for(let r of e.onsetsMs){if(!D(r)||r<0||r<=t)return!1;t=r}return!(!D(e.holdMs)||e.holdMs<=0||!D(e.endMs)||e.endMs<=t||!D(e.clipMs)||e.clipMs<e.endMs||e.clipMs>8e3)}function ye(i,e){return be(i)?Math.max(e,Math.ceil(i.clipMs)):e}function Me(i,e){let t=e.now??(()=>performance.now()),r=be(i)?i:void 0,n=[],a=null,s=null,o=null,c=!1,l=null,d=p=>{l=p;try{e.paint(p)}catch{}},u=p=>{let m=e.frames?.()??null;return m!==null&&o!==null?m.mediaTimeMs+(p-m.presentationTimeMs)-o:p-(s??p)},f=(p,m,y=0)=>{if(c)return;let h=Math.max(0,p-u(t()));a=setTimeout(()=>{if(a=null,!c){if(y<We&&u(t())<p-qe){f(p,m,y+1);return}m()}},h)},v=p=>{if(r===void 0)return;let m=r.endMs;if(p>=r.colours.length){f(m,()=>d(null));return}let y=r.onsetsMs[p],h=p+1<r.onsetsMs.length?r.onsetsMs[p+1]:m;f(y,()=>{let b=u(t());if(b>m){l!==null&&d(null);return}let C=r.colours[p];d(C);let E=n.length===0?0:n[n.length-1].tMs;n.push({tMs:Math.max(E,Math.round(b)),colour:C});let M=y+r.holdMs;if(M<h){f(M,()=>{if(u(t())>m){l!==null&&d(null);return}d("dark"),v(p+1)});return}v(p+1)})};return{started(p){if(r===void 0||c||s!==null)return;s=p;let m=e.frames?.()??null;o=m===null?null:m.mediaTimeMs+(p-m.presentationTimeMs),v(0)},stop(){c||(c=!0,a!==null&&clearTimeout(a),a=null,l!==null&&d(null))},report(){return r===void 0?void 0:{nonce:r.nonce,rendered:[...n]}}}}function Se(i,e,t=.92){return new Promise((r,n)=>{let a=i.videoWidth,s=i.videoHeight;if(!a||!s){n(new Error("video-not-ready"));return}let o=e.getContext("2d");if(!o){n(new Error("no-2d-context"));return}e.width=a,e.height=s,o.scale(-1,1),o.drawImage(i,-a,0),e.toBlob(c=>c?r(c):n(new Error("empty-keyframe")),"image/jpeg",t)})}var O=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 ze=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}),_=i=>Math.min(1,Math.max(0,i)),k=class{constructor(e={}){this.p=0;this.lastTickAt=null;this.lastCenter=null;this.velocityEma=0;this.qWindow=[];this.lastSizeDirection="ideal";this.t={...ze,...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:n}=e,a=this.lastTickAt===null?0:Math.max(0,(n-this.lastTickAt)/1e3);this.lastTickAt=n;let s={presence:0,single:1,centering:0,size:0,pose:0,sharpness:_(r.sharpness),exposure:_(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,n)}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=_(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:n,q:o}),this.qWindow=this.qWindow.filter(d=>d.at>=n-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((f,v)=>v!==u)}let l=this.p>=1&&c.every(d=>d>=this.t.Q_GOOD);return{at:n,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:n}=e,a={x:t.frameWidth/2,y:t.frameHeight/2},s=Math.min(t.frameWidth,t.frameHeight),o=n!==void 0?{x:(n.left.x+n.right.x)/2,y:(n.left.y+n.right.y)/2}:{x:r.x+r.width/2,y:r.y+r.height/2-this.t.BOX_EYE_OFFSET_FACTOR*r.height},c=n!==void 0?Math.hypot(n.right.x-n.left.x,n.right.y-n.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-_(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 f;u<this.t.SIZE_HARD_MIN||u>this.t.SIZE_HARD_MAX?f=0:u<this.t.SIZE_IDEAL_MIN?f=(u-this.t.SIZE_HARD_MIN)/(this.t.SIZE_IDEAL_MIN-this.t.SIZE_HARD_MIN):u>this.t.SIZE_IDEAL_MAX?f=(this.t.SIZE_HARD_MAX-u)/(this.t.SIZE_HARD_MAX-this.t.SIZE_IDEAL_MAX):f=1;let v=1;if(n!==void 0){let p=Math.abs(Math.atan2(n.right.y-n.left.y,n.right.x-n.left.x))*180/Math.PI;v=1-_(p/this.t.ROLL_MAX_DEG)}return{center:o,iod:c,centering:d,size:f,pose:v}}motionOf(e,t,r){let n=this.lastCenter;if(this.lastCenter={...e,at:r},n===null||t<=0)return 1;let a=(r-n.at)/1e3;if(a<=0)return 1;let s=Math.hypot(e.x-n.x,e.y-n.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-_(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 n=[["size",this.sizeGuidance()],["centering","fcv3.center_face"],["pose","fcv3.straighten"],["exposure",this.exposureGuidance(t)],["sharpness","fcv3.steady_camera"],["motion","fcv3.hold_still"]],a=n[0];for(let s of n)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=(G[0]+G[1])/2;return e.meanLuma<t?"fcv3.more_light":"fcv3.too_bright"}};var Xe=["single","size","centering","pose","exposure","sharpness","motion"];function Ze(i){if(i.accepted)return null;if(i.factors.presence<=0)return"no_face";let e="single";for(let t of Xe)i.factors[t]<i.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 n=this.blocked[r]??{count:0,ms:0};n.count+=1,n.ms+=t,this.blocked[r]=n}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 Qe=["obs","manycam","virtual","snap camera","xsplit","droidcam","iriun","camo"],Ye=[/^(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 je(i){let e=(i??"").trim().toLowerCase();return e.length===0?"unknown":Qe.some(t=>e.includes(t))?"known_virtual":Ye.some(t=>t.test(e))?"platform":"unknown"}function Te(i){if(typeof i!="function")return!1;try{return/\{\s*\[native code\]\s*\}\s*$/.test(Function.prototype.toString.call(i))}catch{return!1}}function $e(i=globalThis){return Te(i.navigator?.mediaDevices?.getUserMedia)&&Te(i.MediaStreamTrack?.prototype?.getSettings)}async function Je(i,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(i)));return Array.from(r.subarray(0,8),n=>n.toString(16).padStart(2,"0")).join("")}catch{return}}async function Ce(i,e=globalThis){let t={};try{t=typeof i.getSettings=="function"?i.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 n;try{n=i.label}catch{n=void 0}return{trackSettings:r,capabilitiesPresent:typeof i.getCapabilities=="function",labelClass:je(n),prototypesIntact:$e(e)}}var H=i=>Math.round(i*100)/100;function Ee(i){let e=i,t=typeof e?.requestVideoFrameCallback=="function",r=null,n=null,a=0,s=0,o=0,c=0,l=0,d=0,u=()=>{!t||e?.requestVideoFrameCallback===void 0||(r=e.requestVideoFrameCallback((f,v)=>{if(r=null,!t)return;let p=v.presentationTime;if(n!==null){let m=p-n.presentationTimeMs;s+=1;let y=m-o;o+=y/s,c+=y*(m-o)}typeof v.captureTime=="number"&&Number.isFinite(v.captureTime)&&(l+=p-v.captureTime,d+=1),a+=1,n={mediaTimeMs:v.mediaTime*1e3,presentationTimeMs:p},u()}))};return u(),{latest:()=>n,stats:()=>({n:a,meanGapMs:s===0?0:H(o),stdGapMs:s<2?0:H(Math.sqrt(c/(s-1))),captureLatencyMs:d===0?null:H(l/d)}),stop:()=>{t&&(t=!1,r!==null&&e?.cancelVideoFrameCallback?.(r),r=null)}}}function _e(i,e,t){return{...i,rvfc:e,rampPainter:t}}var et=1e3,K="fcv3.hold_upright",tt=200,B=4,rt=600,nt=1e3,Re={sharpness:1,exposure:1,meanLuma:128};function it(i,e){return e.width=i.videoWidth,e.height=i.videoHeight,e.getContext("2d").drawImage(i,0,0),new Promise((t,r)=>e.toBlob(n=>n?t(n):r(new Error("empty-keyframe")),"image/jpeg",.92))}function at(){return z()==="phone"}var ke=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.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??at)(),this.setState("preflight");let r=j();if(r!=="OK"){this.fail(r==="INSECURE_CONTEXT"?"insecure":"unsupported",{phase:"preflight"});return}this.setState("acquiring");let n=t.getUserMedia??(l=>navigator.mediaDevices.getUserMedia(l)),a;this.cameraRequestedAt=this.now();try{let{facingMode:l,...d}=q(X(),this.facing).video;a=await ne(this.facing,d,{getUserMedia:n,enumerateDevices:lt(t)})}catch(l){if(e!==this.attempt)return;if(l instanceof re){this.fail("backcamera",{phase:"acquiring",name:R(l)});return}this.fail(J(l),{phase:"acquiring",name:R(l)});return}if(ee(a),te(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:Ce(s).catch(()=>null),this.facing=Z(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&&se()?async()=>{try{return await oe.create(t.createWorker(),l)}catch{return x(l)}}:()=>x(l)),u;try{u=await d()}catch(f){e===this.attempt&&this.fail("models",{phase:"models",name:R(f)},f instanceof ie?f.fallbackReason:ot(f));return}if(e!==this.attempt){u.destroy();return}this.detector=u,this.options.telemetry?.({type:"detector",tier:u.tier,fallbackReason:u.fallbackReason})}let o=le(),c=t.deviceClass??ce(o);this.profiler=new ue(c),this.options.telemetry?.({type:"profile",staticClass:c,activeClass:this.profiler.deviceClass,simd:o.simd}),this.gate=new k(t.thresholds??{}),this.blockStats=new w,this.lastGateSnapshotAt=this.now(),t.rankKeyframes?.()&&import("./keyframe-rank-R4NPQGN3.js").then(l=>W=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 n=this.scheduler.stats();this.carriedDegrade+=n.degradeCount,n.meanDetectMs>0&&this.carriedMeans.push(n.meanDetectMs),this.scheduler.stop()}let r=new O({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:n}=this,a=this.options.video;if(e!==this.attempt||t===null||r===null||n===null||this.fired||a.videoWidth===0)return;if(this.isLandscape()){this.holdUpright(e);return}let s=n.deviceClass,o=this.now(),c=this.options.makeSnapshot?.(a,n.profile.inputWidth)??this.defaultSnapshot(a,n.profile.inputWidth),l=null;try{l=await t.detect(c,a.videoWidth,a.videoHeight)}catch{l=null}if(e!==this.attempt||this.fired)return;n.record(this.now()-o),n.deviceClass!==s&&this.startScheduler(e);let d=l===null?Re: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>=et&&(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 n=r?.stats()??{degradeCount:0,meanDetectMs:0},a=[...this.carriedMeans,...n.meanDetectMs>0?[n.meanDetectMs]:[]];t.telemetry?.({type:"fired",timeToGateMs:this.now()-this.positioningStartedAt,degradeCount:this.carriedDegrade+n.degradeCount,meanDetectMs:a.length===0?0:a.reduce((M,g)=>M+g,0)/a.length});let s=t.mode??"clip",o=t.rankKeyframes?.()&&W?W.default(this,e).catch(()=>this.collectKeyframes(e)):this.collectKeyframes(e);if(s==="photo"){let M=this.watchRotation(e,null),g=await o;if(M(),e!==this.attempt)return;if(g===null){this.fail("generic",{phase:"keyframes"});return}let P=await this.provenance({n:0,meanGapMs:0,stdGapMs:0,captureLatencyMs:null},!1);if(e!==this.attempt)return;this.finishCapture({keyframe:g.blob,previewDataUrl:g.previewDataUrl,...P});return}this.setState("recording");let c=this.stream;if(c===null){this.fail("generic",{phase:"recording"});return}let l=t.screenRamp?.(),d=l!==void 0,u=null;o.then(M=>{u=M},()=>{});let f=()=>{e===this.attempt&&u!==null&&this.emit("frozen",{previewDataUrl:u.previewDataUrl})},v=ye(l,N),p=null,m,y=0;try{let M=this.recordTake(e,c,l,v,void 0).then(T=>T,T=>({failed:T})),[g,P]=await Promise.all([M,o]);if(m=P,e!==this.attempt)return;if("failed"in g){if(g.failed.kind==="cliptoolarge")throw g.failed;F(g.failed.requestedMimeType??"")}else p=g,U(g.clip,v)?g.clip.stats===null&&F(g.clip.requestedMimeType??""):f();if(p===null||U(p.clip,v)){y=1,t.telemetry?.({type:"clip_retake",reason:p===null?"error":p.clip.stats===null?"unreadable":"short"});let T=null;try{T=await this.recordTake(e,c,l,v,f)}catch(Ae){if(p===null)throw Ae}if(e!==this.attempt)return;T!==null&&(p===null||ge(T.clip,p.clip))&&(p=T),T===null&&f()}}catch(M){if(e!==this.attempt)return;let g=M.kind;this.fail(g==="cliptoolarge"?"cliptoolarge":"recorder",{phase:"recording",name:R(M)});return}if(p===null){this.fail("recorder",{phase:"recording"});return}let{clip:h,rvfc:b,report:C}=p;if(A(h.blob)){this.fail("cliptoolarge",{phase:"recording"});return}if(m===null){this.fail("generic",{phase:"keyframes"});return}let E=await this.provenance(b,d);e===this.attempt&&this.finishCapture({clip:h.blob,clipMimeType:h.mimeType,...h.stats?{clipStats:h.stats}:{},clipRetakes:y,keyframe:m.blob,previewDataUrl:m.previewDataUrl,...C!==void 0&&C.rendered.length>0?{screenRamp:C}:{},...E})}async recordTake(e,t,r,n,a){let s=this.options.createRecorder?.()??new I({now:()=>this.now()}),o=Ee(this.options.video),c=Me(r,{paint:u=>{(u===null||e===this.attempt)&&this.emit("ramp",{colour:u})},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);try{return{clip:await s.record(t,a,()=>c.started(this.now()),n,o),rvfc:o.stats(),report:c.report()}}finally{d(),l()}}async provenance(e,t){let r=this.trackProvenance;if(r===null)return{};let n,a=new Promise(o=>{n=setTimeout(()=>o(null),nt)}),s=await Promise.race([r,a]);return clearTimeout(n),s===null?{}:{provenance:_e(s,e,t)}}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!==K&&(this.lastGuidanceKey=K,this.emit("guidance",{key:K}))}watchRotation(e,t){if(!this.uprightGuard)return()=>{};let r=this.options.video,n=()=>{if(e!==this.attempt||t!==null&&this.stateValue!=="recording"){o();return}r.videoWidth>0&&this.isLandscape()&&(o(),this.abortRecording(e,t))},a=setInterval(n,tt);r.addEventListener?.("resize",n);let s=!1;function o(){s||(s=!0,clearInterval(a),r.removeEventListener?.("resize",n))}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 k(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=rt/(B-1),n=null;for(let a=0;a<B;a+=1){if(e!==this.attempt)return n;try{let s=await t(this.options.video);(n===null||s.sharpness>n.sharpness)&&(n=s)}catch{}a<B-1&&await st(r)}return n}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,n,a)=>{n!==null&&a!==null&&(e[r]=Math.max(0,Math.round(a-n)))};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"?Se:it)(e,t),n=t.toDataURL("image/jpeg",.92);return{blob:r,previewDataUrl:n,sharpness:this.centerSharpness(e)}}defaultSnapshot(e,t){try{let r=this.snapshotCanvas??document.createElement("canvas"),n=t/Math.max(1,e.videoWidth),a=Math.max(1,Math.round(e.videoWidth*n)),s=Math.max(1,Math.round(e.videoHeight*n)),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=we(e,t,96);return r===null?Re:{sharpness:L(r),exposure:pe(r),meanLuma:de(r)}}centerSharpness(e){let t=ae(e),r=we(e,{x:t.width*.25,y:t.height*.25,width:t.width*.5,height:t.height*.5},96);return r===null?0:L(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 n=t.summary();e&&(this.blockStats=null),n.ticks!==0&&this.options.telemetry?.({type:"gate",final:e,activeClass:r.deviceClass,cadenceHz:r.profile.cadenceHz,...n})}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:n,name:a}=t;this.emit("error",{kind:e,retryable:e!=="insecure"&&e!=="unsupported",detail:a===void 0?{phase:n}:{phase:n,name:a}})}setState(e){this.stateValue=e,this.emit("statechange",{state:e})}now(){return this.options.now?.()??performance.now()}},W;function st(i){return new Promise(e=>setTimeout(e,i))}function ot(i){return i instanceof Error?i.message:String(i)}function we(i,e,t){try{let r=document.createElement("canvas"),n=t/Math.max(1,e.width);r.width=Math.max(1,Math.round(e.width*n)),r.height=Math.max(1,Math.round(e.height*n));let a=r.getContext("2d");return a===null?null:(a.drawImage(i,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 lt(i){if(i.enumerateDevices!==void 0)return i.enumerateDevices;if(i.getUserMedia===void 0&&!(typeof navigator>"u"||typeof navigator.mediaDevices?.enumerateDevices!="function"))return()=>navigator.mediaDevices.enumerateDevices()}export{ut as a,N as b,Pe as c,xe as d,ve as e,Ge as f,Le as g,Fe as h,Ve as i,S as j,Ue as k,U as l,ge as m,I as n,Ke as o,ft as p,Se as q,O as r,ze as s,k as t,Ze as u,w as v,et as w,K as x,tt as y,B as z,rt as A,nt as B,ke as C};
@@ -1 +1 @@
1
- import{a as Y,d as ee,e as O,f as te,g as ne}from"./chunk-7QZWBDI5.js";import{C as X,a as j}from"./chunk-7XT5YDSC.js";import{f as Q,l as Z}from"./chunk-CPUECYAJ.js";import{c as $}from"./chunk-TSA6GHUG.js";import{c as J,h as C}from"./chunk-FSSMUAKC.js";var ue=12e4,re=13e4,le=3e3,fe=1200,P=Symbol.for("@sekyro/web.preload.v1");function g(){let e=globalThis;return e[P]??(e[P]=new Map),e[P]}function S(e){let n=(e??J).replace(/\/+$/,"");return n===""?"/":n}function se(e){let n=g(),r=n.get(e);return r===void 0&&(r={status:"idle",promise:null,scheduled:null,detectorPromise:null,detector:null,listeners:new Set},n.set(e,r)),r}function A(e,n){if(e.status!==n){e.status=n;for(let r of[...e.listeners])r(n)}}var x=e=>C({preferred:["blaze"],v3AssetBaseUrl:e,blazeInitTimeoutMs:ue}),F=x;function Pe(e){F=e??x}function Ae(){for(let e of g().values())e.detector?.destroy();g().clear(),F=x}function pe(){return typeof window<"u"&&typeof navigator<"u"&&typeof navigator.mediaDevices?.getUserMedia=="function"}function me(){return navigator.connection?.saveData===!0}function ve(e){let n=window;if(typeof n.requestIdleCallback=="function"){let s=n.requestIdleCallback(e,{timeout:le});return()=>n.cancelIdleCallback?.(s)}let r=setTimeout(e,fe);return()=>clearTimeout(r)}function ge(e,n){let r,s=new Promise(i=>{r=i}),m=!1,d=()=>{},u={promise:s,settle:i=>{m||(m=!0,d(),e.scheduled===u&&(e.scheduled=null),r(i))}};return e.scheduled=u,d=ve(()=>{m||u.settle(I(e,n))}),s}function I(e,n){if((e.status==="loading"||e.status==="ready")&&e.promise!==null)return e.promise;A(e,"loading");let r=new Promise(i=>i(F(n)));e.detectorPromise=r;let s,m=new Promise((i,f)=>{s=setTimeout(()=>{r.then(h=>h.destroy(),()=>{}),f(new Error(`detector preload exceeded ${re} ms`))},re)}),u=Promise.race([r,m]).then(i=>e.detectorPromise!==r?(i.destroy(),e.status):(e.detector=i,A(e,"ready"),"ready"),i=>(e.detectorPromise===r&&(e.detectorPromise=null,e.detector=null,A(e,"failed"),console.warn("[@sekyro/web] face-detector preload failed:",i)),e.status)).finally(()=>clearTimeout(s));return e.promise=u,e.scheduled?.settle(u),u}function we(e={}){if(!pe())return Promise.resolve("idle");let n=S(e.assetBaseUrl),r=se(n);return e.respectSaveData===!0&&me()?Promise.resolve(r.status):(r.status==="loading"||r.status==="ready")&&r.promise!==null?r.promise:e.idle===!0?r.scheduled?.promise??ge(r,n):I(r,n)}function ke(e){return g().get(S(e))?.status??"idle"}function De(e,n){let r=se(S(n));return r.listeners.add(e),()=>{r.listeners.delete(e)}}function _e(e){let n=g().get(S(e));n!==void 0&&(n.scheduled?.settle("idle"),n.detector?.destroy(),n.detector=null,n.detectorPromise=null,n.promise=null,A(n,"idle"))}function he(e){return{get tier(){return e.tier},get fallbackReason(){return e.fallbackReason},detect:(...n)=>e.detect(...n),destroy:()=>{}}}function oe(e){let n=S(e),r=g().get(n);if(!(r===void 0||r.detector===null&&r.detectorPromise===null&&r.scheduled===null))return async()=>{r.scheduled!==null&&I(r,n);let s=r.promise;for(;r.detector===null&&s!==null&&(await s,r.promise!==s);)s=r.promise;return r.detector!==null?he(r.detector):C({v3AssetBaseUrl:n})}}function Ce(e){switch(e){case"fcv3.no_face":case"fcv3.center_face":case"fcv3.straighten":return"center";case"fcv3.come_closer":return"closer";case"fcv3.move_back":return"farther";case"fcv3.more_light":case"fcv3.too_bright":return"light";case"fcv3.hold_still":case"fcv3.steady_camera":return"still";case"fcv3.hold_upright":return"upright";case"fcv3.one_face":return"one_face";default:return null}}function Se(e){switch(e){case"preflight":case"acquiring":return"starting";case"positioning":return"gating";default:return e}}function ie(e){switch(e){case"permission":case"notfound":case"inuse":case"insecure":case"unsupported":return e;case"backcamera":return"notfound";default:{let n=e;return"generic"}}}function Le(e,n,r){if(r===void 0)return{kind:ie(e),retryable:n};let s=Z(r.name);return{kind:ie(e),retryable:n,detail:{...s!==void 0?{name:s}:{},phase:r.phase,engineKind:e}}}var ye=new Set(["captured","uploading","checking"]);function Ee(e,n={},r,s=()=>"self",m=()=>{},d){let u=n.now??(()=>performance.now()),i=n.canChooseFacing??ee,f="user",h=te(),p=s(),l=Y(),B=!Q(),H=n.engineOptions,ae=H?.createDetector===void 0&&H?.createWorker===void 0?{createDetector:()=>{let t=oe(e.assetBaseUrl);return t!==void 0?t():C({v3AssetBaseUrl:e.assetBaseUrl})}}:{},U={video:e.video,mode:B?"photo":"clip",rankKeyframes:r,facingMode:void 0,v3AssetBaseUrl:e.assetBaseUrl,screenRamp:()=>p==="self"&&l.count("ramp")>0?m():void 0,...n.engineOptions??{},...ae},o=n.createEngine?.(U)??new X(U),v="idle",L=null,y=0,w=!1,k="full",E=null,b=null,D=0,_=0,K=()=>{e.video.videoWidth>0&&e.video.videoHeight>0&&(D=e.video.videoWidth,_=e.video.videoHeight)},V=ne({enabled:e.keepScreenAwake!==!1}),M=t=>{v=t,V.setActive(t==="starting"||t==="gating"||t==="recording"),l.emit("state",t)},R=()=>l.emit("gate",{progress:y,hint:L,faceDetected:w}),G=()=>{let t=o.animations??"full";t!==k&&(k=t,l.emit("profile",{animations:k}))},de=[o.on("statechange",({state:t})=>{let a=Se(t);a==="starting"&&v!=="starting"&&(L=null,y=0,w=!1,E=null,b=null,D=0,_=0),M(a),G(),a==="recording"&&(K(),E=u(),L="hold",y=1,R())}),o.on("checks",t=>{K(),y=t.progress,w=t.factors.presence>0,R(),G()}),o.on("guidance",({key:t})=>{L=Ce(t),R()}),o.on("frozen",({previewDataUrl:t})=>{b=u(),l.emit("frozen",{previewDataUrl:t})}),o.on("ramp",t=>l.emit("ramp",t)),o.on("artifacts",t=>{if(v!=="captured")return;let a=$(),c=t.clipStats,q=c!==void 0?Math.round(c.durationMs):E!==null&&b!==null?Math.max(0,Math.round(b-E)):void 0,N=c!==void 0&&c.frames>1&&c.durationMs>0?Math.round(c.frames*1e4/c.durationMs)/10:void 0;l.emit("captured",{keyframe:t.keyframe,...t.clip!==void 0?{clip:t.clip}:{},...t.clipMimeType!==void 0?{clipMime:t.clipMimeType}:{},width:e.video.videoWidth||D,height:e.video.videoHeight||_,...q!==void 0?{clipMs:q}:{},...c!==void 0?{clipFrames:c.frames}:{},...N!==void 0?{fps:N}:{},...t.clipRetakes!==void 0?{clipRetakes:t.clipRetakes}:{},...t.clipMimeType!==void 0?{codec:j(t.clipMimeType)}:{},captureChannel:a==="desktop"?"desktop":"mobile",formFactor:a,...B?{degraded:"NO_RECORDER"}:{},engine:"v3",facingMode:o.facingMode,mode:p,...t.timing,...t.screenRamp!==void 0?{screenRamp:t.screenRamp}:{},...t.provenance!==void 0?{provenance:t.provenance}:{}})}),o.on("error",({kind:t,retryable:a,detail:c})=>{t==="backcamera"&&ce()||l.emit("error",Le(t,a,c))})],z=!1;function ce(){return T||z||p!=="assisted"||d===void 0||d.session()!=="choice"?!1:(z=!0,d.onModeChange("self"),p="self",f=O("self"),M("mode_switch"),o.restart(f),!0)}let W=async()=>d!==void 0&&d.session()==="choice"&&await i().catch(()=>!1),T=!1;return{handle:{get state(){return v},get captureMode(){return s()},get facingMode(){return o.facingMode??f},on:(t,a)=>l.on(t,a),start:t=>(p=s(),h.facing(p,e.facing),f=h.facing(p,t?.facing),o.start({facingMode:f})),retry:()=>o.retry(),switchCamera:()=>h.refuseSwitch(s()),canSwitchCaptureMode:W,setCaptureMode:async t=>{if(t===s()||!await W()||T||ye.has(v)||d===void 0)return!1;d.onModeChange(t),p=t;let a=O(t);return f=a,v==="idle"||(M("mode_switch"),o.restart(a)),!0},destroy:()=>{T=!0;for(let t of de)t();V.setActive(!1),o.destroy(),l.clear()}},setFlowState:t=>{v!==t&&M(t)}}}function ze(e){return Ee(e).handle}export{ue as a,re as b,Pe as c,Ae as d,we as e,ke as f,De as g,_e as h,oe as i,Ce as j,Se as k,ie as l,Le as m,Ee as n,ze as o};
1
+ import{a as Y,d as ee,e as O,f as te,g as ne}from"./chunk-CPK5FYNJ.js";import{C as X,a as j}from"./chunk-J5IQ6THP.js";import{f as Q,l as Z}from"./chunk-7KXJEF7P.js";import{c as $}from"./chunk-CDDYFUER.js";import{c as J,h as C}from"./chunk-UBRNDTTD.js";var ue=12e4,re=13e4,le=3e3,fe=1200,P=Symbol.for("@sekyro/web.preload.v1");function g(){let e=globalThis;return e[P]??(e[P]=new Map),e[P]}function S(e){let n=(e??J).replace(/\/+$/,"");return n===""?"/":n}function se(e){let n=g(),r=n.get(e);return r===void 0&&(r={status:"idle",promise:null,scheduled:null,detectorPromise:null,detector:null,listeners:new Set},n.set(e,r)),r}function A(e,n){if(e.status!==n){e.status=n;for(let r of[...e.listeners])r(n)}}var x=e=>C({preferred:["blaze"],v3AssetBaseUrl:e,blazeInitTimeoutMs:ue}),F=x;function Pe(e){F=e??x}function Ae(){for(let e of g().values())e.detector?.destroy();g().clear(),F=x}function pe(){return typeof window<"u"&&typeof navigator<"u"&&typeof navigator.mediaDevices?.getUserMedia=="function"}function me(){return navigator.connection?.saveData===!0}function ve(e){let n=window;if(typeof n.requestIdleCallback=="function"){let s=n.requestIdleCallback(e,{timeout:le});return()=>n.cancelIdleCallback?.(s)}let r=setTimeout(e,fe);return()=>clearTimeout(r)}function ge(e,n){let r,s=new Promise(i=>{r=i}),m=!1,d=()=>{},u={promise:s,settle:i=>{m||(m=!0,d(),e.scheduled===u&&(e.scheduled=null),r(i))}};return e.scheduled=u,d=ve(()=>{m||u.settle(I(e,n))}),s}function I(e,n){if((e.status==="loading"||e.status==="ready")&&e.promise!==null)return e.promise;A(e,"loading");let r=new Promise(i=>i(F(n)));e.detectorPromise=r;let s,m=new Promise((i,f)=>{s=setTimeout(()=>{r.then(h=>h.destroy(),()=>{}),f(new Error(`detector preload exceeded ${re} ms`))},re)}),u=Promise.race([r,m]).then(i=>e.detectorPromise!==r?(i.destroy(),e.status):(e.detector=i,A(e,"ready"),"ready"),i=>(e.detectorPromise===r&&(e.detectorPromise=null,e.detector=null,A(e,"failed"),console.warn("[@sekyro/web] face-detector preload failed:",i)),e.status)).finally(()=>clearTimeout(s));return e.promise=u,e.scheduled?.settle(u),u}function we(e={}){if(!pe())return Promise.resolve("idle");let n=S(e.assetBaseUrl),r=se(n);return e.respectSaveData===!0&&me()?Promise.resolve(r.status):(r.status==="loading"||r.status==="ready")&&r.promise!==null?r.promise:e.idle===!0?r.scheduled?.promise??ge(r,n):I(r,n)}function ke(e){return g().get(S(e))?.status??"idle"}function De(e,n){let r=se(S(n));return r.listeners.add(e),()=>{r.listeners.delete(e)}}function _e(e){let n=g().get(S(e));n!==void 0&&(n.scheduled?.settle("idle"),n.detector?.destroy(),n.detector=null,n.detectorPromise=null,n.promise=null,A(n,"idle"))}function he(e){return{get tier(){return e.tier},get fallbackReason(){return e.fallbackReason},detect:(...n)=>e.detect(...n),destroy:()=>{}}}function oe(e){let n=S(e),r=g().get(n);if(!(r===void 0||r.detector===null&&r.detectorPromise===null&&r.scheduled===null))return async()=>{r.scheduled!==null&&I(r,n);let s=r.promise;for(;r.detector===null&&s!==null&&(await s,r.promise!==s);)s=r.promise;return r.detector!==null?he(r.detector):C({v3AssetBaseUrl:n})}}function Ce(e){switch(e){case"fcv3.no_face":case"fcv3.center_face":case"fcv3.straighten":return"center";case"fcv3.come_closer":return"closer";case"fcv3.move_back":return"farther";case"fcv3.more_light":case"fcv3.too_bright":return"light";case"fcv3.hold_still":case"fcv3.steady_camera":return"still";case"fcv3.hold_upright":return"upright";case"fcv3.one_face":return"one_face";default:return null}}function Se(e){switch(e){case"preflight":case"acquiring":return"starting";case"positioning":return"gating";default:return e}}function ie(e){switch(e){case"permission":case"notfound":case"inuse":case"insecure":case"unsupported":return e;case"backcamera":return"notfound";default:{let n=e;return"generic"}}}function Le(e,n,r){if(r===void 0)return{kind:ie(e),retryable:n};let s=Z(r.name);return{kind:ie(e),retryable:n,detail:{...s!==void 0?{name:s}:{},phase:r.phase,engineKind:e}}}var ye=new Set(["captured","uploading","checking"]);function Ee(e,n={},r,s=()=>"self",m=()=>{},d){let u=n.now??(()=>performance.now()),i=n.canChooseFacing??ee,f="user",h=te(),p=s(),l=Y(),B=!Q(),H=n.engineOptions,ae=H?.createDetector===void 0&&H?.createWorker===void 0?{createDetector:()=>{let t=oe(e.assetBaseUrl);return t!==void 0?t():C({v3AssetBaseUrl:e.assetBaseUrl})}}:{},U={video:e.video,mode:B?"photo":"clip",rankKeyframes:r,facingMode:void 0,v3AssetBaseUrl:e.assetBaseUrl,screenRamp:()=>p==="self"&&l.count("ramp")>0?m():void 0,...n.engineOptions??{},...ae},o=n.createEngine?.(U)??new X(U),v="idle",L=null,y=0,w=!1,k="full",E=null,b=null,D=0,_=0,K=()=>{e.video.videoWidth>0&&e.video.videoHeight>0&&(D=e.video.videoWidth,_=e.video.videoHeight)},V=ne({enabled:e.keepScreenAwake!==!1}),M=t=>{v=t,V.setActive(t==="starting"||t==="gating"||t==="recording"),l.emit("state",t)},R=()=>l.emit("gate",{progress:y,hint:L,faceDetected:w}),G=()=>{let t=o.animations??"full";t!==k&&(k=t,l.emit("profile",{animations:k}))},de=[o.on("statechange",({state:t})=>{let a=Se(t);a==="starting"&&v!=="starting"&&(L=null,y=0,w=!1,E=null,b=null,D=0,_=0),M(a),G(),a==="recording"&&(K(),E=u(),L="hold",y=1,R())}),o.on("checks",t=>{K(),y=t.progress,w=t.factors.presence>0,R(),G()}),o.on("guidance",({key:t})=>{L=Ce(t),R()}),o.on("frozen",({previewDataUrl:t})=>{b=u(),l.emit("frozen",{previewDataUrl:t})}),o.on("ramp",t=>l.emit("ramp",t)),o.on("artifacts",t=>{if(v!=="captured")return;let a=$(),c=t.clipStats,q=c!==void 0?Math.round(c.durationMs):E!==null&&b!==null?Math.max(0,Math.round(b-E)):void 0,N=c!==void 0&&c.frames>1&&c.durationMs>0?Math.round(c.frames*1e4/c.durationMs)/10:void 0;l.emit("captured",{keyframe:t.keyframe,...t.clip!==void 0?{clip:t.clip}:{},...t.clipMimeType!==void 0?{clipMime:t.clipMimeType}:{},width:e.video.videoWidth||D,height:e.video.videoHeight||_,...q!==void 0?{clipMs:q}:{},...c!==void 0?{clipFrames:c.frames}:{},...N!==void 0?{fps:N}:{},...t.clipRetakes!==void 0?{clipRetakes:t.clipRetakes}:{},...t.clipMimeType!==void 0?{codec:j(t.clipMimeType)}:{},captureChannel:a==="desktop"?"desktop":"mobile",formFactor:a,...B?{degraded:"NO_RECORDER"}:{},engine:"v3",facingMode:o.facingMode,mode:p,...t.timing,...t.screenRamp!==void 0?{screenRamp:t.screenRamp}:{},...t.provenance!==void 0?{provenance:t.provenance}:{}})}),o.on("error",({kind:t,retryable:a,detail:c})=>{t==="backcamera"&&ce()||l.emit("error",Le(t,a,c))})],z=!1;function ce(){return T||z||p!=="assisted"||d===void 0||d.session()!=="choice"?!1:(z=!0,d.onModeChange("self"),p="self",f=O("self"),M("mode_switch"),o.restart(f),!0)}let W=async()=>d!==void 0&&d.session()==="choice"&&await i().catch(()=>!1),T=!1;return{handle:{get state(){return v},get captureMode(){return s()},get facingMode(){return o.facingMode??f},on:(t,a)=>l.on(t,a),start:t=>(p=s(),h.facing(p,e.facing),f=h.facing(p,t?.facing),o.start({facingMode:f})),retry:()=>o.retry(),switchCamera:()=>h.refuseSwitch(s()),canSwitchCaptureMode:W,setCaptureMode:async t=>{if(t===s()||!await W()||T||ye.has(v)||d===void 0)return!1;d.onModeChange(t),p=t;let a=O(t);return f=a,v==="idle"||(M("mode_switch"),o.restart(a)),!0},destroy:()=>{T=!0;for(let t of de)t();V.setActive(!1),o.destroy(),l.clear()}},setFlowState:t=>{v!==t&&M(t)}}}function ze(e){return Ee(e).handle}export{ue as a,re as b,Pe as c,Ae as d,we as e,ke as f,De as g,_e as h,oe as i,Ce as j,Se as k,ie as l,Le as m,Ee as n,ze as o};
@@ -0,0 +1 @@
1
+ import{A as Fe,B as Be,a as Te,b as Ve,c as De,d as L,e as W,f as j,g as Ne,h as V,i as He,j as R,k as D,l as O,m as se,n as E,o as U,p as F,q as Z,r as Le,s as Ue}from"./chunk-6RJTKX5I.js";import{n as we}from"./chunk-NHXLIDQJ.js";import{a as Me}from"./chunk-CPK5FYNJ.js";import{c as re,g as Ee,h as $}from"./chunk-ZGDUIZC2.js";import{c as Ie,d as ie}from"./chunk-CDDYFUER.js";function J(e){return e.idNumberBound??e.nniBound}function B(e){return e===void 0?void 0:e.idNumberFromDocument??e.nniFromDocument}function Ge(e){let t=e.idNumberMasked??e.nniMasked;return typeof t=="string"&&t!==""?t:void 0}var ht="https://api.sekyro.ai",St=5e3,yt=24e4,gt=3e4,_t=1500,Ct=10;function kt(e){return new Promise(t=>setTimeout(t,e))}function Pt(){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 r=0;r<16;r+=1)t[r]=Math.floor(Math.random()*256);t[6]=(t[6]??0)&15|64,t[8]=(t[8]??0)&63|128;let o=[...t].map(r=>r.toString(16).padStart(2,"0")).join("");return`${o.slice(0,8)}-${o.slice(8,12)}-${o.slice(12,16)}-${o.slice(16,20)}-${o.slice(20)}`}function hn(e){return bt(e,{})}function bt(e,t){let o=e.apiOrigin??ht,r=e.autoRetry??!0,i=e.rearm??"auto",s=t.client??new Ee({apiOrigin:o,sessionToken:e.clientToken,fetch:e.fetch}),u=t.sleep??kt,c=t.uuid??Pt,p=t.getTurnstileToken??((n,a)=>import("./turnstile-MX6YN4YH.js").then(l=>l.executeTurnstile(n,a))),m=Me(),S=null,x=null,d=!1,_=new AbortController,f=null,M=null,G=null,K=()=>G??Le(f),pe=()=>Ue(Z(f),K()),v=n=>{f=n,m.emit("view",n),S?.onView(n)},C=()=>f!==null?Promise.resolve(f):(M??(M=s.getSession().then(n=>(v(n),n)).finally(()=>{M=null})),M),A=async()=>{let n=await s.getSession();return v(n),n},Q=async(n,a)=>{n.plan!==void 0?v(n):await A()},X=null,fe=async n=>{let a=await C();if(n||!a.consentRecorded){let l=await s.recordConsent(e.locale);l.plan!==void 0?v(l):f!==null&&v({...f,consentRecorded:!0})}Re(a.turnstileSiteKey)},w=n=>n?.force===!0?fe(!0):(X??(X=fe(!1).finally(()=>{X=null})),X),z={client:s,ensureConsent:n=>w(n),sleep:u,uuid:c,...t.random!==void 0?{random:t.random}:{},onBusy:n=>{d||m.emit("busy",n)}},me=!1,he=null,ee=n=>{if(n.status==="verified"||n.status==="not_verified"||n.status==="review"){if(me)return;me=!0}he=JSON.stringify(n),m.emit("result",n)},tt=n=>{he!==JSON.stringify(n)&&ee(n)},Se=async n=>{let a=f;n&&(a=await A().catch(()=>f));let l=a===null?null:V(a);return l!==null&&!d&&m.emit("method",l),l!==null},ye=null,ge=!1,_e=!1,Ce=()=>Fe(z,(n,a)=>n.submitCheck("population_registry",{},{idempotencyKey:a})),ke=n=>J(n)===!0||B(O(n,"population_registry"))===!0,nt=async()=>{try{let n=await C();if(R(n)||V(n)!==null||D(n)?.checkType!=="population_registry")return;if(!ke(n)&&B(O(n,"population_registry"))===void 0&&(n=await A()),!ke(n)){_e=!0;return}await w(),await Q(await Ce(),"population_registry");let a=f===null?void 0:O(f,"population_registry");if(a?.state==="input_required"&&a.reason==="registry_unavailable"&&j(a)>0){if(await u(St),d)return;await Q(await Ce(),"population_registry")}}catch(n){if(n instanceof re&&(n.code==="check_not_active"||n.code==="step_not_on_path")){await A().catch(()=>{});return}ge=!0;return}f!==null&&R(f)&&ee(U(f,{autoRetry:r}))},Pe=()=>(ye??(ye=nt()),ye),te=t.now??Date.now,T=null,ne=n=>p(n,{signal:_.signal}),be=(n,a)=>n!==null&&n.siteKey===a&&te()-n.at<yt,Re=n=>{if(n===null||d||be(T,n))return;let a=ne(n);a.catch(()=>{}),T={siteKey:n,at:te(),token:a}},ot=async n=>{let a=T;T=null;let l=be(a,n),g=l?a.at:te(),h=l?a.token.catch(()=>ne(n)):ne(n);h.catch(()=>{});let b,Y=new Promise(P=>{b=setTimeout(()=>P("late"),gt)});try{let P=await Promise.race([h.then(y=>({value:y}),()=>null),Y]);return P==="late"?(!d&&T===null&&(T={siteKey:n,at:g,token:h}),null):P===null?null:P.value}finally{clearTimeout(b)}},it=async()=>{let a=(await C()).turnstileSiteKey;if(a===null)return{sandbox:!0};let l=await ot(a);return l===null?{channel:"hosted_web",siteKey:a}:{channel:"hosted_web",siteKey:a,turnstileToken:l}},q=n=>{if(d)return;let a=s.reportCaptureIssue;if(a===void 0)return;let l=n.formFactor;try{l??(l=Ie())}catch{}try{Promise.resolve(a.call(s,{...n,...l!==void 0?{formFactor:l}:{}})).catch(()=>{})}catch{}},k=null,xe=Promise.resolve(),H=0,rt=async()=>{let n=await C();for(let a=0;a<Ct&&!d&&!R(n)&&D(n)===void 0&&W(n).some(l=>l.state==="processing")&&(await u(_t),!d);a+=1)n=await A();return n},st=async(n,a,l)=>{let{capture:g}=n,h=()=>d,b=()=>n.alive&&n.attempt===l,Y=y=>{b()&&g.setFlowState(y)},P=y=>{if(!h()&&(y.status==="unavailable"&&y.reasonCode!==void 0&&!Te(y.reasonCode)&&q({check:"liveness",kind:"unavailable",phase:"upload",engineKind:y.reasonCode,attempt:Math.max(0,n.issues.value)}),ee(y),!!b())){if(y.status==="retry"&&i==="auto"){g.handle.retry();return}g.setFlowState("done")}};if(a.degraded==="NO_RECORDER"){let y=f?.sessionId??(await C().catch(()=>null))?.sessionId??"";P(E(y,"no_recorder"));return}Y("uploading");try{if(await Pe(),h())return;let y=await C(),Ae;if(!R(y)&&V(y)!==null){await Se(!1),P(E(y.sessionId,"method_required"));return}if(!R(y)){if(D(y)?.checkType==="population_registry"){P(E(y.sessionId,_e?"nni_unbound":ge?"network":"registry_unavailable"));return}if(await w(),h())return;Ae=f??y;let oe=await Be({...z,artifacts:a,getAttestation:it,getView:()=>f??y,refreshView:A,applySubmit:Q,onPhase:Y,isCancelled:h,onKeyframePromoted:mt=>{x=mt}});if(h())return;if(oe.kind==="unavailable"){P(E(y.sessionId,oe.reason));return}if(oe.kind==="resync"&&await A(),f!==null&&V(f)!==null){await Se(!1),P(E(y.sessionId,"method_required"));return}y=await rt()}P(U(y,{autoRetry:r,previous:Ae}))}catch{if(h())return;P(E(f?.sessionId??"","network"))}},at=(n,a)=>{let l=n.attempt;H>0&&n.alive&&n.capture.setFlowState("uploading"),H+=1,xe=xe.then(()=>st(n,a,l)).finally(()=>{H-=1,H===0&&S?.onChainIdle()}).catch(()=>{})},Oe=n=>{k?.capture.handle.destroy(),k!==null&&(k.alive=!1);let a=we(n,S?.captureInternals?.(n)??t.capture,()=>f?.capture?.liveness?.keyframe?.rank===!0,pe,()=>f?.capture?.liveness?.screenRamp,{session:()=>Z(f),onModeChange:h=>{G=h}}),l={capture:a,alive:!0,attempt:0,issues:De()};k=l,a.handle.on("error",h=>{q(Ve("liveness",h,l.issues.value))}),a.handle.on("state",h=>{if(l.issues.note(h),h==="starting"){l.attempt+=1,Re(f?.turnstileSiteKey??null);let b=f===null?void 0:D(f)?.checkType;(b==="liveness"||b==="face_match")&&w().catch(()=>{})}}),a.handle.on("captured",h=>{Promise.resolve().then(()=>at(l,h))});let g=a.handle;return{get state(){return g.state},get captureMode(){return g.captureMode},get facingMode(){return g.facingMode},on:(h,b)=>g.on(h,b),start:async h=>{if(f===null&&await C().catch(()=>{}),!!l.alive)return g.start(h)},retry:()=>g.retry(),switchCamera:()=>g.switchCamera(),canSwitchCaptureMode:()=>g.canSwitchCaptureMode(),setCaptureMode:h=>g.setCaptureMode(h),destroy:()=>{l.alive=!1,k===l&&(k=null),g.destroy()}}},ct=async()=>{if(d)return null;try{let n=await C();return d?null:V(n)}catch{return null}},ut=async()=>{if(d)return"self";try{let n=await C();if(d)return"self";let a=Z(n);return a==="choice"?K()??a:a}catch{return"self"}},dt=async()=>{if(d)return!1;try{let n=await C();return d||R(n)||ie()?!1:F(n,D(n))==="phone"||F(n,O(n,"liveness"))==="phone"}catch{return!1}},lt=async()=>{if(d)return!1;try{let n=await C();return!d&&n.returning===!0}catch{return!1}},pt=async n=>{let a=(await C()).plan?.choice,l=a?.options.find(h=>L[h.service]===n);if(!l)throw new RangeError(`method ${String(n)} is not offered`);let g=await s.choose(a.nodeId,l.id);d||v(g)},ve=null,ft=()=>(ve??(ve=import("./plan-runner-5UZYQ2XH.js").then(n=>{let a=n.createPlanRunner({runtime:z,currentView:()=>f,cameraMode:pe,captureModeSwitch:{pick:K,choose:l=>{G=l}},ensureView:C,refreshView:A,ensureConsent:()=>w(),liveness:Oe,stopLiveness:()=>{k!==null&&(k.alive=!1,k.capture.handle.destroy(),k=null)},chainBusy:()=>H>0,destroyed:()=>d,sleep:u,isMobile:ie,now:t.now??Date.now,keptFaceKey:()=>x,setView:v,baseCapture:t.capture,emitStep:l=>{d||m.emit("step",l)},emitResult:tt,reportCaptureIssue:q,documentInternals:t.document,portraitInternals:t.portrait,livePhotoInternals:t.livePhoto,uploadInternals:t.upload});return S=a,a})),ve);return{consent:()=>w(),startRegistry:Pe,methodChoice:ct,selectMethod:pt,reportCameraUnavailable:async n=>{await w();let a=s.reportCameraUnavailable;if(a===void 0)throw new TypeError("this client cannot report a missing camera");let l=await a.call(s,n).catch(g=>{if(g instanceof re&&g.code==="check_out_of_order")return s.getSession();throw g});d||v(l)},reportCaptureIssue:q,mobileRequired:dt,captureMode:ut,chooseCaptureMode:n=>{G=n},get captureChoice(){return K()},returning:lt,liveness:Oe,run:async()=>{if(d)throw new Error("verification destroyed");return(await ft()).run()},currentStep:()=>S?.current()??null,voiceClips:async()=>{if(d)return null;try{let n=await C();return d?null:n.voice??null}catch{return null}},on:(n,a)=>m.on(n,a),destroy:()=>{d=!0,_.abort(),S?.destroy(),k!==null&&(k.alive=!1,k.capture.handle.destroy(),k=null),m.clear()}}}var Ke=["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 Rt=["carte_identite","passport","residence_permit"];function xt(e,t){let o=e.byIssuer?.[t]??e.default;return Rt.filter(r=>o==="*"||o.includes(r))}function _n(e,t=Ke){return[...new Set([...t,...Object.keys(e.byIssuer??{})])].filter(r=>xt(e,r).length>0).sort()}function qe(e){if(e.acceptedDocuments)return e.acceptedDocuments;let t=e.acceptedDocumentTypes?.length?[...e.acceptedDocumentTypes]:["carte_identite","passport"];return{default:[],byIssuer:{MR:t}}}function Cn(e){return/^[A-Z]{2}$/.test(e)?String.fromCodePoint(...[...e].map(t=>127462+t.charCodeAt(0)-65)):""}var Ye=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",sandbox_nni_not_seeded:"sandbox_id_number_not_seeded",missing_nni:"missing_id_number",registry_needs_nni_source:"registry_needs_id_number_source"}),Ot=new Map(Object.entries(Ye)),Pn=new Map(Object.entries(Ye).map(([e,t])=>[t,e]));function We(e){return Ot.get(e)??e}var Mn=["national_number","document_photo","national_eid"],vt=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"]),At=new Set(["supplied_identity","aml_screening","face_dedup","age_estimation"]),ce=["document","population_registry","national_eid"],ue=["phone_otp","email_otp"],$e={identity_method:ce,contact:ue},It=["population_registry","document"],de="platform_unsupported",Mt=new Set(["prefilled","user_entered","prefilled_or_entered"]),wt={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"};function I(e){return e.section??wt[e.checkType]??null}function Et(e,t){let o=e.plan?.choice;if(o===void 0||o.locked)return;let r=o.options.find(i=>i.id!==o.selected&&i.available!==!1&&t.includes(i.service));return r===void 0?void 0:{nodeId:o.nodeId,option:r}}function le(e){let t=e.plan,o=t?.choice;if(t===void 0||o===void 0||o.locked||t.current===null||t.current===o.nodeId||R(e))return null;let r=$e[o.kind]??[...ce,...ue],i=o.options.flatMap(c=>c.available===!1||!r.includes(c.service)?[]:[c.nationalEid!=null?{id:c.id,service:c.service,nationalEid:c.nationalEid}:{id:c.id,service:c.service}]),s=t.steps.find(c=>c.id===t.current)?.service,u=o.selected??i.find(c=>c.service===s)?.id??null;return i.some(c=>c.id!==u)?{nodeId:o.nodeId,kind:o.kind,current:u,options:i}:null}function Je(e){return e==null?[]:e.options.filter(t=>t.id!==e.current)}function Tt(e){let t=e.simulation;if(typeof t!="object"||t===null)return;let{otpCode:o,skipCapture:r}=t;return typeof o=="string"&&o!==""&&typeof r=="boolean"?{otpCode:o,skipCapture:r}:void 0}function Vt(e){let t=(e.plan?.sections??[]).map(s=>({id:s.id,state:s.state})),o={sessionId:se(e.sessionId),orgName:e.orgName,returning:e.returning===!0,consentRecorded:e.consentRecorded,expiresAt:e.expiresAt,sections:t.map(s=>s.id),progress:t,purpose:e.purpose??"identity"};e.branding!==void 0&&(o.branding=e.branding),e.cameraUnavailableHandled===!0&&(o.cameraUnavailableHandled=!0);let r=Tt(e);r!==void 0&&(o.simulation=r);let i=le(e);return i!==null&&(o.switchable=i),o}function Dt(e){let t={attemptsRemaining:j(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 Qe={phone_otp:"phone",email_otp:"email"};function Nt(e,t){let o=Et(e,[t==="phone_otp"?"email_otp":"phone_otp"]);return o===void 0?void 0:Qe[o.option.service]}function Ht(e,t,o,r){let i=t.checkType==="email_otp",s=(i?t.emailOtp:t.otp)??{},u=i?t.emailOtp?.emailSource:t.otp?.numberSource,c=u!==void 0&&Mt.has(u)?u:i?"prefilled_or_entered":"user_entered",p=typeof s.sentToMasked=="string"&&s.sentToMasked.length>0,m=s.prefilled===!0,S=Nt(e,i?"email_otp":"phone_otp"),x={key:t.checkType,context:o,section:I(t),phase:p?"verify":"send",canSwitch:S!==void 0,...r},d=i?{kind:"email_otp",...x,emailSource:c,needsEmail:c!=="prefilled"&&!m}:{kind:"phone_otp",...x,numberSource:c,needsPhone:c!=="prefilled"&&!m,channels:(t.otp?.channels??[]).filter(_=>_==="whatsapp"||_==="sms")};if(S!==void 0&&(d.switchChannel=S),m&&(d.prefilled=!0),p&&(d.sentToMasked=s.sentToMasked),!i&&t.otp?.channel!==void 0&&(d.channel=t.otp.channel),!i&&Array.isArray(t.phoneCountries)&&(d.phoneCountries=t.phoneCountries.filter(_=>typeof _=="string"&&/^[A-Z]{2}$/.test(_))),!i&&Array.isArray(t.phoneRules)){let _=d.phoneCountries??[];d.phoneRules=t.phoneRules.flatMap(f=>{let M=Ft(f);return M!==void 0&&_.includes(M.code)?[M]:[]})}return!i&&t.phoneInternational===!0&&(d.phoneInternational=!0),s.expiresAt!==void 0&&(d.codeExpiresAt=s.expiresAt),s.resendAvailableAt!==void 0&&(d.resendAvailableAt=s.resendAvailableAt),d}var Lt=/^[\d[\]\-|()?:^]{1,64}$/;function Ut(e){try{return typeof e=="string"&&Lt.test(e)&&new RegExp(e)!==null}catch{return!1}}var je=e=>typeof e=="number"&&Number.isInteger(e)&&e>=1&&e<=15;function Ft(e){let{code:t,dial:o,trunk:r,lengths:i,formats:s}=e??{};if(typeof t!="string"||typeof o!="string"||!/^\d{1,3}$/.test(o)||r!==void 0&&(typeof r!="string"||!/^\d{1,3}$/.test(r))||!Array.isArray(i)||i.length===0||!i.every(je))return;let u={code:t,dial:o,lengths:[...i].sort((c,p)=>c-p)};if(r!==void 0&&(u.trunk=r),s!==void 0){if(!(Array.isArray(s)&&s.length<=8&&s.every(p=>Ut(p?.leading)&&Array.isArray(p.groups)&&p.groups.every(je)&&i.includes(p.groups.reduce((m,S)=>m+S,0)))))return;u.formats=s.map(p=>({leading:p.leading,groups:[...p.groups]}))}return u}function Bt(e,t,o,r){let i=J(e)===!0?"bound":B(t)===!0?"document":"typed",s=i==="typed"&&t.state==="input_required"&&t.reason!==void 0&&We(t.reason)==="id_number_recheck",u=Je(le(e)),c=!r.attemptsExhausted&&u.length===1&&u[0]?.service==="document";return{kind:"registry",key:"registry",context:o,section:I(t),state:t.state==="input_required"?"input_required":"pending",source:i,recheck:s,canUseDocument:c,...r}}function Gt(e,t,o,r,i){let s=[...t.acceptedSides??[]],u={kind:"document",key:"document",context:o,section:I(t),side:s.includes("recto")?"verso":"recto",acceptedSides:s,documents:qe(e),photo:ze(Xe(e.documents),i),...r};return e.detectedCountry!==void 0&&(u.detectedCountry=e.detectedCountry),Kt(e)&&(u.ageStepUp=!0),u}function Xe(e,t=!0){let o=e?.source==="upload"||e?.source==="choice"?e.source:"camera",r=e?.sourcePick==="camera"||e?.sourcePick==="upload"?e.sourcePick:null;return{source:o,pick:r,uploadOffered:t&&e?.uploadOffered===!0}}function ze(e,t){return t?{...e,cameraOnPhone:!0}:e}function Kt(e){let t=W(e).find(r=>r.checkType==="age_estimation"),o=t?.reason;return t?.state==="failed"&&(o==="age_uncertain"||o==="age_unavailable")}function qt(e){let t=O(e,"liveness");return t?.state==="passed"||t?.state==="review"}function Ze(e,t,o,r,i,s=!1){let u=t.icao?.report,c=e.portrait,p=i==="capture"?c?.pendingFix??null:null;p!==null&&(i="review");let m=et(e);return{kind:"portrait",key:`portrait:${i}`,context:o,section:I(t),phase:i,report:Array.isArray(u)?u:null,review:t.state==="review",tuning:e.capture?.icao??null,tuningVersion:e.capture?.tuningVersion??null,icao:$(e),retakeOnly:i==="capture"&&t.state==="input_required"&&m===void 0&&e.capture?.livePhoto?.oneCapture===!0&&qt(e),photo:ze(Xe(c,i==="capture"),s&&i==="capture"),pendingFix:p,...m!==void 0?{captureMode:m}:{},...c?.reuse?.pending===!0?{reuse:!0}:{},...r}}function et(e){let t=e.portrait?.captureMode;return t==="self"||t==="assisted"||t==="choice"?t:void 0}var ae={minLongSidePx:1280,jpegQuality:.95};function Yt(e,t){let o=e.capture?.livePhoto;if(o?.oneCapture!==!0)return null;let r=O(e,"portrait_icao"),i=o.still??ae;return{icao:t==="liveness"&&$(e)!==null&&et(e)===void 0&&r!==void 0&&r.state==="pending"&&r.reason===void 0,still:{minLongSidePx:i.minLongSidePx??ae.minLongSidePx,jpegQuality:i.jpegQuality??ae.jpegQuality}}}function Wt(e,t,o,r){let i=t.eid,s=I(t);if(i===void 0||i.challenge!=="app_code")return{kind:"unsupported",key:"unsupported:eid_auth",context:o,section:s,checkType:"eid_auth",reason:"update_required"};let u=Je(le(e)),c=u.length===1&&It.includes(u[0]?.service??"")?u[0]:void 0,p=c===void 0?void 0:L[c.service],m=p!==void 0,S={kind:"eid",key:"eid",context:o,section:s,provider:i.provider,providerName:i.providerName,country:i.country,challenge:"app_code",phase:i.awaiting==="code"?"code":"identifier",identifierBound:i.identifierBound===!0,canUseCamera:m,afterPass:i.afterPass==="continue"?"continue":"end",...r};return m&&(S.cameraMethod=p),i.expiresAt!==void 0&&(S.codeExpiresAt=i.expiresAt),i.resendAvailableAt!==void 0&&(S.resendAvailableAt=i.resendAvailableAt),i.resendsRemaining!==void 0&&(S.resendsRemaining=i.resendsRemaining),i.codeAttemptsRemaining!==void 0&&(S.codeAttemptsRemaining=i.codeAttemptsRemaining),S}function jt(e,t){if(t.checkType!=="face_match"||t.reason!==void 0)return null;let o=O(e,"portrait_icao");return o!==void 0&&(o.state==="passed"||o.state==="review")?o:null}var Zt={rejected:"rejected",inconclusive:"inconclusive",unavailable:"unavailable",abandoned:"expired",not_opened:"expired",cancelled:"expired",superseded:"expired",policy:"policy"};function $t(e){return e.reasonCode===de?"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?Zt[e.reason]:void 0)??"rejected"}function Jt(e,t){let o=$t(e),r=o==="platform_unsupported"?{sessionId:se(e.sessionId),status:"unavailable",reasonCode:de}:U(e,{autoRetry:!1}),i={kind:"result",key:"result",context:t,section:null,display:o,result:r};return e.status==="not_verified"&&e.reason!==void 0&&(i.reason=e.reason),e.reasonCode!==void 0&&(i.reasonCode=e.reasonCode),e.status==="not_verified"&&e.step!==void 0&&(i.step=e.step),e.retryAfter!==void 0&&(i.retryAfter=e.retryAfter),i}function Qt(e,t,o){let r=e.identitySummary;if(r==null)return null;let i={kind:"identity_summary",key:"identity_summary",context:t,section:o??"identity",summaryKind:r.kind==="partial"?"partial":r.kind??"full",source:r.source,portraitAvailable:r.portrait?.available===!0,retakeAvailable:r.retakeAvailable===!0};for(let u of Xt){let c=r[u];typeof c=="string"&&c!==""&&(i[u]=c)}let s=Ge(r);return s!==void 0&&(i.idNumberMasked=s,i.nniMasked=s),i}var Xt=["fullName","birthDate","birthYear","nationality","documentType","documentNumberMasked","expiryDate","retakeTarget"];function N(e,t,o,r){return{kind:"unsupported",key:`unsupported:${o}`,context:e,section:t,checkType:o,reason:r}}function zt(e){return e.kind==="contact"?"contact":(e.kind==="identity_method","identity")}function en(e,t){let o=$e[e.kind]??[...ce,...ue],r=zt(e),i=e.options.flatMap(u=>{if(u.available===!1||!o.includes(u.service))return[];let c={id:u.id,service:u.service};u.nationalEid!=null&&(c.nationalEid=u.nationalEid);let p=(u.channels??[]).filter(m=>m==="whatsapp"||m==="sms");return u.service==="phone_otp"&&p.length>0&&(c.channels=p),[c]});if(i.length===0){let u=e.options.length>0&&e.options.every(c=>c.service==="nfc");return N(t,r,"choice",u?"platform_unsupported":"update_required")}let s={nodeId:e.nodeId,kind:e.kind,selected:e.selected,options:i};if(e.kind==="identity_method"){let u={kind:"method",key:"method",context:t,section:r,options:i.map(p=>L[p.service]),choice:s},c=i.find(p=>p.nationalEid!==void 0)?.nationalEid;return c!==void 0&&(u.nationalEid=c),u}return e.kind==="contact"?{kind:"contact_choice",key:"contact_choice",context:t,section:r,options:i.map(u=>Qe[u.service]),selected:null,locked:!1,choice:s}:{kind:"choice",key:`choice:${e.nodeId}`,context:t,section:r,choice:s}}function wn(e,t={}){let o=Vt(e);if(R(e)||e.reasonCode===de)return Jt(e,o);let r=e.plan;if(r===void 0||!Array.isArray(r.sections))return N(o,null,"plan","update_required");let i=Ne(e);if(i!==null)return en(i,o);let s=r.current===null?void 0:r.steps.find(d=>d.id===r.current),u=d=>{let _={kind:"processing",key:"processing",context:o,section:d!==void 0?I(d):r.sections.find(f=>f.state==="current")?.id??null,stalled:!1};return typeof d?.service=="string"&&d.service!==""&&(_.service=d.service),_};if(r.current===null)return u(r.steps.find(d=>d.state==="processing"));if(s===void 0)return N(o,null,"step","update_required");if(!vt.has(s.service))return s.interaction==="server"?u(s):N(o,I(s),s.service,"update_required");if(At.has(s.service)||!He(s))return u(s);let c=s,p=Dt(c),m=c.checkType,S=I(c),x=t.isMobile===!1?F(e,c):null;if(x==="phone")return{kind:"mobile_required",key:"mobile_required",context:o,section:S,checkType:m};switch(m){case"phone_otp":case"email_otp":return Ht(e,c,o,p);case"population_registry":return Bt(e,c,o,p);case"eid_auth":return Wt(e,c,o,p);case"doc_ocr":return Gt(e,c,o,p,x==="upload_or_phone");case"identity_confirm":return Qt(e,o,S)??u(c);case"portrait_icao":return Ze(e,c,o,p,"capture",x==="upload_or_phone");case"liveness":case"face_match":{let d=jt(e,c);if(d!==null)return Ze(e,d,o,p,"match");let _=c.requiresMobile===!0,f=$(e);return{kind:"liveness",key:"biometric",context:o,section:S,mode:m==="face_match"?"selfie":"liveness",requiresMobile:_,instructions:f===null?"standard":"icao",icao:f,livePhoto:Yt(e,m),...p}}case"nfc_chip":return N(o,S,m,"platform_unsupported");default:return N(o,S,m,"update_required")}}export{ht as a,St as b,_t as c,Ct as d,Pt as e,hn as f,bt as g,Ke as h,Rt as i,xt as j,_n as k,qe as l,Cn as m,Mn as n,de as o,I as p,le as q,Je as r,jt as s,wn as t};
@@ -1 +1 @@
1
- import{p as k,r as w}from"./chunk-CPUECYAJ.js";import{e as M}from"./chunk-TSA6GHUG.js";var u=class extends Error{constructor(){super("the back camera could not be opened");this.name="BackCameraUnavailableError"}},S=new Set(["NotAllowedError","PermissionDeniedError","SecurityError"]);function h(r){try{return String(r?.name??"")}catch{return""}}function c(r){if(r!==null)for(let t of r.getTracks())t.stop()}async function C(r,t,n){let a=e=>({video:{...t,...e},audio:!1});if(r==="user")return n.getUserMedia(a({facingMode:"user"}));let o=e=>M(e)!=="user";try{let e=await n.getUserMedia(a({facingMode:{exact:"environment"}}));if(o(e))return e;c(e)}catch(e){if(S.has(h(e)))throw e}let d=!1,l=async()=>{if(n.enumerateDevices===void 0||d)return null;let e;try{e=w(await n.enumerateDevices()).slice(0,3)}catch{return null}d=e.length>0;for(let v of e){let i;try{i=await n.getUserMedia(a({deviceId:{exact:v}}))}catch(g){if(S.has(h(g)))throw g;continue}if(o(i))return i;c(i)}return null},m=await l();if(m!==null)return m;let s=await n.getUserMedia(a({facingMode:"environment"}));if(o(s))return s;c(s);let f=await l();if(f!==null)return f;throw new u}export{u as a,C as b};
1
+ import{p as k,r as w}from"./chunk-7KXJEF7P.js";import{e as M}from"./chunk-CDDYFUER.js";var u=class extends Error{constructor(){super("the back camera could not be opened");this.name="BackCameraUnavailableError"}},S=new Set(["NotAllowedError","PermissionDeniedError","SecurityError"]);function h(r){try{return String(r?.name??"")}catch{return""}}function c(r){if(r!==null)for(let t of r.getTracks())t.stop()}async function C(r,t,n){let a=e=>({video:{...t,...e},audio:!1});if(r==="user")return n.getUserMedia(a({facingMode:"user"}));let o=e=>M(e)!=="user";try{let e=await n.getUserMedia(a({facingMode:{exact:"environment"}}));if(o(e))return e;c(e)}catch(e){if(S.has(h(e)))throw e}let d=!1,l=async()=>{if(n.enumerateDevices===void 0||d)return null;let e;try{e=w(await n.enumerateDevices()).slice(0,3)}catch{return null}d=e.length>0;for(let v of e){let i;try{i=await n.getUserMedia(a({deviceId:{exact:v}}))}catch(g){if(S.has(h(g)))throw g;continue}if(o(i))return i;c(i)}return null},m=await l();if(m!==null)return m;let s=await n.getUserMedia(a({facingMode:"environment"}));if(o(s))return s;c(s);let f=await l();if(f!==null)return f;throw new u}export{u as a,C as b};
@@ -1 +1 @@
1
- import{A as _e,C as x,D as j,d as K,e as he,f as Se,g as ge,i as ye,j as ee,l as q,m as te,o as be,p as Ce,t as Pe}from"./chunk-PZYVSLPG.js";import{c as pe,d as me,e as fe}from"./chunk-FPXL63KZ.js";import{c as F,h as Q,i as ke}from"./chunk-2KTSNAVR.js";var Re=["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 We=["carte_identite","passport","residence_permit"];function qe(e,t){let i=e.byIssuer?.[t]??e.default;return We.filter(a=>i==="*"||i.includes(a))}function Yt(e,t=Re){return[...new Set([...t,...Object.keys(e.byIssuer??{})])].filter(a=>qe(e,a).length>0).sort()}function Me(e){if(e.acceptedDocuments)return e.acceptedDocuments;let t=e.acceptedDocumentTypes?.length?[...e.acceptedDocumentTypes]:["carte_identite","passport"];return{default:[],byIssuer:{MR:t}}}var Qe=640,$e=new Set(["network_error","timeout","upload_failed","unknown_error","rate_limit_exceeded"]),Ee=6,Ae=1500,Ie={sharpness:1,exposure:1,meanLuma:128},ve=null;function Je(e,t){try{ve??(ve=document.createElement("canvas"));let i=ve,a=96/Math.max(1,t.width);i.width=Math.max(1,Math.round(t.width*a)),i.height=Math.max(1,Math.round(t.height*a));let r=i.getContext("2d");if(r===null)return Ie;r.drawImage(e,t.x,t.y,t.width,t.height,0,0,i.width,i.height);let c=r.getImageData(0,0,i.width,i.height);return{sharpness:me(c),exposure:fe(c),meanLuma:pe(c)}}catch{return Ie}}async function ze(e,t){let i=e.source;return"convertToBlob"in i?i.convertToBlob({type:"image/jpeg",quality:t}):new Promise((a,r)=>{i.toBlob(c=>c===null?r(new Error("encode failed")):a(c),"image/jpeg",t)})}function $t(e,t={}){let i=t.now??(()=>performance.now()),a=t.setTimer??((m,C)=>setTimeout(m,C)),r=t.clearTimer??(m=>clearTimeout(m)),c=t.encode??ze,l=t.quality??Je,u=e.tuningVersion??null,p=new Set,S=!1,y=e.video??null,E=null,f=t.grabFrame??null,b=null,v=1e3/Ee,A=null,I=null,T=!1,N=!1,D=Number.NEGATIVE_INFINITY,M=null,G=0,L=null,B=null,J=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,C,R,w,O])=>{let k=C.resolveIcaoTuning(e.tuning,e.tuningVersion??void 0);k.background.required&&(I=O.createBackgroundMonitor({tuning:k.backgroundCheck,assetBaseUrl:e.assetBaseUrl??"/models-v3",...t.createSegmenter!==void 0?{createSegmenter:t.createSegmenter}:{},now:i})),E=m.createIcaoGate(k,{policy:e.policy??"reject"}),f??(f=R.defaultGrabber()),b=R.observe,v=1e3/Math.min(Ee,k.cadenceHz);let n=(t.createLandmarker??w.createFaceLandmarker)(e.assetBaseUrl??"/models-v3"),o=await new Promise((s,d)=>{let h=setTimeout(()=>{d(new Error("landmarker init timeout")),n.then(g=>g.close(),()=>{})},w.LANDMARKER_INIT_TIMEOUT_MS);n.then(g=>{clearTimeout(h),s(g)},g=>{clearTimeout(h),d(g)})});S?o.close():A=o}).catch(()=>{T=!0}),H=m=>{for(let C of p)C({holding:N||T,update:m})},Y=()=>{if(M=null,!(S||A===null||E===null||f===null||b===null||y===null)){if(i()-D>Ae){H(null);return}try{let m=f(y,Qe);if(m!==null){let C=Math.max(i(),G+1);G=C;let R=A.detect(m.source,C),w=y.videoWidth||m.width,O=y.videoHeight||m.height,k=b(R,m,w,O);k.geometry!==null&&I!==null&&(k.backgroundCheck=I.measure(m,k.geometry.box,w,O));let n=E.push(k,i());N=n.ready,H(n)}}catch{}M=a(Y,v)}},Z=()=>{let m=i()-D>Ae;D=i(),m&&(E?.reset(),N=!1,L=null,B=null),M===null&&A!==null&&!S&&(M=a(Y,0))},z=()=>{let m=f===null||y===null?null:f(y,null);if(m===null||E===null||Math.max(m.width,m.height)<e.still.minLongSidePx)return Promise.resolve(null);let C=E.summary();return c(m,e.still.jpegQuality).then(R=>({image:R,width:m.width,height:m.height,gate:C}),()=>null)},W=null;return{engineOptions:{measureQuality:(m,C)=>{y=m,Z();let R=l(m,C);return N||T?R:{...R,sharpness:0}},telemetry:m=>{if(m.type!=="fired"||S)return;L=z();let C=W;C!==null&&L.then(R=>R===null?void 0:C(R).catch(()=>{})),N=!1,M!==null&&r(M),M=null,D=Number.NEGATIVE_INFINITY}},decorate:m=>{let C=new WeakMap,R=new Map,w=o=>{let s=C.get(o);return s===void 0&&(s=(async()=>{let d=await Pe(m,"image","image/jpeg",o.image.size,{engine:"portrait"});return await m.uploadToSpaces(d.uploadUrl,o.image,"image/jpeg"),(await m.completeMedia(d.key)).key})(),s.catch(()=>C.delete(o)),C.set(o,s)),s};W=w;let O=async o=>{let s;try{s=await w(o)}catch(d){let h=d?.code;if(typeof h=="string"&&$e.has(h))throw d;return null}return{media:{portrait:s},gate:ke(o.gate),...u!==null?{tuningVersion:u}:{}}},k=m.submitCheck.bind(m),n=(async(o,s,d)=>{if(o!=="liveness")return k(o,s,d);let h=d?.idempotencyKey,g=h===void 0?void 0:R.get(h);if(g===void 0){let de=L;g=de===null?Promise.resolve(null):de.then(le=>le===null?null:O(le)),h!==void 0&&(R.set(h,g),g.catch(()=>R.delete(h)))}let P=await g;if(P===null)return k("liveness",s,d);let _=await k("liveness",{...s,portraitIcao:P},d);return B=P,_});return new Proxy(m,{get(o,s){if(s==="submitCheck")return n;let d=Reflect.get(o,s);return typeof d=="function"?d.bind(o):d}})},onGate:m=>(p.add(m),()=>p.delete(m)),lastPortraitInput:()=>B,destroy:()=>{S=!0,L=null,B=null,M!==null&&r(M),M=null,p.clear(),J.then(()=>{A?.close(),A=null,I?.close(),I=null})}}}function Te(e){return e.idNumberBound??e.nniBound}function Oe(e){return e===void 0?void 0:e.idNumberFromDocument??e.nniFromDocument}function we(e){let t=e.idNumberMasked??e.nniMasked;return typeof t=="string"&&t!==""?t:void 0}var xe=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",sandbox_nni_not_seeded:"sandbox_id_number_not_seeded",missing_nni:"missing_id_number",registry_needs_nni_source:"registry_needs_id_number_source"}),Xe=new Map(Object.entries(xe)),Xt=new Map(Object.entries(xe).map(([e,t])=>[t,e]));function Ne(e){return Xe.get(e)??e}var et=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"]),tt=new Set(["supplied_identity","aml_screening","face_dedup","age_estimation"]),ie=["document","population_registry","national_eid"],oe=["phone_otp","email_otp"],De={identity_method:ie,contact:oe},nt=["population_registry","document"],re="platform_unsupported",it=new Set(["prefilled","user_entered","prefilled_or_entered"]),ot={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"};function V(e){return e.section??ot[e.checkType]??null}function se(e,t){let i=e.plan?.choice;if(i===void 0||i.locked)return;let a=i.options.find(r=>r.id!==i.selected&&r.available!==!1&&t.includes(r.service));return a===void 0?void 0:{nodeId:i.nodeId,option:a}}function ae(e){let t=e.plan,i=t?.choice;if(t===void 0||i===void 0||i.locked||t.current===null||t.current===i.nodeId||ee(e))return null;let a=De[i.kind]??[...ie,...oe],r=i.options.flatMap(u=>u.available===!1||!a.includes(u.service)?[]:[u.nationalEid!=null?{id:u.id,service:u.service,nationalEid:u.nationalEid}:{id:u.id,service:u.service}]),c=t.steps.find(u=>u.id===t.current)?.service,l=i.selected??r.find(u=>u.service===c)?.id??null;return r.some(u=>u.id!==l)?{nodeId:i.nodeId,kind:i.kind,current:l,options:r}:null}function He(e){return e==null?[]:e.options.filter(t=>t.id!==e.current)}function rt(e){let t=e.simulation;if(typeof t!="object"||t===null)return;let{otpCode:i,skipCapture:a}=t;return typeof i=="string"&&i!==""&&typeof a=="boolean"?{otpCode:i,skipCapture:a}:void 0}function st(e){let t=(e.plan?.sections??[]).map(c=>({id:c.id,state:c.state})),i={sessionId:te(e.sessionId),orgName:e.orgName,returning:e.returning===!0,consentRecorded:e.consentRecorded,expiresAt:e.expiresAt,sections:t.map(c=>c.id),progress:t,purpose:e.purpose??"identity"};e.branding!==void 0&&(i.branding=e.branding),e.cameraUnavailableHandled===!0&&(i.cameraUnavailableHandled=!0);let a=rt(e);a!==void 0&&(i.simulation=a);let r=ae(e);return r!==null&&(i.switchable=r),i}function at(e){let t={attemptsRemaining:Se(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 Ge={phone_otp:"phone",email_otp:"email"};function ct(e,t){let i=se(e,[t==="phone_otp"?"email_otp":"phone_otp"]);return i===void 0?void 0:Ge[i.option.service]}function ut(e,t,i,a){let r=t.checkType==="email_otp",c=(r?t.emailOtp:t.otp)??{},l=r?t.emailOtp?.emailSource:t.otp?.numberSource,u=l!==void 0&&it.has(l)?l:r?"prefilled_or_entered":"user_entered",p=typeof c.sentToMasked=="string"&&c.sentToMasked.length>0,S=c.prefilled===!0,y=ct(e,r?"email_otp":"phone_otp"),E={key:t.checkType,context:i,section:V(t),phase:p?"verify":"send",canSwitch:y!==void 0,...a},f=r?{kind:"email_otp",...E,emailSource:u,needsEmail:u!=="prefilled"&&!S}:{kind:"phone_otp",...E,numberSource:u,needsPhone:u!=="prefilled"&&!S,channels:(t.otp?.channels??[]).filter(b=>b==="whatsapp"||b==="sms")};if(y!==void 0&&(f.switchChannel=y),S&&(f.prefilled=!0),p&&(f.sentToMasked=c.sentToMasked),!r&&t.otp?.channel!==void 0&&(f.channel=t.otp.channel),!r&&Array.isArray(t.phoneCountries)&&(f.phoneCountries=t.phoneCountries.filter(b=>typeof b=="string"&&/^[A-Z]{2}$/.test(b))),!r&&Array.isArray(t.phoneRules)){let b=f.phoneCountries??[];f.phoneRules=t.phoneRules.flatMap(v=>{let A=pt(v);return A!==void 0&&b.includes(A.code)?[A]:[]})}return!r&&t.phoneInternational===!0&&(f.phoneInternational=!0),c.expiresAt!==void 0&&(f.codeExpiresAt=c.expiresAt),c.resendAvailableAt!==void 0&&(f.resendAvailableAt=c.resendAvailableAt),f}var dt=/^[\d[\]\-|()?:^]{1,64}$/;function lt(e){try{return typeof e=="string"&&dt.test(e)&&new RegExp(e)!==null}catch{return!1}}var Le=e=>typeof e=="number"&&Number.isInteger(e)&&e>=1&&e<=15;function pt(e){let{code:t,dial:i,trunk:a,lengths:r,formats:c}=e??{};if(typeof t!="string"||typeof i!="string"||!/^\d{1,3}$/.test(i)||a!==void 0&&(typeof a!="string"||!/^\d{1,3}$/.test(a))||!Array.isArray(r)||r.length===0||!r.every(Le))return;let l={code:t,dial:i,lengths:[...r].sort((u,p)=>u-p)};if(a!==void 0&&(l.trunk=a),c!==void 0){if(!(Array.isArray(c)&&c.length<=8&&c.every(p=>lt(p?.leading)&&Array.isArray(p.groups)&&p.groups.every(Le)&&r.includes(p.groups.reduce((S,y)=>S+y,0)))))return;l.formats=c.map(p=>({leading:p.leading,groups:[...p.groups]}))}return l}function mt(e,t,i,a){let r=Te(e)===!0?"bound":Oe(t)===!0?"document":"typed",c=r==="typed"&&t.state==="input_required"&&t.reason!==void 0&&Ne(t.reason)==="id_number_recheck",l=He(ae(e)),u=!a.attemptsExhausted&&l.length===1&&l[0]?.service==="document";return{kind:"registry",key:"registry",context:i,section:V(t),state:t.state==="input_required"?"input_required":"pending",source:r,recheck:c,canUseDocument:u,...a}}function ft(e,t,i,a,r){let c=[...t.acceptedSides??[]],l={kind:"document",key:"document",context:i,section:V(t),side:c.includes("recto")?"verso":"recto",acceptedSides:c,documents:Me(e),photo:Ue(Be(e.documents),r),...a};return e.detectedCountry!==void 0&&(l.detectedCountry=e.detectedCountry),ht(e)&&(l.ageStepUp=!0),l}function Be(e,t=!0){let i=e?.source==="upload"||e?.source==="choice"?e.source:"camera",a=e?.sourcePick==="camera"||e?.sourcePick==="upload"?e.sourcePick:null;return{source:i,pick:a,uploadOffered:t&&e?.uploadOffered===!0}}function Ue(e,t){return t?{...e,cameraOnPhone:!0}:e}function ht(e){let t=he(e).find(a=>a.checkType==="age_estimation"),i=t?.reason;return t?.state==="failed"&&(i==="age_uncertain"||i==="age_unavailable")}function St(e){let t=q(e,"liveness");return t?.state==="passed"||t?.state==="review"}function Ve(e,t,i,a,r,c=!1){let l=t.icao?.report,u=e.portrait,p=r==="capture"?u?.pendingFix??null:null;p!==null&&(r="review");let S=Fe(e);return{kind:"portrait",key:`portrait:${r}`,context:i,section:V(t),phase:r,report:Array.isArray(l)?l:null,review:t.state==="review",tuning:e.capture?.icao??null,tuningVersion:e.capture?.tuningVersion??null,icao:Q(e),retakeOnly:r==="capture"&&t.state==="input_required"&&S===void 0&&e.capture?.livePhoto?.oneCapture===!0&&St(e),photo:Ue(Be(u,r==="capture"),c&&r==="capture"),pendingFix:p,...S!==void 0?{captureMode:S}:{},...u?.reuse?.pending===!0?{reuse:!0}:{},...a}}function Fe(e){let t=e.portrait?.captureMode;return t==="self"||t==="assisted"||t==="choice"?t:void 0}var ne={minLongSidePx:1280,jpegQuality:.95};function gt(e,t){let i=e.capture?.livePhoto;if(i?.oneCapture!==!0)return null;let a=q(e,"portrait_icao"),r=i.still??ne;return{icao:t==="liveness"&&Q(e)!==null&&Fe(e)===void 0&&a!==void 0&&a.state==="pending"&&a.reason===void 0,still:{minLongSidePx:r.minLongSidePx??ne.minLongSidePx,jpegQuality:r.jpegQuality??ne.jpegQuality}}}function yt(e,t,i,a){let r=t.eid,c=V(t);if(r===void 0||r.challenge!=="app_code")return{kind:"unsupported",key:"unsupported:eid_auth",context:i,section:c,checkType:"eid_auth",reason:"update_required"};let l=He(ae(e)),u=l.length===1&&nt.includes(l[0]?.service??"")?l[0]:void 0,p=u===void 0?void 0:K[u.service],S=p!==void 0,y={kind:"eid",key:"eid",context:i,section:c,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",...a};return S&&(y.cameraMethod=p),r.expiresAt!==void 0&&(y.codeExpiresAt=r.expiresAt),r.resendAvailableAt!==void 0&&(y.resendAvailableAt=r.resendAvailableAt),r.resendsRemaining!==void 0&&(y.resendsRemaining=r.resendsRemaining),r.codeAttemptsRemaining!==void 0&&(y.codeAttemptsRemaining=r.codeAttemptsRemaining),y}function bt(e,t){if(t.checkType!=="face_match"||t.reason!==void 0)return null;let i=q(e,"portrait_icao");return i!==void 0&&(i.state==="passed"||i.state==="review")?i:null}var Ct={rejected:"rejected",inconclusive:"inconclusive",unavailable:"unavailable",abandoned:"expired",not_opened:"expired",cancelled:"expired",superseded:"expired",policy:"policy"};function Pt(e){return e.reasonCode===re?"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?Ct[e.reason]:void 0)??"rejected"}function _t(e,t){let i=Pt(e),a=i==="platform_unsupported"?{sessionId:te(e.sessionId),status:"unavailable",reasonCode:re}:be(e,{autoRetry:!1}),r={kind:"result",key:"result",context:t,section:null,display:i,result:a};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 kt(e,t,i){let a=e.identitySummary;if(a==null)return null;let r={kind:"identity_summary",key:"identity_summary",context:t,section:i??"identity",summaryKind:a.kind==="partial"?"partial":a.kind??"full",source:a.source,portraitAvailable:a.portrait?.available===!0,retakeAvailable:a.retakeAvailable===!0};for(let l of Rt){let u=a[l];typeof u=="string"&&u!==""&&(r[l]=u)}let c=we(a);return c!==void 0&&(r.idNumberMasked=c,r.nniMasked=c),r}var Rt=["fullName","birthDate","birthYear","nationality","documentType","documentNumberMasked","expiryDate","retakeTarget"];function U(e,t,i,a){return{kind:"unsupported",key:`unsupported:${i}`,context:e,section:t,checkType:i,reason:a}}function Mt(e){return e.kind==="contact"?"contact":(e.kind==="identity_method","identity")}function Et(e,t){let i=De[e.kind]??[...ie,...oe],a=Mt(e),r=e.options.flatMap(l=>{if(l.available===!1||!i.includes(l.service))return[];let u={id:l.id,service:l.service};l.nationalEid!=null&&(u.nationalEid=l.nationalEid);let p=(l.channels??[]).filter(S=>S==="whatsapp"||S==="sms");return l.service==="phone_otp"&&p.length>0&&(u.channels=p),[u]});if(r.length===0){let l=e.options.length>0&&e.options.every(u=>u.service==="nfc");return U(t,a,"choice",l?"platform_unsupported":"update_required")}let c={nodeId:e.nodeId,kind:e.kind,selected:e.selected,options:r};if(e.kind==="identity_method"){let l={kind:"method",key:"method",context:t,section:a,options:r.map(p=>K[p.service]),choice:c},u=r.find(p=>p.nationalEid!==void 0)?.nationalEid;return u!==void 0&&(l.nationalEid=u),l}return e.kind==="contact"?{kind:"contact_choice",key:"contact_choice",context:t,section:a,options:r.map(l=>Ge[l.service]),selected:null,locked:!1,choice:c}:{kind:"choice",key:`choice:${e.nodeId}`,context:t,section:a,choice:c}}function $(e,t={}){let i=st(e);if(ee(e)||e.reasonCode===re)return _t(e,i);let a=e.plan;if(a===void 0||!Array.isArray(a.sections))return U(i,null,"plan","update_required");let r=ge(e);if(r!==null)return Et(r,i);let c=a.current===null?void 0:a.steps.find(f=>f.id===a.current),l=f=>{let b={kind:"processing",key:"processing",context:i,section:f!==void 0?V(f):a.sections.find(v=>v.state==="current")?.id??null,stalled:!1};return typeof f?.service=="string"&&f.service!==""&&(b.service=f.service),b};if(a.current===null)return l(a.steps.find(f=>f.state==="processing"));if(c===void 0)return U(i,null,"step","update_required");if(!et.has(c.service))return c.interaction==="server"?l(c):U(i,V(c),c.service,"update_required");if(tt.has(c.service)||!ye(c))return l(c);let u=c,p=at(u),S=u.checkType,y=V(u),E=t.isMobile===!1?Ce(e,u):null;if(E==="phone")return{kind:"mobile_required",key:"mobile_required",context:i,section:y,checkType:S};switch(S){case"phone_otp":case"email_otp":return ut(e,u,i,p);case"population_registry":return mt(e,u,i,p);case"eid_auth":return yt(e,u,i,p);case"doc_ocr":return ft(e,u,i,p,E==="upload_or_phone");case"identity_confirm":return kt(e,i,y)??l(u);case"portrait_icao":return Ve(e,u,i,p,"capture",E==="upload_or_phone");case"liveness":case"face_match":{let f=bt(e,u);if(f!==null)return Ve(e,f,i,p,"match");let b=u.requiresMobile===!0,v=Q(e);return{kind:"liveness",key:"biometric",context:i,section:y,mode:S==="face_match"?"selfie":"liveness",requiresMobile:b,instructions:v===null?"standard":"icao",icao:v,livePhoto:gt(e,S),...p}}case"nfc_chip":return U(i,y,S,"platform_unsupported");default:return U(i,y,S,"update_required")}}var At=/^[A-Z0-9][A-Z0-9 -]{0,39}$/,It=Object.freeze({normalize:e=>e.trim().toUpperCase().replace(/\s+/g," "),check:e=>At.test(e),registrySources:Object.freeze([]),describe:"number must be 1 to 40 letters, digits, spaces or hyphens"});function vt(e){return typeof e=="string"&&/^\d{10}$/.test(e)&&Number(e)%97===1}var Tt=Object.freeze({normalize:e=>e.trim(),check:e=>vt(e),registrySources:Object.freeze(["MR.anrpts"]),describe:"number must be the 10-digit Mauritanian national ID number with a valid check digit"}),Ot=Object.freeze({"MR:national_id":Tt});function ce(e,t){return Ot[`${e.toUpperCase()}:${t}`]??It}var wt=Object.freeze({MRT:"MR"});function Ke(e,t){let i=e.trim().toUpperCase();return ce(wt[i]??i,t)}function je(e){let t=Ke(e.issuingCountry,e.type);return t.check(t.normalize(e.number))}function Ye(e){return ce("MR","national_id").check(e)}function ue(e){let t="";for(let i of e){let a=i.codePointAt(0)??0;a>=1632&&a<=1641?t+=String(a-1632):a>=1776&&a<=1785?t+=String(a-1776):i!==" "&&i!=="-"&&i!==" "&&(t+=i)}return t}var xt=[1e3,2e3,4e3,8e3,15e3],Nt=3e4,Lt=/^\+[1-9]\d{6,14}$/,Vt=/^\d{6}$/,Dt=/^\d{6}$/,Ht=/^[^\s@]+@[^\s@]+\.[^\s@]+$/,Ze=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"]),Gt={simulatedCapture:!0},Bt=new Set(["network_error","timeout","upload_failed","unknown_error","rate_limit_exceeded"]);function yn(e){let t=!1,i=null,a="",r=!1,c=!1,l=!1,u={},p={},S=new Set,y=!1,E=!1,f=null,b="idle",v=new Map,A=new Map,I=(n,o,s)=>{let d=`${n}.${o}`,h=v.get(d);if(h!==void 0)return h;let g=A.get(n),P=(g===void 0?s():g.then(s)).finally(()=>{v.delete(d)});v.set(d,P);let _=P.then(()=>{},()=>{});return A.set(n,_),_.then(()=>{A.get(n)===_&&A.delete(n)}),P},T=async(n,o,s)=>{await e.ensureConsent();let d;try{d=await _e(e.runtime,o)}catch(g){if(g instanceof F&&Ze.has(g.code)){await e.refreshView();return}throw g}if(s?.(d),e.destroyed())return;let h=d;h.plan!==void 0&&e.setView!==void 0?e.setView(h):await e.refreshView()},N=async n=>{await e.ensureConsent();let o;try{try{o=await n(e.runtime.client)}catch(s){if(!(s instanceof F)||s.code!=="consent_required")throw s;await e.runtime.ensureConsent({force:!0}),o=await n(e.runtime.client)}}catch(s){if(s instanceof F&&Ze.has(s.code)){await e.refreshView();return}throw s}e.destroyed()||(o!==void 0&&e.setView!==void 0?e.setView(o):await e.refreshView())},D=(n,o)=>I("choice",`${n}:${o}`,()=>N(s=>s.choose(n,o))),M=(n,o)=>n.options.some(s=>s.id===o)?D(n.nodeId,o):Promise.reject(new RangeError(`option ${String(o)} is not offered`)),G=(n,o)=>{let s=e.currentView(),d=s===null?void 0:se(s,n);return d===void 0?Promise.reject(new RangeError(`the ${o} is not offered`)):D(d.nodeId,d.option.id)},L=n=>I("identity",n,()=>N(o=>o.confirmIdentity===void 0?Promise.reject(new Error("identity confirmation is not available in this build")):o.confirmIdentity(n))),B=(n,o)=>{let s=n.kind,d=s==="phone_otp",h=d?"phone":"email",g={action:"send"};if(d?n.needsPhone:n.needsEmail){let P=o[h]??p[s],_=d?P?.replace(/[\s().-]/g,""):P?.trim();if(_!==void 0||n.phase!=="verify"){if(_===void 0||!(d?Lt:Ht).test(_))return Promise.reject(d?new x("phone","format"):new j("email","format"));g[h]=_}}if(d){let P=n.channels,_=o.channel??(P.length===1?P[0]:void 0);if(P.length>0){if(_===void 0)return Promise.reject(new j("channel","required"));if(!P.includes(_))return Promise.reject(new j("channel","unavailable"))}_!==void 0&&(g.channel=_),g.phoneRules=1}return I(s,"send",()=>T(s,(P,_)=>P.submitCheck(s,g,{idempotencyKey:_}),P=>{Ft(P,s)||(u[s]=e.now(),g[h]!==void 0&&(p[s]=g[h]))}))},J=(n,o)=>Vt.test(o)?I(n,"verify",()=>T(n,(s,d)=>s.submitCheck(n,{action:"verify",code:o},{idempotencyKey:d}))):Promise.reject(new x("code","format")),H=(n,o)=>I("eid_auth",n,()=>T("eid_auth",(s,d)=>s.submitCheck("eid_auth",o,{idempotencyKey:d}))),Y=(n,o)=>{if(n.identifierBound)return H("start",{action:"start"});let s=ue(o??"");if(n.country==="MR"){if(!/^\d{10}$/.test(s))return Promise.reject(new x("nni","format"));if(!Ye(s))return Promise.reject(new x("nni","check_digit"))}else if(s==="")return Promise.reject(new x("nni","format"));return H("start",{action:"start",identifier:s})},Z=(n,o,s)=>{if(n.source!=="typed")return Promise.reject(new RangeError("this session already holds the ID number"));let d=ue(o);return/^\d{10}$/.test(d)?je({type:"national_id",issuingCountry:"MR",number:d})?I("population_registry","submitIdNumber",()=>T("population_registry",(h,g)=>h.submitCheck("population_registry",{idNumber:d,nni:d},{idempotencyKey:g}),()=>{f=`\u2022\u2022\u2022\u2022\u2022\u2022${d.slice(-4)}`})):Promise.reject(new x(s,"check_digit")):Promise.reject(new x(s,"format"))},z=n=>(e.stopCameras?.(),I(n,"skipCapture",()=>T(n,(o,s)=>o.submitCheck(n,Gt,{idempotencyKey:s}),()=>{(n==="liveness"||n==="portrait_icao")&&(y=!0)}))),W=n=>{if(n.kind==="result"||n.context.simulation?.skipCapture!==!0)return n;let o=Ut(n);return o===null?n:{...n,skipCapture:()=>z(o)}},X=n=>((n.kind==="document"||n.kind==="portrait")&&n.photo?.cameraOnPhone===!0&&(n.refresh=async()=>{await e.refreshView()}),n),m=n=>{switch(n.kind){case"phone_otp":case"email_otp":{let o={...n,send:(d={})=>B(n,d),verify:d=>J(n.kind,d),switchTo:()=>n.canSwitch&&n.switchChannel!==void 0?G([n.switchChannel==="email"?"email_otp":"phone_otp"],"other contact option"):Promise.reject(new RangeError("this session has no other contact option"))},s=u[n.kind];return o.resendAvailableAt===void 0&&s!==void 0&&(o.resendAvailableAt=new Date(s+Nt).toISOString()),o}case"eid":return{...n,start:o=>Y(n,o),verify:o=>Dt.test(o)?H("verify",{action:"verify",code:o}):Promise.reject(new x("code","format")),resend:()=>n.resendsRemaining===0?Promise.reject(new RangeError("no new code can be sent for this session")):H("resend",{action:"resend"}),useCamera:()=>n.canUseCamera&&n.cameraMethod!==void 0?G(n.cameraMethod==="document_photo"?["document"]:["population_registry"],"camera path"):Promise.reject(new RangeError("the camera path is not offered"))};case"method":return{...n,select:o=>{let s=n.choice.options.find(d=>K[d.service]===o);return s!==void 0?M(n.choice,s.id):Promise.reject(new RangeError(`method ${String(o)} is not offered`))},choose:o=>M(n.choice,o)};case"choice":return{...n,choose:o=>M(n.choice,o)};case"registry":return{...n,submitIdNumber:o=>Z(n,o,"idNumber"),submitNni:o=>Z(n,o,"nni"),confirm:()=>I("population_registry","confirm",()=>T("population_registry",(o,s)=>o.submitCheck("population_registry",{},{idempotencyKey:s}))),useDocument:()=>n.canUseDocument?G(["document"],"document method"):Promise.reject(new RangeError("the document method is not offered"))};case"document":return e.bindDocument!==void 0?X(e.bindDocument(n,k)):{...n,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?X(e.bindPortrait(n,k)):{...n,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"contact_choice":return{...n,select:o=>{let s=o==="phone"?"phone_otp":o==="email"?"email_otp":void 0,d=n.choice.options.find(h=>h.service===s);return d!==void 0?M(n.choice,d.id):Promise.reject(new RangeError(`contact ${String(o)} is not offered`))},choose:o=>M(n.choice,o)};case"identity_summary":return{...n,...n.idNumberMasked===void 0&&n.summaryKind==="partial"&&f!==null?{idNumberMasked:f,nniMasked:f}:{},portrait:async()=>{let o=e.runtime.client;if(!n.portraitAvailable||o.identityPortrait===void 0)return null;try{return await o.identityPortrait()}catch{return null}},confirm:()=>L("confirm"),retake:()=>n.retakeAvailable?L("retake"):Promise.reject(new RangeError("no retake is left"))};case"liveness":return{...n,capture:o=>e.liveness(o),onLivePhoto:o=>n.livePhoto?.icao===!0&&e.onLivePhoto!==void 0?e.onLivePhoto(o):()=>{}};case"mobile_required":case"processing":return{...n,refresh:async()=>{r=!1,await e.refreshView()}};case"unsupported":case"result":return{...n};default:{let o=n;throw new Error(`runner: unhandled step ${JSON.stringify(o)}`)}}},C=n=>W(m(n)),R=async()=>{if(!c){c=!0;try{for(let n of xt){if(await e.sleep(n),!t||e.destroyed())return;let o=await e.refreshView().catch(()=>null);if(o!==null&&$(o,{isMobile:e.isMobile()}).kind!=="processing")return}r=!0,k()}finally{c=!1}}},w=n=>{if(n.kind!=="liveness"||n.mode!=="selfie")return null;let o={kind:"processing",key:"processing",context:n.context,section:n.section,stalled:!1};if(b==="inflight")return o;if(!E||b==="done")return null;let s=e.keptFaceKey?.()??null;return s===null?null:(b="inflight",T("face_match",(d,h)=>d.submitCheck("face_match",{imageKey:s},{idempotencyKey:h}),()=>{b="done"}).then(()=>{b==="inflight"&&(b="done",k())},()=>{b="done",k()}),o)},O=(n,o=!1)=>{if(!t||e.destroyed()||e.chainBusy())return;let s=$(n,{isMobile:e.isMobile()});s.kind==="registry"&&s.recheck&&(E=!0,b="idle"),s=w(s)??s,s.kind==="processing"?s.stalled=r:r=!1;let d=C(s),h=s.kind==="result"?void 0:s.context.switchable,g=h===void 0?d:{...d,chooseOption:_=>M({nodeId:h.nodeId,kind:h.kind,selected:h.current,options:h.options},_)},P=JSON.stringify(g);s.kind==="registry"&&s.source==="document"&&s.state==="pending"&&!S.has("registry")&&(S.add("registry"),g.confirm().catch(_=>{(!(_ instanceof F)||Bt.has(_.code))&&S.delete("registry")})),!(!o&&P===a)&&(a=P,i=g,e.emitStep(g),s.kind==="processing"&&!r&&b!=="inflight"&&R(),s.kind==="result"&&!l&&(l=!0,e.emitResult(s.result)))};function k(){let n=e.currentView();n!==null&&O(n,!0)}return{run:async()=>{if(e.destroyed())throw new Error("verification destroyed");t=!0;let n=await e.ensureView();return i===null&&O(n),i??C($(n,{isMobile:e.isMobile()}))},current:()=>i,onView:n=>O(n),onChainIdle:()=>{let n=e.currentView();n!==null&&O(n)},republish:k,submit:T,faceProbeSkipped:()=>y}}function Ut(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"mobile_required":return e.checkType;case"unsupported":return e.checkType==="nfc_chip"?"nfc_chip":null;default:return null}}function Ft(e,t){let i=e,a=i?.plan?.steps??i?.steps;return Array.isArray(a)?a.some(r=>r.checkType===t&&typeof r.reason=="string"):!1}export{qe as a,Yt as b,Ee as c,Ae as d,$t as e,Fe as f,$ as g,xt as h,Nt as i,yn as j};
1
+ import{A as _e,C as x,D as j,d as K,e as he,f as Se,g as ge,i as ye,j as ee,l as q,m as te,o as be,p as Ce,t as Pe}from"./chunk-6RJTKX5I.js";import{c as pe,d as me,e as fe}from"./chunk-FK2DJADA.js";import{c as F,h as Q,i as ke}from"./chunk-ZGDUIZC2.js";var Re=["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 We=["carte_identite","passport","residence_permit"];function qe(e,t){let i=e.byIssuer?.[t]??e.default;return We.filter(a=>i==="*"||i.includes(a))}function Yt(e,t=Re){return[...new Set([...t,...Object.keys(e.byIssuer??{})])].filter(a=>qe(e,a).length>0).sort()}function Me(e){if(e.acceptedDocuments)return e.acceptedDocuments;let t=e.acceptedDocumentTypes?.length?[...e.acceptedDocumentTypes]:["carte_identite","passport"];return{default:[],byIssuer:{MR:t}}}var Qe=640,$e=new Set(["network_error","timeout","upload_failed","unknown_error","rate_limit_exceeded"]),Ee=6,Ae=1500,Ie={sharpness:1,exposure:1,meanLuma:128},ve=null;function Je(e,t){try{ve??(ve=document.createElement("canvas"));let i=ve,a=96/Math.max(1,t.width);i.width=Math.max(1,Math.round(t.width*a)),i.height=Math.max(1,Math.round(t.height*a));let r=i.getContext("2d");if(r===null)return Ie;r.drawImage(e,t.x,t.y,t.width,t.height,0,0,i.width,i.height);let c=r.getImageData(0,0,i.width,i.height);return{sharpness:me(c),exposure:fe(c),meanLuma:pe(c)}}catch{return Ie}}async function ze(e,t){let i=e.source;return"convertToBlob"in i?i.convertToBlob({type:"image/jpeg",quality:t}):new Promise((a,r)=>{i.toBlob(c=>c===null?r(new Error("encode failed")):a(c),"image/jpeg",t)})}function $t(e,t={}){let i=t.now??(()=>performance.now()),a=t.setTimer??((m,C)=>setTimeout(m,C)),r=t.clearTimer??(m=>clearTimeout(m)),c=t.encode??ze,l=t.quality??Je,u=e.tuningVersion??null,p=new Set,S=!1,y=e.video??null,E=null,f=t.grabFrame??null,b=null,v=1e3/Ee,A=null,I=null,T=!1,N=!1,D=Number.NEGATIVE_INFINITY,M=null,G=0,L=null,B=null,J=Promise.all([import("./icao-gate-SO6YJ7RV.js"),import("./icao-tuning-DCZCMCEQ.js"),import("./create-portrait-capture-VRZZOMJS.js"),import("./landmarker-3BBP3RBY.js"),import("./background-monitor-GCMNCJMG.js")]).then(async([m,C,R,w,O])=>{let k=C.resolveIcaoTuning(e.tuning,e.tuningVersion??void 0);k.background.required&&(I=O.createBackgroundMonitor({tuning:k.backgroundCheck,assetBaseUrl:e.assetBaseUrl??"/models-v3",...t.createSegmenter!==void 0?{createSegmenter:t.createSegmenter}:{},now:i})),E=m.createIcaoGate(k,{policy:e.policy??"reject"}),f??(f=R.defaultGrabber()),b=R.observe,v=1e3/Math.min(Ee,k.cadenceHz);let n=(t.createLandmarker??w.createFaceLandmarker)(e.assetBaseUrl??"/models-v3"),o=await new Promise((s,d)=>{let h=setTimeout(()=>{d(new Error("landmarker init timeout")),n.then(g=>g.close(),()=>{})},w.LANDMARKER_INIT_TIMEOUT_MS);n.then(g=>{clearTimeout(h),s(g)},g=>{clearTimeout(h),d(g)})});S?o.close():A=o}).catch(()=>{T=!0}),H=m=>{for(let C of p)C({holding:N||T,update:m})},Y=()=>{if(M=null,!(S||A===null||E===null||f===null||b===null||y===null)){if(i()-D>Ae){H(null);return}try{let m=f(y,Qe);if(m!==null){let C=Math.max(i(),G+1);G=C;let R=A.detect(m.source,C),w=y.videoWidth||m.width,O=y.videoHeight||m.height,k=b(R,m,w,O);k.geometry!==null&&I!==null&&(k.backgroundCheck=I.measure(m,k.geometry.box,w,O));let n=E.push(k,i());N=n.ready,H(n)}}catch{}M=a(Y,v)}},Z=()=>{let m=i()-D>Ae;D=i(),m&&(E?.reset(),N=!1,L=null,B=null),M===null&&A!==null&&!S&&(M=a(Y,0))},z=()=>{let m=f===null||y===null?null:f(y,null);if(m===null||E===null||Math.max(m.width,m.height)<e.still.minLongSidePx)return Promise.resolve(null);let C=E.summary();return c(m,e.still.jpegQuality).then(R=>({image:R,width:m.width,height:m.height,gate:C}),()=>null)},W=null;return{engineOptions:{measureQuality:(m,C)=>{y=m,Z();let R=l(m,C);return N||T?R:{...R,sharpness:0}},telemetry:m=>{if(m.type!=="fired"||S)return;L=z();let C=W;C!==null&&L.then(R=>R===null?void 0:C(R).catch(()=>{})),N=!1,M!==null&&r(M),M=null,D=Number.NEGATIVE_INFINITY}},decorate:m=>{let C=new WeakMap,R=new Map,w=o=>{let s=C.get(o);return s===void 0&&(s=(async()=>{let d=await Pe(m,"image","image/jpeg",o.image.size,{engine:"portrait"});return await m.uploadToSpaces(d.uploadUrl,o.image,"image/jpeg"),(await m.completeMedia(d.key)).key})(),s.catch(()=>C.delete(o)),C.set(o,s)),s};W=w;let O=async o=>{let s;try{s=await w(o)}catch(d){let h=d?.code;if(typeof h=="string"&&$e.has(h))throw d;return null}return{media:{portrait:s},gate:ke(o.gate),...u!==null?{tuningVersion:u}:{}}},k=m.submitCheck.bind(m),n=(async(o,s,d)=>{if(o!=="liveness")return k(o,s,d);let h=d?.idempotencyKey,g=h===void 0?void 0:R.get(h);if(g===void 0){let de=L;g=de===null?Promise.resolve(null):de.then(le=>le===null?null:O(le)),h!==void 0&&(R.set(h,g),g.catch(()=>R.delete(h)))}let P=await g;if(P===null)return k("liveness",s,d);let _=await k("liveness",{...s,portraitIcao:P},d);return B=P,_});return new Proxy(m,{get(o,s){if(s==="submitCheck")return n;let d=Reflect.get(o,s);return typeof d=="function"?d.bind(o):d}})},onGate:m=>(p.add(m),()=>p.delete(m)),lastPortraitInput:()=>B,destroy:()=>{S=!0,L=null,B=null,M!==null&&r(M),M=null,p.clear(),J.then(()=>{A?.close(),A=null,I?.close(),I=null})}}}function Te(e){return e.idNumberBound??e.nniBound}function Oe(e){return e===void 0?void 0:e.idNumberFromDocument??e.nniFromDocument}function we(e){let t=e.idNumberMasked??e.nniMasked;return typeof t=="string"&&t!==""?t:void 0}var xe=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",sandbox_nni_not_seeded:"sandbox_id_number_not_seeded",missing_nni:"missing_id_number",registry_needs_nni_source:"registry_needs_id_number_source"}),Xe=new Map(Object.entries(xe)),Xt=new Map(Object.entries(xe).map(([e,t])=>[t,e]));function Ne(e){return Xe.get(e)??e}var et=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"]),tt=new Set(["supplied_identity","aml_screening","face_dedup","age_estimation"]),ie=["document","population_registry","national_eid"],oe=["phone_otp","email_otp"],De={identity_method:ie,contact:oe},nt=["population_registry","document"],re="platform_unsupported",it=new Set(["prefilled","user_entered","prefilled_or_entered"]),ot={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"};function V(e){return e.section??ot[e.checkType]??null}function se(e,t){let i=e.plan?.choice;if(i===void 0||i.locked)return;let a=i.options.find(r=>r.id!==i.selected&&r.available!==!1&&t.includes(r.service));return a===void 0?void 0:{nodeId:i.nodeId,option:a}}function ae(e){let t=e.plan,i=t?.choice;if(t===void 0||i===void 0||i.locked||t.current===null||t.current===i.nodeId||ee(e))return null;let a=De[i.kind]??[...ie,...oe],r=i.options.flatMap(u=>u.available===!1||!a.includes(u.service)?[]:[u.nationalEid!=null?{id:u.id,service:u.service,nationalEid:u.nationalEid}:{id:u.id,service:u.service}]),c=t.steps.find(u=>u.id===t.current)?.service,l=i.selected??r.find(u=>u.service===c)?.id??null;return r.some(u=>u.id!==l)?{nodeId:i.nodeId,kind:i.kind,current:l,options:r}:null}function He(e){return e==null?[]:e.options.filter(t=>t.id!==e.current)}function rt(e){let t=e.simulation;if(typeof t!="object"||t===null)return;let{otpCode:i,skipCapture:a}=t;return typeof i=="string"&&i!==""&&typeof a=="boolean"?{otpCode:i,skipCapture:a}:void 0}function st(e){let t=(e.plan?.sections??[]).map(c=>({id:c.id,state:c.state})),i={sessionId:te(e.sessionId),orgName:e.orgName,returning:e.returning===!0,consentRecorded:e.consentRecorded,expiresAt:e.expiresAt,sections:t.map(c=>c.id),progress:t,purpose:e.purpose??"identity"};e.branding!==void 0&&(i.branding=e.branding),e.cameraUnavailableHandled===!0&&(i.cameraUnavailableHandled=!0);let a=rt(e);a!==void 0&&(i.simulation=a);let r=ae(e);return r!==null&&(i.switchable=r),i}function at(e){let t={attemptsRemaining:Se(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 Ge={phone_otp:"phone",email_otp:"email"};function ct(e,t){let i=se(e,[t==="phone_otp"?"email_otp":"phone_otp"]);return i===void 0?void 0:Ge[i.option.service]}function ut(e,t,i,a){let r=t.checkType==="email_otp",c=(r?t.emailOtp:t.otp)??{},l=r?t.emailOtp?.emailSource:t.otp?.numberSource,u=l!==void 0&&it.has(l)?l:r?"prefilled_or_entered":"user_entered",p=typeof c.sentToMasked=="string"&&c.sentToMasked.length>0,S=c.prefilled===!0,y=ct(e,r?"email_otp":"phone_otp"),E={key:t.checkType,context:i,section:V(t),phase:p?"verify":"send",canSwitch:y!==void 0,...a},f=r?{kind:"email_otp",...E,emailSource:u,needsEmail:u!=="prefilled"&&!S}:{kind:"phone_otp",...E,numberSource:u,needsPhone:u!=="prefilled"&&!S,channels:(t.otp?.channels??[]).filter(b=>b==="whatsapp"||b==="sms")};if(y!==void 0&&(f.switchChannel=y),S&&(f.prefilled=!0),p&&(f.sentToMasked=c.sentToMasked),!r&&t.otp?.channel!==void 0&&(f.channel=t.otp.channel),!r&&Array.isArray(t.phoneCountries)&&(f.phoneCountries=t.phoneCountries.filter(b=>typeof b=="string"&&/^[A-Z]{2}$/.test(b))),!r&&Array.isArray(t.phoneRules)){let b=f.phoneCountries??[];f.phoneRules=t.phoneRules.flatMap(v=>{let A=pt(v);return A!==void 0&&b.includes(A.code)?[A]:[]})}return!r&&t.phoneInternational===!0&&(f.phoneInternational=!0),c.expiresAt!==void 0&&(f.codeExpiresAt=c.expiresAt),c.resendAvailableAt!==void 0&&(f.resendAvailableAt=c.resendAvailableAt),f}var dt=/^[\d[\]\-|()?:^]{1,64}$/;function lt(e){try{return typeof e=="string"&&dt.test(e)&&new RegExp(e)!==null}catch{return!1}}var Le=e=>typeof e=="number"&&Number.isInteger(e)&&e>=1&&e<=15;function pt(e){let{code:t,dial:i,trunk:a,lengths:r,formats:c}=e??{};if(typeof t!="string"||typeof i!="string"||!/^\d{1,3}$/.test(i)||a!==void 0&&(typeof a!="string"||!/^\d{1,3}$/.test(a))||!Array.isArray(r)||r.length===0||!r.every(Le))return;let l={code:t,dial:i,lengths:[...r].sort((u,p)=>u-p)};if(a!==void 0&&(l.trunk=a),c!==void 0){if(!(Array.isArray(c)&&c.length<=8&&c.every(p=>lt(p?.leading)&&Array.isArray(p.groups)&&p.groups.every(Le)&&r.includes(p.groups.reduce((S,y)=>S+y,0)))))return;l.formats=c.map(p=>({leading:p.leading,groups:[...p.groups]}))}return l}function mt(e,t,i,a){let r=Te(e)===!0?"bound":Oe(t)===!0?"document":"typed",c=r==="typed"&&t.state==="input_required"&&t.reason!==void 0&&Ne(t.reason)==="id_number_recheck",l=He(ae(e)),u=!a.attemptsExhausted&&l.length===1&&l[0]?.service==="document";return{kind:"registry",key:"registry",context:i,section:V(t),state:t.state==="input_required"?"input_required":"pending",source:r,recheck:c,canUseDocument:u,...a}}function ft(e,t,i,a,r){let c=[...t.acceptedSides??[]],l={kind:"document",key:"document",context:i,section:V(t),side:c.includes("recto")?"verso":"recto",acceptedSides:c,documents:Me(e),photo:Ue(Be(e.documents),r),...a};return e.detectedCountry!==void 0&&(l.detectedCountry=e.detectedCountry),ht(e)&&(l.ageStepUp=!0),l}function Be(e,t=!0){let i=e?.source==="upload"||e?.source==="choice"?e.source:"camera",a=e?.sourcePick==="camera"||e?.sourcePick==="upload"?e.sourcePick:null;return{source:i,pick:a,uploadOffered:t&&e?.uploadOffered===!0}}function Ue(e,t){return t?{...e,cameraOnPhone:!0}:e}function ht(e){let t=he(e).find(a=>a.checkType==="age_estimation"),i=t?.reason;return t?.state==="failed"&&(i==="age_uncertain"||i==="age_unavailable")}function St(e){let t=q(e,"liveness");return t?.state==="passed"||t?.state==="review"}function Ve(e,t,i,a,r,c=!1){let l=t.icao?.report,u=e.portrait,p=r==="capture"?u?.pendingFix??null:null;p!==null&&(r="review");let S=Fe(e);return{kind:"portrait",key:`portrait:${r}`,context:i,section:V(t),phase:r,report:Array.isArray(l)?l:null,review:t.state==="review",tuning:e.capture?.icao??null,tuningVersion:e.capture?.tuningVersion??null,icao:Q(e),retakeOnly:r==="capture"&&t.state==="input_required"&&S===void 0&&e.capture?.livePhoto?.oneCapture===!0&&St(e),photo:Ue(Be(u,r==="capture"),c&&r==="capture"),pendingFix:p,...S!==void 0?{captureMode:S}:{},...u?.reuse?.pending===!0?{reuse:!0}:{},...a}}function Fe(e){let t=e.portrait?.captureMode;return t==="self"||t==="assisted"||t==="choice"?t:void 0}var ne={minLongSidePx:1280,jpegQuality:.95};function gt(e,t){let i=e.capture?.livePhoto;if(i?.oneCapture!==!0)return null;let a=q(e,"portrait_icao"),r=i.still??ne;return{icao:t==="liveness"&&Q(e)!==null&&Fe(e)===void 0&&a!==void 0&&a.state==="pending"&&a.reason===void 0,still:{minLongSidePx:r.minLongSidePx??ne.minLongSidePx,jpegQuality:r.jpegQuality??ne.jpegQuality}}}function yt(e,t,i,a){let r=t.eid,c=V(t);if(r===void 0||r.challenge!=="app_code")return{kind:"unsupported",key:"unsupported:eid_auth",context:i,section:c,checkType:"eid_auth",reason:"update_required"};let l=He(ae(e)),u=l.length===1&&nt.includes(l[0]?.service??"")?l[0]:void 0,p=u===void 0?void 0:K[u.service],S=p!==void 0,y={kind:"eid",key:"eid",context:i,section:c,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",...a};return S&&(y.cameraMethod=p),r.expiresAt!==void 0&&(y.codeExpiresAt=r.expiresAt),r.resendAvailableAt!==void 0&&(y.resendAvailableAt=r.resendAvailableAt),r.resendsRemaining!==void 0&&(y.resendsRemaining=r.resendsRemaining),r.codeAttemptsRemaining!==void 0&&(y.codeAttemptsRemaining=r.codeAttemptsRemaining),y}function bt(e,t){if(t.checkType!=="face_match"||t.reason!==void 0)return null;let i=q(e,"portrait_icao");return i!==void 0&&(i.state==="passed"||i.state==="review")?i:null}var Ct={rejected:"rejected",inconclusive:"inconclusive",unavailable:"unavailable",abandoned:"expired",not_opened:"expired",cancelled:"expired",superseded:"expired",policy:"policy"};function Pt(e){return e.reasonCode===re?"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?Ct[e.reason]:void 0)??"rejected"}function _t(e,t){let i=Pt(e),a=i==="platform_unsupported"?{sessionId:te(e.sessionId),status:"unavailable",reasonCode:re}:be(e,{autoRetry:!1}),r={kind:"result",key:"result",context:t,section:null,display:i,result:a};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 kt(e,t,i){let a=e.identitySummary;if(a==null)return null;let r={kind:"identity_summary",key:"identity_summary",context:t,section:i??"identity",summaryKind:a.kind==="partial"?"partial":a.kind??"full",source:a.source,portraitAvailable:a.portrait?.available===!0,retakeAvailable:a.retakeAvailable===!0};for(let l of Rt){let u=a[l];typeof u=="string"&&u!==""&&(r[l]=u)}let c=we(a);return c!==void 0&&(r.idNumberMasked=c,r.nniMasked=c),r}var Rt=["fullName","birthDate","birthYear","nationality","documentType","documentNumberMasked","expiryDate","retakeTarget"];function U(e,t,i,a){return{kind:"unsupported",key:`unsupported:${i}`,context:e,section:t,checkType:i,reason:a}}function Mt(e){return e.kind==="contact"?"contact":(e.kind==="identity_method","identity")}function Et(e,t){let i=De[e.kind]??[...ie,...oe],a=Mt(e),r=e.options.flatMap(l=>{if(l.available===!1||!i.includes(l.service))return[];let u={id:l.id,service:l.service};l.nationalEid!=null&&(u.nationalEid=l.nationalEid);let p=(l.channels??[]).filter(S=>S==="whatsapp"||S==="sms");return l.service==="phone_otp"&&p.length>0&&(u.channels=p),[u]});if(r.length===0){let l=e.options.length>0&&e.options.every(u=>u.service==="nfc");return U(t,a,"choice",l?"platform_unsupported":"update_required")}let c={nodeId:e.nodeId,kind:e.kind,selected:e.selected,options:r};if(e.kind==="identity_method"){let l={kind:"method",key:"method",context:t,section:a,options:r.map(p=>K[p.service]),choice:c},u=r.find(p=>p.nationalEid!==void 0)?.nationalEid;return u!==void 0&&(l.nationalEid=u),l}return e.kind==="contact"?{kind:"contact_choice",key:"contact_choice",context:t,section:a,options:r.map(l=>Ge[l.service]),selected:null,locked:!1,choice:c}:{kind:"choice",key:`choice:${e.nodeId}`,context:t,section:a,choice:c}}function $(e,t={}){let i=st(e);if(ee(e)||e.reasonCode===re)return _t(e,i);let a=e.plan;if(a===void 0||!Array.isArray(a.sections))return U(i,null,"plan","update_required");let r=ge(e);if(r!==null)return Et(r,i);let c=a.current===null?void 0:a.steps.find(f=>f.id===a.current),l=f=>{let b={kind:"processing",key:"processing",context:i,section:f!==void 0?V(f):a.sections.find(v=>v.state==="current")?.id??null,stalled:!1};return typeof f?.service=="string"&&f.service!==""&&(b.service=f.service),b};if(a.current===null)return l(a.steps.find(f=>f.state==="processing"));if(c===void 0)return U(i,null,"step","update_required");if(!et.has(c.service))return c.interaction==="server"?l(c):U(i,V(c),c.service,"update_required");if(tt.has(c.service)||!ye(c))return l(c);let u=c,p=at(u),S=u.checkType,y=V(u),E=t.isMobile===!1?Ce(e,u):null;if(E==="phone")return{kind:"mobile_required",key:"mobile_required",context:i,section:y,checkType:S};switch(S){case"phone_otp":case"email_otp":return ut(e,u,i,p);case"population_registry":return mt(e,u,i,p);case"eid_auth":return yt(e,u,i,p);case"doc_ocr":return ft(e,u,i,p,E==="upload_or_phone");case"identity_confirm":return kt(e,i,y)??l(u);case"portrait_icao":return Ve(e,u,i,p,"capture",E==="upload_or_phone");case"liveness":case"face_match":{let f=bt(e,u);if(f!==null)return Ve(e,f,i,p,"match");let b=u.requiresMobile===!0,v=Q(e);return{kind:"liveness",key:"biometric",context:i,section:y,mode:S==="face_match"?"selfie":"liveness",requiresMobile:b,instructions:v===null?"standard":"icao",icao:v,livePhoto:gt(e,S),...p}}case"nfc_chip":return U(i,y,S,"platform_unsupported");default:return U(i,y,S,"update_required")}}var At=/^[A-Z0-9][A-Z0-9 -]{0,39}$/,It=Object.freeze({normalize:e=>e.trim().toUpperCase().replace(/\s+/g," "),check:e=>At.test(e),registrySources:Object.freeze([]),describe:"number must be 1 to 40 letters, digits, spaces or hyphens"});function vt(e){return typeof e=="string"&&/^\d{10}$/.test(e)&&Number(e)%97===1}var Tt=Object.freeze({normalize:e=>e.trim(),check:e=>vt(e),registrySources:Object.freeze(["MR.anrpts"]),describe:"number must be the 10-digit Mauritanian national ID number with a valid check digit"}),Ot=Object.freeze({"MR:national_id":Tt});function ce(e,t){return Ot[`${e.toUpperCase()}:${t}`]??It}var wt=Object.freeze({MRT:"MR"});function Ke(e,t){let i=e.trim().toUpperCase();return ce(wt[i]??i,t)}function je(e){let t=Ke(e.issuingCountry,e.type);return t.check(t.normalize(e.number))}function Ye(e){return ce("MR","national_id").check(e)}function ue(e){let t="";for(let i of e){let a=i.codePointAt(0)??0;a>=1632&&a<=1641?t+=String(a-1632):a>=1776&&a<=1785?t+=String(a-1776):i!==" "&&i!=="-"&&i!==" "&&(t+=i)}return t}var xt=[1e3,2e3,4e3,8e3,15e3],Nt=3e4,Lt=/^\+[1-9]\d{6,14}$/,Vt=/^\d{6}$/,Dt=/^\d{6}$/,Ht=/^[^\s@]+@[^\s@]+\.[^\s@]+$/,Ze=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"]),Gt={simulatedCapture:!0},Bt=new Set(["network_error","timeout","upload_failed","unknown_error","rate_limit_exceeded"]);function yn(e){let t=!1,i=null,a="",r=!1,c=!1,l=!1,u={},p={},S=new Set,y=!1,E=!1,f=null,b="idle",v=new Map,A=new Map,I=(n,o,s)=>{let d=`${n}.${o}`,h=v.get(d);if(h!==void 0)return h;let g=A.get(n),P=(g===void 0?s():g.then(s)).finally(()=>{v.delete(d)});v.set(d,P);let _=P.then(()=>{},()=>{});return A.set(n,_),_.then(()=>{A.get(n)===_&&A.delete(n)}),P},T=async(n,o,s)=>{await e.ensureConsent();let d;try{d=await _e(e.runtime,o)}catch(g){if(g instanceof F&&Ze.has(g.code)){await e.refreshView();return}throw g}if(s?.(d),e.destroyed())return;let h=d;h.plan!==void 0&&e.setView!==void 0?e.setView(h):await e.refreshView()},N=async n=>{await e.ensureConsent();let o;try{try{o=await n(e.runtime.client)}catch(s){if(!(s instanceof F)||s.code!=="consent_required")throw s;await e.runtime.ensureConsent({force:!0}),o=await n(e.runtime.client)}}catch(s){if(s instanceof F&&Ze.has(s.code)){await e.refreshView();return}throw s}e.destroyed()||(o!==void 0&&e.setView!==void 0?e.setView(o):await e.refreshView())},D=(n,o)=>I("choice",`${n}:${o}`,()=>N(s=>s.choose(n,o))),M=(n,o)=>n.options.some(s=>s.id===o)?D(n.nodeId,o):Promise.reject(new RangeError(`option ${String(o)} is not offered`)),G=(n,o)=>{let s=e.currentView(),d=s===null?void 0:se(s,n);return d===void 0?Promise.reject(new RangeError(`the ${o} is not offered`)):D(d.nodeId,d.option.id)},L=n=>I("identity",n,()=>N(o=>o.confirmIdentity===void 0?Promise.reject(new Error("identity confirmation is not available in this build")):o.confirmIdentity(n))),B=(n,o)=>{let s=n.kind,d=s==="phone_otp",h=d?"phone":"email",g={action:"send"};if(d?n.needsPhone:n.needsEmail){let P=o[h]??p[s],_=d?P?.replace(/[\s().-]/g,""):P?.trim();if(_!==void 0||n.phase!=="verify"){if(_===void 0||!(d?Lt:Ht).test(_))return Promise.reject(d?new x("phone","format"):new j("email","format"));g[h]=_}}if(d){let P=n.channels,_=o.channel??(P.length===1?P[0]:void 0);if(P.length>0){if(_===void 0)return Promise.reject(new j("channel","required"));if(!P.includes(_))return Promise.reject(new j("channel","unavailable"))}_!==void 0&&(g.channel=_),g.phoneRules=1}return I(s,"send",()=>T(s,(P,_)=>P.submitCheck(s,g,{idempotencyKey:_}),P=>{Ft(P,s)||(u[s]=e.now(),g[h]!==void 0&&(p[s]=g[h]))}))},J=(n,o)=>Vt.test(o)?I(n,"verify",()=>T(n,(s,d)=>s.submitCheck(n,{action:"verify",code:o},{idempotencyKey:d}))):Promise.reject(new x("code","format")),H=(n,o)=>I("eid_auth",n,()=>T("eid_auth",(s,d)=>s.submitCheck("eid_auth",o,{idempotencyKey:d}))),Y=(n,o)=>{if(n.identifierBound)return H("start",{action:"start"});let s=ue(o??"");if(n.country==="MR"){if(!/^\d{10}$/.test(s))return Promise.reject(new x("nni","format"));if(!Ye(s))return Promise.reject(new x("nni","check_digit"))}else if(s==="")return Promise.reject(new x("nni","format"));return H("start",{action:"start",identifier:s})},Z=(n,o,s)=>{if(n.source!=="typed")return Promise.reject(new RangeError("this session already holds the ID number"));let d=ue(o);return/^\d{10}$/.test(d)?je({type:"national_id",issuingCountry:"MR",number:d})?I("population_registry","submitIdNumber",()=>T("population_registry",(h,g)=>h.submitCheck("population_registry",{idNumber:d,nni:d},{idempotencyKey:g}),()=>{f=`\u2022\u2022\u2022\u2022\u2022\u2022${d.slice(-4)}`})):Promise.reject(new x(s,"check_digit")):Promise.reject(new x(s,"format"))},z=n=>(e.stopCameras?.(),I(n,"skipCapture",()=>T(n,(o,s)=>o.submitCheck(n,Gt,{idempotencyKey:s}),()=>{(n==="liveness"||n==="portrait_icao")&&(y=!0)}))),W=n=>{if(n.kind==="result"||n.context.simulation?.skipCapture!==!0)return n;let o=Ut(n);return o===null?n:{...n,skipCapture:()=>z(o)}},X=n=>((n.kind==="document"||n.kind==="portrait")&&n.photo?.cameraOnPhone===!0&&(n.refresh=async()=>{await e.refreshView()}),n),m=n=>{switch(n.kind){case"phone_otp":case"email_otp":{let o={...n,send:(d={})=>B(n,d),verify:d=>J(n.kind,d),switchTo:()=>n.canSwitch&&n.switchChannel!==void 0?G([n.switchChannel==="email"?"email_otp":"phone_otp"],"other contact option"):Promise.reject(new RangeError("this session has no other contact option"))},s=u[n.kind];return o.resendAvailableAt===void 0&&s!==void 0&&(o.resendAvailableAt=new Date(s+Nt).toISOString()),o}case"eid":return{...n,start:o=>Y(n,o),verify:o=>Dt.test(o)?H("verify",{action:"verify",code:o}):Promise.reject(new x("code","format")),resend:()=>n.resendsRemaining===0?Promise.reject(new RangeError("no new code can be sent for this session")):H("resend",{action:"resend"}),useCamera:()=>n.canUseCamera&&n.cameraMethod!==void 0?G(n.cameraMethod==="document_photo"?["document"]:["population_registry"],"camera path"):Promise.reject(new RangeError("the camera path is not offered"))};case"method":return{...n,select:o=>{let s=n.choice.options.find(d=>K[d.service]===o);return s!==void 0?M(n.choice,s.id):Promise.reject(new RangeError(`method ${String(o)} is not offered`))},choose:o=>M(n.choice,o)};case"choice":return{...n,choose:o=>M(n.choice,o)};case"registry":return{...n,submitIdNumber:o=>Z(n,o,"idNumber"),submitNni:o=>Z(n,o,"nni"),confirm:()=>I("population_registry","confirm",()=>T("population_registry",(o,s)=>o.submitCheck("population_registry",{},{idempotencyKey:s}))),useDocument:()=>n.canUseDocument?G(["document"],"document method"):Promise.reject(new RangeError("the document method is not offered"))};case"document":return e.bindDocument!==void 0?X(e.bindDocument(n,k)):{...n,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?X(e.bindPortrait(n,k)):{...n,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"contact_choice":return{...n,select:o=>{let s=o==="phone"?"phone_otp":o==="email"?"email_otp":void 0,d=n.choice.options.find(h=>h.service===s);return d!==void 0?M(n.choice,d.id):Promise.reject(new RangeError(`contact ${String(o)} is not offered`))},choose:o=>M(n.choice,o)};case"identity_summary":return{...n,...n.idNumberMasked===void 0&&n.summaryKind==="partial"&&f!==null?{idNumberMasked:f,nniMasked:f}:{},portrait:async()=>{let o=e.runtime.client;if(!n.portraitAvailable||o.identityPortrait===void 0)return null;try{return await o.identityPortrait()}catch{return null}},confirm:()=>L("confirm"),retake:()=>n.retakeAvailable?L("retake"):Promise.reject(new RangeError("no retake is left"))};case"liveness":return{...n,capture:o=>e.liveness(o),onLivePhoto:o=>n.livePhoto?.icao===!0&&e.onLivePhoto!==void 0?e.onLivePhoto(o):()=>{}};case"mobile_required":case"processing":return{...n,refresh:async()=>{r=!1,await e.refreshView()}};case"unsupported":case"result":return{...n};default:{let o=n;throw new Error(`runner: unhandled step ${JSON.stringify(o)}`)}}},C=n=>W(m(n)),R=async()=>{if(!c){c=!0;try{for(let n of xt){if(await e.sleep(n),!t||e.destroyed())return;let o=await e.refreshView().catch(()=>null);if(o!==null&&$(o,{isMobile:e.isMobile()}).kind!=="processing")return}r=!0,k()}finally{c=!1}}},w=n=>{if(n.kind!=="liveness"||n.mode!=="selfie")return null;let o={kind:"processing",key:"processing",context:n.context,section:n.section,stalled:!1};if(b==="inflight")return o;if(!E||b==="done")return null;let s=e.keptFaceKey?.()??null;return s===null?null:(b="inflight",T("face_match",(d,h)=>d.submitCheck("face_match",{imageKey:s},{idempotencyKey:h}),()=>{b="done"}).then(()=>{b==="inflight"&&(b="done",k())},()=>{b="done",k()}),o)},O=(n,o=!1)=>{if(!t||e.destroyed()||e.chainBusy())return;let s=$(n,{isMobile:e.isMobile()});s.kind==="registry"&&s.recheck&&(E=!0,b="idle"),s=w(s)??s,s.kind==="processing"?s.stalled=r:r=!1;let d=C(s),h=s.kind==="result"?void 0:s.context.switchable,g=h===void 0?d:{...d,chooseOption:_=>M({nodeId:h.nodeId,kind:h.kind,selected:h.current,options:h.options},_)},P=JSON.stringify(g);s.kind==="registry"&&s.source==="document"&&s.state==="pending"&&!S.has("registry")&&(S.add("registry"),g.confirm().catch(_=>{(!(_ instanceof F)||Bt.has(_.code))&&S.delete("registry")})),!(!o&&P===a)&&(a=P,i=g,e.emitStep(g),s.kind==="processing"&&!r&&b!=="inflight"&&R(),s.kind==="result"&&!l&&(l=!0,e.emitResult(s.result)))};function k(){let n=e.currentView();n!==null&&O(n,!0)}return{run:async()=>{if(e.destroyed())throw new Error("verification destroyed");t=!0;let n=await e.ensureView();return i===null&&O(n),i??C($(n,{isMobile:e.isMobile()}))},current:()=>i,onView:n=>O(n),onChainIdle:()=>{let n=e.currentView();n!==null&&O(n)},republish:k,submit:T,faceProbeSkipped:()=>y}}function Ut(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"mobile_required":return e.checkType;case"unsupported":return e.checkType==="nfc_chip"?"nfc_chip":null;default:return null}}function Ft(e,t){let i=e,a=i?.plan?.steps??i?.steps;return Array.isArray(a)?a.some(r=>r.checkType===t&&typeof r.reason=="string"):!1}export{qe as a,Yt as b,Ee as c,Ae as d,$t as e,Fe as f,$ as g,xt as h,Nt as i,yn as j};
@@ -1 +1 @@
1
- import{b as M}from"./chunk-GI3UFGRQ.js";var A=2;function L(u){let l=u.tuning,s=u.now??(()=>performance.now()),t=null,o=!1,g=!1,d=Number.NEGATIVE_INFINITY,a=null,h=0,i=null,n=null,f=0,p=!1,T=()=>{if(p||!l.enabled)return;p=!0;let r=(u.createSegmenter??(e=>import("./segmenter-USLNBX65.js").then(m=>m.createSelfieSegmenter(e))))(u.assetBaseUrl);n=setTimeout(()=>{t===null&&(o=!0)},l.segmenterTimeoutMs),r.then(e=>{n!==null&&clearTimeout(n),g||o?e.close():t=e},()=>{n!==null&&clearTimeout(n),o=!0})};return{measure(r,e,m,S){if(!l.enabled||r.pixels===null)return null;T();let c=s();if(c-d<1e3/l.hz)return a;d=c;let k=r.width/Math.max(1,m),y=r.height/Math.max(1,S),w={x:e.x*k,y:e.y*y,width:e.width*k,height:e.height*y},B=null;if(t!==null&&!o){let x=Math.max(c,h+1);h=x;let U=s();B=t.segment(r.source,x);let b=s()-U;f+=1,f>A&&(i=i===null?b:i*.7+b*.3),i!==null&&i>l.segmenterBudgetMs&&(o=!0,t.close(),t=null)}return a=M(r.pixels,w,B,l),a},close(){g=!0,n!==null&&clearTimeout(n),t?.close(),t=null}}}export{L as a};
1
+ import{b as M}from"./chunk-LL3YYUKR.js";var A=2;function L(u){let l=u.tuning,s=u.now??(()=>performance.now()),t=null,o=!1,g=!1,d=Number.NEGATIVE_INFINITY,a=null,h=0,i=null,n=null,f=0,p=!1,T=()=>{if(p||!l.enabled)return;p=!0;let r=(u.createSegmenter??(e=>import("./segmenter-3CVPTZMM.js").then(m=>m.createSelfieSegmenter(e))))(u.assetBaseUrl);n=setTimeout(()=>{t===null&&(o=!0)},l.segmenterTimeoutMs),r.then(e=>{n!==null&&clearTimeout(n),g||o?e.close():t=e},()=>{n!==null&&clearTimeout(n),o=!0})};return{measure(r,e,m,S){if(!l.enabled||r.pixels===null)return null;T();let c=s();if(c-d<1e3/l.hz)return a;d=c;let k=r.width/Math.max(1,m),y=r.height/Math.max(1,S),w={x:e.x*k,y:e.y*y,width:e.width*k,height:e.height*y},B=null;if(t!==null&&!o){let x=Math.max(c,h+1);h=x;let U=s();B=t.segment(r.source,x);let b=s()-U;f+=1,f>A&&(i=i===null?b:i*.7+b*.3),i!==null&&i>l.segmenterBudgetMs&&(o=!0,t.close(),t=null)}return a=M(r.pixels,w,B,l),a},close(){g=!0,n!==null&&clearTimeout(n),t?.close(),t=null}}}export{L as a};
@@ -0,0 +1 @@
1
+ var h="https://challenges.cloudflare.com/turnstile/v0/api.js",y=3e4;function f(){return window.turnstile}var l=null,i=null,p=Promise.resolve();function P(){l=null,i?.container.remove(),i=null,p=Promise.resolve()}function v(){return l??(l=new Promise((t,e)=>{let r=f();if(r){t(r);return}let n=document.createElement("script");n.src=h,n.async=!0,n.onload=()=>{let s=f();s?t(s):(l=null,e(new Error("Turnstile script loaded but exposed no API")))},n.onerror=()=>{l=null,n.remove(),e(new Error("Turnstile script failed to load"))},document.head.appendChild(n)})),l}function c(){return new Error("Turnstile challenge aborted")}function w(t,e){if(i!==null&&i.siteKey===e)return i;if(i!==null){try{t.remove(i.id)}catch{}i.container.remove(),i=null}let r=document.createElement("div");document.body.appendChild(r);let n={siteKey:e,container:r,fresh:!0,pending:null},s=t.render(r,{sitekey:e,execution:"execute",appearance:"execute",callback:o=>n.pending?.resolve(o),"error-callback":o=>n.pending?.reject(new Error(`Turnstile challenge failed${o?` (${o})`:""}`))});if(s===void 0)throw r.remove(),new Error("Turnstile render returned no widget id");return n.id=s,i=n,i}function x(t){let e=i;if(e!==null){i=null;try{t?.remove(e.id)}catch{}e.container.remove()}}function b(t,e){try{t.reset(e.id),e.fresh=!1}catch{i===e&&(e.container.remove(),i=null)}}function A(t,e={}){let r=p.then(()=>T(t,e),()=>T(t,e));return p=r.catch(()=>{}),r}async function T(t,e){try{return await E(t,e)}catch(r){if(e.signal?.aborted)throw r;return x(f()),E(t,e)}}async function E(t,e){let r=e.timeoutMs??3e4,n=e.signal;if(n?.aborted)throw c();let s=await v();if(n?.aborted)throw c();let o=w(s,t),g,u,m=!1;try{return await new Promise((d,a)=>{o.pending={resolve:d,reject:a},g=setTimeout(()=>a(new Error(`Turnstile challenge timed out (${r} ms)`)),r),n!==void 0&&(u=()=>a(c()),n.addEventListener("abort",u,{once:!0})),o.fresh||s.reset(o.id),o.fresh=!1,s.execute(o.id)}).then(d=>(m=!0,d))}finally{clearTimeout(g),n!==void 0&&u!==void 0&&n.removeEventListener("abort",u),o.pending=null,m||b(s,o)}}export{h as a,y as b,P as c,v as d,A as e};
@@ -0,0 +1 @@
1
+ var f="0.1.0-rc.22.1";var T=/FBAN|FBAV|FB_IAB|FBIOS|MessengerForiOS|Instagram|WhatsApp|musical_ly|BytedanceWebview|TikTok|Snapchat|\bLine\/|LinkedInApp|Pinterest|MicroMessenger|; wv\)/i;function p(t){let e=t??(typeof navigator>"u"?"":String(navigator.userAgent??""));return T.test(e)}var h="sekyro.did",P=1e4,v=()=>globalThis.process?.versions?.node,y;function b(){let t=globalThis.crypto;try{if(typeof t?.randomUUID=="function")return t.randomUUID()}catch{}try{if(typeof t?.getRandomValues=="function"){let e=t.getRandomValues(new Uint8Array(16));return Array.from(e,r=>r.toString(16).padStart(2,"0")).join("")}}catch{}}function I(){try{let t=localStorage.getItem(h);if(t)return t;let e=b();return e!==void 0&&localStorage.setItem(h,e),e}catch{return y??(y=b()),y}}async function w(){let t=globalThis.crypto?.subtle;if(!t)return"";let e=navigator,r=JSON.stringify([e.userAgent,e.platform,e.hardwareConcurrency??null,e.deviceMemory??null,e.maxTouchPoints??0,screen.width,screen.height,screen.colorDepth,globalThis.devicePixelRatio??1,Intl.DateTimeFormat().resolvedOptions().timeZone,e.languages?.join(",")??e.language]),i=await t.digest("SHA-256",new TextEncoder().encode(r));return Array.from(new Uint8Array(i),o=>o.toString(16).padStart(2,"0")).join("").slice(0,32)}function k(){try{let t=Number(navigator.maxTouchPoints);return Number.isFinite(t)&&t>=0?{touch:Math.min(64,Math.trunc(t))}:{}}catch{return{}}}function x(t){let e=new TextEncoder().encode(t),r="";for(let i of e)r+=String.fromCharCode(i);return btoa(r).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function A(t){let e,r,i,o,a,l,u=()=>l?.readyState==="live",_=()=>{a!==void 0||!globalThis.crypto?.subtle||v()||u()||(a=Promise.race([import("./print-4WOMNRBE.js"),new Promise(n=>setTimeout(n,P))]).then(n=>n?.computePrint(u)).then(n=>{n==="busy"?a=void 0:o=n}).catch(()=>{}))};return{timezone(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone?.slice(0,64)||void 0}catch{return}},noteCameraLabel(n){n&&(e=n.slice(0,128))},noteCamera(n){r=n},noteCameraTrack(n){l=n},async deviceHeader(){try{i??(i=w().catch(()=>""));let n=[];navigator.webdriver&&n.push("webdriver"),/HeadlessChrome/.test(navigator.userAgent)&&n.push("headless");let g=await i,m=I(),S={v:1,platform:"web",sdk:t.sdk.slice(0,64),ids:[...m?[{kind:"web_local",value:m.slice(0,128)}]:[],...g?[{kind:"web_fp",value:g}]:[]],screen:{w:screen.width,h:screen.height,dpr:globalThis.devicePixelRatio??1},...k(),...e?{cameraLabel:e}:{},...n.length?{signals:n}:{},...o?{print:{v:2,...o,...r?{camera:r}:{}}}:{},...p()?{inApp:!0}:{}},C=x(JSON.stringify(S));return _(),C}catch{return}},printReady(){return a??Promise.resolve()}}}var s=Symbol.for("sekyro.web.clientContext"),c=globalThis,d=c[s]??(c[s]=A({sdk:`@sekyro/web@${f}`}));function M(t){try{let e=t.getVideoTracks?.()[0];if(e){if(d.noteCameraLabel(e.label),d.noteCameraTrack(e),v())return;import("./camera-trait-HVV5ZEDI.js").then(r=>r.noteCameraTrait(e,d)).catch(()=>{})}}catch{}}export{f as a,p as b,d as c,M as d};
@@ -1 +1 @@
1
- import{a as d,c as p}from"./chunk-GI3UFGRQ.js";var f={id_document:{pose:{yawDeg:7,pitchDeg:7,rollDeg:5,pitchOffsetDeg:4},eyes:{relativeMin:.62,blinkMax:.48,lowerEyeMin:.32},mouth:{jawOpenMax:.13,smileMax:.28,puckerMax:.48},lighting:{faceLuma:[95,185],halfRatio:[.77,1.31],clippedMax:.015},background:{required:!0,lumaMin:165,lumaSdMax:20},resolution:{minIodPx:110,minWidth:480,minHeight:640}},selfie:{pose:{yawDeg:7,pitchDeg:7,rollDeg:7,pitchOffsetDeg:4},eyes:{relativeMin:.62,blinkMax:.48,lowerEyeMin:.32},mouth:{jawOpenMax:.13,smileMax:.28,puckerMax:.28},lighting:{faceLuma:[95,185],halfRatio:[.77,1.31],clippedMax:.015},background:{required:!1,lumaMin:165,lumaSdMax:20},resolution:{minIodPx:100,minWidth:480,minHeight:640}}};function k(a){let i=f[a];return{profile:a,backgroundCheck:d,...i.pose,holdMs:500,alertGraceMs:3e3,eyes:{...i.eyes},mouth:{...i.mouth},lighting:{...i.lighting,faceLuma:[i.lighting.faceLuma[0],i.lighting.faceLuma[1]],halfRatio:[i.lighting.halfRatio[0],i.lighting.halfRatio[1]]},background:{...i.background},resolution:{...i.resolution},holdFrames:3,cadenceHz:10,baseline:{windowMs:3e3,minSamples:6,percentile:.8},sharpnessMin:.25,glare:{specularMax:.01},softGraceMs:4e3,cropMargin:1.25,camera:{width:1920,height:1080}}}var y=k("id_document"),I=/^[A-Za-z0-9._-]{1,64}$/;function n(a,i,r,u){return typeof a=="number"&&Number.isFinite(a)&&a>=r&&a<=u?a:i}function x(a,i,r,u){if(!Array.isArray(a)||a.length!==2)return[i[0],i[1]];let[e,l]=a,t=n(e,Number.NaN,r,u),m=n(l,Number.NaN,r,u);return Number.isNaN(t)||Number.isNaN(m)||t>m?[i[0],i[1]]:[t,m]}function o(a){return typeof a=="object"&&a!==null&&!Array.isArray(a)?a:{}}function R(a,i){let r=o(a),u=r.profile==="selfie"?"selfie":"id_document",e=u==="selfie"?k(u):y,l=o(r.eyes),t=o(r.mouth),m=o(r.lighting),s=o(r.background),c=o(r.resolution),g=o(r.baseline),w=o(r.glare),b=o(r.camera),h=typeof s.required=="boolean"?s.required:e.background.required,M=p(r.backgroundCheck);return{profile:u,yawDeg:n(r.yawDeg,e.yawDeg,1,45),pitchDeg:n(r.pitchDeg,e.pitchDeg,1,45),pitchOffsetDeg:n(r.pitchOffsetDeg,e.pitchOffsetDeg,-20,20),rollDeg:n(r.rollDeg,e.rollDeg,1,45),holdMs:n(r.holdMs,e.holdMs,0,5e3),alertGraceMs:n(r.alertGraceMs,e.alertGraceMs,0,6e4),eyes:{relativeMin:n(l.relativeMin,e.eyes.relativeMin,0,1),blinkMax:n(l.blinkMax,e.eyes.blinkMax,0,1),lowerEyeMin:n(l.lowerEyeMin,e.eyes.lowerEyeMin,0,1)},mouth:{jawOpenMax:n(t.jawOpenMax,e.mouth.jawOpenMax,0,1),smileMax:n(t.smileMax,e.mouth.smileMax,0,1),puckerMax:n(t.puckerMax,e.mouth.puckerMax,0,1)},lighting:{faceLuma:x(m.faceLuma,e.lighting.faceLuma,0,255),halfRatio:x(m.halfRatio,e.lighting.halfRatio,0,10),clippedMax:n(m.clippedMax,e.lighting.clippedMax,0,1)},background:{required:h,lumaMin:n(s.lumaMin,e.background.lumaMin,0,255),lumaSdMax:n(s.lumaSdMax,e.background.lumaSdMax,0,255)},resolution:{minIodPx:n(c.minIodPx,e.resolution.minIodPx,1,2e3),minWidth:n(c.minWidth,e.resolution.minWidth,1,8e3),minHeight:n(c.minHeight,e.resolution.minHeight,1,8e3)},holdFrames:Math.round(n(r.holdFrames,e.holdFrames,1,60)),cadenceHz:n(r.cadenceHz,e.cadenceHz,1,30),baseline:{windowMs:n(g.windowMs,e.baseline.windowMs,200,3e4),minSamples:Math.round(n(g.minSamples,e.baseline.minSamples,1,300)),percentile:n(g.percentile,e.baseline.percentile,.5,1)},sharpnessMin:n(r.sharpnessMin,e.sharpnessMin,0,1),glare:{specularMax:n(w.specularMax,e.glare.specularMax,0,1)},softGraceMs:n(r.softGraceMs,e.softGraceMs,0,6e4),cropMargin:n(r.cropMargin,e.cropMargin,1,2),camera:{width:Math.round(n(b.width,e.camera.width,320,4096)),height:Math.round(n(b.height,e.camera.height,240,4096))},backgroundCheck:h?M:{...M,enabled:!1},tuningVersion:typeof i=="string"&&I.test(i)?i:null}}export{y as a,R as b};
1
+ import{a as d,c as p}from"./chunk-LL3YYUKR.js";var f={id_document:{pose:{yawDeg:7,pitchDeg:7,rollDeg:5,pitchOffsetDeg:4},eyes:{relativeMin:.62,blinkMax:.48,lowerEyeMin:.32},mouth:{jawOpenMax:.13,smileMax:.28,puckerMax:.48},lighting:{faceLuma:[95,185],halfRatio:[.77,1.31],clippedMax:.015},background:{required:!0,lumaMin:165,lumaSdMax:20},resolution:{minIodPx:110,minWidth:480,minHeight:640}},selfie:{pose:{yawDeg:7,pitchDeg:7,rollDeg:7,pitchOffsetDeg:4},eyes:{relativeMin:.62,blinkMax:.48,lowerEyeMin:.32},mouth:{jawOpenMax:.13,smileMax:.28,puckerMax:.28},lighting:{faceLuma:[95,185],halfRatio:[.77,1.31],clippedMax:.015},background:{required:!1,lumaMin:165,lumaSdMax:20},resolution:{minIodPx:100,minWidth:480,minHeight:640}}};function k(a){let i=f[a];return{profile:a,backgroundCheck:d,...i.pose,holdMs:500,alertGraceMs:3e3,eyes:{...i.eyes},mouth:{...i.mouth},lighting:{...i.lighting,faceLuma:[i.lighting.faceLuma[0],i.lighting.faceLuma[1]],halfRatio:[i.lighting.halfRatio[0],i.lighting.halfRatio[1]]},background:{...i.background},resolution:{...i.resolution},holdFrames:3,cadenceHz:10,baseline:{windowMs:3e3,minSamples:6,percentile:.8},sharpnessMin:.25,glare:{specularMax:.01},softGraceMs:4e3,cropMargin:1.25,camera:{width:1920,height:1080}}}var y=k("id_document"),I=/^[A-Za-z0-9._-]{1,64}$/;function n(a,i,r,u){return typeof a=="number"&&Number.isFinite(a)&&a>=r&&a<=u?a:i}function x(a,i,r,u){if(!Array.isArray(a)||a.length!==2)return[i[0],i[1]];let[e,l]=a,t=n(e,Number.NaN,r,u),m=n(l,Number.NaN,r,u);return Number.isNaN(t)||Number.isNaN(m)||t>m?[i[0],i[1]]:[t,m]}function o(a){return typeof a=="object"&&a!==null&&!Array.isArray(a)?a:{}}function R(a,i){let r=o(a),u=r.profile==="selfie"?"selfie":"id_document",e=u==="selfie"?k(u):y,l=o(r.eyes),t=o(r.mouth),m=o(r.lighting),s=o(r.background),c=o(r.resolution),g=o(r.baseline),w=o(r.glare),b=o(r.camera),h=typeof s.required=="boolean"?s.required:e.background.required,M=p(r.backgroundCheck);return{profile:u,yawDeg:n(r.yawDeg,e.yawDeg,1,45),pitchDeg:n(r.pitchDeg,e.pitchDeg,1,45),pitchOffsetDeg:n(r.pitchOffsetDeg,e.pitchOffsetDeg,-20,20),rollDeg:n(r.rollDeg,e.rollDeg,1,45),holdMs:n(r.holdMs,e.holdMs,0,5e3),alertGraceMs:n(r.alertGraceMs,e.alertGraceMs,0,6e4),eyes:{relativeMin:n(l.relativeMin,e.eyes.relativeMin,0,1),blinkMax:n(l.blinkMax,e.eyes.blinkMax,0,1),lowerEyeMin:n(l.lowerEyeMin,e.eyes.lowerEyeMin,0,1)},mouth:{jawOpenMax:n(t.jawOpenMax,e.mouth.jawOpenMax,0,1),smileMax:n(t.smileMax,e.mouth.smileMax,0,1),puckerMax:n(t.puckerMax,e.mouth.puckerMax,0,1)},lighting:{faceLuma:x(m.faceLuma,e.lighting.faceLuma,0,255),halfRatio:x(m.halfRatio,e.lighting.halfRatio,0,10),clippedMax:n(m.clippedMax,e.lighting.clippedMax,0,1)},background:{required:h,lumaMin:n(s.lumaMin,e.background.lumaMin,0,255),lumaSdMax:n(s.lumaSdMax,e.background.lumaSdMax,0,255)},resolution:{minIodPx:n(c.minIodPx,e.resolution.minIodPx,1,2e3),minWidth:n(c.minWidth,e.resolution.minWidth,1,8e3),minHeight:n(c.minHeight,e.resolution.minHeight,1,8e3)},holdFrames:Math.round(n(r.holdFrames,e.holdFrames,1,60)),cadenceHz:n(r.cadenceHz,e.cadenceHz,1,30),baseline:{windowMs:n(g.windowMs,e.baseline.windowMs,200,3e4),minSamples:Math.round(n(g.minSamples,e.baseline.minSamples,1,300)),percentile:n(g.percentile,e.baseline.percentile,.5,1)},sharpnessMin:n(r.sharpnessMin,e.sharpnessMin,0,1),glare:{specularMax:n(w.specularMax,e.glare.specularMax,0,1)},softGraceMs:n(r.softGraceMs,e.softGraceMs,0,6e4),cropMargin:n(r.cropMargin,e.cropMargin,1,2),camera:{width:Math.round(n(b.width,e.camera.width,320,4096)),height:Math.round(n(b.height,e.camera.height,240,4096))},backgroundCheck:h?M:{...M,enabled:!1},tuningVersion:typeof i=="string"&&I.test(i)?i:null}}export{y as a,R as b};
@@ -1 +1 @@
1
- import{c as f}from"./chunk-TSA6GHUG.js";import{a as _,c as y}from"./chunk-BATJN3VQ.js";var w=["session_token_invalid","session_token_required","session_token_session_mismatch","session_not_found","rate_limit_exceeded","consent_required","session_not_active","check_not_found","check_already_finalized","check_out_of_order","check_type_unsupported","force_outcome_forbidden","attestation_invalid","platform_unregistered","app_attest_invalid","too_many_challenges","inference_unavailable","mobile_required","nni_locked","document_nni_mismatch","media_content_type_not_allowed","media_too_large","media_key_invalid","media_key_forbidden","media_not_found","media_unreadable","media_session_invalid","idempotency_key_collision","idempotency_in_progress","idempotency_key_required","validation_error","internal_error","unknown_error","upload_failed","network_error","timeout","nfc_outcome_not_accepted","identity_confirm_required","identity_confirm_locked","choice_not_found","choice_locked","choice_option_unavailable","step_not_on_path","check_not_active","sekyro_app_not_allowed","sekyro_app_unverified","id_number_locked","document_id_number_mismatch","simulated_capture_forbidden"];function D(s){return w.includes(s)}var c=class extends Error{constructor(e){super(e.message),this.name="HostedApiError",this.status=e.status,this.code=e.code,e.retryAfterSeconds!==void 0&&(this.retryAfterSeconds=e.retryAfterSeconds),e.details&&(this.details=e.details)}};function h(s,e,n=Math.random){let t=(s??e)*1e3,o=Math.min(Math.max(t,500),2e4),i=Math.round(o*(1+(n()*2-1)*.25));return Math.min(Math.max(i,500),2e4)}var k=6e4,b=4,R=3e4,I=9e5,E=200,P=5,M=400,C=new Set(["server_busy","request_timeout"]),A=2;function l(s){return(s.split(";")[0]??"").trim()}var v={liveness:"clipKey",face_match:"imageKey",doc_ocr:"imageKey"},O=`@sekyro/web/${_}`,N=O,g=class{constructor(e){this.sessionId=null;this.bootstrap=null;this.captureNonces=[];this.captureFetch=null;this.reportedIssues=new Map;this.apiOrigin=e.apiOrigin.replace(/\/+$/,""),this.sessionToken=e.sessionToken;let n=e.fetch;this.fetchImpl=(t,o)=>(n??globalThis.fetch).call(globalThis,t,o),this.requestTimeoutMs=e.requestTimeoutMs??R,this.retryAttempts=e.inProgressRetry?.attempts??P,this.retryDelayMs=e.inProgressRetry?.delayMs??M,this.random=e.random??Math.random}async getSession(){let e=await this.api("GET","/hosted/session");return this.sessionId=e.sessionId,e}async recordConsent(e){return this.api("POST","/hosted/consent",{body:{locale:e},busyRetry:!0})}async reportCameraUnavailable(e){return this.api("POST","/hosted/camera-unavailable",{body:{cause:e}})}async reportCaptureIssue(e){let n=typeof e.name=="string"?e.name.replace(/[^A-Za-z]/g,"").slice(0,40):"",t=typeof e.engineKind=="string"&&/^[a-z_]{1,32}$/.test(e.engineKind)?e.engineKind:void 0,o=typeof e.attempt=="number"&&Number.isInteger(e.attempt)&&e.attempt>=0&&e.attempt<=1e3?e.attempt:void 0,i=[e.check,o??"",e.kind,n,e.phase??""].join("|"),a=this.reportedIssues.get(i);if(a!==void 0)return a;let d={check:e.check,kind:e.kind,...n!==""?{name:n}:{},...e.phase!==void 0?{phase:e.phase}:{},...t!==void 0?{engineKind:t}:{},...o!==void 0?{attempt:o}:{},...e.formFactor!==void 0?{formFactor:e.formFactor}:{}},r=this.api("POST","/hosted/capture-issue",{body:d,empty:!0}).catch(()=>{this.reportedIssues.delete(i)});return this.reportedIssues.set(i,r),r}async choose(e,n){let t=await this.api("POST","/hosted/choice",{body:{nodeId:e,option:n},busyRetry:!0});return this.sessionId=t.sessionId,t}async confirmIdentity(e){return this.api("POST","/hosted/identity/confirm",{body:{decision:e}})}async identityPortrait(){return this.api("GET","/hosted/identity/portrait",{blob:!0})}async presign(e,n,t,o={}){let i=await this.ensureSessionId(),a={kind:e,contentType:l(n),contentLength:t,...o.source==="upload"?{source:"upload"}:{}};return this.api("POST",`/sessions/${i}/media`,{body:a})}armCapture(e=2){this.fillCaptureNonces(e)}async presignCapture(e,n,t,o={}){let i=await this.ensureSessionId(),a=await this.takeCaptureNonce(),d=a===void 0?void 0:{nonce:a,...o.engine!==void 0?{engine:o.engine.slice(0,32)}:{},...o.durationMs!==void 0&&Number.isFinite(o.durationMs)?{captureMs:Math.min(36e5,Math.max(0,Math.round(o.durationMs)))}:{}},r={kind:e,contentType:l(n),contentLength:t,capture:d};return this.api("POST",`/sessions/${i}/media`,{body:r})}async takeCaptureNonce(){let e=()=>{let n=Date.now();return this.captureNonces=this.captureNonces.filter(t=>t.expiresAt-k>n),this.captureNonces.shift()?.nonce};for(let n=0;n<2;n++){let t=e();if(t!==void 0)return t;await this.fillCaptureNonces(1)}return e()}fillCaptureNonces(e){return this.captureFetch??(this.captureFetch=(async()=>{try{let n=await this.ensureSessionId(),t=await this.api("POST",`/sessions/${n}/media/capture-nonces`,{body:{count:Math.min(b,Math.max(1,e))}}),o=Date.now()+Math.max(0,t.expiresIn)*1e3;for(let i of Array.isArray(t.nonces)?t.nonces:[])typeof i=="string"&&i.length>0&&this.captureNonces.push({nonce:i,expiresAt:o});this.captureNonces=this.captureNonces.slice(-b)}catch{}})().finally(()=>{this.captureFetch=null})),this.captureFetch}async uploadToSpaces(e,n,t){let o;try{o=await this.fetchImpl(e,{method:"PUT",headers:{"content-type":l(t)},body:n,signal:AbortSignal.timeout(I)})}catch(i){throw m(i)}if(!o.ok){let i=(await o.text().catch(()=>"")).slice(0,E);throw new c({status:o.status,code:"upload_failed",message:`media upload failed (HTTP ${o.status})${i?`: ${i}`:""}`})}}async completeMedia(e){let n=await this.ensureSessionId();return this.api("POST",`/sessions/${n}/media/complete`,{body:{key:e}})}async submitCheck(e,n,t={}){let o=await this.ensureSessionId(),i={input:n,forceOutcome:t.forceOutcome};return this.api("POST",`/sessions/${o}/checks/${e}`,{body:i,idempotencyKey:t.idempotencyKey,busyRetry:t.idempotencyKey!==void 0})}async uploadAndSubmit(e,n,t,o={}){let i=l(n.contentType),a=await this.presign(n.kind,i,n.blob.size);await this.uploadToSpaces(a.uploadUrl,n.blob,i);let d=await this.completeMedia(a.key),r={...t,[v[e]]:d.key};return this.submitCheck(e,r,o)}async ensureSessionId(){return this.sessionId!==null?this.sessionId:(this.bootstrap??(this.bootstrap=this.getSession().finally(()=>{this.bootstrap=null})),(await this.bootstrap).sessionId)}async api(e,n,t={}){let o=e==="GET"||t.busyRetry===!0,i=`${this.apiOrigin}/api/v2${n}`,a={"x-session-token":this.sessionToken,"x-sekyro-sdk":N};t.body!==void 0&&(a["content-type"]="application/json"),t.idempotencyKey!==void 0&&(a["x-idempotency-key"]=t.idempotencyKey);try{let d=y.timezone();d!==void 0&&(a["sekyro-client-timezone"]=d)}catch{}a["sekyro-client-form-factor"]=f();try{let d=await y.deviceHeader();d!==void 0&&(a["sekyro-client-device"]=d)}catch{}for(let d=0;;d++){let r;try{r=await this.fetchImpl(i,{method:e,headers:a,...t.body!==void 0?{body:JSON.stringify(t.body)}:{},cache:"no-store",signal:AbortSignal.timeout(this.requestTimeoutMs)})}catch(p){throw m(p)}if(r.ok){if(t.empty===!0)return;if(t.blob===!0)try{return await r.blob()}catch(S){throw m(S)}let p;try{p=await r.json()}catch{throw new c({status:r.status,code:"unknown_error",message:`response body was not valid JSON (HTTP ${r.status})`})}return H(p)}let u=await x(r);if(u.code==="idempotency_in_progress"&&d<this.retryAttempts){this.retryDelayMs>0&&await T(this.retryDelayMs);continue}if(o&&u.status===503&&C.has(u.code)){o=!1,await T(h(u.retryAfterSeconds,A,this.random));continue}throw u}}};function m(s){if((typeof s=="object"&&s!==null?s.name:void 0)==="TimeoutError")return new c({status:0,code:"timeout",message:"request timed out"});let n=s instanceof Error?s.message:String(s);return new c({status:0,code:"network_error",message:`network request failed: ${n}`})}function H(s){return s!==null&&typeof s=="object"&&"success"in s&&"data"in s?s.data:s}async function x(s){let e="unknown_error",n=`request failed (HTTP ${s.status})`,t=Number.NaN,o;try{let d=await s.json();if(d!==null&&typeof d=="object"){let r=d;typeof r.code=="string"&&r.code.length>0&&(e=r.code),typeof r.message=="string"&&r.message.length>0&&(n=r.message),typeof r.retryAfterSeconds=="number"&&(t=r.retryAfterSeconds),Array.isArray(r.details?.issues)&&(o=r.details)}}catch{}let i=s.headers.get("retry-after"),a=i===null?Math.floor(t):Number.parseInt(i,10);return new c({status:s.status,code:e,message:n,...Number.isFinite(a)&&a>=0?{retryAfterSeconds:a}:{},details:o})}function T(s){return new Promise(e=>setTimeout(e,s))}function j(s){let e=s?.portrait,n=e?.icao,t=e?.purpose==="id_document";return n==null?t?{policy:"reject",profile:"id_document"}:null:{policy:n.policy==="alert"?"alert":"reject",profile:t||n.profile==="id_document"?"id_document":"selfie"}}function B(s){return{...s.baselineEyeOpenness!==void 0?{baselineEyeOpenness:s.baselineEyeOpenness}:{},...s.baselineEyeOpennessLeft!==void 0&&s.baselineEyeOpennessRight!==void 0?{baselineEyeOpennessLeft:s.baselineEyeOpennessLeft,baselineEyeOpennessRight:s.baselineEyeOpennessRight}:{},criteria:s.verdict??{},...s.backgroundCheck!==void 0?{backgroundCheck:s.backgroundCheck}:{}}}export{w as a,D as b,c,h as d,l as e,O as f,g,j as h,B as i};
1
+ import{c as f}from"./chunk-CDDYFUER.js";import{a as _,c as y}from"./chunk-XK4CCTLL.js";var w=["session_token_invalid","session_token_required","session_token_session_mismatch","session_not_found","rate_limit_exceeded","consent_required","session_not_active","check_not_found","check_already_finalized","check_out_of_order","check_type_unsupported","force_outcome_forbidden","attestation_invalid","platform_unregistered","app_attest_invalid","too_many_challenges","inference_unavailable","mobile_required","nni_locked","document_nni_mismatch","media_content_type_not_allowed","media_too_large","media_key_invalid","media_key_forbidden","media_not_found","media_unreadable","media_session_invalid","idempotency_key_collision","idempotency_in_progress","idempotency_key_required","validation_error","internal_error","unknown_error","upload_failed","network_error","timeout","nfc_outcome_not_accepted","identity_confirm_required","identity_confirm_locked","choice_not_found","choice_locked","choice_option_unavailable","step_not_on_path","check_not_active","sekyro_app_not_allowed","sekyro_app_unverified","id_number_locked","document_id_number_mismatch","simulated_capture_forbidden"];function D(s){return w.includes(s)}var c=class extends Error{constructor(e){super(e.message),this.name="HostedApiError",this.status=e.status,this.code=e.code,e.retryAfterSeconds!==void 0&&(this.retryAfterSeconds=e.retryAfterSeconds),e.details&&(this.details=e.details)}};function h(s,e,n=Math.random){let t=(s??e)*1e3,o=Math.min(Math.max(t,500),2e4),i=Math.round(o*(1+(n()*2-1)*.25));return Math.min(Math.max(i,500),2e4)}var k=6e4,b=4,R=3e4,I=9e5,E=200,P=5,M=400,C=new Set(["server_busy","request_timeout"]),A=2;function l(s){return(s.split(";")[0]??"").trim()}var v={liveness:"clipKey",face_match:"imageKey",doc_ocr:"imageKey"},O=`@sekyro/web/${_}`,N=O,g=class{constructor(e){this.sessionId=null;this.bootstrap=null;this.captureNonces=[];this.captureFetch=null;this.reportedIssues=new Map;this.apiOrigin=e.apiOrigin.replace(/\/+$/,""),this.sessionToken=e.sessionToken;let n=e.fetch;this.fetchImpl=(t,o)=>(n??globalThis.fetch).call(globalThis,t,o),this.requestTimeoutMs=e.requestTimeoutMs??R,this.retryAttempts=e.inProgressRetry?.attempts??P,this.retryDelayMs=e.inProgressRetry?.delayMs??M,this.random=e.random??Math.random}async getSession(){let e=await this.api("GET","/hosted/session");return this.sessionId=e.sessionId,e}async recordConsent(e){return this.api("POST","/hosted/consent",{body:{locale:e},busyRetry:!0})}async reportCameraUnavailable(e){return this.api("POST","/hosted/camera-unavailable",{body:{cause:e}})}async reportCaptureIssue(e){let n=typeof e.name=="string"?e.name.replace(/[^A-Za-z]/g,"").slice(0,40):"",t=typeof e.engineKind=="string"&&/^[a-z_]{1,32}$/.test(e.engineKind)?e.engineKind:void 0,o=typeof e.attempt=="number"&&Number.isInteger(e.attempt)&&e.attempt>=0&&e.attempt<=1e3?e.attempt:void 0,i=[e.check,o??"",e.kind,n,e.phase??""].join("|"),a=this.reportedIssues.get(i);if(a!==void 0)return a;let d={check:e.check,kind:e.kind,...n!==""?{name:n}:{},...e.phase!==void 0?{phase:e.phase}:{},...t!==void 0?{engineKind:t}:{},...o!==void 0?{attempt:o}:{},...e.formFactor!==void 0?{formFactor:e.formFactor}:{}},r=this.api("POST","/hosted/capture-issue",{body:d,empty:!0}).catch(()=>{this.reportedIssues.delete(i)});return this.reportedIssues.set(i,r),r}async choose(e,n){let t=await this.api("POST","/hosted/choice",{body:{nodeId:e,option:n},busyRetry:!0});return this.sessionId=t.sessionId,t}async confirmIdentity(e){return this.api("POST","/hosted/identity/confirm",{body:{decision:e}})}async identityPortrait(){return this.api("GET","/hosted/identity/portrait",{blob:!0})}async presign(e,n,t,o={}){let i=await this.ensureSessionId(),a={kind:e,contentType:l(n),contentLength:t,...o.source==="upload"?{source:"upload"}:{}};return this.api("POST",`/sessions/${i}/media`,{body:a})}armCapture(e=2){this.fillCaptureNonces(e)}async presignCapture(e,n,t,o={}){let i=await this.ensureSessionId(),a=await this.takeCaptureNonce(),d=a===void 0?void 0:{nonce:a,...o.engine!==void 0?{engine:o.engine.slice(0,32)}:{},...o.durationMs!==void 0&&Number.isFinite(o.durationMs)?{captureMs:Math.min(36e5,Math.max(0,Math.round(o.durationMs)))}:{}},r={kind:e,contentType:l(n),contentLength:t,capture:d};return this.api("POST",`/sessions/${i}/media`,{body:r})}async takeCaptureNonce(){let e=()=>{let n=Date.now();return this.captureNonces=this.captureNonces.filter(t=>t.expiresAt-k>n),this.captureNonces.shift()?.nonce};for(let n=0;n<2;n++){let t=e();if(t!==void 0)return t;await this.fillCaptureNonces(1)}return e()}fillCaptureNonces(e){return this.captureFetch??(this.captureFetch=(async()=>{try{let n=await this.ensureSessionId(),t=await this.api("POST",`/sessions/${n}/media/capture-nonces`,{body:{count:Math.min(b,Math.max(1,e))}}),o=Date.now()+Math.max(0,t.expiresIn)*1e3;for(let i of Array.isArray(t.nonces)?t.nonces:[])typeof i=="string"&&i.length>0&&this.captureNonces.push({nonce:i,expiresAt:o});this.captureNonces=this.captureNonces.slice(-b)}catch{}})().finally(()=>{this.captureFetch=null})),this.captureFetch}async uploadToSpaces(e,n,t){let o;try{o=await this.fetchImpl(e,{method:"PUT",headers:{"content-type":l(t)},body:n,signal:AbortSignal.timeout(I)})}catch(i){throw m(i)}if(!o.ok){let i=(await o.text().catch(()=>"")).slice(0,E);throw new c({status:o.status,code:"upload_failed",message:`media upload failed (HTTP ${o.status})${i?`: ${i}`:""}`})}}async completeMedia(e){let n=await this.ensureSessionId();return this.api("POST",`/sessions/${n}/media/complete`,{body:{key:e}})}async submitCheck(e,n,t={}){let o=await this.ensureSessionId(),i={input:n,forceOutcome:t.forceOutcome};return this.api("POST",`/sessions/${o}/checks/${e}`,{body:i,idempotencyKey:t.idempotencyKey,busyRetry:t.idempotencyKey!==void 0})}async uploadAndSubmit(e,n,t,o={}){let i=l(n.contentType),a=await this.presign(n.kind,i,n.blob.size);await this.uploadToSpaces(a.uploadUrl,n.blob,i);let d=await this.completeMedia(a.key),r={...t,[v[e]]:d.key};return this.submitCheck(e,r,o)}async ensureSessionId(){return this.sessionId!==null?this.sessionId:(this.bootstrap??(this.bootstrap=this.getSession().finally(()=>{this.bootstrap=null})),(await this.bootstrap).sessionId)}async api(e,n,t={}){let o=e==="GET"||t.busyRetry===!0,i=`${this.apiOrigin}/api/v2${n}`,a={"x-session-token":this.sessionToken,"x-sekyro-sdk":N};t.body!==void 0&&(a["content-type"]="application/json"),t.idempotencyKey!==void 0&&(a["x-idempotency-key"]=t.idempotencyKey);try{let d=y.timezone();d!==void 0&&(a["sekyro-client-timezone"]=d)}catch{}a["sekyro-client-form-factor"]=f();try{let d=await y.deviceHeader();d!==void 0&&(a["sekyro-client-device"]=d)}catch{}for(let d=0;;d++){let r;try{r=await this.fetchImpl(i,{method:e,headers:a,...t.body!==void 0?{body:JSON.stringify(t.body)}:{},cache:"no-store",signal:AbortSignal.timeout(this.requestTimeoutMs)})}catch(p){throw m(p)}if(r.ok){if(t.empty===!0)return;if(t.blob===!0)try{return await r.blob()}catch(S){throw m(S)}let p;try{p=await r.json()}catch{throw new c({status:r.status,code:"unknown_error",message:`response body was not valid JSON (HTTP ${r.status})`})}return H(p)}let u=await x(r);if(u.code==="idempotency_in_progress"&&d<this.retryAttempts){this.retryDelayMs>0&&await T(this.retryDelayMs);continue}if(o&&u.status===503&&C.has(u.code)){o=!1,await T(h(u.retryAfterSeconds,A,this.random));continue}throw u}}};function m(s){if((typeof s=="object"&&s!==null?s.name:void 0)==="TimeoutError")return new c({status:0,code:"timeout",message:"request timed out"});let n=s instanceof Error?s.message:String(s);return new c({status:0,code:"network_error",message:`network request failed: ${n}`})}function H(s){return s!==null&&typeof s=="object"&&"success"in s&&"data"in s?s.data:s}async function x(s){let e="unknown_error",n=`request failed (HTTP ${s.status})`,t=Number.NaN,o;try{let d=await s.json();if(d!==null&&typeof d=="object"){let r=d;typeof r.code=="string"&&r.code.length>0&&(e=r.code),typeof r.message=="string"&&r.message.length>0&&(n=r.message),typeof r.retryAfterSeconds=="number"&&(t=r.retryAfterSeconds),Array.isArray(r.details?.issues)&&(o=r.details)}}catch{}let i=s.headers.get("retry-after"),a=i===null?Math.floor(t):Number.parseInt(i,10);return new c({status:s.status,code:e,message:n,...Number.isFinite(a)&&a>=0?{retryAfterSeconds:a}:{},details:o})}function T(s){return new Promise(e=>setTimeout(e,s))}function j(s){let e=s?.portrait,n=e?.icao,t=e?.purpose==="id_document";return n==null?t?{policy:"reject",profile:"id_document"}:null:{policy:n.policy==="alert"?"alert":"reject",profile:t||n.profile==="id_document"?"id_document":"selfie"}}function B(s){return{...s.baselineEyeOpenness!==void 0?{baselineEyeOpenness:s.baselineEyeOpenness}:{},...s.baselineEyeOpennessLeft!==void 0&&s.baselineEyeOpennessRight!==void 0?{baselineEyeOpennessLeft:s.baselineEyeOpennessLeft,baselineEyeOpennessRight:s.baselineEyeOpennessRight}:{},criteria:s.verdict??{},...s.backgroundCheck!==void 0?{backgroundCheck:s.backgroundCheck}:{}}}export{w as a,D as b,c,h as d,l as e,O as f,g,j as h,B as i};