@sekyro/web 0.1.0-rc.11 → 0.1.0-rc.13

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 (44) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/{capture-session-doc-DMQ7T3HC.js → capture-session-doc-7LQAOCHJ.js} +1 -1
  3. package/dist/{capture-session-v3-DYrhYJoM.d.ts → capture-session-v3-C5DRPBhM.d.ts} +1 -1
  4. package/dist/{capture-session-v3-CCHws1mz.d.cts → capture-session-v3-Db4n6d-k.d.cts} +1 -1
  5. package/dist/chunk-57VOMVKM.js +1 -0
  6. package/dist/{chunk-LUKTHL6K.js → chunk-5OIC5TZS.js} +1 -1
  7. package/dist/{chunk-JDGEZ542.js → chunk-H6H2RT6M.js} +1 -1
  8. package/dist/{chunk-HHCGQSD4.js → chunk-IBA5CPDV.js} +1 -1
  9. package/dist/{chunk-IJLHPX35.js → chunk-JRSIMNB5.js} +1 -1
  10. package/dist/chunk-UBDG5IAP.js +1 -0
  11. package/dist/{chunk-OWU22VXP.js → chunk-VJM76LUI.js} +1 -1
  12. package/dist/chunk-WTQE6IGL.js +1 -0
  13. package/dist/chunk-XBVSYVKA.js +1 -0
  14. package/dist/client/index.cjs +1 -1
  15. package/dist/client/index.d.cts +5 -5
  16. package/dist/client/index.d.ts +5 -5
  17. package/dist/client/index.js +1 -1
  18. package/dist/core/index.cjs +1 -1
  19. package/dist/core/index.d.cts +3 -3
  20. package/dist/core/index.d.ts +3 -3
  21. package/dist/core/index.js +1 -1
  22. package/dist/{create-document-capture-FV4XGUKQ.js → create-document-capture-RTFDQSBC.js} +1 -1
  23. package/dist/{create-verification-CzLrQjeM.d.cts → create-verification-BV_T0-CR.d.cts} +39 -13
  24. package/dist/{create-verification-CmJzn7sq.d.ts → create-verification-P6i3tyce.d.ts} +39 -13
  25. package/dist/{icao-gate-BeznQECA.d.cts → icao-gate-B0GDH_JS.d.cts} +13 -5
  26. package/dist/{icao-gate-Bw5sQVlt.d.ts → icao-gate-BP11XO-h.d.ts} +13 -5
  27. package/dist/index.cjs +1 -1
  28. package/dist/index.d.cts +36 -10
  29. package/dist/index.d.ts +36 -10
  30. package/dist/index.js +1 -1
  31. package/dist/internal/index.cjs +1 -1
  32. package/dist/internal/index.d.cts +7 -6
  33. package/dist/internal/index.d.ts +7 -6
  34. package/dist/internal/index.js +1 -1
  35. package/dist/plan-runner-RVVF5DJV.js +1 -0
  36. package/dist/{types-BWyAHKt_.d.cts → types-DPWT_KMn.d.cts} +57 -14
  37. package/dist/{types-BWyAHKt_.d.ts → types-DPWT_KMn.d.ts} +57 -14
  38. package/package.json +1 -1
  39. package/sbom.cdx.json +7 -7
  40. package/dist/chunk-AHD4DA2V.js +0 -1
  41. package/dist/chunk-MXNZMTC2.js +0 -1
  42. package/dist/chunk-URUKV6NC.js +0 -1
  43. package/dist/chunk-V5K2JLC7.js +0 -1
  44. package/dist/plan-runner-ZVAY4FSB.js +0 -1
