@sekyro/elements 0.1.0-rc.11 → 0.1.0-rc.12

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 (81) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/cdn/chunks/{capture-session-doc-2XRGB6AO-ZURBQ4YP.js → capture-session-doc-FAMDLRRZ-QPOFTNTG.js} +1 -1
  3. package/dist/cdn/chunks/challenge-frame-YBTLAQ5G-NN763UU5.js +1 -0
  4. package/dist/cdn/chunks/{chunk-ADYI7APR.js → chunk-3DDOCOIB.js} +1 -1
  5. package/dist/cdn/chunks/{chunk-TXDGBMD4.js → chunk-4YBL75VD.js} +1 -1
  6. package/dist/cdn/chunks/{chunk-R3P75ZRR.js → chunk-5JWGGQBH.js} +1 -1
  7. package/dist/cdn/chunks/{chunk-VPJEUYYP.js → chunk-7JUL7AKT.js} +1 -1
  8. package/dist/cdn/chunks/{chunk-RKNAZPA7.js → chunk-AARN2MG7.js} +1 -1
  9. package/dist/cdn/chunks/{chunk-TPDANNML.js → chunk-BMUUDLFA.js} +1 -1
  10. package/dist/cdn/chunks/{chunk-S774ZMGH.js → chunk-CSKOH7QX.js} +1 -1
  11. package/dist/cdn/chunks/{chunk-BMOSAKXR.js → chunk-CVFJQIMW.js} +1 -1
  12. package/dist/cdn/chunks/{chunk-K5SATFJY.js → chunk-FVWYONHZ.js} +1 -1
  13. package/dist/cdn/chunks/{chunk-FQYXVP54.js → chunk-GPGK6XZM.js} +1 -1
  14. package/dist/cdn/chunks/{chunk-E7OQJP4I.js → chunk-GZOBS7KG.js} +1 -1
  15. package/dist/cdn/chunks/chunk-JJ3Q52P3.js +25 -0
  16. package/dist/cdn/chunks/{chunk-S4ABXV4B.js → chunk-K4BLQMYZ.js} +1 -1
  17. package/dist/cdn/chunks/{chunk-QMBS54J5.js → chunk-LBZCFEU4.js} +2 -2
  18. package/dist/cdn/chunks/{chunk-C6HZ7TYS.js → chunk-Q5BUNNRN.js} +2 -2
  19. package/dist/cdn/chunks/{chunk-RH3APX6G.js → chunk-SDK2YXFV.js} +1 -1
  20. package/dist/cdn/chunks/{chunk-3CEJV42Q.js → chunk-UN4V3UNQ.js} +1 -1
  21. package/dist/cdn/chunks/{chunk-O23O5AAH.js → chunk-VHNWBOKW.js} +1 -1
  22. package/dist/cdn/chunks/{chunk-DW3VKKDE.js → chunk-XDRH4VWV.js} +1 -1
  23. package/dist/cdn/chunks/{chunk-XSGAV3PT.js → chunk-YFJBTK3L.js} +1 -1
  24. package/dist/cdn/chunks/{chunk-QXWWOMOK.js → chunk-YLH3WX7Y.js} +1 -1
  25. package/dist/cdn/chunks/{create-document-capture-XWNBUC55-FZGHPB6L.js → create-document-capture-WFTNVMCE-QOCPJSAU.js} +1 -1
  26. package/dist/cdn/chunks/{document-capture-view-2NFKF44N-4F3CP2ZO.js → document-capture-view-GENB535Z-YBRM7NWN.js} +1 -1
  27. package/dist/cdn/chunks/{eid-view-UGYVZ5NM-NQLRT4US.js → eid-view-IQRZGEMP-SPGYQDQP.js} +1 -1
  28. package/dist/cdn/chunks/{email-otp-view-ENQVRS66-DCCJA246.js → email-otp-view-CL76K5TY-TJMSLYLZ.js} +1 -1
  29. package/dist/cdn/chunks/{flow-views-HNJPDQ63-ER7B4XJF.js → flow-views-C3EIMXME-ODOF67JZ.js} +1 -1
  30. package/dist/cdn/chunks/{form-view-6ERKUFVD-2JHV2SHY.js → form-view-MEYCK437-JBO5DNG5.js} +1 -1
  31. package/dist/cdn/chunks/overlay-de-LOQWEHOH-HSNQGD4A.js +1 -0
  32. package/dist/cdn/chunks/overlay-es-F54CKFZO-BTQKTR4A.js +1 -0
  33. package/dist/cdn/chunks/overlay-pt-NHIQY3JB-DQ7MH2QJ.js +1 -0
  34. package/dist/cdn/chunks/{plan-runner-KX7KUS3M-CECACJOR.js → plan-runner-LSQTIO6L-XZJIKXPZ.js} +1 -1
  35. package/dist/cdn/chunks/{portrait-capture-view-ARRN3JW6-XRLTO3JS.js → portrait-capture-view-VTN2VU3E-JH34ISLI.js} +1 -1
  36. package/dist/cdn/chunks/{portrait-review-view-JF6TYNBU-57HERUGH.js → portrait-review-view-JTRGDYNV-C2O6OFYY.js} +1 -1
  37. package/dist/cdn/chunks/{proof-of-address-view-46Q6F7H5-7ES2ZRQL.js → proof-of-address-view-UQOZZXQO-T3QOIQNE.js} +1 -1
  38. package/dist/cdn/define.js +1 -1
  39. package/dist/cdn/index.js +1 -1
  40. package/dist/{chunk-DXR3ZGW2.js → chunk-6OZGEXX6.js} +1 -1
  41. package/dist/{chunk-37I3KKNR.js → chunk-753PBLDK.js} +1 -1
  42. package/dist/chunk-BZGVYIDN.js +25 -0
  43. package/dist/{chunk-NC6MJEKS.js → chunk-FBXU2OZN.js} +1 -1
  44. package/dist/{chunk-Y6IZDRYW.js → chunk-FCIH6PVW.js} +1 -1
  45. package/dist/{chunk-ZDYBRXXU.js → chunk-GA2DVM5C.js} +1 -1
  46. package/dist/{chunk-PNZPHUSG.js → chunk-HLMRVFVD.js} +1 -1
  47. package/dist/{chunk-5MQUCOFK.js → chunk-K7PFKAQD.js} +1 -1
  48. package/dist/{chunk-Q5HUTAIF.js → chunk-KNWOL5RR.js} +1 -1
  49. package/dist/{chunk-GBOZODQT.js → chunk-LGFZBFVB.js} +2 -2
  50. package/dist/{chunk-JQOJI5Z3.js → chunk-PYQREZ33.js} +1 -1
  51. package/dist/{chunk-43AFSR5C.js → chunk-W6ODZ5JK.js} +1 -1
  52. package/dist/{chunk-FHAN7WFM.js → chunk-XEWL7C6M.js} +1 -1
  53. package/dist/{chunk-OCLSIGRD.js → chunk-ZUVOUGIA.js} +1 -1
  54. package/dist/define.cjs +3 -3
  55. package/dist/define.js +1 -1
  56. package/dist/{document-capture-view-2NFKF44N-4JPWTBPF.js → document-capture-view-GENB535Z-L5V7YSPP.js} +1 -1
  57. package/dist/{eid-view-UGYVZ5NM-H7FHAGGG.js → eid-view-IQRZGEMP-LAMWORUL.js} +1 -1
  58. package/dist/{email-otp-view-ENQVRS66-5ZB3UKOO.js → email-otp-view-CL76K5TY-C7O472UB.js} +1 -1
  59. package/dist/{flow-views-HNJPDQ63-RAX3SDYO.js → flow-views-C3EIMXME-GGE4OUEO.js} +1 -1
  60. package/dist/{form-view-6ERKUFVD-Q2C54SUQ.js → form-view-MEYCK437-356QICGF.js} +1 -1
  61. package/dist/index.cjs +3 -3
  62. package/dist/index.d.cts +1 -0
  63. package/dist/index.d.ts +1 -0
  64. package/dist/index.js +1 -1
  65. package/dist/overlay-de-LOQWEHOH-YIQXHAUD.js +1 -0
  66. package/dist/overlay-es-F54CKFZO-JNTVTVWI.js +1 -0
  67. package/dist/overlay-pt-NHIQY3JB-V5CJ5SGF.js +1 -0
  68. package/dist/{portrait-capture-view-ARRN3JW6-RZYLVCCJ.js → portrait-capture-view-VTN2VU3E-2HKWLWRG.js} +1 -1
  69. package/dist/{portrait-review-view-JF6TYNBU-NHMROJU3.js → portrait-review-view-JTRGDYNV-TNR7WBYD.js} +1 -1
  70. package/dist/{proof-of-address-view-46Q6F7H5-TPLEKAFW.js → proof-of-address-view-UQOZZXQO-XJTGU3G6.js} +1 -1
  71. package/package.json +2 -2
  72. package/sbom.cdx.json +4 -4
  73. package/dist/cdn/chunks/challenge-frame-YAQJ5YMB-MHZYRGKY.js +0 -1
  74. package/dist/cdn/chunks/chunk-SOI356LX.js +0 -25
  75. package/dist/cdn/chunks/overlay-de-2DL4MNC7-5CBBHT7P.js +0 -1
  76. package/dist/cdn/chunks/overlay-es-FMHWRKQW-REFKUX4J.js +0 -1
  77. package/dist/cdn/chunks/overlay-pt-OGIELLCM-GU2A32BS.js +0 -1
  78. package/dist/chunk-VD7QSFUC.js +0 -25
  79. package/dist/overlay-de-2DL4MNC7-ELIZ2XHC.js +0 -1
  80. package/dist/overlay-es-FMHWRKQW-5PQ3EGK2.js +0 -1
  81. package/dist/overlay-pt-OGIELLCM-QT53YCS2.js +0 -1
