@swan-admin/swan-web-component 1.0.92 → 1.0.94

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 (39) hide show
  1. package/dist/{BodyScan-BEFE9I0D.js → BodyScan-97yio9Oh.js} +2 -2
  2. package/dist/{BodyScan-BEFE9I0D.js.map → BodyScan-97yio9Oh.js.map} +1 -1
  3. package/dist/{BodyScan-CQw0C6WC.js → BodyScan-CW2FEtza.js} +2 -2
  4. package/dist/{BodyScan-CQw0C6WC.js.map → BodyScan-CW2FEtza.js.map} +1 -1
  5. package/dist/{FaceScan-DVAAtG8v.js → FaceScan-CD16KBC-.js} +2 -2
  6. package/dist/FaceScan-CD16KBC-.js.map +1 -0
  7. package/dist/{FaceScan-BmbbbsFP.js → FaceScan-CNQpL2rm.js} +2 -2
  8. package/dist/FaceScan-CNQpL2rm.js.map +1 -0
  9. package/dist/{LoadingScreen-vewtx75y.js → LoadingScreen--G_kIDCD.js} +2 -2
  10. package/dist/LoadingScreen--G_kIDCD.js.map +1 -0
  11. package/dist/{LoadingScreen-DCHEgS3u.js → LoadingScreen-bsnFuMYp.js} +2 -2
  12. package/dist/LoadingScreen-bsnFuMYp.js.map +1 -0
  13. package/dist/bodyScan.js +1 -1
  14. package/dist/bodyScan.mjs +1 -1
  15. package/dist/faceScan.js +1 -1
  16. package/dist/faceScan.mjs +1 -1
  17. package/dist/index.js +1 -1
  18. package/dist/index.mjs +1 -1
  19. package/package.json +1 -1
  20. package/dist/BodyScan-CP2sxAs_.js +0 -2
  21. package/dist/BodyScan-CP2sxAs_.js.map +0 -1
  22. package/dist/BodyScan-M3PbHzI8.js +0 -2
  23. package/dist/BodyScan-M3PbHzI8.js.map +0 -1
  24. package/dist/FaceScan-1AZEq6lq.js +0 -2
  25. package/dist/FaceScan-1AZEq6lq.js.map +0 -1
  26. package/dist/FaceScan-BmbbbsFP.js.map +0 -1
  27. package/dist/FaceScan-CiFQac3v.js +0 -2
  28. package/dist/FaceScan-CiFQac3v.js.map +0 -1
  29. package/dist/FaceScan-DVAAtG8v.js.map +0 -1
  30. package/dist/LoadingScreen-BOlJ0UJI.js +0 -2
  31. package/dist/LoadingScreen-BOlJ0UJI.js.map +0 -1
  32. package/dist/LoadingScreen-BYooRTYi.js +0 -2
  33. package/dist/LoadingScreen-BYooRTYi.js.map +0 -1
  34. package/dist/LoadingScreen-DCHEgS3u.js.map +0 -1
  35. package/dist/LoadingScreen-vewtx75y.js.map +0 -1
  36. package/dist/pose-detection.esm-BehJiApJ.js +0 -18
  37. package/dist/pose-detection.esm-BehJiApJ.js.map +0 -1
  38. package/dist/pose-detection.esm-DouwBFG2.js +0 -18
  39. package/dist/pose-detection.esm-DouwBFG2.js.map +0 -1