@@ -1 +1 @@
1
- import{b as jt}from"./chunk-SMKCBUJL.js";import{a as et,b as Zt,c as Jt,e as ht,f as $t}from"./chunk-MXWLCDFX.js";import{d as Wt,h as Xt,k as Yt}from"./chunk-G6LKLN4U.js";import{b as Kt,c as Vt}from"./chunk-TDLIXFDT.js";import{b as Qt,c as Bt}from"./chunk-POIQGEZM.js";import{d as zt}from"./chunk-FHJ7HO3M.js";import{b as ut,c as Ut,d as j,e as Ht}from"./chunk-FPXL63KZ.js";import{b as Nt}from"./chunk-LUKTHL6K.js";var it=Object.freeze({sensing:{key:"sensing",reticle:"searching",minDurationMs:900},too_far:{key:"too_far",reticle:"coaching",minDurationMs:1400},too_close:{key:"too_close",reticle:"coaching",minDurationMs:1400},edge_clipped:{key:"edge_clipped",reticle:"coaching",minDurationMs:1400},wrong_shape:{key:"wrong_shape",reticle:"coaching",minDurationMs:1400},tilted:{key:"tilted",reticle:"coaching",minDurationMs:1400},too_dark:{key:"too_dark",reticle:"coaching",minDurationMs:1400},too_bright:{key:"too_bright",reticle:"coaching",minDurationMs:1400},blurry:{key:"blurry",reticle:"coaching",minDurationMs:1400},focus_far:{key:"focus_far",reticle:"coaching",minDurationMs:1600},glare:{key:"glare",reticle:"coaching",minDurationMs:1400},hold_still:{key:"hold_still",reticle:"locking",minDurationMs:900},processing:{key:"processing",reticle:"processing",minDurationMs:800},side_captured:{key:"side_captured",reticle:"flip",minDurationMs:2600},captured:{key:"captured",reticle:"done",minDurationMs:800}});function qt(e){return e.framing==="no_document"?"sensing":e.framing==="too_far"?"too_far":e.framing==="too_close"?"too_close":e.framing==="edge_clipped"?"edge_clipped":e.framing==="wrong_shape"?"wrong_shape":e.framing==="tilted"?"tilted":e.lighting==="too_dark"?"too_dark":e.lighting==="too_bright"?"too_bright":e.glare==="glare"?"glare":e.blur==="blurry"?"blurry":"hold_still"}var nt=class{constructor(t=2600,n=.35){this.windowMs=t;this.decayPerSecond=n;this.votes=[];this.current=it.sensing;this.currentSinceMs=null}reset(){this.votes=[],this.current=it.sensing,this.currentSinceMs=null}force(t,n){return this.votes=[],this.current=it[t],this.currentSinceMs=n,this.current}tick(t,n){if(this.currentSinceMs===null&&(this.currentSinceMs=n),this.votes.push({key:t,atMs:n}),this.votes=this.votes.filter(r=>n-r.atMs<=this.windowMs),n-this.currentSinceMs<this.current.minDurationMs)return this.current;let i=new Map;for(let r of this.votes){let c=(n-r.atMs)/1e3,a=this.decayPerSecond**c;i.set(r.key,(i.get(r.key)??0)+a)}let o=this.current.key,s=-1;for(let[r,c]of i)c>s&&(s=c,o=r);return o!==this.current.key&&(this.current=it[o],this.currentSinceMs=n),this.current}};var Qe=Object.freeze({MAX_AREA_FRAC:.92,TILT_MAX_SIDE_RATIO:1.3,GLARE_MAX_SPECULAR_FRAC:.025});function ee(e){let{data:t,width:n,height:i}=e,o=n*i;if(o===0)return 0;let s=0;for(let r=0;r<o;r++){let c=r*4;.299*(t[c]??0)+.587*(t[c+1]??0)+.114*(t[c+2]??0)>=252&&s++}return s/o}function Be(e){let t=(a,l)=>Math.hypot(l.x-a.x,l.y-a.y),n=t(e.topLeft,e.topRight),i=t(e.bottomLeft,e.bottomRight),o=t(e.topLeft,e.bottomLeft),s=t(e.topRight,e.bottomRight),r=Math.max(n,i)/Math.max(1e-6,Math.min(n,i)),c=Math.max(o,s)/Math.max(1e-6,Math.min(o,s));return Math.max(r,c)}function ie(e){let t={...Zt,...e.thresholds},n=Qe,{quad:i,frameWidth:o,frameHeight:s,measures:r}=e,c=e.format==="ID-3",a="ok";if(i===null)a="no_document";else if(c){let m=ht(i),h=o>0?m.width/o:0,f=m.height>0?m.width/m.height:0;h<t.ID3_BAND_MIN_WIDTH_FRAC?a="too_far":te(i,o,s,t.EDGE_CLIP_MARGIN_PX)?a="edge_clipped":(f<t.ID3_BAND_ASPECT_MIN||f>t.ID3_BAND_ASPECT_MAX)&&(a="wrong_shape")}else{let m=Jt(i,o,s),h=ht(i),f=Math.max(h.width,h.height)/Math.max(1e-6,Math.min(h.width,h.height));m<t.MIN_AREA_FRAC?a="too_far":m>n.MAX_AREA_FRAC?a="too_close":te(i,o,s,t.EDGE_CLIP_MARGIN_PX)?a="edge_clipped":Vt(e.format,f)?Be(i)>n.TILT_MAX_SIDE_RATIO&&(a="tilted"):a="wrong_shape"}let l=r.exposure>=t.GUIDE_EXPOSURE?"ok":r.meanLuma<(ut[0]+ut[1])/2?"too_dark":"too_bright",u=r.sharpness>=t.GUIDE_SHARPNESS?"ok":"blurry",d=r.specularFraction>=n.GLARE_MAX_SPECULAR_FRAC?"glare":"ok";return{framing:a,lighting:l,blur:u,glare:d,acceptable:a==="ok"&&l==="ok"&&u==="ok"&&d==="ok"}}function te(e,t,n,i){return[e.topLeft,e.topRight,e.bottomRight,e.bottomLeft].some(s=>s.x<=i||s.y<=i||s.x>=t-i||s.y>=n-i)}var oe=Object.freeze({width:1920,height:1080}),Ue=Object.freeze({width:3840,height:2160}),ne=4096,He=2560,se=640,ot=.15,Y=Object.freeze({side:.2,above:.9,below:.3});function L(e){let t=[e.topLeft.x,e.topRight.x,e.bottomRight.x,e.bottomLeft.x],n=[e.topLeft.y,e.topRight.y,e.bottomRight.y,e.bottomLeft.y],i=Math.min(...t),o=Math.min(...n);return{x:i,y:o,width:Math.max(...t)-i,height:Math.max(...n)-o}}function re(e,t){let n=Math.max(0,Math.floor(e.x)),i=Math.max(0,Math.floor(e.y)),o=Math.min(t.width,Math.ceil(e.x+e.width)),s=Math.min(t.height,Math.ceil(e.y+e.height));return o-n<16||s-i<16?null:{x:n,y:i,width:o-n,height:s-i}}function Ke(e,t,n){if(e===null||t.width<=0||t.height<=0)return null;let i=L(e);if(i.width<=0||i.height<=0)return null;let o=n==="ID-3"?{x:i.x-i.width*Y.side,y:i.y-i.width*Y.above,width:i.width*(1+2*Y.side),height:i.height+i.width*(Y.above+Y.below)}:{x:i.x-i.width*ot,y:i.y-i.height*ot,width:i.width*(1+2*ot),height:i.height*(1+2*ot)};return re(o,t)}function dt(e,t,n){let i=Math.max(e,t);return i>0?Math.min(1,n/i):1}function mt(e,t,n,i,o=He){let s=t.width>0?n.width/t.width:1,r=t.height>0?n.height/t.height:1,c=e===null?null:{topLeft:{x:e.topLeft.x*s,y:e.topLeft.y*r},topRight:{x:e.topRight.x*s,y:e.topRight.y*r},bottomRight:{x:e.bottomRight.x*s,y:e.bottomRight.y*r},bottomLeft:{x:e.bottomLeft.x*s,y:e.bottomLeft.y*r}},a=Ke(c,n,i)??{x:0,y:0,width:n.width,height:n.height},l=dt(a.width,a.height,o),u=Math.max(1,Math.round(a.width*l)),d=Math.max(1,Math.round(a.height*l)),m=null;if(c!==null){let h=L(c);m=re({x:(h.x-a.x)*l,y:(h.y-a.y)*l,width:h.width*l,height:h.height*l},{width:u,height:d})}return{crop:a,width:u,height:d,docRegion:m}}function ae(e,t,n,i=Ue){if(n==="LOW")return null;let o=e?.width?.max,s=e?.height?.max;if(typeof o!="number"||typeof s!="number"||o<=0||s<=0)return null;let r=Math.max(o,s),c=Math.min(o,s),a=Math.min(r,Math.max(i.width,i.height)),l=Math.min(c,Math.min(i.width,i.height));return a<=Math.max(t.width,t.height)?null:{width:{ideal:a},height:{ideal:l}}}function ce(e){let t={},n=e?.imageWidth,i=e?.imageHeight;if(typeof n?.max=="number"&&n.max>0){let o=typeof i?.max=="number"&&i.max>0?n.max/i.max:1.3333333333333333,s=o>=1?ne:ne*o,r=Math.min(n.max,Math.floor(s)),c=typeof n.step=="number"&&n.step>0?n.step:1,a=typeof n.min=="number"?n.min:0;r=Math.max(a,a+Math.floor((r-a)/c)*c),t.imageWidth=r}return e?.fillLightMode?.includes("off")===!0&&(t.fillLightMode="off"),t}function le(e,t){if(e.width<=0||e.height<=0||t.width<=0||t.height<=0)return!1;let n=e.width>e.height,i=t.width>t.height;return n!==i&&e.width!==e.height&&t.width!==t.height?!1:Math.max(e.width,e.height)>=1.2*Math.max(t.width,t.height)}function ue(e,t,n,i){if(n===null)return!1;let o=L(e),s=L(n);if(t.width<=0||i.width<=0)return!1;let r=o.width/t.width,c=s.width/i.width;return c>0&&r>=.6*c&&r<=1.25*c}var he=3500,Ve=.92;function me(){let e=globalThis.ImageCapture;return typeof e=="function"?e:null}function We(e){return/AppleWebKit\//.test(e)&&!/(Chrome|Chromium|Edg|OPR)\//.test(e)}function fe(e,t=typeof navigator>"u"?"":navigator.userAgent){return me()!==null&&!We(t)&&e!=null&&e.kind==="video"&&e.readyState==="live"}function de(e,t){return new Promise((n,i)=>{let o=setTimeout(()=>i(new Error("takePhoto timed out")),t);e.then(s=>{clearTimeout(o),n(s)},s=>{clearTimeout(o),i(s)})})}function ft(e,t){let n=document.createElement("canvas");return n.width=e,n.height=t,n}function Xe(e,t){return new Promise((n,i)=>{e.toBlob(o=>o?n(o):i(new Error("toBlob failed")),"image/jpeg",t)})}async function pe(e,t,n,i,o){let s=ft(n,i),r=ft(1,1);try{let c=s.getContext("2d");if(c===null)throw new Error("2d context unavailable");c.imageSmoothingQuality="high",c.drawImage(e,t.x,t.y,t.width,t.height,0,0,n,i);let a=await Xe(s,Ve),l=o===null?null:Wt({topLeft:{x:o.x,y:o.y},topRight:{x:o.x+o.width,y:o.y},bottomRight:{x:o.x+o.width,y:o.y+o.height},bottomLeft:{x:o.x,y:o.y+o.height}},{width:n,height:i},{width:n,height:i}),u=Xt(s,l),d=dt(n,i,se);return r.width=Math.max(1,Math.round(n*d)),r.height=Math.max(1,Math.round(i*d)),r.getContext("2d")?.drawImage(s,0,0,r.width,r.height),{blob:a,previewDataUrl:r.toDataURL("image/jpeg",.85),sharpness:u}}finally{s.width=0,s.height=0,r.width=0,r.height=0}}function je(e,t){let n=Math.min(1,t/e.width),i=ft(Math.max(1,Math.round(e.width*n)),Math.max(1,Math.round(e.height*n)));try{let o=i.getContext("2d",{willReadFrequently:!0});return o===null?null:(o.imageSmoothingQuality="high",o.drawImage(e,0,0,i.width,i.height),o.getImageData(0,0,i.width,i.height))}finally{i.width=0,i.height=0}}async function ge(e,t,n,i){let o={width:Math.max(1,e.videoWidth),height:Math.max(1,e.videoHeight)},s=mt(t,n,o,i);return{...await pe(e,s.crop,s.width,s.height,s.docRegion),docRegion:s.docRegion,source:"video",width:s.width,height:s.height}}async function be(e,t,n,i,o){let s=me();if(s===null)return null;let r=null;try{let c=new s(o.track),a=await de(c.getPhotoCapabilities?.()??Promise.resolve({}),he).catch(()=>({})),l=await de(c.takePhoto(ce(a)),he);r=await createImageBitmap(l);let u={width:e.videoWidth,height:e.videoHeight};if(!le(r,u))return null;let d=je(r,o.detectWidth),m=null;d!==null&&t!==null&&(m=await o.detect(d).catch(()=>null));let h=d??{width:r.width,height:r.height};m!==null&&!ue(m,h,t,n)&&(m=null);let f=mt(m,h,r,i);return{...await pe(r,f.crop,f.width,f.height,f.docRegion),docRegion:f.docRegion,source:"photo",width:f.width,height:f.height}}catch{return null}finally{r?.close()}}var st=Object.freeze({width:3840,height:2160,lensSelection:!0,continuousFocus:!0,refocusBeforePhotoMs:350,zoomMax:2,zoomNoFocusInfo:1.5,zoomMinSourcePx:2160,fillDistanceM:Object.freeze({id1:.11,id3:.15}),focusMarginFrac:.2,stillSharpnessMin:.16,stillRefusalsMax:2,focusFarFillFrac:.45,noDocFarHintMs:1500,zoomFallbackMs:8e3}),S=(e,t,n)=>typeof e=="number"&&Number.isFinite(e)&&e>=t&&e<=n?e:void 0;function ki(e){let t=st,n=e!==null&&typeof e=="object"?e:{},i=n.fillDistanceM!==null&&typeof n.fillDistanceM=="object"?n.fillDistanceM:{},o=(s,r)=>typeof s=="boolean"?s:r;return{width:S(n.width,640,7680)??t.width,height:S(n.height,480,4320)??t.height,lensSelection:o(n.lensSelection,t.lensSelection),continuousFocus:o(n.continuousFocus,t.continuousFocus),refocusBeforePhotoMs:S(n.refocusBeforePhotoMs,0,2e3)??t.refocusBeforePhotoMs,zoomMax:S(n.zoomMax,1,5)??t.zoomMax,zoomNoFocusInfo:S(n.zoomNoFocusInfo,1,5)??t.zoomNoFocusInfo,zoomMinSourcePx:S(n.zoomMinSourcePx,0,8e3)??t.zoomMinSourcePx,fillDistanceM:{id1:S(i.id1,.03,1)??t.fillDistanceM.id1,id3:S(i.id3,.03,1)??t.fillDistanceM.id3},focusMarginFrac:S(n.focusMarginFrac,0,2)??t.focusMarginFrac,stillSharpnessMin:S(n.stillSharpnessMin,0,10)??t.stillSharpnessMin,stillRefusalsMax:S(n.stillRefusalsMax,0,10)??t.stillRefusalsMax,focusFarFillFrac:S(n.focusFarFillFrac,0,1)??t.focusFarFillFrac,noDocFarHintMs:S(n.noDocFarHintMs,0,6e4)??t.noDocFarHintMs,zoomFallbackMs:S(n.zoomFallbackMs,0,12e4)??t.zoomFallbackMs}}function Ye(e){let t=e.toLowerCase();return t===""?"unknown":/front|facing front|user|selfie|face ?time/.test(t)?"front":/ultra|0\.5x|wide angle/.test(t)?"ultra":/tele|zoom|periscope|[2-9]x/.test(t)?"tele":/depth|tof|infrared|\bir\b|truedepth|lidar|macro|monochrome|mono\b/.test(t)?"depth":/dual|triple/.test(t)?"virtual":/back|rear|environment|facing back|arrière|خلفية/.test(t)?"main":"unknown"}function Ze(e){let t=/camera2?\s*(\d+)/i.exec(e);return t?Number(t[1]):Number.POSITIVE_INFINITY}function Je(e){let t={main:0,virtual:1,ultra:9,tele:9,depth:9,front:9,unknown:9};return e.filter(n=>(n.kind===void 0||n.kind==="videoinput")&&n.deviceId!=="").map((n,i)=>({id:n.deviceId,kind:Ye(n.label),index:Ze(n.label),i})).filter(n=>t[n.kind]<9).sort((n,i)=>t[n.kind]-t[i.kind]||n.index-i.index||n.i-i.i).map(n=>n.id)}var pt="sekyro.doc.camera";function $e(){try{let e=globalThis.localStorage?.getItem(pt);return typeof e=="string"&&e!==""?e:null}catch{return null}}function ye(e){try{e===null?globalThis.localStorage?.removeItem(pt):globalThis.localStorage?.setItem(pt,e)}catch{}}var rt=(e,t)=>Array.isArray(e?.focusMode)&&e.focusMode.includes(t);function bt(e,t,n){if(!rt(e,"single-shot"))return null;let i=o=>Math.min(1,Math.max(0,Number.isFinite(o)?o:.5));return{focusMode:"single-shot",pointsOfInterest:[{x:i(t),y:i(n)}]}}function xi(e,t,n,i){if(!Number.isFinite(e)||!Number.isFinite(t)||n.width<=0||n.height<=0||i.width<=0||i.height<=0)return null;let o=Math.max(n.width/i.width,n.height/i.height),s=i.width*o,r=i.height*o,c=(e-n.left+(s-n.width)/2)/s,a=(t-n.top+(r-n.height)/2)/r;return{x:Math.min(1,Math.max(0,c)),y:Math.min(1,Math.max(0,a))}}function ke(e,t,n,i=st){let o=e?.zoom?.min,s=e?.zoom?.max;if(typeof s!="number"||s<=1)return 1;let r=n==="ID-3"?i.fillDistanceM.id3:i.fillDistanceM.id1,c=e?.focusDistance?.min,a;if(typeof c=="number"&&c>0&&c<1){if(a=c*(1+i.focusMarginFrac)/r,a<=1.05)return 1}else{if(Math.min(t.width,t.height)<i.zoomMinSourcePx)return 1;a=i.zoomNoFocusInfo}let l=Math.min(a,i.zoomMax,s);typeof o=="number"&&(l=Math.max(l,o));let u=e?.zoom?.step;return typeof u=="number"&&u>0&&(l=Math.round(l/u)*u),l>1.01?Number(l.toFixed(2)):1}function gt(e){try{return e.getVideoTracks?.()[0]}catch{return}}function Me(e){if(e!==null)for(let t of e.getTracks())t.stop()}function qe(e){try{let t=gt(e)?.getCapabilities?.();return!Array.isArray(t?.focusMode)||t.focusMode.includes("continuous")}catch{return!0}}var ti=3;async function xe(e){let t=s=>({audio:!1,video:{...s,width:{ideal:e.base.width},height:{ideal:e.base.height}}}),n=s=>e.getUserMedia(t({deviceId:{exact:s}})),i=()=>e.getUserMedia(t({facingMode:{ideal:"environment"}}));if(e.lensSelection){let s=$e();if(s!==null)try{return{stream:await n(s),lens:"stored"}}catch{ye(null)}}let o=await i();if(!e.lensSelection||e.enumerateDevices===void 0)return{stream:o,lens:"default"};try{let s=Je(await e.enumerateDevices()).slice(0,ti);if(s.length===0)return{stream:o,lens:"default"};let r=null;for(let c of s){let a=o!==null?gt(o)?.getSettings?.().deviceId:void 0;if(o===null||a!==c){Me(o),o=null;try{o=await n(c)}catch{continue}}if(r??(r=c),qe(o))return ye(c),{stream:o,lens:"selected"}}if(o!==null&&r!==null&&gt(o)?.getSettings?.().deviceId===r)return{stream:o,lens:"selected"};if(Me(o),o=null,r!==null)try{return{stream:await n(r),lens:"selected"}}catch{}return{stream:await i(),lens:"default"}}catch{return{stream:o??await i(),lens:"default"}}}var Z=Object.freeze({brightness:0,glare:0,cardGlare:0,sharpness:0,fill:0,shape:0,content:0,offsetX:0,offsetY:0,edgeConfidence:0,box:null}),I=e=>Math.min(1,Math.max(0,e));function we(e,t,n,i=.06){let o=Math.max(e.width/n,e.height),s=o*n,r=(e.width-s)/2,c=(e.height-o)/2,a=I((t.x-t.width*i-r)/s),l=I((t.y-t.height*i-c)/o),u=I((t.x+t.width*(1+i)-r)/s),d=I((t.y+t.height*(1+i)-c)/o);return{x:a,y:l,width:u-a,height:d-l}}function ve(e,t,n={}){let i=n.edgePeakFrac??0,{width:o,height:s,data:r}=e;if(o<=0||s<=0)return Z;let c=I(t.x),a=I(t.y),l={x:c,y:a,width:Math.max(0,I(t.x+t.width)-c),height:Math.max(0,I(t.y+t.height)-a)};if(l.width<=0||l.height<=0)return Z;let u=l.x*o,d=l.y*s,m=(l.x+l.width)*o,h=(l.y+l.height)*s,f=(m-u)*.15,g=(h-d)*.15,y=(p,b,T)=>Math.min(T,Math.max(b,p)),x=y(Math.floor(u-f),0,o-1),w=y(Math.floor(d-g),0,s-1),E=y(Math.ceil(m+f),x+1,o),v=y(Math.ceil(h+g),w+1,s),D=Math.max(1,Math.ceil(Math.max(E-x,v-w)/320)),M=Math.floor((E-x+D-1)/D),_=Math.floor((v-w+D-1)/D);if(M<3||_<3)return Z;let k=new Int32Array(M*_);for(let p=0;p<_;p++){let b=w+p*D;for(let T=0;T<M;T++){let C=(b*o+x+T*D)*4;k[p*M+T]=(r[C]??0)*77+(r[C+1]??0)*150+(r[C+2]??0)*29>>8}}let F=(p,b)=>(p-b-.5)/D,R=F(u,x),A=F(m,x),B=F(d,w),U=F(h,w),Mt=(m-u)/D,kt=(h-d)/D,xt=y(Math.ceil(R),0,M-1),Ce=y(Math.floor(A),xt,M-1),Dt=y(Math.ceil(B),0,_-1),Fe=y(Math.floor(U),Dt,_-1),wt=0,vt=0,H=0,St=0,_t=0,K=0;for(let p=Dt;p<=Fe;p++)for(let b=xt;b<=Ce;b++){let T=k[p*M+b];if(wt+=T,T>=248&&vt++,H++,b>=1&&b<M-1&&p>=1&&p<_-1){let C=k[p*M+b-1]+k[p*M+b+1]+k[(p-1)*M+b]+k[(p+1)*M+b]-4*T;St+=C,_t+=C*C,K++}}let Ae=H>0?wt/H:0,Rt=H>0?vt/H:0,Tt=K>0?St/K:0,Le=K>0?Math.max(0,_t/K-Tt*Tt):0,V=new Float64Array(M),W=new Float64Array(_);for(let p=0;p<_;p++)for(let b=1;b<M-1;b++)V[b]=V[b]+Math.abs(k[p*M+b+1]-k[p*M+b-1]);for(let p=1;p<_-1;p++)for(let b=0;b<M;b++)W[p]=W[p]+Math.abs(k[(p+1)*M+b]-k[(p-1)*M+b]);let O=at(V,!0,R,i),P=at(V,!1,A,i),G=at(W,!0,B,i),z=at(W,!1,U,i),Ct=(P.position-O.position)/Mt,Ft=(z.position-G.position)/kt,Ie=Ft>0?Ct/Ft:0,Ee=((O.position+P.position)/2-(R+A)/2)/Mt,Oe=((G.position+z.position)/2-(B+U)/2)/kt,At=De(V),Lt=De(W),Pe=At<=0||Lt<=0?0:Math.min(Math.min(O.value,P.value)/At,Math.min(G.value,z.value)/Lt),q=(p,b)=>b+(p+.5)*D,It=Rt,Et=0;{let p=(P.position-O.position)*.06,b=(z.position-G.position)*.06,T=y(Math.ceil(O.position+p),0,M-1),C=y(Math.floor(P.position-p),0,M-1),Ge=y(Math.ceil(G.position+b),0,_-1),Ot=y(Math.floor(z.position-b),0,_-1),Pt=0,tt=0,Gt=0;for(let N=Ge;N<=Ot;N++)for(let Q=T;Q<=C;Q++){tt++;let X=k[N*M+Q];X>=248&&Pt++;let ze=Q+2<=C?k[N*M+Q+2]:X,Ne=N+2<=Ot?k[(N+2)*M+Q]:X;(Math.abs(ze-X)>=24||Math.abs(Ne-X)>=24)&&Gt++}tt>=16&&(It=Pt/tt,Et=Gt/tt)}return{brightness:Ae,glare:Rt,cardGlare:It,sharpness:Le,fill:Ct,shape:Ie,content:Et,offsetX:Ee,offsetY:Oe,edgeConfidence:Pe,box:{left:q(O.position,x),right:q(P.position,x),top:q(G.position,w),bottom:q(z.position,w)}}}function at(e,t,n,i){let o=e.length,s=Math.max(1,Math.floor(o*.45)),r=t?1:Math.max(1,o-1-s),c=t?Math.min(o-2,s):o-2,a=r;for(let h=r;h<=c;h++)e[h]>e[a]&&(a=h);if(i>0&&i<1){let h=e[a]*i,f=a,g=Math.abs(a-n);for(let y=r;y<=c;y++){let x=e[y];if(x<h||x<(e[y-1]??0)||x<(e[y+1]??0))continue;let w=Math.abs(y-n);w<g&&(f=y,g=w)}a=f}let l=a>0?e[a-1]:0,u=e[a],d=a<o-1?e[a+1]:0,m=l+u+d;return{position:m>0?a+(d-l)/m:a,value:u}}function De(e){if(e.length<3)return 0;let t=0;for(let n=1;n<e.length-1;n++)t+=e[n];return t/(e.length-2)}function Se(e){let t=e.box;return t===null||t.right-t.left<4||t.bottom-t.top<4?null:{topLeft:{x:t.left,y:t.top},topRight:{x:t.right,y:t.top},bottomRight:{x:t.right,y:t.bottom},bottomLeft:{x:t.left,y:t.bottom}}}var J=Object.freeze({fillMin:.82,fillMax:1.06,offsetMax:.06,glareMax:.025,sharpnessMin:180,edgeConfidenceMin:1.6,darkBrightness:70,lockMs:450,steadyMs:900,steadyFillMin:.45,steadyFillMax:1.3,steadyFillDelta:.06,steadyOffsetDelta:.04,steadyRefMs:100,edgePeakFrac:.4,shapeTolerance:.2,contentMin:.1});function wi(e){let t=e!==null&&typeof e=="object"?e:{},n={...J};for(let i of Object.keys(J)){let o=t[i];typeof o=="number"&&Number.isFinite(o)&&o>=0&&o<=1e6&&(n[i]=o)}return n}var ct=class{constructor(t=J){this.t=t;this.goodSince=null;this.steadySince=null;this.last=null}reset(){this.goodSince=null,this.steadySince=null,this.last=null}tick(t,n){let i=this.t,o=i.shapeTolerance<=0||Math.abs(t.shape-1)<=i.shapeTolerance,s=t.edgeConfidence>=i.edgeConfidenceMin&&o&&t.content>=i.contentMin,r=t.fill>=i.fillMin&&t.fill<=i.fillMax,c=Math.abs(t.offsetX)<=i.offsetMax&&Math.abs(t.offsetY)<=i.offsetMax,a=t.cardGlare<=i.glareMax,l=t.sharpness>=i.sharpnessMin,u=this.last;this.last={fill:t.fill,offsetX:t.offsetX,offsetY:t.offsetY,at:n};let d=u!==null&&i.steadyRefMs>0?Math.min(3,Math.max(1,(n-u.at)/i.steadyRefMs)):1,m=s&&a&&l&&t.fill>=i.steadyFillMin&&t.fill<=i.steadyFillMax&&u!==null&&Math.abs(t.fill-u.fill)<=i.steadyFillDelta*d&&Math.abs(t.offsetX-u.offsetX)<=i.steadyOffsetDelta*d&&Math.abs(t.offsetY-u.offsetY)<=i.steadyOffsetDelta*d,h=s&&r&&c&&a&&l,f;if(s?a?t.fill<i.fillMin?f="too_small":t.fill>i.fillMax?f="too_big":l?c?f="locking":f="off_center":f="blurry":f="glare":f="no_card",h){if(m&&(this.steadySince??(this.steadySince=n)),this.goodSince??(this.goodSince=n),n-this.goodSince>=i.lockMs)return{detected:s,ready:!0,via:"good",blocker:"locking"};let g=this.steadySince!==null&&n-this.steadySince>=i.steadyMs;return{detected:s,ready:g,via:g?"steady":null,blocker:"locking"}}if(this.goodSince=null,m){this.steadySince??(this.steadySince=n);let g=n-this.steadySince>=i.steadyMs;return{detected:s,ready:g,via:g?"steady":null,blocker:g?"locking":"steadying"}}return this.steadySince=null,{detected:s,ready:!1,via:null,blocker:f}}};var $=null;async function ei(e){return $===null&&($=(await import("./detector-scanic-YCDNLCGV.js")).detectQuad),$(e)}async function ii(e){let t=jt(e);return t===null?null:{topLeft:{x:t.x,y:t.y},topRight:{x:t.x+t.width,y:t.y},bottomRight:{x:t.x+t.width,y:t.y+t.height},bottomLeft:{x:t.x,y:t.y+t.height}}}function Ni(){$===null&&import("./detector-scanic-YCDNLCGV.js").then(e=>{$=e.detectQuad}).catch(()=>{})}var ni=Object.freeze({LOW:3,MID:5,HIGH:6}),yt=Object.freeze({manualShutterMs:6e3,detectedNoLockMs:1950});function Qi(e){let t=e!==null&&typeof e=="object"?e:{},n=(i,o,s)=>typeof i=="number"&&Number.isFinite(i)&&i>=o&&i<=s?i:void 0;return{manualShutterMs:n(t.manualShutterMs,1e3,6e4)??yt.manualShutterMs,detectedNoLockMs:n(t.steadyMs,300,3e4)!==void 0?t.steadyMs+(n(t.lockMs,0,1e4)??450):yt.detectedNoLockMs}}var _e=class e{constructor(t){this.torchOn=!1;this.stillRefusals=0;this.zoom=1;this.positioningSince=null;this.detectedSince=null;this.lastSeenAt=null;this.lastGuideQuad=null;this.lastOcrReady=null;this.shutterOffered=!1;this.stats=e.freshStats();this.handlers=new Map;this.stream=null;this.timer=null;this.state="idle";this.lastGuidance=null;this.attempt=0;this.capturing=!1;this.feedback=new nt;this.lastFeedbackKey=null;this.lastQuad=null;this.lastDetect=null;this.opts=t,this.gate=new $t(t.format??"ID-1",t.thresholds);let n=t.deviceClass??Bt(Qt());this.deviceClass=n,this.camera=t.camera??st,this.shutterTuning=t.shutter??yt,this.guideTuning=t.guideLock??J,this.guideLock=new ct(this.guideTuning),this.cadenceMs=1e3/ni[n]}on(t,n){let i=this.handlers.get(t);return i||(i=new Set,this.handlers.set(t,i)),i.add(n),()=>i?.delete(n)}emit(t,n){for(let i of[...this.handlers.get(t)??[]])i(n)}async start(){let t=++this.attempt;this.gate.reset(),this.resetSide(),this.feedback.reset(),this.lastFeedbackKey=null,this.lastGuidance=null,this.capturing=!1,this.setState("preflight");try{let n=this.opts.getUserMedia??(s=>navigator.mediaDevices.getUserMedia(s));this.setState("acquiring");let i=this.opts.enumerateDevices??(this.opts.getUserMedia===void 0&&typeof navigator<"u"&&navigator.mediaDevices?.enumerateDevices?()=>navigator.mediaDevices.enumerateDevices():void 0),o=await xe({getUserMedia:n,...i!==void 0?{enumerateDevices:i}:{},lensSelection:this.camera.lensSelection,base:oe});if(this.stream=o.stream,Nt(this.stream),t!==this.attempt){for(let s of this.stream.getTracks())s.stop();return}if(this.opts.upgradeResolution!==!1&&await this.upgradeResolution(),t!==this.attempt||(await this.applyFocusAndZoom(),t!==this.attempt))return;this.opts.video.srcObject=this.stream,await this.opts.video.play().catch(()=>{}),this.setState("positioning"),this.scheduleTick(t)}catch(n){let i=zt(n);this.setState("error"),this.emit("error",{kind:i,retryable:!0})}}rearm(t){t!==void 0&&(this.opts.side=t),this.gate.reset(),this.resetSide(),this.feedback.reset(),this.lastFeedbackKey=null,this.lastGuidance=null,this.capturing=!1,this.stillRefusals=0,this.state==="captured"&&(this.setState("positioning"),this.scheduleTick(this.attempt))}async captureNow(){if(this.state!=="positioning"||this.capturing)return;let t=this.opts.video,n=this.lastDetect?.width??Math.max(1,t.videoWidth),i=this.lastDetect?.height??Math.max(1,t.videoHeight),o=this.lastQuad??this.lastGuideQuad??{topLeft:{x:0,y:0},topRight:{x:n,y:0},bottomRight:{x:n,y:i},bottomLeft:{x:0,y:i}},s=(this.opts.now??(()=>performance.now()))(),r=this.feedback.force("processing",s);this.lastFeedbackKey=r.key,this.emit("feedback",r),await this.fire(this.attempt,this.lastOcrReady!==null?this.lastOcrReady.quad:o,{width:n,height:i,tickSharpness:this.lastDetect?.tickSharpness??0},this.lastOcrReady?.via??"manual")}captureReport(){let t=this.stats;return{...this.opts.side!==void 0?{side:this.opts.side}:{},format:this.opts.format??"ID-1",deviceClass:this.deviceClass,video:{width:this.opts.video.videoWidth||0,height:this.opts.video.videoHeight||0},zoom:this.zoom,...t.zoomFallbackAtMs!==void 0?{zoomFallbackAtMs:t.zoomFallbackAtMs}:{},...t.msToCapture!==void 0?{msToCapture:t.msToCapture}:{},...t.via!==void 0?{via:t.via}:{},...t.shutterAtMs!==void 0?{shutterAtMs:t.shutterAtMs}:{},...t.shutterReason!==void 0?{shutterReason:t.shutterReason}:{},ticks:t.ticks,quadFraming:{...t.quadFraming},qualityBlockers:{...t.qualityBlockers},guideBlockers:{...t.guideBlockers},stillRefusals:t.stillRefusals,...this.ocrReport()}}ocrReport(){let t=this.opts.ocr;if(t===void 0)return{};let n=(this.opts.format??"ID-1")==="ID-3"||this.opts.side==="single"?"single":this.opts.side==="verso"?"verso":"recto",i=t.report(n,this.stats.via,(this.opts.now??(()=>performance.now()))());return i===null?{}:{ocr:i}}static freshStats(){return{ticks:0,quadFraming:{},qualityBlockers:{},guideBlockers:{},stillRefusals:0}}setGuide(t){t===void 0?delete this.opts.guide:this.opts.guide=t,this.guideLock.reset()}guideRegion(t){let n=t.width/Math.max(1,t.height),i=this.opts.guide;if(i!==void 0&&i.viewAspect>0){let c={width:i.viewAspect,height:1},a={x:i.rect.x*i.viewAspect,y:i.rect.y,width:i.rect.width*i.viewAspect,height:i.rect.height};return we(c,a,n,0)}let o=Kt(this.opts.format??"ID-1").center,s=.86,r=s*n/o;return r>.84&&(r=.84,s=r*o/n),{x:(1-s)/2,y:(1-r)/2,width:s,height:r}}resetSide(){this.positioningSince=null,this.detectedSince=null,this.lastSeenAt=null,this.guideLock.reset(),this.lastGuideQuad=null,this.lastOcrReady=null,this.opts.ocr?.reset(),this.stats=e.freshStats(),this.shutterOffered&&(this.shutterOffered=!1,this.emit("shutter",{available:!1}))}withdrawShutter(){this.shutterOffered&&(this.shutterOffered=!1,this.emit("shutter",{available:!1}))}zoomFallback(t){let n=this.videoTrack();if(n===null||this.zoom<=1)return;let i=this.focusCaps(),o=typeof i?.zoom?.min=="number"?Math.max(i.zoom.min,1):1;this.zoom=o,this.stats.zoomFallbackAtMs=Math.round(t-(this.positioningSince??t)),this.guideLock.reset(),this.gate.reset(),n.applyConstraints({advanced:[{zoom:o}]}).catch(()=>{})}offerShutter(t,n){this.shutterOffered||(this.shutterOffered=!0,this.stats.shutterAtMs=Math.round(n-(this.positioningSince??n)),this.stats.shutterReason=t,this.emit("shutter",{available:!0,reason:t}))}torchAvailable(){try{return this.stream?.getVideoTracks?.()[0]?.getCapabilities?.()?.torch===!0}catch{return!1}}async setTorch(t){this.torchOn=t;try{await this.stream?.getVideoTracks?.()[0]?.applyConstraints({advanced:[{torch:t}]})}catch{}}destroy(){if(this.attempt+=1,this.timer!==null&&(this.opts.clearTimer??clearTimeout)(this.timer),this.timer=null,this.stream)for(let t of this.stream.getTracks())t.stop();this.stream=null,this.opts.video.srcObject=null}async upgradeResolution(){try{let t=this.stream?.getVideoTracks?.()[0];if(t===void 0)return;let n=t.getSettings?.()??{},i=ae(t.getCapabilities?.(),{width:n.width??0,height:n.height??0},this.deviceClass,{width:this.camera.width,height:this.camera.height});i!==null&&await t.applyConstraints(i)}catch{}}focusCaps(){try{return this.videoTrack()?.getCapabilities?.()??null}catch{return null}}async applyFocusAndZoom(){let t=this.videoTrack();if(t===null)return;let n=this.focusCaps();this.camera.continuousFocus&&rt(n,"continuous")&&await t.applyConstraints({advanced:[{focusMode:"continuous"}]}).catch(()=>{});let i={width:0,height:0};try{let s=t.getSettings?.()??{};i={width:s.width??0,height:s.height??0}}catch{}let o=ke(n,i,this.opts.format??"ID-1",this.camera);if(o>1)try{await t.applyConstraints({advanced:[{zoom:o}]}),this.zoom=o}catch{this.zoom=1}}async focusAt(t,n){let i=this.videoTrack(),o=bt(this.focusCaps(),t,n);if(!(i===null||o===null))try{await i.applyConstraints({advanced:[o]}),(this.opts.setTimer??setTimeout)(()=>{this.restoreContinuous()},1500)}catch{}}async restoreContinuous(){let t=this.videoTrack();t===null||!this.camera.continuousFocus||!rt(this.focusCaps(),"continuous")||await t.applyConstraints({advanced:[{focusMode:"continuous"}]}).catch(()=>{})}async refocusOn(t,n){let i=this.camera.refocusBeforePhotoMs,o=this.videoTrack();if(i<=0||o===null||n.width<=0||n.height<=0)return;let s=L(t),r=bt(this.focusCaps(),(s.x+s.width/2)/n.width,(s.y+s.height/2)/n.height);if(r!==null)try{await o.applyConstraints({advanced:[r]});let c=this.opts.setTimer??setTimeout;await new Promise(a=>{c(()=>a(),i)})}catch{}}videoTrack(){try{return this.stream?.getVideoTracks?.()[0]??null}catch{return null}}async takeStill(t,n,i){if(this.opts.captureStill!==void 0)return this.opts.captureStill(this.opts.video,t,n);let o=this.opts.format??"ID-1",s=this.videoTrack();if(i&&this.opts.photoCapture!==!1&&this.deviceClass!=="LOW"&&!this.torchOn&&s!==null&&fe(s)){await this.refocusOn(t,n);let r=await be(this.opts.video,t,n,o,{track:s,detect:this.detector(),detectWidth:et});if(this.restoreContinuous(),r!==null)return r}return ge(this.opts.video,t,n,o)}detector(){return this.opts.detect??((this.opts.format??"ID-1")==="ID-3"?ii:ei)}setState(t){this.state=t,this.emit("statechange",{state:t})}scheduleTick(t){let n=this.opts.setTimer??setTimeout;this.timer=n(()=>{this.tick(t)},this.cadenceMs)}async tick(t){if(t!==this.attempt||this.state!=="positioning"||this.capturing)return;let n=this.opts.now??(()=>performance.now()),i=this.opts.grabDetectFrame??Te,o=this.detector(),s=i(this.opts.video,et);if(s===null){this.scheduleTick(t);return}let r=null;try{r=await o(s)}catch{r=null}if(t!==this.attempt)return;let c=r!==null?lt(s,r):s,a=n(),l={sharpness:j(c),exposure:Ht(c),meanLuma:Ut(c),specularFraction:ee(c)},u=ie({format:this.opts.format??"ID-1",quad:r,frameWidth:s.width,frameHeight:s.height,measures:l,...this.opts.thresholds!==void 0?{thresholds:this.opts.thresholds}:{}}),d=this.gate.tick({timestampMs:a,quad:r,quality:l,frameWidth:s.width,frameHeight:s.height}),h=(this.opts.format??"ID-1")!=="ID-3"?ve(s,this.guideRegion(s),{edgePeakFrac:this.guideTuning.edgePeakFrac}):Z,f=this.guideLock.tick(h,a);this.lastGuideQuad=f.detected?Se(h):null;let g=this.capturing?null:this.ocrTick(s,r,h,f.detected,u,a);this.positioningSince??(this.positioningSince=a);let y=this.stats;if(y.ticks+=1,y.quadFraming[u.framing]=(y.quadFraming[u.framing]??0)+1,u.framing==="ok"&&!d.ready){let R=u.lighting!=="ok"?u.lighting:u.glare!=="ok"?"glare":u.blur!=="ok"?"blurry":"steadying";y.qualityBlockers[R]=(y.qualityBlockers[R]??0)+1}y.guideBlockers[f.blocker]=(y.guideBlockers[f.blocker]??0)+1,r!==null||f.detected?(this.detectedSince??(this.detectedSince=a),this.lastSeenAt=a):this.detectedSince=null,this.lastSeenAt!==null&&a-this.lastSeenAt<=ui?a-this.positioningSince>=this.shutterTuning.manualShutterMs?this.offerShutter("timeout",a):g?.suspendQuality!==!0&&this.detectedSince!==null&&a-this.detectedSince>=this.shutterTuning.detectedNoLockMs&&this.offerShutter("detected_no_lock",a):this.withdrawShutter();let E=a-(this.lastSeenAt??this.positioningSince);this.zoom>1&&this.camera.zoomFallbackMs>0&&E>=this.camera.zoomFallbackMs&&this.zoomFallback(a),this.emit("checks",{engine:"docv1",p:d.p,plausible:d.plausible,stableTicks:d.stableTicks,quad:d.quad,frameWidth:s.width,frameHeight:s.height,analysis:u,ready:g?.suspendQuality!==!0&&(d.ready&&r!==null||f.ready&&this.lastGuideQuad!==null)||this.lastOcrReady!==null,guide:{detected:f.detected,blocker:f.blocker,fill:h.fill,shape:h.shape,content:h.content,offsetX:h.offsetX,offsetY:h.offsetY},...g!==null&&g.mode!=="off"?{ocr:{mode:g.mode,...g.mrz?{mrz:g.mrz}:{},...g.lock?{lock:g.lock}:{}}}:g?.mrz?{ocr:{mode:g.mode,mrz:g.mrz}}:{}}),this.lastQuad=d.plausible?r:null,this.lastDetect={width:s.width,height:s.height,tickSharpness:l.sharpness};let v=qt(u);u.framing!=="ok"&&f.detected&&(v=li(f.blocker,h.brightness<this.guideTuning.darkBrightness)),v==="blurry"&&r!==null&&si(r,s,this.opts.format??"ID-1")>=this.camera.focusFarFillFrac&&(v="focus_far"),v==="sensing"&&this.zoom>1&&this.camera.noDocFarHintMs>0&&E>=this.camera.noDocFarHintMs&&(v="focus_far");let D=this.feedback.tick(v,a);if(D.key!==this.lastFeedbackKey&&(this.lastFeedbackKey=D.key,this.emit("feedback",D)),d.guidanceKey!==this.lastGuidance&&(this.lastGuidance=d.guidanceKey,this.emit("guidance",{key:d.guidanceKey})),this.capturing)return;let M=g?.suspendQuality!==!0,_=M&&d.ready&&r!==null,k=M&&f.ready&&this.lastGuideQuad!==null,F=this.lastOcrReady;if(F!==null&&this.opts.autoCapture!==!1){let R=this.feedback.force("processing",a);this.lastFeedbackKey=R.key,this.emit("feedback",R);let A=j(lt(s,F.quad));await this.fire(t,F.quad,{width:s.width,height:s.height,tickSharpness:A},F.via);return}if((_||k)&&this.opts.autoCapture!==!1){let R=this.feedback.force("processing",a);this.lastFeedbackKey=R.key,this.emit("feedback",R);let A=k?this.lastGuideQuad:r,B=k?f.via==="steady"?"guide_steady":"guide_good":"quad",U=k?j(lt(s,A)):l.sharpness;await this.fire(t,A,{width:s.width,height:s.height,tickSharpness:U},B);return}this.scheduleTick(t)}async fire(t,n,i,o){this.capturing=!0;let s=this.opts.grabDetectFrame??Te,r=this.opts.setTimer??setTimeout,c={width:i.width,height:i.height};try{let a={still:await this.takeStill(n,c,!0),sharpness:i.tickSharpness};if(t!==this.attempt)return;let l=a.still.source==="photo"?0:ri;for(let m=0;m<l;m++){if(await new Promise(g=>{r(()=>g(),ai)}),t!==this.attempt)return;let h=s(this.opts.video,et);if(h===null)continue;let f=j(lt(h,n));if(f>a.sharpness*ci){let g=await this.takeStill(n,c,!1);if(t!==this.attempt)return;a={still:g,sharpness:f}}}if(t!==this.attempt)return;let u=a.still.sharpness;if(this.opts.autoCapture!==!1&&o!=="manual"&&typeof u=="number"&&u>=0&&u<this.camera.stillSharpnessMin&&this.stillRefusals<this.camera.stillRefusalsMax){this.stillRefusals+=1,this.stats.stillRefusals+=1,this.guideLock.reset(),this.lastOcrReady=null,(o==="text_lock"||o==="live_mrz")&&this.opts.ocr?.rearmFace();let m=(this.opts.now??(()=>performance.now()))(),h=this.feedback.force("focus_far",m);this.lastFeedbackKey=h.key,this.emit("feedback",h),this.capturing=!1,this.gate.reset(),this.scheduleTick(t);return}this.stillRefusals=0;let d=(this.opts.now??(()=>performance.now()))();this.stats.via=o,this.stats.msToCapture=Math.round(d-(this.positioningSince??d)),this.shutterOffered&&(this.shutterOffered=!1,this.emit("shutter",{available:!1})),this.setState("captured"),this.emit("artifacts",{keyframe:a.still.blob,previewDataUrl:a.still.previewDataUrl,...this.opts.side!==void 0?{side:this.opts.side}:{},...a.still.docRegion!==void 0?{docRegion:a.still.docRegion}:{},...(()=>{let m=o==="live_mrz"?this.opts.ocr?.liveCapture():null;return m?{liveMrz:m}:{}})()})}catch{if(t!==this.attempt)return;this.capturing=!1,this.gate.reset(),this.guideLock.reset(),this.lastOcrReady=null,(o==="text_lock"||o==="live_mrz")&&this.opts.ocr?.rearmFace(),this.scheduleTick(t)}}ocrTick(t,n,i,o,s,r){let c=this.opts.ocr,a=this.opts.video;if(c===void 0||!c.hasEngine)return this.lastOcrReady=null,null;let l=a.videoWidth,u=a.videoHeight;if(l<=0||u<=0||t.width<=0||t.height<=0)return null;let m=(this.opts.format??"ID-1")==="ID-3",h=this.guideRegion(t),f={x:h.x*l,y:h.y*u,w:h.width*l,h:h.height*u},g=l/t.width,y=u/t.height,x;m&&n!==null?x=oi(L(n),g,y,l,u):x=Yt(f,c.bandTop,u);let w=m?s.glare==="ok":i.cardGlare<=this.guideTuning.glareMax,E=m?s.blur==="ok":i.sharpness>=this.guideTuning.sharpnessMin,v=c.tick({atMs:r,video:a,mrzFace:m||this.opts.side==="verso"||this.opts.side==="single",present:m||n!==null||o,card:f,band:x,portrait:u>l,glareOk:w,sharpOk:E});if(v.ready&&v.via!==void 0){let D=m?n??Re(h,t):this.lastGuideQuad??Re(h,t);this.lastOcrReady={quad:D,via:v.via}}else this.lastOcrReady=null;return v}};function oi(e,t,n,i,o){let s=Math.min(i,e.width*1.06*t),r=Math.min(o,Math.max(e.height*1.6*n,s/5)),c=(e.y+e.height/2)*n,a=Math.max(0,Math.min(i-s,(e.x-e.width*.03)*t)),l=Math.max(0,Math.min(o-r,c-r/2));return{x:a,y:l,w:s,h:r}}function Re(e,t){let n=e.x*t.width,i=e.y*t.height,o=(e.x+e.width)*t.width,s=(e.y+e.height)*t.height;return{topLeft:{x:n,y:i},topRight:{x:o,y:i},bottomRight:{x:o,y:s},bottomLeft:{x:n,y:s}}}function si(e,t,n){let i=L(e);return t.width<=0||t.height<=0?0:n==="ID-3"?i.width/t.width:i.width*i.height/(t.width*t.height)}var ri=2,ai=260,ci=1.08;function Te(e,t){let n=e.videoWidth,i=e.videoHeight;if(n===0||i===0)return null;let o=Math.min(1,t/n),s=Math.round(n*o),r=Math.round(i*o),c=document.createElement("canvas");c.width=s,c.height=r;let a=c.getContext("2d",{willReadFrequently:!0});return a===null?null:(n/Math.max(1,s)>4&&(a.imageSmoothingQuality="high"),a.drawImage(e,0,0,s,r),a.getImageData(0,0,s,r))}function lt(e,t){let n=[t.topLeft.x,t.topRight.x,t.bottomRight.x,t.bottomLeft.x],i=[t.topLeft.y,t.topRight.y,t.bottomRight.y,t.bottomLeft.y],o=Math.max(0,Math.floor(Math.min(...n))),s=Math.max(0,Math.floor(Math.min(...i))),r=Math.min(e.width,Math.ceil(Math.max(...n))),c=Math.min(e.height,Math.ceil(Math.max(...i))),a=Math.max(1,r-o),l=Math.max(1,c-s),u=new Uint8ClampedArray(a*l*4);for(let d=0;d<l;d++){let m=((s+d)*e.width+o)*4;u.set(e.data.subarray(m,m+a*4),d*a*4)}return{data:u,width:a,height:l,colorSpace:e.colorSpace}}function li(e,t){return e==="glare"?"glare":e==="too_small"?"too_far":e==="too_big"?"too_close":t?"too_dark":e==="blurry"?"blurry":e==="off_center"?"edge_clipped":e==="no_card"?"sensing":"hold_still"}var ui=1200;export{it as a,qt as b,nt as c,Qe as d,ee as e,Be as f,ie as g,st as h,ki as i,Ye as j,Je as k,pt as l,$e as m,ye as n,rt as o,bt as p,xi as q,ke as r,qe as s,ti as t,xe as u,Z as v,we as w,ve as x,Se as y,J as z,wi as A,ct as B,Ni as C,ni as D,yt as E,Qi as F,_e as G,oi as H,ri as I,ai as J};
1
+ import{b as jt}from"./chunk-SMKCBUJL.js";import{a as et,b as Zt,c as Jt,e as ht,f as $t}from"./chunk-MXWLCDFX.js";import{d as Wt,h as Xt,k as Yt}from"./chunk-G6LKLN4U.js";import{b as Kt,c as Vt}from"./chunk-TDLIXFDT.js";import{b as Qt,c as Bt}from"./chunk-POIQGEZM.js";import{d as zt}from"./chunk-FHJ7HO3M.js";import{b as ut,c as Ut,d as j,e as Ht}from"./chunk-FPXL63KZ.js";import{c as Nt}from"./chunk-5OIC5TZS.js";var it=Object.freeze({sensing:{key:"sensing",reticle:"searching",minDurationMs:900},too_far:{key:"too_far",reticle:"coaching",minDurationMs:1400},too_close:{key:"too_close",reticle:"coaching",minDurationMs:1400},edge_clipped:{key:"edge_clipped",reticle:"coaching",minDurationMs:1400},wrong_shape:{key:"wrong_shape",reticle:"coaching",minDurationMs:1400},tilted:{key:"tilted",reticle:"coaching",minDurationMs:1400},too_dark:{key:"too_dark",reticle:"coaching",minDurationMs:1400},too_bright:{key:"too_bright",reticle:"coaching",minDurationMs:1400},blurry:{key:"blurry",reticle:"coaching",minDurationMs:1400},focus_far:{key:"focus_far",reticle:"coaching",minDurationMs:1600},glare:{key:"glare",reticle:"coaching",minDurationMs:1400},hold_still:{key:"hold_still",reticle:"locking",minDurationMs:900},processing:{key:"processing",reticle:"processing",minDurationMs:800},side_captured:{key:"side_captured",reticle:"flip",minDurationMs:2600},captured:{key:"captured",reticle:"done",minDurationMs:800}});function qt(e){return e.framing==="no_document"?"sensing":e.framing==="too_far"?"too_far":e.framing==="too_close"?"too_close":e.framing==="edge_clipped"?"edge_clipped":e.framing==="wrong_shape"?"wrong_shape":e.framing==="tilted"?"tilted":e.lighting==="too_dark"?"too_dark":e.lighting==="too_bright"?"too_bright":e.glare==="glare"?"glare":e.blur==="blurry"?"blurry":"hold_still"}var nt=class{constructor(t=2600,n=.35){this.windowMs=t;this.decayPerSecond=n;this.votes=[];this.current=it.sensing;this.currentSinceMs=null}reset(){this.votes=[],this.current=it.sensing,this.currentSinceMs=null}force(t,n){return this.votes=[],this.current=it[t],this.currentSinceMs=n,this.current}tick(t,n){if(this.currentSinceMs===null&&(this.currentSinceMs=n),this.votes.push({key:t,atMs:n}),this.votes=this.votes.filter(r=>n-r.atMs<=this.windowMs),n-this.currentSinceMs<this.current.minDurationMs)return this.current;let i=new Map;for(let r of this.votes){let c=(n-r.atMs)/1e3,a=this.decayPerSecond**c;i.set(r.key,(i.get(r.key)??0)+a)}let o=this.current.key,s=-1;for(let[r,c]of i)c>s&&(s=c,o=r);return o!==this.current.key&&(this.current=it[o],this.currentSinceMs=n),this.current}};var Qe=Object.freeze({MAX_AREA_FRAC:.92,TILT_MAX_SIDE_RATIO:1.3,GLARE_MAX_SPECULAR_FRAC:.025});function ee(e){let{data:t,width:n,height:i}=e,o=n*i;if(o===0)return 0;let s=0;for(let r=0;r<o;r++){let c=r*4;.299*(t[c]??0)+.587*(t[c+1]??0)+.114*(t[c+2]??0)>=252&&s++}return s/o}function Be(e){let t=(a,l)=>Math.hypot(l.x-a.x,l.y-a.y),n=t(e.topLeft,e.topRight),i=t(e.bottomLeft,e.bottomRight),o=t(e.topLeft,e.bottomLeft),s=t(e.topRight,e.bottomRight),r=Math.max(n,i)/Math.max(1e-6,Math.min(n,i)),c=Math.max(o,s)/Math.max(1e-6,Math.min(o,s));return Math.max(r,c)}function ie(e){let t={...Zt,...e.thresholds},n=Qe,{quad:i,frameWidth:o,frameHeight:s,measures:r}=e,c=e.format==="ID-3",a="ok";if(i===null)a="no_document";else if(c){let m=ht(i),h=o>0?m.width/o:0,f=m.height>0?m.width/m.height:0;h<t.ID3_BAND_MIN_WIDTH_FRAC?a="too_far":te(i,o,s,t.EDGE_CLIP_MARGIN_PX)?a="edge_clipped":(f<t.ID3_BAND_ASPECT_MIN||f>t.ID3_BAND_ASPECT_MAX)&&(a="wrong_shape")}else{let m=Jt(i,o,s),h=ht(i),f=Math.max(h.width,h.height)/Math.max(1e-6,Math.min(h.width,h.height));m<t.MIN_AREA_FRAC?a="too_far":m>n.MAX_AREA_FRAC?a="too_close":te(i,o,s,t.EDGE_CLIP_MARGIN_PX)?a="edge_clipped":Vt(e.format,f)?Be(i)>n.TILT_MAX_SIDE_RATIO&&(a="tilted"):a="wrong_shape"}let l=r.exposure>=t.GUIDE_EXPOSURE?"ok":r.meanLuma<(ut[0]+ut[1])/2?"too_dark":"too_bright",u=r.sharpness>=t.GUIDE_SHARPNESS?"ok":"blurry",d=r.specularFraction>=n.GLARE_MAX_SPECULAR_FRAC?"glare":"ok";return{framing:a,lighting:l,blur:u,glare:d,acceptable:a==="ok"&&l==="ok"&&u==="ok"&&d==="ok"}}function te(e,t,n,i){return[e.topLeft,e.topRight,e.bottomRight,e.bottomLeft].some(s=>s.x<=i||s.y<=i||s.x>=t-i||s.y>=n-i)}var oe=Object.freeze({width:1920,height:1080}),Ue=Object.freeze({width:3840,height:2160}),ne=4096,He=2560,se=640,ot=.15,Y=Object.freeze({side:.2,above:.9,below:.3});function L(e){let t=[e.topLeft.x,e.topRight.x,e.bottomRight.x,e.bottomLeft.x],n=[e.topLeft.y,e.topRight.y,e.bottomRight.y,e.bottomLeft.y],i=Math.min(...t),o=Math.min(...n);return{x:i,y:o,width:Math.max(...t)-i,height:Math.max(...n)-o}}function re(e,t){let n=Math.max(0,Math.floor(e.x)),i=Math.max(0,Math.floor(e.y)),o=Math.min(t.width,Math.ceil(e.x+e.width)),s=Math.min(t.height,Math.ceil(e.y+e.height));return o-n<16||s-i<16?null:{x:n,y:i,width:o-n,height:s-i}}function Ke(e,t,n){if(e===null||t.width<=0||t.height<=0)return null;let i=L(e);if(i.width<=0||i.height<=0)return null;let o=n==="ID-3"?{x:i.x-i.width*Y.side,y:i.y-i.width*Y.above,width:i.width*(1+2*Y.side),height:i.height+i.width*(Y.above+Y.below)}:{x:i.x-i.width*ot,y:i.y-i.height*ot,width:i.width*(1+2*ot),height:i.height*(1+2*ot)};return re(o,t)}function dt(e,t,n){let i=Math.max(e,t);return i>0?Math.min(1,n/i):1}function mt(e,t,n,i,o=He){let s=t.width>0?n.width/t.width:1,r=t.height>0?n.height/t.height:1,c=e===null?null:{topLeft:{x:e.topLeft.x*s,y:e.topLeft.y*r},topRight:{x:e.topRight.x*s,y:e.topRight.y*r},bottomRight:{x:e.bottomRight.x*s,y:e.bottomRight.y*r},bottomLeft:{x:e.bottomLeft.x*s,y:e.bottomLeft.y*r}},a=Ke(c,n,i)??{x:0,y:0,width:n.width,height:n.height},l=dt(a.width,a.height,o),u=Math.max(1,Math.round(a.width*l)),d=Math.max(1,Math.round(a.height*l)),m=null;if(c!==null){let h=L(c);m=re({x:(h.x-a.x)*l,y:(h.y-a.y)*l,width:h.width*l,height:h.height*l},{width:u,height:d})}return{crop:a,width:u,height:d,docRegion:m}}function ae(e,t,n,i=Ue){if(n==="LOW")return null;let o=e?.width?.max,s=e?.height?.max;if(typeof o!="number"||typeof s!="number"||o<=0||s<=0)return null;let r=Math.max(o,s),c=Math.min(o,s),a=Math.min(r,Math.max(i.width,i.height)),l=Math.min(c,Math.min(i.width,i.height));return a<=Math.max(t.width,t.height)?null:{width:{ideal:a},height:{ideal:l}}}function ce(e){let t={},n=e?.imageWidth,i=e?.imageHeight;if(typeof n?.max=="number"&&n.max>0){let o=typeof i?.max=="number"&&i.max>0?n.max/i.max:1.3333333333333333,s=o>=1?ne:ne*o,r=Math.min(n.max,Math.floor(s)),c=typeof n.step=="number"&&n.step>0?n.step:1,a=typeof n.min=="number"?n.min:0;r=Math.max(a,a+Math.floor((r-a)/c)*c),t.imageWidth=r}return e?.fillLightMode?.includes("off")===!0&&(t.fillLightMode="off"),t}function le(e,t){if(e.width<=0||e.height<=0||t.width<=0||t.height<=0)return!1;let n=e.width>e.height,i=t.width>t.height;return n!==i&&e.width!==e.height&&t.width!==t.height?!1:Math.max(e.width,e.height)>=1.2*Math.max(t.width,t.height)}function ue(e,t,n,i){if(n===null)return!1;let o=L(e),s=L(n);if(t.width<=0||i.width<=0)return!1;let r=o.width/t.width,c=s.width/i.width;return c>0&&r>=.6*c&&r<=1.25*c}var he=3500,Ve=.92;function me(){let e=globalThis.ImageCapture;return typeof e=="function"?e:null}function We(e){return/AppleWebKit\//.test(e)&&!/(Chrome|Chromium|Edg|OPR)\//.test(e)}function fe(e,t=typeof navigator>"u"?"":navigator.userAgent){return me()!==null&&!We(t)&&e!=null&&e.kind==="video"&&e.readyState==="live"}function de(e,t){return new Promise((n,i)=>{let o=setTimeout(()=>i(new Error("takePhoto timed out")),t);e.then(s=>{clearTimeout(o),n(s)},s=>{clearTimeout(o),i(s)})})}function ft(e,t){let n=document.createElement("canvas");return n.width=e,n.height=t,n}function Xe(e,t){return new Promise((n,i)=>{e.toBlob(o=>o?n(o):i(new Error("toBlob failed")),"image/jpeg",t)})}async function pe(e,t,n,i,o){let s=ft(n,i),r=ft(1,1);try{let c=s.getContext("2d");if(c===null)throw new Error("2d context unavailable");c.imageSmoothingQuality="high",c.drawImage(e,t.x,t.y,t.width,t.height,0,0,n,i);let a=await Xe(s,Ve),l=o===null?null:Wt({topLeft:{x:o.x,y:o.y},topRight:{x:o.x+o.width,y:o.y},bottomRight:{x:o.x+o.width,y:o.y+o.height},bottomLeft:{x:o.x,y:o.y+o.height}},{width:n,height:i},{width:n,height:i}),u=Xt(s,l),d=dt(n,i,se);return r.width=Math.max(1,Math.round(n*d)),r.height=Math.max(1,Math.round(i*d)),r.getContext("2d")?.drawImage(s,0,0,r.width,r.height),{blob:a,previewDataUrl:r.toDataURL("image/jpeg",.85),sharpness:u}}finally{s.width=0,s.height=0,r.width=0,r.height=0}}function je(e,t){let n=Math.min(1,t/e.width),i=ft(Math.max(1,Math.round(e.width*n)),Math.max(1,Math.round(e.height*n)));try{let o=i.getContext("2d",{willReadFrequently:!0});return o===null?null:(o.imageSmoothingQuality="high",o.drawImage(e,0,0,i.width,i.height),o.getImageData(0,0,i.width,i.height))}finally{i.width=0,i.height=0}}async function ge(e,t,n,i){let o={width:Math.max(1,e.videoWidth),height:Math.max(1,e.videoHeight)},s=mt(t,n,o,i);return{...await pe(e,s.crop,s.width,s.height,s.docRegion),docRegion:s.docRegion,source:"video",width:s.width,height:s.height}}async function be(e,t,n,i,o){let s=me();if(s===null)return null;let r=null;try{let c=new s(o.track),a=await de(c.getPhotoCapabilities?.()??Promise.resolve({}),he).catch(()=>({})),l=await de(c.takePhoto(ce(a)),he);r=await createImageBitmap(l);let u={width:e.videoWidth,height:e.videoHeight};if(!le(r,u))return null;let d=je(r,o.detectWidth),m=null;d!==null&&t!==null&&(m=await o.detect(d).catch(()=>null));let h=d??{width:r.width,height:r.height};m!==null&&!ue(m,h,t,n)&&(m=null);let f=mt(m,h,r,i);return{...await pe(r,f.crop,f.width,f.height,f.docRegion),docRegion:f.docRegion,source:"photo",width:f.width,height:f.height}}catch{return null}finally{r?.close()}}var st=Object.freeze({width:3840,height:2160,lensSelection:!0,continuousFocus:!0,refocusBeforePhotoMs:350,zoomMax:2,zoomNoFocusInfo:1.5,zoomMinSourcePx:2160,fillDistanceM:Object.freeze({id1:.11,id3:.15}),focusMarginFrac:.2,stillSharpnessMin:.16,stillRefusalsMax:2,focusFarFillFrac:.45,noDocFarHintMs:1500,zoomFallbackMs:8e3}),S=(e,t,n)=>typeof e=="number"&&Number.isFinite(e)&&e>=t&&e<=n?e:void 0;function ki(e){let t=st,n=e!==null&&typeof e=="object"?e:{},i=n.fillDistanceM!==null&&typeof n.fillDistanceM=="object"?n.fillDistanceM:{},o=(s,r)=>typeof s=="boolean"?s:r;return{width:S(n.width,640,7680)??t.width,height:S(n.height,480,4320)??t.height,lensSelection:o(n.lensSelection,t.lensSelection),continuousFocus:o(n.continuousFocus,t.continuousFocus),refocusBeforePhotoMs:S(n.refocusBeforePhotoMs,0,2e3)??t.refocusBeforePhotoMs,zoomMax:S(n.zoomMax,1,5)??t.zoomMax,zoomNoFocusInfo:S(n.zoomNoFocusInfo,1,5)??t.zoomNoFocusInfo,zoomMinSourcePx:S(n.zoomMinSourcePx,0,8e3)??t.zoomMinSourcePx,fillDistanceM:{id1:S(i.id1,.03,1)??t.fillDistanceM.id1,id3:S(i.id3,.03,1)??t.fillDistanceM.id3},focusMarginFrac:S(n.focusMarginFrac,0,2)??t.focusMarginFrac,stillSharpnessMin:S(n.stillSharpnessMin,0,10)??t.stillSharpnessMin,stillRefusalsMax:S(n.stillRefusalsMax,0,10)??t.stillRefusalsMax,focusFarFillFrac:S(n.focusFarFillFrac,0,1)??t.focusFarFillFrac,noDocFarHintMs:S(n.noDocFarHintMs,0,6e4)??t.noDocFarHintMs,zoomFallbackMs:S(n.zoomFallbackMs,0,12e4)??t.zoomFallbackMs}}function Ye(e){let t=e.toLowerCase();return t===""?"unknown":/front|facing front|user|selfie|face ?time/.test(t)?"front":/ultra|0\.5x|wide angle/.test(t)?"ultra":/tele|zoom|periscope|[2-9]x/.test(t)?"tele":/depth|tof|infrared|\bir\b|truedepth|lidar|macro|monochrome|mono\b/.test(t)?"depth":/dual|triple/.test(t)?"virtual":/back|rear|environment|facing back|arrière|خلفية/.test(t)?"main":"unknown"}function Ze(e){let t=/camera2?\s*(\d+)/i.exec(e);return t?Number(t[1]):Number.POSITIVE_INFINITY}function Je(e){let t={main:0,virtual:1,ultra:9,tele:9,depth:9,front:9,unknown:9};return e.filter(n=>(n.kind===void 0||n.kind==="videoinput")&&n.deviceId!=="").map((n,i)=>({id:n.deviceId,kind:Ye(n.label),index:Ze(n.label),i})).filter(n=>t[n.kind]<9).sort((n,i)=>t[n.kind]-t[i.kind]||n.index-i.index||n.i-i.i).map(n=>n.id)}var pt="sekyro.doc.camera";function $e(){try{let e=globalThis.localStorage?.getItem(pt);return typeof e=="string"&&e!==""?e:null}catch{return null}}function ye(e){try{e===null?globalThis.localStorage?.removeItem(pt):globalThis.localStorage?.setItem(pt,e)}catch{}}var rt=(e,t)=>Array.isArray(e?.focusMode)&&e.focusMode.includes(t);function bt(e,t,n){if(!rt(e,"single-shot"))return null;let i=o=>Math.min(1,Math.max(0,Number.isFinite(o)?o:.5));return{focusMode:"single-shot",pointsOfInterest:[{x:i(t),y:i(n)}]}}function xi(e,t,n,i){if(!Number.isFinite(e)||!Number.isFinite(t)||n.width<=0||n.height<=0||i.width<=0||i.height<=0)return null;let o=Math.max(n.width/i.width,n.height/i.height),s=i.width*o,r=i.height*o,c=(e-n.left+(s-n.width)/2)/s,a=(t-n.top+(r-n.height)/2)/r;return{x:Math.min(1,Math.max(0,c)),y:Math.min(1,Math.max(0,a))}}function ke(e,t,n,i=st){let o=e?.zoom?.min,s=e?.zoom?.max;if(typeof s!="number"||s<=1)return 1;let r=n==="ID-3"?i.fillDistanceM.id3:i.fillDistanceM.id1,c=e?.focusDistance?.min,a;if(typeof c=="number"&&c>0&&c<1){if(a=c*(1+i.focusMarginFrac)/r,a<=1.05)return 1}else{if(Math.min(t.width,t.height)<i.zoomMinSourcePx)return 1;a=i.zoomNoFocusInfo}let l=Math.min(a,i.zoomMax,s);typeof o=="number"&&(l=Math.max(l,o));let u=e?.zoom?.step;return typeof u=="number"&&u>0&&(l=Math.round(l/u)*u),l>1.01?Number(l.toFixed(2)):1}function gt(e){try{return e.getVideoTracks?.()[0]}catch{return}}function Me(e){if(e!==null)for(let t of e.getTracks())t.stop()}function qe(e){try{let t=gt(e)?.getCapabilities?.();return!Array.isArray(t?.focusMode)||t.focusMode.includes("continuous")}catch{return!0}}var ti=3;async function xe(e){let t=s=>({audio:!1,video:{...s,width:{ideal:e.base.width},height:{ideal:e.base.height}}}),n=s=>e.getUserMedia(t({deviceId:{exact:s}})),i=()=>e.getUserMedia(t({facingMode:{ideal:"environment"}}));if(e.lensSelection){let s=$e();if(s!==null)try{return{stream:await n(s),lens:"stored"}}catch{ye(null)}}let o=await i();if(!e.lensSelection||e.enumerateDevices===void 0)return{stream:o,lens:"default"};try{let s=Je(await e.enumerateDevices()).slice(0,ti);if(s.length===0)return{stream:o,lens:"default"};let r=null;for(let c of s){let a=o!==null?gt(o)?.getSettings?.().deviceId:void 0;if(o===null||a!==c){Me(o),o=null;try{o=await n(c)}catch{continue}}if(r??(r=c),qe(o))return ye(c),{stream:o,lens:"selected"}}if(o!==null&&r!==null&&gt(o)?.getSettings?.().deviceId===r)return{stream:o,lens:"selected"};if(Me(o),o=null,r!==null)try{return{stream:await n(r),lens:"selected"}}catch{}return{stream:await i(),lens:"default"}}catch{return{stream:o??await i(),lens:"default"}}}var Z=Object.freeze({brightness:0,glare:0,cardGlare:0,sharpness:0,fill:0,shape:0,content:0,offsetX:0,offsetY:0,edgeConfidence:0,box:null}),I=e=>Math.min(1,Math.max(0,e));function we(e,t,n,i=.06){let o=Math.max(e.width/n,e.height),s=o*n,r=(e.width-s)/2,c=(e.height-o)/2,a=I((t.x-t.width*i-r)/s),l=I((t.y-t.height*i-c)/o),u=I((t.x+t.width*(1+i)-r)/s),d=I((t.y+t.height*(1+i)-c)/o);return{x:a,y:l,width:u-a,height:d-l}}function ve(e,t,n={}){let i=n.edgePeakFrac??0,{width:o,height:s,data:r}=e;if(o<=0||s<=0)return Z;let c=I(t.x),a=I(t.y),l={x:c,y:a,width:Math.max(0,I(t.x+t.width)-c),height:Math.max(0,I(t.y+t.height)-a)};if(l.width<=0||l.height<=0)return Z;let u=l.x*o,d=l.y*s,m=(l.x+l.width)*o,h=(l.y+l.height)*s,f=(m-u)*.15,g=(h-d)*.15,y=(p,b,T)=>Math.min(T,Math.max(b,p)),x=y(Math.floor(u-f),0,o-1),w=y(Math.floor(d-g),0,s-1),E=y(Math.ceil(m+f),x+1,o),v=y(Math.ceil(h+g),w+1,s),D=Math.max(1,Math.ceil(Math.max(E-x,v-w)/320)),M=Math.floor((E-x+D-1)/D),_=Math.floor((v-w+D-1)/D);if(M<3||_<3)return Z;let k=new Int32Array(M*_);for(let p=0;p<_;p++){let b=w+p*D;for(let T=0;T<M;T++){let C=(b*o+x+T*D)*4;k[p*M+T]=(r[C]??0)*77+(r[C+1]??0)*150+(r[C+2]??0)*29>>8}}let F=(p,b)=>(p-b-.5)/D,R=F(u,x),A=F(m,x),B=F(d,w),U=F(h,w),Mt=(m-u)/D,kt=(h-d)/D,xt=y(Math.ceil(R),0,M-1),Ce=y(Math.floor(A),xt,M-1),Dt=y(Math.ceil(B),0,_-1),Fe=y(Math.floor(U),Dt,_-1),wt=0,vt=0,H=0,St=0,_t=0,K=0;for(let p=Dt;p<=Fe;p++)for(let b=xt;b<=Ce;b++){let T=k[p*M+b];if(wt+=T,T>=248&&vt++,H++,b>=1&&b<M-1&&p>=1&&p<_-1){let C=k[p*M+b-1]+k[p*M+b+1]+k[(p-1)*M+b]+k[(p+1)*M+b]-4*T;St+=C,_t+=C*C,K++}}let Ae=H>0?wt/H:0,Rt=H>0?vt/H:0,Tt=K>0?St/K:0,Le=K>0?Math.max(0,_t/K-Tt*Tt):0,V=new Float64Array(M),W=new Float64Array(_);for(let p=0;p<_;p++)for(let b=1;b<M-1;b++)V[b]=V[b]+Math.abs(k[p*M+b+1]-k[p*M+b-1]);for(let p=1;p<_-1;p++)for(let b=0;b<M;b++)W[p]=W[p]+Math.abs(k[(p+1)*M+b]-k[(p-1)*M+b]);let O=at(V,!0,R,i),P=at(V,!1,A,i),G=at(W,!0,B,i),z=at(W,!1,U,i),Ct=(P.position-O.position)/Mt,Ft=(z.position-G.position)/kt,Ie=Ft>0?Ct/Ft:0,Ee=((O.position+P.position)/2-(R+A)/2)/Mt,Oe=((G.position+z.position)/2-(B+U)/2)/kt,At=De(V),Lt=De(W),Pe=At<=0||Lt<=0?0:Math.min(Math.min(O.value,P.value)/At,Math.min(G.value,z.value)/Lt),q=(p,b)=>b+(p+.5)*D,It=Rt,Et=0;{let p=(P.position-O.position)*.06,b=(z.position-G.position)*.06,T=y(Math.ceil(O.position+p),0,M-1),C=y(Math.floor(P.position-p),0,M-1),Ge=y(Math.ceil(G.position+b),0,_-1),Ot=y(Math.floor(z.position-b),0,_-1),Pt=0,tt=0,Gt=0;for(let N=Ge;N<=Ot;N++)for(let Q=T;Q<=C;Q++){tt++;let X=k[N*M+Q];X>=248&&Pt++;let ze=Q+2<=C?k[N*M+Q+2]:X,Ne=N+2<=Ot?k[(N+2)*M+Q]:X;(Math.abs(ze-X)>=24||Math.abs(Ne-X)>=24)&&Gt++}tt>=16&&(It=Pt/tt,Et=Gt/tt)}return{brightness:Ae,glare:Rt,cardGlare:It,sharpness:Le,fill:Ct,shape:Ie,content:Et,offsetX:Ee,offsetY:Oe,edgeConfidence:Pe,box:{left:q(O.position,x),right:q(P.position,x),top:q(G.position,w),bottom:q(z.position,w)}}}function at(e,t,n,i){let o=e.length,s=Math.max(1,Math.floor(o*.45)),r=t?1:Math.max(1,o-1-s),c=t?Math.min(o-2,s):o-2,a=r;for(let h=r;h<=c;h++)e[h]>e[a]&&(a=h);if(i>0&&i<1){let h=e[a]*i,f=a,g=Math.abs(a-n);for(let y=r;y<=c;y++){let x=e[y];if(x<h||x<(e[y-1]??0)||x<(e[y+1]??0))continue;let w=Math.abs(y-n);w<g&&(f=y,g=w)}a=f}let l=a>0?e[a-1]:0,u=e[a],d=a<o-1?e[a+1]:0,m=l+u+d;return{position:m>0?a+(d-l)/m:a,value:u}}function De(e){if(e.length<3)return 0;let t=0;for(let n=1;n<e.length-1;n++)t+=e[n];return t/(e.length-2)}function Se(e){let t=e.box;return t===null||t.right-t.left<4||t.bottom-t.top<4?null:{topLeft:{x:t.left,y:t.top},topRight:{x:t.right,y:t.top},bottomRight:{x:t.right,y:t.bottom},bottomLeft:{x:t.left,y:t.bottom}}}var J=Object.freeze({fillMin:.82,fillMax:1.06,offsetMax:.06,glareMax:.025,sharpnessMin:180,edgeConfidenceMin:1.6,darkBrightness:70,lockMs:450,steadyMs:900,steadyFillMin:.45,steadyFillMax:1.3,steadyFillDelta:.06,steadyOffsetDelta:.04,steadyRefMs:100,edgePeakFrac:.4,shapeTolerance:.2,contentMin:.1});function wi(e){let t=e!==null&&typeof e=="object"?e:{},n={...J};for(let i of Object.keys(J)){let o=t[i];typeof o=="number"&&Number.isFinite(o)&&o>=0&&o<=1e6&&(n[i]=o)}return n}var ct=class{constructor(t=J){this.t=t;this.goodSince=null;this.steadySince=null;this.last=null}reset(){this.goodSince=null,this.steadySince=null,this.last=null}tick(t,n){let i=this.t,o=i.shapeTolerance<=0||Math.abs(t.shape-1)<=i.shapeTolerance,s=t.edgeConfidence>=i.edgeConfidenceMin&&o&&t.content>=i.contentMin,r=t.fill>=i.fillMin&&t.fill<=i.fillMax,c=Math.abs(t.offsetX)<=i.offsetMax&&Math.abs(t.offsetY)<=i.offsetMax,a=t.cardGlare<=i.glareMax,l=t.sharpness>=i.sharpnessMin,u=this.last;this.last={fill:t.fill,offsetX:t.offsetX,offsetY:t.offsetY,at:n};let d=u!==null&&i.steadyRefMs>0?Math.min(3,Math.max(1,(n-u.at)/i.steadyRefMs)):1,m=s&&a&&l&&t.fill>=i.steadyFillMin&&t.fill<=i.steadyFillMax&&u!==null&&Math.abs(t.fill-u.fill)<=i.steadyFillDelta*d&&Math.abs(t.offsetX-u.offsetX)<=i.steadyOffsetDelta*d&&Math.abs(t.offsetY-u.offsetY)<=i.steadyOffsetDelta*d,h=s&&r&&c&&a&&l,f;if(s?a?t.fill<i.fillMin?f="too_small":t.fill>i.fillMax?f="too_big":l?c?f="locking":f="off_center":f="blurry":f="glare":f="no_card",h){if(m&&(this.steadySince??(this.steadySince=n)),this.goodSince??(this.goodSince=n),n-this.goodSince>=i.lockMs)return{detected:s,ready:!0,via:"good",blocker:"locking"};let g=this.steadySince!==null&&n-this.steadySince>=i.steadyMs;return{detected:s,ready:g,via:g?"steady":null,blocker:"locking"}}if(this.goodSince=null,m){this.steadySince??(this.steadySince=n);let g=n-this.steadySince>=i.steadyMs;return{detected:s,ready:g,via:g?"steady":null,blocker:g?"locking":"steadying"}}return this.steadySince=null,{detected:s,ready:!1,via:null,blocker:f}}};var $=null;async function ei(e){return $===null&&($=(await import("./detector-scanic-YCDNLCGV.js")).detectQuad),$(e)}async function ii(e){let t=jt(e);return t===null?null:{topLeft:{x:t.x,y:t.y},topRight:{x:t.x+t.width,y:t.y},bottomRight:{x:t.x+t.width,y:t.y+t.height},bottomLeft:{x:t.x,y:t.y+t.height}}}function Ni(){$===null&&import("./detector-scanic-YCDNLCGV.js").then(e=>{$=e.detectQuad}).catch(()=>{})}var ni=Object.freeze({LOW:3,MID:5,HIGH:6}),yt=Object.freeze({manualShutterMs:6e3,detectedNoLockMs:1950});function Qi(e){let t=e!==null&&typeof e=="object"?e:{},n=(i,o,s)=>typeof i=="number"&&Number.isFinite(i)&&i>=o&&i<=s?i:void 0;return{manualShutterMs:n(t.manualShutterMs,1e3,6e4)??yt.manualShutterMs,detectedNoLockMs:n(t.steadyMs,300,3e4)!==void 0?t.steadyMs+(n(t.lockMs,0,1e4)??450):yt.detectedNoLockMs}}var _e=class e{constructor(t){this.torchOn=!1;this.stillRefusals=0;this.zoom=1;this.positioningSince=null;this.detectedSince=null;this.lastSeenAt=null;this.lastGuideQuad=null;this.lastOcrReady=null;this.shutterOffered=!1;this.stats=e.freshStats();this.handlers=new Map;this.stream=null;this.timer=null;this.state="idle";this.lastGuidance=null;this.attempt=0;this.capturing=!1;this.feedback=new nt;this.lastFeedbackKey=null;this.lastQuad=null;this.lastDetect=null;this.opts=t,this.gate=new $t(t.format??"ID-1",t.thresholds);let n=t.deviceClass??Bt(Qt());this.deviceClass=n,this.camera=t.camera??st,this.shutterTuning=t.shutter??yt,this.guideTuning=t.guideLock??J,this.guideLock=new ct(this.guideTuning),this.cadenceMs=1e3/ni[n]}on(t,n){let i=this.handlers.get(t);return i||(i=new Set,this.handlers.set(t,i)),i.add(n),()=>i?.delete(n)}emit(t,n){for(let i of[...this.handlers.get(t)??[]])i(n)}async start(){let t=++this.attempt;this.gate.reset(),this.resetSide(),this.feedback.reset(),this.lastFeedbackKey=null,this.lastGuidance=null,this.capturing=!1,this.setState("preflight");try{let n=this.opts.getUserMedia??(s=>navigator.mediaDevices.getUserMedia(s));this.setState("acquiring");let i=this.opts.enumerateDevices??(this.opts.getUserMedia===void 0&&typeof navigator<"u"&&navigator.mediaDevices?.enumerateDevices?()=>navigator.mediaDevices.enumerateDevices():void 0),o=await xe({getUserMedia:n,...i!==void 0?{enumerateDevices:i}:{},lensSelection:this.camera.lensSelection,base:oe});if(this.stream=o.stream,Nt(this.stream),t!==this.attempt){for(let s of this.stream.getTracks())s.stop();return}if(this.opts.upgradeResolution!==!1&&await this.upgradeResolution(),t!==this.attempt||(await this.applyFocusAndZoom(),t!==this.attempt))return;this.opts.video.srcObject=this.stream,await this.opts.video.play().catch(()=>{}),this.setState("positioning"),this.scheduleTick(t)}catch(n){let i=zt(n);this.setState("error"),this.emit("error",{kind:i,retryable:!0})}}rearm(t){t!==void 0&&(this.opts.side=t),this.gate.reset(),this.resetSide(),this.feedback.reset(),this.lastFeedbackKey=null,this.lastGuidance=null,this.capturing=!1,this.stillRefusals=0,this.state==="captured"&&(this.setState("positioning"),this.scheduleTick(this.attempt))}async captureNow(){if(this.state!=="positioning"||this.capturing)return;let t=this.opts.video,n=this.lastDetect?.width??Math.max(1,t.videoWidth),i=this.lastDetect?.height??Math.max(1,t.videoHeight),o=this.lastQuad??this.lastGuideQuad??{topLeft:{x:0,y:0},topRight:{x:n,y:0},bottomRight:{x:n,y:i},bottomLeft:{x:0,y:i}},s=(this.opts.now??(()=>performance.now()))(),r=this.feedback.force("processing",s);this.lastFeedbackKey=r.key,this.emit("feedback",r),await this.fire(this.attempt,this.lastOcrReady!==null?this.lastOcrReady.quad:o,{width:n,height:i,tickSharpness:this.lastDetect?.tickSharpness??0},this.lastOcrReady?.via??"manual")}captureReport(){let t=this.stats;return{...this.opts.side!==void 0?{side:this.opts.side}:{},format:this.opts.format??"ID-1",deviceClass:this.deviceClass,video:{width:this.opts.video.videoWidth||0,height:this.opts.video.videoHeight||0},zoom:this.zoom,...t.zoomFallbackAtMs!==void 0?{zoomFallbackAtMs:t.zoomFallbackAtMs}:{},...t.msToCapture!==void 0?{msToCapture:t.msToCapture}:{},...t.via!==void 0?{via:t.via}:{},...t.shutterAtMs!==void 0?{shutterAtMs:t.shutterAtMs}:{},...t.shutterReason!==void 0?{shutterReason:t.shutterReason}:{},ticks:t.ticks,quadFraming:{...t.quadFraming},qualityBlockers:{...t.qualityBlockers},guideBlockers:{...t.guideBlockers},stillRefusals:t.stillRefusals,...this.ocrReport()}}ocrReport(){let t=this.opts.ocr;if(t===void 0)return{};let n=(this.opts.format??"ID-1")==="ID-3"||this.opts.side==="single"?"single":this.opts.side==="verso"?"verso":"recto",i=t.report(n,this.stats.via,(this.opts.now??(()=>performance.now()))());return i===null?{}:{ocr:i}}static freshStats(){return{ticks:0,quadFraming:{},qualityBlockers:{},guideBlockers:{},stillRefusals:0}}setGuide(t){t===void 0?delete this.opts.guide:this.opts.guide=t,this.guideLock.reset()}guideRegion(t){let n=t.width/Math.max(1,t.height),i=this.opts.guide;if(i!==void 0&&i.viewAspect>0){let c={width:i.viewAspect,height:1},a={x:i.rect.x*i.viewAspect,y:i.rect.y,width:i.rect.width*i.viewAspect,height:i.rect.height};return we(c,a,n,0)}let o=Kt(this.opts.format??"ID-1").center,s=.86,r=s*n/o;return r>.84&&(r=.84,s=r*o/n),{x:(1-s)/2,y:(1-r)/2,width:s,height:r}}resetSide(){this.positioningSince=null,this.detectedSince=null,this.lastSeenAt=null,this.guideLock.reset(),this.lastGuideQuad=null,this.lastOcrReady=null,this.opts.ocr?.reset(),this.stats=e.freshStats(),this.shutterOffered&&(this.shutterOffered=!1,this.emit("shutter",{available:!1}))}withdrawShutter(){this.shutterOffered&&(this.shutterOffered=!1,this.emit("shutter",{available:!1}))}zoomFallback(t){let n=this.videoTrack();if(n===null||this.zoom<=1)return;let i=this.focusCaps(),o=typeof i?.zoom?.min=="number"?Math.max(i.zoom.min,1):1;this.zoom=o,this.stats.zoomFallbackAtMs=Math.round(t-(this.positioningSince??t)),this.guideLock.reset(),this.gate.reset(),n.applyConstraints({advanced:[{zoom:o}]}).catch(()=>{})}offerShutter(t,n){this.shutterOffered||(this.shutterOffered=!0,this.stats.shutterAtMs=Math.round(n-(this.positioningSince??n)),this.stats.shutterReason=t,this.emit("shutter",{available:!0,reason:t}))}torchAvailable(){try{return this.stream?.getVideoTracks?.()[0]?.getCapabilities?.()?.torch===!0}catch{return!1}}async setTorch(t){this.torchOn=t;try{await this.stream?.getVideoTracks?.()[0]?.applyConstraints({advanced:[{torch:t}]})}catch{}}destroy(){if(this.attempt+=1,this.timer!==null&&(this.opts.clearTimer??clearTimeout)(this.timer),this.timer=null,this.stream)for(let t of this.stream.getTracks())t.stop();this.stream=null,this.opts.video.srcObject=null}async upgradeResolution(){try{let t=this.stream?.getVideoTracks?.()[0];if(t===void 0)return;let n=t.getSettings?.()??{},i=ae(t.getCapabilities?.(),{width:n.width??0,height:n.height??0},this.deviceClass,{width:this.camera.width,height:this.camera.height});i!==null&&await t.applyConstraints(i)}catch{}}focusCaps(){try{return this.videoTrack()?.getCapabilities?.()??null}catch{return null}}async applyFocusAndZoom(){let t=this.videoTrack();if(t===null)return;let n=this.focusCaps();this.camera.continuousFocus&&rt(n,"continuous")&&await t.applyConstraints({advanced:[{focusMode:"continuous"}]}).catch(()=>{});let i={width:0,height:0};try{let s=t.getSettings?.()??{};i={width:s.width??0,height:s.height??0}}catch{}let o=ke(n,i,this.opts.format??"ID-1",this.camera);if(o>1)try{await t.applyConstraints({advanced:[{zoom:o}]}),this.zoom=o}catch{this.zoom=1}}async focusAt(t,n){let i=this.videoTrack(),o=bt(this.focusCaps(),t,n);if(!(i===null||o===null))try{await i.applyConstraints({advanced:[o]}),(this.opts.setTimer??setTimeout)(()=>{this.restoreContinuous()},1500)}catch{}}async restoreContinuous(){let t=this.videoTrack();t===null||!this.camera.continuousFocus||!rt(this.focusCaps(),"continuous")||await t.applyConstraints({advanced:[{focusMode:"continuous"}]}).catch(()=>{})}async refocusOn(t,n){let i=this.camera.refocusBeforePhotoMs,o=this.videoTrack();if(i<=0||o===null||n.width<=0||n.height<=0)return;let s=L(t),r=bt(this.focusCaps(),(s.x+s.width/2)/n.width,(s.y+s.height/2)/n.height);if(r!==null)try{await o.applyConstraints({advanced:[r]});let c=this.opts.setTimer??setTimeout;await new Promise(a=>{c(()=>a(),i)})}catch{}}videoTrack(){try{return this.stream?.getVideoTracks?.()[0]??null}catch{return null}}async takeStill(t,n,i){if(this.opts.captureStill!==void 0)return this.opts.captureStill(this.opts.video,t,n);let o=this.opts.format??"ID-1",s=this.videoTrack();if(i&&this.opts.photoCapture!==!1&&this.deviceClass!=="LOW"&&!this.torchOn&&s!==null&&fe(s)){await this.refocusOn(t,n);let r=await be(this.opts.video,t,n,o,{track:s,detect:this.detector(),detectWidth:et});if(this.restoreContinuous(),r!==null)return r}return ge(this.opts.video,t,n,o)}detector(){return this.opts.detect??((this.opts.format??"ID-1")==="ID-3"?ii:ei)}setState(t){this.state=t,this.emit("statechange",{state:t})}scheduleTick(t){let n=this.opts.setTimer??setTimeout;this.timer=n(()=>{this.tick(t)},this.cadenceMs)}async tick(t){if(t!==this.attempt||this.state!=="positioning"||this.capturing)return;let n=this.opts.now??(()=>performance.now()),i=this.opts.grabDetectFrame??Te,o=this.detector(),s=i(this.opts.video,et);if(s===null){this.scheduleTick(t);return}let r=null;try{r=await o(s)}catch{r=null}if(t!==this.attempt)return;let c=r!==null?lt(s,r):s,a=n(),l={sharpness:j(c),exposure:Ht(c),meanLuma:Ut(c),specularFraction:ee(c)},u=ie({format:this.opts.format??"ID-1",quad:r,frameWidth:s.width,frameHeight:s.height,measures:l,...this.opts.thresholds!==void 0?{thresholds:this.opts.thresholds}:{}}),d=this.gate.tick({timestampMs:a,quad:r,quality:l,frameWidth:s.width,frameHeight:s.height}),h=(this.opts.format??"ID-1")!=="ID-3"?ve(s,this.guideRegion(s),{edgePeakFrac:this.guideTuning.edgePeakFrac}):Z,f=this.guideLock.tick(h,a);this.lastGuideQuad=f.detected?Se(h):null;let g=this.capturing?null:this.ocrTick(s,r,h,f.detected,u,a);this.positioningSince??(this.positioningSince=a);let y=this.stats;if(y.ticks+=1,y.quadFraming[u.framing]=(y.quadFraming[u.framing]??0)+1,u.framing==="ok"&&!d.ready){let R=u.lighting!=="ok"?u.lighting:u.glare!=="ok"?"glare":u.blur!=="ok"?"blurry":"steadying";y.qualityBlockers[R]=(y.qualityBlockers[R]??0)+1}y.guideBlockers[f.blocker]=(y.guideBlockers[f.blocker]??0)+1,r!==null||f.detected?(this.detectedSince??(this.detectedSince=a),this.lastSeenAt=a):this.detectedSince=null,this.lastSeenAt!==null&&a-this.lastSeenAt<=ui?a-this.positioningSince>=this.shutterTuning.manualShutterMs?this.offerShutter("timeout",a):g?.suspendQuality!==!0&&this.detectedSince!==null&&a-this.detectedSince>=this.shutterTuning.detectedNoLockMs&&this.offerShutter("detected_no_lock",a):this.withdrawShutter();let E=a-(this.lastSeenAt??this.positioningSince);this.zoom>1&&this.camera.zoomFallbackMs>0&&E>=this.camera.zoomFallbackMs&&this.zoomFallback(a),this.emit("checks",{engine:"docv1",p:d.p,plausible:d.plausible,stableTicks:d.stableTicks,quad:d.quad,frameWidth:s.width,frameHeight:s.height,analysis:u,ready:g?.suspendQuality!==!0&&(d.ready&&r!==null||f.ready&&this.lastGuideQuad!==null)||this.lastOcrReady!==null,guide:{detected:f.detected,blocker:f.blocker,fill:h.fill,shape:h.shape,content:h.content,offsetX:h.offsetX,offsetY:h.offsetY},...g!==null&&g.mode!=="off"?{ocr:{mode:g.mode,...g.mrz?{mrz:g.mrz}:{},...g.lock?{lock:g.lock}:{}}}:g?.mrz?{ocr:{mode:g.mode,mrz:g.mrz}}:{}}),this.lastQuad=d.plausible?r:null,this.lastDetect={width:s.width,height:s.height,tickSharpness:l.sharpness};let v=qt(u);u.framing!=="ok"&&f.detected&&(v=li(f.blocker,h.brightness<this.guideTuning.darkBrightness)),v==="blurry"&&r!==null&&si(r,s,this.opts.format??"ID-1")>=this.camera.focusFarFillFrac&&(v="focus_far"),v==="sensing"&&this.zoom>1&&this.camera.noDocFarHintMs>0&&E>=this.camera.noDocFarHintMs&&(v="focus_far");let D=this.feedback.tick(v,a);if(D.key!==this.lastFeedbackKey&&(this.lastFeedbackKey=D.key,this.emit("feedback",D)),d.guidanceKey!==this.lastGuidance&&(this.lastGuidance=d.guidanceKey,this.emit("guidance",{key:d.guidanceKey})),this.capturing)return;let M=g?.suspendQuality!==!0,_=M&&d.ready&&r!==null,k=M&&f.ready&&this.lastGuideQuad!==null,F=this.lastOcrReady;if(F!==null&&this.opts.autoCapture!==!1){let R=this.feedback.force("processing",a);this.lastFeedbackKey=R.key,this.emit("feedback",R);let A=j(lt(s,F.quad));await this.fire(t,F.quad,{width:s.width,height:s.height,tickSharpness:A},F.via);return}if((_||k)&&this.opts.autoCapture!==!1){let R=this.feedback.force("processing",a);this.lastFeedbackKey=R.key,this.emit("feedback",R);let A=k?this.lastGuideQuad:r,B=k?f.via==="steady"?"guide_steady":"guide_good":"quad",U=k?j(lt(s,A)):l.sharpness;await this.fire(t,A,{width:s.width,height:s.height,tickSharpness:U},B);return}this.scheduleTick(t)}async fire(t,n,i,o){this.capturing=!0;let s=this.opts.grabDetectFrame??Te,r=this.opts.setTimer??setTimeout,c={width:i.width,height:i.height};try{let a={still:await this.takeStill(n,c,!0),sharpness:i.tickSharpness};if(t!==this.attempt)return;let l=a.still.source==="photo"?0:ri;for(let m=0;m<l;m++){if(await new Promise(g=>{r(()=>g(),ai)}),t!==this.attempt)return;let h=s(this.opts.video,et);if(h===null)continue;let f=j(lt(h,n));if(f>a.sharpness*ci){let g=await this.takeStill(n,c,!1);if(t!==this.attempt)return;a={still:g,sharpness:f}}}if(t!==this.attempt)return;let u=a.still.sharpness;if(this.opts.autoCapture!==!1&&o!=="manual"&&typeof u=="number"&&u>=0&&u<this.camera.stillSharpnessMin&&this.stillRefusals<this.camera.stillRefusalsMax){this.stillRefusals+=1,this.stats.stillRefusals+=1,this.guideLock.reset(),this.lastOcrReady=null,(o==="text_lock"||o==="live_mrz")&&this.opts.ocr?.rearmFace();let m=(this.opts.now??(()=>performance.now()))(),h=this.feedback.force("focus_far",m);this.lastFeedbackKey=h.key,this.emit("feedback",h),this.capturing=!1,this.gate.reset(),this.scheduleTick(t);return}this.stillRefusals=0;let d=(this.opts.now??(()=>performance.now()))();this.stats.via=o,this.stats.msToCapture=Math.round(d-(this.positioningSince??d)),this.shutterOffered&&(this.shutterOffered=!1,this.emit("shutter",{available:!1})),this.setState("captured"),this.emit("artifacts",{keyframe:a.still.blob,previewDataUrl:a.still.previewDataUrl,...this.opts.side!==void 0?{side:this.opts.side}:{},...a.still.docRegion!==void 0?{docRegion:a.still.docRegion}:{},...(()=>{let m=o==="live_mrz"?this.opts.ocr?.liveCapture():null;return m?{liveMrz:m}:{}})()})}catch{if(t!==this.attempt)return;this.capturing=!1,this.gate.reset(),this.guideLock.reset(),this.lastOcrReady=null,(o==="text_lock"||o==="live_mrz")&&this.opts.ocr?.rearmFace(),this.scheduleTick(t)}}ocrTick(t,n,i,o,s,r){let c=this.opts.ocr,a=this.opts.video;if(c===void 0||!c.hasEngine)return this.lastOcrReady=null,null;let l=a.videoWidth,u=a.videoHeight;if(l<=0||u<=0||t.width<=0||t.height<=0)return null;let m=(this.opts.format??"ID-1")==="ID-3",h=this.guideRegion(t),f={x:h.x*l,y:h.y*u,w:h.width*l,h:h.height*u},g=l/t.width,y=u/t.height,x;m&&n!==null?x=oi(L(n),g,y,l,u):x=Yt(f,c.bandTop,u);let w=m?s.glare==="ok":i.cardGlare<=this.guideTuning.glareMax,E=m?s.blur==="ok":i.sharpness>=this.guideTuning.sharpnessMin,v=c.tick({atMs:r,video:a,mrzFace:m||this.opts.side==="verso"||this.opts.side==="single",present:m||n!==null||o,card:f,band:x,portrait:u>l,glareOk:w,sharpOk:E});if(v.ready&&v.via!==void 0){let D=m?n??Re(h,t):this.lastGuideQuad??Re(h,t);this.lastOcrReady={quad:D,via:v.via}}else this.lastOcrReady=null;return v}};function oi(e,t,n,i,o){let s=Math.min(i,e.width*1.06*t),r=Math.min(o,Math.max(e.height*1.6*n,s/5)),c=(e.y+e.height/2)*n,a=Math.max(0,Math.min(i-s,(e.x-e.width*.03)*t)),l=Math.max(0,Math.min(o-r,c-r/2));return{x:a,y:l,w:s,h:r}}function Re(e,t){let n=e.x*t.width,i=e.y*t.height,o=(e.x+e.width)*t.width,s=(e.y+e.height)*t.height;return{topLeft:{x:n,y:i},topRight:{x:o,y:i},bottomRight:{x:o,y:s},bottomLeft:{x:n,y:s}}}function si(e,t,n){let i=L(e);return t.width<=0||t.height<=0?0:n==="ID-3"?i.width/t.width:i.width*i.height/(t.width*t.height)}var ri=2,ai=260,ci=1.08;function Te(e,t){let n=e.videoWidth,i=e.videoHeight;if(n===0||i===0)return null;let o=Math.min(1,t/n),s=Math.round(n*o),r=Math.round(i*o),c=document.createElement("canvas");c.width=s,c.height=r;let a=c.getContext("2d",{willReadFrequently:!0});return a===null?null:(n/Math.max(1,s)>4&&(a.imageSmoothingQuality="high"),a.drawImage(e,0,0,s,r),a.getImageData(0,0,s,r))}function lt(e,t){let n=[t.topLeft.x,t.topRight.x,t.bottomRight.x,t.bottomLeft.x],i=[t.topLeft.y,t.topRight.y,t.bottomRight.y,t.bottomLeft.y],o=Math.max(0,Math.floor(Math.min(...n))),s=Math.max(0,Math.floor(Math.min(...i))),r=Math.min(e.width,Math.ceil(Math.max(...n))),c=Math.min(e.height,Math.ceil(Math.max(...i))),a=Math.max(1,r-o),l=Math.max(1,c-s),u=new Uint8ClampedArray(a*l*4);for(let d=0;d<l;d++){let m=((s+d)*e.width+o)*4;u.set(e.data.subarray(m,m+a*4),d*a*4)}return{data:u,width:a,height:l,colorSpace:e.colorSpace}}function li(e,t){return e==="glare"?"glare":e==="too_small"?"too_far":e==="too_big"?"too_close":t?"too_dark":e==="blurry"?"blurry":e==="off_center"?"edge_clipped":e==="no_card"?"sensing":"hold_still"}var ui=1200;export{it as a,qt as b,nt as c,Qe as d,ee as e,Be as f,ie as g,st as h,ki as i,Ye as j,Je as k,pt as l,$e as m,ye as n,rt as o,bt as p,xi as q,ke as r,qe as s,ti as t,xe as u,Z as v,we as w,ve as x,Se as y,J as z,wi as A,ct as B,Ni as C,ni as D,yt as E,Qi as F,_e as G,oi as H,ri as I,ai as J};
@@ -0,0 +1 @@
1
+ import{a as X,b as ke,d as V,e as L,f as U,g as be,h as E,i as B,j as b,k as F,l as P,m as w,n as D,v as Pe,w as xe}from"./chunk-UBDG5IAP.js";import{m as Ce}from"./chunk-JRSIMNB5.js";import{a as ge}from"./chunk-GT2ZLGF7.js";import{d as $}from"./chunk-FUHDOEBP.js";import{c as j,f as _e,g as G}from"./chunk-57VOMVKM.js";function K(e){return e.idNumberBound??e.nniBound}function H(e){return e===void 0?void 0:e.idNumberFromDocument??e.nniFromDocument}function ve(e){let t=e.idNumberMasked??e.nniMasked;return typeof t=="string"&&t!==""?t:void 0}var Ze="https://api.sekyro.ai",We=5e3,Je=1500,Qe=10;function $e(e){return new Promise(t=>setTimeout(t,e))}function je(){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 o=0;o<16;o+=1)t[o]=Math.floor(Math.random()*256);t[6]=(t[6]??0)&15|64,t[8]=(t[8]??0)&63|128;let i=[...t].map(o=>o.toString(16).padStart(2,"0")).join("");return`${i.slice(0,8)}-${i.slice(8,12)}-${i.slice(12,16)}-${i.slice(16,20)}-${i.slice(20)}`}function Tt(e){return Xe(e,{})}function Xe(e,t){let i=e.apiOrigin??Ze,o=e.autoRetry??!0,r=e.rearm??"auto",a=t.client??new _e({apiOrigin:i,sessionToken:e.clientToken,fetch:e.fetch}),u=t.sleep??$e,s=t.uuid??je,h=t.getTurnstileToken??((n,c)=>import("./turnstile-FATNZ4AG.js").then(l=>l.executeTurnstile(n,c))),S=ge(),m=null,p=null,d=!1,R=new AbortController,f=null,q=null,x=n=>{f=n,S.emit("view",n),m?.onView(n)},_=()=>f!==null?Promise.resolve(f):(q??(q=a.getSession().then(n=>(x(n),n)).finally(()=>{q=null})),q),v=async()=>{let n=await a.getSession();return x(n),n},Y=async(n,c)=>{n.plan!==void 0?x(n):await v()},Z=null,ie=async n=>{let c=await _();if(!n&&c.consentRecorded)return;let l=await a.recordConsent(e.locale);l.plan!==void 0?x(l):f!==null&&x({...f,consentRecorded:!0})},O=n=>n?.force===!0?ie(!0):(Z??(Z=ie(!1).finally(()=>{Z=null})),Z),W={client:a,ensureConsent:n=>O(n),sleep:u,uuid:s,onBusy:n=>{d||S.emit("busy",n)}},oe=!1,re=null,J=n=>{if(n.status==="approved"||n.status==="rejected"||n.status==="review"){if(oe)return;oe=!0}re=JSON.stringify(n),S.emit("result",n)},Te=n=>{re!==JSON.stringify(n)&&J(n)},se=async n=>{let c=f;n&&(c=await v().catch(()=>f));let l=c===null?null:E(c);return l!==null&&!d&&S.emit("method",l),l!==null},ae=null,ce=!1,ue=!1,de=()=>Pe(W,(n,c)=>n.submitCheck("population_registry",{},{idempotencyKey:c})),le=n=>K(n)===!0||H(P(n,"population_registry"))===!0,Ve=async()=>{try{let n=await _();if(b(n)||E(n)!==null||F(n)?.checkType!=="population_registry")return;if(!le(n)&&H(P(n,"population_registry"))===void 0&&(n=await v()),!le(n)){ue=!0;return}await O(),await Y(await de(),"population_registry");let c=f===null?void 0:P(f,"population_registry");if(c?.state==="input_required"&&c.reason==="registry_unavailable"&&U(c)>0){if(await u(We),d)return;await Y(await de(),"population_registry")}}catch(n){if(n instanceof j&&(n.code==="check_not_active"||n.code==="step_not_on_path")){await v().catch(()=>{});return}ce=!0;return}f!==null&&b(f)&&J(D(f,{autoRetry:o}))},pe=()=>(ae??(ae=Ve()),ae),De=async()=>{let c=(await _()).turnstileSiteKey;return c===null?{sandbox:!0}:{channel:"hosted_web",siteKey:c,turnstileToken:await h(c,{signal:R.signal})}},k=null,fe=Promise.resolve(),T=0,He=async()=>{let n=await _();for(let c=0;c<Qe&&!d&&!b(n)&&F(n)===void 0&&L(n).some(l=>l.state==="processing")&&(await u(Je),!d);c+=1)n=await v();return n},Ne=async(n,c,l)=>{let{capture:g}=n,C=()=>d,N=()=>n.alive&&n.attempt===l,he=y=>{N()&&g.setFlowState(y)},A=y=>{if(!C()&&(J(y),!!N())){if(y.status==="retry"&&r==="auto"){g.handle.retry();return}g.setFlowState("done")}};if(c.degraded==="NO_RECORDER"){let y=f?.sessionId??(await _().catch(()=>null))?.sessionId??"";A(w(y,"no_recorder"));return}he("uploading");try{if(await pe(),C())return;let y=await _(),ye;if(!b(y)&&E(y)!==null){await se(!1),A(w(y.sessionId,"method_required"));return}if(!b(y)){if(F(y)?.checkType==="population_registry"){A(w(y.sessionId,ue?"nni_unbound":ce?"network":"registry_unavailable"));return}if(await O(),C())return;ye=f??y;let Q=await xe({...W,artifacts:c,getAttestation:De,getView:()=>f??y,refreshView:v,applySubmit:Y,onPhase:he,isCancelled:C,onKeyframePromoted:Ye=>{p=Ye}});if(C())return;if(Q.kind==="unavailable"){A(w(y.sessionId,Q.reason));return}if(Q.kind==="resync"&&await v(),f!==null&&E(f)!==null){await se(!1),A(w(y.sessionId,"method_required"));return}y=await He()}A(D(y,{autoRetry:o,previous:ye}))}catch{if(C())return;A(w(f?.sessionId??"","network"))}},Le=(n,c)=>{let l=n.attempt;T>0&&n.alive&&n.capture.setFlowState("uploading"),T+=1,fe=fe.then(()=>Ne(n,c,l)).finally(()=>{T-=1,T===0&&m?.onChainIdle()}).catch(()=>{})},me=n=>{k?.capture.handle.destroy(),k!==null&&(k.alive=!1);let c=Ce(n,m?.captureInternals?.(n)??t.capture,()=>f?.capture?.liveness?.keyframe?.rank===!0,()=>X(f),()=>f?.capture?.liveness?.screenRamp),l={capture:c,alive:!0,attempt:0};k=l,c.handle.on("state",C=>{C==="starting"&&(l.attempt+=1)}),c.handle.on("captured",C=>{Promise.resolve().then(()=>Le(l,C))});let g=c.handle;return{get state(){return g.state},get captureMode(){return g.captureMode},get facingMode(){return g.facingMode},on:(C,N)=>g.on(C,N),start:async C=>{if(f===null&&await _().catch(()=>{}),!!l.alive)return g.start(C)},retry:()=>g.retry(),switchCamera:()=>g.switchCamera(),destroy:()=>{l.alive=!1,k===l&&(k=null),g.destroy()}}},Ue=async()=>{if(d)return null;try{let n=await _();return d?null:E(n)}catch{return null}},Be=async()=>{if(d)return"self";try{let n=await _();return d?"self":X(n)}catch{return"self"}},Fe=async()=>{if(d)return!1;try{let n=await _();if(d||b(n))return!1;let c=P(n,"liveness");return B(c)&&c?.requiresMobile===!0&&!$()}catch{return!1}},Ge=async()=>{if(d)return!1;try{let n=await _();return!d&&n.returning===!0}catch{return!1}},Ke=async n=>{let c=(await _()).plan?.choice,l=c?.options.find(C=>V[C.service]===n);if(!l)throw new RangeError(`method ${String(n)} is not offered`);let g=await a.choose(c.nodeId,l.id);d||x(g)},Se=null,qe=()=>(Se??(Se=import("./plan-runner-RVVF5DJV.js").then(n=>{let c=n.createPlanRunner({runtime:W,currentView:()=>f,ensureView:_,refreshView:v,ensureConsent:()=>O(),liveness:me,chainBusy:()=>T>0,destroyed:()=>d,sleep:u,isMobile:$,now:t.now??Date.now,keptFaceKey:()=>p,setView:x,baseCapture:t.capture,emitStep:l=>{d||S.emit("step",l)},emitResult:Te,documentInternals:t.document,portraitInternals:t.portrait,livePhotoInternals:t.livePhoto});return m=c,c})),Se);return{consent:()=>O(),startRegistry:pe,methodChoice:Ue,selectMethod:Ke,reportCameraUnavailable:async n=>{await O();let c=a.reportCameraUnavailable;if(c===void 0)throw new TypeError("this client cannot report a missing camera");let l=await c.call(a,n).catch(g=>{if(g instanceof j&&g.code==="check_out_of_order")return a.getSession();throw g});d||x(l)},mobileRequired:Fe,captureMode:Be,returning:Ge,liveness:me,run:async()=>{if(d)throw new Error("verification destroyed");return(await qe()).run()},currentStep:()=>m?.current()??null,voiceClips:async()=>{if(d)return null;try{let n=await _();return d?null:n.voice??null}catch{return null}},on:(n,c)=>S.on(n,c),destroy:()=>{d=!0,R.abort(),m?.destroy(),k!==null&&(k.alive=!1,k.capture.handle.destroy(),k=null),S.clear()}}}var Ie=["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 ze=["carte_identite","passport","residence_permit"];function et(e,t){let i=e.byIssuer?.[t]??e.default;return ze.filter(o=>i==="*"||i.includes(o))}function Nt(e,t=Ie){return[...new Set([...t,...Object.keys(e.byIssuer??{})])].filter(o=>et(e,o).length>0).sort()}function Re(e){if(e.acceptedDocuments)return e.acceptedDocuments;let t=e.acceptedDocumentTypes?.length?[...e.acceptedDocumentTypes]:["carte_identite","passport"];return{default:[],byIssuer:{MR:t}}}function Lt(e){return/^[A-Z]{2}$/.test(e)?String.fromCodePoint(...[...e].map(t=>127462+t.charCodeAt(0)-65)):""}var Yt=["national_number","document_photo","national_eid"],tt=new Set(["phone_otp","email_otp","national_eid","document","nfc","population_registry","supplied_identity","summary_confirm","liveness","face_match","aml_screening","face_dedup","age_estimation"]),nt=new Set(["supplied_identity","aml_screening","face_dedup","age_estimation"]),ee=["document","population_registry","national_eid"],te=["phone_otp","email_otp"],we={identity_method:ee,contact:te},it=["population_registry","document"],Oe="platform_unsupported",ot=new Set(["prefilled","user_entered","prefilled_or_entered"]),rt={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??rt[e.checkType]??null}function st(e,t){let i=e.plan?.choice;if(i===void 0||i.locked)return;let o=i.options.find(r=>r.id!==i.selected&&r.available!==!1&&t.includes(r.service));return o===void 0?void 0:{nodeId:i.nodeId,option:o}}function ne(e){let t=e.plan,i=t?.choice;if(t===void 0||i===void 0||i.locked||t.current===null||t.current===i.nodeId||b(e))return null;let o=we[i.kind]??[...ee,...te],r=i.options.flatMap(s=>s.available===!1||!o.includes(s.service)?[]:[s.nationalEid!=null?{id:s.id,service:s.service,nationalEid:s.nationalEid}:{id:s.id,service:s.service}]),a=t.steps.find(s=>s.id===t.current)?.service,u=i.selected??r.find(s=>s.service===a)?.id??null;return r.some(s=>s.id!==u)?{nodeId:i.nodeId,kind:i.kind,current:u,options:r}:null}function Ee(e){return e==null?[]:e.options.filter(t=>t.id!==e.current)}function at(e){let t=(e.plan?.sections??[]).map(r=>({id:r.id,state:r.state})),i={sessionId:e.sessionId,orgName:e.orgName,returning:e.returning===!0,consentRecorded:e.consentRecorded,expiresAt:e.expiresAt,sections:t.map(r=>r.id),progress:t,purpose:e.purpose??"identity"};e.branding!==void 0&&(i.branding=e.branding),e.cameraUnavailableHandled===!0&&(i.cameraUnavailableHandled=!0);let o=ne(e);return o!==null&&(i.switchable=o),i}function ct(e){let t={attemptsRemaining:U(e),attemptsExhausted:e.attemptsExhausted===!0};return e.reason!==void 0&&(t.reason=e.reason),e.retakeHint!==void 0&&(t.retakeHint=e.retakeHint),t}var Me={phone_otp:"phone",email_otp:"email"};function ut(e,t){let i=st(e,[t==="phone_otp"?"email_otp":"phone_otp"]);return i===void 0?void 0:Me[i.option.service]}function dt(e,t,i,o){let r=t.checkType==="email_otp",a=(r?t.emailOtp:t.otp)??{},u=r?t.emailOtp?.emailSource:t.otp?.numberSource,s=u!==void 0&&ot.has(u)?u:r?"prefilled_or_entered":"user_entered",h=typeof a.sentToMasked=="string"&&a.sentToMasked.length>0,S=ut(e,r?"email_otp":"phone_otp"),m={key:t.checkType,context:i,section:I(t),phase:h?"verify":"send",canSwitch:S!==void 0,...o},p=r?{kind:"email_otp",...m,emailSource:s,needsEmail:s!=="prefilled"}:{kind:"phone_otp",...m,numberSource:s,needsPhone:s!=="prefilled",channels:(t.otp?.channels??[]).filter(d=>d==="whatsapp"||d==="sms")};return S!==void 0&&(p.switchChannel=S),h&&(p.sentToMasked=a.sentToMasked),!r&&t.otp?.channel!==void 0&&(p.channel=t.otp.channel),!r&&Array.isArray(t.phoneCountries)&&(p.phoneCountries=t.phoneCountries.filter(d=>typeof d=="string"&&/^[A-Z]{2}$/.test(d))),a.expiresAt!==void 0&&(p.codeExpiresAt=a.expiresAt),a.resendAvailableAt!==void 0&&(p.resendAvailableAt=a.resendAvailableAt),p}function lt(e,t,i,o){let r=K(e)===!0?"bound":H(t)===!0?"document":"typed",a=r==="typed"&&t.state==="input_required"&&t.reason!==void 0&&ke(t.reason)==="id_number_recheck",u=Ee(ne(e)),s=!o.attemptsExhausted&&u.length===1&&u[0]?.service==="document";return{kind:"registry",key:"registry",context:i,section:I(t),state:t.state==="input_required"?"input_required":"pending",source:r,recheck:a,canUseDocument:s,...o}}function pt(e,t,i,o){let r=[...t.acceptedSides??[]];return{kind:"document",key:"document",context:i,section:I(t),side:r.includes("recto")?"verso":"recto",acceptedSides:r,documents:Re(e),...o}}function ft(e){let t=P(e,"liveness");return t?.state==="passed"||t?.state==="review"}function Ae(e,t,i,o,r){let a=t.icao?.report;return{kind:"portrait",key:`portrait:${r}`,context:i,section:I(t),phase:r,report:Array.isArray(a)?a:null,review:t.state==="review",tuning:e.capture?.icao??null,tuningVersion:e.capture?.tuningVersion??null,icao:G(e),retakeOnly:r==="capture"&&t.state==="input_required"&&e.capture?.livePhoto?.oneCapture===!0&&ft(e),...o}}var z={minLongSidePx:1280,jpegQuality:.95};function mt(e,t){let i=e.capture?.livePhoto;if(i?.oneCapture!==!0)return null;let o=P(e,"portrait_icao"),r=i.still??z;return{icao:t==="liveness"&&G(e)!==null&&o!==void 0&&o.state==="pending"&&o.reason===void 0,still:{minLongSidePx:r.minLongSidePx??z.minLongSidePx,jpegQuality:r.jpegQuality??z.jpegQuality}}}function St(e,t,i,o){let r=t.eid,a=I(t);if(r===void 0||r.challenge!=="app_code")return{kind:"unsupported",key:"unsupported:eid_auth",context:i,section:a,checkType:"eid_auth",reason:"update_required"};let u=Ee(ne(e)),s=u.length===1&&it.includes(u[0]?.service??"")?u[0]:void 0,h=s===void 0?void 0:V[s.service],S=h!==void 0,m={kind:"eid",key:"eid",context:i,section:a,provider:r.provider,providerName:r.providerName,country:r.country,challenge:"app_code",phase:r.awaiting==="code"?"code":"identifier",identifierBound:r.identifierBound===!0,canUseCamera:S,afterPass:r.afterPass==="continue"?"continue":"end",...o};return S&&(m.cameraMethod=h),r.expiresAt!==void 0&&(m.codeExpiresAt=r.expiresAt),r.resendAvailableAt!==void 0&&(m.resendAvailableAt=r.resendAvailableAt),r.resendsRemaining!==void 0&&(m.resendsRemaining=r.resendsRemaining),r.codeAttemptsRemaining!==void 0&&(m.codeAttemptsRemaining=r.codeAttemptsRemaining),m}function ht(e,t){if(t.checkType!=="face_match"||t.reason!==void 0)return null;let i=P(e,"portrait_icao");return i!==void 0&&(i.state==="passed"||i.state==="review")?i:null}function yt(e){return L(e).filter(t=>t.state==="failed").pop()?.attemptsExhausted===!0}function gt(e,t){let i=e.failureReason,o;i===Oe?o="platform_unsupported":e.status==="expired"?o="expired":e.status==="review_pending"?o="review":e.status==="completed"&&e.outcome==="approved"?o="approved":e.status==="completed"&&e.outcome==="review"?o="review":i==="device_cooldown"?o="cooldown":i!==void 0?o="policy_stop":yt(e)?o="attempts_exhausted":o="rejected";let r=o==="platform_unsupported"?{sessionId:e.sessionId,status:"unavailable"}:D(e,{autoRetry:!1}),a={kind:"result",key:"result",context:t,section:null,display:o,result:r};return i!==void 0&&(a.failureReason=i),e.retryAfter!==void 0&&(a.retryAfter=e.retryAfter),a}function Ct(e,t,i){let o=e.identitySummary;if(o==null)return null;let r={kind:"identity_summary",key:"identity_summary",context:t,section:i??"identity",summaryKind:o.kind==="partial"?"partial":o.kind??"full",source:o.source,portraitAvailable:o.portrait?.available===!0,retakeAvailable:o.retakeAvailable===!0};for(let u of _t){let s=o[u];typeof s=="string"&&s!==""&&(r[u]=s)}let a=ve(o);return a!==void 0&&(r.idNumberMasked=a,r.nniMasked=a),r}var _t=["fullName","birthDate","birthYear","nationality","documentType","documentNumberMasked","expiryDate","retakeTarget"];function M(e,t,i,o){return{kind:"unsupported",key:`unsupported:${i}`,context:e,section:t,checkType:i,reason:o}}function kt(e){return e.kind==="contact"?"contact":(e.kind==="identity_method","identity")}function bt(e,t){let i=we[e.kind]??[...ee,...te],o=kt(e),r=e.options.flatMap(u=>{if(u.available===!1||!i.includes(u.service))return[];let s={id:u.id,service:u.service};return u.nationalEid!=null&&(s.nationalEid=u.nationalEid),[s]});if(r.length===0){let u=e.options.length>0&&e.options.every(s=>s.service==="nfc");return M(t,o,"choice",u?"platform_unsupported":"update_required")}let a={nodeId:e.nodeId,kind:e.kind,selected:e.selected,options:r};if(e.kind==="identity_method"){let u={kind:"method",key:"method",context:t,section:o,options:r.map(h=>V[h.service]),choice:a},s=r.find(h=>h.nationalEid!==void 0)?.nationalEid;return s!==void 0&&(u.nationalEid=s),u}return e.kind==="contact"?{kind:"contact_choice",key:"contact_choice",context:t,section:o,options:r.map(u=>Me[u.service]),selected:null,locked:!1,choice:a}:{kind:"choice",key:`choice:${e.nodeId}`,context:t,section:o,choice:a}}function Zt(e,t={}){let i=at(e);if(b(e)||e.failureReason===Oe)return gt(e,i);let o=e.plan;if(o===void 0||!Array.isArray(o.sections))return M(i,null,"plan","update_required");let r=be(e);if(r!==null)return bt(r,i);let a=o.current===null?void 0:o.steps.find(p=>p.id===o.current),u=p=>{let d={kind:"processing",key:"processing",context:i,section:p!==void 0?I(p):o.sections.find(R=>R.state==="current")?.id??null,stalled:!1};return typeof p?.service=="string"&&p.service!==""&&(d.service=p.service),d};if(o.current===null)return u(o.steps.find(p=>p.state==="processing"));if(a===void 0)return M(i,null,"step","update_required");if(!tt.has(a.service))return a.interaction==="server"?u(a):M(i,I(a),a.service,"update_required");if(nt.has(a.service)||!B(a))return u(a);let s=a,h=ct(s),S=s.checkType,m=I(s);switch(S){case"phone_otp":case"email_otp":return dt(e,s,i,h);case"population_registry":return lt(e,s,i,h);case"eid_auth":return St(e,s,i,h);case"doc_ocr":return pt(e,s,i,h);case"identity_confirm":return Ct(e,i,m)??u(s);case"portrait_icao":return Ae(e,s,i,h,"capture");case"liveness":case"face_match":{let p=ht(e,s);if(p!==null)return Ae(e,p,i,h,"match");let d=s.requiresMobile===!0,R=G(e);return d&&t.isMobile===!1?{kind:"mobile_required",key:"mobile_required",context:i,section:m,checkType:S}:{kind:"liveness",key:"biometric",context:i,section:m,mode:S==="face_match"?"selfie":"liveness",requiresMobile:d,instructions:R===null?"standard":"icao",icao:R,livePhoto:mt(e,S),...h}}case"nfc_chip":return M(i,m,S,"platform_unsupported");default:return M(i,m,S,"update_required")}}export{Ze as a,We as b,Je as c,Qe as d,je as e,Tt as f,Xe as g,Ie as h,ze as i,et as j,Nt as k,Re as l,Lt as m,Yt as n,Oe as o,I as p,ne as q,Ee as r,ht as s,Zt as t};
@@ -0,0 +1 @@
1
+ import{d as K,e as pe,f as me,g as fe,i as he,j as X,l as Q,n as Se,o as ge,v as ye,x as T,y as Z}from"./chunk-UBDG5IAP.js";import{c as de,d as ue,e as le}from"./chunk-FPXL63KZ.js";import{c as F,g as q,h as be}from"./chunk-57VOMVKM.js";var _e=["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 Ue=["carte_identite","passport","residence_permit"];function Fe(e,t){let i=e.byIssuer?.[t]??e.default;return Ue.filter(r=>i==="*"||i.includes(r))}function Tt(e,t=_e){return[...new Set([...t,...Object.keys(e.byIssuer??{})])].filter(r=>Fe(e,r).length>0).sort()}function Ce(e){if(e.acceptedDocuments)return e.acceptedDocuments;let t=e.acceptedDocumentTypes?.length?[...e.acceptedDocumentTypes]:["carte_identite","passport"];return{default:[],byIssuer:{MR:t}}}var Ke=640,Ze=new Set(["network_error","timeout","upload_failed","unknown_error","rate_limit_exceeded"]),ke=6,Pe=1500,Me={sharpness:1,exposure:1,meanLuma:128},Re=null;function Ye(e,t){try{Re??(Re=document.createElement("canvas"));let i=Re,r=96/Math.max(1,t.width);i.width=Math.max(1,Math.round(t.width*r)),i.height=Math.max(1,Math.round(t.height*r));let s=i.getContext("2d");if(s===null)return Me;s.drawImage(e,t.x,t.y,t.width,t.height,0,0,i.width,i.height);let d=s.getImageData(0,0,i.width,i.height);return{sharpness:ue(d),exposure:le(d),meanLuma:de(d)}}catch{return Me}}async function je(e,t){let i=e.source;return"convertToBlob"in i?i.convertToBlob({type:"image/jpeg",quality:t}):new Promise((r,s)=>{i.toBlob(d=>d===null?s(new Error("encode failed")):r(d),"image/jpeg",t)})}function Lt(e,t={}){let i=t.now??(()=>performance.now()),r=t.setTimer??((l,n)=>setTimeout(l,n)),s=t.clearTimer??(l=>clearTimeout(l)),d=t.encode??je,p=t.quality??Ye,c=e.tuningVersion??null,_=new Set,C=!1,b=e.video??null,S=null,g=t.grabFrame??null,E=null,x=1e3/ke,P=null,R=null,L=!1,O=!1,A=Number.NEGATIVE_INFINITY,M=null,H=0,N=null,V=null,D=Promise.all([import("./icao-gate-PWBMKRGC.js"),import("./icao-tuning-4GGVX6B4.js"),import("./create-portrait-capture-C462EIB6.js"),import("./landmarker-KB7LVXAU.js"),import("./background-monitor-A7FKJOAG.js")]).then(async([l,n,o,a,u])=>{let f=n.resolveIcaoTuning(e.tuning,e.tuningVersion??void 0);f.background.required&&(R=u.createBackgroundMonitor({tuning:f.backgroundCheck,assetBaseUrl:e.assetBaseUrl??"/models-v3",...t.createSegmenter!==void 0?{createSegmenter:t.createSegmenter}:{},now:i})),S=l.createIcaoGate(f,{policy:e.policy??"reject"}),g??(g=o.defaultGrabber()),E=o.observe,x=1e3/Math.min(ke,f.cadenceHz);let y=(t.createLandmarker??a.createFaceLandmarker)(e.assetBaseUrl??"/models-v3"),h=await new Promise((m,k)=>{let I=setTimeout(()=>{k(new Error("landmarker init timeout")),y.then(v=>v.close(),()=>{})},a.LANDMARKER_INIT_TIMEOUT_MS);y.then(v=>{clearTimeout(I),m(v)},v=>{clearTimeout(I),k(v)})});C?h.close():P=h}).catch(()=>{L=!0}),Y=l=>{for(let n of _)n({holding:O||L,update:l})},B=()=>{if(M=null,!(C||P===null||S===null||g===null||E===null||b===null)){if(i()-A>Pe){Y(null);return}try{let l=g(b,Ke);if(l!==null){let n=Math.max(i(),H+1);H=n;let o=P.detect(l.source,n),a=b.videoWidth||l.width,u=b.videoHeight||l.height,f=E(o,l,a,u);f.geometry!==null&&R!==null&&(f.backgroundCheck=R.measure(l,f.geometry.box,a,u));let y=S.push(f,i());O=y.ready,Y(y)}}catch{}M=r(B,x)}},j=()=>{let l=i()-A>Pe;A=i(),l&&(S?.reset(),O=!1,N=null,V=null),M===null&&P!==null&&!C&&(M=r(B,0))},$=()=>{let l=g===null||b===null?null:g(b,null);if(l===null||S===null||Math.max(l.width,l.height)<e.still.minLongSidePx)return Promise.resolve(null);let n=S.summary();return d(l,e.still.jpegQuality).then(o=>({image:o,width:l.width,height:l.height,gate:n}),()=>null)},W=null;return{engineOptions:{measureQuality:(l,n)=>{b=l,j();let o=p(l,n);return O||L?o:{...o,sharpness:0}},telemetry:l=>{if(l.type!=="fired"||C)return;N=$();let n=W;n!==null&&N.then(o=>o===null?void 0:n(o).catch(()=>{})),O=!1,M!==null&&s(M),M=null,A=Number.NEGATIVE_INFINITY}},decorate:l=>{let n=new WeakMap,o=new Map,a=h=>{let m=n.get(h);return m===void 0&&(m=(async()=>{let k=await ge(l,"image","image/jpeg",h.image.size,{engine:"portrait"});return await l.uploadToSpaces(k.uploadUrl,h.image,"image/jpeg"),(await l.completeMedia(k.key)).key})(),m.catch(()=>n.delete(h)),n.set(h,m)),m};W=a;let u=async h=>{let m;try{m=await a(h)}catch(k){let I=k?.code;if(typeof I=="string"&&Ze.has(I))throw k;return null}return{media:{portrait:m},gate:be(h.gate),...c!==null?{tuningVersion:c}:{}}},f=l.submitCheck.bind(l),y=(async(h,m,k)=>{if(h!=="liveness")return f(h,m,k);let I=k?.idempotencyKey,v=I===void 0?void 0:o.get(I);if(v===void 0){let ae=N;v=ae===null?Promise.resolve(null):ae.then(ce=>ce===null?null:u(ce)),I!==void 0&&(o.set(I,v),v.catch(()=>o.delete(I)))}let z=await v;if(z===null)return f("liveness",m,k);let Be=await f("liveness",{...m,portraitIcao:z},k);return V=z,Be});return new Proxy(l,{get(h,m){if(m==="submitCheck")return y;let k=Reflect.get(h,m);return typeof k=="function"?k.bind(h):k}})},onGate:l=>(_.add(l),()=>_.delete(l)),lastPortraitInput:()=>V,destroy:()=>{C=!0,N=null,V=null,M!==null&&s(M),M=null,_.clear(),D.then(()=>{P?.close(),P=null,R?.close(),R=null})}}}function Ee(e){return e.idNumberBound??e.nniBound}function Ae(e){return e===void 0?void 0:e.idNumberFromDocument??e.nniFromDocument}function Ie(e){let t=e.idNumberMasked??e.nniMasked;return typeof t=="string"&&t!==""?t:void 0}var ve=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"}),We=new Map(Object.entries(ve)),Gt=new Map(Object.entries(ve).map(([e,t])=>[t,e]));function Te(e){return We.get(e)??e}var Qe=new Set(["phone_otp","email_otp","national_eid","document","nfc","population_registry","supplied_identity","summary_confirm","liveness","face_match","aml_screening","face_dedup","age_estimation"]),qe=new Set(["supplied_identity","aml_screening","face_dedup","age_estimation"]),te=["document","population_registry","national_eid"],ne=["phone_otp","email_otp"],we={identity_method:te,contact:ne},Je=["population_registry","document"],xe="platform_unsupported",$e=new Set(["prefilled","user_entered","prefilled_or_entered"]),ze={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 w(e){return e.section??ze[e.checkType]??null}function ie(e,t){let i=e.plan?.choice;if(i===void 0||i.locked)return;let r=i.options.find(s=>s.id!==i.selected&&s.available!==!1&&t.includes(s.service));return r===void 0?void 0:{nodeId:i.nodeId,option:r}}function oe(e){let t=e.plan,i=t?.choice;if(t===void 0||i===void 0||i.locked||t.current===null||t.current===i.nodeId||X(e))return null;let r=we[i.kind]??[...te,...ne],s=i.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}]),d=t.steps.find(c=>c.id===t.current)?.service,p=i.selected??s.find(c=>c.service===d)?.id??null;return s.some(c=>c.id!==p)?{nodeId:i.nodeId,kind:i.kind,current:p,options:s}:null}function Ne(e){return e==null?[]:e.options.filter(t=>t.id!==e.current)}function Xe(e){let t=(e.plan?.sections??[]).map(s=>({id:s.id,state:s.state})),i={sessionId: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&&(i.branding=e.branding),e.cameraUnavailableHandled===!0&&(i.cameraUnavailableHandled=!0);let r=oe(e);return r!==null&&(i.switchable=r),i}function et(e){let t={attemptsRemaining:me(e),attemptsExhausted:e.attemptsExhausted===!0};return e.reason!==void 0&&(t.reason=e.reason),e.retakeHint!==void 0&&(t.retakeHint=e.retakeHint),t}var Le={phone_otp:"phone",email_otp:"email"};function tt(e,t){let i=ie(e,[t==="phone_otp"?"email_otp":"phone_otp"]);return i===void 0?void 0:Le[i.option.service]}function nt(e,t,i,r){let s=t.checkType==="email_otp",d=(s?t.emailOtp:t.otp)??{},p=s?t.emailOtp?.emailSource:t.otp?.numberSource,c=p!==void 0&&$e.has(p)?p:s?"prefilled_or_entered":"user_entered",_=typeof d.sentToMasked=="string"&&d.sentToMasked.length>0,C=tt(e,s?"email_otp":"phone_otp"),b={key:t.checkType,context:i,section:w(t),phase:_?"verify":"send",canSwitch:C!==void 0,...r},S=s?{kind:"email_otp",...b,emailSource:c,needsEmail:c!=="prefilled"}:{kind:"phone_otp",...b,numberSource:c,needsPhone:c!=="prefilled",channels:(t.otp?.channels??[]).filter(g=>g==="whatsapp"||g==="sms")};return C!==void 0&&(S.switchChannel=C),_&&(S.sentToMasked=d.sentToMasked),!s&&t.otp?.channel!==void 0&&(S.channel=t.otp.channel),!s&&Array.isArray(t.phoneCountries)&&(S.phoneCountries=t.phoneCountries.filter(g=>typeof g=="string"&&/^[A-Z]{2}$/.test(g))),d.expiresAt!==void 0&&(S.codeExpiresAt=d.expiresAt),d.resendAvailableAt!==void 0&&(S.resendAvailableAt=d.resendAvailableAt),S}function it(e,t,i,r){let s=Ee(e)===!0?"bound":Ae(t)===!0?"document":"typed",d=s==="typed"&&t.state==="input_required"&&t.reason!==void 0&&Te(t.reason)==="id_number_recheck",p=Ne(oe(e)),c=!r.attemptsExhausted&&p.length===1&&p[0]?.service==="document";return{kind:"registry",key:"registry",context:i,section:w(t),state:t.state==="input_required"?"input_required":"pending",source:s,recheck:d,canUseDocument:c,...r}}function ot(e,t,i,r){let s=[...t.acceptedSides??[]];return{kind:"document",key:"document",context:i,section:w(t),side:s.includes("recto")?"verso":"recto",acceptedSides:s,documents:Ce(e),...r}}function rt(e){let t=Q(e,"liveness");return t?.state==="passed"||t?.state==="review"}function Oe(e,t,i,r,s){let d=t.icao?.report;return{kind:"portrait",key:`portrait:${s}`,context:i,section:w(t),phase:s,report:Array.isArray(d)?d:null,review:t.state==="review",tuning:e.capture?.icao??null,tuningVersion:e.capture?.tuningVersion??null,icao:q(e),retakeOnly:s==="capture"&&t.state==="input_required"&&e.capture?.livePhoto?.oneCapture===!0&&rt(e),...r}}var ee={minLongSidePx:1280,jpegQuality:.95};function st(e,t){let i=e.capture?.livePhoto;if(i?.oneCapture!==!0)return null;let r=Q(e,"portrait_icao"),s=i.still??ee;return{icao:t==="liveness"&&q(e)!==null&&r!==void 0&&r.state==="pending"&&r.reason===void 0,still:{minLongSidePx:s.minLongSidePx??ee.minLongSidePx,jpegQuality:s.jpegQuality??ee.jpegQuality}}}function at(e,t,i,r){let s=t.eid,d=w(t);if(s===void 0||s.challenge!=="app_code")return{kind:"unsupported",key:"unsupported:eid_auth",context:i,section:d,checkType:"eid_auth",reason:"update_required"};let p=Ne(oe(e)),c=p.length===1&&Je.includes(p[0]?.service??"")?p[0]:void 0,_=c===void 0?void 0:K[c.service],C=_!==void 0,b={kind:"eid",key:"eid",context:i,section:d,provider:s.provider,providerName:s.providerName,country:s.country,challenge:"app_code",phase:s.awaiting==="code"?"code":"identifier",identifierBound:s.identifierBound===!0,canUseCamera:C,afterPass:s.afterPass==="continue"?"continue":"end",...r};return C&&(b.cameraMethod=_),s.expiresAt!==void 0&&(b.codeExpiresAt=s.expiresAt),s.resendAvailableAt!==void 0&&(b.resendAvailableAt=s.resendAvailableAt),s.resendsRemaining!==void 0&&(b.resendsRemaining=s.resendsRemaining),s.codeAttemptsRemaining!==void 0&&(b.codeAttemptsRemaining=s.codeAttemptsRemaining),b}function ct(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}function dt(e){return pe(e).filter(t=>t.state==="failed").pop()?.attemptsExhausted===!0}function ut(e,t){let i=e.failureReason,r;i===xe?r="platform_unsupported":e.status==="expired"?r="expired":e.status==="review_pending"?r="review":e.status==="completed"&&e.outcome==="approved"?r="approved":e.status==="completed"&&e.outcome==="review"?r="review":i==="device_cooldown"?r="cooldown":i!==void 0?r="policy_stop":dt(e)?r="attempts_exhausted":r="rejected";let s=r==="platform_unsupported"?{sessionId:e.sessionId,status:"unavailable"}:Se(e,{autoRetry:!1}),d={kind:"result",key:"result",context:t,section:null,display:r,result:s};return i!==void 0&&(d.failureReason=i),e.retryAfter!==void 0&&(d.retryAfter=e.retryAfter),d}function lt(e,t,i){let r=e.identitySummary;if(r==null)return null;let s={kind:"identity_summary",key:"identity_summary",context:t,section:i??"identity",summaryKind:r.kind==="partial"?"partial":r.kind??"full",source:r.source,portraitAvailable:r.portrait?.available===!0,retakeAvailable:r.retakeAvailable===!0};for(let p of pt){let c=r[p];typeof c=="string"&&c!==""&&(s[p]=c)}let d=Ie(r);return d!==void 0&&(s.idNumberMasked=d,s.nniMasked=d),s}var pt=["fullName","birthDate","birthYear","nationality","documentType","documentNumberMasked","expiryDate","retakeTarget"];function G(e,t,i,r){return{kind:"unsupported",key:`unsupported:${i}`,context:e,section:t,checkType:i,reason:r}}function mt(e){return e.kind==="contact"?"contact":(e.kind==="identity_method","identity")}function ft(e,t){let i=we[e.kind]??[...te,...ne],r=mt(e),s=e.options.flatMap(p=>{if(p.available===!1||!i.includes(p.service))return[];let c={id:p.id,service:p.service};return p.nationalEid!=null&&(c.nationalEid=p.nationalEid),[c]});if(s.length===0){let p=e.options.length>0&&e.options.every(c=>c.service==="nfc");return G(t,r,"choice",p?"platform_unsupported":"update_required")}let d={nodeId:e.nodeId,kind:e.kind,selected:e.selected,options:s};if(e.kind==="identity_method"){let p={kind:"method",key:"method",context:t,section:r,options:s.map(_=>K[_.service]),choice:d},c=s.find(_=>_.nationalEid!==void 0)?.nationalEid;return c!==void 0&&(p.nationalEid=c),p}return e.kind==="contact"?{kind:"contact_choice",key:"contact_choice",context:t,section:r,options:s.map(p=>Le[p.service]),selected:null,locked:!1,choice:d}:{kind:"choice",key:`choice:${e.nodeId}`,context:t,section:r,choice:d}}function J(e,t={}){let i=Xe(e);if(X(e)||e.failureReason===xe)return ut(e,i);let r=e.plan;if(r===void 0||!Array.isArray(r.sections))return G(i,null,"plan","update_required");let s=fe(e);if(s!==null)return ft(s,i);let d=r.current===null?void 0:r.steps.find(S=>S.id===r.current),p=S=>{let g={kind:"processing",key:"processing",context:i,section:S!==void 0?w(S):r.sections.find(E=>E.state==="current")?.id??null,stalled:!1};return typeof S?.service=="string"&&S.service!==""&&(g.service=S.service),g};if(r.current===null)return p(r.steps.find(S=>S.state==="processing"));if(d===void 0)return G(i,null,"step","update_required");if(!Qe.has(d.service))return d.interaction==="server"?p(d):G(i,w(d),d.service,"update_required");if(qe.has(d.service)||!he(d))return p(d);let c=d,_=et(c),C=c.checkType,b=w(c);switch(C){case"phone_otp":case"email_otp":return nt(e,c,i,_);case"population_registry":return it(e,c,i,_);case"eid_auth":return at(e,c,i,_);case"doc_ocr":return ot(e,c,i,_);case"identity_confirm":return lt(e,i,b)??p(c);case"portrait_icao":return Oe(e,c,i,_,"capture");case"liveness":case"face_match":{let S=ct(e,c);if(S!==null)return Oe(e,S,i,_,"match");let g=c.requiresMobile===!0,E=q(e);return g&&t.isMobile===!1?{kind:"mobile_required",key:"mobile_required",context:i,section:b,checkType:C}:{kind:"liveness",key:"biometric",context:i,section:b,mode:C==="face_match"?"selfie":"liveness",requiresMobile:g,instructions:E===null?"standard":"icao",icao:E,livePhoto:st(e,C),..._}}case"nfc_chip":return G(i,b,C,"platform_unsupported");default:return G(i,b,C,"update_required")}}var ht=/^[A-Z0-9][A-Z0-9 -]{0,39}$/,St=Object.freeze({normalize:e=>e.trim().toUpperCase().replace(/\s+/g," "),check:e=>ht.test(e),registrySources:Object.freeze([]),describe:"number must be 1 to 40 letters, digits, spaces or hyphens"});function gt(e){return typeof e=="string"&&/^\d{10}$/.test(e)&&Number(e)%97===1}var yt=Object.freeze({normalize:e=>e.trim(),check:e=>gt(e),registrySources:Object.freeze(["MR.anrpts"]),describe:"number must be the 10-digit Mauritanian national ID number with a valid check digit"}),bt=Object.freeze({"MR:national_id":yt});function re(e,t){return bt[`${e.toUpperCase()}:${t}`]??St}var _t=Object.freeze({MRT:"MR"});function Ve(e,t){let i=e.trim().toUpperCase();return re(_t[i]??i,t)}function De(e){let t=Ve(e.issuingCountry,e.type);return t.check(t.normalize(e.number))}function Ge(e){return re("MR","national_id").check(e)}function se(e){let t="";for(let i of e){let r=i.codePointAt(0)??0;r>=1632&&r<=1641?t+=String(r-1632):r>=1776&&r<=1785?t+=String(r-1776):i!==" "&&i!=="-"&&i!==" "&&(t+=i)}return t}var Ct=[1e3,2e3,4e3,8e3,15e3],kt=3e4,Pt=/^\+[1-9]\d{7,14}$/,Mt=/^\d{6}$/,Rt=/^\d{6}$/,Et=/^[^\s@]+@[^\s@]+\.[^\s@]+$/,He=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"]),At=new Set(["network_error","timeout","upload_failed","unknown_error","rate_limit_exceeded"]);function tn(e){let t=!1,i=null,r="",s=!1,d=!1,p=!1,c={},_={},C=new Set,b=!1,S=null,g="idle",E=new Map,x=new Map,P=(n,o,a)=>{let u=`${n}.${o}`,f=E.get(u);if(f!==void 0)return f;let y=x.get(n),h=(y===void 0?a():y.then(a)).finally(()=>{E.delete(u)});E.set(u,h);let m=h.then(()=>{},()=>{});return x.set(n,m),m.then(()=>{x.get(n)===m&&x.delete(n)}),h},R=async(n,o,a)=>{await e.ensureConsent();let u;try{u=await ye(e.runtime,o)}catch(y){if(y instanceof F&&He.has(y.code)){await e.refreshView();return}throw y}if(a?.(),e.destroyed())return;let f=u;f.plan!==void 0&&e.setView!==void 0?e.setView(f):await e.refreshView()},L=async n=>{await e.ensureConsent();let o;try{try{o=await n(e.runtime.client)}catch(a){if(!(a instanceof F)||a.code!=="consent_required")throw a;await e.runtime.ensureConsent({force:!0}),o=await n(e.runtime.client)}}catch(a){if(a instanceof F&&He.has(a.code)){await e.refreshView();return}throw a}e.destroyed()||(o!==void 0&&e.setView!==void 0?e.setView(o):await e.refreshView())},O=(n,o)=>P("choice",`${n}:${o}`,()=>L(a=>a.choose(n,o))),A=(n,o)=>n.options.some(a=>a.id===o)?O(n.nodeId,o):Promise.reject(new RangeError(`option ${String(o)} is not offered`)),M=(n,o)=>{let a=e.currentView(),u=a===null?void 0:ie(a,n);return u===void 0?Promise.reject(new RangeError(`the ${o} is not offered`)):O(u.nodeId,u.option.id)},H=n=>P("identity",n,()=>L(o=>o.confirmIdentity===void 0?Promise.reject(new Error("identity confirmation is not available in this build")):o.confirmIdentity(n))),N=(n,o)=>{let a=n.kind,u=a==="phone_otp",f=u?"phone":"email",y={action:"send"};if(u?n.needsPhone:n.needsEmail){let h=o[f]??_[a],m=u?h?.replace(/[\s().-]/g,""):h?.trim();if(m===void 0||!(u?Pt:Et).test(m))return Promise.reject(u?new T("phone","format"):new Z("email","format"));y[f]=m}if(u){let h=n.channels,m=o.channel??(h.length===1?h[0]:void 0);if(h.length>0){if(m===void 0)return Promise.reject(new Z("channel","required"));if(!h.includes(m))return Promise.reject(new Z("channel","unavailable"))}m!==void 0&&(y.channel=m)}return P(a,"send",()=>R(a,(h,m)=>h.submitCheck(a,y,{idempotencyKey:m}),()=>{c[a]=e.now(),y[f]!==void 0&&(_[a]=y[f])}))},V=(n,o)=>Mt.test(o)?P(n,"verify",()=>R(n,(a,u)=>a.submitCheck(n,{action:"verify",code:o},{idempotencyKey:u}))):Promise.reject(new T("code","format")),D=(n,o)=>P("eid_auth",n,()=>R("eid_auth",(a,u)=>a.submitCheck("eid_auth",o,{idempotencyKey:u}))),Y=(n,o)=>{if(n.identifierBound)return D("start",{action:"start"});let a=se(o??"");if(n.country==="MR"){if(!/^\d{10}$/.test(a))return Promise.reject(new T("nni","format"));if(!Ge(a))return Promise.reject(new T("nni","check_digit"))}else if(a==="")return Promise.reject(new T("nni","format"));return D("start",{action:"start",identifier:a})},B=(n,o,a)=>{if(n.source!=="typed")return Promise.reject(new RangeError("this session already holds the ID number"));let u=se(o);return/^\d{10}$/.test(u)?De({type:"national_id",issuingCountry:"MR",number:u})?P("population_registry","submitIdNumber",()=>R("population_registry",(f,y)=>f.submitCheck("population_registry",{idNumber:u,nni:u},{idempotencyKey:y}),()=>{S=`\u2022\u2022\u2022\u2022\u2022\u2022${u.slice(-4)}`})):Promise.reject(new T(a,"check_digit")):Promise.reject(new T(a,"format"))},j=n=>{switch(n.kind){case"phone_otp":case"email_otp":{let o={...n,send:(u={})=>N(n,u),verify:u=>V(n.kind,u),switchTo:()=>n.canSwitch&&n.switchChannel!==void 0?M([n.switchChannel==="email"?"email_otp":"phone_otp"],"other contact option"):Promise.reject(new RangeError("this session has no other contact option"))},a=c[n.kind];return o.resendAvailableAt===void 0&&a!==void 0&&(o.resendAvailableAt=new Date(a+kt).toISOString()),o}case"eid":return{...n,start:o=>Y(n,o),verify:o=>Rt.test(o)?D("verify",{action:"verify",code:o}):Promise.reject(new T("code","format")),resend:()=>n.resendsRemaining===0?Promise.reject(new RangeError("no new code can be sent for this session")):D("resend",{action:"resend"}),useCamera:()=>n.canUseCamera&&n.cameraMethod!==void 0?M(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 a=n.choice.options.find(u=>K[u.service]===o);return a!==void 0?A(n.choice,a.id):Promise.reject(new RangeError(`method ${String(o)} is not offered`))},choose:o=>A(n.choice,o)};case"choice":return{...n,choose:o=>A(n.choice,o)};case"registry":return{...n,submitIdNumber:o=>B(n,o,"idNumber"),submitNni:o=>B(n,o,"nni"),confirm:()=>P("population_registry","confirm",()=>R("population_registry",(o,a)=>o.submitCheck("population_registry",{},{idempotencyKey:a}))),useDocument:()=>n.canUseDocument?M(["document"],"document method"):Promise.reject(new RangeError("the document method is not offered"))};case"document":return e.bindDocument!==void 0?e.bindDocument(n,l):{...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")}};case"portrait":return e.bindPortrait!==void 0?e.bindPortrait(n,l):{...n,uploadFailed:!1,resubmit:()=>Promise.resolve(),capture:()=>{throw new Error("portrait capture is not available in this build")}};case"contact_choice":return{...n,select:o=>{let a=o==="phone"?"phone_otp":o==="email"?"email_otp":void 0,u=n.choice.options.find(f=>f.service===a);return u!==void 0?A(n.choice,u.id):Promise.reject(new RangeError(`contact ${String(o)} is not offered`))},choose:o=>A(n.choice,o)};case"identity_summary":return{...n,...n.idNumberMasked===void 0&&n.summaryKind==="partial"&&S!==null?{idNumberMasked:S,nniMasked:S}:{},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:()=>H("confirm"),retake:()=>n.retakeAvailable?H("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()=>{s=!1,await e.refreshView()}};case"unsupported":case"result":return{...n};default:{let o=n;throw new Error(`runner: unhandled step ${JSON.stringify(o)}`)}}},$=async()=>{if(!d){d=!0;try{for(let n of Ct){if(await e.sleep(n),!t||e.destroyed())return;let o=await e.refreshView().catch(()=>null);if(o!==null&&J(o,{isMobile:e.isMobile()}).kind!=="processing")return}s=!0,l()}finally{d=!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(g==="inflight")return o;if(!b||g==="done")return null;let a=e.keptFaceKey?.()??null;return a===null?null:(g="inflight",R("face_match",(u,f)=>u.submitCheck("face_match",{imageKey:a},{idempotencyKey:f}),()=>{g="done"}).then(()=>{g==="inflight"&&(g="done",l())},()=>{g="done",l()}),o)},U=(n,o=!1)=>{if(!t||e.destroyed()||e.chainBusy())return;let a=J(n,{isMobile:e.isMobile()});a.kind==="registry"&&a.recheck&&(b=!0,g="idle"),a=W(a)??a,a.kind==="processing"?a.stalled=s:s=!1;let u=j(a),f=a.kind==="result"?void 0:a.context.switchable,y=f===void 0?u:{...u,chooseOption:m=>A({nodeId:f.nodeId,kind:f.kind,selected:f.current,options:f.options},m)},h=JSON.stringify(y);a.kind==="registry"&&a.source==="document"&&a.state==="pending"&&!C.has("registry")&&(C.add("registry"),y.confirm().catch(m=>{(!(m instanceof F)||At.has(m.code))&&C.delete("registry")})),!(!o&&h===r)&&(r=h,i=y,e.emitStep(y),a.kind==="processing"&&!s&&g!=="inflight"&&$(),a.kind==="result"&&!p&&(p=!0,e.emitResult(a.result)))};function l(){let n=e.currentView();n!==null&&U(n,!0)}return{run:async()=>{if(e.destroyed())throw new Error("verification destroyed");t=!0;let n=await e.ensureView();return i===null&&U(n),i??j(J(n,{isMobile:e.isMobile()}))},current:()=>i,onView:n=>U(n),onChainIdle:()=>{let n=e.currentView();n!==null&&U(n)},republish:l,submit:R}}export{Fe as a,Tt as b,ke as c,Pe as d,Lt as e,J as f,Ct as g,kt as h,tn as i};
@@ -1 +1 @@
1
- "use strict";var y=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var O=Object.prototype.hasOwnProperty;var H=(t,e)=>{for(var o in e)y(t,o,{get:e[o],enumerable:!0})},M=(t,e,o,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of R(e))!O.call(t,i)&&i!==o&&y(t,i,{get:()=>e[i],enumerable:!(n=E(e,i))||n.enumerable});return t};var A=t=>M(y({},"__esModule",{value:!0}),t);var Y={};H(Y,{HostedApiError:()=>d,HostedClient:()=>p,KNOWN_CODES:()=>g,icaoPolicyOf:()=>I,isKnownCode:()=>T,portraitIcaoGate:()=>k,stripMimeParams:()=>u});module.exports=A(Y);var b="0.1.0-rc.11";var w="sekyro.did",S;function C(){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,o=>o.toString(16).padStart(2,"0")).join("")}}catch{}}function N(){try{let t=localStorage.getItem(w);if(t)return t;let e=C();return e!==void 0&&localStorage.setItem(w,e),e}catch{return S??(S=C()),S}}async function x(){let t=globalThis.crypto?.subtle;if(!t)return"";let e=navigator,o=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]),n=await t.digest("SHA-256",new TextEncoder().encode(o));return Array.from(new Uint8Array(n),i=>i.toString(16).padStart(2,"0")).join("").slice(0,32)}function V(t){let e=new TextEncoder().encode(t),o="";for(let n of e)o+=String.fromCharCode(n);return btoa(o).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function D(t){let e,o;return{timezone(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone?.slice(0,64)||void 0}catch{return}},noteCameraLabel(n){n&&(e=n.slice(0,128))},async deviceHeader(){try{o??(o=x().catch(()=>""));let n=[];navigator.webdriver&&n.push("webdriver"),/HeadlessChrome/.test(navigator.userAgent)&&n.push("headless");let i=await o,s=N(),r={v:1,platform:"web",sdk:t.sdk.slice(0,64),ids:[...s?[{kind:"web_local",value:s.slice(0,128)}]:[],...i?[{kind:"web_fp",value:i}]:[]],screen:{w:screen.width,h:screen.height,dpr:globalThis.devicePixelRatio??1},...e?{cameraLabel:e}:{},...n.length?{signals:n}:{}};return V(JSON.stringify(r))}catch{return}}}}var m=Symbol.for("sekyro.web.clientContext"),f=globalThis,h=f[m]??(f[m]=D({sdk:`@sekyro/web@${b}`}));var g=["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"];function T(t){return g.includes(t)}var d=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)}};var U=6e4,P=4,K=3e4,L=9e5,q=200,F=5,$=400;function u(t){return(t.split(";")[0]??"").trim()}var B={liveness:"clipKey",face_match:"imageKey",doc_ocr:"imageKey"},p=class{constructor(e){this.sessionId=null;this.bootstrap=null;this.captureNonces=[];this.captureFetch=null;this.apiOrigin=e.apiOrigin.replace(/\/+$/,""),this.sessionToken=e.sessionToken;let o=e.fetch;this.fetchImpl=(n,i)=>(o??globalThis.fetch).call(globalThis,n,i),this.requestTimeoutMs=e.requestTimeoutMs??K,this.retryAttempts=e.inProgressRetry?.attempts??F,this.retryDelayMs=e.inProgressRetry?.delayMs??$}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}})}async reportCameraUnavailable(e){return this.api("POST","/hosted/camera-unavailable",{body:{cause:e}})}async choose(e,o){let n=await this.api("POST","/hosted/choice",{body:{nodeId:e,option:o}});return this.sessionId=n.sessionId,n}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,o,n){let i=await this.ensureSessionId(),s={kind:e,contentType:u(o),contentLength:n};return this.api("POST",`/sessions/${i}/media`,{body:s})}armCapture(e=2){this.fillCaptureNonces(e)}async presignCapture(e,o,n,i={}){let s=await this.ensureSessionId(),r=await this.takeCaptureNonce(),c=r===void 0?void 0:{nonce:r,...i.engine!==void 0?{engine:i.engine.slice(0,32)}:{},...i.durationMs!==void 0&&Number.isFinite(i.durationMs)?{captureMs:Math.min(36e5,Math.max(0,Math.round(i.durationMs)))}:{}},a={kind:e,contentType:u(o),contentLength:n,capture:c};return this.api("POST",`/sessions/${s}/media`,{body:a})}async takeCaptureNonce(){let e=()=>{let o=Date.now();return this.captureNonces=this.captureNonces.filter(n=>n.expiresAt-U>o),this.captureNonces.shift()?.nonce};for(let o=0;o<2;o++){let n=e();if(n!==void 0)return n;await this.fillCaptureNonces(1)}return e()}fillCaptureNonces(e){return this.captureFetch??(this.captureFetch=(async()=>{try{let o=await this.ensureSessionId(),n=await this.api("POST",`/sessions/${o}/media/capture-nonces`,{body:{count:Math.min(P,Math.max(1,e))}}),i=Date.now()+Math.max(0,n.expiresIn)*1e3;for(let s of Array.isArray(n.nonces)?n.nonces:[])typeof s=="string"&&s.length>0&&this.captureNonces.push({nonce:s,expiresAt:i});this.captureNonces=this.captureNonces.slice(-P)}catch{}})().finally(()=>{this.captureFetch=null})),this.captureFetch}async uploadToSpaces(e,o,n){let i;try{i=await this.fetchImpl(e,{method:"PUT",headers:{"content-type":u(n)},body:o,signal:AbortSignal.timeout(L)})}catch(s){throw _(s)}if(!i.ok){let s=(await i.text().catch(()=>"")).slice(0,q);throw new d({status:i.status,code:"upload_failed",message:`media upload failed (HTTP ${i.status})${s?`: ${s}`:""}`})}}async completeMedia(e){let o=await this.ensureSessionId();return this.api("POST",`/sessions/${o}/media/complete`,{body:{key:e}})}async submitCheck(e,o,n={}){let i=await this.ensureSessionId(),s={input:o,forceOutcome:n.forceOutcome};return this.api("POST",`/sessions/${i}/checks/${e}`,{body:s,idempotencyKey:n.idempotencyKey})}async uploadAndSubmit(e,o,n,i={}){let s=u(o.contentType),r=await this.presign(o.kind,s,o.blob.size);await this.uploadToSpaces(r.uploadUrl,o.blob,s);let c=await this.completeMedia(r.key),a={...n,[B[e]]:c.key};return this.submitCheck(e,a,i)}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,o,n={}){let i=`${this.apiOrigin}/api/v2${o}`,s={"x-session-token":this.sessionToken};n.body!==void 0&&(s["content-type"]="application/json"),n.idempotencyKey!==void 0&&(s["x-idempotency-key"]=n.idempotencyKey);try{let r=h.timezone();r!==void 0&&(s["sekyro-client-timezone"]=r)}catch{}try{let r=await h.deviceHeader();r!==void 0&&(s["sekyro-client-device"]=r)}catch{}for(let r=0;;r++){let c;try{c=await this.fetchImpl(i,{method:e,headers:s,...n.body!==void 0?{body:JSON.stringify(n.body)}:{},cache:"no-store",signal:AbortSignal.timeout(this.requestTimeoutMs)})}catch(l){throw _(l)}if(c.ok){if(n.blob===!0)try{return await c.blob()}catch(v){throw _(v)}let l;try{l=await c.json()}catch{throw new d({status:c.status,code:"unknown_error",message:`response body was not valid JSON (HTTP ${c.status})`})}return j(l)}let a=await G(c);if(a.code==="idempotency_in_progress"&&r<this.retryAttempts){this.retryDelayMs>0&&await z(this.retryDelayMs);continue}throw a}}};function _(t){if((typeof t=="object"&&t!==null?t.name:void 0)==="TimeoutError")return new d({status:0,code:"timeout",message:"request timed out"});let o=t instanceof Error?t.message:String(t);return new d({status:0,code:"network_error",message:`network request failed: ${o}`})}function j(t){return t!==null&&typeof t=="object"&&"success"in t&&"data"in t?t.data:t}async function G(t){let e="unknown_error",o=`request failed (HTTP ${t.status})`,n=Number.NaN,i;try{let c=await t.json();if(c!==null&&typeof c=="object"){let a=c;typeof a.code=="string"&&a.code.length>0&&(e=a.code),typeof a.message=="string"&&a.message.length>0&&(o=a.message),typeof a.retryAfterSeconds=="number"&&(n=a.retryAfterSeconds),Array.isArray(a.details?.issues)&&(i=a.details)}}catch{}let s=t.headers.get("retry-after"),r=s===null?Math.floor(n):Number.parseInt(s,10);return new d({status:t.status,code:e,message:o,...Number.isFinite(r)&&r>=0?{retryAfterSeconds:r}:{},details:i})}function z(t){return new Promise(e=>setTimeout(e,t))}function I(t){let e=t?.portrait,o=e?.icao,n=e?.purpose==="id_document";return o==null?n?{policy:"reject",profile:"id_document"}:null:{policy:o.policy==="alert"&&!n?"alert":"reject",profile:n||o.profile==="id_document"?"id_document":"selfie"}}function k(t){return{...t.baselineEyeOpenness!==void 0?{baselineEyeOpenness:t.baselineEyeOpenness}:{},criteria:t.verdict??{},...t.backgroundCheck!==void 0?{backgroundCheck:t.backgroundCheck}:{}}}0&&(module.exports={HostedApiError,HostedClient,KNOWN_CODES,icaoPolicyOf,isKnownCode,portraitIcaoGate,stripMimeParams});
1
+ "use strict";var m=Object.defineProperty;var v=Object.getOwnPropertyDescriptor;var O=Object.getOwnPropertyNames;var H=Object.prototype.hasOwnProperty;var M=(t,e)=>{for(var o in e)m(t,o,{get:e[o],enumerable:!0})},A=(t,e,o,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of O(e))!H.call(t,i)&&i!==o&&m(t,i,{get:()=>e[i],enumerable:!(n=v(e,i))||n.enumerable});return t};var N=t=>A(m({},"__esModule",{value:!0}),t);var J={};M(J,{HostedApiError:()=>d,HostedClient:()=>y,KNOWN_CODES:()=>g,SEKYRO_SDK_HEADER:()=>S,icaoPolicyOf:()=>I,isKnownCode:()=>P,portraitIcaoGate:()=>E,stripMimeParams:()=>u});module.exports=N(J);var p="0.1.0-rc.13";var w="sekyro.did",C;function T(){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,o=>o.toString(16).padStart(2,"0")).join("")}}catch{}}function D(){try{let t=localStorage.getItem(w);if(t)return t;let e=T();return e!==void 0&&localStorage.setItem(w,e),e}catch{return C??(C=T()),C}}async function x(){let t=globalThis.crypto?.subtle;if(!t)return"";let e=navigator,o=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]),n=await t.digest("SHA-256",new TextEncoder().encode(o));return Array.from(new Uint8Array(n),i=>i.toString(16).padStart(2,"0")).join("").slice(0,32)}function V(t){let e=new TextEncoder().encode(t),o="";for(let n of e)o+=String.fromCharCode(n);return btoa(o).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function K(t){let e,o;return{timezone(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone?.slice(0,64)||void 0}catch{return}},noteCameraLabel(n){n&&(e=n.slice(0,128))},async deviceHeader(){try{o??(o=x().catch(()=>""));let n=[];navigator.webdriver&&n.push("webdriver"),/HeadlessChrome/.test(navigator.userAgent)&&n.push("headless");let i=await o,s=D(),r={v:1,platform:"web",sdk:t.sdk.slice(0,64),ids:[...s?[{kind:"web_local",value:s.slice(0,128)}]:[],...i?[{kind:"web_fp",value:i}]:[]],screen:{w:screen.width,h:screen.height,dpr:globalThis.devicePixelRatio??1},...e?{cameraLabel:e}:{},...n.length?{signals:n}:{}};return V(JSON.stringify(r))}catch{return}}}}var f=Symbol.for("sekyro.web.clientContext"),h=globalThis,_=h[f]??(h[f]=K({sdk:`@sekyro/web@${p}`}));var g=["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"];function P(t){return g.includes(t)}var d=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)}};var U=6e4,k=4,L=3e4,$=9e5,q=200,F=5,B=400;function u(t){return(t.split(";")[0]??"").trim()}var j={liveness:"clipKey",face_match:"imageKey",doc_ocr:"imageKey"},S=`@sekyro/web/${p}`,G=S,y=class{constructor(e){this.sessionId=null;this.bootstrap=null;this.captureNonces=[];this.captureFetch=null;this.apiOrigin=e.apiOrigin.replace(/\/+$/,""),this.sessionToken=e.sessionToken;let o=e.fetch;this.fetchImpl=(n,i)=>(o??globalThis.fetch).call(globalThis,n,i),this.requestTimeoutMs=e.requestTimeoutMs??L,this.retryAttempts=e.inProgressRetry?.attempts??F,this.retryDelayMs=e.inProgressRetry?.delayMs??B}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}})}async reportCameraUnavailable(e){return this.api("POST","/hosted/camera-unavailable",{body:{cause:e}})}async choose(e,o){let n=await this.api("POST","/hosted/choice",{body:{nodeId:e,option:o}});return this.sessionId=n.sessionId,n}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,o,n){let i=await this.ensureSessionId(),s={kind:e,contentType:u(o),contentLength:n};return this.api("POST",`/sessions/${i}/media`,{body:s})}armCapture(e=2){this.fillCaptureNonces(e)}async presignCapture(e,o,n,i={}){let s=await this.ensureSessionId(),r=await this.takeCaptureNonce(),c=r===void 0?void 0:{nonce:r,...i.engine!==void 0?{engine:i.engine.slice(0,32)}:{},...i.durationMs!==void 0&&Number.isFinite(i.durationMs)?{captureMs:Math.min(36e5,Math.max(0,Math.round(i.durationMs)))}:{}},a={kind:e,contentType:u(o),contentLength:n,capture:c};return this.api("POST",`/sessions/${s}/media`,{body:a})}async takeCaptureNonce(){let e=()=>{let o=Date.now();return this.captureNonces=this.captureNonces.filter(n=>n.expiresAt-U>o),this.captureNonces.shift()?.nonce};for(let o=0;o<2;o++){let n=e();if(n!==void 0)return n;await this.fillCaptureNonces(1)}return e()}fillCaptureNonces(e){return this.captureFetch??(this.captureFetch=(async()=>{try{let o=await this.ensureSessionId(),n=await this.api("POST",`/sessions/${o}/media/capture-nonces`,{body:{count:Math.min(k,Math.max(1,e))}}),i=Date.now()+Math.max(0,n.expiresIn)*1e3;for(let s of Array.isArray(n.nonces)?n.nonces:[])typeof s=="string"&&s.length>0&&this.captureNonces.push({nonce:s,expiresAt:i});this.captureNonces=this.captureNonces.slice(-k)}catch{}})().finally(()=>{this.captureFetch=null})),this.captureFetch}async uploadToSpaces(e,o,n){let i;try{i=await this.fetchImpl(e,{method:"PUT",headers:{"content-type":u(n)},body:o,signal:AbortSignal.timeout($)})}catch(s){throw b(s)}if(!i.ok){let s=(await i.text().catch(()=>"")).slice(0,q);throw new d({status:i.status,code:"upload_failed",message:`media upload failed (HTTP ${i.status})${s?`: ${s}`:""}`})}}async completeMedia(e){let o=await this.ensureSessionId();return this.api("POST",`/sessions/${o}/media/complete`,{body:{key:e}})}async submitCheck(e,o,n={}){let i=await this.ensureSessionId(),s={input:o,forceOutcome:n.forceOutcome};return this.api("POST",`/sessions/${i}/checks/${e}`,{body:s,idempotencyKey:n.idempotencyKey})}async uploadAndSubmit(e,o,n,i={}){let s=u(o.contentType),r=await this.presign(o.kind,s,o.blob.size);await this.uploadToSpaces(r.uploadUrl,o.blob,s);let c=await this.completeMedia(r.key),a={...n,[j[e]]:c.key};return this.submitCheck(e,a,i)}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,o,n={}){let i=`${this.apiOrigin}/api/v2${o}`,s={"x-session-token":this.sessionToken,"x-sekyro-sdk":G};n.body!==void 0&&(s["content-type"]="application/json"),n.idempotencyKey!==void 0&&(s["x-idempotency-key"]=n.idempotencyKey);try{let r=_.timezone();r!==void 0&&(s["sekyro-client-timezone"]=r)}catch{}try{let r=await _.deviceHeader();r!==void 0&&(s["sekyro-client-device"]=r)}catch{}for(let r=0;;r++){let c;try{c=await this.fetchImpl(i,{method:e,headers:s,...n.body!==void 0?{body:JSON.stringify(n.body)}:{},cache:"no-store",signal:AbortSignal.timeout(this.requestTimeoutMs)})}catch(l){throw b(l)}if(c.ok){if(n.blob===!0)try{return await c.blob()}catch(R){throw b(R)}let l;try{l=await c.json()}catch{throw new d({status:c.status,code:"unknown_error",message:`response body was not valid JSON (HTTP ${c.status})`})}return Y(l)}let a=await z(c);if(a.code==="idempotency_in_progress"&&r<this.retryAttempts){this.retryDelayMs>0&&await W(this.retryDelayMs);continue}throw a}}};function b(t){if((typeof t=="object"&&t!==null?t.name:void 0)==="TimeoutError")return new d({status:0,code:"timeout",message:"request timed out"});let o=t instanceof Error?t.message:String(t);return new d({status:0,code:"network_error",message:`network request failed: ${o}`})}function Y(t){return t!==null&&typeof t=="object"&&"success"in t&&"data"in t?t.data:t}async function z(t){let e="unknown_error",o=`request failed (HTTP ${t.status})`,n=Number.NaN,i;try{let c=await t.json();if(c!==null&&typeof c=="object"){let a=c;typeof a.code=="string"&&a.code.length>0&&(e=a.code),typeof a.message=="string"&&a.message.length>0&&(o=a.message),typeof a.retryAfterSeconds=="number"&&(n=a.retryAfterSeconds),Array.isArray(a.details?.issues)&&(i=a.details)}}catch{}let s=t.headers.get("retry-after"),r=s===null?Math.floor(n):Number.parseInt(s,10);return new d({status:t.status,code:e,message:o,...Number.isFinite(r)&&r>=0?{retryAfterSeconds:r}:{},details:i})}function W(t){return new Promise(e=>setTimeout(e,t))}function I(t){let e=t?.portrait,o=e?.icao,n=e?.purpose==="id_document";return o==null?n?{policy:"reject",profile:"id_document"}:null:{policy:o.policy==="alert"&&!n?"alert":"reject",profile:n||o.profile==="id_document"?"id_document":"selfie"}}function E(t){return{...t.baselineEyeOpenness!==void 0?{baselineEyeOpenness:t.baselineEyeOpenness}:{},criteria:t.verdict??{},...t.backgroundCheck!==void 0?{backgroundCheck:t.backgroundCheck}:{}}}0&&(module.exports={HostedApiError,HostedClient,KNOWN_CODES,SEKYRO_SDK_HEADER,icaoPolicyOf,isKnownCode,portraitIcaoGate,stripMimeParams});
@@ -1,14 +1,14 @@
1
- import { c as IcaoGateSummary } from '../icao-gate-BeznQECA.cjs';
2
- export { N as HostedClient, O as HostedClientOptions, Q as MediaCheckType, S as SubmitOptions, U as UploadMedia, T as stripMimeParams } from '../icao-gate-BeznQECA.cjs';
3
- import { H as HostedSessionView, z as HostedIcaoPolicy, ag as PortraitIcaoInput } from '../types-BWyAHKt_.cjs';
4
- export { A as AcceptedDocumentType, aw as AttestationInput, c as CaptureContext, h as CaptureMode, ax as CaptureNoncesResult, ay as CaptureProof, f as CheckInputByType, j as CheckReason, k as CheckState, e as CheckType, d as CompleteMediaResult, C as ConsentLocale, l as ContactChannel, D as DecisionReason, az as DocDeviceRead, aA as DocOcrInput, m as DocReason, aB as DocSide, E as EidAfterPass, n as EidAuthInput, o as EidReason, aC as EmailOtpInput, p as EmailOtpReason, aD as FaceMatchInput, F as FaceMatchReason, q as HostedAcceptedDocuments, t as HostedCaptureTuning, a as HostedConsentView, u as HostedDocumentCaptureTuning, v as HostedDocumentScanTuning, w as HostedEidView, x as HostedEmailOtpView, y as HostedFlowRef, G as HostedIntegrity, J as HostedLivePhotoTuning, L as HostedNativeCaptureTuning, N as HostedOcrTuning, O as HostedOtpView, Q as HostedPlanView, T as HostedPortraitView, U as HostedStepView, V as HostedVoiceLocale, W as HostedVoiceView, g as IcaoCriterion, Y as IcaoReportEntry, I as IdentityConfirmDecision, Z as IdentityMethod, _ as IdentitySummarySource, $ as IdentitySummaryView, aE as LivenessCaptureInput, aF as LivenessInput, a0 as LivenessReason, a1 as MatchReason, M as MediaKind, a2 as MethodChoiceView, a3 as NationalEidOption, a4 as NfcChipReason, a5 as NfcStepView, a6 as OtpChoiceView, aG as PhoneOtpInput, a7 as PhoneOtpReason, a8 as PlanAttempts, a9 as PlanChoiceKind, aa as PlanChoiceOption, ab as PlanChoiceView, ac as PlanSectionView, ad as PlanStepView, ae as PolicyFailureReason, aH as PopulationInput, af as PopulationReason, ah as PortraitIcaoReason, aI as PresignRequest, P as PresignUploadResult, aJ as RecordConsentResult, am as SessionFailureReason, an as SessionOutcome, ao as SessionStatus, aK as SessionStepView, aL as SessionView, ap as StepSection, aM as SubmitCheckBody, aq as VerificationAssurance, ar as VerificationLevel } from '../types-BWyAHKt_.cjs';
1
+ import { c as IcaoGateSummary } from '../icao-gate-B0GDH_JS.cjs';
2
+ export { N as HostedClient, O as HostedClientOptions, Q as MediaCheckType, S as SEKYRO_SDK_HEADER, T as SubmitOptions, U as UploadMedia, V as stripMimeParams } from '../icao-gate-B0GDH_JS.cjs';
3
+ import { H as HostedSessionView, G as HostedIcaoPolicy, ah as PortraitIcaoInput } from '../types-DPWT_KMn.cjs';
4
+ export { A as AcceptedDocumentType, ax as AttestationInput, c as CaptureContext, i as CaptureMode, ay as CaptureNoncesResult, az as CaptureProof, f as CheckInputByType, k as CheckReason, l as CheckState, e as CheckType, d as CompleteMediaResult, C as ConsentLocale, m as ContactChannel, D as DecisionReason, aA as DocDeviceRead, aB as DocOcrInput, n as DocReason, aC as DocSide, E as EidAfterPass, o as EidAuthInput, p as EidReason, aD as EmailOtpInput, q as EmailOtpReason, aE as FaceMatchInput, F as FaceMatchReason, r as HostedAcceptedDocuments, u as HostedCaptureTuning, a as HostedConsentView, v as HostedDocumentCaptureTuning, w as HostedDocumentScanTuning, x as HostedEidView, y as HostedEmailOtpView, z as HostedFlowRef, J as HostedIntegrity, K as HostedLivePhotoTuning, N as HostedNativeCaptureTuning, O as HostedOcrTuning, Q as HostedOtpView, T as HostedPlanView, U as HostedPortraitView, V as HostedStepView, W as HostedVoiceLocale, X as HostedVoiceView, g as IcaoCriterion, Z as IcaoReportEntry, I as IdentityConfirmDecision, _ as IdentityMethod, $ as IdentitySummarySource, a0 as IdentitySummaryView, aF as LivenessCaptureInput, aG as LivenessInput, a1 as LivenessReason, a2 as MatchReason, M as MediaKind, a3 as MethodChoiceView, a4 as NationalEidOption, a5 as NfcChipReason, a6 as NfcStepView, a7 as OtpChoiceView, aH as PhoneOtpInput, a8 as PhoneOtpReason, a9 as PlanAttempts, aa as PlanChoiceKind, ab as PlanChoiceOption, ac as PlanChoiceView, ad as PlanSectionView, ae as PlanStepView, af as PolicyFailureReason, aI as PopulationInput, ag as PopulationReason, ai as PortraitIcaoReason, aJ as PresignRequest, P as PresignUploadResult, aK as RecordConsentResult, an as SessionFailureReason, ao as SessionOutcome, ap as SessionStatus, aL as SessionStepView, aM as SessionView, aq as StepSection, aN as SubmitCheckBody, ar as VerificationAssurance, as as VerificationLevel } from '../types-DPWT_KMn.cjs';
5
5
 
