@sekyro/elements 0.1.0-rc.3 → 0.1.0-rc.4

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 (29) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/cdn/chunks/{capture-session-doc-WZMI5XPE-AZDHR6MQ.js → capture-session-doc-FRBI7OKF-AIBTLOVK.js} +1 -1
  3. package/dist/cdn/chunks/{chunk-POHYEXNR.js → chunk-5ZNWYB3D.js} +1 -1
  4. package/dist/cdn/chunks/{chunk-MJEQ5ANO.js → chunk-AKUFZTNC.js} +1 -1
  5. package/dist/cdn/chunks/{chunk-CXQO6QMQ.js → chunk-AN2KDTP4.js} +1 -1
  6. package/dist/cdn/chunks/{chunk-UNQ3QO4U.js → chunk-AOM2HJGY.js} +1 -1
  7. package/dist/cdn/chunks/{chunk-2T6RLTDQ.js → chunk-COQQVNNG.js} +1 -1
  8. package/dist/cdn/chunks/{chunk-TKJVGZWP.js → chunk-FYPP4Q7V.js} +2 -2
  9. package/dist/cdn/chunks/{chunk-ZMHEKDRM.js → chunk-G2RZQTCT.js} +1 -1
  10. package/dist/cdn/chunks/{chunk-434MMEWK.js → chunk-GIGTK355.js} +1 -1
  11. package/dist/cdn/chunks/{chunk-7MV4CI4L.js → chunk-H5GXVL63.js} +1 -1
  12. package/dist/cdn/chunks/{chunk-SGUCIULX.js → chunk-HMNCXTZQ.js} +2 -2
  13. package/dist/cdn/chunks/{chunk-ZYZPLDA2.js → chunk-KLODCY6G.js} +1 -1
  14. package/dist/cdn/chunks/{chunk-6BRQUKUP.js → chunk-RPCMWL2U.js} +1 -1
  15. package/dist/cdn/chunks/{chunk-RKH7O2P5.js → chunk-UGP2ZH7W.js} +1 -1
  16. package/dist/cdn/chunks/{chunk-FV4TIWHC.js → chunk-X4MIUKLT.js} +1 -1
  17. package/dist/cdn/chunks/{create-document-capture-OXPLKHOF-GVCM77EK.js → create-document-capture-2YBCDEUB-GYUIXEAL.js} +1 -1
  18. package/dist/cdn/chunks/{document-capture-view-UL3ISHNS-WZLR5RSQ.js → document-capture-view-UL3ISHNS-E6AP35NA.js} +1 -1
  19. package/dist/cdn/chunks/{eid-view-FKFEF42L-2OQYMKAB.js → eid-view-FKFEF42L-4OPACR2A.js} +1 -1
  20. package/dist/cdn/chunks/{email-otp-view-NRZCAJJ4-BJNXOVUF.js → email-otp-view-NRZCAJJ4-UFM2YDCD.js} +1 -1
  21. package/dist/cdn/chunks/{flow-views-N7LBFI55-27RU7EZG.js → flow-views-N7LBFI55-36234BJJ.js} +1 -1
  22. package/dist/cdn/chunks/{plan-runner-EP26JU6A-LU7KJ6JU.js → plan-runner-KQM7I4MR-HEXIU27Q.js} +1 -1
  23. package/dist/cdn/chunks/{portrait-capture-view-6KZGPAJU-2O54W4SR.js → portrait-capture-view-6KZGPAJU-CFUUPI5B.js} +1 -1
  24. package/dist/cdn/chunks/{portrait-review-view-TBSABVSX-5SVU25AE.js → portrait-review-view-TBSABVSX-J5ZCIFSX.js} +1 -1
  25. package/dist/cdn/chunks/{proof-of-address-view-3GG3XEQK-CPQ2AQEQ.js → proof-of-address-view-3GG3XEQK-7DFCRBNZ.js} +1 -1
  26. package/dist/cdn/define.js +1 -1
  27. package/dist/cdn/index.js +1 -1
  28. package/package.json +2 -2
  29. package/sbom.cdx.json +4 -4
