@sekyro/elements 0.1.0-rc.15 → 0.1.0-rc.16

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 (85) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/cdn/chunks/{capture-session-doc-KAKQJPCO-AIHWPBYL.js → capture-session-doc-LKMMJG4H-GQNWHWDA.js} +1 -1
  3. package/dist/cdn/chunks/{chunk-QXCB7CMC.js → chunk-3DAULGZ2.js} +1 -1
  4. package/dist/cdn/chunks/{chunk-CAEMCBEY.js → chunk-7T4LO7VD.js} +1 -1
  5. package/dist/cdn/chunks/{chunk-BSMEALQQ.js → chunk-BR5RW4XZ.js} +1 -1
  6. package/dist/cdn/chunks/{chunk-SI3OCSQL.js → chunk-DHMC5D6M.js} +1 -1
  7. package/dist/cdn/chunks/{chunk-IEZ4K3YX.js → chunk-DQGAOSBX.js} +1 -1
  8. package/dist/cdn/chunks/{chunk-PJT5EI2V.js → chunk-EMKK7NJU.js} +1 -1
  9. package/dist/cdn/chunks/{chunk-JDVZXXYF.js → chunk-F5GIBIWU.js} +1 -1
  10. package/dist/cdn/chunks/{chunk-NLTAFWIN.js → chunk-H5T4U7DM.js} +1 -1
  11. package/dist/cdn/chunks/{chunk-ZEUFK4EC.js → chunk-HOSTJBJM.js} +1 -1
  12. package/dist/cdn/chunks/chunk-IO5LQDY2.js +33 -0
  13. package/dist/cdn/chunks/chunk-Q7ACZDU4.js +1 -0
  14. package/dist/cdn/chunks/{chunk-OCMUHHDC.js → chunk-QR7XWTXK.js} +1 -1
  15. package/dist/cdn/chunks/{chunk-TWWD2WAW.js → chunk-R5I4TYXJ.js} +1 -1
  16. package/dist/cdn/chunks/{chunk-OGJRFKPJ.js → chunk-TDAUIJGS.js} +1 -1
  17. package/dist/cdn/chunks/{chunk-LVBGPPKD.js → chunk-TGVU2IVC.js} +1 -1
  18. package/dist/cdn/chunks/{chunk-TT57CQGK.js → chunk-TIOXYUT7.js} +2 -2
  19. package/dist/cdn/chunks/{chunk-2YPWGFSK.js → chunk-UTTEUW7M.js} +1 -1
  20. package/dist/cdn/chunks/{chunk-HOUFBXEP.js → chunk-VGBSCCXD.js} +1 -1
  21. package/dist/cdn/chunks/{chunk-BLN4F6B2.js → chunk-XFUL5N47.js} +1 -1
  22. package/dist/cdn/chunks/{chunk-3SVGT2PS.js → chunk-YLCUWE22.js} +1 -1
  23. package/dist/cdn/chunks/{chunk-E75YC36S.js → chunk-Z6KNLRUW.js} +1 -1
  24. package/dist/cdn/chunks/{create-document-capture-AITCB4ZU-QA2Z7I3D.js → create-document-capture-PG6NLCPH-SB25EXKH.js} +1 -1
  25. package/dist/cdn/chunks/document-capture-view-I72R2TZK-IPPKCL3Y.js +1 -0
  26. package/dist/cdn/chunks/{eid-view-PWROMDEV-NH4432Y2.js → eid-view-ZM7QAEME-HFAGVDCQ.js} +1 -1
  27. package/dist/cdn/chunks/{email-otp-view-Q334LLOM-RYZD4GMU.js → email-otp-view-EYS26ZZM-5WX42RSL.js} +1 -1
  28. package/dist/cdn/chunks/{flow-views-I3YI3NWV-ENMBLDRD.js → flow-views-7SAYQQ62-4RKPVVBZ.js} +1 -1
  29. package/dist/cdn/chunks/{form-view-XPOGTYL6-R34DVU6J.js → form-view-Y5KA6R5T-KP2XRJQ7.js} +1 -1
  30. package/dist/cdn/chunks/overlay-de-4OISTBDL-WWT74VG7.js +1 -0
  31. package/dist/cdn/chunks/overlay-es-YO5UCAO2-U3OAELIS.js +1 -0
  32. package/dist/cdn/chunks/overlay-pt-E7PSFLLQ-ZPN4CLS4.js +1 -0
  33. package/dist/cdn/chunks/plan-runner-BZ7LODPB-KXZ5UKVT.js +1 -0
  34. package/dist/cdn/chunks/{portrait-capture-view-G4BE6IVC-73TWN235.js → portrait-capture-view-E5LKQQ5Y-MZ3BOZEU.js} +1 -1
  35. package/dist/cdn/chunks/{portrait-review-view-WGI5PXWF-ZJH3G4DR.js → portrait-review-view-NJHH2E4W-5UKV267T.js} +1 -1
  36. package/dist/cdn/chunks/{proof-of-address-view-CFVHB2XR-3RJQNRNW.js → proof-of-address-view-LS3JZUTD-WPPCFOIG.js} +1 -1
  37. package/dist/cdn/define.js +1 -1
  38. package/dist/cdn/index.js +1 -1
  39. package/dist/{chunk-YEY23NFE.js → chunk-2WYXQYNY.js} +1 -1
  40. package/dist/chunk-4JHVEBTX.js +33 -0
  41. package/dist/{chunk-YYQZMOGI.js → chunk-5NSMKCTW.js} +1 -1
  42. package/dist/{chunk-QESP3Y4J.js → chunk-6NNMOFMF.js} +1 -1
  43. package/dist/{chunk-BLT5ZVGV.js → chunk-734Y6RUV.js} +1 -1
  44. package/dist/{chunk-4LFDPSOL.js → chunk-AJHRPKD4.js} +1 -1
  45. package/dist/{chunk-DGVIPMH7.js → chunk-D3TZZ4SI.js} +1 -1
  46. package/dist/{chunk-L2D3XWI2.js → chunk-ICJ544T4.js} +1 -1
  47. package/dist/{chunk-JLKISVND.js → chunk-MWTOWGEI.js} +1 -1
  48. package/dist/{chunk-DZ64G3BB.js → chunk-VJZANYM3.js} +1 -1
  49. package/dist/{chunk-M6FHHGY7.js → chunk-WLCS5VAA.js} +1 -1
  50. package/dist/chunk-XI37ATRU.js +1 -0
  51. package/dist/{chunk-H2EODYM3.js → chunk-YVGOUZ7T.js} +1 -1
  52. package/dist/{chunk-PDYEWDSG.js → chunk-ZUFN5VIE.js} +1 -1
  53. package/dist/define.cjs +5 -5
  54. package/dist/define.js +1 -1
  55. package/dist/document-capture-view-I72R2TZK-LCX5EQJR.js +1 -0
  56. package/dist/{eid-view-PWROMDEV-5AMVHINZ.js → eid-view-ZM7QAEME-7FRC3TV6.js} +1 -1
  57. package/dist/{email-otp-view-Q334LLOM-WWVHZUZ3.js → email-otp-view-EYS26ZZM-EESWRHKM.js} +1 -1
  58. package/dist/{flow-views-I3YI3NWV-5FHNXBHD.js → flow-views-7SAYQQ62-3NIWXTDB.js} +1 -1
  59. package/dist/{form-view-XPOGTYL6-NGLOEF3Y.js → form-view-Y5KA6R5T-DOZFYGBK.js} +1 -1
  60. package/dist/index.cjs +5 -5
  61. package/dist/index.d.cts +9 -0
  62. package/dist/index.d.ts +9 -0
  63. package/dist/index.js +1 -1
  64. package/dist/overlay-de-4OISTBDL-TH46LT3S.js +1 -0
  65. package/dist/overlay-es-YO5UCAO2-NBICE576.js +1 -0
  66. package/dist/overlay-pt-E7PSFLLQ-NCA5NABT.js +1 -0
  67. package/dist/{portrait-capture-view-G4BE6IVC-5UKZX7HH.js → portrait-capture-view-E5LKQQ5Y-E3BRULLL.js} +1 -1
  68. package/dist/{portrait-review-view-WGI5PXWF-PITOWYGV.js → portrait-review-view-NJHH2E4W-CKMVD7ME.js} +1 -1
  69. package/dist/{proof-of-address-view-CFVHB2XR-Y6DJUU4V.js → proof-of-address-view-LS3JZUTD-ZQ4BDFNP.js} +1 -1
  70. package/dist/styles.css +9 -1
  71. package/package.json +2 -2
  72. package/sbom.cdx.json +4 -4
  73. package/dist/cdn/chunks/chunk-2QSUUXLJ.js +0 -1
  74. package/dist/cdn/chunks/chunk-I7TF57NI.js +0 -33
  75. package/dist/cdn/chunks/document-capture-view-FSMO25KF-2Q3A6GDQ.js +0 -1
  76. package/dist/cdn/chunks/overlay-de-VMGXTY3V-VVLXUOLW.js +0 -1
  77. package/dist/cdn/chunks/overlay-es-45YNJBVM-RHH5Z6UY.js +0 -1
  78. package/dist/cdn/chunks/overlay-pt-EU4FBZ2U-OHSSK5RZ.js +0 -1
  79. package/dist/cdn/chunks/plan-runner-HPXZHAQB-N2UJCZUV.js +0 -1
  80. package/dist/chunk-73RGTE4Z.js +0 -1
  81. package/dist/chunk-AXDGT3L2.js +0 -33
  82. package/dist/document-capture-view-FSMO25KF-FFRQD2FZ.js +0 -1
  83. package/dist/overlay-de-VMGXTY3V-3AGJDOK3.js +0 -1
  84. package/dist/overlay-es-45YNJBVM-WHWUGDQ6.js +0 -1
  85. package/dist/overlay-pt-EU4FBZ2U-F34MGCNE.js +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @sekyro/elements
2
2
 
3
+ ## 0.1.0-rc.16
4
+
5
+ ### Patch Changes
6
+
7
+ - Carries the @sekyro/react release of this version: the changes in its changelog reach the element.
8
+ - Updated dependencies [8bbc6f8]
9
+ - @sekyro/web@0.1.0-rc.36
10
+
3
11
  ## 0.1.0-rc.15
4
12
 
5
13
  ### Patch Changes