6
6
  /**
7
7
  * Every error code the hosted page can receive from the session-token surface.
8
8
  * A closed string-literal union — switch over {@link KnownCode} with a `never`
9
9
  * default arm for compile-checked exhaustiveness.
10
10
  */
11
- declare const KNOWN_CODES: readonly ["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"];
11
+ declare const KNOWN_CODES: readonly ["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"];
12
12
  /** Closed union of {@link KNOWN_CODES} — exhaustively switchable. */
13
13
  type KnownCode = (typeof KNOWN_CODES)[number];
14
14
  /** Narrow an arbitrary wire code to the known union (unknown codes stay `string`). */
@@ -1,14 +1,14 @@
1
- import { c as IcaoGateSummary } from '../icao-gate-Bw5sQVlt.js';
2
- export { N as HostedClient, O as HostedClientOptions, Q as MediaCheckType, S as SubmitOptions, U as UploadMedia, T as stripMimeParams } from '../icao-gate-Bw5sQVlt.js';
3
- import { H as HostedSessionView, z as HostedIcaoPolicy, ag as PortraitIcaoInput } from '../types-BWyAHKt_.js';
4
- export { A as AcceptedDocumentType, aw as AttestationInput, c as CaptureContext, h as CaptureMode, ax as CaptureNoncesResult, ay as CaptureProof, f as CheckInputByType, j as CheckReason, k as CheckState, e as CheckType, d as CompleteMediaResult, C as ConsentLocale, l as ContactChannel, D as DecisionReason, az as DocDeviceRead, aA as DocOcrInput, m as DocReason, aB as DocSide, E as EidAfterPass, n as EidAuthInput, o as EidReason, aC as EmailOtpInput, p as EmailOtpReason, aD as FaceMatchInput, F as FaceMatchReason, q as HostedAcceptedDocuments, t as HostedCaptureTuning, a as HostedConsentView, u as HostedDocumentCaptureTuning, v as HostedDocumentScanTuning, w as HostedEidView, x as HostedEmailOtpView, y as HostedFlowRef, G as HostedIntegrity, J as HostedLivePhotoTuning, L as HostedNativeCaptureTuning, N as HostedOcrTuning, O as HostedOtpView, Q as HostedPlanView, T as HostedPortraitView, U as HostedStepView, V as HostedVoiceLocale, W as HostedVoiceView, g as IcaoCriterion, Y as IcaoReportEntry, I as IdentityConfirmDecision, Z as IdentityMethod, _ as IdentitySummarySource, $ as IdentitySummaryView, aE as LivenessCaptureInput, aF as LivenessInput, a0 as LivenessReason, a1 as MatchReason, M as MediaKind, a2 as MethodChoiceView, a3 as NationalEidOption, a4 as NfcChipReason, a5 as NfcStepView, a6 as OtpChoiceView, aG as PhoneOtpInput, a7 as PhoneOtpReason, a8 as PlanAttempts, a9 as PlanChoiceKind, aa as PlanChoiceOption, ab as PlanChoiceView, ac as PlanSectionView, ad as PlanStepView, ae as PolicyFailureReason, aH as PopulationInput, af as PopulationReason, ah as PortraitIcaoReason, aI as PresignRequest, P as PresignUploadResult, aJ as RecordConsentResult, am as SessionFailureReason, an as SessionOutcome, ao as SessionStatus, aK as SessionStepView, aL as SessionView, ap as StepSection, aM as SubmitCheckBody, aq as VerificationAssurance, ar as VerificationLevel } from '../types-BWyAHKt_.js';
1
+ import { c as IcaoGateSummary } from '../icao-gate-BP11XO-h.js';
2
+ export { N as HostedClient, O as HostedClientOptions, Q as MediaCheckType, S as SEKYRO_SDK_HEADER, T as SubmitOptions, U as UploadMedia, V as stripMimeParams } from '../icao-gate-BP11XO-h.js';
3
+ import { H as HostedSessionView, G as HostedIcaoPolicy, ah as PortraitIcaoInput } from '../types-DPWT_KMn.js';
4
+ export { A as AcceptedDocumentType, ax as AttestationInput, c as CaptureContext, i as CaptureMode, ay as CaptureNoncesResult, az as CaptureProof, f as CheckInputByType, k as CheckReason, l as CheckState, e as CheckType, d as CompleteMediaResult, C as ConsentLocale, m as ContactChannel, D as DecisionReason, aA as DocDeviceRead, aB as DocOcrInput, n as DocReason, aC as DocSide, E as EidAfterPass, o as EidAuthInput, p as EidReason, aD as EmailOtpInput, q as EmailOtpReason, aE as FaceMatchInput, F as FaceMatchReason, r as HostedAcceptedDocuments, u as HostedCaptureTuning, a as HostedConsentView, v as HostedDocumentCaptureTuning, w as HostedDocumentScanTuning, x as HostedEidView, y as HostedEmailOtpView, z as HostedFlowRef, J as HostedIntegrity, K as HostedLivePhotoTuning, N as HostedNativeCaptureTuning, O as HostedOcrTuning, Q as HostedOtpView, T as HostedPlanView, U as HostedPortraitView, V as HostedStepView, W as HostedVoiceLocale, X as HostedVoiceView, g as IcaoCriterion, Z as IcaoReportEntry, I as IdentityConfirmDecision, _ as IdentityMethod, $ as IdentitySummarySource, a0 as IdentitySummaryView, aF as LivenessCaptureInput, aG as LivenessInput, a1 as LivenessReason, a2 as MatchReason, M as MediaKind, a3 as MethodChoiceView, a4 as NationalEidOption, a5 as NfcChipReason, a6 as NfcStepView, a7 as OtpChoiceView, aH as PhoneOtpInput, a8 as PhoneOtpReason, a9 as PlanAttempts, aa as PlanChoiceKind, ab as PlanChoiceOption, ac as PlanChoiceView, ad as PlanSectionView, ae as PlanStepView, af as PolicyFailureReason, aI as PopulationInput, ag as PopulationReason, ai as PortraitIcaoReason, aJ as PresignRequest, P as PresignUploadResult, aK as RecordConsentResult, an as SessionFailureReason, ao as SessionOutcome, ap as SessionStatus, aL as SessionStepView, aM as SessionView, aq as StepSection, aN as SubmitCheckBody, ar as VerificationAssurance, as as VerificationLevel } from '../types-DPWT_KMn.js';
5
5
 
