@swan-admin/swan-dev-web-component 0.1.0-alpha.1774936655 → 0.1.0-alpha.1774937896

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.
@@ -0,0 +1,2 @@
1
+ "use strict";var e=require("react/jsx-runtime"),t=require("react"),s=require("./LoadingScreen-CmNyZnEW.js"),n=require("clsx"),a=require("react-webcam"),r=require("lucide-react"),o=require("@mui/material"),c=require("video.js");const i="DESKTOP",l="TAB",u="MOBILE",d=t.createContext(void 0);function m({children:s}){const[n,a]=t.useState([window?.innerWidth,window?.innerHeight]),[r,o]=t.useState(!1),c=()=>{a([window?.innerWidth,window?.innerHeight])};t.useEffect(()=>{c()},[]),t.useLayoutEffect(()=>(window.addEventListener("resize",c),()=>window.removeEventListener("resize",c)),[c]);let m=i;n[0]>768&&n[0]<1024&&(m=l),n[0]<768&&(m=u);const f=t.useMemo(()=>({size:n,setSize:a,clearInputs:r,setClearInputs:o,media:m}),[n,r,m]);return e.jsx(d.Provider,{value:f,children:s})}var f=t.memo(function({size:t=16}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 25 25",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[e.jsx("path",{d:"M22.6968 14.6968C22.6968 16.8185 21.8539 18.8533 20.3536 20.3536C18.8533 21.8539 16.8185 22.6968 14.6968 22.6968",stroke:"white",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),e.jsx("path",{d:"M18.6968 11.6968V10.6968C18.6968 10.1663 18.4861 9.65764 18.111 9.28256C17.7359 8.90749 17.2272 8.69678 16.6968 8.69678C16.1663 8.69678 15.6576 8.90749 15.2826 9.28256C14.9075 9.65764 14.6968 10.1663 14.6968 10.6968",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),e.jsx("path",{d:"M14.6968 10.6968V9.69678C14.6968 9.16634 14.4861 8.65764 14.111 8.28256C13.7359 7.90749 13.2272 7.69678 12.6968 7.69678C12.1663 7.69678 11.6576 7.90749 11.2826 8.28256C10.9075 8.65764 10.6968 9.16634 10.6968 9.69678V10.6968",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),e.jsx("path",{d:"M10.6968 10.1968V4.69678C10.6968 4.16634 10.4861 3.65764 10.111 3.28256C9.73592 2.90749 9.22721 2.69678 8.69678 2.69678C8.16634 2.69678 7.65764 2.90749 7.28256 3.28256C6.90749 3.65764 6.69678 4.16634 6.69678 4.69678V14.6968",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),e.jsx("path",{d:"M18.6969 11.6968C18.6969 11.1663 18.9076 10.6576 19.2827 10.2826C19.6577 9.90749 20.1664 9.69678 20.6969 9.69678C21.2273 9.69678 21.736 9.90749 22.1111 10.2826C22.4862 10.6576 22.6969 11.1663 22.6969 11.6968V14.6968C22.6969 16.8185 21.854 18.8533 20.3537 20.3536C18.8534 21.8539 16.8186 22.6968 14.6969 22.6968H12.6969C9.89688 22.6968 8.19688 21.8368 6.70688 20.3568L3.10688 16.7568C2.76282 16.3757 2.57847 15.8769 2.592 15.3637C2.60554 14.8505 2.81593 14.3621 3.1796 13.9997C3.54327 13.6373 4.03238 13.4287 4.54565 13.417C5.05892 13.4053 5.55704 13.5914 5.93688 13.9368L7.69688 15.6968",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]})});var p=t.memo(function({angle:a,countdown:r,isScanning:o,isInTargetRange:c,stabilityScore:i,children:l}){const{translate:u}=t.useContext(s.LanguageContext)||{},d=s.useConfig(),m=t.useCallback(()=>a<80?Math.max(0,Math.min(100,10*(a-60))):a>95?Math.max(0,Math.min(100,10*(105-a))):100,[a]),p=t.useMemo(()=>{if(o)return d?.style?.angleDetector?.successAngleBackground||"#4f46e5";const e=m();if(0===e)return d?.style?.angleDetector?.successAngleLowBackground||"#ffffff";if(100===e)return d?.style?.angleDetector?.successAngleBackground||"#4f46e5";return`rgb(${Math.round(255-e/100*116)}, ${Math.round(255-e/100*163)}, ${Math.round(255-e/100*9)})`},[o,m]),h=t.useCallback((e,t)=>t>70?e?`text-[${d?.style?.angleDetector?.successAngleTextLightColor}]/70`:`text-[${d?.style?.angleDetector?.successAngleTextLightColor}]`:e?`text-[${d?.style?.angleDetector?.successAngleTextLightColor}]/40`:`text-[${d?.style?.angleDetector?.successAngleTextDarkColor}]/70`,[]),g=t.useCallback((e=!1)=>{const t=m();return o?`text-[${d?.style?.angleDetector?.successAngleTextLightColor}]`:h(e,t)},[o,m]),x=t.useCallback((e,t)=>t>70||e?d?.style?.angleDetector?.successAngleTextLightColor:d?.style?.angleDetector?.successAngleTextDarkColor,[]),y=t.useCallback((e=!1)=>{const t=m();return o?d?.style?.angleDetector?.successAngleTextLightColor:x(e,t)},[o,m]),S=r;function v(){document.documentElement.style.setProperty("--real-vh",window.innerHeight+"px")}return v(),window.addEventListener("resize",v),e.jsxs("div",{className:"flex common-ui-main w-screen flex-col items-center h-[var(--real-vh)] overflow-hidden touch-none justify-center transition-all duration-300 max-w-[28rem] mx-auto",style:{backgroundColor:p},children:[e.jsx("div",{className:"flex justify-start fixed top-[.5rem] max-w-[28rem] mx-auto w-full px-[1rem]",children:e.jsx("div",{className:"flex justify-start ",children:e.jsx(s.Header,{noTitle:!0})})}),null!==S?e.jsx("div",{className:"relative flex h-[6rem] w-[6rem] items-center justify-center rounded-[9999px] bg-[#fff]/20 transition-all duration-300",style:{border:`2px solid ${y()}`},children:e.jsx("div",{className:`text-[3rem] font-bold text-[${y()}]`,style:{fontFamily:d?.style?.base?.baseFontFamily||"Inter, sans-serif",color:y()},children:S})}):o?e.jsxs("div",{className:"relative flex flex-col items-center justify-center",children:[e.jsx("div",{className:"relative flex h-16 w-16 items-center justify-center rounded-[9999px] border-2 bg-[#fff]/30 border-[#fff]",children:e.jsx("div",{className:"h-4 w-4 rounded-[9999px] animate-pulse bg-[#fff]/80"})}),l]}):e.jsxs("div",{className:n("relative flex h-[4rem] w-[4rem] items-center justify-center rounded-[9999px] ",c?"bg-[#fff]/20 border-[#fff]":"bg-[#fff]/10 border-[#fff]"),style:{transform:`translateY(${3*(90-a)}px)`,transition:"transform 0.2s ease-out",border:`2px solid ${y()}`},children:[e.jsx("div",{className:`h-[1rem] w-[1rem] rounded-[9999px] bg-[${y()}]/80`,style:{backgroundColor:`${y()}B3`}}),e.jsxs("div",{className:n("mt-[.5rem] text-center w-[180px] flex-col flex items-center absolute top-[60px]",g()),style:{color:y()},children:[e.jsx(f,{size:30}),e.jsxs("p",{style:{fontFamily:d?.style?.base?.baseFontFamily||"Inter, sans-serif"},children:[" ",u?.(s.LanguageKeys.startLevelCheck),e.jsx("br",{})]})]})]}),null!==S&&e.jsx("div",{className:"absolute bottom-[8rem] text-center",children:e.jsx("div",{className:n("text-sm font-medium px-4 py-1.5 bg-black/20 rounded-[9999px] mt-8",g()),style:{fontFamily:d?.style?.base?.baseFontFamily||"Inter, sans-serif",color:y()},children:u?.(s.LanguageKeys.leavePhone)})}),c&&null===S&&!o&&e.jsx("div",{className:"absolute bottom-[8rem] w-[12rem]",children:e.jsx("div",{className:`h-[.375rem] w-full bg-[${y()}]/20 rounded-[9999px] overflow-hidden`,style:{backgroundColor:`${y()}33`},children:e.jsx("div",{className:`h-full bg-[${y()}]/70 transition-all duration-300 rounded-[9999px]`,style:{width:`${a}%`,backgroundColor:`${y()}B3`}})})}),null===S&&!o&&e.jsx("div",{className:"absolute bottom-[5rem] text-center",children:e.jsxs("div",{className:n("text-[1.5rem] font-light",g()),style:{color:y(),fontFamily:d?.style?.base?.baseFontFamily||"Inter, sans-serif"},children:[Math.round(a),"°"]})}),null===S&&!o&&e.jsx("div",{className:"absolute bottom-[2rem] text-center max-w-[20rem] mx-auto",children:e.jsx("div",{className:n("text-[.75rem] opacity-50",g()),style:{fontFamily:d?.style?.base?.baseFontFamily||"Inter, sans-serif",color:y()},children:u?.(s.LanguageKeys.placePhoneUpright)})})]})});function h({resetScan:n,loadingCam:o,onUserMedia:c,onPause:i,pause:l,recordingStarted:m,startSendingVideoFrames:f,showPause:p,webcamRef:h,onUserMediaError:g,resetDetector:x,videoConstraints:y,webcamKey:S}){const{media:v}=t.useContext(d)||{},{translate:b}=t.useContext(s.LanguageContext)||{};return e.jsxs("div",{className:"App w-screen h-[100vh] relative common-ui-main",children:[e.jsx("span",{onClick:()=>{n(),x()},className:"fixed right-[20px] top-[20px] z-[999]",children:e.jsx(r.X,{className:"text-[#fff]"})}),e.jsx("div",{className:"w-full h-full overflow-hidden ",children:v===u&&e.jsx(a,{audio:!1,ref:h,screenshotQuality:1,videoConstraints:y,mirrored:!0,screenshotFormat:"image/jpeg",onUserMedia:c,onUserMediaError:g,style:{position:"fixed",top:0,bottom:0,zIndex:0,width:"100%",height:"100%",objectFit:"cover"}},S)}),e.jsxs("div",{className:"fixed bottom-[30px] w-full z-[999] flex flex-col gap-4 items-center justify-center",children:[p&&e.jsx(s.SpecificButton,{className:"!w-[180px] !h-[40px] !py-[0] mx-auto ",prefix:s.pauseIcon,buttonText:b?.(s.LanguageKeys.pause),buttonFunc:i,btnSecondary:!0}),l?e.jsx("div",{children:e.jsx(s.SpecificButton,{className:"!w-[180px] !h-[40px] !py-[0] mx-auto",buttonText:b?.(s.LanguageKeys.restart),buttonFunc:n,btnSecondary:!0})}):m?null:e.jsx(s.SpecificButton,{className:"!w-[180px] !h-[40px] !py-[0] mx-auto !bg-[#ffffff] !text-[#000000] "+(o?"!opacity-50":""),buttonText:b?.(s.LanguageKeys.startScan),buttonFunc:f,disabled:o})]}),e.jsx("audio",{id:"audioElement",crossOrigin:"anonymous",preload:"auto",style:{position:"absolute",zIndex:-99999},src:`${s.voiceOverAssetsPath}scanAudioInstructions/silence.mp3`})]})}let g=null,x=null,y=null;let S,v=null,b=null;var C=t.memo(function({setIsScanLocked:n,resetDetector:a,scanID:r,setIsVideoUploaded:o,setScanFailsError:c,setScanStartTime:i,setScanUniqueKey:l,userDetails:u}){const{gender:d,heightInCm:m,email:f,shopDomain:p}=u,C=t.useRef(null),w=t.useRef(null),j=t.useRef(null),[N,k]=t.useState([]),[E,D]=t.useState(!0),[F,T]=t.useState(!1),[I,L]=t.useState(!1),[M,P]=t.useState(!0),[_,A]=t.useState(!1),$=t.useRef(null),[R,U]=t.useState(""),[z,O]=t.useState([]),[K,B]=t.useState(""),[q,V]=t.useState(!1),[W,H]=t.useState(!1),[G,J]=t.useState(!1),[Q,X]=t.useState([]),[Y,Z]=t.useState(!1),ee=t.useRef(!0),{poseDetector:te}=function(){const[e,s]=t.useState(0),[n,a]=t.useState(0),[r,o]=t.useState(!1),c=t.useRef(0),i=t.useRef(0),l=t.useRef(!0);async function u(){if("undefined"==typeof window||"undefined"==typeof navigator)return!1;try{console.log("Starting TensorFlow preload...");const[e,t,s]=await Promise.all([Promise.resolve().then(function(){return require("./pose-detection.esm-CDstzA1V.js")}),import("@tensorflow/tfjs-core"),import("@tensorflow/tfjs-backend-webgl")]);y=e,await t.setBackend("webgl"),await t.ready(),console.log("TensorFlow backend ready (WebGL)");const n={runtime:"mediapipe",modelType:"full",solutionPath:"https://cdn.jsdelivr.net/npm/@mediapipe/pose"};try{x=await y.createDetector(y.SupportedModels.BlazePose,n),console.log("MediaPipe detector created successfully")}catch(e){console.warn("MediaPipe failed, falling back to TFJS runtime:",e),x=await y.createDetector(y.SupportedModels.BlazePose,{runtime:"tfjs",modelType:"full"}),console.log("TFJS detector created successfully")}return!0}catch(e){return console.error("Failed to load TensorFlow dependencies:",e),g=null,!1}}function d(e){return!(!e||0===e.length)&&22===e.filter(e=>e[2]>.7).length}return t.useEffect(()=>{if(l.current=!0,!x)return g||(g=u()),g.then(e=>{e&&l.current&&o(!0)}),()=>{l.current=!1};o(!0)},[]),t.useEffect(()=>{i.current=e,e>6&&c.current<2&&(a(e=>e+1),s(0))},[e]),t.useEffect(()=>{c.current=n},[n]),{poseDetector:async(e,t)=>{if(!x||!l.current||!t?.current?.video)return;const n=t.current.video;if(!(n.readyState<2))try{const t=await x.estimatePoses(n,{flipHorizontal:!1});if(!t||!t.length)return;const a=t[0].keypoints.slice(11).map(e=>[e.x>0&&e.x<720?e.x:-1,e.y>0&&e.y<1280?e.y:-1,e.score??0]);0!==c.current||d(a)||s(e=>e+1),1===c.current&&d(a)&&s(e=>e+1),2===c.current&&e()}catch(e){console.error("Pose detection error:",e)}},isLoaded:r,spinPhase:n,resetDetector:()=>{c.current=0,i.current=0,s(0),a(0)},retryLoading:async()=>{x||g||(g=u(),await g&&l.current&&o(!0))}}}(),se=t.useRef(!0),ne=t.useRef(!1),ae=t.useRef(0),re=t.useRef(0),oe=t.useRef(!1),ce=t.useRef(!1),ie=t.useRef(()=>{}),[le,ue]=t.useState([]),[de,me]=t.useState(0),[fe,pe]=t.useState(s.videoConstraintsExact),{setStartGyro:he,uploadScanFile:ge,setUploadLoading:xe,swan:ye,onScanStart:Se,onCaptureComplete:ve}=t.useContext(s.ParamsContext),be=()=>{ne.current=!1,clearTimeout(S),$.current&&clearTimeout($.current),l(s.generateUuid()),c(""),xe?.(!1),k([]),j.current=null,D(!0),T(!1),L(!1),P(!0),A(!1),$.current=null,U(""),O([]),B(""),V(!q),he(!1),s.speechService.stopAudio(),H(!1),J(!1),ae.current=0,re.current=0,oe.current=!1,ce.current=!1,null!==w.current&&w.current.stop(),Q.forEach(e=>{w.current&&w.current.removeEventListener("dataavailable",e)}),X([]),ee.current=!0,Z(!1),o(!1),C.current?.stream&&D(!1)},Ce=t.useCallback(()=>{setTimeout(()=>{D(!1)},1e3)},[]),we=t.useCallback(e=>{if(console.log("camera error",e),fe===s.videoConstraintsExact)return pe(s.videoConstraintsFallback),void me(e=>e+1);D(!1)},[fe]),je=t.useCallback(()=>{ee.current=!1,J(!0),Z(!1),$.current&&clearTimeout($.current),w.current&&w.current.pause(),s.speechService.stopAudio(),ye.poseDetection.disconnect(),ae.current=0,re.current=0,oe.current=!1,ce.current=!1,w.current&&w.current.stop(),Q.forEach(e=>{w.current&&w.current.removeEventListener("dataavailable",e)}),X([]),clearTimeout(S)},[w,Q,s.speechService,ee]),Ne=t.useMemo(()=>s.getPreferredMediaRecorderTypes(),[]),ke=s.getRecordingMimeType(le),Ee=s.getRecordingExtension(ke),De=t.useCallback(async()=>{ee.current=!0,await s.speechService.playAudio(`${s.voiceOverAssetsPath}SpotOn.mp3`),J(!1),Z(!1),$.current&&clearTimeout($.current),T(!1)},[$,s.speechService]),Fe=t.useCallback(async()=>{try{v=await ye.poseDetection.connect(),console.log(v,"websocket connected"),s.posthog.capture(`${p}/pose_detection_connected`,{scanID:r,email:f,id:v})}catch(e){console.log(e,"while connecting websocket")}},[r,p,f]),Te=t.useCallback(async()=>{s.rescanSupportCaptureEvent({eventName:`${p}/rescan`,email:f,scanID:r,height:m,gender:d,status:!1}),ee.current=!1,ye.poseDetection.disconnect(),be(),await Fe(),Ae()},[Fe,r,f]),Ie=t.useCallback(({data:e})=>{e&&e.size>0&&ee.current&&(k(t=>t.concat(e)),!ne.current&&C.current&&(ne.current=!0,te(()=>{De(),s.handleScanTimeCapture({eventName:`${p}/tensorFlow`,scanID:r,email:f,message:"recording stopped by tensorflow "})},C)))},[De,s.handleScanTimeCapture,p,r,f,C]),Le=t.useCallback(async()=>{z.length>0&&ee.current&&(await s.speechService.playAudio(s.voiceOverAssetsPath+z[z.length-1]),ee.current&&(S=setTimeout(Le,2e3)))},[z,ee]),Me=t.useCallback(()=>{w&&w.current&&w.current.stop(),T(!0);try{if(C&&C.current&&C.current.stream){const e=C.current.stream.getVideoTracks()[0];if(e){const t=e.getSettings();j.current=t.frameRate||null}const t={videoBitsPerSecond:15e5};le[0]&&(t.mimeType=le[0]),w.current=new MediaRecorder(C.current.stream,t),w.current.addEventListener("dataavailable",Ie),X([...Q,Ie]),w.current.start(1e3),P(!1)}}catch(e){console.log("error while using media recorder",e)}},[C,le,Ie,Q]),Pe=t.useCallback(async()=>{$.current&&clearTimeout($.current),Me(),ee.current&&($.current=setTimeout(async()=>{ee.current&&(await s.speechService.playAudio(`${s.voiceOverAssetsPath}SpotOn.mp3`),T(!1))},15e3)),L(!0),ee.current&&await s.speechService.playAudio(`${s.voiceOverAssetsPath}Spin.mp3`)},[Me,ee,s.speechService]);t.useEffect(()=>{ie.current=Pe},[Pe]);const _e=t.useCallback(({data:e})=>{e.size>0&&ye.poseDetection.connected()&&(oe.current||(oe.current=!0,ye.poseDetection.poseStatus(async e=>{if(console.log("poseStatus data:",e),e&&e.audio&&e.audio.length>0){s.posthog.capture(`${p}/pose_instruction_received`,{scanID:r,email:f,audio:e.audio,status:e.status,sid:e.sid,counter:ae.current,consecutiveFalse:re.current,type:"body_scan_instruction"});const t=document.querySelector("#audioElement");!0===e.status&&e.sid===v?(re.current=0,ae.current<2?(ae.current+=1,1!==ae.current||ce.current?2===ae.current&&t?.paused&&s.speechService.playAudio(s.voiceOverAssetsPath+e.audio):(ce.current=!0,s.speechService.stopAudio(),await s.speechService.playAudio(s.voiceOverAssetsPath+e.audio))):(B(e.audio),clearTimeout(S),ye.poseDetection.disconnect(),oe.current=!1,setTimeout(()=>ie.current(),1e3))):(re.current+=1,re.current>=3&&(ae.current=0,ce.current=!1),!t?.paused||b&&b?.audioName===e.audio?b?.audioName===e.audio&&t?.paused&&(b&&b.no_of_times_skipped>=b.skipCount?(b.no_of_times_skipped=0,s.speechService.playAudio(s.voiceOverAssetsPath+e.audio)):b&&(b.no_of_times_skipped+=1)):(b={skipCount:2,no_of_times_skipped:0,audioName:e.audio},s.speechService.playAudio(s.voiceOverAssetsPath+e.audio)))}})),C?.current&&null!==C.current.getScreenshot()&&ye.poseDetection.videoEmit({image:C.current.getScreenshot()||"",scanId:r}))},[C,r,ye,v,s.speechService,p,f]),Ae=t.useCallback(async()=>{A(!0),he(!0),Se?.(),se.current&&(se.current=!1,s.handleScanTimeCapture({eventName:"scan started",scanID:r,status:"success",email:f})),i(s.getCurrentTimeInSeconds()),D(!0),ee.current&&await s.speechService.playAudio(`${s.voiceOverAssetsPath}StartScan.mp3`),ee.current&&await s.speechService.playAudio(`${s.voiceOverAssetsPath}LiftArmsAndHoldAtHip.mp3`),ee.current&&(A(!1),T(!0),H(!0),Z(!0),Ce());try{if(C&&C.current&&C.current.stream&&ee.current){const e=C.current.stream.getVideoTracks()[0];if(e){const t=e.getSettings();j.current=t.frameRate||null}const t={videoBitsPerSecond:15e5};le[0]&&(t.mimeType=le[0]),ee.current&&(w.current=new MediaRecorder(C.current.stream,t)),ee.current&&w.current&&w.current.addEventListener("dataavailable",_e),X([...Q,_e]),w.current&&w.current.start(1e3),P(!1),ee.current&&(S=setTimeout(Le,2e3))}}catch(e){console.log("error ----------",e)}},[C,le,_e,Q,Le,ee,Se]);return t.useEffect(()=>(p&&(n(!0),Fe()),()=>{v&&(ye.poseDetection.disconnect(),s.posthog.capture(`${p}/pose_detection_disconnected`,{scanID:r,email:f,id:v})),Q.forEach(e=>{w?.current?.removeEventListener("dataavailable",e)})}),[p]),t.useEffect(()=>{z.push(R)},[R]),t.useEffect(()=>{O([])},[K]),t.useEffect(()=>{const e=N.length&&N.length>0;M||!e||F||!ee.current||G||w&&w.current&&(F||(w.current.stop(),P(!0)))},[M,F,N,G]),t.useEffect(()=>{const e=N.length&&N.length>0;if(M||!e||F)console.log("No video found to upload.");else if(w&&w.current&&ee.current&&!G&&!F){const e=new File(N,`${r}.${Ee}`,{type:ke});ve?.(),xe?.(!0),c(""),ge?.(e,j.current)}},[M,F,N,G,w,ee]),t.useEffect(()=>{const e=s.getSupportedMediaRecorderTypes(Ne,s.videoTypes);ue(e)},[Ne]),t.useEffect(()=>{be()},[]),e.jsx(h,{resetDetector:a,resetScan:be,loadingCam:E,onPause:je,showRestart:W,pause:G,onReScan:Te,recordingStarted:F,isScanning:_,startSendingVideoFrames:Ae,faceDone:I,stopRecording:De,showPause:Y,webcamRef:C,onUserMedia:Ce,onUserMediaError:we,videoConstraints:fe,webcamKey:de})});function w({scanID:s,userDetails:n,setIsVideoUploaded:a,setScanFailsError:r,setScanStartTime:o,setScanUniqueKey:c}){const[i,l]=t.useState(90),[u,d]=t.useState(0),[m,f]=t.useState(null),[h,g]=t.useState(!1),[x,y]=t.useState(0),S=t.useRef([]),[v,b]=t.useState(!1),w=i-u,j=w>=80&&w<=95;t.useEffect(()=>{if("undefined"!=typeof window&&window.DeviceOrientationEvent){const e=e=>{if(null!==e.beta){let t=Math.abs(e.beta);null!==e.gamma&&(t*=Math.cos(e.gamma*Math.PI/180)),t=Math.max(0,Math.min(180,t)),l(t)}},t=async()=>{const t=DeviceOrientationEvent;if(t&&"function"==typeof t.requestPermission)try{"granted"===await t.requestPermission()&&window.addEventListener("deviceorientation",e)}catch(e){console.error("Permission error",e)}else window.addEventListener("deviceorientation",e);return()=>{e&&window.removeEventListener("deviceorientation",e)}};document.addEventListener("click",t,{once:!0})}},[]),t.useEffect(()=>{if(S.current=[...S.current.slice(-4),w],S.current.length>=5){const e=Math.max(...S.current)-Math.min(...S.current);y(j&&e<2?e=>Math.min(100,e+10):e=>Math.max(0,e-20))}j||null===m&&!h||k()},[w,j,m,h]),t.useEffect(()=>{x>=100&&null===m&&!h&&N(),x<50&&null!==m&&k()},[x,m,h]);const N=()=>{f(3);const e=setInterval(()=>{f(t=>null===t||t<=1?(clearInterval(e),g(!0),null):t-1)},1e3)},k=()=>{f(null),v||g(!1)};return e.jsx(p,{angle:w,countdown:m,isScanning:h,isInTargetRange:j,stabilityScore:x,children:h&&e.jsx(C,{setIsScanLocked:b,resetDetector:()=>{l(90),d(0),f(null),g(!1),y(0),b(!1),S.current=[]},scanID:s,userDetails:n,setIsVideoUploaded:a,setScanFailsError:r,setScanStartTime:o,setScanUniqueKey:c})})}function j({message:n,config:a}){const{translate:r}=t.useContext(s.LanguageContext)||{};return e.jsx(o.Dialog,{open:!0,className:"confirm-modal common-ui-main",disablePortal:!0,children:e.jsx("div",{className:"modal-main",children:e.jsx("div",{className:"text-center",children:n?e.jsxs(e.Fragment,{children:[e.jsx("h2",{className:"my-[0] ",style:{fontFamily:a?.style?.heading?.headingFontFamily||"SeriouslyNostalgic Fn",fontSize:a?.style?.heading?.headingFontSize||"32px",color:a?.style?.heading?.headingColor||"#000",fontWeight:a?.style?.heading?.headingFontWeight||"normal"},children:r?.(s.LanguageKeys.cameraAlreadyInUse)}),e.jsx("p",{className:"mt-[0.5rem] text-sm",style:{fontFamily:a?.style?.base?.baseFontFamily||"Inter, sans-serif",fontSize:a?.style?.base?.baseFontSize||"16px",color:a?.style?.base?.baseTextColor||"#000"},children:r?.(s.LanguageKeys.tryClosingBrowser)})]}):e.jsxs(e.Fragment,{children:[e.jsx("h2",{style:{fontFamily:a?.style?.heading?.headingFontFamily||"SeriouslyNostalgic Fn",fontSize:a?.style?.heading?.headingFontSize||"32px",color:a?.style?.heading?.headingColor||"#000",fontWeight:a?.style?.heading?.headingFontWeight||"normal"},children:r?.(s.LanguageKeys.checkCameraSettings)}),e.jsx("p",{className:"mt-[0.5rem] text-sm",style:{fontFamily:a?.style?.base?.baseFontFamily||"Inter, sans-serif",fontSize:a?.style?.base?.baseFontSize||"16px",color:a?.style?.base?.baseTextColor||"#000"},children:`${r?.(s.LanguageKeys.setting)} > ${s.getBrowserName()} > ${r?.(s.LanguageKeys.enableCameraPermissions)}`})]})})})})}function N({setShowDrawer:n,config:r,loader:o}){const[c,i]=t.useState({disabled:!1,message:""}),[l,u]=t.useState(!0),d=t.useRef(null),m=t.useCallback(async()=>{const e=await s.checkCameraPermission();i(e),u(!1)},[]);return t.useEffect(()=>{m()},[]),l?e.jsx(s.LoadingScreen,{url:o,loaderType:"black"}):c?.disabled?e.jsx(j,{config:r,message:c?.message}):e.jsx(a,{audio:!1,ref:d,screenshotQuality:1,videoConstraints:s.videoConstraints,mirrored:!0,onUserMedia:()=>n?.(!0),screenshotFormat:"image/jpeg",style:{position:"relative",top:0,bottom:0,zIndex:0,width:"100%",height:"100%",objectFit:"cover"}})}function k({link:n,onReady:a,wrapperClassName:r="[&_video]:rounded-t-[20px] w-full h-full"}){const o=t.useRef(null),i=t.useRef(null);let l={autoplay:!0,controls:!1,responsive:!0,fluid:!0,muted:!0,navigationUI:"hide",preload:"metadata",poster:s.videoPoster};return t.useEffect(()=>{if(!i.current&&n&&o?.current){const e=c(o.current,{...l});e.ready(()=>{i.current=e;const t={...l,sources:[{src:n,type:"application/x-mpegURL"}]};e.autoplay(t.autoplay),e.src(t.sources),a?.(e)})}},[n,o]),t.useEffect(()=>{const e=i.current;return()=>{e&&!e.isDisposed()&&(e.dispose(),i.current=null)}},[i]),e.jsx("div",{className:r,children:e.jsx("video",{ref:o,muted:!0,className:"video-js",playsInline:!0,onDrag:e=>e.preventDefault()})})}function E({scanFailsError:n,onNext:a,gender:c,setScanUniqueKey:i,setIsVideoUploaded:l}){const{translate:u}=t.useContext(s.LanguageContext)||{},d=s.useConfig(),[m,f]=t.useState(!1),p=()=>{f(!m)};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex common-ui-main flex-col h-full max-w-[28rem] mx-auto w-full rounded-t-[20px] overflow-y-auto",style:{background:d?.style?.base?.backgroundColor},children:[e.jsx("div",{className:"w-full max-w-[28rem] mx-auto pt-[1rem] px-[1rem]",children:e.jsx(s.Header,{noTitle:!0})}),e.jsx("div",{className:"flex-1",children:n&&e.jsxs("div",{className:"px-[1rem]",children:[e.jsx("h2",{className:"text-center",style:{fontFamily:d?.style?.heading?.headingFontFamily||"SeriouslyNostalgic Fn",fontSize:d?.style?.heading?.headingFontSize||"32px",color:d?.style?.heading?.headingColor||"#000",fontWeight:d?.style?.heading?.headingFontWeight||"normal"},children:u?.(s.LanguageKeys.issueWithScan)}),e.jsx("p",{style:{fontFamily:d?.style?.base?.baseFontFamily||"Inter, sans-serif",fontSize:d?.style?.base?.baseFontSize||"16px",color:d?.style?.base?.baseTextColor||"#1E1E1E"},children:u?.(s.LanguageKeys.reason)}),e.jsx("p",{style:{fontFamily:d?.style?.base?.baseFontFamily||"Inter, sans-serif",fontSize:d?.style?.base?.baseFontSize||"16px",color:d?.style?.base?.baseTextColor||"#1E1E1E"},children:s.handleErrorMessage(n)}),e.jsx("img",{className:"my-[0.5rem] aspect-[2/1.4] w-full object-cover",onClick:p,src:s.VIDEO_POSTER_GENDER_BASED[c],alt:"icon"})]})}),n&&e.jsx("div",{className:"p-[1rem] flex gap-[0.5rem]",children:e.jsx(s.SpecificButton,{disabled:!1,buttonText:u?.(s.LanguageKeys.scanAgain),className:"!shadow-none",buttonFunc:()=>{a?a?.():i?.(s.generateUuid()),l?.(!1)}})})]}),m&&e.jsxs(o.Dialog,{className:"w-screen h-screen video-modal",onClose:p,open:m,disablePortal:!0,children:[e.jsx("div",{className:"flex justifyEnd ",children:e.jsx("span",{className:"closeBtn",onClick:p,children:e.jsx(r.X,{className:"absolute right-[8px] top-[8px] text-white z-[9]"})})}),e.jsx("div",{className:"aspect-video object-cover rounded-[20px] ",children:e.jsx(k,{link:c?s.GENDER[c].PRE_LINK:s.GENDER.male.PRE_LINK,wrapperClassName:"w-screen h-screen fixed top-[0] left-[0]"})})]})]})}function D({scanId:n,userDetails:a,config:r,isVideoUploadedCorrect:c,isMeasurementAvailable:i,onComplete:l,isSuccess:u,onCustomScanSuccess:d,swan:m}){const{gender:f,shopDomain:p,heightInCm:h,deviceFocalLength:g,userName:x,email:y,scanType:S}=a||{},v=[s.CLOTHING_CUSTOM_SCAN,s.CLOTHING_BANNER_SCAN,s.CLOTHING_CUSTOM_FIT_SCAN].includes(S??""),[b,C]=t.useState(!0),w=t.useCallback(async()=>{try{v&&(await(m?.auth.addUser({scanId:n,email:y,name:x,gender:f,height:h})),d?.()),s.posthog.capture(p??"",{scanID:n,email:y,height:h,focalLength:g,clothesFit:"0",gender:f})}catch(e){console.log(e)}},[v]),{translate:j}=t.useContext(s.LanguageContext)||{};t.useEffect(()=>{(c||i)&&w()},[c,i]);const k=u||c||i;return e.jsx(o.Box,{className:"flex h-full w-full flex-col common-ui-main",children:e.jsxs("div",{className:"h-full w-full flex-col items-center justify-center flex",children:[e.jsx(N,{loader:r?.loader,setShowDrawer:C}),e.jsx(o.Drawer,{open:b,onClose:(e,t)=>{},disablePortal:!0,className:"camera-drawer",anchor:"bottom",children:e.jsx("div",{className:"max-w-[28rem] mx-auto w-full h-full flex text-center flex-col justify-between items-center bg-primary rounded-t-[30px] p-[1rem]",style:{background:r?.style?.base?.backgroundColor},children:e.jsxs("div",{className:"w-full h-full flex flex-col",children:[e.jsx(s.Header,{title:j?.(s.LanguageKeys.measurementsBeingTaken)}),e.jsx("div",{className:"flex items-center justify-center flex-1",children:e.jsx("video",{preload:"auto",className:"max-h-[calc(100vh-450px)] mx-auto w-full object-contain border-none",muted:!0,loop:!0,autoPlay:!0,playsInline:!0,children:e.jsx("source",{src:f===s.GenderType.Male?s.maleMeasurementProgress:s.measurementProgress,type:"video/mp4"})})}),k&&e.jsx(s.SpecificButton,{className:"!w-[180px] mx-auto",buttonText:j?.(s.LanguageKeys.next),buttonFunc:()=>{l?.()}})]})})})]})})}const F=()=>{const{userDetails:n,onRetry:a,isError:r,isSuccess:c,gender:i,scanUniqueKey:l,scanFailsError:u,setScanUniqueKey:d,setIsVideoUploaded:m,isMeasurementAvailable:f,isVideoUploadedCorrect:p,loading:h,showDeniedModal:g,uploadLoading:x,setScanFailsError:y,setScanStartTime:S,resetScan:v,onCustomScanSuccess:b,swan:C,onComplete:k}=t.useContext(s.ParamsContext),F=s.useConfig();return r?e.jsxs(e.Fragment,{children:[e.jsx(N,{}),e.jsx(o.Drawer,{anchor:"bottom",open:!0,className:"camera-drawer",onClose:(e,t)=>{},disablePortal:!0,children:e.jsx(E,{scanFailsError:!0,onNext:a,gender:i})})]}):c?e.jsx(D,{isSuccess:!0,onComplete:k,config:F}):h?e.jsx("div",{className:"flex top-0 !mt-0 left-0 z-[999] absolute justify-center items-center w-full h-full",style:{background:F?.style?.base?.backgroundColor},children:e.jsx(s.LoadingScreen,{url:F?.loader,loaderType:"black"})}):g.disabled?e.jsx(j,{}):x||u||f||p?(x||f||p)&&!u?e.jsx(D,{scanId:l,isMeasurementAvailable:f,userDetails:n,isVideoUploadedCorrect:p,onCustomScanSuccess:b,swan:C,onComplete:k,config:F}):e.jsxs(e.Fragment,{children:[e.jsx(N,{}),e.jsx(o.Drawer,{anchor:"bottom",open:!0,className:"camera-drawer",onClose:(e,t)=>{},disablePortal:!0,children:e.jsx(E,{scanFailsError:u,onNext:()=>{a?.(),v()},setScanUniqueKey:d,gender:i,setIsVideoUploaded:m})})]}):e.jsx(w,{scanID:l,userDetails:n,setIsVideoUploaded:m,setScanFailsError:y,setScanStartTime:S,setScanUniqueKey:d})};exports.BodyScan=n=>{const{config:a,onRetry:r,onScanStart:o,onCaptureComplete:c,onUploadStart:i,onUploadEnd:l,onMeasurementSocketStart:u,onMeasurementSocketClose:d,onIntermediateScanSuccess:f,onScanError:p,onScanSuccess:h,onCustomScanSuccess:g,onComplete:x,isError:y,isSuccess:S}=n,v={email:"",shopDomain:"",gender:"male",heightInCm:0,scanType:"",deviceFocalLength:0,deviceModelName:"",sourceTag:"",...n.userDetails??{}},b=n.token??"",{gender:C,scanType:w,shopDomain:j,heightInCm:N,email:k,deviceFocalLength:E,deviceModelName:D,callbackUrl:T,sourceTag:I}=v,L=t.useMemo(()=>s.getSwanService(b),[b]),[M,P]=t.useState(!1),[_,A]=t.useState(!1),[$,R]=t.useState(!1),[U,z]=t.useState({disabled:!1,message:""}),[O,K]=t.useState(""),[B,q]=t.useState(!1),[V,W]=t.useState(!0),[H,G]=t.useState(!1),[J,Q]=t.useState(""),[X,Y]=t.useState(s.getCurrentTimeInSeconds()),{gyroData:Z}=function(e){const[s,n]=t.useState([]),[a,r]=t.useState(!1),o=t.useCallback(e=>{try{const{alpha:t,beta:s,gamma:a}=e;n(e=>[...e,{alpha:t?.toString()||void 0,beta:s?.toString()||void 0,gamma:a?.toString()||void 0,timestamp:(new Date).toISOString()}])}catch(e){console.log(e)}},[]),c=t.useCallback(async()=>{const e=DeviceOrientationEvent;if(void 0!==e&&"function"==typeof e.requestPermission)try{"granted"===await e.requestPermission()?r(!0):console.warn("Device orientation permission denied.")}catch(e){console.error("Error requesting device orientation permission:",e)}else r(!0)},[]);return t.useEffect(()=>(e&&a?window.addEventListener("deviceorientation",o):n([]),()=>{window.removeEventListener("deviceorientation",o)}),[e,a,o]),t.useEffect(()=>{e&&c()},[e,c]),{gyroData:s}}(H);s.usePosthogPageview();const ee=t.useCallback(()=>{Q(s.generateUuid()),K(""),P(!1),q(!1)},[]),te=()=>{Y(null),Q("")},se=t.useCallback(async e=>{if(e&&"success"===e?.scanStatus&&"intermediate"===e?.resultType&&200===e?.code)return s.handleScanTimeCapture({eventName:`${j}/measurement_success/intermediate`,scanID:J,status:"success",email:k}),A(!0),void f?.(e);h?.(e),A(!0),te();const t=J;R(!0),s.handleScanTimeCapture({eventName:`${j}/measurement_success/fit-view`,scanID:t,status:"success",email:k}),X&&s.handleScanTimeCapture({eventName:`${j}/scan_completion_time`,scanID:t,status:"success",completionTime:s.getCurrentTimeInSeconds()-X,email:k})},[w,j,J]),ne=e=>{R(!1),K(""),A(!1),L.measurement.handleMeasurementSocket({scanId:J,onPreopen:()=>{s.handleWebSocketCapture({eventName:`${j}/webSocket`,scanID:J,connection:"pre_open",type:"measurement_recommendation",email:k})},onOpen:()=>{u?.(),s.handleWebSocketCapture({eventName:`${j}/webSocket`,scanID:J,connection:"open",type:"measurement_recommendation",email:k})},onClose:()=>{d?.(),s.handleWebSocketCapture({eventName:`${j}/webSocket`,scanID:J,connection:"close",type:"measurement_recommendation",email:k})},onError:e=>{var t;t=e,p?.({...t,message:s.handleErrorMessage(t)}),te(),R(!1),K(t),A(!1),s.handleScanTimeCapture({eventName:`${j}/measurement_failed/fit-view`,scanID:J,status:"failed",email:k,message:s.handleErrorMessage(t)}),X&&s.handleScanTimeCapture({eventName:`${j}/scan_completion_time`,scanID:J,status:"failed",completionTime:s.getCurrentTimeInSeconds()-X,email:k}),s.handleWebSocketCapture({eventName:`${j}/webSocket`,scanID:J,connection:"error",type:"measurement_recommendation",email:k})},onSuccess:e=>{s.handleWebSocketCapture({eventName:`${j}/webSocket`,scanID:J,connection:"success",type:"measurement_recommendation",email:k}),se(e)}})},ae=t.useCallback(async(e,t)=>{const n=Number((e.size/1048576).toFixed(2)),a=null!=t?t:await s.getVideoFPS(e),r=s.createObjectMetadataArray({gender:C,focal_length:`${E}`,height:`${N}`,customer_store_url:j,clothes_fit:"0",scan_type:w,callback_url:T,source_tag:I});s.handleScanTimeCapture({eventName:`${j}/body_scan_meta_data`,scanID:J,email:k,data:JSON.stringify([...r,{fileSizeInMB:n,video_fps:a||0}])}),i?.();try{await L.fileUpload.uploadFileFrontend({file:e,arrayMetaData:r,scanId:J,email:k}),await L.fileUpload.setDeviceInfo({model:D,detection:"manual",gyro:Z,scanId:J}),console.log("video successfully uploaded"),q(!1),s.handleScanTimeCapture({eventName:`${j}/scan_success`,scanID:J,status:"success",email:k,data:JSON.stringify(r)}),s.handleScanTimeCapture({eventName:"scan finished",scanID:J,status:"success",email:k}),Y(s.getCurrentTimeInSeconds()),setTimeout(()=>{q(!0)},3e3)}catch(e){s.handleScanTimeCapture({eventName:"scan finished",scanID:J,status:"failed",email:k,message:s.handleErrorMessage(e)}),s.handleScanTimeCapture({eventName:`${j}/scan_failed`,scanID:J,status:"failed",email:k,message:s.handleErrorMessage(e),data:JSON.stringify(r)}),K(s.handleErrorMessage(e)),q(!1),p?.({...e,message:s.handleErrorMessage(e)}),te()}finally{G(!1),l?.()}},[J,Z,i,l]),re=t.useCallback(async()=>{if(+N<152.4||+N>213.36)return void p?.({message:"Height must be between 152.4cm (5ft) and 213.36cm (7ft)"});const e=await s.checkCameraPermission();e.disabled?(s.handleScanTimeCapture({eventName:`${j}/camera_activation`,scanID:J,status:"failed",email:k}),W(!1)):(W(!1),s.handleScanTimeCapture({eventName:`${j}/camera_activation`,scanID:J,status:"success",email:k})),z(e),K(""),q(!1)},[k,J,Q,j]);return t.useEffect(()=>{y||S||j&&re()},[j,N,y,S]),t.useEffect(()=>{y||S||B&&j&&J&&ne()},[B,j,J,y,S]),e.jsx(s.LanguageContextProvider,{children:e.jsx(s.ConfigProvider,{config:a,children:e.jsx(m,{children:e.jsx(s.ParamsContext.Provider,{value:{userDetails:v,onRetry:r,onScanError:p,isError:y,isSuccess:S,onScanSuccess:h,gender:C,scanUniqueKey:J,scanFailsError:O,setScanUniqueKey:Q,setIsVideoUploaded:q,isMeasurementAvailable:$,isVideoUploadedCorrect:_,loading:V,showDeniedModal:U,uploadLoading:M,setStartGyro:G,uploadScanFile:ae,setUploadLoading:P,resetScan:ee,setScanFailsError:K,setScanStartTime:Y,onScanStart:o,onCaptureComplete:c,onCustomScanSuccess:g,onComplete:x,swan:L},children:e.jsx(s.ShadowRoot,{children:e.jsx(F,{})})})})})})};
2
+ //# sourceMappingURL=BodyScan-DIsFyZzn.js.map
@@ -0,0 +1,2 @@
1
+ import{jsx as e,jsxs as t,Fragment as n}from"react/jsx-runtime";import a,{useState as r,useCallback as s,useEffect as o,createContext as i,useLayoutEffect as c,useMemo as l,useContext as d,useRef as u}from"react";import{L as m,u as p,H as f,b as h,S as g,z as y,v,h as w,P as b,n as x,s as S,i as N,j as C,k as D,p as F,A as I,x as k,B as T,o as E,e as L,q as $,D as M,E as _,c as U,a as P,I as A,J as z,V as j,K as V,M as B,N as R,G as q,O as K,Q as W,R as O,f as H,l as J,w as G,T as Q,r as Y,C as X,t as Z,y as ee}from"./LoadingScreen-DtPpNDue.js";import te from"clsx";import ne from"react-webcam";import{X as ae}from"lucide-react";import{Dialog as re,Box as se,Drawer as oe}from"@mui/material";import ie from"video.js";const ce="DESKTOP",le="TAB",de="MOBILE",ue=i(void 0);function me({children:t}){const[n,a]=r([window?.innerWidth,window?.innerHeight]),[s,i]=r(!1),d=()=>{a([window?.innerWidth,window?.innerHeight])};o(()=>{d()},[]),c(()=>(window.addEventListener("resize",d),()=>window.removeEventListener("resize",d)),[d]);let u=ce;n[0]>768&&n[0]<1024&&(u=le),n[0]<768&&(u=de);const m=l(()=>({size:n,setSize:a,clearInputs:s,setClearInputs:i,media:u}),[n,s,u]);return e(ue.Provider,{value:m,children:t})}var pe=a.memo(function({size:n=16}){return t("svg",{width:n,height:n,viewBox:"0 0 25 25",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[e("path",{d:"M22.6968 14.6968C22.6968 16.8185 21.8539 18.8533 20.3536 20.3536C18.8533 21.8539 16.8185 22.6968 14.6968 22.6968",stroke:"white",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),e("path",{d:"M18.6968 11.6968V10.6968C18.6968 10.1663 18.4861 9.65764 18.111 9.28256C17.7359 8.90749 17.2272 8.69678 16.6968 8.69678C16.1663 8.69678 15.6576 8.90749 15.2826 9.28256C14.9075 9.65764 14.6968 10.1663 14.6968 10.6968",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),e("path",{d:"M14.6968 10.6968V9.69678C14.6968 9.16634 14.4861 8.65764 14.111 8.28256C13.7359 7.90749 13.2272 7.69678 12.6968 7.69678C12.1663 7.69678 11.6576 7.90749 11.2826 8.28256C10.9075 8.65764 10.6968 9.16634 10.6968 9.69678V10.6968",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),e("path",{d:"M10.6968 10.1968V4.69678C10.6968 4.16634 10.4861 3.65764 10.111 3.28256C9.73592 2.90749 9.22721 2.69678 8.69678 2.69678C8.16634 2.69678 7.65764 2.90749 7.28256 3.28256C6.90749 3.65764 6.69678 4.16634 6.69678 4.69678V14.6968",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),e("path",{d:"M18.6969 11.6968C18.6969 11.1663 18.9076 10.6576 19.2827 10.2826C19.6577 9.90749 20.1664 9.69678 20.6969 9.69678C21.2273 9.69678 21.736 9.90749 22.1111 10.2826C22.4862 10.6576 22.6969 11.1663 22.6969 11.6968V14.6968C22.6969 16.8185 21.854 18.8533 20.3537 20.3536C18.8534 21.8539 16.8186 22.6968 14.6969 22.6968H12.6969C9.89688 22.6968 8.19688 21.8368 6.70688 20.3568L3.10688 16.7568C2.76282 16.3757 2.57847 15.8769 2.592 15.3637C2.60554 14.8505 2.81593 14.3621 3.1796 13.9997C3.54327 13.6373 4.03238 13.4287 4.54565 13.417C5.05892 13.4053 5.55704 13.5914 5.93688 13.9368L7.69688 15.6968",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]})});var fe=a.memo(function({angle:n,countdown:a,isScanning:r,isInTargetRange:o,stabilityScore:i,children:c}){const{translate:u}=d(m)||{},g=p(),y=s(()=>n<80?Math.max(0,Math.min(100,10*(n-60))):n>95?Math.max(0,Math.min(100,10*(105-n))):100,[n]),v=l(()=>{if(r)return g?.style?.angleDetector?.successAngleBackground||"#4f46e5";const e=y();if(0===e)return g?.style?.angleDetector?.successAngleLowBackground||"#ffffff";if(100===e)return g?.style?.angleDetector?.successAngleBackground||"#4f46e5";return`rgb(${Math.round(255-e/100*116)}, ${Math.round(255-e/100*163)}, ${Math.round(255-e/100*9)})`},[r,y]),w=s((e,t)=>t>70?e?`text-[${g?.style?.angleDetector?.successAngleTextLightColor}]/70`:`text-[${g?.style?.angleDetector?.successAngleTextLightColor}]`:e?`text-[${g?.style?.angleDetector?.successAngleTextLightColor}]/40`:`text-[${g?.style?.angleDetector?.successAngleTextDarkColor}]/70`,[]),b=s((e=!1)=>{const t=y();return r?`text-[${g?.style?.angleDetector?.successAngleTextLightColor}]`:w(e,t)},[r,y]),x=s((e,t)=>t>70||e?g?.style?.angleDetector?.successAngleTextLightColor:g?.style?.angleDetector?.successAngleTextDarkColor,[]),S=s((e=!1)=>{const t=y();return r?g?.style?.angleDetector?.successAngleTextLightColor:x(e,t)},[r,y]),N=a;function C(){document.documentElement.style.setProperty("--real-vh",window.innerHeight+"px")}return C(),window.addEventListener("resize",C),t("div",{className:"flex common-ui-main w-screen flex-col items-center h-[var(--real-vh)] overflow-hidden touch-none justify-center transition-all duration-300 max-w-[28rem] mx-auto",style:{backgroundColor:v},children:[e("div",{className:"flex justify-start fixed top-[.5rem] max-w-[28rem] mx-auto w-full px-[1rem]",children:e("div",{className:"flex justify-start ",children:e(f,{noTitle:!0})})}),null!==N?e("div",{className:"relative flex h-[6rem] w-[6rem] items-center justify-center rounded-[9999px] bg-[#fff]/20 transition-all duration-300",style:{border:`2px solid ${S()}`},children:e("div",{className:`text-[3rem] font-bold text-[${S()}]`,style:{fontFamily:g?.style?.base?.baseFontFamily||"Inter, sans-serif",color:S()},children:N})}):t("div",r?{className:"relative flex flex-col items-center justify-center",children:[e("div",{className:"relative flex h-16 w-16 items-center justify-center rounded-[9999px] border-2 bg-[#fff]/30 border-[#fff]",children:e("div",{className:"h-4 w-4 rounded-[9999px] animate-pulse bg-[#fff]/80"})}),c]}:{className:te("relative flex h-[4rem] w-[4rem] items-center justify-center rounded-[9999px] ",o?"bg-[#fff]/20 border-[#fff]":"bg-[#fff]/10 border-[#fff]"),style:{transform:`translateY(${3*(90-n)}px)`,transition:"transform 0.2s ease-out",border:`2px solid ${S()}`},children:[e("div",{className:`h-[1rem] w-[1rem] rounded-[9999px] bg-[${S()}]/80`,style:{backgroundColor:`${S()}B3`}}),t("div",{className:te("mt-[.5rem] text-center w-[180px] flex-col flex items-center absolute top-[60px]",b()),style:{color:S()},children:[e(pe,{size:30}),t("p",{style:{fontFamily:g?.style?.base?.baseFontFamily||"Inter, sans-serif"},children:[" ",u?.(h.startLevelCheck),e("br",{})]})]})]}),null!==N&&e("div",{className:"absolute bottom-[8rem] text-center",children:e("div",{className:te("text-sm font-medium px-4 py-1.5 bg-black/20 rounded-[9999px] mt-8",b()),style:{fontFamily:g?.style?.base?.baseFontFamily||"Inter, sans-serif",color:S()},children:u?.(h.leavePhone)})}),o&&null===N&&!r&&e("div",{className:"absolute bottom-[8rem] w-[12rem]",children:e("div",{className:`h-[.375rem] w-full bg-[${S()}]/20 rounded-[9999px] overflow-hidden`,style:{backgroundColor:`${S()}33`},children:e("div",{className:`h-full bg-[${S()}]/70 transition-all duration-300 rounded-[9999px]`,style:{width:`${n}%`,backgroundColor:`${S()}B3`}})})}),null===N&&!r&&e("div",{className:"absolute bottom-[5rem] text-center",children:t("div",{className:te("text-[1.5rem] font-light",b()),style:{color:S(),fontFamily:g?.style?.base?.baseFontFamily||"Inter, sans-serif"},children:[Math.round(n),"°"]})}),null===N&&!r&&e("div",{className:"absolute bottom-[2rem] text-center max-w-[20rem] mx-auto",children:e("div",{className:te("text-[.75rem] opacity-50",b()),style:{fontFamily:g?.style?.base?.baseFontFamily||"Inter, sans-serif",color:S()},children:u?.(h.placePhoneUpright)})})]})});function he({resetScan:n,loadingCam:a,onUserMedia:r,onPause:s,pause:o,recordingStarted:i,startSendingVideoFrames:c,showPause:l,webcamRef:u,onUserMediaError:p,resetDetector:f,videoConstraints:w,webcamKey:b}){const{media:x}=d(ue)||{},{translate:S}=d(m)||{};return t("div",{className:"App w-screen h-[100vh] relative common-ui-main",children:[e("span",{onClick:()=>{n(),f()},className:"fixed right-[20px] top-[20px] z-[999]",children:e(ae,{className:"text-[#fff]"})}),e("div",{className:"w-full h-full overflow-hidden ",children:x===de&&e(ne,{audio:!1,ref:u,screenshotQuality:1,videoConstraints:w,mirrored:!0,screenshotFormat:"image/jpeg",onUserMedia:r,onUserMediaError:p,style:{position:"fixed",top:0,bottom:0,zIndex:0,width:"100%",height:"100%",objectFit:"cover"}},b)}),t("div",{className:"fixed bottom-[30px] w-full z-[999] flex flex-col gap-4 items-center justify-center",children:[l&&e(g,{className:"!w-[180px] !h-[40px] !py-[0] mx-auto ",prefix:y,buttonText:S?.(h.pause),buttonFunc:s,btnSecondary:!0}),o?e("div",{children:e(g,{className:"!w-[180px] !h-[40px] !py-[0] mx-auto",buttonText:S?.(h.restart),buttonFunc:n,btnSecondary:!0})}):i?null:e(g,{className:"!w-[180px] !h-[40px] !py-[0] mx-auto !bg-[#ffffff] !text-[#000000] "+(a?"!opacity-50":""),buttonText:S?.(h.startScan),buttonFunc:c,disabled:a})]}),e("audio",{id:"audioElement",crossOrigin:"anonymous",preload:"auto",style:{position:"absolute",zIndex:-99999},src:`${v}scanAudioInstructions/silence.mp3`})]})}let ge=null,ye=null,ve=null;let we,be=null,xe=null;var Se=a.memo(function({setIsScanLocked:t,resetDetector:n,scanID:a,setIsVideoUploaded:i,setScanFailsError:c,setScanStartTime:m,setScanUniqueKey:p,userDetails:f}){const{gender:h,heightInCm:g,email:y,shopDomain:M}=f,_=u(null),U=u(null),P=u(null),[A,z]=r([]),[j,V]=r(!0),[B,R]=r(!1),[q,K]=r(!1),[W,O]=r(!0),[H,J]=r(!1),G=u(null),[Q,Y]=r(""),[X,Z]=r([]),[ee,te]=r(""),[ne,ae]=r(!1),[re,se]=r(!1),[oe,ie]=r(!1),[ce,le]=r([]),[de,ue]=r(!1),me=u(!0),{poseDetector:pe}=function(){const[e,t]=r(0),[n,a]=r(0),[s,i]=r(!1),c=u(0),l=u(0),d=u(!0);async function m(){if("undefined"==typeof window||"undefined"==typeof navigator)return!1;try{console.log("Starting TensorFlow preload...");const[e,t,n]=await Promise.all([import("./pose-detection.esm-DmD8en-O.js"),import("@tensorflow/tfjs-core"),import("@tensorflow/tfjs-backend-webgl")]);ve=e,await t.setBackend("webgl"),await t.ready(),console.log("TensorFlow backend ready (WebGL)");const a={runtime:"mediapipe",modelType:"full",solutionPath:"https://cdn.jsdelivr.net/npm/@mediapipe/pose"};try{ye=await ve.createDetector(ve.SupportedModels.BlazePose,a),console.log("MediaPipe detector created successfully")}catch(e){console.warn("MediaPipe failed, falling back to TFJS runtime:",e),ye=await ve.createDetector(ve.SupportedModels.BlazePose,{runtime:"tfjs",modelType:"full"}),console.log("TFJS detector created successfully")}return!0}catch(e){return console.error("Failed to load TensorFlow dependencies:",e),ge=null,!1}}function p(e){return!(!e||0===e.length)&&22===e.filter(e=>e[2]>.7).length}return o(()=>{if(d.current=!0,!ye)return ge||(ge=m()),ge.then(e=>{e&&d.current&&i(!0)}),()=>{d.current=!1};i(!0)},[]),o(()=>{l.current=e,e>6&&c.current<2&&(a(e=>e+1),t(0))},[e]),o(()=>{c.current=n},[n]),{poseDetector:async(e,n)=>{if(!ye||!d.current||!n?.current?.video)return;const a=n.current.video;if(!(a.readyState<2))try{const n=await ye.estimatePoses(a,{flipHorizontal:!1});if(!n||!n.length)return;const r=n[0].keypoints.slice(11).map(e=>[e.x>0&&e.x<720?e.x:-1,e.y>0&&e.y<1280?e.y:-1,e.score??0]);0!==c.current||p(r)||t(e=>e+1),1===c.current&&p(r)&&t(e=>e+1),2===c.current&&e()}catch(e){console.error("Pose detection error:",e)}},isLoaded:s,spinPhase:n,resetDetector:()=>{c.current=0,l.current=0,t(0),a(0)},retryLoading:async()=>{ye||ge||(ge=m(),await ge&&d.current&&i(!0))}}}(),fe=u(!0),Se=u(!1),Ne=u(0),Ce=u(0),De=u(!1),Fe=u(!1),Ie=u(()=>{}),[ke,Te]=r([]),[Ee,Le]=r(0),[$e,Me]=r(w),{setStartGyro:_e,uploadScanFile:Ue,setUploadLoading:Pe,swan:Ae,onScanStart:ze,onCaptureComplete:je}=d(b),Ve=()=>{Se.current=!1,clearTimeout(we),G.current&&clearTimeout(G.current),p(L()),c(""),Pe?.(!1),z([]),P.current=null,V(!0),R(!1),K(!1),O(!0),J(!1),G.current=null,Y(""),Z([]),te(""),ae(!ne),_e(!1),S.stopAudio(),se(!1),ie(!1),Ne.current=0,Ce.current=0,De.current=!1,Fe.current=!1,null!==U.current&&U.current.stop(),ce.forEach(e=>{U.current&&U.current.removeEventListener("dataavailable",e)}),le([]),me.current=!0,ue(!1),i(!1),_.current?.stream&&V(!1)},Be=s(()=>{setTimeout(()=>{V(!1)},1e3)},[]),Re=s(e=>{if(console.log("camera error",e),$e===w)return Me(x),void Le(e=>e+1);V(!1)},[$e]),qe=s(()=>{me.current=!1,ie(!0),ue(!1),G.current&&clearTimeout(G.current),U.current&&U.current.pause(),S.stopAudio(),Ae.poseDetection.disconnect(),Ne.current=0,Ce.current=0,De.current=!1,Fe.current=!1,U.current&&U.current.stop(),ce.forEach(e=>{U.current&&U.current.removeEventListener("dataavailable",e)}),le([]),clearTimeout(we)},[U,ce,S,me]),Ke=l(()=>N(),[]),We=C(ke),Oe=D(We),He=s(async()=>{me.current=!0,await S.playAudio(`${v}SpotOn.mp3`),ie(!1),ue(!1),G.current&&clearTimeout(G.current),R(!1)},[G,S]),Je=s(async()=>{try{be=await Ae.poseDetection.connect(),console.log(be,"websocket connected"),F.capture(`${M}/pose_detection_connected`,{scanID:a,email:y,id:be})}catch(e){console.log(e,"while connecting websocket")}},[a,M,y]),Ge=s(async()=>{I({eventName:`${M}/rescan`,email:y,scanID:a,height:g,gender:h,status:!1}),me.current=!1,Ae.poseDetection.disconnect(),Ve(),await Je(),tt()},[Je,a,y]),Qe=s(({data:e})=>{e&&e.size>0&&me.current&&(z(t=>t.concat(e)),!Se.current&&_.current&&(Se.current=!0,pe(()=>{He(),k({eventName:`${M}/tensorFlow`,scanID:a,email:y,message:"recording stopped by tensorflow "})},_)))},[He,k,M,a,y,_]),Ye=s(async()=>{X.length>0&&me.current&&(await S.playAudio(v+X[X.length-1]),me.current&&(we=setTimeout(Ye,2e3)))},[X,me]),Xe=s(()=>{U&&U.current&&U.current.stop(),R(!0);try{if(_&&_.current&&_.current.stream){const e=_.current.stream.getVideoTracks()[0];if(e){const t=e.getSettings();P.current=t.frameRate||null}const t={videoBitsPerSecond:15e5};ke[0]&&(t.mimeType=ke[0]),U.current=new MediaRecorder(_.current.stream,t),U.current.addEventListener("dataavailable",Qe),le([...ce,Qe]),U.current.start(1e3),O(!1)}}catch(e){console.log("error while using media recorder",e)}},[_,ke,Qe,ce]),Ze=s(async()=>{G.current&&clearTimeout(G.current),Xe(),me.current&&(G.current=setTimeout(async()=>{me.current&&(await S.playAudio(`${v}SpotOn.mp3`),R(!1))},15e3)),K(!0),me.current&&await S.playAudio(`${v}Spin.mp3`)},[Xe,me,S]);o(()=>{Ie.current=Ze},[Ze]);const et=s(({data:e})=>{e.size>0&&Ae.poseDetection.connected()&&(De.current||(De.current=!0,Ae.poseDetection.poseStatus(async e=>{if(console.log("poseStatus data:",e),e&&e.audio&&e.audio.length>0){F.capture(`${M}/pose_instruction_received`,{scanID:a,email:y,audio:e.audio,status:e.status,sid:e.sid,counter:Ne.current,consecutiveFalse:Ce.current,type:"body_scan_instruction"});const t=document.querySelector("#audioElement");!0===e.status&&e.sid===be?(Ce.current=0,Ne.current<2?(Ne.current+=1,1!==Ne.current||Fe.current?2===Ne.current&&t?.paused&&S.playAudio(v+e.audio):(Fe.current=!0,S.stopAudio(),await S.playAudio(v+e.audio))):(te(e.audio),clearTimeout(we),Ae.poseDetection.disconnect(),De.current=!1,setTimeout(()=>Ie.current(),1e3))):(Ce.current+=1,Ce.current>=3&&(Ne.current=0,Fe.current=!1),!t?.paused||xe&&xe?.audioName===e.audio?xe?.audioName===e.audio&&t?.paused&&(xe&&xe.no_of_times_skipped>=xe.skipCount?(xe.no_of_times_skipped=0,S.playAudio(v+e.audio)):xe&&(xe.no_of_times_skipped+=1)):(xe={skipCount:2,no_of_times_skipped:0,audioName:e.audio},S.playAudio(v+e.audio)))}})),_?.current&&null!==_.current.getScreenshot()&&Ae.poseDetection.videoEmit({image:_.current.getScreenshot()||"",scanId:a}))},[_,a,Ae,be,S,M,y]),tt=s(async()=>{J(!0),_e(!0),ze?.(),fe.current&&(fe.current=!1,k({eventName:"scan started",scanID:a,status:"success",email:y})),m(T()),V(!0),me.current&&await S.playAudio(`${v}StartScan.mp3`),me.current&&await S.playAudio(`${v}LiftArmsAndHoldAtHip.mp3`),me.current&&(J(!1),R(!0),se(!0),ue(!0),Be());try{if(_&&_.current&&_.current.stream&&me.current){const e=_.current.stream.getVideoTracks()[0];if(e){const t=e.getSettings();P.current=t.frameRate||null}const t={videoBitsPerSecond:15e5};ke[0]&&(t.mimeType=ke[0]),me.current&&(U.current=new MediaRecorder(_.current.stream,t)),me.current&&U.current&&U.current.addEventListener("dataavailable",et),le([...ce,et]),U.current&&U.current.start(1e3),O(!1),me.current&&(we=setTimeout(Ye,2e3))}}catch(e){console.log("error ----------",e)}},[_,ke,et,ce,Ye,me,ze]);return o(()=>(M&&(t(!0),Je()),()=>{be&&(Ae.poseDetection.disconnect(),F.capture(`${M}/pose_detection_disconnected`,{scanID:a,email:y,id:be})),ce.forEach(e=>{U?.current?.removeEventListener("dataavailable",e)})}),[M]),o(()=>{X.push(Q)},[Q]),o(()=>{Z([])},[ee]),o(()=>{const e=A.length&&A.length>0;W||!e||B||!me.current||oe||U&&U.current&&(B||(U.current.stop(),O(!0)))},[W,B,A,oe]),o(()=>{const e=A.length&&A.length>0;if(W||!e||B)console.log("No video found to upload.");else if(U&&U.current&&me.current&&!oe&&!B){const e=new File(A,`${a}.${Oe}`,{type:We});je?.(),Pe?.(!0),c(""),Ue?.(e,P.current)}},[W,B,A,oe,U,me]),o(()=>{const e=E(Ke,$);Te(e)},[Ke]),o(()=>{Ve()},[]),e(he,{resetDetector:n,resetScan:Ve,loadingCam:j,onPause:qe,showRestart:re,pause:oe,onReScan:Ge,recordingStarted:B,isScanning:H,startSendingVideoFrames:tt,faceDone:q,stopRecording:He,showPause:de,webcamRef:_,onUserMedia:Be,onUserMediaError:Re,videoConstraints:$e,webcamKey:Ee})});function Ne({scanID:t,userDetails:n,setIsVideoUploaded:a,setScanFailsError:s,setScanStartTime:i,setScanUniqueKey:c}){const[l,d]=r(90),[m,p]=r(0),[f,h]=r(null),[g,y]=r(!1),[v,w]=r(0),b=u([]),[x,S]=r(!1),N=l-m,C=N>=80&&N<=95;o(()=>{if("undefined"!=typeof window&&window.DeviceOrientationEvent){const e=e=>{if(null!==e.beta){let t=Math.abs(e.beta);null!==e.gamma&&(t*=Math.cos(e.gamma*Math.PI/180)),t=Math.max(0,Math.min(180,t)),d(t)}},t=async()=>{const t=DeviceOrientationEvent;if(t&&"function"==typeof t.requestPermission)try{"granted"===await t.requestPermission()&&window.addEventListener("deviceorientation",e)}catch(e){console.error("Permission error",e)}else window.addEventListener("deviceorientation",e);return()=>{e&&window.removeEventListener("deviceorientation",e)}};document.addEventListener("click",t,{once:!0})}},[]),o(()=>{if(b.current=[...b.current.slice(-4),N],b.current.length>=5){const e=Math.max(...b.current)-Math.min(...b.current);w(C&&e<2?e=>Math.min(100,e+10):e=>Math.max(0,e-20))}C||null===f&&!g||F()},[N,C,f,g]),o(()=>{v>=100&&null===f&&!g&&D(),v<50&&null!==f&&F()},[v,f,g]);const D=()=>{h(3);const e=setInterval(()=>{h(t=>null===t||t<=1?(clearInterval(e),y(!0),null):t-1)},1e3)},F=()=>{h(null),x||y(!1)};return e(fe,{angle:N,countdown:f,isScanning:g,isInTargetRange:C,stabilityScore:v,children:g&&e(Se,{setIsScanLocked:S,resetDetector:()=>{d(90),p(0),h(null),y(!1),w(0),S(!1),b.current=[]},scanID:t,userDetails:n,setIsVideoUploaded:a,setScanFailsError:s,setScanStartTime:i,setScanUniqueKey:c})})}function Ce({message:a,config:r}){const{translate:s}=d(m)||{};return e(re,{open:!0,className:"confirm-modal common-ui-main",disablePortal:!0,children:e("div",{className:"modal-main",children:e("div",{className:"text-center",children:t(n,a?{children:[e("h2",{className:"my-[0] ",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:s?.(h.cameraAlreadyInUse)}),e("p",{className:"mt-[0.5rem] text-sm",style:{fontFamily:r?.style?.base?.baseFontFamily||"Inter, sans-serif",fontSize:r?.style?.base?.baseFontSize||"16px",color:r?.style?.base?.baseTextColor||"#000"},children:s?.(h.tryClosingBrowser)})]}:{children:[e("h2",{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:s?.(h.checkCameraSettings)}),e("p",{className:"mt-[0.5rem] text-sm",style:{fontFamily:r?.style?.base?.baseFontFamily||"Inter, sans-serif",fontSize:r?.style?.base?.baseFontSize||"16px",color:r?.style?.base?.baseTextColor||"#000"},children:`${s?.(h.setting)} > ${M()} > ${s?.(h.enableCameraPermissions)}`})]})})})})}function De({setShowDrawer:t,config:n,loader:a}){const[i,c]=r({disabled:!1,message:""}),[l,d]=r(!0),m=u(null),p=s(async()=>{const e=await _();c(e),d(!1)},[]);return o(()=>{p()},[]),l?e(U,{url:a,loaderType:"black"}):i?.disabled?e(Ce,{config:n,message:i?.message}):e(ne,{audio:!1,ref:m,screenshotQuality:1,videoConstraints:P,mirrored:!0,onUserMedia:()=>t?.(!0),screenshotFormat:"image/jpeg",style:{position:"relative",top:0,bottom:0,zIndex:0,width:"100%",height:"100%",objectFit:"cover"}})}function Fe({link:t,onReady:n,wrapperClassName:a="[&_video]:rounded-t-[20px] w-full h-full"}){const r=u(null),s=u(null);let i={autoplay:!0,controls:!1,responsive:!0,fluid:!0,muted:!0,navigationUI:"hide",preload:"metadata",poster:A};return o(()=>{if(!s.current&&t&&r?.current){const e=ie(r.current,{...i});e.ready(()=>{s.current=e;const a={...i,sources:[{src:t,type:"application/x-mpegURL"}]};e.autoplay(a.autoplay),e.src(a.sources),n?.(e)})}},[t,r]),o(()=>{const e=s.current;return()=>{e&&!e.isDisposed()&&(e.dispose(),s.current=null)}},[s]),e("div",{className:a,children:e("video",{ref:r,muted:!0,className:"video-js",playsInline:!0,onDrag:e=>e.preventDefault()})})}function Ie({scanFailsError:a,onNext:s,gender:o,setScanUniqueKey:i,setIsVideoUploaded:c}){const{translate:l}=d(m)||{},u=p(),[y,v]=r(!1),w=()=>{v(!y)};return t(n,{children:[t("div",{className:"flex common-ui-main flex-col h-full max-w-[28rem] mx-auto w-full rounded-t-[20px] overflow-y-auto",style:{background:u?.style?.base?.backgroundColor},children:[e("div",{className:"w-full max-w-[28rem] mx-auto pt-[1rem] px-[1rem]",children:e(f,{noTitle:!0})}),e("div",{className:"flex-1",children:a&&t("div",{className:"px-[1rem]",children:[e("h2",{className:"text-center",style:{fontFamily:u?.style?.heading?.headingFontFamily||"SeriouslyNostalgic Fn",fontSize:u?.style?.heading?.headingFontSize||"32px",color:u?.style?.heading?.headingColor||"#000",fontWeight:u?.style?.heading?.headingFontWeight||"normal"},children:l?.(h.issueWithScan)}),e("p",{style:{fontFamily:u?.style?.base?.baseFontFamily||"Inter, sans-serif",fontSize:u?.style?.base?.baseFontSize||"16px",color:u?.style?.base?.baseTextColor||"#1E1E1E"},children:l?.(h.reason)}),e("p",{style:{fontFamily:u?.style?.base?.baseFontFamily||"Inter, sans-serif",fontSize:u?.style?.base?.baseFontSize||"16px",color:u?.style?.base?.baseTextColor||"#1E1E1E"},children:z(a)}),e("img",{className:"my-[0.5rem] aspect-[2/1.4] w-full object-cover",onClick:w,src:j[o],alt:"icon"})]})}),a&&e("div",{className:"p-[1rem] flex gap-[0.5rem]",children:e(g,{disabled:!1,buttonText:l?.(h.scanAgain),className:"!shadow-none",buttonFunc:()=>{s?s?.():i?.(L()),c?.(!1)}})})]}),y&&t(re,{className:"w-screen h-screen video-modal",onClose:w,open:y,disablePortal:!0,children:[e("div",{className:"flex justifyEnd ",children:e("span",{className:"closeBtn",onClick:w,children:e(ae,{className:"absolute right-[8px] top-[8px] text-white z-[9]"})})}),e("div",{className:"aspect-video object-cover rounded-[20px] ",children:e(Fe,{link:o?V[o].PRE_LINK:V.male.PRE_LINK,wrapperClassName:"w-screen h-screen fixed top-[0] left-[0]"})})]})]})}function ke({scanId:n,userDetails:a,config:i,isVideoUploadedCorrect:c,isMeasurementAvailable:l,onComplete:u,isSuccess:p,onCustomScanSuccess:y,swan:v}){const{gender:w,shopDomain:b,heightInCm:x,deviceFocalLength:S,userName:N,email:C,scanType:D}=a||{},I=[K,W,O].includes(D??""),[k,T]=r(!0),E=s(async()=>{try{I&&(await(v?.auth.addUser({scanId:n,email:C,name:N,gender:w,height:x})),y?.()),F.capture(b??"",{scanID:n,email:C,height:x,focalLength:S,clothesFit:"0",gender:w})}catch(e){console.log(e)}},[I]),{translate:L}=d(m)||{};o(()=>{(c||l)&&E()},[c,l]);const $=p||c||l;return e(se,{className:"flex h-full w-full flex-col common-ui-main",children:t("div",{className:"h-full w-full flex-col items-center justify-center flex",children:[e(De,{loader:i?.loader,setShowDrawer:T}),e(oe,{open:k,onClose:(e,t)=>{},disablePortal:!0,className:"camera-drawer",anchor:"bottom",children:e("div",{className:"max-w-[28rem] mx-auto w-full h-full flex text-center flex-col justify-between items-center bg-primary rounded-t-[30px] p-[1rem]",style:{background:i?.style?.base?.backgroundColor},children:t("div",{className:"w-full h-full flex flex-col",children:[e(f,{title:L?.(h.measurementsBeingTaken)}),e("div",{className:"flex items-center justify-center flex-1",children:e("video",{preload:"auto",className:"max-h-[calc(100vh-450px)] mx-auto w-full object-contain border-none",muted:!0,loop:!0,autoPlay:!0,playsInline:!0,children:e("source",{src:w===q.Male?B:R,type:"video/mp4"})})}),$&&e(g,{className:"!w-[180px] mx-auto",buttonText:L?.(h.next),buttonFunc:()=>{u?.()}})]})})})]})})}const Te=()=>{const{userDetails:a,onRetry:r,isError:s,isSuccess:o,gender:i,scanUniqueKey:c,scanFailsError:l,setScanUniqueKey:u,setIsVideoUploaded:m,isMeasurementAvailable:f,isVideoUploadedCorrect:h,loading:g,showDeniedModal:y,uploadLoading:v,setScanFailsError:w,setScanStartTime:x,resetScan:S,onCustomScanSuccess:N,swan:C,onComplete:D}=d(b),F=p();return s?t(n,{children:[e(De,{}),e(oe,{anchor:"bottom",open:!0,className:"camera-drawer",onClose:(e,t)=>{},disablePortal:!0,children:e(Ie,{scanFailsError:!0,onNext:r,gender:i})})]}):o?e(ke,{isSuccess:!0,onComplete:D,config:F}):g?e("div",{className:"flex top-0 !mt-0 left-0 z-[999] absolute justify-center items-center w-full h-full",style:{background:F?.style?.base?.backgroundColor},children:e(U,{url:F?.loader,loaderType:"black"})}):y.disabled?e(Ce,{}):v||l||f||h?(v||f||h)&&!l?e(ke,{scanId:c,isMeasurementAvailable:f,userDetails:a,isVideoUploadedCorrect:h,onCustomScanSuccess:N,swan:C,onComplete:D,config:F}):t(n,{children:[e(De,{}),e(oe,{anchor:"bottom",open:!0,className:"camera-drawer",onClose:(e,t)=>{},disablePortal:!0,children:e(Ie,{scanFailsError:l,onNext:()=>{r?.(),S()},setScanUniqueKey:u,gender:i,setIsVideoUploaded:m})})]}):e(Ne,{scanID:c,userDetails:a,setIsVideoUploaded:m,setScanFailsError:w,setScanStartTime:x,setScanUniqueKey:u})},Ee=t=>{const{config:n,onRetry:a,onScanStart:i,onCaptureComplete:c,onUploadStart:d,onUploadEnd:u,onMeasurementSocketStart:m,onMeasurementSocketClose:p,onIntermediateScanSuccess:f,onScanError:h,onScanSuccess:g,onCustomScanSuccess:y,onComplete:v,isError:w,isSuccess:x}=t,S={email:"",shopDomain:"",gender:"male",heightInCm:0,scanType:"",deviceFocalLength:0,deviceModelName:"",sourceTag:"",...t.userDetails??{}},N=t.token??"",{gender:C,scanType:D,shopDomain:F,heightInCm:I,email:E,deviceFocalLength:$,deviceModelName:M,callbackUrl:U,sourceTag:P}=S,A=l(()=>H(N),[N]),[j,V]=r(!1),[B,R]=r(!1),[q,K]=r(!1),[W,O]=r({disabled:!1,message:""}),[te,ne]=r(""),[ae,re]=r(!1),[se,oe]=r(!0),[ie,ce]=r(!1),[le,de]=r(""),[ue,pe]=r(T()),{gyroData:fe}=function(e){const[t,n]=r([]),[a,i]=r(!1),c=s(e=>{try{const{alpha:t,beta:a,gamma:r}=e;n(e=>[...e,{alpha:t?.toString()||void 0,beta:a?.toString()||void 0,gamma:r?.toString()||void 0,timestamp:(new Date).toISOString()}])}catch(e){console.log(e)}},[]),l=s(async()=>{const e=DeviceOrientationEvent;if(void 0!==e&&"function"==typeof e.requestPermission)try{"granted"===await e.requestPermission()?i(!0):console.warn("Device orientation permission denied.")}catch(e){console.error("Error requesting device orientation permission:",e)}else i(!0)},[]);return o(()=>(e&&a?window.addEventListener("deviceorientation",c):n([]),()=>{window.removeEventListener("deviceorientation",c)}),[e,a,c]),o(()=>{e&&l()},[e,l]),{gyroData:t}}(ie);J();const he=s(()=>{de(L()),ne(""),V(!1),re(!1)},[]),ge=()=>{pe(null),de("")},ye=s(async e=>{if(e&&"success"===e?.scanStatus&&"intermediate"===e?.resultType&&200===e?.code)return k({eventName:`${F}/measurement_success/intermediate`,scanID:le,status:"success",email:E}),R(!0),void f?.(e);g?.(e),R(!0),ge();const t=le;K(!0),k({eventName:`${F}/measurement_success/fit-view`,scanID:t,status:"success",email:E}),ue&&k({eventName:`${F}/scan_completion_time`,scanID:t,status:"success",completionTime:T()-ue,email:E})},[D,F,le]),ve=e=>{K(!1),ne(""),R(!1),A.measurement.handleMeasurementSocket({scanId:le,onPreopen:()=>{ee({eventName:`${F}/webSocket`,scanID:le,connection:"pre_open",type:"measurement_recommendation",email:E})},onOpen:()=>{m?.(),ee({eventName:`${F}/webSocket`,scanID:le,connection:"open",type:"measurement_recommendation",email:E})},onClose:()=>{p?.(),ee({eventName:`${F}/webSocket`,scanID:le,connection:"close",type:"measurement_recommendation",email:E})},onError:e=>{var t;t=e,h?.({...t,message:z(t)}),ge(),K(!1),ne(t),R(!1),k({eventName:`${F}/measurement_failed/fit-view`,scanID:le,status:"failed",email:E,message:z(t)}),ue&&k({eventName:`${F}/scan_completion_time`,scanID:le,status:"failed",completionTime:T()-ue,email:E}),ee({eventName:`${F}/webSocket`,scanID:le,connection:"error",type:"measurement_recommendation",email:E})},onSuccess:e=>{ee({eventName:`${F}/webSocket`,scanID:le,connection:"success",type:"measurement_recommendation",email:E}),ye(e)}})},we=s(async(e,t)=>{const n=Number((e.size/1048576).toFixed(2)),a=null!=t?t:await G(e),r=Q({gender:C,focal_length:`${$}`,height:`${I}`,customer_store_url:F,clothes_fit:"0",scan_type:D,callback_url:U,source_tag:P});k({eventName:`${F}/body_scan_meta_data`,scanID:le,email:E,data:JSON.stringify([...r,{fileSizeInMB:n,video_fps:a||0}])}),d?.();try{await A.fileUpload.uploadFileFrontend({file:e,arrayMetaData:r,scanId:le,email:E}),await A.fileUpload.setDeviceInfo({model:M,detection:"manual",gyro:fe,scanId:le}),console.log("video successfully uploaded"),re(!1),k({eventName:`${F}/scan_success`,scanID:le,status:"success",email:E,data:JSON.stringify(r)}),k({eventName:"scan finished",scanID:le,status:"success",email:E}),pe(T()),setTimeout(()=>{re(!0)},3e3)}catch(e){k({eventName:"scan finished",scanID:le,status:"failed",email:E,message:z(e)}),k({eventName:`${F}/scan_failed`,scanID:le,status:"failed",email:E,message:z(e),data:JSON.stringify(r)}),ne(z(e)),re(!1),h?.({...e,message:z(e)}),ge()}finally{ce(!1),u?.()}},[le,fe,d,u]),be=s(async()=>{if(+I<152.4||+I>213.36)return void h?.({message:"Height must be between 152.4cm (5ft) and 213.36cm (7ft)"});const e=await _();e.disabled?(k({eventName:`${F}/camera_activation`,scanID:le,status:"failed",email:E}),oe(!1)):(oe(!1),k({eventName:`${F}/camera_activation`,scanID:le,status:"success",email:E})),O(e),ne(""),re(!1)},[E,le,de,F]);return o(()=>{w||x||F&&be()},[F,I,w,x]),o(()=>{w||x||ae&&F&&le&&ve()},[ae,F,le,w,x]),e(Y,{children:e(X,{config:n,children:e(me,{children:e(b.Provider,{value:{userDetails:S,onRetry:a,onScanError:h,isError:w,isSuccess:x,onScanSuccess:g,gender:C,scanUniqueKey:le,scanFailsError:te,setScanUniqueKey:de,setIsVideoUploaded:re,isMeasurementAvailable:q,isVideoUploadedCorrect:B,loading:se,showDeniedModal:W,uploadLoading:j,setStartGyro:ce,uploadScanFile:we,setUploadLoading:V,resetScan:he,setScanFailsError:ne,setScanStartTime:pe,onScanStart:i,onCaptureComplete:c,onCustomScanSuccess:y,onComplete:v,swan:A},children:e(Z,{children:e(Te,{})})})})})})};export{Ee as B};
2
+ //# sourceMappingURL=BodyScan-OZyGWLsF.js.map
@@ -0,0 +1,2 @@
1
+ "use strict";var e=require("react/jsx-runtime"),t=require("react"),a=require("./LoadingScreen-CmNyZnEW.js"),n=require("lucide-react"),o=require("@mui/material");let s=null,r=!1;function c({faceScanId:e,onValidPose:n,onScanComplete:o,onModelReady:c,onStartRecording:i,shopDomain:l,isError:d,isSuccess:u}){const f=t.useRef(null),[g,h]=t.useState(0),[m,p]=t.useState(0),[y,S]=t.useState(!1),[x,v]=t.useState(!1),b=t.useRef(null),w=t.useRef(g),C=t.useRef(m),F=t.useRef([]),j=t.useRef(""),_=t.useRef(0),N=t.useRef(!1),E=t.useRef(0),k="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(`${l}/face_scan_pose_detection`,e)},4e3),[l]),R=t.useCallback((t,a,n,o,s,r)=>{const c=Date.now();if(!(c-E.current<4e3)){E.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],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(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(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(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]),M=()=>{a.posthog.capture(`${l}/face_scan_detection_started`,{faceScanId:e,stage:w.current,timestamp:(new Date).toISOString(),stageName:T[w.current]}),setTimeout(()=>{v(!0)},1500)},P=async()=>{if("undefined"!=typeof window)try{console.log("Initializing Face Scan...");const e=await(async()=>{if("undefined"==typeof window)return null;if(s)return s;if(r)for(;r;)if(await new Promise(e=>setTimeout(e,100)),s)return s;r=!0;try{const[e,t]=await Promise.all([import("@tensorflow/tfjs"),Promise.resolve().then(function(){return require("./pose-detection.esm-CDstzA1V.js")})]);await e.setBackend("webgl"),await e.ready();const n=await t.createDetector(t.SupportedModels.BlazePose,{runtime:"tfjs",modelType:"full"}),o=document.createElement("canvas");o.width="number"==typeof a.videoConstraints.width?a.videoConstraints.width:a.videoConstraints.width.ideal??a.videoConstraints.width.max??1280,o.height="number"==typeof a.videoConstraints.height?a.videoConstraints.height:a.videoConstraints.height.ideal??a.videoConstraints.height.max??720;const r=o.getContext("2d");if(r){r.fillStyle="black",r.fillRect(0,0,o.width,o.height);try{await n.estimatePoses(o)}catch(e){console.warn("Warmup frame failed (non-fatal):",e)}}return s=n,n}catch(e){return console.error("Failed to preload detector:",e),null}finally{r=!1}})();e&&(f.current=e,console.log("Face scan model loaded successfully"),S(!0),c?.())}catch(e){console.error("Error initializing face scan:",e)}};return t.useEffect(()=>{if(!d&&!u)return P(),()=>{(async()=>{try{S(!1)}catch(e){console.error("Error disposing resources:",e)}finally{h(0),p(0),w.current=0,C.current=0,F.current=[]}})()}},[d,u]),t.useEffect(()=>{w.current=g},[g]),t.useEffect(()=>{C.current=m},[m]),{faceScanDetector:async(t,s)=>{if(f.current&&t.current&&y&&x&&!(t.current.readyState<2))try{const r=await f.current.estimatePoses(t.current);if(r.length>0){const t=[],c=[];if(r[0].keypoints.forEach((e,a)=>{const n=e.score??0,o=[e.x??-1,e.y??-1,n];a<=10?t.push(o):c.push(o)}),s?.current){const e=s.current.getContext("2d"),{width:t,height:a}=s.current;if(e){e.clearRect(0,0,t,a);const n=Math.min(C.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 d=((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}})(w.current,t),u=c.slice(2).filter(e=>e[2]>.7).length<=2;F.current.push(d&&u),F.current.length>10&&F.current.shift();if(F.current.filter(Boolean).length>=2){const e=C.current+1;p(e)}else p(Math.max(0,C.current-1));if(C.current>=2){n?.();const t=w.current+1;p(0),F.current=[],h(t),v(!1),(async()=>{if(await a.speechService.playAudio(`${a.voiceOverAssetsPath}face-scan-vos/Sound-effect.mp3`),a.posthog.capture(`${l}/face_scan_detection_stage_completed`,{faceScanId:e,completedStage:w.current,nextStage:t,timestamp:(new Date).toISOString(),totalStages:4,stageName:T[w.current]}),1===t&&i&&i(),t>=4)o?.();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 a.speechService.playAudio(`${a.voiceOverAssetsPath}face-scan-vos/${e}`),M()}})()}R(t,c,w.current,d,u,C.current)}}catch(e){console.error("Pose detection error:",e)}},scanStage:g,setScanStage:h,consecutiveValid:m,isModelLoaded:y,resetScan:()=>{a.posthog.capture(`${l}/face_scan_reset`,{faceScanId:e,stage:w.current,timestamp:(new Date).toISOString(),stageName:T[w.current],consecutiveValid:C.current}),h(0),p(0),v(!1),w.current=0,C.current=0,F.current=[],j.current="",_.current=0,N.current=!1,b.current&&(speechSynthesis.cancel(),b.current=null)},enableVoiceCommands:()=>{if(N.current=!0,"undefined"!=typeof window&&k&&"speechSynthesis"in window){const e=new SpeechSynthesisUtterance("");e.volume=0,speechSynthesis.speak(e)}},startScanSequence:M,isScanningActive:x}}function i({onRetry:o,loading:s}){const{translate:r}=t.useContext(a.LanguageContext)||{},c=a.useConfig();return e.jsx("div",{className:"fixed common-ui-main top-[0] left-[0] z-[999] flex justify-center items-center w-full h-full",style:{background:c?.style?.base?.backgroundColor},children:e.jsxs("div",{className:"flex flex-col w-full items-center p-[1rem] rounded-lg ",children:[e.jsx(a.Header,{noTitle:!0}),e.jsxs("div",{className:"flex flex-col items-center w-full",children:[e.jsx("h2",{className:"text-xl my-[0] font-semibold text-gray-800 ",style:{fontFamily:c?.style?.heading?.headingFontFamily||"SeriouslyNostalgic Fn",fontSize:c?.style?.heading?.headingFontSize||"32px",color:c?.style?.heading?.headingColor||"#000",fontWeight:c?.style?.heading?.headingFontWeight||"normal"},children:r?.(a.LanguageKeys.scanFailed)}),e.jsx("p",{className:"mb-[1.5rem]",style:{fontFamily:c?.style?.subheading?.subheadingFontFamily||"'Inter', sans-serif",fontSize:c?.style?.subheading?.subheadingFontSize||"14px",color:c?.style?.subheading?.subheadingColor||"#4b5563",fontWeight:c?.style?.subheading?.subheadingFontWeight||"normal"},children:r?.(a.LanguageKeys.clickToResetScan)}),e.jsx(a.SpecificButton,{disabled:s,className:"w-full h-[45px] shadow-[0px_1px_2px_0px_#00000040] text-[16px]",buttonText:r?.(a.LanguageKeys.resetScan),postfixIcon:e.jsx(n.ArrowRight,{}),buttonFunc:()=>o?.()})]})]})})}function l({stage:n,videoLoading:o,setVideoLoading:s,videoError:r,setVideoError:c,gender:i,btnConfig:l}){const{translate:d}=t.useContext(a.LanguageContext)||{},u=a.useConfig();return-1===n?e.jsxs("div",{className:"text-center common-ui-main p-[16px] w-full h-full",style:{background:u?.style?.base?.backgroundColor},children:[e.jsxs("div",{className:"w-full",children:[e.jsx(a.Header,{noTitle:!0}),e.jsx("h2",{className:"my-[0]",style:{fontFamily:u?.style?.heading?.headingFontFamily||"SeriouslyNostalgic Fn",fontSize:u?.style?.heading?.headingFontSize||"32px",color:u?.style?.heading?.headingColor||"#000",fontWeight:u?.style?.heading?.headingFontWeight||"normal"},children:d?.(a.LanguageKeys.faceVisible)}),o&&e.jsx("div",{className:"mb-4 flex items-center justify-center",style:{fontFamily:u?.style?.subheading?.subheadingFontFamily||"'Inter', sans-serif",fontSize:u?.style?.subheading?.subheadingFontSize||"14px",color:u?.style?.subheading?.subheadingColor||"#4b5563",fontWeight:u?.style?.subheading?.subheadingFontWeight||"normal"},children:d?.(a.LanguageKeys.loadingVideo)}),r&&e.jsx("div",{className:"mb-4 text-red-600",style:{fontFamily:u?.style?.subheading?.subheadingFontFamily||"'Inter', sans-serif",fontSize:u?.style?.subheading?.subheadingFontSize||"14px",color:"#ff0000",fontWeight:u?.style?.subheading?.subheadingFontWeight||"normal"},children:d?.(a.LanguageKeys.videoLoadFailed)}),!r&&e.jsx("div",{className:" w-[100px] mx-auto",children:e.jsx("video",{src:i===a.GenderType.Male?a.maleGlassesOffVideo:a.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(a.SpecificButton,{disabled:l.isDisabled,className:"!w-[60px] !h-[35px] !py-0 !px-0",buttonText:d?.(l.label),postfixIcon:l?.icon,buttonFunc:l.onClick})})]}):e.jsx("div",{className:"text-center common-ui-main p-[16px] w-full h-full",style:{background:u?.style?.base?.backgroundColor},children:e.jsxs("div",{className:"w-full",children:[e.jsx(a.Header,{noTitle:!0}),e.jsx("h3",{className:"mb-[0.5rem] mt-[0]",style:{fontFamily:u?.style?.heading?.headingFontFamily||"SeriouslyNostalgic Fn",fontSize:u?.style?.heading?.headingFontSize||"32px",color:u?.style?.heading?.headingColor||"#000",fontWeight:u?.style?.heading?.headingFontWeight||"normal"},children:d?.(a.directionMessages[n])}),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===n?"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===a.GenderType.Male?a.FACE_SCAN_HEADSHOT.male.forward:a.FACE_SCAN_HEADSHOT.female.forward,type:"video/mp4"})})}),e.jsx("div",{className:` w-[120px] overflow-hidden ${1===n?"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===a.GenderType.Male?a.FACE_SCAN_HEADSHOT.male.left:a.FACE_SCAN_HEADSHOT.female.left,type:"video/mp4"})})}),e.jsx("div",{className:` w-[120px] overflow-hidden ${2===n?"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===a.GenderType.Male?a.FACE_SCAN_HEADSHOT.male.right:a.FACE_SCAN_HEADSHOT.female.right,type:"video/mp4"})})}),e.jsx("div",{className:` w-[120px] overflow-hidden ${3===n?"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===a.GenderType.Male?a.FACE_SCAN_HEADSHOT.male.smile:a.FACE_SCAN_HEADSHOT.female.smile,type:"video/mp4"})})})]})]})})}const d=({webcamRef:s,canvasRef:r})=>{const{isError:c,isSuccess:d,showLoader:u,hasError:f,resetScanState:g,showGuideCard:h,scanStage:m,videoLoading:p,setVideoLoading:y,videoError:S,setVideoError:x,gender:v,getButtonText:b,isScanning:w,startScan:C,isModelLoaded:F,onRetry:j}=t.useContext(a.ParamsContext),_=a.useConfig();return c?e.jsx(i,{onRetry:j}):d?e.jsx("div",{className:"fixed z-[9] common-ui-main w-full h-full",style:{background:_?.style?.base?.backgroundColor},children:e.jsx(a.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&&!f&&e.jsx("div",{className:"fixed z-[9] common-ui-main w-full h-full",style:{background:_?.style?.base?.backgroundColor},children:e.jsx(a.LoadingScreen,{url:_?.loader,loaderType:"black"})}),e.jsx("div",{className:"h-full flex-col common-ui-main 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:s,autoPlay:!0,playsInline:!0,muted:!0,width:a.videoConstraints.width.ideal,height:a.videoConstraints.height.ideal,className:"w-full h-full object-cover fixed left-0 top-0 z-0",style:{transform:"scaleX(-1)"}}),e.jsx("canvas",{ref:r,width:a.videoConstraints.width.ideal,height:a.videoConstraints.height.ideal,style:{transform:"scaleX(-1)",opacity:"0"}})]})})}),!u&&f&&e.jsx(i,{loading:u,onRetry:g}),h&&!f&&!u&&e.jsx(o.Drawer,{open:!0,className:"face-scan-small camera-draw",anchor:"bottom",onClose:(e,t)=>{},disablePortal:!0,hideBackdrop:!0,children:e.jsx(l,{stage:m,videoLoading:p,setVideoLoading:y,videoError:S,setVideoError:x,gender:v,btnConfig:{label:b(),onClick:w?g:C,isDisabled:u||!F,icon:w?e.jsx(n.ArrowRight,{}):e.jsx(e.Fragment,{})}})})]})};exports.FaceScan=n=>{const{onScanSuccess:o,onScanError:s,onRetry:r,onScanStart:i,onCaptureComplete:l,onUploadStart:u,onUploadEnd:f,onMeasurementSocketStart:g,onMeasurementSocketClose:h,config:m,isError:p,isSuccess:y}=n,S=n.userDetails??{email:"",gender:"male",deviceFocalLength:0,shopDomain:"",bodyScanId:""},x=n.token??"",v=t.useRef(null),b=t.useRef(null),w=t.useRef(null),C=t.useRef([]),F=t.useRef(null),j=t.useRef(null),[_,N]=t.useState(!1),[E,k]=t.useState(!1),[T,I]=t.useState(!1),[R,M]=t.useState(!0),[P,D]=t.useState(!1),[L,A]=t.useState(!1),[O,z]=t.useState(!1),[$,H]=t.useState(a.generateUuid()),V=t.useMemo(()=>a.getSwanService(x),[x]),{email:W,gender:K,deviceFocalLength:U,shopDomain:B,callbackUrl:q,bodyScanId:G}=S,[J,X]=t.useState([]),[Q,Y]=t.useState(a.videoConstraintsExact),Z=t.useMemo(()=>a.getPreferredMediaRecorderTypes(),[]),ee=a.getRecordingMimeType(J),te=a.getRecordingExtension(ee);a.usePosthogPageview();const ae=t.useCallback(()=>{console.log("Stopping recording..."),w.current&&"recording"===w.current.state&&w.current.stop(),w.current=null},[]),ne=async()=>{if(l?.(),C.current){if(0===C.current.length)return console.error("No video data recorded"),z(!0),void N(!1);u?.(),N(!0);const e=new File(C.current,`${$}.${te}`,{type:ee}),t=j.current??await a.getVideoFPS(e),n=e.size,o=(n/1048576).toFixed(2),s=Math.round(n/1e4),r={video_size_mb:parseFloat(o),video_size_bytes:n,video_fps:t||0,blob_count:C.current.length,estimated_duration_seconds:s},c=[{gender:K},{face_scan_id:$},{focal_length:`${U}`},{customer_store_url:B},{scan_type:"face_scan"},{body_scan_id:G}];q&&c.push({callback_url:q}),a.handleScanTimeCapture({eventName:`${B}/face_scan_meta_data`,faceScanId:$,email:W,data:JSON.stringify({metaData:c,videoData:r})});const i=Date.now();a.handleScanTimeCapture({eventName:`${B}/face_scan_upload_start`,faceScanId:$,email:W,startTime:i});try{const t=await V.fileUpload.faceScanFileUploader({file:e,arrayMetaData:c,objectKey:$,email:W,contentType:e.type}),n=Date.now(),o=n-i;a.handleScanTimeCapture({eventName:`${B}/face_scan_upload_complete`,faceScanId:$,email:W,completionTime:n,uploadDuration:o}),f?.(),console.log("✅ Upload successful",t),V.measurement.handlFaceScaneSocket({onPreopen:()=>{g?.(),a.handleWebSocketCapture({eventName:`${B}/webSocket`,faceScanID:$,connection:"pre_open",type:"faceScan_recommendation",email:W})},faceScanId:$,onOpen:()=>{a.handleWebSocketCapture({eventName:`${B}/webSocket`,faceScanID:$,connection:"open",type:"faceScan_recommendation",email:W}),console.log("websocket connect open")},onError:e=>{a.handleWebSocketCapture({eventName:`${B}/webSocket`,faceScanID:$,connection:"error",type:"faceScan_recommendation",email:W}),ge(e)},onSuccess:e=>{a.handleWebSocketCapture({eventName:`${B}/webSocket`,faceScanID:$,connection:"success",type:"faceScan_recommendation",email:W}),he(e)},onClose:()=>{h?.(),console.log("websocket connect close"),a.handleWebSocketCapture({eventName:`${B}/webSocket`,faceScanID:$,connection:"close",type:"faceScan_recommendation",email:W})}})}catch(e){f?.(),ge(e)}}},oe=t.useCallback(()=>{const e=v.current?.srcObject;if(!e)return;const t=e.getVideoTracks()[0].getSettings(),{width:a=1280,height:n=720}=t,o=document.createElement("canvas"),s=o.getContext("2d");a>n?(o.width=n,o.height=a):(o.width=a,o.height=n);const r=document.createElement("video");r.srcObject=e,r.muted=!0,r.playsInline=!0,r.play();const c=()=>{a>n?(s?.save(),s?.translate(o.width,0),s?.rotate(Math.PI/2),s?.drawImage(r,0,0,n,a),s?.restore()):s?.drawImage(r,0,0,a,n),requestAnimationFrame(c)};c();const i=t.frameRate??10;j.current=i;const l=o.captureStream(i),d={videoBitsPerSecond:15e5};let u;J.length>0&&(d.mimeType=J[0]);try{u=new MediaRecorder(l,d)}catch(e){return console.error("MediaRecorder init failed:",e),z(!0),void N(!1)}C.current=[],u.ondataavailable=e=>{e?.data&&e.data.size>0&&C.current&&C.current.push(e.data)},u.onstop=()=>{console.log("Recording stopped, total blobs:",C?.current?.length),ne()},u.start(100),w.current=u,console.log("Recording started successfully (portrait normalized)")},[J,ne]),{faceScanDetector:se,scanStage:re,setScanStage:ce,resetScan:ie,isModelLoaded:le,startScanSequence:de}=c({faceScanId:$,shopDomain:B,isError:p,isSuccess:y,onScanComplete:()=>{ae()},onModelReady:()=>{k(!0)},onStartRecording:()=>{console.log("Stage 0 completed - starting recording for stages 1-3"),oe()}}),ue=t.useCallback(()=>{le&&(i?.(),ce(0),a.speechService.playAudio(`${a.voiceOverAssetsPath}face-scan-vos/Face-forward.mp3`),setTimeout(()=>{I(!0),setTimeout(()=>{de()},200)},200))},[ce,I,de,le,i]),fe=t.useCallback(()=>{I(!1),M(!0),ae(),ie(),r?.(),C.current=[],j.current=null,w.current&&(w.current=null),z(!1),ce(-1),H(a.generateUuid()),v.current&&F.current&&(v.current.srcObject=F.current,console.log("Camera stream restored after reset"))},[ce,I,M,ae,ie,H]),ge=e=>{console.log(e,"ws error"),s?.(e),z(!0),N(!1),M(!1),a.handleScanTimeCapture({eventName:`${B}/faceScan`,faceScanId:$,status:"failed",email:W,data:JSON.stringify(e)})},he=e=>{console.log(e,"ws success"),e&&"intermediate"===e?.resultType&&a.handleScanTimeCapture({eventName:`${B}/faceScan_success/intermediate`,faceScanId:$,status:"success",email:W,data:JSON.stringify(e)}),o?.(e)};t.useEffect(()=>{if(!p&&!y)return navigator.mediaDevices.getUserMedia&&navigator.mediaDevices.getUserMedia({video:Q}).then(e=>{F.current=e,v.current&&(v.current.srcObject=e)}).catch(e=>{console.error("Error accessing webcam:",e),Q!==a.videoConstraintsExact?z(!0):Y(a.videoConstraintsFallback)}),()=>{F.current&&F.current.getTracks().forEach(e=>e.stop())}},[p,y,Q]),t.useEffect(()=>{if(!E||!T)return;const e=setInterval(()=>{se(v,b)},500);return()=>clearInterval(e)},[se,E,T]);return console.log("Model ready:",E,"Has error:",O,"Is scanning:",T,"showLoader",_),t.useEffect(()=>{const e=a.getSupportedMediaRecorderTypes(Z,a.videoTypes);X(e)},[Z]),t.useEffect(()=>{ce(-1)},[]),e.jsx(a.LanguageContextProvider,{children:e.jsx(a.ConfigProvider,{config:m,children:e.jsx(a.ParamsContext.Provider,{value:{isError:p,isSuccess:y,showLoader:_,hasError:O,resetScanState:fe,showGuideCard:R,scanStage:re,videoLoading:P,setVideoLoading:D,videoError:L,setVideoError:A,gender:K,getButtonText:()=>T?a.LanguageKeys.reset:le?a.LanguageKeys.start:a.LanguageKeys.loading,isScanning:T,startScan:ue,isModelLoaded:le,onRetry:r},children:e.jsx(a.ShadowRoot,{children:e.jsx(d,{webcamRef:v,canvasRef:b})})})})})};
2
+ //# sourceMappingURL=FaceScan-CFyDHXyU.js.map
@@ -0,0 +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{p as l,s as d,v as u,a as m,L as h,u as f,H as g,b as p,S as y,m as S,g as b,G as w,d as v,F as x,P as F,c as N,e as _,f as I,h as k,i as M,j as C,k as D,l as E,n as P,o as T,q as R,r as z,C as $,t as L,w as j,x as V,y as O}from"./LoadingScreen-DtPpNDue.js";import{ArrowRight as W}from"lucide-react";import{Drawer as U}from"@mui/material";let B=null,A=!1;function q({faceScanId:e,onValidPose:t,onScanComplete:a,onModelReady:s,onStartRecording:h,shopDomain:f,isError:g,isSuccess:p}){const y=n(null),[S,b]=o(0),[w,v]=o(0),[x,F]=o(!1),[N,_]=o(!1),I=n(null),k=n(S),M=n(w),C=n([]),D=n(""),E=n(0),P=n(!1),T=n(0),R="undefined"!=typeof navigator&&(/iPad|iPhone|iPod/.test(navigator.userAgent)||"MacIntel"===navigator.platform&&navigator.maxTouchPoints>1),z=r(()=>["Face front","Turn head fully left","Turn head fully right","Smile facing front"],[]),$=r(()=>function(e,t){let a;return(...n)=>{a&&clearTimeout(a),a=setTimeout(()=>e(...n),t)}}(e=>{l.capture(`${f}/face_scan_pose_detection`,e)},4e3),[f]),L=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],m=t.map(e=>e[2]).filter(e=>e>0),h=m.length>0?m.reduce((e,t)=>e+t,0)/m.length:0,f=a.map(e=>e[2]).filter(e=>e>0),g=f.length>0?f.reduce((e,t)=>e+t,0)/f.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(h.toFixed(3)),avgBodyScore:parseFloat(g.toFixed(3)),faceKeypointsDetected:m.length,bodyKeypointsDetected:f.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})};$(w)}catch(e){console.warn("Failed to track pose detection:",e)}}},[e,$]),j=()=>{l.capture(`${f}/face_scan_detection_started`,{faceScanId:e,stage:k.current,timestamp:(new Date).toISOString(),stageName:z[k.current]}),setTimeout(()=>{_(!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(B)return B;if(A)for(;A;)if(await new Promise(e=>setTimeout(e,100)),B)return B;A=!0;try{const[e,t]=await Promise.all([import("@tensorflow/tfjs"),import("./pose-detection.esm-DmD8en-O.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="number"==typeof m.width?m.width:m.width.ideal??m.width.max??1280,n.height="number"==typeof m.height?m.height:m.height.ideal??m.height.max??720;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 B=a,a}catch(e){return console.error("Failed to preload detector:",e),null}finally{A=!1}})();e&&(y.current=e,console.log("Face scan model loaded successfully"),F(!0),s?.())}catch(e){console.error("Error initializing face scan:",e)}};return i(()=>{if(!g&&!p)return V(),()=>{(async()=>{try{F(!1)}catch(e){console.error("Error disposing resources:",e)}finally{b(0),v(0),k.current=0,M.current=0,C.current=[]}})()}},[g,p]),i(()=>{k.current=S},[S]),i(()=>{M.current=w},[w]),{faceScanDetector:async(n,o)=>{if(y.current&&n.current&&x&&N&&!(n.current.readyState<2))try{const r=await y.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(M.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}})(k.current,n),s=c.slice(2).filter(e=>e[2]>.7).length<=2;C.current.push(i&&s),C.current.length>10&&C.current.shift();if(C.current.filter(Boolean).length>=2){const e=M.current+1;v(e)}else v(Math.max(0,M.current-1));if(M.current>=2){t?.();const n=k.current+1;v(0),C.current=[],b(n),_(!1),(async()=>{if(await d.playAudio(`${u}face-scan-vos/Sound-effect.mp3`),l.capture(`${f}/face_scan_detection_stage_completed`,{faceScanId:e,completedStage:k.current,nextStage:n,timestamp:(new Date).toISOString(),totalStages:4,stageName:z[k.current]}),1===n&&h&&h(),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 d.playAudio(`${u}face-scan-vos/${e}`),j()}})()}L(n,c,k.current,i,s,M.current)}}catch(e){console.error("Pose detection error:",e)}},scanStage:S,setScanStage:b,consecutiveValid:w,isModelLoaded:x,resetScan:()=>{l.capture(`${f}/face_scan_reset`,{faceScanId:e,stage:k.current,timestamp:(new Date).toISOString(),stageName:z[k.current],consecutiveValid:M.current}),b(0),v(0),_(!1),k.current=0,M.current=0,C.current=[],D.current="",E.current=0,P.current=!1,I.current&&(speechSynthesis.cancel(),I.current=null)},enableVoiceCommands:()=>{if(P.current=!0,"undefined"!=typeof window&&R&&"speechSynthesis"in window){const e=new SpeechSynthesisUtterance("");e.volume=0,speechSynthesis.speak(e)}},startScanSequence:j,isScanningActive:N}}function J({onRetry:a,loading:n}){const{translate:o}=s(h)||{},r=f();return e("div",{className:"fixed common-ui-main top-[0] left-[0] z-[999] flex justify-center items-center w-full h-full",style:{background:r?.style?.base?.backgroundColor},children:t("div",{className:"flex flex-col w-full items-center p-[1rem] rounded-lg ",children:[e(g,{noTitle:!0}),t("div",{className:"flex flex-col items-center w-full",children:[e("h2",{className:"text-xl my-[0] 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:o?.(p.scanFailed)}),e("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:o?.(p.clickToResetScan)}),e(y,{disabled:n,className:"w-full h-[45px] shadow-[0px_1px_2px_0px_#00000040] text-[16px]",buttonText:o?.(p.resetScan),postfixIcon:e(W,{}),buttonFunc:()=>a?.()})]})]})})}function G({stage:a,videoLoading:n,setVideoLoading:o,videoError:r,setVideoError:c,gender:i,btnConfig:l}){const{translate:d}=s(h)||{},u=f();return-1===a?t("div",{className:"text-center common-ui-main p-[16px] w-full h-full",style:{background:u?.style?.base?.backgroundColor},children:[t("div",{className:"w-full",children:[e(g,{noTitle:!0}),e("h2",{className:"my-[0]",style:{fontFamily:u?.style?.heading?.headingFontFamily||"SeriouslyNostalgic Fn",fontSize:u?.style?.heading?.headingFontSize||"32px",color:u?.style?.heading?.headingColor||"#000",fontWeight:u?.style?.heading?.headingFontWeight||"normal"},children:d?.(p.faceVisible)}),n&&e("div",{className:"mb-4 flex items-center justify-center",style:{fontFamily:u?.style?.subheading?.subheadingFontFamily||"'Inter', sans-serif",fontSize:u?.style?.subheading?.subheadingFontSize||"14px",color:u?.style?.subheading?.subheadingColor||"#4b5563",fontWeight:u?.style?.subheading?.subheadingFontWeight||"normal"},children:d?.(p.loadingVideo)}),r&&e("div",{className:"mb-4 text-red-600",style:{fontFamily:u?.style?.subheading?.subheadingFontFamily||"'Inter', sans-serif",fontSize:u?.style?.subheading?.subheadingFontSize||"14px",color:"#ff0000",fontWeight:u?.style?.subheading?.subheadingFontWeight||"normal"},children:d?.(p.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:l.isDisabled,className:"!w-[60px] !h-[35px] !py-0 !px-0",buttonText:d?.(l.label),postfixIcon:l?.icon,buttonFunc:l.onClick})})]}):e("div",{className:"text-center common-ui-main p-[16px] w-full h-full",style:{background:u?.style?.base?.backgroundColor},children:t("div",{className:"w-full",children:[e(g,{noTitle:!0}),e("h3",{className:"mb-[0.5rem] mt-[0]",style:{fontFamily:u?.style?.heading?.headingFontFamily||"SeriouslyNostalgic Fn",fontSize:u?.style?.heading?.headingFontSize||"32px",color:u?.style?.heading?.headingColor||"#000",fontWeight:u?.style?.heading?.headingFontWeight||"normal"},children:d?.(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 K=({webcamRef:n,canvasRef:o})=>{const{isError:r,isSuccess:c,showLoader:i,hasError:l,resetScanState:d,showGuideCard:u,scanStage:h,videoLoading:g,setVideoLoading:p,videoError:y,setVideoError:S,gender:b,getButtonText:w,isScanning:v,startScan:x,isModelLoaded:_,onRetry:I}=s(F),k=f();return r?e(J,{onRetry:I}):c?e("div",{className:"fixed z-[9] common-ui-main w-full h-full",style:{background:k?.style?.base?.backgroundColor},children:e(N,{url:k?.loader,loaderType:"black"})}):t(a,{children:[e("audio",{id:"audioElement",crossOrigin:"anonymous",preload:"auto",style:{position:"absolute",zIndex:-99999},src:void 0}),i&&!l&&e("div",{className:"fixed z-[9] common-ui-main w-full h-full",style:{background:k?.style?.base?.backgroundColor},children:e(N,{url:k?.loader,loaderType:"black"})}),e("div",{className:"h-full flex-col common-ui-main relative w-full flex justify-center items-center text-center rounded-t-[20px]",style:{background:k?.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:m.width.ideal,height:m.height.ideal,className:"w-full h-full object-cover fixed left-0 top-0 z-0",style:{transform:"scaleX(-1)"}}),e("canvas",{ref:o,width:m.width.ideal,height:m.height.ideal,style:{transform:"scaleX(-1)",opacity:"0"}})]})})}),!i&&l&&e(J,{loading:i,onRetry:d}),u&&!l&&!i&&e(U,{open:!0,className:"face-scan-small camera-draw",anchor:"bottom",onClose:(e,t)=>{},disablePortal:!0,hideBackdrop:!0,children:e(G,{stage:h,videoLoading:g,setVideoLoading:p,videoError:y,setVideoError:S,gender:b,btnConfig:{label:w(),onClick:v?d:x,isDisabled:i||!_,icon:e(v?W:a,{})}})})]})},H=t=>{const{onScanSuccess:a,onScanError:s,onRetry:l,onScanStart:m,onCaptureComplete:h,onUploadStart:f,onUploadEnd:g,onMeasurementSocketStart:y,onMeasurementSocketClose:S,config:b,isError:w,isSuccess:v}=t,x=t.userDetails??{email:"",gender:"male",deviceFocalLength:0,shopDomain:"",bodyScanId:""},N=t.token??"",W=n(null),U=n(null),B=n(null),A=n([]),J=n(null),G=n(null),[H,X]=o(!1),[Q,Y]=o(!1),[Z,ee]=o(!1),[te,ae]=o(!0),[ne,oe]=o(!1),[re,ce]=o(!1),[ie,se]=o(!1),[le,de]=o(_()),ue=r(()=>I(N),[N]),{email:me,gender:he,deviceFocalLength:fe,shopDomain:ge,callbackUrl:pe,bodyScanId:ye}=x,[Se,be]=o([]),[we,ve]=o(k),xe=r(()=>M(),[]),Fe=C(Se),Ne=D(Fe);E();const _e=c(()=>{console.log("Stopping recording..."),B.current&&"recording"===B.current.state&&B.current.stop(),B.current=null},[]),Ie=async()=>{if(h?.(),A.current){if(0===A.current.length)return console.error("No video data recorded"),se(!0),void X(!1);f?.(),X(!0);const e=new File(A.current,`${le}.${Ne}`,{type:Fe}),t=G.current??await j(e),a=e.size,n=(a/1048576).toFixed(2),o=Math.round(a/1e4),r={video_size_mb:parseFloat(n),video_size_bytes:a,video_fps:t||0,blob_count:A.current.length,estimated_duration_seconds:o},c=[{gender:he},{face_scan_id:le},{focal_length:`${fe}`},{customer_store_url:ge},{scan_type:"face_scan"},{body_scan_id:ye}];pe&&c.push({callback_url:pe}),V({eventName:`${ge}/face_scan_meta_data`,faceScanId:le,email:me,data:JSON.stringify({metaData:c,videoData:r})});const i=Date.now();V({eventName:`${ge}/face_scan_upload_start`,faceScanId:le,email:me,startTime:i});try{const t=await ue.fileUpload.faceScanFileUploader({file:e,arrayMetaData:c,objectKey:le,email:me,contentType:e.type}),a=Date.now();V({eventName:`${ge}/face_scan_upload_complete`,faceScanId:le,email:me,completionTime:a,uploadDuration:a-i}),g?.(),console.log("✅ Upload successful",t),ue.measurement.handlFaceScaneSocket({onPreopen:()=>{y?.(),O({eventName:`${ge}/webSocket`,faceScanID:le,connection:"pre_open",type:"faceScan_recommendation",email:me})},faceScanId:le,onOpen:()=>{O({eventName:`${ge}/webSocket`,faceScanID:le,connection:"open",type:"faceScan_recommendation",email:me}),console.log("websocket connect open")},onError:e=>{O({eventName:`${ge}/webSocket`,faceScanID:le,connection:"error",type:"faceScan_recommendation",email:me}),$e(e)},onSuccess:e=>{O({eventName:`${ge}/webSocket`,faceScanID:le,connection:"success",type:"faceScan_recommendation",email:me}),Le(e)},onClose:()=>{S?.(),console.log("websocket connect close"),O({eventName:`${ge}/webSocket`,faceScanID:le,connection:"close",type:"faceScan_recommendation",email:me})}})}catch(e){g?.(),$e(e)}}},ke=c(()=>{const e=W.current?.srcObject;if(!e)return;const t=e.getVideoTracks()[0].getSettings(),{width:a=1280,height:n=720}=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=t.frameRate??10;G.current=s;const l=o.captureStream(s),d={videoBitsPerSecond:15e5};let u;Se.length>0&&(d.mimeType=Se[0]);try{u=new MediaRecorder(l,d)}catch(e){return console.error("MediaRecorder init failed:",e),se(!0),void X(!1)}A.current=[],u.ondataavailable=e=>{e?.data&&e.data.size>0&&A.current&&A.current.push(e.data)},u.onstop=()=>{console.log("Recording stopped, total blobs:",A?.current?.length),Ie()},u.start(100),B.current=u,console.log("Recording started successfully (portrait normalized)")},[Se,Ie]),{faceScanDetector:Me,scanStage:Ce,setScanStage:De,resetScan:Ee,isModelLoaded:Pe,startScanSequence:Te}=q({faceScanId:le,shopDomain:ge,isError:w,isSuccess:v,onScanComplete:()=>{_e()},onModelReady:()=>{Y(!0)},onStartRecording:()=>{console.log("Stage 0 completed - starting recording for stages 1-3"),ke()}}),Re=c(()=>{Pe&&(m?.(),De(0),d.playAudio(`${u}face-scan-vos/Face-forward.mp3`),setTimeout(()=>{ee(!0),setTimeout(()=>{Te()},200)},200))},[De,ee,Te,Pe,m]),ze=c(()=>{ee(!1),ae(!0),_e(),Ee(),l?.(),A.current=[],G.current=null,B.current&&(B.current=null),se(!1),De(-1),de(_()),W.current&&J.current&&(W.current.srcObject=J.current,console.log("Camera stream restored after reset"))},[De,ee,ae,_e,Ee,de]),$e=e=>{console.log(e,"ws error"),s?.(e),se(!0),X(!1),ae(!1),V({eventName:`${ge}/faceScan`,faceScanId:le,status:"failed",email:me,data:JSON.stringify(e)})},Le=e=>{console.log(e,"ws success"),e&&"intermediate"===e?.resultType&&V({eventName:`${ge}/faceScan_success/intermediate`,faceScanId:le,status:"success",email:me,data:JSON.stringify(e)}),a?.(e)};i(()=>{if(!w&&!v)return navigator.mediaDevices.getUserMedia&&navigator.mediaDevices.getUserMedia({video:we}).then(e=>{J.current=e,W.current&&(W.current.srcObject=e)}).catch(e=>{console.error("Error accessing webcam:",e),we!==k?se(!0):ve(P)}),()=>{J.current&&J.current.getTracks().forEach(e=>e.stop())}},[w,v,we]),i(()=>{if(!Q||!Z)return;const e=setInterval(()=>{Me(W,U)},500);return()=>clearInterval(e)},[Me,Q,Z]);return console.log("Model ready:",Q,"Has error:",ie,"Is scanning:",Z,"showLoader",H),i(()=>{const e=T(xe,R);be(e)},[xe]),i(()=>{De(-1)},[]),e(z,{children:e($,{config:b,children:e(F.Provider,{value:{isError:w,isSuccess:v,showLoader:H,hasError:ie,resetScanState:ze,showGuideCard:te,scanStage:Ce,videoLoading:ne,setVideoLoading:oe,videoError:re,setVideoError:ce,gender:he,getButtonText:()=>Z?p.reset:Pe?p.start:p.loading,isScanning:Z,startScan:Re,isModelLoaded:Pe,onRetry:l},children:e(L,{children:e(K,{webcamRef:W,canvasRef:U})})})})})};export{H as F};
2
+ //# sourceMappingURL=FaceScan-CHTHQItg.js.map