@swan-admin/swan-dev-web-component 0.1.0-alpha.1774966558 → 0.1.0-alpha.1775220535

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/dist/BodyScan-B6V25JbX.js +2 -0
  2. package/dist/BodyScan-BSI8dvZ-.js +2 -0
  3. package/dist/BodyScan-BVsw81qu.js +2 -0
  4. package/dist/BodyScan-BkOwkvRJ.js +2 -0
  5. package/dist/BodyScan-By4r-brw.js +2 -0
  6. package/dist/BodyScan-C4Yn1avh.js +2 -0
  7. package/dist/BodyScan-CAMSgtRm.js +2 -0
  8. package/dist/BodyScan-CUm_fWlg.js +2 -0
  9. package/dist/BodyScan-CV-zZKgh.js +2 -0
  10. package/dist/BodyScan-CV8uk40Q.js +2 -0
  11. package/dist/BodyScan-ChvQMvV4.js +2 -0
  12. package/dist/BodyScan-Cs6MPGYL.js +2 -0
  13. package/dist/BodyScan-Cwr26I6g.js +2 -0
  14. package/dist/BodyScan-D3NN1Hhi.js +2 -0
  15. package/dist/BodyScan-D477Nuqy.js +2 -0
  16. package/dist/BodyScan-DhXVj8MZ.js +2 -0
  17. package/dist/BodyScan-EMR2t8Pq.js +2 -0
  18. package/dist/BodyScan-N5nYk58z.js +2 -0
  19. package/dist/BodyScan-X4TehMmJ.js +2 -0
  20. package/dist/BodyScan-aeNyFIec.js +2 -0
  21. package/dist/BodyScan-dU9HPwU7.js +2 -0
  22. package/dist/BodyScan-eLGCDYF7.js +2 -0
  23. package/dist/BodyScan-uG4zjzcO.js +2 -0
  24. package/dist/BodyScan-vR1X64Wp.js +2 -0
  25. package/dist/FaceScan-0Uz-kLFY.js +2 -0
  26. package/dist/FaceScan-B2_ASC1P.js +2 -0
  27. package/dist/FaceScan-BBWBdmuV.js +2 -0
  28. package/dist/FaceScan-BSlMDnLP.js +2 -0
  29. package/dist/FaceScan-BTUX1xQ-.js +2 -0
  30. package/dist/FaceScan-BX9UdzVe.js +2 -0
  31. package/dist/FaceScan-BY4FLRPo.js +2 -0
  32. package/dist/FaceScan-B_zUY10U.js +2 -0
  33. package/dist/FaceScan-BjfLOZbM.js +2 -0
  34. package/dist/FaceScan-Bt_0cmwm.js +2 -0
  35. package/dist/FaceScan-C4PZeLFt.js +2 -0
  36. package/dist/FaceScan-C7JB-pTz.js +2 -0
  37. package/dist/FaceScan-CTX-Lz9l.js +2 -0
  38. package/dist/FaceScan-CV5kEf_o.js +2 -0
  39. package/dist/FaceScan-CcT0QDJa.js +2 -0
  40. package/dist/FaceScan-Ck0y4-k7.js +2 -0
  41. package/dist/FaceScan-CnTQuv6w.js +2 -0
  42. package/dist/FaceScan-CqmWMoK2.js +2 -0
  43. package/dist/FaceScan-DIWKCqFy.js +2 -0
  44. package/dist/FaceScan-DQdlSt1q.js +2 -0
  45. package/dist/FaceScan-DflumKTC.js +2 -0
  46. package/dist/FaceScan-Dxv5chDy.js +2 -0
  47. package/dist/FaceScan-DycDNnyb.js +2 -0
  48. package/dist/FaceScan-R64B9cu-.js +2 -0
  49. package/dist/FaceScan-h5TxW1xv.js +2 -0
  50. package/dist/FaceScan-lW-C_LdI.js +2 -0
  51. package/dist/LoadingScreen-B4IgJfiH.js +2 -0
  52. package/dist/LoadingScreen-BDw0L2WP.js +2 -0
  53. package/dist/LoadingScreen-BHX14qsW.js +2 -0
  54. package/dist/LoadingScreen-BsIi48_Z.js +2 -0
  55. package/dist/LoadingScreen-C9fIKLpS.js +2 -0
  56. package/dist/LoadingScreen-CXfophtU.js +2 -0
  57. package/dist/LoadingScreen-CetEYktg.js +2 -0
  58. package/dist/LoadingScreen-CjoeOan2.js +2 -0
  59. package/dist/LoadingScreen-DG82-2pH.js +2 -0
  60. package/dist/LoadingScreen-DTVfoOWk.js +2 -0
  61. package/dist/LoadingScreen-DXYShatU.js +2 -0
  62. package/dist/LoadingScreen-LVF7cmU5.js +2 -0
  63. package/dist/LoadingScreen-MOGkyGvK.js +2 -0
  64. package/dist/LoadingScreen-vRwqPBLg.js +2 -0
  65. package/dist/Modal-6Y88Up1w.js +2 -0
  66. package/dist/Modal-B_UR_mwU.js +2 -0
  67. package/dist/bodyScan.js +1 -1
  68. package/dist/bodyScan.mjs +1 -1
  69. package/dist/faceScan.js +1 -1
  70. package/dist/faceScan.mjs +1 -1
  71. package/dist/index.css +1 -1
  72. package/dist/index.js +1 -1
  73. package/dist/index.mjs +1 -1
  74. package/dist/pose-detection.esm-2mkM0o4k.js +18 -0
  75. package/dist/pose-detection.esm-LvkS7dAF.js +18 -0
  76. package/package.json +1 -1