6
6
  /**
7
7
  * Every error code the hosted page can receive from the session-token surface.
8
8
  * A closed string-literal union — switch over {@link KnownCode} with a `never`
9
9
  * default arm for compile-checked exhaustiveness.
10
10
  */
11
- declare const KNOWN_CODES: readonly ["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"];
11
+ declare const KNOWN_CODES: readonly ["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"];
12
12
  /** Closed union of {@link KNOWN_CODES} — exhaustively switchable. */
13
13
  type KnownCode = (typeof KNOWN_CODES)[number];
14
14
  /** Narrow an arbitrary wire code to the known union (unknown codes stay `string`). */
@@ -1 +1 @@
1
- import{a as e,b as t,c as o,d as i,e as n,f as s,g as a}from"../chunk-URUKV6NC.js";import"../chunk-LUKTHL6K.js";export{o as HostedApiError,n as HostedClient,e as KNOWN_CODES,s as icaoPolicyOf,t as isKnownCode,a as portraitIcaoGate,i as stripMimeParams};
1
+ import{a as e,b as t,c as o,d as i,e as n,f as s,g as a,h as p}from"../chunk-57VOMVKM.js";import"../chunk-5OIC5TZS.js";export{o as HostedApiError,s as HostedClient,e as KNOWN_CODES,n as SEKYRO_SDK_HEADER,a as icaoPolicyOf,t as isKnownCode,p as portraitIcaoGate,i as stripMimeParams};