@sekyro/elements 0.1.0-rc.17 → 0.1.0-rc.19

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 (90) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/cdn/chunks/{capture-session-doc-MGDYUASI-LYQ23KS6.js → capture-session-doc-DFLSX6BB-3ULMTYJH.js} +1 -1
  3. package/dist/cdn/chunks/chunk-3PBU4237.js +33 -0
  4. package/dist/cdn/chunks/chunk-4VHWJD57.js +1 -0
  5. package/dist/cdn/chunks/{chunk-SI6GIBVC.js → chunk-6H2SLOEK.js} +1 -1
  6. package/dist/cdn/chunks/{chunk-NPTVQXUW.js → chunk-AC45ZP53.js} +1 -1
  7. package/dist/cdn/chunks/{chunk-2MJOW3FG.js → chunk-CGOCWIXM.js} +1 -1
  8. package/dist/cdn/chunks/chunk-D7YINY2U.js +3 -0
  9. package/dist/cdn/chunks/{chunk-E5JQU363.js → chunk-EPMGZQHF.js} +1 -1
  10. package/dist/cdn/chunks/{chunk-BR5RW4XZ.js → chunk-EXMVZUHU.js} +1 -1
  11. package/dist/cdn/chunks/{chunk-3S7YMUPU.js → chunk-F4Q2Q4OC.js} +1 -1
  12. package/dist/cdn/chunks/{chunk-RPMVDYDV.js → chunk-HXD7VO3F.js} +1 -1
  13. package/dist/cdn/chunks/{chunk-IGZCP7OY.js → chunk-IWZRAEUN.js} +1 -1
  14. package/dist/cdn/chunks/{chunk-6TIQ2463.js → chunk-IXRKOBFA.js} +1 -1
  15. package/dist/cdn/chunks/{chunk-Z5QOJL3W.js → chunk-JR4AQLJ2.js} +1 -1
  16. package/dist/cdn/chunks/{chunk-3DAULGZ2.js → chunk-K2JDLIFO.js} +1 -1
  17. package/dist/cdn/chunks/{chunk-3APQX7OW.js → chunk-L66SWMJ5.js} +1 -1
  18. package/dist/cdn/chunks/{chunk-6L4TYBV7.js → chunk-LUO3AZFS.js} +1 -1
  19. package/dist/cdn/chunks/{chunk-QR7XWTXK.js → chunk-PAU2BFT7.js} +1 -1
  20. package/dist/cdn/chunks/{chunk-Z6KNLRUW.js → chunk-PLWGAXYM.js} +1 -1
  21. package/dist/cdn/chunks/{chunk-DHMC5D6M.js → chunk-RTCZJKYC.js} +1 -1
  22. package/dist/cdn/chunks/{chunk-E5YZMFCZ.js → chunk-WANVL25H.js} +1 -1
  23. package/dist/cdn/chunks/{chunk-DCTDTKG7.js → chunk-WCEIXBIS.js} +1 -1
  24. package/dist/cdn/chunks/{chunk-HM65LKWB.js → chunk-YULJCSQ3.js} +1 -1
  25. package/dist/cdn/chunks/{chunk-PRMQUJTM.js → chunk-ZWP6MDIC.js} +1 -1
  26. package/dist/cdn/chunks/{create-document-capture-KISF6XD3-R6PFAJU6.js → create-document-capture-4ZOSBL3Y-KLZDMWOQ.js} +1 -1
  27. package/dist/cdn/chunks/{detector-scanic-JC25DD3A-YZ3NPKMQ.js → detector-scanic-P2RTEQUV-A5WTP2Q7.js} +1 -1
  28. package/dist/cdn/chunks/document-capture-view-25EASYV7-EUEYS55L.js +1 -0
  29. package/dist/cdn/chunks/{eid-view-ZM7QAEME-DIL3UVBB.js → eid-view-6DXZ5ELB-ZX35JGDS.js} +1 -1
  30. package/dist/cdn/chunks/{email-otp-view-EYS26ZZM-UNGUBHFI.js → email-otp-view-3UJPJOQ6-MIOPWSME.js} +1 -1
  31. package/dist/cdn/chunks/flow-views-ZVDXJZWH-C5ZVKCB6.js +1 -0
  32. package/dist/cdn/chunks/{form-view-Y5KA6R5T-KUDCNJNS.js → form-view-4NKEHYNF-I25LMP47.js} +1 -1
  33. package/dist/cdn/chunks/overlay-de-64ABPD3N-KIBBQI36.js +1 -0
  34. package/dist/cdn/chunks/overlay-es-VIMXYK2Q-KTLONTNF.js +1 -0
  35. package/dist/cdn/chunks/overlay-pt-3IBDZBAW-DQTJHDLG.js +1 -0
  36. package/dist/cdn/chunks/plan-runner-3BLEJWHF-3K3RBXJU.js +1 -0
  37. package/dist/cdn/chunks/{portrait-capture-view-E5LKQQ5Y-3HNPCMBJ.js → portrait-capture-view-QDUJ36UH-GRTZTYTJ.js} +1 -1
  38. package/dist/cdn/chunks/{portrait-review-view-NJHH2E4W-B3RFT2PG.js → portrait-review-view-LW5DBF3L-K7WAOPAG.js} +1 -1
  39. package/dist/cdn/chunks/{proof-of-address-view-LS3JZUTD-MDTXER25.js → proof-of-address-view-E6WJTTIV-7ISFWEEZ.js} +1 -1
  40. package/dist/cdn/define.js +1 -1
  41. package/dist/cdn/index.js +1 -1
  42. package/dist/{chunk-AJHRPKD4.js → chunk-57MVUXQ6.js} +1 -1
  43. package/dist/{chunk-MWTOWGEI.js → chunk-5QJOJLKJ.js} +1 -1
  44. package/dist/{chunk-2WYXQYNY.js → chunk-6FAODASF.js} +1 -1
  45. package/dist/{chunk-D3TZZ4SI.js → chunk-7XJHQ3NM.js} +1 -1
  46. package/dist/{chunk-WLCS5VAA.js → chunk-BRS7YLGB.js} +1 -1
  47. package/dist/{chunk-5NSMKCTW.js → chunk-CY66YE6F.js} +1 -1
  48. package/dist/{chunk-VJZANYM3.js → chunk-KYDIB6KR.js} +1 -1
  49. package/dist/chunk-M7HNWDQD.js +1 -0
  50. package/dist/{chunk-6NNMOFMF.js → chunk-PKK72TVJ.js} +1 -1
  51. package/dist/{chunk-ICJ544T4.js → chunk-QNK7OBIW.js} +1 -1
  52. package/dist/chunk-RPA5QQVH.js +33 -0
  53. package/dist/{chunk-734Y6RUV.js → chunk-SVGBNMXK.js} +1 -1
  54. package/dist/{chunk-YVGOUZ7T.js → chunk-VBJ4CJHE.js} +1 -1
  55. package/dist/{chunk-ZUFN5VIE.js → chunk-XQPY6G2B.js} +1 -1
  56. package/dist/define.cjs +5 -5
  57. package/dist/define.js +1 -1
  58. package/dist/document-capture-view-25EASYV7-MOFQVGV6.js +1 -0
  59. package/dist/{eid-view-ZM7QAEME-7FRC3TV6.js → eid-view-6DXZ5ELB-XDQVFDXS.js} +1 -1
  60. package/dist/{email-otp-view-EYS26ZZM-EESWRHKM.js → email-otp-view-3UJPJOQ6-5PQM7LNW.js} +1 -1
  61. package/dist/flow-views-ZVDXJZWH-LOGNCRIA.js +1 -0
  62. package/dist/{form-view-Y5KA6R5T-DOZFYGBK.js → form-view-4NKEHYNF-VFMN6QFW.js} +1 -1
  63. package/dist/index.cjs +5 -5
  64. package/dist/index.d.cts +5 -0
  65. package/dist/index.d.ts +5 -0
  66. package/dist/index.js +1 -1
  67. package/dist/overlay-de-64ABPD3N-ARJE63WR.js +1 -0
  68. package/dist/overlay-es-VIMXYK2Q-JRHIX3OT.js +1 -0
  69. package/dist/overlay-pt-3IBDZBAW-JXQE6BVY.js +1 -0
  70. package/dist/{portrait-capture-view-E5LKQQ5Y-E3BRULLL.js → portrait-capture-view-QDUJ36UH-QZR4O3YW.js} +1 -1
  71. package/dist/{portrait-review-view-NJHH2E4W-CKMVD7ME.js → portrait-review-view-LW5DBF3L-QVERJXKH.js} +1 -1
  72. package/dist/{proof-of-address-view-LS3JZUTD-ZQ4BDFNP.js → proof-of-address-view-E6WJTTIV-4SHZIQ3O.js} +1 -1
  73. package/package.json +2 -2
  74. package/sbom.cdx.json +4 -4
  75. package/dist/cdn/chunks/chunk-4RGDPCRE.js +0 -33
  76. package/dist/cdn/chunks/chunk-BDRBGJA3.js +0 -3
  77. package/dist/cdn/chunks/chunk-Q7ACZDU4.js +0 -1
  78. package/dist/cdn/chunks/document-capture-view-7ZSM7YTT-UHYBVOQI.js +0 -1
  79. package/dist/cdn/chunks/flow-views-7SAYQQ62-2TENAJ6C.js +0 -1
  80. package/dist/cdn/chunks/overlay-de-4OISTBDL-WWT74VG7.js +0 -1
  81. package/dist/cdn/chunks/overlay-es-YO5UCAO2-U3OAELIS.js +0 -1
  82. package/dist/cdn/chunks/overlay-pt-E7PSFLLQ-ZPN4CLS4.js +0 -1
  83. package/dist/cdn/chunks/plan-runner-NWK4LZFI-CDXUYVEW.js +0 -1
  84. package/dist/chunk-2EMXU2MG.js +0 -33
  85. package/dist/chunk-XI37ATRU.js +0 -1
  86. package/dist/document-capture-view-7ZSM7YTT-GLHWVI3B.js +0 -1
  87. package/dist/flow-views-7SAYQQ62-3NIWXTDB.js +0 -1
  88. package/dist/overlay-de-4OISTBDL-TH46LT3S.js +0 -1
  89. package/dist/overlay-es-YO5UCAO2-NBICE576.js +0 -1
  90. package/dist/overlay-pt-E7PSFLLQ-NCA5NABT.js +0 -1