@@ -1 +1 @@
1
- import{c as a,d as s,e as o,f as r,g as _,h as t,i as A,j as C,k as D,l as p,m as i}from"./chunk-PJT5EI2V.js";import"./chunk-Z25MPNSU.js";import"./chunk-3NOBU7TE.js";import"./chunk-QWPURAKS.js";import"./chunk-L22GFJQV.js";import"./chunk-ZEUFK4EC.js";import"./chunk-P7K7ELYZ.js";import"./chunk-JS2IXPNL.js";import"./chunk-4FHWXBOB.js";export{i as CAPTURE_CANDIDATE_SPACING_MS,p as CAPTURE_EXTRA_CANDIDATES,C as CaptureSessionDoc,o as DOC_BLACK_FRAME_LUMA,r as DOC_BLACK_FRAME_TICKS,_ as DOC_CADENCE_HZ,s as DOC_FIRST_FRAME_MS,t as DOC_SHUTTER_DEFAULTS,D as passportBandOf,A as resolveDocShutterTuning,a as warmDocDetector};
1
+ import{c as a,d as s,e as o,f as r,g as _,h as t,i as A,j as C,k as D,l as p,m as i}from"./chunk-EMKK7NJU.js";import"./chunk-Z25MPNSU.js";import"./chunk-3NOBU7TE.js";import"./chunk-QWPURAKS.js";import"./chunk-L22GFJQV.js";import"./chunk-HOSTJBJM.js";import"./chunk-P7K7ELYZ.js";import"./chunk-JS2IXPNL.js";import"./chunk-4FHWXBOB.js";export{i as CAPTURE_CANDIDATE_SPACING_MS,p as CAPTURE_EXTRA_CANDIDATES,C as CaptureSessionDoc,o as DOC_BLACK_FRAME_LUMA,r as DOC_BLACK_FRAME_TICKS,_ as DOC_CADENCE_HZ,s as DOC_FIRST_FRAME_MS,t as DOC_SHUTTER_DEFAULTS,D as passportBandOf,A as resolveDocShutterTuning,a as warmDocDetector};
@@ -1 +1 @@
1
- import{b,t as r,v as l,y as o}from"./chunk-E75YC36S.js";import{a as i}from"./chunk-5QL6W6FW.js";import{a,c as p}from"./chunk-4FHWXBOB.js";var s=p(b(),1);function f({tone:d,icon:n,busy:c,title:m,titleId:e,children:u,actions:t,live:y,testId:h}){let k=r();return(0,s.jsxs)("section",{className:"sekyro-step sekyro-status",...e!==void 0?{"aria-labelledby":e}:{},...y?{role:"status","aria-live":"polite"}:{},"data-testid":h,children:[(0,s.jsxs)("div",{className:"sekyro-status__body",children:[(0,s.jsx)("span",{className:`sekyro-tile sekyro-tile--${d}${c?" is-busy":""}`,"aria-hidden":"true",children:(0,s.jsx)(l,{name:n})}),(0,s.jsxs)("div",{className:"sekyro-heading sekyro-status__text",children:[(0,s.jsx)("h2",{id:e,ref:k,tabIndex:-1,className:"sekyro-text-body",children:m}),u]})]}),t!=null&&t!==!1?(0,s.jsx)(o,{children:t}):null]})}a(f,"g");i(f,"StatusPage");export{f as a};
1
+ import{b,t as r,v as l,y as o}from"./chunk-Z6KNLRUW.js";import{a as i}from"./chunk-5QL6W6FW.js";import{a,c as p}from"./chunk-4FHWXBOB.js";var s=p(b(),1);function f({tone:d,icon:n,busy:c,title:m,titleId:e,children:u,actions:t,live:y,testId:h}){let k=r();return(0,s.jsxs)("section",{className:"sekyro-step sekyro-status",...e!==void 0?{"aria-labelledby":e}:{},...y?{role:"status","aria-live":"polite"}:{},"data-testid":h,children:[(0,s.jsxs)("div",{className:"sekyro-status__body",children:[(0,s.jsx)("span",{className:`sekyro-tile sekyro-tile--${d}${c?" is-busy":""}`,"aria-hidden":"true",children:(0,s.jsx)(l,{name:n})}),(0,s.jsxs)("div",{className:"sekyro-heading sekyro-status__text",children:[(0,s.jsx)("h2",{id:e,ref:k,tabIndex:-1,className:"sekyro-text-body",children:m}),u]})]}),t!=null&&t!==!1?(0,s.jsx)(o,{children:t}):null]})}a(f,"g");i(f,"StatusPage");export{f as a};
@@ -1 +1 @@
1
- import{a as g}from"./chunk-QXCB7CMC.js";import{K as b,a as k,b as y,c as x}from"./chunk-E75YC36S.js";import{a as n}from"./chunk-5QL6W6FW.js";import{a as c,c as f}from"./chunk-4FHWXBOB.js";var l=f(k(),1),t=f(k(),1),w=f(k(),1),r=f(y(),1),e=f(y(),1);var i,C=(i=class extends w.Component{constructor(){super(...arguments),this.state={failed:!1}}static getDerivedStateFromError(){return{failed:!0}}render(){return this.state.failed?this.props.fallback:this.props.children}},c(i,"c"),i);n(C,"LoadBoundary");var j=C,F={load:n(()=>import("./flow-views-I3YI3NWV-ENMBLDRD.js"),"load")};function S({view:s,i18n:a,quiet:o,...m}){let[d,h]=(0,t.useState)(0),u=(0,t.useMemo)(()=>(0,t.lazy)(()=>F.load().then(v=>({default:v[s]}))),[s,d]),p=(0,r.jsxs)(b,{tone:"danger",children:[(0,r.jsx)("span",{children:a.t("errors.network_error")}),(0,r.jsx)(x,{kind:"secondary",onClick:c(()=>h(v=>v+1),"onClick"),children:a.t("common.retry")})]});return(0,r.jsx)(j,{fallback:p,children:(0,r.jsx)(t.Suspense,{fallback:o===!0?null:(0,r.jsx)("p",{role:"status","aria-busy":"true",className:"sekyro-text-muted",children:a.t("common.loading")}),children:(0,r.jsx)(u,{...m,i18n:a})})},d)}c(S,"k");n(S,"Flow");var B=(0,l.createContext)(void 0);function H({i18n:s,lead:a,refresh:o,actions:m}){let d=(0,l.useContext)(B),[h,u]=(0,l.useState)(!1);if(d!==void 0)return(0,e.jsx)(S,{view:"HandoffView",i18n:s,url:d,lead:a,...o!==void 0?{refresh:o}:{},footer:m});let p=n(()=>{o!==void 0&&(u(!0),o().catch(()=>{}).finally(()=>u(!1)))},"again");return(0,e.jsx)(g,{tone:"brand",icon:"smartphone",title:s.t("handoff.title"),testId:"sekyro-phone-handoff",actions:(0,e.jsxs)(e.Fragment,{children:[m,o!==void 0?(0,e.jsx)(x,{kind:"secondary",full:!0,disabled:h,onClick:p,children:s.t("common.refresh")}):null]}),children:(0,e.jsx)("p",{children:a})})}c(H,"K");n(H,"PhoneHandoff");export{j as a,S as b,B as c,H as d};
1
+ import{a as g}from"./chunk-3DAULGZ2.js";import{K as b,a as k,b as y,c as x}from"./chunk-Z6KNLRUW.js";import{a as n}from"./chunk-5QL6W6FW.js";import{a as c,c as f}from"./chunk-4FHWXBOB.js";var l=f(k(),1),t=f(k(),1),w=f(k(),1),r=f(y(),1),e=f(y(),1);var i,C=(i=class extends w.Component{constructor(){super(...arguments),this.state={failed:!1}}static getDerivedStateFromError(){return{failed:!0}}render(){return this.state.failed?this.props.fallback:this.props.children}},c(i,"c"),i);n(C,"LoadBoundary");var j=C,F={load:n(()=>import("./flow-views-7SAYQQ62-4RKPVVBZ.js"),"load")};function S({view:s,i18n:a,quiet:o,...m}){let[d,h]=(0,t.useState)(0),u=(0,t.useMemo)(()=>(0,t.lazy)(()=>F.load().then(v=>({default:v[s]}))),[s,d]),p=(0,r.jsxs)(b,{tone:"danger",children:[(0,r.jsx)("span",{children:a.t("errors.network_error")}),(0,r.jsx)(x,{kind:"secondary",onClick:c(()=>h(v=>v+1),"onClick"),children:a.t("common.retry")})]});return(0,r.jsx)(j,{fallback:p,children:(0,r.jsx)(t.Suspense,{fallback:o===!0?null:(0,r.jsx)("p",{role:"status","aria-busy":"true",className:"sekyro-text-muted",children:a.t("common.loading")}),children:(0,r.jsx)(u,{...m,i18n:a})})},d)}c(S,"k");n(S,"Flow");var B=(0,l.createContext)(void 0);function H({i18n:s,lead:a,refresh:o,actions:m}){let d=(0,l.useContext)(B),[h,u]=(0,l.useState)(!1);if(d!==void 0)return(0,e.jsx)(S,{view:"HandoffView",i18n:s,url:d,lead:a,...o!==void 0?{refresh:o}:{},footer:m});let p=n(()=>{o!==void 0&&(u(!0),o().catch(()=>{}).finally(()=>u(!1)))},"again");return(0,e.jsx)(g,{tone:"brand",icon:"smartphone",title:s.t("handoff.title"),testId:"sekyro-phone-handoff",actions:(0,e.jsxs)(e.Fragment,{children:[m,o!==void 0?(0,e.jsx)(x,{kind:"secondary",full:!0,disabled:h,onClick:p,children:s.t("common.refresh")}):null]}),children:(0,e.jsx)("p",{children:a})})}c(H,"K");n(H,"PhoneHandoff");export{j as a,S as b,B as c,H as d};
@@ -1 +1 @@
1
- import{a as d}from"./chunk-E75YC36S.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-Z6KNLRUW.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 +1 @@
1
- import{a as C,d as f,e as l,f as d,g as m,h as v,i as p,j as g,l as x}from"./chunk-E75YC36S.js";import{a as i}from"./chunk-5QL6W6FW.js";import{a as o,c as b}from"./chunk-4FHWXBOB.js";var r=b(C(),1);var y={ar:l,fr:d,en:f};function h(e,t){let s=v(e),a=s===void 0?y[m(e)]:{...y.en,...s};if(t===void 0)return a;let n={...a};for(let u of Object.keys(t)){let c=t[u];typeof c=="string"&&(n[u]=c)}return x(n,t),n}o(h,"T");i(h,"resolveStrings");function j(e){let[,t]=(0,r.useState)(0),s=p(e);return(0,r.useEffect)(()=>{if(!s)return;let a=!0;return g(e).then(()=>a&&t(n=>n+1)),()=>{a=!1}},[e,s]),!s}o(j,"w");i(j,"useLocaleReady");var S=(0,r.createContext)(e=>f[e]??""),E=S.Provider;function k(){return(0,r.useContext)(S)}o(k,"I");i(k,"useStrings");export{h as a,j as b,E as c,k as d};
1
+ import{a as C,d as f,e as l,f as d,g as m,h as v,i as p,j as g,l as x}from"./chunk-Z6KNLRUW.js";import{a as i}from"./chunk-5QL6W6FW.js";import{a as o,c as b}from"./chunk-4FHWXBOB.js";var r=b(C(),1);var y={ar:l,fr:d,en:f};function h(e,t){let s=v(e),a=s===void 0?y[m(e)]:{...y.en,...s};if(t===void 0)return a;let n={...a};for(let u of Object.keys(t)){let c=t[u];typeof c=="string"&&(n[u]=c)}return x(n,t),n}o(h,"T");i(h,"resolveStrings");function j(e){let[,t]=(0,r.useState)(0),s=p(e);return(0,r.useEffect)(()=>{if(!s)return;let a=!0;return g(e).then(()=>a&&t(n=>n+1)),()=>{a=!1}},[e,s]),!s}o(j,"w");i(j,"useLocaleReady");var S=(0,r.createContext)(e=>f[e]??""),E=S.Provider;function k(){return(0,r.useContext)(S)}o(k,"I");i(k,"useStrings");export{h as a,j as b,E as c,k as d};
@@ -1 +1 @@
1
- import{a as ke,b as Se,c as ie,d as xe,e as Te,f as Ce,h as Ae}from"./chunk-3NOBU7TE.js";import{a as ne,d as Le,e as Re}from"./chunk-QWPURAKS.js";import{e as Q}from"./chunk-NLTAFWIN.js";import{e as Me,k as be}from"./chunk-6MYG4HWP.js";import{g as ae}from"./chunk-JS2IXPNL.js";import{a as n}from"./chunk-4FHWXBOB.js";function Pe(e,t){let r=new Set(e.flatMap(i=>i.sides.filter(l=>l[t]!==null).map(l=>l.side)));return r.size===1?[...r][0]:null}n(Pe,"Ee");function Xe(e){let t=Le.find(i=>i.docType===e),r=t.mrz==="none"?null:t.mrz==="td3"?"single":"verso";return{sides:t.sides,format:Re(e),mrz:t.mrz==="none"?"none":"required",mrzSide:r,barcodeSide:null,portraitSide:t.portraitSide,scripts:null}}n(Xe,"st");function Ye(e){let t=[];for(let r of e)for(let i of r.sides){if(!Array.isArray(i.scripts))return null;for(let l of i.scripts)t.includes(l)||t.push(l)}return t}n(Ye,"ct");function Je(e,t){if(t.length===0)return Xe(e);let r=t.some(s=>s.sides.length>1),i=new Set(t.map(s=>s.format)),l=i.size===1?[...i][0]:"card",u=t.filter(s=>s.sides.some(h=>h.mrz!==null)).length,d=t.find(s=>s.sides.length>1===r)?.sides.find(s=>s.portrait)?.side;return{sides:r?["recto","verso"]:["single"],format:l,mrz:u===t.length?"required":u===0?"none":"optional",mrzSide:Pe(t,"mrz"),barcodeSide:Pe(t,"barcode"),portraitSide:d??(r?"recto":"single"),scripts:Ye(t)}}n(Je,"Oe");function Qe(e,t){if(e===void 0)return[];let r=e.toUpperCase();return Object.prototype.hasOwnProperty.call(ne,r)?ne[r]?.[t]??[]:[]}n(Qe,"Ae");async function $e(e,t,r){return await e(t)?r:r==="recto"?"verso":"recto"}n($e,"Be");function Ze(e,t,r){return e!==t&&t==="verso"&&r.recto!==void 0&&r.verso===void 0?"verso":e}n(Ze,"Ie");var Ke={low:{maxLongEdge:1920,payloadTargetBytes:7e5,qMin:.7,qMax:.92},mid:{maxLongEdge:2240,payloadTargetBytes:12e5,qMin:.7,qMax:.92},good:{maxLongEdge:2560,payloadTargetBytes:16e5,qMin:.7,qMax:.92}};function et(e){let{deviceMemory:t,effectiveType:r,saveData:i,downlinkMbps:l,sourceLongEdge:u}=e,d=i===!0||r==="slow-2g"||r==="2g"||l!=null&&l>0&&l<1,s=t!=null&&t<=2,h=r==="4g"||l!=null&&l>=5,c=t!=null&&t>=6,k;d||s?k="low":h&&c?k="good":k="mid";let f=Ke[k],P=u&&u>0?Math.min(f.maxLongEdge,u):f.maxLongEdge;return{tier:k,...f,maxLongEdge:P}}n(et,"lt");function tt(e){let t={};try{let r=navigator;typeof r.deviceMemory=="number"&&(t.deviceMemory=r.deviceMemory);let i=r.connection;i&&(t.effectiveType=i.effectiveType,t.saveData=i.saveData,t.downlinkMbps=i.downlink)}catch{}return typeof e=="number"&&e>0&&(t.sourceLongEdge=e),et(t)}n(tt,"Fe");function rt(e,t,r){let i=Math.min(1,Math.max(0,(e-.28)/.21999999999999997)),l=(t+r)/2;return Math.max(t,r-i*(r-l))}n(rt,"dt");function at(e,t,r){let i=Math.max(e,t),l=i>0?Math.min(1,r/i):1;return{width:Math.max(1,Math.round(e*l)),height:Math.max(1,Math.round(t*l))}}n(at,"mt");async function it(e,t){let r=t.startQ,i=await e(r);for(let l=0;l<4&&!(i.size<=t.budgetBytes||r<=t.qMin);l++)r=Math.max(t.qMin,r-.08),i=await e(r);return{blob:i,quality:r}}n(it,"pt");async function nt(e,t,r,i,l){if(t<=0||r<=0)return null;let{width:u,height:d}=at(t,r,i.maxLongEdge),s=document.createElement("canvas");s.width=u,s.height=d;let h=s.getContext("2d");if(!h)return null;h.drawImage(e,0,0,u,d);let c=n(T=>new Promise((y,m)=>{s.toBlob(g=>g?y(g):m(new Error("canvas toBlob returned null")),"image/jpeg",T)}),"l"),k=rt(l,i.qMin,i.qMax),{blob:f,quality:P}=await it(c,{startQ:k,qMin:i.qMin,budgetBytes:i.payloadTargetBytes}).finally(()=>{s.width=0,s.height=0});if(f.size>5242880)throw new Error("encoded document exceeds the 5242880-byte media cap");return{blob:f,quality:P,width:u,height:d}}n(nt,"We");async function ot(e){let t=tt(Math.max(e.width,e.height)),r=await nt(e,e.width,e.height,t,.5);if(r===null)throw new Error("canvas encode unavailable");return{blob:r.blob,width:r.width,height:r.height}}n(ot,"oe");function We(e,t){return{layout:e,phase:"framing",captured:{},pending:[],lastCaptureAt:t,lastReportAt:t,manualShutter:!1,restPhase:"framing",readSides:[],needFlip:!1,flipped:!1,flipTimeoutSpent:!1,timeoutCapture:!1,lastShotByTimeout:!1}}n(We,"ie");var Ie=n(e=>e==="recto"?"verso":"recto","Ue"),Be=n(e=>e.phase==="framing"||e.phase==="locking"||e.phase==="flipCue"||e.phase==="reaskRecto","Ne"),ue=n(e=>(e.captured.recto!==void 0?1:0)+(e.captured.verso!==void 0?1:0)+e.pending.length,"se");function oe(e,t){return e.lastCaptureAt>=0&&e.lastReportAt>=0?e:{...e,lastCaptureAt:e.lastCaptureAt<0?t:e.lastCaptureAt,lastReportAt:e.lastReportAt<0?t:e.lastReportAt}}n(oe,"ae");function lt(e,t,r){if(e.phase==="result")return{...e,lastReportAt:r};let i=!t.present||e.captureArea!==void 0&&t.areaFrac<.6*e.captureArea,{flipped:l,awaySince:u}=e;i&&(u=u??r),u!==void 0&&r-u>=250&&(l=!0),i||(u=void 0);let d=e.flipTimeoutSpent&&!(l&&!e.flipped),s={...e,lastReportAt:r,flipped:l,awaySince:u,flipTimeoutSpent:d,lastArea:t.areaFrac};if(!Be(e))return s;if(e.needFlip&&!l){if(!t.ready)return{...s,phase:e.restPhase,goodSince:void 0};let h=e.lastShot!==void 0&&e.pending.includes(e.lastShot);if(d||h)return{...s,goodSince:void 0,phase:e.restPhase};let c=e.goodSince??r;return r-c>=1800?{...s,goodSince:c,phase:"capturing",flipTimeoutSpent:!0,timeoutCapture:!0}:{...s,goodSince:c,phase:e.restPhase}}return t.ready?{...s,phase:"capturing",goodSince:e.goodSince??r}:{...s,goodSince:void 0,phase:t.locking?"locking":e.restPhase}}n(lt,"ft");function st(e,t){if(!Be(e)||e.manualShutter)return e;let r=t-e.lastReportAt>=2e3,i=t-e.lastCaptureAt>=6e3;return r||i?{...e,manualShutter:!0}:e}n(st,"gt");function dt(e,t,r){let i=e.layout==="singlePage",l=i?{recto:t}:e.captured,u=i?[]:[...e.pending,t],d={...e,captured:l,pending:u,lastShot:t,lastCaptureAt:r,lastReportAt:-1,manualShutter:!1,goodSince:void 0,notice:void 0,awaySince:void 0,flipped:!1,lastShotByTimeout:e.timeoutCapture,timeoutCapture:!1,captureArea:e.lastArea};return i||ue({captured:l,pending:u})>=2?{...d,phase:"reading",restPhase:"framing",current:void 0,needFlip:!1}:{...d,phase:"flipCue",restPhase:"flipCue",current:void 0,needFlip:!0}}n(dt,"ht");function Ue(e,t,r){return e.pending.includes(t)?{...e,pending:e.pending.filter(i=>i!==t),lastShot:e.lastShot===t?void 0:e.lastShot,phase:e.phase==="capturing"?e.phase:"flipCue",restPhase:"flipCue",current:Ie(r),needFlip:!0,flipTimeoutSpent:!0,goodSince:void 0,manualShutter:!0,notice:"same_face",lastCaptureAt:-1,lastReportAt:-1}:e}n(Ue,"Ge");function ut(e,t,r){if(!e.pending.includes(t))return e;if(e.captured[r]!==void 0)return Ue(e,t,r);let i=e.pending.filter(h=>h!==t),l={...e,pending:i,captured:{...e.captured,[r]:t}};if(ue(l)!==1||e.layout==="singlePage")return l;let u=Ie(r),d=u==="recto"&&e.restPhase==="reaskRecto"?"reaskRecto":"flipCue",s=e.phase==="flipCue"||e.phase==="reaskRecto"||e.phase==="framing";return{...l,restPhase:d,current:u,phase:s?d:e.phase}}n(ut,"bt");function ct(e,t){let r=t.id??e.captured[t.side],i={...e.captured};(t.id===void 0||i[t.side]===t.id)&&delete i[t.side];let l=e.pending.filter(c=>c!==r),u=e.layout==="twoSided"&&ue({captured:i,pending:l})>0,d=e.lastShotByTimeout||r===e.lastShot!==e.flipped,s=u&&!d,h=s?t.side==="recto"?"reaskRecto":"flipCue":"framing";return{...e,captured:i,pending:l,readSides:e.readSides.filter(c=>c!==t.side),lastShot:e.lastShot===r?void 0:e.lastShot,notice:t.issue,goodSince:void 0,manualShutter:!1,phase:h,restPhase:h,current:t.side,needFlip:s,flipped:!1,flipTimeoutSpent:!1,awaySince:void 0,lastCaptureAt:-1,lastReportAt:-1}}n(ct,"yt");function pt(e,t){switch(t.type){case"report":return lt(oe(e,t.at),t.report,t.at);case"tick":return st(oe(e,t.at),t.at);case"captured":return dt(oe(e,t.at),t.id,t.at);case"captureFailed":return{...e,phase:e.restPhase,goodSince:void 0,lastCaptureAt:t.at,manualShutter:!0,timeoutCapture:!1};case"classified":return ut(e,t.id,t.side);case"duplicate":return Ue(e,t.id,t.side);case"readOk":{let r=e.readSides.includes(t.side)?e.readSides:[...e.readSides,t.side],i=["recto","verso"].filter(u=>e.captured[u]!==void 0),l=e.phase==="reading"&&e.pending.length===0&&i.every(u=>r.includes(u));return{...e,readSides:r,flipTimeoutSpent:!1,phase:l?"result":e.phase}}case"readFailed":return ct(e,t);case"clockRestart":return e.lastCaptureAt<0&&e.lastReportAt<0&&e.awaySince===void 0?e:{...e,awaySince:void 0,lastCaptureAt:-1,lastReportAt:-1};case"retake":return{...We(e.layout,-1),lastCaptureAt:-1,lastReportAt:-1};default:return e}}n(pt,"qe");function mt(e,t,r=!1){let i=e(t);return i===null?"recto":!r||i.y+i.height/2>=t.height/2?"verso":"recto"}n(mt,"St");async function ht(e,t=!1){let{detectMrzBand:r}=await import("./mrz-band-VYHOTDHY-VEZ2J5IL.js");return mt(r,e,t)}n(ht,"Mt");async function ze(e,t=480,r,i=r!=null){let l=r??{x:0,y:0,width:e.width,height:e.height},u=Math.max(1,Math.round(l.height/l.width*t)),d=document.createElement("canvas");d.width=t,d.height=u;try{let s=d.getContext("2d");return s===null?"recto":(s.drawImage(e,l.x,l.y,l.width,l.height,0,0,t,u),await ht(s.getImageData(0,0,t,u),i))}finally{d.width=0,d.height=0}}n(ze,"ce");var le=n((e,t,r)=>Math.min(r,Math.max(t,Math.round(e))),"ue"),$=n(e=>Math.round(Math.min(1,Math.max(0,e))*1e4)/1e4,"$");async function ft(e,t,r,i){let l=i.decode??(h=>createImageBitmap(h)),u=n(async()=>e.stillRead(await l(t),i.region??[0,0,1,1],i.detectorLimit),"u"),d;try{d=await u()}catch{try{await new Promise(h=>setTimeout(h,i.retryMs??300)),d=await u()}catch{return null}}let s=d.mrzBox;return s===void 0?null:{engine:i.engine,source:"live_mrz",format:r.format,lineCount:le(r.lineCount,2,3),checkDigitsValid:!0,stillConfirmed:d.valid&&d.digest===r.digest,band:[$(s[0]),$(s[1]),$(Math.min(s[2],1-s[0])),$(Math.min(s[3],1-s[1]))],digest:r.digest,framesToValid:le(r.framesToValid,1,1e3),msToValid:le(r.msToValid,0,12e4)}}n(ft,"He");var gt=new Uint8Array([0,97,115,109,1,0,0,0,1,5,1,96,0,1,123,3,2,1,0,10,10,1,8,0,65,0,253,15,253,98,11]),vt=new Uint8Array([0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,2,1,0,10,7,1,5,0,6,64,11,11]);function yt(e=globalThis){let t=e.WebAssembly?.validate;if(typeof t!="function")return{ok:!1,reason:"simd"};try{if(!t.call(e.WebAssembly,gt)||!t.call(e.WebAssembly,vt))return{ok:!1,reason:"simd"}}catch{return{ok:!1,reason:"simd"}}return typeof e.Worker!="function"?{ok:!1,reason:"worker"}:typeof e.createImageBitmap!="function"?{ok:!1,reason:"bitmap"}:{ok:!0}}n(yt,"Xe");function wt(e=globalThis){let t=e.navigator?.connection;return t?.saveData===!0||["slow-2g","2g","3g"].includes(t?.effectiveType??"")}n(wt,"Ye");var j,E=(j=class extends Error{constructor(t){super(t),this.name="OcrEngineError",this.code=t}},n(j,"E"),j);function De(){let e=n(t=>(t.close(),Promise.reject(new E("unsupported"))),"e");return{ready:Promise.resolve("unsupported"),busy:!1,bandRead:e,stillRead:e,layoutRead:e,dispose:n(()=>{},"dispose")}}n(De,"Ve");function Mt(e){let t;try{if(e.createWorker)t=e.createWorker();else if(e.workerUrl!==void 0)t=new Worker(e.workerUrl,{type:"module",name:"sekyro-ocr"});else return De()}catch{return De()}let r=new Map,i=0,l=!1,u=!1,d=!1;t.addEventListener("message",m=>{let g=m.data,b=r.get(g.id);b&&(r.delete(g.id),b.resolve(g))});let s=n(()=>{for(let m of r.values())m.reject(new E("error"));r.clear(),c()},"s");t.addEventListener("error",s),t.addEventListener("messageerror",s);function h(m,g=[]){if(l)return Promise.reject(new E("disposed"));let b=++i;return new Promise((D,W)=>{r.set(b,{resolve:D,reject:W});try{t.postMessage({...m,id:b},g)}catch{r.delete(b),W(new E("error"))}})}n(h,"p");function c(){if(!l){l=!0;try{t.postMessage({id:++i,kind:"dispose"})}catch{}t.terminate();for(let m of r.values())m.reject(new E("disposed"));r.clear()}}n(c,"l");let k=(async()=>{let m=await h({kind:"init",baseUrl:e.baseUrl,salt:e.salt,detectorLimit:e.tuning.detectorLimit,maxDownloadMs:e.tuning.maxDownloadMs});if(m.kind==="failed")return m.reason;if(m.kind!=="ready")return"error";let g=await h({kind:"warmup"});if(g.kind!=="ready")return"error";let b=g.benchMs??g.warmupMs,D=e.deviceMemoryGb===void 0?Se():e.deviceMemoryGb;return{warmupMs:g.warmupMs,downloadMs:m.downloadMs,cached:m.cached,benchMs:b,tier:ke(b,D)}})().catch(()=>"error"),f,P=new Promise(m=>{f=setTimeout(()=>m("timeout"),e.tuning.loadTimeoutMs)}),T=Promise.race([k,P]).then(m=>(clearTimeout(f),typeof m=="string"?c():d=!0,l&&typeof m!="string"?"error":m));(e.page===void 0?globalThis.addEventListener?globalThis:null:e.page)?.addEventListener("pagehide",c,{once:!0});async function y(m,g,b){if(l)throw g.close(),new E("disposed");if(!d)throw g.close(),new E("not_ready");if(u)throw g.close(),new E("busy");u=!0;let D;try{let W=new Promise((U,O)=>{D=setTimeout(()=>{O(new E("timeout")),c()},e.tuning.readTimeoutMs??1e4)}),q=await Promise.race([h(m,[g]),W]);if(q.kind===b){let{id:U,...O}=q;return O}throw new E(q.kind==="error"?q.code:q.kind==="failed"?q.reason:"error")}finally{clearTimeout(D),u=!1}}return n(y,"P"),{ready:T,get busy(){return u},bandRead:n((m,g=e.tuning.detectorLimit)=>y({kind:"band",bitmap:m,detectorLimit:g},m,"band"),"bandRead"),stillRead:n((m,g,b=e.tuning.detectorLimit)=>y({kind:"still",bitmap:m,region:g,detectorLimit:b},m,"band"),"stillRead"),layoutRead:n((m,g)=>y({kind:"layout",bitmap:m,detectorLimit:g},m,"layout"),"layoutRead"),dispose:c}}n(Mt,"Qe");var Z="sekyro-ocr-1",se=n(e=>e!==null&&typeof e=="object"?e:{},"le"),z=n((e,t,r,i)=>typeof e=="number"&&Number.isFinite(e)&&e>=t&&e<=r?e:i,"_"),qe=n((e,t)=>typeof e=="boolean"?e:t,"Ke"),Ee=n(e=>{let t=typeof e=="string"?/^sekyro-ocr-(\d{1,4})$/.exec(e):null;return t?Number(t[1]):Number.POSITIVE_INFINITY},"je");function bt(e,t={}){let r=se(e),i=se(r.liveMrz),l=se(r.frontLock),u=Ee(t.engine??Z),d=t.mode==="off",s=n(g=>g.enabled===!0?g.arm==="live"?"live":"control":null,"s"),h=s(i),c=s(l),k=n((g,b)=>!d&&b==="live"&&Ee(g.minEngine??Z)<=u,"M"),f=Ce,P=k(i,h)?{detectorLimit:z(i.detectorLimit,320,1600,f.detectorLimit),bandMaxWidthPx:z(i.bandMaxWidthPx,320,4096,f.bandMaxWidthPx),minBandWidthPx:z(i.minBandWidthPx,0,4096,f.minBandWidthPx),bandTop:z(i.bandTop,0,.95,f.bandTop),minIntervalMs:z(i.minIntervalMs,0,5e3,f.minIntervalMs),stableReads:Math.round(z(i.stableReads,1,10,f.stableReads)),profileReads:Math.round(z(i.profileReads,1,100,f.profileReads)),maxReadMs:z(i.maxReadMs,50,6e4,f.maxReadMs),searchTimeoutMs:z(i.searchTimeoutMs,1e3,12e4,f.searchTimeoutMs),hint:qe(i.hint,!0),stillConfirm:qe(i.stillConfirm,!0)}:null,T=Te,y=n((g,b,D)=>z(l[g],b,D,T[g]),"S"),m=k(l,c)?{minLines:Math.round(y("minLines",1,50)),fillMin:y("fillMin",0,1),fillMax:y("fillMax",0,2),offsetMax:y("offsetMax",0,1),steadyFillDelta:y("steadyFillDelta",0,1),steadyOffsetDelta:y("steadyOffsetDelta",0,1),layoutShiftMax:y("layoutShiftMax",0,1),lineCountDelta:Math.round(y("lineCountDelta",0,50)),lockMs:y("lockMs",0,3e4),steadyMs:y("steadyMs",0,3e4),minFrames:Math.round(y("minFrames",1,100)),minIntervalMs:y("minIntervalMs",0,5e3),maxWidthPx:y("maxWidthPx",160,2048),detectorLimit:y("detectorLimit",320,1600),searchTimeoutMs:y("searchTimeoutMs",1e3,12e4)}:null;return{enabled:P!==null||m!==null,liveMrz:P,textLock:m,liveMrzArm:h,frontLockArm:c,load:{detectorLimit:P?.detectorLimit??m?.detectorLimit??f.detectorLimit,loadTimeoutMs:z(i.loadTimeoutMs,1e3,12e4,2e4),maxDownloadMs:z(i.maxDownloadMs,1e3,12e4,2e4)},reportSampleRate:z(i.reportSampleRate,0,1,1)}}n(bt,"$e");function kt(e,t){return e.enabled?!(t.probe??yt)().ok||(t.slow??wt)()?{ok:!1,reason:"unsupported"}:{ok:!0,engine:Mt({baseUrl:t.baseUrl,salt:t.salt,tuning:{detectorLimit:e.load.detectorLimit,maxDownloadMs:e.load.maxDownloadMs,loadTimeoutMs:e.load.loadTimeoutMs},...t.workerUrl!==void 0?{workerUrl:t.workerUrl}:{},...t.createWorker!==void 0?{createWorker:t.createWorker}:{},...t.page!==void 0?{page:t.page}:{},...t.deviceMemoryGb!==void 0?{deviceMemoryGb:t.deviceMemoryGb}:{}})}:{ok:!1,reason:"off"}}n(kt,"Je");function St(e=typeof navigator<"u"?navigator.userAgent:""){return/SamsungBrowser\//.test(e)?"samsung":/Firefox\/|FxiOS\//.test(e)?"firefox":/Chrome\/|CriOS\/|Chromium\//.test(e)&&!/Edg\/|OPR\//.test(e)?"chrome":/Safari\//.test(e)&&/Version\/|Mobile\//.test(e)&&!/Chrome\/|CriOS\//.test(e)?"safari":"other"}n(St,"kt");var F=n(e=>e===void 0||!Number.isFinite(e)?void 0:Math.min(6e5,Math.max(0,Math.round(e))),"I"),de=n((e,t,r)=>e===void 0||!Number.isFinite(e)?void 0:Math.min(r,Math.max(t,Math.round(e))),"de");function xt(e){let t=e.assist??null,r=e.load!==null&&e.load!==void 0&&typeof e.load=="object"?e.load:null,i=typeof e.load=="string"?e.load:null,l=t!==null?t.outcome:i==="unsupported"||i==="download"||i==="integrity"?i:i==="error"||i==="timeout"?"error":"off",u={kind:"live_mrz",platform:"web",engine:e.engine??Z,arm:e.arm,capture:e.capture,outcome:l,reads:de(t?.reads??0,0,1e4)??0,browser:e.browser??St()},d=n((s,h)=>{h!==void 0&&(u[s]=h)},"c");return d("format",t?.format),d("framesToValid",de(t?.framesToValid,1,1e4)),d("msToValid",F(t?.msToValid)),d("framesToLock",de(t?.framesToLock,1,1e4)),d("msToLock",F(t?.msToLock)),d("msToCapture",F(e.msToCapture)),d("readP50Ms",F(t?.readP50Ms)),d("readP90Ms",F(t?.readP90Ms)),d("deviceClass",t?.deviceClass),r!==null&&(d("warmupMs",F(r.warmupMs)),d("downloadMs",F(r.downloadMs)),d("cached",r.cached),d("tier",r.tier),d("benchMs",F(r.benchMs))),d("stillConfirmed",e.stillConfirmed),d("typeMismatch",e.typeMismatch),u}n(xt,"Ze");function Fe(e,t){return e===void 0?!1:t==="passport"?e!=="TD3":e==="TD3"}n(Fe,"me");var Tt=2;async function Ct(e){let t=await import("./capture-session-doc-KAKQJPCO-AIHWPBYL.js");return new t.CaptureSessionDoc(e)}n(Ct,"xt");function At(e){return{topLeft:{x:e.x,y:e.y},topRight:{x:e.x+e.width,y:e.y},bottomRight:{x:e.x+e.width,y:e.y+e.height},bottomLeft:{x:e.x,y:e.y+e.height}}}n(At,"vt");function Lt(e,t,r){let i=[e.topLeft,e.topRight,e.bottomRight,e.bottomLeft],l=0;for(let u=0;u<i.length;u+=1){let d=i[u],s=i[(u+1)%i.length];l+=d.x*s.y-s.x*d.y}return t>0&&r>0?Math.abs(l)/2/(t*r):0}n(Lt,"Rt");function Wt(){import("./capture-session-doc-KAKQJPCO-AIHWPBYL.js").then(e=>e.warmDocDetector()).catch(()=>{})}n(Wt,"hn");function It(e){return Rt(e,{}).handle}n(It,"bn");function Rt(e,t){let r=Me(),i=be({enabled:e.keepScreenAwake!==!1}),l=t.decode??(a=>createImageBitmap(a)),u=t.blurRefuseSharpnessMax??.16,d=t.now??(()=>performance.now()),s=Je(e.documentType,t.catalogCapture===!0?t.captureSeries??Qe(e.issuer,e.documentType):[]),h=s.sides.length===1||e.side==="single",c=We(h?"singlePage":"twoSided",d());if(!h&&(e.side==="recto"||e.side==="verso")){let a=e.side==="recto"?"verso":"recto";c={...c,captured:{[a]:"server"},readSides:[a],current:e.side,phase:"flipCue",restPhase:"flipCue"}}let k="idle",f=null,P=null,T=!0,y=0,m=0,g=!1,b=!1,D="",W=null,q,U=null,O=[],ce=s.mrz==="none",Oe=s.barcodeSide==="recto"||s.barcodeSide==="verso"?s.barcodeSide:null,I=ce&&!h?t.barcode?.side??Oe:null,pe=e.barcodeAssetBaseUrl??t.barcode?.assetBaseUrl,K=null,me=n(()=>I===null||pe===void 0||t.barcode?.seen!==void 0?Promise.resolve(null):(K??(K=import("./barcode-detect-C5IOXMKI-ZOZ2WOWU.js").then(a=>a.loadBarcodeDetect(pe)).catch(()=>null)),K),"ge"),Ne=n(async(a,o)=>{if(I===null)return null;let p=I==="recto"?"verso":"recto";try{let v=t.barcode?.seen;if(v!==void 0)return await v(a)?I:p;let[A,S]=await Promise.all([me(),o()]);if(A===null||S===null)return null;let x=Math.min(1600,S.width),M=document.createElement("canvas");M.width=x,M.height=Math.max(1,Math.round(S.height/S.width*x));try{let w=M.getContext("2d");return w===null?null:(w.drawImage(S,0,0,M.width,M.height),await $e(A,w.getImageData(0,0,M.width,M.height),I))}finally{M.width=0,M.height=0}}catch{return null}},"tt"),C=t.webOcr!==void 0&&!ce?bt(t.webOcr.captureDocument,{mode:e.liveMrz?.mode??"auto"}):null,G=null,N=C===null||!C.enabled?"off":null,_=null,X=null,he=new WeakMap,ee="";if(C!==null&&C.enabled&&t.webOcr!==void 0){let a=t.webOcr,o=kt(C,{baseUrl:e.liveMrz?.assetBaseUrl??a.baseUrl,salt:a.salt,...e.liveMrz?.workerUrl!==void 0?{workerUrl:e.liveMrz.workerUrl}:{},...a.createWorker!==void 0?{createWorker:a.createWorker}:{}});if(o.ok){G=o.engine;let p=new Ae({textLock:C.textLock,liveMrz:C.liveMrz});_=p;let v=o.engine;v.ready.then(A=>{N=A,typeof A!="string"&&T&&p.setEngine(v,A.tier)})}else N=o.reason}let V=n(a=>{let o=JSON.stringify(a);o!==ee&&(ee=o,r.emit("mrz",a))},"N"),fe=n((a,o)=>{let p=t.webOcr?.reports;if(p===void 0||C===null||a===void 0)return;let v=a.format==="ID-3"||a.side==="single"?"single":a.side==="verso"?"verso":"recto",A=v!=="recto"?C.liveMrzArm??C.frontLockArm:C.frontLockArm;if(A===null||Math.random()>=C.reportSampleRate)return;let S=a.via==="live_mrz"?X:null,x=n(()=>{let M=S?.value??null;p([xt({arm:A,capture:v,assist:a.ocr??null,load:A==="control"?"off":N,...a.msToCapture!==void 0?{msToCapture:a.msToCapture}:{},...M!==null&&M.stillConfirmed!==void 0?{stillConfirmed:M.stillConfirmed}:{},...o!==void 0?{typeMismatch:Fe(o.format,s.format==="ID-3"?"passport":"card")}:{}})])},"k");S!==null&&S.value===null?Promise.race([S.promise,new Promise(M=>setTimeout(M,3e3))]).then(x):x()},"be"),B=n(a=>{!T||a===k||(k=a,i.setActive(a==="starting"||a==="scanning"),r.emit("state",a))},"W"),Ve=n((a,o)=>o===void 0?null:h?"single":a.captured.recto===o?"recto":a.captured.verso===o?"verso":null,"nt"),je=n(a=>({phase:a.phase,captured:h?a.captured.recto!==void 0?["single"]:[]:["recto","verso"].filter(o=>a.captured[o]!==void 0),expected:h?null:a.current??null,notice:a.notice??null,lastShot:Ve(a,a.lastShot),manualShutter:a.manualShutter,torchAvailable:f?.torchAvailable()??!1,torch:b}),"rt"),ge=n(()=>{let a=f;a!==null&&a.captureNow().catch(()=>R({type:"captureFailed",at:d()}))},"ye");function R(a){if(!T)return;let o=c;c=pt(c,a),c.phase==="capturing"&&o.phase!=="capturing"&&Promise.resolve().then(ge),c.phase==="result"&&o.phase!=="result"&&(B("done"),ve());let p=je(c),v=JSON.stringify(p);v!==D&&(D=v,r.emit("scan",p))}n(R,"L");function ve(){U!==null&&clearInterval(U),U=null;for(let a of O.splice(0))a();f?.destroy(),f=null,i.setActive(!1)}n(ve,"Se");let ye=n(()=>f?.captureReport?.(),"Me"),te=!1,we=n((a,o)=>{if(!(a===void 0||t.onFaceReport===void 0))try{t.onFaceReport(a,o)}catch{}},"De"),Y=n(a=>{ee="",!(f===null||c.phase==="reading"||c.phase==="result")&&(te=!1,f.rearm(h?"single":c.current??a))},"Q"),Ge=n(async(a,o,p,v)=>{if(X=null,v!==void 0&&G!==null&&C?.liveMrz?.hint===!0){let w={promise:ft(G,a,v,{engine:Z,detectorLimit:C.liveMrz.detectorLimit}).catch(()=>null),value:null};w.promise.then(L=>{w.value=L}),X=w}v!==void 0&&Fe(v.format,s.format==="ID-3"?"passport":"card")&&V({state:"mismatch",format:v.format});let A=ye();we(A,"captured"),te=!0,fe(A,v);let S=p===void 0?W:p===null?null:{quad:At(p),frameWidth:0,frameHeight:0,inStill:!0},x={decoded:null},M=n(()=>(x.decoded??(x.decoded=Promise.resolve().then(()=>l(a)).catch(()=>null)),x.decoded),"y");try{await He(a,o,S,M,X)}finally{x.decoded!==null&&(await x.decoded)?.close()}},"ot"),He=n(async(a,o,p,v,A)=>{let S=`shot-${y+=1}`;if(R({type:"captured",id:S,at:d()}),e.haptics!==!1)try{globalThis.navigator?.vibrate?.(30)}catch{}if(!g&&u>0){let w=await(t.measureSharpness!==void 0?t.measureSharpness(a,p):v().then(L=>L===null?-1:xe(L,ie(p?.quad??null,p?.inStill===!0?L:{width:p?.frameWidth??0,height:p?.frameHeight??0},L)))).catch(()=>-1);if(!T)return;if(Number.isFinite(w)&&w>=0&&w<u){g=!0;let L=h?"recto":c.current??(c.captured.recto===void 0?"recto":"verso");R({type:"readFailed",side:L,id:S,issue:"blurry"}),Y(L);return}}g=!1;let x;if(h)x="single";else{let w=c.current,L=t.classify===void 0?await Ne(a,v):null,H=(L===null||I===null?L:Ze(L,I,c.captured))??await(t.classify!==void 0?t.classify(a):v().then(J=>J===null?w??"recto":p?.inStill===!0?ze(J,480,null,!0):ze(J,480,ie(p?.quad??null,{width:p?.frameWidth??0,height:p?.frameHeight??0},J)))).catch(()=>w??"recto");if(!T)return;if(c.captured[H]!==void 0&&m<Tt){m+=1,R({type:"duplicate",id:S,side:H}),Y(H==="recto"?"verso":"recto");return}x=c.captured[H]!==void 0&&w!==void 0?w:H,m=0,R({type:"classified",id:S,side:x})}let M=x==="verso"?"verso":"recto";try{let w=t.encode!==void 0?await t.encode(a):await v().then(L=>{if(L===null)throw new Error("the still could not be decoded");return ot(L)});if(!T)return;A!==null&&he.set(w.blob,A),r.emit("captured",{image:w.blob,side:x,documentType:e.documentType,...e.issuer!==void 0?{issuer:e.issuer}:{},width:w.width,height:w.height,previewDataUrl:o}),t.deferRead!==!0&&R({type:"readOk",side:M})}catch(w){R({type:"readFailed",side:M,id:S,issue:"technical"}),r.emit("error",Q("generic",!0,{phase:"keyframes",name:ae(w)}))}Y(M==="recto"?"verso":"recto")},"at"),_e=n(a=>{O.push(a.on("statechange",({state:o})=>{o==="preflight"||o==="acquiring"?B("starting"):o==="positioning"?B("scanning"):o==="captured"?B("captured"):o==="error"&&B("error")}),a.on("feedback",({key:o,reticle:p})=>r.emit("feedback",{key:o,reticle:p})),a.on("checks",o=>{r.emit("gate",{progress:o.p,quad:o.quad,frameWidth:o.frameWidth,frameHeight:o.frameHeight,...o.guide!==void 0?{guide:{detected:o.guide.detected,fill:o.guide.fill,offsetX:o.guide.offsetX??0,offsetY:o.guide.offsetY??0}}:{}});let p=o.ocr?.mrz;p!==void 0&&(p.state==="fallback"?V({state:"fallback",reason:p.reason}):p.state==="valid"?V({state:"valid",format:p.format}):p.state==="reading"?V({state:"reading",...p.format?{format:p.format}:{},...p.coach?{coach:p.coach}:{}}):V({state:"searching"}));let v=o.quad===null?0:Lt(o.quad,o.frameWidth,o.frameHeight);W=o.quad===null?null:{quad:o.quad,frameWidth:o.frameWidth,frameHeight:o.frameHeight},R({type:"report",report:{present:o.quad!==null&&o.plausible||o.guide?.detected===!0,ready:o.ready===!0,locking:o.p>=.5,areaFrac:v},at:d()})}),a.on("error",({kind:o,retryable:p,detail:v})=>r.emit("error",Q(o,p,v))),a.on("artifacts",o=>{Ge(o.keyframe,o.previewDataUrl,o.docRegion,o.liveMrz)}))},"it"),re=n(()=>(P??(P=(async()=>{if(T){if(me(),f===null){let a;try{a=await(t.createEngine??Ct)({...t.engineOptions??{},...q!==void 0?{guide:q}:{},video:e.video,format:s.format,side:h?"single":e.side??"recto",autoCapture:!1,..._!==null?{ocr:_}:{}})}catch(p){B("error"),r.emit("error",Q("models",!0,{phase:"models",name:ae(p)}));return}if(!T){a.destroy();return}f=a,_e(a);let o=t.tickMs??500;o>0&&(U=setInterval(()=>R({type:"tick",at:d()}),o))}R({type:"clockRestart"}),C!==null&&C.liveMrzArm==="live"&&(N==="unsupported"||N==="off")&&V({state:"fallback",reason:N}),await f.start()}})().finally(()=>{P=null})),P),"ee");return{handle:{get state(){return k},on:n((a,o)=>r.on(a,o),"on"),start:re,retry:n(()=>{if(f===null&&c.phase==="result"){R({type:"retake"}),m=0,g=!1,re();return}if(f!==null&&k!=="error"){R({type:"retake"}),m=0,g=!1,f.rearm(h?"single":void 0);return}re()},"retry"),setSide:n(a=>{h||a==="single"||(c.current!==a&&(c={...c,current:a}),R({type:"clockRestart"}),c.phase!=="reading"&&c.phase!=="result"&&f?.rearm(a))},"setSide"),shutter:ge,focusAt:n((a,o)=>{f?.focusAt?.(a,o)},"focusAt"),setGuide:n(a=>{q=a,f?.setGuide?.(a)},"setGuide"),setTorch:n(a=>{b=a,f?.setTorch(a),R({type:"tick",at:d()})},"setTorch"),destroy:n(()=>{if(T&&f!==null&&k!=="done"){let a=ye();!te&&a!==void 0&&a.ticks>0&&we(a,"abandoned"),fe(a,void 0)}T=!1,ve(),_?.setEngine(null),G?.dispose(),G=null,r.clear()},"destroy")},plan:s,setFlowState:n(a=>{(c.phase==="reading"||c.phase==="result")&&B(a==="done"&&c.phase!=="result"?"scanning":a)},"setFlowState"),settle:n((a,o)=>{let p=a==="verso"?"verso":"recto";R(o.ok?{type:"readOk",side:p}:{type:"readFailed",side:p,issue:o.issue}),o.ok||Y(p)},"settle"),takeDeviceRead:n(a=>he.get(a.image)?.value??null,"takeDeviceRead")}}n(Rt,"Pt");export{Tt as a,Wt as b,It as c,Rt as d};
1
+ import{a as ke,b as Se,c as ie,d as xe,e as Te,f as Ce,h as Ae}from"./chunk-3NOBU7TE.js";import{a as ne,d as Le,e as Re}from"./chunk-QWPURAKS.js";import{e as Q}from"./chunk-H5T4U7DM.js";import{e as Me,k as be}from"./chunk-6MYG4HWP.js";import{g as ae}from"./chunk-JS2IXPNL.js";import{a as n}from"./chunk-4FHWXBOB.js";function Pe(e,t){let r=new Set(e.flatMap(i=>i.sides.filter(l=>l[t]!==null).map(l=>l.side)));return r.size===1?[...r][0]:null}n(Pe,"Ee");function Xe(e){let t=Le.find(i=>i.docType===e),r=t.mrz==="none"?null:t.mrz==="td3"?"single":"verso";return{sides:t.sides,format:Re(e),mrz:t.mrz==="none"?"none":"required",mrzSide:r,barcodeSide:null,portraitSide:t.portraitSide,scripts:null}}n(Xe,"st");function Ye(e){let t=[];for(let r of e)for(let i of r.sides){if(!Array.isArray(i.scripts))return null;for(let l of i.scripts)t.includes(l)||t.push(l)}return t}n(Ye,"ct");function Je(e,t){if(t.length===0)return Xe(e);let r=t.some(s=>s.sides.length>1),i=new Set(t.map(s=>s.format)),l=i.size===1?[...i][0]:"card",u=t.filter(s=>s.sides.some(h=>h.mrz!==null)).length,d=t.find(s=>s.sides.length>1===r)?.sides.find(s=>s.portrait)?.side;return{sides:r?["recto","verso"]:["single"],format:l,mrz:u===t.length?"required":u===0?"none":"optional",mrzSide:Pe(t,"mrz"),barcodeSide:Pe(t,"barcode"),portraitSide:d??(r?"recto":"single"),scripts:Ye(t)}}n(Je,"Oe");function Qe(e,t){if(e===void 0)return[];let r=e.toUpperCase();return Object.prototype.hasOwnProperty.call(ne,r)?ne[r]?.[t]??[]:[]}n(Qe,"Ae");async function $e(e,t,r){return await e(t)?r:r==="recto"?"verso":"recto"}n($e,"Be");function Ze(e,t,r){return e!==t&&t==="verso"&&r.recto!==void 0&&r.verso===void 0?"verso":e}n(Ze,"Ie");var Ke={low:{maxLongEdge:1920,payloadTargetBytes:7e5,qMin:.7,qMax:.92},mid:{maxLongEdge:2240,payloadTargetBytes:12e5,qMin:.7,qMax:.92},good:{maxLongEdge:2560,payloadTargetBytes:16e5,qMin:.7,qMax:.92}};function et(e){let{deviceMemory:t,effectiveType:r,saveData:i,downlinkMbps:l,sourceLongEdge:u}=e,d=i===!0||r==="slow-2g"||r==="2g"||l!=null&&l>0&&l<1,s=t!=null&&t<=2,h=r==="4g"||l!=null&&l>=5,c=t!=null&&t>=6,k;d||s?k="low":h&&c?k="good":k="mid";let f=Ke[k],P=u&&u>0?Math.min(f.maxLongEdge,u):f.maxLongEdge;return{tier:k,...f,maxLongEdge:P}}n(et,"lt");function tt(e){let t={};try{let r=navigator;typeof r.deviceMemory=="number"&&(t.deviceMemory=r.deviceMemory);let i=r.connection;i&&(t.effectiveType=i.effectiveType,t.saveData=i.saveData,t.downlinkMbps=i.downlink)}catch{}return typeof e=="number"&&e>0&&(t.sourceLongEdge=e),et(t)}n(tt,"Fe");function rt(e,t,r){let i=Math.min(1,Math.max(0,(e-.28)/.21999999999999997)),l=(t+r)/2;return Math.max(t,r-i*(r-l))}n(rt,"dt");function at(e,t,r){let i=Math.max(e,t),l=i>0?Math.min(1,r/i):1;return{width:Math.max(1,Math.round(e*l)),height:Math.max(1,Math.round(t*l))}}n(at,"mt");async function it(e,t){let r=t.startQ,i=await e(r);for(let l=0;l<4&&!(i.size<=t.budgetBytes||r<=t.qMin);l++)r=Math.max(t.qMin,r-.08),i=await e(r);return{blob:i,quality:r}}n(it,"pt");async function nt(e,t,r,i,l){if(t<=0||r<=0)return null;let{width:u,height:d}=at(t,r,i.maxLongEdge),s=document.createElement("canvas");s.width=u,s.height=d;let h=s.getContext("2d");if(!h)return null;h.drawImage(e,0,0,u,d);let c=n(T=>new Promise((y,m)=>{s.toBlob(g=>g?y(g):m(new Error("canvas toBlob returned null")),"image/jpeg",T)}),"l"),k=rt(l,i.qMin,i.qMax),{blob:f,quality:P}=await it(c,{startQ:k,qMin:i.qMin,budgetBytes:i.payloadTargetBytes}).finally(()=>{s.width=0,s.height=0});if(f.size>5242880)throw new Error("encoded document exceeds the 5242880-byte media cap");return{blob:f,quality:P,width:u,height:d}}n(nt,"We");async function ot(e){let t=tt(Math.max(e.width,e.height)),r=await nt(e,e.width,e.height,t,.5);if(r===null)throw new Error("canvas encode unavailable");return{blob:r.blob,width:r.width,height:r.height}}n(ot,"oe");function We(e,t){return{layout:e,phase:"framing",captured:{},pending:[],lastCaptureAt:t,lastReportAt:t,manualShutter:!1,restPhase:"framing",readSides:[],needFlip:!1,flipped:!1,flipTimeoutSpent:!1,timeoutCapture:!1,lastShotByTimeout:!1}}n(We,"ie");var Ie=n(e=>e==="recto"?"verso":"recto","Ue"),Be=n(e=>e.phase==="framing"||e.phase==="locking"||e.phase==="flipCue"||e.phase==="reaskRecto","Ne"),ue=n(e=>(e.captured.recto!==void 0?1:0)+(e.captured.verso!==void 0?1:0)+e.pending.length,"se");function oe(e,t){return e.lastCaptureAt>=0&&e.lastReportAt>=0?e:{...e,lastCaptureAt:e.lastCaptureAt<0?t:e.lastCaptureAt,lastReportAt:e.lastReportAt<0?t:e.lastReportAt}}n(oe,"ae");function lt(e,t,r){if(e.phase==="result")return{...e,lastReportAt:r};let i=!t.present||e.captureArea!==void 0&&t.areaFrac<.6*e.captureArea,{flipped:l,awaySince:u}=e;i&&(u=u??r),u!==void 0&&r-u>=250&&(l=!0),i||(u=void 0);let d=e.flipTimeoutSpent&&!(l&&!e.flipped),s={...e,lastReportAt:r,flipped:l,awaySince:u,flipTimeoutSpent:d,lastArea:t.areaFrac};if(!Be(e))return s;if(e.needFlip&&!l){if(!t.ready)return{...s,phase:e.restPhase,goodSince:void 0};let h=e.lastShot!==void 0&&e.pending.includes(e.lastShot);if(d||h)return{...s,goodSince:void 0,phase:e.restPhase};let c=e.goodSince??r;return r-c>=1800?{...s,goodSince:c,phase:"capturing",flipTimeoutSpent:!0,timeoutCapture:!0}:{...s,goodSince:c,phase:e.restPhase}}return t.ready?{...s,phase:"capturing",goodSince:e.goodSince??r}:{...s,goodSince:void 0,phase:t.locking?"locking":e.restPhase}}n(lt,"ft");function st(e,t){if(!Be(e)||e.manualShutter)return e;let r=t-e.lastReportAt>=2e3,i=t-e.lastCaptureAt>=6e3;return r||i?{...e,manualShutter:!0}:e}n(st,"gt");function dt(e,t,r){let i=e.layout==="singlePage",l=i?{recto:t}:e.captured,u=i?[]:[...e.pending,t],d={...e,captured:l,pending:u,lastShot:t,lastCaptureAt:r,lastReportAt:-1,manualShutter:!1,goodSince:void 0,notice:void 0,awaySince:void 0,flipped:!1,lastShotByTimeout:e.timeoutCapture,timeoutCapture:!1,captureArea:e.lastArea};return i||ue({captured:l,pending:u})>=2?{...d,phase:"reading",restPhase:"framing",current:void 0,needFlip:!1}:{...d,phase:"flipCue",restPhase:"flipCue",current:void 0,needFlip:!0}}n(dt,"ht");function Ue(e,t,r){return e.pending.includes(t)?{...e,pending:e.pending.filter(i=>i!==t),lastShot:e.lastShot===t?void 0:e.lastShot,phase:e.phase==="capturing"?e.phase:"flipCue",restPhase:"flipCue",current:Ie(r),needFlip:!0,flipTimeoutSpent:!0,goodSince:void 0,manualShutter:!0,notice:"same_face",lastCaptureAt:-1,lastReportAt:-1}:e}n(Ue,"Ge");function ut(e,t,r){if(!e.pending.includes(t))return e;if(e.captured[r]!==void 0)return Ue(e,t,r);let i=e.pending.filter(h=>h!==t),l={...e,pending:i,captured:{...e.captured,[r]:t}};if(ue(l)!==1||e.layout==="singlePage")return l;let u=Ie(r),d=u==="recto"&&e.restPhase==="reaskRecto"?"reaskRecto":"flipCue",s=e.phase==="flipCue"||e.phase==="reaskRecto"||e.phase==="framing";return{...l,restPhase:d,current:u,phase:s?d:e.phase}}n(ut,"bt");function ct(e,t){let r=t.id??e.captured[t.side],i={...e.captured};(t.id===void 0||i[t.side]===t.id)&&delete i[t.side];let l=e.pending.filter(c=>c!==r),u=e.layout==="twoSided"&&ue({captured:i,pending:l})>0,d=e.lastShotByTimeout||r===e.lastShot!==e.flipped,s=u&&!d,h=s?t.side==="recto"?"reaskRecto":"flipCue":"framing";return{...e,captured:i,pending:l,readSides:e.readSides.filter(c=>c!==t.side),lastShot:e.lastShot===r?void 0:e.lastShot,notice:t.issue,goodSince:void 0,manualShutter:!1,phase:h,restPhase:h,current:t.side,needFlip:s,flipped:!1,flipTimeoutSpent:!1,awaySince:void 0,lastCaptureAt:-1,lastReportAt:-1}}n(ct,"yt");function pt(e,t){switch(t.type){case"report":return lt(oe(e,t.at),t.report,t.at);case"tick":return st(oe(e,t.at),t.at);case"captured":return dt(oe(e,t.at),t.id,t.at);case"captureFailed":return{...e,phase:e.restPhase,goodSince:void 0,lastCaptureAt:t.at,manualShutter:!0,timeoutCapture:!1};case"classified":return ut(e,t.id,t.side);case"duplicate":return Ue(e,t.id,t.side);case"readOk":{let r=e.readSides.includes(t.side)?e.readSides:[...e.readSides,t.side],i=["recto","verso"].filter(u=>e.captured[u]!==void 0),l=e.phase==="reading"&&e.pending.length===0&&i.every(u=>r.includes(u));return{...e,readSides:r,flipTimeoutSpent:!1,phase:l?"result":e.phase}}case"readFailed":return ct(e,t);case"clockRestart":return e.lastCaptureAt<0&&e.lastReportAt<0&&e.awaySince===void 0?e:{...e,awaySince:void 0,lastCaptureAt:-1,lastReportAt:-1};case"retake":return{...We(e.layout,-1),lastCaptureAt:-1,lastReportAt:-1};default:return e}}n(pt,"qe");function mt(e,t,r=!1){let i=e(t);return i===null?"recto":!r||i.y+i.height/2>=t.height/2?"verso":"recto"}n(mt,"St");async function ht(e,t=!1){let{detectMrzBand:r}=await import("./mrz-band-VYHOTDHY-VEZ2J5IL.js");return mt(r,e,t)}n(ht,"Mt");async function ze(e,t=480,r,i=r!=null){let l=r??{x:0,y:0,width:e.width,height:e.height},u=Math.max(1,Math.round(l.height/l.width*t)),d=document.createElement("canvas");d.width=t,d.height=u;try{let s=d.getContext("2d");return s===null?"recto":(s.drawImage(e,l.x,l.y,l.width,l.height,0,0,t,u),await ht(s.getImageData(0,0,t,u),i))}finally{d.width=0,d.height=0}}n(ze,"ce");var le=n((e,t,r)=>Math.min(r,Math.max(t,Math.round(e))),"ue"),$=n(e=>Math.round(Math.min(1,Math.max(0,e))*1e4)/1e4,"$");async function ft(e,t,r,i){let l=i.decode??(h=>createImageBitmap(h)),u=n(async()=>e.stillRead(await l(t),i.region??[0,0,1,1],i.detectorLimit),"u"),d;try{d=await u()}catch{try{await new Promise(h=>setTimeout(h,i.retryMs??300)),d=await u()}catch{return null}}let s=d.mrzBox;return s===void 0?null:{engine:i.engine,source:"live_mrz",format:r.format,lineCount:le(r.lineCount,2,3),checkDigitsValid:!0,stillConfirmed:d.valid&&d.digest===r.digest,band:[$(s[0]),$(s[1]),$(Math.min(s[2],1-s[0])),$(Math.min(s[3],1-s[1]))],digest:r.digest,framesToValid:le(r.framesToValid,1,1e3),msToValid:le(r.msToValid,0,12e4)}}n(ft,"He");var gt=new Uint8Array([0,97,115,109,1,0,0,0,1,5,1,96,0,1,123,3,2,1,0,10,10,1,8,0,65,0,253,15,253,98,11]),vt=new Uint8Array([0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,2,1,0,10,7,1,5,0,6,64,11,11]);function yt(e=globalThis){let t=e.WebAssembly?.validate;if(typeof t!="function")return{ok:!1,reason:"simd"};try{if(!t.call(e.WebAssembly,gt)||!t.call(e.WebAssembly,vt))return{ok:!1,reason:"simd"}}catch{return{ok:!1,reason:"simd"}}return typeof e.Worker!="function"?{ok:!1,reason:"worker"}:typeof e.createImageBitmap!="function"?{ok:!1,reason:"bitmap"}:{ok:!0}}n(yt,"Xe");function wt(e=globalThis){let t=e.navigator?.connection;return t?.saveData===!0||["slow-2g","2g","3g"].includes(t?.effectiveType??"")}n(wt,"Ye");var j,E=(j=class extends Error{constructor(t){super(t),this.name="OcrEngineError",this.code=t}},n(j,"E"),j);function De(){let e=n(t=>(t.close(),Promise.reject(new E("unsupported"))),"e");return{ready:Promise.resolve("unsupported"),busy:!1,bandRead:e,stillRead:e,layoutRead:e,dispose:n(()=>{},"dispose")}}n(De,"Ve");function Mt(e){let t;try{if(e.createWorker)t=e.createWorker();else if(e.workerUrl!==void 0)t=new Worker(e.workerUrl,{type:"module",name:"sekyro-ocr"});else return De()}catch{return De()}let r=new Map,i=0,l=!1,u=!1,d=!1;t.addEventListener("message",m=>{let g=m.data,b=r.get(g.id);b&&(r.delete(g.id),b.resolve(g))});let s=n(()=>{for(let m of r.values())m.reject(new E("error"));r.clear(),c()},"s");t.addEventListener("error",s),t.addEventListener("messageerror",s);function h(m,g=[]){if(l)return Promise.reject(new E("disposed"));let b=++i;return new Promise((D,W)=>{r.set(b,{resolve:D,reject:W});try{t.postMessage({...m,id:b},g)}catch{r.delete(b),W(new E("error"))}})}n(h,"p");function c(){if(!l){l=!0;try{t.postMessage({id:++i,kind:"dispose"})}catch{}t.terminate();for(let m of r.values())m.reject(new E("disposed"));r.clear()}}n(c,"l");let k=(async()=>{let m=await h({kind:"init",baseUrl:e.baseUrl,salt:e.salt,detectorLimit:e.tuning.detectorLimit,maxDownloadMs:e.tuning.maxDownloadMs});if(m.kind==="failed")return m.reason;if(m.kind!=="ready")return"error";let g=await h({kind:"warmup"});if(g.kind!=="ready")return"error";let b=g.benchMs??g.warmupMs,D=e.deviceMemoryGb===void 0?Se():e.deviceMemoryGb;return{warmupMs:g.warmupMs,downloadMs:m.downloadMs,cached:m.cached,benchMs:b,tier:ke(b,D)}})().catch(()=>"error"),f,P=new Promise(m=>{f=setTimeout(()=>m("timeout"),e.tuning.loadTimeoutMs)}),T=Promise.race([k,P]).then(m=>(clearTimeout(f),typeof m=="string"?c():d=!0,l&&typeof m!="string"?"error":m));(e.page===void 0?globalThis.addEventListener?globalThis:null:e.page)?.addEventListener("pagehide",c,{once:!0});async function y(m,g,b){if(l)throw g.close(),new E("disposed");if(!d)throw g.close(),new E("not_ready");if(u)throw g.close(),new E("busy");u=!0;let D;try{let W=new Promise((U,O)=>{D=setTimeout(()=>{O(new E("timeout")),c()},e.tuning.readTimeoutMs??1e4)}),q=await Promise.race([h(m,[g]),W]);if(q.kind===b){let{id:U,...O}=q;return O}throw new E(q.kind==="error"?q.code:q.kind==="failed"?q.reason:"error")}finally{clearTimeout(D),u=!1}}return n(y,"P"),{ready:T,get busy(){return u},bandRead:n((m,g=e.tuning.detectorLimit)=>y({kind:"band",bitmap:m,detectorLimit:g},m,"band"),"bandRead"),stillRead:n((m,g,b=e.tuning.detectorLimit)=>y({kind:"still",bitmap:m,region:g,detectorLimit:b},m,"band"),"stillRead"),layoutRead:n((m,g)=>y({kind:"layout",bitmap:m,detectorLimit:g},m,"layout"),"layoutRead"),dispose:c}}n(Mt,"Qe");var Z="sekyro-ocr-1",se=n(e=>e!==null&&typeof e=="object"?e:{},"le"),z=n((e,t,r,i)=>typeof e=="number"&&Number.isFinite(e)&&e>=t&&e<=r?e:i,"_"),qe=n((e,t)=>typeof e=="boolean"?e:t,"Ke"),Ee=n(e=>{let t=typeof e=="string"?/^sekyro-ocr-(\d{1,4})$/.exec(e):null;return t?Number(t[1]):Number.POSITIVE_INFINITY},"je");function bt(e,t={}){let r=se(e),i=se(r.liveMrz),l=se(r.frontLock),u=Ee(t.engine??Z),d=t.mode==="off",s=n(g=>g.enabled===!0?g.arm==="live"?"live":"control":null,"s"),h=s(i),c=s(l),k=n((g,b)=>!d&&b==="live"&&Ee(g.minEngine??Z)<=u,"M"),f=Ce,P=k(i,h)?{detectorLimit:z(i.detectorLimit,320,1600,f.detectorLimit),bandMaxWidthPx:z(i.bandMaxWidthPx,320,4096,f.bandMaxWidthPx),minBandWidthPx:z(i.minBandWidthPx,0,4096,f.minBandWidthPx),bandTop:z(i.bandTop,0,.95,f.bandTop),minIntervalMs:z(i.minIntervalMs,0,5e3,f.minIntervalMs),stableReads:Math.round(z(i.stableReads,1,10,f.stableReads)),profileReads:Math.round(z(i.profileReads,1,100,f.profileReads)),maxReadMs:z(i.maxReadMs,50,6e4,f.maxReadMs),searchTimeoutMs:z(i.searchTimeoutMs,1e3,12e4,f.searchTimeoutMs),hint:qe(i.hint,!0),stillConfirm:qe(i.stillConfirm,!0)}:null,T=Te,y=n((g,b,D)=>z(l[g],b,D,T[g]),"S"),m=k(l,c)?{minLines:Math.round(y("minLines",1,50)),fillMin:y("fillMin",0,1),fillMax:y("fillMax",0,2),offsetMax:y("offsetMax",0,1),steadyFillDelta:y("steadyFillDelta",0,1),steadyOffsetDelta:y("steadyOffsetDelta",0,1),layoutShiftMax:y("layoutShiftMax",0,1),lineCountDelta:Math.round(y("lineCountDelta",0,50)),lockMs:y("lockMs",0,3e4),steadyMs:y("steadyMs",0,3e4),minFrames:Math.round(y("minFrames",1,100)),minIntervalMs:y("minIntervalMs",0,5e3),maxWidthPx:y("maxWidthPx",160,2048),detectorLimit:y("detectorLimit",320,1600),searchTimeoutMs:y("searchTimeoutMs",1e3,12e4)}:null;return{enabled:P!==null||m!==null,liveMrz:P,textLock:m,liveMrzArm:h,frontLockArm:c,load:{detectorLimit:P?.detectorLimit??m?.detectorLimit??f.detectorLimit,loadTimeoutMs:z(i.loadTimeoutMs,1e3,12e4,2e4),maxDownloadMs:z(i.maxDownloadMs,1e3,12e4,2e4)},reportSampleRate:z(i.reportSampleRate,0,1,1)}}n(bt,"$e");function kt(e,t){return e.enabled?!(t.probe??yt)().ok||(t.slow??wt)()?{ok:!1,reason:"unsupported"}:{ok:!0,engine:Mt({baseUrl:t.baseUrl,salt:t.salt,tuning:{detectorLimit:e.load.detectorLimit,maxDownloadMs:e.load.maxDownloadMs,loadTimeoutMs:e.load.loadTimeoutMs},...t.workerUrl!==void 0?{workerUrl:t.workerUrl}:{},...t.createWorker!==void 0?{createWorker:t.createWorker}:{},...t.page!==void 0?{page:t.page}:{},...t.deviceMemoryGb!==void 0?{deviceMemoryGb:t.deviceMemoryGb}:{}})}:{ok:!1,reason:"off"}}n(kt,"Je");function St(e=typeof navigator<"u"?navigator.userAgent:""){return/SamsungBrowser\//.test(e)?"samsung":/Firefox\/|FxiOS\//.test(e)?"firefox":/Chrome\/|CriOS\/|Chromium\//.test(e)&&!/Edg\/|OPR\//.test(e)?"chrome":/Safari\//.test(e)&&/Version\/|Mobile\//.test(e)&&!/Chrome\/|CriOS\//.test(e)?"safari":"other"}n(St,"kt");var F=n(e=>e===void 0||!Number.isFinite(e)?void 0:Math.min(6e5,Math.max(0,Math.round(e))),"I"),de=n((e,t,r)=>e===void 0||!Number.isFinite(e)?void 0:Math.min(r,Math.max(t,Math.round(e))),"de");function xt(e){let t=e.assist??null,r=e.load!==null&&e.load!==void 0&&typeof e.load=="object"?e.load:null,i=typeof e.load=="string"?e.load:null,l=t!==null?t.outcome:i==="unsupported"||i==="download"||i==="integrity"?i:i==="error"||i==="timeout"?"error":"off",u={kind:"live_mrz",platform:"web",engine:e.engine??Z,arm:e.arm,capture:e.capture,outcome:l,reads:de(t?.reads??0,0,1e4)??0,browser:e.browser??St()},d=n((s,h)=>{h!==void 0&&(u[s]=h)},"c");return d("format",t?.format),d("framesToValid",de(t?.framesToValid,1,1e4)),d("msToValid",F(t?.msToValid)),d("framesToLock",de(t?.framesToLock,1,1e4)),d("msToLock",F(t?.msToLock)),d("msToCapture",F(e.msToCapture)),d("readP50Ms",F(t?.readP50Ms)),d("readP90Ms",F(t?.readP90Ms)),d("deviceClass",t?.deviceClass),r!==null&&(d("warmupMs",F(r.warmupMs)),d("downloadMs",F(r.downloadMs)),d("cached",r.cached),d("tier",r.tier),d("benchMs",F(r.benchMs))),d("stillConfirmed",e.stillConfirmed),d("typeMismatch",e.typeMismatch),u}n(xt,"Ze");function Fe(e,t){return e===void 0?!1:t==="passport"?e!=="TD3":e==="TD3"}n(Fe,"me");var Tt=2;async function Ct(e){let t=await import("./capture-session-doc-LKMMJG4H-GQNWHWDA.js");return new t.CaptureSessionDoc(e)}n(Ct,"xt");function At(e){return{topLeft:{x:e.x,y:e.y},topRight:{x:e.x+e.width,y:e.y},bottomRight:{x:e.x+e.width,y:e.y+e.height},bottomLeft:{x:e.x,y:e.y+e.height}}}n(At,"vt");function Lt(e,t,r){let i=[e.topLeft,e.topRight,e.bottomRight,e.bottomLeft],l=0;for(let u=0;u<i.length;u+=1){let d=i[u],s=i[(u+1)%i.length];l+=d.x*s.y-s.x*d.y}return t>0&&r>0?Math.abs(l)/2/(t*r):0}n(Lt,"Rt");function Wt(){import("./capture-session-doc-LKMMJG4H-GQNWHWDA.js").then(e=>e.warmDocDetector()).catch(()=>{})}n(Wt,"hn");function It(e){return Rt(e,{}).handle}n(It,"bn");function Rt(e,t){let r=Me(),i=be({enabled:e.keepScreenAwake!==!1}),l=t.decode??(a=>createImageBitmap(a)),u=t.blurRefuseSharpnessMax??.16,d=t.now??(()=>performance.now()),s=Je(e.documentType,t.catalogCapture===!0?t.captureSeries??Qe(e.issuer,e.documentType):[]),h=s.sides.length===1||e.side==="single",c=We(h?"singlePage":"twoSided",d());if(!h&&(e.side==="recto"||e.side==="verso")){let a=e.side==="recto"?"verso":"recto";c={...c,captured:{[a]:"server"},readSides:[a],current:e.side,phase:"flipCue",restPhase:"flipCue"}}let k="idle",f=null,P=null,T=!0,y=0,m=0,g=!1,b=!1,D="",W=null,q,U=null,O=[],ce=s.mrz==="none",Oe=s.barcodeSide==="recto"||s.barcodeSide==="verso"?s.barcodeSide:null,I=ce&&!h?t.barcode?.side??Oe:null,pe=e.barcodeAssetBaseUrl??t.barcode?.assetBaseUrl,K=null,me=n(()=>I===null||pe===void 0||t.barcode?.seen!==void 0?Promise.resolve(null):(K??(K=import("./barcode-detect-C5IOXMKI-ZOZ2WOWU.js").then(a=>a.loadBarcodeDetect(pe)).catch(()=>null)),K),"ge"),Ne=n(async(a,o)=>{if(I===null)return null;let p=I==="recto"?"verso":"recto";try{let v=t.barcode?.seen;if(v!==void 0)return await v(a)?I:p;let[A,S]=await Promise.all([me(),o()]);if(A===null||S===null)return null;let x=Math.min(1600,S.width),M=document.createElement("canvas");M.width=x,M.height=Math.max(1,Math.round(S.height/S.width*x));try{let w=M.getContext("2d");return w===null?null:(w.drawImage(S,0,0,M.width,M.height),await $e(A,w.getImageData(0,0,M.width,M.height),I))}finally{M.width=0,M.height=0}}catch{return null}},"tt"),C=t.webOcr!==void 0&&!ce?bt(t.webOcr.captureDocument,{mode:e.liveMrz?.mode??"auto"}):null,G=null,N=C===null||!C.enabled?"off":null,_=null,X=null,he=new WeakMap,ee="";if(C!==null&&C.enabled&&t.webOcr!==void 0){let a=t.webOcr,o=kt(C,{baseUrl:e.liveMrz?.assetBaseUrl??a.baseUrl,salt:a.salt,...e.liveMrz?.workerUrl!==void 0?{workerUrl:e.liveMrz.workerUrl}:{},...a.createWorker!==void 0?{createWorker:a.createWorker}:{}});if(o.ok){G=o.engine;let p=new Ae({textLock:C.textLock,liveMrz:C.liveMrz});_=p;let v=o.engine;v.ready.then(A=>{N=A,typeof A!="string"&&T&&p.setEngine(v,A.tier)})}else N=o.reason}let V=n(a=>{let o=JSON.stringify(a);o!==ee&&(ee=o,r.emit("mrz",a))},"N"),fe=n((a,o)=>{let p=t.webOcr?.reports;if(p===void 0||C===null||a===void 0)return;let v=a.format==="ID-3"||a.side==="single"?"single":a.side==="verso"?"verso":"recto",A=v!=="recto"?C.liveMrzArm??C.frontLockArm:C.frontLockArm;if(A===null||Math.random()>=C.reportSampleRate)return;let S=a.via==="live_mrz"?X:null,x=n(()=>{let M=S?.value??null;p([xt({arm:A,capture:v,assist:a.ocr??null,load:A==="control"?"off":N,...a.msToCapture!==void 0?{msToCapture:a.msToCapture}:{},...M!==null&&M.stillConfirmed!==void 0?{stillConfirmed:M.stillConfirmed}:{},...o!==void 0?{typeMismatch:Fe(o.format,s.format==="ID-3"?"passport":"card")}:{}})])},"k");S!==null&&S.value===null?Promise.race([S.promise,new Promise(M=>setTimeout(M,3e3))]).then(x):x()},"be"),B=n(a=>{!T||a===k||(k=a,i.setActive(a==="starting"||a==="scanning"),r.emit("state",a))},"W"),Ve=n((a,o)=>o===void 0?null:h?"single":a.captured.recto===o?"recto":a.captured.verso===o?"verso":null,"nt"),je=n(a=>({phase:a.phase,captured:h?a.captured.recto!==void 0?["single"]:[]:["recto","verso"].filter(o=>a.captured[o]!==void 0),expected:h?null:a.current??null,notice:a.notice??null,lastShot:Ve(a,a.lastShot),manualShutter:a.manualShutter,torchAvailable:f?.torchAvailable()??!1,torch:b}),"rt"),ge=n(()=>{let a=f;a!==null&&a.captureNow().catch(()=>R({type:"captureFailed",at:d()}))},"ye");function R(a){if(!T)return;let o=c;c=pt(c,a),c.phase==="capturing"&&o.phase!=="capturing"&&Promise.resolve().then(ge),c.phase==="result"&&o.phase!=="result"&&(B("done"),ve());let p=je(c),v=JSON.stringify(p);v!==D&&(D=v,r.emit("scan",p))}n(R,"L");function ve(){U!==null&&clearInterval(U),U=null;for(let a of O.splice(0))a();f?.destroy(),f=null,i.setActive(!1)}n(ve,"Se");let ye=n(()=>f?.captureReport?.(),"Me"),te=!1,we=n((a,o)=>{if(!(a===void 0||t.onFaceReport===void 0))try{t.onFaceReport(a,o)}catch{}},"De"),Y=n(a=>{ee="",!(f===null||c.phase==="reading"||c.phase==="result")&&(te=!1,f.rearm(h?"single":c.current??a))},"Q"),Ge=n(async(a,o,p,v)=>{if(X=null,v!==void 0&&G!==null&&C?.liveMrz?.hint===!0){let w={promise:ft(G,a,v,{engine:Z,detectorLimit:C.liveMrz.detectorLimit}).catch(()=>null),value:null};w.promise.then(L=>{w.value=L}),X=w}v!==void 0&&Fe(v.format,s.format==="ID-3"?"passport":"card")&&V({state:"mismatch",format:v.format});let A=ye();we(A,"captured"),te=!0,fe(A,v);let S=p===void 0?W:p===null?null:{quad:At(p),frameWidth:0,frameHeight:0,inStill:!0},x={decoded:null},M=n(()=>(x.decoded??(x.decoded=Promise.resolve().then(()=>l(a)).catch(()=>null)),x.decoded),"y");try{await He(a,o,S,M,X)}finally{x.decoded!==null&&(await x.decoded)?.close()}},"ot"),He=n(async(a,o,p,v,A)=>{let S=`shot-${y+=1}`;if(R({type:"captured",id:S,at:d()}),e.haptics!==!1)try{globalThis.navigator?.vibrate?.(30)}catch{}if(!g&&u>0){let w=await(t.measureSharpness!==void 0?t.measureSharpness(a,p):v().then(L=>L===null?-1:xe(L,ie(p?.quad??null,p?.inStill===!0?L:{width:p?.frameWidth??0,height:p?.frameHeight??0},L)))).catch(()=>-1);if(!T)return;if(Number.isFinite(w)&&w>=0&&w<u){g=!0;let L=h?"recto":c.current??(c.captured.recto===void 0?"recto":"verso");R({type:"readFailed",side:L,id:S,issue:"blurry"}),Y(L);return}}g=!1;let x;if(h)x="single";else{let w=c.current,L=t.classify===void 0?await Ne(a,v):null,H=(L===null||I===null?L:Ze(L,I,c.captured))??await(t.classify!==void 0?t.classify(a):v().then(J=>J===null?w??"recto":p?.inStill===!0?ze(J,480,null,!0):ze(J,480,ie(p?.quad??null,{width:p?.frameWidth??0,height:p?.frameHeight??0},J)))).catch(()=>w??"recto");if(!T)return;if(c.captured[H]!==void 0&&m<Tt){m+=1,R({type:"duplicate",id:S,side:H}),Y(H==="recto"?"verso":"recto");return}x=c.captured[H]!==void 0&&w!==void 0?w:H,m=0,R({type:"classified",id:S,side:x})}let M=x==="verso"?"verso":"recto";try{let w=t.encode!==void 0?await t.encode(a):await v().then(L=>{if(L===null)throw new Error("the still could not be decoded");return ot(L)});if(!T)return;A!==null&&he.set(w.blob,A),r.emit("captured",{image:w.blob,side:x,documentType:e.documentType,...e.issuer!==void 0?{issuer:e.issuer}:{},width:w.width,height:w.height,previewDataUrl:o}),t.deferRead!==!0&&R({type:"readOk",side:M})}catch(w){R({type:"readFailed",side:M,id:S,issue:"technical"}),r.emit("error",Q("generic",!0,{phase:"keyframes",name:ae(w)}))}Y(M==="recto"?"verso":"recto")},"at"),_e=n(a=>{O.push(a.on("statechange",({state:o})=>{o==="preflight"||o==="acquiring"?B("starting"):o==="positioning"?B("scanning"):o==="captured"?B("captured"):o==="error"&&B("error")}),a.on("feedback",({key:o,reticle:p})=>r.emit("feedback",{key:o,reticle:p})),a.on("checks",o=>{r.emit("gate",{progress:o.p,quad:o.quad,frameWidth:o.frameWidth,frameHeight:o.frameHeight,...o.guide!==void 0?{guide:{detected:o.guide.detected,fill:o.guide.fill,offsetX:o.guide.offsetX??0,offsetY:o.guide.offsetY??0}}:{}});let p=o.ocr?.mrz;p!==void 0&&(p.state==="fallback"?V({state:"fallback",reason:p.reason}):p.state==="valid"?V({state:"valid",format:p.format}):p.state==="reading"?V({state:"reading",...p.format?{format:p.format}:{},...p.coach?{coach:p.coach}:{}}):V({state:"searching"}));let v=o.quad===null?0:Lt(o.quad,o.frameWidth,o.frameHeight);W=o.quad===null?null:{quad:o.quad,frameWidth:o.frameWidth,frameHeight:o.frameHeight},R({type:"report",report:{present:o.quad!==null&&o.plausible||o.guide?.detected===!0,ready:o.ready===!0,locking:o.p>=.5,areaFrac:v},at:d()})}),a.on("error",({kind:o,retryable:p,detail:v})=>r.emit("error",Q(o,p,v))),a.on("artifacts",o=>{Ge(o.keyframe,o.previewDataUrl,o.docRegion,o.liveMrz)}))},"it"),re=n(()=>(P??(P=(async()=>{if(T){if(me(),f===null){let a;try{a=await(t.createEngine??Ct)({...t.engineOptions??{},...q!==void 0?{guide:q}:{},video:e.video,format:s.format,side:h?"single":e.side??"recto",autoCapture:!1,..._!==null?{ocr:_}:{}})}catch(p){B("error"),r.emit("error",Q("models",!0,{phase:"models",name:ae(p)}));return}if(!T){a.destroy();return}f=a,_e(a);let o=t.tickMs??500;o>0&&(U=setInterval(()=>R({type:"tick",at:d()}),o))}R({type:"clockRestart"}),C!==null&&C.liveMrzArm==="live"&&(N==="unsupported"||N==="off")&&V({state:"fallback",reason:N}),await f.start()}})().finally(()=>{P=null})),P),"ee");return{handle:{get state(){return k},on:n((a,o)=>r.on(a,o),"on"),start:re,retry:n(()=>{if(f===null&&c.phase==="result"){R({type:"retake"}),m=0,g=!1,re();return}if(f!==null&&k!=="error"){R({type:"retake"}),m=0,g=!1,f.rearm(h?"single":void 0);return}re()},"retry"),setSide:n(a=>{h||a==="single"||(c.current!==a&&(c={...c,current:a}),R({type:"clockRestart"}),c.phase!=="reading"&&c.phase!=="result"&&f?.rearm(a))},"setSide"),shutter:ge,focusAt:n((a,o)=>{f?.focusAt?.(a,o)},"focusAt"),setGuide:n(a=>{q=a,f?.setGuide?.(a)},"setGuide"),setTorch:n(a=>{b=a,f?.setTorch(a),R({type:"tick",at:d()})},"setTorch"),destroy:n(()=>{if(T&&f!==null&&k!=="done"){let a=ye();!te&&a!==void 0&&a.ticks>0&&we(a,"abandoned"),fe(a,void 0)}T=!1,ve(),_?.setEngine(null),G?.dispose(),G=null,r.clear()},"destroy")},plan:s,setFlowState:n(a=>{(c.phase==="reading"||c.phase==="result")&&B(a==="done"&&c.phase!=="result"?"scanning":a)},"setFlowState"),settle:n((a,o)=>{let p=a==="verso"?"verso":"recto";R(o.ok?{type:"readOk",side:p}:{type:"readFailed",side:p,issue:o.issue}),o.ok||Y(p)},"settle"),takeDeviceRead:n(a=>he.get(a.image)?.value??null,"takeDeviceRead")}}n(Rt,"Pt");export{Tt as a,Wt as b,It as c,Rt as d};
@@ -1 +1 @@
1
- import{a as tt,b as te,c as ee,d as dt,e as ie}from"./chunk-Z25MPNSU.js";import{c as Kt,d as Yt,g as Vt}from"./chunk-3NOBU7TE.js";import{b as Jt,c as Zt}from"./chunk-QWPURAKS.js";import{b as $t}from"./chunk-L22GFJQV.js";import{d as Nt,e as Qt,f as Xt}from"./chunk-ZEUFK4EC.js";import{a as ct,b as ut,c as Y,d as Ut}from"./chunk-P7K7ELYZ.js";import{g as qt,i as Gt,j as jt,k as Bt,l as Ht}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 ze(i){return i.framing==="no_document"?"sensing":i.framing==="too_far"?"too_far":i.framing==="too_close"?"too_close":i.framing==="edge_clipped"?"edge_clipped":i.framing==="wrong_shape"?"wrong_shape":i.framing==="tilted"?"tilted":i.lighting==="too_dark"?"too_dark":i.lighting==="too_bright"?"too_bright":i.glare==="glare"?"glare":i.blur==="blurry"?"blurry":"hold_still"}n(ze,"se");var G,Ce=(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 s=new Map;for(let o of this.votes){let l=(e-o.atMs)/1e3,r=this.decayPerSecond**l;s.set(o.key,(s.get(o.key)??0)+r)}let a=this.current.key,h=-1;for(let[o,l]of s)l>h&&(h=l,a=o);return a!==this.current.key&&(this.current=et[a],this.currentSinceMs=e),this.current}},n(G,"ot"),G),Ie=Object.freeze({MAX_AREA_FRAC:.92,TILT_MAX_SIDE_RATIO:1.3,GLARE_MAX_SPECULAR_FRAC:.025});function Le(i){let{data:t,width:e,height:s}=i,a=e*s;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(Le,"ae");function Oe(i){let t=n((r,c)=>Math.hypot(c.x-r.x,c.y-r.y),"t"),e=t(i.topLeft,i.topRight),s=t(i.bottomLeft,i.bottomRight),a=t(i.topLeft,i.bottomLeft),h=t(i.topRight,i.bottomRight),o=Math.max(e,s)/Math.max(1e-6,Math.min(e,s)),l=Math.max(a,h)/Math.max(1e-6,Math.min(a,h));return Math.max(o,l)}n(Oe,"Ye");function Ee(i){let t={...te,...i.thresholds},e=Ie,{quad:s,frameWidth:a,frameHeight:h,measures:o}=i,l=i.format==="ID-3",r="ok";if(s===null)r="no_document";else if(l){let d=dt(s),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":se(s,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=ee(s,a,h),m=dt(s),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":se(s,a,h,t.EDGE_CLIP_MARGIN_PX)?r="edge_clipped":Zt(i.format,g)?Oe(s)>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(Ee,"ce");function se(i,t,e,s){return[i.topLeft,i.topRight,i.bottomRight,i.bottomLeft].some(a=>a.x<=s||a.y<=s||a.x>=t-s||a.y>=e-s)}n(se,"re");var Pe=Object.freeze({width:1920,height:1080}),We=Object.freeze({width:3840,height:2160}),ae=4096,Ne=2560,qe=640,it=.15,V=Object.freeze({side:.2,above:.9,below:.3});function C(i){let t=[i.topLeft.x,i.topRight.x,i.bottomRight.x,i.bottomLeft.x],e=[i.topLeft.y,i.topRight.y,i.bottomRight.y,i.bottomLeft.y],s=Math.min(...t),a=Math.min(...e);return{x:s,y:a,width:Math.max(...t)-s,height:Math.max(...e)-a}}n(C,"E");function ge(i,t){let e=Math.max(0,Math.floor(i.x)),s=Math.max(0,Math.floor(i.y)),a=Math.min(t.width,Math.ceil(i.x+i.width)),h=Math.min(t.height,Math.ceil(i.y+i.height));return a-e<16||h-s<16?null:{x:e,y:s,width:a-e,height:h-s}}n(ge,"de");function Ge(i,t,e){if(i===null||t.width<=0||t.height<=0)return null;let s=C(i);if(s.width<=0||s.height<=0)return null;let a=e==="ID-3"?{x:s.x-s.width*V.side,y:s.y-s.width*V.above,width:s.width*(1+2*V.side),height:s.height+s.width*(V.above+V.below)}:{x:s.x-s.width*it,y:s.y-s.height*it,width:s.width*(1+2*it),height:s.height*(1+2*it)};return ge(a,t)}n(Ge,"qe");function pe(i,t,e){let s=Math.max(i,t);return s>0?Math.min(1,e/s):1}n(pe,"pt");function Me(i,t,e,s,a=Ne){let h=t.width>0?e.width/t.width:1,o=t.height>0?e.height/t.height:1,l=i===null?null:{topLeft:{x:i.topLeft.x*h,y:i.topLeft.y*o},topRight:{x:i.topRight.x*h,y:i.topRight.y*o},bottomRight:{x:i.bottomRight.x*h,y:i.bottomRight.y*o},bottomLeft:{x:i.bottomLeft.x*h,y:i.bottomLeft.y*o}},r=Ge(l,e,s)??{x:0,y:0,width:e.width,height:e.height},c=pe(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=ge({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(Me,"gt");var je=960,ft=[{width:1920,height:1080},{width:2560,height:1440}];function Be(i){let t=Number.isFinite(i)&&i>0?Math.min(1,i):.85;return ft.find(e=>e.height*t>=je)??ft[ft.length-1]}n(Be,"ti");function He(i,t,e,s=We,a){let h=a===void 0?null:Be(a.fill);if(e==="LOW"&&h===null)return null;let o=e==="LOW"||h!==null&&Math.max(h.width,h.height)>Math.max(s.width,s.height)?h:s,l=i?.width?.max,r=i?.height?.max;if(typeof l!="number"||typeof r!="number"||l<=0||r<=0)return null;let c=Math.max(l,r),u=Math.min(l,r),f=Math.min(c,Math.max(o.width,o.height)),d=Math.min(u,Math.min(o.width,o.height));return f<=Math.max(t.width,t.height)?null:{width:{ideal:f},height:{ideal:d}}}n(He,"me");function Qe(i){let t={},e=i?.imageWidth,s=i?.imageHeight;if(typeof e?.max=="number"&&e.max>0){let a=typeof s?.max=="number"&&s.max>0?e.max/s.max:1.3333333333333333,h=a>=1?ae:ae*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 i?.fillLightMode?.includes("off")===!0&&(t.fillLightMode="off"),t}n(Qe,"fe");function Xe(i,t){if(i.width<=0||i.height<=0||t.width<=0||t.height<=0)return!1;let e=i.width>i.height,s=t.width>t.height;return e!==s&&i.width!==i.height&&t.width!==t.height?!1:Math.max(i.width,i.height)>=1.2*Math.max(t.width,t.height)}n(Xe,"pe");function Ue(i,t,e,s){if(e===null)return!1;let a=C(i),h=C(e);if(t.width<=0||s.width<=0)return!1;let o=a.width/t.width,l=h.width/s.width;return l>0&&o>=.6*l&&o<=1.25*l}n(Ue,"ge");var he=3500,Ke=.92;function ye(){let i=globalThis.ImageCapture;return typeof i=="function"?i:null}n(ye,"Me");function Ye(i){return/AppleWebKit\//.test(i)&&!/(Chrome|Chromium|Edg|OPR)\//.test(i)}n(Ye,"ii");function Ve(i,t=typeof navigator>"u"?"":navigator.userAgent){return ye()!==null&&!Ye(t)&&i!=null&&i.kind==="video"&&i.readyState==="live"}n(Ve,"ke");function oe(i,t){return new Promise((e,s)=>{let a=setTimeout(()=>s(new Error("takePhoto timed out")),t);i.then(h=>{clearTimeout(a),e(h)},h=>{clearTimeout(a),s(h)})})}n(oe,"ye");function mt(i,t){let e=document.createElement("canvas");return e.width=i,e.height=t,e}n(mt,"bt");function Je(i,t){return new Promise((e,s)=>{i.toBlob(a=>a?e(a):s(new Error("toBlob failed")),"image/jpeg",t)})}n(Je,"oi");async function we(i,t,e,s,a){let h=mt(e,s),o=mt(1,1);try{let l=h.getContext("2d");if(l===null)throw new Error("2d context unavailable");l.imageSmoothingQuality="high",l.drawImage(i,t.x,t.y,t.width,t.height,0,0,e,s);let r=await Je(h,Ke),c=a===null?null:Kt({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:s},{width:e,height:s}),u=Yt(h,c),f=pe(e,s,qe);return o.width=Math.max(1,Math.round(e*f)),o.height=Math.max(1,Math.round(s*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(we,"xe");function Ze(i,t){let e=Math.min(1,t/i.width),s=mt(Math.max(1,Math.round(i.width*e)),Math.max(1,Math.round(i.height*e)));try{let a=s.getContext("2d",{willReadFrequently:!0});return a===null?null:(a.imageSmoothingQuality="high",a.drawImage(i,0,0,s.width,s.height),a.getImageData(0,0,s.width,s.height))}finally{s.width=0,s.height=0}}n(Ze,"ni");async function $e(i,t,e,s){let a={width:Math.max(1,i.videoWidth),height:Math.max(1,i.videoHeight)},h=Me(t,e,a,s);return{...await we(i,h.crop,h.width,h.height,h.docRegion),docRegion:h.docRegion,source:"video",width:h.width,height:h.height}}n($e,"De");async function ti(i,t,e,s,a){let h=ye();if(h===null)return null;let o=null;try{let l=new h(a.track),r=await oe(l.getPhotoCapabilities?.()??Promise.resolve({}),he).catch(()=>({})),c=await oe(l.takePhoto(Qe(r)),he);o=await createImageBitmap(c);let u={width:i.videoWidth,height:i.videoHeight};if(!Xe(o,u))return null;let f=Ze(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&&!Ue(d,m,t,e)&&(d=null);let g=Me(d,m,o,s);return{...await we(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(ti,"we");var wt=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((i,t,e)=>typeof i=="number"&&Number.isFinite(i)&&i>=t&&i<=e?i:void 0,"S");function Ti(i){let t=wt,e=i!==null&&typeof i=="object"?i:{},s=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(s.id1,.03,1)??t.fillDistanceM.id1,id3:R(s.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(Ti,"Ri");var gt="sekyro.doc.camera";function ei(){try{let i=globalThis.localStorage?.getItem(gt);return typeof i=="string"&&i!==""?i:null}catch{return null}}n(ei,"si");function re(i){try{i===null?globalThis.localStorage?.removeItem(gt):globalThis.localStorage?.setItem(gt,i)}catch{}}n(re,"ve");var pt=n((i,t)=>Array.isArray(i?.focusMode)&&i.focusMode.includes(t),"rt");function le(i,t,e){if(!pt(i,"single-shot"))return null;let s=n(a=>Math.min(1,Math.max(0,Number.isFinite(a)?a:.5)),"o");return{focusMode:"single-shot",pointsOfInterest:[{x:s(t),y:s(e)}]}}n(le,"kt");function ii(i,t,e,s=wt){let a=i?.zoom?.min,h=i?.zoom?.max;if(typeof h!="number"||h<=1)return 1;let o=e==="ID-3"?s.fillDistanceM.id3:s.fillDistanceM.id1,l=i?.focusDistance?.min,r;if(typeof l=="number"&&l>0&&l<1){if(r=l*(1+s.focusMarginFrac)/o,r<=1.05)return 1}else{if(Math.min(t.width,t.height)<s.zoomMinSourcePx)return 1;r=s.zoomNoFocusInfo}let c=Math.min(r,s.zoomMax,h);typeof a=="number"&&(c=Math.max(c,a));let u=i?.zoom?.step;return typeof u=="number"&&u>0&&(c=Math.round(c/u)*u),c>1.01?Number(c.toFixed(2)):1}n(ii,"_e");function Mt(i){try{return i.getVideoTracks?.()[0]}catch{return}}n(Mt,"Mt");function ne(i){if(i!==null)for(let t of i.getTracks())t.stop()}n(ne,"Se");function si(i){try{let t=Mt(i)?.getCapabilities?.();return!Array.isArray(t?.focusMode)||t.focusMode.includes("continuous")}catch{return!0}}n(si,"ri");async function ai(i){let t=n(h=>({audio:!1,video:{...h,width:{ideal:i.base.width},height:{ideal:i.base.height}}}),"t"),e=n(h=>i.getUserMedia(t({deviceId:{exact:h}})),"e"),s=n(()=>i.getUserMedia(t({facingMode:{ideal:"environment"}})),"o");if(i.lensSelection){let h=ei();if(h!==null)try{return{stream:await e(h),lens:"stored"}}catch{re(null)}}let a=await s();if(!i.lensSelection||i.enumerateDevices===void 0)return{stream:a,lens:"default"};try{let h=Ht(await i.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?Mt(a)?.getSettings?.().deviceId:void 0;if(a===null||r!==l){ne(a),a=null;try{a=await e(l)}catch{continue}}if(o??(o=l),si(a))return re(l),{stream:a,lens:"selected"}}if(a!==null&&o!==null&&Mt(a)?.getSettings?.().deviceId===o)return{stream:a,lens:"selected"};if(ne(a),a=null,o!==null)try{return{stream:await e(o),lens:"selected"}}catch{}return{stream:await s(),lens:"default"}}catch{return{stream:a??await s(),lens:"default"}}}n(ai,"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(i=>Math.min(1,Math.max(0,i)),"L");function hi(i,t,e,s=.06){let a=Math.max(i.width/e,i.height),h=a*e,o=(i.width-h)/2,l=(i.height-a)/2,r=A((t.x-t.width*s-o)/h),c=A((t.y-t.height*s-l)/a),u=A((t.x+t.width*(1+s)-o)/h),f=A((t.y+t.height*(1+s)-l)/a);return{x:r,y:c,width:u-r,height:f-c}}n(hi,"Fe");function oi(i,t,e={}){let s=e.edgePeakFrac??0,{width:a,height:h,data:o}=i;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),v=Math.floor((I-S+F-1)/F);if(y<3||v<3)return ht;let x=new Int32Array(y*v);for(let p=0;p<v;p++){let M=S+p*F;for(let _=0;_<y;_++){let T=(M*a+k+_*F)*4;x[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),bt=(d-u)/F,kt=(m-f)/F,vt=w(Math.ceil(B),0,y-1),be=w(Math.floor(rt),vt,y-1),xt=w(Math.ceil(lt),0,v-1),ke=w(Math.floor(nt),xt,v-1),St=0,Ft=0,H=0,Rt=0,_t=0,Q=0;for(let p=xt;p<=ke;p++)for(let M=vt;M<=be;M++){let _=x[p*y+M];if(St+=_,_>=248&&Ft++,H++,M>=1&&M<y-1&&p>=1&&p<v-1){let T=x[p*y+M-1]+x[p*y+M+1]+x[(p-1)*y+M]+x[(p+1)*y+M]-4*_;Rt+=T,_t+=T*T,Q++}}let ve=H>0?St/H:0,Dt=H>0?Ft/H:0,Tt=Q>0?Rt/Q:0,xe=Q>0?Math.max(0,_t/Q-Tt*Tt):0,X=new Float64Array(y),U=new Float64Array(v);for(let p=0;p<v;p++)for(let M=1;M<y-1;M++)X[M]=X[M]+Math.abs(x[p*y+M+1]-x[p*y+M-1]);for(let p=1;p<v-1;p++)for(let M=0;M<y;M++)U[p]=U[p]+Math.abs(x[(p+1)*y+M]-x[(p-1)*y+M]);let O=st(X,!0,B,s),E=st(X,!1,rt,s),P=st(U,!0,lt,s),W=st(U,!1,nt,s),At=(E.position-O.position)/bt,zt=(W.position-P.position)/kt,Se=zt>0?At/zt:0,Fe=((O.position+E.position)/2-(B+rt)/2)/bt,Re=((P.position+W.position)/2-(lt+nt)/2)/kt,Ct=ce(X),It=ce(U),_e=Ct<=0||It<=0?0:Math.min(Math.min(O.value,E.value)/Ct,Math.min(P.value,W.value)/It),Z=n((p,M)=>M+(p+.5)*F,"$"),Lt=Dt,Ot=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),De=w(Math.ceil(P.position+M),0,v-1),Et=w(Math.floor(W.position-M),0,v-1),Pt=0,$=0,Wt=0;for(let N=De;N<=Et;N++)for(let q=_;q<=T;q++){$++;let K=x[N*y+q];K>=248&&Pt++;let Te=q+2<=T?x[N*y+q+2]:K,Ae=N+2<=Et?x[(N+2)*y+q]:K;(Math.abs(Te-K)>=24||Math.abs(Ae-K)>=24)&&Wt++}$>=16&&(Lt=Pt/$,Ot=Wt/$)}return{brightness:ve,glare:Dt,cardGlare:Lt,sharpness:xe,fill:At,shape:Se,content:Ot,offsetX:Fe,offsetY:Re,edgeConfidence:_e,box:{left:Z(O.position,k),right:Z(E.position,k),top:Z(P.position,S),bottom:Z(W.position,S)}}}n(oi,"Ce");function st(i,t,e,s){let a=i.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++)i[m]>i[r]&&(r=m);if(s>0&&s<1){let m=i[r]*s,g=r,b=Math.abs(r-e);for(let w=o;w<=l;w++){let k=i[w];if(k<m||k<(i[w-1]??0)||k<(i[w+1]??0))continue;let S=Math.abs(w-e);S<b&&(g=w,b=S)}r=g}let c=r>0?i[r-1]:0,u=i[r],f=r<a-1?i[r+1]:0,d=c+u+f;return{position:d>0?r+(f-c)/d:r,value:u}}n(st,"at");function ce(i){if(i.length<3)return 0;let t=0;for(let e=1;e<i.length-1;e++)t+=i[e];return t/(i.length-2)}n(ce,"Re");function ri(i){let t=i.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(ri,"Ae");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 Ai(i){let t=i!==null&&typeof i=="object"?i:{},e={...ot};for(let s of Object.keys(ot)){let a=t[s];typeof a=="number"&&Number.isFinite(a)&&a>=0&&a<=1e6&&(e[s]=a)}return e}n(Ai,"Oi");var j,li=(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 s=this.t,a=s.shapeTolerance<=0||Math.abs(t.shape-1)<=s.shapeTolerance,h=t.edgeConfidence>=s.edgeConfidenceMin&&a&&t.content>=s.contentMin,o=t.fill>=s.fillMin&&t.fill<=s.fillMax,l=Math.abs(t.offsetX)<=s.offsetMax&&Math.abs(t.offsetY)<=s.offsetMax,r=t.cardGlare<=s.glareMax,c=t.sharpness>=s.sharpnessMin,u=this.last;this.last={fill:t.fill,offsetX:t.offsetX,offsetY:t.offsetY,at:e};let f=u!==null&&s.steadyRefMs>0?Math.min(3,Math.max(1,(e-u.at)/s.steadyRefMs)):1,d=h&&r&&c&&t.fill>=s.steadyFillMin&&t.fill<=s.steadyFillMax&&u!==null&&Math.abs(t.fill-u.fill)<=s.steadyFillDelta*f&&Math.abs(t.offsetX-u.offsetX)<=s.steadyOffsetDelta*f&&Math.abs(t.offsetY-u.offsetY)<=s.steadyOffsetDelta*f,m=h&&o&&l&&r&&c,g;if(h?r?t.fill<s.fillMin?g="too_small":t.fill>s.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>=s.lockMs)return{detected:h,ready:!0,via:"good",blocker:"locking"};let b=this.steadySince!==null&&e-this.steadySince>=s.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>=s.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),J=null;async function ni(i){return J===null&&(J=(await import("./detector-scanic-GGIKCF6B-OP62MOM6.js")).detectQuad),J(i)}n(ni,"ai");async function ci(i){let t=$t(i);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(ci,"ci");function zi(){J===null&&import("./detector-scanic-GGIKCF6B-OP62MOM6.js").then(i=>{J=i.detectQuad}).catch(()=>{})}n(zi,"Ji");var ue=4e3,ui=2,de=3,di=Object.freeze({LOW:3,MID:5,HIGH:6}),yt=Object.freeze({manualShutterMs:6e3,detectedNoLockMs:1950});function Ci(i){let t=i!==null&&typeof i=="object"?i:{},e=n((s,a,h)=>typeof s=="number"&&Number.isFinite(s)&&s>=a&&s<=h?s:void 0,"e");return{manualShutterMs:e(t.manualShutterMs,1e3,6e4)??yt.manualShutterMs,detectedNoLockMs:e(t.steadyMs,300,3e4)!==void 0?t.steadyMs+(e(t.lockMs,0,1e4)??450):yt.detectedNoLockMs}}n(Ci,"qi");var z,Ii=(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 Ce,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 ie(t.format??"ID-1",t.thresholds);let e=t.deviceClass??Xt(Qt());this.deviceClass=e,this.camera=t.camera??wt,this.shutterTuning=t.shutter??yt,this.guideTuning=t.guideLock??ot,this.guideLock=new li(this.guideTuning),this.cadenceMs=1e3/di[e]}on(t,e){let s=this.handlers.get(t);return s||(s=new Set,this.handlers.set(t,s)),s.add(e),()=>s?.delete(e)}emit(t,e){for(let s of[...this.handlers.get(t)??[]])s(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(),Bt(),this.setState("preflight");try{let s=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 ai({getUserMedia:s,...a!==void 0?{enumerateDevices:a}:{},lensSelection:this.camera.lensSelection,base:Pe});if(e!==this.attempt){for(let o of h.stream.getTracks())o.stop();return}if(this.stream=h.stream,Nt(this.stream),jt(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(s){if(e!==this.attempt)return;let a=Gt(s),h=qt(s);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??ue;e<=0||(this.clearFrameWatch(),this.frameWatch=setTimeout(()=>{if(this.frameWatch=null,!(t!==this.attempt||this.state!=="positioning")){if(this.framesNow()&&this.blackTicks<de){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 s=n(()=>{t===this.attempt&&(this.state==="positioning"||this.state==="acquiring")&&this.cameraDead(t)},"o");e.addEventListener("ended",s),this.offEnded=()=>e.removeEventListener?.("ended",s)}cameraDead(t){if(t!==this.attempt)return;let e=this.videoTrack(),s=e!==null&&e.readyState==="live"&&!e.muted&&this.opts.video.paused&&!this.framesNow();if(!s&&!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(),s||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),s=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:s},bottomLeft:{x:0,y:s}},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:s,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",s=t.report(e,this.stats.via,(this.opts.now??(()=>performance.now()))());return s===null?{}:{ocr:s}}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),s=this.opts.guide;if(s!==void 0&&s.viewAspect>0){let l={width:s.viewAspect,height:1},r={x:s.rect.x*s.viewAspect,y:s.rect.y,width:s.rect.width*s.viewAspect,height:s.rect.height};return hi(l,r,e,0)}let a=Jt(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 s=this.focusCaps(),a=typeof s?.zoom?.min=="number"?Math.max(s.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?.()??{},s=He(t.getCapabilities?.(),{width:e.width??0,height:e.height??0},this.deviceClass,{width:this.camera.width,height:this.camera.height},this.opts.ocr?.liveMrzOn===!0?{fill:this.guideRegion({width:1080,height:1920}).width}:void 0);s!==null&&await t.applyConstraints(s)}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&&pt(e,"continuous")&&await t.applyConstraints({advanced:[{focusMode:"continuous"}]}).catch(()=>{});let s={width:0,height:0};try{let h=t.getSettings?.()??{};s={width:h.width??0,height:h.height??0}}catch{}let a=ii(e,s,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 s=this.videoTrack(),a=le(this.focusCaps(),t,e);if(!(s===null||a===null))try{await s.applyConstraints({advanced:[a]}),(this.opts.setTimer??setTimeout)(()=>{this.restoreContinuous()},1500)}catch{}}async restoreContinuous(){let t=this.videoTrack();t===null||!this.camera.continuousFocus||!pt(this.focusCaps(),"continuous")||await t.applyConstraints({advanced:[{focusMode:"continuous"}]}).catch(()=>{})}async refocusOn(t,e){let s=this.camera.refocusBeforePhotoMs,a=this.videoTrack();if(s<=0||a===null||e.width<=0||e.height<=0)return;let h=C(t),o=le(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(),s)})}catch{}}videoTrack(){try{return this.stream?.getVideoTracks?.()[0]??null}catch{return null}}async takeStill(t,e,s){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(s&&this.opts.photoCapture!==!1&&this.deviceClass!=="LOW"&&!this.torchOn&&h!==null&&Ve(h)){await this.refocusOn(t,e);let o=await ti(this.opts.video,t,e,a,{track:h,detect:this.detector(),detectWidth:tt});if(this.restoreContinuous(),o!==null)return o}return $e(this.opts.video,t,e,a)}detector(){return this.opts.detect??((this.opts.format??"ID-1")==="ID-3"?ci:ni)}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()),s=this.opts.grabDetectFrame??me,a=this.detector(),h=s(this.opts.video,tt);if(h===null){this.scheduleTick(t);return}if(!this.lit){if(ut(h)>ui)this.lit=!0,this.blackTicks=0;else if(++this.blackTicks>=de&&this.frameWatch===null&&(this.opts.firstFrameMs??ue)>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:Ut(l),meanLuma:ut(l),specularFraction:Le(l)},u=Ee({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"?oi(h,this.guideRegion(h),{edgePeakFrac:this.guideTuning.edgePeakFrac}):ht,m=this.guideLock.tick(d,r);this.lastGuideQuad=m.detected?ri(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 v=u.lighting!=="ok"?u.lighting:u.glare!=="ok"?"glare":u.blur!=="ok"?"blurry":"steadying";b.qualityBlockers[v]=(b.qualityBlockers[v]??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<=wi?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=ze(u);u.framing!=="ok"&&m.detected&&(k=yi(m.blocker,d.brightness<this.guideTuning.darkBrightness)),k==="blurry"&&o!==null&&mi(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 v=this.feedback.force("processing",r);this.lastFeedbackKey=v.key,this.emit("feedback",v);let x=Y(at(h,y.quad));await this.fire(t,y.quad,{width:h.width,height:h.height,tickSharpness:x},y.via);return}if((I||F)&&this.opts.autoCapture!==!1){let v=this.feedback.force("processing",r);this.lastFeedbackKey=v.key,this.emit("feedback",v);let x=F?this.lastGuideQuad:o,L=F?m.via==="steady"?"guide_steady":"guide_good":"quad",B=F?Y(at(h,x)):c.sharpness;await this.fire(t,x,{width:h.width,height:h.height,tickSharpness:B},L);return}this.scheduleTick(t)}async fire(t,e,s,a){this.capturing=!0;let h=this.opts.grabDetectFrame??me,o=this.opts.setTimer??setTimeout,l={width:s.width,height:s.height};try{let r={still:await this.takeStill(e,l,!0),sharpness:s.tickSharpness};if(t!==this.attempt)return;let c=r.still.source==="photo"?0:gi;for(let d=0;d<c;d++){if(await new Promise(b=>{o(()=>b(),pi)}),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,s,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=fi(C(e),g,b,c,u):w=Vt(m,l.bandTop,u);let k=f?h.glare==="ok":s.cardGlare<=this.guideTuning.glareMax,S=f?h.blur==="ok":s.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??fe(d,t):this.lastGuideQuad??fe(d,t);this.lastOcrReady={quad:I,via:D.via}}else this.lastOcrReady=null;return D}},n(z,"i"),z);function fi(i,t,e,s,a){let h=Math.min(s,i.width*1.06*t),o=Math.min(a,Math.max(i.height*1.6*e,h/5)),l=(i.y+i.height/2)*e,r=Math.max(0,Math.min(s-h,(i.x-i.width*.03)*t)),c=Math.max(0,Math.min(a-o,l-o/2));return{x:r,y:c,w:h,h:o}}n(fi,"hi");function fe(i,t){let e=i.x*t.width,s=i.y*t.height,a=(i.x+i.width)*t.width,h=(i.y+i.height)*t.height;return{topLeft:{x:e,y:s},topRight:{x:a,y:s},bottomRight:{x:a,y:h},bottomLeft:{x:e,y:h}}}n(fe,"Ie");function mi(i,t,e){let s=C(i);return t.width<=0||t.height<=0?0:e==="ID-3"?s.width/t.width:s.width*s.height/(t.width*t.height)}n(mi,"di");var gi=2,pi=260,Mi=1.08;function me(i,t){let e=i.videoWidth,s=i.videoHeight;if(e===0||s===0)return null;let a=Math.min(1,t/e),h=Math.round(e*a),o=Math.round(s*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(i,0,0,h,o),r.getImageData(0,0,h,o))}n(me,"Pe");function at(i,t){let e=[t.topLeft.x,t.topRight.x,t.bottomRight.x,t.bottomLeft.x],s=[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(...s))),o=Math.min(i.width,Math.ceil(Math.max(...e))),l=Math.min(i.height,Math.ceil(Math.max(...s))),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)*i.width+a)*4;u.set(i.data.subarray(d,d+r*4),f*r*4)}return{data:u,width:r,height:c,colorSpace:i.colorSpace}}n(at,"lt");function yi(i,t){return i==="glare"?"glare":i==="too_small"?"too_far":i==="too_big"?"too_close":t?"too_dark":i==="blurry"?"blurry":i==="off_center"?"edge_clipped":i==="no_card"?"sensing":"hold_still"}n(yi,"gi");var wi=1200;export{Ti as a,Ai as b,zi as c,ue as d,ui as e,de as f,di as g,yt as h,Ci as i,Ii as j,fi as k,gi as l,pi as m};
1
+ import{a as tt,b as te,c as ee,d as dt,e as ie}from"./chunk-Z25MPNSU.js";import{c as Kt,d as Yt,g as Vt}from"./chunk-3NOBU7TE.js";import{b as Jt,c as Zt}from"./chunk-QWPURAKS.js";import{b as $t}from"./chunk-L22GFJQV.js";import{d as Nt,e as Qt,f as Xt}from"./chunk-HOSTJBJM.js";import{a as ct,b as ut,c as Y,d as Ut}from"./chunk-P7K7ELYZ.js";import{g as qt,i as Gt,j as jt,k as Bt,l as Ht}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 ze(i){return i.framing==="no_document"?"sensing":i.framing==="too_far"?"too_far":i.framing==="too_close"?"too_close":i.framing==="edge_clipped"?"edge_clipped":i.framing==="wrong_shape"?"wrong_shape":i.framing==="tilted"?"tilted":i.lighting==="too_dark"?"too_dark":i.lighting==="too_bright"?"too_bright":i.glare==="glare"?"glare":i.blur==="blurry"?"blurry":"hold_still"}n(ze,"se");var G,Ce=(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 s=new Map;for(let o of this.votes){let l=(e-o.atMs)/1e3,r=this.decayPerSecond**l;s.set(o.key,(s.get(o.key)??0)+r)}let a=this.current.key,h=-1;for(let[o,l]of s)l>h&&(h=l,a=o);return a!==this.current.key&&(this.current=et[a],this.currentSinceMs=e),this.current}},n(G,"ot"),G),Ie=Object.freeze({MAX_AREA_FRAC:.92,TILT_MAX_SIDE_RATIO:1.3,GLARE_MAX_SPECULAR_FRAC:.025});function Le(i){let{data:t,width:e,height:s}=i,a=e*s;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(Le,"ae");function Oe(i){let t=n((r,c)=>Math.hypot(c.x-r.x,c.y-r.y),"t"),e=t(i.topLeft,i.topRight),s=t(i.bottomLeft,i.bottomRight),a=t(i.topLeft,i.bottomLeft),h=t(i.topRight,i.bottomRight),o=Math.max(e,s)/Math.max(1e-6,Math.min(e,s)),l=Math.max(a,h)/Math.max(1e-6,Math.min(a,h));return Math.max(o,l)}n(Oe,"Ye");function Ee(i){let t={...te,...i.thresholds},e=Ie,{quad:s,frameWidth:a,frameHeight:h,measures:o}=i,l=i.format==="ID-3",r="ok";if(s===null)r="no_document";else if(l){let d=dt(s),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":se(s,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=ee(s,a,h),m=dt(s),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":se(s,a,h,t.EDGE_CLIP_MARGIN_PX)?r="edge_clipped":Zt(i.format,g)?Oe(s)>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(Ee,"ce");function se(i,t,e,s){return[i.topLeft,i.topRight,i.bottomRight,i.bottomLeft].some(a=>a.x<=s||a.y<=s||a.x>=t-s||a.y>=e-s)}n(se,"re");var Pe=Object.freeze({width:1920,height:1080}),We=Object.freeze({width:3840,height:2160}),ae=4096,Ne=2560,qe=640,it=.15,V=Object.freeze({side:.2,above:.9,below:.3});function C(i){let t=[i.topLeft.x,i.topRight.x,i.bottomRight.x,i.bottomLeft.x],e=[i.topLeft.y,i.topRight.y,i.bottomRight.y,i.bottomLeft.y],s=Math.min(...t),a=Math.min(...e);return{x:s,y:a,width:Math.max(...t)-s,height:Math.max(...e)-a}}n(C,"E");function ge(i,t){let e=Math.max(0,Math.floor(i.x)),s=Math.max(0,Math.floor(i.y)),a=Math.min(t.width,Math.ceil(i.x+i.width)),h=Math.min(t.height,Math.ceil(i.y+i.height));return a-e<16||h-s<16?null:{x:e,y:s,width:a-e,height:h-s}}n(ge,"de");function Ge(i,t,e){if(i===null||t.width<=0||t.height<=0)return null;let s=C(i);if(s.width<=0||s.height<=0)return null;let a=e==="ID-3"?{x:s.x-s.width*V.side,y:s.y-s.width*V.above,width:s.width*(1+2*V.side),height:s.height+s.width*(V.above+V.below)}:{x:s.x-s.width*it,y:s.y-s.height*it,width:s.width*(1+2*it),height:s.height*(1+2*it)};return ge(a,t)}n(Ge,"qe");function pe(i,t,e){let s=Math.max(i,t);return s>0?Math.min(1,e/s):1}n(pe,"pt");function Me(i,t,e,s,a=Ne){let h=t.width>0?e.width/t.width:1,o=t.height>0?e.height/t.height:1,l=i===null?null:{topLeft:{x:i.topLeft.x*h,y:i.topLeft.y*o},topRight:{x:i.topRight.x*h,y:i.topRight.y*o},bottomRight:{x:i.bottomRight.x*h,y:i.bottomRight.y*o},bottomLeft:{x:i.bottomLeft.x*h,y:i.bottomLeft.y*o}},r=Ge(l,e,s)??{x:0,y:0,width:e.width,height:e.height},c=pe(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=ge({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(Me,"gt");var je=960,ft=[{width:1920,height:1080},{width:2560,height:1440}];function Be(i){let t=Number.isFinite(i)&&i>0?Math.min(1,i):.85;return ft.find(e=>e.height*t>=je)??ft[ft.length-1]}n(Be,"ti");function He(i,t,e,s=We,a){let h=a===void 0?null:Be(a.fill);if(e==="LOW"&&h===null)return null;let o=e==="LOW"||h!==null&&Math.max(h.width,h.height)>Math.max(s.width,s.height)?h:s,l=i?.width?.max,r=i?.height?.max;if(typeof l!="number"||typeof r!="number"||l<=0||r<=0)return null;let c=Math.max(l,r),u=Math.min(l,r),f=Math.min(c,Math.max(o.width,o.height)),d=Math.min(u,Math.min(o.width,o.height));return f<=Math.max(t.width,t.height)?null:{width:{ideal:f},height:{ideal:d}}}n(He,"me");function Qe(i){let t={},e=i?.imageWidth,s=i?.imageHeight;if(typeof e?.max=="number"&&e.max>0){let a=typeof s?.max=="number"&&s.max>0?e.max/s.max:1.3333333333333333,h=a>=1?ae:ae*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 i?.fillLightMode?.includes("off")===!0&&(t.fillLightMode="off"),t}n(Qe,"fe");function Xe(i,t){if(i.width<=0||i.height<=0||t.width<=0||t.height<=0)return!1;let e=i.width>i.height,s=t.width>t.height;return e!==s&&i.width!==i.height&&t.width!==t.height?!1:Math.max(i.width,i.height)>=1.2*Math.max(t.width,t.height)}n(Xe,"pe");function Ue(i,t,e,s){if(e===null)return!1;let a=C(i),h=C(e);if(t.width<=0||s.width<=0)return!1;let o=a.width/t.width,l=h.width/s.width;return l>0&&o>=.6*l&&o<=1.25*l}n(Ue,"ge");var he=3500,Ke=.92;function ye(){let i=globalThis.ImageCapture;return typeof i=="function"?i:null}n(ye,"Me");function Ye(i){return/AppleWebKit\//.test(i)&&!/(Chrome|Chromium|Edg|OPR)\//.test(i)}n(Ye,"ii");function Ve(i,t=typeof navigator>"u"?"":navigator.userAgent){return ye()!==null&&!Ye(t)&&i!=null&&i.kind==="video"&&i.readyState==="live"}n(Ve,"ke");function oe(i,t){return new Promise((e,s)=>{let a=setTimeout(()=>s(new Error("takePhoto timed out")),t);i.then(h=>{clearTimeout(a),e(h)},h=>{clearTimeout(a),s(h)})})}n(oe,"ye");function mt(i,t){let e=document.createElement("canvas");return e.width=i,e.height=t,e}n(mt,"bt");function Je(i,t){return new Promise((e,s)=>{i.toBlob(a=>a?e(a):s(new Error("toBlob failed")),"image/jpeg",t)})}n(Je,"oi");async function we(i,t,e,s,a){let h=mt(e,s),o=mt(1,1);try{let l=h.getContext("2d");if(l===null)throw new Error("2d context unavailable");l.imageSmoothingQuality="high",l.drawImage(i,t.x,t.y,t.width,t.height,0,0,e,s);let r=await Je(h,Ke),c=a===null?null:Kt({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:s},{width:e,height:s}),u=Yt(h,c),f=pe(e,s,qe);return o.width=Math.max(1,Math.round(e*f)),o.height=Math.max(1,Math.round(s*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(we,"xe");function Ze(i,t){let e=Math.min(1,t/i.width),s=mt(Math.max(1,Math.round(i.width*e)),Math.max(1,Math.round(i.height*e)));try{let a=s.getContext("2d",{willReadFrequently:!0});return a===null?null:(a.imageSmoothingQuality="high",a.drawImage(i,0,0,s.width,s.height),a.getImageData(0,0,s.width,s.height))}finally{s.width=0,s.height=0}}n(Ze,"ni");async function $e(i,t,e,s){let a={width:Math.max(1,i.videoWidth),height:Math.max(1,i.videoHeight)},h=Me(t,e,a,s);return{...await we(i,h.crop,h.width,h.height,h.docRegion),docRegion:h.docRegion,source:"video",width:h.width,height:h.height}}n($e,"De");async function ti(i,t,e,s,a){let h=ye();if(h===null)return null;let o=null;try{let l=new h(a.track),r=await oe(l.getPhotoCapabilities?.()??Promise.resolve({}),he).catch(()=>({})),c=await oe(l.takePhoto(Qe(r)),he);o=await createImageBitmap(c);let u={width:i.videoWidth,height:i.videoHeight};if(!Xe(o,u))return null;let f=Ze(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&&!Ue(d,m,t,e)&&(d=null);let g=Me(d,m,o,s);return{...await we(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(ti,"we");var wt=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((i,t,e)=>typeof i=="number"&&Number.isFinite(i)&&i>=t&&i<=e?i:void 0,"S");function Ti(i){let t=wt,e=i!==null&&typeof i=="object"?i:{},s=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(s.id1,.03,1)??t.fillDistanceM.id1,id3:R(s.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(Ti,"Ri");var gt="sekyro.doc.camera";function ei(){try{let i=globalThis.localStorage?.getItem(gt);return typeof i=="string"&&i!==""?i:null}catch{return null}}n(ei,"si");function re(i){try{i===null?globalThis.localStorage?.removeItem(gt):globalThis.localStorage?.setItem(gt,i)}catch{}}n(re,"ve");var pt=n((i,t)=>Array.isArray(i?.focusMode)&&i.focusMode.includes(t),"rt");function le(i,t,e){if(!pt(i,"single-shot"))return null;let s=n(a=>Math.min(1,Math.max(0,Number.isFinite(a)?a:.5)),"o");return{focusMode:"single-shot",pointsOfInterest:[{x:s(t),y:s(e)}]}}n(le,"kt");function ii(i,t,e,s=wt){let a=i?.zoom?.min,h=i?.zoom?.max;if(typeof h!="number"||h<=1)return 1;let o=e==="ID-3"?s.fillDistanceM.id3:s.fillDistanceM.id1,l=i?.focusDistance?.min,r;if(typeof l=="number"&&l>0&&l<1){if(r=l*(1+s.focusMarginFrac)/o,r<=1.05)return 1}else{if(Math.min(t.width,t.height)<s.zoomMinSourcePx)return 1;r=s.zoomNoFocusInfo}let c=Math.min(r,s.zoomMax,h);typeof a=="number"&&(c=Math.max(c,a));let u=i?.zoom?.step;return typeof u=="number"&&u>0&&(c=Math.round(c/u)*u),c>1.01?Number(c.toFixed(2)):1}n(ii,"_e");function Mt(i){try{return i.getVideoTracks?.()[0]}catch{return}}n(Mt,"Mt");function ne(i){if(i!==null)for(let t of i.getTracks())t.stop()}n(ne,"Se");function si(i){try{let t=Mt(i)?.getCapabilities?.();return!Array.isArray(t?.focusMode)||t.focusMode.includes("continuous")}catch{return!0}}n(si,"ri");async function ai(i){let t=n(h=>({audio:!1,video:{...h,width:{ideal:i.base.width},height:{ideal:i.base.height}}}),"t"),e=n(h=>i.getUserMedia(t({deviceId:{exact:h}})),"e"),s=n(()=>i.getUserMedia(t({facingMode:{ideal:"environment"}})),"o");if(i.lensSelection){let h=ei();if(h!==null)try{return{stream:await e(h),lens:"stored"}}catch{re(null)}}let a=await s();if(!i.lensSelection||i.enumerateDevices===void 0)return{stream:a,lens:"default"};try{let h=Ht(await i.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?Mt(a)?.getSettings?.().deviceId:void 0;if(a===null||r!==l){ne(a),a=null;try{a=await e(l)}catch{continue}}if(o??(o=l),si(a))return re(l),{stream:a,lens:"selected"}}if(a!==null&&o!==null&&Mt(a)?.getSettings?.().deviceId===o)return{stream:a,lens:"selected"};if(ne(a),a=null,o!==null)try{return{stream:await e(o),lens:"selected"}}catch{}return{stream:await s(),lens:"default"}}catch{return{stream:a??await s(),lens:"default"}}}n(ai,"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(i=>Math.min(1,Math.max(0,i)),"L");function hi(i,t,e,s=.06){let a=Math.max(i.width/e,i.height),h=a*e,o=(i.width-h)/2,l=(i.height-a)/2,r=A((t.x-t.width*s-o)/h),c=A((t.y-t.height*s-l)/a),u=A((t.x+t.width*(1+s)-o)/h),f=A((t.y+t.height*(1+s)-l)/a);return{x:r,y:c,width:u-r,height:f-c}}n(hi,"Fe");function oi(i,t,e={}){let s=e.edgePeakFrac??0,{width:a,height:h,data:o}=i;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),v=Math.floor((I-S+F-1)/F);if(y<3||v<3)return ht;let x=new Int32Array(y*v);for(let p=0;p<v;p++){let M=S+p*F;for(let _=0;_<y;_++){let T=(M*a+k+_*F)*4;x[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),bt=(d-u)/F,kt=(m-f)/F,vt=w(Math.ceil(B),0,y-1),be=w(Math.floor(rt),vt,y-1),xt=w(Math.ceil(lt),0,v-1),ke=w(Math.floor(nt),xt,v-1),St=0,Ft=0,H=0,Rt=0,_t=0,Q=0;for(let p=xt;p<=ke;p++)for(let M=vt;M<=be;M++){let _=x[p*y+M];if(St+=_,_>=248&&Ft++,H++,M>=1&&M<y-1&&p>=1&&p<v-1){let T=x[p*y+M-1]+x[p*y+M+1]+x[(p-1)*y+M]+x[(p+1)*y+M]-4*_;Rt+=T,_t+=T*T,Q++}}let ve=H>0?St/H:0,Dt=H>0?Ft/H:0,Tt=Q>0?Rt/Q:0,xe=Q>0?Math.max(0,_t/Q-Tt*Tt):0,X=new Float64Array(y),U=new Float64Array(v);for(let p=0;p<v;p++)for(let M=1;M<y-1;M++)X[M]=X[M]+Math.abs(x[p*y+M+1]-x[p*y+M-1]);for(let p=1;p<v-1;p++)for(let M=0;M<y;M++)U[p]=U[p]+Math.abs(x[(p+1)*y+M]-x[(p-1)*y+M]);let O=st(X,!0,B,s),E=st(X,!1,rt,s),P=st(U,!0,lt,s),W=st(U,!1,nt,s),At=(E.position-O.position)/bt,zt=(W.position-P.position)/kt,Se=zt>0?At/zt:0,Fe=((O.position+E.position)/2-(B+rt)/2)/bt,Re=((P.position+W.position)/2-(lt+nt)/2)/kt,Ct=ce(X),It=ce(U),_e=Ct<=0||It<=0?0:Math.min(Math.min(O.value,E.value)/Ct,Math.min(P.value,W.value)/It),Z=n((p,M)=>M+(p+.5)*F,"$"),Lt=Dt,Ot=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),De=w(Math.ceil(P.position+M),0,v-1),Et=w(Math.floor(W.position-M),0,v-1),Pt=0,$=0,Wt=0;for(let N=De;N<=Et;N++)for(let q=_;q<=T;q++){$++;let K=x[N*y+q];K>=248&&Pt++;let Te=q+2<=T?x[N*y+q+2]:K,Ae=N+2<=Et?x[(N+2)*y+q]:K;(Math.abs(Te-K)>=24||Math.abs(Ae-K)>=24)&&Wt++}$>=16&&(Lt=Pt/$,Ot=Wt/$)}return{brightness:ve,glare:Dt,cardGlare:Lt,sharpness:xe,fill:At,shape:Se,content:Ot,offsetX:Fe,offsetY:Re,edgeConfidence:_e,box:{left:Z(O.position,k),right:Z(E.position,k),top:Z(P.position,S),bottom:Z(W.position,S)}}}n(oi,"Ce");function st(i,t,e,s){let a=i.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++)i[m]>i[r]&&(r=m);if(s>0&&s<1){let m=i[r]*s,g=r,b=Math.abs(r-e);for(let w=o;w<=l;w++){let k=i[w];if(k<m||k<(i[w-1]??0)||k<(i[w+1]??0))continue;let S=Math.abs(w-e);S<b&&(g=w,b=S)}r=g}let c=r>0?i[r-1]:0,u=i[r],f=r<a-1?i[r+1]:0,d=c+u+f;return{position:d>0?r+(f-c)/d:r,value:u}}n(st,"at");function ce(i){if(i.length<3)return 0;let t=0;for(let e=1;e<i.length-1;e++)t+=i[e];return t/(i.length-2)}n(ce,"Re");function ri(i){let t=i.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(ri,"Ae");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 Ai(i){let t=i!==null&&typeof i=="object"?i:{},e={...ot};for(let s of Object.keys(ot)){let a=t[s];typeof a=="number"&&Number.isFinite(a)&&a>=0&&a<=1e6&&(e[s]=a)}return e}n(Ai,"Oi");var j,li=(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 s=this.t,a=s.shapeTolerance<=0||Math.abs(t.shape-1)<=s.shapeTolerance,h=t.edgeConfidence>=s.edgeConfidenceMin&&a&&t.content>=s.contentMin,o=t.fill>=s.fillMin&&t.fill<=s.fillMax,l=Math.abs(t.offsetX)<=s.offsetMax&&Math.abs(t.offsetY)<=s.offsetMax,r=t.cardGlare<=s.glareMax,c=t.sharpness>=s.sharpnessMin,u=this.last;this.last={fill:t.fill,offsetX:t.offsetX,offsetY:t.offsetY,at:e};let f=u!==null&&s.steadyRefMs>0?Math.min(3,Math.max(1,(e-u.at)/s.steadyRefMs)):1,d=h&&r&&c&&t.fill>=s.steadyFillMin&&t.fill<=s.steadyFillMax&&u!==null&&Math.abs(t.fill-u.fill)<=s.steadyFillDelta*f&&Math.abs(t.offsetX-u.offsetX)<=s.steadyOffsetDelta*f&&Math.abs(t.offsetY-u.offsetY)<=s.steadyOffsetDelta*f,m=h&&o&&l&&r&&c,g;if(h?r?t.fill<s.fillMin?g="too_small":t.fill>s.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>=s.lockMs)return{detected:h,ready:!0,via:"good",blocker:"locking"};let b=this.steadySince!==null&&e-this.steadySince>=s.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>=s.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),J=null;async function ni(i){return J===null&&(J=(await import("./detector-scanic-GGIKCF6B-OP62MOM6.js")).detectQuad),J(i)}n(ni,"ai");async function ci(i){let t=$t(i);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(ci,"ci");function zi(){J===null&&import("./detector-scanic-GGIKCF6B-OP62MOM6.js").then(i=>{J=i.detectQuad}).catch(()=>{})}n(zi,"Ji");var ue=4e3,ui=2,de=3,di=Object.freeze({LOW:3,MID:5,HIGH:6}),yt=Object.freeze({manualShutterMs:6e3,detectedNoLockMs:1950});function Ci(i){let t=i!==null&&typeof i=="object"?i:{},e=n((s,a,h)=>typeof s=="number"&&Number.isFinite(s)&&s>=a&&s<=h?s:void 0,"e");return{manualShutterMs:e(t.manualShutterMs,1e3,6e4)??yt.manualShutterMs,detectedNoLockMs:e(t.steadyMs,300,3e4)!==void 0?t.steadyMs+(e(t.lockMs,0,1e4)??450):yt.detectedNoLockMs}}n(Ci,"qi");var z,Ii=(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 Ce,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 ie(t.format??"ID-1",t.thresholds);let e=t.deviceClass??Xt(Qt());this.deviceClass=e,this.camera=t.camera??wt,this.shutterTuning=t.shutter??yt,this.guideTuning=t.guideLock??ot,this.guideLock=new li(this.guideTuning),this.cadenceMs=1e3/di[e]}on(t,e){let s=this.handlers.get(t);return s||(s=new Set,this.handlers.set(t,s)),s.add(e),()=>s?.delete(e)}emit(t,e){for(let s of[...this.handlers.get(t)??[]])s(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(),Bt(),this.setState("preflight");try{let s=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 ai({getUserMedia:s,...a!==void 0?{enumerateDevices:a}:{},lensSelection:this.camera.lensSelection,base:Pe});if(e!==this.attempt){for(let o of h.stream.getTracks())o.stop();return}if(this.stream=h.stream,Nt(this.stream),jt(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(s){if(e!==this.attempt)return;let a=Gt(s),h=qt(s);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??ue;e<=0||(this.clearFrameWatch(),this.frameWatch=setTimeout(()=>{if(this.frameWatch=null,!(t!==this.attempt||this.state!=="positioning")){if(this.framesNow()&&this.blackTicks<de){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 s=n(()=>{t===this.attempt&&(this.state==="positioning"||this.state==="acquiring")&&this.cameraDead(t)},"o");e.addEventListener("ended",s),this.offEnded=()=>e.removeEventListener?.("ended",s)}cameraDead(t){if(t!==this.attempt)return;let e=this.videoTrack(),s=e!==null&&e.readyState==="live"&&!e.muted&&this.opts.video.paused&&!this.framesNow();if(!s&&!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(),s||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),s=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:s},bottomLeft:{x:0,y:s}},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:s,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",s=t.report(e,this.stats.via,(this.opts.now??(()=>performance.now()))());return s===null?{}:{ocr:s}}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),s=this.opts.guide;if(s!==void 0&&s.viewAspect>0){let l={width:s.viewAspect,height:1},r={x:s.rect.x*s.viewAspect,y:s.rect.y,width:s.rect.width*s.viewAspect,height:s.rect.height};return hi(l,r,e,0)}let a=Jt(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 s=this.focusCaps(),a=typeof s?.zoom?.min=="number"?Math.max(s.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?.()??{},s=He(t.getCapabilities?.(),{width:e.width??0,height:e.height??0},this.deviceClass,{width:this.camera.width,height:this.camera.height},this.opts.ocr?.liveMrzOn===!0?{fill:this.guideRegion({width:1080,height:1920}).width}:void 0);s!==null&&await t.applyConstraints(s)}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&&pt(e,"continuous")&&await t.applyConstraints({advanced:[{focusMode:"continuous"}]}).catch(()=>{});let s={width:0,height:0};try{let h=t.getSettings?.()??{};s={width:h.width??0,height:h.height??0}}catch{}let a=ii(e,s,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 s=this.videoTrack(),a=le(this.focusCaps(),t,e);if(!(s===null||a===null))try{await s.applyConstraints({advanced:[a]}),(this.opts.setTimer??setTimeout)(()=>{this.restoreContinuous()},1500)}catch{}}async restoreContinuous(){let t=this.videoTrack();t===null||!this.camera.continuousFocus||!pt(this.focusCaps(),"continuous")||await t.applyConstraints({advanced:[{focusMode:"continuous"}]}).catch(()=>{})}async refocusOn(t,e){let s=this.camera.refocusBeforePhotoMs,a=this.videoTrack();if(s<=0||a===null||e.width<=0||e.height<=0)return;let h=C(t),o=le(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(),s)})}catch{}}videoTrack(){try{return this.stream?.getVideoTracks?.()[0]??null}catch{return null}}async takeStill(t,e,s){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(s&&this.opts.photoCapture!==!1&&this.deviceClass!=="LOW"&&!this.torchOn&&h!==null&&Ve(h)){await this.refocusOn(t,e);let o=await ti(this.opts.video,t,e,a,{track:h,detect:this.detector(),detectWidth:tt});if(this.restoreContinuous(),o!==null)return o}return $e(this.opts.video,t,e,a)}detector(){return this.opts.detect??((this.opts.format??"ID-1")==="ID-3"?ci:ni)}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()),s=this.opts.grabDetectFrame??me,a=this.detector(),h=s(this.opts.video,tt);if(h===null){this.scheduleTick(t);return}if(!this.lit){if(ut(h)>ui)this.lit=!0,this.blackTicks=0;else if(++this.blackTicks>=de&&this.frameWatch===null&&(this.opts.firstFrameMs??ue)>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:Ut(l),meanLuma:ut(l),specularFraction:Le(l)},u=Ee({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"?oi(h,this.guideRegion(h),{edgePeakFrac:this.guideTuning.edgePeakFrac}):ht,m=this.guideLock.tick(d,r);this.lastGuideQuad=m.detected?ri(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 v=u.lighting!=="ok"?u.lighting:u.glare!=="ok"?"glare":u.blur!=="ok"?"blurry":"steadying";b.qualityBlockers[v]=(b.qualityBlockers[v]??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<=wi?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=ze(u);u.framing!=="ok"&&m.detected&&(k=yi(m.blocker,d.brightness<this.guideTuning.darkBrightness)),k==="blurry"&&o!==null&&mi(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 v=this.feedback.force("processing",r);this.lastFeedbackKey=v.key,this.emit("feedback",v);let x=Y(at(h,y.quad));await this.fire(t,y.quad,{width:h.width,height:h.height,tickSharpness:x},y.via);return}if((I||F)&&this.opts.autoCapture!==!1){let v=this.feedback.force("processing",r);this.lastFeedbackKey=v.key,this.emit("feedback",v);let x=F?this.lastGuideQuad:o,L=F?m.via==="steady"?"guide_steady":"guide_good":"quad",B=F?Y(at(h,x)):c.sharpness;await this.fire(t,x,{width:h.width,height:h.height,tickSharpness:B},L);return}this.scheduleTick(t)}async fire(t,e,s,a){this.capturing=!0;let h=this.opts.grabDetectFrame??me,o=this.opts.setTimer??setTimeout,l={width:s.width,height:s.height};try{let r={still:await this.takeStill(e,l,!0),sharpness:s.tickSharpness};if(t!==this.attempt)return;let c=r.still.source==="photo"?0:gi;for(let d=0;d<c;d++){if(await new Promise(b=>{o(()=>b(),pi)}),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,s,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=fi(C(e),g,b,c,u):w=Vt(m,l.bandTop,u);let k=f?h.glare==="ok":s.cardGlare<=this.guideTuning.glareMax,S=f?h.blur==="ok":s.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??fe(d,t):this.lastGuideQuad??fe(d,t);this.lastOcrReady={quad:I,via:D.via}}else this.lastOcrReady=null;return D}},n(z,"i"),z);function fi(i,t,e,s,a){let h=Math.min(s,i.width*1.06*t),o=Math.min(a,Math.max(i.height*1.6*e,h/5)),l=(i.y+i.height/2)*e,r=Math.max(0,Math.min(s-h,(i.x-i.width*.03)*t)),c=Math.max(0,Math.min(a-o,l-o/2));return{x:r,y:c,w:h,h:o}}n(fi,"hi");function fe(i,t){let e=i.x*t.width,s=i.y*t.height,a=(i.x+i.width)*t.width,h=(i.y+i.height)*t.height;return{topLeft:{x:e,y:s},topRight:{x:a,y:s},bottomRight:{x:a,y:h},bottomLeft:{x:e,y:h}}}n(fe,"Ie");function mi(i,t,e){let s=C(i);return t.width<=0||t.height<=0?0:e==="ID-3"?s.width/t.width:s.width*s.height/(t.width*t.height)}n(mi,"di");var gi=2,pi=260,Mi=1.08;function me(i,t){let e=i.videoWidth,s=i.videoHeight;if(e===0||s===0)return null;let a=Math.min(1,t/e),h=Math.round(e*a),o=Math.round(s*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(i,0,0,h,o),r.getImageData(0,0,h,o))}n(me,"Pe");function at(i,t){let e=[t.topLeft.x,t.topRight.x,t.bottomRight.x,t.bottomLeft.x],s=[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(...s))),o=Math.min(i.width,Math.ceil(Math.max(...e))),l=Math.min(i.height,Math.ceil(Math.max(...s))),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)*i.width+a)*4;u.set(i.data.subarray(d,d+r*4),f*r*4)}return{data:u,width:r,height:c,colorSpace:i.colorSpace}}n(at,"lt");function yi(i,t){return i==="glare"?"glare":i==="too_small"?"too_far":i==="too_big"?"too_close":t?"too_dark":i==="blurry"?"blurry":i==="off_center"?"edge_clipped":i==="no_card"?"sensing":"hold_still"}n(yi,"gi");var wi=1200;export{Ti as a,Ai as b,zi as c,ue as d,ui as e,de as f,di as g,yt as h,Ci as i,Ii as j,fi as k,gi as l,pi as m};
@@ -1 +1 @@
1
- import{a as U,c as R}from"./chunk-ZEUFK4EC.js";import{b as D}from"./chunk-6MYG4HWP.js";import{a}from"./chunk-4FHWXBOB.js";var k,f=(k=class extends Error{constructor(t){super(t.message),this.name="HostedApiError",this.status=t.status,this.code=t.code,t.retryAfterSeconds!==void 0&&(this.retryAfterSeconds=t.retryAfterSeconds),t.details&&(this.details=t.details)}},a(k,"u"),k);function N(e,t,i=Math.random){let n=(e??t)*1e3,s=Math.min(Math.max(n,500),2e4),r=Math.round(s*(1+(i()*2-1)*.25));return Math.min(Math.max(r,500),2e4)}a(N,"b");var ie=6e4,L=4,ne=3e4,se=9e5,ae=200,re=5,oe=400,ce=new Set(["server_busy","request_timeout"]),de=20,ue=60,le=600,pe=2;function v(e){return(e.split(";")[0]??"").trim()}a(v,"p");var he={liveness:"clipKey",face_match:"imageKey",doc_ocr:"imageKey"},fe=`@sekyro/web/${U}`,me=fe,g,tt=(g=class{constructor(t){this.sessionId=null,this.bootstrap=null,this.captureNonces=[],this.captureFetch=null,this.reportedIssues=new Map,this.issueReports=0,this.issuesPausedUntil=0,this.apiOrigin=t.apiOrigin.replace(/\/+$/,""),this.sessionToken=t.sessionToken;let i=t.fetch;this.fetchImpl=(n,s)=>(i??globalThis.fetch).call(globalThis,n,s),this.requestTimeoutMs=t.requestTimeoutMs??ne,this.retryAttempts=t.inProgressRetry?.attempts??re,this.retryDelayMs=t.inProgressRetry?.delayMs??oe,this.random=t.random??Math.random,this.clientLocale=t.locale}async getSession(){let t=await this.api("GET","/hosted/session");return this.sessionId=t.sessionId,t}async recordConsent(t){let i=await this.api("POST","/hosted/consent",{body:{locale:t},busyRetry:!0}),n=this.captureHold;return this.captureHold=void 0,n&&this.armCapture(n),i}async reportCameraUnavailable(t){return this.api("POST","/hosted/camera-unavailable",{body:{cause:t}})}async testerGate(t){return this.api("POST","/hosted/tester-gate",{body:{input:t}})}async reportCaptureIssue(t){let i=typeof t.name=="string"?t.name.replace(/[^A-Za-z]/g,"").slice(0,40):"",n=typeof t.engineKind=="string"&&/^[a-z_]{1,32}$/.test(t.engineKind)?t.engineKind:void 0,s=typeof t.attempt=="number"&&Number.isInteger(t.attempt)&&t.attempt>=0&&t.attempt<=1e3?t.attempt:void 0,r=t.check==="attestation"?s??"":"",c=[t.check,r,t.kind,i,t.phase??"",n??""].join("|"),d=this.reportedIssues.get(c);if(d!==void 0)return d;if(Date.now()<this.issuesPausedUntil||this.issueReports>=de)return;let o={check:t.check,kind:t.kind,...i!==""?{name:i}:{},...t.phase!==void 0?{phase:t.phase}:{},...n!==void 0?{engineKind:n}:{},...s!==void 0?{attempt:s}:{},...t.formFactor!==void 0?{formFactor:t.formFactor}:{},...typeof t.detail=="string"&&/^\d{1,10}$/.test(t.detail)?{detail:t.detail}:{},...V(t.challengeMs)?{challengeMs:t.challengeMs}:{},...V(t.readyMs)?{readyMs:t.readyMs}:{},...t.inApp===!0?{inApp:!0}:{}};this.issueReports+=1;let u=this.api("POST","/hosted/capture-issue",{body:o,empty:!0}).catch(l=>{if(l instanceof f&&l.status===429){let p=Math.min(Math.max(l.retryAfterSeconds??ue,0),le);this.issuesPausedUntil=Math.max(this.issuesPausedUntil,Date.now()+p*1e3);return}(!(l instanceof f)||l.status===0||l.status>=500)&&this.reportedIssues.delete(c)});return this.reportedIssues.set(c,u),u}async choose(t,i){let n=await this.api("POST","/hosted/choice",{body:{nodeId:t,option:i},busyRetry:!0});return this.sessionId=n.sessionId,n}async confirmIdentity(t){return this.api("POST","/hosted/identity/confirm",{body:{decision:t}})}async identityPortrait(){return this.api("GET","/hosted/identity/portrait",{blob:!0})}async presign(t,i,n,s={}){let r=await this.ensureSessionId(),c={kind:t,contentType:v(i),contentLength:n,...s.source==="upload"?{source:"upload"}:{}};return this.api("POST",`/sessions/${r}/media`,{body:c})}armCapture(t=2){this.captureHold===void 0?this.fillCaptureNonces(t,t):this.captureHold=Math.max(this.captureHold,t)}async presignCapture(t,i,n,s={}){let r=await this.ensureSessionId(),c=await this.takeCaptureNonce(),d=c===void 0?void 0:{nonce:c,...s.engine!==void 0?{engine:s.engine.slice(0,32)}:{},...s.durationMs!==void 0&&Number.isFinite(s.durationMs)?{captureMs:Math.min(36e5,Math.max(0,Math.round(s.durationMs)))}:{}},o={kind:t,contentType:v(i),contentLength:n,capture:d};return this.api("POST",`/sessions/${r}/media`,{body:o})}async takeCaptureNonce(){let t=a(()=>{let i=Date.now();return this.captureNonces=this.captureNonces.filter(n=>n.expiresAt-ie>i),this.captureNonces.shift()?.nonce},"e");for(let i=0;i<2;i++){let n=t();if(n!==void 0)return n;await this.fillCaptureNonces(1)}return t()}fillCaptureNonces(t,i=0){return this.captureFetch??(this.captureFetch=(async()=>{try{let n=await this.ensureSessionId(),s=await this.api("POST",`/sessions/${n}/media/capture-nonces`,{body:{count:Math.min(L,Math.max(1,t))}}),r=Date.now()+Math.max(0,s.expiresIn)*1e3;for(let c of Array.isArray(s.nonces)?s.nonces:[])typeof c=="string"&&c.length>0&&this.captureNonces.push({nonce:c,expiresAt:r});this.captureNonces=this.captureNonces.slice(-L),this.captureHold=void 0}catch(n){n instanceof f&&n.code==="consent_required"&&(this.captureHold=Math.max(this.captureHold??0,i))}})().finally(()=>{this.captureFetch=null})),this.captureFetch}async uploadToSpaces(t,i,n){let s;try{s=await this.fetchImpl(t,{method:"PUT",headers:{"content-type":v(n)},body:i,signal:AbortSignal.timeout(se)})}catch(r){throw K(r)}if(!s.ok){let r=(await s.text().catch(()=>"")).slice(0,ae);throw new f({status:s.status,code:"upload_failed",message:`media upload failed (HTTP ${s.status})${r?`: ${r}`:""}`})}}async completeMedia(t){let i=await this.ensureSessionId();return this.api("POST",`/sessions/${i}/media/complete`,{body:{key:t}})}async submitCheck(t,i,n={}){let s=await this.ensureSessionId(),r={input:i,forceOutcome:n.forceOutcome};return this.api("POST",`/sessions/${s}/checks/${t}`,{body:r,idempotencyKey:n.idempotencyKey,...n.browserCheckToken!==void 0?{browserCheckToken:n.browserCheckToken}:{},busyRetry:n.idempotencyKey!==void 0})}async uploadAndSubmit(t,i,n,s={}){let r=v(i.contentType),c=await this.presign(i.kind,r,i.blob.size);await this.uploadToSpaces(c.uploadUrl,i.blob,r);let d=await this.completeMedia(c.key),o={...n,[he[t]]:d.key};return this.submitCheck(t,o,s)}async ensureSessionId(){return this.sessionId!==null?this.sessionId:(this.bootstrap??(this.bootstrap=this.getSession().finally(()=>{this.bootstrap=null})),(await this.bootstrap).sessionId)}async api(t,i,n={}){let s=t==="GET"||n.busyRetry===!0,r=`${this.apiOrigin}/api/v2${i}`,c={"x-session-token":this.sessionToken,"x-sekyro-sdk":me};n.body!==void 0&&(c["content-type"]="application/json"),n.idempotencyKey!==void 0&&(c["x-idempotency-key"]=n.idempotencyKey),n.browserCheckToken!==void 0&&(c["sekyro-browser-check"]=n.browserCheckToken),this.clientLocale!==void 0&&(c["sekyro-client-locale"]=this.clientLocale);try{let d=R.timezone();d!==void 0&&(c["sekyro-client-timezone"]=d)}catch{}c["sekyro-client-form-factor"]=D();try{let d=await R.deviceHeader();d!==void 0&&(c["sekyro-client-device"]=d)}catch{}for(let d=0;;d++){let o;try{o=await this.fetchImpl(r,{method:t,headers:c,...n.body!==void 0?{body:JSON.stringify(n.body)}:{},cache:"no-store",signal:AbortSignal.timeout(this.requestTimeoutMs)})}catch(l){throw K(l)}if(o.ok){if(n.empty===!0)return;if(n.blob===!0)try{return await o.blob()}catch(p){throw K(p)}let l;try{l=await o.json()}catch{throw new f({status:o.status,code:"unknown_error",message:`response body was not valid JSON (HTTP ${o.status})`})}return ye(l)}let u=await _e(o);if(u.code==="idempotency_in_progress"&&d<this.retryAttempts){this.retryDelayMs>0&&await G(this.retryDelayMs);continue}if(s&&u.status===503&&ce.has(u.code)){s=!1,await G(N(u.retryAfterSeconds,pe,this.random));continue}throw u}}},a(g,"T"),g);function V(e){return typeof e=="number"&&Number.isInteger(e)&&e>=0&&e<=6e5}a(V,"k");function K(e){if((typeof e=="object"&&e!==null?e.name:void 0)==="TimeoutError")return new f({status:0,code:"timeout",message:"request timed out"});let t=e instanceof Error?e.message:String(e);return new f({status:0,code:"network_error",message:`network request failed: ${t}`})}a(K,"h");function ye(e){return e!==null&&typeof e=="object"&&"success"in e&&"data"in e?e.data:e}a(ye,"K");async function _e(e){let t="unknown_error",i=`request failed (HTTP ${e.status})`,n=Number.NaN,s;try{let d=await e.json();if(d!==null&&typeof d=="object"){let o=d;typeof o.code=="string"&&o.code.length>0&&(t=o.code),typeof o.message=="string"&&o.message.length>0&&(i=o.message),typeof o.retryAfterSeconds=="number"&&(n=o.retryAfterSeconds),Array.isArray(o.details?.issues)?s=o.details:Array.isArray(o.details?.errors)&&(s={...o.details,issues:[]})}}catch{}let r=e.headers.get("retry-after"),c=r===null?Math.floor(n):Number.parseInt(r,10);return new f({status:e.status,code:t,message:i,...Number.isFinite(c)&&c>=0?{retryAfterSeconds:c}:{},details:s})}a(_e,"L");function G(e){return new Promise(t=>setTimeout(t,e))}a(G,"S");function it(e){let t=e?.portrait,i=t?.icao,n=t?.purpose==="id_document";return i==null?n?{policy:"reject",profile:"id_document"}:null:{policy:i.policy==="alert"?"alert":"reject",profile:n||i.profile==="id_document"?"id_document":"selfie"}}a(it,"z");function nt(e){return{...e.baselineEyeOpenness!==void 0?{baselineEyeOpenness:e.baselineEyeOpenness}:{},...e.baselineEyeOpennessLeft!==void 0&&e.baselineEyeOpennessRight!==void 0?{baselineEyeOpennessLeft:e.baselineEyeOpennessLeft,baselineEyeOpennessRight:e.baselineEyeOpennessRight}:{},criteria:e.verdict??{},...e.backgroundCheck!==void 0?{backgroundCheck:e.backgroundCheck}:{}}}a(nt,"X");var ve=new Set(["nni_unbound","id_number_unbound","method_required","mobile_required","portrait_required"]);function ot(e){return ve.has(e)}a(ot,"be");function ct(e,t,i){let n=t.detail;return{check:e,kind:t.kind,...n?.name!==void 0?{name:n.name}:{},...n?.phase!==void 0?{phase:n.phase}:{},...n?.engineKind!==void 0?{engineKind:n.engineKind}:{},attempt:Math.max(0,Math.min(1e3,i))}}a(ct,"ve");function dt(){let e=-1,t="";return{note(i){i==="starting"&&t!=="starting"&&(e+=1),t=i},newHandle(){t=""},noteError(){e<0&&(e=0)},get value(){return e}}}a(dt,"Pe");var ke={document:"document_photo",nfc:"document_chip",population_registry:"national_number",national_eid:"national_eid"};function y(e){return e.plan?.steps??[]}a(y,"f");function H(e){return Math.max(0,e.attempts.max-e.attempts.used)}a(H,"x");function ge(e){let t=e.plan?.choice;return t!==void 0&&e.plan?.current===t.nodeId?t:null}a(ge,"W");function ut(e){let t=ge(e);if(t?.kind!=="identity_method")return null;let i=t.options.map(s=>ke[s.service]).filter(s=>s!==void 0),n=t.options.find(s=>s.nationalEid)?.nationalEid;return n?{available:!0,selected:null,options:i,nationalEid:n}:{available:!0,selected:null,options:i}}a(ut,"Me");var be=new Set(["liveness","face_match"]);function z(e){return e!==void 0&&(e.state==="pending"||e.state==="input_required")}a(z,"y");function we(e){return e.status!=="created"&&e.status!=="in_progress"}a(we,"T");function X(e){let t=e.plan?.current,i=t==null?void 0:y(e).find(n=>n.id===t);return z(i)?i:void 0}a(X,"M");function q(e,t){return y(e).find(i=>i.checkType===t)}a(q,"_");function O(e){let t=y(e),i=t.findIndex(n=>n.checkType==="liveness");return t.find((n,s)=>s>i&&n.checkType==="face_match")}a(O,"S");function Me(e,t){let i=q(t,"liveness")?.state,n=O(t)?.state;return(O(e)?.state??"pending")==="pending"&&(i==="passed"||i==="review")&&n!==void 0&&n!=="pending"&&n!=="skipped"}a(Me,"F");function B(e,t){let i=new Map(y(e).map(n=>[n.id,n.state]));return y(t).filter(n=>n.checkType==="face_match"&&(i.get(n.id)??"pending")==="pending"&&n.state!=="pending"&&n.state!=="skipped").map(n=>n.id)}a(B,"V");var Se=/^[0-9a-f]{24}$/i;function E(e){return Se.test(e)?`ses_${e}`:e}a(E,"R");function x(e,t){let i=E(e);return t===void 0?{sessionId:i,status:"unavailable"}:{sessionId:i,status:"unavailable",reasonCode:t}}a(x,"w");function Z(e,t,i){let n=E(e);return i===void 0?{sessionId:n,status:t}:{sessionId:n,status:t,reasonCode:i}}a(Z,"O");function lt(e,t){let i=Te(e,t),n=Ie(e);return n!==void 0&&(i.sandbox={simulated:!0,reason:n}),i}a(lt,"Ve");var Ce=new Set(["no_testers","tester_gate_not_used","tester_gate_missed"]);function Ie(e){if(e.sandbox!==!0)return;let t=e.simulation?.reason;return Ce.has(t)?t:void 0}a(Ie,"Q");function Te(e,t){let i=E(e.sessionId);switch(e.status){case"created":case"in_progress":return Oe(e,t);case"verified":return P(e,{sessionId:i,status:"verified"});case"review_pending":return P(e,Z(i,"review",Q(e,"review")));case"not_verified":return P(e,Ee(e));default:return P(e,{sessionId:i,status:"not_verified"})}}a(Te,"Z");var Ae=new Set([0,1,2,3]);function P(e,t){return Ae.has(e.level)&&(t.level=e.level),typeof e.assurance=="string"&&e.assurance.length>0&&(t.assurance=e.assurance),t}a(P,"b");function Ee(e){let t={sessionId:E(e.sessionId),status:"not_verified"};return e.reason!==void 0&&(t.reason=e.reason),e.reasonCode!==void 0&&(t.reasonCode=e.reasonCode),e.reasonCode==="device_cooldown"&&e.retryAfter!==void 0&&(t.retryAfter=e.retryAfter),t}a(Ee,"ne");function xe(e){return e==="rejected"?"rejected":e==="unavailable"?"unavailable":"inconclusive"}a(xe,"te");function Pe(e,t){if(t===void 0)return!1;let i=y(t).find(n=>n.id===e.id);return i!==void 0&&i.attempts.used===e.attempts.used}a(Pe,"ie");function Oe(e,t){let i=E(e.sessionId),n=y(e).find(r=>be.has(r.checkType)&&r.state==="input_required"&&r.reason!==void 0);if(n?.reason==="mobile_required")return x(i,"mobile_required");if(n?.reason!==void 0){if(n.result==="unavailable")return x(i,n.reason);let r=t.autoRetry&&(H(n)>0||Pe(n,t.previous))?{sessionId:i,status:"retry",reasonCode:n.reason,attemptsRemaining:H(n)}:{sessionId:i,status:"not_verified",reason:xe(n.result),reasonCode:n.reason,attemptsRemaining:H(n)};return n.retakeHint!==void 0&&(r.retakeHint=n.retakeHint),r}let s=X(e);return s===void 0&&y(e).some(r=>r.state==="review")?Z(i,"review",Q(e,"review")):s?.checkType==="portrait_icao"?x(i,"portrait_required"):x(i)}a(Oe,"re");function Q(e,t){return y(e).find(i=>i.state===t&&i.reason!==void 0)?.reason}a(Q,"L");function W(e,t,i,n,s){return e.presignCapture!==void 0?e.presignCapture(t,i,n,s):e.presign(t,i,n)}a(W,"K");function Y(e){return{engine:e?.engine,durationMs:e?.clipMs}}a(Y,"q");var qe=["video/webm","video/mp4"],J="image/jpeg",$e=2,Re=1e3,Ke=1e4,Ne=3,He=10,Fe=3,ze=new Set(["network_error","timeout","upload_failed","unknown_error","rate_limit_exceeded"]),je=new Set(["session_not_active","check_not_found","check_already_finalized","check_out_of_order","identity_confirm_required","check_not_active","step_not_on_path","native_app_required"]),b,j=(b=class extends Error{constructor(){super("verification destroyed"),this.name="FlowCancelledError"}},a(b,"k"),b);function De(e){let t=O(e);return q(e,"portrait_icao")?.state!=="pending"&&(t!==void 0?z(t):e.capture?.livePhoto?.oneCapture===!0)}a(De,"me");var w,A=(w=class extends Error{constructor(t){super(t),this.name="AttestationError"}},a(w,"h"),w),M,Ue=(M=class extends A{constructor(t){super(`no attestation token: ${t}`),this.name="AttestationUnavailableError",this.code=t}},a(M,"E"),M);async function ee(e,t,i={}){let n=e.uuid(),s=!1,r=!1,c=0,d=0;for(;;)try{return await t(e.client,n)}catch(o){if(o instanceof A){if(r||o instanceof Ue)throw o;r=!0,i.onAttestationInvalid?.(),n=e.uuid();continue}if(!(o instanceof f))throw o;if(o.code==="consent_required"&&!s){s=!0,await e.ensureConsent({force:!0}),n=e.uuid();continue}if(o.code==="attestation_invalid"&&!r){r=!0,i.onAttestationInvalid?.(),n=e.uuid();continue}if(o.code==="inference_unavailable"&&d<Ne){d+=1;let u=N(o.retryAfterSeconds,He,e.random??Math.random);e.onBusy?.({attempt:d,retryAfterSeconds:u/1e3}),await e.sleep(u),i.onAttestationInvalid?.(),n=e.uuid();continue}if(ze.has(o.code)&&c<$e){c+=1;let u=o.retryAfterSeconds!==void 0?o.retryAfterSeconds*1e3:void 0;await e.sleep(u!==void 0?Math.min(u,Ke):Re);continue}throw o}}a(ee,"D");var Le=new Set(["passed","review","processing","skipped"]);async function pt(e){let{artifacts:t}=e,i=t.clip,n=v(t.clipMime??"");if(t.degraded==="NO_RECORDER"||i===void 0||!qe.includes(n))return{kind:"unavailable",reason:"no_recorder"};e.client.armCapture?.(2);let s=Ve(e,t.keyframe),r=Ge(e,i,n,s),c=Be(e,s),d=!1,o=new Set,u=!0,l=0;for(;;){if(e.isCancelled())return{kind:"cancelled"};let p=e.getView();if(we(p))return{kind:"settled"};let h=X(p),T=h?.checkType,$=T==="liveness"&&!d?"liveness":T==="face_match"&&!o.has(h?.id)&&o.size<2&&u?"face_match":null;if($===null)return{kind:"settled"};if($==="liveness"&&t.captureChannel==="desktop")return{kind:"unavailable",reason:"mobile_required"};try{if($==="liveness"){d=!0;let m=await r();if(e.isCancelled())return{kind:"cancelled"};Me(p,m)&&o.add(O(m)?.id);for(let te of B(p,m))o.add(te);await e.applySubmit(m,"liveness");let _=q(e.getView(),"liveness")?.state;u=_===void 0||Le.has(_)}else{o.add(h?.id);let m=await c();if(e.isCancelled())return{kind:"cancelled"};for(let _ of B(p,m))o.add(_);await e.applySubmit(m,"face_match")}}catch(m){if(e.isCancelled()||m instanceof j)return{kind:"cancelled"};let _=Qe(m);if(_.kind!=="resync"||l>=Fe)return _;l+=1,await e.refreshView()}}}a(pt,"Fe");function Ve(e,t){let i=null,n=null,s=a(()=>i!==null?Promise.resolve(i):(n??(n=(async()=>{let r=await W(e.client,"image",J,t.size,Y(e.artifacts));return await e.client.uploadToSpaces(r.uploadUrl,t,J),i=(await e.client.completeMedia(r.key)).key,e.onKeyframePromoted?.(i),i})().finally(()=>{n=null})),n),"r");return{ensure:s,attempt:a(()=>s().catch(()=>null),"attempt"),current:a(()=>i,"current")}}a(Ve,"_e");function Ge(e,t,i,n){let s=e.clipKeys?.get()??null,r,c=null,d=0,o;return()=>ee(e,async(u,l)=>{if(s===null||r===void 0){if(e.isCancelled())throw new j;r===void 0&&!De(e.getView())&&(r=null),e.onPhase("uploading");let[p,h]=await Promise.all([s!==null?Promise.resolve(s):(async()=>{let T=await W(u,"clip",i,t.size,Y(e.artifacts));return await u.uploadToSpaces(T.uploadUrl,t,i),(await u.completeMedia(T.key)).key})(),r!==void 0?Promise.resolve(r===null?null:r.imageKey):n.attempt()]);s=p,e.clipKeys?.set(p),r===void 0&&(r=h===null?null:{imageKey:h})}if(c===null){let p=performance.now();try{c=await e.getAttestation(),o=e.attestationError?.()}catch(h){throw h instanceof A?h:new A(h instanceof Error?h.message:String(h))}d=Math.round(performance.now()-p)}return e.onPhase("checking"),u.submitCheck("liveness",{clipKey:s,attestation:c,captureChannel:e.artifacts.captureChannel,capture:{...Je(e.artifacts),attestationMs:d,attestationError:o,...Ze(e.attestationFacts?.())},...r!==null?{faceMatch:r}:{}},{idempotencyKey:l})},{onAttestationInvalid:a(()=>{c=null},"onAttestationInvalid")})}a(Ge,"ge");function Be(e,t){return()=>ee(e,async(i,n)=>{if(t.current()===null){if(e.isCancelled())throw new j;e.onPhase("uploading")}let s=await t.ensure();return e.onPhase("checking"),i.submitCheck("face_match",{imageKey:s},{idempotencyKey:n})})}a(Be,"Se");function Je(e){let t={width:e.width,height:e.height};for(let i of Xe)e[i]!==void 0&&(t[i]=e[i]);return t}a(Je,"ye");var Xe=["engine","facingMode","mode","formFactor","clipMs","clipFrames","fps","clipRetakes","codec","cameraReadyMs","faceAcquireMs","captureMs","screenRamp","provenance"];function Ze(e){return e===void 0?{}:{attestationChecks:e.checks,...e.challengeMs!==void 0?{attestationChallengeMs:e.challengeMs}:{}}}a(Ze,"ke");function Qe(e){if(e instanceof A)return{kind:"unavailable",reason:"attestation"};if(e instanceof f){if(e.code==="attestation_invalid")return{kind:"unavailable",reason:"attestation"};if(e.code==="inference_unavailable")return{kind:"unavailable",reason:"inference_unavailable"};if(e.code==="mobile_required")return{kind:"unavailable",reason:"mobile_required"};if(je.has(e.code))return{kind:"resync"}}return{kind:"unavailable",reason:"network"}}a(Qe,"Ce");var ht="form_answers_invalid",S,ft=(S=class extends Error{constructor(t,i){super(`form answers refused (${t.map(n=>`${n.id}: ${n.code}`).join(", ")})`),this.name="FormAnswersError",this.issues=t,this.source=i}},a(S,"U"),S),C,mt=(C=class extends Error{constructor(t,i){super(`invalid ${t} (${i})`),this.name="InvalidInputError",this.field=t,this.kind=i}},a(C,"B"),C),I,yt=(I=class extends Error{constructor(t,i){super(`invalid ${t} (${i})`),this.name="OtpInputError",this.field=t,this.kind=i}},a(I,"$"),I);function F(e){return e?.source==="upload"?null:e?.source==="choice"&&e.sourcePick!=="camera"?"upload_or_phone":"phone"}a(F,"I");function _t(e,t){if(t===void 0||!z(t)||t.requiresMobile!==!0)return null;switch(t.checkType){case"liveness":return"phone";case"face_match":{if(t.reason!==void 0)return"phone";let i=q(e,"portrait_icao");return i?.state==="passed"||i?.state==="review"?null:"phone"}case"doc_ocr":return F(e.documents);case"poa":return F(e.proofOfAddress);case"portrait_icao":{let i=e.portrait;return i?.pendingFix!==void 0||i?.reuse?.pending===!0?null:F(i)}default:return null}}a(_t,"De");function We(e){let t=e?.capture,i=t?.mode;return i==="assisted"||i==="self"||i==="choice"?i:t?.cameraSwitch===!0?"assisted":"self"}a(We,"we");function vt(e){let t=e?.capture?.pick;return We(e)==="choice"&&(t==="self"||t==="assisted")?t:null}a(vt,"Be");function kt(e,t,i=null){return e==="choice"?t??i??"self":e}a(kt,"$e");var gt={"MR:drivers_license":{normalize:"upper_no_space_or_hyphen",pattern:"^[0-9]{8}$",check:null,registrySources:[],describe:"number must be the 8-digit Mauritanian driver's license number"},"MR:national_id":{normalize:"trim",pattern:"^[0-9]{10}$",check:"mr_nni_mod97",registrySources:["MR.anrpts"],describe:"number must be the 10-digit Mauritanian national ID number with a valid check digit"}};export{f as a,v as b,tt as c,it as d,nt as e,ot as f,ct as g,dt as h,ke as i,y as j,H as k,ge as l,ut as m,z as n,we as o,X as p,q,E as r,x as s,lt as t,Ie as u,W as v,qe as w,Ue as x,ee as y,pt as z,Je as A,ht as B,ft as C,mt as D,yt as E,_t as F,We as G,vt as H,kt as I,gt as J};
1
+ import{a as U,c as R}from"./chunk-HOSTJBJM.js";import{b as D}from"./chunk-6MYG4HWP.js";import{a}from"./chunk-4FHWXBOB.js";var k,f=(k=class extends Error{constructor(t){super(t.message),this.name="HostedApiError",this.status=t.status,this.code=t.code,t.retryAfterSeconds!==void 0&&(this.retryAfterSeconds=t.retryAfterSeconds),t.details&&(this.details=t.details)}},a(k,"u"),k);function N(e,t,i=Math.random){let n=(e??t)*1e3,s=Math.min(Math.max(n,500),2e4),r=Math.round(s*(1+(i()*2-1)*.25));return Math.min(Math.max(r,500),2e4)}a(N,"b");var ie=6e4,L=4,ne=3e4,se=9e5,ae=200,re=5,oe=400,ce=new Set(["server_busy","request_timeout"]),de=20,ue=60,le=600,pe=2;function v(e){return(e.split(";")[0]??"").trim()}a(v,"p");var he={liveness:"clipKey",face_match:"imageKey",doc_ocr:"imageKey"},fe=`@sekyro/web/${U}`,me=fe,g,tt=(g=class{constructor(t){this.sessionId=null,this.bootstrap=null,this.captureNonces=[],this.captureFetch=null,this.reportedIssues=new Map,this.issueReports=0,this.issuesPausedUntil=0,this.apiOrigin=t.apiOrigin.replace(/\/+$/,""),this.sessionToken=t.sessionToken;let i=t.fetch;this.fetchImpl=(n,s)=>(i??globalThis.fetch).call(globalThis,n,s),this.requestTimeoutMs=t.requestTimeoutMs??ne,this.retryAttempts=t.inProgressRetry?.attempts??re,this.retryDelayMs=t.inProgressRetry?.delayMs??oe,this.random=t.random??Math.random,this.clientLocale=t.locale}async getSession(){let t=await this.api("GET","/hosted/session");return this.sessionId=t.sessionId,t}async recordConsent(t){let i=await this.api("POST","/hosted/consent",{body:{locale:t},busyRetry:!0}),n=this.captureHold;return this.captureHold=void 0,n&&this.armCapture(n),i}async reportCameraUnavailable(t){return this.api("POST","/hosted/camera-unavailable",{body:{cause:t}})}async testerGate(t){return this.api("POST","/hosted/tester-gate",{body:{input:t}})}async reportCaptureIssue(t){let i=typeof t.name=="string"?t.name.replace(/[^A-Za-z]/g,"").slice(0,40):"",n=typeof t.engineKind=="string"&&/^[a-z_]{1,32}$/.test(t.engineKind)?t.engineKind:void 0,s=typeof t.attempt=="number"&&Number.isInteger(t.attempt)&&t.attempt>=0&&t.attempt<=1e3?t.attempt:void 0,r=t.check==="attestation"?s??"":"",c=[t.check,r,t.kind,i,t.phase??"",n??""].join("|"),d=this.reportedIssues.get(c);if(d!==void 0)return d;if(Date.now()<this.issuesPausedUntil||this.issueReports>=de)return;let o={check:t.check,kind:t.kind,...i!==""?{name:i}:{},...t.phase!==void 0?{phase:t.phase}:{},...n!==void 0?{engineKind:n}:{},...s!==void 0?{attempt:s}:{},...t.formFactor!==void 0?{formFactor:t.formFactor}:{},...typeof t.detail=="string"&&/^\d{1,10}$/.test(t.detail)?{detail:t.detail}:{},...V(t.challengeMs)?{challengeMs:t.challengeMs}:{},...V(t.readyMs)?{readyMs:t.readyMs}:{},...t.inApp===!0?{inApp:!0}:{}};this.issueReports+=1;let u=this.api("POST","/hosted/capture-issue",{body:o,empty:!0}).catch(l=>{if(l instanceof f&&l.status===429){let p=Math.min(Math.max(l.retryAfterSeconds??ue,0),le);this.issuesPausedUntil=Math.max(this.issuesPausedUntil,Date.now()+p*1e3);return}(!(l instanceof f)||l.status===0||l.status>=500)&&this.reportedIssues.delete(c)});return this.reportedIssues.set(c,u),u}async choose(t,i){let n=await this.api("POST","/hosted/choice",{body:{nodeId:t,option:i},busyRetry:!0});return this.sessionId=n.sessionId,n}async confirmIdentity(t){return this.api("POST","/hosted/identity/confirm",{body:{decision:t}})}async identityPortrait(){return this.api("GET","/hosted/identity/portrait",{blob:!0})}async presign(t,i,n,s={}){let r=await this.ensureSessionId(),c={kind:t,contentType:v(i),contentLength:n,...s.source==="upload"?{source:"upload"}:{}};return this.api("POST",`/sessions/${r}/media`,{body:c})}armCapture(t=2){this.captureHold===void 0?this.fillCaptureNonces(t,t):this.captureHold=Math.max(this.captureHold,t)}async presignCapture(t,i,n,s={}){let r=await this.ensureSessionId(),c=await this.takeCaptureNonce(),d=c===void 0?void 0:{nonce:c,...s.engine!==void 0?{engine:s.engine.slice(0,32)}:{},...s.durationMs!==void 0&&Number.isFinite(s.durationMs)?{captureMs:Math.min(36e5,Math.max(0,Math.round(s.durationMs)))}:{}},o={kind:t,contentType:v(i),contentLength:n,capture:d};return this.api("POST",`/sessions/${r}/media`,{body:o})}async takeCaptureNonce(){let t=a(()=>{let i=Date.now();return this.captureNonces=this.captureNonces.filter(n=>n.expiresAt-ie>i),this.captureNonces.shift()?.nonce},"e");for(let i=0;i<2;i++){let n=t();if(n!==void 0)return n;await this.fillCaptureNonces(1)}return t()}fillCaptureNonces(t,i=0){return this.captureFetch??(this.captureFetch=(async()=>{try{let n=await this.ensureSessionId(),s=await this.api("POST",`/sessions/${n}/media/capture-nonces`,{body:{count:Math.min(L,Math.max(1,t))}}),r=Date.now()+Math.max(0,s.expiresIn)*1e3;for(let c of Array.isArray(s.nonces)?s.nonces:[])typeof c=="string"&&c.length>0&&this.captureNonces.push({nonce:c,expiresAt:r});this.captureNonces=this.captureNonces.slice(-L),this.captureHold=void 0}catch(n){n instanceof f&&n.code==="consent_required"&&(this.captureHold=Math.max(this.captureHold??0,i))}})().finally(()=>{this.captureFetch=null})),this.captureFetch}async uploadToSpaces(t,i,n){let s;try{s=await this.fetchImpl(t,{method:"PUT",headers:{"content-type":v(n)},body:i,signal:AbortSignal.timeout(se)})}catch(r){throw K(r)}if(!s.ok){let r=(await s.text().catch(()=>"")).slice(0,ae);throw new f({status:s.status,code:"upload_failed",message:`media upload failed (HTTP ${s.status})${r?`: ${r}`:""}`})}}async completeMedia(t){let i=await this.ensureSessionId();return this.api("POST",`/sessions/${i}/media/complete`,{body:{key:t}})}async submitCheck(t,i,n={}){let s=await this.ensureSessionId(),r={input:i,forceOutcome:n.forceOutcome};return this.api("POST",`/sessions/${s}/checks/${t}`,{body:r,idempotencyKey:n.idempotencyKey,...n.browserCheckToken!==void 0?{browserCheckToken:n.browserCheckToken}:{},busyRetry:n.idempotencyKey!==void 0})}async uploadAndSubmit(t,i,n,s={}){let r=v(i.contentType),c=await this.presign(i.kind,r,i.blob.size);await this.uploadToSpaces(c.uploadUrl,i.blob,r);let d=await this.completeMedia(c.key),o={...n,[he[t]]:d.key};return this.submitCheck(t,o,s)}async ensureSessionId(){return this.sessionId!==null?this.sessionId:(this.bootstrap??(this.bootstrap=this.getSession().finally(()=>{this.bootstrap=null})),(await this.bootstrap).sessionId)}async api(t,i,n={}){let s=t==="GET"||n.busyRetry===!0,r=`${this.apiOrigin}/api/v2${i}`,c={"x-session-token":this.sessionToken,"x-sekyro-sdk":me};n.body!==void 0&&(c["content-type"]="application/json"),n.idempotencyKey!==void 0&&(c["x-idempotency-key"]=n.idempotencyKey),n.browserCheckToken!==void 0&&(c["sekyro-browser-check"]=n.browserCheckToken),this.clientLocale!==void 0&&(c["sekyro-client-locale"]=this.clientLocale);try{let d=R.timezone();d!==void 0&&(c["sekyro-client-timezone"]=d)}catch{}c["sekyro-client-form-factor"]=D();try{let d=await R.deviceHeader();d!==void 0&&(c["sekyro-client-device"]=d)}catch{}for(let d=0;;d++){let o;try{o=await this.fetchImpl(r,{method:t,headers:c,...n.body!==void 0?{body:JSON.stringify(n.body)}:{},cache:"no-store",signal:AbortSignal.timeout(this.requestTimeoutMs)})}catch(l){throw K(l)}if(o.ok){if(n.empty===!0)return;if(n.blob===!0)try{return await o.blob()}catch(p){throw K(p)}let l;try{l=await o.json()}catch{throw new f({status:o.status,code:"unknown_error",message:`response body was not valid JSON (HTTP ${o.status})`})}return ye(l)}let u=await _e(o);if(u.code==="idempotency_in_progress"&&d<this.retryAttempts){this.retryDelayMs>0&&await G(this.retryDelayMs);continue}if(s&&u.status===503&&ce.has(u.code)){s=!1,await G(N(u.retryAfterSeconds,pe,this.random));continue}throw u}}},a(g,"T"),g);function V(e){return typeof e=="number"&&Number.isInteger(e)&&e>=0&&e<=6e5}a(V,"k");function K(e){if((typeof e=="object"&&e!==null?e.name:void 0)==="TimeoutError")return new f({status:0,code:"timeout",message:"request timed out"});let t=e instanceof Error?e.message:String(e);return new f({status:0,code:"network_error",message:`network request failed: ${t}`})}a(K,"h");function ye(e){return e!==null&&typeof e=="object"&&"success"in e&&"data"in e?e.data:e}a(ye,"K");async function _e(e){let t="unknown_error",i=`request failed (HTTP ${e.status})`,n=Number.NaN,s;try{let d=await e.json();if(d!==null&&typeof d=="object"){let o=d;typeof o.code=="string"&&o.code.length>0&&(t=o.code),typeof o.message=="string"&&o.message.length>0&&(i=o.message),typeof o.retryAfterSeconds=="number"&&(n=o.retryAfterSeconds),Array.isArray(o.details?.issues)?s=o.details:Array.isArray(o.details?.errors)&&(s={...o.details,issues:[]})}}catch{}let r=e.headers.get("retry-after"),c=r===null?Math.floor(n):Number.parseInt(r,10);return new f({status:e.status,code:t,message:i,...Number.isFinite(c)&&c>=0?{retryAfterSeconds:c}:{},details:s})}a(_e,"L");function G(e){return new Promise(t=>setTimeout(t,e))}a(G,"S");function it(e){let t=e?.portrait,i=t?.icao,n=t?.purpose==="id_document";return i==null?n?{policy:"reject",profile:"id_document"}:null:{policy:i.policy==="alert"?"alert":"reject",profile:n||i.profile==="id_document"?"id_document":"selfie"}}a(it,"z");function nt(e){return{...e.baselineEyeOpenness!==void 0?{baselineEyeOpenness:e.baselineEyeOpenness}:{},...e.baselineEyeOpennessLeft!==void 0&&e.baselineEyeOpennessRight!==void 0?{baselineEyeOpennessLeft:e.baselineEyeOpennessLeft,baselineEyeOpennessRight:e.baselineEyeOpennessRight}:{},criteria:e.verdict??{},...e.backgroundCheck!==void 0?{backgroundCheck:e.backgroundCheck}:{}}}a(nt,"X");var ve=new Set(["nni_unbound","id_number_unbound","method_required","mobile_required","portrait_required"]);function ot(e){return ve.has(e)}a(ot,"be");function ct(e,t,i){let n=t.detail;return{check:e,kind:t.kind,...n?.name!==void 0?{name:n.name}:{},...n?.phase!==void 0?{phase:n.phase}:{},...n?.engineKind!==void 0?{engineKind:n.engineKind}:{},attempt:Math.max(0,Math.min(1e3,i))}}a(ct,"ve");function dt(){let e=-1,t="";return{note(i){i==="starting"&&t!=="starting"&&(e+=1),t=i},newHandle(){t=""},noteError(){e<0&&(e=0)},get value(){return e}}}a(dt,"Pe");var ke={document:"document_photo",nfc:"document_chip",population_registry:"national_number",national_eid:"national_eid"};function y(e){return e.plan?.steps??[]}a(y,"f");function H(e){return Math.max(0,e.attempts.max-e.attempts.used)}a(H,"x");function ge(e){let t=e.plan?.choice;return t!==void 0&&e.plan?.current===t.nodeId?t:null}a(ge,"W");function ut(e){let t=ge(e);if(t?.kind!=="identity_method")return null;let i=t.options.map(s=>ke[s.service]).filter(s=>s!==void 0),n=t.options.find(s=>s.nationalEid)?.nationalEid;return n?{available:!0,selected:null,options:i,nationalEid:n}:{available:!0,selected:null,options:i}}a(ut,"Me");var be=new Set(["liveness","face_match"]);function z(e){return e!==void 0&&(e.state==="pending"||e.state==="input_required")}a(z,"y");function we(e){return e.status!=="created"&&e.status!=="in_progress"}a(we,"T");function X(e){let t=e.plan?.current,i=t==null?void 0:y(e).find(n=>n.id===t);return z(i)?i:void 0}a(X,"M");function q(e,t){return y(e).find(i=>i.checkType===t)}a(q,"_");function O(e){let t=y(e),i=t.findIndex(n=>n.checkType==="liveness");return t.find((n,s)=>s>i&&n.checkType==="face_match")}a(O,"S");function Me(e,t){let i=q(t,"liveness")?.state,n=O(t)?.state;return(O(e)?.state??"pending")==="pending"&&(i==="passed"||i==="review")&&n!==void 0&&n!=="pending"&&n!=="skipped"}a(Me,"F");function B(e,t){let i=new Map(y(e).map(n=>[n.id,n.state]));return y(t).filter(n=>n.checkType==="face_match"&&(i.get(n.id)??"pending")==="pending"&&n.state!=="pending"&&n.state!=="skipped").map(n=>n.id)}a(B,"V");var Se=/^[0-9a-f]{24}$/i;function E(e){return Se.test(e)?`ses_${e}`:e}a(E,"R");function x(e,t){let i=E(e);return t===void 0?{sessionId:i,status:"unavailable"}:{sessionId:i,status:"unavailable",reasonCode:t}}a(x,"w");function Z(e,t,i){let n=E(e);return i===void 0?{sessionId:n,status:t}:{sessionId:n,status:t,reasonCode:i}}a(Z,"O");function lt(e,t){let i=Te(e,t),n=Ie(e);return n!==void 0&&(i.sandbox={simulated:!0,reason:n}),i}a(lt,"Ve");var Ce=new Set(["no_testers","tester_gate_not_used","tester_gate_missed"]);function Ie(e){if(e.sandbox!==!0)return;let t=e.simulation?.reason;return Ce.has(t)?t:void 0}a(Ie,"Q");function Te(e,t){let i=E(e.sessionId);switch(e.status){case"created":case"in_progress":return Oe(e,t);case"verified":return P(e,{sessionId:i,status:"verified"});case"review_pending":return P(e,Z(i,"review",Q(e,"review")));case"not_verified":return P(e,Ee(e));default:return P(e,{sessionId:i,status:"not_verified"})}}a(Te,"Z");var Ae=new Set([0,1,2,3]);function P(e,t){return Ae.has(e.level)&&(t.level=e.level),typeof e.assurance=="string"&&e.assurance.length>0&&(t.assurance=e.assurance),t}a(P,"b");function Ee(e){let t={sessionId:E(e.sessionId),status:"not_verified"};return e.reason!==void 0&&(t.reason=e.reason),e.reasonCode!==void 0&&(t.reasonCode=e.reasonCode),e.reasonCode==="device_cooldown"&&e.retryAfter!==void 0&&(t.retryAfter=e.retryAfter),t}a(Ee,"ne");function xe(e){return e==="rejected"?"rejected":e==="unavailable"?"unavailable":"inconclusive"}a(xe,"te");function Pe(e,t){if(t===void 0)return!1;let i=y(t).find(n=>n.id===e.id);return i!==void 0&&i.attempts.used===e.attempts.used}a(Pe,"ie");function Oe(e,t){let i=E(e.sessionId),n=y(e).find(r=>be.has(r.checkType)&&r.state==="input_required"&&r.reason!==void 0);if(n?.reason==="mobile_required")return x(i,"mobile_required");if(n?.reason!==void 0){if(n.result==="unavailable")return x(i,n.reason);let r=t.autoRetry&&(H(n)>0||Pe(n,t.previous))?{sessionId:i,status:"retry",reasonCode:n.reason,attemptsRemaining:H(n)}:{sessionId:i,status:"not_verified",reason:xe(n.result),reasonCode:n.reason,attemptsRemaining:H(n)};return n.retakeHint!==void 0&&(r.retakeHint=n.retakeHint),r}let s=X(e);return s===void 0&&y(e).some(r=>r.state==="review")?Z(i,"review",Q(e,"review")):s?.checkType==="portrait_icao"?x(i,"portrait_required"):x(i)}a(Oe,"re");function Q(e,t){return y(e).find(i=>i.state===t&&i.reason!==void 0)?.reason}a(Q,"L");function W(e,t,i,n,s){return e.presignCapture!==void 0?e.presignCapture(t,i,n,s):e.presign(t,i,n)}a(W,"K");function Y(e){return{engine:e?.engine,durationMs:e?.clipMs}}a(Y,"q");var qe=["video/webm","video/mp4"],J="image/jpeg",$e=2,Re=1e3,Ke=1e4,Ne=3,He=10,Fe=3,ze=new Set(["network_error","timeout","upload_failed","unknown_error","rate_limit_exceeded"]),je=new Set(["session_not_active","check_not_found","check_already_finalized","check_out_of_order","identity_confirm_required","check_not_active","step_not_on_path","native_app_required"]),b,j=(b=class extends Error{constructor(){super("verification destroyed"),this.name="FlowCancelledError"}},a(b,"k"),b);function De(e){let t=O(e);return q(e,"portrait_icao")?.state!=="pending"&&(t!==void 0?z(t):e.capture?.livePhoto?.oneCapture===!0)}a(De,"me");var w,A=(w=class extends Error{constructor(t){super(t),this.name="AttestationError"}},a(w,"h"),w),M,Ue=(M=class extends A{constructor(t){super(`no attestation token: ${t}`),this.name="AttestationUnavailableError",this.code=t}},a(M,"E"),M);async function ee(e,t,i={}){let n=e.uuid(),s=!1,r=!1,c=0,d=0;for(;;)try{return await t(e.client,n)}catch(o){if(o instanceof A){if(r||o instanceof Ue)throw o;r=!0,i.onAttestationInvalid?.(),n=e.uuid();continue}if(!(o instanceof f))throw o;if(o.code==="consent_required"&&!s){s=!0,await e.ensureConsent({force:!0}),n=e.uuid();continue}if(o.code==="attestation_invalid"&&!r){r=!0,i.onAttestationInvalid?.(),n=e.uuid();continue}if(o.code==="inference_unavailable"&&d<Ne){d+=1;let u=N(o.retryAfterSeconds,He,e.random??Math.random);e.onBusy?.({attempt:d,retryAfterSeconds:u/1e3}),await e.sleep(u),i.onAttestationInvalid?.(),n=e.uuid();continue}if(ze.has(o.code)&&c<$e){c+=1;let u=o.retryAfterSeconds!==void 0?o.retryAfterSeconds*1e3:void 0;await e.sleep(u!==void 0?Math.min(u,Ke):Re);continue}throw o}}a(ee,"D");var Le=new Set(["passed","review","processing","skipped"]);async function pt(e){let{artifacts:t}=e,i=t.clip,n=v(t.clipMime??"");if(t.degraded==="NO_RECORDER"||i===void 0||!qe.includes(n))return{kind:"unavailable",reason:"no_recorder"};e.client.armCapture?.(2);let s=Ve(e,t.keyframe),r=Ge(e,i,n,s),c=Be(e,s),d=!1,o=new Set,u=!0,l=0;for(;;){if(e.isCancelled())return{kind:"cancelled"};let p=e.getView();if(we(p))return{kind:"settled"};let h=X(p),T=h?.checkType,$=T==="liveness"&&!d?"liveness":T==="face_match"&&!o.has(h?.id)&&o.size<2&&u?"face_match":null;if($===null)return{kind:"settled"};if($==="liveness"&&t.captureChannel==="desktop")return{kind:"unavailable",reason:"mobile_required"};try{if($==="liveness"){d=!0;let m=await r();if(e.isCancelled())return{kind:"cancelled"};Me(p,m)&&o.add(O(m)?.id);for(let te of B(p,m))o.add(te);await e.applySubmit(m,"liveness");let _=q(e.getView(),"liveness")?.state;u=_===void 0||Le.has(_)}else{o.add(h?.id);let m=await c();if(e.isCancelled())return{kind:"cancelled"};for(let _ of B(p,m))o.add(_);await e.applySubmit(m,"face_match")}}catch(m){if(e.isCancelled()||m instanceof j)return{kind:"cancelled"};let _=Qe(m);if(_.kind!=="resync"||l>=Fe)return _;l+=1,await e.refreshView()}}}a(pt,"Fe");function Ve(e,t){let i=null,n=null,s=a(()=>i!==null?Promise.resolve(i):(n??(n=(async()=>{let r=await W(e.client,"image",J,t.size,Y(e.artifacts));return await e.client.uploadToSpaces(r.uploadUrl,t,J),i=(await e.client.completeMedia(r.key)).key,e.onKeyframePromoted?.(i),i})().finally(()=>{n=null})),n),"r");return{ensure:s,attempt:a(()=>s().catch(()=>null),"attempt"),current:a(()=>i,"current")}}a(Ve,"_e");function Ge(e,t,i,n){let s=e.clipKeys?.get()??null,r,c=null,d=0,o;return()=>ee(e,async(u,l)=>{if(s===null||r===void 0){if(e.isCancelled())throw new j;r===void 0&&!De(e.getView())&&(r=null),e.onPhase("uploading");let[p,h]=await Promise.all([s!==null?Promise.resolve(s):(async()=>{let T=await W(u,"clip",i,t.size,Y(e.artifacts));return await u.uploadToSpaces(T.uploadUrl,t,i),(await u.completeMedia(T.key)).key})(),r!==void 0?Promise.resolve(r===null?null:r.imageKey):n.attempt()]);s=p,e.clipKeys?.set(p),r===void 0&&(r=h===null?null:{imageKey:h})}if(c===null){let p=performance.now();try{c=await e.getAttestation(),o=e.attestationError?.()}catch(h){throw h instanceof A?h:new A(h instanceof Error?h.message:String(h))}d=Math.round(performance.now()-p)}return e.onPhase("checking"),u.submitCheck("liveness",{clipKey:s,attestation:c,captureChannel:e.artifacts.captureChannel,capture:{...Je(e.artifacts),attestationMs:d,attestationError:o,...Ze(e.attestationFacts?.())},...r!==null?{faceMatch:r}:{}},{idempotencyKey:l})},{onAttestationInvalid:a(()=>{c=null},"onAttestationInvalid")})}a(Ge,"ge");function Be(e,t){return()=>ee(e,async(i,n)=>{if(t.current()===null){if(e.isCancelled())throw new j;e.onPhase("uploading")}let s=await t.ensure();return e.onPhase("checking"),i.submitCheck("face_match",{imageKey:s},{idempotencyKey:n})})}a(Be,"Se");function Je(e){let t={width:e.width,height:e.height};for(let i of Xe)e[i]!==void 0&&(t[i]=e[i]);return t}a(Je,"ye");var Xe=["engine","facingMode","mode","formFactor","clipMs","clipFrames","fps","clipRetakes","codec","cameraReadyMs","faceAcquireMs","captureMs","screenRamp","provenance"];function Ze(e){return e===void 0?{}:{attestationChecks:e.checks,...e.challengeMs!==void 0?{attestationChallengeMs:e.challengeMs}:{}}}a(Ze,"ke");function Qe(e){if(e instanceof A)return{kind:"unavailable",reason:"attestation"};if(e instanceof f){if(e.code==="attestation_invalid")return{kind:"unavailable",reason:"attestation"};if(e.code==="inference_unavailable")return{kind:"unavailable",reason:"inference_unavailable"};if(e.code==="mobile_required")return{kind:"unavailable",reason:"mobile_required"};if(je.has(e.code))return{kind:"resync"}}return{kind:"unavailable",reason:"network"}}a(Qe,"Ce");var ht="form_answers_invalid",S,ft=(S=class extends Error{constructor(t,i){super(`form answers refused (${t.map(n=>`${n.id}: ${n.code}`).join(", ")})`),this.name="FormAnswersError",this.issues=t,this.source=i}},a(S,"U"),S),C,mt=(C=class extends Error{constructor(t,i){super(`invalid ${t} (${i})`),this.name="InvalidInputError",this.field=t,this.kind=i}},a(C,"B"),C),I,yt=(I=class extends Error{constructor(t,i){super(`invalid ${t} (${i})`),this.name="OtpInputError",this.field=t,this.kind=i}},a(I,"$"),I);function F(e){return e?.source==="upload"?null:e?.source==="choice"&&e.sourcePick!=="camera"?"upload_or_phone":"phone"}a(F,"I");function _t(e,t){if(t===void 0||!z(t)||t.requiresMobile!==!0)return null;switch(t.checkType){case"liveness":return"phone";case"face_match":{if(t.reason!==void 0)return"phone";let i=q(e,"portrait_icao");return i?.state==="passed"||i?.state==="review"?null:"phone"}case"doc_ocr":return F(e.documents);case"poa":return F(e.proofOfAddress);case"portrait_icao":{let i=e.portrait;return i?.pendingFix!==void 0||i?.reuse?.pending===!0?null:F(i)}default:return null}}a(_t,"De");function We(e){let t=e?.capture,i=t?.mode;return i==="assisted"||i==="self"||i==="choice"?i:t?.cameraSwitch===!0?"assisted":"self"}a(We,"we");function vt(e){let t=e?.capture?.pick;return We(e)==="choice"&&(t==="self"||t==="assisted")?t:null}a(vt,"Be");function kt(e,t,i=null){return e==="choice"?t??i??"self":e}a(kt,"$e");var gt={"MR:drivers_license":{normalize:"upper_no_space_or_hyphen",pattern:"^[0-9]{8}$",check:null,registrySources:[],describe:"number must be the 8-digit Mauritanian driver's license number"},"MR:national_id":{normalize:"trim",pattern:"^[0-9]{10}$",check:"mr_nni_mod97",registrySources:["MR.anrpts"],describe:"number must be the 10-digit Mauritanian national ID number with a valid check digit"}};export{f as a,v as b,tt as c,it as d,nt as e,ot as f,ct as g,dt as h,ke as i,y as j,H as k,ge as l,ut as m,z as n,we as o,X as p,q,E as r,x as s,lt as t,Ie as u,W as v,qe as w,Ue as x,ee as y,pt as z,Je as A,ht as B,ft as C,mt as D,yt as E,_t as F,We as G,vt as H,kt as I,gt as J};