@swan-admin/swan-dev-web-component 0.1.0-alpha.1779446765 → 0.1.0-alpha.1780312064
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.
- package/dist/BodyScan-3YoMZG7n.js +2 -0
- package/dist/BodyScan-B0qqqK3C.js +2 -0
- package/dist/BodyScan-B87W6dpH.js +2 -0
- package/dist/BodyScan-BLvWlYnA.js +2 -0
- package/dist/BodyScan-BMTK6e-E.js +2 -0
- package/dist/BodyScan-BQri8pAO.js +2 -0
- package/dist/BodyScan-BjYHCskz.js +2 -0
- package/dist/BodyScan-CLpL3Uwx.js +2 -0
- package/dist/BodyScan-CXwtxfOd.js +2 -0
- package/dist/BodyScan-CYn7eLoz.js +2 -0
- package/dist/BodyScan-DHMf2V5R.js +2 -0
- package/dist/BodyScan-DPSQ1hKh.js +2 -0
- package/dist/BodyScan-DX_KbG5U.js +2 -0
- package/dist/BodyScan-DntA0MBx.js +2 -0
- package/dist/BodyScan-DyDxGqfI.js +2 -0
- package/dist/BodyScan-Srq29PK8.js +2 -0
- package/dist/BodyScan-eUuIC3jY.js +2 -0
- package/dist/BodyScan-iOXndWaO.js +2 -0
- package/dist/BodyScan-t9qdQAL-.js +2 -0
- package/dist/BodyScan-z6h5fueJ.js +2 -0
- package/dist/FaceScan-AHZ-ajep.js +2 -0
- package/dist/FaceScan-CNoW9DIE.js +2 -0
- package/dist/FaceScan-CxDcvM4f.js +2 -0
- package/dist/FaceScan-DW6Ix1a1.js +2 -0
- package/dist/FaceScan-DrW2yUSA.js +2 -0
- package/dist/Modal-BzH-_ch3.js +2 -0
- package/dist/bodyScan.js +1 -1
- package/dist/bodyScan.mjs +1 -1
- package/dist/faceScan.js +1 -1
- package/dist/faceScan.mjs +1 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{jsx as e,jsxs as t,Fragment as n}from"react/jsx-runtime";import r,{useState as a,useCallback as s,useEffect as o,createContext as c,useLayoutEffect as i,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,B as y,a as v,j as w,P as b,q as x,s as S,p as C,k as D,l as N,n as I,D as k,E as F,z as T,I as _,J as E,r as L,f as $,t as M,K as U,c as P,M as A,v as j,N as z,V,O as R,Q as B,R as q,G as K,T as O,U as W,W as H,h as J,i as G,o as Q,y as X,X as Y,w as Z,C as ee,x as te,A as ne}from"./Modal-BzH-_ch3.js";import re from"clsx";import ae from"react-webcam";import{X as se}from"lucide-react";import{Dialog as oe,Box as ce,Drawer as ie}from"@mui/material";import le from"video.js";const de="DESKTOP",ue="TAB",me="MOBILE",pe=c(void 0);function fe({children:t}){const[n,r]=a([window?.innerWidth,window?.innerHeight]),[s,c]=a(!1),d=()=>{r([window?.innerWidth,window?.innerHeight])};o(()=>{d()},[]),i(()=>(window.addEventListener("resize",d),()=>window.removeEventListener("resize",d)),[d]);let u=de;n[0]>768&&n[0]<1024&&(u=ue),n[0]<768&&(u=me);const m=l(()=>({size:n,setSize:r,clearInputs:s,setClearInputs:c,media:u}),[n,s,u]);return e(pe.Provider,{value:m,children:t})}var he=r.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 ge=r.memo(function({angle:n,countdown:r,isScanning:a,isInTargetRange:o,stabilityScore:c,children:i}){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(a)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)})`},[a,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 a?`text-[${g?.style?.angleDetector?.successAngleTextLightColor}]`:w(e,t)},[a,y]),x=s((e,t)=>t>70||e?g?.style?.angleDetector?.successAngleTextLightColor:g?.style?.angleDetector?.successAngleTextDarkColor,[]),S=s((e=!1)=>{const t=y();return a?g?.style?.angleDetector?.successAngleTextLightColor:x(e,t)},[a,y]),C=r;function D(){document.documentElement.style.setProperty("--real-vh",window.innerHeight+"px")}return D(),window.addEventListener("resize",D),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},"data-testid":"level-screen","data-angle-state":a?"locked":o?"target":"adjusting",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!==C?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:C})}):t("div",a?{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"})}),i]}:{className:re("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:re("mt-[.5rem] text-center w-[180px] flex-col flex items-center absolute top-[60px]",b()),style:{color:S()},children:[e(he,{size:30}),t("p",{style:{fontFamily:g?.style?.base?.baseFontFamily||"Inter, sans-serif"},children:[" ",u?.(h.startLevelCheck),e("br",{})]})]})]}),null!==C&&e("div",{className:"absolute bottom-[8rem] text-center",children:e("div",{className:re("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===C&&!a&&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===C&&!a&&e("div",{className:"absolute bottom-[5rem] text-center",children:t("div",{className:re("text-[1.5rem] font-light",b()),style:{color:S(),fontFamily:g?.style?.base?.baseFontFamily||"Inter, sans-serif"},children:[Math.round(n),"°"]})}),null===C&&!a&&e("div",{className:"absolute bottom-[2rem] text-center max-w-[20rem] mx-auto",children:e("div",{className:re("text-[.75rem] opacity-50",b()),style:{fontFamily:g?.style?.base?.baseFontFamily||"Inter, sans-serif",color:S()},children:u?.(h.placePhoneUpright)})})]})});function ye({resetScan:n,loadingCam:r,onUserMedia:a,onPause:s,pause:o,onReScan:c,recordingStarted:i,startSendingVideoFrames:l,showPause:u,webcamRef:p,onUserMediaError:f,resetDetector:w,videoConstraints:b,webcamKey:x,faceDone:S,isScanning:C}){const{media:D}=d(pe)||{},{translate:N}=d(m)||{};return t("div",{className:"App w-screen h-[100vh] relative common-ui-main","data-testid":"camera-scan","data-scan-phase":S?"spinning":i?"pose-detecting":C?"starting":"ready",children:[e("span",{onClick:()=>{n(),w()},className:"fixed right-[20px] top-[20px] z-[999]",children:e(se,{className:"text-[#fff]"})}),e("div",{className:"w-full h-full overflow-hidden ",children:D===me&&e(ae,{audio:!1,ref:p,screenshotQuality:1,videoConstraints:b,mirrored:!0,screenshotFormat:"image/jpeg",onUserMedia:a,onUserMediaError:f,style:{position:"fixed",top:0,bottom:0,zIndex:0,width:"100%",height:"100%",objectFit:"cover"}},x)}),t("div",{className:"fixed bottom-[30px] w-full z-[999] flex flex-col gap-4 items-center justify-center",children:[u&&e(g,{className:"!w-[180px] !h-[40px] !py-[0] mx-auto ",prefix:y,buttonText:N?.(h.pause),buttonFunc:s,btnSecondary:!0}),o?e("div",{children:e(g,{className:"!w-[180px] !h-[40px] !py-[0] mx-auto",buttonText:N?.(h.restart),buttonFunc:c,btnSecondary:!0})}):i?null:e(g,{"data-testid":"start-scan-btn",className:"!w-[180px] !h-[40px] !py-[0] mx-auto !bg-[#ffffff] !text-[#000000] "+(r?"!opacity-50":""),buttonText:N?.(h.startScan),buttonFunc:l,disabled:r})]}),e("audio",{id:"audioElement",crossOrigin:"anonymous",preload:"auto",style:{position:"absolute",zIndex:-99999},src:`${v}scanAudioInstructions/silence.mp3`})]})}let ve,we=null,be=null,xe=null;let Se=null;var Ce=r.memo(function({setIsScanLocked:t,resetDetector:n,scanID:r,setIsVideoUploaded:c,setScanFailsError:i,setScanStartTime:m,setScanUniqueKey:p,userDetails:f}){const{gender:h,heightInCm:g,email:y,shopDomain:U}=f,P=u(null),A=u(null),j=u(null),[z,V]=a([]),[R,B]=a(!0),[q,K]=a(!1),[O,W]=a(!1),[H,J]=a(!0),[G,Q]=a(!1),X=u(null),[Y,Z]=a(""),[ee,te]=a([]),[ne,re]=a(""),[ae,se]=a(!1),[oe,ce]=a(!1),[ie,le]=a(!1),[de,ue]=a([]),[me,pe]=a(!1),fe=u(!0),{poseDetector:he}=function(){const[e,t]=a(0),[n,r]=a(0),[s,c]=a(!1),i=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-DC0_P6R7.js"),import("@tensorflow/tfjs-core"),import("@tensorflow/tfjs-backend-webgl")]);xe=e,await t.setBackend("webgl"),await t.ready(),console.log("TensorFlow backend ready (WebGL)");const r={runtime:"mediapipe",modelType:"full",solutionPath:"https://cdn.jsdelivr.net/npm/@mediapipe/pose"};try{be=await xe.createDetector(xe.SupportedModels.BlazePose,r),console.log("MediaPipe detector created successfully")}catch(e){console.warn("MediaPipe failed, falling back to TFJS runtime:",e),be=await xe.createDetector(xe.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),we=null,!1}}function p(e){return!(!e||0===e.length)&&22===e.filter(e=>e[2]>.7).length}return o(()=>{if(d.current=!0,!be)return we||(we=m()),we.then(e=>{e&&d.current&&c(!0)}),()=>{d.current=!1};c(!0)},[]),o(()=>{l.current=e,e>6&&i.current<2&&(r(e=>e+1),t(0))},[e]),o(()=>{i.current=n},[n]),{poseDetector:async(e,n)=>{if(!be||!d.current||!n?.current?.video)return;const r=n.current.video;if(!(r.readyState<2))try{const n=await be.estimatePoses(r,{flipHorizontal:!1});if(!n||!n.length)return;const a=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!==i.current||p(a)||t(e=>e+1),1===i.current&&p(a)&&t(e=>e+1),2===i.current&&e()}catch(e){console.error("Pose detection error:",e)}},isLoaded:s,spinPhase:n,resetDetector:()=>{i.current=0,l.current=0,t(0),r(0)},retryLoading:async()=>{be||we||(we=m(),await we&&d.current&&c(!0))}}}(),ge=u(!0),Ce=u(!1),De=u(0),Ne=u(0),Ie=u(!1),ke=u(!1),Fe=u(!1),Te=u(()=>{}),_e=u(()=>{}),Ee=u(null),Le=u(null),[$e,Me]=a([]),[Ue,Pe]=a(0),[Ae,je]=a(w),{setStartGyro:ze,uploadScanFile:Ve,setUploadLoading:Re,swan:Be,onScanStart:qe,onCaptureComplete:Ke}=d(b),Oe=()=>{Ce.current=!1,clearTimeout(ve),X.current&&clearTimeout(X.current),Le.current&&(clearTimeout(Le.current),Le.current=null),p($()),i(""),Re?.(!1),V([]),j.current=null,B(!0),K(!1),W(!1),J(!0),Q(!1),X.current=null,Z(""),te([]),re(""),se(!ae),ze(!1),S.stopAudio(),ce(!1),le(!1),De.current=0,Ne.current=0,Ie.current=!1,Fe.current=!1,null!==A.current&&A.current.stop(),de.forEach(e=>{A.current&&A.current.removeEventListener("dataavailable",e)}),ue([]),fe.current=!0,pe(!1),c(!1),P.current?.stream&&B(!1)},We=s(()=>{setTimeout(()=>{B(!1)},1e3)},[]),He=s(e=>{if(console.log("camera error",e),Ae===w)return je(x),void Pe(e=>e+1);B(!1)},[Ae]),Je=s(()=>{fe.current=!1,le(!0),pe(!1),X.current&&clearTimeout(X.current),Le.current&&(clearTimeout(Le.current),Le.current=null),A.current&&A.current.pause(),S.stopAudio(),Be.poseDetection.disconnect(),C.capture(`${U}/pose_detection_disconnected`,{scanID:r,email:y,id:Ee.current,reason:"pause"}),De.current=0,Ne.current=0,Ie.current=!1,Fe.current=!1,A.current&&A.current.stop(),de.forEach(e=>{A.current&&A.current.removeEventListener("dataavailable",e)}),ue([]),clearTimeout(ve)},[A,de,S,fe]),Ge=l(()=>D(),[]),Qe=N($e),Xe=I(Qe),Ye=s(async()=>{fe.current=!0,await S.playAudio(`${v}SpotOn.mp3`),le(!1),pe(!1),X.current&&clearTimeout(X.current),K(!1)},[X,S]),Ze=s(async()=>{if(!ke.current&&!Ee.current){ke.current=!0;try{Ee.current=await Be.poseDetection.connect(),C.capture(`${U}/pose_detection_connected`,{scanID:r,email:y,id:Ee.current})}catch(e){console.log(e,"while connecting websocket");const t=k(e);i(`Connection failed: ${t}`),C.capture(`${U}/pose_detection_connect_failed`,{scanID:r,email:y,error:t})}finally{ke.current=!1}}},[r,U,y]),et=s(async()=>{F({eventName:`${U}/rescan`,email:y,scanID:r,height:g,gender:h,status:!1}),fe.current=!1,Be.poseDetection.disconnect(),C.capture(`${U}/pose_detection_disconnected`,{scanID:r,email:y,id:Ee.current,reason:"rescan"}),Ee.current=null,Oe(),await Ze(),_e.current()},[Ze,r,y]),tt=s(({data:e})=>{e&&e.size>0&&fe.current&&(V(t=>t.concat(e)),!Ce.current&&P.current&&(Ce.current=!0,he(()=>{Ye(),T({eventName:`${U}/tensorFlow`,scanID:r,email:y,message:"recording stopped by tensorflow "})},P)))},[Ye,T,U,r,y,P]),nt=s(async()=>{const e=ee[ee.length-1];e&&fe.current&&(await S.playAudio(v+e),fe.current&&(ve=setTimeout(nt,2e3)))},[ee,fe]),rt=s(()=>{A&&A.current&&A.current.stop(),K(!0);try{if(P&&P.current&&P.current.stream){const e=P.current.stream.getVideoTracks()[0];if(e){const t=e.getSettings();j.current=t.frameRate||null}const t={videoBitsPerSecond:15e5};$e[0]&&(t.mimeType=$e[0]),A.current=new MediaRecorder(P.current.stream,t),A.current.addEventListener("dataavailable",tt),A.current.addEventListener("stop",()=>{J(!0)}),ue([...de,tt]),A.current.start(1e3),J(!1)}}catch(e){console.log("error while using media recorder",e)}},[P,$e,tt,de]),at=s(async()=>{Le.current&&(clearTimeout(Le.current),Le.current=null),X.current&&clearTimeout(X.current),rt(),fe.current&&(X.current=setTimeout(async()=>{fe.current&&(await S.playAudio(`${v}SpotOn.mp3`),K(!1))},15e3)),W(!0),fe.current&&await S.playAudio(`${v}Spin.mp3`)},[rt,fe,S]);o(()=>{Te.current=at},[at]);const st=s(({data:e})=>{const t=Be.poseDetection.connected();e.size>0&&!t?i("Pose detection connection lost. Please try again."):e.size>0&&t&&(Ie.current||(Ie.current=!0,Be.poseDetection.poseStatus(async e=>{if(console.log("poseStatus data:",e),e&&e.audio&&e.audio.length>0){C.capture(`${U}/pose_instruction_received`,{scanID:r,email:y,audio:e.audio,status:e.status,sid:e.sid,counter:De.current,consecutiveFalse:Ne.current,type:"body_scan_instruction"});const t=_();!0===e.status&&e.sid===Ee.current?(Ne.current=0,De.current<2?(De.current+=1,1!==De.current||Fe.current?2===De.current&&t?.paused&&S.playAudio(v+e.audio):(Fe.current=!0,S.stopAudio(),await S.playAudio(v+e.audio))):(re(e.audio),clearTimeout(ve),Be.poseDetection.disconnect(),C.capture(`${U}/pose_detection_disconnected`,{scanID:r,email:y,id:Ee.current,reason:"pose_confirmed"}),Ie.current=!1,setTimeout(()=>Te.current(),1e3))):(Ne.current+=1,Ne.current>=3&&(De.current=0,Fe.current=!1),!t?.paused||Se&&Se?.audioName===e.audio?Se?.audioName===e.audio&&t?.paused&&(Se&&Se.no_of_times_skipped>=Se.skipCount?(Se.no_of_times_skipped=0,S.playAudio(v+e.audio)):Se&&(Se.no_of_times_skipped+=1)):(Se={skipCount:2,no_of_times_skipped:0,audioName:e.audio},S.playAudio(v+e.audio)))}})),P?.current&&null!==P.current.getScreenshot()&&Be.poseDetection.videoEmit({image:P.current.getScreenshot()||"",scanId:r}))},[P,r,Be,S,U,y]),ot=s(async()=>{Q(!0),ze(!0),qe?.(),Le.current&&clearTimeout(Le.current),Le.current=setTimeout(()=>{fe.current&&(i("Pose not detected. Please try again."),fe.current=!1,Be.poseDetection.disconnect())},24e4),ge.current&&(ge.current=!1,T({eventName:"scan started",scanID:r,status:"success",email:y})),m(E()),B(!0),fe.current&&await S.playAudio(`${v}StartScan.mp3`),fe.current&&await S.playAudio(`${v}LiftArmsAndHoldAtHip.mp3`),fe.current&&(Q(!1),K(!0),ce(!0),pe(!0),We());try{if(P&&P.current&&P.current.stream&&fe.current){const e=P.current.stream.getVideoTracks()[0];if(e){const t=e.getSettings();j.current=t.frameRate||null}const t={videoBitsPerSecond:15e5};$e[0]&&(t.mimeType=$e[0]),fe.current&&(A.current=new MediaRecorder(P.current.stream,t)),fe.current&&A.current&&A.current.addEventListener("dataavailable",st),ue([...de,st]),A.current&&A.current.start(1e3),J(!1),fe.current&&(ve=setTimeout(nt,2e3))}}catch(e){console.log("error ----------",e)}},[P,$e,st,de,nt,fe,qe]);return o(()=>(U&&(t(!0),Ze()),()=>{const e=Ee.current;Ee.current=null,e&&(Be.poseDetection.disconnect(),C.capture(`${U}/pose_detection_disconnected`,{scanID:r,email:y,id:e,reason:"unmount"})),de.forEach(e=>{A?.current?.removeEventListener("dataavailable",e)})}),[U]),o(()=>{ee.push(Y)},[Y]),o(()=>{te([])},[ne]),o(()=>{const e=z.length&&z.length>0;H||!e||q||!fe.current||ie||A&&A.current&&(q||A.current.stop())},[H,q,z,ie]),o(()=>{const e=z.length&&z.length>0;if(H&&e&&!q&&A&&A.current&&fe.current&&!ie&&!q){const e=new File(z,`${r}.${Xe}`,{type:Qe});Ke?.(),Re?.(!0),i(""),Ve?.(e,j.current)}},[H,q,z,ie,A,fe]),o(()=>{_e.current=ot},[ot]),o(()=>{const e=L(Ge,M);Me(e)},[Ge]),o(()=>{Oe()},[]),e(ye,{resetDetector:n,resetScan:Oe,loadingCam:R,onPause:Je,showRestart:oe,pause:ie,onReScan:et,recordingStarted:q,isScanning:G,startSendingVideoFrames:ot,faceDone:O,stopRecording:Ye,showPause:me,webcamRef:P,onUserMedia:We,onUserMediaError:He,videoConstraints:Ae,webcamKey:Ue})});function De({scanID:t,userDetails:n,setIsVideoUploaded:r,setScanFailsError:s,setScanStartTime:c,setScanUniqueKey:i}){const[l,d]=a(90),[m,p]=a(0),[f,h]=a(null),[g,y]=a(!1),[v,w]=a(0),b=u([]),[x,S]=a(!1),C=l-m,D=C>=80&&C<=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),C],b.current.length>=5){const e=Math.max(...b.current)-Math.min(...b.current);w(D&&e<2?e=>Math.min(100,e+10):e=>Math.max(0,e-20))}D||null===f&&!g||I()},[C,D,f,g]),o(()=>{v>=100&&null===f&&!g&&N(),v<50&&null!==f&&I()},[v,f,g]);const N=()=>{h(3);const e=setInterval(()=>{h(t=>null===t||t<=1?(clearInterval(e),y(!0),null):t-1)},1e3)},I=()=>{h(null),x||y(!1)};return e(ge,{angle:C,countdown:f,isScanning:g,isInTargetRange:D,stabilityScore:v,children:g&&e(Ce,{setIsScanLocked:S,resetDetector:()=>{d(90),p(0),h(null),y(!1),w(0),S(!1),b.current=[]},scanID:t,userDetails:n,setIsVideoUploaded:r,setScanFailsError:s,setScanStartTime:c,setScanUniqueKey:i})})}function Ne({setShowDrawer:t,config:n,loader:r}){const[c,i]=a({disabled:!1,message:""}),[l,d]=a(!0),m=u(null),p=s(async()=>{const e=await U();i(e),d(!1)},[]);return o(()=>{p()},[]),l?e(P,{url:r,loaderType:"black"}):c?.disabled?e(A,{config:n,message:c?.message}):e(ae,{audio:!1,ref:m,screenshotQuality:1,videoConstraints:j,mirrored:!0,onUserMedia:()=>t?.(!0),screenshotFormat:"image/jpeg",style:{position:"relative",top:0,bottom:0,zIndex:0,width:"100%",height:"100%",objectFit:"cover"}})}function Ie({link:t,onReady:n,wrapperClassName:r="[&_video]:rounded-t-[20px] w-full h-full"}){const a=u(null),s=u(null);let c={autoplay:!0,controls:!1,responsive:!0,fluid:!0,muted:!0,navigationUI:"hide",preload:"metadata",poster:z};return o(()=>{if(!s.current&&t&&a?.current){const e=le(a.current,{...c});e.ready(()=>{s.current=e;const r={...c,sources:[{src:t,type:"application/x-mpegURL"}]};e.autoplay(r.autoplay),e.src(r.sources),n?.(e)})}},[t,a]),o(()=>{const e=s.current;return()=>{e&&!e.isDisposed()&&(e.dispose(),s.current=null)}},[s]),e("div",{className:r,children:e("video",{ref:a,muted:!0,className:"video-js",playsInline:!0,onDrag:e=>e.preventDefault()})})}function ke({scanFailsError:r,onNext:s,gender:o,setScanUniqueKey:c,setIsVideoUploaded:i}){const{translate:l}=d(m)||{},u=p(),[y,v]=a(!1),w=()=>{v(!y)};return t(n,{children:[t("div",{"data-testid":"scan-error-message",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:r&&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:k(r)}),e("img",{className:"my-[0.5rem] aspect-[2/1.4] w-full object-cover",onClick:w,src:V[o],alt:"icon"})]})}),r&&e("div",{className:"p-[1rem] flex gap-[0.5rem]",children:e(g,{"data-testid":"scan-again-btn",disabled:!1,buttonText:l?.(h.scanAgain),className:"!shadow-none",buttonFunc:()=>{s?s?.():c?.($()),i?.(!1)}})})]}),y&&t(oe,{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(se,{className:"absolute right-[8px] top-[8px] text-white z-[9]"})})}),e("div",{className:"aspect-video object-cover rounded-[20px] ",children:e(Ie,{link:o?R[o].PRE_LINK:R.male.PRE_LINK,wrapperClassName:"w-screen h-screen fixed top-[0] left-[0]"})})]})]})}function Fe({scanId:n,userDetails:r,config:c,isVideoUploadedCorrect:i,isMeasurementAvailable:l,onComplete:u,isSuccess:p,onCustomScanSuccess:y,swan:v}){const{gender:w,shopDomain:b,heightInCm:x,deviceFocalLength:S,userName:D,email:N,scanType:I}=r||{},k=[O,W,H].includes(I??""),[F,T]=a(!0),_=s(async()=>{try{k&&(await(v?.auth.addUser({scanId:n,email:N,name:D,gender:w,height:x})),y?.()),C.capture(b??"",{scanID:n,email:N,height:x,focalLength:S,clothesFit:"0",gender:w})}catch(e){console.log(e)}},[k]),{translate:E}=d(m)||{};o(()=>{(i||l)&&_()},[i,l]);const L=p||i||l;return e(ce,{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(Ne,{loader:c?.loader,setShowDrawer:T}),e(ie,{open:F,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] common-ui-main overflow-y-auto",style:{background:c?.style?.base?.backgroundColor},children:t("div",{className:"w-full flex-1 flex flex-col min-h-[400px]",children:[e(f,{title:E?.(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 min-h-[170px]",muted:!0,loop:!0,autoPlay:!0,playsInline:!0,children:e("source",{src:w===K.Male?B:q,type:"video/mp4"})})}),L&&e(g,{className:"!w-[180px] mx-auto",buttonText:E?.(h.next),buttonFunc:()=>{u?.()}})]})})})]})})}const Te=()=>{const{userDetails:n,onRetry:r,isError:a,isSuccess:s,gender:o,scanUniqueKey:c,scanFailsError:i,setScanUniqueKey:l,setIsVideoUploaded:u,isMeasurementAvailable:m,isVideoUploadedCorrect:f,loading:h,showDeniedModal:g,uploadLoading:y,isLandscape:v,setScanFailsError:w,setScanStartTime:x,resetScan:S,onCustomScanSuccess:C,swan:D,onComplete:N}=d(b),I=p();return a?t("div",{"data-scan-state":"error",children:[e(Ne,{}),e(ie,{anchor:"bottom",open:!0,className:"camera-drawer",onClose:(e,t)=>{},disablePortal:!0,children:e(ke,{scanFailsError:!0,onNext:r,gender:o})})]}):s?e("div",{"data-scan-state":"success",children:e(Fe,{isSuccess:!0,onComplete:N})}):h?e("div",{"data-scan-state":"loading",className:"flex top-0 !mt-0 left-0 z-[999] absolute justify-center items-center w-full h-full",style:{background:I?.style?.base?.backgroundColor},children:e(P,{url:I?.loader,loaderType:"black"})}):!v||y||i?g.disabled?e("div",{"data-scan-state":"camera-denied",children:e(A,{})}):y||i||m||f?(y||m||f)&&!i?e("div",{"data-scan-state":"processing",children:e(Fe,{scanId:c,isMeasurementAvailable:m,userDetails:n,isVideoUploadedCorrect:f,onCustomScanSuccess:C,swan:D,onComplete:N,config:I})}):t("div",{"data-scan-state":"error-retry",children:[e(Ne,{}),e(ie,{anchor:"bottom",open:!0,className:"camera-drawer",onClose:(e,t)=>{},disablePortal:!0,children:e(ke,{scanFailsError:i,onNext:()=>{r?.(),S()},setScanUniqueKey:l,gender:o,setIsVideoUploaded:u})})]}):e("div",{"data-scan-state":"scanning",children:e(De,{scanID:c,userDetails:n,setIsVideoUploaded:u,setScanFailsError:w,setScanStartTime:x,setScanUniqueKey:l})}):e(A,{variant:"portrait",config:I})},_e=t=>{const{config:n,onRetry:r,onScanStart:c,onCaptureComplete:i,onUploadStart:d,onUploadEnd:m,onMeasurementSocketStart:p,onMeasurementSocketClose:f,onIntermediateScanSuccess:h,onScanError:g,onScanSuccess:y,onCustomScanSuccess:v,onComplete:w,isError:x,isSuccess:C}=t,D={email:"",shopDomain:"",gender:"male",heightInCm:0,scanType:"",deviceFocalLength:0,deviceModelName:"",sourceTag:"",callbackUrl:null,...t.userDetails??{}},N=t.token??"",{gender:I,scanType:F,shopDomain:_,heightInCm:L,email:M,deviceFocalLength:P,deviceModelName:A,callbackUrl:j,sourceTag:z}=D,V=l(()=>J(N),[N]),[R,B]=a(!1),[q,K]=a(!1),[O,W]=a(!1),[H,re]=a({disabled:!1,message:""}),[ae,se]=a(""),[oe,ce]=a(!1),[ie,le]=a(!0),[de,ue]=a(!1),[me,pe]=a(""),[he,ge]=a(E()),{gyroData:ye}=function(e){const[t,n]=a([]),[r,c]=a(!1),i=s(e=>{try{const{alpha:t,beta:r,gamma:a}=e;n(e=>[...e,{alpha:t?.toString()||void 0,beta:r?.toString()||void 0,gamma:a?.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()?c(!0):console.warn("Device orientation permission denied.")}catch(e){console.error("Error requesting device orientation permission:",e)}else c(!0)},[]);return o(()=>(e&&r?window.addEventListener("deviceorientation",i):n([]),()=>{window.removeEventListener("deviceorientation",i)}),[e,r,i]),o(()=>{e&&l()},[e,l]),{gyroData:t}}(de),{isLandscape:ve}=G();Q();const we=s(()=>{pe($()),se(""),B(!1),ce(!1)},[]),be=u(!1);o(()=>{!ve||be.current||R||x||C||ae||(S.stopAudio(),we()),be.current=ve},[ve,R,x,C,ae,we]);const xe=()=>{ge(null),pe("")},Se=s(async e=>{if(e&&"success"===e?.scanStatus&&"intermediate"===e?.resultType&&200===e?.code)return T({eventName:`${_}/measurement_success/intermediate`,scanID:me,status:"success",email:M}),K(!0),void h?.(e);y?.(e),K(!0),xe();const t=me;W(!0),T({eventName:`${_}/measurement_success/fit-view`,scanID:t,status:"success",email:M}),he&&T({eventName:`${_}/scan_completion_time`,scanID:t,status:"success",completionTime:E()-he,email:M})},[F,_,me]),Ce=e=>{W(!1),se(""),K(!1);let t=!1;V.measurement.handleMeasurementSocket({scanId:me,onPreopen:()=>{ne({eventName:`${_}/webSocket`,scanID:me,connection:"pre_open",type:"measurement_recommendation",email:M})},onOpen:()=>{p?.(),ne({eventName:`${_}/webSocket`,scanID:me,connection:"open",type:"measurement_recommendation",email:M})},onClose:()=>{f?.(),ne({eventName:`${_}/webSocket`,scanID:me,connection:"close",type:"measurement_recommendation",email:M}),t||(se("Connection closed. Please try again."),B(!1))},onError:e=>{var n;t=!0,n=e,g?.({...n,message:k(n)}),xe(),W(!1),se(n),K(!1),T({eventName:`${_}/measurement_failed/fit-view`,scanID:me,status:"failed",email:M,message:k(n)}),he&&T({eventName:`${_}/scan_completion_time`,scanID:me,status:"failed",completionTime:E()-he,email:M}),ne({eventName:`${_}/webSocket`,scanID:me,connection:"error",type:"measurement_recommendation",email:M})},onSuccess:e=>{t=!0,ne({eventName:`${_}/webSocket`,scanID:me,connection:"success",type:"measurement_recommendation",email:M}),Se(e)}})},De=s(async(e,t)=>{const n=Number((e.size/1048576).toFixed(2)),r=null!=t?t:await X(e),a=Y({gender:I,focal_length:`${P}`,height:`${L}`,customer_store_url:_,clothes_fit:"0",scan_type:F,callback_url:j,source_tag:z});T({eventName:`${_}/body_scan_meta_data`,scanID:me,email:M,data:JSON.stringify([...a,{fileSizeInMB:n,video_fps:r||0}])}),d?.();try{await V.fileUpload.uploadFileFrontend({file:e,arrayMetaData:a,scanId:me,email:M}),await V.fileUpload.setDeviceInfo({model:A,detection:"manual",gyro:ye,scanId:me}),console.log("video successfully uploaded"),ce(!1),T({eventName:`${_}/scan_success`,scanID:me,status:"success",email:M,data:JSON.stringify(a)}),T({eventName:"scan finished",scanID:me,status:"success",email:M}),ge(E()),setTimeout(()=>{ce(!0)},3e3)}catch(e){T({eventName:"scan finished",scanID:me,status:"failed",email:M,message:k(e)}),T({eventName:`${_}/scan_failed`,scanID:me,status:"failed",email:M,message:k(e),data:JSON.stringify(a)}),se(k(e)),ce(!1),g?.({...e,message:k(e)}),xe()}finally{ue(!1),m?.()}},[me,ye,d,m]),Ne=s(async()=>{if(+L<152.4||+L>213.36)return void g?.({message:"Height must be between 152.4cm (5ft) and 213.36cm (7ft)"});const e=await U();e.disabled?(T({eventName:`${_}/camera_activation`,scanID:me,status:"failed",email:M}),le(!1)):(le(!1),T({eventName:`${_}/camera_activation`,scanID:me,status:"success",email:M})),re(e),se(""),ce(!1)},[M,me,pe,_]);return o(()=>{x||C||_&&Ne()},[_,L,x,C]),o(()=>{x||C||oe&&_&&me&&Ce()},[oe,_,me,x,C]),e("div",{"data-testid":"body-scan-root",children:e(Z,{children:e(ee,{config:n,children:e(fe,{children:e(b.Provider,{value:{userDetails:D,onRetry:r,onScanError:g,isError:x,isSuccess:C,onScanSuccess:y,gender:I,scanUniqueKey:me,scanFailsError:ae,setScanUniqueKey:pe,setIsVideoUploaded:ce,isMeasurementAvailable:O,isVideoUploadedCorrect:q,loading:ie,showDeniedModal:H,uploadLoading:R,isLandscape:ve,setStartGyro:ue,uploadScanFile:De,setUploadLoading:B,resetScan:we,setScanFailsError:se,setScanStartTime:ge,onScanStart:c,onCaptureComplete:i,onCustomScanSuccess:v,onComplete:w,swan:V},children:e(te,{children:e(Te,{})})})})})})})};export{_e as B};
|
|
2
|
+
//# sourceMappingURL=BodyScan-3YoMZG7n.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{jsx as e,jsxs as t,Fragment as n}from"react/jsx-runtime";import r,{useState as a,useCallback as s,useEffect as o,createContext as c,useLayoutEffect as i,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,a as v,i as w,P as x,o as b,s as S,j as C,k as N,l as D,p as I,A as k,x as F,B as T,q as E,f as L,r as M,D as _,c as $,M as U,v as j,E as A,I as P,V as z,J as V,K as R,N as B,G as q,O as K,Q as O,R as W,h as H,n as J,w as G,T as Q,t as Y,C as X,y as Z}from"./Modal-CB_MHF7l.js";import ee from"clsx";import te from"react-webcam";import{X as ne}from"lucide-react";import{Dialog as re,Box as ae,Drawer as se}from"@mui/material";import oe from"video.js";const ce="DESKTOP",ie="TAB",le="MOBILE",de=c(void 0);function ue({children:t}){const[n,r]=a([window?.innerWidth,window?.innerHeight]),[s,c]=a(!1),d=()=>{r([window?.innerWidth,window?.innerHeight])};o(()=>{d()},[]),i(()=>(window.addEventListener("resize",d),()=>window.removeEventListener("resize",d)),[d]);let u=ce;n[0]>768&&n[0]<1024&&(u=ie),n[0]<768&&(u=le);const m=l(()=>({size:n,setSize:r,clearInputs:s,setClearInputs:c,media:u}),[n,s,u]);return e(de.Provider,{value:m,children:t})}var me=r.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 pe=r.memo(function({angle:n,countdown:r,isScanning:a,isInTargetRange:o,stabilityScore:c,children:i}){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(a)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)})`},[a,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`,[]),x=s((e=!1)=>{const t=y();return a?`text-[${g?.style?.angleDetector?.successAngleTextLightColor}]`:w(e,t)},[a,y]),b=s((e,t)=>t>70||e?g?.style?.angleDetector?.successAngleTextLightColor:g?.style?.angleDetector?.successAngleTextDarkColor,[]),S=s((e=!1)=>{const t=y();return a?g?.style?.angleDetector?.successAngleTextLightColor:b(e,t)},[a,y]),C=r;function N(){document.documentElement.style.setProperty("--real-vh",window.innerHeight+"px")}return N(),window.addEventListener("resize",N),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},"data-testid":"level-screen","data-angle-state":a?"locked":o?"target":"adjusting",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!==C?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:C})}):t("div",a?{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"})}),i]}:{className:ee("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:ee("mt-[.5rem] text-center w-[180px] flex-col flex items-center absolute top-[60px]",x()),style:{color:S()},children:[e(me,{size:30}),t("p",{style:{fontFamily:g?.style?.base?.baseFontFamily||"Inter, sans-serif"},children:[" ",u?.(h.startLevelCheck),e("br",{})]})]})]}),null!==C&&e("div",{className:"absolute bottom-[8rem] text-center",children:e("div",{className:ee("text-sm font-medium px-4 py-1.5 bg-black/20 rounded-[9999px] mt-8",x()),style:{fontFamily:g?.style?.base?.baseFontFamily||"Inter, sans-serif",color:S()},children:u?.(h.leavePhone)})}),o&&null===C&&!a&&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===C&&!a&&e("div",{className:"absolute bottom-[5rem] text-center",children:t("div",{className:ee("text-[1.5rem] font-light",x()),style:{color:S()},children:[Math.round(n),"°"]})}),null===C&&!a&&e("div",{className:"absolute bottom-[2rem] text-center max-w-[20rem] mx-auto",children:e("div",{className:ee("text-[.75rem] opacity-50",x()),style:{fontFamily:g?.style?.base?.baseFontFamily||"Inter, sans-serif",color:S()},children:u?.(h.placePhoneUpright)})})]})});function fe({resetScan:n,loadingCam:r,onUserMedia:a,onPause:s,pause:o,onReScan:c,recordingStarted:i,startSendingVideoFrames:l,showPause:u,webcamRef:p,onUserMediaError:f,resetDetector:w,videoConstraints:x,webcamKey:b,faceDone:S,isScanning:C}){const{media:N}=d(de)||{},{translate:D}=d(m)||{};return t("div",{className:"App w-screen h-[100vh] relative common-ui-main","data-testid":"camera-scan","data-scan-phase":S?"spinning":i?"pose-detecting":C?"starting":"ready",children:[e("span",{onClick:()=>{n(),w()},className:"fixed right-[20px] top-[20px] z-[999]",children:e(ne,{className:"text-[#fff]"})}),e("div",{className:"w-full h-full overflow-hidden ",children:N===le&&e(te,{audio:!1,ref:p,screenshotQuality:1,videoConstraints:x,mirrored:!0,screenshotFormat:"image/jpeg",onUserMedia:a,onUserMediaError:f,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:[u&&e(g,{className:"!w-[180px] !h-[40px] !py-[0] mx-auto ",prefix:y,buttonText:D?.(h.pause),buttonFunc:s,btnSecondary:!0}),o?e("div",{children:e(g,{className:"!w-[180px] !h-[40px] !py-[0] mx-auto",buttonText:D?.(h.restart),buttonFunc:c,btnSecondary:!0})}):i?null:e(g,{"data-testid":"start-scan-btn",className:"!w-[180px] !h-[40px] !py-[0] mx-auto !bg-[#ffffff] !text-[#000000] "+(r?"!opacity-50":""),buttonText:D?.(h.startScan),buttonFunc:l,disabled:r})]}),e("audio",{id:"audioElement",crossOrigin:"anonymous",preload:"auto",style:{position:"absolute",zIndex:-99999},src:`${v}scanAudioInstructions/silence.mp3`})]})}let he,ge=null,ye=null,ve=null;let we=null;var xe=r.memo(function({setIsScanLocked:t,resetDetector:n,scanID:r,setIsVideoUploaded:c,setScanFailsError:i,setScanStartTime:m,setScanUniqueKey:p,userDetails:f}){const{gender:h,heightInCm:g,email:y,shopDomain:_}=f,$=u(null),U=u(null),j=u(null),[A,P]=a([]),[z,V]=a(!0),[R,B]=a(!1),[q,K]=a(!1),[O,W]=a(!0),[H,J]=a(!1),G=u(null),[Q,Y]=a(""),[X,Z]=a([]),[ee,te]=a(""),[ne,re]=a(!1),[ae,se]=a(!1),[oe,ce]=a(!1),[ie,le]=a([]),[de,ue]=a(!1),me=u(!0),{poseDetector:pe}=function(){const[e,t]=a(0),[n,r]=a(0),[s,c]=a(!1),i=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-DejsYGYM.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 r={runtime:"mediapipe",modelType:"full",solutionPath:"https://cdn.jsdelivr.net/npm/@mediapipe/pose"};try{ye=await ve.createDetector(ve.SupportedModels.BlazePose,r),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&&c(!0)}),()=>{d.current=!1};c(!0)},[]),o(()=>{l.current=e,e>6&&i.current<2&&(r(e=>e+1),t(0))},[e]),o(()=>{i.current=n},[n]),{poseDetector:async(e,n)=>{if(!ye||!d.current||!n?.current?.video)return;const r=n.current.video;if(!(r.readyState<2))try{const n=await ye.estimatePoses(r,{flipHorizontal:!1});if(!n||!n.length)return;const a=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!==i.current||p(a)||t(e=>e+1),1===i.current&&p(a)&&t(e=>e+1),2===i.current&&e()}catch(e){console.error("Pose detection error:",e)}},isLoaded:s,spinPhase:n,resetDetector:()=>{i.current=0,l.current=0,t(0),r(0)},retryLoading:async()=>{ye||ge||(ge=m(),await ge&&d.current&&c(!0))}}}(),xe=u(!0),be=u(!1),Se=u(0),Ce=u(0),Ne=u(!1),De=u(!1),Ie=u(!1),ke=u(()=>{}),Fe=u(()=>{}),Te=u(null),[Ee,Le]=a([]),[Me,_e]=a(0),[$e,Ue]=a(w),{setStartGyro:je,uploadScanFile:Ae,setUploadLoading:Pe,swan:ze,onScanStart:Ve,onCaptureComplete:Re}=d(x),Be=()=>{be.current=!1,clearTimeout(he),G.current&&clearTimeout(G.current),p(L()),i(""),Pe?.(!1),P([]),j.current=null,V(!0),B(!1),K(!1),W(!0),J(!1),G.current=null,Y(""),Z([]),te(""),re(!ne),je(!1),S.stopAudio(),se(!1),ce(!1),Se.current=0,Ce.current=0,Ne.current=!1,Ie.current=!1,null!==U.current&&U.current.stop(),ie.forEach(e=>{U.current&&U.current.removeEventListener("dataavailable",e)}),le([]),me.current=!0,ue(!1),c(!1),$.current?.stream&&V(!1)},qe=s(()=>{setTimeout(()=>{V(!1)},1e3)},[]),Ke=s(e=>{if(console.log("camera error",e),$e===w)return Ue(b),void _e(e=>e+1);V(!1)},[$e]),Oe=s(()=>{me.current=!1,ce(!0),ue(!1),G.current&&clearTimeout(G.current),U.current&&U.current.pause(),S.stopAudio(),ze.poseDetection.disconnect(),Se.current=0,Ce.current=0,Ne.current=!1,Ie.current=!1,U.current&&U.current.stop(),ie.forEach(e=>{U.current&&U.current.removeEventListener("dataavailable",e)}),le([]),clearTimeout(he)},[U,ie,S,me]),We=l(()=>C(),[]),He=N(Ee),Je=D(He),Ge=s(async()=>{me.current=!0,await S.playAudio(`${v}SpotOn.mp3`),ce(!1),ue(!1),G.current&&clearTimeout(G.current),B(!1)},[G,S]),Qe=s(async()=>{if(!De.current&&!Te.current){De.current=!0;try{Te.current=await ze.poseDetection.connect(),I.capture(`${_}/pose_detection_connected`,{scanID:r,email:y,id:Te.current})}catch(e){console.log(e,"while connecting websocket")}finally{De.current=!1}}},[r,_,y]),Ye=s(async()=>{k({eventName:`${_}/rescan`,email:y,scanID:r,height:g,gender:h,status:!1}),me.current=!1,ze.poseDetection.disconnect(),Te.current=null,Be(),await Qe(),Fe.current()},[Qe,r,y]),Xe=s(({data:e})=>{e&&e.size>0&&me.current&&(P(t=>t.concat(e)),!be.current&&$.current&&(be.current=!0,pe(()=>{Ge(),F({eventName:`${_}/tensorFlow`,scanID:r,email:y,message:"recording stopped by tensorflow "})},$)))},[Ge,F,_,r,y,$]),Ze=s(async()=>{const e=X[X.length-1];e&&me.current&&(await S.playAudio(v+e),me.current&&(he=setTimeout(Ze,2e3)))},[X,me]),et=s(()=>{U&&U.current&&U.current.stop(),B(!0);try{if($&&$.current&&$.current.stream){const e=$.current.stream.getVideoTracks()[0];if(e){const t=e.getSettings();j.current=t.frameRate||null}const t={videoBitsPerSecond:15e5};Ee[0]&&(t.mimeType=Ee[0]),U.current=new MediaRecorder($.current.stream,t),U.current.addEventListener("dataavailable",Xe),U.current.addEventListener("stop",()=>{W(!0)}),le([...ie,Xe]),U.current.start(1e3),W(!1)}}catch(e){console.log("error while using media recorder",e)}},[$,Ee,Xe,ie]),tt=s(async()=>{G.current&&clearTimeout(G.current),et(),me.current&&(G.current=setTimeout(async()=>{me.current&&(await S.playAudio(`${v}SpotOn.mp3`),B(!1))},15e3)),K(!0),me.current&&await S.playAudio(`${v}Spin.mp3`)},[et,me,S]);o(()=>{ke.current=tt},[tt]);const nt=s(({data:e})=>{const t=ze.poseDetection.connected();e.size>0&&t&&(Ne.current||(Ne.current=!0,ze.poseDetection.poseStatus(async e=>{if(e&&e.audio&&e.audio.length>0){const t=document.querySelector("#audioElement");I.capture(`${_}/pose_instruction_received`,{scanID:r,email:y,audio:e.audio,status:e.status,sid:e.sid,counter:Se.current,consecutiveFalse:Ce.current,type:"body_scan_instruction"}),!0===e.status&&e.sid===Te.current?(Ce.current=0,Se.current<2?(Se.current+=1,1!==Se.current||Ie.current?2===Se.current&&t?.paused&&S.playAudio(v+e.audio):(Ie.current=!0,S.stopAudio(),await S.playAudio(v+e.audio))):(te(e.audio),clearTimeout(he),ze.poseDetection.disconnect(),Ne.current=!1,setTimeout(()=>ke.current(),1e3))):(Ce.current+=1,Ce.current>=3&&(Se.current=0,Ie.current=!1),!t?.paused||we&&we?.audioName===e.audio?we?.audioName===e.audio&&t?.paused&&(we&&we.no_of_times_skipped>=we.skipCount?(we.no_of_times_skipped=0,S.playAudio(v+e.audio)):we&&(we.no_of_times_skipped+=1)):(we={skipCount:2,no_of_times_skipped:0,audioName:e.audio},S.playAudio(v+e.audio)))}})),$?.current&&null!==$.current.getScreenshot()&&ze.poseDetection.videoEmit({image:$.current.getScreenshot()||"",scanId:r}))},[$,r,ze,S,_,y]),rt=s(async()=>{J(!0),je(!0),Ve?.(),xe.current&&(xe.current=!1,F({eventName:"scan started",scanID:r,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),B(!0),se(!0),ue(!0),qe());try{if($&&$.current&&$.current.stream&&me.current){const e=$.current.stream.getVideoTracks()[0];if(e){const t=e.getSettings();j.current=t.frameRate||null}const t={videoBitsPerSecond:15e5};Ee[0]&&(t.mimeType=Ee[0]),me.current&&(U.current=new MediaRecorder($.current.stream,t)),me.current&&U.current&&U.current.addEventListener("dataavailable",nt),le([...ie,nt]),U.current&&U.current.start(1e3),W(!1),me.current&&(he=setTimeout(Ze,2e3))}}catch(e){console.log("error ----------",e)}},[$,Ee,nt,ie,Ze,me,Ve]);return o(()=>(_&&(t(!0),Qe()),()=>{const e=Te.current;Te.current=null,e&&(ze.poseDetection.disconnect(),I.capture(`${_}/pose_detection_disconnected`,{scanID:r,email:y,id:e})),ie.forEach(e=>{U?.current?.removeEventListener("dataavailable",e)})}),[_]),o(()=>{X.push(Q)},[Q]),o(()=>{Z([])},[ee]),o(()=>{const e=A.length&&A.length>0;O||!e||R||!me.current||oe||U&&U.current&&(R||U.current.stop())},[O,R,A,oe]),o(()=>{const e=A.length&&A.length>0;if(O&&e&&!R&&U&&U.current&&me.current&&!oe&&!R){const e=new File(A,`${r}.${Je}`,{type:He});Re?.(),Pe?.(!0),i(""),Ae?.(e,j.current)}},[O,R,A,oe,U,me]),o(()=>{Fe.current=rt},[rt]),o(()=>{const e=E(We,M);Le(e)},[We]),o(()=>{Be()},[]),e(fe,{resetDetector:n,resetScan:Be,loadingCam:z,onPause:Oe,showRestart:ae,pause:oe,onReScan:Ye,recordingStarted:R,isScanning:H,startSendingVideoFrames:rt,faceDone:q,stopRecording:Ge,showPause:de,webcamRef:$,onUserMedia:qe,onUserMediaError:Ke,videoConstraints:$e,webcamKey:Me})});function be({scanID:t,userDetails:n,setIsVideoUploaded:r,setScanFailsError:s,setScanStartTime:c,setScanUniqueKey:i}){const[l,d]=a(90),[m,p]=a(0),[f,h]=a(null),[g,y]=a(!1),[v,w]=a(0),x=u([]),[b,S]=a(!1),C=l-m,N=C>=80&&C<=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(x.current=[...x.current.slice(-4),C],x.current.length>=5){const e=Math.max(...x.current)-Math.min(...x.current);w(N&&e<2?e=>Math.min(100,e+10):e=>Math.max(0,e-20))}N||null===f&&!g||I()},[C,N,f,g]),o(()=>{v>=100&&null===f&&!g&&D(),v<50&&null!==f&&I()},[v,f,g]);const D=()=>{h(3);const e=setInterval(()=>{h(t=>null===t||t<=1?(clearInterval(e),y(!0),null):t-1)},1e3)},I=()=>{h(null),b||y(!1)};return e(pe,{angle:C,countdown:f,isScanning:g,isInTargetRange:N,stabilityScore:v,children:g&&e(xe,{setIsScanLocked:S,resetDetector:()=>{d(90),p(0),h(null),y(!1),w(0),S(!1),x.current=[]},scanID:t,userDetails:n,setIsVideoUploaded:r,setScanFailsError:s,setScanStartTime:c,setScanUniqueKey:i})})}function Se({setShowDrawer:t,config:n,loader:r}){const[c,i]=a({disabled:!1,message:""}),[l,d]=a(!0),m=u(null),p=s(async()=>{const e=await _();i(e),d(!1)},[]);return o(()=>{p()},[]),l?e($,{url:r,loaderType:"black"}):c?.disabled?e(U,{config:n,message:c?.message}):e(te,{audio:!1,ref:m,screenshotQuality:1,videoConstraints:j,mirrored:!0,onUserMedia:()=>t?.(!0),screenshotFormat:"image/jpeg",style:{position:"relative",top:0,bottom:0,zIndex:0,width:"100%",height:"100%",objectFit:"cover"}})}function Ce({link:t,onReady:n,wrapperClassName:r="[&_video]:rounded-t-[20px] w-full h-full"}){const a=u(null),s=u(null);let c={autoplay:!0,controls:!1,responsive:!0,fluid:!0,muted:!0,navigationUI:"hide",preload:"metadata",poster:A};return o(()=>{if(!s.current&&t&&a?.current){const e=oe(a.current,{...c});e.ready(()=>{s.current=e;const r={...c,sources:[{src:t,type:"application/x-mpegURL"}]};e.autoplay(r.autoplay),e.src(r.sources),n?.(e)})}},[t,a]),o(()=>{const e=s.current;return()=>{e&&!e.isDisposed()&&(e.dispose(),s.current=null)}},[s]),e("div",{className:r,children:e("video",{ref:a,muted:!0,className:"video-js",playsInline:!0,onDrag:e=>e.preventDefault()})})}function Ne({scanFailsError:r,onNext:s,gender:o,setScanUniqueKey:c,setIsVideoUploaded:i}){const{translate:l}=d(m)||{},u=p(),[y,v]=a(!1),w=()=>{v(!y)};return t(n,{children:[t("div",{"data-testid":"scan-error-message",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:r&&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:P(r)}),e("img",{className:"my-[0.5rem] aspect-[2/1.4] w-full object-cover",onClick:w,src:z[o],alt:"icon"})]})}),r&&e("div",{className:"p-[1rem] flex gap-[0.5rem]",children:e(g,{"data-testid":"scan-again-btn",disabled:!1,buttonText:l?.(h.scanAgain),className:"!shadow-none",buttonFunc:()=>{s?s?.():c?.(L()),i?.(!1)}})})]}),y&&t(re,{className:"w-screen h-screen video-modal",onClose:w,open:y,children:[e("div",{className:"flex justifyEnd ",children:e("span",{className:"closeBtn",onClick:w,children:e(ne,{className:"absolute right-[8px] top-[8px] text-white z-[9]"})})}),e("div",{className:"aspect-video object-cover rounded-[20px] ",children:e(Ce,{link:o?V[o].PRE_LINK:V.male.PRE_LINK,wrapperClassName:"w-screen h-screen fixed top-[0] left-[0]"})})]})]})}function De({scanId:n,userDetails:r,config:c,isVideoUploadedCorrect:i,isMeasurementAvailable:l,onComplete:u,isSuccess:p,onCustomScanSuccess:y,swan:v}){const{gender:w,shopDomain:x,heightInCm:b,deviceFocalLength:S,userName:C,email:N,scanType:D}=r||{},k=[K,O,W].includes(D??""),[F,T]=a(!0),E=s(async()=>{try{k&&(await(v?.auth.addUser({scanId:n,email:N,name:C,gender:w,height:b})),y?.()),I.capture(x??"",{scanID:n,email:N,height:b,focalLength:S,clothesFit:"0",gender:w})}catch(e){console.log(e)}},[k]),{translate:L}=d(m)||{};o(()=>{(i||l)&&E()},[i,l]);const M=p||i||l;return e(ae,{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(Se,{loader:c?.loader,setShowDrawer:T}),e(se,{open:F,onClose:(e,t)=>{},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:c?.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?R:B,type:"video/mp4"})})}),M&&e(g,{className:"!w-[180px] mx-auto",buttonText:L?.(h.next),buttonFunc:()=>{u?.()}})]})})})]})})}const Ie=()=>{const{userDetails:n,onRetry:r,isError:a,isSuccess:s,gender:o,scanUniqueKey:c,scanFailsError:i,setScanUniqueKey:l,setIsVideoUploaded:u,isMeasurementAvailable:m,isVideoUploadedCorrect:f,loading:h,showDeniedModal:g,uploadLoading:y,setScanFailsError:v,setScanStartTime:w,resetScan:b,onCustomScanSuccess:S,swan:C,onComplete:N}=d(x),D=p();return a?t("div",{"data-scan-state":"error",children:[e(Se,{}),e(se,{anchor:"bottom",open:!0,className:"camera-drawer",onClose:(e,t)=>{},children:e(Ne,{scanFailsError:!0,onNext:r,gender:o})})]}):s?e("div",{"data-scan-state":"success",children:e(De,{isSuccess:!0,onComplete:N})}):h?e("div",{"data-scan-state":"loading",className:"flex top-0 !mt-0 left-0 z-[999] absolute justify-center items-center w-full h-full",style:{background:D?.style?.base?.backgroundColor},children:e($,{url:D?.loader,loaderType:"black"})}):g.disabled?e("div",{"data-scan-state":"camera-denied",children:e(U,{})}):y||i||m||f?(y||m||f)&&!i?e("div",{"data-scan-state":"processing",children:e(De,{scanId:c,isMeasurementAvailable:m,userDetails:n,isVideoUploadedCorrect:f,onCustomScanSuccess:S,swan:C,onComplete:N})}):t("div",{"data-scan-state":"error-retry",children:[e(Se,{}),e(se,{anchor:"bottom",open:!0,className:"camera-drawer",onClose:(e,t)=>{},children:e(Ne,{scanFailsError:i,onNext:()=>{r?.(),b()},setScanUniqueKey:l,gender:o,setIsVideoUploaded:u})})]}):e("div",{"data-scan-state":"scanning",children:e(be,{scanID:c,userDetails:n,setIsVideoUploaded:u,setScanFailsError:v,setScanStartTime:w,setScanUniqueKey:l})})},ke=t=>{const{config:n,onRetry:r,onScanStart:c,onCaptureComplete:i,onUploadStart:d,onUploadEnd:u,onMeasurementSocketStart:m,onMeasurementSocketClose:p,onIntermediateScanSuccess:f,onScanError:h,onScanSuccess:g,onCustomScanSuccess:y,onComplete:v,isError:w,isSuccess:b}=t,S={email:"",shopDomain:"",gender:"male",heightInCm:0,scanType:"",deviceFocalLength:0,deviceModelName:"",sourceTag:"",callbackUrl:null,...t.userDetails??{}},C=t.token??"",{gender:N,scanType:D,shopDomain:I,heightInCm:k,email:E,deviceFocalLength:M,deviceModelName:$,callbackUrl:U,sourceTag:j}=S,A=l(()=>H(C),[C]),[z,V]=a(!1),[R,B]=a(!1),[q,K]=a(!1),[O,W]=a({disabled:!1,message:""}),[ee,te]=a(""),[ne,re]=a(!1),[ae,se]=a(!0),[oe,ce]=a(!1),[ie,le]=a(""),[de,me]=a(T()),{gyroData:pe}=function(e){const[t,n]=a([]),[r,c]=a(!1),i=s(e=>{try{const{alpha:t,beta:r,gamma:a}=e;n(e=>[...e,{alpha:t?.toString()||void 0,beta:r?.toString()||void 0,gamma:a?.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()?c(!0):console.warn("Device orientation permission denied.")}catch(e){console.error("Error requesting device orientation permission:",e)}else c(!0)},[]);return o(()=>(e&&r?window.addEventListener("deviceorientation",i):n([]),()=>{window.removeEventListener("deviceorientation",i)}),[e,r,i]),o(()=>{e&&l()},[e,l]),{gyroData:t}}(oe);J();const fe=s(()=>{le(L()),te(""),V(!1),re(!1)},[]),he=()=>{me(null),le("")},ge=s(async e=>{if(e&&"success"===e?.scanStatus&&"intermediate"===e?.resultType&&200===e?.code)return F({eventName:`${I}/measurement_success/intermediate`,scanID:ie,status:"success",email:E}),B(!0),void f?.(e);g?.(e),B(!0),he();const t=ie;K(!0),F({eventName:`${I}/measurement_success/fit-view`,scanID:t,status:"success",email:E}),de&&F({eventName:`${I}/scan_completion_time`,scanID:t,status:"success",completionTime:T()-de,email:E})},[D,I,ie]),ye=e=>{K(!1),te(""),B(!1),A.measurement.handleMeasurementSocket({scanId:ie,onPreopen:()=>{Z({eventName:`${I}/webSocket`,scanID:ie,connection:"pre_open",type:"measurement_recommendation",email:E})},onOpen:()=>{m?.(),Z({eventName:`${I}/webSocket`,scanID:ie,connection:"open",type:"measurement_recommendation",email:E})},onClose:()=>{p?.(),Z({eventName:`${I}/webSocket`,scanID:ie,connection:"close",type:"measurement_recommendation",email:E})},onError:e=>{var t;t=e,h?.({...t,message:P(t)}),he(),K(!1),te(t),B(!1),F({eventName:`${I}/measurement_failed/fit-view`,scanID:ie,status:"failed",email:E,message:P(t)}),de&&F({eventName:`${I}/scan_completion_time`,scanID:ie,status:"failed",completionTime:T()-de,email:E}),Z({eventName:`${I}/webSocket`,scanID:ie,connection:"error",type:"measurement_recommendation",email:E})},onSuccess:e=>{Z({eventName:`${I}/webSocket`,scanID:ie,connection:"success",type:"measurement_recommendation",email:E}),ge(e)}})},ve=s(async(e,t)=>{const n=Number((e.size/1048576).toFixed(2)),r=null!=t?t:await G(e),a=Q({gender:N,focal_length:`${M}`,height:`${k}`,customer_store_url:I,clothes_fit:"0",scan_type:D,callback_url:U,source_tag:j});F({eventName:`${I}/body_scan_meta_data`,scanID:ie,email:E,data:JSON.stringify([...a,{fileSizeInMB:n,video_fps:r||0}])}),d?.();try{await A.fileUpload.uploadFileFrontend({file:e,arrayMetaData:a,scanId:ie,email:E}),await A.fileUpload.setDeviceInfo({model:$,detection:"manual",gyro:pe,scanId:ie}),console.log("video successfully uploaded"),re(!1),F({eventName:`${I}/scan_success`,scanID:ie,status:"success",email:E,data:JSON.stringify(a)}),F({eventName:"scan finished",scanID:ie,status:"success",email:E}),me(T()),setTimeout(()=>{re(!0)},3e3)}catch(e){F({eventName:"scan finished",scanID:ie,status:"failed",email:E,message:P(e)}),F({eventName:`${I}/scan_failed`,scanID:ie,status:"failed",email:E,message:P(e),data:JSON.stringify(a)}),te(P(e)),re(!1),h?.({...e,message:P(e)}),he()}finally{ce(!1),u?.()}},[ie,pe,d,u]),we=s(async()=>{if(+k<152.4||+k>213.36)return void h?.({message:"Height must be between 152.4cm (5ft) and 213.36cm (7ft)"});const e=await _();e.disabled?(F({eventName:`${I}/camera_activation`,scanID:ie,status:"failed",email:E}),se(!1)):(se(!1),F({eventName:`${I}/camera_activation`,scanID:ie,status:"success",email:E})),W(e),te(""),re(!1)},[E,ie,le,I]);return o(()=>{w||b||I&&we()},[I,k,w,b]),o(()=>{w||b||ne&&I&&ie&&ye()},[ne,I,ie,w,b]),e("div",{"data-testid":"body-scan-root",children:e(Y,{children:e(X,{config:n,children:e(ue,{children:e(x.Provider,{value:{userDetails:S,onRetry:r,onScanError:h,isError:w,isSuccess:b,onScanSuccess:g,gender:N,scanUniqueKey:ie,scanFailsError:ee,setScanUniqueKey:le,setIsVideoUploaded:re,isMeasurementAvailable:q,isVideoUploadedCorrect:R,loading:ae,showDeniedModal:O,uploadLoading:z,setStartGyro:ce,uploadScanFile:ve,setUploadLoading:V,resetScan:fe,setScanFailsError:te,setScanStartTime:me,onScanStart:c,onCaptureComplete:i,onCustomScanSuccess:y,onComplete:v,swan:A},children:e(Ie,{})})})})})})};export{ke as B};
|
|
2
|
+
//# sourceMappingURL=BodyScan-B0qqqK3C.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var e=require("react/jsx-runtime"),t=require("react"),s=require("./Modal-DnweWp6L.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 p=t.useMemo(()=>({size:n,setSize:a,clearInputs:r,setClearInputs:o,media:m}),[n,r,m]);return e.jsx(d.Provider,{value:p,children:s})}var p=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 f=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]),f=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,[]),v=t.useCallback((e=!1)=>{const t=m();return o?d?.style?.angleDetector?.successAngleTextLightColor:x(e,t)},[o,m]),S=r;function y(){document.documentElement.style.setProperty("--real-vh",window.innerHeight+"px")}return y(),window.addEventListener("resize",y),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:f},"data-testid":"level-screen","data-angle-state":o?"locked":c?"target":"adjusting",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 ${v()}`},children:e.jsx("div",{className:`text-[3rem] font-bold text-[${v()}]`,style:{fontFamily:d?.style?.base?.baseFontFamily||"Inter, sans-serif",color:v()},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 ${v()}`},children:[e.jsx("div",{className:`h-[1rem] w-[1rem] rounded-[9999px] bg-[${v()}]/80`,style:{backgroundColor:`${v()}B3`}}),e.jsxs("div",{className:n("mt-[.5rem] text-center w-[180px] flex-col flex items-center absolute top-[60px]",g()),style:{color:v()},children:[e.jsx(p,{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:v()},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-[${v()}]/20 rounded-[9999px] overflow-hidden`,style:{backgroundColor:`${v()}33`},children:e.jsx("div",{className:`h-full bg-[${v()}]/70 transition-all duration-300 rounded-[9999px]`,style:{width:`${a}%`,backgroundColor:`${v()}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:v()},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:v()},children:u?.(s.LanguageKeys.placePhoneUpright)})})]})});function h({resetScan:n,loadingCam:o,onUserMedia:c,onPause:i,pause:l,onReScan:m,recordingStarted:p,startSendingVideoFrames:f,showPause:h,webcamRef:g,onUserMediaError:x,resetDetector:v,videoConstraints:S,webcamKey:y,faceDone:C,isScanning:b}){const{media:w}=t.useContext(d)||{},{translate:j}=t.useContext(s.LanguageContext)||{};return e.jsxs("div",{className:"App w-screen h-[100vh] relative common-ui-main",style:{background:"#000"},"data-testid":"camera-scan","data-scan-phase":C?"spinning":p?"pose-detecting":b?"starting":"ready",children:[e.jsx("span",{onClick:()=>{n(),v()},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:w===u&&e.jsx(a,{audio:!1,ref:g,screenshotQuality:1,videoConstraints:S,mirrored:!0,screenshotFormat:"image/jpeg",onUserMedia:c,onUserMediaError:x,style:{position:"fixed",top:0,left:0,width:"100%",height:"100%",objectFit:"cover",zIndex:0}},y)}),e.jsxs("div",{className:"fixed bottom-[30px] w-full z-[999] flex flex-col gap-4 items-center justify-center",children:[h&&e.jsx(s.SpecificButton,{className:"!w-[180px] !h-[40px] !py-[0] mx-auto ",prefix:s.pauseIcon,buttonText:j?.(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:j?.(s.LanguageKeys.restart),buttonFunc:m,btnSecondary:!0})}):p?null:e.jsx(s.SpecificButton,{"data-testid":"start-scan-btn",className:"!w-[180px] !h-[40px] !py-[0] mx-auto !bg-[#ffffff] !text-[#000000] "+(o?"!opacity-50":""),buttonText:j?.(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,x=null,v=null,S=null;let y=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:p,shopDomain:f}=u,C=t.useRef(null),b=t.useRef(null),w=t.useRef(null),[j,k]=t.useState([]),[E,N]=t.useState(!0),[D,T]=t.useState(!1),[I,L]=t.useState(!1),[M,F]=t.useState(!0),[_,P]=t.useState(!1),A=t.useRef(null),[R,$]=t.useState(""),[U,O]=t.useState([]),[z,K]=t.useState(""),[q,B]=t.useState(!1),[V,W]=t.useState(!1),[H,G]=t.useState(!1),[J,Q]=t.useState([]),[X,Y]=t.useState(!1),Z=t.useRef(!0),{poseDetector:ee}=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-Bc8T4UAD.js")}),import("@tensorflow/tfjs-core"),import("@tensorflow/tfjs-backend-webgl")]);S=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{v=await S.createDetector(S.SupportedModels.BlazePose,n),console.log("MediaPipe detector created successfully")}catch(e){console.warn("MediaPipe failed, falling back to TFJS runtime:",e),v=await S.createDetector(S.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),x=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,!v)return x||(x=u()),x.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(!v||!l.current||!t?.current?.video)return;const n=t.current.video;if(!(n.readyState<2))try{const t=await v.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()=>{v||x||(x=u(),await x&&l.current&&o(!0))}}}(),te=t.useRef(!0),se=t.useRef(!1),ne=t.useRef(0),ae=t.useRef(0),re=t.useRef(!1),oe=t.useRef(!1),ce=t.useRef(!1),ie=t.useRef(()=>{}),le=t.useRef(()=>{}),ue=t.useRef(null),[de,me]=t.useState([]),[pe,fe]=t.useState(0),[he,ge]=t.useState(s.videoConstraintsExact),{setStartGyro:xe,uploadScanFile:ve,setUploadLoading:Se,swan:ye,onScanStart:Ce,onCaptureComplete:be}=t.useContext(s.ParamsContext),we=()=>{se.current=!1,clearTimeout(g),A.current&&clearTimeout(A.current),l(s.generateUuid()),c(""),Se?.(!1),k([]),w.current=null,N(!0),T(!1),L(!1),F(!0),P(!1),A.current=null,$(""),O([]),K(""),B(!q),xe(!1),s.speechService.stopAudio(),W(!1),G(!1),ne.current=0,ae.current=0,re.current=!1,ce.current=!1,null!==b.current&&b.current.stop(),J.forEach(e=>{b.current&&b.current.removeEventListener("dataavailable",e)}),Q([]),Z.current=!0,Y(!1),o(!1),C.current?.stream&&N(!1)},je=t.useCallback(()=>{setTimeout(()=>{N(!1)},1e3)},[]),ke=t.useCallback(e=>{if(console.log("camera error",e),he===s.videoConstraintsExact)return ge(s.videoConstraintsFallback),void fe(e=>e+1);N(!1)},[he]),Ee=t.useCallback(()=>{Z.current=!1,G(!0),Y(!1),A.current&&clearTimeout(A.current),b.current&&b.current.pause(),s.speechService.stopAudio(),ye.poseDetection.disconnect(),ne.current=0,ae.current=0,re.current=!1,ce.current=!1,b.current&&b.current.stop(),J.forEach(e=>{b.current&&b.current.removeEventListener("dataavailable",e)}),Q([]),clearTimeout(g)},[b,J,s.speechService,Z]),Ne=t.useMemo(()=>s.getPreferredMediaRecorderTypes(),[]),De=s.getRecordingMimeType(de),Te=s.getRecordingExtension(De),Ie=t.useCallback(async()=>{Z.current=!0,await s.speechService.playAudio(`${s.voiceOverAssetsPath}SpotOn.mp3`),G(!1),Y(!1),A.current&&clearTimeout(A.current),T(!1)},[A,s.speechService]),Le=t.useCallback(async()=>{if(!oe.current&&!ue.current){oe.current=!0;try{ue.current=await ye.poseDetection.connect(),s.posthog.capture(`${f}/pose_detection_connected`,{scanID:r,email:p,id:ue.current})}catch(e){console.log(e,"while connecting websocket")}finally{oe.current=!1}}},[r,f,p]),Me=t.useCallback(async()=>{s.rescanSupportCaptureEvent({eventName:`${f}/rescan`,email:p,scanID:r,height:m,gender:d,status:!1}),Z.current=!1,ye.poseDetection.disconnect(),ue.current=null,we(),await Le(),le.current()},[Le,r,p]),Fe=t.useCallback(({data:e})=>{e&&e.size>0&&Z.current&&(k(t=>t.concat(e)),!se.current&&C.current&&(se.current=!0,ee(()=>{Ie(),s.handleScanTimeCapture({eventName:`${f}/tensorFlow`,scanID:r,email:p,message:"recording stopped by tensorflow "})},C)))},[Ie,s.handleScanTimeCapture,f,r,p,C]),_e=t.useCallback(async()=>{const e=U[U.length-1];e&&Z.current&&(await s.speechService.playAudio(s.voiceOverAssetsPath+e),Z.current&&(g=setTimeout(_e,2e3)))},[U,Z]),Pe=t.useCallback(()=>{b&&b.current&&b.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();w.current=t.frameRate||null}const t={videoBitsPerSecond:15e5};de[0]&&(t.mimeType=de[0]),b.current=new MediaRecorder(C.current.stream,t),b.current.addEventListener("dataavailable",Fe),b.current.addEventListener("stop",()=>{F(!0)}),Q([...J,Fe]),b.current.start(1e3),F(!1)}}catch(e){console.log("error while using media recorder",e)}},[C,de,Fe,J]),Ae=t.useCallback(async()=>{A.current&&clearTimeout(A.current),Pe(),Z.current&&(A.current=setTimeout(async()=>{Z.current&&(await s.speechService.playAudio(`${s.voiceOverAssetsPath}SpotOn.mp3`),T(!1))},15e3)),L(!0),Z.current&&await s.speechService.playAudio(`${s.voiceOverAssetsPath}Spin.mp3`)},[Pe,Z,s.speechService]);t.useEffect(()=>{ie.current=Ae},[Ae]);const Re=t.useCallback(({data:e})=>{const t=ye.poseDetection.connected();e.size>0&&t&&(re.current||(re.current=!0,ye.poseDetection.poseStatus(async e=>{if(e&&e.audio&&e.audio.length>0){const t=document.querySelector("#audioElement");s.posthog.capture(`${f}/pose_instruction_received`,{scanID:r,email:p,audio:e.audio,status:e.status,sid:e.sid,counter:ne.current,consecutiveFalse:ae.current,type:"body_scan_instruction"}),!0===e.status&&e.sid===ue.current?(ae.current=0,ne.current<2?(ne.current+=1,1!==ne.current||ce.current?2===ne.current&&t?.paused&&s.speechService.playAudio(s.voiceOverAssetsPath+e.audio):(ce.current=!0,s.speechService.stopAudio(),await s.speechService.playAudio(s.voiceOverAssetsPath+e.audio))):(K(e.audio),clearTimeout(g),ye.poseDetection.disconnect(),re.current=!1,setTimeout(()=>ie.current(),1e3))):(ae.current+=1,ae.current>=3&&(ne.current=0,ce.current=!1),!t?.paused||y&&y?.audioName===e.audio?y?.audioName===e.audio&&t?.paused&&(y&&y.no_of_times_skipped>=y.skipCount?(y.no_of_times_skipped=0,s.speechService.playAudio(s.voiceOverAssetsPath+e.audio)):y&&(y.no_of_times_skipped+=1)):(y={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,s.speechService,f,p]),$e=t.useCallback(async()=>{P(!0),xe(!0),Ce?.(),te.current&&(te.current=!1,s.handleScanTimeCapture({eventName:"scan started",scanID:r,status:"success",email:p})),i(s.getCurrentTimeInSeconds()),N(!0),Z.current&&await s.speechService.playAudio(`${s.voiceOverAssetsPath}StartScan.mp3`),Z.current&&await s.speechService.playAudio(`${s.voiceOverAssetsPath}LiftArmsAndHoldAtHip.mp3`),Z.current&&(P(!1),T(!0),W(!0),Y(!0),je());try{if(C&&C.current&&C.current.stream&&Z.current){const e=C.current.stream.getVideoTracks()[0];if(e){const t=e.getSettings();w.current=t.frameRate||null}const t={videoBitsPerSecond:15e5};de[0]&&(t.mimeType=de[0]),Z.current&&(b.current=new MediaRecorder(C.current.stream,t)),Z.current&&b.current&&b.current.addEventListener("dataavailable",Re),Q([...J,Re]),b.current&&b.current.start(1e3),F(!1),Z.current&&(g=setTimeout(_e,2e3))}}catch(e){console.log("error ----------",e)}},[C,de,Re,J,_e,Z,Ce]);return t.useEffect(()=>(f&&(n(!0),Le()),()=>{const e=ue.current;ue.current=null,e&&(ye.poseDetection.disconnect(),s.posthog.capture(`${f}/pose_detection_disconnected`,{scanID:r,email:p,id:e})),J.forEach(e=>{b?.current?.removeEventListener("dataavailable",e)})}),[f]),t.useEffect(()=>{U.push(R)},[R]),t.useEffect(()=>{O([])},[z]),t.useEffect(()=>{const e=j.length&&j.length>0;M||!e||D||!Z.current||H||b&&b.current&&(D||b.current.stop())},[M,D,j,H]),t.useEffect(()=>{const e=j.length&&j.length>0;if(M&&e&&!D&&b&&b.current&&Z.current&&!H&&!D){const e=new File(j,`${r}.${Te}`,{type:De});be?.(),Se?.(!0),c(""),ve?.(e,w.current)}},[M,D,j,H,b,Z]),t.useEffect(()=>{le.current=$e},[$e]),t.useEffect(()=>{const e=s.getSupportedMediaRecorderTypes(Ne,s.videoTypes);me(e)},[Ne]),t.useEffect(()=>{we()},[]),e.jsx(h,{resetDetector:a,resetScan:we,loadingCam:E,onPause:Ee,showRestart:V,pause:H,onReScan:Me,recordingStarted:D,isScanning:_,startSendingVideoFrames:$e,faceDone:I,stopRecording:Ie,showPause:X,webcamRef:C,onUserMedia:je,onUserMediaError:ke,videoConstraints:he,webcamKey:pe})});function b({scanID:s,userDetails:n,setIsVideoUploaded:a,setScanFailsError:r,setScanStartTime:o,setScanUniqueKey:c}){const[i,l]=t.useState(90),[u,d]=t.useState(0),[m,p]=t.useState(null),[h,g]=t.useState(!1),[x,v]=t.useState(0),S=t.useRef([]),[y,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);v(j&&e<2?e=>Math.min(100,e+10):e=>Math.max(0,e-20))}j||null===m&&!h||E()},[w,j,m,h]),t.useEffect(()=>{x>=100&&null===m&&!h&&k(),x<50&&null!==m&&E()},[x,m,h]);const k=()=>{p(3);const e=setInterval(()=>{p(t=>null===t||t<=1?(clearInterval(e),g(!0),null):t-1)},1e3)},E=()=>{p(null),y||g(!1)};return e.jsx(f,{angle:w,countdown:m,isScanning:h,isInTargetRange:j,stabilityScore:x,children:h&&e.jsx(C,{setIsScanLocked:b,resetDetector:()=>{l(90),d(0),p(null),g(!1),v(0),b(!1),S.current=[]},scanID:s,userDetails:n,setIsVideoUploaded:a,setScanFailsError:r,setScanStartTime:o,setScanUniqueKey:c})})}function w({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(s.Modal,{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 j({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 k({scanFailsError:n,onNext:a,gender:c,setScanUniqueKey:i,setIsVideoUploaded:l}){const{translate:u}=t.useContext(s.LanguageContext)||{},d=s.useConfig(),[m,p]=t.useState(!1),f=()=>{p(!m)};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{"data-testid":"scan-error-message",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:f,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,{"data-testid":"scan-again-btn",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:f,open:m,children:[e.jsx("div",{className:"flex justifyEnd ",children:e.jsx("span",{className:"closeBtn",onClick:f,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(j,{link:c?s.GENDER[c].PRE_LINK:s.GENDER.male.PRE_LINK,wrapperClassName:"w-screen h-screen fixed top-[0] left-[0]"})})]})]})}function E({scanId:n,userDetails:a,config:r,isVideoUploadedCorrect:c,isMeasurementAvailable:i,onComplete:l,isSuccess:u,onCustomScanSuccess:d,swan:m}){const{gender:p,shopDomain:f,heightInCm:h,deviceFocalLength:g,userName:x,email:v,scanType:S}=a||{},y=[s.CLOTHING_CUSTOM_SCAN,s.CLOTHING_BANNER_SCAN,s.CLOTHING_CUSTOM_FIT_SCAN].includes(S??""),[C,b]=t.useState(!0),j=t.useCallback(async()=>{try{y&&(await(m?.auth.addUser({scanId:n,email:v,name:x,gender:p,height:h})),d?.()),s.posthog.capture(f??"",{scanID:n,email:v,height:h,focalLength:g,clothesFit:"0",gender:p})}catch(e){console.log(e)}},[y]),{translate:k}=t.useContext(s.LanguageContext)||{};t.useEffect(()=>{(c||i)&&j()},[c,i]);const E=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(w,{loader:r?.loader,setShowDrawer:b}),e.jsx(o.Drawer,{open:C,onClose:(e,t)=>{},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:k?.(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:p===s.GenderType.Male?s.maleMeasurementProgress:s.measurementProgress,type:"video/mp4"})})}),E&&e.jsx(s.SpecificButton,{className:"!w-[180px] mx-auto",buttonText:k?.(s.LanguageKeys.next),buttonFunc:()=>{l?.()}})]})})})]})})}const N=()=>{const{userDetails:n,onRetry:a,isError:r,isSuccess:c,gender:i,scanUniqueKey:l,scanFailsError:u,setScanUniqueKey:d,setIsVideoUploaded:m,isMeasurementAvailable:p,isVideoUploadedCorrect:f,loading:h,showDeniedModal:g,uploadLoading:x,setScanFailsError:v,setScanStartTime:S,resetScan:y,onCustomScanSuccess:C,swan:j,onComplete:N}=t.useContext(s.ParamsContext),D=s.useConfig();return r?e.jsxs("div",{"data-scan-state":"error",children:[e.jsx(w,{}),e.jsx(o.Drawer,{anchor:"bottom",open:!0,className:"camera-drawer",onClose:(e,t)=>{},children:e.jsx(k,{scanFailsError:!0,onNext:a,gender:i})})]}):c?e.jsx("div",{"data-scan-state":"success",children:e.jsx(E,{isSuccess:!0,onComplete:N})}):h?e.jsx("div",{"data-scan-state":"loading",className:"flex top-0 !mt-0 left-0 z-[999] absolute justify-center items-center w-full h-full",style:{background:D?.style?.base?.backgroundColor},children:e.jsx(s.LoadingScreen,{url:D?.loader,loaderType:"black"})}):g.disabled?e.jsx("div",{"data-scan-state":"camera-denied",children:e.jsx(s.Modal,{})}):x||u||p||f?(x||p||f)&&!u?e.jsx("div",{"data-scan-state":"processing",children:e.jsx(E,{scanId:l,isMeasurementAvailable:p,userDetails:n,isVideoUploadedCorrect:f,onCustomScanSuccess:C,swan:j,onComplete:N})}):e.jsxs("div",{"data-scan-state":"error-retry",children:[e.jsx(w,{}),e.jsx(o.Drawer,{anchor:"bottom",open:!0,className:"camera-drawer",onClose:(e,t)=>{},children:e.jsx(k,{scanFailsError:u,onNext:()=>{a?.(),y()},setScanUniqueKey:d,gender:i,setIsVideoUploaded:m})})]}):e.jsx("div",{"data-scan-state":"scanning",children:e.jsx(b,{scanID:l,userDetails:n,setIsVideoUploaded:m,setScanFailsError:v,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:p,onScanError:f,onScanSuccess:h,onCustomScanSuccess:g,onComplete:x,isError:v,isSuccess:S}=n,y={email:"",shopDomain:"",gender:"male",heightInCm:0,scanType:"",deviceFocalLength:0,deviceModelName:"",sourceTag:"",callbackUrl:null,...n.userDetails??{}},C=n.token??"",{gender:b,scanType:w,shopDomain:j,heightInCm:k,email:E,deviceFocalLength:D,deviceModelName:T,callbackUrl:I,sourceTag:L}=y,M=t.useMemo(()=>s.getSwanService(C),[C]),[F,_]=t.useState(!1),[P,A]=t.useState(!1),[R,$]=t.useState(!1),[U,O]=t.useState({disabled:!1,message:""}),[z,K]=t.useState(""),[q,B]=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(""),_(!1),B(!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:E}),A(!0),void p?.(e);h?.(e),A(!0),te();const t=J;$(!0),s.handleScanTimeCapture({eventName:`${j}/measurement_success/fit-view`,scanID:t,status:"success",email:E}),X&&s.handleScanTimeCapture({eventName:`${j}/scan_completion_time`,scanID:t,status:"success",completionTime:s.getCurrentTimeInSeconds()-X,email:E})},[w,j,J]),ne=e=>{$(!1),K(""),A(!1),M.measurement.handleMeasurementSocket({scanId:J,onPreopen:()=>{s.handleWebSocketCapture({eventName:`${j}/webSocket`,scanID:J,connection:"pre_open",type:"measurement_recommendation",email:E})},onOpen:()=>{u?.(),s.handleWebSocketCapture({eventName:`${j}/webSocket`,scanID:J,connection:"open",type:"measurement_recommendation",email:E})},onClose:()=>{d?.(),s.handleWebSocketCapture({eventName:`${j}/webSocket`,scanID:J,connection:"close",type:"measurement_recommendation",email:E})},onError:e=>{var t;t=e,f?.({...t,message:s.handleErrorMessage(t)}),te(),$(!1),K(t),A(!1),s.handleScanTimeCapture({eventName:`${j}/measurement_failed/fit-view`,scanID:J,status:"failed",email:E,message:s.handleErrorMessage(t)}),X&&s.handleScanTimeCapture({eventName:`${j}/scan_completion_time`,scanID:J,status:"failed",completionTime:s.getCurrentTimeInSeconds()-X,email:E}),s.handleWebSocketCapture({eventName:`${j}/webSocket`,scanID:J,connection:"error",type:"measurement_recommendation",email:E})},onSuccess:e=>{s.handleWebSocketCapture({eventName:`${j}/webSocket`,scanID:J,connection:"success",type:"measurement_recommendation",email:E}),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:b,focal_length:`${D}`,height:`${k}`,customer_store_url:j,clothes_fit:"0",scan_type:w,callback_url:I,source_tag:L});s.handleScanTimeCapture({eventName:`${j}/body_scan_meta_data`,scanID:J,email:E,data:JSON.stringify([...r,{fileSizeInMB:n,video_fps:a||0}])}),i?.();try{await M.fileUpload.uploadFileFrontend({file:e,arrayMetaData:r,scanId:J,email:E}),await M.fileUpload.setDeviceInfo({model:T,detection:"manual",gyro:Z,scanId:J}),console.log("video successfully uploaded"),B(!1),s.handleScanTimeCapture({eventName:`${j}/scan_success`,scanID:J,status:"success",email:E,data:JSON.stringify(r)}),s.handleScanTimeCapture({eventName:"scan finished",scanID:J,status:"success",email:E}),Y(s.getCurrentTimeInSeconds()),setTimeout(()=>{B(!0)},3e3)}catch(e){s.handleScanTimeCapture({eventName:"scan finished",scanID:J,status:"failed",email:E,message:s.handleErrorMessage(e)}),s.handleScanTimeCapture({eventName:`${j}/scan_failed`,scanID:J,status:"failed",email:E,message:s.handleErrorMessage(e),data:JSON.stringify(r)}),K(s.handleErrorMessage(e)),B(!1),f?.({...e,message:s.handleErrorMessage(e)}),te()}finally{G(!1),l?.()}},[J,Z,i,l]),re=t.useCallback(async()=>{if(+k<152.4||+k>213.36)return void f?.({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:E}),W(!1)):(W(!1),s.handleScanTimeCapture({eventName:`${j}/camera_activation`,scanID:J,status:"success",email:E})),O(e),K(""),B(!1)},[E,J,Q,j]);return t.useEffect(()=>{v||S||j&&re()},[j,k,v,S]),t.useEffect(()=>{v||S||q&&j&&J&&ne()},[q,j,J,v,S]),e.jsx("div",{"data-testid":"body-scan-root",children:e.jsx(s.LanguageContextProvider,{children:e.jsx(s.ConfigProvider,{config:a,children:e.jsx(m,{children:e.jsx(s.ParamsContext.Provider,{value:{userDetails:y,onRetry:r,onScanError:f,isError:v,isSuccess:S,onScanSuccess:h,gender:b,scanUniqueKey:J,scanFailsError:z,setScanUniqueKey:Q,setIsVideoUploaded:B,isMeasurementAvailable:R,isVideoUploadedCorrect:P,loading:V,showDeniedModal:U,uploadLoading:F,setStartGyro:G,uploadScanFile:ae,setUploadLoading:_,resetScan:ee,setScanFailsError:K,setScanStartTime:Y,onScanStart:o,onCaptureComplete:c,onCustomScanSuccess:g,onComplete:x,swan:M},children:e.jsx(N,{})})})})})})};
|
|
2
|
+
//# sourceMappingURL=BodyScan-B87W6dpH.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{jsx as e,jsxs as t,Fragment as n}from"react/jsx-runtime";import r,{useState as a,useCallback as s,useEffect as o,createContext as c,useLayoutEffect as i,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,B as y,a as v,j as w,P as b,q as x,s as S,p as D,k as C,l as N,n as I,D as k,E as _,z as T,I as F,J as E,r as L,f as $,t as M,K as U,c as P,M as A,v as j,N as z,V,O as R,Q as B,R as q,G as K,T as O,U as W,W as H,h as J,i as G,o as Q,y as X,X as Y,w as Z,C as ee,x as te,A as ne}from"./Modal-BzH-_ch3.js";import re from"clsx";import ae from"react-webcam";import{X as se}from"lucide-react";import{Dialog as oe,Box as ce,Drawer as ie}from"@mui/material";import le from"video.js";const de="DESKTOP",ue="TAB",me="MOBILE",pe=c(void 0);function fe({children:t}){const[n,r]=a([window?.innerWidth,window?.innerHeight]),[s,c]=a(!1),d=()=>{r([window?.innerWidth,window?.innerHeight])};o(()=>{d()},[]),i(()=>(window.addEventListener("resize",d),()=>window.removeEventListener("resize",d)),[d]);let u=de;n[0]>768&&n[0]<1024&&(u=ue),n[0]<768&&(u=me);const m=l(()=>({size:n,setSize:r,clearInputs:s,setClearInputs:c,media:u}),[n,s,u]);return e(pe.Provider,{value:m,children:t})}var he=r.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 ge=r.memo(function({angle:n,countdown:r,isScanning:a,isInTargetRange:o,stabilityScore:c,children:i}){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(a)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)})`},[a,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 a?`text-[${g?.style?.angleDetector?.successAngleTextLightColor}]`:w(e,t)},[a,y]),x=s((e,t)=>t>70||e?g?.style?.angleDetector?.successAngleTextLightColor:g?.style?.angleDetector?.successAngleTextDarkColor,[]),S=s((e=!1)=>{const t=y();return a?g?.style?.angleDetector?.successAngleTextLightColor:x(e,t)},[a,y]),D=r;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},"data-testid":"level-screen","data-angle-state":a?"locked":o?"target":"adjusting",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!==D?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:D})}):t("div",a?{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"})}),i]}:{className:re("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:re("mt-[.5rem] text-center w-[180px] flex-col flex items-center absolute top-[60px]",b()),style:{color:S()},children:[e(he,{size:30}),t("p",{style:{fontFamily:g?.style?.base?.baseFontFamily||"Inter, sans-serif"},children:[" ",u?.(h.startLevelCheck),e("br",{})]})]})]}),null!==D&&e("div",{className:"absolute bottom-[8rem] text-center",children:e("div",{className:re("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===D&&!a&&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===D&&!a&&e("div",{className:"absolute bottom-[5rem] text-center",children:t("div",{className:re("text-[1.5rem] font-light",b()),style:{color:S(),fontFamily:g?.style?.base?.baseFontFamily||"Inter, sans-serif"},children:[Math.round(n),"°"]})}),null===D&&!a&&e("div",{className:"absolute bottom-[2rem] text-center max-w-[20rem] mx-auto",children:e("div",{className:re("text-[.75rem] opacity-50",b()),style:{fontFamily:g?.style?.base?.baseFontFamily||"Inter, sans-serif",color:S()},children:u?.(h.placePhoneUpright)})})]})});function ye({resetScan:n,loadingCam:r,onUserMedia:a,onPause:s,pause:o,onReScan:c,recordingStarted:i,startSendingVideoFrames:l,showPause:u,webcamRef:p,onUserMediaError:f,resetDetector:w,videoConstraints:b,webcamKey:x,faceDone:S,isScanning:D}){const{media:C}=d(pe)||{},{translate:N}=d(m)||{};return t("div",{className:"App w-screen h-[100vh] relative common-ui-main","data-testid":"camera-scan","data-scan-phase":S?"spinning":i?"pose-detecting":D?"starting":"ready",children:[e("span",{onClick:()=>{n(),w()},className:"fixed right-[20px] top-[20px] z-[999]",children:e(se,{className:"text-[#fff]"})}),e("div",{className:"w-full h-full overflow-hidden ",children:C===me&&e(ae,{audio:!1,ref:p,screenshotQuality:1,videoConstraints:b,mirrored:!0,screenshotFormat:"image/jpeg",onUserMedia:a,onUserMediaError:f,style:{position:"fixed",top:0,bottom:0,zIndex:0,width:"100%",height:"100%",objectFit:"cover"}},x)}),t("div",{className:"fixed bottom-[30px] w-full z-[999] flex flex-col gap-4 items-center justify-center",children:[u&&e(g,{className:"!w-[180px] !h-[40px] !py-[0] mx-auto ",prefix:y,buttonText:N?.(h.pause),buttonFunc:s,btnSecondary:!0}),o?e("div",{children:e(g,{className:"!w-[180px] !h-[40px] !py-[0] mx-auto",buttonText:N?.(h.restart),buttonFunc:c,btnSecondary:!0})}):i?null:e(g,{"data-testid":"start-scan-btn",className:"!w-[180px] !h-[40px] !py-[0] mx-auto !bg-[#ffffff] !text-[#000000] "+(r?"!opacity-50":""),buttonText:N?.(h.startScan),buttonFunc:l,disabled:r})]}),e("audio",{id:"audioElement",crossOrigin:"anonymous",preload:"auto",style:{position:"absolute",zIndex:-99999},src:`${v}scanAudioInstructions/silence.mp3`})]})}let ve,we=null,be=null,xe=null;let Se=null;var De=r.memo(function({setIsScanLocked:t,resetDetector:n,scanID:r,setIsVideoUploaded:c,setScanFailsError:i,setScanStartTime:m,setScanUniqueKey:p,userDetails:f}){const{gender:h,heightInCm:g,email:y,shopDomain:U}=f,P=u(null),A=u(null),j=u(null),[z,V]=a([]),[R,B]=a(!0),[q,K]=a(!1),[O,W]=a(!1),[H,J]=a(!0),[G,Q]=a(!1),X=u(null),[Y,Z]=a(""),[ee,te]=a([]),[ne,re]=a(""),[ae,se]=a(!1),[oe,ce]=a(!1),[ie,le]=a(!1),[de,ue]=a([]),[me,pe]=a(!1),fe=u(!0),{poseDetector:he}=function(){const[e,t]=a(0),[n,r]=a(0),[s,c]=a(!1),i=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-DC0_P6R7.js"),import("@tensorflow/tfjs-core"),import("@tensorflow/tfjs-backend-webgl")]);xe=e,await t.setBackend("webgl"),await t.ready(),console.log("TensorFlow backend ready (WebGL)");const r={runtime:"mediapipe",modelType:"full",solutionPath:"https://cdn.jsdelivr.net/npm/@mediapipe/pose"};try{be=await xe.createDetector(xe.SupportedModels.BlazePose,r),console.log("MediaPipe detector created successfully")}catch(e){console.warn("MediaPipe failed, falling back to TFJS runtime:",e),be=await xe.createDetector(xe.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),we=null,!1}}function p(e){return!(!e||0===e.length)&&22===e.filter(e=>e[2]>.7).length}return o(()=>{if(d.current=!0,!be)return we||(we=m()),we.then(e=>{e&&d.current&&c(!0)}),()=>{d.current=!1};c(!0)},[]),o(()=>{l.current=e,e>6&&i.current<2&&(r(e=>e+1),t(0))},[e]),o(()=>{i.current=n},[n]),{poseDetector:async(e,n)=>{if(!be||!d.current||!n?.current?.video)return;const r=n.current.video;if(!(r.readyState<2))try{const n=await be.estimatePoses(r,{flipHorizontal:!1});if(!n||!n.length)return;const a=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!==i.current||p(a)||t(e=>e+1),1===i.current&&p(a)&&t(e=>e+1),2===i.current&&e()}catch(e){console.error("Pose detection error:",e)}},isLoaded:s,spinPhase:n,resetDetector:()=>{i.current=0,l.current=0,t(0),r(0)},retryLoading:async()=>{be||we||(we=m(),await we&&d.current&&c(!0))}}}(),ge=u(!0),De=u(!1),Ce=u(0),Ne=u(0),Ie=u(!1),ke=u(!1),_e=u(!1),Te=u(()=>{}),Fe=u(()=>{}),Ee=u(null),Le=u(null),$e=u(0),[Me,Ue]=a([]),[Pe,Ae]=a(0),[je,ze]=a(w),{setStartGyro:Ve,uploadScanFile:Re,setUploadLoading:Be,swan:qe,onScanStart:Ke,onCaptureComplete:Oe}=d(b),We=()=>{De.current=!1,clearTimeout(ve),X.current&&clearTimeout(X.current),Le.current&&(clearTimeout(Le.current),Le.current=null),$e.current=0,p($()),i(""),Be?.(!1),V([]),j.current=null,B(!0),K(!1),W(!1),J(!0),Q(!1),X.current=null,Z(""),te([]),re(""),se(!ae),Ve(!1),S.stopAudio(),ce(!1),le(!1),Ce.current=0,Ne.current=0,Ie.current=!1,_e.current=!1,null!==A.current&&A.current.stop(),de.forEach(e=>{A.current&&A.current.removeEventListener("dataavailable",e)}),ue([]),fe.current=!0,pe(!1),c(!1),P.current?.stream&&B(!1)},He=s(()=>{setTimeout(()=>{B(!1)},1e3)},[]),Je=s(e=>{if(console.log("camera error",e),je===w)return ze(x),void Ae(e=>e+1);B(!1)},[je]),Ge=s(()=>{fe.current=!1,le(!0),pe(!1),X.current&&clearTimeout(X.current),Le.current&&(clearTimeout(Le.current),Le.current=null),A.current&&A.current.pause(),S.stopAudio(),qe.poseDetection.disconnect(),D.capture(`${U}/pose_detection_disconnected`,{scanID:r,email:y,id:Ee.current,type:"user_pause",reason:"User paused the scan"}),Ce.current=0,Ne.current=0,Ie.current=!1,_e.current=!1,A.current&&A.current.stop(),de.forEach(e=>{A.current&&A.current.removeEventListener("dataavailable",e)}),ue([]),clearTimeout(ve)},[A,de,S,fe]),Qe=l(()=>C(),[]),Xe=N(Me),Ye=I(Xe),Ze=s(async()=>{fe.current=!0,await S.playAudio(`${v}SpotOn.mp3`),le(!1),pe(!1),X.current&&clearTimeout(X.current),K(!1)},[X,S]),et=s(async()=>{if(!ke.current&&!Ee.current){ke.current=!0;try{Ee.current=await qe.poseDetection.connect(),$e.current=0,D.capture(`${U}/pose_detection_connected`,{scanID:r,email:y,id:Ee.current})}catch(e){console.log(e,"while connecting websocket");const t=k(e);$e.current+=1,$e.current<=2?(D.capture(`${U}/pose_detection_retry`,{scanID:r,email:y,attempt:$e.current,type:"connect_failed",reason:t}),setTimeout(()=>et(),2e3)):(D.capture(`${U}/pose_detection_connect_failed`,{scanID:r,email:y,attempt:$e.current,type:"connect_failed",reason:t}),i(`Connection failed: ${t}`),$e.current=0)}finally{ke.current=!1}}},[r,U,y]),tt=s(async()=>{_({eventName:`${U}/rescan`,email:y,scanID:r,height:g,gender:h,status:!1}),fe.current=!1,qe.poseDetection.disconnect(),D.capture(`${U}/pose_detection_disconnected`,{scanID:r,email:y,id:Ee.current,type:"user_rescan",reason:"User initiated a rescan"}),Ee.current=null,We(),await et(),Fe.current()},[et,r,y]),nt=s(({data:e})=>{e&&e.size>0&&fe.current&&(V(t=>t.concat(e)),!De.current&&P.current&&(De.current=!0,he(()=>{Ze(),T({eventName:`${U}/tensorFlow`,scanID:r,email:y,message:"recording stopped by tensorflow "})},P)))},[Ze,T,U,r,y,P]),rt=s(async()=>{const e=ee[ee.length-1];e&&fe.current&&(await S.playAudio(v+e),fe.current&&(ve=setTimeout(rt,2e3)))},[ee,fe]),at=s(()=>{A&&A.current&&A.current.stop(),K(!0);try{if(P&&P.current&&P.current.stream){const e=P.current.stream.getVideoTracks()[0];if(e){const t=e.getSettings();j.current=t.frameRate||null}const t={videoBitsPerSecond:15e5};Me[0]&&(t.mimeType=Me[0]),A.current=new MediaRecorder(P.current.stream,t),A.current.addEventListener("dataavailable",nt),A.current.addEventListener("stop",()=>{J(!0)}),ue([...de,nt]),A.current.start(1e3),J(!1)}}catch(e){console.log("error while using media recorder",e)}},[P,Me,nt,de]),st=s(async()=>{Le.current&&(clearTimeout(Le.current),Le.current=null),X.current&&clearTimeout(X.current),at(),fe.current&&(X.current=setTimeout(async()=>{fe.current&&(await S.playAudio(`${v}SpotOn.mp3`),K(!1))},15e3)),W(!0),fe.current&&await S.playAudio(`${v}Spin.mp3`)},[at,fe,S]);o(()=>{Te.current=st},[st]);const ot=s(({data:e})=>{const t=qe.poseDetection.connected();if(e.size>0&&!t)return $e.current+=1,void($e.current<=2?(D.capture(`${U}/pose_detection_retry`,{scanID:r,email:y,attempt:$e.current,type:"mid_scan_drop",reason:"WebSocket disconnected during active scanning"}),Ee.current=null,Ie.current=!1,et()):(D.capture(`${U}/pose_detection_connection_lost`,{scanID:r,email:y,attempt:$e.current,type:"mid_scan_drop",reason:"Pose detection WebSocket dropped. Retries exhausted."}),i("Pose detection connection lost. Please try again."),$e.current=0));e.size>0&&t&&(Ie.current||(Ie.current=!0,qe.poseDetection.poseStatus(async e=>{if(console.log("poseStatus data:",e),e&&e.audio&&e.audio.length>0){D.capture(`${U}/pose_instruction_received`,{scanID:r,email:y,audio:e.audio,status:e.status,sid:e.sid,counter:Ce.current,consecutiveFalse:Ne.current,type:"body_scan_instruction"});const t=F();!0===e.status&&e.sid===Ee.current?(Ne.current=0,Ce.current<2?(Ce.current+=1,1!==Ce.current||_e.current?2===Ce.current&&t?.paused&&S.playAudio(v+e.audio):(_e.current=!0,S.stopAudio(),await S.playAudio(v+e.audio))):(re(e.audio),clearTimeout(ve),qe.poseDetection.disconnect(),D.capture(`${U}/pose_detection_disconnected`,{scanID:r,email:y,id:Ee.current,type:"pose_confirmed",reason:"T-pose confirmed after 3 consecutive detections"}),Ie.current=!1,setTimeout(()=>Te.current(),1e3))):(Ne.current+=1,Ne.current>=3&&(Ce.current=0,_e.current=!1),!t?.paused||Se&&Se?.audioName===e.audio?Se?.audioName===e.audio&&t?.paused&&(Se&&Se.no_of_times_skipped>=Se.skipCount?(Se.no_of_times_skipped=0,S.playAudio(v+e.audio)):Se&&(Se.no_of_times_skipped+=1)):(Se={skipCount:2,no_of_times_skipped:0,audioName:e.audio},S.playAudio(v+e.audio)))}})),P?.current&&null!==P.current.getScreenshot()&&qe.poseDetection.videoEmit({image:P.current.getScreenshot()||"",scanId:r}))},[P,r,qe,S,U,y]),ct=s(async()=>{Q(!0),Ve(!0),Ke?.(),Le.current&&clearTimeout(Le.current),Le.current=setTimeout(()=>{fe.current&&(i("Pose not detected. Please try again."),fe.current=!1,qe.poseDetection.disconnect())},24e4),ge.current&&(ge.current=!1,T({eventName:"scan started",scanID:r,status:"success",email:y})),m(E()),B(!0),fe.current&&await S.playAudio(`${v}StartScan.mp3`),fe.current&&await S.playAudio(`${v}LiftArmsAndHoldAtHip.mp3`),fe.current&&(Q(!1),K(!0),ce(!0),pe(!0),He());try{if(P&&P.current&&P.current.stream&&fe.current){const e=P.current.stream.getVideoTracks()[0];if(e){const t=e.getSettings();j.current=t.frameRate||null}const t={videoBitsPerSecond:15e5};Me[0]&&(t.mimeType=Me[0]),fe.current&&(A.current=new MediaRecorder(P.current.stream,t)),fe.current&&A.current&&A.current.addEventListener("dataavailable",ot),ue([...de,ot]),A.current&&A.current.start(1e3),J(!1),fe.current&&(ve=setTimeout(rt,2e3))}}catch(e){console.log("error ----------",e)}},[P,Me,ot,de,rt,fe,Ke]);return o(()=>(U&&(t(!0),et()),()=>{const e=Ee.current;Ee.current=null,e&&(qe.poseDetection.disconnect(),D.capture(`${U}/pose_detection_disconnected`,{scanID:r,email:y,id:e,type:"component_unmount",reason:"Component unmounted"})),de.forEach(e=>{A?.current?.removeEventListener("dataavailable",e)})}),[U]),o(()=>{ee.push(Y)},[Y]),o(()=>{te([])},[ne]),o(()=>{const e=z.length&&z.length>0;H||!e||q||!fe.current||ie||A&&A.current&&(q||A.current.stop())},[H,q,z,ie]),o(()=>{const e=z.length&&z.length>0;if(H&&e&&!q&&A&&A.current&&fe.current&&!ie&&!q){const e=new File(z,`${r}.${Ye}`,{type:Xe});Oe?.(),Be?.(!0),i(""),Re?.(e,j.current)}},[H,q,z,ie,A,fe]),o(()=>{Fe.current=ct},[ct]),o(()=>{const e=L(Qe,M);Ue(e)},[Qe]),o(()=>{We()},[]),e(ye,{resetDetector:n,resetScan:We,loadingCam:R,onPause:Ge,showRestart:oe,pause:ie,onReScan:tt,recordingStarted:q,isScanning:G,startSendingVideoFrames:ct,faceDone:O,stopRecording:Ze,showPause:me,webcamRef:P,onUserMedia:He,onUserMediaError:Je,videoConstraints:je,webcamKey:Pe})});function Ce({scanID:t,userDetails:n,setIsVideoUploaded:r,setScanFailsError:s,setScanStartTime:c,setScanUniqueKey:i}){const[l,d]=a(90),[m,p]=a(0),[f,h]=a(null),[g,y]=a(!1),[v,w]=a(0),b=u([]),[x,S]=a(!1),D=l-m,C=D>=80&&D<=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),D],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||I()},[D,C,f,g]),o(()=>{v>=100&&null===f&&!g&&N(),v<50&&null!==f&&I()},[v,f,g]);const N=()=>{h(3);const e=setInterval(()=>{h(t=>null===t||t<=1?(clearInterval(e),y(!0),null):t-1)},1e3)},I=()=>{h(null),x||y(!1)};return e(ge,{angle:D,countdown:f,isScanning:g,isInTargetRange:C,stabilityScore:v,children:g&&e(De,{setIsScanLocked:S,resetDetector:()=>{d(90),p(0),h(null),y(!1),w(0),S(!1),b.current=[]},scanID:t,userDetails:n,setIsVideoUploaded:r,setScanFailsError:s,setScanStartTime:c,setScanUniqueKey:i})})}function Ne({setShowDrawer:t,config:n,loader:r}){const[c,i]=a({disabled:!1,message:""}),[l,d]=a(!0),m=u(null),p=s(async()=>{const e=await U();i(e),d(!1)},[]);return o(()=>{p()},[]),l?e(P,{url:r,loaderType:"black"}):c?.disabled?e(A,{config:n,message:c?.message}):e(ae,{audio:!1,ref:m,screenshotQuality:1,videoConstraints:j,mirrored:!0,onUserMedia:()=>t?.(!0),screenshotFormat:"image/jpeg",style:{position:"relative",top:0,bottom:0,zIndex:0,width:"100%",height:"100%",objectFit:"cover"}})}function Ie({link:t,onReady:n,wrapperClassName:r="[&_video]:rounded-t-[20px] w-full h-full"}){const a=u(null),s=u(null);let c={autoplay:!0,controls:!1,responsive:!0,fluid:!0,muted:!0,navigationUI:"hide",preload:"metadata",poster:z};return o(()=>{if(!s.current&&t&&a?.current){const e=le(a.current,{...c});e.ready(()=>{s.current=e;const r={...c,sources:[{src:t,type:"application/x-mpegURL"}]};e.autoplay(r.autoplay),e.src(r.sources),n?.(e)})}},[t,a]),o(()=>{const e=s.current;return()=>{e&&!e.isDisposed()&&(e.dispose(),s.current=null)}},[s]),e("div",{className:r,children:e("video",{ref:a,muted:!0,className:"video-js",playsInline:!0,onDrag:e=>e.preventDefault()})})}function ke({scanFailsError:r,onNext:s,gender:o,setScanUniqueKey:c,setIsVideoUploaded:i}){const{translate:l}=d(m)||{},u=p(),[y,v]=a(!1),w=()=>{v(!y)};return t(n,{children:[t("div",{"data-testid":"scan-error-message",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:r&&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:k(r)}),e("img",{className:"my-[0.5rem] aspect-[2/1.4] w-full object-cover",onClick:w,src:V[o],alt:"icon"})]})}),r&&e("div",{className:"p-[1rem] flex gap-[0.5rem]",children:e(g,{"data-testid":"scan-again-btn",disabled:!1,buttonText:l?.(h.scanAgain),className:"!shadow-none",buttonFunc:()=>{s?s?.():c?.($()),i?.(!1)}})})]}),y&&t(oe,{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(se,{className:"absolute right-[8px] top-[8px] text-white z-[9]"})})}),e("div",{className:"aspect-video object-cover rounded-[20px] ",children:e(Ie,{link:o?R[o].PRE_LINK:R.male.PRE_LINK,wrapperClassName:"w-screen h-screen fixed top-[0] left-[0]"})})]})]})}function _e({scanId:n,userDetails:r,config:c,isVideoUploadedCorrect:i,isMeasurementAvailable:l,onComplete:u,isSuccess:p,onCustomScanSuccess:y,swan:v}){const{gender:w,shopDomain:b,heightInCm:x,deviceFocalLength:S,userName:C,email:N,scanType:I}=r||{},k=[O,W,H].includes(I??""),[_,T]=a(!0),F=s(async()=>{try{k&&(await(v?.auth.addUser({scanId:n,email:N,name:C,gender:w,height:x})),y?.()),D.capture(b??"",{scanID:n,email:N,height:x,focalLength:S,clothesFit:"0",gender:w})}catch(e){console.log(e)}},[k]),{translate:E}=d(m)||{};o(()=>{(i||l)&&F()},[i,l]);const L=p||i||l;return e(ce,{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(Ne,{loader:c?.loader,setShowDrawer:T}),e(ie,{open:_,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] common-ui-main overflow-y-auto",style:{background:c?.style?.base?.backgroundColor},children:t("div",{className:"w-full flex-1 flex flex-col min-h-[400px]",children:[e(f,{title:E?.(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 min-h-[170px]",muted:!0,loop:!0,autoPlay:!0,playsInline:!0,children:e("source",{src:w===K.Male?B:q,type:"video/mp4"})})}),L&&e(g,{className:"!w-[180px] mx-auto",buttonText:E?.(h.next),buttonFunc:()=>{u?.()}})]})})})]})})}const Te=()=>{const{userDetails:n,onRetry:r,isError:a,isSuccess:s,gender:o,scanUniqueKey:c,scanFailsError:i,setScanUniqueKey:l,setIsVideoUploaded:u,isMeasurementAvailable:m,isVideoUploadedCorrect:f,loading:h,showDeniedModal:g,uploadLoading:y,isLandscape:v,setScanFailsError:w,setScanStartTime:x,resetScan:S,onCustomScanSuccess:D,swan:C,onComplete:N}=d(b),I=p();return a?t("div",{"data-scan-state":"error",children:[e(Ne,{}),e(ie,{anchor:"bottom",open:!0,className:"camera-drawer",onClose:(e,t)=>{},disablePortal:!0,children:e(ke,{scanFailsError:!0,onNext:r,gender:o})})]}):s?e("div",{"data-scan-state":"success",children:e(_e,{isSuccess:!0,onComplete:N})}):h?e("div",{"data-scan-state":"loading",className:"flex top-0 !mt-0 left-0 z-[999] absolute justify-center items-center w-full h-full",style:{background:I?.style?.base?.backgroundColor},children:e(P,{url:I?.loader,loaderType:"black"})}):!v||y||i?g.disabled?e("div",{"data-scan-state":"camera-denied",children:e(A,{})}):y||i||m||f?(y||m||f)&&!i?e("div",{"data-scan-state":"processing",children:e(_e,{scanId:c,isMeasurementAvailable:m,userDetails:n,isVideoUploadedCorrect:f,onCustomScanSuccess:D,swan:C,onComplete:N,config:I})}):t("div",{"data-scan-state":"error-retry",children:[e(Ne,{}),e(ie,{anchor:"bottom",open:!0,className:"camera-drawer",onClose:(e,t)=>{},disablePortal:!0,children:e(ke,{scanFailsError:i,onNext:()=>{r?.(),S()},setScanUniqueKey:l,gender:o,setIsVideoUploaded:u})})]}):e("div",{"data-scan-state":"scanning",children:e(Ce,{scanID:c,userDetails:n,setIsVideoUploaded:u,setScanFailsError:w,setScanStartTime:x,setScanUniqueKey:l})}):e(A,{variant:"portrait",config:I})},Fe=t=>{const{config:n,onRetry:r,onScanStart:c,onCaptureComplete:i,onUploadStart:d,onUploadEnd:m,onMeasurementSocketStart:p,onMeasurementSocketClose:f,onIntermediateScanSuccess:h,onScanError:g,onScanSuccess:y,onCustomScanSuccess:v,onComplete:w,isError:x,isSuccess:D}=t,C={email:"",shopDomain:"",gender:"male",heightInCm:0,scanType:"",deviceFocalLength:0,deviceModelName:"",sourceTag:"",callbackUrl:null,...t.userDetails??{}},N=t.token??"",{gender:I,scanType:_,shopDomain:F,heightInCm:L,email:M,deviceFocalLength:P,deviceModelName:A,callbackUrl:j,sourceTag:z}=C,V=l(()=>J(N),[N]),[R,B]=a(!1),[q,K]=a(!1),[O,W]=a(!1),[H,re]=a({disabled:!1,message:""}),[ae,se]=a(""),[oe,ce]=a(!1),[ie,le]=a(!0),[de,ue]=a(!1),[me,pe]=a(""),[he,ge]=a(E()),{gyroData:ye}=function(e){const[t,n]=a([]),[r,c]=a(!1),i=s(e=>{try{const{alpha:t,beta:r,gamma:a}=e;n(e=>[...e,{alpha:t?.toString()||void 0,beta:r?.toString()||void 0,gamma:a?.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()?c(!0):console.warn("Device orientation permission denied.")}catch(e){console.error("Error requesting device orientation permission:",e)}else c(!0)},[]);return o(()=>(e&&r?window.addEventListener("deviceorientation",i):n([]),()=>{window.removeEventListener("deviceorientation",i)}),[e,r,i]),o(()=>{e&&l()},[e,l]),{gyroData:t}}(de),{isLandscape:ve}=G();Q();const we=s(()=>{pe($()),se(""),B(!1),ce(!1)},[]),be=u(!1);o(()=>{!ve||be.current||R||x||D||ae||(S.stopAudio(),we()),be.current=ve},[ve,R,x,D,ae,we]);const xe=()=>{ge(null),pe("")},Se=s(async e=>{if(e&&"success"===e?.scanStatus&&"intermediate"===e?.resultType&&200===e?.code)return T({eventName:`${F}/measurement_success/intermediate`,scanID:me,status:"success",email:M}),K(!0),void h?.(e);y?.(e),K(!0),xe();const t=me;W(!0),T({eventName:`${F}/measurement_success/fit-view`,scanID:t,status:"success",email:M}),he&&T({eventName:`${F}/scan_completion_time`,scanID:t,status:"success",completionTime:E()-he,email:M})},[_,F,me]),De=e=>{W(!1),se(""),K(!1);let t=!1;V.measurement.handleMeasurementSocket({scanId:me,onPreopen:()=>{ne({eventName:`${F}/webSocket`,scanID:me,connection:"pre_open",type:"measurement_recommendation",email:M})},onOpen:()=>{p?.(),ne({eventName:`${F}/webSocket`,scanID:me,connection:"open",type:"measurement_recommendation",email:M})},onClose:()=>{f?.(),ne({eventName:`${F}/webSocket`,scanID:me,connection:"close",type:"measurement_recommendation",email:M}),t||(se("Connection closed. Please try again."),B(!1))},onError:e=>{var n;t=!0,n=e,g?.({...n,message:k(n)}),xe(),W(!1),se(n),K(!1),T({eventName:`${F}/measurement_failed/fit-view`,scanID:me,status:"failed",email:M,message:k(n)}),he&&T({eventName:`${F}/scan_completion_time`,scanID:me,status:"failed",completionTime:E()-he,email:M}),ne({eventName:`${F}/webSocket`,scanID:me,connection:"error",type:"measurement_recommendation",email:M})},onSuccess:e=>{t=!0,ne({eventName:`${F}/webSocket`,scanID:me,connection:"success",type:"measurement_recommendation",email:M}),Se(e)}})},Ce=s(async(e,t)=>{const n=Number((e.size/1048576).toFixed(2)),r=null!=t?t:await X(e),a=Y({gender:I,focal_length:`${P}`,height:`${L}`,customer_store_url:F,clothes_fit:"0",scan_type:_,callback_url:j,source_tag:z});T({eventName:`${F}/body_scan_meta_data`,scanID:me,email:M,data:JSON.stringify([...a,{fileSizeInMB:n,video_fps:r||0}])}),d?.();try{await V.fileUpload.uploadFileFrontend({file:e,arrayMetaData:a,scanId:me,email:M}),await V.fileUpload.setDeviceInfo({model:A,detection:"manual",gyro:ye,scanId:me}),console.log("video successfully uploaded"),ce(!1),T({eventName:`${F}/scan_success`,scanID:me,status:"success",email:M,data:JSON.stringify(a)}),T({eventName:"scan finished",scanID:me,status:"success",email:M}),ge(E()),setTimeout(()=>{ce(!0)},3e3)}catch(e){T({eventName:"scan finished",scanID:me,status:"failed",email:M,message:k(e)}),T({eventName:`${F}/scan_failed`,scanID:me,status:"failed",email:M,message:k(e),data:JSON.stringify(a)}),se(k(e)),ce(!1),g?.({...e,message:k(e)}),xe()}finally{ue(!1),m?.()}},[me,ye,d,m]),Ne=s(async()=>{if(+L<152.4||+L>213.36)return void g?.({message:"Height must be between 152.4cm (5ft) and 213.36cm (7ft)"});const e=await U();e.disabled?(T({eventName:`${F}/camera_activation`,scanID:me,status:"failed",email:M}),le(!1)):(le(!1),T({eventName:`${F}/camera_activation`,scanID:me,status:"success",email:M})),re(e),se(""),ce(!1)},[M,me,pe,F]);return o(()=>{x||D||F&&Ne()},[F,L,x,D]),o(()=>{x||D||oe&&F&&me&&De()},[oe,F,me,x,D]),e("div",{"data-testid":"body-scan-root",children:e(Z,{children:e(ee,{config:n,children:e(fe,{children:e(b.Provider,{value:{userDetails:C,onRetry:r,onScanError:g,isError:x,isSuccess:D,onScanSuccess:y,gender:I,scanUniqueKey:me,scanFailsError:ae,setScanUniqueKey:pe,setIsVideoUploaded:ce,isMeasurementAvailable:O,isVideoUploadedCorrect:q,loading:ie,showDeniedModal:H,uploadLoading:R,isLandscape:ve,setStartGyro:ue,uploadScanFile:Ce,setUploadLoading:B,resetScan:we,setScanFailsError:se,setScanStartTime:ge,onScanStart:c,onCaptureComplete:i,onCustomScanSuccess:v,onComplete:w,swan:V},children:e(te,{children:e(Te,{})})})})})})})};export{Fe as B};
|
|
2
|
+
//# sourceMappingURL=BodyScan-BLvWlYnA.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var e=require("react/jsx-runtime"),t=require("react"),s=require("./Modal-DU2Jymve.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 p=t.useMemo(()=>({size:n,setSize:a,clearInputs:r,setClearInputs:o,media:m}),[n,r,m]);return e.jsx(d.Provider,{value:p,children:s})}var p=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 f=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]),f=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,[]),v=t.useCallback((e=!1)=>{const t=m();return o?d?.style?.angleDetector?.successAngleTextLightColor:x(e,t)},[o,m]),S=r;function y(){document.documentElement.style.setProperty("--real-vh",window.innerHeight+"px")}return y(),window.addEventListener("resize",y),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:f},"data-testid":"level-screen","data-angle-state":o?"locked":c?"target":"adjusting",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 ${v()}`},children:e.jsx("div",{className:`text-[3rem] font-bold text-[${v()}]`,style:{fontFamily:d?.style?.base?.baseFontFamily||"Inter, sans-serif",color:v()},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 ${v()}`},children:[e.jsx("div",{className:`h-[1rem] w-[1rem] rounded-[9999px] bg-[${v()}]/80`,style:{backgroundColor:`${v()}B3`}}),e.jsxs("div",{className:n("mt-[.5rem] text-center w-[180px] flex-col flex items-center absolute top-[60px]",g()),style:{color:v()},children:[e.jsx(p,{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:v()},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-[${v()}]/20 rounded-[9999px] overflow-hidden`,style:{backgroundColor:`${v()}33`},children:e.jsx("div",{className:`h-full bg-[${v()}]/70 transition-all duration-300 rounded-[9999px]`,style:{width:`${a}%`,backgroundColor:`${v()}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:v(),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:v()},children:u?.(s.LanguageKeys.placePhoneUpright)})})]})});function h({resetScan:n,loadingCam:o,onUserMedia:c,onPause:i,pause:l,onReScan:m,recordingStarted:p,startSendingVideoFrames:f,showPause:h,webcamRef:g,onUserMediaError:x,resetDetector:v,videoConstraints:S,webcamKey:y,faceDone:b,isScanning:C}){const{media:w}=t.useContext(d)||{},{translate:j}=t.useContext(s.LanguageContext)||{};return e.jsxs("div",{className:"App w-screen h-[100vh] relative common-ui-main","data-testid":"camera-scan","data-scan-phase":b?"spinning":p?"pose-detecting":C?"starting":"ready",children:[e.jsx("span",{onClick:()=>{n(),v()},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:w===u&&e.jsx(a,{audio:!1,ref:g,screenshotQuality:1,videoConstraints:S,mirrored:!0,screenshotFormat:"image/jpeg",onUserMedia:c,onUserMediaError:x,style:{position:"fixed",top:0,bottom:0,zIndex:0,width:"100%",height:"100%",objectFit:"cover"}},y)}),e.jsxs("div",{className:"fixed bottom-[30px] w-full z-[999] flex flex-col gap-4 items-center justify-center",children:[h&&e.jsx(s.SpecificButton,{className:"!w-[180px] !h-[40px] !py-[0] mx-auto ",prefix:s.pauseIcon,buttonText:j?.(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:j?.(s.LanguageKeys.restart),buttonFunc:m,btnSecondary:!0})}):p?null:e.jsx(s.SpecificButton,{"data-testid":"start-scan-btn",className:"!w-[180px] !h-[40px] !py-[0] mx-auto !bg-[#ffffff] !text-[#000000] "+(o?"!opacity-50":""),buttonText:j?.(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,x=null,v=null,S=null;let y=null;var b=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:p,shopDomain:f}=u,b=t.useRef(null),C=t.useRef(null),w=t.useRef(null),[j,k]=t.useState([]),[E,D]=t.useState(!0),[N,T]=t.useState(!1),[I,L]=t.useState(!1),[F,M]=t.useState(!0),[_,P]=t.useState(!1),A=t.useRef(null),[$,R]=t.useState(""),[U,O]=t.useState([]),[z,K]=t.useState(""),[B,q]=t.useState(!1),[V,W]=t.useState(!1),[H,G]=t.useState(!1),[J,Q]=t.useState([]),[X,Y]=t.useState(!1),Z=t.useRef(!0),{poseDetector:ee}=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-D08ZA0zl.js")}),import("@tensorflow/tfjs-core"),import("@tensorflow/tfjs-backend-webgl")]);S=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{v=await S.createDetector(S.SupportedModels.BlazePose,n),console.log("MediaPipe detector created successfully")}catch(e){console.warn("MediaPipe failed, falling back to TFJS runtime:",e),v=await S.createDetector(S.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),x=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,!v)return x||(x=u()),x.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(!v||!l.current||!t?.current?.video)return;const n=t.current.video;if(!(n.readyState<2))try{const t=await v.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()=>{v||x||(x=u(),await x&&l.current&&o(!0))}}}(),te=t.useRef(!0),se=t.useRef(!1),ne=t.useRef(0),ae=t.useRef(0),re=t.useRef(!1),oe=t.useRef(!1),ce=t.useRef(!1),ie=t.useRef(()=>{}),le=t.useRef(()=>{}),ue=t.useRef(null),de=t.useRef(null),[me,pe]=t.useState([]),[fe,he]=t.useState(0),[ge,xe]=t.useState(s.videoConstraintsExact),{setStartGyro:ve,uploadScanFile:Se,setUploadLoading:ye,swan:be,onScanStart:Ce,onCaptureComplete:we}=t.useContext(s.ParamsContext),je=()=>{se.current=!1,clearTimeout(g),A.current&&clearTimeout(A.current),de.current&&(clearTimeout(de.current),de.current=null),l(s.generateUuid()),c(""),ye?.(!1),k([]),w.current=null,D(!0),T(!1),L(!1),M(!0),P(!1),A.current=null,R(""),O([]),K(""),q(!B),ve(!1),s.speechService.stopAudio(),W(!1),G(!1),ne.current=0,ae.current=0,re.current=!1,ce.current=!1,null!==C.current&&C.current.stop(),J.forEach(e=>{C.current&&C.current.removeEventListener("dataavailable",e)}),Q([]),Z.current=!0,Y(!1),o(!1),b.current?.stream&&D(!1)},ke=t.useCallback(()=>{setTimeout(()=>{D(!1)},1e3)},[]),Ee=t.useCallback(e=>{if(console.log("camera error",e),ge===s.videoConstraintsExact)return xe(s.videoConstraintsFallback),void he(e=>e+1);D(!1)},[ge]),De=t.useCallback(()=>{Z.current=!1,G(!0),Y(!1),A.current&&clearTimeout(A.current),de.current&&(clearTimeout(de.current),de.current=null),C.current&&C.current.pause(),s.speechService.stopAudio(),be.poseDetection.disconnect(),s.posthog.capture(`${f}/pose_detection_disconnected`,{scanID:r,email:p,id:ue.current,reason:"pause"}),ne.current=0,ae.current=0,re.current=!1,ce.current=!1,C.current&&C.current.stop(),J.forEach(e=>{C.current&&C.current.removeEventListener("dataavailable",e)}),Q([]),clearTimeout(g)},[C,J,s.speechService,Z]),Ne=t.useMemo(()=>s.getPreferredMediaRecorderTypes(),[]),Te=s.getRecordingMimeType(me),Ie=s.getRecordingExtension(Te),Le=t.useCallback(async()=>{Z.current=!0,await s.speechService.playAudio(`${s.voiceOverAssetsPath}SpotOn.mp3`),G(!1),Y(!1),A.current&&clearTimeout(A.current),T(!1)},[A,s.speechService]),Fe=t.useCallback(async()=>{if(!oe.current&&!ue.current){oe.current=!0;try{ue.current=await be.poseDetection.connect(),s.posthog.capture(`${f}/pose_detection_connected`,{scanID:r,email:p,id:ue.current})}catch(e){console.log(e,"while connecting websocket");const t=s.handleErrorMessage(e);c(`Connection failed: ${t}`),s.posthog.capture(`${f}/pose_detection_connect_failed`,{scanID:r,email:p,error:t})}finally{oe.current=!1}}},[r,f,p]),Me=t.useCallback(async()=>{s.rescanSupportCaptureEvent({eventName:`${f}/rescan`,email:p,scanID:r,height:m,gender:d,status:!1}),Z.current=!1,be.poseDetection.disconnect(),s.posthog.capture(`${f}/pose_detection_disconnected`,{scanID:r,email:p,id:ue.current,reason:"rescan"}),ue.current=null,je(),await Fe(),le.current()},[Fe,r,p]),_e=t.useCallback(({data:e})=>{e&&e.size>0&&Z.current&&(k(t=>t.concat(e)),!se.current&&b.current&&(se.current=!0,ee(()=>{Le(),s.handleScanTimeCapture({eventName:`${f}/tensorFlow`,scanID:r,email:p,message:"recording stopped by tensorflow "})},b)))},[Le,s.handleScanTimeCapture,f,r,p,b]),Pe=t.useCallback(async()=>{const e=U[U.length-1];e&&Z.current&&(await s.speechService.playAudio(s.voiceOverAssetsPath+e),Z.current&&(g=setTimeout(Pe,2e3)))},[U,Z]),Ae=t.useCallback(()=>{C&&C.current&&C.current.stop(),T(!0);try{if(b&&b.current&&b.current.stream){const e=b.current.stream.getVideoTracks()[0];if(e){const t=e.getSettings();w.current=t.frameRate||null}const t={videoBitsPerSecond:15e5};me[0]&&(t.mimeType=me[0]),C.current=new MediaRecorder(b.current.stream,t),C.current.addEventListener("dataavailable",_e),C.current.addEventListener("stop",()=>{M(!0)}),Q([...J,_e]),C.current.start(1e3),M(!1)}}catch(e){console.log("error while using media recorder",e)}},[b,me,_e,J]),$e=t.useCallback(async()=>{de.current&&(clearTimeout(de.current),de.current=null),A.current&&clearTimeout(A.current),Ae(),Z.current&&(A.current=setTimeout(async()=>{Z.current&&(await s.speechService.playAudio(`${s.voiceOverAssetsPath}SpotOn.mp3`),T(!1))},15e3)),L(!0),Z.current&&await s.speechService.playAudio(`${s.voiceOverAssetsPath}Spin.mp3`)},[Ae,Z,s.speechService]);t.useEffect(()=>{ie.current=$e},[$e]);const Re=t.useCallback(({data:e})=>{const t=be.poseDetection.connected();e.size>0&&!t?c("Pose detection connection lost. Please try again."):e.size>0&&t&&(re.current||(re.current=!0,be.poseDetection.poseStatus(async e=>{if(console.log("poseStatus data:",e),e&&e.audio&&e.audio.length>0){s.posthog.capture(`${f}/pose_instruction_received`,{scanID:r,email:p,audio:e.audio,status:e.status,sid:e.sid,counter:ne.current,consecutiveFalse:ae.current,type:"body_scan_instruction"});const t=s.findAudioElement();!0===e.status&&e.sid===ue.current?(ae.current=0,ne.current<2?(ne.current+=1,1!==ne.current||ce.current?2===ne.current&&t?.paused&&s.speechService.playAudio(s.voiceOverAssetsPath+e.audio):(ce.current=!0,s.speechService.stopAudio(),await s.speechService.playAudio(s.voiceOverAssetsPath+e.audio))):(K(e.audio),clearTimeout(g),be.poseDetection.disconnect(),s.posthog.capture(`${f}/pose_detection_disconnected`,{scanID:r,email:p,id:ue.current,reason:"pose_confirmed"}),re.current=!1,setTimeout(()=>ie.current(),1e3))):(ae.current+=1,ae.current>=3&&(ne.current=0,ce.current=!1),!t?.paused||y&&y?.audioName===e.audio?y?.audioName===e.audio&&t?.paused&&(y&&y.no_of_times_skipped>=y.skipCount?(y.no_of_times_skipped=0,s.speechService.playAudio(s.voiceOverAssetsPath+e.audio)):y&&(y.no_of_times_skipped+=1)):(y={skipCount:2,no_of_times_skipped:0,audioName:e.audio},s.speechService.playAudio(s.voiceOverAssetsPath+e.audio)))}})),b?.current&&null!==b.current.getScreenshot()&&be.poseDetection.videoEmit({image:b.current.getScreenshot()||"",scanId:r}))},[b,r,be,s.speechService,f,p]),Ue=t.useCallback(async()=>{P(!0),ve(!0),Ce?.(),de.current&&clearTimeout(de.current),de.current=setTimeout(()=>{Z.current&&(c("Pose not detected. Please try again."),Z.current=!1,be.poseDetection.disconnect())},24e4),te.current&&(te.current=!1,s.handleScanTimeCapture({eventName:"scan started",scanID:r,status:"success",email:p})),i(s.getCurrentTimeInSeconds()),D(!0),Z.current&&await s.speechService.playAudio(`${s.voiceOverAssetsPath}StartScan.mp3`),Z.current&&await s.speechService.playAudio(`${s.voiceOverAssetsPath}LiftArmsAndHoldAtHip.mp3`),Z.current&&(P(!1),T(!0),W(!0),Y(!0),ke());try{if(b&&b.current&&b.current.stream&&Z.current){const e=b.current.stream.getVideoTracks()[0];if(e){const t=e.getSettings();w.current=t.frameRate||null}const t={videoBitsPerSecond:15e5};me[0]&&(t.mimeType=me[0]),Z.current&&(C.current=new MediaRecorder(b.current.stream,t)),Z.current&&C.current&&C.current.addEventListener("dataavailable",Re),Q([...J,Re]),C.current&&C.current.start(1e3),M(!1),Z.current&&(g=setTimeout(Pe,2e3))}}catch(e){console.log("error ----------",e)}},[b,me,Re,J,Pe,Z,Ce]);return t.useEffect(()=>(f&&(n(!0),Fe()),()=>{const e=ue.current;ue.current=null,e&&(be.poseDetection.disconnect(),s.posthog.capture(`${f}/pose_detection_disconnected`,{scanID:r,email:p,id:e,reason:"unmount"})),J.forEach(e=>{C?.current?.removeEventListener("dataavailable",e)})}),[f]),t.useEffect(()=>{U.push($)},[$]),t.useEffect(()=>{O([])},[z]),t.useEffect(()=>{const e=j.length&&j.length>0;F||!e||N||!Z.current||H||C&&C.current&&(N||C.current.stop())},[F,N,j,H]),t.useEffect(()=>{const e=j.length&&j.length>0;if(F&&e&&!N&&C&&C.current&&Z.current&&!H&&!N){const e=new File(j,`${r}.${Ie}`,{type:Te});we?.(),ye?.(!0),c(""),Se?.(e,w.current)}},[F,N,j,H,C,Z]),t.useEffect(()=>{le.current=Ue},[Ue]),t.useEffect(()=>{const e=s.getSupportedMediaRecorderTypes(Ne,s.videoTypes);pe(e)},[Ne]),t.useEffect(()=>{je()},[]),e.jsx(h,{resetDetector:a,resetScan:je,loadingCam:E,onPause:De,showRestart:V,pause:H,onReScan:Me,recordingStarted:N,isScanning:_,startSendingVideoFrames:Ue,faceDone:I,stopRecording:Le,showPause:X,webcamRef:b,onUserMedia:ke,onUserMediaError:Ee,videoConstraints:ge,webcamKey:fe})});function C({scanID:s,userDetails:n,setIsVideoUploaded:a,setScanFailsError:r,setScanStartTime:o,setScanUniqueKey:c}){const[i,l]=t.useState(90),[u,d]=t.useState(0),[m,p]=t.useState(null),[h,g]=t.useState(!1),[x,v]=t.useState(0),S=t.useRef([]),[y,C]=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);v(j&&e<2?e=>Math.min(100,e+10):e=>Math.max(0,e-20))}j||null===m&&!h||E()},[w,j,m,h]),t.useEffect(()=>{x>=100&&null===m&&!h&&k(),x<50&&null!==m&&E()},[x,m,h]);const k=()=>{p(3);const e=setInterval(()=>{p(t=>null===t||t<=1?(clearInterval(e),g(!0),null):t-1)},1e3)},E=()=>{p(null),y||g(!1)};return e.jsx(f,{angle:w,countdown:m,isScanning:h,isInTargetRange:j,stabilityScore:x,children:h&&e.jsx(b,{setIsScanLocked:C,resetDetector:()=>{l(90),d(0),p(null),g(!1),v(0),C(!1),S.current=[]},scanID:s,userDetails:n,setIsVideoUploaded:a,setScanFailsError:r,setScanStartTime:o,setScanUniqueKey:c})})}function w({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(s.Modal,{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 j({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 k({scanFailsError:n,onNext:a,gender:c,setScanUniqueKey:i,setIsVideoUploaded:l}){const{translate:u}=t.useContext(s.LanguageContext)||{},d=s.useConfig(),[m,p]=t.useState(!1),f=()=>{p(!m)};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{"data-testid":"scan-error-message",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:f,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,{"data-testid":"scan-again-btn",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:f,open:m,disablePortal:!0,children:[e.jsx("div",{className:"flex justifyEnd ",children:e.jsx("span",{className:"closeBtn",onClick:f,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(j,{link:c?s.GENDER[c].PRE_LINK:s.GENDER.male.PRE_LINK,wrapperClassName:"w-screen h-screen fixed top-[0] left-[0]"})})]})]})}function E({scanId:n,userDetails:a,config:r,isVideoUploadedCorrect:c,isMeasurementAvailable:i,onComplete:l,isSuccess:u,onCustomScanSuccess:d,swan:m}){const{gender:p,shopDomain:f,heightInCm:h,deviceFocalLength:g,userName:x,email:v,scanType:S}=a||{},y=[s.CLOTHING_CUSTOM_SCAN,s.CLOTHING_BANNER_SCAN,s.CLOTHING_CUSTOM_FIT_SCAN].includes(S??""),[b,C]=t.useState(!0),j=t.useCallback(async()=>{try{y&&(await(m?.auth.addUser({scanId:n,email:v,name:x,gender:p,height:h})),d?.()),s.posthog.capture(f??"",{scanID:n,email:v,height:h,focalLength:g,clothesFit:"0",gender:p})}catch(e){console.log(e)}},[y]),{translate:k}=t.useContext(s.LanguageContext)||{};t.useEffect(()=>{(c||i)&&j()},[c,i]);const E=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(w,{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] common-ui-main overflow-y-auto",style:{background:r?.style?.base?.backgroundColor},children:e.jsxs("div",{className:"w-full flex-1 flex flex-col min-h-[400px]",children:[e.jsx(s.Header,{title:k?.(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 min-h-[170px]",muted:!0,loop:!0,autoPlay:!0,playsInline:!0,children:e.jsx("source",{src:p===s.GenderType.Male?s.maleMeasurementProgress:s.measurementProgress,type:"video/mp4"})})}),E&&e.jsx(s.SpecificButton,{className:"!w-[180px] mx-auto",buttonText:k?.(s.LanguageKeys.next),buttonFunc:()=>{l?.()}})]})})})]})})}const D=()=>{const{userDetails:n,onRetry:a,isError:r,isSuccess:c,gender:i,scanUniqueKey:l,scanFailsError:u,setScanUniqueKey:d,setIsVideoUploaded:m,isMeasurementAvailable:p,isVideoUploadedCorrect:f,loading:h,showDeniedModal:g,uploadLoading:x,isLandscape:v,setScanFailsError:S,setScanStartTime:y,resetScan:b,onCustomScanSuccess:j,swan:D,onComplete:N}=t.useContext(s.ParamsContext),T=s.useConfig();return r?e.jsxs("div",{"data-scan-state":"error",children:[e.jsx(w,{}),e.jsx(o.Drawer,{anchor:"bottom",open:!0,className:"camera-drawer",onClose:(e,t)=>{},disablePortal:!0,children:e.jsx(k,{scanFailsError:!0,onNext:a,gender:i})})]}):c?e.jsx("div",{"data-scan-state":"success",children:e.jsx(E,{isSuccess:!0,onComplete:N})}):h?e.jsx("div",{"data-scan-state":"loading",className:"flex top-0 !mt-0 left-0 z-[999] absolute justify-center items-center w-full h-full",style:{background:T?.style?.base?.backgroundColor},children:e.jsx(s.LoadingScreen,{url:T?.loader,loaderType:"black"})}):!v||x||u?g.disabled?e.jsx("div",{"data-scan-state":"camera-denied",children:e.jsx(s.Modal,{})}):x||u||p||f?(x||p||f)&&!u?e.jsx("div",{"data-scan-state":"processing",children:e.jsx(E,{scanId:l,isMeasurementAvailable:p,userDetails:n,isVideoUploadedCorrect:f,onCustomScanSuccess:j,swan:D,onComplete:N,config:T})}):e.jsxs("div",{"data-scan-state":"error-retry",children:[e.jsx(w,{}),e.jsx(o.Drawer,{anchor:"bottom",open:!0,className:"camera-drawer",onClose:(e,t)=>{},disablePortal:!0,children:e.jsx(k,{scanFailsError:u,onNext:()=>{a?.(),b()},setScanUniqueKey:d,gender:i,setIsVideoUploaded:m})})]}):e.jsx("div",{"data-scan-state":"scanning",children:e.jsx(C,{scanID:l,userDetails:n,setIsVideoUploaded:m,setScanFailsError:S,setScanStartTime:y,setScanUniqueKey:d})}):e.jsx(s.Modal,{variant:"portrait",config:T})};exports.BodyScan=n=>{const{config:a,onRetry:r,onScanStart:o,onCaptureComplete:c,onUploadStart:i,onUploadEnd:l,onMeasurementSocketStart:u,onMeasurementSocketClose:d,onIntermediateScanSuccess:p,onScanError:f,onScanSuccess:h,onCustomScanSuccess:g,onComplete:x,isError:v,isSuccess:S}=n,y={email:"",shopDomain:"",gender:"male",heightInCm:0,scanType:"",deviceFocalLength:0,deviceModelName:"",sourceTag:"",callbackUrl:null,...n.userDetails??{}},b=n.token??"",{gender:C,scanType:w,shopDomain:j,heightInCm:k,email:E,deviceFocalLength:N,deviceModelName:T,callbackUrl:I,sourceTag:L}=y,F=t.useMemo(()=>s.getSwanService(b),[b]),[M,_]=t.useState(!1),[P,A]=t.useState(!1),[$,R]=t.useState(!1),[U,O]=t.useState({disabled:!1,message:""}),[z,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),{isLandscape:ee}=s.usePortraitLock();s.usePosthogPageview();const te=t.useCallback(()=>{Q(s.generateUuid()),K(""),_(!1),q(!1)},[]),se=t.useRef(!1);t.useEffect(()=>{!ee||se.current||M||v||S||z||(s.speechService.stopAudio(),te()),se.current=ee},[ee,M,v,S,z,te]);const ne=()=>{Y(null),Q("")},ae=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:E}),A(!0),void p?.(e);h?.(e),A(!0),ne();const t=J;R(!0),s.handleScanTimeCapture({eventName:`${j}/measurement_success/fit-view`,scanID:t,status:"success",email:E}),X&&s.handleScanTimeCapture({eventName:`${j}/scan_completion_time`,scanID:t,status:"success",completionTime:s.getCurrentTimeInSeconds()-X,email:E})},[w,j,J]),re=e=>{R(!1),K(""),A(!1);let t=!1;F.measurement.handleMeasurementSocket({scanId:J,onPreopen:()=>{s.handleWebSocketCapture({eventName:`${j}/webSocket`,scanID:J,connection:"pre_open",type:"measurement_recommendation",email:E})},onOpen:()=>{u?.(),s.handleWebSocketCapture({eventName:`${j}/webSocket`,scanID:J,connection:"open",type:"measurement_recommendation",email:E})},onClose:()=>{d?.(),s.handleWebSocketCapture({eventName:`${j}/webSocket`,scanID:J,connection:"close",type:"measurement_recommendation",email:E}),t||(K("Connection closed. Please try again."),_(!1))},onError:e=>{var n;t=!0,n=e,f?.({...n,message:s.handleErrorMessage(n)}),ne(),R(!1),K(n),A(!1),s.handleScanTimeCapture({eventName:`${j}/measurement_failed/fit-view`,scanID:J,status:"failed",email:E,message:s.handleErrorMessage(n)}),X&&s.handleScanTimeCapture({eventName:`${j}/scan_completion_time`,scanID:J,status:"failed",completionTime:s.getCurrentTimeInSeconds()-X,email:E}),s.handleWebSocketCapture({eventName:`${j}/webSocket`,scanID:J,connection:"error",type:"measurement_recommendation",email:E})},onSuccess:e=>{t=!0,s.handleWebSocketCapture({eventName:`${j}/webSocket`,scanID:J,connection:"success",type:"measurement_recommendation",email:E}),ae(e)}})},oe=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:`${N}`,height:`${k}`,customer_store_url:j,clothes_fit:"0",scan_type:w,callback_url:I,source_tag:L});s.handleScanTimeCapture({eventName:`${j}/body_scan_meta_data`,scanID:J,email:E,data:JSON.stringify([...r,{fileSizeInMB:n,video_fps:a||0}])}),i?.();try{await F.fileUpload.uploadFileFrontend({file:e,arrayMetaData:r,scanId:J,email:E}),await F.fileUpload.setDeviceInfo({model:T,detection:"manual",gyro:Z,scanId:J}),console.log("video successfully uploaded"),q(!1),s.handleScanTimeCapture({eventName:`${j}/scan_success`,scanID:J,status:"success",email:E,data:JSON.stringify(r)}),s.handleScanTimeCapture({eventName:"scan finished",scanID:J,status:"success",email:E}),Y(s.getCurrentTimeInSeconds()),setTimeout(()=>{q(!0)},3e3)}catch(e){s.handleScanTimeCapture({eventName:"scan finished",scanID:J,status:"failed",email:E,message:s.handleErrorMessage(e)}),s.handleScanTimeCapture({eventName:`${j}/scan_failed`,scanID:J,status:"failed",email:E,message:s.handleErrorMessage(e),data:JSON.stringify(r)}),K(s.handleErrorMessage(e)),q(!1),f?.({...e,message:s.handleErrorMessage(e)}),ne()}finally{G(!1),l?.()}},[J,Z,i,l]),ce=t.useCallback(async()=>{if(+k<152.4||+k>213.36)return void f?.({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:E}),W(!1)):(W(!1),s.handleScanTimeCapture({eventName:`${j}/camera_activation`,scanID:J,status:"success",email:E})),O(e),K(""),q(!1)},[E,J,Q,j]);return t.useEffect(()=>{v||S||j&&ce()},[j,k,v,S]),t.useEffect(()=>{v||S||B&&j&&J&&re()},[B,j,J,v,S]),e.jsx("div",{"data-testid":"body-scan-root",children:e.jsx(s.LanguageContextProvider,{children:e.jsx(s.ConfigProvider,{config:a,children:e.jsx(m,{children:e.jsx(s.ParamsContext.Provider,{value:{userDetails:y,onRetry:r,onScanError:f,isError:v,isSuccess:S,onScanSuccess:h,gender:C,scanUniqueKey:J,scanFailsError:z,setScanUniqueKey:Q,setIsVideoUploaded:q,isMeasurementAvailable:$,isVideoUploadedCorrect:P,loading:V,showDeniedModal:U,uploadLoading:M,isLandscape:ee,setStartGyro:G,uploadScanFile:oe,setUploadLoading:_,resetScan:te,setScanFailsError:K,setScanStartTime:Y,onScanStart:o,onCaptureComplete:c,onCustomScanSuccess:g,onComplete:x,swan:F},children:e.jsx(s.ShadowRoot,{children:e.jsx(D,{})})})})})})})};
|
|
2
|
+
//# sourceMappingURL=BodyScan-BMTK6e-E.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{jsx as e,jsxs as t,Fragment as n}from"react/jsx-runtime";import r,{useState as a,useCallback as s,useEffect as o,createContext as c,useLayoutEffect as i,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,a as v,i as w,P as x,o as b,s as S,p as D,j as C,k as N,l as I,A as k,x as F,B as T,q as _,f as E,r as L,D as $,c as M,M as U,v as j,E as A,I as P,V as z,J as V,K as R,N as B,G as q,O as K,Q as O,R as W,h as H,n as J,w as G,T as Q,t as Y,C as X,y as Z}from"./Modal-CB_MHF7l.js";import ee from"clsx";import te from"react-webcam";import{X as ne}from"lucide-react";import{Dialog as re,Box as ae,Drawer as se}from"@mui/material";import oe from"video.js";const ce="DESKTOP",ie="TAB",le="MOBILE",de=c(void 0);function ue({children:t}){const[n,r]=a([window?.innerWidth,window?.innerHeight]),[s,c]=a(!1),d=()=>{r([window?.innerWidth,window?.innerHeight])};o(()=>{d()},[]),i(()=>(window.addEventListener("resize",d),()=>window.removeEventListener("resize",d)),[d]);let u=ce;n[0]>768&&n[0]<1024&&(u=ie),n[0]<768&&(u=le);const m=l(()=>({size:n,setSize:r,clearInputs:s,setClearInputs:c,media:u}),[n,s,u]);return e(de.Provider,{value:m,children:t})}var me=r.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 pe=r.memo(function({angle:n,countdown:r,isScanning:a,isInTargetRange:o,stabilityScore:c,children:i}){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(a)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)})`},[a,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`,[]),x=s((e=!1)=>{const t=y();return a?`text-[${g?.style?.angleDetector?.successAngleTextLightColor}]`:w(e,t)},[a,y]),b=s((e,t)=>t>70||e?g?.style?.angleDetector?.successAngleTextLightColor:g?.style?.angleDetector?.successAngleTextDarkColor,[]),S=s((e=!1)=>{const t=y();return a?g?.style?.angleDetector?.successAngleTextLightColor:b(e,t)},[a,y]),D=r;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},"data-testid":"level-screen","data-angle-state":a?"locked":o?"target":"adjusting",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!==D?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:D})}):t("div",a?{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"})}),i]}:{className:ee("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:ee("mt-[.5rem] text-center w-[180px] flex-col flex items-center absolute top-[60px]",x()),style:{color:S()},children:[e(me,{size:30}),t("p",{style:{fontFamily:g?.style?.base?.baseFontFamily||"Inter, sans-serif"},children:[" ",u?.(h.startLevelCheck),e("br",{})]})]})]}),null!==D&&e("div",{className:"absolute bottom-[8rem] text-center",children:e("div",{className:ee("text-sm font-medium px-4 py-1.5 bg-black/20 rounded-[9999px] mt-8",x()),style:{fontFamily:g?.style?.base?.baseFontFamily||"Inter, sans-serif",color:S()},children:u?.(h.leavePhone)})}),o&&null===D&&!a&&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===D&&!a&&e("div",{className:"absolute bottom-[5rem] text-center",children:t("div",{className:ee("text-[1.5rem] font-light",x()),style:{color:S()},children:[Math.round(n),"°"]})}),null===D&&!a&&e("div",{className:"absolute bottom-[2rem] text-center max-w-[20rem] mx-auto",children:e("div",{className:ee("text-[.75rem] opacity-50",x()),style:{fontFamily:g?.style?.base?.baseFontFamily||"Inter, sans-serif",color:S()},children:u?.(h.placePhoneUpright)})})]})});function fe({resetScan:n,loadingCam:r,onUserMedia:a,onPause:s,pause:o,onReScan:c,recordingStarted:i,startSendingVideoFrames:l,showPause:u,webcamRef:p,onUserMediaError:f,resetDetector:w,videoConstraints:x,webcamKey:b,faceDone:S,isScanning:D}){const{media:C}=d(de)||{},{translate:N}=d(m)||{};return t("div",{className:"App w-screen h-[100vh] relative common-ui-main","data-testid":"camera-scan","data-scan-phase":S?"spinning":i?"pose-detecting":D?"starting":"ready",children:[e("span",{onClick:()=>{n(),w()},className:"fixed right-[20px] top-[20px] z-[999]",children:e(ne,{className:"text-[#fff]"})}),e("div",{className:"w-full h-full overflow-hidden ",children:C===le&&e(te,{audio:!1,ref:p,screenshotQuality:1,videoConstraints:x,mirrored:!0,screenshotFormat:"image/jpeg",onUserMedia:a,onUserMediaError:f,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:[u&&e(g,{className:"!w-[180px] !h-[40px] !py-[0] mx-auto ",prefix:y,buttonText:N?.(h.pause),buttonFunc:s,btnSecondary:!0}),o?e("div",{children:e(g,{className:"!w-[180px] !h-[40px] !py-[0] mx-auto",buttonText:N?.(h.restart),buttonFunc:c,btnSecondary:!0})}):i?null:e(g,{"data-testid":"start-scan-btn",className:"!w-[180px] !h-[40px] !py-[0] mx-auto !bg-[#ffffff] !text-[#000000] "+(r?"!opacity-50":""),buttonText:N?.(h.startScan),buttonFunc:l,disabled:r})]}),e("audio",{id:"audioElement",crossOrigin:"anonymous",preload:"auto",style:{position:"absolute",zIndex:-99999},src:`${v}scanAudioInstructions/silence.mp3`})]})}let he,ge=null,ye=null,ve=null;let we=null;var xe=r.memo(function({setIsScanLocked:t,resetDetector:n,scanID:r,setIsVideoUploaded:c,setScanFailsError:i,setScanStartTime:m,setScanUniqueKey:p,userDetails:f}){const{gender:h,heightInCm:g,email:y,shopDomain:$}=f,M=u(null),U=u(null),j=u(null),[A,P]=a([]),[z,V]=a(!0),[R,B]=a(!1),[q,K]=a(!1),[O,W]=a(!0),[H,J]=a(!1),G=u(null),[Q,Y]=a(""),[X,Z]=a([]),[ee,te]=a(""),[ne,re]=a(!1),[ae,se]=a(!1),[oe,ce]=a(!1),[ie,le]=a([]),[de,ue]=a(!1),me=u(!0),{poseDetector:pe}=function(){const[e,t]=a(0),[n,r]=a(0),[s,c]=a(!1),i=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-DejsYGYM.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 r={runtime:"mediapipe",modelType:"full",solutionPath:"https://cdn.jsdelivr.net/npm/@mediapipe/pose"};try{ye=await ve.createDetector(ve.SupportedModels.BlazePose,r),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&&c(!0)}),()=>{d.current=!1};c(!0)},[]),o(()=>{l.current=e,e>6&&i.current<2&&(r(e=>e+1),t(0))},[e]),o(()=>{i.current=n},[n]),{poseDetector:async(e,n)=>{if(!ye||!d.current||!n?.current?.video)return;const r=n.current.video;if(!(r.readyState<2))try{const n=await ye.estimatePoses(r,{flipHorizontal:!1});if(!n||!n.length)return;const a=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!==i.current||p(a)||t(e=>e+1),1===i.current&&p(a)&&t(e=>e+1),2===i.current&&e()}catch(e){console.error("Pose detection error:",e)}},isLoaded:s,spinPhase:n,resetDetector:()=>{i.current=0,l.current=0,t(0),r(0)},retryLoading:async()=>{ye||ge||(ge=m(),await ge&&d.current&&c(!0))}}}(),xe=u(!0),be=u(!1),Se=u(0),De=u(0),Ce=u(!1),Ne=u(!1),Ie=u(!1),ke=u(()=>{}),Fe=u(()=>{}),Te=u(null),[_e,Ee]=a([]),[Le,$e]=a(0),[Me,Ue]=a(w),{setStartGyro:je,uploadScanFile:Ae,setUploadLoading:Pe,swan:ze,onScanStart:Ve,onCaptureComplete:Re}=d(x),Be=()=>{be.current=!1,clearTimeout(he),G.current&&clearTimeout(G.current),p(E()),i(""),Pe?.(!1),P([]),j.current=null,V(!0),B(!1),K(!1),W(!0),J(!1),G.current=null,Y(""),Z([]),te(""),re(!ne),je(!1),S.stopAudio(),se(!1),ce(!1),Se.current=0,De.current=0,Ce.current=!1,Ie.current=!1,null!==U.current&&U.current.stop(),ie.forEach(e=>{U.current&&U.current.removeEventListener("dataavailable",e)}),le([]),me.current=!0,ue(!1),c(!1),M.current?.stream&&V(!1)},qe=s(()=>{setTimeout(()=>{V(!1)},1e3)},[]),Ke=s(e=>{if(console.log("camera error",e),Me===w)return Ue(b),void $e(e=>e+1);V(!1)},[Me]),Oe=s(()=>{me.current=!1,ce(!0),ue(!1),G.current&&clearTimeout(G.current),U.current&&U.current.pause(),S.stopAudio(),ze.poseDetection.disconnect(),D.capture(`${$}/pose_detection_disconnected`,{scanID:r,email:y,id:Te.current,reason:"pause"}),Se.current=0,De.current=0,Ce.current=!1,Ie.current=!1,U.current&&U.current.stop(),ie.forEach(e=>{U.current&&U.current.removeEventListener("dataavailable",e)}),le([]),clearTimeout(he)},[U,ie,S,me]),We=l(()=>C(),[]),He=N(_e),Je=I(He),Ge=s(async()=>{me.current=!0,await S.playAudio(`${v}SpotOn.mp3`),ce(!1),ue(!1),G.current&&clearTimeout(G.current),B(!1)},[G,S]),Qe=s(async()=>{if(!Ne.current&&!Te.current){Ne.current=!0;try{Te.current=await ze.poseDetection.connect(),D.capture(`${$}/pose_detection_connected`,{scanID:r,email:y,id:Te.current})}catch(e){console.log(e,"while connecting websocket"),D.capture(`${$}/pose_detection_connect_failed`,{scanID:r,email:y,error:String(e)})}finally{Ne.current=!1}}},[r,$,y]),Ye=s(async()=>{k({eventName:`${$}/rescan`,email:y,scanID:r,height:g,gender:h,status:!1}),me.current=!1,ze.poseDetection.disconnect(),D.capture(`${$}/pose_detection_disconnected`,{scanID:r,email:y,id:Te.current,reason:"rescan"}),Te.current=null,Be(),await Qe(),Fe.current()},[Qe,r,y]),Xe=s(({data:e})=>{e&&e.size>0&&me.current&&(P(t=>t.concat(e)),!be.current&&M.current&&(be.current=!0,pe(()=>{Ge(),F({eventName:`${$}/tensorFlow`,scanID:r,email:y,message:"recording stopped by tensorflow "})},M)))},[Ge,F,$,r,y,M]),Ze=s(async()=>{const e=X[X.length-1];e&&me.current&&(await S.playAudio(v+e),me.current&&(he=setTimeout(Ze,2e3)))},[X,me]),et=s(()=>{U&&U.current&&U.current.stop(),B(!0);try{if(M&&M.current&&M.current.stream){const e=M.current.stream.getVideoTracks()[0];if(e){const t=e.getSettings();j.current=t.frameRate||null}const t={videoBitsPerSecond:15e5};_e[0]&&(t.mimeType=_e[0]),U.current=new MediaRecorder(M.current.stream,t),U.current.addEventListener("dataavailable",Xe),U.current.addEventListener("stop",()=>{W(!0)}),le([...ie,Xe]),U.current.start(1e3),W(!1)}}catch(e){console.log("error while using media recorder",e)}},[M,_e,Xe,ie]),tt=s(async()=>{G.current&&clearTimeout(G.current),et(),me.current&&(G.current=setTimeout(async()=>{me.current&&(await S.playAudio(`${v}SpotOn.mp3`),B(!1))},15e3)),K(!0),me.current&&await S.playAudio(`${v}Spin.mp3`)},[et,me,S]);o(()=>{ke.current=tt},[tt]);const nt=s(({data:e})=>{const t=ze.poseDetection.connected();e.size>0&&t&&(Ce.current||(Ce.current=!0,ze.poseDetection.poseStatus(async e=>{if(e&&e.audio&&e.audio.length>0){const t=document.querySelector("#audioElement");D.capture(`${$}/pose_instruction_received`,{scanID:r,email:y,audio:e.audio,status:e.status,sid:e.sid,counter:Se.current,consecutiveFalse:De.current,type:"body_scan_instruction"}),!0===e.status&&e.sid===Te.current?(De.current=0,Se.current<2?(Se.current+=1,1!==Se.current||Ie.current?2===Se.current&&t?.paused&&S.playAudio(v+e.audio):(Ie.current=!0,S.stopAudio(),await S.playAudio(v+e.audio))):(te(e.audio),clearTimeout(he),ze.poseDetection.disconnect(),D.capture(`${$}/pose_detection_disconnected`,{scanID:r,email:y,id:Te.current,reason:"pose_confirmed"}),Ce.current=!1,setTimeout(()=>ke.current(),1e3))):(De.current+=1,De.current>=3&&(Se.current=0,Ie.current=!1),!t?.paused||we&&we?.audioName===e.audio?we?.audioName===e.audio&&t?.paused&&(we&&we.no_of_times_skipped>=we.skipCount?(we.no_of_times_skipped=0,S.playAudio(v+e.audio)):we&&(we.no_of_times_skipped+=1)):(we={skipCount:2,no_of_times_skipped:0,audioName:e.audio},S.playAudio(v+e.audio)))}})),M?.current&&null!==M.current.getScreenshot()&&ze.poseDetection.videoEmit({image:M.current.getScreenshot()||"",scanId:r}))},[M,r,ze,S,$,y]),rt=s(async()=>{J(!0),je(!0),Ve?.(),xe.current&&(xe.current=!1,F({eventName:"scan started",scanID:r,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),B(!0),se(!0),ue(!0),qe());try{if(M&&M.current&&M.current.stream&&me.current){const e=M.current.stream.getVideoTracks()[0];if(e){const t=e.getSettings();j.current=t.frameRate||null}const t={videoBitsPerSecond:15e5};_e[0]&&(t.mimeType=_e[0]),me.current&&(U.current=new MediaRecorder(M.current.stream,t)),me.current&&U.current&&U.current.addEventListener("dataavailable",nt),le([...ie,nt]),U.current&&U.current.start(1e3),W(!1),me.current&&(he=setTimeout(Ze,2e3))}}catch(e){console.log("error ----------",e)}},[M,_e,nt,ie,Ze,me,Ve]);return o(()=>($&&(t(!0),Qe()),()=>{const e=Te.current;Te.current=null,e&&(ze.poseDetection.disconnect(),D.capture(`${$}/pose_detection_disconnected`,{scanID:r,email:y,id:e,reason:"unmount"})),ie.forEach(e=>{U?.current?.removeEventListener("dataavailable",e)})}),[$]),o(()=>{X.push(Q)},[Q]),o(()=>{Z([])},[ee]),o(()=>{const e=A.length&&A.length>0;O||!e||R||!me.current||oe||U&&U.current&&(R||U.current.stop())},[O,R,A,oe]),o(()=>{const e=A.length&&A.length>0;if(O&&e&&!R&&U&&U.current&&me.current&&!oe&&!R){const e=new File(A,`${r}.${Je}`,{type:He});Re?.(),Pe?.(!0),i(""),Ae?.(e,j.current)}},[O,R,A,oe,U,me]),o(()=>{Fe.current=rt},[rt]),o(()=>{const e=_(We,L);Ee(e)},[We]),o(()=>{Be()},[]),e(fe,{resetDetector:n,resetScan:Be,loadingCam:z,onPause:Oe,showRestart:ae,pause:oe,onReScan:Ye,recordingStarted:R,isScanning:H,startSendingVideoFrames:rt,faceDone:q,stopRecording:Ge,showPause:de,webcamRef:M,onUserMedia:qe,onUserMediaError:Ke,videoConstraints:Me,webcamKey:Le})});function be({scanID:t,userDetails:n,setIsVideoUploaded:r,setScanFailsError:s,setScanStartTime:c,setScanUniqueKey:i}){const[l,d]=a(90),[m,p]=a(0),[f,h]=a(null),[g,y]=a(!1),[v,w]=a(0),x=u([]),[b,S]=a(!1),D=l-m,C=D>=80&&D<=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(x.current=[...x.current.slice(-4),D],x.current.length>=5){const e=Math.max(...x.current)-Math.min(...x.current);w(C&&e<2?e=>Math.min(100,e+10):e=>Math.max(0,e-20))}C||null===f&&!g||I()},[D,C,f,g]),o(()=>{v>=100&&null===f&&!g&&N(),v<50&&null!==f&&I()},[v,f,g]);const N=()=>{h(3);const e=setInterval(()=>{h(t=>null===t||t<=1?(clearInterval(e),y(!0),null):t-1)},1e3)},I=()=>{h(null),b||y(!1)};return e(pe,{angle:D,countdown:f,isScanning:g,isInTargetRange:C,stabilityScore:v,children:g&&e(xe,{setIsScanLocked:S,resetDetector:()=>{d(90),p(0),h(null),y(!1),w(0),S(!1),x.current=[]},scanID:t,userDetails:n,setIsVideoUploaded:r,setScanFailsError:s,setScanStartTime:c,setScanUniqueKey:i})})}function Se({setShowDrawer:t,config:n,loader:r}){const[c,i]=a({disabled:!1,message:""}),[l,d]=a(!0),m=u(null),p=s(async()=>{const e=await $();i(e),d(!1)},[]);return o(()=>{p()},[]),l?e(M,{url:r,loaderType:"black"}):c?.disabled?e(U,{config:n,message:c?.message}):e(te,{audio:!1,ref:m,screenshotQuality:1,videoConstraints:j,mirrored:!0,onUserMedia:()=>t?.(!0),screenshotFormat:"image/jpeg",style:{position:"relative",top:0,bottom:0,zIndex:0,width:"100%",height:"100%",objectFit:"cover"}})}function De({link:t,onReady:n,wrapperClassName:r="[&_video]:rounded-t-[20px] w-full h-full"}){const a=u(null),s=u(null);let c={autoplay:!0,controls:!1,responsive:!0,fluid:!0,muted:!0,navigationUI:"hide",preload:"metadata",poster:A};return o(()=>{if(!s.current&&t&&a?.current){const e=oe(a.current,{...c});e.ready(()=>{s.current=e;const r={...c,sources:[{src:t,type:"application/x-mpegURL"}]};e.autoplay(r.autoplay),e.src(r.sources),n?.(e)})}},[t,a]),o(()=>{const e=s.current;return()=>{e&&!e.isDisposed()&&(e.dispose(),s.current=null)}},[s]),e("div",{className:r,children:e("video",{ref:a,muted:!0,className:"video-js",playsInline:!0,onDrag:e=>e.preventDefault()})})}function Ce({scanFailsError:r,onNext:s,gender:o,setScanUniqueKey:c,setIsVideoUploaded:i}){const{translate:l}=d(m)||{},u=p(),[y,v]=a(!1),w=()=>{v(!y)};return t(n,{children:[t("div",{"data-testid":"scan-error-message",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:r&&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:P(r)}),e("img",{className:"my-[0.5rem] aspect-[2/1.4] w-full object-cover",onClick:w,src:z[o],alt:"icon"})]})}),r&&e("div",{className:"p-[1rem] flex gap-[0.5rem]",children:e(g,{"data-testid":"scan-again-btn",disabled:!1,buttonText:l?.(h.scanAgain),className:"!shadow-none",buttonFunc:()=>{s?s?.():c?.(E()),i?.(!1)}})})]}),y&&t(re,{className:"w-screen h-screen video-modal",onClose:w,open:y,children:[e("div",{className:"flex justifyEnd ",children:e("span",{className:"closeBtn",onClick:w,children:e(ne,{className:"absolute right-[8px] top-[8px] text-white z-[9]"})})}),e("div",{className:"aspect-video object-cover rounded-[20px] ",children:e(De,{link:o?V[o].PRE_LINK:V.male.PRE_LINK,wrapperClassName:"w-screen h-screen fixed top-[0] left-[0]"})})]})]})}function Ne({scanId:n,userDetails:r,config:c,isVideoUploadedCorrect:i,isMeasurementAvailable:l,onComplete:u,isSuccess:p,onCustomScanSuccess:y,swan:v}){const{gender:w,shopDomain:x,heightInCm:b,deviceFocalLength:S,userName:C,email:N,scanType:I}=r||{},k=[K,O,W].includes(I??""),[F,T]=a(!0),_=s(async()=>{try{k&&(await(v?.auth.addUser({scanId:n,email:N,name:C,gender:w,height:b})),y?.()),D.capture(x??"",{scanID:n,email:N,height:b,focalLength:S,clothesFit:"0",gender:w})}catch(e){console.log(e)}},[k]),{translate:E}=d(m)||{};o(()=>{(i||l)&&_()},[i,l]);const L=p||i||l;return e(ae,{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(Se,{loader:c?.loader,setShowDrawer:T}),e(se,{open:F,onClose:(e,t)=>{},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:c?.style?.base?.backgroundColor},children:t("div",{className:"w-full h-full flex flex-col",children:[e(f,{title:E?.(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?R:B,type:"video/mp4"})})}),L&&e(g,{className:"!w-[180px] mx-auto",buttonText:E?.(h.next),buttonFunc:()=>{u?.()}})]})})})]})})}const Ie=()=>{const{userDetails:n,onRetry:r,isError:a,isSuccess:s,gender:o,scanUniqueKey:c,scanFailsError:i,setScanUniqueKey:l,setIsVideoUploaded:u,isMeasurementAvailable:m,isVideoUploadedCorrect:f,loading:h,showDeniedModal:g,uploadLoading:y,setScanFailsError:v,setScanStartTime:w,resetScan:b,onCustomScanSuccess:S,swan:D,onComplete:C}=d(x),N=p();return a?t("div",{"data-scan-state":"error",children:[e(Se,{}),e(se,{anchor:"bottom",open:!0,className:"camera-drawer",onClose:(e,t)=>{},children:e(Ce,{scanFailsError:!0,onNext:r,gender:o})})]}):s?e("div",{"data-scan-state":"success",children:e(Ne,{isSuccess:!0,onComplete:C})}):h?e("div",{"data-scan-state":"loading",className:"flex top-0 !mt-0 left-0 z-[999] absolute justify-center items-center w-full h-full",style:{background:N?.style?.base?.backgroundColor},children:e(M,{url:N?.loader,loaderType:"black"})}):g.disabled?e("div",{"data-scan-state":"camera-denied",children:e(U,{})}):y||i||m||f?(y||m||f)&&!i?e("div",{"data-scan-state":"processing",children:e(Ne,{scanId:c,isMeasurementAvailable:m,userDetails:n,isVideoUploadedCorrect:f,onCustomScanSuccess:S,swan:D,onComplete:C})}):t("div",{"data-scan-state":"error-retry",children:[e(Se,{}),e(se,{anchor:"bottom",open:!0,className:"camera-drawer",onClose:(e,t)=>{},children:e(Ce,{scanFailsError:i,onNext:()=>{r?.(),b()},setScanUniqueKey:l,gender:o,setIsVideoUploaded:u})})]}):e("div",{"data-scan-state":"scanning",children:e(be,{scanID:c,userDetails:n,setIsVideoUploaded:u,setScanFailsError:v,setScanStartTime:w,setScanUniqueKey:l})})},ke=t=>{const{config:n,onRetry:r,onScanStart:c,onCaptureComplete:i,onUploadStart:d,onUploadEnd:u,onMeasurementSocketStart:m,onMeasurementSocketClose:p,onIntermediateScanSuccess:f,onScanError:h,onScanSuccess:g,onCustomScanSuccess:y,onComplete:v,isError:w,isSuccess:b}=t,S={email:"",shopDomain:"",gender:"male",heightInCm:0,scanType:"",deviceFocalLength:0,deviceModelName:"",sourceTag:"",callbackUrl:null,...t.userDetails??{}},D=t.token??"",{gender:C,scanType:N,shopDomain:I,heightInCm:k,email:_,deviceFocalLength:L,deviceModelName:M,callbackUrl:U,sourceTag:j}=S,A=l(()=>H(D),[D]),[z,V]=a(!1),[R,B]=a(!1),[q,K]=a(!1),[O,W]=a({disabled:!1,message:""}),[ee,te]=a(""),[ne,re]=a(!1),[ae,se]=a(!0),[oe,ce]=a(!1),[ie,le]=a(""),[de,me]=a(T()),{gyroData:pe}=function(e){const[t,n]=a([]),[r,c]=a(!1),i=s(e=>{try{const{alpha:t,beta:r,gamma:a}=e;n(e=>[...e,{alpha:t?.toString()||void 0,beta:r?.toString()||void 0,gamma:a?.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()?c(!0):console.warn("Device orientation permission denied.")}catch(e){console.error("Error requesting device orientation permission:",e)}else c(!0)},[]);return o(()=>(e&&r?window.addEventListener("deviceorientation",i):n([]),()=>{window.removeEventListener("deviceorientation",i)}),[e,r,i]),o(()=>{e&&l()},[e,l]),{gyroData:t}}(oe);J();const fe=s(()=>{le(E()),te(""),V(!1),re(!1)},[]),he=()=>{me(null),le("")},ge=s(async e=>{if(e&&"success"===e?.scanStatus&&"intermediate"===e?.resultType&&200===e?.code)return F({eventName:`${I}/measurement_success/intermediate`,scanID:ie,status:"success",email:_}),B(!0),void f?.(e);g?.(e),B(!0),he();const t=ie;K(!0),F({eventName:`${I}/measurement_success/fit-view`,scanID:t,status:"success",email:_}),de&&F({eventName:`${I}/scan_completion_time`,scanID:t,status:"success",completionTime:T()-de,email:_})},[N,I,ie]),ye=e=>{K(!1),te(""),B(!1),A.measurement.handleMeasurementSocket({scanId:ie,onPreopen:()=>{Z({eventName:`${I}/webSocket`,scanID:ie,connection:"pre_open",type:"measurement_recommendation",email:_})},onOpen:()=>{m?.(),Z({eventName:`${I}/webSocket`,scanID:ie,connection:"open",type:"measurement_recommendation",email:_})},onClose:()=>{p?.(),Z({eventName:`${I}/webSocket`,scanID:ie,connection:"close",type:"measurement_recommendation",email:_})},onError:e=>{var t;t=e,h?.({...t,message:P(t)}),he(),K(!1),te(t),B(!1),F({eventName:`${I}/measurement_failed/fit-view`,scanID:ie,status:"failed",email:_,message:P(t)}),de&&F({eventName:`${I}/scan_completion_time`,scanID:ie,status:"failed",completionTime:T()-de,email:_}),Z({eventName:`${I}/webSocket`,scanID:ie,connection:"error",type:"measurement_recommendation",email:_})},onSuccess:e=>{Z({eventName:`${I}/webSocket`,scanID:ie,connection:"success",type:"measurement_recommendation",email:_}),ge(e)}})},ve=s(async(e,t)=>{const n=Number((e.size/1048576).toFixed(2)),r=null!=t?t:await G(e),a=Q({gender:C,focal_length:`${L}`,height:`${k}`,customer_store_url:I,clothes_fit:"0",scan_type:N,callback_url:U,source_tag:j});F({eventName:`${I}/body_scan_meta_data`,scanID:ie,email:_,data:JSON.stringify([...a,{fileSizeInMB:n,video_fps:r||0}])}),d?.();try{await A.fileUpload.uploadFileFrontend({file:e,arrayMetaData:a,scanId:ie,email:_}),await A.fileUpload.setDeviceInfo({model:M,detection:"manual",gyro:pe,scanId:ie}),console.log("video successfully uploaded"),re(!1),F({eventName:`${I}/scan_success`,scanID:ie,status:"success",email:_,data:JSON.stringify(a)}),F({eventName:"scan finished",scanID:ie,status:"success",email:_}),me(T()),setTimeout(()=>{re(!0)},3e3)}catch(e){F({eventName:"scan finished",scanID:ie,status:"failed",email:_,message:P(e)}),F({eventName:`${I}/scan_failed`,scanID:ie,status:"failed",email:_,message:P(e),data:JSON.stringify(a)}),te(P(e)),re(!1),h?.({...e,message:P(e)}),he()}finally{ce(!1),u?.()}},[ie,pe,d,u]),we=s(async()=>{if(+k<152.4||+k>213.36)return void h?.({message:"Height must be between 152.4cm (5ft) and 213.36cm (7ft)"});const e=await $();e.disabled?(F({eventName:`${I}/camera_activation`,scanID:ie,status:"failed",email:_}),se(!1)):(se(!1),F({eventName:`${I}/camera_activation`,scanID:ie,status:"success",email:_})),W(e),te(""),re(!1)},[_,ie,le,I]);return o(()=>{w||b||I&&we()},[I,k,w,b]),o(()=>{w||b||ne&&I&&ie&&ye()},[ne,I,ie,w,b]),e("div",{"data-testid":"body-scan-root",children:e(Y,{children:e(X,{config:n,children:e(ue,{children:e(x.Provider,{value:{userDetails:S,onRetry:r,onScanError:h,isError:w,isSuccess:b,onScanSuccess:g,gender:C,scanUniqueKey:ie,scanFailsError:ee,setScanUniqueKey:le,setIsVideoUploaded:re,isMeasurementAvailable:q,isVideoUploadedCorrect:R,loading:ae,showDeniedModal:O,uploadLoading:z,setStartGyro:ce,uploadScanFile:ve,setUploadLoading:V,resetScan:fe,setScanFailsError:te,setScanStartTime:me,onScanStart:c,onCaptureComplete:i,onCustomScanSuccess:y,onComplete:v,swan:A},children:e(Ie,{})})})})})})};export{ke as B};
|
|
2
|
+
//# sourceMappingURL=BodyScan-BQri8pAO.js.map
|