@@ -0,0 +1,2 @@
1
+ "use strict";var e=require("react/jsx-runtime"),t=require("react"),s=require("./LoadingScreen-C9fIKLpS.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,[]),S=t.useCallback((e=!1)=>{const t=m();return o?d?.style?.angleDetector?.successAngleTextLightColor:x(e,t)},[o,m]),v=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},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!==v?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 ${S()}`},children:e.jsx("div",{className:`text-[3rem] font-bold text-[${S()}]`,style:{fontFamily:d?.style?.base?.baseFontFamily||"Inter, sans-serif",color:S()},children:v})}):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 ${S()}`},children:[e.jsx("div",{className:`h-[1rem] w-[1rem] rounded-[9999px] bg-[${S()}]/80`,style:{backgroundColor:`${S()}B3`}}),e.jsxs("div",{className:n("mt-[.5rem] text-center w-[180px] flex-col flex items-center absolute top-[60px]",g()),style:{color:S()},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!==v&&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:S()},children:u?.(s.LanguageKeys.leavePhone)})}),c&&null===v&&!o&&e.jsx("div",{className:"absolute bottom-[8rem] w-[12rem]",children:e.jsx("div",{className:`h-[.375rem] w-full bg-[${S()}]/20 rounded-[9999px] overflow-hidden`,style:{backgroundColor:`${S()}33`},children:e.jsx("div",{className:`h-full bg-[${S()}]/70 transition-all duration-300 rounded-[9999px]`,style:{width:`${a}%`,backgroundColor:`${S()}B3`}})})}),null===v&&!o&&e.jsx("div",{className:"absolute bottom-[5rem] text-center",children:e.jsxs("div",{className:n("text-[1.5rem] font-light",g()),style:{color:S(),fontFamily:d?.style?.base?.baseFontFamily||"Inter, sans-serif"},children:[Math.round(a),"°"]})}),null===v&&!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:S()},children:u?.(s.LanguageKeys.placePhoneUpright)})})]})});function h({resetScan:n,loadingCam:o,onUserMedia:c,onPause:i,pause:l,recordingStarted:m,startSendingVideoFrames:p,showPause:f,webcamRef:h,onUserMediaError:g,resetDetector:x,videoConstraints:S,webcamKey:v}){const{media:y}=t.useContext(d)||{},{translate:b}=t.useContext(s.LanguageContext)||{};return e.jsxs("div",{className:"App w-screen h-[100vh] relative common-ui-main",children:[e.jsx("span",{onClick:()=>{n(),x()},className:"fixed right-[20px] top-[20px] z-[999]",children:e.jsx(r.X,{className:"text-[#fff]"})}),e.jsx("div",{className:"w-full h-full overflow-hidden ",children:y===u&&e.jsx(a,{audio:!1,ref:h,screenshotQuality:1,videoConstraints:S,mirrored:!0,screenshotFormat:"image/jpeg",onUserMedia:c,onUserMediaError:g,style:{position:"fixed",top:0,bottom:0,zIndex:0,width:"100%",height:"100%",objectFit:"cover"}},v)}),e.jsxs("div",{className:"fixed bottom-[30px] w-full z-[999] flex flex-col gap-4 items-center justify-center",children:[f&&e.jsx(s.SpecificButton,{className:"!w-[180px] !h-[40px] !py-[0] mx-auto ",prefix:s.pauseIcon,buttonText:b?.(s.LanguageKeys.pause),buttonFunc:i,btnSecondary:!0}),l?e.jsx("div",{children:e.jsx(s.SpecificButton,{className:"!w-[180px] !h-[40px] !py-[0] mx-auto",buttonText:b?.(s.LanguageKeys.restart),buttonFunc:n,btnSecondary:!0})}):m?null:e.jsx(s.SpecificButton,{className:"!w-[180px] !h-[40px] !py-[0] mx-auto !bg-[#ffffff] !text-[#000000] "+(o?"!opacity-50":""),buttonText:b?.(s.LanguageKeys.startScan),buttonFunc:p,disabled:o})]}),e.jsx("audio",{id:"audioElement",crossOrigin:"anonymous",preload:"auto",style:{position:"absolute",zIndex:-99999},src:`${s.voiceOverAssetsPath}scanAudioInstructions/silence.mp3`})]})}let g=null,x=null,S=null;let v,y=null,b=null;var C=t.memo(function({setIsScanLocked:n,resetDetector:a,scanID:r,setIsVideoUploaded:o,setScanFailsError:c,setScanStartTime:i,setScanUniqueKey:l,userDetails:u}){const{gender:d,heightInCm:m,email:p,shopDomain:f}=u,C=t.useRef(null),w=t.useRef(null),j=t.useRef(null),[k,N]=t.useState([]),[E,D]=t.useState(!0),[T,I]=t.useState(!1),[L,F]=t.useState(!1),[M,P]=t.useState(!0),[_,A]=t.useState(!1),$=t.useRef(null),[R,U]=t.useState(""),[O,z]=t.useState([]),[K,q]=t.useState(""),[B,V]=t.useState(!1),[W,H]=t.useState(!1),[G,J]=t.useState(!1),[Q,X]=t.useState([]),[Y,Z]=t.useState(!1),ee=t.useRef(!0),{poseDetector:te}=function(){const[e,s]=t.useState(0),[n,a]=t.useState(0),[r,o]=t.useState(!1),c=t.useRef(0),i=t.useRef(0),l=t.useRef(!0);async function u(){if("undefined"==typeof window||"undefined"==typeof navigator)return!1;try{console.log("Starting TensorFlow preload...");const[e,t,s]=await Promise.all([Promise.resolve().then(function(){return require("./pose-detection.esm-yM_Igca-.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{x=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),x=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),g=null,!1}}function d(e){return!(!e||0===e.length)&&22===e.filter(e=>e[2]>.7).length}return t.useEffect(()=>{if(l.current=!0,!x)return g||(g=u()),g.then(e=>{e&&l.current&&o(!0)}),()=>{l.current=!1};o(!0)},[]),t.useEffect(()=>{i.current=e,e>6&&c.current<2&&(a(e=>e+1),s(0))},[e]),t.useEffect(()=>{c.current=n},[n]),{poseDetector:async(e,t)=>{if(!x||!l.current||!t?.current?.video)return;const n=t.current.video;if(!(n.readyState<2))try{const t=await x.estimatePoses(n,{flipHorizontal:!1});if(!t||!t.length)return;const a=t[0].keypoints.slice(11).map(e=>[e.x>0&&e.x<720?e.x:-1,e.y>0&&e.y<1280?e.y:-1,e.score??0]);0!==c.current||d(a)||s(e=>e+1),1===c.current&&d(a)&&s(e=>e+1),2===c.current&&e()}catch(e){console.error("Pose detection error:",e)}},isLoaded:r,spinPhase:n,resetDetector:()=>{c.current=0,i.current=0,s(0),a(0)},retryLoading:async()=>{x||g||(g=u(),await g&&l.current&&o(!0))}}}(),se=t.useRef(!0),ne=t.useRef(!1),ae=t.useRef(0),re=t.useRef(0),oe=t.useRef(!1),ce=t.useRef(!1),ie=t.useRef(()=>{}),[le,ue]=t.useState([]),[de,me]=t.useState(0),[pe,fe]=t.useState(s.videoConstraintsExact),{setStartGyro:he,uploadScanFile:ge,setUploadLoading:xe,swan:Se,onScanStart:ve,onCaptureComplete:ye}=t.useContext(s.ParamsContext),be=()=>{ne.current=!1,clearTimeout(v),$.current&&clearTimeout($.current),l(s.generateUuid()),c(""),xe?.(!1),N([]),j.current=null,D(!0),I(!1),F(!1),P(!0),A(!1),$.current=null,U(""),z([]),q(""),V(!B),he(!1),s.speechService.stopAudio(),H(!1),J(!1),ae.current=0,re.current=0,oe.current=!1,ce.current=!1,null!==w.current&&w.current.stop(),Q.forEach(e=>{w.current&&w.current.removeEventListener("dataavailable",e)}),X([]),ee.current=!0,Z(!1),o(!1),C.current?.stream&&D(!1)},Ce=t.useCallback(()=>{setTimeout(()=>{D(!1)},1e3)},[]),we=t.useCallback(e=>{if(console.log("camera error",e),pe===s.videoConstraintsExact)return fe(s.videoConstraintsFallback),void me(e=>e+1);D(!1)},[pe]),je=t.useCallback(()=>{ee.current=!1,J(!0),Z(!1),$.current&&clearTimeout($.current),w.current&&w.current.pause(),s.speechService.stopAudio(),Se.poseDetection.disconnect(),ae.current=0,re.current=0,oe.current=!1,ce.current=!1,w.current&&w.current.stop(),Q.forEach(e=>{w.current&&w.current.removeEventListener("dataavailable",e)}),X([]),clearTimeout(v)},[w,Q,s.speechService,ee]),ke=t.useMemo(()=>s.getPreferredMediaRecorderTypes(),[]),Ne=s.getRecordingMimeType(le),Ee=s.getRecordingExtension(Ne),De=t.useCallback(async()=>{ee.current=!0,await s.speechService.playAudio(`${s.voiceOverAssetsPath}SpotOn.mp3`),J(!1),Z(!1),$.current&&clearTimeout($.current),I(!1)},[$,s.speechService]),Te=t.useCallback(async()=>{try{y=await Se.poseDetection.connect(),console.log(y,"websocket connected"),s.posthog.capture(`${f}/pose_detection_connected`,{scanID:r,email:p,id:y})}catch(e){console.log(e,"while connecting websocket")}},[r,f,p]),Ie=t.useCallback(async()=>{s.rescanSupportCaptureEvent({eventName:`${f}/rescan`,email:p,scanID:r,height:m,gender:d,status:!1}),ee.current=!1,Se.poseDetection.disconnect(),be(),await Te(),Ae()},[Te,r,p]),Le=t.useCallback(({data:e})=>{e&&e.size>0&&ee.current&&(N(t=>t.concat(e)),!ne.current&&C.current&&(ne.current=!0,te(()=>{De(),s.handleScanTimeCapture({eventName:`${f}/tensorFlow`,scanID:r,email:p,message:"recording stopped by tensorflow "})},C)))},[De,s.handleScanTimeCapture,f,r,p,C]),Fe=t.useCallback(async()=>{O.length>0&&ee.current&&(await s.speechService.playAudio(s.voiceOverAssetsPath+O[O.length-1]),ee.current&&(v=setTimeout(Fe,2e3)))},[O,ee]),Me=t.useCallback(()=>{w&&w.current&&w.current.stop(),I(!0);try{if(C&&C.current&&C.current.stream){const e=C.current.stream.getVideoTracks()[0];if(e){const t=e.getSettings();j.current=t.frameRate||null}const t={videoBitsPerSecond:15e5};le[0]&&(t.mimeType=le[0]),w.current=new MediaRecorder(C.current.stream,t),w.current.addEventListener("dataavailable",Le),X([...Q,Le]),w.current.start(1e3),P(!1)}}catch(e){console.log("error while using media recorder",e)}},[C,le,Le,Q]),Pe=t.useCallback(async()=>{$.current&&clearTimeout($.current),Me(),ee.current&&($.current=setTimeout(async()=>{ee.current&&(await s.speechService.playAudio(`${s.voiceOverAssetsPath}SpotOn.mp3`),I(!1))},15e3)),F(!0),ee.current&&await s.speechService.playAudio(`${s.voiceOverAssetsPath}Spin.mp3`)},[Me,ee,s.speechService]);t.useEffect(()=>{ie.current=Pe},[Pe]);const _e=t.useCallback(({data:e})=>{e.size>0&&Se.poseDetection.connected()&&(oe.current||(oe.current=!0,Se.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:ae.current,consecutiveFalse:re.current,type:"body_scan_instruction"});const t=document.querySelector("#audioElement");!0===e.status&&e.sid===y?(re.current=0,ae.current<2?(ae.current+=1,1!==ae.current||ce.current?2===ae.current&&t?.paused&&s.speechService.playAudio(s.voiceOverAssetsPath+e.audio):(ce.current=!0,s.speechService.stopAudio(),await s.speechService.playAudio(s.voiceOverAssetsPath+e.audio))):(q(e.audio),clearTimeout(v),Se.poseDetection.disconnect(),oe.current=!1,setTimeout(()=>ie.current(),1e3))):(re.current+=1,re.current>=3&&(ae.current=0,ce.current=!1),!t?.paused||b&&b?.audioName===e.audio?b?.audioName===e.audio&&t?.paused&&(b&&b.no_of_times_skipped>=b.skipCount?(b.no_of_times_skipped=0,s.speechService.playAudio(s.voiceOverAssetsPath+e.audio)):b&&(b.no_of_times_skipped+=1)):(b={skipCount:2,no_of_times_skipped:0,audioName:e.audio},s.speechService.playAudio(s.voiceOverAssetsPath+e.audio)))}})),C?.current&&null!==C.current.getScreenshot()&&Se.poseDetection.videoEmit({image:C.current.getScreenshot()||"",scanId:r}))},[C,r,Se,y,s.speechService,f,p]),Ae=t.useCallback(async()=>{A(!0),he(!0),ve?.(),se.current&&(se.current=!1,s.handleScanTimeCapture({eventName:"scan started",scanID:r,status:"success",email:p})),i(s.getCurrentTimeInSeconds()),D(!0),ee.current&&await s.speechService.playAudio(`${s.voiceOverAssetsPath}StartScan.mp3`),ee.current&&await s.speechService.playAudio(`${s.voiceOverAssetsPath}LiftArmsAndHoldAtHip.mp3`),ee.current&&(A(!1),I(!0),H(!0),Z(!0),Ce());try{if(C&&C.current&&C.current.stream&&ee.current){const e=C.current.stream.getVideoTracks()[0];if(e){const t=e.getSettings();j.current=t.frameRate||null}const t={videoBitsPerSecond:15e5};le[0]&&(t.mimeType=le[0]),ee.current&&(w.current=new MediaRecorder(C.current.stream,t)),ee.current&&w.current&&w.current.addEventListener("dataavailable",_e),X([...Q,_e]),w.current&&w.current.start(1e3),P(!1),ee.current&&(v=setTimeout(Fe,2e3))}}catch(e){console.log("error ----------",e)}},[C,le,_e,Q,Fe,ee,ve]);return t.useEffect(()=>(f&&(n(!0),Te()),()=>{y&&(Se.poseDetection.disconnect(),s.posthog.capture(`${f}/pose_detection_disconnected`,{scanID:r,email:p,id:y})),Q.forEach(e=>{w?.current?.removeEventListener("dataavailable",e)})}),[f]),t.useEffect(()=>{O.push(R)},[R]),t.useEffect(()=>{z([])},[K]),t.useEffect(()=>{const e=k.length&&k.length>0;M||!e||T||!ee.current||G||w&&w.current&&(T||(w.current.stop(),P(!0)))},[M,T,k,G]),t.useEffect(()=>{const e=k.length&&k.length>0;if(M||!e||T)console.log("No video found to upload.");else if(w&&w.current&&ee.current&&!G&&!T){const e=new File(k,`${r}.${Ee}`,{type:Ne});ye?.(),xe?.(!0),c(""),ge?.(e,j.current)}},[M,T,k,G,w,ee]),t.useEffect(()=>{const e=s.getSupportedMediaRecorderTypes(ke,s.videoTypes);ue(e)},[ke]),t.useEffect(()=>{be()},[]),e.jsx(h,{resetDetector:a,resetScan:be,loadingCam:E,onPause:je,showRestart:W,pause:G,onReScan:Ie,recordingStarted:T,isScanning:_,startSendingVideoFrames:Ae,faceDone:L,stopRecording:De,showPause:Y,webcamRef:C,onUserMedia:Ce,onUserMediaError:we,videoConstraints:pe,webcamKey:de})});function w({scanID:s,userDetails:n,setIsVideoUploaded:a,setScanFailsError:r,setScanStartTime:o,setScanUniqueKey:c}){const[i,l]=t.useState(90),[u,d]=t.useState(0),[m,p]=t.useState(null),[h,g]=t.useState(!1),[x,S]=t.useState(0),v=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(v.current=[...v.current.slice(-4),w],v.current.length>=5){const e=Math.max(...v.current)-Math.min(...v.current);S(j&&e<2?e=>Math.min(100,e+10):e=>Math.max(0,e-20))}j||null===m&&!h||N()},[w,j,m,h]),t.useEffect(()=>{x>=100&&null===m&&!h&&k(),x<50&&null!==m&&N()},[x,m,h]);const k=()=>{p(3);const e=setInterval(()=>{p(t=>null===t||t<=1?(clearInterval(e),g(!0),null):t-1)},1e3)},N=()=>{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),S(0),b(!1),v.current=[]},scanID:s,userDetails:n,setIsVideoUploaded:a,setScanFailsError:r,setScanStartTime:o,setScanUniqueKey:c})})}function j({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 k({link:n,onReady:a,wrapperClassName:r="[&_video]:rounded-t-[20px] w-full h-full"}){const o=t.useRef(null),i=t.useRef(null);let l={autoplay:!0,controls:!1,responsive:!0,fluid:!0,muted:!0,navigationUI:"hide",preload:"metadata",poster:s.videoPoster};return t.useEffect(()=>{if(!i.current&&n&&o?.current){const e=c(o.current,{...l});e.ready(()=>{i.current=e;const t={...l,sources:[{src:n,type:"application/x-mpegURL"}]};e.autoplay(t.autoplay),e.src(t.sources),a?.(e)})}},[n,o]),t.useEffect(()=>{const e=i.current;return()=>{e&&!e.isDisposed()&&(e.dispose(),i.current=null)}},[i]),e.jsx("div",{className:r,children:e.jsx("video",{ref:o,muted:!0,className:"video-js",playsInline:!0,onDrag:e=>e.preventDefault()})})}function N({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",{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,{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(k,{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:S,scanType:v}=a||{},y=[s.CLOTHING_CUSTOM_SCAN,s.CLOTHING_BANNER_SCAN,s.CLOTHING_CUSTOM_FIT_SCAN].includes(v??""),[b,C]=t.useState(!0),w=t.useCallback(async()=>{try{y&&(await(m?.auth.addUser({scanId:n,email:S,name:x,gender:p,height:h})),d?.()),s.posthog.capture(f??"",{scanID:n,email:S,height:h,focalLength:g,clothesFit:"0",gender:p})}catch(e){console.log(e)}},[y]),{translate:k}=t.useContext(s.LanguageContext)||{};t.useEffect(()=>{(c||i)&&w()},[c,i]);const N=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(j,{loader:r?.loader,setShowDrawer:C}),e.jsx(o.Drawer,{open:b,onClose:(e,t)=>{},disablePortal:!0,className:"camera-drawer",anchor:"bottom",children:e.jsx("div",{className:"max-w-[28rem] mx-auto w-full h-full flex text-center flex-col justify-between items-center bg-primary rounded-t-[30px] p-[1rem]",style:{background:r?.style?.base?.backgroundColor},children:e.jsxs("div",{className:"w-full h-full flex flex-col",children:[e.jsx(s.Header,{title: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"})})}),N&&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:S,setScanFailsError:v,setScanStartTime:y,resetScan:b,onCustomScanSuccess:C,swan:k,onComplete:D}=t.useContext(s.ParamsContext),T=s.useConfig();return S&&!x?e.jsx(s.Modal,{variant:"portrait",config:T}):r?e.jsxs(e.Fragment,{children:[e.jsx(j,{}),e.jsx(o.Drawer,{anchor:"bottom",open:!0,className:"camera-drawer",onClose:(e,t)=>{},disablePortal:!0,children:e.jsx(N,{scanFailsError:!0,onNext:a,gender:i})})]}):c?e.jsx(E,{isSuccess:!0,onComplete:D,config:T}):h?e.jsx("div",{className:"flex top-0 !mt-0 left-0 z-[999] absolute justify-center items-center w-full h-full",style:{background:T?.style?.base?.backgroundColor},children:e.jsx(s.LoadingScreen,{url:T?.loader,loaderType:"black"})}):g.disabled?e.jsx(s.Modal,{}):x||u||p||f?(x||p||f)&&!u?e.jsx(E,{scanId:l,isMeasurementAvailable:p,userDetails:n,isVideoUploadedCorrect:f,onCustomScanSuccess:C,swan:k,onComplete:D,config:T}):e.jsxs(e.Fragment,{children:[e.jsx(j,{}),e.jsx(o.Drawer,{anchor:"bottom",open:!0,className:"camera-drawer",onClose:(e,t)=>{},disablePortal:!0,children:e.jsx(N,{scanFailsError:u,onNext:()=>{a?.(),b()},setScanUniqueKey:d,gender:i,setIsVideoUploaded:m})})]}):e.jsx(w,{scanID:l,userDetails:n,setIsVideoUploaded:m,setScanFailsError:v,setScanStartTime:y,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:S,isSuccess:v}=n,y={email:"",shopDomain:"",gender:"male",heightInCm:0,scanType:"",deviceFocalLength:0,deviceModelName:"",sourceTag:"",...n.userDetails??{}},b=n.token??"",{gender:C,scanType:w,shopDomain:j,heightInCm:k,email:N,deviceFocalLength:E,deviceModelName:T,callbackUrl:I,sourceTag:L}=y,F=t.useMemo(()=>s.getSwanService(b),[b]),[M,P]=t.useState(!1),[_,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),{isLandscape:ee}=s.usePortraitLock();s.usePosthogPageview();const te=t.useCallback(()=>{Q(s.generateUuid()),K(""),P(!1),B(!1)},[]);t.useEffect(()=>{ee&&!M&&te()},[ee,M,te]);const se=()=>{Y(null),Q("")},ne=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:N}),A(!0),void p?.(e);h?.(e),A(!0),se();const t=J;R(!0),s.handleScanTimeCapture({eventName:`${j}/measurement_success/fit-view`,scanID:t,status:"success",email:N}),X&&s.handleScanTimeCapture({eventName:`${j}/scan_completion_time`,scanID:t,status:"success",completionTime:s.getCurrentTimeInSeconds()-X,email:N})},[w,j,J]),ae=e=>{R(!1),K(""),A(!1),F.measurement.handleMeasurementSocket({scanId:J,onPreopen:()=>{s.handleWebSocketCapture({eventName:`${j}/webSocket`,scanID:J,connection:"pre_open",type:"measurement_recommendation",email:N})},onOpen:()=>{u?.(),s.handleWebSocketCapture({eventName:`${j}/webSocket`,scanID:J,connection:"open",type:"measurement_recommendation",email:N})},onClose:()=>{d?.(),s.handleWebSocketCapture({eventName:`${j}/webSocket`,scanID:J,connection:"close",type:"measurement_recommendation",email:N})},onError:e=>{var t;t=e,f?.({...t,message:s.handleErrorMessage(t)}),se(),R(!1),K(t),A(!1),s.handleScanTimeCapture({eventName:`${j}/measurement_failed/fit-view`,scanID:J,status:"failed",email:N,message:s.handleErrorMessage(t)}),X&&s.handleScanTimeCapture({eventName:`${j}/scan_completion_time`,scanID:J,status:"failed",completionTime:s.getCurrentTimeInSeconds()-X,email:N}),s.handleWebSocketCapture({eventName:`${j}/webSocket`,scanID:J,connection:"error",type:"measurement_recommendation",email:N})},onSuccess:e=>{s.handleWebSocketCapture({eventName:`${j}/webSocket`,scanID:J,connection:"success",type:"measurement_recommendation",email:N}),ne(e)}})},re=t.useCallback(async(e,t)=>{const n=Number((e.size/1048576).toFixed(2)),a=null!=t?t:await s.getVideoFPS(e),r=s.createObjectMetadataArray({gender:C,focal_length:`${E}`,height:`${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:N,data:JSON.stringify([...r,{fileSizeInMB:n,video_fps:a||0}])}),i?.();try{await F.fileUpload.uploadFileFrontend({file:e,arrayMetaData:r,scanId:J,email:N}),await F.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:N,data:JSON.stringify(r)}),s.handleScanTimeCapture({eventName:"scan finished",scanID:J,status:"success",email:N}),Y(s.getCurrentTimeInSeconds()),setTimeout(()=>{B(!0)},3e3)}catch(e){s.handleScanTimeCapture({eventName:"scan finished",scanID:J,status:"failed",email:N,message:s.handleErrorMessage(e)}),s.handleScanTimeCapture({eventName:`${j}/scan_failed`,scanID:J,status:"failed",email:N,message:s.handleErrorMessage(e),data:JSON.stringify(r)}),K(s.handleErrorMessage(e)),B(!1),f?.({...e,message:s.handleErrorMessage(e)}),se()}finally{G(!1),l?.()}},[J,Z,i,l]),oe=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:N}),W(!1)):(W(!1),s.handleScanTimeCapture({eventName:`${j}/camera_activation`,scanID:J,status:"success",email:N})),O(e),K(""),B(!1)},[N,J,Q,j]);return t.useEffect(()=>{S||v||j&&oe()},[j,k,S,v]),t.useEffect(()=>{S||v||q&&j&&J&&ae()},[q,j,J,S,v]),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:S,isSuccess:v,onScanSuccess:h,gender:C,scanUniqueKey:J,scanFailsError:z,setScanUniqueKey:Q,setIsVideoUploaded:B,isMeasurementAvailable:$,isVideoUploadedCorrect:_,loading:V,showDeniedModal:U,uploadLoading:M,isLandscape:ee,setStartGyro:G,uploadScanFile:re,setUploadLoading:P,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-B6V25JbX.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,A as y,v,i as w,P as b,o as x,s as S,j as C,k as N,l as D,p as I,B as k,y as F,D as T,q as E,e as L,r as M,E as _,c as $,M as U,a as A,I as P,J as j,V as z,K as V,N as R,O as B,G as q,Q as K,R as O,T as W,f as H,h as J,n as G,x as Q,U as Y,t as X,C as Z,w as ee,z as te}from"./LoadingScreen-DTVfoOWk.js";import ne from"clsx";import re from"react-webcam";import{X as ae}from"lucide-react";import{Dialog as se,Box as oe,Drawer as ce}from"@mui/material";import ie from"video.js";const le="DESKTOP",de="TAB",ue="MOBILE",me=c(void 0);function pe({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=le;n[0]>768&&n[0]<1024&&(u=de),n[0]<768&&(u=ue);const m=l(()=>({size:n,setSize:r,clearInputs:s,setClearInputs:c,media:u}),[n,s,u]);return e(me.Provider,{value:m,children:t})}var fe=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 he=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 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},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:ne("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:ne("mt-[.5rem] text-center w-[180px] flex-col flex items-center absolute top-[60px]",b()),style:{color:S()},children:[e(fe,{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:ne("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:ne("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:ne("text-[.75rem] opacity-50",b()),style:{fontFamily:g?.style?.base?.baseFontFamily||"Inter, sans-serif",color:S()},children:u?.(h.placePhoneUpright)})})]})});function ge({resetScan:n,loadingCam:r,onUserMedia:a,onPause:s,pause:o,recordingStarted:c,startSendingVideoFrames:i,showPause:l,webcamRef:u,onUserMediaError:p,resetDetector:f,videoConstraints:w,webcamKey:b}){const{media:x}=d(me)||{},{translate:S}=d(m)||{};return t("div",{className:"App w-screen h-[100vh] relative common-ui-main",children:[e("span",{onClick:()=>{n(),f()},className:"fixed right-[20px] top-[20px] z-[999]",children:e(ae,{className:"text-[#fff]"})}),e("div",{className:"w-full h-full overflow-hidden ",children:x===ue&&e(re,{audio:!1,ref:u,screenshotQuality:1,videoConstraints:w,mirrored:!0,screenshotFormat:"image/jpeg",onUserMedia:a,onUserMediaError:p,style:{position:"fixed",top:0,bottom:0,zIndex:0,width:"100%",height:"100%",objectFit:"cover"}},b)}),t("div",{className:"fixed bottom-[30px] w-full z-[999] flex flex-col gap-4 items-center justify-center",children:[l&&e(g,{className:"!w-[180px] !h-[40px] !py-[0] mx-auto ",prefix:y,buttonText:S?.(h.pause),buttonFunc:s,btnSecondary:!0}),o?e("div",{children:e(g,{className:"!w-[180px] !h-[40px] !py-[0] mx-auto",buttonText:S?.(h.restart),buttonFunc:n,btnSecondary:!0})}):c?null:e(g,{className:"!w-[180px] !h-[40px] !py-[0] mx-auto !bg-[#ffffff] !text-[#000000] "+(r?"!opacity-50":""),buttonText:S?.(h.startScan),buttonFunc:i,disabled:r})]}),e("audio",{id:"audioElement",crossOrigin:"anonymous",preload:"auto",style:{position:"absolute",zIndex:-99999},src:`${v}scanAudioInstructions/silence.mp3`})]})}let ye=null,ve=null,we=null;let be,xe=null,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:_}=f,$=u(null),U=u(null),A=u(null),[P,j]=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-B1DONWkg.js"),import("@tensorflow/tfjs-core"),import("@tensorflow/tfjs-backend-webgl")]);we=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{ve=await we.createDetector(we.SupportedModels.BlazePose,r),console.log("MediaPipe detector created successfully")}catch(e){console.warn("MediaPipe failed, falling back to TFJS runtime:",e),ve=await we.createDetector(we.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),ye=null,!1}}function p(e){return!(!e||0===e.length)&&22===e.filter(e=>e[2]>.7).length}return o(()=>{if(d.current=!0,!ve)return ye||(ye=m()),ye.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(!ve||!d.current||!n?.current?.video)return;const r=n.current.video;if(!(r.readyState<2))try{const n=await ve.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()=>{ve||ye||(ye=m(),await ye&&d.current&&c(!0))}}}(),fe=u(!0),he=u(!1),Ce=u(0),Ne=u(0),De=u(!1),Ie=u(!1),ke=u(()=>{}),[Fe,Te]=a([]),[Ee,Le]=a(0),[Me,_e]=a(w),{setStartGyro:$e,uploadScanFile:Ue,setUploadLoading:Ae,swan:Pe,onScanStart:je,onCaptureComplete:ze}=d(b),Ve=()=>{he.current=!1,clearTimeout(be),G.current&&clearTimeout(G.current),p(L()),i(""),Ae?.(!1),j([]),A.current=null,V(!0),B(!1),K(!1),W(!0),J(!1),G.current=null,Y(""),Z([]),te(""),re(!ne),$e(!1),S.stopAudio(),se(!1),ce(!1),Ce.current=0,Ne.current=0,De.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)},Re=s(()=>{setTimeout(()=>{V(!1)},1e3)},[]),Be=s(e=>{if(console.log("camera error",e),Me===w)return _e(x),void Le(e=>e+1);V(!1)},[Me]),qe=s(()=>{me.current=!1,ce(!0),ue(!1),G.current&&clearTimeout(G.current),U.current&&U.current.pause(),S.stopAudio(),Pe.poseDetection.disconnect(),Ce.current=0,Ne.current=0,De.current=!1,Ie.current=!1,U.current&&U.current.stop(),ie.forEach(e=>{U.current&&U.current.removeEventListener("dataavailable",e)}),le([]),clearTimeout(be)},[U,ie,S,me]),Ke=l(()=>C(),[]),Oe=N(Fe),We=D(Oe),He=s(async()=>{me.current=!0,await S.playAudio(`${v}SpotOn.mp3`),ce(!1),ue(!1),G.current&&clearTimeout(G.current),B(!1)},[G,S]),Je=s(async()=>{try{xe=await Pe.poseDetection.connect(),console.log(xe,"websocket connected"),I.capture(`${_}/pose_detection_connected`,{scanID:r,email:y,id:xe})}catch(e){console.log(e,"while connecting websocket")}},[r,_,y]),Ge=s(async()=>{k({eventName:`${_}/rescan`,email:y,scanID:r,height:g,gender:h,status:!1}),me.current=!1,Pe.poseDetection.disconnect(),Ve(),await Je(),tt()},[Je,r,y]),Qe=s(({data:e})=>{e&&e.size>0&&me.current&&(j(t=>t.concat(e)),!he.current&&$.current&&(he.current=!0,pe(()=>{He(),F({eventName:`${_}/tensorFlow`,scanID:r,email:y,message:"recording stopped by tensorflow "})},$)))},[He,F,_,r,y,$]),Ye=s(async()=>{X.length>0&&me.current&&(await S.playAudio(v+X[X.length-1]),me.current&&(be=setTimeout(Ye,2e3)))},[X,me]),Xe=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();A.current=t.frameRate||null}const t={videoBitsPerSecond:15e5};Fe[0]&&(t.mimeType=Fe[0]),U.current=new MediaRecorder($.current.stream,t),U.current.addEventListener("dataavailable",Qe),le([...ie,Qe]),U.current.start(1e3),W(!1)}}catch(e){console.log("error while using media recorder",e)}},[$,Fe,Qe,ie]),Ze=s(async()=>{G.current&&clearTimeout(G.current),Xe(),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`)},[Xe,me,S]);o(()=>{ke.current=Ze},[Ze]);const et=s(({data:e})=>{e.size>0&&Pe.poseDetection.connected()&&(De.current||(De.current=!0,Pe.poseDetection.poseStatus(async e=>{if(console.log("poseStatus data:",e),e&&e.audio&&e.audio.length>0){I.capture(`${_}/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=document.querySelector("#audioElement");!0===e.status&&e.sid===xe?(Ne.current=0,Ce.current<2?(Ce.current+=1,1!==Ce.current||Ie.current?2===Ce.current&&t?.paused&&S.playAudio(v+e.audio):(Ie.current=!0,S.stopAudio(),await S.playAudio(v+e.audio))):(te(e.audio),clearTimeout(be),Pe.poseDetection.disconnect(),De.current=!1,setTimeout(()=>ke.current(),1e3))):(Ne.current+=1,Ne.current>=3&&(Ce.current=0,Ie.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)))}})),$?.current&&null!==$.current.getScreenshot()&&Pe.poseDetection.videoEmit({image:$.current.getScreenshot()||"",scanId:r}))},[$,r,Pe,xe,S,_,y]),tt=s(async()=>{J(!0),$e(!0),je?.(),fe.current&&(fe.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),Re());try{if($&&$.current&&$.current.stream&&me.current){const e=$.current.stream.getVideoTracks()[0];if(e){const t=e.getSettings();A.current=t.frameRate||null}const t={videoBitsPerSecond:15e5};Fe[0]&&(t.mimeType=Fe[0]),me.current&&(U.current=new MediaRecorder($.current.stream,t)),me.current&&U.current&&U.current.addEventListener("dataavailable",et),le([...ie,et]),U.current&&U.current.start(1e3),W(!1),me.current&&(be=setTimeout(Ye,2e3))}}catch(e){console.log("error ----------",e)}},[$,Fe,et,ie,Ye,me,je]);return o(()=>(_&&(t(!0),Je()),()=>{xe&&(Pe.poseDetection.disconnect(),I.capture(`${_}/pose_detection_disconnected`,{scanID:r,email:y,id:xe})),ie.forEach(e=>{U?.current?.removeEventListener("dataavailable",e)})}),[_]),o(()=>{X.push(Q)},[Q]),o(()=>{Z([])},[ee]),o(()=>{const e=P.length&&P.length>0;O||!e||R||!me.current||oe||U&&U.current&&(R||(U.current.stop(),W(!0)))},[O,R,P,oe]),o(()=>{const e=P.length&&P.length>0;if(O||!e||R)console.log("No video found to upload.");else if(U&&U.current&&me.current&&!oe&&!R){const e=new File(P,`${r}.${We}`,{type:Oe});ze?.(),Ae?.(!0),i(""),Ue?.(e,A.current)}},[O,R,P,oe,U,me]),o(()=>{const e=E(Ke,M);Te(e)},[Ke]),o(()=>{Ve()},[]),e(ge,{resetDetector:n,resetScan:Ve,loadingCam:z,onPause:qe,showRestart:ae,pause:oe,onReScan:Ge,recordingStarted:R,isScanning:H,startSendingVideoFrames:tt,faceDone:q,stopRecording:He,showPause:de,webcamRef:$,onUserMedia:Re,onUserMediaError:Be,videoConstraints:Me,webcamKey:Ee})});function Ne({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,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(b.current=[...b.current.slice(-4),C],b.current.length>=5){const e=Math.max(...b.current)-Math.min(...b.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),x||y(!1)};return e(he,{angle:C,countdown:f,isScanning:g,isInTargetRange:N,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 De({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(re,{audio:!1,ref:m,screenshotQuality:1,videoConstraints:A,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:P};return o(()=>{if(!s.current&&t&&a?.current){const e=ie(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",{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:j(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,{disabled:!1,buttonText:l?.(h.scanAgain),className:"!shadow-none",buttonFunc:()=>{s?s?.():c?.(L()),i?.(!1)}})})]}),y&&t(se,{className:"w-screen h-screen video-modal",onClose:w,open:y,disablePortal:!0,children:[e("div",{className:"flex justifyEnd ",children:e("span",{className:"closeBtn",onClick:w,children:e(ae,{className:"absolute right-[8px] top-[8px] text-white z-[9]"})})}),e("div",{className:"aspect-video object-cover rounded-[20px] ",children:e(Ie,{link:o?V[o].PRE_LINK:V.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: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:x})),y?.()),I.capture(b??"",{scanID:n,email:N,height:x,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(oe,{className:"flex h-full w-full flex-col common-ui-main",children:t("div",{className:"h-full w-full flex-col items-center justify-center flex",children:[e(De,{loader:c?.loader,setShowDrawer:T}),e(ce,{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]",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 Te=()=>{const{userDetails:r,onRetry:a,isError:s,isSuccess:o,gender:c,scanUniqueKey:i,scanFailsError:l,setScanUniqueKey:u,setIsVideoUploaded:m,isMeasurementAvailable:f,isVideoUploadedCorrect:h,loading:g,showDeniedModal:y,uploadLoading:v,setScanFailsError:w,setScanStartTime:x,resetScan:S,onCustomScanSuccess:C,swan:N,onComplete:D}=d(b),I=p();return s?t(n,{children:[e(De,{}),e(ce,{anchor:"bottom",open:!0,className:"camera-drawer",onClose:(e,t)=>{},disablePortal:!0,children:e(ke,{scanFailsError:!0,onNext:a,gender:c})})]}):o?e(Fe,{isSuccess:!0,onComplete:D,config:I}):g?e("div",{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($,{url:I?.loader,loaderType:"black"})}):y.disabled?e(U,{}):v||l||f||h?(v||f||h)&&!l?e(Fe,{scanId:i,isMeasurementAvailable:f,userDetails:r,isVideoUploadedCorrect:h,onCustomScanSuccess:C,swan:N,onComplete:D,config:I}):t(n,{children:[e(De,{}),e(ce,{anchor:"bottom",open:!0,className:"camera-drawer",onClose:(e,t)=>{},disablePortal:!0,children:e(ke,{scanFailsError:l,onNext:()=>{a?.(),S()},setScanUniqueKey:u,gender:c,setIsVideoUploaded:m})})]}):e(Ne,{scanID:i,userDetails:r,setIsVideoUploaded:m,setScanFailsError:w,setScanStartTime:x,setScanUniqueKey:u})},Ee=n=>{const{config:r,onRetry:c,onScanStart:i,onCaptureComplete:d,onUploadStart:u,onUploadEnd:m,onMeasurementSocketStart:p,onMeasurementSocketClose:f,onIntermediateScanSuccess:h,onScanError:g,onScanSuccess:y,onCustomScanSuccess:v,onComplete:w,isError:x,isSuccess:S}=n,C={email:"",shopDomain:"",gender:"male",heightInCm:0,scanType:"",deviceFocalLength:0,deviceModelName:"",sourceTag:"",...n.userDetails??{}},N=n.token??"",{gender:D,scanType:I,shopDomain:k,heightInCm:E,email:M,deviceFocalLength:$,deviceModelName:A,callbackUrl:P,sourceTag:z}=C,V=l(()=>H(N),[N]),[R,B]=a(!1),[q,K]=a(!1),[O,W]=a(!1),[ne,re]=a({disabled:!1,message:""}),[ae,se]=a(""),[oe,ce]=a(!1),[ie,le]=a(!0),[de,ue]=a(!1),[me,fe]=a(""),[he,ge]=a(T()),{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}=J();G();const we=s(()=>{fe(L()),se(""),B(!1),ce(!1)},[]);o(()=>{ve&&!R&&we()},[ve,R,we]);const be=()=>{ge(null),fe("")},xe=s(async e=>{if(e&&"success"===e?.scanStatus&&"intermediate"===e?.resultType&&200===e?.code)return F({eventName:`${k}/measurement_success/intermediate`,scanID:me,status:"success",email:M}),K(!0),void h?.(e);y?.(e),K(!0),be();const t=me;W(!0),F({eventName:`${k}/measurement_success/fit-view`,scanID:t,status:"success",email:M}),he&&F({eventName:`${k}/scan_completion_time`,scanID:t,status:"success",completionTime:T()-he,email:M})},[I,k,me]),Se=e=>{W(!1),se(""),K(!1),V.measurement.handleMeasurementSocket({scanId:me,onPreopen:()=>{te({eventName:`${k}/webSocket`,scanID:me,connection:"pre_open",type:"measurement_recommendation",email:M})},onOpen:()=>{p?.(),te({eventName:`${k}/webSocket`,scanID:me,connection:"open",type:"measurement_recommendation",email:M})},onClose:()=>{f?.(),te({eventName:`${k}/webSocket`,scanID:me,connection:"close",type:"measurement_recommendation",email:M})},onError:e=>{var t;t=e,g?.({...t,message:j(t)}),be(),W(!1),se(t),K(!1),F({eventName:`${k}/measurement_failed/fit-view`,scanID:me,status:"failed",email:M,message:j(t)}),he&&F({eventName:`${k}/scan_completion_time`,scanID:me,status:"failed",completionTime:T()-he,email:M}),te({eventName:`${k}/webSocket`,scanID:me,connection:"error",type:"measurement_recommendation",email:M})},onSuccess:e=>{te({eventName:`${k}/webSocket`,scanID:me,connection:"success",type:"measurement_recommendation",email:M}),xe(e)}})},Ce=s(async(e,t)=>{const n=Number((e.size/1048576).toFixed(2)),r=null!=t?t:await Q(e),a=Y({gender:D,focal_length:`${$}`,height:`${E}`,customer_store_url:k,clothes_fit:"0",scan_type:I,callback_url:P,source_tag:z});F({eventName:`${k}/body_scan_meta_data`,scanID:me,email:M,data:JSON.stringify([...a,{fileSizeInMB:n,video_fps:r||0}])}),u?.();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),F({eventName:`${k}/scan_success`,scanID:me,status:"success",email:M,data:JSON.stringify(a)}),F({eventName:"scan finished",scanID:me,status:"success",email:M}),ge(T()),setTimeout(()=>{ce(!0)},3e3)}catch(e){F({eventName:"scan finished",scanID:me,status:"failed",email:M,message:j(e)}),F({eventName:`${k}/scan_failed`,scanID:me,status:"failed",email:M,message:j(e),data:JSON.stringify(a)}),se(j(e)),ce(!1),g?.({...e,message:j(e)}),be()}finally{ue(!1),m?.()}},[me,ye,u,m]),Ne=s(async()=>{if(+E<152.4||+E>213.36)return void g?.({message:"Height must be between 152.4cm (5ft) and 213.36cm (7ft)"});const e=await _();e.disabled?(F({eventName:`${k}/camera_activation`,scanID:me,status:"failed",email:M}),le(!1)):(le(!1),F({eventName:`${k}/camera_activation`,scanID:me,status:"success",email:M})),re(e),se(""),ce(!1)},[M,me,fe,k]);return o(()=>{x||S||k&&Ne()},[k,E,x,S]),o(()=>{x||S||oe&&k&&me&&Se()},[oe,k,me,x,S]),e(X,{children:e(Z,{config:r,children:t(pe,{children:[ve&&!R&&e(U,{variant:"portrait",config:r}),e(b.Provider,{value:{userDetails:C,onRetry:c,onScanError:g,isError:x,isSuccess:S,onScanSuccess:y,gender:D,scanUniqueKey:me,scanFailsError:ae,setScanUniqueKey:fe,setIsVideoUploaded:ce,isMeasurementAvailable:O,isVideoUploadedCorrect:q,loading:ie,showDeniedModal:ne,uploadLoading:R,setStartGyro:ue,uploadScanFile:Ce,setUploadLoading:B,resetScan:we,setScanFailsError:se,setScanStartTime:ge,onScanStart:i,onCaptureComplete:d,onCustomScanSuccess:v,onComplete:w,swan:V},children:e(ee,{children:e(Te,{})})})]})})})};export{Ee as B};
2
+ //# sourceMappingURL=BodyScan-BSI8dvZ-.js.map
@@ -0,0 +1,2 @@
1
+ "use strict";var e=require("react/jsx-runtime"),t=require("react"),s=require("./LoadingScreen-vRwqPBLg.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,[]),S=t.useCallback((e=!1)=>{const t=m();return o?d?.style?.angleDetector?.successAngleTextLightColor:x(e,t)},[o,m]),v=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},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!==v?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 ${S()}`},children:e.jsx("div",{className:`text-[3rem] font-bold text-[${S()}]`,style:{fontFamily:d?.style?.base?.baseFontFamily||"Inter, sans-serif",color:S()},children:v})}):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 ${S()}`},children:[e.jsx("div",{className:`h-[1rem] w-[1rem] rounded-[9999px] bg-[${S()}]/80`,style:{backgroundColor:`${S()}B3`}}),e.jsxs("div",{className:n("mt-[.5rem] text-center w-[180px] flex-col flex items-center absolute top-[60px]",g()),style:{color:S()},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!==v&&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:S()},children:u?.(s.LanguageKeys.leavePhone)})}),c&&null===v&&!o&&e.jsx("div",{className:"absolute bottom-[8rem] w-[12rem]",children:e.jsx("div",{className:`h-[.375rem] w-full bg-[${S()}]/20 rounded-[9999px] overflow-hidden`,style:{backgroundColor:`${S()}33`},children:e.jsx("div",{className:`h-full bg-[${S()}]/70 transition-all duration-300 rounded-[9999px]`,style:{width:`${a}%`,backgroundColor:`${S()}B3`}})})}),null===v&&!o&&e.jsx("div",{className:"absolute bottom-[5rem] text-center",children:e.jsxs("div",{className:n("text-[1.5rem] font-light",g()),style:{color:S(),fontFamily:d?.style?.base?.baseFontFamily||"Inter, sans-serif"},children:[Math.round(a),"°"]})}),null===v&&!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:S()},children:u?.(s.LanguageKeys.placePhoneUpright)})})]})});function h({resetScan:n,loadingCam:o,onUserMedia:c,onPause:i,pause:l,recordingStarted:m,startSendingVideoFrames:p,showPause:f,webcamRef:h,onUserMediaError:g,resetDetector:x,videoConstraints:S,webcamKey:v}){const{media:y}=t.useContext(d)||{},{translate:b}=t.useContext(s.LanguageContext)||{};return e.jsxs("div",{className:"App w-screen h-[100vh] relative common-ui-main",children:[e.jsx("span",{onClick:()=>{n(),x()},className:"fixed right-[20px] top-[20px] z-[999]",children:e.jsx(r.X,{className:"text-[#fff]"})}),e.jsx("div",{className:"w-full h-full overflow-hidden ",children:y===u&&e.jsx(a,{audio:!1,ref:h,screenshotQuality:1,videoConstraints:S,mirrored:!0,screenshotFormat:"image/jpeg",onUserMedia:c,onUserMediaError:g,style:{position:"fixed",top:0,bottom:0,zIndex:0,width:"100%",height:"100%",objectFit:"cover"}},v)}),e.jsxs("div",{className:"fixed bottom-[30px] w-full z-[999] flex flex-col gap-4 items-center justify-center",children:[f&&e.jsx(s.SpecificButton,{className:"!w-[180px] !h-[40px] !py-[0] mx-auto ",prefix:s.pauseIcon,buttonText:b?.(s.LanguageKeys.pause),buttonFunc:i,btnSecondary:!0}),l?e.jsx("div",{children:e.jsx(s.SpecificButton,{className:"!w-[180px] !h-[40px] !py-[0] mx-auto",buttonText:b?.(s.LanguageKeys.restart),buttonFunc:n,btnSecondary:!0})}):m?null:e.jsx(s.SpecificButton,{className:"!w-[180px] !h-[40px] !py-[0] mx-auto !bg-[#ffffff] !text-[#000000] "+(o?"!opacity-50":""),buttonText:b?.(s.LanguageKeys.startScan),buttonFunc:p,disabled:o})]}),e.jsx("audio",{id:"audioElement",crossOrigin:"anonymous",preload:"auto",style:{position:"absolute",zIndex:-99999},src:`${s.voiceOverAssetsPath}scanAudioInstructions/silence.mp3`})]})}let g=null,x=null,S=null;let v,y=null,b=null;var C=t.memo(function({setIsScanLocked:n,resetDetector:a,scanID:r,setIsVideoUploaded:o,setScanFailsError:c,setScanStartTime:i,setScanUniqueKey:l,userDetails:u}){const{gender:d,heightInCm:m,email:p,shopDomain:f}=u,C=t.useRef(null),w=t.useRef(null),j=t.useRef(null),[k,N]=t.useState([]),[E,D]=t.useState(!0),[T,I]=t.useState(!1),[L,F]=t.useState(!1),[M,P]=t.useState(!0),[_,A]=t.useState(!1),$=t.useRef(null),[R,U]=t.useState(""),[O,z]=t.useState([]),[K,B]=t.useState(""),[q,V]=t.useState(!1),[W,H]=t.useState(!1),[G,J]=t.useState(!1),[Q,X]=t.useState([]),[Y,Z]=t.useState(!1),ee=t.useRef(!0),{poseDetector:te}=function(){const[e,s]=t.useState(0),[n,a]=t.useState(0),[r,o]=t.useState(!1),c=t.useRef(0),i=t.useRef(0),l=t.useRef(!0);async function u(){if("undefined"==typeof window||"undefined"==typeof navigator)return!1;try{console.log("Starting TensorFlow preload...");const[e,t,s]=await Promise.all([Promise.resolve().then(function(){return require("./pose-detection.esm-yM_Igca-.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{x=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),x=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),g=null,!1}}function d(e){return!(!e||0===e.length)&&22===e.filter(e=>e[2]>.7).length}return t.useEffect(()=>{if(l.current=!0,!x)return g||(g=u()),g.then(e=>{e&&l.current&&o(!0)}),()=>{l.current=!1};o(!0)},[]),t.useEffect(()=>{i.current=e,e>6&&c.current<2&&(a(e=>e+1),s(0))},[e]),t.useEffect(()=>{c.current=n},[n]),{poseDetector:async(e,t)=>{if(!x||!l.current||!t?.current?.video)return;const n=t.current.video;if(!(n.readyState<2))try{const t=await x.estimatePoses(n,{flipHorizontal:!1});if(!t||!t.length)return;const a=t[0].keypoints.slice(11).map(e=>[e.x>0&&e.x<720?e.x:-1,e.y>0&&e.y<1280?e.y:-1,e.score??0]);0!==c.current||d(a)||s(e=>e+1),1===c.current&&d(a)&&s(e=>e+1),2===c.current&&e()}catch(e){console.error("Pose detection error:",e)}},isLoaded:r,spinPhase:n,resetDetector:()=>{c.current=0,i.current=0,s(0),a(0)},retryLoading:async()=>{x||g||(g=u(),await g&&l.current&&o(!0))}}}(),se=t.useRef(!0),ne=t.useRef(!1),ae=t.useRef(0),re=t.useRef(0),oe=t.useRef(!1),ce=t.useRef(!1),ie=t.useRef(()=>{}),[le,ue]=t.useState([]),[de,me]=t.useState(0),[pe,fe]=t.useState(s.videoConstraintsExact),{setStartGyro:he,uploadScanFile:ge,setUploadLoading:xe,swan:Se,onScanStart:ve,onCaptureComplete:ye}=t.useContext(s.ParamsContext),be=()=>{ne.current=!1,clearTimeout(v),$.current&&clearTimeout($.current),l(s.generateUuid()),c(""),xe?.(!1),N([]),j.current=null,D(!0),I(!1),F(!1),P(!0),A(!1),$.current=null,U(""),z([]),B(""),V(!q),he(!1),s.speechService.stopAudio(),H(!1),J(!1),ae.current=0,re.current=0,oe.current=!1,ce.current=!1,null!==w.current&&w.current.stop(),Q.forEach(e=>{w.current&&w.current.removeEventListener("dataavailable",e)}),X([]),ee.current=!0,Z(!1),o(!1),C.current?.stream&&D(!1)},Ce=t.useCallback(()=>{setTimeout(()=>{D(!1)},1e3)},[]),we=t.useCallback(e=>{if(console.log("camera error",e),pe===s.videoConstraintsExact)return fe(s.videoConstraintsFallback),void me(e=>e+1);D(!1)},[pe]),je=t.useCallback(()=>{ee.current=!1,J(!0),Z(!1),$.current&&clearTimeout($.current),w.current&&w.current.pause(),s.speechService.stopAudio(),Se.poseDetection.disconnect(),ae.current=0,re.current=0,oe.current=!1,ce.current=!1,w.current&&w.current.stop(),Q.forEach(e=>{w.current&&w.current.removeEventListener("dataavailable",e)}),X([]),clearTimeout(v)},[w,Q,s.speechService,ee]),ke=t.useMemo(()=>s.getPreferredMediaRecorderTypes(),[]),Ne=s.getRecordingMimeType(le),Ee=s.getRecordingExtension(Ne),De=t.useCallback(async()=>{ee.current=!0,await s.speechService.playAudio(`${s.voiceOverAssetsPath}SpotOn.mp3`),J(!1),Z(!1),$.current&&clearTimeout($.current),I(!1)},[$,s.speechService]),Te=t.useCallback(async()=>{try{y=await Se.poseDetection.connect(),console.log(y,"websocket connected"),s.posthog.capture(`${f}/pose_detection_connected`,{scanID:r,email:p,id:y})}catch(e){console.log(e,"while connecting websocket")}},[r,f,p]),Ie=t.useCallback(async()=>{s.rescanSupportCaptureEvent({eventName:`${f}/rescan`,email:p,scanID:r,height:m,gender:d,status:!1}),ee.current=!1,Se.poseDetection.disconnect(),be(),await Te(),Ae()},[Te,r,p]),Le=t.useCallback(({data:e})=>{e&&e.size>0&&ee.current&&(N(t=>t.concat(e)),!ne.current&&C.current&&(ne.current=!0,te(()=>{De(),s.handleScanTimeCapture({eventName:`${f}/tensorFlow`,scanID:r,email:p,message:"recording stopped by tensorflow "})},C)))},[De,s.handleScanTimeCapture,f,r,p,C]),Fe=t.useCallback(async()=>{O.length>0&&ee.current&&(await s.speechService.playAudio(s.voiceOverAssetsPath+O[O.length-1]),ee.current&&(v=setTimeout(Fe,2e3)))},[O,ee]),Me=t.useCallback(()=>{w&&w.current&&w.current.stop(),I(!0);try{if(C&&C.current&&C.current.stream){const e=C.current.stream.getVideoTracks()[0];if(e){const t=e.getSettings();j.current=t.frameRate||null}const t={videoBitsPerSecond:15e5};le[0]&&(t.mimeType=le[0]),w.current=new MediaRecorder(C.current.stream,t),w.current.addEventListener("dataavailable",Le),X([...Q,Le]),w.current.start(1e3),P(!1)}}catch(e){console.log("error while using media recorder",e)}},[C,le,Le,Q]),Pe=t.useCallback(async()=>{$.current&&clearTimeout($.current),Me(),ee.current&&($.current=setTimeout(async()=>{ee.current&&(await s.speechService.playAudio(`${s.voiceOverAssetsPath}SpotOn.mp3`),I(!1))},15e3)),F(!0),ee.current&&await s.speechService.playAudio(`${s.voiceOverAssetsPath}Spin.mp3`)},[Me,ee,s.speechService]);t.useEffect(()=>{ie.current=Pe},[Pe]);const _e=t.useCallback(({data:e})=>{e.size>0&&Se.poseDetection.connected()&&(oe.current||(oe.current=!0,Se.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:ae.current,consecutiveFalse:re.current,type:"body_scan_instruction"});const t=s.findAudioElement();!0===e.status&&e.sid===y?(re.current=0,ae.current<2?(ae.current+=1,1!==ae.current||ce.current?2===ae.current&&t?.paused&&s.speechService.playAudio(s.voiceOverAssetsPath+e.audio):(ce.current=!0,s.speechService.stopAudio(),await s.speechService.playAudio(s.voiceOverAssetsPath+e.audio))):(B(e.audio),clearTimeout(v),Se.poseDetection.disconnect(),oe.current=!1,setTimeout(()=>ie.current(),1e3))):(re.current+=1,re.current>=3&&(ae.current=0,ce.current=!1),!t?.paused||b&&b?.audioName===e.audio?b?.audioName===e.audio&&t?.paused&&(b&&b.no_of_times_skipped>=b.skipCount?(b.no_of_times_skipped=0,s.speechService.playAudio(s.voiceOverAssetsPath+e.audio)):b&&(b.no_of_times_skipped+=1)):(b={skipCount:2,no_of_times_skipped:0,audioName:e.audio},s.speechService.playAudio(s.voiceOverAssetsPath+e.audio)))}})),C?.current&&null!==C.current.getScreenshot()&&Se.poseDetection.videoEmit({image:C.current.getScreenshot()||"",scanId:r}))},[C,r,Se,y,s.speechService,f,p]),Ae=t.useCallback(async()=>{A(!0),he(!0),ve?.(),se.current&&(se.current=!1,s.handleScanTimeCapture({eventName:"scan started",scanID:r,status:"success",email:p})),i(s.getCurrentTimeInSeconds()),D(!0),ee.current&&await s.speechService.playAudio(`${s.voiceOverAssetsPath}StartScan.mp3`),ee.current&&await s.speechService.playAudio(`${s.voiceOverAssetsPath}LiftArmsAndHoldAtHip.mp3`),ee.current&&(A(!1),I(!0),H(!0),Z(!0),Ce());try{if(C&&C.current&&C.current.stream&&ee.current){const e=C.current.stream.getVideoTracks()[0];if(e){const t=e.getSettings();j.current=t.frameRate||null}const t={videoBitsPerSecond:15e5};le[0]&&(t.mimeType=le[0]),ee.current&&(w.current=new MediaRecorder(C.current.stream,t)),ee.current&&w.current&&w.current.addEventListener("dataavailable",_e),X([...Q,_e]),w.current&&w.current.start(1e3),P(!1),ee.current&&(v=setTimeout(Fe,2e3))}}catch(e){console.log("error ----------",e)}},[C,le,_e,Q,Fe,ee,ve]);return t.useEffect(()=>(f&&(n(!0),Te()),()=>{y&&(Se.poseDetection.disconnect(),s.posthog.capture(`${f}/pose_detection_disconnected`,{scanID:r,email:p,id:y})),Q.forEach(e=>{w?.current?.removeEventListener("dataavailable",e)})}),[f]),t.useEffect(()=>{O.push(R)},[R]),t.useEffect(()=>{z([])},[K]),t.useEffect(()=>{const e=k.length&&k.length>0;M||!e||T||!ee.current||G||w&&w.current&&(T||(w.current.stop(),P(!0)))},[M,T,k,G]),t.useEffect(()=>{const e=k.length&&k.length>0;if(M||!e||T)console.log("No video found to upload.");else if(w&&w.current&&ee.current&&!G&&!T){const e=new File(k,`${r}.${Ee}`,{type:Ne});ye?.(),xe?.(!0),c(""),ge?.(e,j.current)}},[M,T,k,G,w,ee]),t.useEffect(()=>{const e=s.getSupportedMediaRecorderTypes(ke,s.videoTypes);ue(e)},[ke]),t.useEffect(()=>{be()},[]),e.jsx(h,{resetDetector:a,resetScan:be,loadingCam:E,onPause:je,showRestart:W,pause:G,onReScan:Ie,recordingStarted:T,isScanning:_,startSendingVideoFrames:Ae,faceDone:L,stopRecording:De,showPause:Y,webcamRef:C,onUserMedia:Ce,onUserMediaError:we,videoConstraints:pe,webcamKey:de})});function w({scanID:s,userDetails:n,setIsVideoUploaded:a,setScanFailsError:r,setScanStartTime:o,setScanUniqueKey:c}){const[i,l]=t.useState(90),[u,d]=t.useState(0),[m,p]=t.useState(null),[h,g]=t.useState(!1),[x,S]=t.useState(0),v=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(v.current=[...v.current.slice(-4),w],v.current.length>=5){const e=Math.max(...v.current)-Math.min(...v.current);S(j&&e<2?e=>Math.min(100,e+10):e=>Math.max(0,e-20))}j||null===m&&!h||N()},[w,j,m,h]),t.useEffect(()=>{x>=100&&null===m&&!h&&k(),x<50&&null!==m&&N()},[x,m,h]);const k=()=>{p(3);const e=setInterval(()=>{p(t=>null===t||t<=1?(clearInterval(e),g(!0),null):t-1)},1e3)},N=()=>{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),S(0),b(!1),v.current=[]},scanID:s,userDetails:n,setIsVideoUploaded:a,setScanFailsError:r,setScanStartTime:o,setScanUniqueKey:c})})}function j({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 k({link:n,onReady:a,wrapperClassName:r="[&_video]:rounded-t-[20px] w-full h-full"}){const o=t.useRef(null),i=t.useRef(null);let l={autoplay:!0,controls:!1,responsive:!0,fluid:!0,muted:!0,navigationUI:"hide",preload:"metadata",poster:s.videoPoster};return t.useEffect(()=>{if(!i.current&&n&&o?.current){const e=c(o.current,{...l});e.ready(()=>{i.current=e;const t={...l,sources:[{src:n,type:"application/x-mpegURL"}]};e.autoplay(t.autoplay),e.src(t.sources),a?.(e)})}},[n,o]),t.useEffect(()=>{const e=i.current;return()=>{e&&!e.isDisposed()&&(e.dispose(),i.current=null)}},[i]),e.jsx("div",{className:r,children:e.jsx("video",{ref:o,muted:!0,className:"video-js",playsInline:!0,onDrag:e=>e.preventDefault()})})}function N({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",{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,{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(k,{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:S,scanType:v}=a||{},y=[s.CLOTHING_CUSTOM_SCAN,s.CLOTHING_BANNER_SCAN,s.CLOTHING_CUSTOM_FIT_SCAN].includes(v??""),[b,C]=t.useState(!0),w=t.useCallback(async()=>{try{y&&(await(m?.auth.addUser({scanId:n,email:S,name:x,gender:p,height:h})),d?.()),s.posthog.capture(f??"",{scanID:n,email:S,height:h,focalLength:g,clothesFit:"0",gender:p})}catch(e){console.log(e)}},[y]),{translate:k}=t.useContext(s.LanguageContext)||{};t.useEffect(()=>{(c||i)&&w()},[c,i]);const N=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(j,{loader:r?.loader,setShowDrawer:C}),e.jsx(o.Drawer,{open:b,onClose:(e,t)=>{},disablePortal:!0,className:"camera-drawer",anchor:"bottom",children:e.jsx("div",{className:"max-w-[28rem] mx-auto w-full h-full flex text-center flex-col justify-between items-center bg-primary rounded-t-[30px] p-[1rem]",style:{background:r?.style?.base?.backgroundColor},children:e.jsxs("div",{className:"w-full h-full flex flex-col",children:[e.jsx(s.Header,{title: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"})})}),N&&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:S,setScanFailsError:v,setScanStartTime:y,resetScan:b,onCustomScanSuccess:C,swan:k,onComplete:D}=t.useContext(s.ParamsContext),T=s.useConfig();return S&&!x?e.jsx(s.Modal,{variant:"portrait",config:T}):r?e.jsxs(e.Fragment,{children:[e.jsx(j,{}),e.jsx(o.Drawer,{anchor:"bottom",open:!0,className:"camera-drawer",onClose:(e,t)=>{},disablePortal:!0,children:e.jsx(N,{scanFailsError:!0,onNext:a,gender:i})})]}):c?e.jsx(E,{isSuccess:!0,onComplete:D,config:T}):h?e.jsx("div",{className:"flex top-0 !mt-0 left-0 z-[999] absolute justify-center items-center w-full h-full",style:{background:T?.style?.base?.backgroundColor},children:e.jsx(s.LoadingScreen,{url:T?.loader,loaderType:"black"})}):g.disabled?e.jsx(s.Modal,{}):x||u||p||f?(x||p||f)&&!u?e.jsx(E,{scanId:l,isMeasurementAvailable:p,userDetails:n,isVideoUploadedCorrect:f,onCustomScanSuccess:C,swan:k,onComplete:D,config:T}):e.jsxs(e.Fragment,{children:[e.jsx(j,{}),e.jsx(o.Drawer,{anchor:"bottom",open:!0,className:"camera-drawer",onClose:(e,t)=>{},disablePortal:!0,children:e.jsx(N,{scanFailsError:u,onNext:()=>{a?.(),b()},setScanUniqueKey:d,gender:i,setIsVideoUploaded:m})})]}):e.jsx(w,{scanID:l,userDetails:n,setIsVideoUploaded:m,setScanFailsError:v,setScanStartTime:y,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:S,isSuccess:v}=n,y={email:"",shopDomain:"",gender:"male",heightInCm:0,scanType:"",deviceFocalLength:0,deviceModelName:"",sourceTag:"",...n.userDetails??{}},b=n.token??"",{gender:C,scanType:w,shopDomain:j,heightInCm:k,email:N,deviceFocalLength:E,deviceModelName:T,callbackUrl:I,sourceTag:L}=y,F=t.useMemo(()=>s.getSwanService(b),[b]),[M,P]=t.useState(!1),[_,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(""),P(!1),q(!1)},[]);t.useEffect(()=>{ee&&!M&&te()},[ee,M,te]);const se=()=>{Y(null),Q("")},ne=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:N}),A(!0),void p?.(e);h?.(e),A(!0),se();const t=J;R(!0),s.handleScanTimeCapture({eventName:`${j}/measurement_success/fit-view`,scanID:t,status:"success",email:N}),X&&s.handleScanTimeCapture({eventName:`${j}/scan_completion_time`,scanID:t,status:"success",completionTime:s.getCurrentTimeInSeconds()-X,email:N})},[w,j,J]),ae=e=>{R(!1),K(""),A(!1),F.measurement.handleMeasurementSocket({scanId:J,onPreopen:()=>{s.handleWebSocketCapture({eventName:`${j}/webSocket`,scanID:J,connection:"pre_open",type:"measurement_recommendation",email:N})},onOpen:()=>{u?.(),s.handleWebSocketCapture({eventName:`${j}/webSocket`,scanID:J,connection:"open",type:"measurement_recommendation",email:N})},onClose:()=>{d?.(),s.handleWebSocketCapture({eventName:`${j}/webSocket`,scanID:J,connection:"close",type:"measurement_recommendation",email:N})},onError:e=>{var t;t=e,f?.({...t,message:s.handleErrorMessage(t)}),se(),R(!1),K(t),A(!1),s.handleScanTimeCapture({eventName:`${j}/measurement_failed/fit-view`,scanID:J,status:"failed",email:N,message:s.handleErrorMessage(t)}),X&&s.handleScanTimeCapture({eventName:`${j}/scan_completion_time`,scanID:J,status:"failed",completionTime:s.getCurrentTimeInSeconds()-X,email:N}),s.handleWebSocketCapture({eventName:`${j}/webSocket`,scanID:J,connection:"error",type:"measurement_recommendation",email:N})},onSuccess:e=>{s.handleWebSocketCapture({eventName:`${j}/webSocket`,scanID:J,connection:"success",type:"measurement_recommendation",email:N}),ne(e)}})},re=t.useCallback(async(e,t)=>{const n=Number((e.size/1048576).toFixed(2)),a=null!=t?t:await s.getVideoFPS(e),r=s.createObjectMetadataArray({gender:C,focal_length:`${E}`,height:`${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:N,data:JSON.stringify([...r,{fileSizeInMB:n,video_fps:a||0}])}),i?.();try{await F.fileUpload.uploadFileFrontend({file:e,arrayMetaData:r,scanId:J,email:N}),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:N,data:JSON.stringify(r)}),s.handleScanTimeCapture({eventName:"scan finished",scanID:J,status:"success",email:N}),Y(s.getCurrentTimeInSeconds()),setTimeout(()=>{q(!0)},3e3)}catch(e){s.handleScanTimeCapture({eventName:"scan finished",scanID:J,status:"failed",email:N,message:s.handleErrorMessage(e)}),s.handleScanTimeCapture({eventName:`${j}/scan_failed`,scanID:J,status:"failed",email:N,message:s.handleErrorMessage(e),data:JSON.stringify(r)}),K(s.handleErrorMessage(e)),q(!1),f?.({...e,message:s.handleErrorMessage(e)}),se()}finally{G(!1),l?.()}},[J,Z,i,l]),oe=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:N}),W(!1)):(W(!1),s.handleScanTimeCapture({eventName:`${j}/camera_activation`,scanID:J,status:"success",email:N})),O(e),K(""),q(!1)},[N,J,Q,j]);return t.useEffect(()=>{S||v||j&&oe()},[j,k,S,v]),t.useEffect(()=>{S||v||B&&j&&J&&ae()},[B,j,J,S,v]),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:S,isSuccess:v,onScanSuccess:h,gender:C,scanUniqueKey:J,scanFailsError:z,setScanUniqueKey:Q,setIsVideoUploaded:q,isMeasurementAvailable:$,isVideoUploadedCorrect:_,loading:V,showDeniedModal:U,uploadLoading:M,isLandscape:ee,setStartGyro:G,uploadScanFile:re,setUploadLoading:P,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-BVsw81qu.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 u,useRef as d}from"react";import{L as m,u as p,H as f,b as h,S as g,z as y,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,e as L,r as M,D as _,c as $,M as U,a as A,E as j,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,f as H,h as J,n as G,w as Q,T as Y,t as X,C as Z,y as ee}from"./LoadingScreen-BsIi48_Z.js";import te from"clsx";import ne from"react-webcam";import{X as re}from"lucide-react";import{Dialog as ae,Box as se,Drawer as oe}from"@mui/material";import ce from"video.js";const ie="DESKTOP",le="TAB",ue="MOBILE",de=c(void 0);function me({children:t}){const[n,r]=a([window?.innerWidth,window?.innerHeight]),[s,c]=a(!1),u=()=>{r([window?.innerWidth,window?.innerHeight])};o(()=>{u()},[]),i(()=>(window.addEventListener("resize",u),()=>window.removeEventListener("resize",u)),[u]);let d=ie;n[0]>768&&n[0]<1024&&(d=le),n[0]<768&&(d=ue);const m=l(()=>({size:n,setSize:r,clearInputs:s,setClearInputs:c,media:d}),[n,s,d]);return e(de.Provider,{value:m,children:t})}var pe=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 fe=r.memo(function({angle:n,countdown:r,isScanning:a,isInTargetRange:o,stabilityScore:c,children:i}){const{translate:d}=u(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},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:te("relative flex h-[4rem] w-[4rem] items-center justify-center rounded-[9999px] ",o?"bg-[#fff]/20 border-[#fff]":"bg-[#fff]/10 border-[#fff]"),style:{transform:`translateY(${3*(90-n)}px)`,transition:"transform 0.2s ease-out",border:`2px solid ${S()}`},children:[e("div",{className:`h-[1rem] w-[1rem] rounded-[9999px] bg-[${S()}]/80`,style:{backgroundColor:`${S()}B3`}}),t("div",{className:te("mt-[.5rem] text-center w-[180px] flex-col flex items-center absolute top-[60px]",x()),style:{color:S()},children:[e(pe,{size:30}),t("p",{style:{fontFamily:g?.style?.base?.baseFontFamily||"Inter, sans-serif"},children:[" ",d?.(h.startLevelCheck),e("br",{})]})]})]}),null!==C&&e("div",{className:"absolute bottom-[8rem] text-center",children:e("div",{className:te("text-sm font-medium px-4 py-1.5 bg-black/20 rounded-[9999px] mt-8",x()),style:{fontFamily:g?.style?.base?.baseFontFamily||"Inter, sans-serif",color:S()},children:d?.(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:te("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:te("text-[.75rem] opacity-50",x()),style:{fontFamily:g?.style?.base?.baseFontFamily||"Inter, sans-serif",color:S()},children:d?.(h.placePhoneUpright)})})]})});function he({resetScan:n,loadingCam:r,onUserMedia:a,onPause:s,pause:o,recordingStarted:c,startSendingVideoFrames:i,showPause:l,webcamRef:d,onUserMediaError:p,resetDetector:f,videoConstraints:w,webcamKey:x}){const{media:b}=u(de)||{},{translate:S}=u(m)||{};return t("div",{className:"App w-screen h-[100vh] relative common-ui-main",children:[e("span",{onClick:()=>{n(),f()},className:"fixed right-[20px] top-[20px] z-[999]",children:e(re,{className:"text-[#fff]"})}),e("div",{className:"w-full h-full overflow-hidden ",children:b===ue&&e(ne,{audio:!1,ref:d,screenshotQuality:1,videoConstraints:w,mirrored:!0,screenshotFormat:"image/jpeg",onUserMedia:a,onUserMediaError:p,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:[l&&e(g,{className:"!w-[180px] !h-[40px] !py-[0] mx-auto ",prefix:y,buttonText:S?.(h.pause),buttonFunc:s,btnSecondary:!0}),o?e("div",{children:e(g,{className:"!w-[180px] !h-[40px] !py-[0] mx-auto",buttonText:S?.(h.restart),buttonFunc:n,btnSecondary:!0})}):c?null:e(g,{className:"!w-[180px] !h-[40px] !py-[0] mx-auto !bg-[#ffffff] !text-[#000000] "+(r?"!opacity-50":""),buttonText:S?.(h.startScan),buttonFunc:i,disabled:r})]}),e("audio",{id:"audioElement",crossOrigin:"anonymous",preload:"auto",style:{position:"absolute",zIndex:-99999},src:`${v}scanAudioInstructions/silence.mp3`})]})}let ge=null,ye=null,ve=null;let we,xe=null,be=null;var Se=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,$=d(null),U=d(null),A=d(null),[j,P]=a([]),[z,V]=a(!0),[R,B]=a(!1),[q,K]=a(!1),[O,W]=a(!0),[H,J]=a(!1),G=d(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([]),[ue,de]=a(!1),me=d(!0),{poseDetector:pe}=function(){const[e,t]=a(0),[n,r]=a(0),[s,c]=a(!1),i=d(0),l=d(0),u=d(!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-c4ZA7-te.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(u.current=!0,!ye)return ge||(ge=m()),ge.then(e=>{e&&u.current&&c(!0)}),()=>{u.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||!u.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&&u.current&&c(!0))}}}(),fe=d(!0),Se=d(!1),Ce=d(0),Ne=d(0),De=d(!1),Ie=d(!1),ke=d(()=>{}),[Fe,Te]=a([]),[Ee,Le]=a(0),[Me,_e]=a(w),{setStartGyro:$e,uploadScanFile:Ue,setUploadLoading:Ae,swan:je,onScanStart:Pe,onCaptureComplete:ze}=u(x),Ve=()=>{Se.current=!1,clearTimeout(we),G.current&&clearTimeout(G.current),p(L()),i(""),Ae?.(!1),P([]),A.current=null,V(!0),B(!1),K(!1),W(!0),J(!1),G.current=null,Y(""),Z([]),te(""),re(!ne),$e(!1),S.stopAudio(),se(!1),ce(!1),Ce.current=0,Ne.current=0,De.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,de(!1),c(!1),$.current?.stream&&V(!1)},Re=s(()=>{setTimeout(()=>{V(!1)},1e3)},[]),Be=s(e=>{if(console.log("camera error",e),Me===w)return _e(b),void Le(e=>e+1);V(!1)},[Me]),qe=s(()=>{me.current=!1,ce(!0),de(!1),G.current&&clearTimeout(G.current),U.current&&U.current.pause(),S.stopAudio(),je.poseDetection.disconnect(),Ce.current=0,Ne.current=0,De.current=!1,Ie.current=!1,U.current&&U.current.stop(),ie.forEach(e=>{U.current&&U.current.removeEventListener("dataavailable",e)}),le([]),clearTimeout(we)},[U,ie,S,me]),Ke=l(()=>C(),[]),Oe=N(Fe),We=D(Oe),He=s(async()=>{me.current=!0,await S.playAudio(`${v}SpotOn.mp3`),ce(!1),de(!1),G.current&&clearTimeout(G.current),B(!1)},[G,S]),Je=s(async()=>{try{xe=await je.poseDetection.connect(),console.log(xe,"websocket connected"),I.capture(`${_}/pose_detection_connected`,{scanID:r,email:y,id:xe})}catch(e){console.log(e,"while connecting websocket")}},[r,_,y]),Ge=s(async()=>{k({eventName:`${_}/rescan`,email:y,scanID:r,height:g,gender:h,status:!1}),me.current=!1,je.poseDetection.disconnect(),Ve(),await Je(),tt()},[Je,r,y]),Qe=s(({data:e})=>{e&&e.size>0&&me.current&&(P(t=>t.concat(e)),!Se.current&&$.current&&(Se.current=!0,pe(()=>{He(),F({eventName:`${_}/tensorFlow`,scanID:r,email:y,message:"recording stopped by tensorflow "})},$)))},[He,F,_,r,y,$]),Ye=s(async()=>{X.length>0&&me.current&&(await S.playAudio(v+X[X.length-1]),me.current&&(we=setTimeout(Ye,2e3)))},[X,me]),Xe=s(()=>{U&&U.current&&U.current.stop(),B(!0);try{if($&&$.current&&$.current.stream){const e=$.current.stream.getVideoTracks()[0];if(e){const t=e.getSettings();A.current=t.frameRate||null}const t={videoBitsPerSecond:15e5};Fe[0]&&(t.mimeType=Fe[0]),U.current=new MediaRecorder($.current.stream,t),U.current.addEventListener("dataavailable",Qe),le([...ie,Qe]),U.current.start(1e3),W(!1)}}catch(e){console.log("error while using media recorder",e)}},[$,Fe,Qe,ie]),Ze=s(async()=>{G.current&&clearTimeout(G.current),Xe(),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`)},[Xe,me,S]);o(()=>{ke.current=Ze},[Ze]);const et=s(({data:e})=>{e.size>0&&je.poseDetection.connected()&&(De.current||(De.current=!0,je.poseDetection.poseStatus(async e=>{if(console.log("poseStatus data:",e),e&&e.audio&&e.audio.length>0){I.capture(`${_}/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=document.querySelector("#audioElement");!0===e.status&&e.sid===xe?(Ne.current=0,Ce.current<2?(Ce.current+=1,1!==Ce.current||Ie.current?2===Ce.current&&t?.paused&&S.playAudio(v+e.audio):(Ie.current=!0,S.stopAudio(),await S.playAudio(v+e.audio))):(te(e.audio),clearTimeout(we),je.poseDetection.disconnect(),De.current=!1,setTimeout(()=>ke.current(),1e3))):(Ne.current+=1,Ne.current>=3&&(Ce.current=0,Ie.current=!1),!t?.paused||be&&be?.audioName===e.audio?be?.audioName===e.audio&&t?.paused&&(be&&be.no_of_times_skipped>=be.skipCount?(be.no_of_times_skipped=0,S.playAudio(v+e.audio)):be&&(be.no_of_times_skipped+=1)):(be={skipCount:2,no_of_times_skipped:0,audioName:e.audio},S.playAudio(v+e.audio)))}})),$?.current&&null!==$.current.getScreenshot()&&je.poseDetection.videoEmit({image:$.current.getScreenshot()||"",scanId:r}))},[$,r,je,xe,S,_,y]),tt=s(async()=>{J(!0),$e(!0),Pe?.(),fe.current&&(fe.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),de(!0),Re());try{if($&&$.current&&$.current.stream&&me.current){const e=$.current.stream.getVideoTracks()[0];if(e){const t=e.getSettings();A.current=t.frameRate||null}const t={videoBitsPerSecond:15e5};Fe[0]&&(t.mimeType=Fe[0]),me.current&&(U.current=new MediaRecorder($.current.stream,t)),me.current&&U.current&&U.current.addEventListener("dataavailable",et),le([...ie,et]),U.current&&U.current.start(1e3),W(!1),me.current&&(we=setTimeout(Ye,2e3))}}catch(e){console.log("error ----------",e)}},[$,Fe,et,ie,Ye,me,Pe]);return o(()=>(_&&(t(!0),Je()),()=>{xe&&(je.poseDetection.disconnect(),I.capture(`${_}/pose_detection_disconnected`,{scanID:r,email:y,id:xe})),ie.forEach(e=>{U?.current?.removeEventListener("dataavailable",e)})}),[_]),o(()=>{X.push(Q)},[Q]),o(()=>{Z([])},[ee]),o(()=>{const e=j.length&&j.length>0;O||!e||R||!me.current||oe||U&&U.current&&(R||(U.current.stop(),W(!0)))},[O,R,j,oe]),o(()=>{const e=j.length&&j.length>0;if(O||!e||R)console.log("No video found to upload.");else if(U&&U.current&&me.current&&!oe&&!R){const e=new File(j,`${r}.${We}`,{type:Oe});ze?.(),Ae?.(!0),i(""),Ue?.(e,A.current)}},[O,R,j,oe,U,me]),o(()=>{const e=E(Ke,M);Te(e)},[Ke]),o(()=>{Ve()},[]),e(he,{resetDetector:n,resetScan:Ve,loadingCam:z,onPause:qe,showRestart:ae,pause:oe,onReScan:Ge,recordingStarted:R,isScanning:H,startSendingVideoFrames:tt,faceDone:q,stopRecording:He,showPause:ue,webcamRef:$,onUserMedia:Re,onUserMediaError:Be,videoConstraints:Me,webcamKey:Ee})});function Ce({scanID:t,userDetails:n,setIsVideoUploaded:r,setScanFailsError:s,setScanStartTime:c,setScanUniqueKey:i}){const[l,u]=a(90),[m,p]=a(0),[f,h]=a(null),[g,y]=a(!1),[v,w]=a(0),x=d([]),[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)),u(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(fe,{angle:C,countdown:f,isScanning:g,isInTargetRange:N,stabilityScore:v,children:g&&e(Se,{setIsScanLocked:S,resetDetector:()=>{u(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 Ne({setShowDrawer:t,config:n,loader:r}){const[c,i]=a({disabled:!1,message:""}),[l,u]=a(!0),m=d(null),p=s(async()=>{const e=await _();i(e),u(!1)},[]);return o(()=>{p()},[]),l?e($,{url:r,loaderType:"black"}):c?.disabled?e(U,{config:n,message:c?.message}):e(ne,{audio:!1,ref:m,screenshotQuality:1,videoConstraints:A,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=d(null),s=d(null);let c={autoplay:!0,controls:!1,responsive:!0,fluid:!0,muted:!0,navigationUI:"hide",preload:"metadata",poster:j};return o(()=>{if(!s.current&&t&&a?.current){const e=ce(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 Ie({scanFailsError:r,onNext:s,gender:o,setScanUniqueKey:c,setIsVideoUploaded:i}){const{translate:l}=u(m)||{},d=p(),[y,v]=a(!1),w=()=>{v(!y)};return t(n,{children:[t("div",{className:"flex common-ui-main flex-col h-full max-w-[28rem] mx-auto w-full rounded-t-[20px] overflow-y-auto",style:{background:d?.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: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:l?.(h.issueWithScan)}),e("p",{style:{fontFamily:d?.style?.base?.baseFontFamily||"Inter, sans-serif",fontSize:d?.style?.base?.baseFontSize||"16px",color:d?.style?.base?.baseTextColor||"#1E1E1E"},children:l?.(h.reason)}),e("p",{style:{fontFamily:d?.style?.base?.baseFontFamily||"Inter, sans-serif",fontSize:d?.style?.base?.baseFontSize||"16px",color:d?.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,{disabled:!1,buttonText:l?.(h.scanAgain),className:"!shadow-none",buttonFunc:()=>{s?s?.():c?.(L()),i?.(!1)}})})]}),y&&t(ae,{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(re,{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 ke({scanId:n,userDetails:r,config:c,isVideoUploadedCorrect:i,isMeasurementAvailable:l,onComplete:d,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}=u(m)||{};o(()=>{(i||l)&&E()},[i,l]);const M=p||i||l;return e(se,{className:"flex h-full w-full flex-col common-ui-main",children:t("div",{className:"h-full w-full flex-col items-center justify-center flex",children:[e(Ne,{loader:c?.loader,setShowDrawer:T}),e(oe,{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:()=>{d?.()}})]})})})]})})}const Fe=()=>{const{userDetails:r,onRetry:a,isError:s,isSuccess:o,gender:c,scanUniqueKey:i,scanFailsError:l,setScanUniqueKey:d,setIsVideoUploaded:m,isMeasurementAvailable:f,isVideoUploadedCorrect:h,loading:g,showDeniedModal:y,uploadLoading:v,setScanFailsError:w,setScanStartTime:b,resetScan:S,onCustomScanSuccess:C,swan:N,onComplete:D}=u(x),I=p();return s?t(n,{children:[e(Ne,{}),e(oe,{anchor:"bottom",open:!0,className:"camera-drawer",onClose:(e,t)=>{},children:e(Ie,{scanFailsError:!0,onNext:a,gender:c})})]}):o?e(ke,{isSuccess:!0,onComplete:D}):g?e("div",{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($,{url:I?.loader,loaderType:"black"})}):y.disabled?e(U,{}):v||l||f||h?(v||f||h)&&!l?e(ke,{scanId:i,isMeasurementAvailable:f,userDetails:r,isVideoUploadedCorrect:h,onCustomScanSuccess:C,swan:N,onComplete:D}):t(n,{children:[e(Ne,{}),e(oe,{anchor:"bottom",open:!0,className:"camera-drawer",onClose:(e,t)=>{},children:e(Ie,{scanFailsError:l,onNext:()=>{a?.(),S()},setScanUniqueKey:d,gender:c,setIsVideoUploaded:m})})]}):e(Ce,{scanID:i,userDetails:r,setIsVideoUploaded:m,setScanFailsError:w,setScanStartTime:b,setScanUniqueKey:d})},Te=n=>{const{config:r,onRetry:c,onScanStart:i,onCaptureComplete:u,onUploadStart:d,onUploadEnd:m,onMeasurementSocketStart:p,onMeasurementSocketClose:f,onIntermediateScanSuccess:h,onScanError:g,onScanSuccess:y,onCustomScanSuccess:v,onComplete:w,isError:b,isSuccess:S}=n,C={email:"",shopDomain:"",gender:"male",heightInCm:0,scanType:"",deviceFocalLength:0,deviceModelName:"",sourceTag:"",...n.userDetails??{}},N=n.token??"",{gender:D,scanType:I,shopDomain:k,heightInCm:E,email:M,deviceFocalLength:$,deviceModelName:A,callbackUrl:j,sourceTag:z}=C,V=l(()=>H(N),[N]),[R,B]=a(!1),[q,K]=a(!1),[O,W]=a(!1),[te,ne]=a({disabled:!1,message:""}),[re,ae]=a(""),[se,oe]=a(!1),[ce,ie]=a(!0),[le,ue]=a(!1),[de,pe]=a(""),[fe,he]=a(T()),{gyroData:ge}=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}}(le),{isLandscape:ye}=J();G();const ve=s(()=>{pe(L()),ae(""),B(!1),oe(!1)},[]);o(()=>{ye&&!R&&ve()},[ye,R,ve]);const we=()=>{he(null),pe("")},xe=s(async e=>{if(e&&"success"===e?.scanStatus&&"intermediate"===e?.resultType&&200===e?.code)return F({eventName:`${k}/measurement_success/intermediate`,scanID:de,status:"success",email:M}),K(!0),void h?.(e);y?.(e),K(!0),we();const t=de;W(!0),F({eventName:`${k}/measurement_success/fit-view`,scanID:t,status:"success",email:M}),fe&&F({eventName:`${k}/scan_completion_time`,scanID:t,status:"success",completionTime:T()-fe,email:M})},[I,k,de]),be=e=>{W(!1),ae(""),K(!1),V.measurement.handleMeasurementSocket({scanId:de,onPreopen:()=>{ee({eventName:`${k}/webSocket`,scanID:de,connection:"pre_open",type:"measurement_recommendation",email:M})},onOpen:()=>{p?.(),ee({eventName:`${k}/webSocket`,scanID:de,connection:"open",type:"measurement_recommendation",email:M})},onClose:()=>{f?.(),ee({eventName:`${k}/webSocket`,scanID:de,connection:"close",type:"measurement_recommendation",email:M})},onError:e=>{var t;t=e,g?.({...t,message:P(t)}),we(),W(!1),ae(t),K(!1),F({eventName:`${k}/measurement_failed/fit-view`,scanID:de,status:"failed",email:M,message:P(t)}),fe&&F({eventName:`${k}/scan_completion_time`,scanID:de,status:"failed",completionTime:T()-fe,email:M}),ee({eventName:`${k}/webSocket`,scanID:de,connection:"error",type:"measurement_recommendation",email:M})},onSuccess:e=>{ee({eventName:`${k}/webSocket`,scanID:de,connection:"success",type:"measurement_recommendation",email:M}),xe(e)}})},Se=s(async(e,t)=>{const n=Number((e.size/1048576).toFixed(2)),r=null!=t?t:await Q(e),a=Y({gender:D,focal_length:`${$}`,height:`${E}`,customer_store_url:k,clothes_fit:"0",scan_type:I,callback_url:j,source_tag:z});F({eventName:`${k}/body_scan_meta_data`,scanID:de,email:M,data:JSON.stringify([...a,{fileSizeInMB:n,video_fps:r||0}])}),d?.();try{await V.fileUpload.uploadFileFrontend({file:e,arrayMetaData:a,scanId:de,email:M}),await V.fileUpload.setDeviceInfo({model:A,detection:"manual",gyro:ge,scanId:de}),console.log("video successfully uploaded"),oe(!1),F({eventName:`${k}/scan_success`,scanID:de,status:"success",email:M,data:JSON.stringify(a)}),F({eventName:"scan finished",scanID:de,status:"success",email:M}),he(T()),setTimeout(()=>{oe(!0)},3e3)}catch(e){F({eventName:"scan finished",scanID:de,status:"failed",email:M,message:P(e)}),F({eventName:`${k}/scan_failed`,scanID:de,status:"failed",email:M,message:P(e),data:JSON.stringify(a)}),ae(P(e)),oe(!1),g?.({...e,message:P(e)}),we()}finally{ue(!1),m?.()}},[de,ge,d,m]),Ce=s(async()=>{if(+E<152.4||+E>213.36)return void g?.({message:"Height must be between 152.4cm (5ft) and 213.36cm (7ft)"});const e=await _();e.disabled?(F({eventName:`${k}/camera_activation`,scanID:de,status:"failed",email:M}),ie(!1)):(ie(!1),F({eventName:`${k}/camera_activation`,scanID:de,status:"success",email:M})),ne(e),ae(""),oe(!1)},[M,de,pe,k]);return o(()=>{b||S||k&&Ce()},[k,E,b,S]),o(()=>{b||S||se&&k&&de&&be()},[se,k,de,b,S]),e(X,{children:e(Z,{config:r,children:t(me,{children:[ye&&!R&&e(U,{variant:"portrait",config:r}),e(x.Provider,{value:{userDetails:C,onRetry:c,onScanError:g,isError:b,isSuccess:S,onScanSuccess:y,gender:D,scanUniqueKey:de,scanFailsError:re,setScanUniqueKey:pe,setIsVideoUploaded:oe,isMeasurementAvailable:O,isVideoUploadedCorrect:q,loading:ce,showDeniedModal:te,uploadLoading:R,setStartGyro:ue,uploadScanFile:Se,setUploadLoading:B,resetScan:ve,setScanFailsError:ae,setScanStartTime:he,onScanStart:i,onCaptureComplete:u,onCustomScanSuccess:v,onComplete:w,swan:V},children:e(Fe,{})})]})})})};export{Te as B};
2
+ //# sourceMappingURL=BodyScan-BkOwkvRJ.js.map
@@ -0,0 +1,2 @@
1
+ import{jsx as e,jsxs as t,Fragment as n}from"react/jsx-runtime";import a,{useState as r,useCallback as s,useEffect as o,createContext as i,useLayoutEffect as c,useMemo as l,useContext as d,useRef as u}from"react";import{L as m,u as p,H as f,b as h,S as g,y,v,h as w,P as x,n as b,s as S,i as C,j as N,k as D,p as F,z as I,w as k,A as T,o as E,e as L,q as $,B as M,D as _,c as U,a as A,E as z,I as j,V as P,J as V,K as B,M as R,G as q,N as K,O as W,Q as O,f as H,l as J,t as G,R as Q,r as Y,C as X,x as Z}from"./LoadingScreen-DuHTvhiM.js";import ee from"clsx";import te from"react-webcam";import{X as ne}from"lucide-react";import{Dialog as ae,Box as re,Drawer as se}from"@mui/material";import oe from"video.js";const ie="DESKTOP",ce="TAB",le="MOBILE",de=i(void 0);function ue({children:t}){const[n,a]=r([window?.innerWidth,window?.innerHeight]),[s,i]=r(!1),d=()=>{a([window?.innerWidth,window?.innerHeight])};o(()=>{d()},[]),c(()=>(window.addEventListener("resize",d),()=>window.removeEventListener("resize",d)),[d]);let u=ie;n[0]>768&&n[0]<1024&&(u=ce),n[0]<768&&(u=le);const m=l(()=>({size:n,setSize:a,clearInputs:s,setClearInputs:i,media:u}),[n,s,u]);return e(de.Provider,{value:m,children:t})}var me=a.memo(function({size:n=16}){return t("svg",{width:n,height:n,viewBox:"0 0 25 25",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[e("path",{d:"M22.6968 14.6968C22.6968 16.8185 21.8539 18.8533 20.3536 20.3536C18.8533 21.8539 16.8185 22.6968 14.6968 22.6968",stroke:"white",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),e("path",{d:"M18.6968 11.6968V10.6968C18.6968 10.1663 18.4861 9.65764 18.111 9.28256C17.7359 8.90749 17.2272 8.69678 16.6968 8.69678C16.1663 8.69678 15.6576 8.90749 15.2826 9.28256C14.9075 9.65764 14.6968 10.1663 14.6968 10.6968",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),e("path",{d:"M14.6968 10.6968V9.69678C14.6968 9.16634 14.4861 8.65764 14.111 8.28256C13.7359 7.90749 13.2272 7.69678 12.6968 7.69678C12.1663 7.69678 11.6576 7.90749 11.2826 8.28256C10.9075 8.65764 10.6968 9.16634 10.6968 9.69678V10.6968",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),e("path",{d:"M10.6968 10.1968V4.69678C10.6968 4.16634 10.4861 3.65764 10.111 3.28256C9.73592 2.90749 9.22721 2.69678 8.69678 2.69678C8.16634 2.69678 7.65764 2.90749 7.28256 3.28256C6.90749 3.65764 6.69678 4.16634 6.69678 4.69678V14.6968",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),e("path",{d:"M18.6969 11.6968C18.6969 11.1663 18.9076 10.6576 19.2827 10.2826C19.6577 9.90749 20.1664 9.69678 20.6969 9.69678C21.2273 9.69678 21.736 9.90749 22.1111 10.2826C22.4862 10.6576 22.6969 11.1663 22.6969 11.6968V14.6968C22.6969 16.8185 21.854 18.8533 20.3537 20.3536C18.8534 21.8539 16.8186 22.6968 14.6969 22.6968H12.6969C9.89688 22.6968 8.19688 21.8368 6.70688 20.3568L3.10688 16.7568C2.76282 16.3757 2.57847 15.8769 2.592 15.3637C2.60554 14.8505 2.81593 14.3621 3.1796 13.9997C3.54327 13.6373 4.03238 13.4287 4.54565 13.417C5.05892 13.4053 5.55704 13.5914 5.93688 13.9368L7.69688 15.6968",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]})});var pe=a.memo(function({angle:n,countdown:a,isScanning:r,isInTargetRange:o,stabilityScore:i,children:c}){const{translate:u}=d(m)||{},g=p(),y=s(()=>n<80?Math.max(0,Math.min(100,10*(n-60))):n>95?Math.max(0,Math.min(100,10*(105-n))):100,[n]),v=l(()=>{if(r)return g?.style?.angleDetector?.successAngleBackground||"#4f46e5";const e=y();if(0===e)return g?.style?.angleDetector?.successAngleLowBackground||"#ffffff";if(100===e)return g?.style?.angleDetector?.successAngleBackground||"#4f46e5";return`rgb(${Math.round(255-e/100*116)}, ${Math.round(255-e/100*163)}, ${Math.round(255-e/100*9)})`},[r,y]),w=s((e,t)=>t>70?e?`text-[${g?.style?.angleDetector?.successAngleTextLightColor}]/70`:`text-[${g?.style?.angleDetector?.successAngleTextLightColor}]`:e?`text-[${g?.style?.angleDetector?.successAngleTextLightColor}]/40`:`text-[${g?.style?.angleDetector?.successAngleTextDarkColor}]/70`,[]),x=s((e=!1)=>{const t=y();return r?`text-[${g?.style?.angleDetector?.successAngleTextLightColor}]`:w(e,t)},[r,y]),b=s((e,t)=>t>70||e?g?.style?.angleDetector?.successAngleTextLightColor:g?.style?.angleDetector?.successAngleTextDarkColor,[]),S=s((e=!1)=>{const t=y();return r?g?.style?.angleDetector?.successAngleTextLightColor:b(e,t)},[r,y]),C=a;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},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",r?{className:"relative flex flex-col items-center justify-center",children:[e("div",{className:"relative flex h-16 w-16 items-center justify-center rounded-[9999px] border-2 bg-[#fff]/30 border-[#fff]",children:e("div",{className:"h-4 w-4 rounded-[9999px] animate-pulse bg-[#fff]/80"})}),c]}:{className: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&&!r&&e("div",{className:"absolute bottom-[8rem] w-[12rem]",children:e("div",{className:`h-[.375rem] w-full bg-[${S()}]/20 rounded-[9999px] overflow-hidden`,style:{backgroundColor:`${S()}33`},children:e("div",{className:`h-full bg-[${S()}]/70 transition-all duration-300 rounded-[9999px]`,style:{width:`${n}%`,backgroundColor:`${S()}B3`}})})}),null===C&&!r&&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&&!r&&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:a,onUserMedia:r,onPause:s,pause:o,recordingStarted:i,startSendingVideoFrames:c,showPause:l,webcamRef:u,onUserMediaError:p,resetDetector:f,videoConstraints:w,webcamKey:x}){const{media:b}=d(de)||{},{translate:S}=d(m)||{};return t("div",{className:"App w-screen h-[100vh] relative common-ui-main",children:[e("span",{onClick:()=>{n(),f()},className:"fixed right-[20px] top-[20px] z-[999]",children:e(ne,{className:"text-[#fff]"})}),e("div",{className:"w-full h-full overflow-hidden ",children:b===le&&e(te,{audio:!1,ref:u,screenshotQuality:1,videoConstraints:w,mirrored:!0,screenshotFormat:"image/jpeg",onUserMedia:r,onUserMediaError:p,style:{position:"fixed",top:0,bottom:0,zIndex:0,width:"100%",height:"100%",objectFit:"cover"}},x)}),t("div",{className:"fixed bottom-[30px] w-full z-[999] flex flex-col gap-4 items-center justify-center",children:[l&&e(g,{className:"!w-[180px] !h-[40px] !py-[0] mx-auto ",prefix:y,buttonText:S?.(h.pause),buttonFunc:s,btnSecondary:!0}),o?e("div",{children:e(g,{className:"!w-[180px] !h-[40px] !py-[0] mx-auto",buttonText:S?.(h.restart),buttonFunc:n,btnSecondary:!0})}):i?null:e(g,{className:"!w-[180px] !h-[40px] !py-[0] mx-auto !bg-[#ffffff] !text-[#000000] "+(a?"!opacity-50":""),buttonText:S?.(h.startScan),buttonFunc:c,disabled:a})]}),e("audio",{id:"audioElement",crossOrigin:"anonymous",preload:"auto",style:{position:"absolute",zIndex:-99999},src:`${v}scanAudioInstructions/silence.mp3`})]})}let he=null,ge=null,ye=null;let ve,we=null,xe=null;var be=a.memo(function({setIsScanLocked:t,resetDetector:n,scanID:a,setIsVideoUploaded:i,setScanFailsError:c,setScanStartTime:m,setScanUniqueKey:p,userDetails:f}){const{gender:h,heightInCm:g,email:y,shopDomain:M}=f,_=u(null),U=u(null),A=u(null),[z,j]=r([]),[P,V]=r(!0),[B,R]=r(!1),[q,K]=r(!1),[W,O]=r(!0),[H,J]=r(!1),G=u(null),[Q,Y]=r(""),[X,Z]=r([]),[ee,te]=r(""),[ne,ae]=r(!1),[re,se]=r(!1),[oe,ie]=r(!1),[ce,le]=r([]),[de,ue]=r(!1),me=u(!0),{poseDetector:pe}=function(){const[e,t]=r(0),[n,a]=r(0),[s,i]=r(!1),c=u(0),l=u(0),d=u(!0);async function m(){if("undefined"==typeof window||"undefined"==typeof navigator)return!1;try{console.log("Starting TensorFlow preload...");const[e,t,n]=await Promise.all([import("./pose-detection.esm-c4ZA7-te.js"),import("@tensorflow/tfjs-core"),import("@tensorflow/tfjs-backend-webgl")]);ye=e,await t.setBackend("webgl"),await t.ready(),console.log("TensorFlow backend ready (WebGL)");const a={runtime:"mediapipe",modelType:"full",solutionPath:"https://cdn.jsdelivr.net/npm/@mediapipe/pose"};try{ge=await ye.createDetector(ye.SupportedModels.BlazePose,a),console.log("MediaPipe detector created successfully")}catch(e){console.warn("MediaPipe failed, falling back to TFJS runtime:",e),ge=await ye.createDetector(ye.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),he=null,!1}}function p(e){return!(!e||0===e.length)&&22===e.filter(e=>e[2]>.7).length}return o(()=>{if(d.current=!0,!ge)return he||(he=m()),he.then(e=>{e&&d.current&&i(!0)}),()=>{d.current=!1};i(!0)},[]),o(()=>{l.current=e,e>6&&c.current<2&&(a(e=>e+1),t(0))},[e]),o(()=>{c.current=n},[n]),{poseDetector:async(e,n)=>{if(!ge||!d.current||!n?.current?.video)return;const a=n.current.video;if(!(a.readyState<2))try{const n=await ge.estimatePoses(a,{flipHorizontal:!1});if(!n||!n.length)return;const r=n[0].keypoints.slice(11).map(e=>[e.x>0&&e.x<720?e.x:-1,e.y>0&&e.y<1280?e.y:-1,e.score??0]);0!==c.current||p(r)||t(e=>e+1),1===c.current&&p(r)&&t(e=>e+1),2===c.current&&e()}catch(e){console.error("Pose detection error:",e)}},isLoaded:s,spinPhase:n,resetDetector:()=>{c.current=0,l.current=0,t(0),a(0)},retryLoading:async()=>{ge||he||(he=m(),await he&&d.current&&i(!0))}}}(),be=u(!0),Se=u(!1),Ce=u(0),Ne=u(0),De=u(!1),Fe=u(!1),Ie=u(()=>{}),[ke,Te]=r([]),[Ee,Le]=r(0),[$e,Me]=r(w),{setStartGyro:_e,uploadScanFile:Ue,setUploadLoading:Ae,swan:ze,onScanStart:je,onCaptureComplete:Pe}=d(x),Ve=()=>{Se.current=!1,clearTimeout(ve),G.current&&clearTimeout(G.current),p(L()),c(""),Ae?.(!1),j([]),A.current=null,V(!0),R(!1),K(!1),O(!0),J(!1),G.current=null,Y(""),Z([]),te(""),ae(!ne),_e(!1),S.stopAudio(),se(!1),ie(!1),Ce.current=0,Ne.current=0,De.current=!1,Fe.current=!1,null!==U.current&&U.current.stop(),ce.forEach(e=>{U.current&&U.current.removeEventListener("dataavailable",e)}),le([]),me.current=!0,ue(!1),i(!1),_.current?.stream&&V(!1)},Be=s(()=>{setTimeout(()=>{V(!1)},1e3)},[]),Re=s(e=>{if(console.log("camera error",e),$e===w)return Me(b),void Le(e=>e+1);V(!1)},[$e]),qe=s(()=>{me.current=!1,ie(!0),ue(!1),G.current&&clearTimeout(G.current),U.current&&U.current.pause(),S.stopAudio(),ze.poseDetection.disconnect(),Ce.current=0,Ne.current=0,De.current=!1,Fe.current=!1,U.current&&U.current.stop(),ce.forEach(e=>{U.current&&U.current.removeEventListener("dataavailable",e)}),le([]),clearTimeout(ve)},[U,ce,S,me]),Ke=l(()=>C(),[]),We=N(ke),Oe=D(We),He=s(async()=>{me.current=!0,await S.playAudio(`${v}SpotOn.mp3`),ie(!1),ue(!1),G.current&&clearTimeout(G.current),R(!1)},[G,S]),Je=s(async()=>{try{we=await ze.poseDetection.connect(),console.log(we,"websocket connected"),F.capture(`${M}/pose_detection_connected`,{scanID:a,email:y,id:we})}catch(e){console.log(e,"while connecting websocket")}},[a,M,y]),Ge=s(async()=>{I({eventName:`${M}/rescan`,email:y,scanID:a,height:g,gender:h,status:!1}),me.current=!1,ze.poseDetection.disconnect(),Ve(),await Je(),tt()},[Je,a,y]),Qe=s(({data:e})=>{e&&e.size>0&&me.current&&(j(t=>t.concat(e)),!Se.current&&_.current&&(Se.current=!0,pe(()=>{He(),k({eventName:`${M}/tensorFlow`,scanID:a,email:y,message:"recording stopped by tensorflow "})},_)))},[He,k,M,a,y,_]),Ye=s(async()=>{X.length>0&&me.current&&(await S.playAudio(v+X[X.length-1]),me.current&&(ve=setTimeout(Ye,2e3)))},[X,me]),Xe=s(()=>{U&&U.current&&U.current.stop(),R(!0);try{if(_&&_.current&&_.current.stream){const e=_.current.stream.getVideoTracks()[0];if(e){const t=e.getSettings();A.current=t.frameRate||null}const t={videoBitsPerSecond:15e5};ke[0]&&(t.mimeType=ke[0]),U.current=new MediaRecorder(_.current.stream,t),U.current.addEventListener("dataavailable",Qe),le([...ce,Qe]),U.current.start(1e3),O(!1)}}catch(e){console.log("error while using media recorder",e)}},[_,ke,Qe,ce]),Ze=s(async()=>{G.current&&clearTimeout(G.current),Xe(),me.current&&(G.current=setTimeout(async()=>{me.current&&(await S.playAudio(`${v}SpotOn.mp3`),R(!1))},15e3)),K(!0),me.current&&await S.playAudio(`${v}Spin.mp3`)},[Xe,me,S]);o(()=>{Ie.current=Ze},[Ze]);const et=s(({data:e})=>{e.size>0&&ze.poseDetection.connected()&&(De.current||(De.current=!0,ze.poseDetection.poseStatus(async e=>{if(console.log("poseStatus data:",e),e&&e.audio&&e.audio.length>0){F.capture(`${M}/pose_instruction_received`,{scanID:a,email:y,audio:e.audio,status:e.status,sid:e.sid,counter:Ce.current,consecutiveFalse:Ne.current,type:"body_scan_instruction"});const t=document.querySelector("#audioElement");!0===e.status&&e.sid===we?(Ne.current=0,Ce.current<2?(Ce.current+=1,1!==Ce.current||Fe.current?2===Ce.current&&t?.paused&&S.playAudio(v+e.audio):(Fe.current=!0,S.stopAudio(),await S.playAudio(v+e.audio))):(te(e.audio),clearTimeout(ve),ze.poseDetection.disconnect(),De.current=!1,setTimeout(()=>Ie.current(),1e3))):(Ne.current+=1,Ne.current>=3&&(Ce.current=0,Fe.current=!1),!t?.paused||xe&&xe?.audioName===e.audio?xe?.audioName===e.audio&&t?.paused&&(xe&&xe.no_of_times_skipped>=xe.skipCount?(xe.no_of_times_skipped=0,S.playAudio(v+e.audio)):xe&&(xe.no_of_times_skipped+=1)):(xe={skipCount:2,no_of_times_skipped:0,audioName:e.audio},S.playAudio(v+e.audio)))}})),_?.current&&null!==_.current.getScreenshot()&&ze.poseDetection.videoEmit({image:_.current.getScreenshot()||"",scanId:a}))},[_,a,ze,we,S,M,y]),tt=s(async()=>{J(!0),_e(!0),je?.(),be.current&&(be.current=!1,k({eventName:"scan started",scanID:a,status:"success",email:y})),m(T()),V(!0),me.current&&await S.playAudio(`${v}StartScan.mp3`),me.current&&await S.playAudio(`${v}LiftArmsAndHoldAtHip.mp3`),me.current&&(J(!1),R(!0),se(!0),ue(!0),Be());try{if(_&&_.current&&_.current.stream&&me.current){const e=_.current.stream.getVideoTracks()[0];if(e){const t=e.getSettings();A.current=t.frameRate||null}const t={videoBitsPerSecond:15e5};ke[0]&&(t.mimeType=ke[0]),me.current&&(U.current=new MediaRecorder(_.current.stream,t)),me.current&&U.current&&U.current.addEventListener("dataavailable",et),le([...ce,et]),U.current&&U.current.start(1e3),O(!1),me.current&&(ve=setTimeout(Ye,2e3))}}catch(e){console.log("error ----------",e)}},[_,ke,et,ce,Ye,me,je]);return o(()=>(M&&(t(!0),Je()),()=>{we&&(ze.poseDetection.disconnect(),F.capture(`${M}/pose_detection_disconnected`,{scanID:a,email:y,id:we})),ce.forEach(e=>{U?.current?.removeEventListener("dataavailable",e)})}),[M]),o(()=>{X.push(Q)},[Q]),o(()=>{Z([])},[ee]),o(()=>{const e=z.length&&z.length>0;W||!e||B||!me.current||oe||U&&U.current&&(B||(U.current.stop(),O(!0)))},[W,B,z,oe]),o(()=>{const e=z.length&&z.length>0;if(W||!e||B)console.log("No video found to upload.");else if(U&&U.current&&me.current&&!oe&&!B){const e=new File(z,`${a}.${Oe}`,{type:We});Pe?.(),Ae?.(!0),c(""),Ue?.(e,A.current)}},[W,B,z,oe,U,me]),o(()=>{const e=E(Ke,$);Te(e)},[Ke]),o(()=>{Ve()},[]),e(fe,{resetDetector:n,resetScan:Ve,loadingCam:P,onPause:qe,showRestart:re,pause:oe,onReScan:Ge,recordingStarted:B,isScanning:H,startSendingVideoFrames:tt,faceDone:q,stopRecording:He,showPause:de,webcamRef:_,onUserMedia:Be,onUserMediaError:Re,videoConstraints:$e,webcamKey:Ee})});function Se({scanID:t,userDetails:n,setIsVideoUploaded:a,setScanFailsError:s,setScanStartTime:i,setScanUniqueKey:c}){const[l,d]=r(90),[m,p]=r(0),[f,h]=r(null),[g,y]=r(!1),[v,w]=r(0),x=u([]),[b,S]=r(!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||F()},[C,N,f,g]),o(()=>{v>=100&&null===f&&!g&&D(),v<50&&null!==f&&F()},[v,f,g]);const D=()=>{h(3);const e=setInterval(()=>{h(t=>null===t||t<=1?(clearInterval(e),y(!0),null):t-1)},1e3)},F=()=>{h(null),b||y(!1)};return e(pe,{angle:C,countdown:f,isScanning:g,isInTargetRange:N,stabilityScore:v,children:g&&e(be,{setIsScanLocked:S,resetDetector:()=>{d(90),p(0),h(null),y(!1),w(0),S(!1),x.current=[]},scanID:t,userDetails:n,setIsVideoUploaded:a,setScanFailsError:s,setScanStartTime:i,setScanUniqueKey:c})})}function Ce({message:a,config:r}){const{translate:s}=d(m)||{};return e(ae,{open:!0,className:"confirm-modal common-ui-main",children:e("div",{className:"modal-main",children:e("div",{className:"text-center",children:t(n,a?{children:[e("h2",{style:{fontFamily:r?.style?.heading?.headingFontFamily||"SeriouslyNostalgic Fn",fontSize:r?.style?.heading?.headingFontSize||"32px",color:r?.style?.heading?.headingColor||"#000",fontWeight:r?.style?.heading?.headingFontWeight||"normal"},children:s?.(h.cameraAlreadyInUse)}),e("p",{className:"mt-[0.5rem] text-sm",style:{fontFamily:r?.style?.base?.baseFontFamily||"Inter, sans-serif",fontSize:r?.style?.base?.baseFontSize||"16px",color:r?.style?.base?.baseTextColor||"#000"},children:s?.(h.tryClosingBrowser)})]}:{children:[e("h2",{style:{fontFamily:r?.style?.heading?.headingFontFamily||"SeriouslyNostalgic Fn",fontSize:r?.style?.heading?.headingFontSize||"32px",color:r?.style?.heading?.headingColor||"#000",fontWeight:r?.style?.heading?.headingFontWeight||"normal"},children:s?.(h.checkCameraSettings)}),e("p",{className:"mt-[0.5rem] text-sm",style:{fontFamily:r?.style?.base?.baseFontFamily||"Inter, sans-serif",fontSize:r?.style?.base?.baseFontSize||"16px",color:r?.style?.base?.baseTextColor||"#000"},children:`${s?.(h.setting)} > ${M()} > ${s?.(h.enableCameraPermissions)}`})]})})})})}function Ne({setShowDrawer:t,config:n,loader:a}){const[i,c]=r({disabled:!1,message:""}),[l,d]=r(!0),m=u(null),p=s(async()=>{const e=await _();c(e),d(!1)},[]);return o(()=>{p()},[]),l?e(U,{url:a,loaderType:"black"}):i?.disabled?e(Ce,{config:n,message:i?.message}):e(te,{audio:!1,ref:m,screenshotQuality:1,videoConstraints:A,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:a="[&_video]:rounded-t-[20px] w-full h-full"}){const r=u(null),s=u(null);let i={autoplay:!0,controls:!1,responsive:!0,fluid:!0,muted:!0,navigationUI:"hide",preload:"metadata",poster:z};return o(()=>{if(!s.current&&t&&r?.current){const e=oe(r.current,{...i});e.ready(()=>{s.current=e;const a={...i,sources:[{src:t,type:"application/x-mpegURL"}]};e.autoplay(a.autoplay),e.src(a.sources),n?.(e)})}},[t,r]),o(()=>{const e=s.current;return()=>{e&&!e.isDisposed()&&(e.dispose(),s.current=null)}},[s]),e("div",{className:a,children:e("video",{ref:r,muted:!0,className:"video-js",playsInline:!0,onDrag:e=>e.preventDefault()})})}function Fe({scanFailsError:a,onNext:s,gender:o,setScanUniqueKey:i,setIsVideoUploaded:c}){const{translate:l}=d(m)||{},u=p(),[y,v]=r(!1),w=()=>{v(!y)};return t(n,{children:[t("div",{className:"flex common-ui-main flex-col h-full max-w-[28rem] mx-auto w-full rounded-t-[20px] overflow-y-auto",style:{background:u?.style?.base?.backgroundColor},children:[e("div",{className:"w-full max-w-[28rem] mx-auto pt-[1rem] px-[1rem]",children:e(f,{noTitle:!0})}),e("div",{className:"flex-1",children:a&&t("div",{className:"px-[1rem]",children:[e("h2",{className:"text-center",style:{fontFamily:u?.style?.heading?.headingFontFamily||"SeriouslyNostalgic Fn",fontSize:u?.style?.heading?.headingFontSize||"32px",color:u?.style?.heading?.headingColor||"#000",fontWeight:u?.style?.heading?.headingFontWeight||"normal"},children:l?.(h.issueWithScan)}),e("p",{style:{fontFamily:u?.style?.base?.baseFontFamily||"Inter, sans-serif",fontSize:u?.style?.base?.baseFontSize||"16px",color:u?.style?.base?.baseTextColor||"#1E1E1E"},children:l?.(h.reason)}),e("p",{style:{fontFamily:u?.style?.base?.baseFontFamily||"Inter, sans-serif",fontSize:u?.style?.base?.baseFontSize||"16px",color:u?.style?.base?.baseTextColor||"#1E1E1E"},children:j(a)}),e("img",{className:"my-[0.5rem] aspect-[2/1.4] w-full object-cover",onClick:w,src:P[o],alt:"icon"})]})}),a&&e("div",{className:"p-[1rem] flex gap-[0.5rem]",children:e(g,{disabled:!1,buttonText:l?.(h.scanAgain),className:"!shadow-none",buttonFunc:()=>{s?s?.():i?.(L()),c?.(!1)}})})]}),y&&t(ae,{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 Ie({scanId:n,userDetails:a,config:i,isVideoUploadedCorrect:c,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}=a||{},I=[K,W,O].includes(D??""),[k,T]=r(!0),E=s(async()=>{try{I&&(await(v?.auth.addUser({scanId:n,email:N,name:C,gender:w,height:b})),y?.()),F.capture(x??"",{scanID:n,email:N,height:b,focalLength:S,clothesFit:"0",gender:w})}catch(e){console.log(e)}},[I]),{translate:L}=d(m)||{};o(()=>{(c||l)&&E()},[c,l]);const $=p||c||l;return e(re,{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:i?.loader,setShowDrawer:T}),e(se,{open:k,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:i?.style?.base?.backgroundColor},children:t("div",{className:"w-full h-full flex flex-col",children:[e(f,{title:L?.(h.measurementsBeingTaken)}),e("div",{className:"flex items-center justify-center flex-1",children:e("video",{preload:"auto",className:"max-h-[calc(100vh-450px)] mx-auto w-full object-contain border-none",muted:!0,loop:!0,autoPlay:!0,playsInline:!0,children:e("source",{src:w===q.Male?B:R,type:"video/mp4"})})}),$&&e(g,{className:"!w-[180px] mx-auto",buttonText:L?.(h.next),buttonFunc:()=>{u?.()}})]})})})]})})}const ke=()=>{const{userDetails:a,onRetry:r,isError:s,isSuccess:o,gender:i,scanUniqueKey:c,scanFailsError:l,setScanUniqueKey:u,setIsVideoUploaded:m,isMeasurementAvailable:f,isVideoUploadedCorrect:h,loading:g,showDeniedModal:y,uploadLoading:v,setScanFailsError:w,setScanStartTime:b,resetScan:S,onCustomScanSuccess:C,swan:N,onComplete:D}=d(x),F=p();return s?t(n,{children:[e(Ne,{}),e(se,{anchor:"bottom",open:!0,className:"camera-drawer",onClose:(e,t)=>{},children:e(Fe,{scanFailsError:!0,onNext:r,gender:i})})]}):o?e(Ie,{isSuccess:!0,onComplete:D}):g?e("div",{className:"flex top-0 !mt-0 left-0 z-[999] absolute justify-center items-center w-full h-full",style:{background:F?.style?.base?.backgroundColor},children:e(U,{url:F?.loader,loaderType:"black"})}):y.disabled?e(Ce,{}):v||l||f||h?(v||f||h)&&!l?e(Ie,{scanId:c,isMeasurementAvailable:f,userDetails:a,isVideoUploadedCorrect:h,onCustomScanSuccess:C,swan:N,onComplete:D}):t(n,{children:[e(Ne,{}),e(se,{anchor:"bottom",open:!0,className:"camera-drawer",onClose:(e,t)=>{},children:e(Fe,{scanFailsError:l,onNext:()=>{r?.(),S()},setScanUniqueKey:u,gender:i,setIsVideoUploaded:m})})]}):e(Se,{scanID:c,userDetails:a,setIsVideoUploaded:m,setScanFailsError:w,setScanStartTime:b,setScanUniqueKey:u})},Te=t=>{const{config:n,onRetry:a,onScanStart:i,onCaptureComplete:c,onUploadStart:d,onUploadEnd:u,onMeasurementSocketStart:m,onMeasurementSocketClose:p,onIntermediateScanSuccess:f,onScanError:h,onScanSuccess:g,onCustomScanSuccess:y,onComplete:v,isError:w,isSuccess:b}=t,S={email:"",shopDomain:"",gender:"male",heightInCm:0,scanType:"",deviceFocalLength:0,deviceModelName:"",sourceTag:"",...t.userDetails??{}},C=t.token??"",{gender:N,scanType:D,shopDomain:F,heightInCm:I,email:E,deviceFocalLength:$,deviceModelName:M,callbackUrl:U,sourceTag:A}=S,z=l(()=>H(C),[C]),[P,V]=r(!1),[B,R]=r(!1),[q,K]=r(!1),[W,O]=r({disabled:!1,message:""}),[ee,te]=r(""),[ne,ae]=r(!1),[re,se]=r(!0),[oe,ie]=r(!1),[ce,le]=r(""),[de,me]=r(T()),{gyroData:pe}=function(e){const[t,n]=r([]),[a,i]=r(!1),c=s(e=>{try{const{alpha:t,beta:a,gamma:r}=e;n(e=>[...e,{alpha:t?.toString()||void 0,beta:a?.toString()||void 0,gamma:r?.toString()||void 0,timestamp:(new Date).toISOString()}])}catch(e){console.log(e)}},[]),l=s(async()=>{const e=DeviceOrientationEvent;if(void 0!==e&&"function"==typeof e.requestPermission)try{"granted"===await e.requestPermission()?i(!0):console.warn("Device orientation permission denied.")}catch(e){console.error("Error requesting device orientation permission:",e)}else i(!0)},[]);return o(()=>(e&&a?window.addEventListener("deviceorientation",c):n([]),()=>{window.removeEventListener("deviceorientation",c)}),[e,a,c]),o(()=>{e&&l()},[e,l]),{gyroData:t}}(oe);J();const fe=s(()=>{le(L()),te(""),V(!1),ae(!1)},[]),he=()=>{me(null),le("")},ge=s(async e=>{if(e&&"success"===e?.scanStatus&&"intermediate"===e?.resultType&&200===e?.code)return k({eventName:`${F}/measurement_success/intermediate`,scanID:ce,status:"success",email:E}),R(!0),void f?.(e);g?.(e),R(!0),he();const t=ce;K(!0),k({eventName:`${F}/measurement_success/fit-view`,scanID:t,status:"success",email:E}),de&&k({eventName:`${F}/scan_completion_time`,scanID:t,status:"success",completionTime:T()-de,email:E})},[D,F,ce]),ye=e=>{K(!1),te(""),R(!1),z.measurement.handleMeasurementSocket({scanId:ce,onPreopen:()=>{Z({eventName:`${F}/webSocket`,scanID:ce,connection:"pre_open",type:"measurement_recommendation",email:E})},onOpen:()=>{m?.(),Z({eventName:`${F}/webSocket`,scanID:ce,connection:"open",type:"measurement_recommendation",email:E})},onClose:()=>{p?.(),Z({eventName:`${F}/webSocket`,scanID:ce,connection:"close",type:"measurement_recommendation",email:E})},onError:e=>{var t;t=e,h?.({...t,message:j(t)}),he(),K(!1),te(t),R(!1),k({eventName:`${F}/measurement_failed/fit-view`,scanID:ce,status:"failed",email:E,message:j(t)}),de&&k({eventName:`${F}/scan_completion_time`,scanID:ce,status:"failed",completionTime:T()-de,email:E}),Z({eventName:`${F}/webSocket`,scanID:ce,connection:"error",type:"measurement_recommendation",email:E})},onSuccess:e=>{Z({eventName:`${F}/webSocket`,scanID:ce,connection:"success",type:"measurement_recommendation",email:E}),ge(e)}})},ve=s(async(e,t)=>{const n=Number((e.size/1048576).toFixed(2)),a=null!=t?t:await G(e),r=Q({gender:N,focal_length:`${$}`,height:`${I}`,customer_store_url:F,clothes_fit:"0",scan_type:D,callback_url:U,source_tag:A});k({eventName:`${F}/body_scan_meta_data`,scanID:ce,email:E,data:JSON.stringify([...r,{fileSizeInMB:n,video_fps:a||0}])}),d?.();try{await z.fileUpload.uploadFileFrontend({file:e,arrayMetaData:r,scanId:ce,email:E}),await z.fileUpload.setDeviceInfo({model:M,detection:"manual",gyro:pe,scanId:ce}),console.log("video successfully uploaded"),ae(!1),k({eventName:`${F}/scan_success`,scanID:ce,status:"success",email:E,data:JSON.stringify(r)}),k({eventName:"scan finished",scanID:ce,status:"success",email:E}),me(T()),setTimeout(()=>{ae(!0)},3e3)}catch(e){k({eventName:"scan finished",scanID:ce,status:"failed",email:E,message:j(e)}),k({eventName:`${F}/scan_failed`,scanID:ce,status:"failed",email:E,message:j(e),data:JSON.stringify(r)}),te(j(e)),ae(!1),h?.({...e,message:j(e)}),he()}finally{ie(!1),u?.()}},[ce,pe,d,u]),we=s(async()=>{if(+I<152.4||+I>213.36)return void h?.({message:"Height must be between 152.4cm (5ft) and 213.36cm (7ft)"});const e=await _();e.disabled?(k({eventName:`${F}/camera_activation`,scanID:ce,status:"failed",email:E}),se(!1)):(se(!1),k({eventName:`${F}/camera_activation`,scanID:ce,status:"success",email:E})),O(e),te(""),ae(!1)},[E,ce,le,F]);return o(()=>{w||b||F&&we()},[F,I,w,b]),o(()=>{w||b||ne&&F&&ce&&ye()},[ne,F,ce,w,b]),e(Y,{children:e(X,{config:n,children:e(ue,{children:e(x.Provider,{value:{userDetails:S,onRetry:a,onScanError:h,isError:w,isSuccess:b,onScanSuccess:g,gender:N,scanUniqueKey:ce,scanFailsError:ee,setScanUniqueKey:le,setIsVideoUploaded:ae,isMeasurementAvailable:q,isVideoUploadedCorrect:B,loading:re,showDeniedModal:W,uploadLoading:P,setStartGyro:ie,uploadScanFile:ve,setUploadLoading:V,resetScan:fe,setScanFailsError:te,setScanStartTime:me,onScanStart:i,onCaptureComplete:c,onCustomScanSuccess:y,onComplete:v,swan:z},children:e(ke,{})})})})})};export{Te as B};
2
+ //# sourceMappingURL=BodyScan-By4r-brw.js.map
@@ -0,0 +1,2 @@
1
+ "use strict";var e=require("react/jsx-runtime"),t=require("react"),n=require("./LoadingScreen-DG82-2pH.js"),s=require("clsx"),a=require("react-webcam"),r=require("lucide-react"),o=require("@mui/material"),i=require("video.js");const c="DESKTOP",l="TAB",u="MOBILE",d=t.createContext(void 0);function m({children:n}){const[s,a]=t.useState([window?.innerWidth,window?.innerHeight]),[r,o]=t.useState(!1),i=()=>{a([window?.innerWidth,window?.innerHeight])};t.useEffect(()=>{i()},[]),t.useLayoutEffect(()=>(window.addEventListener("resize",i),()=>window.removeEventListener("resize",i)),[i]);let m=c;s[0]>768&&s[0]<1024&&(m=l),s[0]<768&&(m=u);const f=t.useMemo(()=>({size:s,setSize:a,clearInputs:r,setClearInputs:o,media:m}),[s,r,m]);return e.jsx(d.Provider,{value:f,children:n})}var f=t.memo(function({size:t=16}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 25 25",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[e.jsx("path",{d:"M22.6968 14.6968C22.6968 16.8185 21.8539 18.8533 20.3536 20.3536C18.8533 21.8539 16.8185 22.6968 14.6968 22.6968",stroke:"white",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),e.jsx("path",{d:"M18.6968 11.6968V10.6968C18.6968 10.1663 18.4861 9.65764 18.111 9.28256C17.7359 8.90749 17.2272 8.69678 16.6968 8.69678C16.1663 8.69678 15.6576 8.90749 15.2826 9.28256C14.9075 9.65764 14.6968 10.1663 14.6968 10.6968",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),e.jsx("path",{d:"M14.6968 10.6968V9.69678C14.6968 9.16634 14.4861 8.65764 14.111 8.28256C13.7359 7.90749 13.2272 7.69678 12.6968 7.69678C12.1663 7.69678 11.6576 7.90749 11.2826 8.28256C10.9075 8.65764 10.6968 9.16634 10.6968 9.69678V10.6968",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),e.jsx("path",{d:"M10.6968 10.1968V4.69678C10.6968 4.16634 10.4861 3.65764 10.111 3.28256C9.73592 2.90749 9.22721 2.69678 8.69678 2.69678C8.16634 2.69678 7.65764 2.90749 7.28256 3.28256C6.90749 3.65764 6.69678 4.16634 6.69678 4.69678V14.6968",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),e.jsx("path",{d:"M18.6969 11.6968C18.6969 11.1663 18.9076 10.6576 19.2827 10.2826C19.6577 9.90749 20.1664 9.69678 20.6969 9.69678C21.2273 9.69678 21.736 9.90749 22.1111 10.2826C22.4862 10.6576 22.6969 11.1663 22.6969 11.6968V14.6968C22.6969 16.8185 21.854 18.8533 20.3537 20.3536C18.8534 21.8539 16.8186 22.6968 14.6969 22.6968H12.6969C9.89688 22.6968 8.19688 21.8368 6.70688 20.3568L3.10688 16.7568C2.76282 16.3757 2.57847 15.8769 2.592 15.3637C2.60554 14.8505 2.81593 14.3621 3.1796 13.9997C3.54327 13.6373 4.03238 13.4287 4.54565 13.417C5.05892 13.4053 5.55704 13.5914 5.93688 13.9368L7.69688 15.6968",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]})});var p=t.memo(function({angle:a,countdown:r,isScanning:o,isInTargetRange:i,stabilityScore:c,children:l}){const{translate:u}=t.useContext(n.LanguageContext)||{},d=n.useConfig(),m=t.useCallback(()=>a<80?Math.max(0,Math.min(100,10*(a-60))):a>95?Math.max(0,Math.min(100,10*(105-a))):100,[a]),p=t.useMemo(()=>{if(o)return d?.style?.angleDetector?.successAngleBackground||"#4f46e5";const e=m();if(0===e)return d?.style?.angleDetector?.successAngleLowBackground||"#ffffff";if(100===e)return d?.style?.angleDetector?.successAngleBackground||"#4f46e5";return`rgb(${Math.round(255-e/100*116)}, ${Math.round(255-e/100*163)}, ${Math.round(255-e/100*9)})`},[o,m]),h=t.useCallback((e,t)=>t>70?e?`text-[${d?.style?.angleDetector?.successAngleTextLightColor}]/70`:`text-[${d?.style?.angleDetector?.successAngleTextLightColor}]`:e?`text-[${d?.style?.angleDetector?.successAngleTextLightColor}]/40`:`text-[${d?.style?.angleDetector?.successAngleTextDarkColor}]/70`,[]),g=t.useCallback((e=!1)=>{const t=m();return o?`text-[${d?.style?.angleDetector?.successAngleTextLightColor}]`:h(e,t)},[o,m]),x=t.useCallback((e,t)=>t>70||e?d?.style?.angleDetector?.successAngleTextLightColor:d?.style?.angleDetector?.successAngleTextDarkColor,[]),y=t.useCallback((e=!1)=>{const t=m();return o?d?.style?.angleDetector?.successAngleTextLightColor:x(e,t)},[o,m]),S=r;function v(){document.documentElement.style.setProperty("--real-vh",window.innerHeight+"px")}return v(),window.addEventListener("resize",v),e.jsxs("div",{className:"flex common-ui-main w-screen flex-col items-center h-[var(--real-vh)] overflow-hidden touch-none justify-center transition-all duration-300 max-w-[28rem] mx-auto",style:{backgroundColor:p},children:[e.jsx("div",{className:"flex justify-start fixed top-[.5rem] max-w-[28rem] mx-auto w-full px-[1rem]",children:e.jsx("div",{className:"flex justify-start ",children:e.jsx(n.Header,{noTitle:!0})})}),null!==S?e.jsx("div",{className:"relative flex h-[6rem] w-[6rem] items-center justify-center rounded-[9999px] bg-[#fff]/20 transition-all duration-300",style:{border:`2px solid ${y()}`},children:e.jsx("div",{className:`text-[3rem] font-bold text-[${y()}]`,style:{fontFamily:d?.style?.base?.baseFontFamily||"Inter, sans-serif",color:y()},children:S})}):o?e.jsxs("div",{className:"relative flex flex-col items-center justify-center",children:[e.jsx("div",{className:"relative flex h-16 w-16 items-center justify-center rounded-[9999px] border-2 bg-[#fff]/30 border-[#fff]",children:e.jsx("div",{className:"h-4 w-4 rounded-[9999px] animate-pulse bg-[#fff]/80"})}),l]}):e.jsxs("div",{className:s("relative flex h-[4rem] w-[4rem] items-center justify-center rounded-[9999px] ",i?"bg-[#fff]/20 border-[#fff]":"bg-[#fff]/10 border-[#fff]"),style:{transform:`translateY(${3*(90-a)}px)`,transition:"transform 0.2s ease-out",border:`2px solid ${y()}`},children:[e.jsx("div",{className:`h-[1rem] w-[1rem] rounded-[9999px] bg-[${y()}]/80`,style:{backgroundColor:`${y()}B3`}}),e.jsxs("div",{className:s("mt-[.5rem] text-center w-[180px] flex-col flex items-center absolute top-[60px]",g()),style:{color:y()},children:[e.jsx(f,{size:30}),e.jsxs("p",{style:{fontFamily:d?.style?.base?.baseFontFamily||"Inter, sans-serif"},children:[" ",u?.(n.LanguageKeys.startLevelCheck),e.jsx("br",{})]})]})]}),null!==S&&e.jsx("div",{className:"absolute bottom-[8rem] text-center",children:e.jsx("div",{className:s("text-sm font-medium px-4 py-1.5 bg-black/20 rounded-[9999px] mt-8",g()),style:{fontFamily:d?.style?.base?.baseFontFamily||"Inter, sans-serif",color:y()},children:u?.(n.LanguageKeys.leavePhone)})}),i&&null===S&&!o&&e.jsx("div",{className:"absolute bottom-[8rem] w-[12rem]",children:e.jsx("div",{className:`h-[.375rem] w-full bg-[${y()}]/20 rounded-[9999px] overflow-hidden`,style:{backgroundColor:`${y()}33`},children:e.jsx("div",{className:`h-full bg-[${y()}]/70 transition-all duration-300 rounded-[9999px]`,style:{width:`${a}%`,backgroundColor:`${y()}B3`}})})}),null===S&&!o&&e.jsx("div",{className:"absolute bottom-[5rem] text-center",children:e.jsxs("div",{className:s("text-[1.5rem] font-light",g()),style:{color:y(),fontFamily:d?.style?.base?.baseFontFamily||"Inter, sans-serif"},children:[Math.round(a),"°"]})}),null===S&&!o&&e.jsx("div",{className:"absolute bottom-[2rem] text-center max-w-[20rem] mx-auto",children:e.jsx("div",{className:s("text-[.75rem] opacity-50",g()),style:{fontFamily:d?.style?.base?.baseFontFamily||"Inter, sans-serif",color:y()},children:u?.(n.LanguageKeys.placePhoneUpright)})})]})});function h({resetScan:s,loadingCam:o,onUserMedia:i,onPause:c,pause:l,recordingStarted:m,startSendingVideoFrames:f,showPause:p,webcamRef:h,onUserMediaError:g,resetDetector:x,videoConstraints:y,webcamKey:S}){const{media:v}=t.useContext(d)||{},{translate:b}=t.useContext(n.LanguageContext)||{};return e.jsxs("div",{className:"App w-screen h-[100vh] relative common-ui-main",children:[e.jsx("span",{onClick:()=>{s(),x()},className:"fixed right-[20px] top-[20px] z-[999]",children:e.jsx(r.X,{className:"text-[#fff]"})}),e.jsx("div",{className:"w-full h-full overflow-hidden ",children:v===u&&e.jsx(a,{audio:!1,ref:h,screenshotQuality:1,videoConstraints:y,mirrored:!0,screenshotFormat:"image/jpeg",onUserMedia:i,onUserMediaError:g,style:{position:"fixed",top:0,bottom:0,zIndex:0,width:"100%",height:"100%",objectFit:"cover"}},S)}),e.jsxs("div",{className:"fixed bottom-[30px] w-full z-[999] flex flex-col gap-4 items-center justify-center",children:[p&&e.jsx(n.SpecificButton,{className:"!w-[180px] !h-[40px] !py-[0] mx-auto ",prefix:n.pauseIcon,buttonText:b?.(n.LanguageKeys.pause),buttonFunc:c,btnSecondary:!0}),l?e.jsx("div",{children:e.jsx(n.SpecificButton,{className:"!w-[180px] !h-[40px] !py-[0] mx-auto",buttonText:b?.(n.LanguageKeys.restart),buttonFunc:s,btnSecondary:!0})}):m?null:e.jsx(n.SpecificButton,{className:"!w-[180px] !h-[40px] !py-[0] mx-auto !bg-[#ffffff] !text-[#000000] "+(o?"!opacity-50":""),buttonText:b?.(n.LanguageKeys.startScan),buttonFunc:f,disabled:o})]}),e.jsx("audio",{id:"audioElement",crossOrigin:"anonymous",preload:"auto",style:{position:"absolute",zIndex:-99999},src:`${n.voiceOverAssetsPath}scanAudioInstructions/silence.mp3`})]})}let g=null,x=null,y=null;let S,v=null,b=null;var C=t.memo(function({setIsScanLocked:s,resetDetector:a,scanID:r,setIsVideoUploaded:o,setScanFailsError:i,setScanStartTime:c,setScanUniqueKey:l,userDetails:u}){const{gender:d,heightInCm:m,email:f,shopDomain:p}=u,C=t.useRef(null),w=t.useRef(null),j=t.useRef(null),[N,k]=t.useState([]),[E,F]=t.useState(!0),[D,T]=t.useState(!1),[L,I]=t.useState(!1),[M,P]=t.useState(!0),[_,A]=t.useState(!1),$=t.useRef(null),[R,U]=t.useState(""),[z,K]=t.useState([]),[O,B]=t.useState(""),[q,V]=t.useState(!1),[W,H]=t.useState(!1),[G,J]=t.useState(!1),[Q,X]=t.useState([]),[Y,Z]=t.useState(!1),ee=t.useRef(!0),{poseDetector:te}=function(){const[e,n]=t.useState(0),[s,a]=t.useState(0),[r,o]=t.useState(!1),i=t.useRef(0),c=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,n]=await Promise.all([Promise.resolve().then(function(){return require("./pose-detection.esm-yM_Igca-.js")}),import("@tensorflow/tfjs-core"),import("@tensorflow/tfjs-backend-webgl")]);y=e,await t.setBackend("webgl"),await t.ready(),console.log("TensorFlow backend ready (WebGL)");const s={runtime:"mediapipe",modelType:"full",solutionPath:"https://cdn.jsdelivr.net/npm/@mediapipe/pose"};try{x=await y.createDetector(y.SupportedModels.BlazePose,s),console.log("MediaPipe detector created successfully")}catch(e){console.warn("MediaPipe failed, falling back to TFJS runtime:",e),x=await y.createDetector(y.SupportedModels.BlazePose,{runtime:"tfjs",modelType:"full"}),console.log("TFJS detector created successfully")}return!0}catch(e){return console.error("Failed to load TensorFlow dependencies:",e),g=null,!1}}function d(e){return!(!e||0===e.length)&&22===e.filter(e=>e[2]>.7).length}return t.useEffect(()=>{if(l.current=!0,!x)return g||(g=u()),g.then(e=>{e&&l.current&&o(!0)}),()=>{l.current=!1};o(!0)},[]),t.useEffect(()=>{c.current=e,e>6&&i.current<2&&(a(e=>e+1),n(0))},[e]),t.useEffect(()=>{i.current=s},[s]),{poseDetector:async(e,t)=>{if(!x||!l.current||!t?.current?.video)return;const s=t.current.video;if(!(s.readyState<2))try{const t=await x.estimatePoses(s,{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!==i.current||d(a)||n(e=>e+1),1===i.current&&d(a)&&n(e=>e+1),2===i.current&&e()}catch(e){console.error("Pose detection error:",e)}},isLoaded:r,spinPhase:s,resetDetector:()=>{i.current=0,c.current=0,n(0),a(0)},retryLoading:async()=>{x||g||(g=u(),await g&&l.current&&o(!0))}}}(),ne=t.useRef(!0),se=t.useRef(!1),ae=t.useRef(0),re=t.useRef(0),oe=t.useRef(!1),ie=t.useRef(!1),ce=t.useRef(()=>{}),[le,ue]=t.useState([]),[de,me]=t.useState(0),[fe,pe]=t.useState(n.videoConstraintsExact),{setStartGyro:he,uploadScanFile:ge,setUploadLoading:xe,swan:ye,onScanStart:Se,onCaptureComplete:ve}=t.useContext(n.ParamsContext),be=()=>{se.current=!1,clearTimeout(S),$.current&&clearTimeout($.current),l(n.generateUuid()),i(""),xe?.(!1),k([]),j.current=null,F(!0),T(!1),I(!1),P(!0),A(!1),$.current=null,U(""),K([]),B(""),V(!q),he(!1),n.speechService.stopAudio(),H(!1),J(!1),ae.current=0,re.current=0,oe.current=!1,ie.current=!1,null!==w.current&&w.current.stop(),Q.forEach(e=>{w.current&&w.current.removeEventListener("dataavailable",e)}),X([]),ee.current=!0,Z(!1),o(!1),C.current?.stream&&F(!1)},Ce=t.useCallback(()=>{setTimeout(()=>{F(!1)},1e3)},[]),we=t.useCallback(e=>{if(console.log("camera error",e),fe===n.videoConstraintsExact)return pe(n.videoConstraintsFallback),void me(e=>e+1);F(!1)},[fe]),je=t.useCallback(()=>{ee.current=!1,J(!0),Z(!1),$.current&&clearTimeout($.current),w.current&&w.current.pause(),n.speechService.stopAudio(),ye.poseDetection.disconnect(),ae.current=0,re.current=0,oe.current=!1,ie.current=!1,w.current&&w.current.stop(),Q.forEach(e=>{w.current&&w.current.removeEventListener("dataavailable",e)}),X([]),clearTimeout(S)},[w,Q,n.speechService,ee]),Ne=t.useMemo(()=>n.getPreferredMediaRecorderTypes(),[]),ke=n.getRecordingMimeType(le),Ee=n.getRecordingExtension(ke),Fe=t.useCallback(async()=>{ee.current=!0,await n.speechService.playAudio(`${n.voiceOverAssetsPath}SpotOn.mp3`),J(!1),Z(!1),$.current&&clearTimeout($.current),T(!1)},[$,n.speechService]),De=t.useCallback(async()=>{try{v=await ye.poseDetection.connect(),console.log(v,"websocket connected"),n.posthog.capture(`${p}/pose_detection_connected`,{scanID:r,email:f,id:v})}catch(e){console.log(e,"while connecting websocket")}},[r,p,f]),Te=t.useCallback(async()=>{n.rescanSupportCaptureEvent({eventName:`${p}/rescan`,email:f,scanID:r,height:m,gender:d,status:!1}),ee.current=!1,ye.poseDetection.disconnect(),be(),await De(),Ae()},[De,r,f]),Le=t.useCallback(({data:e})=>{e&&e.size>0&&ee.current&&(k(t=>t.concat(e)),!se.current&&C.current&&(se.current=!0,te(()=>{Fe(),n.handleScanTimeCapture({eventName:`${p}/tensorFlow`,scanID:r,email:f,message:"recording stopped by tensorflow "})},C)))},[Fe,n.handleScanTimeCapture,p,r,f,C]),Ie=t.useCallback(async()=>{z.length>0&&ee.current&&(await n.speechService.playAudio(n.voiceOverAssetsPath+z[z.length-1]),ee.current&&(S=setTimeout(Ie,2e3)))},[z,ee]),Me=t.useCallback(()=>{w&&w.current&&w.current.stop(),T(!0);try{if(C&&C.current&&C.current.stream){const e=C.current.stream.getVideoTracks()[0];if(e){const t=e.getSettings();j.current=t.frameRate||null}const t={videoBitsPerSecond:15e5};le[0]&&(t.mimeType=le[0]),w.current=new MediaRecorder(C.current.stream,t),w.current.addEventListener("dataavailable",Le),X([...Q,Le]),w.current.start(1e3),P(!1)}}catch(e){console.log("error while using media recorder",e)}},[C,le,Le,Q]),Pe=t.useCallback(async()=>{$.current&&clearTimeout($.current),Me(),ee.current&&($.current=setTimeout(async()=>{ee.current&&(await n.speechService.playAudio(`${n.voiceOverAssetsPath}SpotOn.mp3`),T(!1))},15e3)),I(!0),ee.current&&await n.speechService.playAudio(`${n.voiceOverAssetsPath}Spin.mp3`)},[Me,ee,n.speechService]);t.useEffect(()=>{ce.current=Pe},[Pe]);const _e=t.useCallback(({data:e})=>{e.size>0&&ye.poseDetection.connected()&&(oe.current||(oe.current=!0,ye.poseDetection.poseStatus(async e=>{if(console.log("poseStatus data:",e),e&&e.audio&&e.audio.length>0){n.posthog.capture(`${p}/pose_instruction_received`,{scanID:r,email:f,audio:e.audio,status:e.status,sid:e.sid,counter:ae.current,consecutiveFalse:re.current,type:"body_scan_instruction"});const t=document.querySelector("#audioElement");!0===e.status&&e.sid===v?(re.current=0,ae.current<2?(ae.current+=1,1!==ae.current||ie.current?2===ae.current&&t?.paused&&n.speechService.playAudio(n.voiceOverAssetsPath+e.audio):(ie.current=!0,n.speechService.stopAudio(),await n.speechService.playAudio(n.voiceOverAssetsPath+e.audio))):(B(e.audio),clearTimeout(S),ye.poseDetection.disconnect(),oe.current=!1,setTimeout(()=>ce.current(),1e3))):(re.current+=1,re.current>=3&&(ae.current=0,ie.current=!1),!t?.paused||b&&b?.audioName===e.audio?b?.audioName===e.audio&&t?.paused&&(b&&b.no_of_times_skipped>=b.skipCount?(b.no_of_times_skipped=0,n.speechService.playAudio(n.voiceOverAssetsPath+e.audio)):b&&(b.no_of_times_skipped+=1)):(b={skipCount:2,no_of_times_skipped:0,audioName:e.audio},n.speechService.playAudio(n.voiceOverAssetsPath+e.audio)))}})),C?.current&&null!==C.current.getScreenshot()&&ye.poseDetection.videoEmit({image:C.current.getScreenshot()||"",scanId:r}))},[C,r,ye,v,n.speechService,p,f]),Ae=t.useCallback(async()=>{A(!0),he(!0),Se?.(),ne.current&&(ne.current=!1,n.handleScanTimeCapture({eventName:"scan started",scanID:r,status:"success",email:f})),c(n.getCurrentTimeInSeconds()),F(!0),ee.current&&await n.speechService.playAudio(`${n.voiceOverAssetsPath}StartScan.mp3`),ee.current&&await n.speechService.playAudio(`${n.voiceOverAssetsPath}LiftArmsAndHoldAtHip.mp3`),ee.current&&(A(!1),T(!0),H(!0),Z(!0),Ce());try{if(C&&C.current&&C.current.stream&&ee.current){const e=C.current.stream.getVideoTracks()[0];if(e){const t=e.getSettings();j.current=t.frameRate||null}const t={videoBitsPerSecond:15e5};le[0]&&(t.mimeType=le[0]),ee.current&&(w.current=new MediaRecorder(C.current.stream,t)),ee.current&&w.current&&w.current.addEventListener("dataavailable",_e),X([...Q,_e]),w.current&&w.current.start(1e3),P(!1),ee.current&&(S=setTimeout(Ie,2e3))}}catch(e){console.log("error ----------",e)}},[C,le,_e,Q,Ie,ee,Se]);return t.useEffect(()=>(p&&(s(!0),De()),()=>{v&&(ye.poseDetection.disconnect(),n.posthog.capture(`${p}/pose_detection_disconnected`,{scanID:r,email:f,id:v})),Q.forEach(e=>{w?.current?.removeEventListener("dataavailable",e)})}),[p]),t.useEffect(()=>{z.push(R)},[R]),t.useEffect(()=>{K([])},[O]),t.useEffect(()=>{const e=N.length&&N.length>0;M||!e||D||!ee.current||G||w&&w.current&&(D||(w.current.stop(),P(!0)))},[M,D,N,G]),t.useEffect(()=>{const e=N.length&&N.length>0;if(M||!e||D)console.log("No video found to upload.");else if(w&&w.current&&ee.current&&!G&&!D){const e=new File(N,`${r}.${Ee}`,{type:ke});ve?.(),xe?.(!0),i(""),ge?.(e,j.current)}},[M,D,N,G,w,ee]),t.useEffect(()=>{const e=n.getSupportedMediaRecorderTypes(Ne,n.videoTypes);ue(e)},[Ne]),t.useEffect(()=>{be()},[]),e.jsx(h,{resetDetector:a,resetScan:be,loadingCam:E,onPause:je,showRestart:W,pause:G,onReScan:Te,recordingStarted:D,isScanning:_,startSendingVideoFrames:Ae,faceDone:L,stopRecording:Fe,showPause:Y,webcamRef:C,onUserMedia:Ce,onUserMediaError:we,videoConstraints:fe,webcamKey:de})});function w({scanID:n,userDetails:s,setIsVideoUploaded:a,setScanFailsError:r,setScanStartTime:o,setScanUniqueKey:i}){const[c,l]=t.useState(90),[u,d]=t.useState(0),[m,f]=t.useState(null),[h,g]=t.useState(!1),[x,y]=t.useState(0),S=t.useRef([]),[v,b]=t.useState(!1),w=c-u,j=w>=80&&w<=95;t.useEffect(()=>{if("undefined"!=typeof window&&window.DeviceOrientationEvent){const e=e=>{if(null!==e.beta){let t=Math.abs(e.beta);null!==e.gamma&&(t*=Math.cos(e.gamma*Math.PI/180)),t=Math.max(0,Math.min(180,t)),l(t)}},t=async()=>{const t=DeviceOrientationEvent;if(t&&"function"==typeof t.requestPermission)try{"granted"===await t.requestPermission()&&window.addEventListener("deviceorientation",e)}catch(e){console.error("Permission error",e)}else window.addEventListener("deviceorientation",e);return()=>{e&&window.removeEventListener("deviceorientation",e)}};document.addEventListener("click",t,{once:!0})}},[]),t.useEffect(()=>{if(S.current=[...S.current.slice(-4),w],S.current.length>=5){const e=Math.max(...S.current)-Math.min(...S.current);y(j&&e<2?e=>Math.min(100,e+10):e=>Math.max(0,e-20))}j||null===m&&!h||k()},[w,j,m,h]),t.useEffect(()=>{x>=100&&null===m&&!h&&N(),x<50&&null!==m&&k()},[x,m,h]);const N=()=>{f(3);const e=setInterval(()=>{f(t=>null===t||t<=1?(clearInterval(e),g(!0),null):t-1)},1e3)},k=()=>{f(null),v||g(!1)};return e.jsx(p,{angle:w,countdown:m,isScanning:h,isInTargetRange:j,stabilityScore:x,children:h&&e.jsx(C,{setIsScanLocked:b,resetDetector:()=>{l(90),d(0),f(null),g(!1),y(0),b(!1),S.current=[]},scanID:n,userDetails:s,setIsVideoUploaded:a,setScanFailsError:r,setScanStartTime:o,setScanUniqueKey:i})})}function j({message:s,config:a,variant:r}){const{translate:i}=t.useContext(n.LanguageContext)||{};return e.jsx(o.Dialog,{open:!0,className:"confirm-modal common-ui-main",disablePortal:!0,children:e.jsx("div",{className:"modal-main",children:e.jsx("div",{className:"text-center",children:"portrait"===r?e.jsxs(e.Fragment,{children:[e.jsx("h2",{style:{fontFamily:a?.style?.heading?.headingFontFamily||"SeriouslyNostalgic Fn",fontSize:a?.style?.heading?.headingFontSize||"32px",color:a?.style?.heading?.headingColor||"#000",fontWeight:a?.style?.heading?.headingFontWeight||"normal"},children:i?.(n.LanguageKeys.pleaseRotateToPortrait)}),e.jsx("p",{className:"mt-[0.5rem] text-sm",style:{fontFamily:a?.style?.base?.baseFontFamily||"Inter, sans-serif",fontSize:a?.style?.base?.baseFontSize||"16px",color:a?.style?.base?.baseTextColor||"#000"},children:i?.(n.LanguageKeys.rotateToPortraitDescription)})]}):s?e.jsxs(e.Fragment,{children:[e.jsx("h2",{style:{fontFamily:a?.style?.heading?.headingFontFamily||"SeriouslyNostalgic Fn",fontSize:a?.style?.heading?.headingFontSize||"32px",color:a?.style?.heading?.headingColor||"#000",fontWeight:a?.style?.heading?.headingFontWeight||"normal"},children:i?.(n.LanguageKeys.cameraAlreadyInUse)}),e.jsx("p",{className:"mt-[0.5rem] text-sm",style:{fontFamily:a?.style?.base?.baseFontFamily||"Inter, sans-serif",fontSize:a?.style?.base?.baseFontSize||"16px",color:a?.style?.base?.baseTextColor||"#000"},children:i?.(n.LanguageKeys.tryClosingBrowser)})]}):e.jsxs(e.Fragment,{children:[e.jsx("h2",{style:{fontFamily:a?.style?.heading?.headingFontFamily||"SeriouslyNostalgic Fn",fontSize:a?.style?.heading?.headingFontSize||"32px",color:a?.style?.heading?.headingColor||"#000",fontWeight:a?.style?.heading?.headingFontWeight||"normal"},children:i?.(n.LanguageKeys.checkCameraSettings)}),e.jsx("p",{className:"mt-[0.5rem] text-sm",style:{fontFamily:a?.style?.base?.baseFontFamily||"Inter, sans-serif",fontSize:a?.style?.base?.baseFontSize||"16px",color:a?.style?.base?.baseTextColor||"#000"},children:`${i?.(n.LanguageKeys.setting)} > ${n.getBrowserName()} > ${i?.(n.LanguageKeys.enableCameraPermissions)}`})]})})})})}function N({setShowDrawer:s,config:r,loader:o}){const[i,c]=t.useState({disabled:!1,message:""}),[l,u]=t.useState(!0),d=t.useRef(null),m=t.useCallback(async()=>{const e=await n.checkCameraPermission();c(e),u(!1)},[]);return t.useEffect(()=>{m()},[]),l?e.jsx(n.LoadingScreen,{url:o,loaderType:"black"}):i?.disabled?e.jsx(j,{config:r,message:i?.message}):e.jsx(a,{audio:!1,ref:d,screenshotQuality:1,videoConstraints:n.videoConstraints,mirrored:!0,onUserMedia:()=>s?.(!0),screenshotFormat:"image/jpeg",style:{position:"relative",top:0,bottom:0,zIndex:0,width:"100%",height:"100%",objectFit:"cover"}})}function k({link:s,onReady:a,wrapperClassName:r="[&_video]:rounded-t-[20px] w-full h-full"}){const o=t.useRef(null),c=t.useRef(null);let l={autoplay:!0,controls:!1,responsive:!0,fluid:!0,muted:!0,navigationUI:"hide",preload:"metadata",poster:n.videoPoster};return t.useEffect(()=>{if(!c.current&&s&&o?.current){const e=i(o.current,{...l});e.ready(()=>{c.current=e;const t={...l,sources:[{src:s,type:"application/x-mpegURL"}]};e.autoplay(t.autoplay),e.src(t.sources),a?.(e)})}},[s,o]),t.useEffect(()=>{const e=c.current;return()=>{e&&!e.isDisposed()&&(e.dispose(),c.current=null)}},[c]),e.jsx("div",{className:r,children:e.jsx("video",{ref:o,muted:!0,className:"video-js",playsInline:!0,onDrag:e=>e.preventDefault()})})}function E({scanFailsError:s,onNext:a,gender:i,setScanUniqueKey:c,setIsVideoUploaded:l}){const{translate:u}=t.useContext(n.LanguageContext)||{},d=n.useConfig(),[m,f]=t.useState(!1),p=()=>{f(!m)};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex common-ui-main flex-col h-full max-w-[28rem] mx-auto w-full rounded-t-[20px] overflow-y-auto",style:{background:d?.style?.base?.backgroundColor},children:[e.jsx("div",{className:"w-full max-w-[28rem] mx-auto pt-[1rem] px-[1rem]",children:e.jsx(n.Header,{noTitle:!0})}),e.jsx("div",{className:"flex-1",children:s&&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?.(n.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?.(n.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:n.handleErrorMessage(s)}),e.jsx("img",{className:"my-[0.5rem] aspect-[2/1.4] w-full object-cover",onClick:p,src:n.VIDEO_POSTER_GENDER_BASED[i],alt:"icon"})]})}),s&&e.jsx("div",{className:"p-[1rem] flex gap-[0.5rem]",children:e.jsx(n.SpecificButton,{disabled:!1,buttonText:u?.(n.LanguageKeys.scanAgain),className:"!shadow-none",buttonFunc:()=>{a?a?.():c?.(n.generateUuid()),l?.(!1)}})})]}),m&&e.jsxs(o.Dialog,{className:"w-screen h-screen video-modal",onClose:p,open:m,disablePortal:!0,children:[e.jsx("div",{className:"flex justifyEnd ",children:e.jsx("span",{className:"closeBtn",onClick:p,children:e.jsx(r.X,{className:"absolute right-[8px] top-[8px] text-white z-[9]"})})}),e.jsx("div",{className:"aspect-video object-cover rounded-[20px] ",children:e.jsx(k,{link:i?n.GENDER[i].PRE_LINK:n.GENDER.male.PRE_LINK,wrapperClassName:"w-screen h-screen fixed top-[0] left-[0]"})})]})]})}function F({scanId:s,userDetails:a,config:r,isVideoUploadedCorrect:i,isMeasurementAvailable:c,onComplete:l,isSuccess:u,onCustomScanSuccess:d,swan:m}){const{gender:f,shopDomain:p,heightInCm:h,deviceFocalLength:g,userName:x,email:y,scanType:S}=a||{},v=[n.CLOTHING_CUSTOM_SCAN,n.CLOTHING_BANNER_SCAN,n.CLOTHING_CUSTOM_FIT_SCAN].includes(S??""),[b,C]=t.useState(!0),w=t.useCallback(async()=>{try{v&&(await(m?.auth.addUser({scanId:s,email:y,name:x,gender:f,height:h})),d?.()),n.posthog.capture(p??"",{scanID:s,email:y,height:h,focalLength:g,clothesFit:"0",gender:f})}catch(e){console.log(e)}},[v]),{translate:j}=t.useContext(n.LanguageContext)||{};t.useEffect(()=>{(i||c)&&w()},[i,c]);const k=u||i||c;return e.jsx(o.Box,{className:"flex h-full w-full flex-col common-ui-main",children:e.jsxs("div",{className:"h-full w-full flex-col items-center justify-center flex",children:[e.jsx(N,{loader:r?.loader,setShowDrawer:C}),e.jsx(o.Drawer,{open:b,onClose:(e,t)=>{},disablePortal:!0,className:"camera-drawer",anchor:"bottom",children:e.jsx("div",{className:"max-w-[28rem] mx-auto w-full h-full flex text-center flex-col justify-between items-center bg-primary rounded-t-[30px] p-[1rem]",style:{background:r?.style?.base?.backgroundColor},children:e.jsxs("div",{className:"w-full h-full flex flex-col",children:[e.jsx(n.Header,{title:j?.(n.LanguageKeys.measurementsBeingTaken)}),e.jsx("div",{className:"flex items-center justify-center flex-1",children:e.jsx("video",{preload:"auto",className:"max-h-[calc(100vh-450px)] mx-auto w-full object-contain border-none",muted:!0,loop:!0,autoPlay:!0,playsInline:!0,children:e.jsx("source",{src:f===n.GenderType.Male?n.maleMeasurementProgress:n.measurementProgress,type:"video/mp4"})})}),k&&e.jsx(n.SpecificButton,{className:"!w-[180px] mx-auto",buttonText:j?.(n.LanguageKeys.next),buttonFunc:()=>{l?.()}})]})})})]})})}const D=()=>{const{userDetails:s,onRetry:a,isError:r,isSuccess:i,gender:c,scanUniqueKey:l,scanFailsError:u,setScanUniqueKey:d,setIsVideoUploaded:m,isMeasurementAvailable:f,isVideoUploadedCorrect:p,loading:h,showDeniedModal:g,uploadLoading:x,setScanFailsError:y,setScanStartTime:S,resetScan:v,onCustomScanSuccess:b,swan:C,onComplete:k}=t.useContext(n.ParamsContext),D=n.useConfig();return r?e.jsxs(e.Fragment,{children:[e.jsx(N,{}),e.jsx(o.Drawer,{anchor:"bottom",open:!0,className:"camera-drawer",onClose:(e,t)=>{},disablePortal:!0,children:e.jsx(E,{scanFailsError:!0,onNext:a,gender:c})})]}):i?e.jsx(F,{isSuccess:!0,onComplete:k,config:D}):h?e.jsx("div",{className:"flex top-0 !mt-0 left-0 z-[999] absolute justify-center items-center w-full h-full",style:{background:D?.style?.base?.backgroundColor},children:e.jsx(n.LoadingScreen,{url:D?.loader,loaderType:"black"})}):g.disabled?e.jsx(j,{}):x||u||f||p?(x||f||p)&&!u?e.jsx(F,{scanId:l,isMeasurementAvailable:f,userDetails:s,isVideoUploadedCorrect:p,onCustomScanSuccess:b,swan:C,onComplete:k,config:D}):e.jsxs(e.Fragment,{children:[e.jsx(N,{}),e.jsx(o.Drawer,{anchor:"bottom",open:!0,className:"camera-drawer",onClose:(e,t)=>{},disablePortal:!0,children:e.jsx(E,{scanFailsError:u,onNext:()=>{a?.(),v()},setScanUniqueKey:d,gender:c,setIsVideoUploaded:m})})]}):e.jsx(w,{scanID:l,userDetails:s,setIsVideoUploaded:m,setScanFailsError:y,setScanStartTime:S,setScanUniqueKey:d})};exports.BodyScan=s=>{const{config:a,onRetry:r,onScanStart:o,onCaptureComplete:i,onUploadStart:c,onUploadEnd:l,onMeasurementSocketStart:u,onMeasurementSocketClose:d,onIntermediateScanSuccess:f,onScanError:p,onScanSuccess:h,onCustomScanSuccess:g,onComplete:x,isError:y,isSuccess:S}=s,v={email:"",shopDomain:"",gender:"male",heightInCm:0,scanType:"",deviceFocalLength:0,deviceModelName:"",sourceTag:"",...s.userDetails??{}},b=s.token??"",{gender:C,scanType:w,shopDomain:N,heightInCm:k,email:E,deviceFocalLength:F,deviceModelName:T,callbackUrl:L,sourceTag:I}=v,M=t.useMemo(()=>n.getSwanService(b),[b]),[P,_]=t.useState(!1),[A,$]=t.useState(!1),[R,U]=t.useState(!1),[z,K]=t.useState({disabled:!1,message:""}),[O,B]=t.useState(""),[q,V]=t.useState(!1),[W,H]=t.useState(!0),[G,J]=t.useState(!1),[Q,X]=t.useState(""),[Y,Z]=t.useState(n.getCurrentTimeInSeconds()),{gyroData:ee}=function(e){const[n,s]=t.useState([]),[a,r]=t.useState(!1),o=t.useCallback(e=>{try{const{alpha:t,beta:n,gamma:a}=e;s(e=>[...e,{alpha:t?.toString()||void 0,beta:n?.toString()||void 0,gamma:a?.toString()||void 0,timestamp:(new Date).toISOString()}])}catch(e){console.log(e)}},[]),i=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):s([]),()=>{window.removeEventListener("deviceorientation",o)}),[e,a,o]),t.useEffect(()=>{e&&i()},[e,i]),{gyroData:n}}(G),{isLandscape:te}=(()=>{const[e,n]=t.useState(!1),s=t.useCallback(()=>{if("undefined"!=typeof window){if(screen?.orientation?.type){const e=screen.orientation.type;return void n(e.startsWith("landscape"))}n(window.innerWidth>window.innerHeight)}},[]);return t.useEffect(()=>{if("undefined"==typeof window)return;(async()=>{try{screen?.orientation?.lock&&await screen.orientation.lock("portrait")}catch{}})(),s();const e=()=>s();return screen?.orientation?.addEventListener&&screen.orientation.addEventListener("change",e),window.addEventListener("orientationchange",e),window.addEventListener("resize",e),()=>{screen?.orientation?.removeEventListener&&screen.orientation.removeEventListener("change",e),window.removeEventListener("orientationchange",e),window.removeEventListener("resize",e);try{screen?.orientation?.unlock?.()}catch{}}},[s]),{isLandscape:e}})();n.usePosthogPageview();const ne=t.useCallback(()=>{X(n.generateUuid()),B(""),_(!1),V(!1)},[]);t.useEffect(()=>{te&&!P&&ne()},[te,P,ne]);const se=()=>{Z(null),X("")},ae=t.useCallback(async e=>{if(e&&"success"===e?.scanStatus&&"intermediate"===e?.resultType&&200===e?.code)return n.handleScanTimeCapture({eventName:`${N}/measurement_success/intermediate`,scanID:Q,status:"success",email:E}),$(!0),void f?.(e);h?.(e),$(!0),se();const t=Q;U(!0),n.handleScanTimeCapture({eventName:`${N}/measurement_success/fit-view`,scanID:t,status:"success",email:E}),Y&&n.handleScanTimeCapture({eventName:`${N}/scan_completion_time`,scanID:t,status:"success",completionTime:n.getCurrentTimeInSeconds()-Y,email:E})},[w,N,Q]),re=e=>{U(!1),B(""),$(!1),M.measurement.handleMeasurementSocket({scanId:Q,onPreopen:()=>{n.handleWebSocketCapture({eventName:`${N}/webSocket`,scanID:Q,connection:"pre_open",type:"measurement_recommendation",email:E})},onOpen:()=>{u?.(),n.handleWebSocketCapture({eventName:`${N}/webSocket`,scanID:Q,connection:"open",type:"measurement_recommendation",email:E})},onClose:()=>{d?.(),n.handleWebSocketCapture({eventName:`${N}/webSocket`,scanID:Q,connection:"close",type:"measurement_recommendation",email:E})},onError:e=>{var t;t=e,p?.({...t,message:n.handleErrorMessage(t)}),se(),U(!1),B(t),$(!1),n.handleScanTimeCapture({eventName:`${N}/measurement_failed/fit-view`,scanID:Q,status:"failed",email:E,message:n.handleErrorMessage(t)}),Y&&n.handleScanTimeCapture({eventName:`${N}/scan_completion_time`,scanID:Q,status:"failed",completionTime:n.getCurrentTimeInSeconds()-Y,email:E}),n.handleWebSocketCapture({eventName:`${N}/webSocket`,scanID:Q,connection:"error",type:"measurement_recommendation",email:E})},onSuccess:e=>{n.handleWebSocketCapture({eventName:`${N}/webSocket`,scanID:Q,connection:"success",type:"measurement_recommendation",email:E}),ae(e)}})},oe=t.useCallback(async(e,t)=>{const s=Number((e.size/1048576).toFixed(2)),a=null!=t?t:await n.getVideoFPS(e),r=n.createObjectMetadataArray({gender:C,focal_length:`${F}`,height:`${k}`,customer_store_url:N,clothes_fit:"0",scan_type:w,callback_url:L,source_tag:I});n.handleScanTimeCapture({eventName:`${N}/body_scan_meta_data`,scanID:Q,email:E,data:JSON.stringify([...r,{fileSizeInMB:s,video_fps:a||0}])}),c?.();try{await M.fileUpload.uploadFileFrontend({file:e,arrayMetaData:r,scanId:Q,email:E}),await M.fileUpload.setDeviceInfo({model:T,detection:"manual",gyro:ee,scanId:Q}),console.log("video successfully uploaded"),V(!1),n.handleScanTimeCapture({eventName:`${N}/scan_success`,scanID:Q,status:"success",email:E,data:JSON.stringify(r)}),n.handleScanTimeCapture({eventName:"scan finished",scanID:Q,status:"success",email:E}),Z(n.getCurrentTimeInSeconds()),setTimeout(()=>{V(!0)},3e3)}catch(e){n.handleScanTimeCapture({eventName:"scan finished",scanID:Q,status:"failed",email:E,message:n.handleErrorMessage(e)}),n.handleScanTimeCapture({eventName:`${N}/scan_failed`,scanID:Q,status:"failed",email:E,message:n.handleErrorMessage(e),data:JSON.stringify(r)}),B(n.handleErrorMessage(e)),V(!1),p?.({...e,message:n.handleErrorMessage(e)}),se()}finally{J(!1),l?.()}},[Q,ee,c,l]),ie=t.useCallback(async()=>{if(+k<152.4||+k>213.36)return void p?.({message:"Height must be between 152.4cm (5ft) and 213.36cm (7ft)"});const e=await n.checkCameraPermission();e.disabled?(n.handleScanTimeCapture({eventName:`${N}/camera_activation`,scanID:Q,status:"failed",email:E}),H(!1)):(H(!1),n.handleScanTimeCapture({eventName:`${N}/camera_activation`,scanID:Q,status:"success",email:E})),K(e),B(""),V(!1)},[E,Q,X,N]);return t.useEffect(()=>{y||S||N&&ie()},[N,k,y,S]),t.useEffect(()=>{y||S||q&&N&&Q&&re()},[q,N,Q,y,S]),e.jsx(n.LanguageContextProvider,{children:e.jsx(n.ConfigProvider,{config:a,children:e.jsxs(m,{children:[te&&!P&&e.jsx(j,{variant:"portrait",config:a}),e.jsx(n.ParamsContext.Provider,{value:{userDetails:v,onRetry:r,onScanError:p,isError:y,isSuccess:S,onScanSuccess:h,gender:C,scanUniqueKey:Q,scanFailsError:O,setScanUniqueKey:X,setIsVideoUploaded:V,isMeasurementAvailable:R,isVideoUploadedCorrect:A,loading:W,showDeniedModal:z,uploadLoading:P,setStartGyro:J,uploadScanFile:oe,setUploadLoading:_,resetScan:ne,setScanFailsError:B,setScanStartTime:Z,onScanStart:o,onCaptureComplete:i,onCustomScanSuccess:g,onComplete:x,swan:M},children:e.jsx(ShadowRoot,{children:e.jsx(D,{})})})]})})})};
2
+ //# sourceMappingURL=BodyScan-C4Yn1avh.js.map