@@ -1,2 +1,2 @@
1
- import{jsx as e,jsxs as t,Fragment as a}from"react/jsx-runtime";import{useRef as n,useState as o,useMemo as r,useCallback as c,useEffect as i,useContext as s}from"react";import l,{posthog as d}from"posthog-js";import{s as u,v as f,a as g,L as h,b as m,H as p,S as y,m as S,g as b,G as w,d as v,F as x,P as F,u as N,c as _,e as I,f as k,p as M,h as C,i as D,j as T,k as P,l as E}from"./LoadingScreen-DCHEgS3u.js";import{ArrowRight as L}from"lucide-react";import{Drawer as z}from"@mui/material";let $=null,j=!1;function R({faceScanId:e,onValidPose:t,onScanComplete:a,onModelReady:s,onStartRecording:l,shopDomain:h}){const m=n(null),[p,y]=o(0),[S,b]=o(0),[w,v]=o(!1),[x,F]=o(!1),N=n(null),_=n(p),I=n(S),k=n([]),M=n(""),C=n(0),D=n(!1),T=n(0),P="undefined"!=typeof navigator&&(/iPad|iPhone|iPod/.test(navigator.userAgent)||"MacIntel"===navigator.platform&&navigator.maxTouchPoints>1),E=r(()=>["Face front","Turn head fully left","Turn head fully right","Smile facing front"],[]),L=r(()=>function(e,t){let a;return(...n)=>{a&&clearTimeout(a),a=setTimeout(()=>e(...n),t)}}(e=>{d.capture(`${h}/face_scan_pose_detection`,e)},4e3),[h]),z=c((t,a,n,o,r,c)=>{const i=Date.now();if(!(i-T.current<4e3)){T.current=i;try{const i=t[0]||[0,0,0],s=t[2]||[0,0,0],l=t[5]||[0,0,0],d=t[9]||[0,0,0],u=t[10]||[0,0,0],f=t.map(e=>e[2]).filter(e=>e>0),g=f.length>0?f.reduce((e,t)=>e+t,0)/f.length:0,h=a.map(e=>e[2]).filter(e=>e>0),m=h.length>0?h.reduce((e,t)=>e+t,0)/h.length:0,p=Math.abs(s[0]-l[0]),y=i[0]-l[0],S=s[0]-i[0];let b="frontal";1===n?b="left":2===n?b="right":3===n&&(b="frontal_smile");const w={faceScanId:e,stage:n,timestamp:(new Date).toISOString(),data:JSON.stringify({headValid:o,bodyInvalid:r,consecutiveValid:c,avgFaceScore:parseFloat(g.toFixed(3)),avgBodyScore:parseFloat(m.toFixed(3)),faceKeypointsDetected:f.length,bodyKeypointsDetected:h.length,eyeDistance:parseFloat(p.toFixed(2)),noseToRightRatio:parseFloat((y/p).toFixed(3)),noseToLeftRatio:parseFloat((S/p).toFixed(3)),noseScore:parseFloat(i[2].toFixed(3)),leftEyeScore:parseFloat(s[2].toFixed(3)),rightEyeScore:parseFloat(l[2].toFixed(3)),leftMouthScore:parseFloat(d[2].toFixed(3)),rightMouthScore:parseFloat(u[2].toFixed(3)),expectedPosition:b})};L(w)}catch(e){console.warn("Failed to track pose detection:",e)}}},[e,L]),R=()=>{d.capture(`${h}/face_scan_detection_started`,{faceScanId:e,stage:_.current,timestamp:(new Date).toISOString(),stageName:E[_.current]}),setTimeout(()=>{F(!0)},1500)},V=async()=>{if("undefined"!=typeof window)try{console.log("Initializing Face Scan...");const e=await(async()=>{if("undefined"==typeof window)return null;if($)return $;if(j)for(;j;)if(await new Promise(e=>setTimeout(e,100)),$)return $;j=!0;try{const[e,t]=await Promise.all([import("@tensorflow/tfjs"),import("./pose-detection.esm-BehJiApJ.js")]);await e.setBackend("webgl"),await e.ready();const a=await t.createDetector(t.SupportedModels.BlazePose,{runtime:"tfjs",modelType:"full"}),n=document.createElement("canvas");n.width=g.width,n.height=g.height;const o=n.getContext("2d");if(o){o.fillStyle="black",o.fillRect(0,0,n.width,n.height);try{await a.estimatePoses(n)}catch(e){console.warn("Warmup frame failed (non-fatal):",e)}}return $=a,a}catch(e){return console.error("Failed to preload detector:",e),null}finally{j=!1}})();e&&(m.current=e,console.log("Face scan model loaded successfully"),v(!0),s?.())}catch(e){console.error("Error initializing face scan:",e)}};return i(()=>(V(),()=>{(async()=>{try{v(!1)}catch(e){console.error("Error disposing resources:",e)}finally{y(0),b(0),_.current=0,I.current=0,k.current=[]}})()}),[]),i(()=>{_.current=p},[p]),i(()=>{I.current=S},[S]),{faceScanDetector:async(n,o)=>{if(m.current&&n.current&&w&&x&&!(n.current.readyState<2))try{const r=await m.current.estimatePoses(n.current);if(r.length>0){const n=[],c=[];if(r[0].keypoints.forEach((e,t)=>{const a=e.score??0,o=[e.x??-1,e.y??-1,a];t<=10?n.push(o):c.push(o)}),o?.current){const e=o.current.getContext("2d"),{width:t,height:a}=o.current;if(e){e.clearRect(0,0,t,a);const n=Math.min(I.current/2,1),o=.35*a;e.beginPath(),e.strokeStyle="#00ff00",e.lineWidth=6,e.arc(t/2,a/2,o+10,-Math.PI/2,-Math.PI/2+2*n*Math.PI),e.stroke()}}const i=((e,t)=>{if(!t[0]||!t[2]||!t[5]||t[0][2]<.2||t[2][2]<.2||t[5][2]<.2)return!1;const a=.5*(t[10][1]+t[9][1])-.5*(t[5][1]+t[2][1]),n=(.5*(t[10][1]+t[9][1])-t[0][1])/a,o=n>.7||n<.3,r=Math.abs(t[2][1]-t[5][1])<.5*a&&Math.abs(t[9][1]-t[10][1])<.5*a,c=t[2][0]-t[5][0],i=t[0][0]-t[5][0],s=i>.4*c&&i<.6*c,l=i>.85*c,d=t[2][0]-t[0][0]>.85*c;switch(e){case 0:case 3:return!o&&r&&s;case 1:return!o&&r&&l;case 2:return!o&&r&&d;default:return!1}})(_.current,n),s=c.slice(2).filter(e=>e[2]>.7).length<=2;k.current.push(i&&s),k.current.length>10&&k.current.shift();if(k.current.filter(Boolean).length>=2){const e=I.current+1;b(e)}else b(Math.max(0,I.current-1));if(I.current>=2){t?.();const n=_.current+1;b(0),k.current=[],y(n),F(!1),(async()=>{if(await u.playAudio(`${f}face-scan-vos/Sound-effect.mp3`),d.capture(`${h}/face_scan_detection_stage_completed`,{faceScanId:e,completedStage:_.current,nextStage:n,timestamp:(new Date).toISOString(),totalStages:4,stageName:E[_.current]}),1===n&&l&&l(),n>=4)a?.();else{let e=null;switch(n){case 1:e="Left.mp3";break;case 2:e="Right.mp3";break;case 3:e="Smile.mp3"}e&&await u.playAudio(`${f}face-scan-vos/${e}`),R()}})()}z(n,c,_.current,i,s,I.current)}}catch(e){console.error("Pose detection error:",e)}},scanStage:p,setScanStage:y,consecutiveValid:S,isModelLoaded:w,resetScan:()=>{d.capture(`${h}/face_scan_reset`,{faceScanId:e,stage:_.current,timestamp:(new Date).toISOString(),stageName:E[_.current],consecutiveValid:I.current}),y(0),b(0),F(!1),_.current=0,I.current=0,k.current=[],M.current="",C.current=0,D.current=!1,N.current&&(speechSynthesis.cancel(),N.current=null)},enableVoiceCommands:()=>{if(D.current=!0,"undefined"!=typeof window&&P&&"speechSynthesis"in window){const e=new SpeechSynthesisUtterance("");e.volume=0,speechSynthesis.speak(e)}},startScanSequence:R,isScanningActive:x}}function V({resetScanState:a,loading:n,config:o}){const{translate:r,preferredLanguage:c}=s(h)||{};return console.log(c,"preferredLanguage"),console.log(r?.(m.scanFailed),"translate"),e("div",{className:"fixed top-[0] left-[0] z-[999] flex justify-center items-center w-full h-full",style:{background:o?.style?.base?.backgroundColor},children:t("div",{className:"flex flex-col w-full items-center p-[1rem] rounded-lg ",children:[e(p,{noTitle:!0,resolvedConfig:o}),t("div",{className:"flex flex-col items-center w-full",children:[e("h2",{className:"text-xl font-semibold text-gray-800 ",style:{fontFamily:o?.style?.heading?.headingFontFamily||"SeriouslyNostalgic Fn",fontSize:o?.style?.heading?.headingFontSize||"32px",color:o?.style?.heading?.headingColor||"#000",fontWeight:o?.style?.heading?.headingFontWeight||"normal"},children:r?.(m.scanFailed)}),e("p",{className:"mb-[1.5rem]",style:{fontFamily:o?.style?.subheading?.subheadingFontFamily||"'Inter', sans-serif",fontSize:o?.style?.subheading?.subheadingFontSize||"14px",color:o?.style?.subheading?.subheadingColor||"#4b5563",fontWeight:o?.style?.subheading?.subheadingFontWeight||"normal"},children:r?.(m.clickToResetScan)}),e(y,{disabled:n,className:"w-full h-[45px] shadow-[0px_1px_2px_0px_#00000040] text-[16px]",buttonText:r?.(m.resetScan),postfixIcon:e(L,{}),buttonFunc:()=>a?.(),resolvedConfig:o})]})]})})}function O({stage:a,videoLoading:n,setVideoLoading:o,videoError:r,setVideoError:c,gender:i,config:l,btnConfig:d}){const{translate:u}=s(h)||{};return-1===a?t("div",{className:"text-center p-[16px] w-full h-full",style:{background:l?.style?.base?.backgroundColor},children:[t("div",{className:"w-full",children:[e(p,{noTitle:!0,resolvedConfig:l}),e("h2",{style:{fontFamily:l?.style?.heading?.headingFontFamily||"SeriouslyNostalgic Fn",fontSize:l?.style?.heading?.headingFontSize||"32px",color:l?.style?.heading?.headingColor||"#000",fontWeight:l?.style?.heading?.headingFontWeight||"normal"},children:u?.(m.faceVisible)}),n&&e("div",{className:"mb-4 flex items-center justify-center",style:{fontFamily:l?.style?.subheading?.subheadingFontFamily||"'Inter', sans-serif",fontSize:l?.style?.subheading?.subheadingFontSize||"14px",color:l?.style?.subheading?.subheadingColor||"#4b5563",fontWeight:l?.style?.subheading?.subheadingFontWeight||"normal"},children:u?.(m.loadingVideo)}),r&&e("div",{className:"mb-4 text-red-600",style:{fontFamily:l?.style?.subheading?.subheadingFontFamily||"'Inter', sans-serif",fontSize:l?.style?.subheading?.subheadingFontSize||"14px",color:"#ff0000",fontWeight:l?.style?.subheading?.subheadingFontWeight||"normal"},children:u?.(m.videoLoadFailed)}),!r&&e("div",{className:" w-[100px] mx-auto",children:e("video",{src:i===w.Male?S:b,autoPlay:!0,loop:!0,controls:!1,muted:!0,playsInline:!0,className:"h-full w-full object-contain border-none",onCanPlay:()=>o(!1),onLoadStart:()=>o(!0),onError:()=>c(!0),"aria-label":"Instructional video: Please remove your glasses before starting the scan."})})]}),e("div",{className:"flex justify-center w-full p-[1rem]",children:e(y,{disabled:d.isDisabled,className:"!w-[60px] !h-[35px] !py-0 !px-0",buttonText:u?.(d.label),postfixIcon:d?.icon,buttonFunc:d.onClick,resolvedConfig:l})})]}):e("div",{className:"text-center p-[16px] w-full h-full",style:{background:l?.style?.base?.backgroundColor},children:t("div",{className:"w-full",children:[e(p,{noTitle:!0,resolvedConfig:l}),e("h3",{className:"mb-[0.5rem]",style:{fontFamily:l?.style?.heading?.headingFontFamily||"SeriouslyNostalgic Fn",fontSize:l?.style?.heading?.headingFontSize||"32px",color:l?.style?.heading?.headingColor||"#000",fontWeight:l?.style?.heading?.headingFontWeight||"normal"},children:u?.(v[a])}),t("div",{className:"max-w-[400px] justify-center gap-1 mx-auto flex items-center",children:[e("div",{className:` w-[120px] overflow-hidden ${0===a?"opacity-100":"opacity-0 hidden"} `,children:e("video",{className:"h-full w-full object-contain border-none",muted:!0,loop:!0,autoPlay:!0,playsInline:!0,children:e("source",{src:i===w.Male?x.male.forward:x.female.forward,type:"video/mp4"})})}),e("div",{className:` w-[120px] overflow-hidden ${1===a?"opacity-100":"opacity-0 hidden"} `,children:e("video",{className:"h-full w-full object-contain border-none",muted:!0,loop:!0,autoPlay:!0,playsInline:!0,children:e("source",{src:i===w.Male?x.male.left:x.female.left,type:"video/mp4"})})}),e("div",{className:` w-[120px] overflow-hidden ${2===a?"opacity-100":"opacity-0 hidden"} `,children:e("video",{className:"h-full w-full object-contain border-none",muted:!0,loop:!0,autoPlay:!0,playsInline:!0,children:e("source",{src:i===w.Male?x.male.right:x.female.right,type:"video/mp4"})})}),e("div",{className:` w-[120px] overflow-hidden ${3===a?"opacity-100":"opacity-0 hidden"} `,children:e("video",{className:"h-full w-full object-contain border-none",muted:!0,loop:!0,autoPlay:!0,playsInline:!0,children:e("source",{src:i===w.Male?x.male.smile:x.female.smile,type:"video/mp4"})})})]})]})})}const W=({webcamRef:n,canvasRef:o})=>{const{isError:r,isSuccess:c,showLoader:l,hasError:d,resetScanState:u,showGuideCard:f,scanStage:m,videoLoading:p,setVideoLoading:y,videoError:S,setVideoError:b,gender:w,getButtonText:v,isScanning:x,startScan:I,isModelLoaded:k,config:M}=s(F),C=N(M),{setPreferredLanguage:D}=s(h)||{};return i(()=>{D?.(C?.language)},[C]),r?e(V,{config:C}):c?e("div",{className:"fixed z-[9] w-full h-full",style:{background:C?.style?.base?.backgroundColor},children:e(_,{url:C?.loader,loaderType:"black"})}):t(a,{children:[e("audio",{id:"audioElement",crossOrigin:"anonymous",preload:"auto",style:{position:"absolute",zIndex:-99999},src:void 0}),!l&&d&&e(V,{loading:l,resetScanState:u,config:C}),e("div",{className:"h-full flex-col relative w-full flex justify-center items-center text-center rounded-t-[20px]",style:{background:C?.style?.base?.backgroundColor},children:e("div",{className:"flex-1 w-full max-w-md overflow-hidden",children:t("div",{className:"w-full h-full",children:[e("video",{ref:n,autoPlay:!0,playsInline:!0,muted:!0,width:g.width,height:g.height,className:"w-full h-full object-cover fixed left-0 top-0 z-0",style:{transform:"scaleX(-1)"}}),e("canvas",{ref:o,width:g.width,height:g.height,style:{transform:"scaleX(-1)",opacity:"0"}})]})})}),!l&&d&&e(V,{loading:l,resetScanState:u,config:C}),f&&!d&&!l&&e(z,{open:!0,className:"face-scan-small camera-draw",anchor:"bottom",onClose:(e,t)=>{},hideBackdrop:!0,children:e(O,{stage:m,videoLoading:p,setVideoLoading:y,videoError:S,setVideoError:b,gender:w,config:C,btnConfig:{label:v(),onClick:x?u:I,isDisabled:l||!k,icon:e(x?L:a,{})}})})]})},B=({userDetails:t,onScanSuccess:a,onScanError:r,onRetry:s,config:d,isError:h,isSuccess:p})=>{const y=n(null),S=n(null),b=n(null),w=n([]),v=n(null),[x,N]=o(!1),[_,L]=o(!1),[z,$]=o(!1),[j,V]=o(!0),[O,B]=o(!1),[U,A]=o(!1),[J,q]=o(!1),[G,K]=o(I()),{email:H,gender:X,deviceFocalLength:Q,shopDomain:Y,callbackUrl:Z}=t,[ee,te]=o([]),ae=c(()=>{console.log("Stopping recording..."),b.current&&"recording"===b.current.state&&b.current.stop(),b.current=null},[]),ne=async()=>{if(N(!0),console.log("upload final video"),w.current){if(0===w.current.length)return console.error("No video data recorded"),q(!0),void N(!1);const e=new File(w.current,`${G}.webm`,{type:"video/webm"}),t=e.size,a=(t/1048576).toFixed(2),n=Math.round(t/1e4),o={video_size_mb:parseFloat(a),video_size_bytes:t,blob_count:w.current.length,estimated_duration_seconds:n},r=[{gender:X},{face_scan_id:G},{focal_length:`${Q}`},{customer_store_url:Y},{scan_type:"face_scan"},{callback_url:Z}];T({eventName:`${Y}/face_scan_meta_data`,faceScanId:G,email:H,data:JSON.stringify({metaData:r,videoData:o})});const c=Date.now();T({eventName:`${Y}/face_scan_upload_start`,faceScanId:G,email:H,startTime:c});try{const t=await P.fileUpload.faceScanFileUploader({file:e,objectKey:G,email:H,arrayMetaData:r,contentType:e.type}),a=Date.now();T({eventName:`${Y}/face_scan_upload_complete`,faceScanId:G,email:H,completionTime:a,uploadDuration:a-c}),console.log("✅ Upload successful",t),P.measurement.handlFaceScaneSocket({faceScanId:G,onOpen:()=>{E({eventName:`${Y}/webSocket`,faceScanID:G,connection:"open",type:"faceScan_recommendation",email:H}),console.log("websocket connect open")},onError:e=>{E({eventName:`${Y}/webSocket`,faceScanID:G,connection:"error",type:"faceScan_recommendation",email:H}),ge(e)},onSuccess:e=>{E({eventName:`${Y}/webSocket`,faceScanID:G,connection:"success",type:"faceScan_recommendation",email:H}),he(e)},onClose:()=>{console.log("websocket connect close"),E({eventName:`${Y}/webSocket`,faceScanID:G,connection:"close",type:"faceScan_recommendation",email:H})}})}catch(e){ge(e)}}},oe=c(()=>{console.log("Starting recording for stages 1-3...");const e=y.current?.srcObject;if(!e)return;const t=e.getVideoTracks()[0].getSettings(),{width:a=g.width,height:n=g.height}=t,o=document.createElement("canvas"),r=o.getContext("2d");a>n?(o.width=n,o.height=a):(o.width=a,o.height=n);const c=document.createElement("video");c.srcObject=e,c.muted=!0,c.playsInline=!0,c.play();const i=()=>{a>n?(r?.save(),r?.translate(o.width,0),r?.rotate(Math.PI/2),r?.drawImage(c,0,0,n,a),r?.restore()):r?.drawImage(c,0,0,a,n),requestAnimationFrame(i)};i();const s=o.captureStream(30),l=ee.length>0?{mimeType:ee[0]}:{};let d;try{d=new MediaRecorder(s,l)}catch(e){return console.error("MediaRecorder init failed:",e),q(!0),void N(!1)}w.current=[],d.ondataavailable=e=>{e?.data&&e.data.size>0&&w.current&&w.current.push(e.data)},d.onstop=()=>{console.log("Recording stopped, total blobs:",w?.current?.length),ne()},d.start(100),b.current=d,console.log("Recording started successfully (portrait normalized)")},[ee,ne]),{faceScanDetector:re,scanStage:ce,setScanStage:ie,resetScan:se,isModelLoaded:le,startScanSequence:de}=R({faceScanId:G,shopDomain:Y,onScanComplete:()=>{ae()},onModelReady:()=>{L(!0)},onStartRecording:()=>{console.log("Stage 0 completed - starting recording for stages 1-3"),oe()}}),ue=c(()=>{le&&(ie(0),u.playAudio(`${f}face-scan-vos/Face-forward.mp3`),setTimeout(()=>{$(!0),setTimeout(()=>{de()},200)},200))},[ie,$,de,le]),fe=c(()=>{$(!1),V(!0),ae(),se(),s?.(),w.current=[],b.current&&(b.current=null),q(!1),ie(-1),K(I()),y.current&&v.current&&(y.current.srcObject=v.current,console.log("Camera stream restored after reset"))},[ie,$,V,ae,se,K]),ge=e=>{console.log(e,"ws error"),r?.(e),q(!0),N(!1),V(!1),T({eventName:`${Y}/faceScan`,faceScanId:G,status:"failed",email:H,data:JSON.stringify(e)})},he=e=>{console.log(e,"ws success"),e&&"intermediate"===e?.resultType&&T({eventName:`${Y}/faceScan_success/intermediate`,faceScanId:G,status:"success",email:H,data:JSON.stringify(e)}),a?.(e)};i(()=>{if(!h&&!p)return navigator.mediaDevices.getUserMedia&&navigator.mediaDevices.getUserMedia({video:g}).then(e=>{v.current=e,y.current&&(y.current.srcObject=e)}).catch(e=>console.error("Error accessing webcam:",e)),()=>{v.current&&v.current.getTracks().forEach(e=>e.stop())}},[h,p]),i(()=>{if(!_||!z)return;const e=setInterval(()=>{re(y,S)},500);return()=>clearInterval(e)},[re,_,z]);return console.log("Model ready:",_,"Has error:",J,"Is scanning:",z,"showLoader",x),i(()=>{if("undefined"!=typeof MediaRecorder){const e=k.filter(e=>MediaRecorder.isTypeSupported(e));te(e)}},[]),i(()=>{ie(-1)},[h,p]),i(()=>{l.init(M,{api_host:C}),l.capture("$pageview")},[]),e(D,{children:e(F.Provider,{value:{isError:h,isSuccess:p,showLoader:x,hasError:J,resetScanState:fe,showGuideCard:j,scanStage:ce,videoLoading:O,setVideoLoading:B,videoError:U,setVideoError:A,gender:X,getButtonText:()=>z?m.reset:le?m.start:m.loading,isScanning:z,startScan:ue,isModelLoaded:le,config:d},children:e(W,{webcamRef:y,canvasRef:S})})})};export{B as F};
2
- //# sourceMappingURL=FaceScan-DVAAtG8v.js.map
1
+ import{jsx as e,jsxs as t,Fragment as a}from"react/jsx-runtime";import{useRef as n,useState as o,useMemo as r,useCallback as c,useEffect as i,useContext as s}from"react";import l,{posthog as d}from"posthog-js";import{s as u,v as f,a as g,L as h,b as m,H as p,S as y,m as S,g as b,G as w,d as v,F as x,P as F,u as N,c as _,e as I,f as k,p as M,h as C,i as T,j as D,k as P,l as E}from"./LoadingScreen-bsnFuMYp.js";import{ArrowRight as z}from"lucide-react";import{Drawer as L}from"@mui/material";let $=null,j=!1;function R({faceScanId:e,onValidPose:t,onScanComplete:a,onModelReady:s,onStartRecording:l,shopDomain:h}){const m=n(null),[p,y]=o(0),[S,b]=o(0),[w,v]=o(!1),[x,F]=o(!1),N=n(null),_=n(p),I=n(S),k=n([]),M=n(""),C=n(0),T=n(!1),D=n(0),P="undefined"!=typeof navigator&&(/iPad|iPhone|iPod/.test(navigator.userAgent)||"MacIntel"===navigator.platform&&navigator.maxTouchPoints>1),E=r(()=>["Face front","Turn head fully left","Turn head fully right","Smile facing front"],[]),z=r(()=>function(e,t){let a;return(...n)=>{a&&clearTimeout(a),a=setTimeout(()=>e(...n),t)}}(e=>{d.capture(`${h}/face_scan_pose_detection`,e)},4e3),[h]),L=c((t,a,n,o,r,c)=>{const i=Date.now();if(!(i-D.current<4e3)){D.current=i;try{const i=t[0]||[0,0,0],s=t[2]||[0,0,0],l=t[5]||[0,0,0],d=t[9]||[0,0,0],u=t[10]||[0,0,0],f=t.map(e=>e[2]).filter(e=>e>0),g=f.length>0?f.reduce((e,t)=>e+t,0)/f.length:0,h=a.map(e=>e[2]).filter(e=>e>0),m=h.length>0?h.reduce((e,t)=>e+t,0)/h.length:0,p=Math.abs(s[0]-l[0]),y=i[0]-l[0],S=s[0]-i[0];let b="frontal";1===n?b="left":2===n?b="right":3===n&&(b="frontal_smile");const w={faceScanId:e,stage:n,timestamp:(new Date).toISOString(),data:JSON.stringify({headValid:o,bodyInvalid:r,consecutiveValid:c,avgFaceScore:parseFloat(g.toFixed(3)),avgBodyScore:parseFloat(m.toFixed(3)),faceKeypointsDetected:f.length,bodyKeypointsDetected:h.length,eyeDistance:parseFloat(p.toFixed(2)),noseToRightRatio:parseFloat((y/p).toFixed(3)),noseToLeftRatio:parseFloat((S/p).toFixed(3)),noseScore:parseFloat(i[2].toFixed(3)),leftEyeScore:parseFloat(s[2].toFixed(3)),rightEyeScore:parseFloat(l[2].toFixed(3)),leftMouthScore:parseFloat(d[2].toFixed(3)),rightMouthScore:parseFloat(u[2].toFixed(3)),expectedPosition:b})};z(w)}catch(e){console.warn("Failed to track pose detection:",e)}}},[e,z]),R=()=>{d.capture(`${h}/face_scan_detection_started`,{faceScanId:e,stage:_.current,timestamp:(new Date).toISOString(),stageName:E[_.current]}),setTimeout(()=>{F(!0)},1500)},V=async()=>{if("undefined"!=typeof window)try{console.log("Initializing Face Scan...");const e=await(async()=>{if("undefined"==typeof window)return null;if($)return $;if(j)for(;j;)if(await new Promise(e=>setTimeout(e,100)),$)return $;j=!0;try{const[e,t]=await Promise.all([import("@tensorflow/tfjs"),import("./pose-detection.esm-CgI8fYpB.js")]);await e.setBackend("webgl"),await e.ready();const a=await t.createDetector(t.SupportedModels.BlazePose,{runtime:"tfjs",modelType:"full"}),n=document.createElement("canvas");n.width=g.width,n.height=g.height;const o=n.getContext("2d");if(o){o.fillStyle="black",o.fillRect(0,0,n.width,n.height);try{await a.estimatePoses(n)}catch(e){console.warn("Warmup frame failed (non-fatal):",e)}}return $=a,a}catch(e){return console.error("Failed to preload detector:",e),null}finally{j=!1}})();e&&(m.current=e,console.log("Face scan model loaded successfully"),v(!0),s?.())}catch(e){console.error("Error initializing face scan:",e)}};return i(()=>(V(),()=>{(async()=>{try{v(!1)}catch(e){console.error("Error disposing resources:",e)}finally{y(0),b(0),_.current=0,I.current=0,k.current=[]}})()}),[]),i(()=>{_.current=p},[p]),i(()=>{I.current=S},[S]),{faceScanDetector:async(n,o)=>{if(m.current&&n.current&&w&&x&&!(n.current.readyState<2))try{const r=await m.current.estimatePoses(n.current);if(r.length>0){const n=[],c=[];if(r[0].keypoints.forEach((e,t)=>{const a=e.score??0,o=[e.x??-1,e.y??-1,a];t<=10?n.push(o):c.push(o)}),o?.current){const e=o.current.getContext("2d"),{width:t,height:a}=o.current;if(e){e.clearRect(0,0,t,a);const n=Math.min(I.current/2,1),o=.35*a;e.beginPath(),e.strokeStyle="#00ff00",e.lineWidth=6,e.arc(t/2,a/2,o+10,-Math.PI/2,-Math.PI/2+2*n*Math.PI),e.stroke()}}const i=((e,t)=>{if(!t[0]||!t[2]||!t[5]||t[0][2]<.2||t[2][2]<.2||t[5][2]<.2)return!1;const a=.5*(t[10][1]+t[9][1])-.5*(t[5][1]+t[2][1]),n=(.5*(t[10][1]+t[9][1])-t[0][1])/a,o=n>.7||n<.3,r=Math.abs(t[2][1]-t[5][1])<.5*a&&Math.abs(t[9][1]-t[10][1])<.5*a,c=t[2][0]-t[5][0],i=t[0][0]-t[5][0],s=i>.4*c&&i<.6*c,l=i>.85*c,d=t[2][0]-t[0][0]>.85*c;switch(e){case 0:case 3:return!o&&r&&s;case 1:return!o&&r&&l;case 2:return!o&&r&&d;default:return!1}})(_.current,n),s=c.slice(2).filter(e=>e[2]>.7).length<=2;k.current.push(i&&s),k.current.length>10&&k.current.shift();if(k.current.filter(Boolean).length>=2){const e=I.current+1;b(e)}else b(Math.max(0,I.current-1));if(I.current>=2){t?.();const n=_.current+1;b(0),k.current=[],y(n),F(!1),(async()=>{if(await u.playAudio(`${f}face-scan-vos/Sound-effect.mp3`),d.capture(`${h}/face_scan_detection_stage_completed`,{faceScanId:e,completedStage:_.current,nextStage:n,timestamp:(new Date).toISOString(),totalStages:4,stageName:E[_.current]}),1===n&&l&&l(),n>=4)a?.();else{let e=null;switch(n){case 1:e="Left.mp3";break;case 2:e="Right.mp3";break;case 3:e="Smile.mp3"}e&&await u.playAudio(`${f}face-scan-vos/${e}`),R()}})()}L(n,c,_.current,i,s,I.current)}}catch(e){console.error("Pose detection error:",e)}},scanStage:p,setScanStage:y,consecutiveValid:S,isModelLoaded:w,resetScan:()=>{d.capture(`${h}/face_scan_reset`,{faceScanId:e,stage:_.current,timestamp:(new Date).toISOString(),stageName:E[_.current],consecutiveValid:I.current}),y(0),b(0),F(!1),_.current=0,I.current=0,k.current=[],M.current="",C.current=0,T.current=!1,N.current&&(speechSynthesis.cancel(),N.current=null)},enableVoiceCommands:()=>{if(T.current=!0,"undefined"!=typeof window&&P&&"speechSynthesis"in window){const e=new SpeechSynthesisUtterance("");e.volume=0,speechSynthesis.speak(e)}},startScanSequence:R,isScanningActive:x}}function V({resetScanState:a,loading:n,config:o}){const{translate:r,preferredLanguage:c}=s(h)||{};return console.log(c,"preferredLanguage"),console.log(r?.(m.scanFailed),"translate"),e("div",{className:"fixed top-[0] left-[0] z-[999] flex justify-center items-center w-full h-full",style:{background:o?.style?.base?.backgroundColor},children:t("div",{className:"flex flex-col w-full items-center p-[1rem] rounded-lg ",children:[e(p,{noTitle:!0,resolvedConfig:o}),t("div",{className:"flex flex-col items-center w-full",children:[e("h2",{className:"text-xl font-semibold text-gray-800 ",style:{fontFamily:o?.style?.heading?.headingFontFamily||"SeriouslyNostalgic Fn",fontSize:o?.style?.heading?.headingFontSize||"32px",color:o?.style?.heading?.headingColor||"#000",fontWeight:o?.style?.heading?.headingFontWeight||"normal"},children:r?.(m.scanFailed)}),e("p",{className:"mb-[1.5rem]",style:{fontFamily:o?.style?.subheading?.subheadingFontFamily||"'Inter', sans-serif",fontSize:o?.style?.subheading?.subheadingFontSize||"14px",color:o?.style?.subheading?.subheadingColor||"#4b5563",fontWeight:o?.style?.subheading?.subheadingFontWeight||"normal"},children:r?.(m.clickToResetScan)}),e(y,{disabled:n,className:"w-full h-[45px] shadow-[0px_1px_2px_0px_#00000040] text-[16px]",buttonText:r?.(m.resetScan),postfixIcon:e(z,{}),buttonFunc:()=>a?.(),resolvedConfig:o})]})]})})}function O({stage:a,videoLoading:n,setVideoLoading:o,videoError:r,setVideoError:c,gender:i,config:l,btnConfig:d}){const{translate:u}=s(h)||{};return-1===a?t("div",{className:"text-center p-[16px] w-full h-full",style:{background:l?.style?.base?.backgroundColor},children:[t("div",{className:"w-full",children:[e(p,{noTitle:!0,resolvedConfig:l}),e("h2",{style:{fontFamily:l?.style?.heading?.headingFontFamily||"SeriouslyNostalgic Fn",fontSize:l?.style?.heading?.headingFontSize||"32px",color:l?.style?.heading?.headingColor||"#000",fontWeight:l?.style?.heading?.headingFontWeight||"normal"},children:u?.(m.faceVisible)}),n&&e("div",{className:"mb-4 flex items-center justify-center",style:{fontFamily:l?.style?.subheading?.subheadingFontFamily||"'Inter', sans-serif",fontSize:l?.style?.subheading?.subheadingFontSize||"14px",color:l?.style?.subheading?.subheadingColor||"#4b5563",fontWeight:l?.style?.subheading?.subheadingFontWeight||"normal"},children:u?.(m.loadingVideo)}),r&&e("div",{className:"mb-4 text-red-600",style:{fontFamily:l?.style?.subheading?.subheadingFontFamily||"'Inter', sans-serif",fontSize:l?.style?.subheading?.subheadingFontSize||"14px",color:"#ff0000",fontWeight:l?.style?.subheading?.subheadingFontWeight||"normal"},children:u?.(m.videoLoadFailed)}),!r&&e("div",{className:" w-[100px] mx-auto",children:e("video",{src:i===w.Male?S:b,autoPlay:!0,loop:!0,controls:!1,muted:!0,playsInline:!0,className:"h-full w-full object-contain border-none",onCanPlay:()=>o(!1),onLoadStart:()=>o(!0),onError:()=>c(!0),"aria-label":"Instructional video: Please remove your glasses before starting the scan."})})]}),e("div",{className:"flex justify-center w-full p-[1rem]",children:e(y,{disabled:d.isDisabled,className:"!w-[60px] !h-[35px] !py-0 !px-0",buttonText:u?.(d.label),postfixIcon:d?.icon,buttonFunc:d.onClick,resolvedConfig:l})})]}):e("div",{className:"text-center p-[16px] w-full h-full",style:{background:l?.style?.base?.backgroundColor},children:t("div",{className:"w-full",children:[e(p,{noTitle:!0,resolvedConfig:l}),e("h3",{className:"mb-[0.5rem]",style:{fontFamily:l?.style?.heading?.headingFontFamily||"SeriouslyNostalgic Fn",fontSize:l?.style?.heading?.headingFontSize||"32px",color:l?.style?.heading?.headingColor||"#000",fontWeight:l?.style?.heading?.headingFontWeight||"normal"},children:u?.(v[a])}),t("div",{className:"max-w-[400px] justify-center gap-1 mx-auto flex items-center",children:[e("div",{className:` w-[120px] overflow-hidden ${0===a?"opacity-100":"opacity-0 hidden"} `,children:e("video",{className:"h-full w-full object-contain border-none",muted:!0,loop:!0,autoPlay:!0,playsInline:!0,children:e("source",{src:i===w.Male?x.male.forward:x.female.forward,type:"video/mp4"})})}),e("div",{className:` w-[120px] overflow-hidden ${1===a?"opacity-100":"opacity-0 hidden"} `,children:e("video",{className:"h-full w-full object-contain border-none",muted:!0,loop:!0,autoPlay:!0,playsInline:!0,children:e("source",{src:i===w.Male?x.male.left:x.female.left,type:"video/mp4"})})}),e("div",{className:` w-[120px] overflow-hidden ${2===a?"opacity-100":"opacity-0 hidden"} `,children:e("video",{className:"h-full w-full object-contain border-none",muted:!0,loop:!0,autoPlay:!0,playsInline:!0,children:e("source",{src:i===w.Male?x.male.right:x.female.right,type:"video/mp4"})})}),e("div",{className:` w-[120px] overflow-hidden ${3===a?"opacity-100":"opacity-0 hidden"} `,children:e("video",{className:"h-full w-full object-contain border-none",muted:!0,loop:!0,autoPlay:!0,playsInline:!0,children:e("source",{src:i===w.Male?x.male.smile:x.female.smile,type:"video/mp4"})})})]})]})})}const W=({webcamRef:n,canvasRef:o})=>{const{isError:r,isSuccess:c,showLoader:l,hasError:d,resetScanState:u,showGuideCard:f,scanStage:m,videoLoading:p,setVideoLoading:y,videoError:S,setVideoError:b,gender:w,getButtonText:v,isScanning:x,startScan:I,isModelLoaded:k,config:M}=s(F),C=N(M),{setPreferredLanguage:T}=s(h)||{};return i(()=>{T?.(C?.language)},[C]),r?e(V,{config:C}):c?e("div",{className:"fixed z-[9] w-full h-full",style:{background:C?.style?.base?.backgroundColor},children:e(_,{url:C?.loader,loaderType:"black"})}):t(a,{children:[e("audio",{id:"audioElement",crossOrigin:"anonymous",preload:"auto",style:{position:"absolute",zIndex:-99999},src:void 0}),l&&d&&e("div",{className:"fixed z-[9] w-full h-full",style:{background:C?.style?.base?.backgroundColor},children:e(_,{url:C?.loader,loaderType:"black"})}),e("div",{className:"h-full flex-col relative w-full flex justify-center items-center text-center rounded-t-[20px]",style:{background:C?.style?.base?.backgroundColor},children:e("div",{className:"flex-1 w-full max-w-md overflow-hidden",children:t("div",{className:"w-full h-full",children:[e("video",{ref:n,autoPlay:!0,playsInline:!0,muted:!0,width:g.width,height:g.height,className:"w-full h-full object-cover fixed left-0 top-0 z-0",style:{transform:"scaleX(-1)"}}),e("canvas",{ref:o,width:g.width,height:g.height,style:{transform:"scaleX(-1)",opacity:"0"}})]})})}),!l&&d&&e(V,{loading:l,resetScanState:u,config:C}),f&&!d&&!l&&e(L,{open:!0,className:"face-scan-small camera-draw",anchor:"bottom",onClose:(e,t)=>{},hideBackdrop:!0,children:e(O,{stage:m,videoLoading:p,setVideoLoading:y,videoError:S,setVideoError:b,gender:w,config:C,btnConfig:{label:v(),onClick:x?u:I,isDisabled:l||!k,icon:e(x?z:a,{})}})})]})},B=({userDetails:t,onScanSuccess:a,onScanError:r,onRetry:s,config:d,isError:h,isSuccess:p})=>{const y=n(null),S=n(null),b=n(null),w=n([]),v=n(null),[x,N]=o(!1),[_,z]=o(!1),[L,$]=o(!1),[j,V]=o(!0),[O,B]=o(!1),[U,A]=o(!1),[J,q]=o(!1),[G,K]=o(I()),{email:H,gender:X,deviceFocalLength:Q,shopDomain:Y,callbackUrl:Z}=t,[ee,te]=o([]),ae=c(()=>{console.log("Stopping recording..."),b.current&&"recording"===b.current.state&&b.current.stop(),b.current=null},[]),ne=async()=>{if(N(!0),w.current){if(0===w.current.length)return console.error("No video data recorded"),q(!0),void N(!1);const e=new File(w.current,`${G}.webm`,{type:"video/webm"}),t=e.size,a=(t/1048576).toFixed(2),n=Math.round(t/1e4),o={video_size_mb:parseFloat(a),video_size_bytes:t,blob_count:w.current.length,estimated_duration_seconds:n},r=[{gender:X},{face_scan_id:G},{focal_length:`${Q}`},{customer_store_url:Y},{scan_type:"face_scan"},{callback_url:Z||"https://example.com/webhook"}];console.log(r,"metadat"),D({eventName:`${Y}/face_scan_meta_data`,faceScanId:G,email:H,data:JSON.stringify({metaData:r,videoData:o})});const c=Date.now();D({eventName:`${Y}/face_scan_upload_start`,faceScanId:G,email:H,startTime:c});try{const t=await P.fileUpload.faceScanFileUploader({file:e,arrayMetaData:r,objectKey:G,email:H,contentType:e.type}),a=Date.now();D({eventName:`${Y}/face_scan_upload_complete`,faceScanId:G,email:H,completionTime:a,uploadDuration:a-c}),console.log("✅ Upload successful",t),P.measurement.handlFaceScaneSocket({faceScanId:G,onOpen:()=>{E({eventName:`${Y}/webSocket`,faceScanID:G,connection:"open",type:"faceScan_recommendation",email:H}),console.log("websocket connect open")},onError:e=>{E({eventName:`${Y}/webSocket`,faceScanID:G,connection:"error",type:"faceScan_recommendation",email:H}),ge(e)},onSuccess:e=>{E({eventName:`${Y}/webSocket`,faceScanID:G,connection:"success",type:"faceScan_recommendation",email:H}),he(e)},onClose:()=>{console.log("websocket connect close"),E({eventName:`${Y}/webSocket`,faceScanID:G,connection:"close",type:"faceScan_recommendation",email:H})}})}catch(e){ge(e)}}},oe=c(()=>{console.log("Starting recording for stages 1-3...");const e=y.current?.srcObject;if(!e)return;const t=e.getVideoTracks()[0].getSettings(),{width:a=g.width,height:n=g.height}=t,o=document.createElement("canvas"),r=o.getContext("2d");a>n?(o.width=n,o.height=a):(o.width=a,o.height=n);const c=document.createElement("video");c.srcObject=e,c.muted=!0,c.playsInline=!0,c.play();const i=()=>{a>n?(r?.save(),r?.translate(o.width,0),r?.rotate(Math.PI/2),r?.drawImage(c,0,0,n,a),r?.restore()):r?.drawImage(c,0,0,a,n),requestAnimationFrame(i)};i();const s=o.captureStream(30),l=ee.length>0?{mimeType:ee[0]}:{};let d;try{d=new MediaRecorder(s,l)}catch(e){return console.error("MediaRecorder init failed:",e),q(!0),void N(!1)}w.current=[],d.ondataavailable=e=>{e?.data&&e.data.size>0&&w.current&&w.current.push(e.data)},d.onstop=()=>{console.log("Recording stopped, total blobs:",w?.current?.length),ne()},d.start(100),b.current=d,console.log("Recording started successfully (portrait normalized)")},[ee,ne]),{faceScanDetector:re,scanStage:ce,setScanStage:ie,resetScan:se,isModelLoaded:le,startScanSequence:de}=R({faceScanId:G,shopDomain:Y,onScanComplete:()=>{ae()},onModelReady:()=>{z(!0)},onStartRecording:()=>{console.log("Stage 0 completed - starting recording for stages 1-3"),oe()}}),ue=c(()=>{le&&(ie(0),u.playAudio(`${f}face-scan-vos/Face-forward.mp3`),setTimeout(()=>{$(!0),setTimeout(()=>{de()},200)},200))},[ie,$,de,le]),fe=c(()=>{$(!1),V(!0),ae(),se(),s?.(),w.current=[],b.current&&(b.current=null),q(!1),ie(-1),K(I()),y.current&&v.current&&(y.current.srcObject=v.current,console.log("Camera stream restored after reset"))},[ie,$,V,ae,se,K]),ge=e=>{console.log(e,"ws error"),r?.(e),q(!0),N(!1),V(!1),D({eventName:`${Y}/faceScan`,faceScanId:G,status:"failed",email:H,data:JSON.stringify(e)})},he=e=>{console.log(e,"ws success"),e&&"intermediate"===e?.resultType&&D({eventName:`${Y}/faceScan_success/intermediate`,faceScanId:G,status:"success",email:H,data:JSON.stringify(e)}),a?.(e)};i(()=>{if(!h&&!p)return navigator.mediaDevices.getUserMedia&&navigator.mediaDevices.getUserMedia({video:g}).then(e=>{v.current=e,y.current&&(y.current.srcObject=e)}).catch(e=>console.error("Error accessing webcam:",e)),()=>{v.current&&v.current.getTracks().forEach(e=>e.stop())}},[h,p]),i(()=>{if(!_||!L)return;const e=setInterval(()=>{re(y,S)},500);return()=>clearInterval(e)},[re,_,L]);return console.log("Model ready:",_,"Has error:",J,"Is scanning:",L,"showLoader",x),i(()=>{if("undefined"!=typeof MediaRecorder){const e=k.filter(e=>MediaRecorder.isTypeSupported(e));te(e)}},[]),i(()=>{ie(-1)},[h,p]),i(()=>{l.init(M,{api_host:C}),l.capture("$pageview")},[]),e(T,{children:e(F.Provider,{value:{isError:h,isSuccess:p,showLoader:x,hasError:J,resetScanState:fe,showGuideCard:j,scanStage:ce,videoLoading:O,setVideoLoading:B,videoError:U,setVideoError:A,gender:X,getButtonText:()=>L?m.reset:le?m.start:m.loading,isScanning:L,startScan:ue,isModelLoaded:le,config:d},children:e(W,{webcamRef:y,canvasRef:S})})})};export{B as F};
2
+ //# sourceMappingURL=FaceScan-CD16KBC-.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FaceScan-CD16KBC-.js","sources":["../src/customHooks/useFaceScan.ts","../src/components/faceScan/FaceScanErrorScreen.tsx","../src/components/faceScan/FaceScanGuide.tsx","../src/components/faceScan/FaceScanStep.tsx","../src/components/faceScan/FaceScan.tsx"],"sourcesContent":["import {\n useState,\n useRef,\n useEffect,\n useCallback,\n useMemo,\n RefObject,\n} from \"react\";\n// 1. Use TYPE-ONLY imports. These are erased at build time and won't crash SSR.\nimport type { PoseDetector } from \"@tensorflow-models/pose-detection\";\nimport { posthog } from \"posthog-js\";\nimport speechService from \"../utils/service/speechService\";\nimport { videoConstraints, voiceOverAssetsPath } from \"../utils/constants\";\n\n/**\n * useFaceScan Hook with PostHog Analytics\n * Refactored for Zero-Config SSR/CSR Compatibility\n */\n\n// Debounce utility\nfunction debounce(fn: (...args: any) => void, delay: number) {\n let timer: number | NodeJS.Timeout;\n return (...args: any) => {\n if (timer) clearTimeout(timer);\n timer = setTimeout(() => fn(...args), delay);\n };\n}\n\n// Global Singleton Cache (Preserves state across re-renders)\nlet preloadedDetector: PoseDetector | null = null;\nlet isPreloading = false;\n\n// 2. Async Preloader with Dynamic Imports\nexport const preloadDetector = async (): Promise<PoseDetector | null> => {\n // Guard: Never run on server\n if (typeof window === \"undefined\") return null;\n if (preloadedDetector) return preloadedDetector;\n if (isPreloading) {\n // Simple wait mechanism if already loading\n while (isPreloading) {\n await new Promise(r => setTimeout(r, 100));\n if (preloadedDetector) return preloadedDetector;\n }\n }\n\n isPreloading = true;\n\n try {\n // DYNAMIC IMPORTS: Only fetch these heavy bundles in the browser\n const [tf, poseDetection] = await Promise.all([\n import(\"@tensorflow/tfjs\"),\n import(\"@tensorflow-models/pose-detection\")\n ]);\n\n // Initialize Backend\n await tf.setBackend(\"webgl\");\n await tf.ready();\n\n const detector = await poseDetection.createDetector(\n poseDetection.SupportedModels.BlazePose,\n {\n runtime: \"tfjs\",\n modelType: \"full\",\n }\n );\n\n // Dummy video warmup (Performance Optimization)\n // This runs the model once on a blank canvas to \"wake up\" the GPU\n // so the first user frame detects instantly.\n const dummyCanvas = document.createElement(\"canvas\");\n dummyCanvas.width = videoConstraints.width;\n dummyCanvas.height = videoConstraints.height;\n const ctx = dummyCanvas.getContext(\"2d\");\n if (ctx) {\n ctx.fillStyle = \"black\";\n ctx.fillRect(0, 0, dummyCanvas.width, dummyCanvas.height);\n try {\n await detector.estimatePoses(dummyCanvas);\n } catch (e) {\n console.warn(\"Warmup frame failed (non-fatal):\", e);\n }\n }\n\n preloadedDetector = detector;\n return detector;\n } catch (err) {\n console.error(\"Failed to preload detector:\", err);\n return null;\n } finally {\n isPreloading = false;\n }\n};\n\ntype Point = [number, number, number];\n\nfunction useFaceScan({\n faceScanId,\n onValidPose,\n onScanComplete,\n onModelReady,\n onStartRecording,\n shopDomain,\n}: {\n faceScanId: string;\n onValidPose?: () => void;\n onScanComplete?: () => void;\n onModelReady?: () => void;\n onStartRecording: () => void;\n shopDomain: string;\n}) {\n const detectorRef = useRef<PoseDetector | null>(null);\n const [scanStage, setScanStage] = useState(0);\n const [consecutiveValid, setConsecutiveValid] = useState(0);\n const [isModelLoaded, setIsModelLoaded] = useState(false);\n const [isScanningActive, setIsScanningActive] = useState(false);\n \n const utteranceRef = useRef<SpeechSynthesisUtterance | null>(null);\n const scanStageRef = useRef(scanStage);\n const consecutiveValidRef = useRef(consecutiveValid);\n const validityBufferRef = useRef<boolean[]>([]);\n const lastSpokenMessageRef = useRef(\"\");\n const lastSpokenTimeRef = useRef(0);\n const voiceEnabledRef = useRef(false);\n \n const VALIDITY_BUFFER_LENGTH = 10;\n const CONSECUTIVE_VALID_LENGTH = 2;\n const TOTAL_STAGES = 4;\n const POSE_TRACKING_INTERVAL = 4000;\n const lastPoseTrackingTimeRef = useRef(0);\n\n // Safe iOS detection (SSR safe)\n const isIOS = typeof navigator !== 'undefined' && (\n /iPad|iPhone|iPod/.test(navigator.userAgent) ||\n (navigator.platform === \"MacIntel\" && navigator.maxTouchPoints > 1)\n );\n\n const directionMessages = useMemo(\n () => [\n \"Face front\",\n \"Turn head fully left\",\n \"Turn head fully right\",\n \"Smile facing front\",\n ],\n []\n );\n\n const debouncedTrackPoseDetection = useMemo(\n () =>\n debounce((payload) => {\n posthog.capture(`${shopDomain}/face_scan_pose_detection`, payload);\n }, 4000),\n [shopDomain]\n );\n\n const trackPoseDetection = useCallback(\n (\n faceKeypoints: Point[],\n bodyKeypoints: Point[],\n stage: number,\n headValid: boolean,\n bodyInvalid: boolean,\n consecutiveValidCount: number\n ) => {\n const now = Date.now();\n if (now - lastPoseTrackingTimeRef.current < POSE_TRACKING_INTERVAL) {\n return;\n }\n\n lastPoseTrackingTimeRef.current = now;\n\n try {\n const nose = faceKeypoints[0] || [0, 0, 0];\n const leftEye = faceKeypoints[2] || [0, 0, 0];\n const rightEye = faceKeypoints[5] || [0, 0, 0];\n const leftMouth = faceKeypoints[9] || [0, 0, 0];\n const rightMouth = faceKeypoints[10] || [0, 0, 0];\n\n const faceKeypointScores = faceKeypoints\n .map((kp: Point) => kp[2])\n .filter((score: number) => score > 0);\n const avgFaceScore =\n faceKeypointScores.length > 0\n ? faceKeypointScores.reduce((a, b) => a + b, 0) /\n faceKeypointScores.length\n : 0;\n\n const bodyKeypointScores = bodyKeypoints\n .map((kp: Point) => kp[2])\n .filter((score: number) => score > 0);\n const avgBodyScore =\n bodyKeypointScores.length > 0\n ? bodyKeypointScores.reduce((a: number, b: number) => a + b, 0) /\n bodyKeypointScores.length\n : 0;\n\n const eyeDistance = Math.abs(leftEye[0] - rightEye[0]);\n const noseToRight = nose[0] - rightEye[0];\n const noseToLeft = leftEye[0] - nose[0];\n\n let expectedPosition = \"frontal\";\n if (stage === 1) expectedPosition = \"left\";\n else if (stage === 2) expectedPosition = \"right\";\n else if (stage === 3) expectedPosition = \"frontal_smile\";\n\n const payload = {\n faceScanId,\n stage,\n timestamp: new Date().toISOString(),\n data: JSON.stringify({\n headValid,\n bodyInvalid,\n consecutiveValid: consecutiveValidCount,\n avgFaceScore: parseFloat(avgFaceScore.toFixed(3)),\n avgBodyScore: parseFloat(avgBodyScore.toFixed(3)),\n faceKeypointsDetected: faceKeypointScores.length,\n bodyKeypointsDetected: bodyKeypointScores.length,\n eyeDistance: parseFloat(eyeDistance.toFixed(2)),\n noseToRightRatio: parseFloat((noseToRight / eyeDistance).toFixed(3)),\n noseToLeftRatio: parseFloat((noseToLeft / eyeDistance).toFixed(3)),\n noseScore: parseFloat(nose[2].toFixed(3)),\n leftEyeScore: parseFloat(leftEye[2].toFixed(3)),\n rightEyeScore: parseFloat(rightEye[2].toFixed(3)),\n leftMouthScore: parseFloat(leftMouth[2].toFixed(3)),\n rightMouthScore: parseFloat(rightMouth[2].toFixed(3)),\n expectedPosition,\n }),\n };\n debouncedTrackPoseDetection(payload);\n } catch (error) {\n console.warn(\"Failed to track pose detection:\", error);\n }\n },\n [faceScanId, debouncedTrackPoseDetection]\n );\n\n const enableVoiceCommands = () => {\n voiceEnabledRef.current = true;\n if (typeof window !== 'undefined' && isIOS && \"speechSynthesis\" in window) {\n const silentUtterance = new SpeechSynthesisUtterance(\"\");\n silentUtterance.volume = 0;\n speechSynthesis.speak(silentUtterance);\n }\n };\n\n const startScanSequence = () => {\n posthog.capture(`${shopDomain}/face_scan_detection_started`, {\n faceScanId,\n stage: scanStageRef.current,\n timestamp: new Date().toISOString(),\n stageName: directionMessages[scanStageRef.current],\n });\n\n setTimeout(() => {\n setIsScanningActive(true);\n }, 1500);\n };\n\n const isHeadInPosition = (stage: number, keypoints: Point[]) => {\n // ... logic unchanged ...\n const nose = 0;\n const leftEye = 2;\n const rightEye = 5;\n const leftMouth = 9;\n const rightMouth = 10;\n\n const minScore = 0.2;\n if (\n !keypoints[nose] || !keypoints[leftEye] || !keypoints[rightEye] ||\n keypoints[nose][2] < minScore ||\n keypoints[leftEye][2] < minScore ||\n keypoints[rightEye][2] < minScore\n ) {\n return false;\n }\n\n const eyesToMouthVerticalDistance =\n 0.5 * (keypoints[rightMouth][1] + keypoints[leftMouth][1]) -\n 0.5 * (keypoints[rightEye][1] + keypoints[leftEye][1]);\n\n const faceTiltedness =\n (0.5 * (keypoints[rightMouth][1] + keypoints[leftMouth][1]) -\n keypoints[nose][1]) /\n eyesToMouthVerticalDistance;\n\n const faceIsTilted = faceTiltedness > 0.7 || faceTiltedness < 0.3;\n\n const faceIsVertical =\n Math.abs(keypoints[leftEye][1] - keypoints[rightEye][1]) <\n 0.5 * eyesToMouthVerticalDistance &&\n Math.abs(keypoints[leftMouth][1] - keypoints[rightMouth][1]) <\n 0.5 * eyesToMouthVerticalDistance;\n\n const eyeDistance = keypoints[leftEye][0] - keypoints[rightEye][0];\n const noseToRight = keypoints[nose][0] - keypoints[rightEye][0];\n const noseToLeft = keypoints[leftEye][0] - keypoints[nose][0];\n\n const frontalFace =\n noseToRight > 0.4 * eyeDistance && noseToRight < 0.6 * eyeDistance;\n const fullLeft = noseToRight > 0.85 * eyeDistance;\n const fullRight = noseToLeft > 0.85 * eyeDistance;\n\n switch (stage) {\n case 0:\n return !faceIsTilted && faceIsVertical && frontalFace;\n case 1:\n return !faceIsTilted && faceIsVertical && fullLeft;\n case 2:\n return !faceIsTilted && faceIsVertical && fullRight;\n case 3:\n return !faceIsTilted && faceIsVertical && frontalFace;\n default:\n return false;\n }\n };\n\n const faceScanDetector = async (\n webcamRef: RefObject<HTMLVideoElement | null>,\n canvasRef: RefObject<HTMLCanvasElement | null>\n ) => {\n if (\n !detectorRef.current ||\n !webcamRef.current ||\n !isModelLoaded ||\n !isScanningActive\n )\n return;\n\n // Safety: ensure video is actually playing with data\n if (webcamRef.current.readyState < 2) return;\n\n try {\n const poses = await detectorRef.current.estimatePoses(webcamRef.current);\n if (poses.length > 0) {\n const faceKeypoints: Point[] = [];\n const bodyKeypoints: Point[] = [];\n poses[0].keypoints.forEach((landmark, idx) => {\n const score = landmark.score ?? 0;\n const point: Point = [landmark.x ?? -1, landmark.y ?? -1, score];\n if (idx <= 10) faceKeypoints.push(point);\n else bodyKeypoints.push(point);\n });\n\n // Optional drawing\n if (canvasRef?.current) {\n const ctx = canvasRef.current.getContext(\"2d\");\n const { width, height } = canvasRef.current;\n if (ctx) {\n ctx.clearRect(0, 0, width, height);\n\n const progress = Math.min(\n consecutiveValidRef.current / CONSECUTIVE_VALID_LENGTH,\n 1\n );\n const radius = height * 0.35;\n ctx.beginPath();\n ctx.strokeStyle = \"#00ff00\";\n ctx.lineWidth = 6;\n ctx.arc(\n width / 2,\n height / 2,\n radius + 10,\n -Math.PI / 2,\n -Math.PI / 2 + progress * 2 * Math.PI\n );\n ctx.stroke();\n }\n }\n\n const headValid = isHeadInPosition(scanStageRef.current, faceKeypoints);\n const bodyInvalid =\n bodyKeypoints.slice(2).filter((p) => p[2] > 0.7).length <= 2;\n\n validityBufferRef.current.push(headValid && bodyInvalid);\n if (validityBufferRef.current.length > VALIDITY_BUFFER_LENGTH) {\n validityBufferRef.current.shift();\n }\n\n const validCount = validityBufferRef.current.filter(Boolean).length;\n if (validCount >= 2) {\n const nextValid = consecutiveValidRef.current + 1;\n setConsecutiveValid(nextValid);\n } else {\n setConsecutiveValid(Math.max(0, consecutiveValidRef.current - 1));\n }\n\n if (consecutiveValidRef.current >= CONSECUTIVE_VALID_LENGTH) {\n onValidPose?.();\n\n const nextStage = scanStageRef.current + 1;\n setConsecutiveValid(0);\n validityBufferRef.current = [];\n setScanStage(nextStage);\n setIsScanningActive(false);\n\n (async () => {\n await speechService.playAudio(\n `${voiceOverAssetsPath}face-scan-vos/Sound-effect.mp3`\n );\n posthog.capture(\n `${shopDomain}/face_scan_detection_stage_completed`,\n {\n faceScanId,\n completedStage: scanStageRef.current,\n nextStage,\n timestamp: new Date().toISOString(),\n totalStages: TOTAL_STAGES,\n stageName: directionMessages[scanStageRef.current],\n }\n );\n \n if (nextStage === 1 && onStartRecording) {\n onStartRecording();\n }\n if (nextStage >= TOTAL_STAGES) {\n onScanComplete?.();\n } else {\n let nextSound = null;\n switch (nextStage) {\n case 1: nextSound = \"Left.mp3\"; break;\n case 2: nextSound = \"Right.mp3\"; break;\n case 3: nextSound = \"Smile.mp3\"; break;\n }\n if (nextSound) {\n await speechService.playAudio(\n `${voiceOverAssetsPath}face-scan-vos/${nextSound}`\n );\n }\n startScanSequence();\n }\n })();\n }\n\n trackPoseDetection(\n faceKeypoints,\n bodyKeypoints,\n scanStageRef.current,\n headValid,\n bodyInvalid,\n consecutiveValidRef.current\n );\n }\n } catch (err) {\n console.error(\"Pose detection error:\", err);\n }\n };\n\n const initializeModels = async () => {\n // 3. Browser Guard\n if (typeof window === 'undefined') return;\n\n try {\n console.log(\"Initializing Face Scan...\");\n // Calls our safe, dynamic preloader\n const detector = await preloadDetector();\n \n if (detector) {\n detectorRef.current = detector;\n console.log(\"Face scan model loaded successfully\");\n setIsModelLoaded(true);\n onModelReady?.();\n }\n } catch (err) {\n console.error(\"Error initializing face scan:\", err);\n }\n };\n\n const disposeModelAndTf = async () => {\n // Optional: We might NOT want to dispose if we want to keep the cache \n // for re-mounting. But if you must dispose:\n try {\n setIsModelLoaded(false);\n // NOTE: We generally don't dispose the detector if we want to reuse it \n // via the 'preloadedDetector' global variable.\n // If you dispose here, make sure to set 'preloadedDetector = null' too.\n /* if (detectorRef.current) {\n await detectorRef.current.dispose();\n detectorRef.current = null;\n preloadedDetector = null; // Clear global cache if disposing\n }\n */\n } catch (err) {\n console.error(\"Error disposing resources:\", err);\n } finally {\n // Reset state\n setScanStage(0);\n setConsecutiveValid(0);\n scanStageRef.current = 0;\n consecutiveValidRef.current = 0;\n validityBufferRef.current = [];\n }\n };\n\n const resetScan = () => {\n posthog.capture(`${shopDomain}/face_scan_reset`, {\n faceScanId,\n stage: scanStageRef.current,\n timestamp: new Date().toISOString(),\n stageName: directionMessages[scanStageRef.current],\n consecutiveValid: consecutiveValidRef.current,\n });\n\n setScanStage(0);\n setConsecutiveValid(0);\n setIsScanningActive(false);\n scanStageRef.current = 0;\n consecutiveValidRef.current = 0;\n validityBufferRef.current = [];\n lastSpokenMessageRef.current = \"\";\n lastSpokenTimeRef.current = 0;\n voiceEnabledRef.current = false;\n if (utteranceRef.current) {\n speechSynthesis.cancel();\n utteranceRef.current = null;\n }\n };\n\n useEffect(() => {\n initializeModels();\n return () => {\n disposeModelAndTf();\n };\n }, []);\n\n useEffect(() => {\n scanStageRef.current = scanStage;\n }, [scanStage]);\n\n useEffect(() => {\n consecutiveValidRef.current = consecutiveValid;\n }, [consecutiveValid]);\n\n return {\n faceScanDetector,\n scanStage,\n setScanStage,\n consecutiveValid,\n isModelLoaded,\n resetScan,\n enableVoiceCommands,\n startScanSequence,\n isScanningActive,\n };\n}\n\nexport default useFaceScan;","import { ArrowRight } from \"lucide-react\";\nimport Header from \"../Header\";\nimport SpecificButton from \"../../atoms/specificButton/SpecificButton\";\nimport { useContext } from \"react\";\nimport { LanguageKeys } from \"../../utils/languageKeys\";\nimport { LanguageContext } from \"../../utils/context/languageContext\";\nimport { Config } from \"../../types/interfaces\";\n\nfunction FaceScanErrorScreen({ resetScanState, loading, config }: { resetScanState?: () => void; loading?: boolean; config?: Config }) {\n\tconst { translate,preferredLanguage } = useContext(LanguageContext) || {};\nconsole.log(preferredLanguage,\"preferredLanguage\");\n\nconsole.log(translate?.(LanguageKeys.scanFailed),\"translate\");\n\n\n\treturn (\n\t\t<div className=\"fixed top-[0] left-[0] z-[999] flex justify-center items-center w-full h-full\" style={{ background: config?.style?.base?.backgroundColor }}>\n\t\t\t<div className=\"flex flex-col w-full items-center p-[1rem] rounded-lg \">\n\t\t\t\t<Header noTitle resolvedConfig={config} />\n\t\t\t\t<div className=\"flex flex-col items-center w-full\">\n\t\t\t\t\t<h2\n\t\t\t\t\t\tclassName=\"text-xl font-semibold text-gray-800 \"\n\t\t\t\t\t\tstyle={{\n\t\t\t\t\t\t\tfontFamily: config?.style?.heading?.headingFontFamily || \"SeriouslyNostalgic Fn\",\n\t\t\t\t\t\t\tfontSize: config?.style?.heading?.headingFontSize || \"32px\",\n\t\t\t\t\t\t\tcolor: config?.style?.heading?.headingColor || \"#000\",\n\t\t\t\t\t\t\tfontWeight: config?.style?.heading?.headingFontWeight || \"normal\",\n\t\t\t\t\t\t}}\n\t\t\t\t\t>\n\t\t\t\t\t\t{translate?.(LanguageKeys.scanFailed)}\n\t\t\t\t\t</h2>\n\t\t\t\t\t<p\n\t\t\t\t\t\tclassName=\"mb-[1.5rem]\"\n\t\t\t\t\t\tstyle={{\n\t\t\t\t\t\t\tfontFamily: config?.style?.subheading?.subheadingFontFamily || \"'Inter', sans-serif\",\n\t\t\t\t\t\t\tfontSize: config?.style?.subheading?.subheadingFontSize || \"14px\",\n\t\t\t\t\t\t\tcolor: config?.style?.subheading?.subheadingColor || \"#4b5563\",\n\t\t\t\t\t\t\tfontWeight: config?.style?.subheading?.subheadingFontWeight || \"normal\",\n\t\t\t\t\t\t}}\n\t\t\t\t\t>\n\t\t\t\t\t\t{translate?.(LanguageKeys.clickToResetScan)}\n\t\t\t\t\t</p>\n\t\t\t\t\t<SpecificButton\n\t\t\t\t\t\tdisabled={loading}\n\t\t\t\t\t\tclassName=\"w-full h-[45px] shadow-[0px_1px_2px_0px_#00000040] text-[16px]\"\n\t\t\t\t\t\tbuttonText={translate?.(LanguageKeys.resetScan)}\n\t\t\t\t\t\tpostfixIcon={<ArrowRight />}\n\t\t\t\t\t\tbuttonFunc={() => resetScanState?.()}\n\t\t\t\t\t\tresolvedConfig={config}\n\t\t\t\t\t/>\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t</div>\n\t);\n}\n\nexport default FaceScanErrorScreen;\n","import { FaceScanGuideProps } from \"../../types/interfaces\";\nimport Header from \"../Header\";\nimport { GenderType } from \"../../utils/enums\";\nimport { directionMessages, FACE_SCAN_HEADSHOT, glassesOffVideo, maleGlassesOffVideo } from \"../../utils/constants\";\nimport { LanguageContext } from \"../../utils/context/languageContext\";\nimport { useContext } from \"react\";\nimport SpecificButton from \"../../atoms/specificButton/SpecificButton\";\nimport { LanguageKeys } from \"../../utils/languageKeys\";\n\nfunction FaceScanGuide({ stage, videoLoading, setVideoLoading, videoError, setVideoError, gender, config, btnConfig }: FaceScanGuideProps) {\n\tconst { translate } = useContext(LanguageContext) || {};\n\n\n\n\tif (stage === -1) {\n\t\treturn (\n\t\t\t<div className=\"text-center p-[16px] w-full h-full\" style={{ background: config?.style?.base?.backgroundColor }}>\n\t\t\t\t<div className=\"w-full\">\n\t\t\t\t\t<Header noTitle resolvedConfig={config} />\n\t\t\t\t\t<h2\n\t\t\t\t\t\tstyle={{\n\t\t\t\t\t\t\tfontFamily: config?.style?.heading?.headingFontFamily || \"SeriouslyNostalgic Fn\",\n\t\t\t\t\t\t\tfontSize: config?.style?.heading?.headingFontSize || \"32px\",\n\t\t\t\t\t\t\tcolor: config?.style?.heading?.headingColor || \"#000\",\n\t\t\t\t\t\t\tfontWeight: config?.style?.heading?.headingFontWeight || \"normal\",\n\t\t\t\t\t\t}}\n\t\t\t\t\t>\n\t\t\t\t\t\t{translate?.(LanguageKeys.faceVisible)}\n\t\t\t\t\t</h2>\n\t\t\t\t\t{videoLoading && (\n\t\t\t\t\t\t<div\n\t\t\t\t\t\t\tclassName=\"mb-4 flex items-center justify-center\"\n\t\t\t\t\t\t\tstyle={{\n\t\t\t\t\t\t\t\tfontFamily: config?.style?.subheading?.subheadingFontFamily || \"'Inter', sans-serif\",\n\t\t\t\t\t\t\t\tfontSize: config?.style?.subheading?.subheadingFontSize || \"14px\",\n\t\t\t\t\t\t\t\tcolor: config?.style?.subheading?.subheadingColor || \"#4b5563\",\n\t\t\t\t\t\t\t\tfontWeight: config?.style?.subheading?.subheadingFontWeight || \"normal\",\n\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{translate?.(LanguageKeys.loadingVideo)}\n\t\t\t\t\t\t</div>\n\t\t\t\t\t)}\n\t\t\t\t\t{videoError && (\n\t\t\t\t\t\t<div\n\t\t\t\t\t\t\tclassName=\"mb-4 text-red-600\"\n\t\t\t\t\t\t\tstyle={{\n\t\t\t\t\t\t\t\tfontFamily: config?.style?.subheading?.subheadingFontFamily || \"'Inter', sans-serif\",\n\t\t\t\t\t\t\t\tfontSize: config?.style?.subheading?.subheadingFontSize || \"14px\",\n\t\t\t\t\t\t\t\tcolor: \"#ff0000\",\n\t\t\t\t\t\t\t\tfontWeight: config?.style?.subheading?.subheadingFontWeight || \"normal\",\n\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{translate?.(LanguageKeys.videoLoadFailed)}\n\t\t\t\t\t\t</div>\n\t\t\t\t\t)}\n\t\t\t\t\t{!videoError && (\n\t\t\t\t\t\t<div className={` w-[100px] mx-auto`}>\n\t\t\t\t\t\t\t<video\n\t\t\t\t\t\t\t\tsrc={gender === GenderType.Male ? maleGlassesOffVideo : glassesOffVideo}\n\t\t\t\t\t\t\t\tautoPlay\n\t\t\t\t\t\t\t\tloop\n\t\t\t\t\t\t\t\tcontrols={false}\n\t\t\t\t\t\t\t\tmuted\n\t\t\t\t\t\t\t\tplaysInline\n\t\t\t\t\t\t\t\tclassName=\"h-full w-full object-contain border-none\"\n\t\t\t\t\t\t\t\tonCanPlay={() => setVideoLoading(false)}\n\t\t\t\t\t\t\t\tonLoadStart={() => setVideoLoading(true)}\n\t\t\t\t\t\t\t\tonError={() => setVideoError(true)}\n\t\t\t\t\t\t\t\taria-label=\"Instructional video: Please remove your glasses before starting the scan.\"\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t)}\n\t\t\t\t</div>\n\t\t\t\t<div className=\"flex justify-center w-full p-[1rem]\">\n\t\t\t\t\t<SpecificButton\n\t\t\t\t\t\tdisabled={btnConfig.isDisabled}\n\t\t\t\t\t\tclassName=\"!w-[60px] !h-[35px] !py-0 !px-0\"\n\t\t\t\t\t\tbuttonText={translate?.(btnConfig.label)}\n\t\t\t\t\t\tpostfixIcon={btnConfig?.icon}\n\t\t\t\t\t\tbuttonFunc={btnConfig.onClick}\n\t\t\t\t\t\tresolvedConfig={config}\n\t\t\t\t\t/>\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t);\n\t}\n\n\treturn (\n\t\t<div className=\"text-center p-[16px] w-full h-full\" style={{ background: config?.style?.base?.backgroundColor }}>\n\t\t\t<div className=\"w-full\">\n\t\t\t\t<Header noTitle resolvedConfig={config} />\n\t\t\t\t<h3\n\t\t\t\t\tclassName=\"mb-[0.5rem]\"\n\t\t\t\t\tstyle={{\n\t\t\t\t\t\tfontFamily: config?.style?.heading?.headingFontFamily || \"SeriouslyNostalgic Fn\",\n\t\t\t\t\t\tfontSize: config?.style?.heading?.headingFontSize || \"32px\",\n\t\t\t\t\t\tcolor: config?.style?.heading?.headingColor || \"#000\",\n\t\t\t\t\t\tfontWeight: config?.style?.heading?.headingFontWeight || \"normal\",\n\t\t\t\t\t}}\n\t\t\t\t>\n\t\t\t\t\t{translate?.(directionMessages[stage])}\n\t\t\t\t</h3>\n\t\t\t\t{/* <p>We'll guide you to take 6 selfies </p> */}\n\t\t\t\t<div className=\"max-w-[400px] justify-center gap-1 mx-auto flex items-center\">\n\t\t\t\t\t<div className={` w-[120px] overflow-hidden ${stage === 0 ? \"opacity-100\" : \"opacity-0 hidden\"} `}>\n\t\t\t\t\t\t<video className=\"h-full w-full object-contain border-none\" muted loop autoPlay playsInline>\n\t\t\t\t\t\t\t<source src={gender === GenderType.Male ? FACE_SCAN_HEADSHOT.male.forward : FACE_SCAN_HEADSHOT.female.forward} type=\"video/mp4\" />\n\t\t\t\t\t\t</video>\n\t\t\t\t\t</div>\n\t\t\t\t\t<div className={` w-[120px] overflow-hidden ${stage === 1 ? \"opacity-100\" : \"opacity-0 hidden\"} `}>\n\t\t\t\t\t\t<video className=\"h-full w-full object-contain border-none\" muted loop autoPlay playsInline>\n\t\t\t\t\t\t\t<source src={gender === GenderType.Male ? FACE_SCAN_HEADSHOT.male.left : FACE_SCAN_HEADSHOT.female.left} type=\"video/mp4\" />\n\t\t\t\t\t\t</video>\n\t\t\t\t\t</div>\n\t\t\t\t\t<div className={` w-[120px] overflow-hidden ${stage === 2 ? \"opacity-100\" : \"opacity-0 hidden\"} `}>\n\t\t\t\t\t\t<video className=\"h-full w-full object-contain border-none\" muted loop autoPlay playsInline>\n\t\t\t\t\t\t\t<source src={gender === GenderType.Male ? FACE_SCAN_HEADSHOT.male.right : FACE_SCAN_HEADSHOT.female.right} type=\"video/mp4\" />\n\t\t\t\t\t\t</video>\n\t\t\t\t\t</div>\n\t\t\t\t\t<div className={` w-[120px] overflow-hidden ${stage === 3 ? \"opacity-100\" : \"opacity-0 hidden\"} `}>\n\t\t\t\t\t\t<video className=\"h-full w-full object-contain border-none\" muted loop autoPlay playsInline>\n\t\t\t\t\t\t\t<source src={gender === GenderType.Male ? FACE_SCAN_HEADSHOT.male.smile : FACE_SCAN_HEADSHOT.female.smile} type=\"video/mp4\" />\n\t\t\t\t\t\t</video>\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t</div>\n\t);\n}\n\nexport default FaceScanGuide;\n","import React, { useContext, useEffect } from \"react\";\nimport ParamsContext from \"../../utils/context/paramsContext\";\nimport FaceScanErrorScreen from \"./FaceScanErrorScreen\";\nimport LoadingScreen from \"../LoadingScreen\";\nimport { videoConstraints } from \"../../utils/constants\";\nimport { Drawer } from \"@mui/material\";\nimport FaceScanGuide from \"./FaceScanGuide\";\nimport { ArrowRight } from \"lucide-react\";\nimport { LanguageContext } from \"../../utils/context/languageContext\";\nimport { useLocalConfig } from \"../../config/useLocalConfig\";\ninterface FaceScanStepProps {\n\twebcamRef: React.RefObject<HTMLVideoElement | null>;\n\tcanvasRef: React.RefObject<HTMLCanvasElement | null>;\n}\n\nconst FaceScanStep: React.FC<FaceScanStepProps> = ({ webcamRef, canvasRef }) => {\n\tconst {\n\t\tisError,\n\t\tisSuccess,\n\t\tshowLoader,\n\t\thasError,\n\t\tresetScanState,\n\t\tshowGuideCard,\n\t\tscanStage,\n\t\tvideoLoading,\n\t\tsetVideoLoading,\n\t\tvideoError,\n\t\tsetVideoError,\n\t\tgender,\n\t\tgetButtonText,\n\t\tisScanning,\n\t\tstartScan,\n\t\tisModelLoaded,\n\t\tconfig,\n\t} = useContext(ParamsContext);\n\tconst resolvedConfig = useLocalConfig(config);\n\n\tconst { setPreferredLanguage } = useContext(LanguageContext) || {};\n\tuseEffect(() => {\n\t\tsetPreferredLanguage?.(resolvedConfig?.language);\n\t}, [resolvedConfig]);\n\tif (isError) {\n\t\treturn <FaceScanErrorScreen config={resolvedConfig} />;\n\t}\n\tif (isSuccess) {\n\t\treturn (\n\t\t\t<div className=\"fixed z-[9] w-full h-full\" style={{ background: resolvedConfig?.style?.base?.backgroundColor }}>\n\t\t\t\t{/* <Asset genderType={gender} /> */}\n\t\t\t\t<LoadingScreen url={resolvedConfig?.loader} loaderType=\"black\" />\n\t\t\t</div>\n\t\t);\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t<audio id=\"audioElement\" crossOrigin=\"anonymous\" preload=\"auto\" style={{ position: \"absolute\", zIndex: -99999 }} src={undefined} />\n\n\t\t\t{/* Error overlay */}\n\t\t\t{showLoader && hasError && (\n\t\t\t\t<div className=\"fixed z-[9] w-full h-full\" style={{ background: resolvedConfig?.style?.base?.backgroundColor }}>\n\t\t\t\t\t{/* <Asset genderType={gender} /> */}\n\t\t\t\t\t<LoadingScreen url={resolvedConfig?.loader} loaderType=\"black\" />\n\t\t\t\t</div>\n\t\t\t)}\n\n\t\t\t{/* Always show camera view */}\n\t\t\t<div className=\"h-full flex-col relative w-full flex justify-center items-center text-center rounded-t-[20px]\" style={{ background: resolvedConfig?.style?.base?.backgroundColor }}>\n\t\t\t\t<div className=\"flex-1 w-full max-w-md overflow-hidden\">\n\t\t\t\t\t<div className=\"w-full h-full\">\n\t\t\t\t\t\t<video\n\t\t\t\t\t\t\tref={webcamRef}\n\t\t\t\t\t\t\tautoPlay\n\t\t\t\t\t\t\tplaysInline\n\t\t\t\t\t\t\tmuted\n\t\t\t\t\t\t\twidth={videoConstraints.width}\n\t\t\t\t\t\t\theight={videoConstraints.height}\n\t\t\t\t\t\t\tclassName=\"w-full h-full object-cover fixed left-0 top-0 z-0\"\n\t\t\t\t\t\t\tstyle={{ transform: \"scaleX(-1)\" }}\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<canvas ref={canvasRef} width={videoConstraints.width} height={videoConstraints.height} style={{ transform: \"scaleX(-1)\", opacity: \"0\" }} />\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t</div>\n\n\t\t\t{/* Error overlay */}\n\t\t\t{!showLoader && hasError && <FaceScanErrorScreen loading={showLoader} resetScanState={resetScanState} config={resolvedConfig} />}\n\n\t\t\t{/* Scan guide drawer - only show when scanning */}\n\t\t\t{showGuideCard && !hasError && !showLoader && (\n\t\t\t\t<Drawer\n\t\t\t\t\topen\n\t\t\t\t\tclassName=\"face-scan-small camera-draw\"\n\t\t\t\t\tanchor=\"bottom\"\n\t\t\t\t\tonClose={(event, reason) => {\n\t\t\t\t\t\tif (reason === \"backdropClick\") {\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t}}\n\t\t\t\t\thideBackdrop\n\t\t\t\t>\n\t\t\t\t\t<FaceScanGuide\n\t\t\t\t\t\tstage={scanStage}\n\t\t\t\t\t\tvideoLoading={videoLoading}\n\t\t\t\t\t\tsetVideoLoading={setVideoLoading}\n\t\t\t\t\t\tvideoError={videoError}\n\t\t\t\t\t\tsetVideoError={setVideoError}\n\t\t\t\t\t\tgender={gender}\n\t\t\t\t\t\tconfig={resolvedConfig}\n\t\t\t\t\t\tbtnConfig={{\n\t\t\t\t\t\t\tlabel: getButtonText(),\n\t\t\t\t\t\t\tonClick: isScanning ? resetScanState : startScan,\n\t\t\t\t\t\t\tisDisabled: showLoader || !isModelLoaded,\n\t\t\t\t\t\t\ticon: isScanning ? <ArrowRight /> : <></>,\n\t\t\t\t\t\t}}\n\t\t\t\t\t/>\n\t\t\t\t</Drawer>\n\t\t\t)}\n\t\t</>\n\t);\n};\n\nexport default FaceScanStep;\n","\"use client\";\nimport { useEffect, useRef, useState, useCallback, } from \"react\";\nimport posthog from \"posthog-js\";\nimport { FaceScanProps } from \"../../types/interfaces\";\nimport { generateUuid, handleScanTimeCapture, handleWebSocketCapture } from \"../../utils/utils\";\nimport { posthogPublicHost, posthogPublicKey, videoConstraints, videoTypes, voiceOverAssetsPath } from \"../../utils/constants\";\nimport swan from \"../../utils/service/swanService\";\nimport speechService from \"../../utils/service/speechService\";\nimport useFaceScan from \"../../customHooks/useFaceScan\";\nimport { LanguageKeys } from \"../../utils/languageKeys\";\nimport LanguageContextProvider, { LanguageContext } from \"../../utils/context/languageContext\";\nimport FaceScanStep from \"./FaceScanStep\";\nimport ParamsContext from \"../../utils/context/paramsContext\";\n\nexport const FaceScan: React.FC<FaceScanProps> = ({ userDetails, onScanSuccess, onScanError, onRetry, config, isError, isSuccess }) => {\n\tconst webcamRef = useRef<HTMLVideoElement | null>(null);\n\tconst canvasRef = useRef<HTMLCanvasElement | null>(null);\n\tconst mediaRecorderRef = useRef<MediaRecorder | null>(null);\n\tconst recordedBlobsRef = useRef<Blob[] | null>([]);\n\tconst streamRef = useRef<MediaStream | null>(null);\n\tconst [showLoader, setShowLoader] = useState(false);\n\tconst [modelReady, setModelReady] = useState(false);\n\tconst [isScanning, setIsScanning] = useState(false);\n\tconst [showGuideCard, setShowGuideCard] = useState(true);\n\tconst [videoLoading, setVideoLoading] = useState(false);\n\tconst [videoError, setVideoError] = useState(false);\n\tconst [hasError, setHasError] = useState(false);\n\tconst [faceScanId, setFaceScanId] = useState(generateUuid());\n\tconst { email, gender, deviceFocalLength, shopDomain, callbackUrl } = userDetails;\n\tconst [supportedTypes, setSupportedTypes] = useState<string[]>([]);\n\t// const supportedTypes = useMemo(() => videoTypes.filter((type) => MediaRecorder.isTypeSupported(type)), []);\n\t\n\tconst stopRecording = useCallback(() => {\n\t\tconsole.log(\"Stopping recording...\");\n\t\tif (mediaRecorderRef.current && mediaRecorderRef.current.state === \"recording\") {\n\t\t\tmediaRecorderRef.current.stop();\n\t\t}\n\t\tmediaRecorderRef.current = null;\n\t}, []);\n\n\tconst uploadFinalVideo = async () => {\n\t\tsetShowLoader(true);\n\t\tif (recordedBlobsRef.current) {\n\t\t\tif (recordedBlobsRef.current.length === 0) {\n\t\t\t\tconsole.error(\"No video data recorded\");\n\t\t\t\tsetHasError(true);\n\t\t\t\tsetShowLoader(false);\n\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst videoFile = new File(recordedBlobsRef.current, `${faceScanId}.webm`, {\n\t\t\t\ttype: \"video/webm\",\n\t\t\t});\n\t\t\tconst fileSize = videoFile.size;\n\t\t\tconst fileSizeMB = (fileSize / (1024 * 1024)).toFixed(2);\n\t\t\tconst estimatedDuration = Math.round(fileSize / 10000);\n\t\t\tconst videoData = {\n\t\t\t\tvideo_size_mb: parseFloat(fileSizeMB),\n\t\t\t\tvideo_size_bytes: fileSize,\n\t\t\t\tblob_count: recordedBlobsRef.current.length,\n\t\t\t\testimated_duration_seconds: estimatedDuration,\n\t\t\t};\n\n\t\t\tconst metaData = [\n\t\t\t\t{ gender: gender },\n\t\t\t\t{ face_scan_id: faceScanId },\n\t\t\t\t{\n\t\t\t\t\tfocal_length: `${deviceFocalLength}`,\n\t\t\t\t},\n\t\t\t\t{ customer_store_url: shopDomain },\n\t\t\t\t{ scan_type: \"face_scan\" },\n\t\t\t\t{ callback_url: callbackUrl || \"https://example.com/webhook\" },\n\t\t\t];\n\t\t\tconsole.log(metaData,\"metadat\");\n\t\t\t\n\t\t\thandleScanTimeCapture({\n\t\t\t\teventName: `${shopDomain}/face_scan_meta_data`,\n\t\t\t\tfaceScanId,\n\t\t\t\temail,\n\t\t\t\tdata: JSON.stringify({ metaData, videoData }),\n\t\t\t});\n\n\t\t\tconst uploadStartTime = Date.now();\n\t\t\thandleScanTimeCapture({\n\t\t\t\teventName: `${shopDomain}/face_scan_upload_start`,\n\t\t\t\tfaceScanId,\n\t\t\t\temail,\n\t\t\t\tstartTime: uploadStartTime,\n\t\t\t});\n\n\t\t\ttry {\n\t\t\t\tconst res = await swan.fileUpload.faceScanFileUploader({\n\t\t\t\t\tfile: videoFile,\n\t\t\t\t\tarrayMetaData: metaData,\n\t\t\t\t\tobjectKey: faceScanId,\n\t\t\t\t\temail,\n\t\t\t\t\tcontentType: videoFile.type,\n\t\t\t\t});\n\n\t\t\t\tconst uploadEndTime = Date.now();\n\t\t\t\tconst uploadDuration = uploadEndTime - uploadStartTime;\n\n\t\t\t\thandleScanTimeCapture({\n\t\t\t\t\teventName: `${shopDomain}/face_scan_upload_complete`,\n\t\t\t\t\tfaceScanId,\n\t\t\t\t\temail,\n\t\t\t\t\tcompletionTime: uploadEndTime,\n\t\t\t\t\tuploadDuration,\n\t\t\t\t});\n\n\t\t\t\tconsole.log(\"✅ Upload successful\", res);\n\t\t\t\tswan.measurement.handlFaceScaneSocket({\n\t\t\t\t\tfaceScanId,\n\t\t\t\t\tonOpen: () => {\n\t\t\t\t\t\thandleWebSocketCapture({\n\t\t\t\t\t\t\teventName: `${shopDomain}/webSocket`,\n\t\t\t\t\t\t\tfaceScanID: faceScanId,\n\t\t\t\t\t\t\tconnection: \"open\",\n\t\t\t\t\t\t\ttype: \"faceScan_recommendation\",\n\t\t\t\t\t\t\temail,\n\t\t\t\t\t\t});\n\t\t\t\t\t\tconsole.log(\"websocket connect open\");\n\t\t\t\t\t},\n\t\t\t\t\tonError: (err) => {\n\t\t\t\t\t\thandleWebSocketCapture({\n\t\t\t\t\t\t\teventName: `${shopDomain}/webSocket`,\n\t\t\t\t\t\t\tfaceScanID: faceScanId,\n\t\t\t\t\t\t\tconnection: \"error\",\n\t\t\t\t\t\t\ttype: \"faceScan_recommendation\",\n\t\t\t\t\t\t\temail,\n\t\t\t\t\t\t});\n\t\t\t\t\t\tonError(err);\n\t\t\t\t\t},\n\t\t\t\t\tonSuccess: (data) => {\n\t\t\t\t\t\thandleWebSocketCapture({\n\t\t\t\t\t\t\teventName: `${shopDomain}/webSocket`,\n\t\t\t\t\t\t\tfaceScanID: faceScanId,\n\t\t\t\t\t\t\tconnection: \"success\",\n\t\t\t\t\t\t\ttype: \"faceScan_recommendation\",\n\t\t\t\t\t\t\temail,\n\t\t\t\t\t\t});\n\t\t\t\t\t\tonSuccess(data);\n\t\t\t\t\t},\n\t\t\t\t\tonClose: () => {\n\t\t\t\t\t\tconsole.log(\"websocket connect close\");\n\t\t\t\t\t\thandleWebSocketCapture({\n\t\t\t\t\t\t\teventName: `${shopDomain}/webSocket`,\n\t\t\t\t\t\t\tfaceScanID: faceScanId,\n\t\t\t\t\t\t\tconnection: \"close\",\n\t\t\t\t\t\t\ttype: \"faceScan_recommendation\",\n\t\t\t\t\t\t\temail,\n\t\t\t\t\t\t});\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t} catch (error) {\n\t\t\t\tonError(error);\n\t\t\t}\n\t\t}\n\t};\n\n\tconst startRecording = useCallback(() => {\n\t\tconsole.log(\"Starting recording for stages 1-3...\");\n\t\tconst stream = webcamRef.current?.srcObject as MediaStream | null;\n\t\tif (!stream) return;\n\n\t\t// Create a canvas to normalize orientation\n\t\tconst videoTrack = stream.getVideoTracks()[0];\n\t\tconst settings = videoTrack.getSettings();\n\t\tconst { width = videoConstraints.width, height = videoConstraints.height } = settings;\n\n\t\tconst canvas = document.createElement(\"canvas\");\n\t\tconst ctx = canvas.getContext(\"2d\");\n\n\t\t// Always force portrait (swap width/height if landscape)\n\t\tif (width > height) {\n\t\t\tcanvas.width = height;\n\t\t\tcanvas.height = width;\n\t\t} else {\n\t\t\tcanvas.width = width;\n\t\t\tcanvas.height = height;\n\t\t}\n\n\t\tconst videoEl = document.createElement(\"video\");\n\t\tvideoEl.srcObject = stream;\n\t\tvideoEl.muted = true;\n\t\tvideoEl.playsInline = true;\n\t\tvideoEl.play();\n\n\t\t// Draw video frames onto canvas\n\t\tconst drawFrame = () => {\n\t\t\t// Rotate if camera gives landscape frames\n\t\t\tif (width > height) {\n\t\t\t\tctx?.save();\n\t\t\t\tctx?.translate(canvas.width, 0);\n\t\t\t\tctx?.rotate(Math.PI / 2);\n\t\t\t\tctx?.drawImage(videoEl, 0, 0, height, width);\n\t\t\t\tctx?.restore();\n\t\t\t} else {\n\t\t\t\tctx?.drawImage(videoEl, 0, 0, width, height);\n\t\t\t}\n\t\t\trequestAnimationFrame(drawFrame);\n\t\t};\n\t\tdrawFrame();\n\n\t\tconst canvasStream = canvas.captureStream(30); // 30fps\n\t\tconst mediaRecorderOptions = supportedTypes.length > 0 ? { mimeType: supportedTypes[0] } : {};\n\t\tlet mediaRecorder;\n\n\t\ttry {\n\t\t\tmediaRecorder = new MediaRecorder(canvasStream, mediaRecorderOptions);\n\t\t} catch (e) {\n\t\t\tconsole.error(\"MediaRecorder init failed:\", e);\n\t\t\tsetHasError(true);\n\t\t\tsetShowLoader(false);\n\t\t\treturn;\n\t\t}\n\n\t\trecordedBlobsRef.current = [];\n\t\tmediaRecorder.ondataavailable = (event) => {\n\t\t\tif (event?.data && event.data.size > 0 && recordedBlobsRef.current) {\n\t\t\t\trecordedBlobsRef.current.push(event.data);\n\t\t\t}\n\t\t};\n\t\tmediaRecorder.onstop = () => {\n\t\t\tconsole.log(\"Recording stopped, total blobs:\", recordedBlobsRef?.current?.length);\n\t\t\tuploadFinalVideo();\n\t\t};\n\n\t\tmediaRecorder.start(100); // 100ms chunks\n\t\tmediaRecorderRef.current = mediaRecorder;\n\t\tconsole.log(\"Recording started successfully (portrait normalized)\");\n\t}, [supportedTypes, uploadFinalVideo]);\n\n\tconst { faceScanDetector, scanStage, setScanStage, resetScan, isModelLoaded, startScanSequence } = useFaceScan({\n\t\tfaceScanId,\n\t\tshopDomain,\n\t\tonScanComplete: () => {\n\t\t\tstopRecording();\n\t\t},\n\t\tonModelReady: () => {\n\t\t\tsetModelReady(true);\n\t\t},\n\t\tonStartRecording: () => {\n\t\t\tconsole.log(\"Stage 0 completed - starting recording for stages 1-3\");\n\t\t\tstartRecording();\n\t\t},\n\t});\n\n\tconst startScan = useCallback(() => {\n\t\tif (!isModelLoaded) return;\n\t\tsetScanStage(0);\n\t\tspeechService.playAudio(`${voiceOverAssetsPath}face-scan-vos/Face-forward.mp3`);\n\t\tsetTimeout(() => {\n\t\t\tsetIsScanning(true);\n\t\t\tsetTimeout(() => {\n\t\t\t\tstartScanSequence();\n\t\t\t}, 200);\n\t\t}, 200);\n\t}, [setScanStage, setIsScanning, startScanSequence, isModelLoaded]);\n\n\tconst resetScanState = useCallback(() => {\n\t\tsetIsScanning(false);\n\t\tsetShowGuideCard(true);\n\t\tstopRecording();\n\t\tresetScan();\n\t\tonRetry?.();\n\t\trecordedBlobsRef.current = [];\n\t\tif (mediaRecorderRef.current) {\n\t\t\tmediaRecorderRef.current = null;\n\t\t}\n\t\tsetHasError(false);\n\t\tsetScanStage(-1);\n\t\tsetFaceScanId(generateUuid());\n\t\tif (webcamRef.current && streamRef.current) {\n\t\t\twebcamRef.current.srcObject = streamRef.current;\n\t\t\tconsole.log(\"Camera stream restored after reset\");\n\t\t}\n\t}, [setScanStage, setIsScanning, setShowGuideCard, stopRecording, resetScan, setFaceScanId]);\n\n\tconst onError = (data: any) => {\n\t\tconsole.log(data, \"ws error\");\n\t\tonScanError?.(data);\n\t\tsetHasError(true);\n\t\tsetShowLoader(false);\n\t\tsetShowGuideCard(false);\n\t\thandleScanTimeCapture({\n\t\t\teventName: `${shopDomain}/faceScan`,\n\t\t\tfaceScanId,\n\t\t\tstatus: \"failed\",\n\t\t\temail,\n\t\t\tdata: JSON.stringify(data),\n\t\t});\n\t};\n\n\tconst onSuccess = (data: any) => {\n\t\tconsole.log(data, \"ws success\");\n\t\tif (data && data?.resultType === \"intermediate\") {\n\t\t\thandleScanTimeCapture({\n\t\t\t\teventName: `${shopDomain}/faceScan_success/intermediate`,\n\t\t\t\tfaceScanId,\n\t\t\t\tstatus: \"success\",\n\t\t\t\temail,\n\t\t\t\tdata: JSON.stringify(data),\n\t\t\t});\n\t\t}\n\t\tonScanSuccess?.(data);\n\t};\n\n\tuseEffect(() => {\n\t\tif (isError || isSuccess) return;\n\t\tif (navigator.mediaDevices.getUserMedia) {\n\t\t\tnavigator.mediaDevices\n\t\t\t\t.getUserMedia({ video: videoConstraints })\n\t\t\t\t.then((stream) => {\n\t\t\t\t\tstreamRef.current = stream;\n\t\t\t\t\tif (webcamRef.current) {\n\t\t\t\t\t\twebcamRef.current.srcObject = stream;\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\t\t.catch((err) => console.error(\"Error accessing webcam:\", err));\n\t\t}\n\t\treturn () => {\n\t\t\tif (streamRef.current) {\n\t\t\t\tstreamRef.current.getTracks().forEach((track) => track.stop());\n\t\t\t}\n\t\t};\n\t}, [isError, isSuccess]);\n\n\t// Face detection interval - only run when scanning is active\n\tuseEffect(() => {\n\t\tif (!modelReady || !isScanning) return;\n\t\tconst intervalId = setInterval(() => {\n\t\t\tfaceScanDetector(webcamRef, canvasRef);\n\t\t}, 500);\n\n\t\t// eslint-disable-next-line consistent-return\n\t\treturn () => clearInterval(intervalId);\n\t}, [faceScanDetector, modelReady, isScanning]);\n\n\tconst getButtonText = () => {\n\t\tif (isScanning) return LanguageKeys.reset;\n\t\tif (!isModelLoaded) return LanguageKeys.loading;\n\t\treturn LanguageKeys.start;\n\t};\n\n\tconsole.log(\"Model ready:\", modelReady, \"Has error:\", hasError, \"Is scanning:\", isScanning, \"showLoader\", showLoader);\n\tuseEffect(() => {\n\t\tif (typeof MediaRecorder !== \"undefined\") {\n\t\t\tconst supported = videoTypes.filter((type) => MediaRecorder.isTypeSupported(type));\n\t\t\tsetSupportedTypes(supported);\n\t\t}\n\t}, []);\n\tuseEffect(() => {\n\t\tsetScanStage(-1);\n\t\tif (isError || isSuccess) return;\n\t}, [isError, isSuccess]);\n\n\tuseEffect(() => {\n\t\tposthog.init(posthogPublicKey, { api_host: posthogPublicHost });\n\t\tposthog.capture(\"$pageview\");\n\t}, []);\n\n return (\n\t\t<LanguageContextProvider>\n\t\t\t<ParamsContext.Provider value={{isError,isSuccess,showLoader,hasError,resetScanState,showGuideCard,scanStage,videoLoading,setVideoLoading,videoError,setVideoError,gender,getButtonText,isScanning,startScan,isModelLoaded,config}}>\n\t\t\t<FaceScanStep webcamRef={webcamRef} canvasRef={canvasRef}/>\n\t\t\t</ParamsContext.Provider>\n\t\t</LanguageContextProvider>\n\t )\n};\n"],"names":["preloadedDetector","isPreloading","useFaceScan","faceScanId","onValidPose","onScanComplete","onModelReady","onStartRecording","shopDomain","detectorRef","useRef","scanStage","setScanStage","useState","consecutiveValid","setConsecutiveValid","isModelLoaded","setIsModelLoaded","isScanningActive","setIsScanningActive","utteranceRef","scanStageRef","consecutiveValidRef","validityBufferRef","lastSpokenMessageRef","lastSpokenTimeRef","voiceEnabledRef","lastPoseTrackingTimeRef","isIOS","navigator","test","userAgent","platform","maxTouchPoints","directionMessages","useMemo","debouncedTrackPoseDetection","fn","delay","timer","args","clearTimeout","setTimeout","debounce","payload","posthog","capture","trackPoseDetection","useCallback","faceKeypoints","bodyKeypoints","stage","headValid","bodyInvalid","consecutiveValidCount","now","Date","current","nose","leftEye","rightEye","leftMouth","rightMouth","faceKeypointScores","map","kp","filter","score","avgFaceScore","length","reduce","a","b","bodyKeypointScores","avgBodyScore","eyeDistance","Math","abs","noseToRight","noseToLeft","expectedPosition","timestamp","toISOString","data","JSON","stringify","parseFloat","toFixed","faceKeypointsDetected","bodyKeypointsDetected","noseToRightRatio","noseToLeftRatio","noseScore","leftEyeScore","rightEyeScore","leftMouthScore","rightMouthScore","error","console","warn","startScanSequence","stageName","initializeModels","async","window","log","detector","Promise","r","tf","poseDetection","all","import","setBackend","ready","createDetector","SupportedModels","BlazePose","runtime","modelType","dummyCanvas","document","createElement","width","videoConstraints","height","ctx","getContext","fillStyle","fillRect","estimatePoses","e","err","preloadDetector","useEffect","disposeModelAndTf","faceScanDetector","webcamRef","canvasRef","readyState","poses","keypoints","forEach","landmark","idx","point","x","y","push","clearRect","progress","min","radius","beginPath","strokeStyle","lineWidth","arc","PI","stroke","eyesToMouthVerticalDistance","faceTiltedness","faceIsTilted","faceIsVertical","frontalFace","fullLeft","fullRight","isHeadInPosition","slice","p","shift","Boolean","nextValid","max","nextStage","speechService","playAudio","voiceOverAssetsPath","completedStage","totalStages","nextSound","resetScan","speechSynthesis","cancel","enableVoiceCommands","silentUtterance","SpeechSynthesisUtterance","volume","speak","FaceScanErrorScreen","resetScanState","loading","config","translate","preferredLanguage","useContext","LanguageContext","LanguageKeys","scanFailed","_jsx","className","style","background","base","backgroundColor","children","_jsxs","Header","noTitle","resolvedConfig","fontFamily","heading","headingFontFamily","fontSize","headingFontSize","color","headingColor","fontWeight","headingFontWeight","subheading","subheadingFontFamily","subheadingFontSize","subheadingColor","subheadingFontWeight","clickToResetScan","SpecificButton","disabled","buttonText","postfixIcon","ArrowRight","buttonFunc","FaceScanGuide","videoLoading","setVideoLoading","videoError","setVideoError","gender","btnConfig","faceVisible","loadingVideo","videoLoadFailed","src","GenderType","Male","maleGlassesOffVideo","glassesOffVideo","autoPlay","loop","controls","muted","playsInline","onCanPlay","onLoadStart","onError","isDisabled","label","icon","onClick","FACE_SCAN_HEADSHOT","male","forward","female","type","left","right","smile","FaceScanStep","isError","isSuccess","showLoader","hasError","showGuideCard","getButtonText","isScanning","startScan","ParamsContext","useLocalConfig","setPreferredLanguage","language","LoadingScreen","url","loader","loaderType","_Fragment","id","crossOrigin","preload","position","zIndex","undefined","ref","transform","opacity","Drawer","open","anchor","onClose","event","reason","hideBackdrop","FaceScan","userDetails","onScanSuccess","onScanError","onRetry","mediaRecorderRef","recordedBlobsRef","streamRef","setShowLoader","modelReady","setModelReady","setIsScanning","setShowGuideCard","setHasError","setFaceScanId","generateUuid","email","deviceFocalLength","callbackUrl","supportedTypes","setSupportedTypes","stopRecording","state","stop","uploadFinalVideo","videoFile","File","fileSize","size","fileSizeMB","estimatedDuration","round","videoData","video_size_mb","video_size_bytes","blob_count","estimated_duration_seconds","metaData","face_scan_id","focal_length","customer_store_url","scan_type","callback_url","handleScanTimeCapture","eventName","uploadStartTime","startTime","res","swan","fileUpload","faceScanFileUploader","file","arrayMetaData","objectKey","contentType","uploadEndTime","completionTime","uploadDuration","measurement","handlFaceScaneSocket","onOpen","handleWebSocketCapture","faceScanID","connection","onSuccess","startRecording","stream","srcObject","settings","getVideoTracks","getSettings","canvas","videoEl","play","drawFrame","save","rotate","drawImage","restore","requestAnimationFrame","canvasStream","captureStream","mediaRecorderOptions","mimeType","mediaRecorder","MediaRecorder","ondataavailable","onstop","start","status","resultType","mediaDevices","getUserMedia","video","then","catch","getTracks","track","intervalId","setInterval","clearInterval","supported","videoTypes","isTypeSupported","init","posthogPublicKey","api_host","posthogPublicHost","LanguageContextProvider","Provider","value","reset"],"mappings":"6eA6BA,IAAIA,EAAyC,KACzCC,GAAe,EAiEnB,SAASC,GAAYC,WACnBA,EAAUC,YACVA,EAAWC,eACXA,EAAcC,aACdA,EAAYC,iBACZA,EAAgBC,WAChBA,IASA,MAAMC,EAAcC,EAA4B,OACzCC,EAAWC,GAAgBC,EAAS,IACpCC,EAAkBC,GAAuBF,EAAS,IAClDG,EAAeC,GAAoBJ,GAAS,IAC5CK,EAAkBC,GAAuBN,GAAS,GAEnDO,EAAeV,EAAwC,MACvDW,EAAeX,EAAOC,GACtBW,EAAsBZ,EAAOI,GAC7BS,EAAoBb,EAAkB,IACtCc,EAAuBd,EAAO,IAC9Be,EAAoBf,EAAO,GAC3BgB,EAAkBhB,GAAO,GAMzBiB,EAA0BjB,EAAO,GAGjCkB,EAA6B,oBAAdC,YACnB,mBAAmBC,KAAKD,UAAUE,YACV,aAAvBF,UAAUG,UAA2BH,UAAUI,eAAiB,GAG7DC,EAAoBC,EACxB,IAAM,CACJ,aACA,uBACA,wBACA,sBAEF,IAGIC,EAA8BD,EAClC,IA/HJ,SAAkBE,EAA4BC,GAC5C,IAAIC,EACJ,MAAO,IAAIC,KACLD,GAAOE,aAAaF,GACxBA,EAAQG,WAAW,IAAML,KAAMG,GAAOF,GAE1C,CA0HMK,CAAUC,IACRC,EAAQC,QAAQ,GAAGtC,6BAAuCoC,IACzD,KACL,CAACpC,IAGGuC,EAAqBC,EACzB,CACEC,EACAC,EACAC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AUzP,QAAQkV,YAAY7P,QAAS8P,GAAUA,EAAM1E,UAGvD,CAACxD,EAASC,IAGbrI,EAAU,KACT,IAAK8K,IAAepC,EAAY,OAChC,MAAM6H,EAAaC,YAAY,KAC9BtQ,GAAiBC,EAAWC,IAC1B,KAGH,MAAO,IAAMqQ,cAAcF,IACzB,CAACrQ,GAAkB4K,EAAYpC,IAyB9B,OAjBJ9K,QAAQO,IAAI,eAAgB2M,EAAY,aAAcvC,EAAU,eAAgBG,EAAY,aAAcJ,GAC1GtI,EAAU,KACT,GAA6B,oBAAlB0P,cAA+B,CACzC,MAAMgB,EAAYC,EAAW/U,OAAQmM,GAAS2H,cAAckB,gBAAgB7I,IAC5E0D,GAAkBiF,EACnB,GACE,IACH1Q,EAAU,KACT1H,IAAa,IAEX,CAAC8P,EAASC,IAEbrI,EAAU,KACTzF,EAAQsW,KAAKC,EAAkB,CAAEC,SAAUC,IAC3CzW,EAAQC,QAAQ,cACd,IAGFwJ,EAACiN,EAAuB,CAAA3M,SACvBN,EAAC4E,EAAcsI,SAAQ,CAACC,MAAO,CAAC/I,UAAQC,YAAUC,aAAWC,WAAShF,kBAAeiF,gBAAcnQ,aAAU4N,eAAaC,kBAAgBC,aAAWC,gBAAcC,SAAOoC,cAzBtJ,IACjBC,EAAmB5E,EAAasN,MAC/B1Y,GACEoL,EAAa+L,MADO/L,EAAaN,QAuBiJkF,aAAWC,aAAUjQ,iBAAc+K,UAAOa,SAClON,EAACmE,EAAY,CAAChI,UAAWA,EAAWC,UAAWA"}
@@ -1,2 +1,2 @@
1
- "use strict";var e=require("react/jsx-runtime"),t=require("react"),a=require("posthog-js"),n=require("./LoadingScreen-vewtx75y.js"),o=require("lucide-react"),s=require("@mui/material");let r=null,c=!1;function i({faceScanId:e,onValidPose:o,onScanComplete:s,onModelReady:i,onStartRecording:l,shopDomain:d}){const u=t.useRef(null),[g,f]=t.useState(0),[h,m]=t.useState(0),[p,y]=t.useState(!1),[S,x]=t.useState(!1),v=t.useRef(null),b=t.useRef(g),w=t.useRef(h),F=t.useRef([]),C=t.useRef(""),j=t.useRef(0),_=t.useRef(!1),N=t.useRef(0),E="undefined"!=typeof navigator&&(/iPad|iPhone|iPod/.test(navigator.userAgent)||"MacIntel"===navigator.platform&&navigator.maxTouchPoints>1),T=t.useMemo(()=>["Face front","Turn head fully left","Turn head fully right","Smile facing front"],[]),I=t.useMemo(()=>function(e,t){let a;return(...n)=>{a&&clearTimeout(a),a=setTimeout(()=>e(...n),t)}}(e=>{a.posthog.capture(`${d}/face_scan_pose_detection`,e)},4e3),[d]),k=t.useCallback((t,a,n,o,s,r)=>{const c=Date.now();if(!(c-N.current<4e3)){N.current=c;try{const c=t[0]||[0,0,0],i=t[2]||[0,0,0],l=t[5]||[0,0,0],d=t[9]||[0,0,0],u=t[10]||[0,0,0],g=t.map(e=>e[2]).filter(e=>e>0),f=g.length>0?g.reduce((e,t)=>e+t,0)/g.length:0,h=a.map(e=>e[2]).filter(e=>e>0),m=h.length>0?h.reduce((e,t)=>e+t,0)/h.length:0,p=Math.abs(i[0]-l[0]),y=c[0]-l[0],S=i[0]-c[0];let x="frontal";1===n?x="left":2===n?x="right":3===n&&(x="frontal_smile");const v={faceScanId:e,stage:n,timestamp:(new Date).toISOString(),data:JSON.stringify({headValid:o,bodyInvalid:s,consecutiveValid:r,avgFaceScore:parseFloat(f.toFixed(3)),avgBodyScore:parseFloat(m.toFixed(3)),faceKeypointsDetected:g.length,bodyKeypointsDetected:h.length,eyeDistance:parseFloat(p.toFixed(2)),noseToRightRatio:parseFloat((y/p).toFixed(3)),noseToLeftRatio:parseFloat((S/p).toFixed(3)),noseScore:parseFloat(c[2].toFixed(3)),leftEyeScore:parseFloat(i[2].toFixed(3)),rightEyeScore:parseFloat(l[2].toFixed(3)),leftMouthScore:parseFloat(d[2].toFixed(3)),rightMouthScore:parseFloat(u[2].toFixed(3)),expectedPosition:x})};I(v)}catch(e){console.warn("Failed to track pose detection:",e)}}},[e,I]),L=()=>{a.posthog.capture(`${d}/face_scan_detection_started`,{faceScanId:e,stage:b.current,timestamp:(new Date).toISOString(),stageName:T[b.current]}),setTimeout(()=>{x(!0)},1500)},D=async()=>{if("undefined"!=typeof window)try{console.log("Initializing Face Scan...");const e=await(async()=>{if("undefined"==typeof window)return null;if(r)return r;if(c)for(;c;)if(await new Promise(e=>setTimeout(e,100)),r)return r;c=!0;try{const[e,t]=await Promise.all([import("@tensorflow/tfjs"),Promise.resolve().then(function(){return require("./pose-detection.esm-DouwBFG2.js")})]);await e.setBackend("webgl"),await e.ready();const a=await t.createDetector(t.SupportedModels.BlazePose,{runtime:"tfjs",modelType:"full"}),o=document.createElement("canvas");o.width=n.videoConstraints.width,o.height=n.videoConstraints.height;const s=o.getContext("2d");if(s){s.fillStyle="black",s.fillRect(0,0,o.width,o.height);try{await a.estimatePoses(o)}catch(e){console.warn("Warmup frame failed (non-fatal):",e)}}return r=a,a}catch(e){return console.error("Failed to preload detector:",e),null}finally{c=!1}})();e&&(u.current=e,console.log("Face scan model loaded successfully"),y(!0),i?.())}catch(e){console.error("Error initializing face scan:",e)}};return t.useEffect(()=>(D(),()=>{(async()=>{try{y(!1)}catch(e){console.error("Error disposing resources:",e)}finally{f(0),m(0),b.current=0,w.current=0,F.current=[]}})()}),[]),t.useEffect(()=>{b.current=g},[g]),t.useEffect(()=>{w.current=h},[h]),{faceScanDetector:async(t,r)=>{if(u.current&&t.current&&p&&S&&!(t.current.readyState<2))try{const c=await u.current.estimatePoses(t.current);if(c.length>0){const t=[],i=[];if(c[0].keypoints.forEach((e,a)=>{const n=e.score??0,o=[e.x??-1,e.y??-1,n];a<=10?t.push(o):i.push(o)}),r?.current){const e=r.current.getContext("2d"),{width:t,height:a}=r.current;if(e){e.clearRect(0,0,t,a);const n=Math.min(w.current/2,1),o=.35*a;e.beginPath(),e.strokeStyle="#00ff00",e.lineWidth=6,e.arc(t/2,a/2,o+10,-Math.PI/2,-Math.PI/2+2*n*Math.PI),e.stroke()}}const u=((e,t)=>{if(!t[0]||!t[2]||!t[5]||t[0][2]<.2||t[2][2]<.2||t[5][2]<.2)return!1;const a=.5*(t[10][1]+t[9][1])-.5*(t[5][1]+t[2][1]),n=(.5*(t[10][1]+t[9][1])-t[0][1])/a,o=n>.7||n<.3,s=Math.abs(t[2][1]-t[5][1])<.5*a&&Math.abs(t[9][1]-t[10][1])<.5*a,r=t[2][0]-t[5][0],c=t[0][0]-t[5][0],i=c>.4*r&&c<.6*r,l=c>.85*r,d=t[2][0]-t[0][0]>.85*r;switch(e){case 0:case 3:return!o&&s&&i;case 1:return!o&&s&&l;case 2:return!o&&s&&d;default:return!1}})(b.current,t),g=i.slice(2).filter(e=>e[2]>.7).length<=2;F.current.push(u&&g),F.current.length>10&&F.current.shift();if(F.current.filter(Boolean).length>=2){const e=w.current+1;m(e)}else m(Math.max(0,w.current-1));if(w.current>=2){o?.();const t=b.current+1;m(0),F.current=[],f(t),x(!1),(async()=>{if(await n.speechService.playAudio(`${n.voiceOverAssetsPath}face-scan-vos/Sound-effect.mp3`),a.posthog.capture(`${d}/face_scan_detection_stage_completed`,{faceScanId:e,completedStage:b.current,nextStage:t,timestamp:(new Date).toISOString(),totalStages:4,stageName:T[b.current]}),1===t&&l&&l(),t>=4)s?.();else{let e=null;switch(t){case 1:e="Left.mp3";break;case 2:e="Right.mp3";break;case 3:e="Smile.mp3"}e&&await n.speechService.playAudio(`${n.voiceOverAssetsPath}face-scan-vos/${e}`),L()}})()}k(t,i,b.current,u,g,w.current)}}catch(e){console.error("Pose detection error:",e)}},scanStage:g,setScanStage:f,consecutiveValid:h,isModelLoaded:p,resetScan:()=>{a.posthog.capture(`${d}/face_scan_reset`,{faceScanId:e,stage:b.current,timestamp:(new Date).toISOString(),stageName:T[b.current],consecutiveValid:w.current}),f(0),m(0),x(!1),b.current=0,w.current=0,F.current=[],C.current="",j.current=0,_.current=!1,v.current&&(speechSynthesis.cancel(),v.current=null)},enableVoiceCommands:()=>{if(_.current=!0,"undefined"!=typeof window&&E&&"speechSynthesis"in window){const e=new SpeechSynthesisUtterance("");e.volume=0,speechSynthesis.speak(e)}},startScanSequence:L,isScanningActive:S}}function l({resetScanState:a,loading:s,config:r}){const{translate:c,preferredLanguage:i}=t.useContext(n.LanguageContext)||{};return console.log(i,"preferredLanguage"),console.log(c?.(n.LanguageKeys.scanFailed),"translate"),e.jsx("div",{className:"fixed top-[0] left-[0] z-[999] flex justify-center items-center w-full h-full",style:{background:r?.style?.base?.backgroundColor},children:e.jsxs("div",{className:"flex flex-col w-full items-center p-[1rem] rounded-lg ",children:[e.jsx(n.Header,{noTitle:!0,resolvedConfig:r}),e.jsxs("div",{className:"flex flex-col items-center w-full",children:[e.jsx("h2",{className:"text-xl font-semibold text-gray-800 ",style:{fontFamily:r?.style?.heading?.headingFontFamily||"SeriouslyNostalgic Fn",fontSize:r?.style?.heading?.headingFontSize||"32px",color:r?.style?.heading?.headingColor||"#000",fontWeight:r?.style?.heading?.headingFontWeight||"normal"},children:c?.(n.LanguageKeys.scanFailed)}),e.jsx("p",{className:"mb-[1.5rem]",style:{fontFamily:r?.style?.subheading?.subheadingFontFamily||"'Inter', sans-serif",fontSize:r?.style?.subheading?.subheadingFontSize||"14px",color:r?.style?.subheading?.subheadingColor||"#4b5563",fontWeight:r?.style?.subheading?.subheadingFontWeight||"normal"},children:c?.(n.LanguageKeys.clickToResetScan)}),e.jsx(n.SpecificButton,{disabled:s,className:"w-full h-[45px] shadow-[0px_1px_2px_0px_#00000040] text-[16px]",buttonText:c?.(n.LanguageKeys.resetScan),postfixIcon:e.jsx(o.ArrowRight,{}),buttonFunc:()=>a?.(),resolvedConfig:r})]})]})})}function d({stage:a,videoLoading:o,setVideoLoading:s,videoError:r,setVideoError:c,gender:i,config:l,btnConfig:d}){const{translate:u}=t.useContext(n.LanguageContext)||{};return-1===a?e.jsxs("div",{className:"text-center p-[16px] w-full h-full",style:{background:l?.style?.base?.backgroundColor},children:[e.jsxs("div",{className:"w-full",children:[e.jsx(n.Header,{noTitle:!0,resolvedConfig:l}),e.jsx("h2",{style:{fontFamily:l?.style?.heading?.headingFontFamily||"SeriouslyNostalgic Fn",fontSize:l?.style?.heading?.headingFontSize||"32px",color:l?.style?.heading?.headingColor||"#000",fontWeight:l?.style?.heading?.headingFontWeight||"normal"},children:u?.(n.LanguageKeys.faceVisible)}),o&&e.jsx("div",{className:"mb-4 flex items-center justify-center",style:{fontFamily:l?.style?.subheading?.subheadingFontFamily||"'Inter', sans-serif",fontSize:l?.style?.subheading?.subheadingFontSize||"14px",color:l?.style?.subheading?.subheadingColor||"#4b5563",fontWeight:l?.style?.subheading?.subheadingFontWeight||"normal"},children:u?.(n.LanguageKeys.loadingVideo)}),r&&e.jsx("div",{className:"mb-4 text-red-600",style:{fontFamily:l?.style?.subheading?.subheadingFontFamily||"'Inter', sans-serif",fontSize:l?.style?.subheading?.subheadingFontSize||"14px",color:"#ff0000",fontWeight:l?.style?.subheading?.subheadingFontWeight||"normal"},children:u?.(n.LanguageKeys.videoLoadFailed)}),!r&&e.jsx("div",{className:" w-[100px] mx-auto",children:e.jsx("video",{src:i===n.GenderType.Male?n.maleGlassesOffVideo:n.glassesOffVideo,autoPlay:!0,loop:!0,controls:!1,muted:!0,playsInline:!0,className:"h-full w-full object-contain border-none",onCanPlay:()=>s(!1),onLoadStart:()=>s(!0),onError:()=>c(!0),"aria-label":"Instructional video: Please remove your glasses before starting the scan."})})]}),e.jsx("div",{className:"flex justify-center w-full p-[1rem]",children:e.jsx(n.SpecificButton,{disabled:d.isDisabled,className:"!w-[60px] !h-[35px] !py-0 !px-0",buttonText:u?.(d.label),postfixIcon:d?.icon,buttonFunc:d.onClick,resolvedConfig:l})})]}):e.jsx("div",{className:"text-center p-[16px] w-full h-full",style:{background:l?.style?.base?.backgroundColor},children:e.jsxs("div",{className:"w-full",children:[e.jsx(n.Header,{noTitle:!0,resolvedConfig:l}),e.jsx("h3",{className:"mb-[0.5rem]",style:{fontFamily:l?.style?.heading?.headingFontFamily||"SeriouslyNostalgic Fn",fontSize:l?.style?.heading?.headingFontSize||"32px",color:l?.style?.heading?.headingColor||"#000",fontWeight:l?.style?.heading?.headingFontWeight||"normal"},children:u?.(n.directionMessages[a])}),e.jsxs("div",{className:"max-w-[400px] justify-center gap-1 mx-auto flex items-center",children:[e.jsx("div",{className:` w-[120px] overflow-hidden ${0===a?"opacity-100":"opacity-0 hidden"} `,children:e.jsx("video",{className:"h-full w-full object-contain border-none",muted:!0,loop:!0,autoPlay:!0,playsInline:!0,children:e.jsx("source",{src:i===n.GenderType.Male?n.FACE_SCAN_HEADSHOT.male.forward:n.FACE_SCAN_HEADSHOT.female.forward,type:"video/mp4"})})}),e.jsx("div",{className:` w-[120px] overflow-hidden ${1===a?"opacity-100":"opacity-0 hidden"} `,children:e.jsx("video",{className:"h-full w-full object-contain border-none",muted:!0,loop:!0,autoPlay:!0,playsInline:!0,children:e.jsx("source",{src:i===n.GenderType.Male?n.FACE_SCAN_HEADSHOT.male.left:n.FACE_SCAN_HEADSHOT.female.left,type:"video/mp4"})})}),e.jsx("div",{className:` w-[120px] overflow-hidden ${2===a?"opacity-100":"opacity-0 hidden"} `,children:e.jsx("video",{className:"h-full w-full object-contain border-none",muted:!0,loop:!0,autoPlay:!0,playsInline:!0,children:e.jsx("source",{src:i===n.GenderType.Male?n.FACE_SCAN_HEADSHOT.male.right:n.FACE_SCAN_HEADSHOT.female.right,type:"video/mp4"})})}),e.jsx("div",{className:` w-[120px] overflow-hidden ${3===a?"opacity-100":"opacity-0 hidden"} `,children:e.jsx("video",{className:"h-full w-full object-contain border-none",muted:!0,loop:!0,autoPlay:!0,playsInline:!0,children:e.jsx("source",{src:i===n.GenderType.Male?n.FACE_SCAN_HEADSHOT.male.smile:n.FACE_SCAN_HEADSHOT.female.smile,type:"video/mp4"})})})]})]})})}const u=({webcamRef:a,canvasRef:r})=>{const{isError:c,isSuccess:i,showLoader:u,hasError:g,resetScanState:f,showGuideCard:h,scanStage:m,videoLoading:p,setVideoLoading:y,videoError:S,setVideoError:x,gender:v,getButtonText:b,isScanning:w,startScan:F,isModelLoaded:C,config:j}=t.useContext(n.ParamsContext),_=n.useLocalConfig(j),{setPreferredLanguage:N}=t.useContext(n.LanguageContext)||{};return t.useEffect(()=>{N?.(_?.language)},[_]),c?e.jsx(l,{config:_}):i?e.jsx("div",{className:"fixed z-[9] w-full h-full",style:{background:_?.style?.base?.backgroundColor},children:e.jsx(n.LoadingScreen,{url:_?.loader,loaderType:"black"})}):e.jsxs(e.Fragment,{children:[e.jsx("audio",{id:"audioElement",crossOrigin:"anonymous",preload:"auto",style:{position:"absolute",zIndex:-99999},src:void 0}),!u&&g&&e.jsx(l,{loading:u,resetScanState:f,config:_}),e.jsx("div",{className:"h-full flex-col relative w-full flex justify-center items-center text-center rounded-t-[20px]",style:{background:_?.style?.base?.backgroundColor},children:e.jsx("div",{className:"flex-1 w-full max-w-md overflow-hidden",children:e.jsxs("div",{className:"w-full h-full",children:[e.jsx("video",{ref:a,autoPlay:!0,playsInline:!0,muted:!0,width:n.videoConstraints.width,height:n.videoConstraints.height,className:"w-full h-full object-cover fixed left-0 top-0 z-0",style:{transform:"scaleX(-1)"}}),e.jsx("canvas",{ref:r,width:n.videoConstraints.width,height:n.videoConstraints.height,style:{transform:"scaleX(-1)",opacity:"0"}})]})})}),!u&&g&&e.jsx(l,{loading:u,resetScanState:f,config:_}),h&&!g&&!u&&e.jsx(s.Drawer,{open:!0,className:"face-scan-small camera-draw",anchor:"bottom",onClose:(e,t)=>{},hideBackdrop:!0,children:e.jsx(d,{stage:m,videoLoading:p,setVideoLoading:y,videoError:S,setVideoError:x,gender:v,config:_,btnConfig:{label:b(),onClick:w?f:F,isDisabled:u||!C,icon:w?e.jsx(o.ArrowRight,{}):e.jsx(e.Fragment,{})}})})]})};exports.FaceScan=({userDetails:o,onScanSuccess:s,onScanError:r,onRetry:c,config:l,isError:d,isSuccess:g})=>{const f=t.useRef(null),h=t.useRef(null),m=t.useRef(null),p=t.useRef([]),y=t.useRef(null),[S,x]=t.useState(!1),[v,b]=t.useState(!1),[w,F]=t.useState(!1),[C,j]=t.useState(!0),[_,N]=t.useState(!1),[E,T]=t.useState(!1),[I,k]=t.useState(!1),[L,D]=t.useState(n.generateUuid()),{email:R,gender:M,deviceFocalLength:P,shopDomain:A,callbackUrl:O}=o,[z,$]=t.useState([]),H=t.useCallback(()=>{console.log("Stopping recording..."),m.current&&"recording"===m.current.state&&m.current.stop(),m.current=null},[]),V=async()=>{if(x(!0),console.log("upload final video"),p.current){if(0===p.current.length)return console.error("No video data recorded"),k(!0),void x(!1);const e=new File(p.current,`${L}.webm`,{type:"video/webm"}),t=e.size,a=(t/1048576).toFixed(2),o=Math.round(t/1e4),s={video_size_mb:parseFloat(a),video_size_bytes:t,blob_count:p.current.length,estimated_duration_seconds:o},r=[{gender:M},{face_scan_id:L},{focal_length:`${P}`},{customer_store_url:A},{scan_type:"face_scan"},{callback_url:O}];n.handleScanTimeCapture({eventName:`${A}/face_scan_meta_data`,faceScanId:L,email:R,data:JSON.stringify({metaData:r,videoData:s})});const c=Date.now();n.handleScanTimeCapture({eventName:`${A}/face_scan_upload_start`,faceScanId:L,email:R,startTime:c});try{const t=await n.swan.fileUpload.faceScanFileUploader({file:e,objectKey:L,email:R,arrayMetaData:r,contentType:e.type}),a=Date.now(),o=a-c;n.handleScanTimeCapture({eventName:`${A}/face_scan_upload_complete`,faceScanId:L,email:R,completionTime:a,uploadDuration:o}),console.log("✅ Upload successful",t),n.swan.measurement.handlFaceScaneSocket({faceScanId:L,onOpen:()=>{n.handleWebSocketCapture({eventName:`${A}/webSocket`,faceScanID:L,connection:"open",type:"faceScan_recommendation",email:R}),console.log("websocket connect open")},onError:e=>{n.handleWebSocketCapture({eventName:`${A}/webSocket`,faceScanID:L,connection:"error",type:"faceScan_recommendation",email:R}),Y(e)},onSuccess:e=>{n.handleWebSocketCapture({eventName:`${A}/webSocket`,faceScanID:L,connection:"success",type:"faceScan_recommendation",email:R}),Z(e)},onClose:()=>{console.log("websocket connect close"),n.handleWebSocketCapture({eventName:`${A}/webSocket`,faceScanID:L,connection:"close",type:"faceScan_recommendation",email:R})}})}catch(e){Y(e)}}},W=t.useCallback(()=>{console.log("Starting recording for stages 1-3...");const e=f.current?.srcObject;if(!e)return;const t=e.getVideoTracks()[0].getSettings(),{width:a=n.videoConstraints.width,height:o=n.videoConstraints.height}=t,s=document.createElement("canvas"),r=s.getContext("2d");a>o?(s.width=o,s.height=a):(s.width=a,s.height=o);const c=document.createElement("video");c.srcObject=e,c.muted=!0,c.playsInline=!0,c.play();const i=()=>{a>o?(r?.save(),r?.translate(s.width,0),r?.rotate(Math.PI/2),r?.drawImage(c,0,0,o,a),r?.restore()):r?.drawImage(c,0,0,a,o),requestAnimationFrame(i)};i();const l=s.captureStream(30),d=z.length>0?{mimeType:z[0]}:{};let u;try{u=new MediaRecorder(l,d)}catch(e){return console.error("MediaRecorder init failed:",e),k(!0),void x(!1)}p.current=[],u.ondataavailable=e=>{e?.data&&e.data.size>0&&p.current&&p.current.push(e.data)},u.onstop=()=>{console.log("Recording stopped, total blobs:",p?.current?.length),V()},u.start(100),m.current=u,console.log("Recording started successfully (portrait normalized)")},[z,V]),{faceScanDetector:K,scanStage:q,setScanStage:B,resetScan:U,isModelLoaded:G,startScanSequence:J}=i({faceScanId:L,shopDomain:A,onScanComplete:()=>{H()},onModelReady:()=>{b(!0)},onStartRecording:()=>{console.log("Stage 0 completed - starting recording for stages 1-3"),W()}}),X=t.useCallback(()=>{G&&(B(0),n.speechService.playAudio(`${n.voiceOverAssetsPath}face-scan-vos/Face-forward.mp3`),setTimeout(()=>{F(!0),setTimeout(()=>{J()},200)},200))},[B,F,J,G]),Q=t.useCallback(()=>{F(!1),j(!0),H(),U(),c?.(),p.current=[],m.current&&(m.current=null),k(!1),B(-1),D(n.generateUuid()),f.current&&y.current&&(f.current.srcObject=y.current,console.log("Camera stream restored after reset"))},[B,F,j,H,U,D]),Y=e=>{console.log(e,"ws error"),r?.(e),k(!0),x(!1),j(!1),n.handleScanTimeCapture({eventName:`${A}/faceScan`,faceScanId:L,status:"failed",email:R,data:JSON.stringify(e)})},Z=e=>{console.log(e,"ws success"),e&&"intermediate"===e?.resultType&&n.handleScanTimeCapture({eventName:`${A}/faceScan_success/intermediate`,faceScanId:L,status:"success",email:R,data:JSON.stringify(e)}),s?.(e)};t.useEffect(()=>{if(!d&&!g)return navigator.mediaDevices.getUserMedia&&navigator.mediaDevices.getUserMedia({video:n.videoConstraints}).then(e=>{y.current=e,f.current&&(f.current.srcObject=e)}).catch(e=>console.error("Error accessing webcam:",e)),()=>{y.current&&y.current.getTracks().forEach(e=>e.stop())}},[d,g]),t.useEffect(()=>{if(!v||!w)return;const e=setInterval(()=>{K(f,h)},500);return()=>clearInterval(e)},[K,v,w]);return console.log("Model ready:",v,"Has error:",I,"Is scanning:",w,"showLoader",S),t.useEffect(()=>{if("undefined"!=typeof MediaRecorder){const e=n.videoTypes.filter(e=>MediaRecorder.isTypeSupported(e));$(e)}},[]),t.useEffect(()=>{B(-1)},[d,g]),t.useEffect(()=>{a.init(n.posthogPublicKey,{api_host:n.posthogPublicHost}),a.capture("$pageview")},[]),e.jsx(n.LanguageContextProvider,{children:e.jsx(n.ParamsContext.Provider,{value:{isError:d,isSuccess:g,showLoader:S,hasError:I,resetScanState:Q,showGuideCard:C,scanStage:q,videoLoading:_,setVideoLoading:N,videoError:E,setVideoError:T,gender:M,getButtonText:()=>w?n.LanguageKeys.reset:G?n.LanguageKeys.start:n.LanguageKeys.loading,isScanning:w,startScan:X,isModelLoaded:G,config:l},children:e.jsx(u,{webcamRef:f,canvasRef:h})})})};
2
- //# sourceMappingURL=FaceScan-BmbbbsFP.js.map
1
+ "use strict";var e=require("react/jsx-runtime"),t=require("react"),a=require("posthog-js"),n=require("./LoadingScreen--G_kIDCD.js"),o=require("lucide-react"),s=require("@mui/material");let r=null,c=!1;function i({faceScanId:e,onValidPose:o,onScanComplete:s,onModelReady:i,onStartRecording:l,shopDomain:d}){const u=t.useRef(null),[g,f]=t.useState(0),[h,m]=t.useState(0),[p,y]=t.useState(!1),[S,x]=t.useState(!1),v=t.useRef(null),b=t.useRef(g),w=t.useRef(h),F=t.useRef([]),C=t.useRef(""),j=t.useRef(0),_=t.useRef(!1),N=t.useRef(0),E="undefined"!=typeof navigator&&(/iPad|iPhone|iPod/.test(navigator.userAgent)||"MacIntel"===navigator.platform&&navigator.maxTouchPoints>1),T=t.useMemo(()=>["Face front","Turn head fully left","Turn head fully right","Smile facing front"],[]),k=t.useMemo(()=>function(e,t){let a;return(...n)=>{a&&clearTimeout(a),a=setTimeout(()=>e(...n),t)}}(e=>{a.posthog.capture(`${d}/face_scan_pose_detection`,e)},4e3),[d]),I=t.useCallback((t,a,n,o,s,r)=>{const c=Date.now();if(!(c-N.current<4e3)){N.current=c;try{const c=t[0]||[0,0,0],i=t[2]||[0,0,0],l=t[5]||[0,0,0],d=t[9]||[0,0,0],u=t[10]||[0,0,0],g=t.map(e=>e[2]).filter(e=>e>0),f=g.length>0?g.reduce((e,t)=>e+t,0)/g.length:0,h=a.map(e=>e[2]).filter(e=>e>0),m=h.length>0?h.reduce((e,t)=>e+t,0)/h.length:0,p=Math.abs(i[0]-l[0]),y=c[0]-l[0],S=i[0]-c[0];let x="frontal";1===n?x="left":2===n?x="right":3===n&&(x="frontal_smile");const v={faceScanId:e,stage:n,timestamp:(new Date).toISOString(),data:JSON.stringify({headValid:o,bodyInvalid:s,consecutiveValid:r,avgFaceScore:parseFloat(f.toFixed(3)),avgBodyScore:parseFloat(m.toFixed(3)),faceKeypointsDetected:g.length,bodyKeypointsDetected:h.length,eyeDistance:parseFloat(p.toFixed(2)),noseToRightRatio:parseFloat((y/p).toFixed(3)),noseToLeftRatio:parseFloat((S/p).toFixed(3)),noseScore:parseFloat(c[2].toFixed(3)),leftEyeScore:parseFloat(i[2].toFixed(3)),rightEyeScore:parseFloat(l[2].toFixed(3)),leftMouthScore:parseFloat(d[2].toFixed(3)),rightMouthScore:parseFloat(u[2].toFixed(3)),expectedPosition:x})};k(v)}catch(e){console.warn("Failed to track pose detection:",e)}}},[e,k]),L=()=>{a.posthog.capture(`${d}/face_scan_detection_started`,{faceScanId:e,stage:b.current,timestamp:(new Date).toISOString(),stageName:T[b.current]}),setTimeout(()=>{x(!0)},1500)},D=async()=>{if("undefined"!=typeof window)try{console.log("Initializing Face Scan...");const e=await(async()=>{if("undefined"==typeof window)return null;if(r)return r;if(c)for(;c;)if(await new Promise(e=>setTimeout(e,100)),r)return r;c=!0;try{const[e,t]=await Promise.all([import("@tensorflow/tfjs"),Promise.resolve().then(function(){return require("./pose-detection.esm-BMyJE2Fw.js")})]);await e.setBackend("webgl"),await e.ready();const a=await t.createDetector(t.SupportedModels.BlazePose,{runtime:"tfjs",modelType:"full"}),o=document.createElement("canvas");o.width=n.videoConstraints.width,o.height=n.videoConstraints.height;const s=o.getContext("2d");if(s){s.fillStyle="black",s.fillRect(0,0,o.width,o.height);try{await a.estimatePoses(o)}catch(e){console.warn("Warmup frame failed (non-fatal):",e)}}return r=a,a}catch(e){return console.error("Failed to preload detector:",e),null}finally{c=!1}})();e&&(u.current=e,console.log("Face scan model loaded successfully"),y(!0),i?.())}catch(e){console.error("Error initializing face scan:",e)}};return t.useEffect(()=>(D(),()=>{(async()=>{try{y(!1)}catch(e){console.error("Error disposing resources:",e)}finally{f(0),m(0),b.current=0,w.current=0,F.current=[]}})()}),[]),t.useEffect(()=>{b.current=g},[g]),t.useEffect(()=>{w.current=h},[h]),{faceScanDetector:async(t,r)=>{if(u.current&&t.current&&p&&S&&!(t.current.readyState<2))try{const c=await u.current.estimatePoses(t.current);if(c.length>0){const t=[],i=[];if(c[0].keypoints.forEach((e,a)=>{const n=e.score??0,o=[e.x??-1,e.y??-1,n];a<=10?t.push(o):i.push(o)}),r?.current){const e=r.current.getContext("2d"),{width:t,height:a}=r.current;if(e){e.clearRect(0,0,t,a);const n=Math.min(w.current/2,1),o=.35*a;e.beginPath(),e.strokeStyle="#00ff00",e.lineWidth=6,e.arc(t/2,a/2,o+10,-Math.PI/2,-Math.PI/2+2*n*Math.PI),e.stroke()}}const u=((e,t)=>{if(!t[0]||!t[2]||!t[5]||t[0][2]<.2||t[2][2]<.2||t[5][2]<.2)return!1;const a=.5*(t[10][1]+t[9][1])-.5*(t[5][1]+t[2][1]),n=(.5*(t[10][1]+t[9][1])-t[0][1])/a,o=n>.7||n<.3,s=Math.abs(t[2][1]-t[5][1])<.5*a&&Math.abs(t[9][1]-t[10][1])<.5*a,r=t[2][0]-t[5][0],c=t[0][0]-t[5][0],i=c>.4*r&&c<.6*r,l=c>.85*r,d=t[2][0]-t[0][0]>.85*r;switch(e){case 0:case 3:return!o&&s&&i;case 1:return!o&&s&&l;case 2:return!o&&s&&d;default:return!1}})(b.current,t),g=i.slice(2).filter(e=>e[2]>.7).length<=2;F.current.push(u&&g),F.current.length>10&&F.current.shift();if(F.current.filter(Boolean).length>=2){const e=w.current+1;m(e)}else m(Math.max(0,w.current-1));if(w.current>=2){o?.();const t=b.current+1;m(0),F.current=[],f(t),x(!1),(async()=>{if(await n.speechService.playAudio(`${n.voiceOverAssetsPath}face-scan-vos/Sound-effect.mp3`),a.posthog.capture(`${d}/face_scan_detection_stage_completed`,{faceScanId:e,completedStage:b.current,nextStage:t,timestamp:(new Date).toISOString(),totalStages:4,stageName:T[b.current]}),1===t&&l&&l(),t>=4)s?.();else{let e=null;switch(t){case 1:e="Left.mp3";break;case 2:e="Right.mp3";break;case 3:e="Smile.mp3"}e&&await n.speechService.playAudio(`${n.voiceOverAssetsPath}face-scan-vos/${e}`),L()}})()}I(t,i,b.current,u,g,w.current)}}catch(e){console.error("Pose detection error:",e)}},scanStage:g,setScanStage:f,consecutiveValid:h,isModelLoaded:p,resetScan:()=>{a.posthog.capture(`${d}/face_scan_reset`,{faceScanId:e,stage:b.current,timestamp:(new Date).toISOString(),stageName:T[b.current],consecutiveValid:w.current}),f(0),m(0),x(!1),b.current=0,w.current=0,F.current=[],C.current="",j.current=0,_.current=!1,v.current&&(speechSynthesis.cancel(),v.current=null)},enableVoiceCommands:()=>{if(_.current=!0,"undefined"!=typeof window&&E&&"speechSynthesis"in window){const e=new SpeechSynthesisUtterance("");e.volume=0,speechSynthesis.speak(e)}},startScanSequence:L,isScanningActive:S}}function l({resetScanState:a,loading:s,config:r}){const{translate:c,preferredLanguage:i}=t.useContext(n.LanguageContext)||{};return console.log(i,"preferredLanguage"),console.log(c?.(n.LanguageKeys.scanFailed),"translate"),e.jsx("div",{className:"fixed top-[0] left-[0] z-[999] flex justify-center items-center w-full h-full",style:{background:r?.style?.base?.backgroundColor},children:e.jsxs("div",{className:"flex flex-col w-full items-center p-[1rem] rounded-lg ",children:[e.jsx(n.Header,{noTitle:!0,resolvedConfig:r}),e.jsxs("div",{className:"flex flex-col items-center w-full",children:[e.jsx("h2",{className:"text-xl font-semibold text-gray-800 ",style:{fontFamily:r?.style?.heading?.headingFontFamily||"SeriouslyNostalgic Fn",fontSize:r?.style?.heading?.headingFontSize||"32px",color:r?.style?.heading?.headingColor||"#000",fontWeight:r?.style?.heading?.headingFontWeight||"normal"},children:c?.(n.LanguageKeys.scanFailed)}),e.jsx("p",{className:"mb-[1.5rem]",style:{fontFamily:r?.style?.subheading?.subheadingFontFamily||"'Inter', sans-serif",fontSize:r?.style?.subheading?.subheadingFontSize||"14px",color:r?.style?.subheading?.subheadingColor||"#4b5563",fontWeight:r?.style?.subheading?.subheadingFontWeight||"normal"},children:c?.(n.LanguageKeys.clickToResetScan)}),e.jsx(n.SpecificButton,{disabled:s,className:"w-full h-[45px] shadow-[0px_1px_2px_0px_#00000040] text-[16px]",buttonText:c?.(n.LanguageKeys.resetScan),postfixIcon:e.jsx(o.ArrowRight,{}),buttonFunc:()=>a?.(),resolvedConfig:r})]})]})})}function d({stage:a,videoLoading:o,setVideoLoading:s,videoError:r,setVideoError:c,gender:i,config:l,btnConfig:d}){const{translate:u}=t.useContext(n.LanguageContext)||{};return-1===a?e.jsxs("div",{className:"text-center p-[16px] w-full h-full",style:{background:l?.style?.base?.backgroundColor},children:[e.jsxs("div",{className:"w-full",children:[e.jsx(n.Header,{noTitle:!0,resolvedConfig:l}),e.jsx("h2",{style:{fontFamily:l?.style?.heading?.headingFontFamily||"SeriouslyNostalgic Fn",fontSize:l?.style?.heading?.headingFontSize||"32px",color:l?.style?.heading?.headingColor||"#000",fontWeight:l?.style?.heading?.headingFontWeight||"normal"},children:u?.(n.LanguageKeys.faceVisible)}),o&&e.jsx("div",{className:"mb-4 flex items-center justify-center",style:{fontFamily:l?.style?.subheading?.subheadingFontFamily||"'Inter', sans-serif",fontSize:l?.style?.subheading?.subheadingFontSize||"14px",color:l?.style?.subheading?.subheadingColor||"#4b5563",fontWeight:l?.style?.subheading?.subheadingFontWeight||"normal"},children:u?.(n.LanguageKeys.loadingVideo)}),r&&e.jsx("div",{className:"mb-4 text-red-600",style:{fontFamily:l?.style?.subheading?.subheadingFontFamily||"'Inter', sans-serif",fontSize:l?.style?.subheading?.subheadingFontSize||"14px",color:"#ff0000",fontWeight:l?.style?.subheading?.subheadingFontWeight||"normal"},children:u?.(n.LanguageKeys.videoLoadFailed)}),!r&&e.jsx("div",{className:" w-[100px] mx-auto",children:e.jsx("video",{src:i===n.GenderType.Male?n.maleGlassesOffVideo:n.glassesOffVideo,autoPlay:!0,loop:!0,controls:!1,muted:!0,playsInline:!0,className:"h-full w-full object-contain border-none",onCanPlay:()=>s(!1),onLoadStart:()=>s(!0),onError:()=>c(!0),"aria-label":"Instructional video: Please remove your glasses before starting the scan."})})]}),e.jsx("div",{className:"flex justify-center w-full p-[1rem]",children:e.jsx(n.SpecificButton,{disabled:d.isDisabled,className:"!w-[60px] !h-[35px] !py-0 !px-0",buttonText:u?.(d.label),postfixIcon:d?.icon,buttonFunc:d.onClick,resolvedConfig:l})})]}):e.jsx("div",{className:"text-center p-[16px] w-full h-full",style:{background:l?.style?.base?.backgroundColor},children:e.jsxs("div",{className:"w-full",children:[e.jsx(n.Header,{noTitle:!0,resolvedConfig:l}),e.jsx("h3",{className:"mb-[0.5rem]",style:{fontFamily:l?.style?.heading?.headingFontFamily||"SeriouslyNostalgic Fn",fontSize:l?.style?.heading?.headingFontSize||"32px",color:l?.style?.heading?.headingColor||"#000",fontWeight:l?.style?.heading?.headingFontWeight||"normal"},children:u?.(n.directionMessages[a])}),e.jsxs("div",{className:"max-w-[400px] justify-center gap-1 mx-auto flex items-center",children:[e.jsx("div",{className:` w-[120px] overflow-hidden ${0===a?"opacity-100":"opacity-0 hidden"} `,children:e.jsx("video",{className:"h-full w-full object-contain border-none",muted:!0,loop:!0,autoPlay:!0,playsInline:!0,children:e.jsx("source",{src:i===n.GenderType.Male?n.FACE_SCAN_HEADSHOT.male.forward:n.FACE_SCAN_HEADSHOT.female.forward,type:"video/mp4"})})}),e.jsx("div",{className:` w-[120px] overflow-hidden ${1===a?"opacity-100":"opacity-0 hidden"} `,children:e.jsx("video",{className:"h-full w-full object-contain border-none",muted:!0,loop:!0,autoPlay:!0,playsInline:!0,children:e.jsx("source",{src:i===n.GenderType.Male?n.FACE_SCAN_HEADSHOT.male.left:n.FACE_SCAN_HEADSHOT.female.left,type:"video/mp4"})})}),e.jsx("div",{className:` w-[120px] overflow-hidden ${2===a?"opacity-100":"opacity-0 hidden"} `,children:e.jsx("video",{className:"h-full w-full object-contain border-none",muted:!0,loop:!0,autoPlay:!0,playsInline:!0,children:e.jsx("source",{src:i===n.GenderType.Male?n.FACE_SCAN_HEADSHOT.male.right:n.FACE_SCAN_HEADSHOT.female.right,type:"video/mp4"})})}),e.jsx("div",{className:` w-[120px] overflow-hidden ${3===a?"opacity-100":"opacity-0 hidden"} `,children:e.jsx("video",{className:"h-full w-full object-contain border-none",muted:!0,loop:!0,autoPlay:!0,playsInline:!0,children:e.jsx("source",{src:i===n.GenderType.Male?n.FACE_SCAN_HEADSHOT.male.smile:n.FACE_SCAN_HEADSHOT.female.smile,type:"video/mp4"})})})]})]})})}const u=({webcamRef:a,canvasRef:r})=>{const{isError:c,isSuccess:i,showLoader:u,hasError:g,resetScanState:f,showGuideCard:h,scanStage:m,videoLoading:p,setVideoLoading:y,videoError:S,setVideoError:x,gender:v,getButtonText:b,isScanning:w,startScan:F,isModelLoaded:C,config:j}=t.useContext(n.ParamsContext),_=n.useLocalConfig(j),{setPreferredLanguage:N}=t.useContext(n.LanguageContext)||{};return t.useEffect(()=>{N?.(_?.language)},[_]),c?e.jsx(l,{config:_}):i?e.jsx("div",{className:"fixed z-[9] w-full h-full",style:{background:_?.style?.base?.backgroundColor},children:e.jsx(n.LoadingScreen,{url:_?.loader,loaderType:"black"})}):e.jsxs(e.Fragment,{children:[e.jsx("audio",{id:"audioElement",crossOrigin:"anonymous",preload:"auto",style:{position:"absolute",zIndex:-99999},src:void 0}),u&&g&&e.jsx("div",{className:"fixed z-[9] w-full h-full",style:{background:_?.style?.base?.backgroundColor},children:e.jsx(n.LoadingScreen,{url:_?.loader,loaderType:"black"})}),e.jsx("div",{className:"h-full flex-col relative w-full flex justify-center items-center text-center rounded-t-[20px]",style:{background:_?.style?.base?.backgroundColor},children:e.jsx("div",{className:"flex-1 w-full max-w-md overflow-hidden",children:e.jsxs("div",{className:"w-full h-full",children:[e.jsx("video",{ref:a,autoPlay:!0,playsInline:!0,muted:!0,width:n.videoConstraints.width,height:n.videoConstraints.height,className:"w-full h-full object-cover fixed left-0 top-0 z-0",style:{transform:"scaleX(-1)"}}),e.jsx("canvas",{ref:r,width:n.videoConstraints.width,height:n.videoConstraints.height,style:{transform:"scaleX(-1)",opacity:"0"}})]})})}),!u&&g&&e.jsx(l,{loading:u,resetScanState:f,config:_}),h&&!g&&!u&&e.jsx(s.Drawer,{open:!0,className:"face-scan-small camera-draw",anchor:"bottom",onClose:(e,t)=>{},hideBackdrop:!0,children:e.jsx(d,{stage:m,videoLoading:p,setVideoLoading:y,videoError:S,setVideoError:x,gender:v,config:_,btnConfig:{label:b(),onClick:w?f:F,isDisabled:u||!C,icon:w?e.jsx(o.ArrowRight,{}):e.jsx(e.Fragment,{})}})})]})};exports.FaceScan=({userDetails:o,onScanSuccess:s,onScanError:r,onRetry:c,config:l,isError:d,isSuccess:g})=>{const f=t.useRef(null),h=t.useRef(null),m=t.useRef(null),p=t.useRef([]),y=t.useRef(null),[S,x]=t.useState(!1),[v,b]=t.useState(!1),[w,F]=t.useState(!1),[C,j]=t.useState(!0),[_,N]=t.useState(!1),[E,T]=t.useState(!1),[k,I]=t.useState(!1),[L,D]=t.useState(n.generateUuid()),{email:R,gender:M,deviceFocalLength:P,shopDomain:A,callbackUrl:O}=o,[z,$]=t.useState([]),H=t.useCallback(()=>{console.log("Stopping recording..."),m.current&&"recording"===m.current.state&&m.current.stop(),m.current=null},[]),V=async()=>{if(x(!0),p.current){if(0===p.current.length)return console.error("No video data recorded"),I(!0),void x(!1);const e=new File(p.current,`${L}.webm`,{type:"video/webm"}),t=e.size,a=(t/1048576).toFixed(2),o=Math.round(t/1e4),s={video_size_mb:parseFloat(a),video_size_bytes:t,blob_count:p.current.length,estimated_duration_seconds:o},r=[{gender:M},{face_scan_id:L},{focal_length:`${P}`},{customer_store_url:A},{scan_type:"face_scan"},{callback_url:O||"https://example.com/webhook"}];console.log(r,"metadat"),n.handleScanTimeCapture({eventName:`${A}/face_scan_meta_data`,faceScanId:L,email:R,data:JSON.stringify({metaData:r,videoData:s})});const c=Date.now();n.handleScanTimeCapture({eventName:`${A}/face_scan_upload_start`,faceScanId:L,email:R,startTime:c});try{const t=await n.swan.fileUpload.faceScanFileUploader({file:e,arrayMetaData:r,objectKey:L,email:R,contentType:e.type}),a=Date.now(),o=a-c;n.handleScanTimeCapture({eventName:`${A}/face_scan_upload_complete`,faceScanId:L,email:R,completionTime:a,uploadDuration:o}),console.log("✅ Upload successful",t),n.swan.measurement.handlFaceScaneSocket({faceScanId:L,onOpen:()=>{n.handleWebSocketCapture({eventName:`${A}/webSocket`,faceScanID:L,connection:"open",type:"faceScan_recommendation",email:R}),console.log("websocket connect open")},onError:e=>{n.handleWebSocketCapture({eventName:`${A}/webSocket`,faceScanID:L,connection:"error",type:"faceScan_recommendation",email:R}),Y(e)},onSuccess:e=>{n.handleWebSocketCapture({eventName:`${A}/webSocket`,faceScanID:L,connection:"success",type:"faceScan_recommendation",email:R}),Z(e)},onClose:()=>{console.log("websocket connect close"),n.handleWebSocketCapture({eventName:`${A}/webSocket`,faceScanID:L,connection:"close",type:"faceScan_recommendation",email:R})}})}catch(e){Y(e)}}},W=t.useCallback(()=>{console.log("Starting recording for stages 1-3...");const e=f.current?.srcObject;if(!e)return;const t=e.getVideoTracks()[0].getSettings(),{width:a=n.videoConstraints.width,height:o=n.videoConstraints.height}=t,s=document.createElement("canvas"),r=s.getContext("2d");a>o?(s.width=o,s.height=a):(s.width=a,s.height=o);const c=document.createElement("video");c.srcObject=e,c.muted=!0,c.playsInline=!0,c.play();const i=()=>{a>o?(r?.save(),r?.translate(s.width,0),r?.rotate(Math.PI/2),r?.drawImage(c,0,0,o,a),r?.restore()):r?.drawImage(c,0,0,a,o),requestAnimationFrame(i)};i();const l=s.captureStream(30),d=z.length>0?{mimeType:z[0]}:{};let u;try{u=new MediaRecorder(l,d)}catch(e){return console.error("MediaRecorder init failed:",e),I(!0),void x(!1)}p.current=[],u.ondataavailable=e=>{e?.data&&e.data.size>0&&p.current&&p.current.push(e.data)},u.onstop=()=>{console.log("Recording stopped, total blobs:",p?.current?.length),V()},u.start(100),m.current=u,console.log("Recording started successfully (portrait normalized)")},[z,V]),{faceScanDetector:K,scanStage:q,setScanStage:B,resetScan:U,isModelLoaded:G,startScanSequence:J}=i({faceScanId:L,shopDomain:A,onScanComplete:()=>{H()},onModelReady:()=>{b(!0)},onStartRecording:()=>{console.log("Stage 0 completed - starting recording for stages 1-3"),W()}}),X=t.useCallback(()=>{G&&(B(0),n.speechService.playAudio(`${n.voiceOverAssetsPath}face-scan-vos/Face-forward.mp3`),setTimeout(()=>{F(!0),setTimeout(()=>{J()},200)},200))},[B,F,J,G]),Q=t.useCallback(()=>{F(!1),j(!0),H(),U(),c?.(),p.current=[],m.current&&(m.current=null),I(!1),B(-1),D(n.generateUuid()),f.current&&y.current&&(f.current.srcObject=y.current,console.log("Camera stream restored after reset"))},[B,F,j,H,U,D]),Y=e=>{console.log(e,"ws error"),r?.(e),I(!0),x(!1),j(!1),n.handleScanTimeCapture({eventName:`${A}/faceScan`,faceScanId:L,status:"failed",email:R,data:JSON.stringify(e)})},Z=e=>{console.log(e,"ws success"),e&&"intermediate"===e?.resultType&&n.handleScanTimeCapture({eventName:`${A}/faceScan_success/intermediate`,faceScanId:L,status:"success",email:R,data:JSON.stringify(e)}),s?.(e)};t.useEffect(()=>{if(!d&&!g)return navigator.mediaDevices.getUserMedia&&navigator.mediaDevices.getUserMedia({video:n.videoConstraints}).then(e=>{y.current=e,f.current&&(f.current.srcObject=e)}).catch(e=>console.error("Error accessing webcam:",e)),()=>{y.current&&y.current.getTracks().forEach(e=>e.stop())}},[d,g]),t.useEffect(()=>{if(!v||!w)return;const e=setInterval(()=>{K(f,h)},500);return()=>clearInterval(e)},[K,v,w]);return console.log("Model ready:",v,"Has error:",k,"Is scanning:",w,"showLoader",S),t.useEffect(()=>{if("undefined"!=typeof MediaRecorder){const e=n.videoTypes.filter(e=>MediaRecorder.isTypeSupported(e));$(e)}},[]),t.useEffect(()=>{B(-1)},[d,g]),t.useEffect(()=>{a.init(n.posthogPublicKey,{api_host:n.posthogPublicHost}),a.capture("$pageview")},[]),e.jsx(n.LanguageContextProvider,{children:e.jsx(n.ParamsContext.Provider,{value:{isError:d,isSuccess:g,showLoader:S,hasError:k,resetScanState:Q,showGuideCard:C,scanStage:q,videoLoading:_,setVideoLoading:N,videoError:E,setVideoError:T,gender:M,getButtonText:()=>w?n.LanguageKeys.reset:G?n.LanguageKeys.start:n.LanguageKeys.loading,isScanning:w,startScan:X,isModelLoaded:G,config:l},children:e.jsx(u,{webcamRef:f,canvasRef:h})})})};
2
+ //# sourceMappingURL=FaceScan-CNQpL2rm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FaceScan-CNQpL2rm.js","sources":["../src/customHooks/useFaceScan.ts","../src/components/faceScan/FaceScanErrorScreen.tsx","../src/components/faceScan/FaceScanGuide.tsx","../src/components/faceScan/FaceScanStep.tsx","../src/components/faceScan/FaceScan.tsx"],"sourcesContent":["import {\n useState,\n useRef,\n useEffect,\n useCallback,\n useMemo,\n RefObject,\n} from \"react\";\n// 1. Use TYPE-ONLY imports. These are erased at build time and won't crash SSR.\nimport type { PoseDetector } from \"@tensorflow-models/pose-detection\";\nimport { posthog } from \"posthog-js\";\nimport speechService from \"../utils/service/speechService\";\nimport { videoConstraints, voiceOverAssetsPath } from \"../utils/constants\";\n\n/**\n * useFaceScan Hook with PostHog Analytics\n * Refactored for Zero-Config SSR/CSR Compatibility\n */\n\n// Debounce utility\nfunction debounce(fn: (...args: any) => void, delay: number) {\n let timer: number | NodeJS.Timeout;\n return (...args: any) => {\n if (timer) clearTimeout(timer);\n timer = setTimeout(() => fn(...args), delay);\n };\n}\n\n// Global Singleton Cache (Preserves state across re-renders)\nlet preloadedDetector: PoseDetector | null = null;\nlet isPreloading = false;\n\n// 2. Async Preloader with Dynamic Imports\nexport const preloadDetector = async (): Promise<PoseDetector | null> => {\n // Guard: Never run on server\n if (typeof window === \"undefined\") return null;\n if (preloadedDetector) return preloadedDetector;\n if (isPreloading) {\n // Simple wait mechanism if already loading\n while (isPreloading) {\n await new Promise(r => setTimeout(r, 100));\n if (preloadedDetector) return preloadedDetector;\n }\n }\n\n isPreloading = true;\n\n try {\n // DYNAMIC IMPORTS: Only fetch these heavy bundles in the browser\n const [tf, poseDetection] = await Promise.all([\n import(\"@tensorflow/tfjs\"),\n import(\"@tensorflow-models/pose-detection\")\n ]);\n\n // Initialize Backend\n await tf.setBackend(\"webgl\");\n await tf.ready();\n\n const detector = await poseDetection.createDetector(\n poseDetection.SupportedModels.BlazePose,\n {\n runtime: \"tfjs\",\n modelType: \"full\",\n }\n );\n\n // Dummy video warmup (Performance Optimization)\n // This runs the model once on a blank canvas to \"wake up\" the GPU\n // so the first user frame detects instantly.\n const dummyCanvas = document.createElement(\"canvas\");\n dummyCanvas.width = videoConstraints.width;\n dummyCanvas.height = videoConstraints.height;\n const ctx = dummyCanvas.getContext(\"2d\");\n if (ctx) {\n ctx.fillStyle = \"black\";\n ctx.fillRect(0, 0, dummyCanvas.width, dummyCanvas.height);\n try {\n await detector.estimatePoses(dummyCanvas);\n } catch (e) {\n console.warn(\"Warmup frame failed (non-fatal):\", e);\n }\n }\n\n preloadedDetector = detector;\n return detector;\n } catch (err) {\n console.error(\"Failed to preload detector:\", err);\n return null;\n } finally {\n isPreloading = false;\n }\n};\n\ntype Point = [number, number, number];\n\nfunction useFaceScan({\n faceScanId,\n onValidPose,\n onScanComplete,\n onModelReady,\n onStartRecording,\n shopDomain,\n}: {\n faceScanId: string;\n onValidPose?: () => void;\n onScanComplete?: () => void;\n onModelReady?: () => void;\n onStartRecording: () => void;\n shopDomain: string;\n}) {\n const detectorRef = useRef<PoseDetector | null>(null);\n const [scanStage, setScanStage] = useState(0);\n const [consecutiveValid, setConsecutiveValid] = useState(0);\n const [isModelLoaded, setIsModelLoaded] = useState(false);\n const [isScanningActive, setIsScanningActive] = useState(false);\n \n const utteranceRef = useRef<SpeechSynthesisUtterance | null>(null);\n const scanStageRef = useRef(scanStage);\n const consecutiveValidRef = useRef(consecutiveValid);\n const validityBufferRef = useRef<boolean[]>([]);\n const lastSpokenMessageRef = useRef(\"\");\n const lastSpokenTimeRef = useRef(0);\n const voiceEnabledRef = useRef(false);\n \n const VALIDITY_BUFFER_LENGTH = 10;\n const CONSECUTIVE_VALID_LENGTH = 2;\n const TOTAL_STAGES = 4;\n const POSE_TRACKING_INTERVAL = 4000;\n const lastPoseTrackingTimeRef = useRef(0);\n\n // Safe iOS detection (SSR safe)\n const isIOS = typeof navigator !== 'undefined' && (\n /iPad|iPhone|iPod/.test(navigator.userAgent) ||\n (navigator.platform === \"MacIntel\" && navigator.maxTouchPoints > 1)\n );\n\n const directionMessages = useMemo(\n () => [\n \"Face front\",\n \"Turn head fully left\",\n \"Turn head fully right\",\n \"Smile facing front\",\n ],\n []\n );\n\n const debouncedTrackPoseDetection = useMemo(\n () =>\n debounce((payload) => {\n posthog.capture(`${shopDomain}/face_scan_pose_detection`, payload);\n }, 4000),\n [shopDomain]\n );\n\n const trackPoseDetection = useCallback(\n (\n faceKeypoints: Point[],\n bodyKeypoints: Point[],\n stage: number,\n headValid: boolean,\n bodyInvalid: boolean,\n consecutiveValidCount: number\n ) => {\n const now = Date.now();\n if (now - lastPoseTrackingTimeRef.current < POSE_TRACKING_INTERVAL) {\n return;\n }\n\n lastPoseTrackingTimeRef.current = now;\n\n try {\n const nose = faceKeypoints[0] || [0, 0, 0];\n const leftEye = faceKeypoints[2] || [0, 0, 0];\n const rightEye = faceKeypoints[5] || [0, 0, 0];\n const leftMouth = faceKeypoints[9] || [0, 0, 0];\n const rightMouth = faceKeypoints[10] || [0, 0, 0];\n\n const faceKeypointScores = faceKeypoints\n .map((kp: Point) => kp[2])\n .filter((score: number) => score > 0);\n const avgFaceScore =\n faceKeypointScores.length > 0\n ? faceKeypointScores.reduce((a, b) => a + b, 0) /\n faceKeypointScores.length\n : 0;\n\n const bodyKeypointScores = bodyKeypoints\n .map((kp: Point) => kp[2])\n .filter((score: number) => score > 0);\n const avgBodyScore =\n bodyKeypointScores.length > 0\n ? bodyKeypointScores.reduce((a: number, b: number) => a + b, 0) /\n bodyKeypointScores.length\n : 0;\n\n const eyeDistance = Math.abs(leftEye[0] - rightEye[0]);\n const noseToRight = nose[0] - rightEye[0];\n const noseToLeft = leftEye[0] - nose[0];\n\n let expectedPosition = \"frontal\";\n if (stage === 1) expectedPosition = \"left\";\n else if (stage === 2) expectedPosition = \"right\";\n else if (stage === 3) expectedPosition = \"frontal_smile\";\n\n const payload = {\n faceScanId,\n stage,\n timestamp: new Date().toISOString(),\n data: JSON.stringify({\n headValid,\n bodyInvalid,\n consecutiveValid: consecutiveValidCount,\n avgFaceScore: parseFloat(avgFaceScore.toFixed(3)),\n avgBodyScore: parseFloat(avgBodyScore.toFixed(3)),\n faceKeypointsDetected: faceKeypointScores.length,\n bodyKeypointsDetected: bodyKeypointScores.length,\n eyeDistance: parseFloat(eyeDistance.toFixed(2)),\n noseToRightRatio: parseFloat((noseToRight / eyeDistance).toFixed(3)),\n noseToLeftRatio: parseFloat((noseToLeft / eyeDistance).toFixed(3)),\n noseScore: parseFloat(nose[2].toFixed(3)),\n leftEyeScore: parseFloat(leftEye[2].toFixed(3)),\n rightEyeScore: parseFloat(rightEye[2].toFixed(3)),\n leftMouthScore: parseFloat(leftMouth[2].toFixed(3)),\n rightMouthScore: parseFloat(rightMouth[2].toFixed(3)),\n expectedPosition,\n }),\n };\n debouncedTrackPoseDetection(payload);\n } catch (error) {\n console.warn(\"Failed to track pose detection:\", error);\n }\n },\n [faceScanId, debouncedTrackPoseDetection]\n );\n\n const enableVoiceCommands = () => {\n voiceEnabledRef.current = true;\n if (typeof window !== 'undefined' && isIOS && \"speechSynthesis\" in window) {\n const silentUtterance = new SpeechSynthesisUtterance(\"\");\n silentUtterance.volume = 0;\n speechSynthesis.speak(silentUtterance);\n }\n };\n\n const startScanSequence = () => {\n posthog.capture(`${shopDomain}/face_scan_detection_started`, {\n faceScanId,\n stage: scanStageRef.current,\n timestamp: new Date().toISOString(),\n stageName: directionMessages[scanStageRef.current],\n });\n\n setTimeout(() => {\n setIsScanningActive(true);\n }, 1500);\n };\n\n const isHeadInPosition = (stage: number, keypoints: Point[]) => {\n // ... logic unchanged ...\n const nose = 0;\n const leftEye = 2;\n const rightEye = 5;\n const leftMouth = 9;\n const rightMouth = 10;\n\n const minScore = 0.2;\n if (\n !keypoints[nose] || !keypoints[leftEye] || !keypoints[rightEye] ||\n keypoints[nose][2] < minScore ||\n keypoints[leftEye][2] < minScore ||\n keypoints[rightEye][2] < minScore\n ) {\n return false;\n }\n\n const eyesToMouthVerticalDistance =\n 0.5 * (keypoints[rightMouth][1] + keypoints[leftMouth][1]) -\n 0.5 * (keypoints[rightEye][1] + keypoints[leftEye][1]);\n\n const faceTiltedness =\n (0.5 * (keypoints[rightMouth][1] + keypoints[leftMouth][1]) -\n keypoints[nose][1]) /\n eyesToMouthVerticalDistance;\n\n const faceIsTilted = faceTiltedness > 0.7 || faceTiltedness < 0.3;\n\n const faceIsVertical =\n Math.abs(keypoints[leftEye][1] - keypoints[rightEye][1]) <\n 0.5 * eyesToMouthVerticalDistance &&\n Math.abs(keypoints[leftMouth][1] - keypoints[rightMouth][1]) <\n 0.5 * eyesToMouthVerticalDistance;\n\n const eyeDistance = keypoints[leftEye][0] - keypoints[rightEye][0];\n const noseToRight = keypoints[nose][0] - keypoints[rightEye][0];\n const noseToLeft = keypoints[leftEye][0] - keypoints[nose][0];\n\n const frontalFace =\n noseToRight > 0.4 * eyeDistance && noseToRight < 0.6 * eyeDistance;\n const fullLeft = noseToRight > 0.85 * eyeDistance;\n const fullRight = noseToLeft > 0.85 * eyeDistance;\n\n switch (stage) {\n case 0:\n return !faceIsTilted && faceIsVertical && frontalFace;\n case 1:\n return !faceIsTilted && faceIsVertical && fullLeft;\n case 2:\n return !faceIsTilted && faceIsVertical && fullRight;\n case 3:\n return !faceIsTilted && faceIsVertical && frontalFace;\n default:\n return false;\n }\n };\n\n const faceScanDetector = async (\n webcamRef: RefObject<HTMLVideoElement | null>,\n canvasRef: RefObject<HTMLCanvasElement | null>\n ) => {\n if (\n !detectorRef.current ||\n !webcamRef.current ||\n !isModelLoaded ||\n !isScanningActive\n )\n return;\n\n // Safety: ensure video is actually playing with data\n if (webcamRef.current.readyState < 2) return;\n\n try {\n const poses = await detectorRef.current.estimatePoses(webcamRef.current);\n if (poses.length > 0) {\n const faceKeypoints: Point[] = [];\n const bodyKeypoints: Point[] = [];\n poses[0].keypoints.forEach((landmark, idx) => {\n const score = landmark.score ?? 0;\n const point: Point = [landmark.x ?? -1, landmark.y ?? -1, score];\n if (idx <= 10) faceKeypoints.push(point);\n else bodyKeypoints.push(point);\n });\n\n // Optional drawing\n if (canvasRef?.current) {\n const ctx = canvasRef.current.getContext(\"2d\");\n const { width, height } = canvasRef.current;\n if (ctx) {\n ctx.clearRect(0, 0, width, height);\n\n const progress = Math.min(\n consecutiveValidRef.current / CONSECUTIVE_VALID_LENGTH,\n 1\n );\n const radius = height * 0.35;\n ctx.beginPath();\n ctx.strokeStyle = \"#00ff00\";\n ctx.lineWidth = 6;\n ctx.arc(\n width / 2,\n height / 2,\n radius + 10,\n -Math.PI / 2,\n -Math.PI / 2 + progress * 2 * Math.PI\n );\n ctx.stroke();\n }\n }\n\n const headValid = isHeadInPosition(scanStageRef.current, faceKeypoints);\n const bodyInvalid =\n bodyKeypoints.slice(2).filter((p) => p[2] > 0.7).length <= 2;\n\n validityBufferRef.current.push(headValid && bodyInvalid);\n if (validityBufferRef.current.length > VALIDITY_BUFFER_LENGTH) {\n validityBufferRef.current.shift();\n }\n\n const validCount = validityBufferRef.current.filter(Boolean).length;\n if (validCount >= 2) {\n const nextValid = consecutiveValidRef.current + 1;\n setConsecutiveValid(nextValid);\n } else {\n setConsecutiveValid(Math.max(0, consecutiveValidRef.current - 1));\n }\n\n if (consecutiveValidRef.current >= CONSECUTIVE_VALID_LENGTH) {\n onValidPose?.();\n\n const nextStage = scanStageRef.current + 1;\n setConsecutiveValid(0);\n validityBufferRef.current = [];\n setScanStage(nextStage);\n setIsScanningActive(false);\n\n (async () => {\n await speechService.playAudio(\n `${voiceOverAssetsPath}face-scan-vos/Sound-effect.mp3`\n );\n posthog.capture(\n `${shopDomain}/face_scan_detection_stage_completed`,\n {\n faceScanId,\n completedStage: scanStageRef.current,\n nextStage,\n timestamp: new Date().toISOString(),\n totalStages: TOTAL_STAGES,\n stageName: directionMessages[scanStageRef.current],\n }\n );\n \n if (nextStage === 1 && onStartRecording) {\n onStartRecording();\n }\n if (nextStage >= TOTAL_STAGES) {\n onScanComplete?.();\n } else {\n let nextSound = null;\n switch (nextStage) {\n case 1: nextSound = \"Left.mp3\"; break;\n case 2: nextSound = \"Right.mp3\"; break;\n case 3: nextSound = \"Smile.mp3\"; break;\n }\n if (nextSound) {\n await speechService.playAudio(\n `${voiceOverAssetsPath}face-scan-vos/${nextSound}`\n );\n }\n startScanSequence();\n }\n })();\n }\n\n trackPoseDetection(\n faceKeypoints,\n bodyKeypoints,\n scanStageRef.current,\n headValid,\n bodyInvalid,\n consecutiveValidRef.current\n );\n }\n } catch (err) {\n console.error(\"Pose detection error:\", err);\n }\n };\n\n const initializeModels = async () => {\n // 3. Browser Guard\n if (typeof window === 'undefined') return;\n\n try {\n console.log(\"Initializing Face Scan...\");\n // Calls our safe, dynamic preloader\n const detector = await preloadDetector();\n \n if (detector) {\n detectorRef.current = detector;\n console.log(\"Face scan model loaded successfully\");\n setIsModelLoaded(true);\n onModelReady?.();\n }\n } catch (err) {\n console.error(\"Error initializing face scan:\", err);\n }\n };\n\n const disposeModelAndTf = async () => {\n // Optional: We might NOT want to dispose if we want to keep the cache \n // for re-mounting. But if you must dispose:\n try {\n setIsModelLoaded(false);\n // NOTE: We generally don't dispose the detector if we want to reuse it \n // via the 'preloadedDetector' global variable.\n // If you dispose here, make sure to set 'preloadedDetector = null' too.\n /* if (detectorRef.current) {\n await detectorRef.current.dispose();\n detectorRef.current = null;\n preloadedDetector = null; // Clear global cache if disposing\n }\n */\n } catch (err) {\n console.error(\"Error disposing resources:\", err);\n } finally {\n // Reset state\n setScanStage(0);\n setConsecutiveValid(0);\n scanStageRef.current = 0;\n consecutiveValidRef.current = 0;\n validityBufferRef.current = [];\n }\n };\n\n const resetScan = () => {\n posthog.capture(`${shopDomain}/face_scan_reset`, {\n faceScanId,\n stage: scanStageRef.current,\n timestamp: new Date().toISOString(),\n stageName: directionMessages[scanStageRef.current],\n consecutiveValid: consecutiveValidRef.current,\n });\n\n setScanStage(0);\n setConsecutiveValid(0);\n setIsScanningActive(false);\n scanStageRef.current = 0;\n consecutiveValidRef.current = 0;\n validityBufferRef.current = [];\n lastSpokenMessageRef.current = \"\";\n lastSpokenTimeRef.current = 0;\n voiceEnabledRef.current = false;\n if (utteranceRef.current) {\n speechSynthesis.cancel();\n utteranceRef.current = null;\n }\n };\n\n useEffect(() => {\n initializeModels();\n return () => {\n disposeModelAndTf();\n };\n }, []);\n\n useEffect(() => {\n scanStageRef.current = scanStage;\n }, [scanStage]);\n\n useEffect(() => {\n consecutiveValidRef.current = consecutiveValid;\n }, [consecutiveValid]);\n\n return {\n faceScanDetector,\n scanStage,\n setScanStage,\n consecutiveValid,\n isModelLoaded,\n resetScan,\n enableVoiceCommands,\n startScanSequence,\n isScanningActive,\n };\n}\n\nexport default useFaceScan;","import { ArrowRight } from \"lucide-react\";\nimport Header from \"../Header\";\nimport SpecificButton from \"../../atoms/specificButton/SpecificButton\";\nimport { useContext } from \"react\";\nimport { LanguageKeys } from \"../../utils/languageKeys\";\nimport { LanguageContext } from \"../../utils/context/languageContext\";\nimport { Config } from \"../../types/interfaces\";\n\nfunction FaceScanErrorScreen({ resetScanState, loading, config }: { resetScanState?: () => void; loading?: boolean; config?: Config }) {\n\tconst { translate,preferredLanguage } = useContext(LanguageContext) || {};\nconsole.log(preferredLanguage,\"preferredLanguage\");\n\nconsole.log(translate?.(LanguageKeys.scanFailed),\"translate\");\n\n\n\treturn (\n\t\t<div className=\"fixed top-[0] left-[0] z-[999] flex justify-center items-center w-full h-full\" style={{ background: config?.style?.base?.backgroundColor }}>\n\t\t\t<div className=\"flex flex-col w-full items-center p-[1rem] rounded-lg \">\n\t\t\t\t<Header noTitle resolvedConfig={config} />\n\t\t\t\t<div className=\"flex flex-col items-center w-full\">\n\t\t\t\t\t<h2\n\t\t\t\t\t\tclassName=\"text-xl font-semibold text-gray-800 \"\n\t\t\t\t\t\tstyle={{\n\t\t\t\t\t\t\tfontFamily: config?.style?.heading?.headingFontFamily || \"SeriouslyNostalgic Fn\",\n\t\t\t\t\t\t\tfontSize: config?.style?.heading?.headingFontSize || \"32px\",\n\t\t\t\t\t\t\tcolor: config?.style?.heading?.headingColor || \"#000\",\n\t\t\t\t\t\t\tfontWeight: config?.style?.heading?.headingFontWeight || \"normal\",\n\t\t\t\t\t\t}}\n\t\t\t\t\t>\n\t\t\t\t\t\t{translate?.(LanguageKeys.scanFailed)}\n\t\t\t\t\t</h2>\n\t\t\t\t\t<p\n\t\t\t\t\t\tclassName=\"mb-[1.5rem]\"\n\t\t\t\t\t\tstyle={{\n\t\t\t\t\t\t\tfontFamily: config?.style?.subheading?.subheadingFontFamily || \"'Inter', sans-serif\",\n\t\t\t\t\t\t\tfontSize: config?.style?.subheading?.subheadingFontSize || \"14px\",\n\t\t\t\t\t\t\tcolor: config?.style?.subheading?.subheadingColor || \"#4b5563\",\n\t\t\t\t\t\t\tfontWeight: config?.style?.subheading?.subheadingFontWeight || \"normal\",\n\t\t\t\t\t\t}}\n\t\t\t\t\t>\n\t\t\t\t\t\t{translate?.(LanguageKeys.clickToResetScan)}\n\t\t\t\t\t</p>\n\t\t\t\t\t<SpecificButton\n\t\t\t\t\t\tdisabled={loading}\n\t\t\t\t\t\tclassName=\"w-full h-[45px] shadow-[0px_1px_2px_0px_#00000040] text-[16px]\"\n\t\t\t\t\t\tbuttonText={translate?.(LanguageKeys.resetScan)}\n\t\t\t\t\t\tpostfixIcon={<ArrowRight />}\n\t\t\t\t\t\tbuttonFunc={() => resetScanState?.()}\n\t\t\t\t\t\tresolvedConfig={config}\n\t\t\t\t\t/>\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t</div>\n\t);\n}\n\nexport default FaceScanErrorScreen;\n","import { FaceScanGuideProps } from \"../../types/interfaces\";\nimport Header from \"../Header\";\nimport { GenderType } from \"../../utils/enums\";\nimport { directionMessages, FACE_SCAN_HEADSHOT, glassesOffVideo, maleGlassesOffVideo } from \"../../utils/constants\";\nimport { LanguageContext } from \"../../utils/context/languageContext\";\nimport { useContext } from \"react\";\nimport SpecificButton from \"../../atoms/specificButton/SpecificButton\";\nimport { LanguageKeys } from \"../../utils/languageKeys\";\n\nfunction FaceScanGuide({ stage, videoLoading, setVideoLoading, videoError, setVideoError, gender, config, btnConfig }: FaceScanGuideProps) {\n\tconst { translate } = useContext(LanguageContext) || {};\n\n\n\n\tif (stage === -1) {\n\t\treturn (\n\t\t\t<div className=\"text-center p-[16px] w-full h-full\" style={{ background: config?.style?.base?.backgroundColor }}>\n\t\t\t\t<div className=\"w-full\">\n\t\t\t\t\t<Header noTitle resolvedConfig={config} />\n\t\t\t\t\t<h2\n\t\t\t\t\t\tstyle={{\n\t\t\t\t\t\t\tfontFamily: config?.style?.heading?.headingFontFamily || \"SeriouslyNostalgic Fn\",\n\t\t\t\t\t\t\tfontSize: config?.style?.heading?.headingFontSize || \"32px\",\n\t\t\t\t\t\t\tcolor: config?.style?.heading?.headingColor || \"#000\",\n\t\t\t\t\t\t\tfontWeight: config?.style?.heading?.headingFontWeight || \"normal\",\n\t\t\t\t\t\t}}\n\t\t\t\t\t>\n\t\t\t\t\t\t{translate?.(LanguageKeys.faceVisible)}\n\t\t\t\t\t</h2>\n\t\t\t\t\t{videoLoading && (\n\t\t\t\t\t\t<div\n\t\t\t\t\t\t\tclassName=\"mb-4 flex items-center justify-center\"\n\t\t\t\t\t\t\tstyle={{\n\t\t\t\t\t\t\t\tfontFamily: config?.style?.subheading?.subheadingFontFamily || \"'Inter', sans-serif\",\n\t\t\t\t\t\t\t\tfontSize: config?.style?.subheading?.subheadingFontSize || \"14px\",\n\t\t\t\t\t\t\t\tcolor: config?.style?.subheading?.subheadingColor || \"#4b5563\",\n\t\t\t\t\t\t\t\tfontWeight: config?.style?.subheading?.subheadingFontWeight || \"normal\",\n\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{translate?.(LanguageKeys.loadingVideo)}\n\t\t\t\t\t\t</div>\n\t\t\t\t\t)}\n\t\t\t\t\t{videoError && (\n\t\t\t\t\t\t<div\n\t\t\t\t\t\t\tclassName=\"mb-4 text-red-600\"\n\t\t\t\t\t\t\tstyle={{\n\t\t\t\t\t\t\t\tfontFamily: config?.style?.subheading?.subheadingFontFamily || \"'Inter', sans-serif\",\n\t\t\t\t\t\t\t\tfontSize: config?.style?.subheading?.subheadingFontSize || \"14px\",\n\t\t\t\t\t\t\t\tcolor: \"#ff0000\",\n\t\t\t\t\t\t\t\tfontWeight: config?.style?.subheading?.subheadingFontWeight || \"normal\",\n\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{translate?.(LanguageKeys.videoLoadFailed)}\n\t\t\t\t\t\t</div>\n\t\t\t\t\t)}\n\t\t\t\t\t{!videoError && (\n\t\t\t\t\t\t<div className={` w-[100px] mx-auto`}>\n\t\t\t\t\t\t\t<video\n\t\t\t\t\t\t\t\tsrc={gender === GenderType.Male ? maleGlassesOffVideo : glassesOffVideo}\n\t\t\t\t\t\t\t\tautoPlay\n\t\t\t\t\t\t\t\tloop\n\t\t\t\t\t\t\t\tcontrols={false}\n\t\t\t\t\t\t\t\tmuted\n\t\t\t\t\t\t\t\tplaysInline\n\t\t\t\t\t\t\t\tclassName=\"h-full w-full object-contain border-none\"\n\t\t\t\t\t\t\t\tonCanPlay={() => setVideoLoading(false)}\n\t\t\t\t\t\t\t\tonLoadStart={() => setVideoLoading(true)}\n\t\t\t\t\t\t\t\tonError={() => setVideoError(true)}\n\t\t\t\t\t\t\t\taria-label=\"Instructional video: Please remove your glasses before starting the scan.\"\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t)}\n\t\t\t\t</div>\n\t\t\t\t<div className=\"flex justify-center w-full p-[1rem]\">\n\t\t\t\t\t<SpecificButton\n\t\t\t\t\t\tdisabled={btnConfig.isDisabled}\n\t\t\t\t\t\tclassName=\"!w-[60px] !h-[35px] !py-0 !px-0\"\n\t\t\t\t\t\tbuttonText={translate?.(btnConfig.label)}\n\t\t\t\t\t\tpostfixIcon={btnConfig?.icon}\n\t\t\t\t\t\tbuttonFunc={btnConfig.onClick}\n\t\t\t\t\t\tresolvedConfig={config}\n\t\t\t\t\t/>\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t);\n\t}\n\n\treturn (\n\t\t<div className=\"text-center p-[16px] w-full h-full\" style={{ background: config?.style?.base?.backgroundColor }}>\n\t\t\t<div className=\"w-full\">\n\t\t\t\t<Header noTitle resolvedConfig={config} />\n\t\t\t\t<h3\n\t\t\t\t\tclassName=\"mb-[0.5rem]\"\n\t\t\t\t\tstyle={{\n\t\t\t\t\t\tfontFamily: config?.style?.heading?.headingFontFamily || \"SeriouslyNostalgic Fn\",\n\t\t\t\t\t\tfontSize: config?.style?.heading?.headingFontSize || \"32px\",\n\t\t\t\t\t\tcolor: config?.style?.heading?.headingColor || \"#000\",\n\t\t\t\t\t\tfontWeight: config?.style?.heading?.headingFontWeight || \"normal\",\n\t\t\t\t\t}}\n\t\t\t\t>\n\t\t\t\t\t{translate?.(directionMessages[stage])}\n\t\t\t\t</h3>\n\t\t\t\t{/* <p>We'll guide you to take 6 selfies </p> */}\n\t\t\t\t<div className=\"max-w-[400px] justify-center gap-1 mx-auto flex items-center\">\n\t\t\t\t\t<div className={` w-[120px] overflow-hidden ${stage === 0 ? \"opacity-100\" : \"opacity-0 hidden\"} `}>\n\t\t\t\t\t\t<video className=\"h-full w-full object-contain border-none\" muted loop autoPlay playsInline>\n\t\t\t\t\t\t\t<source src={gender === GenderType.Male ? FACE_SCAN_HEADSHOT.male.forward : FACE_SCAN_HEADSHOT.female.forward} type=\"video/mp4\" />\n\t\t\t\t\t\t</video>\n\t\t\t\t\t</div>\n\t\t\t\t\t<div className={` w-[120px] overflow-hidden ${stage === 1 ? \"opacity-100\" : \"opacity-0 hidden\"} `}>\n\t\t\t\t\t\t<video className=\"h-full w-full object-contain border-none\" muted loop autoPlay playsInline>\n\t\t\t\t\t\t\t<source src={gender === GenderType.Male ? FACE_SCAN_HEADSHOT.male.left : FACE_SCAN_HEADSHOT.female.left} type=\"video/mp4\" />\n\t\t\t\t\t\t</video>\n\t\t\t\t\t</div>\n\t\t\t\t\t<div className={` w-[120px] overflow-hidden ${stage === 2 ? \"opacity-100\" : \"opacity-0 hidden\"} `}>\n\t\t\t\t\t\t<video className=\"h-full w-full object-contain border-none\" muted loop autoPlay playsInline>\n\t\t\t\t\t\t\t<source src={gender === GenderType.Male ? FACE_SCAN_HEADSHOT.male.right : FACE_SCAN_HEADSHOT.female.right} type=\"video/mp4\" />\n\t\t\t\t\t\t</video>\n\t\t\t\t\t</div>\n\t\t\t\t\t<div className={` w-[120px] overflow-hidden ${stage === 3 ? \"opacity-100\" : \"opacity-0 hidden\"} `}>\n\t\t\t\t\t\t<video className=\"h-full w-full object-contain border-none\" muted loop autoPlay playsInline>\n\t\t\t\t\t\t\t<source src={gender === GenderType.Male ? FACE_SCAN_HEADSHOT.male.smile : FACE_SCAN_HEADSHOT.female.smile} type=\"video/mp4\" />\n\t\t\t\t\t\t</video>\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t</div>\n\t);\n}\n\nexport default FaceScanGuide;\n","import React, { useContext, useEffect } from \"react\";\nimport ParamsContext from \"../../utils/context/paramsContext\";\nimport FaceScanErrorScreen from \"./FaceScanErrorScreen\";\nimport LoadingScreen from \"../LoadingScreen\";\nimport { videoConstraints } from \"../../utils/constants\";\nimport { Drawer } from \"@mui/material\";\nimport FaceScanGuide from \"./FaceScanGuide\";\nimport { ArrowRight } from \"lucide-react\";\nimport { LanguageContext } from \"../../utils/context/languageContext\";\nimport { useLocalConfig } from \"../../config/useLocalConfig\";\ninterface FaceScanStepProps {\n\twebcamRef: React.RefObject<HTMLVideoElement | null>;\n\tcanvasRef: React.RefObject<HTMLCanvasElement | null>;\n}\n\nconst FaceScanStep: React.FC<FaceScanStepProps> = ({ webcamRef, canvasRef }) => {\n\tconst {\n\t\tisError,\n\t\tisSuccess,\n\t\tshowLoader,\n\t\thasError,\n\t\tresetScanState,\n\t\tshowGuideCard,\n\t\tscanStage,\n\t\tvideoLoading,\n\t\tsetVideoLoading,\n\t\tvideoError,\n\t\tsetVideoError,\n\t\tgender,\n\t\tgetButtonText,\n\t\tisScanning,\n\t\tstartScan,\n\t\tisModelLoaded,\n\t\tconfig,\n\t} = useContext(ParamsContext);\n\tconst resolvedConfig = useLocalConfig(config);\n\n\tconst { setPreferredLanguage } = useContext(LanguageContext) || {};\n\tuseEffect(() => {\n\t\tsetPreferredLanguage?.(resolvedConfig?.language);\n\t}, [resolvedConfig]);\n\tif (isError) {\n\t\treturn <FaceScanErrorScreen config={resolvedConfig} />;\n\t}\n\tif (isSuccess) {\n\t\treturn (\n\t\t\t<div className=\"fixed z-[9] w-full h-full\" style={{ background: resolvedConfig?.style?.base?.backgroundColor }}>\n\t\t\t\t{/* <Asset genderType={gender} /> */}\n\t\t\t\t<LoadingScreen url={resolvedConfig?.loader} loaderType=\"black\" />\n\t\t\t</div>\n\t\t);\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t<audio id=\"audioElement\" crossOrigin=\"anonymous\" preload=\"auto\" style={{ position: \"absolute\", zIndex: -99999 }} src={undefined} />\n\n\t\t\t{/* Error overlay */}\n\t\t\t{showLoader && hasError && (\n\t\t\t\t<div className=\"fixed z-[9] w-full h-full\" style={{ background: resolvedConfig?.style?.base?.backgroundColor }}>\n\t\t\t\t\t{/* <Asset genderType={gender} /> */}\n\t\t\t\t\t<LoadingScreen url={resolvedConfig?.loader} loaderType=\"black\" />\n\t\t\t\t</div>\n\t\t\t)}\n\n\t\t\t{/* Always show camera view */}\n\t\t\t<div className=\"h-full flex-col relative w-full flex justify-center items-center text-center rounded-t-[20px]\" style={{ background: resolvedConfig?.style?.base?.backgroundColor }}>\n\t\t\t\t<div className=\"flex-1 w-full max-w-md overflow-hidden\">\n\t\t\t\t\t<div className=\"w-full h-full\">\n\t\t\t\t\t\t<video\n\t\t\t\t\t\t\tref={webcamRef}\n\t\t\t\t\t\t\tautoPlay\n\t\t\t\t\t\t\tplaysInline\n\t\t\t\t\t\t\tmuted\n\t\t\t\t\t\t\twidth={videoConstraints.width}\n\t\t\t\t\t\t\theight={videoConstraints.height}\n\t\t\t\t\t\t\tclassName=\"w-full h-full object-cover fixed left-0 top-0 z-0\"\n\t\t\t\t\t\t\tstyle={{ transform: \"scaleX(-1)\" }}\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<canvas ref={canvasRef} width={videoConstraints.width} height={videoConstraints.height} style={{ transform: \"scaleX(-1)\", opacity: \"0\" }} />\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t</div>\n\n\t\t\t{/* Error overlay */}\n\t\t\t{!showLoader && hasError && <FaceScanErrorScreen loading={showLoader} resetScanState={resetScanState} config={resolvedConfig} />}\n\n\t\t\t{/* Scan guide drawer - only show when scanning */}\n\t\t\t{showGuideCard && !hasError && !showLoader && (\n\t\t\t\t<Drawer\n\t\t\t\t\topen\n\t\t\t\t\tclassName=\"face-scan-small camera-draw\"\n\t\t\t\t\tanchor=\"bottom\"\n\t\t\t\t\tonClose={(event, reason) => {\n\t\t\t\t\t\tif (reason === \"backdropClick\") {\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t}}\n\t\t\t\t\thideBackdrop\n\t\t\t\t>\n\t\t\t\t\t<FaceScanGuide\n\t\t\t\t\t\tstage={scanStage}\n\t\t\t\t\t\tvideoLoading={videoLoading}\n\t\t\t\t\t\tsetVideoLoading={setVideoLoading}\n\t\t\t\t\t\tvideoError={videoError}\n\t\t\t\t\t\tsetVideoError={setVideoError}\n\t\t\t\t\t\tgender={gender}\n\t\t\t\t\t\tconfig={resolvedConfig}\n\t\t\t\t\t\tbtnConfig={{\n\t\t\t\t\t\t\tlabel: getButtonText(),\n\t\t\t\t\t\t\tonClick: isScanning ? resetScanState : startScan,\n\t\t\t\t\t\t\tisDisabled: showLoader || !isModelLoaded,\n\t\t\t\t\t\t\ticon: isScanning ? <ArrowRight /> : <></>,\n\t\t\t\t\t\t}}\n\t\t\t\t\t/>\n\t\t\t\t</Drawer>\n\t\t\t)}\n\t\t</>\n\t);\n};\n\nexport default FaceScanStep;\n","\"use client\";\nimport { useEffect, useRef, useState, useCallback, } from \"react\";\nimport posthog from \"posthog-js\";\nimport { FaceScanProps } from \"../../types/interfaces\";\nimport { generateUuid, handleScanTimeCapture, handleWebSocketCapture } from \"../../utils/utils\";\nimport { posthogPublicHost, posthogPublicKey, videoConstraints, videoTypes, voiceOverAssetsPath } from \"../../utils/constants\";\nimport swan from \"../../utils/service/swanService\";\nimport speechService from \"../../utils/service/speechService\";\nimport useFaceScan from \"../../customHooks/useFaceScan\";\nimport { LanguageKeys } from \"../../utils/languageKeys\";\nimport LanguageContextProvider, { LanguageContext } from \"../../utils/context/languageContext\";\nimport FaceScanStep from \"./FaceScanStep\";\nimport ParamsContext from \"../../utils/context/paramsContext\";\n\nexport const FaceScan: React.FC<FaceScanProps> = ({ userDetails, onScanSuccess, onScanError, onRetry, config, isError, isSuccess }) => {\n\tconst webcamRef = useRef<HTMLVideoElement | null>(null);\n\tconst canvasRef = useRef<HTMLCanvasElement | null>(null);\n\tconst mediaRecorderRef = useRef<MediaRecorder | null>(null);\n\tconst recordedBlobsRef = useRef<Blob[] | null>([]);\n\tconst streamRef = useRef<MediaStream | null>(null);\n\tconst [showLoader, setShowLoader] = useState(false);\n\tconst [modelReady, setModelReady] = useState(false);\n\tconst [isScanning, setIsScanning] = useState(false);\n\tconst [showGuideCard, setShowGuideCard] = useState(true);\n\tconst [videoLoading, setVideoLoading] = useState(false);\n\tconst [videoError, setVideoError] = useState(false);\n\tconst [hasError, setHasError] = useState(false);\n\tconst [faceScanId, setFaceScanId] = useState(generateUuid());\n\tconst { email, gender, deviceFocalLength, shopDomain, callbackUrl } = userDetails;\n\tconst [supportedTypes, setSupportedTypes] = useState<string[]>([]);\n\t// const supportedTypes = useMemo(() => videoTypes.filter((type) => MediaRecorder.isTypeSupported(type)), []);\n\t\n\tconst stopRecording = useCallback(() => {\n\t\tconsole.log(\"Stopping recording...\");\n\t\tif (mediaRecorderRef.current && mediaRecorderRef.current.state === \"recording\") {\n\t\t\tmediaRecorderRef.current.stop();\n\t\t}\n\t\tmediaRecorderRef.current = null;\n\t}, []);\n\n\tconst uploadFinalVideo = async () => {\n\t\tsetShowLoader(true);\n\t\tif (recordedBlobsRef.current) {\n\t\t\tif (recordedBlobsRef.current.length === 0) {\n\t\t\t\tconsole.error(\"No video data recorded\");\n\t\t\t\tsetHasError(true);\n\t\t\t\tsetShowLoader(false);\n\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst videoFile = new File(recordedBlobsRef.current, `${faceScanId}.webm`, {\n\t\t\t\ttype: \"video/webm\",\n\t\t\t});\n\t\t\tconst fileSize = videoFile.size;\n\t\t\tconst fileSizeMB = (fileSize / (1024 * 1024)).toFixed(2);\n\t\t\tconst estimatedDuration = Math.round(fileSize / 10000);\n\t\t\tconst videoData = {\n\t\t\t\tvideo_size_mb: parseFloat(fileSizeMB),\n\t\t\t\tvideo_size_bytes: fileSize,\n\t\t\t\tblob_count: recordedBlobsRef.current.length,\n\t\t\t\testimated_duration_seconds: estimatedDuration,\n\t\t\t};\n\n\t\t\tconst metaData = [\n\t\t\t\t{ gender: gender },\n\t\t\t\t{ face_scan_id: faceScanId },\n\t\t\t\t{\n\t\t\t\t\tfocal_length: `${deviceFocalLength}`,\n\t\t\t\t},\n\t\t\t\t{ customer_store_url: shopDomain },\n\t\t\t\t{ scan_type: \"face_scan\" },\n\t\t\t\t{ callback_url: callbackUrl || \"https://example.com/webhook\" },\n\t\t\t];\n\t\t\tconsole.log(metaData,\"metadat\");\n\t\t\t\n\t\t\thandleScanTimeCapture({\n\t\t\t\teventName: `${shopDomain}/face_scan_meta_data`,\n\t\t\t\tfaceScanId,\n\t\t\t\temail,\n\t\t\t\tdata: JSON.stringify({ metaData, videoData }),\n\t\t\t});\n\n\t\t\tconst uploadStartTime = Date.now();\n\t\t\thandleScanTimeCapture({\n\t\t\t\teventName: `${shopDomain}/face_scan_upload_start`,\n\t\t\t\tfaceScanId,\n\t\t\t\temail,\n\t\t\t\tstartTime: uploadStartTime,\n\t\t\t});\n\n\t\t\ttry {\n\t\t\t\tconst res = await swan.fileUpload.faceScanFileUploader({\n\t\t\t\t\tfile: videoFile,\n\t\t\t\t\tarrayMetaData: metaData,\n\t\t\t\t\tobjectKey: faceScanId,\n\t\t\t\t\temail,\n\t\t\t\t\tcontentType: videoFile.type,\n\t\t\t\t});\n\n\t\t\t\tconst uploadEndTime = Date.now();\n\t\t\t\tconst uploadDuration = uploadEndTime - uploadStartTime;\n\n\t\t\t\thandleScanTimeCapture({\n\t\t\t\t\teventName: `${shopDomain}/face_scan_upload_complete`,\n\t\t\t\t\tfaceScanId,\n\t\t\t\t\temail,\n\t\t\t\t\tcompletionTime: uploadEndTime,\n\t\t\t\t\tuploadDuration,\n\t\t\t\t});\n\n\t\t\t\tconsole.log(\"✅ Upload successful\", res);\n\t\t\t\tswan.measurement.handlFaceScaneSocket({\n\t\t\t\t\tfaceScanId,\n\t\t\t\t\tonOpen: () => {\n\t\t\t\t\t\thandleWebSocketCapture({\n\t\t\t\t\t\t\teventName: `${shopDomain}/webSocket`,\n\t\t\t\t\t\t\tfaceScanID: faceScanId,\n\t\t\t\t\t\t\tconnection: \"open\",\n\t\t\t\t\t\t\ttype: \"faceScan_recommendation\",\n\t\t\t\t\t\t\temail,\n\t\t\t\t\t\t});\n\t\t\t\t\t\tconsole.log(\"websocket connect open\");\n\t\t\t\t\t},\n\t\t\t\t\tonError: (err) => {\n\t\t\t\t\t\thandleWebSocketCapture({\n\t\t\t\t\t\t\teventName: `${shopDomain}/webSocket`,\n\t\t\t\t\t\t\tfaceScanID: faceScanId,\n\t\t\t\t\t\t\tconnection: \"error\",\n\t\t\t\t\t\t\ttype: \"faceScan_recommendation\",\n\t\t\t\t\t\t\temail,\n\t\t\t\t\t\t});\n\t\t\t\t\t\tonError(err);\n\t\t\t\t\t},\n\t\t\t\t\tonSuccess: (data) => {\n\t\t\t\t\t\thandleWebSocketCapture({\n\t\t\t\t\t\t\teventName: `${shopDomain}/webSocket`,\n\t\t\t\t\t\t\tfaceScanID: faceScanId,\n\t\t\t\t\t\t\tconnection: \"success\",\n\t\t\t\t\t\t\ttype: \"faceScan_recommendation\",\n\t\t\t\t\t\t\temail,\n\t\t\t\t\t\t});\n\t\t\t\t\t\tonSuccess(data);\n\t\t\t\t\t},\n\t\t\t\t\tonClose: () => {\n\t\t\t\t\t\tconsole.log(\"websocket connect close\");\n\t\t\t\t\t\thandleWebSocketCapture({\n\t\t\t\t\t\t\teventName: `${shopDomain}/webSocket`,\n\t\t\t\t\t\t\tfaceScanID: faceScanId,\n\t\t\t\t\t\t\tconnection: \"close\",\n\t\t\t\t\t\t\ttype: \"faceScan_recommendation\",\n\t\t\t\t\t\t\temail,\n\t\t\t\t\t\t});\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t} catch (error) {\n\t\t\t\tonError(error);\n\t\t\t}\n\t\t}\n\t};\n\n\tconst startRecording = useCallback(() => {\n\t\tconsole.log(\"Starting recording for stages 1-3...\");\n\t\tconst stream = webcamRef.current?.srcObject as MediaStream | null;\n\t\tif (!stream) return;\n\n\t\t// Create a canvas to normalize orientation\n\t\tconst videoTrack = stream.getVideoTracks()[0];\n\t\tconst settings = videoTrack.getSettings();\n\t\tconst { width = videoConstraints.width, height = videoConstraints.height } = settings;\n\n\t\tconst canvas = document.createElement(\"canvas\");\n\t\tconst ctx = canvas.getContext(\"2d\");\n\n\t\t// Always force portrait (swap width/height if landscape)\n\t\tif (width > height) {\n\t\t\tcanvas.width = height;\n\t\t\tcanvas.height = width;\n\t\t} else {\n\t\t\tcanvas.width = width;\n\t\t\tcanvas.height = height;\n\t\t}\n\n\t\tconst videoEl = document.createElement(\"video\");\n\t\tvideoEl.srcObject = stream;\n\t\tvideoEl.muted = true;\n\t\tvideoEl.playsInline = true;\n\t\tvideoEl.play();\n\n\t\t// Draw video frames onto canvas\n\t\tconst drawFrame = () => {\n\t\t\t// Rotate if camera gives landscape frames\n\t\t\tif (width > height) {\n\t\t\t\tctx?.save();\n\t\t\t\tctx?.translate(canvas.width, 0);\n\t\t\t\tctx?.rotate(Math.PI / 2);\n\t\t\t\tctx?.drawImage(videoEl, 0, 0, height, width);\n\t\t\t\tctx?.restore();\n\t\t\t} else {\n\t\t\t\tctx?.drawImage(videoEl, 0, 0, width, height);\n\t\t\t}\n\t\t\trequestAnimationFrame(drawFrame);\n\t\t};\n\t\tdrawFrame();\n\n\t\tconst canvasStream = canvas.captureStream(30); // 30fps\n\t\tconst mediaRecorderOptions = supportedTypes.length > 0 ? { mimeType: supportedTypes[0] } : {};\n\t\tlet mediaRecorder;\n\n\t\ttry {\n\t\t\tmediaRecorder = new MediaRecorder(canvasStream, mediaRecorderOptions);\n\t\t} catch (e) {\n\t\t\tconsole.error(\"MediaRecorder init failed:\", e);\n\t\t\tsetHasError(true);\n\t\t\tsetShowLoader(false);\n\t\t\treturn;\n\t\t}\n\n\t\trecordedBlobsRef.current = [];\n\t\tmediaRecorder.ondataavailable = (event) => {\n\t\t\tif (event?.data && event.data.size > 0 && recordedBlobsRef.current) {\n\t\t\t\trecordedBlobsRef.current.push(event.data);\n\t\t\t}\n\t\t};\n\t\tmediaRecorder.onstop = () => {\n\t\t\tconsole.log(\"Recording stopped, total blobs:\", recordedBlobsRef?.current?.length);\n\t\t\tuploadFinalVideo();\n\t\t};\n\n\t\tmediaRecorder.start(100); // 100ms chunks\n\t\tmediaRecorderRef.current = mediaRecorder;\n\t\tconsole.log(\"Recording started successfully (portrait normalized)\");\n\t}, [supportedTypes, uploadFinalVideo]);\n\n\tconst { faceScanDetector, scanStage, setScanStage, resetScan, isModelLoaded, startScanSequence } = useFaceScan({\n\t\tfaceScanId,\n\t\tshopDomain,\n\t\tonScanComplete: () => {\n\t\t\tstopRecording();\n\t\t},\n\t\tonModelReady: () => {\n\t\t\tsetModelReady(true);\n\t\t},\n\t\tonStartRecording: () => {\n\t\t\tconsole.log(\"Stage 0 completed - starting recording for stages 1-3\");\n\t\t\tstartRecording();\n\t\t},\n\t});\n\n\tconst startScan = useCallback(() => {\n\t\tif (!isModelLoaded) return;\n\t\tsetScanStage(0);\n\t\tspeechService.playAudio(`${voiceOverAssetsPath}face-scan-vos/Face-forward.mp3`);\n\t\tsetTimeout(() => {\n\t\t\tsetIsScanning(true);\n\t\t\tsetTimeout(() => {\n\t\t\t\tstartScanSequence();\n\t\t\t}, 200);\n\t\t}, 200);\n\t}, [setScanStage, setIsScanning, startScanSequence, isModelLoaded]);\n\n\tconst resetScanState = useCallback(() => {\n\t\tsetIsScanning(false);\n\t\tsetShowGuideCard(true);\n\t\tstopRecording();\n\t\tresetScan();\n\t\tonRetry?.();\n\t\trecordedBlobsRef.current = [];\n\t\tif (mediaRecorderRef.current) {\n\t\t\tmediaRecorderRef.current = null;\n\t\t}\n\t\tsetHasError(false);\n\t\tsetScanStage(-1);\n\t\tsetFaceScanId(generateUuid());\n\t\tif (webcamRef.current && streamRef.current) {\n\t\t\twebcamRef.current.srcObject = streamRef.current;\n\t\t\tconsole.log(\"Camera stream restored after reset\");\n\t\t}\n\t}, [setScanStage, setIsScanning, setShowGuideCard, stopRecording, resetScan, setFaceScanId]);\n\n\tconst onError = (data: any) => {\n\t\tconsole.log(data, \"ws error\");\n\t\tonScanError?.(data);\n\t\tsetHasError(true);\n\t\tsetShowLoader(false);\n\t\tsetShowGuideCard(false);\n\t\thandleScanTimeCapture({\n\t\t\teventName: `${shopDomain}/faceScan`,\n\t\t\tfaceScanId,\n\t\t\tstatus: \"failed\",\n\t\t\temail,\n\t\t\tdata: JSON.stringify(data),\n\t\t});\n\t};\n\n\tconst onSuccess = (data: any) => {\n\t\tconsole.log(data, \"ws success\");\n\t\tif (data && data?.resultType === \"intermediate\") {\n\t\t\thandleScanTimeCapture({\n\t\t\t\teventName: `${shopDomain}/faceScan_success/intermediate`,\n\t\t\t\tfaceScanId,\n\t\t\t\tstatus: \"success\",\n\t\t\t\temail,\n\t\t\t\tdata: JSON.stringify(data),\n\t\t\t});\n\t\t}\n\t\tonScanSuccess?.(data);\n\t};\n\n\tuseEffect(() => {\n\t\tif (isError || isSuccess) return;\n\t\tif (navigator.mediaDevices.getUserMedia) {\n\t\t\tnavigator.mediaDevices\n\t\t\t\t.getUserMedia({ video: videoConstraints })\n\t\t\t\t.then((stream) => {\n\t\t\t\t\tstreamRef.current = stream;\n\t\t\t\t\tif (webcamRef.current) {\n\t\t\t\t\t\twebcamRef.current.srcObject = stream;\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\t\t.catch((err) => console.error(\"Error accessing webcam:\", err));\n\t\t}\n\t\treturn () => {\n\t\t\tif (streamRef.current) {\n\t\t\t\tstreamRef.current.getTracks().forEach((track) => track.stop());\n\t\t\t}\n\t\t};\n\t}, [isError, isSuccess]);\n\n\t// Face detection interval - only run when scanning is active\n\tuseEffect(() => {\n\t\tif (!modelReady || !isScanning) return;\n\t\tconst intervalId = setInterval(() => {\n\t\t\tfaceScanDetector(webcamRef, canvasRef);\n\t\t}, 500);\n\n\t\t// eslint-disable-next-line consistent-return\n\t\treturn () => clearInterval(intervalId);\n\t}, [faceScanDetector, modelReady, isScanning]);\n\n\tconst getButtonText = () => {\n\t\tif (isScanning) return LanguageKeys.reset;\n\t\tif (!isModelLoaded) return LanguageKeys.loading;\n\t\treturn LanguageKeys.start;\n\t};\n\n\tconsole.log(\"Model ready:\", modelReady, \"Has error:\", hasError, \"Is scanning:\", isScanning, \"showLoader\", showLoader);\n\tuseEffect(() => {\n\t\tif (typeof MediaRecorder !== \"undefined\") {\n\t\t\tconst supported = videoTypes.filter((type) => MediaRecorder.isTypeSupported(type));\n\t\t\tsetSupportedTypes(supported);\n\t\t}\n\t}, []);\n\tuseEffect(() => {\n\t\tsetScanStage(-1);\n\t\tif (isError || isSuccess) return;\n\t}, [isError, isSuccess]);\n\n\tuseEffect(() => {\n\t\tposthog.init(posthogPublicKey, { api_host: posthogPublicHost });\n\t\tposthog.capture(\"$pageview\");\n\t}, []);\n\n return (\n\t\t<LanguageContextProvider>\n\t\t\t<ParamsContext.Provider value={{isError,isSuccess,showLoader,hasError,resetScanState,showGuideCard,scanStage,videoLoading,setVideoLoading,videoError,setVideoError,gender,getButtonText,isScanning,startScan,isModelLoaded,config}}>\n\t\t\t<FaceScanStep webcamRef={webcamRef} canvasRef={canvasRef}/>\n\t\t\t</ParamsContext.Provider>\n\t\t</LanguageContextProvider>\n\t )\n};\n"],"names":["preloadedDetector","isPreloading","useFaceScan","faceScanId","onValidPose","onScanComplete","onModelReady","onStartRecording","shopDomain","detectorRef","useRef","scanStage","setScanStage","useState","consecutiveValid","setConsecutiveValid","isModelLoaded","setIsModelLoaded","isScanningActive","setIsScanningActive","utteranceRef","scanStageRef","consecutiveValidRef","validityBufferRef","lastSpokenMessageRef","lastSpokenTimeRef","voiceEnabledRef","lastPoseTrackingTimeRef","isIOS","navigator","test","userAgent","platform","maxTouchPoints","directionMessages","useMemo","debouncedTrackPoseDetection","fn","delay","timer","args","clearTimeout","setTimeout","debounce","payload","posthog","capture","trackPoseDetection","useCallback","faceKeypoints","bodyKeypoints","stage","headValid","bodyInvalid","consecutiveValidCount","now","Date","current","nose","leftEye","rightEye","leftMouth","rightMouth","faceKeypointScores","map","kp","filter","score","avgFaceScore","length","reduce","a","b","bodyKeypointScores","avgBodyScore","eyeDistance","Math","abs","noseToRight","noseToLeft","expectedPosition","timestamp","toISOString","data","JSON","stringify","parseFloat","toFixed","faceKeypointsDetected","bodyKeypointsDetected","noseToRightRatio","noseToLeftRatio","noseScore","leftEyeScore","rightEyeScore","leftMouthScore","rightMouthScore","error","console","warn","startScanSequence","stageName","initializeModels","async","window","log","detector","Promise","r","tf","poseDetection","all","import","setBackend","ready","createDetector","SupportedModels","BlazePose","runtime","modelType","dummyCanvas","document","createElement","width","videoConstraints","height","ctx","getContext","fillStyle","fillRect","estimatePoses","e","err","preloadDetector","useEffect","disposeModelAndTf","faceScanDetector","webcamRef","canvasRef","readyState","poses","keypoints","forEach","landmark","idx","point","x","y","push","clearRect","progress","min","radius","beginPath","strokeStyle","lineWidth","arc","PI","stroke","eyesToMouthVerticalDistance","faceTiltedness","faceIsTilted","faceIsVertical","frontalFace","fullLeft","fullRight","isHeadInPosition","slice","p","shift","Boolean","nextValid","max","nextStage","speechService","playAudio","voiceOverAssetsPath","completedStage","totalStages","nextSound","resetScan","speechSynthesis","cancel","enableVoiceCommands","silentUtterance","SpeechSynthesisUtterance","volume","speak","FaceScanErrorScreen","resetScanState","loading","config","translate","preferredLanguage","useContext","LanguageContext","LanguageKeys","scanFailed","_jsx","className","style","background","base","backgroundColor","children","_jsxs","Header","noTitle","resolvedConfig","fontFamily","heading","headingFontFamily","fontSize","headingFontSize","color","headingColor","fontWeight","headingFontWeight","subheading","subheadingFontFamily","subheadingFontSize","subheadingColor","subheadingFontWeight","clickToResetScan","SpecificButton","disabled","buttonText","postfixIcon","ArrowRight","buttonFunc","FaceScanGuide","videoLoading","setVideoLoading","videoError","setVideoError","gender","btnConfig","faceVisible","loadingVideo","videoLoadFailed","src","GenderType","Male","maleGlassesOffVideo","glassesOffVideo","autoPlay","loop","controls","muted","playsInline","onCanPlay","onLoadStart","onError","isDisabled","label","icon","onClick","FACE_SCAN_HEADSHOT","male","forward","female","type","left","right","smile","FaceScanStep","isError","isSuccess","showLoader","hasError","showGuideCard","getButtonText","isScanning","startScan","ParamsContext","useLocalConfig","setPreferredLanguage","language","LoadingScreen","url","loader","loaderType","_Fragment","id","crossOrigin","preload","position","zIndex","undefined","ref","transform","opacity","Drawer","open","anchor","onClose","event","reason","hideBackdrop","userDetails","onScanSuccess","onScanError","onRetry","mediaRecorderRef","recordedBlobsRef","streamRef","setShowLoader","modelReady","setModelReady","setIsScanning","setShowGuideCard","setHasError","setFaceScanId","generateUuid","email","deviceFocalLength","callbackUrl","supportedTypes","setSupportedTypes","stopRecording","state","stop","uploadFinalVideo","videoFile","File","fileSize","size","fileSizeMB","estimatedDuration","round","videoData","video_size_mb","video_size_bytes","blob_count","estimated_duration_seconds","metaData","face_scan_id","focal_length","customer_store_url","scan_type","callback_url","handleScanTimeCapture","eventName","uploadStartTime","startTime","res","swan","fileUpload","faceScanFileUploader","file","arrayMetaData","objectKey","contentType","uploadEndTime","uploadDuration","completionTime","measurement","handlFaceScaneSocket","onOpen","handleWebSocketCapture","faceScanID","connection","onSuccess","startRecording","stream","srcObject","settings","getVideoTracks","getSettings","canvas","videoEl","play","drawFrame","save","rotate","drawImage","restore","requestAnimationFrame","canvasStream","captureStream","mediaRecorderOptions","mimeType","mediaRecorder","MediaRecorder","ondataavailable","onstop","start","status","resultType","mediaDevices","getUserMedia","video","then","catch","getTracks","track","intervalId","setInterval","clearInterval","supported","videoTypes","isTypeSupported","init","posthogPublicKey","api_host","posthogPublicHost","LanguageContextProvider","Provider","value","reset"],"mappings":"yLA6BA,IAAIA,EAAyC,KACzCC,GAAe,EAiEnB,SAASC,GAAYC,WACnBA,EAAUC,YACVA,EAAWC,eACXA,EAAcC,aACdA,EAAYC,iBACZA,EAAgBC,WAChBA,IASA,MAAMC,EAAcC,EAAAA,OAA4B,OACzCC,EAAWC,GAAgBC,EAAAA,SAAS,IACpCC,EAAkBC,GAAuBF,EAAAA,SAAS,IAClDG,EAAeC,GAAoBJ,EAAAA,UAAS,IAC5CK,EAAkBC,GAAuBN,EAAAA,UAAS,GAEnDO,EAAeV,EAAAA,OAAwC,MACvDW,EAAeX,EAAAA,OAAOC,GACtBW,EAAsBZ,EAAAA,OAAOI,GAC7BS,EAAoBb,EAAAA,OAAkB,IACtCc,EAAuBd,EAAAA,OAAO,IAC9Be,EAAoBf,EAAAA,OAAO,GAC3BgB,EAAkBhB,EAAAA,QAAO,GAMzBiB,EAA0BjB,EAAAA,OAAO,GAGjCkB,EAA6B,oBAAdC,YACnB,mBAAmBC,KAAKD,UAAUE,YACV,aAAvBF,UAAUG,UAA2BH,UAAUI,eAAiB,GAG7DC,EAAoBC,EAAAA,QACxB,IAAM,CACJ,aACA,uBACA,wBACA,sBAE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