@@ -1 +1 @@
1
- import{a as tt,b as $t,c as te,d as dt,e as ee}from"./chunk-WPRIGJHG.js";import{a as Ut,b as Kt,e as Yt}from"./chunk-2FETDQV5.js";import{a as Vt,b as Zt}from"./chunk-EWTKC2C2.js";import{b as Jt}from"./chunk-L22GFJQV.js";import{d as Wt,e as Ht,f as Qt}from"./chunk-434MMEWK.js";import{a as ct,b as ut,c as Y,d as Xt}from"./chunk-P7K7ELYZ.js";import{g as Nt,i as qt,j as Gt,k as jt,l as Bt}from"./chunk-JS2IXPNL.js";import{a as n}from"./chunk-4FHWXBOB.js";var et=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 Ae(s){return s.framing==="no_document"?"sensing":s.framing==="too_far"?"too_far":s.framing==="too_close"?"too_close":s.framing==="edge_clipped"?"edge_clipped":s.framing==="wrong_shape"?"wrong_shape":s.framing==="tilted"?"tilted":s.lighting==="too_dark"?"too_dark":s.lighting==="too_bright"?"too_bright":s.glare==="glare"?"glare":s.blur==="blurry"?"blurry":"hold_still"}n(Ae,"ne");var G,ze=(G=class{constructor(t=2600,e=.35){this.windowMs=t,this.decayPerSecond=e,this.votes=[],this.current=et.sensing,this.currentSinceMs=null}reset(){this.votes=[],this.current=et.sensing,this.currentSinceMs=null}force(t,e){return this.votes=[],this.current=et[t],this.currentSinceMs=e,this.current}tick(t,e){if(this.currentSinceMs===null&&(this.currentSinceMs=e),this.votes.push({key:t,atMs:e}),this.votes=this.votes.filter(o=>e-o.atMs<=this.windowMs),e-this.currentSinceMs<this.current.minDurationMs)return this.current;let i=new Map;for(let o of this.votes){let l=(e-o.atMs)/1e3,r=this.decayPerSecond**l;i.set(o.key,(i.get(o.key)??0)+r)}let a=this.current.key,h=-1;for(let[o,l]of i)l>h&&(h=l,a=o);return a!==this.current.key&&(this.current=et[a],this.currentSinceMs=e),this.current}},n(G,"ot"),G),Ce=Object.freeze({MAX_AREA_FRAC:.92,TILT_MAX_SIDE_RATIO:1.3,GLARE_MAX_SPECULAR_FRAC:.025});function Ie(s){let{data:t,width:e,height:i}=s,a=e*i;if(a===0)return 0;let h=0;for(let o=0;o<a;o++){let l=o*4;.299*(t[l]??0)+.587*(t[l+1]??0)+.114*(t[l+2]??0)>=252&&h++}return h/a}n(Ie,"re");function Le(s){let t=n((r,c)=>Math.hypot(c.x-r.x,c.y-r.y),"t"),e=t(s.topLeft,s.topRight),i=t(s.bottomLeft,s.bottomRight),a=t(s.topLeft,s.bottomLeft),h=t(s.topRight,s.bottomRight),o=Math.max(e,i)/Math.max(1e-6,Math.min(e,i)),l=Math.max(a,h)/Math.max(1e-6,Math.min(a,h));return Math.max(o,l)}n(Le,"je");function Oe(s){let t={...$t,...s.thresholds},e=Ce,{quad:i,frameWidth:a,frameHeight:h,measures:o}=s,l=s.format==="ID-3",r="ok";if(i===null)r="no_document";else if(l){let d=dt(i),m=a>0?d.width/a:0,g=d.height>0?d.width/d.height:0;m<t.ID3_BAND_MIN_WIDTH_FRAC?r="too_far":ie(i,a,h,t.EDGE_CLIP_MARGIN_PX)?r="edge_clipped":(g<t.ID3_BAND_ASPECT_MIN||g>t.ID3_BAND_ASPECT_MAX)&&(r="wrong_shape")}else{let d=te(i,a,h),m=dt(i),g=Math.max(m.width,m.height)/Math.max(1e-6,Math.min(m.width,m.height));d<t.MIN_AREA_FRAC?r="too_far":d>e.MAX_AREA_FRAC?r="too_close":ie(i,a,h,t.EDGE_CLIP_MARGIN_PX)?r="edge_clipped":Zt(s.format,g)?Le(i)>e.TILT_MAX_SIDE_RATIO&&(r="tilted"):r="wrong_shape"}let c=o.exposure>=t.GUIDE_EXPOSURE?"ok":o.meanLuma<(ct[0]+ct[1])/2?"too_dark":"too_bright",u=o.sharpness>=t.GUIDE_SHARPNESS?"ok":"blurry",f=o.specularFraction>=e.GLARE_MAX_SPECULAR_FRAC?"glare":"ok";return{framing:r,lighting:c,blur:u,glare:f,acceptable:r==="ok"&&c==="ok"&&u==="ok"&&f==="ok"}}n(Oe,"ae");function ie(s,t,e,i){return[s.topLeft,s.topRight,s.bottomRight,s.bottomLeft].some(a=>a.x<=i||a.y<=i||a.x>=t-i||a.y>=e-i)}n(ie,"se");var Ee=Object.freeze({width:1920,height:1080}),Pe=Object.freeze({width:3840,height:2160}),se=4096,We=2560,Ne=640,it=.15,V=Object.freeze({side:.2,above:.9,below:.3});function C(s){let t=[s.topLeft.x,s.topRight.x,s.bottomRight.x,s.bottomLeft.x],e=[s.topLeft.y,s.topRight.y,s.bottomRight.y,s.bottomLeft.y],i=Math.min(...t),a=Math.min(...e);return{x:i,y:a,width:Math.max(...t)-i,height:Math.max(...e)-a}}n(C,"E");function me(s,t){let e=Math.max(0,Math.floor(s.x)),i=Math.max(0,Math.floor(s.y)),a=Math.min(t.width,Math.ceil(s.x+s.width)),h=Math.min(t.height,Math.ceil(s.y+s.height));return a-e<16||h-i<16?null:{x:e,y:i,width:a-e,height:h-i}}n(me,"he");function qe(s,t,e){if(s===null||t.width<=0||t.height<=0)return null;let i=C(s);if(i.width<=0||i.height<=0)return null;let a=e==="ID-3"?{x:i.x-i.width*V.side,y:i.y-i.width*V.above,width:i.width*(1+2*V.side),height:i.height+i.width*(V.above+V.below)}:{x:i.x-i.width*it,y:i.y-i.height*it,width:i.width*(1+2*it),height:i.height*(1+2*it)};return me(a,t)}n(qe,"Je");function ge(s,t,e){let i=Math.max(s,t);return i>0?Math.min(1,e/i):1}n(ge,"ft");function pe(s,t,e,i,a=We){let h=t.width>0?e.width/t.width:1,o=t.height>0?e.height/t.height:1,l=s===null?null:{topLeft:{x:s.topLeft.x*h,y:s.topLeft.y*o},topRight:{x:s.topRight.x*h,y:s.topRight.y*o},bottomRight:{x:s.bottomRight.x*h,y:s.bottomRight.y*o},bottomLeft:{x:s.bottomLeft.x*h,y:s.bottomLeft.y*o}},r=qe(l,e,i)??{x:0,y:0,width:e.width,height:e.height},c=ge(r.width,r.height,a),u=Math.max(1,Math.round(r.width*c)),f=Math.max(1,Math.round(r.height*c)),d=null;if(l!==null){let m=C(l);d=me({x:(m.x-r.x)*c,y:(m.y-r.y)*c,width:m.width*c,height:m.height*c},{width:u,height:f})}return{crop:r,width:u,height:f,docRegion:d}}n(pe,"pt");function Ge(s,t,e,i=Pe){if(e==="LOW")return null;let a=s?.width?.max,h=s?.height?.max;if(typeof a!="number"||typeof h!="number"||a<=0||h<=0)return null;let o=Math.max(a,h),l=Math.min(a,h),r=Math.min(o,Math.max(i.width,i.height)),c=Math.min(l,Math.min(i.width,i.height));return r<=Math.max(t.width,t.height)?null:{width:{ideal:r},height:{ideal:c}}}n(Ge,"de");function je(s){let t={},e=s?.imageWidth,i=s?.imageHeight;if(typeof e?.max=="number"&&e.max>0){let a=typeof i?.max=="number"&&i.max>0?e.max/i.max:1.3333333333333333,h=a>=1?se:se*a,o=Math.min(e.max,Math.floor(h)),l=typeof e.step=="number"&&e.step>0?e.step:1,r=typeof e.min=="number"?e.min:0;o=Math.max(r,r+Math.floor((o-r)/l)*l),t.imageWidth=o}return s?.fillLightMode?.includes("off")===!0&&(t.fillLightMode="off"),t}n(je,"me");function Be(s,t){if(s.width<=0||s.height<=0||t.width<=0||t.height<=0)return!1;let e=s.width>s.height,i=t.width>t.height;return e!==i&&s.width!==s.height&&t.width!==t.height?!1:Math.max(s.width,s.height)>=1.2*Math.max(t.width,t.height)}n(Be,"fe");function He(s,t,e,i){if(e===null)return!1;let a=C(s),h=C(e);if(t.width<=0||i.width<=0)return!1;let o=a.width/t.width,l=h.width/i.width;return l>0&&o>=.6*l&&o<=1.25*l}n(He,"pe");var ae=3500,Qe=.92;function Me(){let s=globalThis.ImageCapture;return typeof s=="function"?s:null}n(Me,"ye");function Xe(s){return/AppleWebKit\//.test(s)&&!/(Chrome|Chromium|Edg|OPR)\//.test(s)}n(Xe,"$e");function Ue(s,t=typeof navigator>"u"?"":navigator.userAgent){return Me()!==null&&!Xe(t)&&s!=null&&s.kind==="video"&&s.readyState==="live"}n(Ue,"Me");function he(s,t){return new Promise((e,i)=>{let a=setTimeout(()=>i(new Error("takePhoto timed out")),t);s.then(h=>{clearTimeout(a),e(h)},h=>{clearTimeout(a),i(h)})})}n(he,"be");function ft(s,t){let e=document.createElement("canvas");return e.width=s,e.height=t,e}n(ft,"gt");function Ke(s,t){return new Promise((e,i)=>{s.toBlob(a=>a?e(a):i(new Error("toBlob failed")),"image/jpeg",t)})}n(Ke,"ti");async function ye(s,t,e,i,a){let h=ft(e,i),o=ft(1,1);try{let l=h.getContext("2d");if(l===null)throw new Error("2d context unavailable");l.imageSmoothingQuality="high",l.drawImage(s,t.x,t.y,t.width,t.height,0,0,e,i);let r=await Ke(h,Qe),c=a===null?null:Ut({topLeft:{x:a.x,y:a.y},topRight:{x:a.x+a.width,y:a.y},bottomRight:{x:a.x+a.width,y:a.y+a.height},bottomLeft:{x:a.x,y:a.y+a.height}},{width:e,height:i},{width:e,height:i}),u=Kt(h,c),f=ge(e,i,Ne);return o.width=Math.max(1,Math.round(e*f)),o.height=Math.max(1,Math.round(i*f)),o.getContext("2d")?.drawImage(h,0,0,o.width,o.height),{blob:r,previewDataUrl:o.toDataURL("image/jpeg",.85),sharpness:u}}finally{h.width=0,h.height=0,o.width=0,o.height=0}}n(ye,"ke");function Ye(s,t){let e=Math.min(1,t/s.width),i=ft(Math.max(1,Math.round(s.width*e)),Math.max(1,Math.round(s.height*e)));try{let a=i.getContext("2d",{willReadFrequently:!0});return a===null?null:(a.imageSmoothingQuality="high",a.drawImage(s,0,0,i.width,i.height),a.getImageData(0,0,i.width,i.height))}finally{i.width=0,i.height=0}}n(Ye,"ei");async function Ve(s,t,e,i){let a={width:Math.max(1,s.videoWidth),height:Math.max(1,s.videoHeight)},h=pe(t,e,a,i);return{...await ye(s,h.crop,h.width,h.height,h.docRegion),docRegion:h.docRegion,source:"video",width:h.width,height:h.height}}n(Ve,"De");async function Ze(s,t,e,i,a){let h=Me();if(h===null)return null;let o=null;try{let l=new h(a.track),r=await he(l.getPhotoCapabilities?.()??Promise.resolve({}),ae).catch(()=>({})),c=await he(l.takePhoto(je(r)),ae);o=await createImageBitmap(c);let u={width:s.videoWidth,height:s.videoHeight};if(!Be(o,u))return null;let f=Ye(o,a.detectWidth),d=null;f!==null&&t!==null&&(d=await a.detect(f).catch(()=>null));let m=f??{width:o.width,height:o.height};d!==null&&!He(d,m,t,e)&&(d=null);let g=pe(d,m,o,i);return{...await ye(o,g.crop,g.width,g.height,g.docRegion),docRegion:g.docRegion,source:"photo",width:g.width,height:g.height}}catch{return null}finally{o?.close()}}n(Ze,"xe");var yt=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}),R=n((s,t,e)=>typeof s=="number"&&Number.isFinite(s)&&s>=t&&s<=e?s:void 0,"S");function Ri(s){let t=yt,e=s!==null&&typeof s=="object"?s:{},i=e.fillDistanceM!==null&&typeof e.fillDistanceM=="object"?e.fillDistanceM:{},a=n((h,o)=>typeof h=="boolean"?h:o,"n");return{width:R(e.width,640,7680)??t.width,height:R(e.height,480,4320)??t.height,lensSelection:a(e.lensSelection,t.lensSelection),continuousFocus:a(e.continuousFocus,t.continuousFocus),refocusBeforePhotoMs:R(e.refocusBeforePhotoMs,0,2e3)??t.refocusBeforePhotoMs,zoomMax:R(e.zoomMax,1,5)??t.zoomMax,zoomNoFocusInfo:R(e.zoomNoFocusInfo,1,5)??t.zoomNoFocusInfo,zoomMinSourcePx:R(e.zoomMinSourcePx,0,8e3)??t.zoomMinSourcePx,fillDistanceM:{id1:R(i.id1,.03,1)??t.fillDistanceM.id1,id3:R(i.id3,.03,1)??t.fillDistanceM.id3},focusMarginFrac:R(e.focusMarginFrac,0,2)??t.focusMarginFrac,stillSharpnessMin:R(e.stillSharpnessMin,0,10)??t.stillSharpnessMin,stillRefusalsMax:R(e.stillRefusalsMax,0,10)??t.stillRefusalsMax,focusFarFillFrac:R(e.focusFarFillFrac,0,1)??t.focusFarFillFrac,noDocFarHintMs:R(e.noDocFarHintMs,0,6e4)??t.noDocFarHintMs,zoomFallbackMs:R(e.zoomFallbackMs,0,12e4)??t.zoomFallbackMs}}n(Ri,"Si");var mt="sekyro.doc.camera";function Je(){try{let s=globalThis.localStorage?.getItem(mt);return typeof s=="string"&&s!==""?s:null}catch{return null}}n(Je,"ii");function oe(s){try{s===null?globalThis.localStorage?.removeItem(mt):globalThis.localStorage?.setItem(mt,s)}catch{}}n(oe,"we");var gt=n((s,t)=>Array.isArray(s?.focusMode)&&s.focusMode.includes(t),"rt");function re(s,t,e){if(!gt(s,"single-shot"))return null;let i=n(a=>Math.min(1,Math.max(0,Number.isFinite(a)?a:.5)),"o");return{focusMode:"single-shot",pointsOfInterest:[{x:i(t),y:i(e)}]}}n(re,"Mt");function $e(s,t,e,i=yt){let a=s?.zoom?.min,h=s?.zoom?.max;if(typeof h!="number"||h<=1)return 1;let o=e==="ID-3"?i.fillDistanceM.id3:i.fillDistanceM.id1,l=s?.focusDistance?.min,r;if(typeof l=="number"&&l>0&&l<1){if(r=l*(1+i.focusMarginFrac)/o,r<=1.05)return 1}else{if(Math.min(t.width,t.height)<i.zoomMinSourcePx)return 1;r=i.zoomNoFocusInfo}let c=Math.min(r,i.zoomMax,h);typeof a=="number"&&(c=Math.max(c,a));let u=s?.zoom?.step;return typeof u=="number"&&u>0&&(c=Math.round(c/u)*u),c>1.01?Number(c.toFixed(2)):1}n($e,"Se");function pt(s){try{return s.getVideoTracks?.()[0]}catch{return}}n(pt,"yt");function le(s){if(s!==null)for(let t of s.getTracks())t.stop()}n(le,"ve");function ti(s){try{let t=pt(s)?.getCapabilities?.();return!Array.isArray(t?.focusMode)||t.focusMode.includes("continuous")}catch{return!0}}n(ti,"oi");async function ei(s){let t=n(h=>({audio:!1,video:{...h,width:{ideal:s.base.width},height:{ideal:s.base.height}}}),"t"),e=n(h=>s.getUserMedia(t({deviceId:{exact:h}})),"e"),i=n(()=>s.getUserMedia(t({facingMode:{ideal:"environment"}})),"o");if(s.lensSelection){let h=Je();if(h!==null)try{return{stream:await e(h),lens:"stored"}}catch{oe(null)}}let a=await i();if(!s.lensSelection||s.enumerateDevices===void 0)return{stream:a,lens:"default"};try{let h=Bt(await s.enumerateDevices()).slice(0,3);if(h.length===0)return{stream:a,lens:"default"};let o=null;for(let l of h){let r=a!==null?pt(a)?.getSettings?.().deviceId:void 0;if(a===null||r!==l){le(a),a=null;try{a=await e(l)}catch{continue}}if(o??(o=l),ti(a))return oe(l),{stream:a,lens:"selected"}}if(a!==null&&o!==null&&pt(a)?.getSettings?.().deviceId===o)return{stream:a,lens:"selected"};if(le(a),a=null,o!==null)try{return{stream:await e(o),lens:"selected"}}catch{}return{stream:await i(),lens:"default"}}catch{return{stream:a??await i(),lens:"default"}}}n(ei,"Te");var ht=Object.freeze({brightness:0,glare:0,cardGlare:0,sharpness:0,fill:0,shape:0,content:0,offsetX:0,offsetY:0,edgeConfidence:0,box:null}),A=n(s=>Math.min(1,Math.max(0,s)),"L");function ii(s,t,e,i=.06){let a=Math.max(s.width/e,s.height),h=a*e,o=(s.width-h)/2,l=(s.height-a)/2,r=A((t.x-t.width*i-o)/h),c=A((t.y-t.height*i-l)/a),u=A((t.x+t.width*(1+i)-o)/h),f=A((t.y+t.height*(1+i)-l)/a);return{x:r,y:c,width:u-r,height:f-c}}n(ii,"Re");function si(s,t,e={}){let i=e.edgePeakFrac??0,{width:a,height:h,data:o}=s;if(a<=0||h<=0)return ht;let l=A(t.x),r=A(t.y),c={x:l,y:r,width:Math.max(0,A(t.x+t.width)-l),height:Math.max(0,A(t.y+t.height)-r)};if(c.width<=0||c.height<=0)return ht;let u=c.x*a,f=c.y*h,d=(c.x+c.width)*a,m=(c.y+c.height)*h,g=(d-u)*.15,b=(m-f)*.15,w=n((p,M,_)=>Math.min(_,Math.max(M,p)),"y"),k=w(Math.floor(u-g),0,a-1),S=w(Math.floor(f-b),0,h-1),D=w(Math.ceil(d+g),k+1,a),I=w(Math.ceil(m+b),S+1,h),F=Math.max(1,Math.ceil(Math.max(D-k,I-S)/320)),y=Math.floor((D-k+F-1)/F),x=Math.floor((I-S+F-1)/F);if(y<3||x<3)return ht;let v=new Int32Array(y*x);for(let p=0;p<x;p++){let M=S+p*F;for(let _=0;_<y;_++){let T=(M*a+k+_*F)*4;v[p*y+_]=(o[T]??0)*77+(o[T+1]??0)*150+(o[T+2]??0)*29>>8}}let L=n((p,M)=>(p-M-.5)/F,"C"),B=L(u,k),rt=L(d,k),lt=L(f,S),nt=L(m,S),wt=(d-u)/F,bt=(m-f)/F,kt=w(Math.ceil(B),0,y-1),we=w(Math.floor(rt),kt,y-1),xt=w(Math.ceil(lt),0,x-1),be=w(Math.floor(nt),xt,x-1),vt=0,St=0,H=0,Ft=0,Rt=0,Q=0;for(let p=xt;p<=be;p++)for(let M=kt;M<=we;M++){let _=v[p*y+M];if(vt+=_,_>=248&&St++,H++,M>=1&&M<y-1&&p>=1&&p<x-1){let T=v[p*y+M-1]+v[p*y+M+1]+v[(p-1)*y+M]+v[(p+1)*y+M]-4*_;Ft+=T,Rt+=T*T,Q++}}let ke=H>0?vt/H:0,_t=H>0?St/H:0,Dt=Q>0?Ft/Q:0,xe=Q>0?Math.max(0,Rt/Q-Dt*Dt):0,X=new Float64Array(y),U=new Float64Array(x);for(let p=0;p<x;p++)for(let M=1;M<y-1;M++)X[M]=X[M]+Math.abs(v[p*y+M+1]-v[p*y+M-1]);for(let p=1;p<x-1;p++)for(let M=0;M<y;M++)U[p]=U[p]+Math.abs(v[(p+1)*y+M]-v[(p-1)*y+M]);let O=st(X,!0,B,i),E=st(X,!1,rt,i),P=st(U,!0,lt,i),W=st(U,!1,nt,i),Tt=(E.position-O.position)/wt,At=(W.position-P.position)/bt,ve=At>0?Tt/At:0,Se=((O.position+E.position)/2-(B+rt)/2)/wt,Fe=((P.position+W.position)/2-(lt+nt)/2)/bt,zt=ne(X),Ct=ne(U),Re=zt<=0||Ct<=0?0:Math.min(Math.min(O.value,E.value)/zt,Math.min(P.value,W.value)/Ct),J=n((p,M)=>M+(p+.5)*F,"$"),It=_t,Lt=0;{let p=(E.position-O.position)*.06,M=(W.position-P.position)*.06,_=w(Math.ceil(O.position+p),0,y-1),T=w(Math.floor(E.position-p),0,y-1),_e=w(Math.ceil(P.position+M),0,x-1),Ot=w(Math.floor(W.position-M),0,x-1),Et=0,$=0,Pt=0;for(let N=_e;N<=Ot;N++)for(let q=_;q<=T;q++){$++;let K=v[N*y+q];K>=248&&Et++;let De=q+2<=T?v[N*y+q+2]:K,Te=N+2<=Ot?v[(N+2)*y+q]:K;(Math.abs(De-K)>=24||Math.abs(Te-K)>=24)&&Pt++}$>=16&&(It=Et/$,Lt=Pt/$)}return{brightness:ke,glare:_t,cardGlare:It,sharpness:xe,fill:Tt,shape:ve,content:Lt,offsetX:Se,offsetY:Fe,edgeConfidence:Re,box:{left:J(O.position,k),right:J(E.position,k),top:J(P.position,S),bottom:J(W.position,S)}}}n(si,"Fe");function st(s,t,e,i){let a=s.length,h=Math.max(1,Math.floor(a*.45)),o=t?1:Math.max(1,a-1-h),l=t?Math.min(a-2,h):a-2,r=o;for(let m=o;m<=l;m++)s[m]>s[r]&&(r=m);if(i>0&&i<1){let m=s[r]*i,g=r,b=Math.abs(r-e);for(let w=o;w<=l;w++){let k=s[w];if(k<m||k<(s[w-1]??0)||k<(s[w+1]??0))continue;let S=Math.abs(w-e);S<b&&(g=w,b=S)}r=g}let c=r>0?s[r-1]:0,u=s[r],f=r<a-1?s[r+1]:0,d=c+u+f;return{position:d>0?r+(f-c)/d:r,value:u}}n(st,"at");function ne(s){if(s.length<3)return 0;let t=0;for(let e=1;e<s.length-1;e++)t+=s[e];return t/(s.length-2)}n(ne,"_e");function ai(s){let t=s.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}}}n(ai,"Ce");var ot=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 _i(s){let t=s!==null&&typeof s=="object"?s:{},e={...ot};for(let i of Object.keys(ot)){let a=t[i];typeof a=="number"&&Number.isFinite(a)&&a>=0&&a<=1e6&&(e[i]=a)}return e}n(_i,"Ai");var j,hi=(j=class{constructor(t=ot){this.t=t,this.goodSince=null,this.steadySince=null,this.last=null}reset(){this.goodSince=null,this.steadySince=null,this.last=null}tick(t,e){let i=this.t,a=i.shapeTolerance<=0||Math.abs(t.shape-1)<=i.shapeTolerance,h=t.edgeConfidence>=i.edgeConfidenceMin&&a&&t.content>=i.contentMin,o=t.fill>=i.fillMin&&t.fill<=i.fillMax,l=Math.abs(t.offsetX)<=i.offsetMax&&Math.abs(t.offsetY)<=i.offsetMax,r=t.cardGlare<=i.glareMax,c=t.sharpness>=i.sharpnessMin,u=this.last;this.last={fill:t.fill,offsetX:t.offsetX,offsetY:t.offsetY,at:e};let f=u!==null&&i.steadyRefMs>0?Math.min(3,Math.max(1,(e-u.at)/i.steadyRefMs)):1,d=h&&r&&c&&t.fill>=i.steadyFillMin&&t.fill<=i.steadyFillMax&&u!==null&&Math.abs(t.fill-u.fill)<=i.steadyFillDelta*f&&Math.abs(t.offsetX-u.offsetX)<=i.steadyOffsetDelta*f&&Math.abs(t.offsetY-u.offsetY)<=i.steadyOffsetDelta*f,m=h&&o&&l&&r&&c,g;if(h?r?t.fill<i.fillMin?g="too_small":t.fill>i.fillMax?g="too_big":c?l?g="locking":g="off_center":g="blurry":g="glare":g="no_card",m){if(d&&(this.steadySince??(this.steadySince=e)),this.goodSince??(this.goodSince=e),e-this.goodSince>=i.lockMs)return{detected:h,ready:!0,via:"good",blocker:"locking"};let b=this.steadySince!==null&&e-this.steadySince>=i.steadyMs;return{detected:h,ready:b,via:b?"steady":null,blocker:"locking"}}if(this.goodSince=null,d){this.steadySince??(this.steadySince=e);let b=e-this.steadySince>=i.steadyMs;return{detected:h,ready:b,via:b?"steady":null,blocker:b?"locking":"steadying"}}return this.steadySince=null,{detected:h,ready:!1,via:null,blocker:g}}},n(j,"ct"),j),Z=null;async function oi(s){return Z===null&&(Z=(await import("./detector-scanic-23DAYT3H-AJXQA7H4.js")).detectQuad),Z(s)}n(oi,"ni");async function ri(s){let t=Jt(s);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}}}n(ri,"si");function Di(){Z===null&&import("./detector-scanic-23DAYT3H-AJXQA7H4.js").then(s=>{Z=s.detectQuad}).catch(()=>{})}n(Di,"ji");var ce=4e3,li=2,ue=3,ni=Object.freeze({LOW:3,MID:5,HIGH:6}),Mt=Object.freeze({manualShutterMs:6e3,detectedNoLockMs:1950});function Ti(s){let t=s!==null&&typeof s=="object"?s:{},e=n((i,a,h)=>typeof i=="number"&&Number.isFinite(i)&&i>=a&&i<=h?i:void 0,"e");return{manualShutterMs:e(t.manualShutterMs,1e3,6e4)??Mt.manualShutterMs,detectedNoLockMs:e(t.steadyMs,300,3e4)!==void 0?t.steadyMs+(e(t.lockMs,0,1e4)??450):Mt.detectedNoLockMs}}n(Ti,"Yi");var z,Ai=(z=class{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=z.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 ze,this.lastFeedbackKey=null,this.lastQuad=null,this.lastDetect=null,this.frameWatch=null,this.reopened=!1,this.lit=!1,this.blackTicks=0,this.offEnded=null,this.opts=t,this.gate=new ee(t.format??"ID-1",t.thresholds);let e=t.deviceClass??Qt(Ht());this.deviceClass=e,this.camera=t.camera??yt,this.shutterTuning=t.shutter??Mt,this.guideTuning=t.guideLock??ot,this.guideLock=new hi(this.guideTuning),this.cadenceMs=1e3/ni[e]}on(t,e){let i=this.handlers.get(t);return i||(i=new Set,this.handlers.set(t,i)),i.add(e),()=>i?.delete(e)}emit(t,e){for(let i of[...this.handlers.get(t)??[]])i(e)}async start(){let t=this.state==="error"?this.resumePlayback():null,e=++this.attempt;if(this.clearFrameWatch(),this.gate.reset(),this.resetSide(),this.feedback.reset(),this.lastFeedbackKey=null,this.lastGuidance=null,this.capturing=!1,this.lit=!1,this.blackTicks=0,t!==null&&await t&&e===this.attempt){this.setState("positioning"),this.scheduleTick(e),this.watchFrames(e);return}if(e===this.attempt){this.releaseStream(),jt(),this.setState("preflight");try{let i=this.opts.getUserMedia??(o=>navigator.mediaDevices.getUserMedia(o));this.setState("acquiring");let a=this.opts.enumerateDevices??(this.opts.getUserMedia===void 0&&typeof navigator<"u"&&navigator.mediaDevices?.enumerateDevices?()=>navigator.mediaDevices.enumerateDevices():void 0),h=await ei({getUserMedia:i,...a!==void 0?{enumerateDevices:a}:{},lensSelection:this.camera.lensSelection,base:Ee});if(e!==this.attempt){for(let o of h.stream.getTracks())o.stop();return}if(this.stream=h.stream,Wt(this.stream),Gt(this.stream),this.watchEnded(e),this.opts.upgradeResolution!==!1&&await this.upgradeResolution(),e!==this.attempt||(await this.applyFocusAndZoom(),e!==this.attempt)||(this.opts.video.srcObject=this.stream,await this.opts.video.play().catch(()=>{}),e!==this.attempt))return;this.setState("positioning"),this.scheduleTick(e),this.watchFrames(e)}catch(i){if(e!==this.attempt)return;let a=qt(i),h=Nt(i);this.setState("error"),this.emit("error",{kind:a,retryable:!0,detail:h===void 0?{phase:"acquiring"}:{phase:"acquiring",name:h}})}}}resumePlayback(){let t=this.opts.video,e=this.videoTrack();if(this.stream===null||e===null||e.readyState!=="live"||t.srcObject!==this.stream)return null;try{return Promise.resolve(t.play()).then(()=>this.framesNow(),()=>!1)}catch{return null}}framesNow(){let t=this.opts.video;return this.opts.hasFrames!==void 0?this.opts.hasFrames(t):!t.paused&&t.readyState>=2&&t.videoWidth>0}watchFrames(t){let e=this.opts.firstFrameMs??ce;e<=0||(this.clearFrameWatch(),this.frameWatch=setTimeout(()=>{if(this.frameWatch=null,!(t!==this.attempt||this.state!=="positioning")){if(this.framesNow()&&this.blackTicks<ue){this.reopened=!1;return}this.cameraDead(t)}},e))}clearFrameWatch(){this.frameWatch!==null&&clearTimeout(this.frameWatch),this.frameWatch=null}watchEnded(t){this.offEnded?.(),this.offEnded=null;let e=this.videoTrack();if(e===null||typeof e.addEventListener!="function")return;let i=n(()=>{t===this.attempt&&(this.state==="positioning"||this.state==="acquiring")&&this.cameraDead(t)},"o");e.addEventListener("ended",i),this.offEnded=()=>e.removeEventListener?.("ended",i)}cameraDead(t){if(t!==this.attempt)return;let e=this.videoTrack(),i=e!==null&&e.readyState==="live"&&!e.muted&&this.opts.video.paused&&!this.framesNow();if(!i&&!this.reopened){this.reopened=!0,this.start();return}this.attempt+=1,this.timer!==null&&(this.opts.clearTimer??clearTimeout)(this.timer),this.timer=null,this.clearFrameWatch(),i||this.releaseStream(),this.reopened=!1,this.setState("error"),this.emit("error",{kind:"generic",retryable:!0,detail:{phase:"acquiring"}})}releaseStream(){if(this.offEnded?.(),this.offEnded=null,this.stream)for(let t of this.stream.getTracks())t.stop();this.stream=null,this.opts.video.srcObject!==null&&this.opts.video.srcObject!==void 0&&(this.opts.video.srcObject=null)}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,e=this.lastDetect?.width??Math.max(1,t.videoWidth),i=this.lastDetect?.height??Math.max(1,t.videoHeight),a=this.lastQuad??this.lastGuideQuad??{topLeft:{x:0,y:0},topRight:{x:e,y:0},bottomRight:{x:e,y:i},bottomLeft:{x:0,y:i}},h=(this.opts.now??(()=>performance.now()))(),o=this.feedback.force("processing",h);this.lastFeedbackKey=o.key,this.emit("feedback",o),await this.fire(this.attempt,this.lastOcrReady!==null?this.lastOcrReady.quad:a,{width:e,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 e=(this.opts.format??"ID-1")==="ID-3"||this.opts.side==="single"?"single":this.opts.side==="verso"?"verso":"recto",i=t.report(e,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 e=t.width/Math.max(1,t.height),i=this.opts.guide;if(i!==void 0&&i.viewAspect>0){let l={width:i.viewAspect,height:1},r={x:i.rect.x*i.viewAspect,y:i.rect.y,width:i.rect.width*i.viewAspect,height:i.rect.height};return ii(l,r,e,0)}let a=Vt(this.opts.format??"ID-1").center,h=.86,o=h*e/a;return o>.84&&(o=.84,h=o*a/e),{x:(1-h)/2,y:(1-o)/2,width:h,height:o}}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=z.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 e=this.videoTrack();if(e===null||this.zoom<=1)return;let i=this.focusCaps(),a=typeof i?.zoom?.min=="number"?Math.max(i.zoom.min,1):1;this.zoom=a,this.stats.zoomFallbackAtMs=Math.round(t-(this.positioningSince??t)),this.guideLock.reset(),this.gate.reset(),e.applyConstraints({advanced:[{zoom:a}]}).catch(()=>{})}offerShutter(t,e){this.shutterOffered||(this.shutterOffered=!0,this.stats.shutterAtMs=Math.round(e-(this.positioningSince??e)),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.clearFrameWatch(),this.offEnded?.(),this.offEnded=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 e=t.getSettings?.()??{},i=Ge(t.getCapabilities?.(),{width:e.width??0,height:e.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 e=this.focusCaps();this.camera.continuousFocus&&gt(e,"continuous")&&await t.applyConstraints({advanced:[{focusMode:"continuous"}]}).catch(()=>{});let i={width:0,height:0};try{let h=t.getSettings?.()??{};i={width:h.width??0,height:h.height??0}}catch{}let a=$e(e,i,this.opts.format??"ID-1",this.camera);if(a>1)try{await t.applyConstraints({advanced:[{zoom:a}]}),this.zoom=a}catch{this.zoom=1}}async focusAt(t,e){let i=this.videoTrack(),a=re(this.focusCaps(),t,e);if(!(i===null||a===null))try{await i.applyConstraints({advanced:[a]}),(this.opts.setTimer??setTimeout)(()=>{this.restoreContinuous()},1500)}catch{}}async restoreContinuous(){let t=this.videoTrack();t===null||!this.camera.continuousFocus||!gt(this.focusCaps(),"continuous")||await t.applyConstraints({advanced:[{focusMode:"continuous"}]}).catch(()=>{})}async refocusOn(t,e){let i=this.camera.refocusBeforePhotoMs,a=this.videoTrack();if(i<=0||a===null||e.width<=0||e.height<=0)return;let h=C(t),o=re(this.focusCaps(),(h.x+h.width/2)/e.width,(h.y+h.height/2)/e.height);if(o!==null)try{await a.applyConstraints({advanced:[o]});let l=this.opts.setTimer??setTimeout;await new Promise(r=>{l(()=>r(),i)})}catch{}}videoTrack(){try{return this.stream?.getVideoTracks?.()[0]??null}catch{return null}}async takeStill(t,e,i){if(this.opts.captureStill!==void 0)return this.opts.captureStill(this.opts.video,t,e);let a=this.opts.format??"ID-1",h=this.videoTrack();if(i&&this.opts.photoCapture!==!1&&this.deviceClass!=="LOW"&&!this.torchOn&&h!==null&&Ue(h)){await this.refocusOn(t,e);let o=await Ze(this.opts.video,t,e,a,{track:h,detect:this.detector(),detectWidth:tt});if(this.restoreContinuous(),o!==null)return o}return Ve(this.opts.video,t,e,a)}detector(){return this.opts.detect??((this.opts.format??"ID-1")==="ID-3"?ri:oi)}setState(t){this.state=t,this.emit("statechange",{state:t})}scheduleTick(t){let e=this.opts.setTimer??setTimeout;this.timer=e(()=>{this.tick(t)},this.cadenceMs)}async tick(t){if(t!==this.attempt||this.state!=="positioning"||this.capturing)return;let e=this.opts.now??(()=>performance.now()),i=this.opts.grabDetectFrame??fe,a=this.detector(),h=i(this.opts.video,tt);if(h===null){this.scheduleTick(t);return}if(!this.lit){if(ut(h)>li)this.lit=!0,this.blackTicks=0;else if(++this.blackTicks>=ue&&this.frameWatch===null&&(this.opts.firstFrameMs??ce)>0){this.cameraDead(t);return}}let o=null;try{o=await a(h)}catch{o=null}if(t!==this.attempt)return;let l=o!==null?at(h,o):h,r=e(),c={sharpness:Y(l),exposure:Xt(l),meanLuma:ut(l),specularFraction:Ie(l)},u=Oe({format:this.opts.format??"ID-1",quad:o,frameWidth:h.width,frameHeight:h.height,measures:c,...this.opts.thresholds!==void 0?{thresholds:this.opts.thresholds}:{}}),f=this.gate.tick({timestampMs:r,quad:o,quality:c,frameWidth:h.width,frameHeight:h.height}),d=(this.opts.format??"ID-1")!=="ID-3"?si(h,this.guideRegion(h),{edgePeakFrac:this.guideTuning.edgePeakFrac}):ht,m=this.guideLock.tick(d,r);this.lastGuideQuad=m.detected?ai(d):null;let g=this.capturing?null:this.ocrTick(h,o,d,m.detected,u,r);this.positioningSince??(this.positioningSince=r);let b=this.stats;if(b.ticks+=1,b.quadFraming[u.framing]=(b.quadFraming[u.framing]??0)+1,u.framing==="ok"&&!f.ready){let x=u.lighting!=="ok"?u.lighting:u.glare!=="ok"?"glare":u.blur!=="ok"?"blurry":"steadying";b.qualityBlockers[x]=(b.qualityBlockers[x]??0)+1}b.guideBlockers[m.blocker]=(b.guideBlockers[m.blocker]??0)+1,o!==null||m.detected?(this.detectedSince??(this.detectedSince=r),this.lastSeenAt=r):this.detectedSince=null,this.lastSeenAt!==null&&r-this.lastSeenAt<=pi?r-this.positioningSince>=this.shutterTuning.manualShutterMs?this.offerShutter("timeout",r):g?.suspendQuality!==!0&&this.detectedSince!==null&&r-this.detectedSince>=this.shutterTuning.detectedNoLockMs&&this.offerShutter("detected_no_lock",r):this.withdrawShutter();let w=r-(this.lastSeenAt??this.positioningSince);this.zoom>1&&this.camera.zoomFallbackMs>0&&w>=this.camera.zoomFallbackMs&&this.zoomFallback(r),this.emit("checks",{engine:"docv1",p:f.p,plausible:f.plausible,stableTicks:f.stableTicks,quad:f.quad,frameWidth:h.width,frameHeight:h.height,analysis:u,ready:g?.suspendQuality!==!0&&(f.ready&&o!==null||m.ready&&this.lastGuideQuad!==null)||this.lastOcrReady!==null,guide:{detected:m.detected,blocker:m.blocker,fill:d.fill,shape:d.shape,content:d.content,offsetX:d.offsetX,offsetY:d.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=f.plausible?o:null,this.lastDetect={width:h.width,height:h.height,tickSharpness:c.sharpness};let k=Ae(u);u.framing!=="ok"&&m.detected&&(k=gi(m.blocker,d.brightness<this.guideTuning.darkBrightness)),k==="blurry"&&o!==null&&ui(o,h,this.opts.format??"ID-1")>=this.camera.focusFarFillFrac&&(k="focus_far"),k==="sensing"&&this.zoom>1&&this.camera.noDocFarHintMs>0&&w>=this.camera.noDocFarHintMs&&(k="focus_far");let S=this.feedback.tick(k,r);if(S.key!==this.lastFeedbackKey&&(this.lastFeedbackKey=S.key,this.emit("feedback",S)),f.guidanceKey!==this.lastGuidance&&(this.lastGuidance=f.guidanceKey,this.emit("guidance",{key:f.guidanceKey})),this.capturing)return;let D=g?.suspendQuality!==!0,I=D&&f.ready&&o!==null,F=D&&m.ready&&this.lastGuideQuad!==null,y=this.lastOcrReady;if(y!==null&&this.opts.autoCapture!==!1){let x=this.feedback.force("processing",r);this.lastFeedbackKey=x.key,this.emit("feedback",x);let v=Y(at(h,y.quad));await this.fire(t,y.quad,{width:h.width,height:h.height,tickSharpness:v},y.via);return}if((I||F)&&this.opts.autoCapture!==!1){let x=this.feedback.force("processing",r);this.lastFeedbackKey=x.key,this.emit("feedback",x);let v=F?this.lastGuideQuad:o,L=F?m.via==="steady"?"guide_steady":"guide_good":"quad",B=F?Y(at(h,v)):c.sharpness;await this.fire(t,v,{width:h.width,height:h.height,tickSharpness:B},L);return}this.scheduleTick(t)}async fire(t,e,i,a){this.capturing=!0;let h=this.opts.grabDetectFrame??fe,o=this.opts.setTimer??setTimeout,l={width:i.width,height:i.height};try{let r={still:await this.takeStill(e,l,!0),sharpness:i.tickSharpness};if(t!==this.attempt)return;let c=r.still.source==="photo"?0:di;for(let d=0;d<c;d++){if(await new Promise(b=>{o(()=>b(),fi)}),t!==this.attempt)return;let m=h(this.opts.video,tt);if(m===null)continue;let g=Y(at(m,e));if(g>r.sharpness*mi){let b=await this.takeStill(e,l,!1);if(t!==this.attempt)return;r={still:b,sharpness:g}}}if(t!==this.attempt)return;let u=r.still.sharpness;if(this.opts.autoCapture!==!1&&a!=="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,(a==="text_lock"||a==="live_mrz")&&this.opts.ocr?.rearmFace();let d=(this.opts.now??(()=>performance.now()))(),m=this.feedback.force("focus_far",d);this.lastFeedbackKey=m.key,this.emit("feedback",m),this.capturing=!1,this.gate.reset(),this.scheduleTick(t);return}this.stillRefusals=0;let f=(this.opts.now??(()=>performance.now()))();this.stats.via=a,this.stats.msToCapture=Math.round(f-(this.positioningSince??f)),this.shutterOffered&&(this.shutterOffered=!1,this.emit("shutter",{available:!1})),this.setState("captured"),this.emit("artifacts",{keyframe:r.still.blob,previewDataUrl:r.still.previewDataUrl,...this.opts.side!==void 0?{side:this.opts.side}:{},...r.still.docRegion!==void 0?{docRegion:r.still.docRegion}:{},...(()=>{let d=a==="live_mrz"?this.opts.ocr?.liveCapture():null;return d?{liveMrz:d}:{}})()})}catch{if(t!==this.attempt)return;this.capturing=!1,this.gate.reset(),this.guideLock.reset(),this.lastOcrReady=null,(a==="text_lock"||a==="live_mrz")&&this.opts.ocr?.rearmFace(),this.scheduleTick(t)}}ocrTick(t,e,i,a,h,o){let l=this.opts.ocr,r=this.opts.video;if(l===void 0||!l.hasEngine)return this.lastOcrReady=null,null;let c=r.videoWidth,u=r.videoHeight;if(c<=0||u<=0||t.width<=0||t.height<=0)return null;let f=(this.opts.format??"ID-1")==="ID-3",d=this.guideRegion(t),m={x:d.x*c,y:d.y*u,w:d.width*c,h:d.height*u},g=c/t.width,b=u/t.height,w;f&&e!==null?w=ci(C(e),g,b,c,u):w=Yt(m,l.bandTop,u);let k=f?h.glare==="ok":i.cardGlare<=this.guideTuning.glareMax,S=f?h.blur==="ok":i.sharpness>=this.guideTuning.sharpnessMin,D=l.tick({atMs:o,video:r,mrzFace:f||this.opts.side==="verso"||this.opts.side==="single",present:f||e!==null||a,card:m,band:w,portrait:u>c,glareOk:k,sharpOk:S});if(D.ready&&D.via!==void 0){let I=f?e??de(d,t):this.lastGuideQuad??de(d,t);this.lastOcrReady={quad:I,via:D.via}}else this.lastOcrReady=null;return D}},n(z,"i"),z);function ci(s,t,e,i,a){let h=Math.min(i,s.width*1.06*t),o=Math.min(a,Math.max(s.height*1.6*e,h/5)),l=(s.y+s.height/2)*e,r=Math.max(0,Math.min(i-h,(s.x-s.width*.03)*t)),c=Math.max(0,Math.min(a-o,l-o/2));return{x:r,y:c,w:h,h:o}}n(ci,"ci");function de(s,t){let e=s.x*t.width,i=s.y*t.height,a=(s.x+s.width)*t.width,h=(s.y+s.height)*t.height;return{topLeft:{x:e,y:i},topRight:{x:a,y:i},bottomRight:{x:a,y:h},bottomLeft:{x:e,y:h}}}n(de,"Oe");function ui(s,t,e){let i=C(s);return t.width<=0||t.height<=0?0:e==="ID-3"?i.width/t.width:i.width*i.height/(t.width*t.height)}n(ui,"li");var di=2,fi=260,mi=1.08;function fe(s,t){let e=s.videoWidth,i=s.videoHeight;if(e===0||i===0)return null;let a=Math.min(1,t/e),h=Math.round(e*a),o=Math.round(i*a),l=document.createElement("canvas");l.width=h,l.height=o;let r=l.getContext("2d",{willReadFrequently:!0});return r===null?null:(e/Math.max(1,h)>4&&(r.imageSmoothingQuality="high"),r.drawImage(s,0,0,h,o),r.getImageData(0,0,h,o))}n(fe,"Pe");function at(s,t){let e=[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],a=Math.max(0,Math.floor(Math.min(...e))),h=Math.max(0,Math.floor(Math.min(...i))),o=Math.min(s.width,Math.ceil(Math.max(...e))),l=Math.min(s.height,Math.ceil(Math.max(...i))),r=Math.max(1,o-a),c=Math.max(1,l-h),u=new Uint8ClampedArray(r*c*4);for(let f=0;f<c;f++){let d=((h+f)*s.width+a)*4;u.set(s.data.subarray(d,d+r*4),f*r*4)}return{data:u,width:r,height:c,colorSpace:s.colorSpace}}n(at,"lt");function gi(s,t){return s==="glare"?"glare":s==="too_small"?"too_far":s==="too_big"?"too_close":t?"too_dark":s==="blurry"?"blurry":s==="off_center"?"edge_clipped":s==="no_card"?"sensing":"hold_still"}n(gi,"mi");var pi=1200;export{Ri as a,_i as b,Di as c,ce as d,li as e,ue as f,ni as g,Mt as h,Ti as i,Ai as j,ci as k,di as l,fi as m};
1
+ import{a as tt,b as $t,c as te,d as dt,e as ee}from"./chunk-WPRIGJHG.js";import{a as Ut,b as Kt,e as Yt}from"./chunk-2FETDQV5.js";import{a as Vt,b as Zt}from"./chunk-EWTKC2C2.js";import{b as Jt}from"./chunk-L22GFJQV.js";import{d as Wt,e as Ht,f as Qt}from"./chunk-GIGTK355.js";import{a as ct,b as ut,c as Y,d as Xt}from"./chunk-P7K7ELYZ.js";import{g as Nt,i as qt,j as Gt,k as jt,l as Bt}from"./chunk-JS2IXPNL.js";import{a as n}from"./chunk-4FHWXBOB.js";var et=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 Ae(s){return s.framing==="no_document"?"sensing":s.framing==="too_far"?"too_far":s.framing==="too_close"?"too_close":s.framing==="edge_clipped"?"edge_clipped":s.framing==="wrong_shape"?"wrong_shape":s.framing==="tilted"?"tilted":s.lighting==="too_dark"?"too_dark":s.lighting==="too_bright"?"too_bright":s.glare==="glare"?"glare":s.blur==="blurry"?"blurry":"hold_still"}n(Ae,"ne");var G,ze=(G=class{constructor(t=2600,e=.35){this.windowMs=t,this.decayPerSecond=e,this.votes=[],this.current=et.sensing,this.currentSinceMs=null}reset(){this.votes=[],this.current=et.sensing,this.currentSinceMs=null}force(t,e){return this.votes=[],this.current=et[t],this.currentSinceMs=e,this.current}tick(t,e){if(this.currentSinceMs===null&&(this.currentSinceMs=e),this.votes.push({key:t,atMs:e}),this.votes=this.votes.filter(o=>e-o.atMs<=this.windowMs),e-this.currentSinceMs<this.current.minDurationMs)return this.current;let i=new Map;for(let o of this.votes){let l=(e-o.atMs)/1e3,r=this.decayPerSecond**l;i.set(o.key,(i.get(o.key)??0)+r)}let a=this.current.key,h=-1;for(let[o,l]of i)l>h&&(h=l,a=o);return a!==this.current.key&&(this.current=et[a],this.currentSinceMs=e),this.current}},n(G,"ot"),G),Ce=Object.freeze({MAX_AREA_FRAC:.92,TILT_MAX_SIDE_RATIO:1.3,GLARE_MAX_SPECULAR_FRAC:.025});function Ie(s){let{data:t,width:e,height:i}=s,a=e*i;if(a===0)return 0;let h=0;for(let o=0;o<a;o++){let l=o*4;.299*(t[l]??0)+.587*(t[l+1]??0)+.114*(t[l+2]??0)>=252&&h++}return h/a}n(Ie,"re");function Le(s){let t=n((r,c)=>Math.hypot(c.x-r.x,c.y-r.y),"t"),e=t(s.topLeft,s.topRight),i=t(s.bottomLeft,s.bottomRight),a=t(s.topLeft,s.bottomLeft),h=t(s.topRight,s.bottomRight),o=Math.max(e,i)/Math.max(1e-6,Math.min(e,i)),l=Math.max(a,h)/Math.max(1e-6,Math.min(a,h));return Math.max(o,l)}n(Le,"je");function Oe(s){let t={...$t,...s.thresholds},e=Ce,{quad:i,frameWidth:a,frameHeight:h,measures:o}=s,l=s.format==="ID-3",r="ok";if(i===null)r="no_document";else if(l){let d=dt(i),m=a>0?d.width/a:0,g=d.height>0?d.width/d.height:0;m<t.ID3_BAND_MIN_WIDTH_FRAC?r="too_far":ie(i,a,h,t.EDGE_CLIP_MARGIN_PX)?r="edge_clipped":(g<t.ID3_BAND_ASPECT_MIN||g>t.ID3_BAND_ASPECT_MAX)&&(r="wrong_shape")}else{let d=te(i,a,h),m=dt(i),g=Math.max(m.width,m.height)/Math.max(1e-6,Math.min(m.width,m.height));d<t.MIN_AREA_FRAC?r="too_far":d>e.MAX_AREA_FRAC?r="too_close":ie(i,a,h,t.EDGE_CLIP_MARGIN_PX)?r="edge_clipped":Zt(s.format,g)?Le(i)>e.TILT_MAX_SIDE_RATIO&&(r="tilted"):r="wrong_shape"}let c=o.exposure>=t.GUIDE_EXPOSURE?"ok":o.meanLuma<(ct[0]+ct[1])/2?"too_dark":"too_bright",u=o.sharpness>=t.GUIDE_SHARPNESS?"ok":"blurry",f=o.specularFraction>=e.GLARE_MAX_SPECULAR_FRAC?"glare":"ok";return{framing:r,lighting:c,blur:u,glare:f,acceptable:r==="ok"&&c==="ok"&&u==="ok"&&f==="ok"}}n(Oe,"ae");function ie(s,t,e,i){return[s.topLeft,s.topRight,s.bottomRight,s.bottomLeft].some(a=>a.x<=i||a.y<=i||a.x>=t-i||a.y>=e-i)}n(ie,"se");var Ee=Object.freeze({width:1920,height:1080}),Pe=Object.freeze({width:3840,height:2160}),se=4096,We=2560,Ne=640,it=.15,V=Object.freeze({side:.2,above:.9,below:.3});function C(s){let t=[s.topLeft.x,s.topRight.x,s.bottomRight.x,s.bottomLeft.x],e=[s.topLeft.y,s.topRight.y,s.bottomRight.y,s.bottomLeft.y],i=Math.min(...t),a=Math.min(...e);return{x:i,y:a,width:Math.max(...t)-i,height:Math.max(...e)-a}}n(C,"E");function me(s,t){let e=Math.max(0,Math.floor(s.x)),i=Math.max(0,Math.floor(s.y)),a=Math.min(t.width,Math.ceil(s.x+s.width)),h=Math.min(t.height,Math.ceil(s.y+s.height));return a-e<16||h-i<16?null:{x:e,y:i,width:a-e,height:h-i}}n(me,"he");function qe(s,t,e){if(s===null||t.width<=0||t.height<=0)return null;let i=C(s);if(i.width<=0||i.height<=0)return null;let a=e==="ID-3"?{x:i.x-i.width*V.side,y:i.y-i.width*V.above,width:i.width*(1+2*V.side),height:i.height+i.width*(V.above+V.below)}:{x:i.x-i.width*it,y:i.y-i.height*it,width:i.width*(1+2*it),height:i.height*(1+2*it)};return me(a,t)}n(qe,"Je");function ge(s,t,e){let i=Math.max(s,t);return i>0?Math.min(1,e/i):1}n(ge,"ft");function pe(s,t,e,i,a=We){let h=t.width>0?e.width/t.width:1,o=t.height>0?e.height/t.height:1,l=s===null?null:{topLeft:{x:s.topLeft.x*h,y:s.topLeft.y*o},topRight:{x:s.topRight.x*h,y:s.topRight.y*o},bottomRight:{x:s.bottomRight.x*h,y:s.bottomRight.y*o},bottomLeft:{x:s.bottomLeft.x*h,y:s.bottomLeft.y*o}},r=qe(l,e,i)??{x:0,y:0,width:e.width,height:e.height},c=ge(r.width,r.height,a),u=Math.max(1,Math.round(r.width*c)),f=Math.max(1,Math.round(r.height*c)),d=null;if(l!==null){let m=C(l);d=me({x:(m.x-r.x)*c,y:(m.y-r.y)*c,width:m.width*c,height:m.height*c},{width:u,height:f})}return{crop:r,width:u,height:f,docRegion:d}}n(pe,"pt");function Ge(s,t,e,i=Pe){if(e==="LOW")return null;let a=s?.width?.max,h=s?.height?.max;if(typeof a!="number"||typeof h!="number"||a<=0||h<=0)return null;let o=Math.max(a,h),l=Math.min(a,h),r=Math.min(o,Math.max(i.width,i.height)),c=Math.min(l,Math.min(i.width,i.height));return r<=Math.max(t.width,t.height)?null:{width:{ideal:r},height:{ideal:c}}}n(Ge,"de");function je(s){let t={},e=s?.imageWidth,i=s?.imageHeight;if(typeof e?.max=="number"&&e.max>0){let a=typeof i?.max=="number"&&i.max>0?e.max/i.max:1.3333333333333333,h=a>=1?se:se*a,o=Math.min(e.max,Math.floor(h)),l=typeof e.step=="number"&&e.step>0?e.step:1,r=typeof e.min=="number"?e.min:0;o=Math.max(r,r+Math.floor((o-r)/l)*l),t.imageWidth=o}return s?.fillLightMode?.includes("off")===!0&&(t.fillLightMode="off"),t}n(je,"me");function Be(s,t){if(s.width<=0||s.height<=0||t.width<=0||t.height<=0)return!1;let e=s.width>s.height,i=t.width>t.height;return e!==i&&s.width!==s.height&&t.width!==t.height?!1:Math.max(s.width,s.height)>=1.2*Math.max(t.width,t.height)}n(Be,"fe");function He(s,t,e,i){if(e===null)return!1;let a=C(s),h=C(e);if(t.width<=0||i.width<=0)return!1;let o=a.width/t.width,l=h.width/i.width;return l>0&&o>=.6*l&&o<=1.25*l}n(He,"pe");var ae=3500,Qe=.92;function Me(){let s=globalThis.ImageCapture;return typeof s=="function"?s:null}n(Me,"ye");function Xe(s){return/AppleWebKit\//.test(s)&&!/(Chrome|Chromium|Edg|OPR)\//.test(s)}n(Xe,"$e");function Ue(s,t=typeof navigator>"u"?"":navigator.userAgent){return Me()!==null&&!Xe(t)&&s!=null&&s.kind==="video"&&s.readyState==="live"}n(Ue,"Me");function he(s,t){return new Promise((e,i)=>{let a=setTimeout(()=>i(new Error("takePhoto timed out")),t);s.then(h=>{clearTimeout(a),e(h)},h=>{clearTimeout(a),i(h)})})}n(he,"be");function ft(s,t){let e=document.createElement("canvas");return e.width=s,e.height=t,e}n(ft,"gt");function Ke(s,t){return new Promise((e,i)=>{s.toBlob(a=>a?e(a):i(new Error("toBlob failed")),"image/jpeg",t)})}n(Ke,"ti");async function ye(s,t,e,i,a){let h=ft(e,i),o=ft(1,1);try{let l=h.getContext("2d");if(l===null)throw new Error("2d context unavailable");l.imageSmoothingQuality="high",l.drawImage(s,t.x,t.y,t.width,t.height,0,0,e,i);let r=await Ke(h,Qe),c=a===null?null:Ut({topLeft:{x:a.x,y:a.y},topRight:{x:a.x+a.width,y:a.y},bottomRight:{x:a.x+a.width,y:a.y+a.height},bottomLeft:{x:a.x,y:a.y+a.height}},{width:e,height:i},{width:e,height:i}),u=Kt(h,c),f=ge(e,i,Ne);return o.width=Math.max(1,Math.round(e*f)),o.height=Math.max(1,Math.round(i*f)),o.getContext("2d")?.drawImage(h,0,0,o.width,o.height),{blob:r,previewDataUrl:o.toDataURL("image/jpeg",.85),sharpness:u}}finally{h.width=0,h.height=0,o.width=0,o.height=0}}n(ye,"ke");function Ye(s,t){let e=Math.min(1,t/s.width),i=ft(Math.max(1,Math.round(s.width*e)),Math.max(1,Math.round(s.height*e)));try{let a=i.getContext("2d",{willReadFrequently:!0});return a===null?null:(a.imageSmoothingQuality="high",a.drawImage(s,0,0,i.width,i.height),a.getImageData(0,0,i.width,i.height))}finally{i.width=0,i.height=0}}n(Ye,"ei");async function Ve(s,t,e,i){let a={width:Math.max(1,s.videoWidth),height:Math.max(1,s.videoHeight)},h=pe(t,e,a,i);return{...await ye(s,h.crop,h.width,h.height,h.docRegion),docRegion:h.docRegion,source:"video",width:h.width,height:h.height}}n(Ve,"De");async function Ze(s,t,e,i,a){let h=Me();if(h===null)return null;let o=null;try{let l=new h(a.track),r=await he(l.getPhotoCapabilities?.()??Promise.resolve({}),ae).catch(()=>({})),c=await he(l.takePhoto(je(r)),ae);o=await createImageBitmap(c);let u={width:s.videoWidth,height:s.videoHeight};if(!Be(o,u))return null;let f=Ye(o,a.detectWidth),d=null;f!==null&&t!==null&&(d=await a.detect(f).catch(()=>null));let m=f??{width:o.width,height:o.height};d!==null&&!He(d,m,t,e)&&(d=null);let g=pe(d,m,o,i);return{...await ye(o,g.crop,g.width,g.height,g.docRegion),docRegion:g.docRegion,source:"photo",width:g.width,height:g.height}}catch{return null}finally{o?.close()}}n(Ze,"xe");var yt=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}),R=n((s,t,e)=>typeof s=="number"&&Number.isFinite(s)&&s>=t&&s<=e?s:void 0,"S");function Ri(s){let t=yt,e=s!==null&&typeof s=="object"?s:{},i=e.fillDistanceM!==null&&typeof e.fillDistanceM=="object"?e.fillDistanceM:{},a=n((h,o)=>typeof h=="boolean"?h:o,"n");return{width:R(e.width,640,7680)??t.width,height:R(e.height,480,4320)??t.height,lensSelection:a(e.lensSelection,t.lensSelection),continuousFocus:a(e.continuousFocus,t.continuousFocus),refocusBeforePhotoMs:R(e.refocusBeforePhotoMs,0,2e3)??t.refocusBeforePhotoMs,zoomMax:R(e.zoomMax,1,5)??t.zoomMax,zoomNoFocusInfo:R(e.zoomNoFocusInfo,1,5)??t.zoomNoFocusInfo,zoomMinSourcePx:R(e.zoomMinSourcePx,0,8e3)??t.zoomMinSourcePx,fillDistanceM:{id1:R(i.id1,.03,1)??t.fillDistanceM.id1,id3:R(i.id3,.03,1)??t.fillDistanceM.id3},focusMarginFrac:R(e.focusMarginFrac,0,2)??t.focusMarginFrac,stillSharpnessMin:R(e.stillSharpnessMin,0,10)??t.stillSharpnessMin,stillRefusalsMax:R(e.stillRefusalsMax,0,10)??t.stillRefusalsMax,focusFarFillFrac:R(e.focusFarFillFrac,0,1)??t.focusFarFillFrac,noDocFarHintMs:R(e.noDocFarHintMs,0,6e4)??t.noDocFarHintMs,zoomFallbackMs:R(e.zoomFallbackMs,0,12e4)??t.zoomFallbackMs}}n(Ri,"Si");var mt="sekyro.doc.camera";function Je(){try{let s=globalThis.localStorage?.getItem(mt);return typeof s=="string"&&s!==""?s:null}catch{return null}}n(Je,"ii");function oe(s){try{s===null?globalThis.localStorage?.removeItem(mt):globalThis.localStorage?.setItem(mt,s)}catch{}}n(oe,"we");var gt=n((s,t)=>Array.isArray(s?.focusMode)&&s.focusMode.includes(t),"rt");function re(s,t,e){if(!gt(s,"single-shot"))return null;let i=n(a=>Math.min(1,Math.max(0,Number.isFinite(a)?a:.5)),"o");return{focusMode:"single-shot",pointsOfInterest:[{x:i(t),y:i(e)}]}}n(re,"Mt");function $e(s,t,e,i=yt){let a=s?.zoom?.min,h=s?.zoom?.max;if(typeof h!="number"||h<=1)return 1;let o=e==="ID-3"?i.fillDistanceM.id3:i.fillDistanceM.id1,l=s?.focusDistance?.min,r;if(typeof l=="number"&&l>0&&l<1){if(r=l*(1+i.focusMarginFrac)/o,r<=1.05)return 1}else{if(Math.min(t.width,t.height)<i.zoomMinSourcePx)return 1;r=i.zoomNoFocusInfo}let c=Math.min(r,i.zoomMax,h);typeof a=="number"&&(c=Math.max(c,a));let u=s?.zoom?.step;return typeof u=="number"&&u>0&&(c=Math.round(c/u)*u),c>1.01?Number(c.toFixed(2)):1}n($e,"Se");function pt(s){try{return s.getVideoTracks?.()[0]}catch{return}}n(pt,"yt");function le(s){if(s!==null)for(let t of s.getTracks())t.stop()}n(le,"ve");function ti(s){try{let t=pt(s)?.getCapabilities?.();return!Array.isArray(t?.focusMode)||t.focusMode.includes("continuous")}catch{return!0}}n(ti,"oi");async function ei(s){let t=n(h=>({audio:!1,video:{...h,width:{ideal:s.base.width},height:{ideal:s.base.height}}}),"t"),e=n(h=>s.getUserMedia(t({deviceId:{exact:h}})),"e"),i=n(()=>s.getUserMedia(t({facingMode:{ideal:"environment"}})),"o");if(s.lensSelection){let h=Je();if(h!==null)try{return{stream:await e(h),lens:"stored"}}catch{oe(null)}}let a=await i();if(!s.lensSelection||s.enumerateDevices===void 0)return{stream:a,lens:"default"};try{let h=Bt(await s.enumerateDevices()).slice(0,3);if(h.length===0)return{stream:a,lens:"default"};let o=null;for(let l of h){let r=a!==null?pt(a)?.getSettings?.().deviceId:void 0;if(a===null||r!==l){le(a),a=null;try{a=await e(l)}catch{continue}}if(o??(o=l),ti(a))return oe(l),{stream:a,lens:"selected"}}if(a!==null&&o!==null&&pt(a)?.getSettings?.().deviceId===o)return{stream:a,lens:"selected"};if(le(a),a=null,o!==null)try{return{stream:await e(o),lens:"selected"}}catch{}return{stream:await i(),lens:"default"}}catch{return{stream:a??await i(),lens:"default"}}}n(ei,"Te");var ht=Object.freeze({brightness:0,glare:0,cardGlare:0,sharpness:0,fill:0,shape:0,content:0,offsetX:0,offsetY:0,edgeConfidence:0,box:null}),A=n(s=>Math.min(1,Math.max(0,s)),"L");function ii(s,t,e,i=.06){let a=Math.max(s.width/e,s.height),h=a*e,o=(s.width-h)/2,l=(s.height-a)/2,r=A((t.x-t.width*i-o)/h),c=A((t.y-t.height*i-l)/a),u=A((t.x+t.width*(1+i)-o)/h),f=A((t.y+t.height*(1+i)-l)/a);return{x:r,y:c,width:u-r,height:f-c}}n(ii,"Re");function si(s,t,e={}){let i=e.edgePeakFrac??0,{width:a,height:h,data:o}=s;if(a<=0||h<=0)return ht;let l=A(t.x),r=A(t.y),c={x:l,y:r,width:Math.max(0,A(t.x+t.width)-l),height:Math.max(0,A(t.y+t.height)-r)};if(c.width<=0||c.height<=0)return ht;let u=c.x*a,f=c.y*h,d=(c.x+c.width)*a,m=(c.y+c.height)*h,g=(d-u)*.15,b=(m-f)*.15,w=n((p,M,_)=>Math.min(_,Math.max(M,p)),"y"),k=w(Math.floor(u-g),0,a-1),S=w(Math.floor(f-b),0,h-1),D=w(Math.ceil(d+g),k+1,a),I=w(Math.ceil(m+b),S+1,h),F=Math.max(1,Math.ceil(Math.max(D-k,I-S)/320)),y=Math.floor((D-k+F-1)/F),x=Math.floor((I-S+F-1)/F);if(y<3||x<3)return ht;let v=new Int32Array(y*x);for(let p=0;p<x;p++){let M=S+p*F;for(let _=0;_<y;_++){let T=(M*a+k+_*F)*4;v[p*y+_]=(o[T]??0)*77+(o[T+1]??0)*150+(o[T+2]??0)*29>>8}}let L=n((p,M)=>(p-M-.5)/F,"C"),B=L(u,k),rt=L(d,k),lt=L(f,S),nt=L(m,S),wt=(d-u)/F,bt=(m-f)/F,kt=w(Math.ceil(B),0,y-1),we=w(Math.floor(rt),kt,y-1),xt=w(Math.ceil(lt),0,x-1),be=w(Math.floor(nt),xt,x-1),vt=0,St=0,H=0,Ft=0,Rt=0,Q=0;for(let p=xt;p<=be;p++)for(let M=kt;M<=we;M++){let _=v[p*y+M];if(vt+=_,_>=248&&St++,H++,M>=1&&M<y-1&&p>=1&&p<x-1){let T=v[p*y+M-1]+v[p*y+M+1]+v[(p-1)*y+M]+v[(p+1)*y+M]-4*_;Ft+=T,Rt+=T*T,Q++}}let ke=H>0?vt/H:0,_t=H>0?St/H:0,Dt=Q>0?Ft/Q:0,xe=Q>0?Math.max(0,Rt/Q-Dt*Dt):0,X=new Float64Array(y),U=new Float64Array(x);for(let p=0;p<x;p++)for(let M=1;M<y-1;M++)X[M]=X[M]+Math.abs(v[p*y+M+1]-v[p*y+M-1]);for(let p=1;p<x-1;p++)for(let M=0;M<y;M++)U[p]=U[p]+Math.abs(v[(p+1)*y+M]-v[(p-1)*y+M]);let O=st(X,!0,B,i),E=st(X,!1,rt,i),P=st(U,!0,lt,i),W=st(U,!1,nt,i),Tt=(E.position-O.position)/wt,At=(W.position-P.position)/bt,ve=At>0?Tt/At:0,Se=((O.position+E.position)/2-(B+rt)/2)/wt,Fe=((P.position+W.position)/2-(lt+nt)/2)/bt,zt=ne(X),Ct=ne(U),Re=zt<=0||Ct<=0?0:Math.min(Math.min(O.value,E.value)/zt,Math.min(P.value,W.value)/Ct),J=n((p,M)=>M+(p+.5)*F,"$"),It=_t,Lt=0;{let p=(E.position-O.position)*.06,M=(W.position-P.position)*.06,_=w(Math.ceil(O.position+p),0,y-1),T=w(Math.floor(E.position-p),0,y-1),_e=w(Math.ceil(P.position+M),0,x-1),Ot=w(Math.floor(W.position-M),0,x-1),Et=0,$=0,Pt=0;for(let N=_e;N<=Ot;N++)for(let q=_;q<=T;q++){$++;let K=v[N*y+q];K>=248&&Et++;let De=q+2<=T?v[N*y+q+2]:K,Te=N+2<=Ot?v[(N+2)*y+q]:K;(Math.abs(De-K)>=24||Math.abs(Te-K)>=24)&&Pt++}$>=16&&(It=Et/$,Lt=Pt/$)}return{brightness:ke,glare:_t,cardGlare:It,sharpness:xe,fill:Tt,shape:ve,content:Lt,offsetX:Se,offsetY:Fe,edgeConfidence:Re,box:{left:J(O.position,k),right:J(E.position,k),top:J(P.position,S),bottom:J(W.position,S)}}}n(si,"Fe");function st(s,t,e,i){let a=s.length,h=Math.max(1,Math.floor(a*.45)),o=t?1:Math.max(1,a-1-h),l=t?Math.min(a-2,h):a-2,r=o;for(let m=o;m<=l;m++)s[m]>s[r]&&(r=m);if(i>0&&i<1){let m=s[r]*i,g=r,b=Math.abs(r-e);for(let w=o;w<=l;w++){let k=s[w];if(k<m||k<(s[w-1]??0)||k<(s[w+1]??0))continue;let S=Math.abs(w-e);S<b&&(g=w,b=S)}r=g}let c=r>0?s[r-1]:0,u=s[r],f=r<a-1?s[r+1]:0,d=c+u+f;return{position:d>0?r+(f-c)/d:r,value:u}}n(st,"at");function ne(s){if(s.length<3)return 0;let t=0;for(let e=1;e<s.length-1;e++)t+=s[e];return t/(s.length-2)}n(ne,"_e");function ai(s){let t=s.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}}}n(ai,"Ce");var ot=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 _i(s){let t=s!==null&&typeof s=="object"?s:{},e={...ot};for(let i of Object.keys(ot)){let a=t[i];typeof a=="number"&&Number.isFinite(a)&&a>=0&&a<=1e6&&(e[i]=a)}return e}n(_i,"Ai");var j,hi=(j=class{constructor(t=ot){this.t=t,this.goodSince=null,this.steadySince=null,this.last=null}reset(){this.goodSince=null,this.steadySince=null,this.last=null}tick(t,e){let i=this.t,a=i.shapeTolerance<=0||Math.abs(t.shape-1)<=i.shapeTolerance,h=t.edgeConfidence>=i.edgeConfidenceMin&&a&&t.content>=i.contentMin,o=t.fill>=i.fillMin&&t.fill<=i.fillMax,l=Math.abs(t.offsetX)<=i.offsetMax&&Math.abs(t.offsetY)<=i.offsetMax,r=t.cardGlare<=i.glareMax,c=t.sharpness>=i.sharpnessMin,u=this.last;this.last={fill:t.fill,offsetX:t.offsetX,offsetY:t.offsetY,at:e};let f=u!==null&&i.steadyRefMs>0?Math.min(3,Math.max(1,(e-u.at)/i.steadyRefMs)):1,d=h&&r&&c&&t.fill>=i.steadyFillMin&&t.fill<=i.steadyFillMax&&u!==null&&Math.abs(t.fill-u.fill)<=i.steadyFillDelta*f&&Math.abs(t.offsetX-u.offsetX)<=i.steadyOffsetDelta*f&&Math.abs(t.offsetY-u.offsetY)<=i.steadyOffsetDelta*f,m=h&&o&&l&&r&&c,g;if(h?r?t.fill<i.fillMin?g="too_small":t.fill>i.fillMax?g="too_big":c?l?g="locking":g="off_center":g="blurry":g="glare":g="no_card",m){if(d&&(this.steadySince??(this.steadySince=e)),this.goodSince??(this.goodSince=e),e-this.goodSince>=i.lockMs)return{detected:h,ready:!0,via:"good",blocker:"locking"};let b=this.steadySince!==null&&e-this.steadySince>=i.steadyMs;return{detected:h,ready:b,via:b?"steady":null,blocker:"locking"}}if(this.goodSince=null,d){this.steadySince??(this.steadySince=e);let b=e-this.steadySince>=i.steadyMs;return{detected:h,ready:b,via:b?"steady":null,blocker:b?"locking":"steadying"}}return this.steadySince=null,{detected:h,ready:!1,via:null,blocker:g}}},n(j,"ct"),j),Z=null;async function oi(s){return Z===null&&(Z=(await import("./detector-scanic-23DAYT3H-AJXQA7H4.js")).detectQuad),Z(s)}n(oi,"ni");async function ri(s){let t=Jt(s);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}}}n(ri,"si");function Di(){Z===null&&import("./detector-scanic-23DAYT3H-AJXQA7H4.js").then(s=>{Z=s.detectQuad}).catch(()=>{})}n(Di,"ji");var ce=4e3,li=2,ue=3,ni=Object.freeze({LOW:3,MID:5,HIGH:6}),Mt=Object.freeze({manualShutterMs:6e3,detectedNoLockMs:1950});function Ti(s){let t=s!==null&&typeof s=="object"?s:{},e=n((i,a,h)=>typeof i=="number"&&Number.isFinite(i)&&i>=a&&i<=h?i:void 0,"e");return{manualShutterMs:e(t.manualShutterMs,1e3,6e4)??Mt.manualShutterMs,detectedNoLockMs:e(t.steadyMs,300,3e4)!==void 0?t.steadyMs+(e(t.lockMs,0,1e4)??450):Mt.detectedNoLockMs}}n(Ti,"Yi");var z,Ai=(z=class{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=z.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 ze,this.lastFeedbackKey=null,this.lastQuad=null,this.lastDetect=null,this.frameWatch=null,this.reopened=!1,this.lit=!1,this.blackTicks=0,this.offEnded=null,this.opts=t,this.gate=new ee(t.format??"ID-1",t.thresholds);let e=t.deviceClass??Qt(Ht());this.deviceClass=e,this.camera=t.camera??yt,this.shutterTuning=t.shutter??Mt,this.guideTuning=t.guideLock??ot,this.guideLock=new hi(this.guideTuning),this.cadenceMs=1e3/ni[e]}on(t,e){let i=this.handlers.get(t);return i||(i=new Set,this.handlers.set(t,i)),i.add(e),()=>i?.delete(e)}emit(t,e){for(let i of[...this.handlers.get(t)??[]])i(e)}async start(){let t=this.state==="error"?this.resumePlayback():null,e=++this.attempt;if(this.clearFrameWatch(),this.gate.reset(),this.resetSide(),this.feedback.reset(),this.lastFeedbackKey=null,this.lastGuidance=null,this.capturing=!1,this.lit=!1,this.blackTicks=0,t!==null&&await t&&e===this.attempt){this.setState("positioning"),this.scheduleTick(e),this.watchFrames(e);return}if(e===this.attempt){this.releaseStream(),jt(),this.setState("preflight");try{let i=this.opts.getUserMedia??(o=>navigator.mediaDevices.getUserMedia(o));this.setState("acquiring");let a=this.opts.enumerateDevices??(this.opts.getUserMedia===void 0&&typeof navigator<"u"&&navigator.mediaDevices?.enumerateDevices?()=>navigator.mediaDevices.enumerateDevices():void 0),h=await ei({getUserMedia:i,...a!==void 0?{enumerateDevices:a}:{},lensSelection:this.camera.lensSelection,base:Ee});if(e!==this.attempt){for(let o of h.stream.getTracks())o.stop();return}if(this.stream=h.stream,Wt(this.stream),Gt(this.stream),this.watchEnded(e),this.opts.upgradeResolution!==!1&&await this.upgradeResolution(),e!==this.attempt||(await this.applyFocusAndZoom(),e!==this.attempt)||(this.opts.video.srcObject=this.stream,await this.opts.video.play().catch(()=>{}),e!==this.attempt))return;this.setState("positioning"),this.scheduleTick(e),this.watchFrames(e)}catch(i){if(e!==this.attempt)return;let a=qt(i),h=Nt(i);this.setState("error"),this.emit("error",{kind:a,retryable:!0,detail:h===void 0?{phase:"acquiring"}:{phase:"acquiring",name:h}})}}}resumePlayback(){let t=this.opts.video,e=this.videoTrack();if(this.stream===null||e===null||e.readyState!=="live"||t.srcObject!==this.stream)return null;try{return Promise.resolve(t.play()).then(()=>this.framesNow(),()=>!1)}catch{return null}}framesNow(){let t=this.opts.video;return this.opts.hasFrames!==void 0?this.opts.hasFrames(t):!t.paused&&t.readyState>=2&&t.videoWidth>0}watchFrames(t){let e=this.opts.firstFrameMs??ce;e<=0||(this.clearFrameWatch(),this.frameWatch=setTimeout(()=>{if(this.frameWatch=null,!(t!==this.attempt||this.state!=="positioning")){if(this.framesNow()&&this.blackTicks<ue){this.reopened=!1;return}this.cameraDead(t)}},e))}clearFrameWatch(){this.frameWatch!==null&&clearTimeout(this.frameWatch),this.frameWatch=null}watchEnded(t){this.offEnded?.(),this.offEnded=null;let e=this.videoTrack();if(e===null||typeof e.addEventListener!="function")return;let i=n(()=>{t===this.attempt&&(this.state==="positioning"||this.state==="acquiring")&&this.cameraDead(t)},"o");e.addEventListener("ended",i),this.offEnded=()=>e.removeEventListener?.("ended",i)}cameraDead(t){if(t!==this.attempt)return;let e=this.videoTrack(),i=e!==null&&e.readyState==="live"&&!e.muted&&this.opts.video.paused&&!this.framesNow();if(!i&&!this.reopened){this.reopened=!0,this.start();return}this.attempt+=1,this.timer!==null&&(this.opts.clearTimer??clearTimeout)(this.timer),this.timer=null,this.clearFrameWatch(),i||this.releaseStream(),this.reopened=!1,this.setState("error"),this.emit("error",{kind:"generic",retryable:!0,detail:{phase:"acquiring"}})}releaseStream(){if(this.offEnded?.(),this.offEnded=null,this.stream)for(let t of this.stream.getTracks())t.stop();this.stream=null,this.opts.video.srcObject!==null&&this.opts.video.srcObject!==void 0&&(this.opts.video.srcObject=null)}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,e=this.lastDetect?.width??Math.max(1,t.videoWidth),i=this.lastDetect?.height??Math.max(1,t.videoHeight),a=this.lastQuad??this.lastGuideQuad??{topLeft:{x:0,y:0},topRight:{x:e,y:0},bottomRight:{x:e,y:i},bottomLeft:{x:0,y:i}},h=(this.opts.now??(()=>performance.now()))(),o=this.feedback.force("processing",h);this.lastFeedbackKey=o.key,this.emit("feedback",o),await this.fire(this.attempt,this.lastOcrReady!==null?this.lastOcrReady.quad:a,{width:e,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 e=(this.opts.format??"ID-1")==="ID-3"||this.opts.side==="single"?"single":this.opts.side==="verso"?"verso":"recto",i=t.report(e,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 e=t.width/Math.max(1,t.height),i=this.opts.guide;if(i!==void 0&&i.viewAspect>0){let l={width:i.viewAspect,height:1},r={x:i.rect.x*i.viewAspect,y:i.rect.y,width:i.rect.width*i.viewAspect,height:i.rect.height};return ii(l,r,e,0)}let a=Vt(this.opts.format??"ID-1").center,h=.86,o=h*e/a;return o>.84&&(o=.84,h=o*a/e),{x:(1-h)/2,y:(1-o)/2,width:h,height:o}}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=z.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 e=this.videoTrack();if(e===null||this.zoom<=1)return;let i=this.focusCaps(),a=typeof i?.zoom?.min=="number"?Math.max(i.zoom.min,1):1;this.zoom=a,this.stats.zoomFallbackAtMs=Math.round(t-(this.positioningSince??t)),this.guideLock.reset(),this.gate.reset(),e.applyConstraints({advanced:[{zoom:a}]}).catch(()=>{})}offerShutter(t,e){this.shutterOffered||(this.shutterOffered=!0,this.stats.shutterAtMs=Math.round(e-(this.positioningSince??e)),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.clearFrameWatch(),this.offEnded?.(),this.offEnded=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 e=t.getSettings?.()??{},i=Ge(t.getCapabilities?.(),{width:e.width??0,height:e.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 e=this.focusCaps();this.camera.continuousFocus&&gt(e,"continuous")&&await t.applyConstraints({advanced:[{focusMode:"continuous"}]}).catch(()=>{});let i={width:0,height:0};try{let h=t.getSettings?.()??{};i={width:h.width??0,height:h.height??0}}catch{}let a=$e(e,i,this.opts.format??"ID-1",this.camera);if(a>1)try{await t.applyConstraints({advanced:[{zoom:a}]}),this.zoom=a}catch{this.zoom=1}}async focusAt(t,e){let i=this.videoTrack(),a=re(this.focusCaps(),t,e);if(!(i===null||a===null))try{await i.applyConstraints({advanced:[a]}),(this.opts.setTimer??setTimeout)(()=>{this.restoreContinuous()},1500)}catch{}}async restoreContinuous(){let t=this.videoTrack();t===null||!this.camera.continuousFocus||!gt(this.focusCaps(),"continuous")||await t.applyConstraints({advanced:[{focusMode:"continuous"}]}).catch(()=>{})}async refocusOn(t,e){let i=this.camera.refocusBeforePhotoMs,a=this.videoTrack();if(i<=0||a===null||e.width<=0||e.height<=0)return;let h=C(t),o=re(this.focusCaps(),(h.x+h.width/2)/e.width,(h.y+h.height/2)/e.height);if(o!==null)try{await a.applyConstraints({advanced:[o]});let l=this.opts.setTimer??setTimeout;await new Promise(r=>{l(()=>r(),i)})}catch{}}videoTrack(){try{return this.stream?.getVideoTracks?.()[0]??null}catch{return null}}async takeStill(t,e,i){if(this.opts.captureStill!==void 0)return this.opts.captureStill(this.opts.video,t,e);let a=this.opts.format??"ID-1",h=this.videoTrack();if(i&&this.opts.photoCapture!==!1&&this.deviceClass!=="LOW"&&!this.torchOn&&h!==null&&Ue(h)){await this.refocusOn(t,e);let o=await Ze(this.opts.video,t,e,a,{track:h,detect:this.detector(),detectWidth:tt});if(this.restoreContinuous(),o!==null)return o}return Ve(this.opts.video,t,e,a)}detector(){return this.opts.detect??((this.opts.format??"ID-1")==="ID-3"?ri:oi)}setState(t){this.state=t,this.emit("statechange",{state:t})}scheduleTick(t){let e=this.opts.setTimer??setTimeout;this.timer=e(()=>{this.tick(t)},this.cadenceMs)}async tick(t){if(t!==this.attempt||this.state!=="positioning"||this.capturing)return;let e=this.opts.now??(()=>performance.now()),i=this.opts.grabDetectFrame??fe,a=this.detector(),h=i(this.opts.video,tt);if(h===null){this.scheduleTick(t);return}if(!this.lit){if(ut(h)>li)this.lit=!0,this.blackTicks=0;else if(++this.blackTicks>=ue&&this.frameWatch===null&&(this.opts.firstFrameMs??ce)>0){this.cameraDead(t);return}}let o=null;try{o=await a(h)}catch{o=null}if(t!==this.attempt)return;let l=o!==null?at(h,o):h,r=e(),c={sharpness:Y(l),exposure:Xt(l),meanLuma:ut(l),specularFraction:Ie(l)},u=Oe({format:this.opts.format??"ID-1",quad:o,frameWidth:h.width,frameHeight:h.height,measures:c,...this.opts.thresholds!==void 0?{thresholds:this.opts.thresholds}:{}}),f=this.gate.tick({timestampMs:r,quad:o,quality:c,frameWidth:h.width,frameHeight:h.height}),d=(this.opts.format??"ID-1")!=="ID-3"?si(h,this.guideRegion(h),{edgePeakFrac:this.guideTuning.edgePeakFrac}):ht,m=this.guideLock.tick(d,r);this.lastGuideQuad=m.detected?ai(d):null;let g=this.capturing?null:this.ocrTick(h,o,d,m.detected,u,r);this.positioningSince??(this.positioningSince=r);let b=this.stats;if(b.ticks+=1,b.quadFraming[u.framing]=(b.quadFraming[u.framing]??0)+1,u.framing==="ok"&&!f.ready){let x=u.lighting!=="ok"?u.lighting:u.glare!=="ok"?"glare":u.blur!=="ok"?"blurry":"steadying";b.qualityBlockers[x]=(b.qualityBlockers[x]??0)+1}b.guideBlockers[m.blocker]=(b.guideBlockers[m.blocker]??0)+1,o!==null||m.detected?(this.detectedSince??(this.detectedSince=r),this.lastSeenAt=r):this.detectedSince=null,this.lastSeenAt!==null&&r-this.lastSeenAt<=pi?r-this.positioningSince>=this.shutterTuning.manualShutterMs?this.offerShutter("timeout",r):g?.suspendQuality!==!0&&this.detectedSince!==null&&r-this.detectedSince>=this.shutterTuning.detectedNoLockMs&&this.offerShutter("detected_no_lock",r):this.withdrawShutter();let w=r-(this.lastSeenAt??this.positioningSince);this.zoom>1&&this.camera.zoomFallbackMs>0&&w>=this.camera.zoomFallbackMs&&this.zoomFallback(r),this.emit("checks",{engine:"docv1",p:f.p,plausible:f.plausible,stableTicks:f.stableTicks,quad:f.quad,frameWidth:h.width,frameHeight:h.height,analysis:u,ready:g?.suspendQuality!==!0&&(f.ready&&o!==null||m.ready&&this.lastGuideQuad!==null)||this.lastOcrReady!==null,guide:{detected:m.detected,blocker:m.blocker,fill:d.fill,shape:d.shape,content:d.content,offsetX:d.offsetX,offsetY:d.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=f.plausible?o:null,this.lastDetect={width:h.width,height:h.height,tickSharpness:c.sharpness};let k=Ae(u);u.framing!=="ok"&&m.detected&&(k=gi(m.blocker,d.brightness<this.guideTuning.darkBrightness)),k==="blurry"&&o!==null&&ui(o,h,this.opts.format??"ID-1")>=this.camera.focusFarFillFrac&&(k="focus_far"),k==="sensing"&&this.zoom>1&&this.camera.noDocFarHintMs>0&&w>=this.camera.noDocFarHintMs&&(k="focus_far");let S=this.feedback.tick(k,r);if(S.key!==this.lastFeedbackKey&&(this.lastFeedbackKey=S.key,this.emit("feedback",S)),f.guidanceKey!==this.lastGuidance&&(this.lastGuidance=f.guidanceKey,this.emit("guidance",{key:f.guidanceKey})),this.capturing)return;let D=g?.suspendQuality!==!0,I=D&&f.ready&&o!==null,F=D&&m.ready&&this.lastGuideQuad!==null,y=this.lastOcrReady;if(y!==null&&this.opts.autoCapture!==!1){let x=this.feedback.force("processing",r);this.lastFeedbackKey=x.key,this.emit("feedback",x);let v=Y(at(h,y.quad));await this.fire(t,y.quad,{width:h.width,height:h.height,tickSharpness:v},y.via);return}if((I||F)&&this.opts.autoCapture!==!1){let x=this.feedback.force("processing",r);this.lastFeedbackKey=x.key,this.emit("feedback",x);let v=F?this.lastGuideQuad:o,L=F?m.via==="steady"?"guide_steady":"guide_good":"quad",B=F?Y(at(h,v)):c.sharpness;await this.fire(t,v,{width:h.width,height:h.height,tickSharpness:B},L);return}this.scheduleTick(t)}async fire(t,e,i,a){this.capturing=!0;let h=this.opts.grabDetectFrame??fe,o=this.opts.setTimer??setTimeout,l={width:i.width,height:i.height};try{let r={still:await this.takeStill(e,l,!0),sharpness:i.tickSharpness};if(t!==this.attempt)return;let c=r.still.source==="photo"?0:di;for(let d=0;d<c;d++){if(await new Promise(b=>{o(()=>b(),fi)}),t!==this.attempt)return;let m=h(this.opts.video,tt);if(m===null)continue;let g=Y(at(m,e));if(g>r.sharpness*mi){let b=await this.takeStill(e,l,!1);if(t!==this.attempt)return;r={still:b,sharpness:g}}}if(t!==this.attempt)return;let u=r.still.sharpness;if(this.opts.autoCapture!==!1&&a!=="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,(a==="text_lock"||a==="live_mrz")&&this.opts.ocr?.rearmFace();let d=(this.opts.now??(()=>performance.now()))(),m=this.feedback.force("focus_far",d);this.lastFeedbackKey=m.key,this.emit("feedback",m),this.capturing=!1,this.gate.reset(),this.scheduleTick(t);return}this.stillRefusals=0;let f=(this.opts.now??(()=>performance.now()))();this.stats.via=a,this.stats.msToCapture=Math.round(f-(this.positioningSince??f)),this.shutterOffered&&(this.shutterOffered=!1,this.emit("shutter",{available:!1})),this.setState("captured"),this.emit("artifacts",{keyframe:r.still.blob,previewDataUrl:r.still.previewDataUrl,...this.opts.side!==void 0?{side:this.opts.side}:{},...r.still.docRegion!==void 0?{docRegion:r.still.docRegion}:{},...(()=>{let d=a==="live_mrz"?this.opts.ocr?.liveCapture():null;return d?{liveMrz:d}:{}})()})}catch{if(t!==this.attempt)return;this.capturing=!1,this.gate.reset(),this.guideLock.reset(),this.lastOcrReady=null,(a==="text_lock"||a==="live_mrz")&&this.opts.ocr?.rearmFace(),this.scheduleTick(t)}}ocrTick(t,e,i,a,h,o){let l=this.opts.ocr,r=this.opts.video;if(l===void 0||!l.hasEngine)return this.lastOcrReady=null,null;let c=r.videoWidth,u=r.videoHeight;if(c<=0||u<=0||t.width<=0||t.height<=0)return null;let f=(this.opts.format??"ID-1")==="ID-3",d=this.guideRegion(t),m={x:d.x*c,y:d.y*u,w:d.width*c,h:d.height*u},g=c/t.width,b=u/t.height,w;f&&e!==null?w=ci(C(e),g,b,c,u):w=Yt(m,l.bandTop,u);let k=f?h.glare==="ok":i.cardGlare<=this.guideTuning.glareMax,S=f?h.blur==="ok":i.sharpness>=this.guideTuning.sharpnessMin,D=l.tick({atMs:o,video:r,mrzFace:f||this.opts.side==="verso"||this.opts.side==="single",present:f||e!==null||a,card:m,band:w,portrait:u>c,glareOk:k,sharpOk:S});if(D.ready&&D.via!==void 0){let I=f?e??de(d,t):this.lastGuideQuad??de(d,t);this.lastOcrReady={quad:I,via:D.via}}else this.lastOcrReady=null;return D}},n(z,"i"),z);function ci(s,t,e,i,a){let h=Math.min(i,s.width*1.06*t),o=Math.min(a,Math.max(s.height*1.6*e,h/5)),l=(s.y+s.height/2)*e,r=Math.max(0,Math.min(i-h,(s.x-s.width*.03)*t)),c=Math.max(0,Math.min(a-o,l-o/2));return{x:r,y:c,w:h,h:o}}n(ci,"ci");function de(s,t){let e=s.x*t.width,i=s.y*t.height,a=(s.x+s.width)*t.width,h=(s.y+s.height)*t.height;return{topLeft:{x:e,y:i},topRight:{x:a,y:i},bottomRight:{x:a,y:h},bottomLeft:{x:e,y:h}}}n(de,"Oe");function ui(s,t,e){let i=C(s);return t.width<=0||t.height<=0?0:e==="ID-3"?i.width/t.width:i.width*i.height/(t.width*t.height)}n(ui,"li");var di=2,fi=260,mi=1.08;function fe(s,t){let e=s.videoWidth,i=s.videoHeight;if(e===0||i===0)return null;let a=Math.min(1,t/e),h=Math.round(e*a),o=Math.round(i*a),l=document.createElement("canvas");l.width=h,l.height=o;let r=l.getContext("2d",{willReadFrequently:!0});return r===null?null:(e/Math.max(1,h)>4&&(r.imageSmoothingQuality="high"),r.drawImage(s,0,0,h,o),r.getImageData(0,0,h,o))}n(fe,"Pe");function at(s,t){let e=[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],a=Math.max(0,Math.floor(Math.min(...e))),h=Math.max(0,Math.floor(Math.min(...i))),o=Math.min(s.width,Math.ceil(Math.max(...e))),l=Math.min(s.height,Math.ceil(Math.max(...i))),r=Math.max(1,o-a),c=Math.max(1,l-h),u=new Uint8ClampedArray(r*c*4);for(let f=0;f<c;f++){let d=((h+f)*s.width+a)*4;u.set(s.data.subarray(d,d+r*4),f*r*4)}return{data:u,width:r,height:c,colorSpace:s.colorSpace}}n(at,"lt");function gi(s,t){return s==="glare"?"glare":s==="too_small"?"too_far":s==="too_big"?"too_close":t?"too_dark":s==="blurry"?"blurry":s==="off_center"?"edge_clipped":s==="no_card"?"sensing":"hold_still"}n(gi,"mi");var pi=1200;export{Ri as a,_i as b,Di as c,ce as d,li as e,ue as f,ni as g,Mt as h,Ti as i,Ai as j,ci as k,di as l,fi as m};
@@ -1 +1 @@
1
- import{a as n}from"./chunk-4FHWXBOB.js";var S="0.1.0-rc.26",k=/FBAN|FBAV|FB_IAB|FBIOS|MessengerForiOS|Instagram|WhatsApp|musical_ly|BytedanceWebview|TikTok|Snapchat|\bLine\/|LinkedInApp|Pinterest|MicroMessenger|; wv\)/i;function O(t){let e=t??(typeof navigator>"u"?"":String(navigator.userAgent??""));return k.test(e)}n(O,"p");var f="sekyro.did",C=1e4,w=n(()=>globalThis.process?.versions?.node,"v"),l;function y(){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,a=>a.toString(16).padStart(2,"0")).join("")}}catch{}}n(y,"b");function H(){try{let t=localStorage.getItem(f);if(t)return t;let e=y();return e!==void 0&&localStorage.setItem(f,e),e}catch{return l??(l=y()),l}}n(H,"I");async function M(){let t=globalThis.crypto?.subtle;if(!t)return"";let e=navigator,a=JSON.stringify([e.userAgent,e.platform,e.hardwareConcurrency??null,e.deviceMemory??null,e.maxTouchPoints??0,screen.width,screen.height,screen.colorDepth,globalThis.devicePixelRatio??1,Intl.DateTimeFormat().resolvedOptions().timeZone,e.languages?.join(",")??e.language]),i=await t.digest("SHA-256",new TextEncoder().encode(a));return Array.from(new Uint8Array(i),s=>s.toString(16).padStart(2,"0")).join("").slice(0,32)}n(M,"w");function x(){try{let t=Number(navigator.maxTouchPoints);return Number.isFinite(t)&&t>=0?{touch:Math.min(64,Math.trunc(t))}:{}}catch{return{}}}n(x,"k");function W(t){let e=new TextEncoder().encode(t),a="";for(let i of e)a+=String.fromCharCode(i);return btoa(a).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}n(W,"x");function j(t){let e,a,i,s,c,d,m=n(()=>d?.readyState==="live","u"),T=n(()=>{c!==void 0||!globalThis.crypto?.subtle||w()||m()||(c=Promise.race([import("./print-SEWS3VHQ-HWJTHADG.js"),new Promise(r=>setTimeout(r,C))]).then(r=>r?.computePrint(m)).then(r=>{r==="busy"?c=void 0:s=r}).catch(()=>{}))},"_");return{timezone(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone?.slice(0,64)||void 0}catch{return}},noteCameraLabel(r){r&&(e=r.slice(0,128))},noteCamera(r){a=r},noteCameraTrack(r){d=r},async deviceHeader(){try{i??(i=M().catch(()=>""));let r=[];navigator.webdriver&&r.push("webdriver"),/HeadlessChrome/.test(navigator.userAgent)&&r.push("headless");let g=await i,p=H(),A={v:1,platform:"web",sdk:t.sdk.slice(0,64),ids:[...p?[{kind:"web_local",value:p.slice(0,128)}]:[],...g?[{kind:"web_fp",value:g}]:[]],screen:{w:screen.width,h:screen.height,dpr:globalThis.devicePixelRatio??1},...x(),...e?{cameraLabel:e}:{},...r.length?{signals:r}:{},...s?{print:{v:2,...s,...a?{camera:a}:{}}}:{},...O()?{inApp:!0}:{}},I=W(JSON.stringify(A));return T(),I}catch{return}},printReady(){return c??Promise.resolve()}}}n(j,"A");var v=Symbol.for("sekyro.web.clientContext"),b=globalThis,u=b[v]??(b[v]=j({sdk:`@sekyro/web@${S}`}));function z(t){try{let e=t.getVideoTracks?.()[0];if(e){if(u.noteCameraLabel(e.label),u.noteCameraTrack(e),w())return;import("./camera-trait-V4UAOPIQ-TFCPOCSU.js").then(a=>a.noteCameraTrait(e,u)).catch(()=>{})}}catch{}}n(z,"M");var P=Object.freeze({LOW:Object.freeze({cadenceHz:5,inputWidth:128,animations:"reduced"}),MID:Object.freeze({cadenceHz:8,inputWidth:160,animations:"full"}),HIGH:Object.freeze({cadenceHz:10,inputWidth:192,animations:"full"})}),L=new Uint8Array([0,97,115,109,1,0,0,0,1,5,1,96,0,1,123,3,2,1,0,10,10,1,8,0,65,0,253,15,253,98,11]);function F(){let t=typeof navigator>"u"?void 0:navigator,e=!1;try{e=typeof WebAssembly<"u"&&WebAssembly.validate(L)}catch{e=!1}return{cores:t?.hardwareConcurrency??2,memGB:t?.deviceMemory??null,simd:e}}n(F,"o");function U(t){let e=t.memGB??4;return t.cores<4||e<3?"LOW":t.cores>=8&&e>=6?"HIGH":"MID"}n(U,"l");var h=["LOW","MID","HIGH"],o,_=(o=class{constructor(e){this.samples=[],this.adjusted=!1,this.current=e}get deviceClass(){return this.current}get profile(){return P[this.current]}record(e){if(this.adjusted||this.samples.length>=10)return this.current;if(this.samples.push(e),this.samples.length<10)return this.current;this.adjusted=!0;let a=this.samples.reduce((i,s)=>i+s,0)/this.samples.length;if(a>70)this.current="LOW";else if(a<25){let i=h.indexOf(this.current);this.current=h[Math.min(h.length-1,i+1)]??this.current}return this.current}},n(o,"i"),o);export{S as a,O as b,u as c,z as d,F as e,U as f,_ as g};
1
+ import{a as n}from"./chunk-4FHWXBOB.js";var S="0.1.0-rc.27",k=/FBAN|FBAV|FB_IAB|FBIOS|MessengerForiOS|Instagram|WhatsApp|musical_ly|BytedanceWebview|TikTok|Snapchat|\bLine\/|LinkedInApp|Pinterest|MicroMessenger|; wv\)/i;function O(t){let e=t??(typeof navigator>"u"?"":String(navigator.userAgent??""));return k.test(e)}n(O,"p");var f="sekyro.did",C=1e4,w=n(()=>globalThis.process?.versions?.node,"v"),l;function y(){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,a=>a.toString(16).padStart(2,"0")).join("")}}catch{}}n(y,"b");function H(){try{let t=localStorage.getItem(f);if(t)return t;let e=y();return e!==void 0&&localStorage.setItem(f,e),e}catch{return l??(l=y()),l}}n(H,"I");async function M(){let t=globalThis.crypto?.subtle;if(!t)return"";let e=navigator,a=JSON.stringify([e.userAgent,e.platform,e.hardwareConcurrency??null,e.deviceMemory??null,e.maxTouchPoints??0,screen.width,screen.height,screen.colorDepth,globalThis.devicePixelRatio??1,Intl.DateTimeFormat().resolvedOptions().timeZone,e.languages?.join(",")??e.language]),i=await t.digest("SHA-256",new TextEncoder().encode(a));return Array.from(new Uint8Array(i),s=>s.toString(16).padStart(2,"0")).join("").slice(0,32)}n(M,"w");function x(){try{let t=Number(navigator.maxTouchPoints);return Number.isFinite(t)&&t>=0?{touch:Math.min(64,Math.trunc(t))}:{}}catch{return{}}}n(x,"k");function W(t){let e=new TextEncoder().encode(t),a="";for(let i of e)a+=String.fromCharCode(i);return btoa(a).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}n(W,"x");function j(t){let e,a,i,s,c,d,m=n(()=>d?.readyState==="live","u"),T=n(()=>{c!==void 0||!globalThis.crypto?.subtle||w()||m()||(c=Promise.race([import("./print-SEWS3VHQ-HWJTHADG.js"),new Promise(r=>setTimeout(r,C))]).then(r=>r?.computePrint(m)).then(r=>{r==="busy"?c=void 0:s=r}).catch(()=>{}))},"_");return{timezone(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone?.slice(0,64)||void 0}catch{return}},noteCameraLabel(r){r&&(e=r.slice(0,128))},noteCamera(r){a=r},noteCameraTrack(r){d=r},async deviceHeader(){try{i??(i=M().catch(()=>""));let r=[];navigator.webdriver&&r.push("webdriver"),/HeadlessChrome/.test(navigator.userAgent)&&r.push("headless");let g=await i,p=H(),A={v:1,platform:"web",sdk:t.sdk.slice(0,64),ids:[...p?[{kind:"web_local",value:p.slice(0,128)}]:[],...g?[{kind:"web_fp",value:g}]:[]],screen:{w:screen.width,h:screen.height,dpr:globalThis.devicePixelRatio??1},...x(),...e?{cameraLabel:e}:{},...r.length?{signals:r}:{},...s?{print:{v:2,...s,...a?{camera:a}:{}}}:{},...O()?{inApp:!0}:{}},I=W(JSON.stringify(A));return T(),I}catch{return}},printReady(){return c??Promise.resolve()}}}n(j,"A");var v=Symbol.for("sekyro.web.clientContext"),b=globalThis,u=b[v]??(b[v]=j({sdk:`@sekyro/web@${S}`}));function z(t){try{let e=t.getVideoTracks?.()[0];if(e){if(u.noteCameraLabel(e.label),u.noteCameraTrack(e),w())return;import("./camera-trait-V4UAOPIQ-TFCPOCSU.js").then(a=>a.noteCameraTrait(e,u)).catch(()=>{})}}catch{}}n(z,"M");var P=Object.freeze({LOW:Object.freeze({cadenceHz:5,inputWidth:128,animations:"reduced"}),MID:Object.freeze({cadenceHz:8,inputWidth:160,animations:"full"}),HIGH:Object.freeze({cadenceHz:10,inputWidth:192,animations:"full"})}),L=new Uint8Array([0,97,115,109,1,0,0,0,1,5,1,96,0,1,123,3,2,1,0,10,10,1,8,0,65,0,253,15,253,98,11]);function F(){let t=typeof navigator>"u"?void 0:navigator,e=!1;try{e=typeof WebAssembly<"u"&&WebAssembly.validate(L)}catch{e=!1}return{cores:t?.hardwareConcurrency??2,memGB:t?.deviceMemory??null,simd:e}}n(F,"o");function U(t){let e=t.memGB??4;return t.cores<4||e<3?"LOW":t.cores>=8&&e>=6?"HIGH":"MID"}n(U,"l");var h=["LOW","MID","HIGH"],o,_=(o=class{constructor(e){this.samples=[],this.adjusted=!1,this.current=e}get deviceClass(){return this.current}get profile(){return P[this.current]}record(e){if(this.adjusted||this.samples.length>=10)return this.current;if(this.samples.push(e),this.samples.length<10)return this.current;this.adjusted=!0;let a=this.samples.reduce((i,s)=>i+s,0)/this.samples.length;if(a>70)this.current="LOW";else if(a<25){let i=h.indexOf(this.current);this.current=h[Math.min(h.length-1,i+1)]??this.current}return this.current}},n(o,"i"),o);export{S as a,O as b,u as c,z as d,F as e,U as f,_ as g};
@@ -1 +1 @@
1
- import{d as Et,e as Bt,f as Wt,g as qt}from"./chunk-434MMEWK.js";import{a as it,b as zt,c as rt,d as Ht}from"./chunk-P7K7ELYZ.js";import{a as kt,b as V,c as Tt,d as _t,e as St,g as At,h as tt,i as It,j as xt,k as Nt,l as Lt}from"./chunk-CW56KMMH.js";import{a as Dt,b as Rt,c as Ct,d as Ot,e as Pt,f as et,g as K,h as Gt,i as Ut,j as Ft}from"./chunk-JS2IXPNL.js";import{a as o}from"./chunk-4FHWXBOB.js";var me=1e4,C,pe=(C=class{constructor(t,e){this.tier="blaze",this.inner=t,e!==void 0&&(this.fallbackReason=e)}static async create(t,e){let r=await import("./vision_bundle-WBHR7TEE.js"),s=await r.FilesetResolver.forVisionTasks(t),a=await r.FaceDetector.createFromOptions(s,{baseOptions:{modelAssetPath:`${t}/blaze_face_short_range.tflite`,delegate:"CPU"},runningMode:"IMAGE"});return new C(a,e)}async detect(t,e,r){let s;try{s=this.inner.detect(t).detections}catch{return null}let a=ge(s);if(a?.boundingBox===void 0)return null;let n=Z(t),l=ve(a.keypoints,n),c=a.keypoints?.[2],h={box:{x:a.boundingBox.originX,y:a.boundingBox.originY,width:a.boundingBox.width,height:a.boundingBox.height},...l!==void 0?{eyes:l}:{},...c!==void 0?{nose:{x:c.x*n.width,y:c.y*n.height}}:{},score:a.categories[0]?.score??0,extraFaces:Kt(s.map(d=>d.boundingBox??{width:0,height:0}),s.indexOf(a))};return Xt(h,t,e,r)}destroy(){try{this.inner.close()}catch{}}},o(C,"t"),C);function ge(i){let t,e=-1;for(let r of i){let s=r.categories[0]?.score??0;s>e&&(t=r,e=s)}return t}o(ge,"R");function ve(i,t){let e=i?.[0],r=i?.[1];if(e===void 0||r===void 0)return;let s=o(l=>({x:l.x*t.width,y:l.y*t.height}),"n"),[a,n]=[s(e),s(r)];return a.x<=n.x?{left:a,right:n}:{left:n,right:a}}o(ve,"T");function ye(){if(typeof OffscreenCanvas=="function")return new OffscreenCanvas(2,2);let i=document.createElement("canvas");return i.width=2,i.height=2,i}o(ye,"E");var we=4;async function be(){let i=globalThis.FaceDetector;if(typeof i!="function")return{ok:!1,reason:"unsupported"};try{let t=new i({fastMode:!0,maxDetectedFaces:we});return await t.detect(ye()),{ok:!0,instance:t}}catch(t){return{ok:!1,reason:`smoke_failed:${t instanceof Error?t.message:String(t)}`}}}o(be,"w");var P,Me=(P=class{constructor(t,e){this.tier="native",this.inner=t,e!==void 0&&(this.fallbackReason=e)}async detect(t,e,r){let s;try{s=await this.inner.detect(t)}catch{return null}let a=s.map(d=>d.boundingBox),n=-1;a.forEach((d,u)=>{let v=a[n];(v===void 0||d.width*d.height>v.width*v.height)&&(n=u)});let l=s[n];if(l===void 0)return null;let c=ke(l.landmarks),h={box:{x:l.boundingBox.x,y:l.boundingBox.y,width:l.boundingBox.width,height:l.boundingBox.height},...c!==void 0?{eyes:c}:{},score:1,extraFaces:Kt(a,n)};return Xt(h,t,e,r)}destroy(){}},o(P,"b"),P);function ke(i){if(i===void 0)return;let t=i.filter(s=>s.type==="eye").map(s=>s.locations[0]).filter(s=>s!==void 0),[e,r]=t;if(!(e===void 0||r===void 0))return e.x<=r.x?{left:e,right:r}:{left:r,right:e}}o(ke,"S");var Te=.25;function Kt(i,t){let e=i[t],r=e===void 0?0:e.width*e.height;if(!(r>0))return 0;let s=0;return i.forEach((a,n)=>{n!==t&&a.width*a.height>=Te*r&&(s+=1)}),s}o(Kt,"f");var at="/models-v3",_e=["native","blaze"],G,nt=(G=class extends Error{constructor(t){super(`no detector tier available (${t})`),this.name="DetectorLadderError",this.fallbackReason=t}},o(G,"x"),G);function Z(i){let t=i;if(typeof t.videoWidth=="number"&&t.videoWidth>0)return{width:t.videoWidth,height:t.videoHeight??0};if(typeof t.naturalWidth=="number"&&t.naturalWidth>0)return{width:t.naturalWidth,height:t.naturalHeight??0};let e=typeof t.width=="number"?t.width:0,r=typeof t.height=="number"?t.height:0;return{width:e,height:r}}o(Z,"y");function Xt(i,t,e,r){let s=Z(t),a=s.width>0?e/s.width:1,n=s.height>0?r/s.height:1,l=o(c=>({x:c.x*a,y:c.y*n}),"s");return{box:{x:i.box.x*a,y:i.box.y*n,width:i.box.width*a,height:i.box.height*n},...i.eyes!==void 0?{eyes:{left:l(i.eyes.left),right:l(i.eyes.right)}}:{},...i.nose!==void 0?{nose:l(i.nose)}:{},score:i.score,...i.extraFaces!==void 0?{extraFaces:i.extraFaces}:{}}}o(Xt,"h");function Ee(i){return i instanceof Error?i.message:String(i)}o(Ee,"C");async function x(i){let t=i.preferred??_e,e=[];for(let r of t){if(r==="native"){let s=await be();if(s.ok)return new Me(s.instance,st(e));e.push(`native:${s.reason}`);continue}try{return await Se(pe.create(i.v3AssetBaseUrl??at,st(e)),i.blazeInitTimeoutMs??me)}catch(s){e.push(s instanceof Vt?"blaze:blaze_init_timeout":`blaze:${Ee(s)}`)}}throw new nt(st(e)??"no_tier_available")}o(x,"O");function st(i){return i.length>0?i.join("; "):void 0}o(st,"v");var U,Vt=(U=class extends Error{},o(U,"g"),U);function Se(i,t){return new Promise((e,r)=>{let s=setTimeout(()=>{r(new Vt(`init exceeded ${t}ms`)),i.then(a=>a.destroy(),()=>{})},t);i.then(a=>{clearTimeout(s),e(a)},a=>{clearTimeout(s),r(a)})})}o(Se,"W");var R=1;function Zt(){return typeof OffscreenCanvas=="function"&&typeof createImageBitmap=="function"&&typeof Worker=="function"}o(Zt,"K");function Ae(i,t={}){let e=t.createDetector??x,r=null;i.onmessage=s=>{let a=s.data;if(a.v!==R){a.bitmap?.close?.();return}if(a.type==="init"){e(a.options).then(n=>{r=n;let l={v:R,type:"ready",tier:n.tier,...n.fallbackReason!==void 0?{fallbackReason:n.fallbackReason}:{}};i.postMessage(l)});return}if(a.type==="detect"){let n=o(l=>{let c={v:R,type:"result",id:a.id,observation:l};i.postMessage(c),a.bitmap.close?.()},"a");if(r===null){n(null);return}r.detect(a.bitmap,a.streamWidth,a.streamHeight).then(n,()=>n(null))}}}o(Ae,"B");typeof self<"u"&&typeof self.importScripts=="function"&&Ae(self);var O,jt=(O=class{constructor(t,e){this.pending=new Map,this.nextId=1,this.worker=t,this.tier=e.tier,e.fallbackReason!==void 0&&(this.fallbackReason=e.fallbackReason),t.addEventListener("message",r=>{let s=r.data;if(s.v!==R||s.type!=="result")return;let a=this.pending.get(s.id);this.pending.delete(s.id),a?.(s.observation)})}static create(t,e,r=1e4){return new Promise((s,a)=>{let n=setTimeout(()=>{t.removeEventListener("message",l),t.terminate(),a(new Error(`worker detector not ready within ${r}ms`))},r),l=o(h=>{let d=h.data;d.v!==R||d.type!=="ready"||(clearTimeout(n),t.removeEventListener("message",l),s(new O(t,d)))},"s");t.addEventListener("message",l);let c={v:R,type:"init",options:e};t.postMessage(c)})}async detect(t,e,r){let s;try{typeof ImageBitmap<"u"&&t instanceof ImageBitmap?s=t:typeof createImageBitmap=="function"?s=await createImageBitmap(t):s=t}catch{return null}let a=this.nextId;return this.nextId+=1,new Promise(n=>{this.pending.set(a,n);let l={v:R,type:"detect",id:a,bitmap:s,streamWidth:e,streamHeight:r};this.worker.postMessage(l,[s])})}destroy(){for(let t of this.pending.values())t(null);this.pending.clear(),this.worker.terminate()}},o(O,"t"),O);var Ie=[...Dt.filter(i=>i.startsWith("video/mp4")),"video/webm;codecs=h264","video/webm;codecs=avc1","video/webm;codecs=vp8","video/webm;codecs=vp9","video/webm"],se=new Set;function xe(i){let t=/(?:Chrome|Chromium)\/(\d+)\./.exec(i??"");return t?Number(t[1]):null}o(xe,"De");function De(i=Ce(),t=globalThis.navigator?.userAgent){if(i===void 0)return"";let e=xe(t)===126;for(let r of Ie)if(!(se.has(r)||e&&r.startsWith("video/mp4")))try{if(i(r))return r}catch{}return""}o(De,"he");function $t(i){i!==""&&se.add(i)}o($t,"F");function Re(i){return i.replace(/^video\/x-matroska/i,"video/webm")}o(Re,"fe");function ae(i){let t=/codecs=["']?([^,;"']+)/i.exec(i);return t?t[1].trim():i.split(";")[0].trim()}o(ae,"ut");function Ce(){let i=globalThis.MediaRecorder;return i&&typeof i.isTypeSupported=="function"?t=>i.isTypeSupported(t):void 0}o(Ce,"Oe");var ne=2500,Oe=1e3,Pe=1500,Yt=25e5,Ge=100,Ue=700,Fe=20,Ne=1500,j=null;function Le(){return j??(j=import("./clip-inspect-DLJXVKV6-TNHTD4LV.js").catch(i=>{throw j=null,i})),j.catch(()=>null)}o(Le,"Ne");var N,D=(N=class extends Error{constructor(t,e){super(e??t),this.kind=t}},o(N,"S"),N),Be=100;function Qt(i,t){return i.stats===void 0?!1:i.stats===null?!0:i.stats.durationMs<t-Be}o(Qt,"U");function We(i,t){return i.stats?t.stats?i.stats.durationMs>t.stats.durationMs:!0:!1}o(We,"ge");var L,qe=(L=class{constructor(t={}){this.recorder=null,this.stream=null,this.chunks=[],this.bytes=0,this.hardStopTimer=null,this.graceTimer=null,this.pollTimer=null,this.settled=!1,this.now=t.now??(()=>globalThis.performance?.now?.()??Date.now())}clearTimers(){this.hardStopTimer&&clearTimeout(this.hardStopTimer),this.graceTimer&&clearTimeout(this.graceTimer),this.pollTimer&&clearInterval(this.pollTimer),this.hardStopTimer=null,this.graceTimer=null,this.pollTimer=null}record(t,e,r,s=ne,a){let n=De(),l=Le();return this.recordRaw(t,e,r,s,a,n).then(c=>ze(c,l),c=>{throw c instanceof D&&(c.requestedMimeType=n),c})}recordRaw(t,e,r,s,a,n){return this.recorder&&!this.settled?Promise.reject(new D("generic","record() called while a recording is in flight — ClipRecorder handles one recording at a time")):(this.recorder=null,this.clearTimers(),this.chunks=[],this.bytes=0,this.settled=!1,this.stream=t,new Promise((l,c)=>{let h;try{h=new MediaRecorder(t,n?{mimeType:n,videoBitsPerSecond:Yt}:{videoBitsPerSecond:Yt})}catch{try{h=new MediaRecorder(t)}catch{c(new D("unsupported"));return}}this.recorder=h;let d=o(p=>{this.settled||(this.settled=!0,this.clearTimers(),p())},"d"),u=o(()=>d(()=>{let p=Re(h.mimeType||n||Rt),M=new Blob(this.chunks,{type:p});if(M.size===0){c(new D("generic","empty clip"));return}if(et(M)){c(new D("cliptoolarge"));return}l({blob:M,mimeType:p,requestedMimeType:n})}),"u");h.ondataavailable=p=>{p.data&&p.data.size&&(this.chunks.push(p.data),this.bytes+=p.data.size,this.bytes>Pt&&d(()=>{try{h.state!=="inactive"&&h.stop()}catch{}c(new D("cliptoolarge"))}))},h.onstop=u,h.onerror=()=>d(()=>c(new D("generic")));let v=this.now();if(r!==void 0||a!==void 0){let p=!1;h.onstart=()=>{if(!(p||this.settled)&&(p=!0,v=this.now(),r!==void 0))try{r()}catch{}}}try{h.start(Oe)}catch{d(()=>c(new D("generic")));return}let w=o(()=>{if(this.pollTimer&&clearInterval(this.pollTimer),this.pollTimer=null,this.hardStopTimer&&clearTimeout(this.hardStopTimer),this.hardStopTimer=null,this.settled||e?.(),h.state!=="inactive"){try{h.stop()}catch{u()}this.graceTimer=setTimeout(u,Pe)}else u()},"v"),m=this.now();if(a===void 0){this.hardStopTimer=setTimeout(w,s);return}let g=null,y=!1;this.hardStopTimer=setTimeout(w,s+Ue),this.pollTimer=setInterval(()=>{if(this.settled||y)return;let p=null;try{p=a.latest()}catch{p=null}let M=p?.presentationTimeMs;M!==void 0&&Number.isFinite(M)&&M>=v&&g===null&&(g=M);let T=g!==null&&M!==void 0&&M-g>=s,A=g===null&&this.now()-m>=s;if(!(!T&&!A)){if(y=!0,this.pollTimer&&clearInterval(this.pollTimer),this.pollTimer=null,A){w();return}this.hardStopTimer&&clearTimeout(this.hardStopTimer),this.hardStopTimer=setTimeout(w,Ge)}},Fe)}))}stop(t){this.clearTimers();let e=this.recorder;if(e&&e.state!=="inactive")try{e.stop()}catch{}this.recorder=null,(t??this.stream)?.getTracks().forEach(r=>r.stop()),this.stream=null}},o(L,"I"),L);async function ze(i,t){let e,r=new Promise(h=>{e=setTimeout(()=>h(null),Ne)}),s=await Promise.race([t,r]);if(clearTimeout(e),s===null)return i;let a;try{a=await s.blobBytes(i.blob)}catch{return{...i,stats:null}}let n=s.inspectClipBytes(a);if(n?.container!=="webm")return{...i,stats:n};let l=s.withWebmDuration(a,n.durationMs);if(l===null)return{...i,stats:n};let c=s.inspectClipBytes(l);return c===null||c.frames!==n.frames||c.durationMs!==n.durationMs?{...i,stats:n}:{...i,blob:new Blob([l],{type:i.blob.type}),stats:n}}o(ze,"He");var He=["magenta","yellow","green","blue"],Ke={magenta:"rgb(255, 72, 150)",yellow:"rgb(255, 190, 0)",green:"rgb(0, 238, 175)",blue:"rgb(25, 150, 255)",dark:"rgb(0, 0, 0)"};function zi(i){return Ke[i]}o(zi,"ft");var Xe=4,Ve=4,$=o(i=>typeof i=="number"&&Number.isFinite(i),"D");function oe(i){if(typeof i!="object"||i===null)return!1;let t=i;if(typeof t.nonce!="string"||t.nonce.length===0||!Array.isArray(t.colours)||t.colours.length<1||t.colours.length>8||!t.colours.every(r=>He.includes(r))||!Array.isArray(t.onsetsMs)||t.onsetsMs.length!==t.colours.length)return!1;let e=-1;for(let r of t.onsetsMs){if(!$(r)||r<0||r<=e)return!1;e=r}return!(!$(t.holdMs)||t.holdMs<=0||!$(t.endMs)||t.endMs<=e||!$(t.clipMs)||t.clipMs<t.endMs||t.clipMs>8e3)}o(oe,"be");function Ze(i,t){return oe(i)?Math.max(t,Math.ceil(i.clipMs)):t}o(Ze,"ye");function je(i,t){let e=t.now??(()=>performance.now()),r=oe(i)?i:void 0,s=[],a=null,n=null,l=null,c=!1,h=null,d=o(m=>{h=m;try{t.paint(m)}catch{}},"d"),u=o(m=>{let g=t.frames?.()??null;return g!==null&&l!==null?g.mediaTimeMs+(m-g.presentationTimeMs)-l:m-(n??m)},"u"),v=o((m,g,y=0)=>{if(c)return;let p=Math.max(0,m-u(e()));a=setTimeout(()=>{if(a=null,!c){if(y<Xe&&u(e())<m-Ve){v(m,g,y+1);return}g()}},p)},"f"),w=o(m=>{if(r===void 0)return;let g=r.endMs;if(m>=r.colours.length){v(g,()=>d(null));return}let y=r.onsetsMs[m],p=m+1<r.onsetsMs.length?r.onsetsMs[m+1]:g;v(y,()=>{let M=u(e());if(M>g){h!==null&&d(null);return}let T=r.colours[m];d(T);let A=s.length===0?0:s[s.length-1].tMs;s.push({tMs:Math.max(A,Math.round(M)),colour:T});let k=y+r.holdMs;if(k<p){v(k,()=>{if(u(e())>g){h!==null&&d(null);return}d("dark"),w(m+1)});return}w(m+1)})},"v");return{started(m){if(r===void 0||c||n!==null)return;n=m;let g=t.frames?.()??null;l=g===null?null:g.mediaTimeMs+(m-g.presentationTimeMs),w(0)},stop(){c||(c=!0,a!==null&&clearTimeout(a),a=null,h!==null&&d(null))},report(){return r===void 0?void 0:{nonce:r.nonce,rendered:[...s]}}}}o(je,"Me");function $e(i,t,e=.92){return new Promise((r,s)=>{let a=i.videoWidth,n=i.videoHeight;if(!a||!n){s(new Error("video-not-ready"));return}let l=t.getContext("2d");if(!l){s(new Error("no-2d-context"));return}t.width=a,t.height=n,l.scale(-1,1),l.drawImage(i,-a,0),t.toBlob(c=>c?r(c):s(new Error("empty-keyframe")),"image/jpeg",e)})}o($e,"Se");var B,Ye=(B=class{constructor(t){this.timer=null,this.frameCallbackId=null,this.running=!1,this.busy=!1,this.lastRunAt=Number.NEGATIVE_INFINITY,this.degradeCount=0,this.durations=[],this.options=t,this.periodMs=1e3/t.cadenceHz}start(){if(this.running)return;this.running=!0;let t=this.options.video;if(typeof t?.requestVideoFrameCallback=="function"){let e=o(()=>{this.running&&(this.frameCallbackId=t.requestVideoFrameCallback?.(()=>{this.frameCallbackId=null,this.now()-this.lastRunAt>=this.periodMs&&this.tick(),e()}))},"t");e();return}this.timer=setInterval(()=>this.tick(),this.periodMs)}stop(){this.running=!1,this.timer!==null&&(clearInterval(this.timer),this.timer=null),this.frameCallbackId!==null&&(this.options.video?.cancelVideoFrameCallback?.(this.frameCallbackId),this.frameCallbackId=null)}stats(){let t=this.durations.length===0?0:this.durations.reduce((e,r)=>e+r,0)/this.durations.length;return{degradeCount:this.degradeCount,meanDetectMs:t}}now(){return this.options.now?.()??performance.now()}tick(){if(!this.running)return;if(this.busy){this.degradeCount+=1;return}this.busy=!0,this.lastRunAt=this.now();let t=this.now();this.options.run().catch(()=>{}).finally(()=>{this.busy=!1,this.durations.push(this.now()-t),this.durations.length>20&&this.durations.shift()})}},o(B,"O"),B),Qe=Object.freeze({Q_GOOD:.6,RISE_PER_S:.9,FALL_PER_S:.25,CENTER_FALLOFF_IOD_MULTIPLE:1.35,BOX_EYE_OFFSET_FACTOR:.12,IOD_BOX_PROXY_FACTOR:.42,SIZE_IDEAL_MIN:.12,SIZE_IDEAL_MAX:.3,SIZE_HARD_MIN:.08,SIZE_HARD_MAX:.45,ROLL_MAX_DEG:25,MOTION_VELOCITY_IOD_PER_S:.5,MOTION_TAU_S:.4,MOTION_DEADBAND_IOD_PER_S:.1,READY_WINDOW_MS:500,GUIDE_SIZE:.6,GUIDE_CENTERING:.6,GUIDE_POSE:.6,GUIDE_EXPOSURE:.6,GUIDE_SHARPNESS:.35,GUIDE_MOTION:.5}),F=o(i=>Math.min(1,Math.max(0,i)),"_"),W,Jt=(W=class{constructor(t={}){this.p=0,this.lastTickAt=null,this.lastCenter=null,this.velocityEma=0,this.qWindow=[],this.lastSizeDirection="ideal",this.t={...Qe,...t}}reset(){this.p=0,this.lastTickAt=null,this.lastCenter=null,this.velocityEma=0,this.qWindow=[],this.lastSizeDirection="ideal"}tick(t){let{observation:e,quality:r,timestampMs:s}=t,a=this.lastTickAt===null?0:Math.max(0,(s-this.lastTickAt)/1e3);this.lastTickAt=s;let n={presence:0,single:1,centering:0,size:0,pose:0,sharpness:F(r.sharpness),exposure:F(r.exposure),motion:1};if(e!==null){n.presence=1,n.single=(e.extraFaces??0)>0?0:1;let d=this.geometryOf(e,t);n.centering=d.centering,n.size=d.size,n.pose=d.pose,n.motion=this.motionOf(d.center,d.iod,s)}else this.lastCenter=null,this.velocityEma=0;let l=Math.min(n.presence,n.single,n.centering,n.size,n.pose,n.sharpness,n.exposure,n.motion);this.p=F(this.p+(l>=this.t.Q_GOOD?this.t.RISE_PER_S*l:-this.t.FALL_PER_S*(1-l))*a),this.qWindow.push({at:s,q:l}),this.qWindow=this.qWindow.filter(d=>d.at>=s-this.t.READY_WINDOW_MS);let c=this.qWindow.map(d=>d.q);if(c.length>=3){let d=Math.min(...c),u=c.indexOf(d);c=c.filter((v,w)=>w!==u)}let h=this.p>=1&&c.every(d=>d>=this.t.Q_GOOD);return{at:s,q:l,p:this.p,factors:n,guidanceKey:this.guidanceOf(n,r,l),ready:h,accepted:l>=this.t.Q_GOOD}}geometryOf(t,e){let{box:r,eyes:s}=t,a={x:e.frameWidth/2,y:e.frameHeight/2},n=Math.min(e.frameWidth,e.frameHeight),l=s!==void 0?{x:(s.left.x+s.right.x)/2,y:(s.left.y+s.right.y)/2}:{x:r.x+r.width/2,y:r.y+r.height/2-this.t.BOX_EYE_OFFSET_FACTOR*r.height},c=s!==void 0?Math.hypot(s.right.x-s.left.x,s.right.y-s.left.y):this.t.IOD_BOX_PROXY_FACTOR*r.width,h=Math.hypot(l.x-a.x,l.y-a.y),d=c<=0?0:1-F(h/(this.t.CENTER_FALLOFF_IOD_MULTIPLE*c)),u=n>0?c/n:0;this.lastSizeDirection=u<this.t.SIZE_IDEAL_MIN?"far":u>this.t.SIZE_IDEAL_MAX?"close":"ideal";let v;u<this.t.SIZE_HARD_MIN||u>this.t.SIZE_HARD_MAX?v=0:u<this.t.SIZE_IDEAL_MIN?v=(u-this.t.SIZE_HARD_MIN)/(this.t.SIZE_IDEAL_MIN-this.t.SIZE_HARD_MIN):u>this.t.SIZE_IDEAL_MAX?v=(this.t.SIZE_HARD_MAX-u)/(this.t.SIZE_HARD_MAX-this.t.SIZE_IDEAL_MAX):v=1;let w=1;if(s!==void 0){let m=Math.abs(Math.atan2(s.right.y-s.left.y,s.right.x-s.left.x))*180/Math.PI;w=1-F(m/this.t.ROLL_MAX_DEG)}return{center:l,iod:c,centering:d,size:v,pose:w}}motionOf(t,e,r){let s=this.lastCenter;if(this.lastCenter={...t,at:r},s===null||e<=0)return 1;let a=(r-s.at)/1e3;if(a<=0)return 1;let n=Math.hypot(t.x-s.x,t.y-s.y)/e/a;n<=this.t.MOTION_DEADBAND_IOD_PER_S&&(n=0);let l=1-Math.exp(-a/this.t.MOTION_TAU_S);return this.velocityEma=l*n+(1-l)*this.velocityEma,1-F(this.velocityEma/this.t.MOTION_VELOCITY_IOD_PER_S)}guidanceOf(t,e,r){if(t.presence<=0)return"fcv3.no_face";if(t.single<=0)return"fcv3.one_face";if(t.size<this.t.GUIDE_SIZE)return this.sizeGuidance();if(t.centering<this.t.GUIDE_CENTERING)return"fcv3.center_face";if(t.pose<this.t.GUIDE_POSE)return"fcv3.straighten";if(t.exposure<this.t.GUIDE_EXPOSURE)return this.exposureGuidance(e);if(t.sharpness<this.t.GUIDE_SHARPNESS)return"fcv3.steady_camera";if(t.motion<this.t.GUIDE_MOTION)return"fcv3.hold_still";if(r<this.t.Q_GOOD){let s=[["size",this.sizeGuidance()],["centering","fcv3.center_face"],["pose","fcv3.straighten"],["exposure",this.exposureGuidance(e)],["sharpness","fcv3.steady_camera"],["motion","fcv3.hold_still"]],a=s[0];for(let n of s)t[n[0]]<t[a[0]]&&(a=n);return a[1]}return"fcv3.hold_still"}sizeGuidance(){return this.lastSizeDirection==="far"?"fcv3.come_closer":"fcv3.move_back"}exposureGuidance(t){let e=(it[0]+it[1])/2;return t.meanLuma<e?"fcv3.more_light":"fcv3.too_bright"}},o(W,"k"),W),Je=["single","size","centering","pose","exposure","sharpness","motion"];function ti(i){if(i.accepted)return null;if(i.factors.presence<=0)return"no_face";let t="single";for(let e of Je)i.factors[e]<i.factors[t]&&(t=e);return t}o(ti,"Ze");var q,te=(q=class{constructor(){this.blocked={},this.acceptedMs=0,this.ticks=0,this.lastAt=null}record(t){let e=this.lastAt===null?0:Math.max(0,t.at-this.lastAt);this.lastAt=t.at,this.ticks+=1;let r=ti(t);if(r===null){this.acceptedMs+=e;return}let s=this.blocked[r]??{count:0,ms:0};s.count+=1,s.ms+=e,this.blocked[r]=s}summary(){let t={};for(let[e,r]of Object.entries(this.blocked))t[e]={count:r.count,ms:Math.round(r.ms)};return{blocked:t,acceptedMs:Math.round(this.acceptedMs),ticks:this.ticks}}},o(q,"w"),q),ei=["obs","manycam","virtual","snap camera","xsplit","droidcam","iriun","camo"],ii=[/^(front|back|rear)( [a-z ]+)? camera$/i,/^caméra (avant|arrière)\b/i,/^cámara (frontal|trasera|delantera)\b/i,/^câmera (frontal|traseira)\b/i,/^(front|rück)kamera\b/i,/^الكاميرا (الأمامية|الخلفية)/,/^camera2? ?\d+, facing (front|back|external)/i,/facetime/i,/\b(integrated|built-in|builtin) (web)?cam(era)?\b/i,/\b(hd )?web ?cam\b/i,/\([0-9a-f]{4}:[0-9a-f]{4}\)\s*$/i];function ri(i){let t=(i??"").trim().toLowerCase();return t.length===0?"unknown":ei.some(e=>t.includes(e))?"known_virtual":ii.some(e=>e.test(t))?"platform":"unknown"}o(ri,"je");function ee(i){if(typeof i!="function")return!1;try{return/\{\s*\[native code\]\s*\}\s*$/.test(Function.prototype.toString.call(i))}catch{return!1}}o(ee,"Te");function si(i=globalThis){return ee(i.navigator?.mediaDevices?.getUserMedia)&&ee(i.MediaStreamTrack?.prototype?.getSettings)}o(si,"$e");async function ai(i,t=globalThis){let e=t.crypto?.subtle?.digest;if(typeof e=="function")try{let r=new Uint8Array(await e.call(t.crypto?.subtle,"SHA-256",new TextEncoder().encode(i)));return Array.from(r.subarray(0,8),s=>s.toString(16).padStart(2,"0")).join("")}catch{return}}o(ai,"Je");async function ni(i,t=globalThis){let e={};try{e=typeof i.getSettings=="function"?i.getSettings()??{}:{}}catch{e={}}let r={};if((e.facingMode==="user"||e.facingMode==="environment"||e.facingMode==="left"||e.facingMode==="right")&&(r.facingMode=e.facingMode),typeof e.frameRate=="number"&&Number.isFinite(e.frameRate)&&(r.frameRate=e.frameRate),typeof e.width=="number"&&Number.isFinite(e.width)&&(r.width=e.width),typeof e.height=="number"&&Number.isFinite(e.height)&&(r.height=e.height),typeof e.deviceId=="string"&&e.deviceId.length>0){let a=await ai(e.deviceId,t);a!==void 0&&(r.deviceIdHash=a)}let s;try{s=i.label}catch{s=void 0}return{trackSettings:r,capabilitiesPresent:typeof i.getCapabilities=="function",labelClass:ri(s),prototypesIntact:si(t)}}o(ni,"Ce");var ot=o(i=>Math.round(i*100)/100,"H");function oi(i){let t=i,e=typeof t?.requestVideoFrameCallback=="function",r=null,s=null,a=0,n=0,l=0,c=0,h=0,d=0,u=o(()=>{!e||t?.requestVideoFrameCallback===void 0||(r=t.requestVideoFrameCallback((v,w)=>{if(r=null,!e)return;let m=w.presentationTime;if(s!==null){let g=m-s.presentationTimeMs;n+=1;let y=g-l;l+=y/n,c+=y*(g-l)}typeof w.captureTime=="number"&&Number.isFinite(w.captureTime)&&(h+=m-w.captureTime,d+=1),a+=1,s={mediaTimeMs:w.mediaTime*1e3,presentationTimeMs:m},u()}))},"u");return u(),{latest:o(()=>s,"latest"),stats:o(()=>({n:a,meanGapMs:n===0?0:ot(l),stdGapMs:n<2?0:ot(Math.sqrt(c/(n-1))),captureLatencyMs:d===0?null:ot(h/d)}),"stats"),stop:o(()=>{e&&(e=!1,r!==null&&t?.cancelVideoFrameCallback?.(r),r=null)},"stop")}}o(oi,"Ee");function li(i,t,e){return{...i,rvfc:t,rampPainter:e}}o(li,"_e");var ci=1e3,lt="fcv3.hold_upright",hi=200,ct=4,ui=600,di=1e3,ie={sharpness:1,exposure:1,meanLuma:128};function fi(i,t){return t.width=i.videoWidth,t.height=i.videoHeight,t.getContext("2d").drawImage(i,0,0),new Promise((e,r)=>t.toBlob(s=>s?e(s):r(new Error("empty-keyframe")),"image/jpeg",.92))}o(fi,"it");function mi(){return V()==="phone"}o(mi,"at");var z,le=(z=class{constructor(t){this.handlers=new Map,this.stateValue="idle",this.attempt=0,this.stream=null,this.detector=null,this.scheduler=null,this.gate=null,this.profiler=null,this.lastGuidanceKey=null,this.positioningStartedAt=0,this.cameraRequestedAt=null,this.cameraReadyAt=null,this.faceAcquiredAt=null,this.captureCompleteAt=null,this.fired=!1,this.carriedDegrade=0,this.carriedMeans=[],this.blockStats=null,this.lastGateSnapshotAt=Number.NEGATIVE_INFINITY,this.uprightGuard=!1,this.trackProvenance=null,this.ramp=null,this.snapshotCanvas=null,this.options=t,this.facing=t.facingMode??"user"}get state(){return this.stateValue}on(t,e){let r=this.handlers.get(t);return r||(r=new Set,this.handlers.set(t,r)),r.add(e),()=>r?.delete(e)}emit(t,e){for(let r of[...this.handlers.get(t)??[]])r(e)}async start(t={}){t.facingMode!==void 0&&(this.facing=t.facingMode),this.attempt+=1,await this.run(this.attempt)}get facingMode(){return this.facing}retry(){this.teardownAttempt(),this.start()}switchCamera(){this.facing=this.facing==="user"?"environment":"user",this.teardownAttempt(),this.start()}restart(t){this.facing=t,this.teardownAttempt(),this.start()}destroy(){this.attempt+=1,this.teardownAttempt(),this.detector?.destroy(),this.detector=null,this.options.video.srcObject=null}async run(t){let{options:e}=this;this.fired=!1,this.lastGuidanceKey=null,this.carriedDegrade=0,this.carriedMeans=[],this.cameraRequestedAt=null,this.cameraReadyAt=null,this.faceAcquiredAt=null,this.captureCompleteAt=null,this.uprightGuard=(e.isPhone??mi)(),this.setState("preflight");let r=Ct();if(r!=="OK"){this.fail(r==="INSECURE_CONTEXT"?"insecure":"unsupported",{phase:"preflight"});return}this.setState("acquiring");let s=e.getUserMedia??(h=>navigator.mediaDevices.getUserMedia(h)),a;this.cameraRequestedAt=this.now();try{let{facingMode:h,...d}=kt(Tt(),this.facing).video;a=await Lt(this.facing,d,{getUserMedia:s,enumerateDevices:vi(e)})}catch(h){if(t!==this.attempt)return;if(h instanceof Nt){this.fail("backcamera",{phase:"acquiring",name:K(h)});return}this.fail(Ut(h),{phase:"acquiring",name:K(h)});return}if(Et(a),Ft(a),t!==this.attempt){for(let h of a.getTracks())h.stop();return}this.stream=a;let n=a.getVideoTracks?.()[0];if(this.trackProvenance=n===void 0?null:ni(n).catch(()=>null),this.facing=_t(a)??this.facing,e.video.srcObject=a,await e.video.play().catch(()=>{}),t!==this.attempt)return;if(this.cameraReadyAt=this.now(),this.detector===null){let h={v3AssetBaseUrl:e.v3AssetBaseUrl},d=e.createDetector??(e.createWorker!==void 0&&Zt()?async()=>{try{return await jt.create(e.createWorker(),h)}catch{return x(h)}}:()=>x(h)),u;try{u=await d()}catch(v){t===this.attempt&&this.fail("models",{phase:"models",name:K(v)},v instanceof nt?v.fallbackReason:gi(v));return}if(t!==this.attempt){u.destroy();return}this.detector=u,this.options.telemetry?.({type:"detector",tier:u.tier,fallbackReason:u.fallbackReason})}let l=Bt(),c=e.deviceClass??Wt(l);this.profiler=new qt(c),this.options.telemetry?.({type:"profile",staticClass:c,activeClass:this.profiler.deviceClass,simd:l.simd}),this.gate=new Jt(e.thresholds??{}),this.blockStats=new te,this.lastGateSnapshotAt=this.now(),e.rankKeyframes?.()&&import("./keyframe-rank-YAJLYJYF-WCA6RPMD.js").then(h=>ht=h,()=>{}),this.setState("positioning"),this.positioningStartedAt=this.now(),this.startScheduler(t)}get animations(){return this.profiler?.profile.animations??"full"}startScheduler(t){let e=this.profiler;if(e===null)return;if(this.scheduler!==null){let s=this.scheduler.stats();this.carriedDegrade+=s.degradeCount,s.meanDetectMs>0&&this.carriedMeans.push(s.meanDetectMs),this.scheduler.stop()}let r=new Ye({cadenceHz:e.profile.cadenceHz,video:this.options.video,now:this.options.now,run:o(()=>this.detectTick(t),"run")});this.scheduler=r,r.start()}async detectTick(t){let{detector:e,gate:r,profiler:s}=this,a=this.options.video;if(t!==this.attempt||e===null||r===null||s===null||this.fired||a.videoWidth===0)return;if(this.isLandscape()){this.holdUpright(t);return}let n=s.deviceClass,l=this.now(),c=this.options.makeSnapshot?.(a,s.profile.inputWidth)??this.defaultSnapshot(a,s.profile.inputWidth),h=null;try{h=await e.detect(c,a.videoWidth,a.videoHeight)}catch{h=null}if(t!==this.attempt||this.fired)return;s.record(this.now()-l),s.deviceClass!==n&&this.startScheduler(t);let d=h===null?ie:this.options.measureQuality?.(a,h.box)??this.defaultQuality(a,h.box),u=r.tick({timestampMs:this.now(),observation:h,quality:d,frameWidth:a.videoWidth,frameHeight:a.videoHeight});u.accepted&&this.faceAcquiredAt===null&&(this.faceAcquiredAt=u.at),this.blockStats?.record(u),!u.ready&&u.at-this.lastGateSnapshotAt>=ci&&(this.lastGateSnapshotAt=u.at,this.reportGate(!1)),this.emit("checks",{engine:"v3",progress:u.p,q:u.q,factors:u.factors,attempt:t}),u.guidanceKey!==this.lastGuidanceKey&&(this.lastGuidanceKey=u.guidanceKey,this.emit("guidance",{key:u.guidanceKey})),u.ready&&this.stateValue==="positioning"&&(this.fired=!0,this.captureCompleteAt=u.at,this.fire(t))}async fire(t){let{options:e}=this,r=this.scheduler;r?.stop(),this.reportGate(!0);let s=r?.stats()??{degradeCount:0,meanDetectMs:0},a=[...this.carriedMeans,...s.meanDetectMs>0?[s.meanDetectMs]:[]];e.telemetry?.({type:"fired",timeToGateMs:this.now()-this.positioningStartedAt,degradeCount:this.carriedDegrade+s.degradeCount,meanDetectMs:a.length===0?0:a.reduce((k,b)=>k+b,0)/a.length});let n=e.mode??"clip",l=e.rankKeyframes?.()&&ht?ht.default(this,t).catch(()=>this.collectKeyframes(t)):this.collectKeyframes(t);if(n==="photo"){let k=this.watchRotation(t,null),b=await l;if(k(),t!==this.attempt)return;if(b===null){this.fail("generic",{phase:"keyframes"});return}let I=await this.provenance({n:0,meanGapMs:0,stdGapMs:0,captureLatencyMs:null},!1);if(t!==this.attempt)return;this.finishCapture({keyframe:b.blob,previewDataUrl:b.previewDataUrl,...I});return}this.setState("recording");let c=this.stream;if(c===null){this.fail("generic",{phase:"recording"});return}let h=e.screenRamp?.(),d=h!==void 0,u=null;l.then(k=>{u=k},()=>{});let v=o(()=>{t===this.attempt&&u!==null&&this.emit("frozen",{previewDataUrl:u.previewDataUrl})},"f"),w=Ze(h,ne),m=null,g,y=0;try{let k=this.recordTake(t,c,h,w,void 0).then(_=>_,_=>({failed:_})),[b,I]=await Promise.all([k,l]);if(g=I,t!==this.attempt)return;if("failed"in b){if(b.failed.kind==="cliptoolarge")throw b.failed;$t(b.failed.requestedMimeType??"")}else m=b,Qt(b.clip,w)?b.clip.stats===null&&$t(b.clip.requestedMimeType??""):v();if(m===null||Qt(m.clip,w)){y=1,e.telemetry?.({type:"clip_retake",reason:m===null?"error":m.clip.stats===null?"unreadable":"short"});let _=null;try{_=await this.recordTake(t,c,h,w,v)}catch(H){if(m===null)throw H}if(t!==this.attempt)return;_!==null&&(m===null||We(_.clip,m.clip))&&(m=_),_===null&&v()}}catch(k){if(t!==this.attempt)return;let b=k.kind;this.fail(b==="cliptoolarge"?"cliptoolarge":"recorder",{phase:"recording",name:K(k)});return}if(m===null){this.fail("recorder",{phase:"recording"});return}let{clip:p,rvfc:M,report:T}=m;if(et(p.blob)){this.fail("cliptoolarge",{phase:"recording"});return}if(g===null){this.fail("generic",{phase:"keyframes"});return}let A=await this.provenance(M,d);t===this.attempt&&this.finishCapture({clip:p.blob,clipMimeType:p.mimeType,...p.stats?{clipStats:p.stats}:{},clipRetakes:y,keyframe:g.blob,previewDataUrl:g.previewDataUrl,...T!==void 0&&T.rendered.length>0?{screenRamp:T}:{},...A})}async recordTake(t,e,r,s,a){let n=this.options.createRecorder?.()??new qe({now:o(()=>this.now(),"now")}),l=oi(this.options.video),c=je(r,{paint:o(u=>{(u===null||t===this.attempt)&&this.emit("ramp",{colour:u})},"paint"),now:o(()=>this.now(),"now"),frames:l.latest});this.ramp=c;let h=o(()=>{l.stop(),c.stop(),this.ramp===c&&(this.ramp=null)},"l"),d=this.watchRotation(t,n);try{return{clip:await n.record(e,a,()=>c.started(this.now()),s,l),rvfc:l.stats(),report:c.report()}}finally{d(),h()}}async provenance(t,e){let r=this.trackProvenance;if(r===null)return{};let s,a=new Promise(l=>{s=setTimeout(()=>l(null),di)}),n=await Promise.race([r,a]);return clearTimeout(s),n===null?{}:{provenance:li(n,t,e)}}isLandscape(){let t=this.options.video;return this.uprightGuard&&t.videoWidth>t.videoHeight}holdUpright(t){this.gate?.reset(),this.emit("checks",{engine:"v3",progress:0,q:0,factors:{presence:0,single:1,centering:0,size:0,pose:0,sharpness:0,exposure:0,motion:0},attempt:t}),this.lastGuidanceKey!==lt&&(this.lastGuidanceKey=lt,this.emit("guidance",{key:lt}))}watchRotation(t,e){if(!this.uprightGuard)return()=>{};let r=this.options.video,s=o(()=>{if(t!==this.attempt||e!==null&&this.stateValue!=="recording"){l();return}r.videoWidth>0&&this.isLandscape()&&(l(),this.abortRecording(t,e))},"n"),a=setInterval(s,hi);r.addEventListener?.("resize",s);let n=!1;function l(){n||(n=!0,clearInterval(a),r.removeEventListener?.("resize",s))}return o(l,"o"),l}abortRecording(t,e){if(t!==this.attempt)return;this.attempt+=1;let r=this.attempt;try{e?.stop()}catch{}this.ramp?.stop(),this.ramp=null,this.fired=!1,this.captureCompleteAt=null,this.gate=new Jt(this.options.thresholds??{}),this.blockStats=new te,this.lastGateSnapshotAt=this.now(),this.lastGuidanceKey=null,this.setState("positioning"),this.positioningStartedAt=this.now(),this.holdUpright(r),this.startScheduler(r)}async collectKeyframes(t){let e=this.options.captureKeyframe??(a=>this.defaultKeyframe(a)),r=ui/(ct-1),s=null;for(let a=0;a<ct;a+=1){if(t!==this.attempt)return s;try{let n=await e(this.options.video);(s===null||n.sharpness>s.sharpness)&&(s=n)}catch{}a<ct-1&&await pi(r)}return s}finishCapture(t){this.stopTracks(),this.setState("captured");let e=this.captureTiming();this.emit("artifacts",e===void 0?t:{...t,timing:e})}captureTiming(){let t={},e=o((r,s,a)=>{s!==null&&a!==null&&(t[r]=Math.max(0,Math.round(a-s)))},"t");return e("cameraReadyMs",this.cameraRequestedAt,this.cameraReadyAt),e("faceAcquireMs",this.cameraReadyAt,this.faceAcquiredAt),e("captureMs",this.faceAcquiredAt,this.captureCompleteAt),Object.keys(t).length>0?t:void 0}async defaultKeyframe(t){let e=document.createElement("canvas"),r=await(this.facing==="user"?$e:fi)(t,e),s=e.toDataURL("image/jpeg",.92);return{blob:r,previewDataUrl:s,sharpness:this.centerSharpness(t)}}defaultSnapshot(t,e){try{let r=this.snapshotCanvas??document.createElement("canvas"),s=e/Math.max(1,t.videoWidth),a=Math.max(1,Math.round(t.videoWidth*s)),n=Math.max(1,Math.round(t.videoHeight*s)),l=r.getContext("2d");return l===null?t:(r.width!==a&&(r.width=a),r.height!==n&&(r.height=n),l.drawImage(t,0,0,a,n),this.snapshotCanvas=r,r)}catch{return t}}defaultQuality(t,e){let r=re(t,e,96);return r===null?ie:{sharpness:rt(r),exposure:Ht(r),meanLuma:zt(r)}}centerSharpness(t){let e=Z(t),r=re(t,{x:e.width*.25,y:e.height*.25,width:e.width*.5,height:e.height*.5},96);return r===null?0:rt(r)}teardownAttempt(){this.scheduler?.stop(),this.scheduler=null,this.reportGate(!0),this.gate=null,this.ramp?.stop(),this.ramp=null,this.stopTracks()}reportGate(t){let e=this.blockStats,r=this.profiler;if(e===null||r===null)return;let s=e.summary();t&&(this.blockStats=null),s.ticks!==0&&this.options.telemetry?.({type:"gate",final:t,activeClass:r.deviceClass,cadenceHz:r.profile.cadenceHz,...s})}stopTracks(){if(this.stream!==null){for(let t of this.stream.getTracks())t.stop();this.stream=null}}fail(t,e,r){this.scheduler?.stop(),this.reportGate(!0),this.stopTracks(),this.setState("error"),this.options.telemetry?.({type:"error",kind:t,fallbackReason:r});let{phase:s,name:a}=e;this.emit("error",{kind:t,retryable:t!=="insecure"&&t!=="unsupported",detail:a===void 0?{phase:s}:{phase:s,name:a}})}setState(t){this.stateValue=t,this.emit("statechange",{state:t})}now(){return this.options.now?.()??performance.now()}},o(z,"ke"),z),ht;function pi(i){return new Promise(t=>setTimeout(t,i))}o(pi,"st");function gi(i){return i instanceof Error?i.message:String(i)}o(gi,"ot");function re(i,t,e){try{let r=document.createElement("canvas"),s=e/Math.max(1,t.width);r.width=Math.max(1,Math.round(t.width*s)),r.height=Math.max(1,Math.round(t.height*s));let a=r.getContext("2d");return a===null?null:(a.drawImage(i,t.x,t.y,t.width,t.height,0,0,r.width,r.height),a.getImageData(0,0,r.width,r.height))}catch{return null}}o(re,"we");function vi(i){if(i.enumerateDevices!==void 0)return i.enumerateDevices;if(i.getUserMedia===void 0&&!(typeof navigator>"u"||typeof navigator.mediaDevices?.enumerateDevices!="function"))return()=>navigator.mediaDevices.enumerateDevices()}o(vi,"lt");var yi=12e4,ce=13e4,wi=3e3,bi=1200,ut=Symbol.for("@sekyro/web.preload.v1");function ft(){let i=globalThis;return i[ut]??(i[ut]=new Map),i[ut]}o(ft,"g");function Y(i){let t=(i??at).replace(/\/+$/,"");return t===""?"/":t}o(Y,"S");function ue(i){let t=ft(),e=t.get(i);return e===void 0&&(e={status:"idle",promise:null,scheduled:null,detectorPromise:null,detector:null,listeners:new Set},t.set(i,e)),e}o(ue,"se");function dt(i,t){if(i.status!==t){i.status=t;for(let e of[...i.listeners])e(t)}}o(dt,"A");var Mi=o(i=>x({preferred:["blaze"],v3AssetBaseUrl:i,blazeInitTimeoutMs:yi}),"x"),ki=Mi;function Ti(){return typeof window<"u"&&typeof navigator<"u"&&typeof navigator.mediaDevices?.getUserMedia=="function"}o(Ti,"pe");function _i(){return navigator.connection?.saveData===!0}o(_i,"me");function Ei(i){let t=window;if(typeof t.requestIdleCallback=="function"){let r=t.requestIdleCallback(i,{timeout:wi});return()=>t.cancelIdleCallback?.(r)}let e=setTimeout(i,bi);return()=>clearTimeout(e)}o(Ei,"ve");function Si(i,t){let e,r=new Promise(l=>{e=l}),s=!1,a=o(()=>{},"d"),n={promise:r,settle:o(l=>{s||(s=!0,a(),i.scheduled===n&&(i.scheduled=null),e(l))},"settle")};return i.scheduled=n,a=Ei(()=>{s||n.settle(mt(i,t))}),r}o(Si,"ge");function mt(i,t){if((i.status==="loading"||i.status==="ready")&&i.promise!==null)return i.promise;dt(i,"loading");let e=new Promise(n=>n(ki(t)));i.detectorPromise=e;let r,s=new Promise((n,l)=>{r=setTimeout(()=>{e.then(c=>c.destroy(),()=>{}),l(new Error(`detector preload exceeded ${ce} ms`))},ce)}),a=Promise.race([e,s]).then(n=>i.detectorPromise!==e?(n.destroy(),i.status):(i.detector=n,dt(i,"ready"),"ready"),n=>(i.detectorPromise===e&&(i.detectorPromise=null,i.detector=null,dt(i,"failed"),console.warn("[@sekyro/web] face-detector preload failed:",n)),i.status)).finally(()=>clearTimeout(r));return i.promise=a,i.scheduled?.settle(a),a}o(mt,"I");function Yi(i={}){if(!Ti())return Promise.resolve("idle");let t=Y(i.assetBaseUrl),e=ue(t);return i.respectSaveData===!0&&_i()?Promise.resolve(e.status):(e.status==="loading"||e.status==="ready")&&e.promise!==null?e.promise:i.idle===!0?e.scheduled?.promise??Si(e,t):mt(e,t)}o(Yi,"we");function Qi(i){return ft().get(Y(i))?.status??"idle"}o(Qi,"ke");function Ji(i,t){let e=ue(Y(t));return e.listeners.add(i),()=>{e.listeners.delete(i)}}o(Ji,"De");function Ai(i){return{get tier(){return i.tier},get fallbackReason(){return i.fallbackReason},detect:o((...t)=>i.detect(...t),"detect"),destroy:o(()=>{},"destroy")}}o(Ai,"he");function Ii(i){let t=Y(i),e=ft().get(t);if(!(e===void 0||e.detector===null&&e.detectorPromise===null&&e.scheduled===null))return async()=>{e.scheduled!==null&&mt(e,t);let r=e.promise;for(;e.detector===null&&r!==null&&(await r,e.promise!==r);)r=e.promise;return e.detector!==null?Ai(e.detector):x({v3AssetBaseUrl:t})}}o(Ii,"oe");function xi(i){switch(i){case"fcv3.no_face":case"fcv3.center_face":case"fcv3.straighten":return"center";case"fcv3.come_closer":return"closer";case"fcv3.move_back":return"farther";case"fcv3.more_light":case"fcv3.too_bright":return"light";case"fcv3.hold_still":case"fcv3.steady_camera":return"still";case"fcv3.hold_upright":return"upright";case"fcv3.one_face":return"one_face";default:return null}}o(xi,"Ce");function Di(i){switch(i){case"preflight":case"acquiring":return"starting";case"positioning":return"gating";default:return i}}o(Di,"Se");function he(i){switch(i){case"permission":case"notfound":case"inuse":case"insecure":case"unsupported":return i;case"backcamera":return"notfound";default:{let t=i;return"generic"}}}o(he,"ie");function Ri(i,t,e){if(e===void 0)return{kind:he(i),retryable:t};let r=Gt(e.name);return{kind:he(i),retryable:t,detail:{...r!==void 0?{name:r}:{},phase:e.phase,engineKind:i}}}o(Ri,"Le");var Ci=new Set(["captured","uploading","checking"]);function Oi(i,t={},e,r=()=>"self",s=()=>{},a){let n=t.now??(()=>performance.now()),l=t.canChooseFacing??At,c="user",h=It(),d=r(),u=St(),v=!Ot(),w=t.engineOptions,m=w?.createDetector===void 0&&w?.createWorker===void 0?{createDetector:o(()=>{let f=Ii(i.assetBaseUrl);return f!==void 0?f():x({v3AssetBaseUrl:i.assetBaseUrl})},"createDetector")}:{},g={video:i.video,mode:v?"photo":"clip",rankKeyframes:e,facingMode:void 0,v3AssetBaseUrl:i.assetBaseUrl,screenRamp:o(()=>d==="self"&&u.count("ramp")>0?s():void 0,"screenRamp"),...t.engineOptions??{},...m},y=t.createEngine?.(g)??new le(g),p="idle",M=null,T=0,A=!1,k="full",b=null,I=null,_=0,H=0,pt=o(()=>{i.video.videoWidth>0&&i.video.videoHeight>0&&(_=i.video.videoWidth,H=i.video.videoHeight)},"K"),gt=xt({enabled:i.keepScreenAwake!==!1}),X=o(f=>{p=f,gt.setActive(f==="starting"||f==="gating"||f==="recording"),u.emit("state",f)},"M"),Q=o(()=>u.emit("gate",{progress:T,hint:M,faceDetected:A}),"R"),vt=o(()=>{let f=y.animations??"full";f!==k&&(k=f,u.emit("profile",{animations:k}))},"G"),de=[y.on("statechange",({state:f})=>{let E=Di(f);E==="starting"&&p!=="starting"&&(M=null,T=0,A=!1,b=null,I=null,_=0,H=0),X(E),vt(),E==="recording"&&(pt(),b=n(),M="hold",T=1,Q())}),y.on("checks",f=>{pt(),T=f.progress,A=f.factors.presence>0,Q(),vt()}),y.on("guidance",({key:f})=>{M=xi(f),Q()}),y.on("frozen",({previewDataUrl:f})=>{I=n(),u.emit("frozen",{previewDataUrl:f})}),y.on("ramp",f=>u.emit("ramp",f)),y.on("artifacts",f=>{if(p!=="captured")return;let E=V(),S=f.clipStats,bt=S!==void 0?Math.round(S.durationMs):b!==null&&I!==null?Math.max(0,Math.round(I-b)):void 0,Mt=S!==void 0&&S.frames>1&&S.durationMs>0?Math.round(S.frames*1e4/S.durationMs)/10:void 0;u.emit("captured",{keyframe:f.keyframe,...f.clip!==void 0?{clip:f.clip}:{},...f.clipMimeType!==void 0?{clipMime:f.clipMimeType}:{},width:i.video.videoWidth||_,height:i.video.videoHeight||H,...bt!==void 0?{clipMs:bt}:{},...S!==void 0?{clipFrames:S.frames}:{},...Mt!==void 0?{fps:Mt}:{},...f.clipRetakes!==void 0?{clipRetakes:f.clipRetakes}:{},...f.clipMimeType!==void 0?{codec:ae(f.clipMimeType)}:{},captureChannel:E==="desktop"?"desktop":"mobile",formFactor:E,...v?{degraded:"NO_RECORDER"}:{},engine:"v3",facingMode:y.facingMode,mode:d,...f.timing,...f.screenRamp!==void 0?{screenRamp:f.screenRamp}:{},...f.provenance!==void 0?{provenance:f.provenance}:{}})}),y.on("error",({kind:f,retryable:E,detail:S})=>{f==="backcamera"&&fe()||u.emit("error",Ri(f,E,S))})],yt=!1;function fe(){return J||yt||d!=="assisted"||a===void 0||a.session()!=="choice"?!1:(yt=!0,a.onModeChange("self"),d="self",c=tt("self"),X("mode_switch"),y.restart(c),!0)}o(fe,"ce");let wt=o(async()=>a!==void 0&&a.session()==="choice"&&await l().catch(()=>!1),"W"),J=!1;return{handle:{get state(){return p},get captureMode(){return r()},get facingMode(){return y.facingMode??c},on:o((f,E)=>u.on(f,E),"on"),start:o(f=>(d=r(),h.facing(d,i.facing),c=h.facing(d,f?.facing),y.start({facingMode:c})),"start"),retry:o(()=>y.retry(),"retry"),switchCamera:o(()=>h.refuseSwitch(r()),"switchCamera"),canSwitchCaptureMode:wt,setCaptureMode:o(async f=>{if(f===r()||!await wt()||J||Ci.has(p)||a===void 0)return!1;a.onModeChange(f),d=f;let E=tt(f);return c=E,p==="idle"||(X("mode_switch"),y.restart(E)),!0},"setCaptureMode"),destroy:o(()=>{J=!0;for(let f of de)f();gt.setActive(!1),y.destroy(),u.clear()},"destroy")},setFlowState:o(f=>{p!==f&&X(f)},"setFlowState")}}o(Oi,"Ee");function tr(i){return Oi(i).handle}o(tr,"ze");export{zi as a,Yi as b,Qi as c,Ji as d,Ri as e,Oi as f,tr as g};
1
+ import{d as Et,e as Bt,f as Wt,g as qt}from"./chunk-GIGTK355.js";import{a as it,b as zt,c as rt,d as Ht}from"./chunk-P7K7ELYZ.js";import{a as kt,b as V,c as Tt,d as _t,e as St,g as At,h as tt,i as It,j as xt,k as Nt,l as Lt}from"./chunk-CW56KMMH.js";import{a as Dt,b as Rt,c as Ct,d as Ot,e as Pt,f as et,g as K,h as Gt,i as Ut,j as Ft}from"./chunk-JS2IXPNL.js";import{a as o}from"./chunk-4FHWXBOB.js";var me=1e4,C,pe=(C=class{constructor(t,e){this.tier="blaze",this.inner=t,e!==void 0&&(this.fallbackReason=e)}static async create(t,e){let r=await import("./vision_bundle-WBHR7TEE.js"),s=await r.FilesetResolver.forVisionTasks(t),a=await r.FaceDetector.createFromOptions(s,{baseOptions:{modelAssetPath:`${t}/blaze_face_short_range.tflite`,delegate:"CPU"},runningMode:"IMAGE"});return new C(a,e)}async detect(t,e,r){let s;try{s=this.inner.detect(t).detections}catch{return null}let a=ge(s);if(a?.boundingBox===void 0)return null;let n=Z(t),l=ve(a.keypoints,n),c=a.keypoints?.[2],h={box:{x:a.boundingBox.originX,y:a.boundingBox.originY,width:a.boundingBox.width,height:a.boundingBox.height},...l!==void 0?{eyes:l}:{},...c!==void 0?{nose:{x:c.x*n.width,y:c.y*n.height}}:{},score:a.categories[0]?.score??0,extraFaces:Kt(s.map(d=>d.boundingBox??{width:0,height:0}),s.indexOf(a))};return Xt(h,t,e,r)}destroy(){try{this.inner.close()}catch{}}},o(C,"t"),C);function ge(i){let t,e=-1;for(let r of i){let s=r.categories[0]?.score??0;s>e&&(t=r,e=s)}return t}o(ge,"R");function ve(i,t){let e=i?.[0],r=i?.[1];if(e===void 0||r===void 0)return;let s=o(l=>({x:l.x*t.width,y:l.y*t.height}),"n"),[a,n]=[s(e),s(r)];return a.x<=n.x?{left:a,right:n}:{left:n,right:a}}o(ve,"T");function ye(){if(typeof OffscreenCanvas=="function")return new OffscreenCanvas(2,2);let i=document.createElement("canvas");return i.width=2,i.height=2,i}o(ye,"E");var we=4;async function be(){let i=globalThis.FaceDetector;if(typeof i!="function")return{ok:!1,reason:"unsupported"};try{let t=new i({fastMode:!0,maxDetectedFaces:we});return await t.detect(ye()),{ok:!0,instance:t}}catch(t){return{ok:!1,reason:`smoke_failed:${t instanceof Error?t.message:String(t)}`}}}o(be,"w");var P,Me=(P=class{constructor(t,e){this.tier="native",this.inner=t,e!==void 0&&(this.fallbackReason=e)}async detect(t,e,r){let s;try{s=await this.inner.detect(t)}catch{return null}let a=s.map(d=>d.boundingBox),n=-1;a.forEach((d,u)=>{let v=a[n];(v===void 0||d.width*d.height>v.width*v.height)&&(n=u)});let l=s[n];if(l===void 0)return null;let c=ke(l.landmarks),h={box:{x:l.boundingBox.x,y:l.boundingBox.y,width:l.boundingBox.width,height:l.boundingBox.height},...c!==void 0?{eyes:c}:{},score:1,extraFaces:Kt(a,n)};return Xt(h,t,e,r)}destroy(){}},o(P,"b"),P);function ke(i){if(i===void 0)return;let t=i.filter(s=>s.type==="eye").map(s=>s.locations[0]).filter(s=>s!==void 0),[e,r]=t;if(!(e===void 0||r===void 0))return e.x<=r.x?{left:e,right:r}:{left:r,right:e}}o(ke,"S");var Te=.25;function Kt(i,t){let e=i[t],r=e===void 0?0:e.width*e.height;if(!(r>0))return 0;let s=0;return i.forEach((a,n)=>{n!==t&&a.width*a.height>=Te*r&&(s+=1)}),s}o(Kt,"f");var at="/models-v3",_e=["native","blaze"],G,nt=(G=class extends Error{constructor(t){super(`no detector tier available (${t})`),this.name="DetectorLadderError",this.fallbackReason=t}},o(G,"x"),G);function Z(i){let t=i;if(typeof t.videoWidth=="number"&&t.videoWidth>0)return{width:t.videoWidth,height:t.videoHeight??0};if(typeof t.naturalWidth=="number"&&t.naturalWidth>0)return{width:t.naturalWidth,height:t.naturalHeight??0};let e=typeof t.width=="number"?t.width:0,r=typeof t.height=="number"?t.height:0;return{width:e,height:r}}o(Z,"y");function Xt(i,t,e,r){let s=Z(t),a=s.width>0?e/s.width:1,n=s.height>0?r/s.height:1,l=o(c=>({x:c.x*a,y:c.y*n}),"s");return{box:{x:i.box.x*a,y:i.box.y*n,width:i.box.width*a,height:i.box.height*n},...i.eyes!==void 0?{eyes:{left:l(i.eyes.left),right:l(i.eyes.right)}}:{},...i.nose!==void 0?{nose:l(i.nose)}:{},score:i.score,...i.extraFaces!==void 0?{extraFaces:i.extraFaces}:{}}}o(Xt,"h");function Ee(i){return i instanceof Error?i.message:String(i)}o(Ee,"C");async function x(i){let t=i.preferred??_e,e=[];for(let r of t){if(r==="native"){let s=await be();if(s.ok)return new Me(s.instance,st(e));e.push(`native:${s.reason}`);continue}try{return await Se(pe.create(i.v3AssetBaseUrl??at,st(e)),i.blazeInitTimeoutMs??me)}catch(s){e.push(s instanceof Vt?"blaze:blaze_init_timeout":`blaze:${Ee(s)}`)}}throw new nt(st(e)??"no_tier_available")}o(x,"O");function st(i){return i.length>0?i.join("; "):void 0}o(st,"v");var U,Vt=(U=class extends Error{},o(U,"g"),U);function Se(i,t){return new Promise((e,r)=>{let s=setTimeout(()=>{r(new Vt(`init exceeded ${t}ms`)),i.then(a=>a.destroy(),()=>{})},t);i.then(a=>{clearTimeout(s),e(a)},a=>{clearTimeout(s),r(a)})})}o(Se,"W");var R=1;function Zt(){return typeof OffscreenCanvas=="function"&&typeof createImageBitmap=="function"&&typeof Worker=="function"}o(Zt,"K");function Ae(i,t={}){let e=t.createDetector??x,r=null;i.onmessage=s=>{let a=s.data;if(a.v!==R){a.bitmap?.close?.();return}if(a.type==="init"){e(a.options).then(n=>{r=n;let l={v:R,type:"ready",tier:n.tier,...n.fallbackReason!==void 0?{fallbackReason:n.fallbackReason}:{}};i.postMessage(l)});return}if(a.type==="detect"){let n=o(l=>{let c={v:R,type:"result",id:a.id,observation:l};i.postMessage(c),a.bitmap.close?.()},"a");if(r===null){n(null);return}r.detect(a.bitmap,a.streamWidth,a.streamHeight).then(n,()=>n(null))}}}o(Ae,"B");typeof self<"u"&&typeof self.importScripts=="function"&&Ae(self);var O,jt=(O=class{constructor(t,e){this.pending=new Map,this.nextId=1,this.worker=t,this.tier=e.tier,e.fallbackReason!==void 0&&(this.fallbackReason=e.fallbackReason),t.addEventListener("message",r=>{let s=r.data;if(s.v!==R||s.type!=="result")return;let a=this.pending.get(s.id);this.pending.delete(s.id),a?.(s.observation)})}static create(t,e,r=1e4){return new Promise((s,a)=>{let n=setTimeout(()=>{t.removeEventListener("message",l),t.terminate(),a(new Error(`worker detector not ready within ${r}ms`))},r),l=o(h=>{let d=h.data;d.v!==R||d.type!=="ready"||(clearTimeout(n),t.removeEventListener("message",l),s(new O(t,d)))},"s");t.addEventListener("message",l);let c={v:R,type:"init",options:e};t.postMessage(c)})}async detect(t,e,r){let s;try{typeof ImageBitmap<"u"&&t instanceof ImageBitmap?s=t:typeof createImageBitmap=="function"?s=await createImageBitmap(t):s=t}catch{return null}let a=this.nextId;return this.nextId+=1,new Promise(n=>{this.pending.set(a,n);let l={v:R,type:"detect",id:a,bitmap:s,streamWidth:e,streamHeight:r};this.worker.postMessage(l,[s])})}destroy(){for(let t of this.pending.values())t(null);this.pending.clear(),this.worker.terminate()}},o(O,"t"),O);var Ie=[...Dt.filter(i=>i.startsWith("video/mp4")),"video/webm;codecs=h264","video/webm;codecs=avc1","video/webm;codecs=vp8","video/webm;codecs=vp9","video/webm"],se=new Set;function xe(i){let t=/(?:Chrome|Chromium)\/(\d+)\./.exec(i??"");return t?Number(t[1]):null}o(xe,"De");function De(i=Ce(),t=globalThis.navigator?.userAgent){if(i===void 0)return"";let e=xe(t)===126;for(let r of Ie)if(!(se.has(r)||e&&r.startsWith("video/mp4")))try{if(i(r))return r}catch{}return""}o(De,"he");function $t(i){i!==""&&se.add(i)}o($t,"F");function Re(i){return i.replace(/^video\/x-matroska/i,"video/webm")}o(Re,"fe");function ae(i){let t=/codecs=["']?([^,;"']+)/i.exec(i);return t?t[1].trim():i.split(";")[0].trim()}o(ae,"ut");function Ce(){let i=globalThis.MediaRecorder;return i&&typeof i.isTypeSupported=="function"?t=>i.isTypeSupported(t):void 0}o(Ce,"Oe");var ne=2500,Oe=1e3,Pe=1500,Yt=25e5,Ge=100,Ue=700,Fe=20,Ne=1500,j=null;function Le(){return j??(j=import("./clip-inspect-DLJXVKV6-TNHTD4LV.js").catch(i=>{throw j=null,i})),j.catch(()=>null)}o(Le,"Ne");var N,D=(N=class extends Error{constructor(t,e){super(e??t),this.kind=t}},o(N,"S"),N),Be=100;function Qt(i,t){return i.stats===void 0?!1:i.stats===null?!0:i.stats.durationMs<t-Be}o(Qt,"U");function We(i,t){return i.stats?t.stats?i.stats.durationMs>t.stats.durationMs:!0:!1}o(We,"ge");var L,qe=(L=class{constructor(t={}){this.recorder=null,this.stream=null,this.chunks=[],this.bytes=0,this.hardStopTimer=null,this.graceTimer=null,this.pollTimer=null,this.settled=!1,this.now=t.now??(()=>globalThis.performance?.now?.()??Date.now())}clearTimers(){this.hardStopTimer&&clearTimeout(this.hardStopTimer),this.graceTimer&&clearTimeout(this.graceTimer),this.pollTimer&&clearInterval(this.pollTimer),this.hardStopTimer=null,this.graceTimer=null,this.pollTimer=null}record(t,e,r,s=ne,a){let n=De(),l=Le();return this.recordRaw(t,e,r,s,a,n).then(c=>ze(c,l),c=>{throw c instanceof D&&(c.requestedMimeType=n),c})}recordRaw(t,e,r,s,a,n){return this.recorder&&!this.settled?Promise.reject(new D("generic","record() called while a recording is in flight — ClipRecorder handles one recording at a time")):(this.recorder=null,this.clearTimers(),this.chunks=[],this.bytes=0,this.settled=!1,this.stream=t,new Promise((l,c)=>{let h;try{h=new MediaRecorder(t,n?{mimeType:n,videoBitsPerSecond:Yt}:{videoBitsPerSecond:Yt})}catch{try{h=new MediaRecorder(t)}catch{c(new D("unsupported"));return}}this.recorder=h;let d=o(p=>{this.settled||(this.settled=!0,this.clearTimers(),p())},"d"),u=o(()=>d(()=>{let p=Re(h.mimeType||n||Rt),M=new Blob(this.chunks,{type:p});if(M.size===0){c(new D("generic","empty clip"));return}if(et(M)){c(new D("cliptoolarge"));return}l({blob:M,mimeType:p,requestedMimeType:n})}),"u");h.ondataavailable=p=>{p.data&&p.data.size&&(this.chunks.push(p.data),this.bytes+=p.data.size,this.bytes>Pt&&d(()=>{try{h.state!=="inactive"&&h.stop()}catch{}c(new D("cliptoolarge"))}))},h.onstop=u,h.onerror=()=>d(()=>c(new D("generic")));let v=this.now();if(r!==void 0||a!==void 0){let p=!1;h.onstart=()=>{if(!(p||this.settled)&&(p=!0,v=this.now(),r!==void 0))try{r()}catch{}}}try{h.start(Oe)}catch{d(()=>c(new D("generic")));return}let w=o(()=>{if(this.pollTimer&&clearInterval(this.pollTimer),this.pollTimer=null,this.hardStopTimer&&clearTimeout(this.hardStopTimer),this.hardStopTimer=null,this.settled||e?.(),h.state!=="inactive"){try{h.stop()}catch{u()}this.graceTimer=setTimeout(u,Pe)}else u()},"v"),m=this.now();if(a===void 0){this.hardStopTimer=setTimeout(w,s);return}let g=null,y=!1;this.hardStopTimer=setTimeout(w,s+Ue),this.pollTimer=setInterval(()=>{if(this.settled||y)return;let p=null;try{p=a.latest()}catch{p=null}let M=p?.presentationTimeMs;M!==void 0&&Number.isFinite(M)&&M>=v&&g===null&&(g=M);let T=g!==null&&M!==void 0&&M-g>=s,A=g===null&&this.now()-m>=s;if(!(!T&&!A)){if(y=!0,this.pollTimer&&clearInterval(this.pollTimer),this.pollTimer=null,A){w();return}this.hardStopTimer&&clearTimeout(this.hardStopTimer),this.hardStopTimer=setTimeout(w,Ge)}},Fe)}))}stop(t){this.clearTimers();let e=this.recorder;if(e&&e.state!=="inactive")try{e.stop()}catch{}this.recorder=null,(t??this.stream)?.getTracks().forEach(r=>r.stop()),this.stream=null}},o(L,"I"),L);async function ze(i,t){let e,r=new Promise(h=>{e=setTimeout(()=>h(null),Ne)}),s=await Promise.race([t,r]);if(clearTimeout(e),s===null)return i;let a;try{a=await s.blobBytes(i.blob)}catch{return{...i,stats:null}}let n=s.inspectClipBytes(a);if(n?.container!=="webm")return{...i,stats:n};let l=s.withWebmDuration(a,n.durationMs);if(l===null)return{...i,stats:n};let c=s.inspectClipBytes(l);return c===null||c.frames!==n.frames||c.durationMs!==n.durationMs?{...i,stats:n}:{...i,blob:new Blob([l],{type:i.blob.type}),stats:n}}o(ze,"He");var He=["magenta","yellow","green","blue"],Ke={magenta:"rgb(255, 72, 150)",yellow:"rgb(255, 190, 0)",green:"rgb(0, 238, 175)",blue:"rgb(25, 150, 255)",dark:"rgb(0, 0, 0)"};function zi(i){return Ke[i]}o(zi,"ft");var Xe=4,Ve=4,$=o(i=>typeof i=="number"&&Number.isFinite(i),"D");function oe(i){if(typeof i!="object"||i===null)return!1;let t=i;if(typeof t.nonce!="string"||t.nonce.length===0||!Array.isArray(t.colours)||t.colours.length<1||t.colours.length>8||!t.colours.every(r=>He.includes(r))||!Array.isArray(t.onsetsMs)||t.onsetsMs.length!==t.colours.length)return!1;let e=-1;for(let r of t.onsetsMs){if(!$(r)||r<0||r<=e)return!1;e=r}return!(!$(t.holdMs)||t.holdMs<=0||!$(t.endMs)||t.endMs<=e||!$(t.clipMs)||t.clipMs<t.endMs||t.clipMs>8e3)}o(oe,"be");function Ze(i,t){return oe(i)?Math.max(t,Math.ceil(i.clipMs)):t}o(Ze,"ye");function je(i,t){let e=t.now??(()=>performance.now()),r=oe(i)?i:void 0,s=[],a=null,n=null,l=null,c=!1,h=null,d=o(m=>{h=m;try{t.paint(m)}catch{}},"d"),u=o(m=>{let g=t.frames?.()??null;return g!==null&&l!==null?g.mediaTimeMs+(m-g.presentationTimeMs)-l:m-(n??m)},"u"),v=o((m,g,y=0)=>{if(c)return;let p=Math.max(0,m-u(e()));a=setTimeout(()=>{if(a=null,!c){if(y<Xe&&u(e())<m-Ve){v(m,g,y+1);return}g()}},p)},"f"),w=o(m=>{if(r===void 0)return;let g=r.endMs;if(m>=r.colours.length){v(g,()=>d(null));return}let y=r.onsetsMs[m],p=m+1<r.onsetsMs.length?r.onsetsMs[m+1]:g;v(y,()=>{let M=u(e());if(M>g){h!==null&&d(null);return}let T=r.colours[m];d(T);let A=s.length===0?0:s[s.length-1].tMs;s.push({tMs:Math.max(A,Math.round(M)),colour:T});let k=y+r.holdMs;if(k<p){v(k,()=>{if(u(e())>g){h!==null&&d(null);return}d("dark"),w(m+1)});return}w(m+1)})},"v");return{started(m){if(r===void 0||c||n!==null)return;n=m;let g=t.frames?.()??null;l=g===null?null:g.mediaTimeMs+(m-g.presentationTimeMs),w(0)},stop(){c||(c=!0,a!==null&&clearTimeout(a),a=null,h!==null&&d(null))},report(){return r===void 0?void 0:{nonce:r.nonce,rendered:[...s]}}}}o(je,"Me");function $e(i,t,e=.92){return new Promise((r,s)=>{let a=i.videoWidth,n=i.videoHeight;if(!a||!n){s(new Error("video-not-ready"));return}let l=t.getContext("2d");if(!l){s(new Error("no-2d-context"));return}t.width=a,t.height=n,l.scale(-1,1),l.drawImage(i,-a,0),t.toBlob(c=>c?r(c):s(new Error("empty-keyframe")),"image/jpeg",e)})}o($e,"Se");var B,Ye=(B=class{constructor(t){this.timer=null,this.frameCallbackId=null,this.running=!1,this.busy=!1,this.lastRunAt=Number.NEGATIVE_INFINITY,this.degradeCount=0,this.durations=[],this.options=t,this.periodMs=1e3/t.cadenceHz}start(){if(this.running)return;this.running=!0;let t=this.options.video;if(typeof t?.requestVideoFrameCallback=="function"){let e=o(()=>{this.running&&(this.frameCallbackId=t.requestVideoFrameCallback?.(()=>{this.frameCallbackId=null,this.now()-this.lastRunAt>=this.periodMs&&this.tick(),e()}))},"t");e();return}this.timer=setInterval(()=>this.tick(),this.periodMs)}stop(){this.running=!1,this.timer!==null&&(clearInterval(this.timer),this.timer=null),this.frameCallbackId!==null&&(this.options.video?.cancelVideoFrameCallback?.(this.frameCallbackId),this.frameCallbackId=null)}stats(){let t=this.durations.length===0?0:this.durations.reduce((e,r)=>e+r,0)/this.durations.length;return{degradeCount:this.degradeCount,meanDetectMs:t}}now(){return this.options.now?.()??performance.now()}tick(){if(!this.running)return;if(this.busy){this.degradeCount+=1;return}this.busy=!0,this.lastRunAt=this.now();let t=this.now();this.options.run().catch(()=>{}).finally(()=>{this.busy=!1,this.durations.push(this.now()-t),this.durations.length>20&&this.durations.shift()})}},o(B,"O"),B),Qe=Object.freeze({Q_GOOD:.6,RISE_PER_S:.9,FALL_PER_S:.25,CENTER_FALLOFF_IOD_MULTIPLE:1.35,BOX_EYE_OFFSET_FACTOR:.12,IOD_BOX_PROXY_FACTOR:.42,SIZE_IDEAL_MIN:.12,SIZE_IDEAL_MAX:.3,SIZE_HARD_MIN:.08,SIZE_HARD_MAX:.45,ROLL_MAX_DEG:25,MOTION_VELOCITY_IOD_PER_S:.5,MOTION_TAU_S:.4,MOTION_DEADBAND_IOD_PER_S:.1,READY_WINDOW_MS:500,GUIDE_SIZE:.6,GUIDE_CENTERING:.6,GUIDE_POSE:.6,GUIDE_EXPOSURE:.6,GUIDE_SHARPNESS:.35,GUIDE_MOTION:.5}),F=o(i=>Math.min(1,Math.max(0,i)),"_"),W,Jt=(W=class{constructor(t={}){this.p=0,this.lastTickAt=null,this.lastCenter=null,this.velocityEma=0,this.qWindow=[],this.lastSizeDirection="ideal",this.t={...Qe,...t}}reset(){this.p=0,this.lastTickAt=null,this.lastCenter=null,this.velocityEma=0,this.qWindow=[],this.lastSizeDirection="ideal"}tick(t){let{observation:e,quality:r,timestampMs:s}=t,a=this.lastTickAt===null?0:Math.max(0,(s-this.lastTickAt)/1e3);this.lastTickAt=s;let n={presence:0,single:1,centering:0,size:0,pose:0,sharpness:F(r.sharpness),exposure:F(r.exposure),motion:1};if(e!==null){n.presence=1,n.single=(e.extraFaces??0)>0?0:1;let d=this.geometryOf(e,t);n.centering=d.centering,n.size=d.size,n.pose=d.pose,n.motion=this.motionOf(d.center,d.iod,s)}else this.lastCenter=null,this.velocityEma=0;let l=Math.min(n.presence,n.single,n.centering,n.size,n.pose,n.sharpness,n.exposure,n.motion);this.p=F(this.p+(l>=this.t.Q_GOOD?this.t.RISE_PER_S*l:-this.t.FALL_PER_S*(1-l))*a),this.qWindow.push({at:s,q:l}),this.qWindow=this.qWindow.filter(d=>d.at>=s-this.t.READY_WINDOW_MS);let c=this.qWindow.map(d=>d.q);if(c.length>=3){let d=Math.min(...c),u=c.indexOf(d);c=c.filter((v,w)=>w!==u)}let h=this.p>=1&&c.every(d=>d>=this.t.Q_GOOD);return{at:s,q:l,p:this.p,factors:n,guidanceKey:this.guidanceOf(n,r,l),ready:h,accepted:l>=this.t.Q_GOOD}}geometryOf(t,e){let{box:r,eyes:s}=t,a={x:e.frameWidth/2,y:e.frameHeight/2},n=Math.min(e.frameWidth,e.frameHeight),l=s!==void 0?{x:(s.left.x+s.right.x)/2,y:(s.left.y+s.right.y)/2}:{x:r.x+r.width/2,y:r.y+r.height/2-this.t.BOX_EYE_OFFSET_FACTOR*r.height},c=s!==void 0?Math.hypot(s.right.x-s.left.x,s.right.y-s.left.y):this.t.IOD_BOX_PROXY_FACTOR*r.width,h=Math.hypot(l.x-a.x,l.y-a.y),d=c<=0?0:1-F(h/(this.t.CENTER_FALLOFF_IOD_MULTIPLE*c)),u=n>0?c/n:0;this.lastSizeDirection=u<this.t.SIZE_IDEAL_MIN?"far":u>this.t.SIZE_IDEAL_MAX?"close":"ideal";let v;u<this.t.SIZE_HARD_MIN||u>this.t.SIZE_HARD_MAX?v=0:u<this.t.SIZE_IDEAL_MIN?v=(u-this.t.SIZE_HARD_MIN)/(this.t.SIZE_IDEAL_MIN-this.t.SIZE_HARD_MIN):u>this.t.SIZE_IDEAL_MAX?v=(this.t.SIZE_HARD_MAX-u)/(this.t.SIZE_HARD_MAX-this.t.SIZE_IDEAL_MAX):v=1;let w=1;if(s!==void 0){let m=Math.abs(Math.atan2(s.right.y-s.left.y,s.right.x-s.left.x))*180/Math.PI;w=1-F(m/this.t.ROLL_MAX_DEG)}return{center:l,iod:c,centering:d,size:v,pose:w}}motionOf(t,e,r){let s=this.lastCenter;if(this.lastCenter={...t,at:r},s===null||e<=0)return 1;let a=(r-s.at)/1e3;if(a<=0)return 1;let n=Math.hypot(t.x-s.x,t.y-s.y)/e/a;n<=this.t.MOTION_DEADBAND_IOD_PER_S&&(n=0);let l=1-Math.exp(-a/this.t.MOTION_TAU_S);return this.velocityEma=l*n+(1-l)*this.velocityEma,1-F(this.velocityEma/this.t.MOTION_VELOCITY_IOD_PER_S)}guidanceOf(t,e,r){if(t.presence<=0)return"fcv3.no_face";if(t.single<=0)return"fcv3.one_face";if(t.size<this.t.GUIDE_SIZE)return this.sizeGuidance();if(t.centering<this.t.GUIDE_CENTERING)return"fcv3.center_face";if(t.pose<this.t.GUIDE_POSE)return"fcv3.straighten";if(t.exposure<this.t.GUIDE_EXPOSURE)return this.exposureGuidance(e);if(t.sharpness<this.t.GUIDE_SHARPNESS)return"fcv3.steady_camera";if(t.motion<this.t.GUIDE_MOTION)return"fcv3.hold_still";if(r<this.t.Q_GOOD){let s=[["size",this.sizeGuidance()],["centering","fcv3.center_face"],["pose","fcv3.straighten"],["exposure",this.exposureGuidance(e)],["sharpness","fcv3.steady_camera"],["motion","fcv3.hold_still"]],a=s[0];for(let n of s)t[n[0]]<t[a[0]]&&(a=n);return a[1]}return"fcv3.hold_still"}sizeGuidance(){return this.lastSizeDirection==="far"?"fcv3.come_closer":"fcv3.move_back"}exposureGuidance(t){let e=(it[0]+it[1])/2;return t.meanLuma<e?"fcv3.more_light":"fcv3.too_bright"}},o(W,"k"),W),Je=["single","size","centering","pose","exposure","sharpness","motion"];function ti(i){if(i.accepted)return null;if(i.factors.presence<=0)return"no_face";let t="single";for(let e of Je)i.factors[e]<i.factors[t]&&(t=e);return t}o(ti,"Ze");var q,te=(q=class{constructor(){this.blocked={},this.acceptedMs=0,this.ticks=0,this.lastAt=null}record(t){let e=this.lastAt===null?0:Math.max(0,t.at-this.lastAt);this.lastAt=t.at,this.ticks+=1;let r=ti(t);if(r===null){this.acceptedMs+=e;return}let s=this.blocked[r]??{count:0,ms:0};s.count+=1,s.ms+=e,this.blocked[r]=s}summary(){let t={};for(let[e,r]of Object.entries(this.blocked))t[e]={count:r.count,ms:Math.round(r.ms)};return{blocked:t,acceptedMs:Math.round(this.acceptedMs),ticks:this.ticks}}},o(q,"w"),q),ei=["obs","manycam","virtual","snap camera","xsplit","droidcam","iriun","camo"],ii=[/^(front|back|rear)( [a-z ]+)? camera$/i,/^caméra (avant|arrière)\b/i,/^cámara (frontal|trasera|delantera)\b/i,/^câmera (frontal|traseira)\b/i,/^(front|rück)kamera\b/i,/^الكاميرا (الأمامية|الخلفية)/,/^camera2? ?\d+, facing (front|back|external)/i,/facetime/i,/\b(integrated|built-in|builtin) (web)?cam(era)?\b/i,/\b(hd )?web ?cam\b/i,/\([0-9a-f]{4}:[0-9a-f]{4}\)\s*$/i];function ri(i){let t=(i??"").trim().toLowerCase();return t.length===0?"unknown":ei.some(e=>t.includes(e))?"known_virtual":ii.some(e=>e.test(t))?"platform":"unknown"}o(ri,"je");function ee(i){if(typeof i!="function")return!1;try{return/\{\s*\[native code\]\s*\}\s*$/.test(Function.prototype.toString.call(i))}catch{return!1}}o(ee,"Te");function si(i=globalThis){return ee(i.navigator?.mediaDevices?.getUserMedia)&&ee(i.MediaStreamTrack?.prototype?.getSettings)}o(si,"$e");async function ai(i,t=globalThis){let e=t.crypto?.subtle?.digest;if(typeof e=="function")try{let r=new Uint8Array(await e.call(t.crypto?.subtle,"SHA-256",new TextEncoder().encode(i)));return Array.from(r.subarray(0,8),s=>s.toString(16).padStart(2,"0")).join("")}catch{return}}o(ai,"Je");async function ni(i,t=globalThis){let e={};try{e=typeof i.getSettings=="function"?i.getSettings()??{}:{}}catch{e={}}let r={};if((e.facingMode==="user"||e.facingMode==="environment"||e.facingMode==="left"||e.facingMode==="right")&&(r.facingMode=e.facingMode),typeof e.frameRate=="number"&&Number.isFinite(e.frameRate)&&(r.frameRate=e.frameRate),typeof e.width=="number"&&Number.isFinite(e.width)&&(r.width=e.width),typeof e.height=="number"&&Number.isFinite(e.height)&&(r.height=e.height),typeof e.deviceId=="string"&&e.deviceId.length>0){let a=await ai(e.deviceId,t);a!==void 0&&(r.deviceIdHash=a)}let s;try{s=i.label}catch{s=void 0}return{trackSettings:r,capabilitiesPresent:typeof i.getCapabilities=="function",labelClass:ri(s),prototypesIntact:si(t)}}o(ni,"Ce");var ot=o(i=>Math.round(i*100)/100,"H");function oi(i){let t=i,e=typeof t?.requestVideoFrameCallback=="function",r=null,s=null,a=0,n=0,l=0,c=0,h=0,d=0,u=o(()=>{!e||t?.requestVideoFrameCallback===void 0||(r=t.requestVideoFrameCallback((v,w)=>{if(r=null,!e)return;let m=w.presentationTime;if(s!==null){let g=m-s.presentationTimeMs;n+=1;let y=g-l;l+=y/n,c+=y*(g-l)}typeof w.captureTime=="number"&&Number.isFinite(w.captureTime)&&(h+=m-w.captureTime,d+=1),a+=1,s={mediaTimeMs:w.mediaTime*1e3,presentationTimeMs:m},u()}))},"u");return u(),{latest:o(()=>s,"latest"),stats:o(()=>({n:a,meanGapMs:n===0?0:ot(l),stdGapMs:n<2?0:ot(Math.sqrt(c/(n-1))),captureLatencyMs:d===0?null:ot(h/d)}),"stats"),stop:o(()=>{e&&(e=!1,r!==null&&t?.cancelVideoFrameCallback?.(r),r=null)},"stop")}}o(oi,"Ee");function li(i,t,e){return{...i,rvfc:t,rampPainter:e}}o(li,"_e");var ci=1e3,lt="fcv3.hold_upright",hi=200,ct=4,ui=600,di=1e3,ie={sharpness:1,exposure:1,meanLuma:128};function fi(i,t){return t.width=i.videoWidth,t.height=i.videoHeight,t.getContext("2d").drawImage(i,0,0),new Promise((e,r)=>t.toBlob(s=>s?e(s):r(new Error("empty-keyframe")),"image/jpeg",.92))}o(fi,"it");function mi(){return V()==="phone"}o(mi,"at");var z,le=(z=class{constructor(t){this.handlers=new Map,this.stateValue="idle",this.attempt=0,this.stream=null,this.detector=null,this.scheduler=null,this.gate=null,this.profiler=null,this.lastGuidanceKey=null,this.positioningStartedAt=0,this.cameraRequestedAt=null,this.cameraReadyAt=null,this.faceAcquiredAt=null,this.captureCompleteAt=null,this.fired=!1,this.carriedDegrade=0,this.carriedMeans=[],this.blockStats=null,this.lastGateSnapshotAt=Number.NEGATIVE_INFINITY,this.uprightGuard=!1,this.trackProvenance=null,this.ramp=null,this.snapshotCanvas=null,this.options=t,this.facing=t.facingMode??"user"}get state(){return this.stateValue}on(t,e){let r=this.handlers.get(t);return r||(r=new Set,this.handlers.set(t,r)),r.add(e),()=>r?.delete(e)}emit(t,e){for(let r of[...this.handlers.get(t)??[]])r(e)}async start(t={}){t.facingMode!==void 0&&(this.facing=t.facingMode),this.attempt+=1,await this.run(this.attempt)}get facingMode(){return this.facing}retry(){this.teardownAttempt(),this.start()}switchCamera(){this.facing=this.facing==="user"?"environment":"user",this.teardownAttempt(),this.start()}restart(t){this.facing=t,this.teardownAttempt(),this.start()}destroy(){this.attempt+=1,this.teardownAttempt(),this.detector?.destroy(),this.detector=null,this.options.video.srcObject=null}async run(t){let{options:e}=this;this.fired=!1,this.lastGuidanceKey=null,this.carriedDegrade=0,this.carriedMeans=[],this.cameraRequestedAt=null,this.cameraReadyAt=null,this.faceAcquiredAt=null,this.captureCompleteAt=null,this.uprightGuard=(e.isPhone??mi)(),this.setState("preflight");let r=Ct();if(r!=="OK"){this.fail(r==="INSECURE_CONTEXT"?"insecure":"unsupported",{phase:"preflight"});return}this.setState("acquiring");let s=e.getUserMedia??(h=>navigator.mediaDevices.getUserMedia(h)),a;this.cameraRequestedAt=this.now();try{let{facingMode:h,...d}=kt(Tt(),this.facing).video;a=await Lt(this.facing,d,{getUserMedia:s,enumerateDevices:vi(e)})}catch(h){if(t!==this.attempt)return;if(h instanceof Nt){this.fail("backcamera",{phase:"acquiring",name:K(h)});return}this.fail(Ut(h),{phase:"acquiring",name:K(h)});return}if(Et(a),Ft(a),t!==this.attempt){for(let h of a.getTracks())h.stop();return}this.stream=a;let n=a.getVideoTracks?.()[0];if(this.trackProvenance=n===void 0?null:ni(n).catch(()=>null),this.facing=_t(a)??this.facing,e.video.srcObject=a,await e.video.play().catch(()=>{}),t!==this.attempt)return;if(this.cameraReadyAt=this.now(),this.detector===null){let h={v3AssetBaseUrl:e.v3AssetBaseUrl},d=e.createDetector??(e.createWorker!==void 0&&Zt()?async()=>{try{return await jt.create(e.createWorker(),h)}catch{return x(h)}}:()=>x(h)),u;try{u=await d()}catch(v){t===this.attempt&&this.fail("models",{phase:"models",name:K(v)},v instanceof nt?v.fallbackReason:gi(v));return}if(t!==this.attempt){u.destroy();return}this.detector=u,this.options.telemetry?.({type:"detector",tier:u.tier,fallbackReason:u.fallbackReason})}let l=Bt(),c=e.deviceClass??Wt(l);this.profiler=new qt(c),this.options.telemetry?.({type:"profile",staticClass:c,activeClass:this.profiler.deviceClass,simd:l.simd}),this.gate=new Jt(e.thresholds??{}),this.blockStats=new te,this.lastGateSnapshotAt=this.now(),e.rankKeyframes?.()&&import("./keyframe-rank-YAJLYJYF-WCA6RPMD.js").then(h=>ht=h,()=>{}),this.setState("positioning"),this.positioningStartedAt=this.now(),this.startScheduler(t)}get animations(){return this.profiler?.profile.animations??"full"}startScheduler(t){let e=this.profiler;if(e===null)return;if(this.scheduler!==null){let s=this.scheduler.stats();this.carriedDegrade+=s.degradeCount,s.meanDetectMs>0&&this.carriedMeans.push(s.meanDetectMs),this.scheduler.stop()}let r=new Ye({cadenceHz:e.profile.cadenceHz,video:this.options.video,now:this.options.now,run:o(()=>this.detectTick(t),"run")});this.scheduler=r,r.start()}async detectTick(t){let{detector:e,gate:r,profiler:s}=this,a=this.options.video;if(t!==this.attempt||e===null||r===null||s===null||this.fired||a.videoWidth===0)return;if(this.isLandscape()){this.holdUpright(t);return}let n=s.deviceClass,l=this.now(),c=this.options.makeSnapshot?.(a,s.profile.inputWidth)??this.defaultSnapshot(a,s.profile.inputWidth),h=null;try{h=await e.detect(c,a.videoWidth,a.videoHeight)}catch{h=null}if(t!==this.attempt||this.fired)return;s.record(this.now()-l),s.deviceClass!==n&&this.startScheduler(t);let d=h===null?ie:this.options.measureQuality?.(a,h.box)??this.defaultQuality(a,h.box),u=r.tick({timestampMs:this.now(),observation:h,quality:d,frameWidth:a.videoWidth,frameHeight:a.videoHeight});u.accepted&&this.faceAcquiredAt===null&&(this.faceAcquiredAt=u.at),this.blockStats?.record(u),!u.ready&&u.at-this.lastGateSnapshotAt>=ci&&(this.lastGateSnapshotAt=u.at,this.reportGate(!1)),this.emit("checks",{engine:"v3",progress:u.p,q:u.q,factors:u.factors,attempt:t}),u.guidanceKey!==this.lastGuidanceKey&&(this.lastGuidanceKey=u.guidanceKey,this.emit("guidance",{key:u.guidanceKey})),u.ready&&this.stateValue==="positioning"&&(this.fired=!0,this.captureCompleteAt=u.at,this.fire(t))}async fire(t){let{options:e}=this,r=this.scheduler;r?.stop(),this.reportGate(!0);let s=r?.stats()??{degradeCount:0,meanDetectMs:0},a=[...this.carriedMeans,...s.meanDetectMs>0?[s.meanDetectMs]:[]];e.telemetry?.({type:"fired",timeToGateMs:this.now()-this.positioningStartedAt,degradeCount:this.carriedDegrade+s.degradeCount,meanDetectMs:a.length===0?0:a.reduce((k,b)=>k+b,0)/a.length});let n=e.mode??"clip",l=e.rankKeyframes?.()&&ht?ht.default(this,t).catch(()=>this.collectKeyframes(t)):this.collectKeyframes(t);if(n==="photo"){let k=this.watchRotation(t,null),b=await l;if(k(),t!==this.attempt)return;if(b===null){this.fail("generic",{phase:"keyframes"});return}let I=await this.provenance({n:0,meanGapMs:0,stdGapMs:0,captureLatencyMs:null},!1);if(t!==this.attempt)return;this.finishCapture({keyframe:b.blob,previewDataUrl:b.previewDataUrl,...I});return}this.setState("recording");let c=this.stream;if(c===null){this.fail("generic",{phase:"recording"});return}let h=e.screenRamp?.(),d=h!==void 0,u=null;l.then(k=>{u=k},()=>{});let v=o(()=>{t===this.attempt&&u!==null&&this.emit("frozen",{previewDataUrl:u.previewDataUrl})},"f"),w=Ze(h,ne),m=null,g,y=0;try{let k=this.recordTake(t,c,h,w,void 0).then(_=>_,_=>({failed:_})),[b,I]=await Promise.all([k,l]);if(g=I,t!==this.attempt)return;if("failed"in b){if(b.failed.kind==="cliptoolarge")throw b.failed;$t(b.failed.requestedMimeType??"")}else m=b,Qt(b.clip,w)?b.clip.stats===null&&$t(b.clip.requestedMimeType??""):v();if(m===null||Qt(m.clip,w)){y=1,e.telemetry?.({type:"clip_retake",reason:m===null?"error":m.clip.stats===null?"unreadable":"short"});let _=null;try{_=await this.recordTake(t,c,h,w,v)}catch(H){if(m===null)throw H}if(t!==this.attempt)return;_!==null&&(m===null||We(_.clip,m.clip))&&(m=_),_===null&&v()}}catch(k){if(t!==this.attempt)return;let b=k.kind;this.fail(b==="cliptoolarge"?"cliptoolarge":"recorder",{phase:"recording",name:K(k)});return}if(m===null){this.fail("recorder",{phase:"recording"});return}let{clip:p,rvfc:M,report:T}=m;if(et(p.blob)){this.fail("cliptoolarge",{phase:"recording"});return}if(g===null){this.fail("generic",{phase:"keyframes"});return}let A=await this.provenance(M,d);t===this.attempt&&this.finishCapture({clip:p.blob,clipMimeType:p.mimeType,...p.stats?{clipStats:p.stats}:{},clipRetakes:y,keyframe:g.blob,previewDataUrl:g.previewDataUrl,...T!==void 0&&T.rendered.length>0?{screenRamp:T}:{},...A})}async recordTake(t,e,r,s,a){let n=this.options.createRecorder?.()??new qe({now:o(()=>this.now(),"now")}),l=oi(this.options.video),c=je(r,{paint:o(u=>{(u===null||t===this.attempt)&&this.emit("ramp",{colour:u})},"paint"),now:o(()=>this.now(),"now"),frames:l.latest});this.ramp=c;let h=o(()=>{l.stop(),c.stop(),this.ramp===c&&(this.ramp=null)},"l"),d=this.watchRotation(t,n);try{return{clip:await n.record(e,a,()=>c.started(this.now()),s,l),rvfc:l.stats(),report:c.report()}}finally{d(),h()}}async provenance(t,e){let r=this.trackProvenance;if(r===null)return{};let s,a=new Promise(l=>{s=setTimeout(()=>l(null),di)}),n=await Promise.race([r,a]);return clearTimeout(s),n===null?{}:{provenance:li(n,t,e)}}isLandscape(){let t=this.options.video;return this.uprightGuard&&t.videoWidth>t.videoHeight}holdUpright(t){this.gate?.reset(),this.emit("checks",{engine:"v3",progress:0,q:0,factors:{presence:0,single:1,centering:0,size:0,pose:0,sharpness:0,exposure:0,motion:0},attempt:t}),this.lastGuidanceKey!==lt&&(this.lastGuidanceKey=lt,this.emit("guidance",{key:lt}))}watchRotation(t,e){if(!this.uprightGuard)return()=>{};let r=this.options.video,s=o(()=>{if(t!==this.attempt||e!==null&&this.stateValue!=="recording"){l();return}r.videoWidth>0&&this.isLandscape()&&(l(),this.abortRecording(t,e))},"n"),a=setInterval(s,hi);r.addEventListener?.("resize",s);let n=!1;function l(){n||(n=!0,clearInterval(a),r.removeEventListener?.("resize",s))}return o(l,"o"),l}abortRecording(t,e){if(t!==this.attempt)return;this.attempt+=1;let r=this.attempt;try{e?.stop()}catch{}this.ramp?.stop(),this.ramp=null,this.fired=!1,this.captureCompleteAt=null,this.gate=new Jt(this.options.thresholds??{}),this.blockStats=new te,this.lastGateSnapshotAt=this.now(),this.lastGuidanceKey=null,this.setState("positioning"),this.positioningStartedAt=this.now(),this.holdUpright(r),this.startScheduler(r)}async collectKeyframes(t){let e=this.options.captureKeyframe??(a=>this.defaultKeyframe(a)),r=ui/(ct-1),s=null;for(let a=0;a<ct;a+=1){if(t!==this.attempt)return s;try{let n=await e(this.options.video);(s===null||n.sharpness>s.sharpness)&&(s=n)}catch{}a<ct-1&&await pi(r)}return s}finishCapture(t){this.stopTracks(),this.setState("captured");let e=this.captureTiming();this.emit("artifacts",e===void 0?t:{...t,timing:e})}captureTiming(){let t={},e=o((r,s,a)=>{s!==null&&a!==null&&(t[r]=Math.max(0,Math.round(a-s)))},"t");return e("cameraReadyMs",this.cameraRequestedAt,this.cameraReadyAt),e("faceAcquireMs",this.cameraReadyAt,this.faceAcquiredAt),e("captureMs",this.faceAcquiredAt,this.captureCompleteAt),Object.keys(t).length>0?t:void 0}async defaultKeyframe(t){let e=document.createElement("canvas"),r=await(this.facing==="user"?$e:fi)(t,e),s=e.toDataURL("image/jpeg",.92);return{blob:r,previewDataUrl:s,sharpness:this.centerSharpness(t)}}defaultSnapshot(t,e){try{let r=this.snapshotCanvas??document.createElement("canvas"),s=e/Math.max(1,t.videoWidth),a=Math.max(1,Math.round(t.videoWidth*s)),n=Math.max(1,Math.round(t.videoHeight*s)),l=r.getContext("2d");return l===null?t:(r.width!==a&&(r.width=a),r.height!==n&&(r.height=n),l.drawImage(t,0,0,a,n),this.snapshotCanvas=r,r)}catch{return t}}defaultQuality(t,e){let r=re(t,e,96);return r===null?ie:{sharpness:rt(r),exposure:Ht(r),meanLuma:zt(r)}}centerSharpness(t){let e=Z(t),r=re(t,{x:e.width*.25,y:e.height*.25,width:e.width*.5,height:e.height*.5},96);return r===null?0:rt(r)}teardownAttempt(){this.scheduler?.stop(),this.scheduler=null,this.reportGate(!0),this.gate=null,this.ramp?.stop(),this.ramp=null,this.stopTracks()}reportGate(t){let e=this.blockStats,r=this.profiler;if(e===null||r===null)return;let s=e.summary();t&&(this.blockStats=null),s.ticks!==0&&this.options.telemetry?.({type:"gate",final:t,activeClass:r.deviceClass,cadenceHz:r.profile.cadenceHz,...s})}stopTracks(){if(this.stream!==null){for(let t of this.stream.getTracks())t.stop();this.stream=null}}fail(t,e,r){this.scheduler?.stop(),this.reportGate(!0),this.stopTracks(),this.setState("error"),this.options.telemetry?.({type:"error",kind:t,fallbackReason:r});let{phase:s,name:a}=e;this.emit("error",{kind:t,retryable:t!=="insecure"&&t!=="unsupported",detail:a===void 0?{phase:s}:{phase:s,name:a}})}setState(t){this.stateValue=t,this.emit("statechange",{state:t})}now(){return this.options.now?.()??performance.now()}},o(z,"ke"),z),ht;function pi(i){return new Promise(t=>setTimeout(t,i))}o(pi,"st");function gi(i){return i instanceof Error?i.message:String(i)}o(gi,"ot");function re(i,t,e){try{let r=document.createElement("canvas"),s=e/Math.max(1,t.width);r.width=Math.max(1,Math.round(t.width*s)),r.height=Math.max(1,Math.round(t.height*s));let a=r.getContext("2d");return a===null?null:(a.drawImage(i,t.x,t.y,t.width,t.height,0,0,r.width,r.height),a.getImageData(0,0,r.width,r.height))}catch{return null}}o(re,"we");function vi(i){if(i.enumerateDevices!==void 0)return i.enumerateDevices;if(i.getUserMedia===void 0&&!(typeof navigator>"u"||typeof navigator.mediaDevices?.enumerateDevices!="function"))return()=>navigator.mediaDevices.enumerateDevices()}o(vi,"lt");var yi=12e4,ce=13e4,wi=3e3,bi=1200,ut=Symbol.for("@sekyro/web.preload.v1");function ft(){let i=globalThis;return i[ut]??(i[ut]=new Map),i[ut]}o(ft,"g");function Y(i){let t=(i??at).replace(/\/+$/,"");return t===""?"/":t}o(Y,"S");function ue(i){let t=ft(),e=t.get(i);return e===void 0&&(e={status:"idle",promise:null,scheduled:null,detectorPromise:null,detector:null,listeners:new Set},t.set(i,e)),e}o(ue,"se");function dt(i,t){if(i.status!==t){i.status=t;for(let e of[...i.listeners])e(t)}}o(dt,"A");var Mi=o(i=>x({preferred:["blaze"],v3AssetBaseUrl:i,blazeInitTimeoutMs:yi}),"x"),ki=Mi;function Ti(){return typeof window<"u"&&typeof navigator<"u"&&typeof navigator.mediaDevices?.getUserMedia=="function"}o(Ti,"pe");function _i(){return navigator.connection?.saveData===!0}o(_i,"me");function Ei(i){let t=window;if(typeof t.requestIdleCallback=="function"){let r=t.requestIdleCallback(i,{timeout:wi});return()=>t.cancelIdleCallback?.(r)}let e=setTimeout(i,bi);return()=>clearTimeout(e)}o(Ei,"ve");function Si(i,t){let e,r=new Promise(l=>{e=l}),s=!1,a=o(()=>{},"d"),n={promise:r,settle:o(l=>{s||(s=!0,a(),i.scheduled===n&&(i.scheduled=null),e(l))},"settle")};return i.scheduled=n,a=Ei(()=>{s||n.settle(mt(i,t))}),r}o(Si,"ge");function mt(i,t){if((i.status==="loading"||i.status==="ready")&&i.promise!==null)return i.promise;dt(i,"loading");let e=new Promise(n=>n(ki(t)));i.detectorPromise=e;let r,s=new Promise((n,l)=>{r=setTimeout(()=>{e.then(c=>c.destroy(),()=>{}),l(new Error(`detector preload exceeded ${ce} ms`))},ce)}),a=Promise.race([e,s]).then(n=>i.detectorPromise!==e?(n.destroy(),i.status):(i.detector=n,dt(i,"ready"),"ready"),n=>(i.detectorPromise===e&&(i.detectorPromise=null,i.detector=null,dt(i,"failed"),console.warn("[@sekyro/web] face-detector preload failed:",n)),i.status)).finally(()=>clearTimeout(r));return i.promise=a,i.scheduled?.settle(a),a}o(mt,"I");function Yi(i={}){if(!Ti())return Promise.resolve("idle");let t=Y(i.assetBaseUrl),e=ue(t);return i.respectSaveData===!0&&_i()?Promise.resolve(e.status):(e.status==="loading"||e.status==="ready")&&e.promise!==null?e.promise:i.idle===!0?e.scheduled?.promise??Si(e,t):mt(e,t)}o(Yi,"we");function Qi(i){return ft().get(Y(i))?.status??"idle"}o(Qi,"ke");function Ji(i,t){let e=ue(Y(t));return e.listeners.add(i),()=>{e.listeners.delete(i)}}o(Ji,"De");function Ai(i){return{get tier(){return i.tier},get fallbackReason(){return i.fallbackReason},detect:o((...t)=>i.detect(...t),"detect"),destroy:o(()=>{},"destroy")}}o(Ai,"he");function Ii(i){let t=Y(i),e=ft().get(t);if(!(e===void 0||e.detector===null&&e.detectorPromise===null&&e.scheduled===null))return async()=>{e.scheduled!==null&&mt(e,t);let r=e.promise;for(;e.detector===null&&r!==null&&(await r,e.promise!==r);)r=e.promise;return e.detector!==null?Ai(e.detector):x({v3AssetBaseUrl:t})}}o(Ii,"oe");function xi(i){switch(i){case"fcv3.no_face":case"fcv3.center_face":case"fcv3.straighten":return"center";case"fcv3.come_closer":return"closer";case"fcv3.move_back":return"farther";case"fcv3.more_light":case"fcv3.too_bright":return"light";case"fcv3.hold_still":case"fcv3.steady_camera":return"still";case"fcv3.hold_upright":return"upright";case"fcv3.one_face":return"one_face";default:return null}}o(xi,"Ce");function Di(i){switch(i){case"preflight":case"acquiring":return"starting";case"positioning":return"gating";default:return i}}o(Di,"Se");function he(i){switch(i){case"permission":case"notfound":case"inuse":case"insecure":case"unsupported":return i;case"backcamera":return"notfound";default:{let t=i;return"generic"}}}o(he,"ie");function Ri(i,t,e){if(e===void 0)return{kind:he(i),retryable:t};let r=Gt(e.name);return{kind:he(i),retryable:t,detail:{...r!==void 0?{name:r}:{},phase:e.phase,engineKind:i}}}o(Ri,"Le");var Ci=new Set(["captured","uploading","checking"]);function Oi(i,t={},e,r=()=>"self",s=()=>{},a){let n=t.now??(()=>performance.now()),l=t.canChooseFacing??At,c="user",h=It(),d=r(),u=St(),v=!Ot(),w=t.engineOptions,m=w?.createDetector===void 0&&w?.createWorker===void 0?{createDetector:o(()=>{let f=Ii(i.assetBaseUrl);return f!==void 0?f():x({v3AssetBaseUrl:i.assetBaseUrl})},"createDetector")}:{},g={video:i.video,mode:v?"photo":"clip",rankKeyframes:e,facingMode:void 0,v3AssetBaseUrl:i.assetBaseUrl,screenRamp:o(()=>d==="self"&&u.count("ramp")>0?s():void 0,"screenRamp"),...t.engineOptions??{},...m},y=t.createEngine?.(g)??new le(g),p="idle",M=null,T=0,A=!1,k="full",b=null,I=null,_=0,H=0,pt=o(()=>{i.video.videoWidth>0&&i.video.videoHeight>0&&(_=i.video.videoWidth,H=i.video.videoHeight)},"K"),gt=xt({enabled:i.keepScreenAwake!==!1}),X=o(f=>{p=f,gt.setActive(f==="starting"||f==="gating"||f==="recording"),u.emit("state",f)},"M"),Q=o(()=>u.emit("gate",{progress:T,hint:M,faceDetected:A}),"R"),vt=o(()=>{let f=y.animations??"full";f!==k&&(k=f,u.emit("profile",{animations:k}))},"G"),de=[y.on("statechange",({state:f})=>{let E=Di(f);E==="starting"&&p!=="starting"&&(M=null,T=0,A=!1,b=null,I=null,_=0,H=0),X(E),vt(),E==="recording"&&(pt(),b=n(),M="hold",T=1,Q())}),y.on("checks",f=>{pt(),T=f.progress,A=f.factors.presence>0,Q(),vt()}),y.on("guidance",({key:f})=>{M=xi(f),Q()}),y.on("frozen",({previewDataUrl:f})=>{I=n(),u.emit("frozen",{previewDataUrl:f})}),y.on("ramp",f=>u.emit("ramp",f)),y.on("artifacts",f=>{if(p!=="captured")return;let E=V(),S=f.clipStats,bt=S!==void 0?Math.round(S.durationMs):b!==null&&I!==null?Math.max(0,Math.round(I-b)):void 0,Mt=S!==void 0&&S.frames>1&&S.durationMs>0?Math.round(S.frames*1e4/S.durationMs)/10:void 0;u.emit("captured",{keyframe:f.keyframe,...f.clip!==void 0?{clip:f.clip}:{},...f.clipMimeType!==void 0?{clipMime:f.clipMimeType}:{},width:i.video.videoWidth||_,height:i.video.videoHeight||H,...bt!==void 0?{clipMs:bt}:{},...S!==void 0?{clipFrames:S.frames}:{},...Mt!==void 0?{fps:Mt}:{},...f.clipRetakes!==void 0?{clipRetakes:f.clipRetakes}:{},...f.clipMimeType!==void 0?{codec:ae(f.clipMimeType)}:{},captureChannel:E==="desktop"?"desktop":"mobile",formFactor:E,...v?{degraded:"NO_RECORDER"}:{},engine:"v3",facingMode:y.facingMode,mode:d,...f.timing,...f.screenRamp!==void 0?{screenRamp:f.screenRamp}:{},...f.provenance!==void 0?{provenance:f.provenance}:{}})}),y.on("error",({kind:f,retryable:E,detail:S})=>{f==="backcamera"&&fe()||u.emit("error",Ri(f,E,S))})],yt=!1;function fe(){return J||yt||d!=="assisted"||a===void 0||a.session()!=="choice"?!1:(yt=!0,a.onModeChange("self"),d="self",c=tt("self"),X("mode_switch"),y.restart(c),!0)}o(fe,"ce");let wt=o(async()=>a!==void 0&&a.session()==="choice"&&await l().catch(()=>!1),"W"),J=!1;return{handle:{get state(){return p},get captureMode(){return r()},get facingMode(){return y.facingMode??c},on:o((f,E)=>u.on(f,E),"on"),start:o(f=>(d=r(),h.facing(d,i.facing),c=h.facing(d,f?.facing),y.start({facingMode:c})),"start"),retry:o(()=>y.retry(),"retry"),switchCamera:o(()=>h.refuseSwitch(r()),"switchCamera"),canSwitchCaptureMode:wt,setCaptureMode:o(async f=>{if(f===r()||!await wt()||J||Ci.has(p)||a===void 0)return!1;a.onModeChange(f),d=f;let E=tt(f);return c=E,p==="idle"||(X("mode_switch"),y.restart(E)),!0},"setCaptureMode"),destroy:o(()=>{J=!0;for(let f of de)f();gt.setActive(!1),y.destroy(),u.clear()},"destroy")},setFlowState:o(f=>{p!==f&&X(f)},"setFlowState")}}o(Oi,"Ee");function tr(i){return Oi(i).handle}o(tr,"ze");export{zi as a,Yi as b,Qi as c,Ji as d,Ri as e,Oi as f,tr as g};
@@ -1,3 +1,3 @@
1
- import{B as ee,C as j,D as De,E as Ge,a as V,b as we,c as Ce,f as Me,g as Ae,h as Se,i as Ie,j as Te,k as Ee,m as E,o as A,p as R,q as N,r as F,s as S,t as X,u as Re,v as Pe,w as Oe,x as xe,y as Ne}from"./chunk-ZYZPLDA2.js";import{f as Le}from"./chunk-7MV4CI4L.js";import{b as ke,c as Q,e as Ue}from"./chunk-CW56KMMH.js";import{a as t}from"./chunk-4FHWXBOB.js";function dt(n){return n.idNumberBound??n.nniBound}t(dt,"te");function Ke(n){return n===void 0?void 0:n.idNumberFromDocument??n.nniFromDocument}t(Ke,"j");var Ve="https://api.sekyro.ai",pt=5e3,ft=24e4,mt=3e4,ht=1500,vt=10;function Be(n){return n instanceof Error&&n.name==="ChallengeError"&&n.code||"challenge_failed"}t(Be,"tt");function yt(n){return new Promise(a=>setTimeout(a,n))}t(yt,"vt");function _t(){let n=globalThis.crypto;if(n!==void 0&&typeof n.randomUUID=="function")return n.randomUUID();let a=new Uint8Array(16);if(n!==void 0&&typeof n.getRandomValues=="function")n.getRandomValues(a);else for(let p=0;p<16;p+=1)a[p]=Math.floor(Math.random()*256);a[6]=(a[6]??0)&15|64,a[8]=(a[8]??0)&63|128;let d=[...a].map(p=>p.toString(16).padStart(2,"0")).join("");return`${d.slice(0,8)}-${d.slice(8,12)}-${d.slice(12,16)}-${d.slice(16,20)}-${d.slice(20)}`}t(_t,"Et");function gt(n){return bt(n,{})}t(gt,"wn");function bt(n,a){let d=n.apiOrigin??Ve,p=n.autoRetry??!0,Ze=n.rearm??"auto",f=a.client??new Ce({apiOrigin:d,sessionToken:n.clientToken,fetch:n.fetch}),D=a.sleep??yt,Ye=a.uuid??_t,We=a.getChallengeToken??((e,r)=>import("./challenge-frame-NUGPTWFP-V3GGQN65.js").then(i=>i.executeChallenge({frameUrl:e.url,siteKey:e.siteKey,action:"liveness",subject:r.subject,signal:r.signal}))),M=Ue(),I=null,ne=null,u=!1,re=new AbortController,l=null,G=null,U=null,L=t(()=>U??De(l),"Z"),ie=t(()=>Ge(j(l),L()),"ge"),g=t(e=>{l=e,M.emit("view",e),I?.onView(e)},"O"),m=t(()=>l!==null?Promise.resolve(l):(G??(G=f.getSession().then(e=>(g(e),e)).finally(()=>{G=null})),G),"_"),b=t(async()=>{let e=await f.getSession();return g(e),e},"w"),H=t(async(e,r)=>{e.plan!==void 0?g(e):await b()},"ne"),K=null,ae=t(async e=>{let r=await m();if(e||!r.consentRecorded){let i=await f.recordConsent(n.locale);i.plan!==void 0?g(i):l!==null&&g({...l,consentRecorded:!0})}ve(r)},"Ce"),k=t(e=>e?.force===!0?ae(!0):(K??(K=ae(!1).finally(()=>{K=null})),K),"v"),q={client:f,ensureConsent:t(e=>k(e),"ensureConsent"),sleep:D,uuid:Ye,...a.random!==void 0?{random:a.random}:{},onBusy:t(e=>{u||M.emit("busy",e)},"onBusy")},oe=!1,se=null,$=t(e=>{if(e.status==="verified"||e.status==="not_verified"||e.status==="review"){if(oe)return;oe=!0}se=JSON.stringify(e),M.emit("result",e)},"re"),Je=t(e=>{se!==JSON.stringify(e)&&$(e)},"pt"),le=t(async e=>{let r=l;e&&(r=await b().catch(()=>l));let i=r===null?null:E(r);return i!==null&&!u&&M.emit("method",i),i!==null},"Pe"),z=null,ue=!1,ce=!1,de=t(()=>Oe(q,(e,r)=>e.submitCheck("population_registry",{},{idempotencyKey:r})),"Ae"),pe=t(e=>dt(e)===!0||Ke(N(e,"population_registry"))===!0,"Oe"),Qe=t(async()=>{try{let e=await m();if(A(e)||E(e)!==null||R(e)?.checkType!=="population_registry")return;if(!pe(e)&&Ke(N(e,"population_registry"))===void 0&&(e=await b()),!pe(e)){ce=!0;return}await k(),await H(await de(),"population_registry");let r=l===null?void 0:N(l,"population_registry");if(r?.state==="input_required"&&r.reason==="registry_unavailable"&&Ee(r)>0){if(await D(pt),u)return;await H(await de(),"population_registry")}}catch(e){if(e instanceof V&&(e.code==="check_not_active"||e.code==="step_not_on_path")){await b().catch(()=>{});return}ue=!0;return}l!==null&&A(l)&&$(X(l,{autoRetry:p}))},"ft"),fe=t(()=>(z??(z=Qe()),z),"we"),Z=a.now??Date.now,T=null,P,Y,me=t((e,r)=>`${e.url}
1
+ import{B as ee,C as j,D as De,E as Ge,a as V,b as we,c as Ce,f as Me,g as Ae,h as Se,i as Ie,j as Te,k as Ee,m as E,o as A,p as R,q as N,r as F,s as S,t as X,u as Re,v as Pe,w as Oe,x as xe,y as Ne}from"./chunk-KLODCY6G.js";import{f as Le}from"./chunk-H5GXVL63.js";import{b as ke,c as Q,e as Ue}from"./chunk-CW56KMMH.js";import{a as t}from"./chunk-4FHWXBOB.js";function dt(n){return n.idNumberBound??n.nniBound}t(dt,"te");function Ke(n){return n===void 0?void 0:n.idNumberFromDocument??n.nniFromDocument}t(Ke,"j");var Ve="https://api.sekyro.ai",pt=5e3,ft=24e4,mt=3e4,ht=1500,vt=10;function Be(n){return n instanceof Error&&n.name==="ChallengeError"&&n.code||"challenge_failed"}t(Be,"tt");function yt(n){return new Promise(a=>setTimeout(a,n))}t(yt,"vt");function _t(){let n=globalThis.crypto;if(n!==void 0&&typeof n.randomUUID=="function")return n.randomUUID();let a=new Uint8Array(16);if(n!==void 0&&typeof n.getRandomValues=="function")n.getRandomValues(a);else for(let p=0;p<16;p+=1)a[p]=Math.floor(Math.random()*256);a[6]=(a[6]??0)&15|64,a[8]=(a[8]??0)&63|128;let d=[...a].map(p=>p.toString(16).padStart(2,"0")).join("");return`${d.slice(0,8)}-${d.slice(8,12)}-${d.slice(12,16)}-${d.slice(16,20)}-${d.slice(20)}`}t(_t,"Et");function gt(n){return bt(n,{})}t(gt,"wn");function bt(n,a){let d=n.apiOrigin??Ve,p=n.autoRetry??!0,Ze=n.rearm??"auto",f=a.client??new Ce({apiOrigin:d,sessionToken:n.clientToken,fetch:n.fetch}),D=a.sleep??yt,Ye=a.uuid??_t,We=a.getChallengeToken??((e,r)=>import("./challenge-frame-NUGPTWFP-V3GGQN65.js").then(i=>i.executeChallenge({frameUrl:e.url,siteKey:e.siteKey,action:"liveness",subject:r.subject,signal:r.signal}))),M=Ue(),I=null,ne=null,u=!1,re=new AbortController,l=null,G=null,U=null,L=t(()=>U??De(l),"Z"),ie=t(()=>Ge(j(l),L()),"ge"),g=t(e=>{l=e,M.emit("view",e),I?.onView(e)},"O"),m=t(()=>l!==null?Promise.resolve(l):(G??(G=f.getSession().then(e=>(g(e),e)).finally(()=>{G=null})),G),"_"),b=t(async()=>{let e=await f.getSession();return g(e),e},"w"),H=t(async(e,r)=>{e.plan!==void 0?g(e):await b()},"ne"),K=null,ae=t(async e=>{let r=await m();if(e||!r.consentRecorded){let i=await f.recordConsent(n.locale);i.plan!==void 0?g(i):l!==null&&g({...l,consentRecorded:!0})}ve(r)},"Ce"),k=t(e=>e?.force===!0?ae(!0):(K??(K=ae(!1).finally(()=>{K=null})),K),"v"),q={client:f,ensureConsent:t(e=>k(e),"ensureConsent"),sleep:D,uuid:Ye,...a.random!==void 0?{random:a.random}:{},onBusy:t(e=>{u||M.emit("busy",e)},"onBusy")},oe=!1,se=null,$=t(e=>{if(e.status==="verified"||e.status==="not_verified"||e.status==="review"){if(oe)return;oe=!0}se=JSON.stringify(e),M.emit("result",e)},"re"),Je=t(e=>{se!==JSON.stringify(e)&&$(e)},"pt"),le=t(async e=>{let r=l;e&&(r=await b().catch(()=>l));let i=r===null?null:E(r);return i!==null&&!u&&M.emit("method",i),i!==null},"Pe"),z=null,ue=!1,ce=!1,de=t(()=>Oe(q,(e,r)=>e.submitCheck("population_registry",{},{idempotencyKey:r})),"Ae"),pe=t(e=>dt(e)===!0||Ke(N(e,"population_registry"))===!0,"Oe"),Qe=t(async()=>{try{let e=await m();if(A(e)||E(e)!==null||R(e)?.checkType!=="population_registry")return;if(!pe(e)&&Ke(N(e,"population_registry"))===void 0&&(e=await b()),!pe(e)){ce=!0;return}await k(),await H(await de(),"population_registry");let r=l===null?void 0:N(l,"population_registry");if(r?.state==="input_required"&&r.reason==="registry_unavailable"&&Ee(r)>0){if(await D(pt),u)return;await H(await de(),"population_registry")}}catch(e){if(e instanceof V&&(e.code==="check_not_active"||e.code==="step_not_on_path")){await b().catch(()=>{});return}ue=!0;return}l!==null&&A(l)&&$(X(l,{autoRetry:p}))},"ft"),fe=t(()=>(z??(z=Qe()),z),"we"),Z=a.now??Date.now,T=null,P,Y,me=t((e,r)=>`${e.url}
2
2
  ${e.siteKey}
3
- ${r}`,"Ie"),W=t((e,r)=>{let i=We(e,{signal:re.signal,subject:r});return i.then(()=>{Y=void 0},o=>{let s=Be(o);u||s==="aborted"||(Y=s,O({check:"attestation",kind:"unavailable",engineKind:s}))}),i},"ce"),he=t((e,r)=>e!==null&&e.key===r&&Z()-e.at<ft,"Me"),ve=t(e=>{let r=e?.challenge??null;if(e===null||r===null||u)return;let i=me(r,F(e.sessionId));if(he(T,i))return;let o=W(r,F(e.sessionId));o.catch(()=>{}),T={key:i,at:Z(),token:o}},"ve"),Xe=t(async(e,r)=>{let i=me(e,r),o=T;T=null;let s=he(o,i),y=s?o.at:Z(),w=s?o.token.catch(()=>W(e,r)):W(e,r);w.catch(()=>{});let v,c=new Promise(_=>{v=setTimeout(()=>_("late"),mt)});try{let _=await Promise.race([w.then(C=>({token:C}),C=>({error:Be(C)})),c]);return _==="late"&&!u&&T===null&&(T={key:i,at:y,token:w}),_}finally{clearTimeout(v)}},"mt"),ye=t(async()=>{P=void 0;let e=await m(),r=e.challenge;if(r==null)return{};let i=await Xe(r,F(e.sessionId));return i!=="late"&&"token"in i?{channel:"hosted_web",turnstileToken:i.token}:(P=i!=="late"?i.error:Y,{channel:"hosted_web"})},"Ee"),et=t(()=>P,"ht"),O=t(e=>{if(u)return;let r=f.reportCaptureIssue;if(r===void 0)return;let i=e.formFactor;try{i??(i=ke())}catch{}try{Promise.resolve(r.call(f,{...e,...i!==void 0?{formFactor:i}:{}})).catch(()=>{})}catch{}},"G"),h=null,_e=Promise.resolve(),x=0,tt=t(async()=>{let e=await m();for(let r=0;r<vt&&!u&&!A(e)&&R(e)===void 0&&Te(e).some(i=>i.state==="processing")&&(await D(ht),!u);r+=1)e=await b();return e},"St"),nt=t(async(e,r,i)=>{let{capture:o}=e,s=t(()=>u,"h"),y=t(()=>e.alive&&e.attempt===i,"b"),w=t(c=>{y()&&o.setFlowState(c)},"E"),v=t(c=>{if(!s()&&(c.status==="unavailable"&&c.reasonCode!==void 0&&!Me(c.reasonCode)&&O({check:"liveness",kind:"unavailable",phase:"upload",engineKind:c.reasonCode,attempt:Math.max(0,e.issues.value)}),$(c),!!y())){if(c.status==="retry"&&Ze==="auto"){o.handle.retry();return}o.setFlowState("done")}},"P");if(r.degraded==="NO_RECORDER"){let c=l?.sessionId??(await m().catch(()=>null))?.sessionId??"";v(S(c,"no_recorder"));return}w("uploading");try{if(await fe(),s())return;let c=await m(),_;if(!A(c)&&E(c)!==null){await le(!1),v(S(c.sessionId,"method_required"));return}if(!A(c)){if(R(c)?.checkType==="population_registry"){v(S(c.sessionId,ce?"nni_unbound":ue?"network":"registry_unavailable"));return}if(await k(),s())return;_=l??c;let C=await xe({...q,artifacts:r,getAttestation:ye,attestationError:et,getView:t(()=>l??c,"getView"),refreshView:b,applySubmit:H,onPhase:w,isCancelled:s,onKeyframePromoted:t(B=>{ne=B},"onKeyframePromoted")});if(s())return;if(C.kind==="unavailable"){let B=S(c.sessionId,C.reason),be=C.reason==="attestation"?P:void 0;v(be!==void 0?{...B,attestationError:be}:B);return}if(C.kind==="resync"&&await b(),l!==null&&E(l)!==null){await le(!1),v(S(c.sessionId,"method_required"));return}c=await tt()}v(X(c,{autoRetry:p,previous:_}))}catch{if(s())return;v(S(l?.sessionId??"","network"))}},"yt"),rt=t((e,r)=>{let i=e.attempt;x>0&&e.alive&&e.capture.setFlowState("uploading"),x+=1,_e=_e.then(()=>nt(e,r,i)).finally(()=>{x-=1,x===0&&I?.onChainIdle()}).catch(()=>{})},"gt"),ge=t(e=>{h?.capture.handle.destroy(),h!==null&&(h.alive=!1);let r=Le(e,I?.captureInternals?.(e)??a.capture,()=>l?.capture?.liveness?.keyframe?.rank===!0,ie,()=>l?.capture?.liveness?.screenRamp,{session:t(()=>j(l),"session"),onModeChange:t(s=>{U=s},"onModeChange")}),i={capture:r,alive:!0,attempt:0,issues:Se()};h=i,r.handle.on("error",s=>{O(Ae("liveness",s,i.issues.value))}),r.handle.on("state",s=>{if(i.issues.note(s),s==="starting"){i.attempt+=1,ve(l);let y=l===null?void 0:R(l)?.checkType;(y==="liveness"||y==="face_match")&&k().catch(()=>{})}}),r.handle.on("captured",s=>{Promise.resolve().then(()=>rt(i,s))});let o=r.handle;return{get state(){return o.state},get captureMode(){return o.captureMode},get facingMode(){return o.facingMode},on:t((s,y)=>o.on(s,y),"on"),start:t(async s=>{if(l===null&&await m().catch(()=>{}),!!i.alive)return o.start(s)},"start"),retry:t(()=>o.retry(),"retry"),switchCamera:t(()=>o.switchCamera(),"switchCamera"),canSwitchCaptureMode:t(()=>o.canSwitchCaptureMode(),"canSwitchCaptureMode"),setCaptureMode:t(s=>o.setCaptureMode(s),"setCaptureMode"),destroy:t(()=>{i.alive=!1,h===i&&(h=null),o.destroy()},"destroy")}},"Ve"),it=t(async()=>{if(u)return null;try{let e=await m();return u?null:E(e)}catch{return null}},"Ct"),at=t(async()=>{if(u)return"self";try{let e=await m();if(u)return"self";let r=j(e);return r==="choice"?L()??r:r}catch{return"self"}},"_t"),ot=t(async()=>{if(u)return!1;try{let e=await m();return u||A(e)||Q()?!1:ee(e,R(e))==="phone"||ee(e,N(e,"liveness"))==="phone"}catch{return!1}},"kt"),st=t(async()=>{if(u)return!1;try{let e=await m();return!u&&e.returning===!0}catch{return!1}},"Pt"),lt=t(async e=>{let r=(await m()).plan?.choice,i=r?.options.find(s=>Ie[s.service]===e);if(!i)throw new RangeError(`method ${String(e)} is not offered`);let o=await f.choose(r.nodeId,i.id);u||g(o)},"bt"),J=null,ut=t(()=>(J??(J=import("./plan-runner-EP26JU6A-LU7KJ6JU.js").then(e=>{let r=e.createPlanRunner({runtime:q,currentView:t(()=>l,"currentView"),cameraMode:ie,captureModeSwitch:{pick:L,choose:t(i=>{U=i},"choose")},ensureView:m,refreshView:b,ensureConsent:t(()=>k(),"ensureConsent"),liveness:ge,stopLiveness:t(()=>{h!==null&&(h.alive=!1,h.capture.handle.destroy(),h=null)},"stopLiveness"),chainBusy:t(()=>x>0,"chainBusy"),destroyed:t(()=>u,"destroyed"),sleep:D,isMobile:Q,now:a.now??Date.now,keptFaceKey:t(()=>ne,"keptFaceKey"),setView:g,baseCapture:a.capture,emitStep:t(i=>{u||M.emit("step",i)},"emitStep"),emitResult:Je,reportCaptureIssue:O,documentInternals:a.document,portraitInternals:a.portrait,livePhotoInternals:a.livePhoto,uploadInternals:a.upload,pageCameraInternals:a.pageCamera});return I=r,r})),J),"xt");return{consent:t(()=>k(),"consent"),startRegistry:fe,methodChoice:it,selectMethod:lt,reportCameraUnavailable:t(async e=>{await k();let r=f.reportCameraUnavailable;if(r===void 0)throw new TypeError("this client cannot report a missing camera");let i=await r.call(f,e).catch(o=>{if(o instanceof V&&o.code==="check_out_of_order")return f.getSession();throw o});u||g(i)},"reportCameraUnavailable"),reportCaptureIssue:O,testerGate:t(async e=>{let r=f.testerGate;if(r===void 0)throw new TypeError("this client cannot run the tester gate");let i=e.clip,o=we(e.clipMime??"");if(i===void 0||!Pe.includes(o))throw new TypeError("the capture has no clip");await k();let s=await Re(f,"clip",o,i.size,{engine:e.engine,durationMs:e.clipMs});await f.uploadToSpaces(s.uploadUrl,i,o);let{key:y}=await f.completeMedia(s.key),w=await ye(),v=await r.call(f,{clipKey:y,attestation:w,captureChannel:e.captureChannel,capture:{...Ne(e),attestationError:P}}),{bound:c,..._}=v;return u||(_.plan!==void 0?g(_):await b()),{bound:c===!0}},"testerGate"),mobileRequired:ot,captureMode:at,chooseCaptureMode:t(e=>{U=e},"chooseCaptureMode"),get captureChoice(){return L()},returning:st,liveness:ge,run:t(async()=>{if(u)throw new Error("verification destroyed");return(await ut()).run()},"run"),currentStep:t(()=>I?.current()??null,"currentStep"),voiceClips:t(async()=>{if(u)return null;try{let e=await m();return u?null:e.voice??null}catch{return null}},"voiceClips"),on:t((e,r)=>M.on(e,r),"on"),destroy:t(()=>{u=!0,re.abort(),I?.destroy(),h!==null&&(h.alive=!1,h.capture.handle.destroy(),h=null),M.clear()},"destroy")}}t(bt,"Tt");var Fe=["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"],je=["carte_identite","passport","residence_permit","drivers_license"],kt=["carte_identite","passport","residence_permit"];function te(n,a){let d=n.byIssuer?.[a]??n.default;return je.filter(p=>d==="*"?kt.includes(p):d.includes(p))}t(te,"Dt");function He(n,a=Fe){return[...new Set([...a,...Object.keys(n.byIssuer??{})])].filter(d=>te(n,d).length>0).sort()}t(He,"En");var qe=Object.freeze({nni_invalid:"id_number_invalid",nni_not_found:"registry_record_not_found",nni_recheck:"id_number_recheck",document_nni_mismatch:"document_id_number_mismatch",nni_locked:"id_number_locked",nni_unbound:"id_number_unbound",missing_nni:"missing_id_number",registry_needs_nni_source:"registry_needs_id_number_source"}),Ft=new Map(Object.entries(qe)),jt=new Map(Object.entries(qe).map(([n,a])=>[a,n]));var Ht=10*1024*1024;function wn(n){if(n==="permission")return"denied";if(n==="notfound"||n==="insecure"||n==="unsupported")return"no_camera"}t(wn,"oe");var wt=/^[A-Z0-9][A-Z0-9 -]{0,39}$/,Ct=Object.freeze({normalize:t(n=>n.trim().toUpperCase().replace(/\s+/g," "),"normalize"),check:t(n=>wt.test(n),"check"),registrySources:Object.freeze([]),describe:"number must be 1 to 40 letters, digits, spaces or hyphens"}),Mt=/^[A-Z0-9]{4,20}$/,$e=t(n=>n.trim().toUpperCase().replace(/[\s-]+/g,""),"R"),ze=Object.freeze({normalize:$e,check:t(n=>Mt.test($e(n)),"check"),registrySources:Object.freeze([]),describe:"number must be 4 to 20 letters or digits"});function At(n){return typeof n=="string"&&/^\d{10}$/.test(n)&&Number(n)%97===1}t(At,"ae");var St=Object.freeze({normalize:t(n=>n.trim(),"normalize"),check:t(n=>At(n),"check"),registrySources:Object.freeze(["MR.anrpts"]),describe:"number must be the 10-digit Mauritanian national ID number with a valid check digit"}),It=Object.freeze({...ze,check:t(n=>/^\d{8}$/.test(n.trim()),"check"),describe:"number must be the 8-digit Mauritanian driver's license number"}),Tt=Object.freeze({"MR:national_id":St,"MR:drivers_license":It});function Et(n,a){return Tt[`${n.toUpperCase()}:${a}`]??(a==="drivers_license"?ze:Ct)}t(Et,"m");var Cn=Object.freeze({MRT:"MR"});function Mn(n){return Et("MR","national_id").check(n)}t(Mn,"le");function Rt(n){let a="";for(let d of n){let p=d.codePointAt(0)??0;p>=1632&&p<=1641?a+=String(p-1632):p>=1776&&p<=1785?a+=String(p-1776):d!==" "&&d!=="-"&&d!==" "&&(a+=d)}return a}t(Rt,"E");function An(n){return Rt(n)}t(An,"me");var Sn=te,In=He;var Pt=t(()=>import("./create-document-capture-OXPLKHOF-GVCM77EK.js"),"H");function Ot(){Pt().then(n=>n.warmDocumentCapture()).catch(()=>{})}t(Ot,"D");function Tn(){Ot()}t(Tn,"Ke");var xt=t(()=>import("./create-portrait-capture-5VGYZUOK-N3333DJC.js"),"L");function Nt(){xt().then(n=>n.warmPortraitCapture()).catch(()=>{})}t(Nt,"I");function En(){Nt()}t(En,"Ye");export{gt as a,wn as b,Mn as c,An as d,Sn as e,In as f,Tn as g,En as h};
3
+ ${r}`,"Ie"),W=t((e,r)=>{let i=We(e,{signal:re.signal,subject:r});return i.then(()=>{Y=void 0},o=>{let s=Be(o);u||s==="aborted"||(Y=s,O({check:"attestation",kind:"unavailable",engineKind:s}))}),i},"ce"),he=t((e,r)=>e!==null&&e.key===r&&Z()-e.at<ft,"Me"),ve=t(e=>{let r=e?.challenge??null;if(e===null||r===null||u)return;let i=me(r,F(e.sessionId));if(he(T,i))return;let o=W(r,F(e.sessionId));o.catch(()=>{}),T={key:i,at:Z(),token:o}},"ve"),Xe=t(async(e,r)=>{let i=me(e,r),o=T;T=null;let s=he(o,i),y=s?o.at:Z(),w=s?o.token.catch(()=>W(e,r)):W(e,r);w.catch(()=>{});let v,c=new Promise(_=>{v=setTimeout(()=>_("late"),mt)});try{let _=await Promise.race([w.then(C=>({token:C}),C=>({error:Be(C)})),c]);return _==="late"&&!u&&T===null&&(T={key:i,at:y,token:w}),_}finally{clearTimeout(v)}},"mt"),ye=t(async()=>{P=void 0;let e=await m(),r=e.challenge;if(r==null)return{};let i=await Xe(r,F(e.sessionId));return i!=="late"&&"token"in i?{channel:"hosted_web",turnstileToken:i.token}:(P=i!=="late"?i.error:Y,{channel:"hosted_web"})},"Ee"),et=t(()=>P,"ht"),O=t(e=>{if(u)return;let r=f.reportCaptureIssue;if(r===void 0)return;let i=e.formFactor;try{i??(i=ke())}catch{}try{Promise.resolve(r.call(f,{...e,...i!==void 0?{formFactor:i}:{}})).catch(()=>{})}catch{}},"G"),h=null,_e=Promise.resolve(),x=0,tt=t(async()=>{let e=await m();for(let r=0;r<vt&&!u&&!A(e)&&R(e)===void 0&&Te(e).some(i=>i.state==="processing")&&(await D(ht),!u);r+=1)e=await b();return e},"St"),nt=t(async(e,r,i)=>{let{capture:o}=e,s=t(()=>u,"h"),y=t(()=>e.alive&&e.attempt===i,"b"),w=t(c=>{y()&&o.setFlowState(c)},"E"),v=t(c=>{if(!s()&&(c.status==="unavailable"&&c.reasonCode!==void 0&&!Me(c.reasonCode)&&O({check:"liveness",kind:"unavailable",phase:"upload",engineKind:c.reasonCode,attempt:Math.max(0,e.issues.value)}),$(c),!!y())){if(c.status==="retry"&&Ze==="auto"){o.handle.retry();return}o.setFlowState("done")}},"P");if(r.degraded==="NO_RECORDER"){let c=l?.sessionId??(await m().catch(()=>null))?.sessionId??"";v(S(c,"no_recorder"));return}w("uploading");try{if(await fe(),s())return;let c=await m(),_;if(!A(c)&&E(c)!==null){await le(!1),v(S(c.sessionId,"method_required"));return}if(!A(c)){if(R(c)?.checkType==="population_registry"){v(S(c.sessionId,ce?"nni_unbound":ue?"network":"registry_unavailable"));return}if(await k(),s())return;_=l??c;let C=await xe({...q,artifacts:r,getAttestation:ye,attestationError:et,getView:t(()=>l??c,"getView"),refreshView:b,applySubmit:H,onPhase:w,isCancelled:s,onKeyframePromoted:t(B=>{ne=B},"onKeyframePromoted")});if(s())return;if(C.kind==="unavailable"){let B=S(c.sessionId,C.reason),be=C.reason==="attestation"?P:void 0;v(be!==void 0?{...B,attestationError:be}:B);return}if(C.kind==="resync"&&await b(),l!==null&&E(l)!==null){await le(!1),v(S(c.sessionId,"method_required"));return}c=await tt()}v(X(c,{autoRetry:p,previous:_}))}catch{if(s())return;v(S(l?.sessionId??"","network"))}},"yt"),rt=t((e,r)=>{let i=e.attempt;x>0&&e.alive&&e.capture.setFlowState("uploading"),x+=1,_e=_e.then(()=>nt(e,r,i)).finally(()=>{x-=1,x===0&&I?.onChainIdle()}).catch(()=>{})},"gt"),ge=t(e=>{h?.capture.handle.destroy(),h!==null&&(h.alive=!1);let r=Le(e,I?.captureInternals?.(e)??a.capture,()=>l?.capture?.liveness?.keyframe?.rank===!0,ie,()=>l?.capture?.liveness?.screenRamp,{session:t(()=>j(l),"session"),onModeChange:t(s=>{U=s},"onModeChange")}),i={capture:r,alive:!0,attempt:0,issues:Se()};h=i,r.handle.on("error",s=>{O(Ae("liveness",s,i.issues.value))}),r.handle.on("state",s=>{if(i.issues.note(s),s==="starting"){i.attempt+=1,ve(l);let y=l===null?void 0:R(l)?.checkType;(y==="liveness"||y==="face_match")&&k().catch(()=>{})}}),r.handle.on("captured",s=>{Promise.resolve().then(()=>rt(i,s))});let o=r.handle;return{get state(){return o.state},get captureMode(){return o.captureMode},get facingMode(){return o.facingMode},on:t((s,y)=>o.on(s,y),"on"),start:t(async s=>{if(l===null&&await m().catch(()=>{}),!!i.alive)return o.start(s)},"start"),retry:t(()=>o.retry(),"retry"),switchCamera:t(()=>o.switchCamera(),"switchCamera"),canSwitchCaptureMode:t(()=>o.canSwitchCaptureMode(),"canSwitchCaptureMode"),setCaptureMode:t(s=>o.setCaptureMode(s),"setCaptureMode"),destroy:t(()=>{i.alive=!1,h===i&&(h=null),o.destroy()},"destroy")}},"Ve"),it=t(async()=>{if(u)return null;try{let e=await m();return u?null:E(e)}catch{return null}},"Ct"),at=t(async()=>{if(u)return"self";try{let e=await m();if(u)return"self";let r=j(e);return r==="choice"?L()??r:r}catch{return"self"}},"_t"),ot=t(async()=>{if(u)return!1;try{let e=await m();return u||A(e)||Q()?!1:ee(e,R(e))==="phone"||ee(e,N(e,"liveness"))==="phone"}catch{return!1}},"kt"),st=t(async()=>{if(u)return!1;try{let e=await m();return!u&&e.returning===!0}catch{return!1}},"Pt"),lt=t(async e=>{let r=(await m()).plan?.choice,i=r?.options.find(s=>Ie[s.service]===e);if(!i)throw new RangeError(`method ${String(e)} is not offered`);let o=await f.choose(r.nodeId,i.id);u||g(o)},"bt"),J=null,ut=t(()=>(J??(J=import("./plan-runner-KQM7I4MR-HEXIU27Q.js").then(e=>{let r=e.createPlanRunner({runtime:q,currentView:t(()=>l,"currentView"),cameraMode:ie,captureModeSwitch:{pick:L,choose:t(i=>{U=i},"choose")},ensureView:m,refreshView:b,ensureConsent:t(()=>k(),"ensureConsent"),liveness:ge,stopLiveness:t(()=>{h!==null&&(h.alive=!1,h.capture.handle.destroy(),h=null)},"stopLiveness"),chainBusy:t(()=>x>0,"chainBusy"),destroyed:t(()=>u,"destroyed"),sleep:D,isMobile:Q,now:a.now??Date.now,keptFaceKey:t(()=>ne,"keptFaceKey"),setView:g,baseCapture:a.capture,emitStep:t(i=>{u||M.emit("step",i)},"emitStep"),emitResult:Je,reportCaptureIssue:O,documentInternals:a.document,portraitInternals:a.portrait,livePhotoInternals:a.livePhoto,uploadInternals:a.upload,pageCameraInternals:a.pageCamera});return I=r,r})),J),"xt");return{consent:t(()=>k(),"consent"),startRegistry:fe,methodChoice:it,selectMethod:lt,reportCameraUnavailable:t(async e=>{await k();let r=f.reportCameraUnavailable;if(r===void 0)throw new TypeError("this client cannot report a missing camera");let i=await r.call(f,e).catch(o=>{if(o instanceof V&&o.code==="check_out_of_order")return f.getSession();throw o});u||g(i)},"reportCameraUnavailable"),reportCaptureIssue:O,testerGate:t(async e=>{let r=f.testerGate;if(r===void 0)throw new TypeError("this client cannot run the tester gate");let i=e.clip,o=we(e.clipMime??"");if(i===void 0||!Pe.includes(o))throw new TypeError("the capture has no clip");await k();let s=await Re(f,"clip",o,i.size,{engine:e.engine,durationMs:e.clipMs});await f.uploadToSpaces(s.uploadUrl,i,o);let{key:y}=await f.completeMedia(s.key),w=await ye(),v=await r.call(f,{clipKey:y,attestation:w,captureChannel:e.captureChannel,capture:{...Ne(e),attestationError:P}}),{bound:c,..._}=v;return u||(_.plan!==void 0?g(_):await b()),{bound:c===!0}},"testerGate"),mobileRequired:ot,captureMode:at,chooseCaptureMode:t(e=>{U=e},"chooseCaptureMode"),get captureChoice(){return L()},returning:st,liveness:ge,run:t(async()=>{if(u)throw new Error("verification destroyed");return(await ut()).run()},"run"),currentStep:t(()=>I?.current()??null,"currentStep"),voiceClips:t(async()=>{if(u)return null;try{let e=await m();return u?null:e.voice??null}catch{return null}},"voiceClips"),on:t((e,r)=>M.on(e,r),"on"),destroy:t(()=>{u=!0,re.abort(),I?.destroy(),h!==null&&(h.alive=!1,h.capture.handle.destroy(),h=null),M.clear()},"destroy")}}t(bt,"Tt");var Fe=["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"],je=["carte_identite","passport","residence_permit","drivers_license"],kt=["carte_identite","passport","residence_permit"];function te(n,a){let d=n.byIssuer?.[a]??n.default;return je.filter(p=>d==="*"?kt.includes(p):d.includes(p))}t(te,"Dt");function He(n,a=Fe){return[...new Set([...a,...Object.keys(n.byIssuer??{})])].filter(d=>te(n,d).length>0).sort()}t(He,"En");var qe=Object.freeze({nni_invalid:"id_number_invalid",nni_not_found:"registry_record_not_found",nni_recheck:"id_number_recheck",document_nni_mismatch:"document_id_number_mismatch",nni_locked:"id_number_locked",nni_unbound:"id_number_unbound",missing_nni:"missing_id_number",registry_needs_nni_source:"registry_needs_id_number_source"}),Ft=new Map(Object.entries(qe)),jt=new Map(Object.entries(qe).map(([n,a])=>[a,n]));var Ht=10*1024*1024;function wn(n){if(n==="permission")return"denied";if(n==="notfound"||n==="insecure"||n==="unsupported")return"no_camera"}t(wn,"oe");var wt=/^[A-Z0-9][A-Z0-9 -]{0,39}$/,Ct=Object.freeze({normalize:t(n=>n.trim().toUpperCase().replace(/\s+/g," "),"normalize"),check:t(n=>wt.test(n),"check"),registrySources:Object.freeze([]),describe:"number must be 1 to 40 letters, digits, spaces or hyphens"}),Mt=/^[A-Z0-9]{4,20}$/,$e=t(n=>n.trim().toUpperCase().replace(/[\s-]+/g,""),"R"),ze=Object.freeze({normalize:$e,check:t(n=>Mt.test($e(n)),"check"),registrySources:Object.freeze([]),describe:"number must be 4 to 20 letters or digits"});function At(n){return typeof n=="string"&&/^\d{10}$/.test(n)&&Number(n)%97===1}t(At,"ae");var St=Object.freeze({normalize:t(n=>n.trim(),"normalize"),check:t(n=>At(n),"check"),registrySources:Object.freeze(["MR.anrpts"]),describe:"number must be the 10-digit Mauritanian national ID number with a valid check digit"}),It=Object.freeze({...ze,check:t(n=>/^\d{8}$/.test(n.trim()),"check"),describe:"number must be the 8-digit Mauritanian driver's license number"}),Tt=Object.freeze({"MR:national_id":St,"MR:drivers_license":It});function Et(n,a){return Tt[`${n.toUpperCase()}:${a}`]??(a==="drivers_license"?ze:Ct)}t(Et,"m");var Cn=Object.freeze({MRT:"MR"});function Mn(n){return Et("MR","national_id").check(n)}t(Mn,"le");function Rt(n){let a="";for(let d of n){let p=d.codePointAt(0)??0;p>=1632&&p<=1641?a+=String(p-1632):p>=1776&&p<=1785?a+=String(p-1776):d!==" "&&d!=="-"&&d!==" "&&(a+=d)}return a}t(Rt,"E");function An(n){return Rt(n)}t(An,"me");var Sn=te,In=He;var Pt=t(()=>import("./create-document-capture-2YBCDEUB-GYUIXEAL.js"),"H");function Ot(){Pt().then(n=>n.warmDocumentCapture()).catch(()=>{})}t(Ot,"D");function Tn(){Ot()}t(Tn,"Ke");var xt=t(()=>import("./create-portrait-capture-5VGYZUOK-N3333DJC.js"),"L");function Nt(){xt().then(n=>n.warmPortraitCapture()).catch(()=>{})}t(Nt,"I");function En(){Nt()}t(En,"Ye");export{gt as a,wn as b,Mn as c,An as d,Sn as e,In as f,Tn as g,En as h};