@swan-admin/swan-dev-web-component 0.1.0-alpha.1774954489 → 0.1.0-alpha.1774957097

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