@@ -1,4 +1,4 @@
1
- import{d as I}from"./chunk-RKNAZPA7.js";import{a as C,b as P,c as H}from"./chunk-SOI356LX.js";import{a as T}from"./chunk-FQYXVP54.js";import{a as u}from"./chunk-5QL6W6FW.js";import{a as s,b as D,c as N}from"./chunk-4FHWXBOB.js";var j=D(l=>{"use strict";var Q=C();function V(r){var e="https://react.dev/errors/"+r;if(1<arguments.length){e+="?args[]="+encodeURIComponent(arguments[1]);for(var t=2;t<arguments.length;t++)e+="&args[]="+encodeURIComponent(arguments[t])}return"Minified React error #"+r+"; visit "+e+" for the full message or use the non-minified dev environment for full errors and additional helpful warnings."}s(V,"formatProdErrorMessage");function h(){}s(h,"noop");var c={d:{f:h,r:s(function(){throw Error(V(522))},"r"),D:h,C:h,L:h,m:h,X:h,S:h,M:h},p:0,findDOMNode:null},ee=Symbol.for("react.portal");function re(r,e,t){var n=3<arguments.length&&arguments[3]!==void 0?arguments[3]:null;return{$$typeof:ee,key:n==null?null:""+n,children:r,containerInfo:e,implementation:t}}s(re,"createPortal$1");var O=Q.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;function M(r,e){if(r==="font")return"";if(typeof e=="string")return e==="use-credentials"?e:""}s(M,"getCrossOriginStringAs");l.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE=c;l.createPortal=function(r,e){var t=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11)throw Error(V(299));return re(r,e,null,t)};l.flushSync=function(r){var e=O.T,t=c.p;try{if(O.T=null,c.p=2,r)return r()}finally{O.T=e,c.p=t,c.d.f()}};l.preconnect=function(r,e){typeof r=="string"&&(e?(e=e.crossOrigin,e=typeof e=="string"?e==="use-credentials"?e:"":void 0):e=null,c.d.C(r,e))};l.prefetchDNS=function(r){typeof r=="string"&&c.d.D(r)};l.preinit=function(r,e){if(typeof r=="string"&&e&&typeof e.as=="string"){var t=e.as,n=M(t,e.crossOrigin),o=typeof e.integrity=="string"?e.integrity:void 0,i=typeof e.fetchPriority=="string"?e.fetchPriority:void 0;t==="style"?c.d.S(r,typeof e.precedence=="string"?e.precedence:void 0,{crossOrigin:n,integrity:o,fetchPriority:i}):t==="script"&&c.d.X(r,{crossOrigin:n,integrity:o,fetchPriority:i,nonce:typeof e.nonce=="string"?e.nonce:void 0})}};l.preinitModule=function(r,e){if(typeof r=="string")if(typeof e=="object"&&e!==null){if(e.as==null||e.as==="script"){var t=M(e.as,e.crossOrigin);c.d.M(r,{crossOrigin:t,integrity:typeof e.integrity=="string"?e.integrity:void 0,nonce:typeof e.nonce=="string"?e.nonce:void 0})}}else e==null&&c.d.M(r)};l.preload=function(r,e){if(typeof r=="string"&&typeof e=="object"&&e!==null&&typeof e.as=="string"){var t=e.as,n=M(t,e.crossOrigin);c.d.L(r,t,{crossOrigin:n,integrity:typeof e.integrity=="string"?e.integrity:void 0,nonce:typeof e.nonce=="string"?e.nonce:void 0,type:typeof e.type=="string"?e.type:void 0,fetchPriority:typeof e.fetchPriority=="string"?e.fetchPriority:void 0,referrerPolicy:typeof e.referrerPolicy=="string"?e.referrerPolicy:void 0,imageSrcSet:typeof e.imageSrcSet=="string"?e.imageSrcSet:void 0,imageSizes:typeof e.imageSizes=="string"?e.imageSizes:void 0,media:typeof e.media=="string"?e.media:void 0})}};l.preloadModule=function(r,e){if(typeof r=="string")if(e){var t=M(e.as,e.crossOrigin);c.d.m(r,{as:typeof e.as=="string"&&e.as!=="script"?e.as:void 0,crossOrigin:t,integrity:typeof e.integrity=="string"?e.integrity:void 0})}else c.d.m(r)};l.requestFormReset=function(r){c.d.r(r)};l.unstable_batchedUpdates=function(r,e){return r(e)};l.useFormState=function(r,e,t){return O.H.useFormState(r,e,t)};l.useFormStatus=function(){return O.H.useHostTransitionStatus()};l.version="19.2.0"});var W=D((de,B)=>{"use strict";function U(){if(!(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__>"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(U)}catch(r){console.error(r)}}s(U,"checkDCE");U(),B.exports=j()});var z=N(C(),1),f=N(P(),1),a=N(P(),1);var E=N(C(),1),Z=N(W(),1),v=N(P(),1);var te=Array.from({length:56},(r,e)=>{let t=e/56*2*Math.PI-Math.PI/2,n=Math.cos(t),o=Math.sin(t);return{id:`tick-${e}`,frac:e/55,x1:150+108*n,y1:150+108*o,x2:150+138*n,y2:150+138*o,style:{transitionDelay:`${e*6}ms`}}});function F(r,e,t,n){return t?"var(--sekyro-color-success)":r?n?"color-mix(in srgb, var(--sekyro-color-warning) 75%, transparent)":e<.33?"color-mix(in srgb, var(--sekyro-color-brand) 55%, transparent)":e<.66?"color-mix(in srgb, var(--sekyro-color-brand) 80%, transparent)":"var(--sekyro-color-brand)":"color-mix(in srgb, var(--sekyro-color-surface) 32%, transparent)"}s(F,"T");u(F,"tickColor");var ae="M0 -50 H300 V350 H0 Z M50 150 a100,100 0 1 0 200,0 a100,100 0 1 0 -200,0 Z";function G({progress:r,phase:e,draining:t=!1}){let n=Math.min(1,Math.max(0,r)),o=Math.round(n*56),i=e==="checking",y=e==="recording",d=e==="frozen",m=i||d,p=i||y||d,k=e==="locked"||p,S=t&&!k;return(0,f.jsxs)("svg",{"aria-hidden":"true",viewBox:"0 0 300 300",preserveAspectRatio:"xMidYMid meet",className:"sekyro-stage__arc","data-testid":"sekyro-capture-arc","data-phase":e,"data-filled":o,"data-recording":y?"":void 0,"data-draining":S?"":void 0,children:[(0,f.jsx)("path",{fillRule:"evenodd",d:ae,fill:"color-mix(in srgb, var(--sekyro-color-fg) var(--sekyro-scrim, 96%), transparent)",style:{"--sekyro-scrim":m?"100%":"96%"},className:"sekyro-arc__scrim sekyro-capture-fade-in","data-testid":"sekyro-capture-scrim"}),(0,f.jsxs)("g",{className:e==="locked"?"sekyro-capture-settle":void 0,children:[(0,f.jsx)("g",{className:m?"sekyro-arc__ring sekyro-arc__ring--dim":"sekyro-arc__ring",children:te.map((g,x)=>(0,f.jsx)("line",{x1:g.x1,y1:g.y1,x2:g.x2,y2:g.y2,stroke:F(x<o,g.frac,k,S),strokeWidth:3,strokeLinecap:"round",style:g.style,className:"sekyro-arc__tick"},g.id))}),(0,f.jsx)("g",{className:e==="seeking"?"sekyro-capture-breathe":void 0,children:(0,f.jsx)("circle",{cx:150,cy:150,r:100,fill:"none",stroke:k?"var(--sekyro-color-success)":"var(--sekyro-color-surface)",strokeWidth:k?3.5:2.5,className:p?"sekyro-arc__guide sekyro-arc__guide--spin sekyro-capture-ring-spin":"sekyro-arc__guide sekyro-capture-fade-in","data-testid":"sekyro-capture-guide"})})]})]})}s(G,"x");u(G,"CaptureArc");function ne({videoRef:r,guidanceText:e,guidanceHint:t,guidanceKey:n,progress:o,phase:i,draining:y=!1,stillUrl:d,showChecking:m,operatorText:p=null,voicePrompt:k,overlay:S,reduceMotion:g=!1,modeSwitch:x=null}){let b=I(),w=i==="checking",_=w||i==="frozen",A=_&&m?b("capture.checking"):e,L=k?.(t,A,n);return(0,a.jsxs)("div",{className:g?"sekyro-stage sekyro-capture-reduce":"sekyro-stage","data-testid":"sekyro-capture-stage",children:[(0,a.jsx)("video",{ref:r,playsInline:!0,muted:!0,className:"sekyro-stage__video","data-testid":"sekyro-capture-video"}),d!==null&&_?(0,a.jsx)("img",{src:d,alt:b("capture.previewAlt"),className:"sekyro-stage__still sekyro-capture-develop","data-testid":"sekyro-capture-still"}):null,(0,a.jsx)(G,{progress:o,phase:i,draining:y}),S?.(r),L!=null&&!_?(0,a.jsx)("div",{className:"sekyro-stage__corner-start","data-testid":"sekyro-voice-slot",children:L}):null,x!==null&&!_?(0,a.jsx)($,{view:x,className:"sekyro-stage__corner-end sekyro-stage__mode-switch",kind:"chip"}):null,w&&m?(0,a.jsxs)("span",{className:"sekyro-stage__corner-end sekyro-stage__pill sekyro-capture-pill-in","data-testid":"sekyro-camera-off-pill",children:[(0,a.jsx)(Y,{}),b("capture.cameraOff")]}):null,(0,a.jsxs)("p",{"aria-live":"polite",className:"sekyro-stage__guidance","data-testid":"sekyro-capture-guidance",children:[(0,a.jsx)("span",{className:"sekyro-stage__guidance-text sekyro-capture-text-in",children:A},A),_&&m?(0,a.jsx)("span",{className:"sekyro-stage__guidance-hint",children:b("capture.checkingHint")}):p!==null&&!_?(0,a.jsx)("span",{className:"sekyro-stage__guidance-hint","data-testid":"sekyro-operator-line",children:p}):null]})]})}s(ne,"ne");u(ne,"CaptureStage");function $({view:r,className:e,kind:t}){let n=(0,z.useId)(),o=(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(K,{}),(0,a.jsx)("span",{children:r.label})]}),i={onClick:r.onSwitch,"aria-describedby":n,"data-testid":"sekyro-capture-mode-switch","data-mode":r.to};return(0,a.jsxs)(a.Fragment,{children:[t==="chip"?(0,a.jsx)(H,{kind:"chip",className:e,...i,children:o}):(0,a.jsx)("button",{type:"button",className:e,...i,children:o}),(0,a.jsx)("span",{id:n,className:"sekyro-visually-hidden",children:r.description})]})}s($,"H");u($,"ModeSwitchChip");function K(){return(0,a.jsxs)("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",className:"sekyro-icon",children:[(0,a.jsx)("path",{d:"M4 7.5h2.2l1.4-1.9h8.8l1.4 1.9H20a1.6 1.6 0 0 1 1.6 1.6v8.3A1.6 1.6 0 0 1 20 19H4a1.6 1.6 0 0 1-1.6-1.6V9.1A1.6 1.6 0 0 1 4 7.5Z"}),(0,a.jsx)("path",{d:"M15.4 11.9a3.5 3.5 0 0 0-6.1-1.4M15.4 11.9h-2.1m2.1 0V9.8"}),(0,a.jsx)("path",{d:"M8.6 13.4a3.5 3.5 0 0 0 6.1 1.4M8.6 13.4h2.1m-2.1 0v2.1"})]})}s(K,"D");u(K,"FlipCameraIcon");function Y(){return(0,a.jsxs)("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",className:"sekyro-icon sekyro-icon--sm",children:[(0,a.jsx)("path",{d:"M4 7.5h2.2l1.4-1.9h8.8l1.4 1.9H20a1.6 1.6 0 0 1 1.6 1.6v8.3A1.6 1.6 0 0 1 20 19H4a1.6 1.6 0 0 1-1.6-1.6V9.1A1.6 1.6 0 0 1 4 7.5Z"}),(0,a.jsx)("path",{d:"M3 3l18 18"})]})}s(Y,"G");u(Y,"CameraOffIcon");var ie=typeof window>"u"?E.useEffect:E.useLayoutEffect,R="data-sekyro-ramp",se=[["background-color","transparent"],["background-image","none"]];function q(r){let e=[],t=r.ownerDocument;for(let i=r;i!==null&&i!==t.documentElement;i=i.parentElement){if(!(i instanceof HTMLElement)&&!(i instanceof SVGElement))continue;let y=i.style;for(let[d,m]of se){let p=y.getPropertyValue(d),k=y.getPropertyPriority(d);y.setProperty(d,m,"important"),e.push(()=>{p===""?y.removeProperty(d):y.setProperty(d,p,k)})}}let n=t.documentElement,o=n.hasAttribute(R);return n.setAttribute(R,""),o||e.push(()=>n.removeAttribute(R)),()=>{for(let i of e.reverse())i()}}s(q,"z");u(q,"clearAncestorBackdrops");function X(r){return{position:"fixed",inset:0,minWidth:"100vw",minHeight:"100lvh",margin:0,padding:0,border:0,zIndex:-1,pointerEvents:"none",backgroundColor:T(r)}}s(X,"B");u(X,"washStyle");function J(r){return{position:"absolute",inset:0,pointerEvents:"none",backgroundColor:T(r)}}s(J,"Y");u(J,"coverStyle");function oe({colour:r}){let e=(0,E.useRef)(null),t=r!==null;return ie(()=>{let n=e.current?.parentElement;if(!(!t||n===null||n===void 0))return q(n)},[t]),r===null||typeof document>"u"?null:(0,v.jsxs)(v.Fragment,{children:[(0,v.jsx)("div",{ref:e,"aria-hidden":"true","data-testid":"sekyro-screen-ramp-cover","data-colour":r,style:J(r)}),(0,Z.createPortal)((0,v.jsx)("div",{"aria-hidden":"true","data-testid":"sekyro-screen-ramp","data-colour":r,style:X(r)}),document.body)]})}s(oe,"de");u(oe,"ScreenRampLayer");export{W as a,ne as b,$ as c,oe as d};
1
+ import{d as I}from"./chunk-AARN2MG7.js";import{a as C,b as P,c as H}from"./chunk-JJ3Q52P3.js";import{a as T}from"./chunk-GPGK6XZM.js";import{a as u}from"./chunk-5QL6W6FW.js";import{a as s,b as D,c as N}from"./chunk-4FHWXBOB.js";var j=D(l=>{"use strict";var Q=C();function V(r){var e="https://react.dev/errors/"+r;if(1<arguments.length){e+="?args[]="+encodeURIComponent(arguments[1]);for(var t=2;t<arguments.length;t++)e+="&args[]="+encodeURIComponent(arguments[t])}return"Minified React error #"+r+"; visit "+e+" for the full message or use the non-minified dev environment for full errors and additional helpful warnings."}s(V,"formatProdErrorMessage");function h(){}s(h,"noop");var c={d:{f:h,r:s(function(){throw Error(V(522))},"r"),D:h,C:h,L:h,m:h,X:h,S:h,M:h},p:0,findDOMNode:null},ee=Symbol.for("react.portal");function re(r,e,t){var n=3<arguments.length&&arguments[3]!==void 0?arguments[3]:null;return{$$typeof:ee,key:n==null?null:""+n,children:r,containerInfo:e,implementation:t}}s(re,"createPortal$1");var O=Q.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;function M(r,e){if(r==="font")return"";if(typeof e=="string")return e==="use-credentials"?e:""}s(M,"getCrossOriginStringAs");l.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE=c;l.createPortal=function(r,e){var t=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11)throw Error(V(299));return re(r,e,null,t)};l.flushSync=function(r){var e=O.T,t=c.p;try{if(O.T=null,c.p=2,r)return r()}finally{O.T=e,c.p=t,c.d.f()}};l.preconnect=function(r,e){typeof r=="string"&&(e?(e=e.crossOrigin,e=typeof e=="string"?e==="use-credentials"?e:"":void 0):e=null,c.d.C(r,e))};l.prefetchDNS=function(r){typeof r=="string"&&c.d.D(r)};l.preinit=function(r,e){if(typeof r=="string"&&e&&typeof e.as=="string"){var t=e.as,n=M(t,e.crossOrigin),o=typeof e.integrity=="string"?e.integrity:void 0,i=typeof e.fetchPriority=="string"?e.fetchPriority:void 0;t==="style"?c.d.S(r,typeof e.precedence=="string"?e.precedence:void 0,{crossOrigin:n,integrity:o,fetchPriority:i}):t==="script"&&c.d.X(r,{crossOrigin:n,integrity:o,fetchPriority:i,nonce:typeof e.nonce=="string"?e.nonce:void 0})}};l.preinitModule=function(r,e){if(typeof r=="string")if(typeof e=="object"&&e!==null){if(e.as==null||e.as==="script"){var t=M(e.as,e.crossOrigin);c.d.M(r,{crossOrigin:t,integrity:typeof e.integrity=="string"?e.integrity:void 0,nonce:typeof e.nonce=="string"?e.nonce:void 0})}}else e==null&&c.d.M(r)};l.preload=function(r,e){if(typeof r=="string"&&typeof e=="object"&&e!==null&&typeof e.as=="string"){var t=e.as,n=M(t,e.crossOrigin);c.d.L(r,t,{crossOrigin:n,integrity:typeof e.integrity=="string"?e.integrity:void 0,nonce:typeof e.nonce=="string"?e.nonce:void 0,type:typeof e.type=="string"?e.type:void 0,fetchPriority:typeof e.fetchPriority=="string"?e.fetchPriority:void 0,referrerPolicy:typeof e.referrerPolicy=="string"?e.referrerPolicy:void 0,imageSrcSet:typeof e.imageSrcSet=="string"?e.imageSrcSet:void 0,imageSizes:typeof e.imageSizes=="string"?e.imageSizes:void 0,media:typeof e.media=="string"?e.media:void 0})}};l.preloadModule=function(r,e){if(typeof r=="string")if(e){var t=M(e.as,e.crossOrigin);c.d.m(r,{as:typeof e.as=="string"&&e.as!=="script"?e.as:void 0,crossOrigin:t,integrity:typeof e.integrity=="string"?e.integrity:void 0})}else c.d.m(r)};l.requestFormReset=function(r){c.d.r(r)};l.unstable_batchedUpdates=function(r,e){return r(e)};l.useFormState=function(r,e,t){return O.H.useFormState(r,e,t)};l.useFormStatus=function(){return O.H.useHostTransitionStatus()};l.version="19.2.0"});var W=D((de,B)=>{"use strict";function U(){if(!(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__>"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(U)}catch(r){console.error(r)}}s(U,"checkDCE");U(),B.exports=j()});var z=N(C(),1),f=N(P(),1),a=N(P(),1);var E=N(C(),1),Z=N(W(),1),v=N(P(),1);var te=Array.from({length:56},(r,e)=>{let t=e/56*2*Math.PI-Math.PI/2,n=Math.cos(t),o=Math.sin(t);return{id:`tick-${e}`,frac:e/55,x1:150+108*n,y1:150+108*o,x2:150+138*n,y2:150+138*o,style:{transitionDelay:`${e*6}ms`}}});function F(r,e,t,n){return t?"var(--sekyro-color-success)":r?n?"color-mix(in srgb, var(--sekyro-color-warning) 75%, transparent)":e<.33?"color-mix(in srgb, var(--sekyro-color-brand) 55%, transparent)":e<.66?"color-mix(in srgb, var(--sekyro-color-brand) 80%, transparent)":"var(--sekyro-color-brand)":"color-mix(in srgb, var(--sekyro-color-surface) 32%, transparent)"}s(F,"T");u(F,"tickColor");var ae="M0 -50 H300 V350 H0 Z M50 150 a100,100 0 1 0 200,0 a100,100 0 1 0 -200,0 Z";function G({progress:r,phase:e,draining:t=!1}){let n=Math.min(1,Math.max(0,r)),o=Math.round(n*56),i=e==="checking",y=e==="recording",d=e==="frozen",m=i||d,p=i||y||d,k=e==="locked"||p,S=t&&!k;return(0,f.jsxs)("svg",{"aria-hidden":"true",viewBox:"0 0 300 300",preserveAspectRatio:"xMidYMid meet",className:"sekyro-stage__arc","data-testid":"sekyro-capture-arc","data-phase":e,"data-filled":o,"data-recording":y?"":void 0,"data-draining":S?"":void 0,children:[(0,f.jsx)("path",{fillRule:"evenodd",d:ae,fill:"color-mix(in srgb, var(--sekyro-color-fg) var(--sekyro-scrim, 96%), transparent)",style:{"--sekyro-scrim":m?"100%":"96%"},className:"sekyro-arc__scrim sekyro-capture-fade-in","data-testid":"sekyro-capture-scrim"}),(0,f.jsxs)("g",{className:e==="locked"?"sekyro-capture-settle":void 0,children:[(0,f.jsx)("g",{className:m?"sekyro-arc__ring sekyro-arc__ring--dim":"sekyro-arc__ring",children:te.map((g,x)=>(0,f.jsx)("line",{x1:g.x1,y1:g.y1,x2:g.x2,y2:g.y2,stroke:F(x<o,g.frac,k,S),strokeWidth:3,strokeLinecap:"round",style:g.style,className:"sekyro-arc__tick"},g.id))}),(0,f.jsx)("g",{className:e==="seeking"?"sekyro-capture-breathe":void 0,children:(0,f.jsx)("circle",{cx:150,cy:150,r:100,fill:"none",stroke:k?"var(--sekyro-color-success)":"var(--sekyro-color-surface)",strokeWidth:k?3.5:2.5,className:p?"sekyro-arc__guide sekyro-arc__guide--spin sekyro-capture-ring-spin":"sekyro-arc__guide sekyro-capture-fade-in","data-testid":"sekyro-capture-guide"})})]})]})}s(G,"x");u(G,"CaptureArc");function ne({videoRef:r,guidanceText:e,guidanceHint:t,guidanceKey:n,progress:o,phase:i,draining:y=!1,stillUrl:d,showChecking:m,operatorText:p=null,voicePrompt:k,overlay:S,reduceMotion:g=!1,modeSwitch:x=null}){let b=I(),w=i==="checking",_=w||i==="frozen",A=_&&m?b("capture.checking"):e,L=k?.(t,A,n);return(0,a.jsxs)("div",{className:g?"sekyro-stage sekyro-capture-reduce":"sekyro-stage","data-testid":"sekyro-capture-stage",children:[(0,a.jsx)("video",{ref:r,playsInline:!0,muted:!0,className:"sekyro-stage__video","data-testid":"sekyro-capture-video"}),d!==null&&_?(0,a.jsx)("img",{src:d,alt:b("capture.previewAlt"),className:"sekyro-stage__still sekyro-capture-develop","data-testid":"sekyro-capture-still"}):null,(0,a.jsx)(G,{progress:o,phase:i,draining:y}),S?.(r),L!=null&&!_?(0,a.jsx)("div",{className:"sekyro-stage__corner-start","data-testid":"sekyro-voice-slot",children:L}):null,x!==null&&!_?(0,a.jsx)($,{view:x,className:"sekyro-stage__corner-end sekyro-stage__mode-switch",kind:"chip"}):null,w&&m?(0,a.jsxs)("span",{className:"sekyro-stage__corner-end sekyro-stage__pill sekyro-capture-pill-in","data-testid":"sekyro-camera-off-pill",children:[(0,a.jsx)(Y,{}),b("capture.cameraOff")]}):null,(0,a.jsxs)("p",{"aria-live":"polite",className:"sekyro-stage__guidance","data-testid":"sekyro-capture-guidance",children:[(0,a.jsx)("span",{className:"sekyro-stage__guidance-text sekyro-capture-text-in",children:A},A),_&&m?(0,a.jsx)("span",{className:"sekyro-stage__guidance-hint",children:b("capture.checkingHint")}):p!==null&&!_?(0,a.jsx)("span",{className:"sekyro-stage__guidance-hint","data-testid":"sekyro-operator-line",children:p}):null]})]})}s(ne,"ne");u(ne,"CaptureStage");function $({view:r,className:e,kind:t}){let n=(0,z.useId)(),o=(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(K,{}),(0,a.jsx)("span",{children:r.label})]}),i={onClick:r.onSwitch,"aria-describedby":n,"data-testid":"sekyro-capture-mode-switch","data-mode":r.to};return(0,a.jsxs)(a.Fragment,{children:[t==="chip"?(0,a.jsx)(H,{kind:"chip",className:e,...i,children:o}):(0,a.jsx)("button",{type:"button",className:e,...i,children:o}),(0,a.jsx)("span",{id:n,className:"sekyro-visually-hidden",children:r.description})]})}s($,"H");u($,"ModeSwitchChip");function K(){return(0,a.jsxs)("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",className:"sekyro-icon",children:[(0,a.jsx)("path",{d:"M4 7.5h2.2l1.4-1.9h8.8l1.4 1.9H20a1.6 1.6 0 0 1 1.6 1.6v8.3A1.6 1.6 0 0 1 20 19H4a1.6 1.6 0 0 1-1.6-1.6V9.1A1.6 1.6 0 0 1 4 7.5Z"}),(0,a.jsx)("path",{d:"M15.4 11.9a3.5 3.5 0 0 0-6.1-1.4M15.4 11.9h-2.1m2.1 0V9.8"}),(0,a.jsx)("path",{d:"M8.6 13.4a3.5 3.5 0 0 0 6.1 1.4M8.6 13.4h2.1m-2.1 0v2.1"})]})}s(K,"D");u(K,"FlipCameraIcon");function Y(){return(0,a.jsxs)("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",className:"sekyro-icon sekyro-icon--sm",children:[(0,a.jsx)("path",{d:"M4 7.5h2.2l1.4-1.9h8.8l1.4 1.9H20a1.6 1.6 0 0 1 1.6 1.6v8.3A1.6 1.6 0 0 1 20 19H4a1.6 1.6 0 0 1-1.6-1.6V9.1A1.6 1.6 0 0 1 4 7.5Z"}),(0,a.jsx)("path",{d:"M3 3l18 18"})]})}s(Y,"G");u(Y,"CameraOffIcon");var ie=typeof window>"u"?E.useEffect:E.useLayoutEffect,R="data-sekyro-ramp",se=[["background-color","transparent"],["background-image","none"]];function q(r){let e=[],t=r.ownerDocument;for(let i=r;i!==null&&i!==t.documentElement;i=i.parentElement){if(!(i instanceof HTMLElement)&&!(i instanceof SVGElement))continue;let y=i.style;for(let[d,m]of se){let p=y.getPropertyValue(d),k=y.getPropertyPriority(d);y.setProperty(d,m,"important"),e.push(()=>{p===""?y.removeProperty(d):y.setProperty(d,p,k)})}}let n=t.documentElement,o=n.hasAttribute(R);return n.setAttribute(R,""),o||e.push(()=>n.removeAttribute(R)),()=>{for(let i of e.reverse())i()}}s(q,"z");u(q,"clearAncestorBackdrops");function X(r){return{position:"fixed",inset:0,minWidth:"100vw",minHeight:"100lvh",margin:0,padding:0,border:0,zIndex:-1,pointerEvents:"none",backgroundColor:T(r)}}s(X,"B");u(X,"washStyle");function J(r){return{position:"absolute",inset:0,pointerEvents:"none",backgroundColor:T(r)}}s(J,"Y");u(J,"coverStyle");function oe({colour:r}){let e=(0,E.useRef)(null),t=r!==null;return ie(()=>{let n=e.current?.parentElement;if(!(!t||n===null||n===void 0))return q(n)},[t]),r===null||typeof document>"u"?null:(0,v.jsxs)(v.Fragment,{children:[(0,v.jsx)("div",{ref:e,"aria-hidden":"true","data-testid":"sekyro-screen-ramp-cover","data-colour":r,style:J(r)}),(0,Z.createPortal)((0,v.jsx)("div",{"aria-hidden":"true","data-testid":"sekyro-screen-ramp","data-colour":r,style:X(r)}),document.body)]})}s(oe,"de");u(oe,"ScreenRampLayer");export{W as a,ne as b,$ as c,oe as d};
2
2
  /*! Bundled license information:
3
3
 
4
4
  react-dom/cjs/react-dom.production.js:
@@ -1 +1 @@
1
- import{b,c as t,v as s,w as i,y as l}from"./chunk-SOI356LX.js";import{a as r}from"./chunk-5QL6W6FW.js";import{a as o,c as k}from"./chunk-4FHWXBOB.js";var a=k(b(),1);function x({title:n,lead:d,cameraLabel:c,uploadLabel:m,notice:p,testId:e,onCamera:h,onUpload:u,onPhone:f=!1}){return(0,a.jsxs)("section",{className:"sekyro-step","data-testid":e,children:[(0,a.jsx)(i,{title:n,lead:d}),p,(0,a.jsxs)(l,{children:[(0,a.jsxs)(t,{full:!0,onClick:h,"data-testid":`${e}-camera`,children:[(0,a.jsx)(s,{name:f?"smartphone":"camera"}),c]}),(0,a.jsx)(t,{full:!0,kind:"ghost",onClick:u,"data-testid":`${e}-upload`,children:m})]})]})}o(x,"k");r(x,"PhotoSourceView");export{x as a};
1
+ import{b,c as t,v as s,w as i,y as l}from"./chunk-JJ3Q52P3.js";import{a as r}from"./chunk-5QL6W6FW.js";import{a as o,c as k}from"./chunk-4FHWXBOB.js";var a=k(b(),1);function x({title:n,lead:d,cameraLabel:c,uploadLabel:m,notice:p,testId:e,onCamera:h,onUpload:u,onPhone:f=!1}){return(0,a.jsxs)("section",{className:"sekyro-step","data-testid":e,children:[(0,a.jsx)(i,{title:n,lead:d}),p,(0,a.jsxs)(l,{children:[(0,a.jsxs)(t,{full:!0,onClick:h,"data-testid":`${e}-camera`,children:[(0,a.jsx)(s,{name:f?"smartphone":"camera"}),c]}),(0,a.jsx)(t,{full:!0,kind:"ghost",onClick:u,"data-testid":`${e}-upload`,children:m})]})]})}o(x,"k");r(x,"PhotoSourceView");export{x as a};
@@ -1 +1 @@
1
- import{D as n,E as a,a as i}from"./chunk-QXWWOMOK.js";import{a as t}from"./chunk-5QL6W6FW.js";import{a as o}from"./chunk-4FHWXBOB.js";function d(r,p){if(r instanceof n)return r.field==="phone"?"otp.phoneInvalid":r.field==="code"?"otp.codeInvalid":r.kind==="check_digit"?"population.reason_id_number_invalid":"population.invalid";if(r instanceof a&&r.field==="channel")return"otp.reason_otp_channel_unavailable";if(r instanceof i){let e=`errors.${r.code}`;if(Object.hasOwn(p,e))return e}return"errors.network_error"}o(d,"d");t(d,"errorKey");export{d as a};
1
+ import{D as n,E as a,a as i}from"./chunk-YLH3WX7Y.js";import{a as t}from"./chunk-5QL6W6FW.js";import{a as o}from"./chunk-4FHWXBOB.js";function d(r,p){if(r instanceof n)return r.field==="phone"?"otp.phoneInvalid":r.field==="code"?"otp.codeInvalid":r.kind==="check_digit"?"population.reason_id_number_invalid":"population.invalid";if(r instanceof a&&r.field==="channel")return"otp.reason_otp_channel_unavailable";if(r instanceof i){let e=`errors.${r.code}`;if(Object.hasOwn(p,e))return e}return"errors.network_error"}o(d,"d");t(d,"errorKey");export{d as a};
@@ -1 +1 @@
1
- import{a as tt,b as $t,c as te,d as dt,e as ee}from"./chunk-JI5WT66H.js";import{a as Ut,b as Kt,e as Yt}from"./chunk-2FETDQV5.js";import{b as Vt,c as Zt}from"./chunk-XSGZY4JI.js";import{b as Jt}from"./chunk-L22GFJQV.js";import{d as Wt,e as Ht,f as Qt}from"./chunk-TXDGBMD4.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-S4PB2RNW-3KSM3MW5.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-S4PB2RNW-3KSM3MW5.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-JI5WT66H.js";import{a as Ut,b as Kt,e as Yt}from"./chunk-2FETDQV5.js";import{b as Vt,c as Zt}from"./chunk-XSGZY4JI.js";import{b as Jt}from"./chunk-L22GFJQV.js";import{d as Wt,e as Ht,f as Qt}from"./chunk-4YBL75VD.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-S4PB2RNW-3KSM3MW5.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-S4PB2RNW-3KSM3MW5.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{d as xe,e as He,f as Ke,g as Xe}from"./chunk-TXDGBMD4.js";import{a as ne,b as Ze,c as oe,d as Ve}from"./chunk-P7K7ELYZ.js";import{a as Se,b as Y,c as Ie,d as Ae,e as De,h as Re,i as se,j as Ce,k as Oe,l as We,m as ze}from"./chunk-6MYG4HWP.js";import{a as Ge,b as Pe,c as Ue,d as Fe,e as Ne,f as ae,g as j,h as Be,i as Le,j as qe}from"./chunk-JS2IXPNL.js";import{a as n}from"./chunk-4FHWXBOB.js";var wt=1e4,C,bt=(C=class{constructor(e,t){this.tier="blaze",this.inner=e,t!==void 0&&(this.fallbackReason=t)}static async create(e,t){let r=await import("./vision_bundle-WBHR7TEE.js"),s=await r.FilesetResolver.forVisionTasks(e),a=await r.FaceDetector.createFromOptions(s,{baseOptions:{modelAssetPath:`${e}/blaze_face_short_range.tflite`,delegate:"CPU"},runningMode:"IMAGE"});return new C(a,t)}async detect(e,t,r){let s;try{s=this.inner.detect(e).detections}catch{return null}let a=Mt(s);if(a?.boundingBox===void 0)return null;let o=Q(e),l=kt(a.keypoints,o),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*o.width,y:c.y*o.height}}:{},score:a.categories[0]?.score??0,extraFaces:je(s.map(d=>d.boundingBox??{width:0,height:0}),s.indexOf(a))};return $e(h,e,t,r)}destroy(){try{this.inner.close()}catch{}}},n(C,"t"),C);function Mt(i){let e,t=-1;for(let r of i){let s=r.categories[0]?.score??0;s>t&&(e=r,t=s)}return e}n(Mt,"R");function kt(i,e){let t=i?.[0],r=i?.[1];if(t===void 0||r===void 0)return;let s=n(l=>({x:l.x*e.width,y:l.y*e.height}),"n"),[a,o]=[s(t),s(r)];return a.x<=o.x?{left:a,right:o}:{left:o,right:a}}n(kt,"T");function Tt(){if(typeof OffscreenCanvas=="function")return new OffscreenCanvas(2,2);let i=document.createElement("canvas");return i.width=2,i.height=2,i}n(Tt,"E");var _t=4;async function Et(){let i=globalThis.FaceDetector;if(typeof i!="function")return{ok:!1,reason:"unsupported"};try{let e=new i({fastMode:!0,maxDetectedFaces:_t});return await e.detect(Tt()),{ok:!0,instance:e}}catch(e){return{ok:!1,reason:`smoke_failed:${e instanceof Error?e.message:String(e)}`}}}n(Et,"w");var P,St=(P=class{constructor(e,t){this.tier="native",this.inner=e,t!==void 0&&(this.fallbackReason=t)}async detect(e,t,r){let s;try{s=await this.inner.detect(e)}catch{return null}let a=s.map(d=>d.boundingBox),o=-1;a.forEach((d,u)=>{let v=a[o];(v===void 0||d.width*d.height>v.width*v.height)&&(o=u)});let l=s[o];if(l===void 0)return null;let c=It(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:je(a,o)};return $e(h,e,t,r)}destroy(){}},n(P,"b"),P);function It(i){if(i===void 0)return;let e=i.filter(s=>s.type==="eye").map(s=>s.locations[0]).filter(s=>s!==void 0),[t,r]=e;if(!(t===void 0||r===void 0))return t.x<=r.x?{left:t,right:r}:{left:r,right:t}}n(It,"S");var At=.25;function je(i,e){let t=i[e],r=t===void 0?0:t.width*t.height;if(!(r>0))return 0;let s=0;return i.forEach((a,o)=>{o!==e&&a.width*a.height>=At*r&&(s+=1)}),s}n(je,"f");var ce="/models-v3",xt=["native","blaze"],U,he=(U=class extends Error{constructor(e){super(`no detector tier available (${e})`),this.name="DetectorLadderError",this.fallbackReason=e}},n(U,"x"),U);function Q(i){let e=i;if(typeof e.videoWidth=="number"&&e.videoWidth>0)return{width:e.videoWidth,height:e.videoHeight??0};if(typeof e.naturalWidth=="number"&&e.naturalWidth>0)return{width:e.naturalWidth,height:e.naturalHeight??0};let t=typeof e.width=="number"?e.width:0,r=typeof e.height=="number"?e.height:0;return{width:t,height:r}}n(Q,"y");function $e(i,e,t,r){let s=Q(e),a=s.width>0?t/s.width:1,o=s.height>0?r/s.height:1,l=n(c=>({x:c.x*a,y:c.y*o}),"s");return{box:{x:i.box.x*a,y:i.box.y*o,width:i.box.width*a,height:i.box.height*o},...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}:{}}}n($e,"h");function Dt(i){return i instanceof Error?i.message:String(i)}n(Dt,"C");async function x(i){let e=i.preferred??xt,t=[];for(let r of e){if(r==="native"){let s=await Et();if(s.ok)return new St(s.instance,le(t));t.push(`native:${s.reason}`);continue}try{return await Rt(bt.create(i.v3AssetBaseUrl??ce,le(t)),i.blazeInitTimeoutMs??wt)}catch(s){t.push(s instanceof Ye?"blaze:blaze_init_timeout":`blaze:${Dt(s)}`)}}throw new he(le(t)??"no_tier_available")}n(x,"O");function le(i){return i.length>0?i.join("; "):void 0}n(le,"v");var F,Ye=(F=class extends Error{},n(F,"g"),F);function Rt(i,e){return new Promise((t,r)=>{let s=setTimeout(()=>{r(new Ye(`init exceeded ${e}ms`)),i.then(a=>a.destroy(),()=>{})},e);i.then(a=>{clearTimeout(s),t(a)},a=>{clearTimeout(s),r(a)})})}n(Rt,"W");var R=1;function Qe(){return typeof OffscreenCanvas=="function"&&typeof createImageBitmap=="function"&&typeof Worker=="function"}n(Qe,"K");function Ct(i,e={}){let t=e.createDetector??x,r=null;i.onmessage=s=>{let a=s.data;if(a.v!==R){a.bitmap?.close?.();return}if(a.type==="init"){t(a.options).then(o=>{r=o;let l={v:R,type:"ready",tier:o.tier,...o.fallbackReason!==void 0?{fallbackReason:o.fallbackReason}:{}};i.postMessage(l)});return}if(a.type==="detect"){let o=n(l=>{let c={v:R,type:"result",id:a.id,observation:l};i.postMessage(c),a.bitmap.close?.()},"a");if(r===null){o(null);return}r.detect(a.bitmap,a.streamWidth,a.streamHeight).then(o,()=>o(null))}}}n(Ct,"B");typeof self<"u"&&typeof self.importScripts=="function"&&Ct(self);var O,Je=(O=class{constructor(e,t){this.pending=new Map,this.nextId=1,this.worker=e,this.tier=t.tier,t.fallbackReason!==void 0&&(this.fallbackReason=t.fallbackReason),e.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(e,t,r=1e4){return new Promise((s,a)=>{let o=setTimeout(()=>{e.removeEventListener("message",l),e.terminate(),a(new Error(`worker detector not ready within ${r}ms`))},r),l=n(h=>{let d=h.data;d.v!==R||d.type!=="ready"||(clearTimeout(o),e.removeEventListener("message",l),s(new O(e,d)))},"s");e.addEventListener("message",l);let c={v:R,type:"init",options:t};e.postMessage(c)})}async detect(e,t,r){let s;try{typeof ImageBitmap<"u"&&e instanceof ImageBitmap?s=e:typeof createImageBitmap=="function"?s=await createImageBitmap(e):s=e}catch{return null}let a=this.nextId;return this.nextId+=1,new Promise(o=>{this.pending.set(a,o);let l={v:R,type:"detect",id:a,bitmap:s,streamWidth:t,streamHeight:r};this.worker.postMessage(l,[s])})}destroy(){for(let e of this.pending.values())e(null);this.pending.clear(),this.worker.terminate()}},n(O,"t"),O);var Ot=[...Ge.filter(i=>i.startsWith("video/mp4")),"video/webm;codecs=h264","video/webm;codecs=avc1","video/webm;codecs=vp8","video/webm;codecs=vp9","video/webm"],lt=new Set;function Gt(i){let e=/(?:Chrome|Chromium)\/(\d+)\./.exec(i??"");return e?Number(e[1]):null}n(Gt,"De");function Pt(i=Ft(),e=globalThis.navigator?.userAgent){if(i===void 0)return"";let t=Gt(e)===126;for(let r of Ot)if(!(lt.has(r)||t&&r.startsWith("video/mp4")))try{if(i(r))return r}catch{}return""}n(Pt,"fe");function et(i){i!==""&&lt.add(i)}n(et,"V");function Ut(i){return i.replace(/^video\/x-matroska/i,"video/webm")}n(Ut,"ge");function ct(i){let e=/codecs=["']?([^,;"']+)/i.exec(i);return e?e[1].trim():i.split(";")[0].trim()}n(ct,"ut");function Ft(){let i=globalThis.MediaRecorder;return i&&typeof i.isTypeSupported=="function"?e=>i.isTypeSupported(e):void 0}n(Ft,"Oe");var ht=2500,Nt=1e3,Bt=1500,tt=25e5,Lt=100,qt=700,Wt=20,zt=1500,J=null;function Ht(){return J??(J=import("./clip-inspect-DLJXVKV6-TNHTD4LV.js").catch(i=>{throw J=null,i})),J.catch(()=>null)}n(Ht,"Ne");var B,D=(B=class extends Error{constructor(e,t){super(t??e),this.kind=e}},n(B,"S"),B),Kt=100;function it(i,e){return i.stats===void 0?!1:i.stats===null?!0:i.stats.durationMs<e-Kt}n(it,"H");function Xt(i,e){return i.stats?e.stats?i.stats.durationMs>e.stats.durationMs:!0:!1}n(Xt,"be");var L,Zt=(L=class{constructor(e={}){this.recorder=null,this.stream=null,this.chunks=[],this.bytes=0,this.hardStopTimer=null,this.graceTimer=null,this.pollTimer=null,this.settled=!1,this.now=e.now??(()=>globalThis.performance?.now?.()??Date.now())}clearTimers(){this.hardStopTimer&&clearTimeout(this.hardStopTimer),this.graceTimer&&clearTimeout(this.graceTimer),this.pollTimer&&clearInterval(this.pollTimer),this.hardStopTimer=null,this.graceTimer=null,this.pollTimer=null}record(e,t,r,s=ht,a){let o=Pt(),l=Ht();return this.recordRaw(e,t,r,s,a,o).then(c=>Vt(c,l),c=>{throw c instanceof D&&(c.requestedMimeType=o),c})}recordRaw(e,t,r,s,a,o){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=e,new Promise((l,c)=>{let h;try{h=new MediaRecorder(e,o?{mimeType:o,videoBitsPerSecond:tt}:{videoBitsPerSecond:tt})}catch{try{h=new MediaRecorder(e)}catch{c(new D("unsupported"));return}}this.recorder=h;let d=n(p=>{this.settled||(this.settled=!0,this.clearTimers(),p())},"d"),u=n(()=>d(()=>{let p=Ut(h.mimeType||o||Pe),M=new Blob(this.chunks,{type:p});if(M.size===0){c(new D("generic","empty clip"));return}if(ae(M)){c(new D("cliptoolarge"));return}l({blob:M,mimeType:p,requestedMimeType:o})}),"u");h.ondataavailable=p=>{p.data&&p.data.size&&(this.chunks.push(p.data),this.bytes+=p.data.size,this.bytes>Ne&&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(Nt)}catch{d(()=>c(new D("generic")));return}let w=n(()=>{if(this.pollTimer&&clearInterval(this.pollTimer),this.pollTimer=null,this.hardStopTimer&&clearTimeout(this.hardStopTimer),this.hardStopTimer=null,this.settled||t?.(),h.state!=="inactive"){try{h.stop()}catch{u()}this.graceTimer=setTimeout(u,Bt)}else u()},"g"),m=this.now();if(a===void 0){this.hardStopTimer=setTimeout(w,s);return}let g=null,y=!1;this.hardStopTimer=setTimeout(w,s+qt),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 E=g!==null&&M!==void 0&&M-g>=s,I=g===null&&this.now()-m>=s;if(!(!E&&!I)){if(y=!0,this.pollTimer&&clearInterval(this.pollTimer),this.pollTimer=null,I){w();return}this.hardStopTimer&&clearTimeout(this.hardStopTimer),this.hardStopTimer=setTimeout(w,Lt)}},Wt)}))}stop(e){this.clearTimers();let t=this.recorder;if(t&&t.state!=="inactive")try{t.stop()}catch{}this.recorder=null,(e??this.stream)?.getTracks().forEach(r=>r.stop()),this.stream=null}},n(L,"I"),L);async function Vt(i,e){let t,r=new Promise(h=>{t=setTimeout(()=>h(null),zt)}),s=await Promise.race([e,r]);if(clearTimeout(t),s===null)return i;let a;try{a=await s.blobBytes(i.blob)}catch{return{...i,stats:null}}let o=s.inspectClipBytes(a);if(o?.container!=="webm")return{...i,stats:o};let l=s.withWebmDuration(a,o.durationMs);if(l===null)return{...i,stats:o};let c=s.inspectClipBytes(l);return c===null||c.frames!==o.frames||c.durationMs!==o.durationMs?{...i,stats:o}:{...i,blob:new Blob([l],{type:i.blob.type}),stats:o}}n(Vt,"He");var jt=["magenta","yellow","green","blue"],$t={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 $i(i){return $t[i]}n($i,"ft");var Yt=4,Qt=4,ee=n(i=>typeof i=="number"&&Number.isFinite(i),"D");function pe(i){if(typeof i!="object"||i===null)return!1;let e=i;if(typeof e.nonce!="string"||e.nonce.length===0||!Array.isArray(e.colours)||e.colours.length<1||e.colours.length>8||!e.colours.every(r=>jt.includes(r))||!Array.isArray(e.onsetsMs)||e.onsetsMs.length!==e.colours.length)return!1;let t=-1;for(let r of e.onsetsMs){if(!ee(r)||r<0||r<=t)return!1;t=r}return!(!ee(e.holdMs)||e.holdMs<=0||!ee(e.endMs)||e.endMs<=t||!ee(e.clipMs)||e.clipMs<e.endMs||e.clipMs>8e3)}n(pe,"O");function Jt(i,e){return pe(i)?Math.max(e,Math.ceil(i.clipMs)):e}n(Jt,"ye");function ei(i,e){let t=e.now??(()=>performance.now()),r=pe(i)?i:void 0,s=[],a=null,o=null,l=null,c=!1,h=null,d=n(m=>{h=m;try{e.paint(m)}catch{}},"d"),u=n(m=>{let g=e.frames?.()??null;return g!==null&&l!==null?g.mediaTimeMs+(m-g.presentationTimeMs)-l:m-(o??m)},"u"),v=n((m,g,y=0)=>{if(c)return;let p=Math.max(0,m-u(t()));a=setTimeout(()=>{if(a=null,!c){if(y<Yt&&u(t())<m-Qt){v(m,g,y+1);return}g()}},p)},"f"),w=n(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(t());if(M>g){h!==null&&d(null);return}let E=r.colours[m];d(E);let I=s.length===0?0:s[s.length-1].tMs;s.push({tMs:Math.max(I,Math.round(M)),colour:E});let T=y+r.holdMs;if(T<p){v(T,()=>{if(u(t())>g){h!==null&&d(null);return}d("dark"),w(m+1)});return}w(m+1)})},"g");return{started(m){if(r===void 0||c||o!==null)return;o=m;let g=e.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]}}}}n(ei,"Me");function ti(i,e,t=.92){return new Promise((r,s)=>{let a=i.videoWidth,o=i.videoHeight;if(!a||!o){s(new Error("video-not-ready"));return}let l=e.getContext("2d");if(!l){s(new Error("no-2d-context"));return}e.width=a,e.height=o,l.scale(-1,1),l.drawImage(i,-a,0),e.toBlob(c=>c?r(c):s(new Error("empty-keyframe")),"image/jpeg",t)})}n(ti,"Se");var q,ii=(q=class{constructor(e){this.timer=null,this.frameCallbackId=null,this.running=!1,this.busy=!1,this.lastRunAt=Number.NEGATIVE_INFINITY,this.degradeCount=0,this.durations=[],this.options=e,this.periodMs=1e3/e.cadenceHz}start(){if(this.running)return;this.running=!0;let e=this.options.video;if(typeof e?.requestVideoFrameCallback=="function"){let t=n(()=>{this.running&&(this.frameCallbackId=e.requestVideoFrameCallback?.(()=>{this.frameCallbackId=null,this.now()-this.lastRunAt>=this.periodMs&&this.tick(),t()}))},"t");t();return}this.timer=setInterval(()=>this.tick(),this.periodMs)}stop(){this.running=!1,this.timer!==null&&(clearInterval(this.timer),this.timer=null),this.frameCallbackId!==null&&(this.options.video?.cancelVideoFrameCallback?.(this.frameCallbackId),this.frameCallbackId=null)}stats(){let e=this.durations.length===0?0:this.durations.reduce((t,r)=>t+r,0)/this.durations.length;return{degradeCount:this.degradeCount,meanDetectMs:e}}now(){return this.options.now?.()??performance.now()}tick(){if(!this.running)return;if(this.busy){this.degradeCount+=1;return}this.busy=!0,this.lastRunAt=this.now();let e=this.now();this.options.run().catch(()=>{}).finally(()=>{this.busy=!1,this.durations.push(this.now()-e),this.durations.length>20&&this.durations.shift()})}},n(q,"P"),q),ri=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}),N=n(i=>Math.min(1,Math.max(0,i)),"_"),W,rt=(W=class{constructor(e={}){this.p=0,this.lastTickAt=null,this.lastCenter=null,this.velocityEma=0,this.qWindow=[],this.lastSizeDirection="ideal",this.t={...ri,...e}}reset(){this.p=0,this.lastTickAt=null,this.lastCenter=null,this.velocityEma=0,this.qWindow=[],this.lastSizeDirection="ideal"}tick(e){let{observation:t,quality:r,timestampMs:s}=e,a=this.lastTickAt===null?0:Math.max(0,(s-this.lastTickAt)/1e3);this.lastTickAt=s;let o={presence:0,single:1,centering:0,size:0,pose:0,sharpness:N(r.sharpness),exposure:N(r.exposure),motion:1};if(t!==null){o.presence=1,o.single=(t.extraFaces??0)>0?0:1;let d=this.geometryOf(t,e);o.centering=d.centering,o.size=d.size,o.pose=d.pose,o.motion=this.motionOf(d.center,d.iod,s)}else this.lastCenter=null,this.velocityEma=0;let l=Math.min(o.presence,o.single,o.centering,o.size,o.pose,o.sharpness,o.exposure,o.motion);this.p=N(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:o,guidanceKey:this.guidanceOf(o,r,l),ready:h,accepted:l>=this.t.Q_GOOD}}geometryOf(e,t){let{box:r,eyes:s}=e,a={x:t.frameWidth/2,y:t.frameHeight/2},o=Math.min(t.frameWidth,t.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-N(h/(this.t.CENTER_FALLOFF_IOD_MULTIPLE*c)),u=o>0?c/o: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-N(m/this.t.ROLL_MAX_DEG)}return{center:l,iod:c,centering:d,size:v,pose:w}}motionOf(e,t,r){let s=this.lastCenter;if(this.lastCenter={...e,at:r},s===null||t<=0)return 1;let a=(r-s.at)/1e3;if(a<=0)return 1;let o=Math.hypot(e.x-s.x,e.y-s.y)/t/a;o<=this.t.MOTION_DEADBAND_IOD_PER_S&&(o=0);let l=1-Math.exp(-a/this.t.MOTION_TAU_S);return this.velocityEma=l*o+(1-l)*this.velocityEma,1-N(this.velocityEma/this.t.MOTION_VELOCITY_IOD_PER_S)}guidanceOf(e,t,r){if(e.presence<=0)return"fcv3.no_face";if(e.single<=0)return"fcv3.one_face";if(e.size<this.t.GUIDE_SIZE)return this.sizeGuidance();if(e.centering<this.t.GUIDE_CENTERING)return"fcv3.center_face";if(e.pose<this.t.GUIDE_POSE)return"fcv3.straighten";if(e.exposure<this.t.GUIDE_EXPOSURE)return this.exposureGuidance(t);if(e.sharpness<this.t.GUIDE_SHARPNESS)return"fcv3.steady_camera";if(e.motion<this.t.GUIDE_MOTION)return"fcv3.hold_still";if(r<this.t.Q_GOOD){let s=[["size",this.sizeGuidance()],["centering","fcv3.center_face"],["pose","fcv3.straighten"],["exposure",this.exposureGuidance(t)],["sharpness","fcv3.steady_camera"],["motion","fcv3.hold_still"]],a=s[0];for(let o of s)e[o[0]]<e[a[0]]&&(a=o);return a[1]}return"fcv3.hold_still"}sizeGuidance(){return this.lastSizeDirection==="far"?"fcv3.come_closer":"fcv3.move_back"}exposureGuidance(e){let t=(ne[0]+ne[1])/2;return e.meanLuma<t?"fcv3.more_light":"fcv3.too_bright"}},n(W,"k"),W),si=["single","size","centering","pose","exposure","sharpness","motion"];function ai(i){if(i.accepted)return null;if(i.factors.presence<=0)return"no_face";let e="single";for(let t of si)i.factors[t]<i.factors[e]&&(e=t);return e}n(ai,"Ze");var z,st=(z=class{constructor(){this.blocked={},this.acceptedMs=0,this.ticks=0,this.lastAt=null}record(e){let t=this.lastAt===null?0:Math.max(0,e.at-this.lastAt);this.lastAt=e.at,this.ticks+=1;let r=ai(e);if(r===null){this.acceptedMs+=t;return}let s=this.blocked[r]??{count:0,ms:0};s.count+=1,s.ms+=t,this.blocked[r]=s}summary(){let e={};for(let[t,r]of Object.entries(this.blocked))e[t]={count:r.count,ms:Math.round(r.ms)};return{blocked:e,acceptedMs:Math.round(this.acceptedMs),ticks:this.ticks}}},n(z,"w"),z),ni=["obs","manycam","virtual","snap camera","xsplit","droidcam","iriun","camo"],oi=[/^(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 li(i){let e=(i??"").trim().toLowerCase();return e.length===0?"unknown":ni.some(t=>e.includes(t))?"known_virtual":oi.some(t=>t.test(e))?"platform":"unknown"}n(li,"je");function at(i){if(typeof i!="function")return!1;try{return/\{\s*\[native code\]\s*\}\s*$/.test(Function.prototype.toString.call(i))}catch{return!1}}n(at,"Te");function ci(i=globalThis){return at(i.navigator?.mediaDevices?.getUserMedia)&&at(i.MediaStreamTrack?.prototype?.getSettings)}n(ci,"$e");async function hi(i,e=globalThis){let t=e.crypto?.subtle?.digest;if(typeof t=="function")try{let r=new Uint8Array(await t.call(e.crypto?.subtle,"SHA-256",new TextEncoder().encode(i)));return Array.from(r.subarray(0,8),s=>s.toString(16).padStart(2,"0")).join("")}catch{return}}n(hi,"Je");async function ui(i,e=globalThis){let t={};try{t=typeof i.getSettings=="function"?i.getSettings()??{}:{}}catch{t={}}let r={};if((t.facingMode==="user"||t.facingMode==="environment"||t.facingMode==="left"||t.facingMode==="right")&&(r.facingMode=t.facingMode),typeof t.frameRate=="number"&&Number.isFinite(t.frameRate)&&(r.frameRate=t.frameRate),typeof t.width=="number"&&Number.isFinite(t.width)&&(r.width=t.width),typeof t.height=="number"&&Number.isFinite(t.height)&&(r.height=t.height),typeof t.deviceId=="string"&&t.deviceId.length>0){let a=await hi(t.deviceId,e);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:li(s),prototypesIntact:ci(e)}}n(ui,"Ce");var ue=n(i=>Math.round(i*100)/100,"K");function di(i){let e=i,t=typeof e?.requestVideoFrameCallback=="function",r=null,s=null,a=0,o=0,l=0,c=0,h=0,d=0,u=n(()=>{!t||e?.requestVideoFrameCallback===void 0||(r=e.requestVideoFrameCallback((v,w)=>{if(r=null,!t)return;let m=w.presentationTime;if(s!==null){let g=m-s.presentationTimeMs;o+=1;let y=g-l;l+=y/o,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:n(()=>s,"latest"),stats:n(()=>({n:a,meanGapMs:o===0?0:ue(l),stdGapMs:o<2?0:ue(Math.sqrt(c/(o-1))),captureLatencyMs:d===0?null:ue(h/d)}),"stats"),stop:n(()=>{t&&(t=!1,r!==null&&e?.cancelVideoFrameCallback?.(r),r=null)},"stop")}}n(di,"Ee");function fi(i,e,t){return{...i,rvfc:e,rampPainter:t}}n(fi,"_e");var mi=1e3,de="fcv3.hold_upright",pi=200,fe=4,gi=600,vi=1e3,nt={sharpness:1,exposure:1,meanLuma:128};function yi(i,e){return e.width=i.videoWidth,e.height=i.videoHeight,e.getContext("2d").drawImage(i,0,0),new Promise((t,r)=>e.toBlob(s=>s?t(s):r(new Error("empty-keyframe")),"image/jpeg",.92))}n(yi,"it");function wi(){return Y()==="phone"}n(wi,"at");var H,ut=(H=class{constructor(e){this.handlers=new Map,this.stateValue="idle",this.attempt=0,this.stream=null,this.detector=null,this.scheduler=null,this.gate=null,this.profiler=null,this.lastGuidanceKey=null,this.positioningStartedAt=0,this.cameraRequestedAt=null,this.cameraReadyAt=null,this.faceAcquiredAt=null,this.captureCompleteAt=null,this.fired=!1,this.carriedDegrade=0,this.carriedMeans=[],this.blockStats=null,this.lastGateSnapshotAt=Number.NEGATIVE_INFINITY,this.uprightGuard=!1,this.trackProvenance=null,this.ramp=null,this.snapshotCanvas=null,this.options=e,this.facing=e.facingMode??"user"}get state(){return this.stateValue}on(e,t){let r=this.handlers.get(e);return r||(r=new Set,this.handlers.set(e,r)),r.add(t),()=>r?.delete(t)}emit(e,t){for(let r of[...this.handlers.get(e)??[]])r(t)}async start(e={}){e.facingMode!==void 0&&(this.facing=e.facingMode),this.attempt+=1,await this.run(this.attempt)}get facingMode(){return this.facing}retry(){this.teardownAttempt(),this.start()}switchCamera(){this.facing=this.facing==="user"?"environment":"user",this.teardownAttempt(),this.start()}restart(e){this.facing=e,this.teardownAttempt(),this.start()}destroy(){this.attempt+=1,this.teardownAttempt(),this.detector?.destroy(),this.detector=null,this.options.video.srcObject=null}async run(e){let{options:t}=this;this.fired=!1,this.lastGuidanceKey=null,this.carriedDegrade=0,this.carriedMeans=[],this.cameraRequestedAt=null,this.cameraReadyAt=null,this.faceAcquiredAt=null,this.captureCompleteAt=null,this.uprightGuard=(t.isPhone??wi)(),this.setState("preflight");let r=Ue();if(r!=="OK"){this.fail(r==="INSECURE_CONTEXT"?"insecure":"unsupported",{phase:"preflight"});return}this.setState("acquiring");let s=t.getUserMedia??(h=>navigator.mediaDevices.getUserMedia(h)),a;this.cameraRequestedAt=this.now();try{let{facingMode:h,...d}=Se(Ie(),this.facing).video;a=await ze(this.facing,d,{getUserMedia:s,enumerateDevices:ki(t)})}catch(h){if(e!==this.attempt)return;if(h instanceof We){this.fail("backcamera",{phase:"acquiring",name:j(h)});return}this.fail(Le(h),{phase:"acquiring",name:j(h)});return}if(xe(a),qe(a),e!==this.attempt){for(let h of a.getTracks())h.stop();return}this.stream=a;let o=a.getVideoTracks?.()[0];if(this.trackProvenance=o===void 0?null:ui(o).catch(()=>null),this.facing=Ae(a)??this.facing,t.video.srcObject=a,await t.video.play().catch(()=>{}),e!==this.attempt)return;if(this.cameraReadyAt=this.now(),this.detector===null){let h={v3AssetBaseUrl:t.v3AssetBaseUrl},d=t.createDetector??(t.createWorker!==void 0&&Qe()?async()=>{try{return await Je.create(t.createWorker(),h)}catch{return x(h)}}:()=>x(h)),u;try{u=await d()}catch(v){e===this.attempt&&this.fail("models",{phase:"models",name:j(v)},v instanceof he?v.fallbackReason:Mi(v));return}if(e!==this.attempt){u.destroy();return}this.detector=u,this.options.telemetry?.({type:"detector",tier:u.tier,fallbackReason:u.fallbackReason})}let l=He(),c=t.deviceClass??Ke(l);this.profiler=new Xe(c),this.options.telemetry?.({type:"profile",staticClass:c,activeClass:this.profiler.deviceClass,simd:l.simd}),this.gate=new rt(t.thresholds??{}),this.blockStats=new st,this.lastGateSnapshotAt=this.now(),t.rankKeyframes?.()&&import("./keyframe-rank-YAJLYJYF-WCA6RPMD.js").then(h=>me=h,()=>{}),this.setState("positioning"),this.positioningStartedAt=this.now(),this.startScheduler(e)}get animations(){return this.profiler?.profile.animations??"full"}startScheduler(e){let t=this.profiler;if(t===null)return;if(this.scheduler!==null){let s=this.scheduler.stats();this.carriedDegrade+=s.degradeCount,s.meanDetectMs>0&&this.carriedMeans.push(s.meanDetectMs),this.scheduler.stop()}let r=new ii({cadenceHz:t.profile.cadenceHz,video:this.options.video,now:this.options.now,run:n(()=>this.detectTick(e),"run")});this.scheduler=r,r.start()}async detectTick(e){let{detector:t,gate:r,profiler:s}=this,a=this.options.video;if(e!==this.attempt||t===null||r===null||s===null||this.fired||a.videoWidth===0)return;if(this.isLandscape()){this.holdUpright(e);return}let o=s.deviceClass,l=this.now(),c=this.options.makeSnapshot?.(a,s.profile.inputWidth)??this.defaultSnapshot(a,s.profile.inputWidth),h=null;try{h=await t.detect(c,a.videoWidth,a.videoHeight)}catch{h=null}if(e!==this.attempt||this.fired)return;s.record(this.now()-l),s.deviceClass!==o&&this.startScheduler(e);let d=h===null?nt: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>=mi&&(this.lastGateSnapshotAt=u.at,this.reportGate(!1)),this.emit("checks",{engine:"v3",progress:u.p,q:u.q,factors:u.factors,attempt:e}),u.guidanceKey!==this.lastGuidanceKey&&(this.lastGuidanceKey=u.guidanceKey,this.emit("guidance",{key:u.guidanceKey})),u.ready&&this.stateValue==="positioning"&&(this.fired=!0,this.captureCompleteAt=u.at,this.fire(e))}async fire(e){let{options:t}=this,r=this.scheduler;r?.stop(),this.reportGate(!0);let s=r?.stats()??{degradeCount:0,meanDetectMs:0},a=[...this.carriedMeans,...s.meanDetectMs>0?[s.meanDetectMs]:[]];t.telemetry?.({type:"fired",timeToGateMs:this.now()-this.positioningStartedAt,degradeCount:this.carriedDegrade+s.degradeCount,meanDetectMs:a.length===0?0:a.reduce((T,b)=>T+b,0)/a.length});let o=t.mode??"clip",l=t.rankKeyframes?.()&&me?me.default(this,e).catch(()=>this.collectKeyframes(e)):this.collectKeyframes(e);if(o==="photo"){let T=this.watchRotation(e,null),b=await l;if(T(),e!==this.attempt)return;if(b===null){this.fail("generic",{phase:"keyframes"});return}let A=await this.provenance({n:0,meanGapMs:0,stdGapMs:0,captureLatencyMs:null},!1);if(e!==this.attempt)return;this.finishCapture({keyframe:b.blob,previewDataUrl:b.previewDataUrl,...A});return}this.setState("recording");let c=this.stream;if(c===null){this.fail("generic",{phase:"recording"});return}let h=t.screenRamp?.(),d=pe(h),u=null;l.then(T=>{u=T},()=>{});let v=n(()=>{e===this.attempt&&u!==null&&this.emit("frozen",{previewDataUrl:u.previewDataUrl})},"f"),w=Jt(h,ht),m=null,g,y=0;try{let T=this.recordTake(e,c,h,w,void 0).then(S=>S,S=>({failed:S})),[b,A]=await Promise.all([T,l]);if(g=A,e!==this.attempt)return;if("failed"in b){if(b.failed.kind==="cliptoolarge")throw b.failed;et(b.failed.requestedMimeType??"")}else m=b,it(b.clip,w)?b.clip.stats===null&&et(b.clip.requestedMimeType??""):v();if(m===null||it(m.clip,w)){y=1,t.telemetry?.({type:"clip_retake",reason:m===null?"error":m.clip.stats===null?"unreadable":"short"});let S=null;try{S=await this.recordTake(e,c,h,w,v)}catch(K){if(m===null)throw K}if(e!==this.attempt)return;S!==null&&(m===null||Xt(S.clip,m.clip))&&(m=S),S===null&&v()}}catch(T){if(e!==this.attempt)return;let b=T.kind;this.fail(b==="cliptoolarge"?"cliptoolarge":"recorder",{phase:"recording",name:j(T)});return}if(m===null){this.fail("recorder",{phase:"recording"});return}let{clip:p,rvfc:M,report:E}=m;if(ae(p.blob)){this.fail("cliptoolarge",{phase:"recording"});return}if(g===null){this.fail("generic",{phase:"keyframes"});return}let I=await this.provenance(M,d);e===this.attempt&&this.finishCapture({clip:p.blob,clipMimeType:p.mimeType,...p.stats?{clipStats:p.stats}:{},clipRetakes:y,keyframe:g.blob,previewDataUrl:g.previewDataUrl,...E!==void 0&&E.rendered.length>0?{screenRamp:E}:{},...I})}async recordTake(e,t,r,s,a){let o=this.options.createRecorder?.()??new Zt({now:n(()=>this.now(),"now")}),l=di(this.options.video),c=ei(r,{paint:n(u=>{(u===null||e===this.attempt)&&this.emit("ramp",{colour:u})},"paint"),now:n(()=>this.now(),"now"),frames:l.latest});this.ramp=c;let h=n(()=>{l.stop(),c.stop(),this.ramp===c&&(this.ramp=null)},"l"),d=this.watchRotation(e,o);try{return{clip:await o.record(t,a,()=>c.started(this.now()),s,l),rvfc:l.stats(),report:c.report()}}finally{d(),h()}}async provenance(e,t){let r=this.trackProvenance;if(r===null)return{};let s,a=new Promise(l=>{s=setTimeout(()=>l(null),vi)}),o=await Promise.race([r,a]);return clearTimeout(s),o===null?{}:{provenance:fi(o,e,t)}}isLandscape(){let e=this.options.video;return this.uprightGuard&&e.videoWidth>e.videoHeight}holdUpright(e){this.gate?.reset(),this.emit("checks",{engine:"v3",progress:0,q:0,factors:{presence:0,single:1,centering:0,size:0,pose:0,sharpness:0,exposure:0,motion:0},attempt:e}),this.lastGuidanceKey!==de&&(this.lastGuidanceKey=de,this.emit("guidance",{key:de}))}watchRotation(e,t){if(!this.uprightGuard)return()=>{};let r=this.options.video,s=n(()=>{if(e!==this.attempt||t!==null&&this.stateValue!=="recording"){l();return}r.videoWidth>0&&this.isLandscape()&&(l(),this.abortRecording(e,t))},"n"),a=setInterval(s,pi);r.addEventListener?.("resize",s);let o=!1;function l(){o||(o=!0,clearInterval(a),r.removeEventListener?.("resize",s))}return n(l,"o"),l}abortRecording(e,t){if(e!==this.attempt)return;this.attempt+=1;let r=this.attempt;try{t?.stop()}catch{}this.ramp?.stop(),this.ramp=null,this.fired=!1,this.captureCompleteAt=null,this.gate=new rt(this.options.thresholds??{}),this.blockStats=new st,this.lastGateSnapshotAt=this.now(),this.lastGuidanceKey=null,this.setState("positioning"),this.positioningStartedAt=this.now(),this.holdUpright(r),this.startScheduler(r)}async collectKeyframes(e){let t=this.options.captureKeyframe??(a=>this.defaultKeyframe(a)),r=gi/(fe-1),s=null;for(let a=0;a<fe;a+=1){if(e!==this.attempt)return s;try{let o=await t(this.options.video);(s===null||o.sharpness>s.sharpness)&&(s=o)}catch{}a<fe-1&&await bi(r)}return s}finishCapture(e){this.stopTracks(),this.setState("captured");let t=this.captureTiming();this.emit("artifacts",t===void 0?e:{...e,timing:t})}captureTiming(){let e={},t=n((r,s,a)=>{s!==null&&a!==null&&(e[r]=Math.max(0,Math.round(a-s)))},"t");return t("cameraReadyMs",this.cameraRequestedAt,this.cameraReadyAt),t("faceAcquireMs",this.cameraReadyAt,this.faceAcquiredAt),t("captureMs",this.faceAcquiredAt,this.captureCompleteAt),Object.keys(e).length>0?e:void 0}async defaultKeyframe(e){let t=document.createElement("canvas"),r=await(this.facing==="user"?ti:yi)(e,t),s=t.toDataURL("image/jpeg",.92);return{blob:r,previewDataUrl:s,sharpness:this.centerSharpness(e)}}defaultSnapshot(e,t){try{let r=this.snapshotCanvas??document.createElement("canvas"),s=t/Math.max(1,e.videoWidth),a=Math.max(1,Math.round(e.videoWidth*s)),o=Math.max(1,Math.round(e.videoHeight*s)),l=r.getContext("2d");return l===null?e:(r.width!==a&&(r.width=a),r.height!==o&&(r.height=o),l.drawImage(e,0,0,a,o),this.snapshotCanvas=r,r)}catch{return e}}defaultQuality(e,t){let r=ot(e,t,96);return r===null?nt:{sharpness:oe(r),exposure:Ve(r),meanLuma:Ze(r)}}centerSharpness(e){let t=Q(e),r=ot(e,{x:t.width*.25,y:t.height*.25,width:t.width*.5,height:t.height*.5},96);return r===null?0:oe(r)}teardownAttempt(){this.scheduler?.stop(),this.scheduler=null,this.reportGate(!0),this.gate=null,this.ramp?.stop(),this.ramp=null,this.stopTracks()}reportGate(e){let t=this.blockStats,r=this.profiler;if(t===null||r===null)return;let s=t.summary();e&&(this.blockStats=null),s.ticks!==0&&this.options.telemetry?.({type:"gate",final:e,activeClass:r.deviceClass,cadenceHz:r.profile.cadenceHz,...s})}stopTracks(){if(this.stream!==null){for(let e of this.stream.getTracks())e.stop();this.stream=null}}fail(e,t,r){this.scheduler?.stop(),this.reportGate(!0),this.stopTracks(),this.setState("error"),this.options.telemetry?.({type:"error",kind:e,fallbackReason:r});let{phase:s,name:a}=t;this.emit("error",{kind:e,retryable:e!=="insecure"&&e!=="unsupported",detail:a===void 0?{phase:s}:{phase:s,name:a}})}setState(e){this.stateValue=e,this.emit("statechange",{state:e})}now(){return this.options.now?.()??performance.now()}},n(H,"ke"),H),me;function bi(i){return new Promise(e=>setTimeout(e,i))}n(bi,"st");function Mi(i){return i instanceof Error?i.message:String(i)}n(Mi,"ot");function ot(i,e,t){try{let r=document.createElement("canvas"),s=t/Math.max(1,e.width);r.width=Math.max(1,Math.round(e.width*s)),r.height=Math.max(1,Math.round(e.height*s));let a=r.getContext("2d");return a===null?null:(a.drawImage(i,e.x,e.y,e.width,e.height,0,0,r.width,r.height),a.getImageData(0,0,r.width,r.height))}catch{return null}}n(ot,"we");function ki(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()}n(ki,"lt");var Ti=12e4,dt=13e4,_i=3e3,Ei=1200,ge=Symbol.for("@sekyro/web.preload.v1");function ye(){let i=globalThis;return i[ge]??(i[ge]=new Map),i[ge]}n(ye,"h");function te(i){let e=(i??ce).replace(/\/+$/,"");return e===""?"/":e}n(te,"b");function mt(i){let e=ye(),t=e.get(i);return t===void 0&&(t={status:"idle",promise:null,scheduled:null,detectorPromise:null,detector:null,listeners:new Set},e.set(i,t)),t}n(mt,"ae");function ve(i,e){if(i.status!==e){i.status=e;for(let t of[...i.listeners])t(e)}}n(ve,"k");var Si=n(i=>x({preferred:["blaze"],v3AssetBaseUrl:i,blazeInitTimeoutMs:Ti}),"K"),Ii=Si;function Ai(){return typeof window<"u"&&typeof navigator<"u"&&typeof navigator.mediaDevices?.getUserMedia=="function"}n(Ai,"Ce");function xi(){return navigator.connection?.saveData===!0}n(xi,"Se");function Di(i){let e=window;if(typeof e.requestIdleCallback=="function"){let r=e.requestIdleCallback(i,{timeout:_i});return()=>e.cancelIdleCallback?.(r)}let t=setTimeout(i,Ei);return()=>clearTimeout(t)}n(Di,"Ee");function Ri(i,e){let t,r=new Promise(l=>{t=l}),s=!1,a=n(()=>{},"u"),o={promise:r,settle:n(l=>{s||(s=!0,a(),i.scheduled===o&&(i.scheduled=null),t(l))},"settle")};return i.scheduled=o,a=Di(()=>{s||o.settle(we(i,e))}),r}n(Ri,"ye");function we(i,e){if((i.status==="loading"||i.status==="ready")&&i.promise!==null)return i.promise;ve(i,"loading");let t=new Promise(o=>o(Ii(e)));i.detectorPromise=t;let r,s=new Promise((o,l)=>{r=setTimeout(()=>{t.then(c=>c.destroy(),()=>{}),l(new Error(`detector preload exceeded ${dt} ms`))},dt)}),a=Promise.race([t,s]).then(o=>i.detectorPromise!==t?(o.destroy(),i.status):(i.detector=o,ve(i,"ready"),"ready"),o=>(i.detectorPromise===t&&(i.detectorPromise=null,i.detector=null,ve(i,"failed"),console.warn("[@sekyro/web] face-detector preload failed:",o)),i.status)).finally(()=>clearTimeout(r));return i.promise=a,i.scheduled?.settle(a),a}n(we,"U");function sr(i={}){if(!Ai())return Promise.resolve("idle");let e=te(i.assetBaseUrl),t=mt(e);return i.respectSaveData===!0&&xi()?Promise.resolve(t.status):(t.status==="loading"||t.status==="ready")&&t.promise!==null?t.promise:i.idle===!0?t.scheduled?.promise??Ri(t,e):we(t,e)}n(sr,"xe");function ar(i){return ye().get(te(i))?.status??"idle"}n(ar,"Fe");function nr(i,e){let t=mt(te(e));return t.listeners.add(i),()=>{t.listeners.delete(i)}}n(nr,"Ie");function Ci(i){return{get tier(){return i.tier},get fallbackReason(){return i.fallbackReason},detect:n((...e)=>i.detect(...e),"detect"),destroy:n(()=>{},"destroy")}}n(Ci,"Le");function Oi(i){let e=te(i),t=ye().get(e);if(!(t===void 0||t.detector===null&&t.detectorPromise===null&&t.scheduled===null))return async()=>{t.scheduled!==null&&we(t,e);let r=t.promise;for(;t.detector===null&&r!==null&&(await r,t.promise!==r);)r=t.promise;return t.detector!==null?Ci(t.detector):x({v3AssetBaseUrl:e})}}n(Oi,"de");var Gi=new Set(["inuse","overconstrained","notfound"]),Pi=[500,1500];function Ui(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}}n(Ui,"Ae");function Fi(i){switch(i){case"preflight":case"acquiring":return"starting";case"positioning":return"gating";default:return i}}n(Fi,"Pe");function ft(i){switch(i){case"permission":case"notfound":case"inuse":case"insecure":case"unsupported":return i;case"backcamera":return"notfound";default:{let e=i;return"generic"}}}n(ft,"ue");function Ni(i,e,t){if(t===void 0)return{kind:ft(i),retryable:e};let r=Be(t.name);return{kind:ft(i),retryable:e,detail:{...r!==void 0?{name:r}:{},phase:t.phase,engineKind:i}}}n(Ni,"we");var Bi=new Set(["captured","uploading","checking"]);function Li(i,e={},t,r=()=>"self",s=()=>{},a){let o=e.now??(()=>performance.now()),l=e.canChooseFacing??Re,c="user",h=Ce(),d=r(),u=De(),v=!Fe(),w=e.engineOptions,m=w?.createDetector===void 0&&w?.createWorker===void 0?{createDetector:n(()=>{let f=Oi(i.assetBaseUrl);return f!==void 0?f():x({v3AssetBaseUrl:i.assetBaseUrl})},"createDetector")}:{},g={video:i.video,mode:v?"photo":"clip",rankKeyframes:t,facingMode:void 0,v3AssetBaseUrl:i.assetBaseUrl,screenRamp:n(()=>d==="self"&&u.count("ramp")>0?s():void 0,"screenRamp"),...e.engineOptions??{},...m},y=e.createEngine?.(g)??new ut(g),p="idle",M=null,E=0,I=!1,T="full",b=null,A=null,S=0,K=0,be=n(()=>{i.video.videoWidth>0&&i.video.videoHeight>0&&(S=i.video.videoWidth,K=i.video.videoHeight)},"W"),Me=Oe({enabled:i.keepScreenAwake!==!1}),X=n(f=>{p=f,Me.setActive(f==="starting"||f==="gating"||f==="recording"),u.emit("state",f)},"S"),ie=n(()=>u.emit("gate",{progress:E,hint:M,faceDetected:I}),"F"),re=n(()=>{let f=y.animations??"full";f!==T&&(T=f,u.emit("profile",{animations:T}))},"I"),G=0,$=null,pt=e.schedule??((f,k)=>{let _=setTimeout(f,k);return()=>clearTimeout(_)}),Z=n(()=>{$?.(),$=null},"E"),gt=n((f,k)=>{if(V||!Gi.has(f)||k?.phase!=="acquiring")return!1;let _=Pi[G];return _===void 0?!1:(G+=1,Z(),$=pt(()=>{$=null,V||y.retry()},_),!0)},"fe"),vt=[y.on("statechange",({state:f})=>{if(f==="error")return;let k=Fi(f);k==="gating"&&(G=0),k==="starting"&&p!=="starting"&&(M=null,E=0,I=!1,b=null,A=null,S=0,K=0),X(k),re(),k==="recording"&&(be(),b=o(),M="hold",E=1,ie())}),y.on("checks",f=>{be(),E=f.progress,I=f.factors.presence>0,ie(),re()}),y.on("guidance",({key:f})=>{M=Ui(f),ie()}),y.on("frozen",({previewDataUrl:f})=>{A=o(),u.emit("frozen",{previewDataUrl:f})}),y.on("ramp",f=>u.emit("ramp",f)),y.on("artifacts",f=>{if(p!=="captured")return;let k=Y(),_=f.clipStats,_e=_!==void 0?Math.round(_.durationMs):b!==null&&A!==null?Math.max(0,Math.round(A-b)):void 0,Ee=_!==void 0&&_.frames>1&&_.durationMs>0?Math.round(_.frames*1e4/_.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||S,height:i.video.videoHeight||K,..._e!==void 0?{clipMs:_e}:{},..._!==void 0?{clipFrames:_.frames}:{},...Ee!==void 0?{fps:Ee}:{},...f.clipRetakes!==void 0?{clipRetakes:f.clipRetakes}:{},...f.clipMimeType!==void 0?{codec:ct(f.clipMimeType)}:{},captureChannel:k==="desktop"?"desktop":"mobile",formFactor:k,...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:k,detail:_})=>{f==="backcamera"&&yt()||gt(f,_)||(X("error"),re(),u.emit("error",Ni(f,k,_)))})],ke=!1;function yt(){return V||ke||d!=="assisted"||a===void 0||a.session()!=="choice"?!1:(ke=!0,a.onModeChange("self"),d="self",c=se("self"),X("mode_switch"),y.restart(c),!0)}n(yt,"me");let Te=n(async()=>a!==void 0&&a.session()==="choice"&&await l().catch(()=>!1),"$"),V=!1;return{handle:{get state(){return p},get captureMode(){return r()},get facingMode(){return y.facingMode??c},on:n((f,k)=>u.on(f,k),"on"),start:n(f=>(d=r(),h.facing(d,i.facing),c=h.facing(d,f?.facing),Z(),G=0,y.start({facingMode:c})),"start"),retry:n(()=>{Z(),G=0,y.retry()},"retry"),switchCamera:n(()=>h.refuseSwitch(r()),"switchCamera"),canSwitchCaptureMode:Te,setCaptureMode:n(async f=>{if(f===r()||!await Te()||V||Bi.has(p)||a===void 0)return!1;a.onModeChange(f),d=f;let k=se(f);return c=k,p==="idle"||(X("mode_switch"),Z(),G=0,y.restart(k)),!0},"setCaptureMode"),destroy:n(()=>{V=!0,Z();for(let f of vt)f();Me.setActive(!1),y.destroy(),u.clear()},"destroy")},setFlowState:n(f=>{p!==f&&X(f)},"setFlowState")}}n(Li,"De");function or(i){return Li(i).handle}n(or,"Ze");export{$i as a,sr as b,ar as c,nr as d,Ni as e,Li as f,or as g};
1
+ import{d as xe,e as He,f as Ke,g as Xe}from"./chunk-4YBL75VD.js";import{a as ne,b as Ze,c as oe,d as Ve}from"./chunk-P7K7ELYZ.js";import{a as Se,b as Y,c as Ie,d as Ae,e as De,h as Re,i as se,j as Ce,k as Oe,l as We,m as ze}from"./chunk-6MYG4HWP.js";import{a as Ge,b as Pe,c as Ue,d as Fe,e as Ne,f as ae,g as j,h as Be,i as Le,j as qe}from"./chunk-JS2IXPNL.js";import{a as n}from"./chunk-4FHWXBOB.js";var wt=1e4,C,bt=(C=class{constructor(e,t){this.tier="blaze",this.inner=e,t!==void 0&&(this.fallbackReason=t)}static async create(e,t){let r=await import("./vision_bundle-WBHR7TEE.js"),s=await r.FilesetResolver.forVisionTasks(e),a=await r.FaceDetector.createFromOptions(s,{baseOptions:{modelAssetPath:`${e}/blaze_face_short_range.tflite`,delegate:"CPU"},runningMode:"IMAGE"});return new C(a,t)}async detect(e,t,r){let s;try{s=this.inner.detect(e).detections}catch{return null}let a=Mt(s);if(a?.boundingBox===void 0)return null;let o=Q(e),l=kt(a.keypoints,o),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*o.width,y:c.y*o.height}}:{},score:a.categories[0]?.score??0,extraFaces:je(s.map(d=>d.boundingBox??{width:0,height:0}),s.indexOf(a))};return $e(h,e,t,r)}destroy(){try{this.inner.close()}catch{}}},n(C,"t"),C);function Mt(i){let e,t=-1;for(let r of i){let s=r.categories[0]?.score??0;s>t&&(e=r,t=s)}return e}n(Mt,"R");function kt(i,e){let t=i?.[0],r=i?.[1];if(t===void 0||r===void 0)return;let s=n(l=>({x:l.x*e.width,y:l.y*e.height}),"n"),[a,o]=[s(t),s(r)];return a.x<=o.x?{left:a,right:o}:{left:o,right:a}}n(kt,"T");function Tt(){if(typeof OffscreenCanvas=="function")return new OffscreenCanvas(2,2);let i=document.createElement("canvas");return i.width=2,i.height=2,i}n(Tt,"E");var _t=4;async function Et(){let i=globalThis.FaceDetector;if(typeof i!="function")return{ok:!1,reason:"unsupported"};try{let e=new i({fastMode:!0,maxDetectedFaces:_t});return await e.detect(Tt()),{ok:!0,instance:e}}catch(e){return{ok:!1,reason:`smoke_failed:${e instanceof Error?e.message:String(e)}`}}}n(Et,"w");var P,St=(P=class{constructor(e,t){this.tier="native",this.inner=e,t!==void 0&&(this.fallbackReason=t)}async detect(e,t,r){let s;try{s=await this.inner.detect(e)}catch{return null}let a=s.map(d=>d.boundingBox),o=-1;a.forEach((d,u)=>{let v=a[o];(v===void 0||d.width*d.height>v.width*v.height)&&(o=u)});let l=s[o];if(l===void 0)return null;let c=It(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:je(a,o)};return $e(h,e,t,r)}destroy(){}},n(P,"b"),P);function It(i){if(i===void 0)return;let e=i.filter(s=>s.type==="eye").map(s=>s.locations[0]).filter(s=>s!==void 0),[t,r]=e;if(!(t===void 0||r===void 0))return t.x<=r.x?{left:t,right:r}:{left:r,right:t}}n(It,"S");var At=.25;function je(i,e){let t=i[e],r=t===void 0?0:t.width*t.height;if(!(r>0))return 0;let s=0;return i.forEach((a,o)=>{o!==e&&a.width*a.height>=At*r&&(s+=1)}),s}n(je,"f");var ce="/models-v3",xt=["native","blaze"],U,he=(U=class extends Error{constructor(e){super(`no detector tier available (${e})`),this.name="DetectorLadderError",this.fallbackReason=e}},n(U,"x"),U);function Q(i){let e=i;if(typeof e.videoWidth=="number"&&e.videoWidth>0)return{width:e.videoWidth,height:e.videoHeight??0};if(typeof e.naturalWidth=="number"&&e.naturalWidth>0)return{width:e.naturalWidth,height:e.naturalHeight??0};let t=typeof e.width=="number"?e.width:0,r=typeof e.height=="number"?e.height:0;return{width:t,height:r}}n(Q,"y");function $e(i,e,t,r){let s=Q(e),a=s.width>0?t/s.width:1,o=s.height>0?r/s.height:1,l=n(c=>({x:c.x*a,y:c.y*o}),"s");return{box:{x:i.box.x*a,y:i.box.y*o,width:i.box.width*a,height:i.box.height*o},...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}:{}}}n($e,"h");function Dt(i){return i instanceof Error?i.message:String(i)}n(Dt,"C");async function x(i){let e=i.preferred??xt,t=[];for(let r of e){if(r==="native"){let s=await Et();if(s.ok)return new St(s.instance,le(t));t.push(`native:${s.reason}`);continue}try{return await Rt(bt.create(i.v3AssetBaseUrl??ce,le(t)),i.blazeInitTimeoutMs??wt)}catch(s){t.push(s instanceof Ye?"blaze:blaze_init_timeout":`blaze:${Dt(s)}`)}}throw new he(le(t)??"no_tier_available")}n(x,"O");function le(i){return i.length>0?i.join("; "):void 0}n(le,"v");var F,Ye=(F=class extends Error{},n(F,"g"),F);function Rt(i,e){return new Promise((t,r)=>{let s=setTimeout(()=>{r(new Ye(`init exceeded ${e}ms`)),i.then(a=>a.destroy(),()=>{})},e);i.then(a=>{clearTimeout(s),t(a)},a=>{clearTimeout(s),r(a)})})}n(Rt,"W");var R=1;function Qe(){return typeof OffscreenCanvas=="function"&&typeof createImageBitmap=="function"&&typeof Worker=="function"}n(Qe,"K");function Ct(i,e={}){let t=e.createDetector??x,r=null;i.onmessage=s=>{let a=s.data;if(a.v!==R){a.bitmap?.close?.();return}if(a.type==="init"){t(a.options).then(o=>{r=o;let l={v:R,type:"ready",tier:o.tier,...o.fallbackReason!==void 0?{fallbackReason:o.fallbackReason}:{}};i.postMessage(l)});return}if(a.type==="detect"){let o=n(l=>{let c={v:R,type:"result",id:a.id,observation:l};i.postMessage(c),a.bitmap.close?.()},"a");if(r===null){o(null);return}r.detect(a.bitmap,a.streamWidth,a.streamHeight).then(o,()=>o(null))}}}n(Ct,"B");typeof self<"u"&&typeof self.importScripts=="function"&&Ct(self);var O,Je=(O=class{constructor(e,t){this.pending=new Map,this.nextId=1,this.worker=e,this.tier=t.tier,t.fallbackReason!==void 0&&(this.fallbackReason=t.fallbackReason),e.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(e,t,r=1e4){return new Promise((s,a)=>{let o=setTimeout(()=>{e.removeEventListener("message",l),e.terminate(),a(new Error(`worker detector not ready within ${r}ms`))},r),l=n(h=>{let d=h.data;d.v!==R||d.type!=="ready"||(clearTimeout(o),e.removeEventListener("message",l),s(new O(e,d)))},"s");e.addEventListener("message",l);let c={v:R,type:"init",options:t};e.postMessage(c)})}async detect(e,t,r){let s;try{typeof ImageBitmap<"u"&&e instanceof ImageBitmap?s=e:typeof createImageBitmap=="function"?s=await createImageBitmap(e):s=e}catch{return null}let a=this.nextId;return this.nextId+=1,new Promise(o=>{this.pending.set(a,o);let l={v:R,type:"detect",id:a,bitmap:s,streamWidth:t,streamHeight:r};this.worker.postMessage(l,[s])})}destroy(){for(let e of this.pending.values())e(null);this.pending.clear(),this.worker.terminate()}},n(O,"t"),O);var Ot=[...Ge.filter(i=>i.startsWith("video/mp4")),"video/webm;codecs=h264","video/webm;codecs=avc1","video/webm;codecs=vp8","video/webm;codecs=vp9","video/webm"],lt=new Set;function Gt(i){let e=/(?:Chrome|Chromium)\/(\d+)\./.exec(i??"");return e?Number(e[1]):null}n(Gt,"De");function Pt(i=Ft(),e=globalThis.navigator?.userAgent){if(i===void 0)return"";let t=Gt(e)===126;for(let r of Ot)if(!(lt.has(r)||t&&r.startsWith("video/mp4")))try{if(i(r))return r}catch{}return""}n(Pt,"fe");function et(i){i!==""&&lt.add(i)}n(et,"V");function Ut(i){return i.replace(/^video\/x-matroska/i,"video/webm")}n(Ut,"ge");function ct(i){let e=/codecs=["']?([^,;"']+)/i.exec(i);return e?e[1].trim():i.split(";")[0].trim()}n(ct,"ut");function Ft(){let i=globalThis.MediaRecorder;return i&&typeof i.isTypeSupported=="function"?e=>i.isTypeSupported(e):void 0}n(Ft,"Oe");var ht=2500,Nt=1e3,Bt=1500,tt=25e5,Lt=100,qt=700,Wt=20,zt=1500,J=null;function Ht(){return J??(J=import("./clip-inspect-DLJXVKV6-TNHTD4LV.js").catch(i=>{throw J=null,i})),J.catch(()=>null)}n(Ht,"Ne");var B,D=(B=class extends Error{constructor(e,t){super(t??e),this.kind=e}},n(B,"S"),B),Kt=100;function it(i,e){return i.stats===void 0?!1:i.stats===null?!0:i.stats.durationMs<e-Kt}n(it,"H");function Xt(i,e){return i.stats?e.stats?i.stats.durationMs>e.stats.durationMs:!0:!1}n(Xt,"be");var L,Zt=(L=class{constructor(e={}){this.recorder=null,this.stream=null,this.chunks=[],this.bytes=0,this.hardStopTimer=null,this.graceTimer=null,this.pollTimer=null,this.settled=!1,this.now=e.now??(()=>globalThis.performance?.now?.()??Date.now())}clearTimers(){this.hardStopTimer&&clearTimeout(this.hardStopTimer),this.graceTimer&&clearTimeout(this.graceTimer),this.pollTimer&&clearInterval(this.pollTimer),this.hardStopTimer=null,this.graceTimer=null,this.pollTimer=null}record(e,t,r,s=ht,a){let o=Pt(),l=Ht();return this.recordRaw(e,t,r,s,a,o).then(c=>Vt(c,l),c=>{throw c instanceof D&&(c.requestedMimeType=o),c})}recordRaw(e,t,r,s,a,o){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=e,new Promise((l,c)=>{let h;try{h=new MediaRecorder(e,o?{mimeType:o,videoBitsPerSecond:tt}:{videoBitsPerSecond:tt})}catch{try{h=new MediaRecorder(e)}catch{c(new D("unsupported"));return}}this.recorder=h;let d=n(p=>{this.settled||(this.settled=!0,this.clearTimers(),p())},"d"),u=n(()=>d(()=>{let p=Ut(h.mimeType||o||Pe),M=new Blob(this.chunks,{type:p});if(M.size===0){c(new D("generic","empty clip"));return}if(ae(M)){c(new D("cliptoolarge"));return}l({blob:M,mimeType:p,requestedMimeType:o})}),"u");h.ondataavailable=p=>{p.data&&p.data.size&&(this.chunks.push(p.data),this.bytes+=p.data.size,this.bytes>Ne&&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(Nt)}catch{d(()=>c(new D("generic")));return}let w=n(()=>{if(this.pollTimer&&clearInterval(this.pollTimer),this.pollTimer=null,this.hardStopTimer&&clearTimeout(this.hardStopTimer),this.hardStopTimer=null,this.settled||t?.(),h.state!=="inactive"){try{h.stop()}catch{u()}this.graceTimer=setTimeout(u,Bt)}else u()},"g"),m=this.now();if(a===void 0){this.hardStopTimer=setTimeout(w,s);return}let g=null,y=!1;this.hardStopTimer=setTimeout(w,s+qt),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 E=g!==null&&M!==void 0&&M-g>=s,I=g===null&&this.now()-m>=s;if(!(!E&&!I)){if(y=!0,this.pollTimer&&clearInterval(this.pollTimer),this.pollTimer=null,I){w();return}this.hardStopTimer&&clearTimeout(this.hardStopTimer),this.hardStopTimer=setTimeout(w,Lt)}},Wt)}))}stop(e){this.clearTimers();let t=this.recorder;if(t&&t.state!=="inactive")try{t.stop()}catch{}this.recorder=null,(e??this.stream)?.getTracks().forEach(r=>r.stop()),this.stream=null}},n(L,"I"),L);async function Vt(i,e){let t,r=new Promise(h=>{t=setTimeout(()=>h(null),zt)}),s=await Promise.race([e,r]);if(clearTimeout(t),s===null)return i;let a;try{a=await s.blobBytes(i.blob)}catch{return{...i,stats:null}}let o=s.inspectClipBytes(a);if(o?.container!=="webm")return{...i,stats:o};let l=s.withWebmDuration(a,o.durationMs);if(l===null)return{...i,stats:o};let c=s.inspectClipBytes(l);return c===null||c.frames!==o.frames||c.durationMs!==o.durationMs?{...i,stats:o}:{...i,blob:new Blob([l],{type:i.blob.type}),stats:o}}n(Vt,"He");var jt=["magenta","yellow","green","blue"],$t={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 $i(i){return $t[i]}n($i,"ft");var Yt=4,Qt=4,ee=n(i=>typeof i=="number"&&Number.isFinite(i),"D");function pe(i){if(typeof i!="object"||i===null)return!1;let e=i;if(typeof e.nonce!="string"||e.nonce.length===0||!Array.isArray(e.colours)||e.colours.length<1||e.colours.length>8||!e.colours.every(r=>jt.includes(r))||!Array.isArray(e.onsetsMs)||e.onsetsMs.length!==e.colours.length)return!1;let t=-1;for(let r of e.onsetsMs){if(!ee(r)||r<0||r<=t)return!1;t=r}return!(!ee(e.holdMs)||e.holdMs<=0||!ee(e.endMs)||e.endMs<=t||!ee(e.clipMs)||e.clipMs<e.endMs||e.clipMs>8e3)}n(pe,"O");function Jt(i,e){return pe(i)?Math.max(e,Math.ceil(i.clipMs)):e}n(Jt,"ye");function ei(i,e){let t=e.now??(()=>performance.now()),r=pe(i)?i:void 0,s=[],a=null,o=null,l=null,c=!1,h=null,d=n(m=>{h=m;try{e.paint(m)}catch{}},"d"),u=n(m=>{let g=e.frames?.()??null;return g!==null&&l!==null?g.mediaTimeMs+(m-g.presentationTimeMs)-l:m-(o??m)},"u"),v=n((m,g,y=0)=>{if(c)return;let p=Math.max(0,m-u(t()));a=setTimeout(()=>{if(a=null,!c){if(y<Yt&&u(t())<m-Qt){v(m,g,y+1);return}g()}},p)},"f"),w=n(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(t());if(M>g){h!==null&&d(null);return}let E=r.colours[m];d(E);let I=s.length===0?0:s[s.length-1].tMs;s.push({tMs:Math.max(I,Math.round(M)),colour:E});let T=y+r.holdMs;if(T<p){v(T,()=>{if(u(t())>g){h!==null&&d(null);return}d("dark"),w(m+1)});return}w(m+1)})},"g");return{started(m){if(r===void 0||c||o!==null)return;o=m;let g=e.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]}}}}n(ei,"Me");function ti(i,e,t=.92){return new Promise((r,s)=>{let a=i.videoWidth,o=i.videoHeight;if(!a||!o){s(new Error("video-not-ready"));return}let l=e.getContext("2d");if(!l){s(new Error("no-2d-context"));return}e.width=a,e.height=o,l.scale(-1,1),l.drawImage(i,-a,0),e.toBlob(c=>c?r(c):s(new Error("empty-keyframe")),"image/jpeg",t)})}n(ti,"Se");var q,ii=(q=class{constructor(e){this.timer=null,this.frameCallbackId=null,this.running=!1,this.busy=!1,this.lastRunAt=Number.NEGATIVE_INFINITY,this.degradeCount=0,this.durations=[],this.options=e,this.periodMs=1e3/e.cadenceHz}start(){if(this.running)return;this.running=!0;let e=this.options.video;if(typeof e?.requestVideoFrameCallback=="function"){let t=n(()=>{this.running&&(this.frameCallbackId=e.requestVideoFrameCallback?.(()=>{this.frameCallbackId=null,this.now()-this.lastRunAt>=this.periodMs&&this.tick(),t()}))},"t");t();return}this.timer=setInterval(()=>this.tick(),this.periodMs)}stop(){this.running=!1,this.timer!==null&&(clearInterval(this.timer),this.timer=null),this.frameCallbackId!==null&&(this.options.video?.cancelVideoFrameCallback?.(this.frameCallbackId),this.frameCallbackId=null)}stats(){let e=this.durations.length===0?0:this.durations.reduce((t,r)=>t+r,0)/this.durations.length;return{degradeCount:this.degradeCount,meanDetectMs:e}}now(){return this.options.now?.()??performance.now()}tick(){if(!this.running)return;if(this.busy){this.degradeCount+=1;return}this.busy=!0,this.lastRunAt=this.now();let e=this.now();this.options.run().catch(()=>{}).finally(()=>{this.busy=!1,this.durations.push(this.now()-e),this.durations.length>20&&this.durations.shift()})}},n(q,"P"),q),ri=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}),N=n(i=>Math.min(1,Math.max(0,i)),"_"),W,rt=(W=class{constructor(e={}){this.p=0,this.lastTickAt=null,this.lastCenter=null,this.velocityEma=0,this.qWindow=[],this.lastSizeDirection="ideal",this.t={...ri,...e}}reset(){this.p=0,this.lastTickAt=null,this.lastCenter=null,this.velocityEma=0,this.qWindow=[],this.lastSizeDirection="ideal"}tick(e){let{observation:t,quality:r,timestampMs:s}=e,a=this.lastTickAt===null?0:Math.max(0,(s-this.lastTickAt)/1e3);this.lastTickAt=s;let o={presence:0,single:1,centering:0,size:0,pose:0,sharpness:N(r.sharpness),exposure:N(r.exposure),motion:1};if(t!==null){o.presence=1,o.single=(t.extraFaces??0)>0?0:1;let d=this.geometryOf(t,e);o.centering=d.centering,o.size=d.size,o.pose=d.pose,o.motion=this.motionOf(d.center,d.iod,s)}else this.lastCenter=null,this.velocityEma=0;let l=Math.min(o.presence,o.single,o.centering,o.size,o.pose,o.sharpness,o.exposure,o.motion);this.p=N(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:o,guidanceKey:this.guidanceOf(o,r,l),ready:h,accepted:l>=this.t.Q_GOOD}}geometryOf(e,t){let{box:r,eyes:s}=e,a={x:t.frameWidth/2,y:t.frameHeight/2},o=Math.min(t.frameWidth,t.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-N(h/(this.t.CENTER_FALLOFF_IOD_MULTIPLE*c)),u=o>0?c/o: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-N(m/this.t.ROLL_MAX_DEG)}return{center:l,iod:c,centering:d,size:v,pose:w}}motionOf(e,t,r){let s=this.lastCenter;if(this.lastCenter={...e,at:r},s===null||t<=0)return 1;let a=(r-s.at)/1e3;if(a<=0)return 1;let o=Math.hypot(e.x-s.x,e.y-s.y)/t/a;o<=this.t.MOTION_DEADBAND_IOD_PER_S&&(o=0);let l=1-Math.exp(-a/this.t.MOTION_TAU_S);return this.velocityEma=l*o+(1-l)*this.velocityEma,1-N(this.velocityEma/this.t.MOTION_VELOCITY_IOD_PER_S)}guidanceOf(e,t,r){if(e.presence<=0)return"fcv3.no_face";if(e.single<=0)return"fcv3.one_face";if(e.size<this.t.GUIDE_SIZE)return this.sizeGuidance();if(e.centering<this.t.GUIDE_CENTERING)return"fcv3.center_face";if(e.pose<this.t.GUIDE_POSE)return"fcv3.straighten";if(e.exposure<this.t.GUIDE_EXPOSURE)return this.exposureGuidance(t);if(e.sharpness<this.t.GUIDE_SHARPNESS)return"fcv3.steady_camera";if(e.motion<this.t.GUIDE_MOTION)return"fcv3.hold_still";if(r<this.t.Q_GOOD){let s=[["size",this.sizeGuidance()],["centering","fcv3.center_face"],["pose","fcv3.straighten"],["exposure",this.exposureGuidance(t)],["sharpness","fcv3.steady_camera"],["motion","fcv3.hold_still"]],a=s[0];for(let o of s)e[o[0]]<e[a[0]]&&(a=o);return a[1]}return"fcv3.hold_still"}sizeGuidance(){return this.lastSizeDirection==="far"?"fcv3.come_closer":"fcv3.move_back"}exposureGuidance(e){let t=(ne[0]+ne[1])/2;return e.meanLuma<t?"fcv3.more_light":"fcv3.too_bright"}},n(W,"k"),W),si=["single","size","centering","pose","exposure","sharpness","motion"];function ai(i){if(i.accepted)return null;if(i.factors.presence<=0)return"no_face";let e="single";for(let t of si)i.factors[t]<i.factors[e]&&(e=t);return e}n(ai,"Ze");var z,st=(z=class{constructor(){this.blocked={},this.acceptedMs=0,this.ticks=0,this.lastAt=null}record(e){let t=this.lastAt===null?0:Math.max(0,e.at-this.lastAt);this.lastAt=e.at,this.ticks+=1;let r=ai(e);if(r===null){this.acceptedMs+=t;return}let s=this.blocked[r]??{count:0,ms:0};s.count+=1,s.ms+=t,this.blocked[r]=s}summary(){let e={};for(let[t,r]of Object.entries(this.blocked))e[t]={count:r.count,ms:Math.round(r.ms)};return{blocked:e,acceptedMs:Math.round(this.acceptedMs),ticks:this.ticks}}},n(z,"w"),z),ni=["obs","manycam","virtual","snap camera","xsplit","droidcam","iriun","camo"],oi=[/^(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 li(i){let e=(i??"").trim().toLowerCase();return e.length===0?"unknown":ni.some(t=>e.includes(t))?"known_virtual":oi.some(t=>t.test(e))?"platform":"unknown"}n(li,"je");function at(i){if(typeof i!="function")return!1;try{return/\{\s*\[native code\]\s*\}\s*$/.test(Function.prototype.toString.call(i))}catch{return!1}}n(at,"Te");function ci(i=globalThis){return at(i.navigator?.mediaDevices?.getUserMedia)&&at(i.MediaStreamTrack?.prototype?.getSettings)}n(ci,"$e");async function hi(i,e=globalThis){let t=e.crypto?.subtle?.digest;if(typeof t=="function")try{let r=new Uint8Array(await t.call(e.crypto?.subtle,"SHA-256",new TextEncoder().encode(i)));return Array.from(r.subarray(0,8),s=>s.toString(16).padStart(2,"0")).join("")}catch{return}}n(hi,"Je");async function ui(i,e=globalThis){let t={};try{t=typeof i.getSettings=="function"?i.getSettings()??{}:{}}catch{t={}}let r={};if((t.facingMode==="user"||t.facingMode==="environment"||t.facingMode==="left"||t.facingMode==="right")&&(r.facingMode=t.facingMode),typeof t.frameRate=="number"&&Number.isFinite(t.frameRate)&&(r.frameRate=t.frameRate),typeof t.width=="number"&&Number.isFinite(t.width)&&(r.width=t.width),typeof t.height=="number"&&Number.isFinite(t.height)&&(r.height=t.height),typeof t.deviceId=="string"&&t.deviceId.length>0){let a=await hi(t.deviceId,e);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:li(s),prototypesIntact:ci(e)}}n(ui,"Ce");var ue=n(i=>Math.round(i*100)/100,"K");function di(i){let e=i,t=typeof e?.requestVideoFrameCallback=="function",r=null,s=null,a=0,o=0,l=0,c=0,h=0,d=0,u=n(()=>{!t||e?.requestVideoFrameCallback===void 0||(r=e.requestVideoFrameCallback((v,w)=>{if(r=null,!t)return;let m=w.presentationTime;if(s!==null){let g=m-s.presentationTimeMs;o+=1;let y=g-l;l+=y/o,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:n(()=>s,"latest"),stats:n(()=>({n:a,meanGapMs:o===0?0:ue(l),stdGapMs:o<2?0:ue(Math.sqrt(c/(o-1))),captureLatencyMs:d===0?null:ue(h/d)}),"stats"),stop:n(()=>{t&&(t=!1,r!==null&&e?.cancelVideoFrameCallback?.(r),r=null)},"stop")}}n(di,"Ee");function fi(i,e,t){return{...i,rvfc:e,rampPainter:t}}n(fi,"_e");var mi=1e3,de="fcv3.hold_upright",pi=200,fe=4,gi=600,vi=1e3,nt={sharpness:1,exposure:1,meanLuma:128};function yi(i,e){return e.width=i.videoWidth,e.height=i.videoHeight,e.getContext("2d").drawImage(i,0,0),new Promise((t,r)=>e.toBlob(s=>s?t(s):r(new Error("empty-keyframe")),"image/jpeg",.92))}n(yi,"it");function wi(){return Y()==="phone"}n(wi,"at");var H,ut=(H=class{constructor(e){this.handlers=new Map,this.stateValue="idle",this.attempt=0,this.stream=null,this.detector=null,this.scheduler=null,this.gate=null,this.profiler=null,this.lastGuidanceKey=null,this.positioningStartedAt=0,this.cameraRequestedAt=null,this.cameraReadyAt=null,this.faceAcquiredAt=null,this.captureCompleteAt=null,this.fired=!1,this.carriedDegrade=0,this.carriedMeans=[],this.blockStats=null,this.lastGateSnapshotAt=Number.NEGATIVE_INFINITY,this.uprightGuard=!1,this.trackProvenance=null,this.ramp=null,this.snapshotCanvas=null,this.options=e,this.facing=e.facingMode??"user"}get state(){return this.stateValue}on(e,t){let r=this.handlers.get(e);return r||(r=new Set,this.handlers.set(e,r)),r.add(t),()=>r?.delete(t)}emit(e,t){for(let r of[...this.handlers.get(e)??[]])r(t)}async start(e={}){e.facingMode!==void 0&&(this.facing=e.facingMode),this.attempt+=1,await this.run(this.attempt)}get facingMode(){return this.facing}retry(){this.teardownAttempt(),this.start()}switchCamera(){this.facing=this.facing==="user"?"environment":"user",this.teardownAttempt(),this.start()}restart(e){this.facing=e,this.teardownAttempt(),this.start()}destroy(){this.attempt+=1,this.teardownAttempt(),this.detector?.destroy(),this.detector=null,this.options.video.srcObject=null}async run(e){let{options:t}=this;this.fired=!1,this.lastGuidanceKey=null,this.carriedDegrade=0,this.carriedMeans=[],this.cameraRequestedAt=null,this.cameraReadyAt=null,this.faceAcquiredAt=null,this.captureCompleteAt=null,this.uprightGuard=(t.isPhone??wi)(),this.setState("preflight");let r=Ue();if(r!=="OK"){this.fail(r==="INSECURE_CONTEXT"?"insecure":"unsupported",{phase:"preflight"});return}this.setState("acquiring");let s=t.getUserMedia??(h=>navigator.mediaDevices.getUserMedia(h)),a;this.cameraRequestedAt=this.now();try{let{facingMode:h,...d}=Se(Ie(),this.facing).video;a=await ze(this.facing,d,{getUserMedia:s,enumerateDevices:ki(t)})}catch(h){if(e!==this.attempt)return;if(h instanceof We){this.fail("backcamera",{phase:"acquiring",name:j(h)});return}this.fail(Le(h),{phase:"acquiring",name:j(h)});return}if(xe(a),qe(a),e!==this.attempt){for(let h of a.getTracks())h.stop();return}this.stream=a;let o=a.getVideoTracks?.()[0];if(this.trackProvenance=o===void 0?null:ui(o).catch(()=>null),this.facing=Ae(a)??this.facing,t.video.srcObject=a,await t.video.play().catch(()=>{}),e!==this.attempt)return;if(this.cameraReadyAt=this.now(),this.detector===null){let h={v3AssetBaseUrl:t.v3AssetBaseUrl},d=t.createDetector??(t.createWorker!==void 0&&Qe()?async()=>{try{return await Je.create(t.createWorker(),h)}catch{return x(h)}}:()=>x(h)),u;try{u=await d()}catch(v){e===this.attempt&&this.fail("models",{phase:"models",name:j(v)},v instanceof he?v.fallbackReason:Mi(v));return}if(e!==this.attempt){u.destroy();return}this.detector=u,this.options.telemetry?.({type:"detector",tier:u.tier,fallbackReason:u.fallbackReason})}let l=He(),c=t.deviceClass??Ke(l);this.profiler=new Xe(c),this.options.telemetry?.({type:"profile",staticClass:c,activeClass:this.profiler.deviceClass,simd:l.simd}),this.gate=new rt(t.thresholds??{}),this.blockStats=new st,this.lastGateSnapshotAt=this.now(),t.rankKeyframes?.()&&import("./keyframe-rank-YAJLYJYF-WCA6RPMD.js").then(h=>me=h,()=>{}),this.setState("positioning"),this.positioningStartedAt=this.now(),this.startScheduler(e)}get animations(){return this.profiler?.profile.animations??"full"}startScheduler(e){let t=this.profiler;if(t===null)return;if(this.scheduler!==null){let s=this.scheduler.stats();this.carriedDegrade+=s.degradeCount,s.meanDetectMs>0&&this.carriedMeans.push(s.meanDetectMs),this.scheduler.stop()}let r=new ii({cadenceHz:t.profile.cadenceHz,video:this.options.video,now:this.options.now,run:n(()=>this.detectTick(e),"run")});this.scheduler=r,r.start()}async detectTick(e){let{detector:t,gate:r,profiler:s}=this,a=this.options.video;if(e!==this.attempt||t===null||r===null||s===null||this.fired||a.videoWidth===0)return;if(this.isLandscape()){this.holdUpright(e);return}let o=s.deviceClass,l=this.now(),c=this.options.makeSnapshot?.(a,s.profile.inputWidth)??this.defaultSnapshot(a,s.profile.inputWidth),h=null;try{h=await t.detect(c,a.videoWidth,a.videoHeight)}catch{h=null}if(e!==this.attempt||this.fired)return;s.record(this.now()-l),s.deviceClass!==o&&this.startScheduler(e);let d=h===null?nt: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>=mi&&(this.lastGateSnapshotAt=u.at,this.reportGate(!1)),this.emit("checks",{engine:"v3",progress:u.p,q:u.q,factors:u.factors,attempt:e}),u.guidanceKey!==this.lastGuidanceKey&&(this.lastGuidanceKey=u.guidanceKey,this.emit("guidance",{key:u.guidanceKey})),u.ready&&this.stateValue==="positioning"&&(this.fired=!0,this.captureCompleteAt=u.at,this.fire(e))}async fire(e){let{options:t}=this,r=this.scheduler;r?.stop(),this.reportGate(!0);let s=r?.stats()??{degradeCount:0,meanDetectMs:0},a=[...this.carriedMeans,...s.meanDetectMs>0?[s.meanDetectMs]:[]];t.telemetry?.({type:"fired",timeToGateMs:this.now()-this.positioningStartedAt,degradeCount:this.carriedDegrade+s.degradeCount,meanDetectMs:a.length===0?0:a.reduce((T,b)=>T+b,0)/a.length});let o=t.mode??"clip",l=t.rankKeyframes?.()&&me?me.default(this,e).catch(()=>this.collectKeyframes(e)):this.collectKeyframes(e);if(o==="photo"){let T=this.watchRotation(e,null),b=await l;if(T(),e!==this.attempt)return;if(b===null){this.fail("generic",{phase:"keyframes"});return}let A=await this.provenance({n:0,meanGapMs:0,stdGapMs:0,captureLatencyMs:null},!1);if(e!==this.attempt)return;this.finishCapture({keyframe:b.blob,previewDataUrl:b.previewDataUrl,...A});return}this.setState("recording");let c=this.stream;if(c===null){this.fail("generic",{phase:"recording"});return}let h=t.screenRamp?.(),d=pe(h),u=null;l.then(T=>{u=T},()=>{});let v=n(()=>{e===this.attempt&&u!==null&&this.emit("frozen",{previewDataUrl:u.previewDataUrl})},"f"),w=Jt(h,ht),m=null,g,y=0;try{let T=this.recordTake(e,c,h,w,void 0).then(S=>S,S=>({failed:S})),[b,A]=await Promise.all([T,l]);if(g=A,e!==this.attempt)return;if("failed"in b){if(b.failed.kind==="cliptoolarge")throw b.failed;et(b.failed.requestedMimeType??"")}else m=b,it(b.clip,w)?b.clip.stats===null&&et(b.clip.requestedMimeType??""):v();if(m===null||it(m.clip,w)){y=1,t.telemetry?.({type:"clip_retake",reason:m===null?"error":m.clip.stats===null?"unreadable":"short"});let S=null;try{S=await this.recordTake(e,c,h,w,v)}catch(K){if(m===null)throw K}if(e!==this.attempt)return;S!==null&&(m===null||Xt(S.clip,m.clip))&&(m=S),S===null&&v()}}catch(T){if(e!==this.attempt)return;let b=T.kind;this.fail(b==="cliptoolarge"?"cliptoolarge":"recorder",{phase:"recording",name:j(T)});return}if(m===null){this.fail("recorder",{phase:"recording"});return}let{clip:p,rvfc:M,report:E}=m;if(ae(p.blob)){this.fail("cliptoolarge",{phase:"recording"});return}if(g===null){this.fail("generic",{phase:"keyframes"});return}let I=await this.provenance(M,d);e===this.attempt&&this.finishCapture({clip:p.blob,clipMimeType:p.mimeType,...p.stats?{clipStats:p.stats}:{},clipRetakes:y,keyframe:g.blob,previewDataUrl:g.previewDataUrl,...E!==void 0&&E.rendered.length>0?{screenRamp:E}:{},...I})}async recordTake(e,t,r,s,a){let o=this.options.createRecorder?.()??new Zt({now:n(()=>this.now(),"now")}),l=di(this.options.video),c=ei(r,{paint:n(u=>{(u===null||e===this.attempt)&&this.emit("ramp",{colour:u})},"paint"),now:n(()=>this.now(),"now"),frames:l.latest});this.ramp=c;let h=n(()=>{l.stop(),c.stop(),this.ramp===c&&(this.ramp=null)},"l"),d=this.watchRotation(e,o);try{return{clip:await o.record(t,a,()=>c.started(this.now()),s,l),rvfc:l.stats(),report:c.report()}}finally{d(),h()}}async provenance(e,t){let r=this.trackProvenance;if(r===null)return{};let s,a=new Promise(l=>{s=setTimeout(()=>l(null),vi)}),o=await Promise.race([r,a]);return clearTimeout(s),o===null?{}:{provenance:fi(o,e,t)}}isLandscape(){let e=this.options.video;return this.uprightGuard&&e.videoWidth>e.videoHeight}holdUpright(e){this.gate?.reset(),this.emit("checks",{engine:"v3",progress:0,q:0,factors:{presence:0,single:1,centering:0,size:0,pose:0,sharpness:0,exposure:0,motion:0},attempt:e}),this.lastGuidanceKey!==de&&(this.lastGuidanceKey=de,this.emit("guidance",{key:de}))}watchRotation(e,t){if(!this.uprightGuard)return()=>{};let r=this.options.video,s=n(()=>{if(e!==this.attempt||t!==null&&this.stateValue!=="recording"){l();return}r.videoWidth>0&&this.isLandscape()&&(l(),this.abortRecording(e,t))},"n"),a=setInterval(s,pi);r.addEventListener?.("resize",s);let o=!1;function l(){o||(o=!0,clearInterval(a),r.removeEventListener?.("resize",s))}return n(l,"o"),l}abortRecording(e,t){if(e!==this.attempt)return;this.attempt+=1;let r=this.attempt;try{t?.stop()}catch{}this.ramp?.stop(),this.ramp=null,this.fired=!1,this.captureCompleteAt=null,this.gate=new rt(this.options.thresholds??{}),this.blockStats=new st,this.lastGateSnapshotAt=this.now(),this.lastGuidanceKey=null,this.setState("positioning"),this.positioningStartedAt=this.now(),this.holdUpright(r),this.startScheduler(r)}async collectKeyframes(e){let t=this.options.captureKeyframe??(a=>this.defaultKeyframe(a)),r=gi/(fe-1),s=null;for(let a=0;a<fe;a+=1){if(e!==this.attempt)return s;try{let o=await t(this.options.video);(s===null||o.sharpness>s.sharpness)&&(s=o)}catch{}a<fe-1&&await bi(r)}return s}finishCapture(e){this.stopTracks(),this.setState("captured");let t=this.captureTiming();this.emit("artifacts",t===void 0?e:{...e,timing:t})}captureTiming(){let e={},t=n((r,s,a)=>{s!==null&&a!==null&&(e[r]=Math.max(0,Math.round(a-s)))},"t");return t("cameraReadyMs",this.cameraRequestedAt,this.cameraReadyAt),t("faceAcquireMs",this.cameraReadyAt,this.faceAcquiredAt),t("captureMs",this.faceAcquiredAt,this.captureCompleteAt),Object.keys(e).length>0?e:void 0}async defaultKeyframe(e){let t=document.createElement("canvas"),r=await(this.facing==="user"?ti:yi)(e,t),s=t.toDataURL("image/jpeg",.92);return{blob:r,previewDataUrl:s,sharpness:this.centerSharpness(e)}}defaultSnapshot(e,t){try{let r=this.snapshotCanvas??document.createElement("canvas"),s=t/Math.max(1,e.videoWidth),a=Math.max(1,Math.round(e.videoWidth*s)),o=Math.max(1,Math.round(e.videoHeight*s)),l=r.getContext("2d");return l===null?e:(r.width!==a&&(r.width=a),r.height!==o&&(r.height=o),l.drawImage(e,0,0,a,o),this.snapshotCanvas=r,r)}catch{return e}}defaultQuality(e,t){let r=ot(e,t,96);return r===null?nt:{sharpness:oe(r),exposure:Ve(r),meanLuma:Ze(r)}}centerSharpness(e){let t=Q(e),r=ot(e,{x:t.width*.25,y:t.height*.25,width:t.width*.5,height:t.height*.5},96);return r===null?0:oe(r)}teardownAttempt(){this.scheduler?.stop(),this.scheduler=null,this.reportGate(!0),this.gate=null,this.ramp?.stop(),this.ramp=null,this.stopTracks()}reportGate(e){let t=this.blockStats,r=this.profiler;if(t===null||r===null)return;let s=t.summary();e&&(this.blockStats=null),s.ticks!==0&&this.options.telemetry?.({type:"gate",final:e,activeClass:r.deviceClass,cadenceHz:r.profile.cadenceHz,...s})}stopTracks(){if(this.stream!==null){for(let e of this.stream.getTracks())e.stop();this.stream=null}}fail(e,t,r){this.scheduler?.stop(),this.reportGate(!0),this.stopTracks(),this.setState("error"),this.options.telemetry?.({type:"error",kind:e,fallbackReason:r});let{phase:s,name:a}=t;this.emit("error",{kind:e,retryable:e!=="insecure"&&e!=="unsupported",detail:a===void 0?{phase:s}:{phase:s,name:a}})}setState(e){this.stateValue=e,this.emit("statechange",{state:e})}now(){return this.options.now?.()??performance.now()}},n(H,"ke"),H),me;function bi(i){return new Promise(e=>setTimeout(e,i))}n(bi,"st");function Mi(i){return i instanceof Error?i.message:String(i)}n(Mi,"ot");function ot(i,e,t){try{let r=document.createElement("canvas"),s=t/Math.max(1,e.width);r.width=Math.max(1,Math.round(e.width*s)),r.height=Math.max(1,Math.round(e.height*s));let a=r.getContext("2d");return a===null?null:(a.drawImage(i,e.x,e.y,e.width,e.height,0,0,r.width,r.height),a.getImageData(0,0,r.width,r.height))}catch{return null}}n(ot,"we");function ki(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()}n(ki,"lt");var Ti=12e4,dt=13e4,_i=3e3,Ei=1200,ge=Symbol.for("@sekyro/web.preload.v1");function ye(){let i=globalThis;return i[ge]??(i[ge]=new Map),i[ge]}n(ye,"h");function te(i){let e=(i??ce).replace(/\/+$/,"");return e===""?"/":e}n(te,"b");function mt(i){let e=ye(),t=e.get(i);return t===void 0&&(t={status:"idle",promise:null,scheduled:null,detectorPromise:null,detector:null,listeners:new Set},e.set(i,t)),t}n(mt,"ae");function ve(i,e){if(i.status!==e){i.status=e;for(let t of[...i.listeners])t(e)}}n(ve,"k");var Si=n(i=>x({preferred:["blaze"],v3AssetBaseUrl:i,blazeInitTimeoutMs:Ti}),"K"),Ii=Si;function Ai(){return typeof window<"u"&&typeof navigator<"u"&&typeof navigator.mediaDevices?.getUserMedia=="function"}n(Ai,"Ce");function xi(){return navigator.connection?.saveData===!0}n(xi,"Se");function Di(i){let e=window;if(typeof e.requestIdleCallback=="function"){let r=e.requestIdleCallback(i,{timeout:_i});return()=>e.cancelIdleCallback?.(r)}let t=setTimeout(i,Ei);return()=>clearTimeout(t)}n(Di,"Ee");function Ri(i,e){let t,r=new Promise(l=>{t=l}),s=!1,a=n(()=>{},"u"),o={promise:r,settle:n(l=>{s||(s=!0,a(),i.scheduled===o&&(i.scheduled=null),t(l))},"settle")};return i.scheduled=o,a=Di(()=>{s||o.settle(we(i,e))}),r}n(Ri,"ye");function we(i,e){if((i.status==="loading"||i.status==="ready")&&i.promise!==null)return i.promise;ve(i,"loading");let t=new Promise(o=>o(Ii(e)));i.detectorPromise=t;let r,s=new Promise((o,l)=>{r=setTimeout(()=>{t.then(c=>c.destroy(),()=>{}),l(new Error(`detector preload exceeded ${dt} ms`))},dt)}),a=Promise.race([t,s]).then(o=>i.detectorPromise!==t?(o.destroy(),i.status):(i.detector=o,ve(i,"ready"),"ready"),o=>(i.detectorPromise===t&&(i.detectorPromise=null,i.detector=null,ve(i,"failed"),console.warn("[@sekyro/web] face-detector preload failed:",o)),i.status)).finally(()=>clearTimeout(r));return i.promise=a,i.scheduled?.settle(a),a}n(we,"U");function sr(i={}){if(!Ai())return Promise.resolve("idle");let e=te(i.assetBaseUrl),t=mt(e);return i.respectSaveData===!0&&xi()?Promise.resolve(t.status):(t.status==="loading"||t.status==="ready")&&t.promise!==null?t.promise:i.idle===!0?t.scheduled?.promise??Ri(t,e):we(t,e)}n(sr,"xe");function ar(i){return ye().get(te(i))?.status??"idle"}n(ar,"Fe");function nr(i,e){let t=mt(te(e));return t.listeners.add(i),()=>{t.listeners.delete(i)}}n(nr,"Ie");function Ci(i){return{get tier(){return i.tier},get fallbackReason(){return i.fallbackReason},detect:n((...e)=>i.detect(...e),"detect"),destroy:n(()=>{},"destroy")}}n(Ci,"Le");function Oi(i){let e=te(i),t=ye().get(e);if(!(t===void 0||t.detector===null&&t.detectorPromise===null&&t.scheduled===null))return async()=>{t.scheduled!==null&&we(t,e);let r=t.promise;for(;t.detector===null&&r!==null&&(await r,t.promise!==r);)r=t.promise;return t.detector!==null?Ci(t.detector):x({v3AssetBaseUrl:e})}}n(Oi,"de");var Gi=new Set(["inuse","overconstrained","notfound"]),Pi=[500,1500];function Ui(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}}n(Ui,"Ae");function Fi(i){switch(i){case"preflight":case"acquiring":return"starting";case"positioning":return"gating";default:return i}}n(Fi,"Pe");function ft(i){switch(i){case"permission":case"notfound":case"inuse":case"insecure":case"unsupported":return i;case"backcamera":return"notfound";default:{let e=i;return"generic"}}}n(ft,"ue");function Ni(i,e,t){if(t===void 0)return{kind:ft(i),retryable:e};let r=Be(t.name);return{kind:ft(i),retryable:e,detail:{...r!==void 0?{name:r}:{},phase:t.phase,engineKind:i}}}n(Ni,"we");var Bi=new Set(["captured","uploading","checking"]);function Li(i,e={},t,r=()=>"self",s=()=>{},a){let o=e.now??(()=>performance.now()),l=e.canChooseFacing??Re,c="user",h=Ce(),d=r(),u=De(),v=!Fe(),w=e.engineOptions,m=w?.createDetector===void 0&&w?.createWorker===void 0?{createDetector:n(()=>{let f=Oi(i.assetBaseUrl);return f!==void 0?f():x({v3AssetBaseUrl:i.assetBaseUrl})},"createDetector")}:{},g={video:i.video,mode:v?"photo":"clip",rankKeyframes:t,facingMode:void 0,v3AssetBaseUrl:i.assetBaseUrl,screenRamp:n(()=>d==="self"&&u.count("ramp")>0?s():void 0,"screenRamp"),...e.engineOptions??{},...m},y=e.createEngine?.(g)??new ut(g),p="idle",M=null,E=0,I=!1,T="full",b=null,A=null,S=0,K=0,be=n(()=>{i.video.videoWidth>0&&i.video.videoHeight>0&&(S=i.video.videoWidth,K=i.video.videoHeight)},"W"),Me=Oe({enabled:i.keepScreenAwake!==!1}),X=n(f=>{p=f,Me.setActive(f==="starting"||f==="gating"||f==="recording"),u.emit("state",f)},"S"),ie=n(()=>u.emit("gate",{progress:E,hint:M,faceDetected:I}),"F"),re=n(()=>{let f=y.animations??"full";f!==T&&(T=f,u.emit("profile",{animations:T}))},"I"),G=0,$=null,pt=e.schedule??((f,k)=>{let _=setTimeout(f,k);return()=>clearTimeout(_)}),Z=n(()=>{$?.(),$=null},"E"),gt=n((f,k)=>{if(V||!Gi.has(f)||k?.phase!=="acquiring")return!1;let _=Pi[G];return _===void 0?!1:(G+=1,Z(),$=pt(()=>{$=null,V||y.retry()},_),!0)},"fe"),vt=[y.on("statechange",({state:f})=>{if(f==="error")return;let k=Fi(f);k==="gating"&&(G=0),k==="starting"&&p!=="starting"&&(M=null,E=0,I=!1,b=null,A=null,S=0,K=0),X(k),re(),k==="recording"&&(be(),b=o(),M="hold",E=1,ie())}),y.on("checks",f=>{be(),E=f.progress,I=f.factors.presence>0,ie(),re()}),y.on("guidance",({key:f})=>{M=Ui(f),ie()}),y.on("frozen",({previewDataUrl:f})=>{A=o(),u.emit("frozen",{previewDataUrl:f})}),y.on("ramp",f=>u.emit("ramp",f)),y.on("artifacts",f=>{if(p!=="captured")return;let k=Y(),_=f.clipStats,_e=_!==void 0?Math.round(_.durationMs):b!==null&&A!==null?Math.max(0,Math.round(A-b)):void 0,Ee=_!==void 0&&_.frames>1&&_.durationMs>0?Math.round(_.frames*1e4/_.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||S,height:i.video.videoHeight||K,..._e!==void 0?{clipMs:_e}:{},..._!==void 0?{clipFrames:_.frames}:{},...Ee!==void 0?{fps:Ee}:{},...f.clipRetakes!==void 0?{clipRetakes:f.clipRetakes}:{},...f.clipMimeType!==void 0?{codec:ct(f.clipMimeType)}:{},captureChannel:k==="desktop"?"desktop":"mobile",formFactor:k,...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:k,detail:_})=>{f==="backcamera"&&yt()||gt(f,_)||(X("error"),re(),u.emit("error",Ni(f,k,_)))})],ke=!1;function yt(){return V||ke||d!=="assisted"||a===void 0||a.session()!=="choice"?!1:(ke=!0,a.onModeChange("self"),d="self",c=se("self"),X("mode_switch"),y.restart(c),!0)}n(yt,"me");let Te=n(async()=>a!==void 0&&a.session()==="choice"&&await l().catch(()=>!1),"$"),V=!1;return{handle:{get state(){return p},get captureMode(){return r()},get facingMode(){return y.facingMode??c},on:n((f,k)=>u.on(f,k),"on"),start:n(f=>(d=r(),h.facing(d,i.facing),c=h.facing(d,f?.facing),Z(),G=0,y.start({facingMode:c})),"start"),retry:n(()=>{Z(),G=0,y.retry()},"retry"),switchCamera:n(()=>h.refuseSwitch(r()),"switchCamera"),canSwitchCaptureMode:Te,setCaptureMode:n(async f=>{if(f===r()||!await Te()||V||Bi.has(p)||a===void 0)return!1;a.onModeChange(f),d=f;let k=se(f);return c=k,p==="idle"||(X("mode_switch"),Z(),G=0,y.restart(k)),!0},"setCaptureMode"),destroy:n(()=>{V=!0,Z();for(let f of vt)f();Me.setActive(!1),y.destroy(),u.clear()},"destroy")},setFlowState:n(f=>{p!==f&&X(f)},"setFlowState")}}n(Li,"De");function or(i){return Li(i).handle}n(or,"Ze");export{$i as a,sr as b,ar as c,nr as d,Ni as e,Li as f,or as g};
@@ -1 +1 @@
1
- import{a as d}from"./chunk-SOI356LX.js";import{a as t}from"./chunk-5QL6W6FW.js";import{a as i,c as r}from"./chunk-4FHWXBOB.js";var s=r(d(),1);var u=(0,s.createContext)(null);function c(a,n,o){let e=n.detail;return{check:a,kind:n.kind,...e?.name!==void 0?{name:e.name}:{},...e?.phase!==void 0?{phase:e.phase}:{},...e?.engineKind!==void 0?{engineKind:e.engineKind}:{},attempt:Math.max(0,Math.min(1e3,o))}}i(c,"a");t(c,"captureIssueOf");function m(a,n){if(a!==void 0)try{a(n)}catch{}}i(m,"o");t(m,"sendCaptureIssue");export{u as a,c as b,m as c};
1
+ import{a as d}from"./chunk-JJ3Q52P3.js";import{a as t}from"./chunk-5QL6W6FW.js";import{a as i,c as r}from"./chunk-4FHWXBOB.js";var s=r(d(),1);var u=(0,s.createContext)(null);function c(a,n,o){let e=n.detail;return{check:a,kind:n.kind,...e?.name!==void 0?{name:e.name}:{},...e?.phase!==void 0?{phase:e.phase}:{},...e?.engineKind!==void 0?{engineKind:e.engineKind}:{},attempt:Math.max(0,Math.min(1e3,o))}}i(c,"a");t(c,"captureIssueOf");function m(a,n){if(a!==void 0)try{a(n)}catch{}}i(m,"o");t(m,"sendCaptureIssue");export{u as a,c as b,m as c};