@@ -1 +1 @@
1
- import{a as tt,b as te,c as ee,d as dt,e as ie}from"./chunk-IGZCP7OY.js";import{c as Kt,d as Yt,g as Vt}from"./chunk-2TFK736S.js";import{b as Jt,c as Zt}from"./chunk-3S7YMUPU.js";import{b as $t}from"./chunk-L22GFJQV.js";import{d as Nt,e as Qt,f as Xt}from"./chunk-RPMVDYDV.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){if(e==="LOW")return null;let h=a===void 0?null:Be(a.fill),o=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-JC25DD3A-YZ3NPKMQ.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-JC25DD3A-YZ3NPKMQ.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"||this.deviceClass==="LOW"?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-IWZRAEUN.js";import{c as Kt,d as Yt,g as Vt}from"./chunk-2TFK736S.js";import{b as Jt,c as Zt}from"./chunk-F4Q2Q4OC.js";import{b as $t}from"./chunk-L22GFJQV.js";import{d as Nt,e as Qt,f as Xt}from"./chunk-HXD7VO3F.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){if(e==="LOW")return null;let h=a===void 0?null:Be(a.fill),o=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-P2RTEQUV-A5WTP2Q7.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-P2RTEQUV-A5WTP2Q7.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"||this.deviceClass==="LOW"?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{b,c as t,v as s,w as i,y as l}from"./chunk-Z6KNLRUW.js";import{a as r}from"./chunk-5QL6W6FW.js";import{a as o,c as k}from"./chunk-4FHWXBOB.js";var a=k(b(),1);function x({title:n,lead:d,cameraLabel:c,uploadLabel:m,notice:p,testId:e,onCamera:h,onUpload:u,onPhone:f=!1}){return(0,a.jsxs)("section",{className:"sekyro-step","data-testid":e,children:[(0,a.jsx)(i,{title:n,lead:d}),p,(0,a.jsxs)(l,{children:[(0,a.jsxs)(t,{full:!0,onClick:h,"data-testid":`${e}-camera`,children:[(0,a.jsx)(s,{name:f?"smartphone":"camera"}),c]}),(0,a.jsx)(t,{full:!0,kind:"ghost",onClick:u,"data-testid":`${e}-upload`,children:m})]})]})}o(x,"k");r(x,"PhotoSourceView");export{x as a};
1
+ import{b,c as t,v as s,w as i,y as l}from"./chunk-PLWGAXYM.js";import{a as r}from"./chunk-5QL6W6FW.js";import{a as o,c as k}from"./chunk-4FHWXBOB.js";var a=k(b(),1);function x({title:n,lead:d,cameraLabel:c,uploadLabel:m,notice:p,testId:e,onCamera:h,onUpload:u,onPhone:f=!1}){return(0,a.jsxs)("section",{className:"sekyro-step","data-testid":e,children:[(0,a.jsx)(i,{title:n,lead:d}),p,(0,a.jsxs)(l,{children:[(0,a.jsxs)(t,{full:!0,onClick:h,"data-testid":`${e}-camera`,children:[(0,a.jsx)(s,{name:f?"smartphone":"camera"}),c]}),(0,a.jsx)(t,{full:!0,kind:"ghost",onClick:u,"data-testid":`${e}-upload`,children:m})]})]})}o(x,"k");r(x,"PhotoSourceView");export{x as a};