12 lines
13 KiB
JavaScript
12 lines
13 KiB
JavaScript
|
|
import{o as xe,r as t,w as he,j as e,L as z,v as J,q as me,X as fe}from"./index-oAPVDf-r.js";import{C as Ae}from"./circle-alert-C1Hs9zwh.js";import{A as Te}from"./index-B-MEeiYV.js";import{S as Ie}from"./shield-BWGzcrms.js";import{C as De}from"./check-CG8zylH4.js";/**
|
||
|
|
* @license lucide-react v0.462.0 - ISC
|
||
|
|
*
|
||
|
|
* This source code is licensed under the ISC license.
|
||
|
|
* See the LICENSE file in the root directory of this source tree.
|
||
|
|
*/const Pe=xe("Flashlight",[["path",{d:"M18 6c0 2-2 2-2 4v10a2 2 0 0 1-2 2h-4a2 2 0 0 1-2-2V10c0-2-2-2-2-4V2h12z",key:"1orkel"}],["line",{x1:"6",x2:"18",y1:"6",y2:"6",key:"1z11jq"}],["line",{x1:"12",x2:"12",y1:"12",y2:"12",key:"1f4yc1"}]]);/**
|
||
|
|
* @license lucide-react v0.462.0 - ISC
|
||
|
|
*
|
||
|
|
* This source code is licensed under the ISC license.
|
||
|
|
* See the LICENSE file in the root directory of this source tree.
|
||
|
|
*/const ze=xe("FlipHorizontal",[["path",{d:"M8 3H5a2 2 0 0 0-2 2v14c0 1.1.9 2 2 2h3",key:"1i73f7"}],["path",{d:"M16 3h3a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-3",key:"saxlbk"}],["path",{d:"M12 20v2",key:"1lh1kg"}],["path",{d:"M12 14v2",key:"8jcxud"}],["path",{d:"M12 8v2",key:"1woqiv"}],["path",{d:"M12 2v2",key:"tus03m"}]]),Ke=({mode:i,docTypeLabel:ge,hint:pe,onPhotoCapture:Q,onCancel:Z,onFrameCapture:ee,isUploading:be=!1})=>{const N=t.useRef(null),L=t.useRef(null),x=t.useRef(null),E=t.useRef(null),F=t.useRef(null),[A,je]=t.useState(i==="selfie"?"user":"environment"),[q,te]=t.useState(!1),[we,se]=t.useState(!1),B=t.useRef(null),[ke,j]=t.useState(!0),[g,H]=t.useState(!1),[T,w]=t.useState(null),[ae,re]=t.useState(!1),[u,W]=t.useState(null),[C,S]=t.useState("searching"),[ve,K]=t.useState(0),[U,ne]=t.useState(!1),I=t.useRef(!1),le=t.useRef(0),D=t.useRef(null),p=t.useRef(null),R=t.useCallback(()=>{x.current&&(x.current.getTracks().forEach(a=>a.stop()),x.current=null)},[]),V=t.useCallback(async a=>{var n,s;x.current&&(x.current.getTracks().forEach(r=>r.stop()),x.current=null),j(!0),H(!1),w(null);try{const r=await navigator.mediaDevices.getUserMedia({video:{facingMode:{ideal:a},width:{ideal:1920},height:{ideal:1080}},audio:!1});x.current=r;const c=r.getVideoTracks();B.current=c[0]??null,se(!!((s=(n=B.current)==null?void 0:n.getCapabilities)!=null&&s.call(n).torch));const l=N.current;if(!l){r.getTracks().forEach(m=>m.stop()),w("Internt fel — kameravyn saknas. Ladda om sidan."),j(!1);return}l.srcObject=r,l.onloadedmetadata=()=>{l.play().then(()=>{H(!0),j(!1)}).catch(m=>{console.error("[SecureCamera] play() failed:",m),w("Kunde inte visa kamerabilden. Prova att ladda om sidan."),j(!1)})}}catch(r){console.error("[SecureCamera] getUserMedia failed:",r);const c=(r==null?void 0:r.name)??"";w(c==="NotAllowedError"||c==="PermissionDeniedError"?"Kameratillåtelse nekades. Tillåt kameraåtkomst i webbläsarens inställningar och försök igen.":c==="NotFoundError"?"Ingen kamera hittades på enheten.":"Kunde inte starta kameran. Kontrollera kameratillståndet och försök igen."),j(!1)}},[]);t.useEffect(()=>{E.current=V},[V]),t.useEffect(()=>{F.current=ce}),t.useEffect(()=>(V(A),()=>{R()}),[]);const ye=t.useCallback(async()=>{var n;const a=B.current;if(a)try{const s=(n=a.getCapabilities)==null?void 0:n.call(a);if(!(s!=null&&s.torch))return;const r=!q;await a.applyConstraints({advanced:[{torch:r}]}),te(r)}catch(s){console.error("[SecureCamera] torch toggle failed",s),he.error("Ficklampan kunde inte slås på")}},[q]),Ne=t.useCallback(async()=>{var n;const a=A==="environment"?"user":"environment";je(a),W(null),H(!1),j(!0),te(!1),se(!1),await((n=E.current)==null?void 0:n.call(E,a))},[A]),X=t.useCallback((a,n,s,r,c)=>{const l=document.createElement("canvas");return l.width=Math.round(r),l.height=Math.round(c),l.getContext("2d").drawImage(a,n,s,r,c,0,0,l.width,l.height),l},[]),_=t.useRef(!1),ce=t.useCallback(async a=>{const n=a??N.current;if(!(!n||!L.current||_.current)){_.current=!0,re(!0);try{const s=L.current,r=s.getContext("2d");if(!r)throw new Error("Canvas context saknas");const c=n.videoWidth||1280,l=n.videoHeight||720,m=1400,b=c>m?m/c:1;s.width=Math.round(c*b),s.height=Math.round(l*b),r.drawImage(n,0,0,s.width,s.height);let k;if(i==="document"){const d=s.width*.86,h=d*(2/3),f=(s.width-d)/2,v=(s.height-h)/2;k=X(s,f,v,d,h)}else{const d=s.width*.7,h=d*(4/3),f=(s.width-d)/2,v=s.height*.45-h/2;k=X(s,f,v,d,h)}const O=await new Promise((d,h)=>{k.toBlob(f=>f?d(f):h(new Error("Blob misslyckades")),"image/jpeg",.92)}),$=k.toDataURL("image/jpeg",.92);W({blob:O,dataUrl:$,timestamp:Date.now(),deviceInfo:{userAgent:navigator.userAgent,platform:navigator.platform,timestamp:Date.now()}})}catch(s){console.error("[SecureCamera] capture failed:",s),he.error("Kunde inte ta fotot — försök igen")}finally{_.current=!1,re(!1)}}},[i,X]);t.useEffect(()=>{if(i!=="selfie"||!g||u)return;I.current=!1;let a=0;S("searching"),ne(!1),D.current=setTimeout(()=>{ne(!0)},12e3);const n=document.createElement("canvas");n.width=160,n.height=120;const s=n.getContext("2d"),r=60
|