@swan-admin/swan-web-component 1.0.95 → 1.0.97

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.
@@ -1,2 +1,2 @@
1
- "use strict";var e=require("react/jsx-runtime"),t=require("react"),s=require("posthog-js"),a=require("./LoadingScreen--G_kIDCD.js"),n=require("clsx"),r=require("react-webcam"),o=require("@mui/icons-material"),i=require("@mui/material"),c=require("video.js");const l="DESKTOP",u="TAB",d="MOBILE",m=t.createContext(void 0);function f({children:s}){const[a,n]=t.useState([window?.innerWidth,window?.innerHeight]),[r,o]=t.useState(!1),i=()=>{n([window?.innerWidth,window?.innerHeight])};t.useEffect(()=>{i()},[]),t.useLayoutEffect(()=>(window.addEventListener("resize",i),()=>window.removeEventListener("resize",i)),[i]);let c=l;a[0]>768&&a[0]<1024&&(c=u),a[0]<768&&(c=d);const f=t.useMemo(()=>({size:a,setSize:n,clearInputs:r,setClearInputs:o,media:c}),[a,r,c]);return e.jsx(m.Provider,{value:f,children:s})}var h=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 g=t.memo(function({angle:s,countdown:r,isScanning:o,isInTargetRange:i,stabilityScore:c,children:l,config:u}){const{translate:d}=t.useContext(a.LanguageContext)||{},m=t.useCallback(()=>s<80?Math.max(0,Math.min(100,10*(s-60))):s>95?Math.max(0,Math.min(100,10*(105-s))):100,[s]),f=t.useMemo(()=>{if(o)return u?.style?.angleDetector?.successAngleBackground||"#4f46e5";const e=m();if(0===e)return u?.style?.angleDetector?.successAngleLowBackground||"#ffffff";if(100===e)return u?.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]),g=t.useCallback((e,t)=>t>70?e?`text-[${u?.style?.angleDetector?.successAngleTextLightColor}]/70`:`text-[${u?.style?.angleDetector?.successAngleTextLightColor}]`:e?`text-[${u?.style?.angleDetector?.successAngleTextLightColor}]/40`:`text-[${u?.style?.angleDetector?.successAngleTextDarkColor}]/70`,[]),p=t.useCallback((e=!1)=>{const t=m();return o?`text-[${u?.style?.angleDetector?.successAngleTextLightColor}]`:g(e,t)},[o,m]),x=t.useCallback((e,t)=>t>70||e?u?.style?.angleDetector?.successAngleTextLightColor:u?.style?.angleDetector?.successAngleTextDarkColor,[]),y=t.useCallback((e=!1)=>{const t=m();return o?u?.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 w-screen flex-col items-center h-[var(--real-vh)] overflow-hidden touch-none justify-center transition-all duration-300 max-w-[28rem] mx-auto",style:{backgroundColor:f},children:[e.jsx("div",{className:"flex justify-start fixed top-[.5rem] max-w-[28rem] mx-auto w-full px-[1rem]",children:e.jsx("div",{className:"flex justify-start ",children:e.jsx(a.Header,{noTitle:!0,resolvedConfig:u})})}),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:u?.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] ",i?"bg-[#fff]/20 border-[#fff]":"bg-[#fff]/10 border-[#fff]"),style:{transform:`translateY(${3*(90-s)}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]",p()),style:{color:y()},children:[e.jsx(h,{size:30}),e.jsxs("p",{style:{fontFamily:u?.style?.base?.baseFontFamily||"Inter, sans-serif"},children:[" ",d?.(a.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",p()),style:{fontFamily:u?.style?.base?.baseFontFamily||"Inter, sans-serif",color:y()},children:d?.(a.LanguageKeys.leavePhone)})}),i&&null===S&&!o&&e.jsx("div",{className:"absolute bottom-[8rem] w-[12rem]",children:e.jsx("div",{className:`h-[.375rem] w-full bg-[${y()}]/20 rounded-[9999px] overflow-hidden`,style:{backgroundColor:`${y()}33`},children:e.jsx("div",{className:`h-full bg-[${y()}]/70 transition-all duration-300 rounded-[9999px]`,style:{width:`${s}%`,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",p()),style:{color:y()},children:[Math.round(s),"°"]})}),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",p()),style:{fontFamily:u?.style?.base?.baseFontFamily||"Inter, sans-serif",color:y()},children:d?.(a.LanguageKeys.placePhoneUpright)})})]})});function p({handleShowStreamCamera:s,loadingCam:n,handleUserMedia:i,handlePause:c,pause:l,recordingStarted:u,startSendingVideoFrames:f,showPause:h,webcamRef:g,resetDetector:p,config:x}){const{media:y}=t.useContext(m)||{},{translate:S}=t.useContext(a.LanguageContext)||{};return e.jsxs("div",{className:"App w-screen h-[100vh] relative ",children:[e.jsx("span",{onClick:()=>{s(),p()},className:"fixed right-[20px] top-[20px] z-[999]",children:e.jsx(o.Close,{className:"text-[#fff]"})}),e.jsx("div",{className:"w-full h-full overflow-hidden ",children:y===d&&e.jsx(r,{audio:!1,ref:g,screenshotQuality:1,videoConstraints:a.videoConstraints,mirrored:!0,screenshotFormat:"image/jpeg",onUserMedia:i,style:{position:"fixed",top:0,bottom:0,zIndex:0,width:"100%",height:"100%",objectFit:"cover"}})}),e.jsxs("div",{className:"fixed bottom-[30px] w-full z-[999] flex flex-col gap-4 items-center justify-center",children:[h&&e.jsx(a.SpecificButton,{className:"!w-[180px] !h-[40px] !py-[0] mx-auto ",prefix:a.pauseIcon,buttonText:S?.(a.LanguageKeys.pause),buttonFunc:c,resolvedConfig:x,btnSecondary:!0}),l?e.jsx("div",{children:e.jsx(a.SpecificButton,{className:"!w-[180px] !h-[40px] !py-[0] mx-auto",buttonText:S?.(a.LanguageKeys.restart),buttonFunc:s,resolvedConfig:x,btnSecondary:!0})}):u?null:e.jsx(a.SpecificButton,{className:"!w-[180px] !h-[40px] !py-[0] mx-auto !bg-[#ffffff] !text-[#000000] "+(n?"!opacity-50":""),buttonText:S?.(a.LanguageKeys.startScan),buttonFunc:f,disabled:n,resolvedConfig:x})]}),e.jsx("audio",{id:"audioElement",crossOrigin:"anonymous",preload:"auto",style:{position:"absolute",zIndex:-99999},src:`${a.voiceOverAssetsPath}scanAudioInstructions/silence.mp3`})]})}let x=null,y=null,S=null;let v,b=null,C=null;var w=t.memo(function({setIsScanLocked:n,resetDetector:r,scanID:o,setIsVideoUploaded:i,setScanFailsError:c,setScanStartTime:l,setScanUniqueKey:u,userDetails:d,config:m}){const{gender:f,heightInCm:h,email:g,shopDomain:w}=d,j=t.useRef(null),N=t.useRef(null),[F,E]=t.useState([]),[D,k]=t.useState(!0),[I,T]=t.useState(!1),[L,M]=t.useState(!1),[A,_]=t.useState(!0),[P,U]=t.useState(!1),$=t.useRef(null),[z,R]=t.useState(""),[K,O]=t.useState([]),[q,B]=t.useState(""),[V,W]=t.useState(!1),[H,G]=t.useState(!1),[J,Q]=t.useState(!1),[Y,X]=t.useState([]),[Z,ee]=t.useState(!1),te=t.useRef(!0),{poseDetector:se}=function(){const[e,s]=t.useState(0),[a,n]=t.useState(0),[r,o]=t.useState(!1),i=t.useRef(0),c=t.useRef(0),l=t.useRef(!0);async function u(){if("undefined"==typeof window||"undefined"==typeof navigator)return!1;try{console.log("Starting TensorFlow preload...");const[e,t,s]=await Promise.all([Promise.resolve().then(function(){return require("./pose-detection.esm-BMyJE2Fw.js")}),import("@tensorflow/tfjs-core"),import("@tensorflow/tfjs-backend-webgl")]);S=e,await t.setBackend("webgl"),await t.ready(),console.log("TensorFlow backend ready (WebGL)");const a={runtime:"mediapipe",modelType:"full",solutionPath:"https://cdn.jsdelivr.net/npm/@mediapipe/pose"};try{y=await S.createDetector(S.SupportedModels.BlazePose,a),console.log("MediaPipe detector created successfully")}catch(e){console.warn("MediaPipe failed, falling back to TFJS runtime:",e),y=await S.createDetector(S.SupportedModels.BlazePose,{runtime:"tfjs",modelType:"full"}),console.log("TFJS detector created successfully")}return!0}catch(e){return console.error("Failed to load TensorFlow dependencies:",e),x=null,!1}}function d(e){return!(!e||0===e.length)&&22===e.filter(e=>e[2]>.7).length}return t.useEffect(()=>{if(l.current=!0,!y)return x||(x=u()),x.then(e=>{e&&l.current&&o(!0)}),()=>{l.current=!1};o(!0)},[]),t.useEffect(()=>{c.current=e,e>6&&i.current<2&&(n(e=>e+1),s(0))},[e]),t.useEffect(()=>{i.current=a},[a]),{poseDetector:async(e,t)=>{if(!y||!l.current||!t?.current?.video)return;const a=t.current.video;if(!(a.readyState<2))try{const t=await y.estimatePoses(a,{flipHorizontal:!1});if(!t||!t.length)return;const n=t[0].keypoints.slice(11).map(e=>[e.x>0&&e.x<720?e.x:-1,e.y>0&&e.y<1280?e.y:-1,e.score??0]);0!==i.current||d(n)||s(e=>e+1),1===i.current&&d(n)&&s(e=>e+1),2===i.current&&e()}catch(e){console.error("Pose detection error:",e)}},isLoaded:r,spinPhase:a,resetDetector:()=>{i.current=0,c.current=0,s(0),n(0)},retryLoading:async()=>{y||x||(x=u(),await x&&l.current&&o(!0))}}}(),ae=t.useRef(!0),ne=t.useRef(!1),[re,oe]=t.useState([]);let ie=0;const{setStartGyro:ce,handleFileUpload:le,setUploadLoading:ue}=t.useContext(a.ParamsContext),de=()=>{ne.current=!1,clearTimeout(v),$.current&&clearTimeout($.current),u(a.generateUuid()),c(""),ue?.(!1),E([]),k(!0),T(!1),M(!1),_(!0),U(!1),$.current=null,R(""),O([]),B(""),W(!V),ce(!1),a.speechService.stopAudio(),G(!1),Q(!1),ie=0,null!==N.current&&N.current.stop(),Y.forEach(e=>{N.current&&N.current.removeEventListener("dataavailable",e)}),X([]),te.current=!0,ee(!1),i(!1)},me=t.useCallback(()=>{setTimeout(()=>{k(!1)},1e3)},[]),fe=t.useCallback(()=>{a.rescanSupportCaptureEvent({eventName:`${w}/rescan`,email:g,scanID:o,height:h,gender:f,status:!1}),te.current=!1,de(),Ce()},[de,o,g]),he=t.useCallback(()=>{te.current=!1,Q(!0),ee(!1),$.current&&clearTimeout($.current),N.current&&N.current.pause(),a.speechService.stopAudio(),a.swan.poseDetection.disconnect(),ie=0,N.current&&N.current.stop(),Y.forEach(e=>{N.current&&N.current.removeEventListener("dataavailable",e)}),X([]),clearTimeout(v)},[N,Y,a.speechService,te]),ge=t.useCallback(async()=>{te.current=!0,await a.speechService.playAudio(`${a.voiceOverAssetsPath}SpotOn.mp3`),Q(!1),ee(!1),$.current&&clearTimeout($.current),T(!1)},[$,a.speechService]),pe=t.useCallback(async()=>{try{b=await a.swan.poseDetection.connect(),s.capture(`${w}/pose_detection_connected`,{scanID:o,email:g,id:b})}catch(e){console.log(e,"while connecting websocket")}},[o,w,g]),xe=t.useCallback(({data:e})=>{e&&e.size>0&&te.current&&(E(t=>t.concat(e)),!ne.current&&j.current&&(ne.current=!0,se(()=>{ge(),a.handleScanTimeCapture({eventName:`${w}/tensorFlow`,scanID:o,email:g,message:"recording stopped by tensorflow "})},j)))},[ge,a.handleScanTimeCapture,w,o,g,j]),ye=t.useCallback(async()=>{K.length>0&&te.current&&(await a.speechService.playAudio(a.voiceOverAssetsPath+K[K.length-1]),te.current&&(v=setTimeout(ye,2e3)))},[K,te]),Se=t.useCallback(()=>{N&&N.current&&N.current.stop(),T(!0);try{if(j&&j.current&&j.current.stream){const e={mimeType:re[0]};N.current=new MediaRecorder(j.current.stream,e),N.current.addEventListener("dataavailable",xe),X([...Y,xe]),N.current.start(1e3),_(!1)}}catch(e){console.log("error while using media recorder",e)}},[j,re,xe,Y]),ve=t.useCallback(async()=>{$.current&&clearTimeout($.current),Se(),te.current&&($.current=setTimeout(async()=>{te.current&&(await a.speechService.playAudio(`${a.voiceOverAssetsPath}SpotOn.mp3`),T(!1))},15e3)),M(!0),te.current&&await a.speechService.playAudio(`${a.voiceOverAssetsPath}Spin.mp3`)},[Se,te,a.speechService]),be=t.useCallback(({data:e})=>{e.size>0&&a.swan.poseDetection.connected()&&(a.swan.poseDetection.poseStatus(async e=>{if(e&&e.audio&&e.audio.length>0){const t=document.querySelector("#audioElement");!0===e.status&&e.sid===b?ie<2?(0===ie&&t?.paused&&await a.speechService.playAudio(a.voiceOverAssetsPath+e.audio),ie+=1):(B(e.audio),clearTimeout(v),a.swan.poseDetection.disconnect(),setTimeout(ve,1e3)):(ie=0,!t?.paused||C&&C?.audioName===e.audio?C?.audioName===e.audio&&t?.paused&&(C&&C.no_of_times_skipped>=C.skipCount?(C.no_of_times_skipped=0,a.speechService.playAudio(a.voiceOverAssetsPath+e.audio)):C&&(C.no_of_times_skipped+=1)):(C={skipCount:2,no_of_times_skipped:0,audioName:e.audio},a.speechService.playAudio(a.voiceOverAssetsPath+e.audio)))}}),j?.current&&null!==j.current.getScreenshot()&&a.swan.poseDetection.videoEmit({image:j.current.getScreenshot()||"",scanId:o}))},[j,o,a.swan,b,ie,ve,a.speechService]),Ce=t.useCallback(async()=>{U(!0),ce(!0),ae.current&&(ae.current=!1,a.handleScanTimeCapture({eventName:"scan started",scanID:o,status:"success",email:g})),l(a.getCurrentTimeInSeconds()),k(!0),te.current&&await a.speechService.playAudio(`${a.voiceOverAssetsPath}StartScan.mp3`),te.current&&await a.speechService.playAudio(`${a.voiceOverAssetsPath}LiftArmsAndHoldAtHip.mp3`),te.current&&(U(!1),T(!0),G(!0),ee(!0),me());try{if(j&&j.current&&j.current.stream&&te.current){const e={mimeType:re[0]};te.current&&(N.current=new MediaRecorder(j.current.stream,e)),te.current&&N.current&&N.current.addEventListener("dataavailable",be),X([...Y,be]),N.current&&N.current.start(1e3),_(!1),te.current&&(v=setTimeout(ye,2e3))}}catch(e){console.log("error ----------",e)}},[j,re,be,Y,ye,te]);return t.useEffect(()=>(w&&(n(!0),pe()),()=>{b&&(a.swan.poseDetection.disconnect(),s.capture(`${w}/pose_detection_disconnected`,{scanID:o,email:g,id:b})),Y.forEach(e=>{N?.current?.removeEventListener("dataavailable",e)})}),[V,w]),t.useEffect(()=>{K.push(z)},[z]),t.useEffect(()=>{O([])},[q]),t.useEffect(()=>{const e=F.length&&F.length>0;A||!e||I||!te.current||J||N&&N.current&&(I||(N.current.stop(),_(!0)))},[A,I,F,J]),t.useEffect(()=>{const e=F.length&&F.length>0;if(A||!e||I)console.log("No video found to upload");else if(N&&N.current&&te.current&&!J&&!I){const e=new File(F,`${o}.webm`,{type:"video/webm"});ue?.(!0),c(""),le?.(e)}},[A,I,F,J,N,te]),t.useEffect(()=>{if("undefined"!=typeof MediaRecorder){const e=a.videoTypes.filter(e=>MediaRecorder.isTypeSupported(e));oe(e)}},[]),t.useEffect(()=>{de()},[]),e.jsx(p,{resetDetector:r,handleShowStreamCamera:de,loadingCam:D,handlePause:he,showRestart:H,pause:J,handleReScan:fe,recordingStarted:I,isScanning:P,startSendingVideoFrames:Ce,faceDone:L,stopRecording:ge,showPause:Z,webcamRef:j,handleUserMedia:me,config:m})});function j({scanID:s,userDetails:a,setIsVideoUploaded:n,setScanFailsError:r,setScanStartTime:o,setScanUniqueKey:i,config:c}){const[l,u]=t.useState(90),[d,m]=t.useState(0),[f,h]=t.useState(null),[p,x]=t.useState(!1),[y,S]=t.useState(0),v=t.useRef([]),[b,C]=t.useState(!1),j=l-d,N=j>=80&&j<=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)),u(t)}},t=async()=>{const t=DeviceOrientationEvent;if(t&&"function"==typeof t.requestPermission)try{"granted"===await t.requestPermission()&&window.addEventListener("deviceorientation",e)}catch(e){console.error("Permission error",e)}else window.addEventListener("deviceorientation",e);return()=>{e&&window.removeEventListener("deviceorientation",e)}};document.addEventListener("click",t,{once:!0})}},[]),t.useEffect(()=>{if(v.current=[...v.current.slice(-4),j],v.current.length>=5){const e=Math.max(...v.current)-Math.min(...v.current);S(N&&e<2?e=>Math.min(100,e+10):e=>Math.max(0,e-20))}N||null===f&&!p||E()},[j,N,f,p]),t.useEffect(()=>{y>=100&&null===f&&!p&&F(),y<50&&null!==f&&E()},[y,f,p]);const F=()=>{h(3);const e=setInterval(()=>{h(t=>null===t||t<=1?(clearInterval(e),x(!0),null):t-1)},1e3)},E=()=>{h(null),b||x(!1)};return e.jsx(g,{angle:j,countdown:f,isScanning:p,isInTargetRange:N,stabilityScore:y,config:c,children:p&&e.jsx(w,{setIsScanLocked:C,resetDetector:()=>{u(90),m(0),h(null),x(!1),S(0),C(!1),v.current=[]},scanID:s,userDetails:a,setIsVideoUploaded:n,setScanFailsError:r,setScanStartTime:o,setScanUniqueKey:i,config:c})})}function N({message:s,config:n}){const{translate:r}=t.useContext(a.LanguageContext)||{};return e.jsx(i.Dialog,{open:!0,className:"confirm-modal",children:e.jsx("div",{className:"modal-main",children:e.jsx("div",{className:"text-center",children:s?e.jsxs(e.Fragment,{children:[e.jsx("h2",{style:{fontFamily:n?.style?.heading?.headingFontFamily||"SeriouslyNostalgic Fn",fontSize:n?.style?.heading?.headingFontSize||"32px",color:n?.style?.heading?.headingColor||"#000",fontWeight:n?.style?.heading?.headingFontWeight||"normal"},children:r?.(a.LanguageKeys.cameraAlreadyInUse)}),e.jsx("p",{className:"mt-[0.5rem] text-sm",style:{fontFamily:n?.style?.base?.baseFontFamily||"Inter, sans-serif",fontSize:n?.style?.base?.baseFontSize||"16px",color:n?.style?.base?.baseTextColor||"#000"},children:r?.(a.LanguageKeys.tryClosingBrowser)})]}):e.jsxs(e.Fragment,{children:[e.jsx("h2",{style:{fontFamily:n?.style?.heading?.headingFontFamily||"SeriouslyNostalgic Fn",fontSize:n?.style?.heading?.headingFontSize||"32px",color:n?.style?.heading?.headingColor||"#000",fontWeight:n?.style?.heading?.headingFontWeight||"normal"},children:r?.(a.LanguageKeys.checkCameraSettings)}),e.jsx("p",{className:"mt-[0.5rem] text-sm",style:{fontFamily:n?.style?.base?.baseFontFamily||"Inter, sans-serif",fontSize:n?.style?.base?.baseFontSize||"16px",color:n?.style?.base?.baseTextColor||"#000"},children:`${r?.(a.LanguageKeys.setting)} > ${a.getBrowserName()} > ${r?.(a.LanguageKeys.enableCameraPermissions)}`})]})})})})}function F({setShowDrawer:s,config:n,loader:o}){const[i,c]=t.useState({disabled:!1,message:""}),[l,u]=t.useState(!0),d=t.useRef(null),m=t.useCallback(async()=>{const e=await a.checkCameraPermission();c(e),u(!1)},[]);return t.useEffect(()=>{m()},[]),l?e.jsx(a.LoadingScreen,{url:o}):i?.disabled?e.jsx(N,{config:n,message:i?.message}):e.jsx(r,{audio:!1,ref:d,screenshotQuality:1,videoConstraints:a.videoConstraints,mirrored:!0,onUserMedia:()=>s?.(!0),screenshotFormat:"image/jpeg",style:{position:"relative",top:0,bottom:0,zIndex:0,width:"100%",height:"100%",objectFit:"cover"}})}function E({link:s,onReady:n,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:a.videoPoster};return t.useEffect(()=>{if(!i.current&&s&&o?.current){const e=c(o.current,{...l});e.ready(()=>{i.current=e;const t={...l,sources:[{src:s,type:"application/x-mpegURL"}]};e.autoplay(t.autoplay),e.src(t.sources),n?.(e)})}},[s,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 D({scanFailsError:s,serverAtCapacity:n=!1,onNext:r,gender:c,setScanUniqueKey:l,resolvedConfig:u,setIsVideoUploaded:d}){const{translate:m}=t.useContext(a.LanguageContext)||{},[f,h]=t.useState(!1),g=()=>{h(!f)};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex 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.jsx("div",{className:"w-full max-w-[28rem] mx-auto pt-[1rem] px-[1rem]",children:e.jsx(a.Header,{noTitle:!0,resolvedConfig:u})}),e.jsxs("div",{className:"flex-1",children:[s&&e.jsxs("div",{className:"px-[1rem]",children:[e.jsx("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:m?.(a.LanguageKeys.issueWithScan)}),e.jsx("p",{style:{fontFamily:u?.style?.base?.baseFontFamily||"Inter, sans-serif",fontSize:u?.style?.base?.baseFontSize||"16px",color:u?.style?.base?.baseTextColor||"#1E1E1E"},children:m?.(a.LanguageKeys.reason)}),e.jsx("p",{style:{fontFamily:u?.style?.base?.baseFontFamily||"Inter, sans-serif",fontSize:u?.style?.base?.baseFontSize||"16px",color:u?.style?.base?.baseTextColor||"#1E1E1E"},children:a.handleErrorMessage(s)}),e.jsx("img",{className:"my-[0.5rem] aspect-[2/1.4] w-full object-cover",onClick:g,src:a.VIDEO_POSTER_GENDER_BASED[c],alt:"icon"})]}),n&&e.jsxs("div",{className:"p-[1rem] text-center",children:[e.jsx("h3",{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:m?.(a.LanguageKeys.serverAtCapacity)}),e.jsx("p",{className:"text-base mt-[0.5rem]",style:{fontFamily:u?.style?.base?.baseFontFamily||"Inter, sans-serif",fontSize:u?.style?.base?.baseFontSize||"16px",color:u?.style?.base?.baseTextColor||"#1E1E1E"},children:m?.(a.LanguageKeys.serverAtCapacityDescription)})]})]}),s&&e.jsx("div",{className:"p-[1rem] flex gap-[0.5rem]",children:e.jsx(a.SpecificButton,{disabled:!1,buttonText:m?.(a.LanguageKeys.scanAgain),className:"!shadow-none",buttonFunc:()=>{r?r?.():l(a.generateUuid()),d(!1)},resolvedConfig:u})})]}),f&&e.jsxs(i.Dialog,{className:"w-screen h-screen video-modal",onClose:g,open:f,children:[e.jsx("div",{className:"flex justifyEnd ",children:e.jsx("span",{className:"closeBtn",onClick:g,children:e.jsx(o.Close,{className:"absolute right-[8px] top-[8px] text-white z-[9]"})})}),e.jsx("div",{className:"aspect-video object-cover rounded-[20px] ",children:e.jsx(E,{link:c?a.GENDER[c].PRE_LINK:a.GENDER.male.PRE_LINK,wrapperClassName:"w-screen h-screen fixed top-[0] left-[0]"})})]})]})}function k({scanId:n,userDetails:r,config:o,isFaceScan:c,isVideoUploadedCorrect:l,isMeasurementAvailable:u,onScanSuccess:d,isSuccess:m}){const{gender:f,shopDomain:h,heightInCm:g,deviceFocalLength:p,userName:x,email:y,scanType:S}=r,v=[a.CLOTHING_CUSTOM_SCAN,a.CLOTHING_BANNER_SCAN,a.CLOTHING_CUSTOM_FIT_SCAN].includes(S),[b,C]=t.useState(!0),w=t.useCallback(async()=>{try{v&&await a.swan.auth.addUser({scanId:n,email:y,name:x,gender:f,height:g}),s.posthog.capture(h,{scanID:n,email:y,height:g,focalLength:p,clothesFit:"0",gender:f})}catch(e){console.log(e)}},[v]),{translate:j}=t.useContext(a.LanguageContext)||{};t.useEffect(()=>{l&&w()},[l]);const N=m||(c?u&&l:l||u);return e.jsx(i.Box,{className:"flex h-full w-full flex-col ",children:e.jsxs("div",{className:"h-full w-full flex-col items-center justify-center flex",children:[e.jsx(F,{loader:o?.loader,setShowDrawer:C}),e.jsx(i.Drawer,{open:b,onClose:(e,t)=>{},className:"camera-drawer",anchor:"bottom",children:e.jsx("div",{className:"max-w-[28rem] mx-auto w-full h-full flex text-center flex-col justify-between items-center bg-primary rounded-t-[30px] p-[1rem]",style:{background:o?.style?.base?.backgroundColor},children:e.jsxs("div",{className:"w-full h-full flex flex-col",children:[e.jsx(a.Header,{title:j?.(a.LanguageKeys.measurementsBeingTaken),resolvedConfig:o}),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===a.GenderType.Male?a.maleMeasurementProgress:a.measurementProgress,type:"video/mp4"})})}),N&&e.jsx(a.SpecificButton,{resolvedConfig:o,className:"!w-[180px] mx-auto",buttonText:j?.(a.LanguageKeys.next),buttonFunc:d&&d})]})})})]})})}const I=()=>{const{userDetails:s,config:n,onRetry:r,isError:o,isSuccess:c,onScanSuccess:l,gender:u,scanUniqueKey:d,scanFailsError:m,setScanUniqueKey:f,setIsVideoUploaded:h,isMeasurementAvailable:g,isVideoUploadedCorrect:p,loading:x,showDeniedModal:y,uploadLoading:S,setStartGyro:v,handleFileUpload:b,setUploadLoading:C,setScanFailsError:w,setScanStartTime:E,handleShowStreamCamera:I}=t.useContext(a.ParamsContext),{setPreferredLanguage:T}=t.useContext(a.LanguageContext)||{},L=a.useLocalConfig(n);return t.useEffect(()=>{T?.(L?.language)},[L]),o?e.jsxs(e.Fragment,{children:[e.jsx(F,{}),e.jsx(i.Drawer,{anchor:"bottom",open:!0,className:"camera-drawer",onClose:(e,t)=>{},children:e.jsx(D,{scanFailsError:m||o,onNext:()=>{},setScanUniqueKey:f,gender:u,resolvedConfig:L,setIsVideoUploaded:h})})]}):c?e.jsx(k,{isFaceScan:!1,scanId:d,isMeasurementAvailable:g,userDetails:s,isVideoUploadedCorrect:p,config:L,isSuccess:c}):x?e.jsx("div",{className:"flex top-0 !mt-0 left-0 z-[999] bg-opacity-80 bg-[#1b1b1b] absolute justify-center items-center w-full h-full",children:e.jsx(a.LoadingScreen,{url:L?.loader})}):y.disabled?e.jsx(N,{}):S||m?!S&&!g||m?e.jsxs(e.Fragment,{children:[e.jsx(F,{}),e.jsx(i.Drawer,{anchor:"bottom",open:!0,className:"camera-drawer",onClose:(e,t)=>{},children:e.jsx(D,{scanFailsError:m,onNext:()=>{r?.(),I()},setScanUniqueKey:f,gender:u,resolvedConfig:L,setIsVideoUploaded:h})})]}):e.jsx(k,{isFaceScan:!1,scanId:d,isMeasurementAvailable:g,userDetails:s,onScanSuccess:l,isVideoUploadedCorrect:p,config:L}):e.jsx(j,{config:L,scanID:d,userDetails:s,setIsVideoUploaded:h,setScanFailsError:w,setScanStartTime:E,setScanUniqueKey:f})};exports.BodyScan=({userDetails:n,config:r,onRetry:o,onScanError:i,isError:c,isSuccess:l,onScanSuccess:u})=>{const{gender:d,scanType:m,shopDomain:h,heightInCm:g,email:p,deviceFocalLength:x,deviceModelName:y,callbackUrl:S}=n,[v,b]=t.useState(!1),[C,w]=t.useState(!1),[j,N]=t.useState(!1),[F,E]=t.useState({disabled:!1,message:""}),[D,k]=t.useState(""),[T,L]=t.useState(!1),[M,A]=t.useState(!0),[_,P]=t.useState(!1),[U,$]=t.useState(""),[z,R]=t.useState(a.getCurrentTimeInSeconds()),{gyroData:K}=function(e){const[s,a]=t.useState([]),[n,r]=t.useState(!1),o=t.useCallback(e=>{try{const{alpha:t,beta:s,gamma:n}=e;a(e=>[...e,{alpha:t?.toString()||void 0,beta:s?.toString()||void 0,gamma:n?.toString()||void 0,timestamp:(new Date).toISOString()}])}catch(e){console.log(e)}},[]),i=t.useCallback(async()=>{const e=DeviceOrientationEvent;if(void 0!==e&&"function"==typeof e.requestPermission)try{"granted"===await e.requestPermission()?r(!0):console.warn("Device orientation permission denied.")}catch(e){console.error("Error requesting device orientation permission:",e)}else r(!0)},[]);return t.useEffect(()=>(e&&n?window.addEventListener("deviceorientation",o):a([]),()=>{window.removeEventListener("deviceorientation",o)}),[e,n,o]),t.useEffect(()=>{e&&i()},[e,i]),{gyroData:s}}(_),O=t.useCallback(()=>{$(a.generateUuid()),k(""),b(!1),L(!1)},[]),q=e=>{i({...e,message:a.handleErrorMessage(e)}),B(),N(!1),k(e),w(!1),a.handleScanTimeCapture({eventName:`${h}/measurement_failed/fit-view`,scanID:U,status:"failed",email:p,message:a.handleErrorMessage(e)}),z&&a.handleScanTimeCapture({eventName:`${h}/scan_completion_time`,scanID:U,status:"failed",completionTime:a.getCurrentTimeInSeconds()-z,email:p})},B=()=>{R(null),$("")},V=t.useCallback(async e=>{if(e&&"success"===e?.scanStatus&&"intermediate"===e?.resultType&&200===e?.code)return void a.handleScanTimeCapture({eventName:`${h}/measurement_success/intermediate`,scanID:U,status:"success",email:p});B();const t=U;N(!0),a.handleScanTimeCapture({eventName:`${h}/measurement_success/fit-view`,scanID:t,status:"success",email:p}),z&&a.handleScanTimeCapture({eventName:`${h}/scan_completion_time`,scanID:t,status:"success",completionTime:a.getCurrentTimeInSeconds()-z,email:p})},[m,h,U]),W=e=>{N(!1),k(""),w(!1),a.swan.measurement.handleMeasurementSocket({scanId:e||U,onOpen:()=>{a.handleWebSocketCapture({eventName:`${h}/webSocket`,scanID:U,connection:"open",type:"measurement_recommendation",email:p})},onClose:()=>a.handleWebSocketCapture({eventName:`${h}/webSocket`,scanID:U,connection:"close",type:"measurement_recommendation",email:p}),onError:e=>{q(e),a.handleWebSocketCapture({eventName:`${h}/webSocket`,scanID:U,connection:"error",type:"measurement_recommendation",email:p})},onSuccess:e=>{a.handleWebSocketCapture({eventName:`${h}/webSocket`,scanID:U,connection:"success",type:"measurement_recommendation",email:p}),V(e)}})},H=t.useCallback(async e=>{const t=a.createObjectMetadataArray({gender:d,focal_length:`${x}`,height:`${g}`,customer_store_url:h,clothes_fit:"0",scan_type:m,callback_url:S||"https://example.com/webhook"});a.handleScanTimeCapture({eventName:`${h}/body_scan_meta_data`,scanID:U,email:p,data:JSON.stringify(t)});try{await a.swan.fileUpload.uploadFileFrontend({file:e,arrayMetaData:t,scanId:U,email:p}),await a.swan.fileUpload.setDeviceInfo({model:y,detection:"manual",gyro:K,scanId:U}),console.log("video successfully uploaded"),L(!1),a.handleScanTimeCapture({eventName:`${h}/scan_success`,scanID:U,status:"success",email:p,data:JSON.stringify(t)}),a.handleScanTimeCapture({eventName:"scan finished",scanID:U,status:"success",email:p}),R(a.getCurrentTimeInSeconds()),setTimeout(()=>{L(!0)},3e3)}catch(e){a.handleScanTimeCapture({eventName:"scan finished",scanID:U,status:"failed",email:p,message:a.handleErrorMessage(e)}),a.handleScanTimeCapture({eventName:`${h}/scan_failed`,scanID:U,status:"failed",email:p,message:a.handleErrorMessage(e),data:JSON.stringify(t)}),k(a.handleErrorMessage(e)),L(!1),console.log(e,"video upload failed")}finally{P(!1)}},[U,K]),G=t.useCallback(async e=>{try{const t=await a.swan.measurement.getMeasurementResult(e),s=t?.data?.isMeasured,n=z||a.getCurrentTimeInSeconds(),r=a.getCurrentTimeInSeconds(),o=300;if(A(!1),!1===s)return B(),void $(a.generateUuid());b(!0),!0===s?await V(null):null===s&&n>r+o?q(t?.data?.error):W(e)}catch(e){console.log(e),B(),$(a.generateUuid()),b(!1)}},[q,V,$]),J=t.useCallback(async()=>{if(+g<152.4||+g>213.36)return void i({message:"Height must be between 152.4cm (5ft) and 213.36cm (7ft)"});const e=await a.checkCameraPermission();if(e.disabled)a.handleScanTimeCapture({eventName:`${h}/camera_activation`,scanID:U,status:"failed",email:p}),A(!1);else{U?G(U):A(!1),a.handleScanTimeCapture({eventName:`${h}/camera_activation`,scanID:U,status:"success",email:p})}E(e),k(""),L(!1)},[G,p,U,$,h]);return t.useEffect(()=>{s.init(a.posthogPublicKey,{api_host:a.posthogPublicHost}),s.capture("$pageview")},[]),t.useEffect(()=>{c||l||h&&J()},[h,g,c,l]),t.useEffect(()=>{c||l||T&&h&&U&&W()},[T,h,U,c,l]),e.jsx(a.LanguageContextProvider,{children:e.jsx(f,{children:e.jsx(a.ParamsContext.Provider,{value:{userDetails:n,config:r,onRetry:o,onScanError:i,isError:c,isSuccess:l,onScanSuccess:u,gender:d,scanUniqueKey:U,scanFailsError:D,setScanUniqueKey:$,setIsVideoUploaded:L,isMeasurementAvailable:j,isVideoUploadedCorrect:C,loading:M,showDeniedModal:F,uploadLoading:v,setStartGyro:P,handleFileUpload:H,setUploadLoading:b,handleShowStreamCamera:O,setScanFailsError:k,setScanStartTime:R},children:e.jsx(I,{})})})})};
2
- //# sourceMappingURL=BodyScan-97yio9Oh.js.map
1
+ "use strict";var e=require("react/jsx-runtime"),t=require("react"),s=require("posthog-js"),a=require("./LoadingScreen-CHUc0ves.js"),n=require("clsx"),r=require("react-webcam"),o=require("@mui/icons-material"),i=require("@mui/material"),c=require("video.js");const l="DESKTOP",u="TAB",d="MOBILE",m=t.createContext(void 0);function f({children:s}){const[a,n]=t.useState([window?.innerWidth,window?.innerHeight]),[r,o]=t.useState(!1),i=()=>{n([window?.innerWidth,window?.innerHeight])};t.useEffect(()=>{i()},[]),t.useLayoutEffect(()=>(window.addEventListener("resize",i),()=>window.removeEventListener("resize",i)),[i]);let c=l;a[0]>768&&a[0]<1024&&(c=u),a[0]<768&&(c=d);const f=t.useMemo(()=>({size:a,setSize:n,clearInputs:r,setClearInputs:o,media:c}),[a,r,c]);return e.jsx(m.Provider,{value:f,children:s})}var h=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 g=t.memo(function({angle:s,countdown:r,isScanning:o,isInTargetRange:i,stabilityScore:c,children:l,config:u}){const{translate:d}=t.useContext(a.LanguageContext)||{},m=t.useCallback(()=>s<80?Math.max(0,Math.min(100,10*(s-60))):s>95?Math.max(0,Math.min(100,10*(105-s))):100,[s]),f=t.useMemo(()=>{if(o)return u?.style?.angleDetector?.successAngleBackground||"#4f46e5";const e=m();if(0===e)return u?.style?.angleDetector?.successAngleLowBackground||"#ffffff";if(100===e)return u?.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]),g=t.useCallback((e,t)=>t>70?e?`text-[${u?.style?.angleDetector?.successAngleTextLightColor}]/70`:`text-[${u?.style?.angleDetector?.successAngleTextLightColor}]`:e?`text-[${u?.style?.angleDetector?.successAngleTextLightColor}]/40`:`text-[${u?.style?.angleDetector?.successAngleTextDarkColor}]/70`,[]),p=t.useCallback((e=!1)=>{const t=m();return o?`text-[${u?.style?.angleDetector?.successAngleTextLightColor}]`:g(e,t)},[o,m]),x=t.useCallback((e,t)=>t>70||e?u?.style?.angleDetector?.successAngleTextLightColor:u?.style?.angleDetector?.successAngleTextDarkColor,[]),y=t.useCallback((e=!1)=>{const t=m();return o?u?.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 w-screen flex-col items-center h-[var(--real-vh)] overflow-hidden touch-none justify-center transition-all duration-300 max-w-[28rem] mx-auto",style:{backgroundColor:f},children:[e.jsx("div",{className:"flex justify-start fixed top-[.5rem] max-w-[28rem] mx-auto w-full px-[1rem]",children:e.jsx("div",{className:"flex justify-start ",children:e.jsx(a.Header,{noTitle:!0,resolvedConfig:u})})}),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:u?.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] ",i?"bg-[#fff]/20 border-[#fff]":"bg-[#fff]/10 border-[#fff]"),style:{transform:`translateY(${3*(90-s)}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]",p()),style:{color:y()},children:[e.jsx(h,{size:30}),e.jsxs("p",{style:{fontFamily:u?.style?.base?.baseFontFamily||"Inter, sans-serif"},children:[" ",d?.(a.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",p()),style:{fontFamily:u?.style?.base?.baseFontFamily||"Inter, sans-serif",color:y()},children:d?.(a.LanguageKeys.leavePhone)})}),i&&null===S&&!o&&e.jsx("div",{className:"absolute bottom-[8rem] w-[12rem]",children:e.jsx("div",{className:`h-[.375rem] w-full bg-[${y()}]/20 rounded-[9999px] overflow-hidden`,style:{backgroundColor:`${y()}33`},children:e.jsx("div",{className:`h-full bg-[${y()}]/70 transition-all duration-300 rounded-[9999px]`,style:{width:`${s}%`,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",p()),style:{color:y()},children:[Math.round(s),"°"]})}),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",p()),style:{fontFamily:u?.style?.base?.baseFontFamily||"Inter, sans-serif",color:y()},children:d?.(a.LanguageKeys.placePhoneUpright)})})]})});function p({handleShowStreamCamera:s,loadingCam:n,handleUserMedia:i,handlePause:c,pause:l,recordingStarted:u,startSendingVideoFrames:f,showPause:h,webcamRef:g,resetDetector:p,config:x}){const{media:y}=t.useContext(m)||{},{translate:S}=t.useContext(a.LanguageContext)||{};return e.jsxs("div",{className:"App w-screen h-[100vh] relative ",children:[e.jsx("span",{onClick:()=>{s(),p()},className:"fixed right-[20px] top-[20px] z-[999]",children:e.jsx(o.Close,{className:"text-[#fff]"})}),e.jsx("div",{className:"w-full h-full overflow-hidden ",children:y===d&&e.jsx(r,{audio:!1,ref:g,screenshotQuality:1,videoConstraints:a.videoConstraints,mirrored:!0,screenshotFormat:"image/jpeg",onUserMedia:i,style:{position:"fixed",top:0,bottom:0,zIndex:0,width:"100%",height:"100%",objectFit:"cover"}})}),e.jsxs("div",{className:"fixed bottom-[30px] w-full z-[999] flex flex-col gap-4 items-center justify-center",children:[h&&e.jsx(a.SpecificButton,{className:"!w-[180px] !h-[40px] !py-[0] mx-auto ",prefix:a.pauseIcon,buttonText:S?.(a.LanguageKeys.pause),buttonFunc:c,resolvedConfig:x,btnSecondary:!0}),l?e.jsx("div",{children:e.jsx(a.SpecificButton,{className:"!w-[180px] !h-[40px] !py-[0] mx-auto",buttonText:S?.(a.LanguageKeys.restart),buttonFunc:s,resolvedConfig:x,btnSecondary:!0})}):u?null:e.jsx(a.SpecificButton,{className:"!w-[180px] !h-[40px] !py-[0] mx-auto !bg-[#ffffff] !text-[#000000] "+(n?"!opacity-50":""),buttonText:S?.(a.LanguageKeys.startScan),buttonFunc:f,disabled:n,resolvedConfig:x})]}),e.jsx("audio",{id:"audioElement",crossOrigin:"anonymous",preload:"auto",style:{position:"absolute",zIndex:-99999},src:`${a.voiceOverAssetsPath}scanAudioInstructions/silence.mp3`})]})}let x=null,y=null,S=null;let v,b=null,C=null;var w=t.memo(function({setIsScanLocked:n,resetDetector:r,scanID:o,setIsVideoUploaded:i,setScanFailsError:c,setScanStartTime:l,setScanUniqueKey:u,userDetails:d,config:m}){const{gender:f,heightInCm:h,email:g,shopDomain:w}=d,j=t.useRef(null),N=t.useRef(null),[F,E]=t.useState([]),[D,k]=t.useState(!0),[I,T]=t.useState(!1),[L,M]=t.useState(!1),[A,_]=t.useState(!0),[P,U]=t.useState(!1),$=t.useRef(null),[z,R]=t.useState(""),[K,O]=t.useState([]),[q,B]=t.useState(""),[V,W]=t.useState(!1),[H,G]=t.useState(!1),[J,Q]=t.useState(!1),[Y,X]=t.useState([]),[Z,ee]=t.useState(!1),te=t.useRef(!0),{poseDetector:se}=function(){const[e,s]=t.useState(0),[a,n]=t.useState(0),[r,o]=t.useState(!1),i=t.useRef(0),c=t.useRef(0),l=t.useRef(!0);async function u(){if("undefined"==typeof window||"undefined"==typeof navigator)return!1;try{console.log("Starting TensorFlow preload...");const[e,t,s]=await Promise.all([Promise.resolve().then(function(){return require("./pose-detection.esm-BMyJE2Fw.js")}),import("@tensorflow/tfjs-core"),import("@tensorflow/tfjs-backend-webgl")]);S=e,await t.setBackend("webgl"),await t.ready(),console.log("TensorFlow backend ready (WebGL)");const a={runtime:"mediapipe",modelType:"full",solutionPath:"https://cdn.jsdelivr.net/npm/@mediapipe/pose"};try{y=await S.createDetector(S.SupportedModels.BlazePose,a),console.log("MediaPipe detector created successfully")}catch(e){console.warn("MediaPipe failed, falling back to TFJS runtime:",e),y=await S.createDetector(S.SupportedModels.BlazePose,{runtime:"tfjs",modelType:"full"}),console.log("TFJS detector created successfully")}return!0}catch(e){return console.error("Failed to load TensorFlow dependencies:",e),x=null,!1}}function d(e){return!(!e||0===e.length)&&22===e.filter(e=>e[2]>.7).length}return t.useEffect(()=>{if(l.current=!0,!y)return x||(x=u()),x.then(e=>{e&&l.current&&o(!0)}),()=>{l.current=!1};o(!0)},[]),t.useEffect(()=>{c.current=e,e>6&&i.current<2&&(n(e=>e+1),s(0))},[e]),t.useEffect(()=>{i.current=a},[a]),{poseDetector:async(e,t)=>{if(!y||!l.current||!t?.current?.video)return;const a=t.current.video;if(!(a.readyState<2))try{const t=await y.estimatePoses(a,{flipHorizontal:!1});if(!t||!t.length)return;const n=t[0].keypoints.slice(11).map(e=>[e.x>0&&e.x<720?e.x:-1,e.y>0&&e.y<1280?e.y:-1,e.score??0]);0!==i.current||d(n)||s(e=>e+1),1===i.current&&d(n)&&s(e=>e+1),2===i.current&&e()}catch(e){console.error("Pose detection error:",e)}},isLoaded:r,spinPhase:a,resetDetector:()=>{i.current=0,c.current=0,s(0),n(0)},retryLoading:async()=>{y||x||(x=u(),await x&&l.current&&o(!0))}}}(),ae=t.useRef(!0),ne=t.useRef(!1),[re,oe]=t.useState([]);let ie=0;const{setStartGyro:ce,handleFileUpload:le,setUploadLoading:ue}=t.useContext(a.ParamsContext),de=()=>{ne.current=!1,clearTimeout(v),$.current&&clearTimeout($.current),u(a.generateUuid()),c(""),ue?.(!1),E([]),k(!0),T(!1),M(!1),_(!0),U(!1),$.current=null,R(""),O([]),B(""),W(!V),ce(!1),a.speechService.stopAudio(),G(!1),Q(!1),ie=0,null!==N.current&&N.current.stop(),Y.forEach(e=>{N.current&&N.current.removeEventListener("dataavailable",e)}),X([]),te.current=!0,ee(!1),i(!1)},me=t.useCallback(()=>{setTimeout(()=>{k(!1)},1e3)},[]),fe=t.useCallback(()=>{a.rescanSupportCaptureEvent({eventName:`${w}/rescan`,email:g,scanID:o,height:h,gender:f,status:!1}),te.current=!1,de(),Ce()},[de,o,g]),he=t.useCallback(()=>{te.current=!1,Q(!0),ee(!1),$.current&&clearTimeout($.current),N.current&&N.current.pause(),a.speechService.stopAudio(),a.swan.poseDetection.disconnect(),ie=0,N.current&&N.current.stop(),Y.forEach(e=>{N.current&&N.current.removeEventListener("dataavailable",e)}),X([]),clearTimeout(v)},[N,Y,a.speechService,te]),ge=t.useCallback(async()=>{te.current=!0,await a.speechService.playAudio(`${a.voiceOverAssetsPath}SpotOn.mp3`),Q(!1),ee(!1),$.current&&clearTimeout($.current),T(!1)},[$,a.speechService]),pe=t.useCallback(async()=>{try{b=await a.swan.poseDetection.connect(),s.capture(`${w}/pose_detection_connected`,{scanID:o,email:g,id:b})}catch(e){console.log(e,"while connecting websocket")}},[o,w,g]),xe=t.useCallback(({data:e})=>{e&&e.size>0&&te.current&&(E(t=>t.concat(e)),!ne.current&&j.current&&(ne.current=!0,se(()=>{ge(),a.handleScanTimeCapture({eventName:`${w}/tensorFlow`,scanID:o,email:g,message:"recording stopped by tensorflow "})},j)))},[ge,a.handleScanTimeCapture,w,o,g,j]),ye=t.useCallback(async()=>{K.length>0&&te.current&&(await a.speechService.playAudio(a.voiceOverAssetsPath+K[K.length-1]),te.current&&(v=setTimeout(ye,2e3)))},[K,te]),Se=t.useCallback(()=>{N&&N.current&&N.current.stop(),T(!0);try{if(j&&j.current&&j.current.stream){const e={mimeType:re[0]};N.current=new MediaRecorder(j.current.stream,e),N.current.addEventListener("dataavailable",xe),X([...Y,xe]),N.current.start(1e3),_(!1)}}catch(e){console.log("error while using media recorder",e)}},[j,re,xe,Y]),ve=t.useCallback(async()=>{$.current&&clearTimeout($.current),Se(),te.current&&($.current=setTimeout(async()=>{te.current&&(await a.speechService.playAudio(`${a.voiceOverAssetsPath}SpotOn.mp3`),T(!1))},15e3)),M(!0),te.current&&await a.speechService.playAudio(`${a.voiceOverAssetsPath}Spin.mp3`)},[Se,te,a.speechService]),be=t.useCallback(({data:e})=>{e.size>0&&a.swan.poseDetection.connected()&&(a.swan.poseDetection.poseStatus(async e=>{if(e&&e.audio&&e.audio.length>0){const t=document.querySelector("#audioElement");!0===e.status&&e.sid===b?ie<2?(0===ie&&t?.paused&&await a.speechService.playAudio(a.voiceOverAssetsPath+e.audio),ie+=1):(B(e.audio),clearTimeout(v),a.swan.poseDetection.disconnect(),setTimeout(ve,1e3)):(ie=0,!t?.paused||C&&C?.audioName===e.audio?C?.audioName===e.audio&&t?.paused&&(C&&C.no_of_times_skipped>=C.skipCount?(C.no_of_times_skipped=0,a.speechService.playAudio(a.voiceOverAssetsPath+e.audio)):C&&(C.no_of_times_skipped+=1)):(C={skipCount:2,no_of_times_skipped:0,audioName:e.audio},a.speechService.playAudio(a.voiceOverAssetsPath+e.audio)))}}),j?.current&&null!==j.current.getScreenshot()&&a.swan.poseDetection.videoEmit({image:j.current.getScreenshot()||"",scanId:o}))},[j,o,a.swan,b,ie,ve,a.speechService]),Ce=t.useCallback(async()=>{U(!0),ce(!0),ae.current&&(ae.current=!1,a.handleScanTimeCapture({eventName:"scan started",scanID:o,status:"success",email:g})),l(a.getCurrentTimeInSeconds()),k(!0),te.current&&await a.speechService.playAudio(`${a.voiceOverAssetsPath}StartScan.mp3`),te.current&&await a.speechService.playAudio(`${a.voiceOverAssetsPath}LiftArmsAndHoldAtHip.mp3`),te.current&&(U(!1),T(!0),G(!0),ee(!0),me());try{if(j&&j.current&&j.current.stream&&te.current){const e={mimeType:re[0]};te.current&&(N.current=new MediaRecorder(j.current.stream,e)),te.current&&N.current&&N.current.addEventListener("dataavailable",be),X([...Y,be]),N.current&&N.current.start(1e3),_(!1),te.current&&(v=setTimeout(ye,2e3))}}catch(e){console.log("error ----------",e)}},[j,re,be,Y,ye,te]);return t.useEffect(()=>(w&&(n(!0),pe()),()=>{b&&(a.swan.poseDetection.disconnect(),s.capture(`${w}/pose_detection_disconnected`,{scanID:o,email:g,id:b})),Y.forEach(e=>{N?.current?.removeEventListener("dataavailable",e)})}),[V,w]),t.useEffect(()=>{K.push(z)},[z]),t.useEffect(()=>{O([])},[q]),t.useEffect(()=>{const e=F.length&&F.length>0;A||!e||I||!te.current||J||N&&N.current&&(I||(N.current.stop(),_(!0)))},[A,I,F,J]),t.useEffect(()=>{const e=F.length&&F.length>0;if(A||!e||I)console.log("No video found to upload");else if(N&&N.current&&te.current&&!J&&!I){const e=new File(F,`${o}.webm`,{type:"video/webm"});ue?.(!0),c(""),le?.(e)}},[A,I,F,J,N,te]),t.useEffect(()=>{if("undefined"!=typeof MediaRecorder){const e=a.videoTypes.filter(e=>MediaRecorder.isTypeSupported(e));oe(e)}},[]),t.useEffect(()=>{de()},[]),e.jsx(p,{resetDetector:r,handleShowStreamCamera:de,loadingCam:D,handlePause:he,showRestart:H,pause:J,handleReScan:fe,recordingStarted:I,isScanning:P,startSendingVideoFrames:Ce,faceDone:L,stopRecording:ge,showPause:Z,webcamRef:j,handleUserMedia:me,config:m})});function j({scanID:s,userDetails:a,setIsVideoUploaded:n,setScanFailsError:r,setScanStartTime:o,setScanUniqueKey:i,config:c}){const[l,u]=t.useState(90),[d,m]=t.useState(0),[f,h]=t.useState(null),[p,x]=t.useState(!1),[y,S]=t.useState(0),v=t.useRef([]),[b,C]=t.useState(!1),j=l-d,N=j>=80&&j<=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)),u(t)}},t=async()=>{const t=DeviceOrientationEvent;if(t&&"function"==typeof t.requestPermission)try{"granted"===await t.requestPermission()&&window.addEventListener("deviceorientation",e)}catch(e){console.error("Permission error",e)}else window.addEventListener("deviceorientation",e);return()=>{e&&window.removeEventListener("deviceorientation",e)}};document.addEventListener("click",t,{once:!0})}},[]),t.useEffect(()=>{if(v.current=[...v.current.slice(-4),j],v.current.length>=5){const e=Math.max(...v.current)-Math.min(...v.current);S(N&&e<2?e=>Math.min(100,e+10):e=>Math.max(0,e-20))}N||null===f&&!p||E()},[j,N,f,p]),t.useEffect(()=>{y>=100&&null===f&&!p&&F(),y<50&&null!==f&&E()},[y,f,p]);const F=()=>{h(3);const e=setInterval(()=>{h(t=>null===t||t<=1?(clearInterval(e),x(!0),null):t-1)},1e3)},E=()=>{h(null),b||x(!1)};return e.jsx(g,{angle:j,countdown:f,isScanning:p,isInTargetRange:N,stabilityScore:y,config:c,children:p&&e.jsx(w,{setIsScanLocked:C,resetDetector:()=>{u(90),m(0),h(null),x(!1),S(0),C(!1),v.current=[]},scanID:s,userDetails:a,setIsVideoUploaded:n,setScanFailsError:r,setScanStartTime:o,setScanUniqueKey:i,config:c})})}function N({message:s,config:n}){const{translate:r}=t.useContext(a.LanguageContext)||{};return e.jsx(i.Dialog,{open:!0,className:"confirm-modal",children:e.jsx("div",{className:"modal-main",children:e.jsx("div",{className:"text-center",children:s?e.jsxs(e.Fragment,{children:[e.jsx("h2",{style:{fontFamily:n?.style?.heading?.headingFontFamily||"SeriouslyNostalgic Fn",fontSize:n?.style?.heading?.headingFontSize||"32px",color:n?.style?.heading?.headingColor||"#000",fontWeight:n?.style?.heading?.headingFontWeight||"normal"},children:r?.(a.LanguageKeys.cameraAlreadyInUse)}),e.jsx("p",{className:"mt-[0.5rem] text-sm",style:{fontFamily:n?.style?.base?.baseFontFamily||"Inter, sans-serif",fontSize:n?.style?.base?.baseFontSize||"16px",color:n?.style?.base?.baseTextColor||"#000"},children:r?.(a.LanguageKeys.tryClosingBrowser)})]}):e.jsxs(e.Fragment,{children:[e.jsx("h2",{style:{fontFamily:n?.style?.heading?.headingFontFamily||"SeriouslyNostalgic Fn",fontSize:n?.style?.heading?.headingFontSize||"32px",color:n?.style?.heading?.headingColor||"#000",fontWeight:n?.style?.heading?.headingFontWeight||"normal"},children:r?.(a.LanguageKeys.checkCameraSettings)}),e.jsx("p",{className:"mt-[0.5rem] text-sm",style:{fontFamily:n?.style?.base?.baseFontFamily||"Inter, sans-serif",fontSize:n?.style?.base?.baseFontSize||"16px",color:n?.style?.base?.baseTextColor||"#000"},children:`${r?.(a.LanguageKeys.setting)} > ${a.getBrowserName()} > ${r?.(a.LanguageKeys.enableCameraPermissions)}`})]})})})})}function F({setShowDrawer:s,config:n,loader:o}){const[i,c]=t.useState({disabled:!1,message:""}),[l,u]=t.useState(!0),d=t.useRef(null),m=t.useCallback(async()=>{const e=await a.checkCameraPermission();c(e),u(!1)},[]);return t.useEffect(()=>{m()},[]),l?e.jsx(a.LoadingScreen,{url:o}):i?.disabled?e.jsx(N,{config:n,message:i?.message}):e.jsx(r,{audio:!1,ref:d,screenshotQuality:1,videoConstraints:a.videoConstraints,mirrored:!0,onUserMedia:()=>s?.(!0),screenshotFormat:"image/jpeg",style:{position:"relative",top:0,bottom:0,zIndex:0,width:"100%",height:"100%",objectFit:"cover"}})}function E({link:s,onReady:n,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:a.videoPoster};return t.useEffect(()=>{if(!i.current&&s&&o?.current){const e=c(o.current,{...l});e.ready(()=>{i.current=e;const t={...l,sources:[{src:s,type:"application/x-mpegURL"}]};e.autoplay(t.autoplay),e.src(t.sources),n?.(e)})}},[s,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 D({scanFailsError:s,serverAtCapacity:n=!1,onNext:r,gender:c,setScanUniqueKey:l,resolvedConfig:u,setIsVideoUploaded:d}){const{translate:m}=t.useContext(a.LanguageContext)||{},[f,h]=t.useState(!1),g=()=>{h(!f)};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex 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.jsx("div",{className:"w-full max-w-[28rem] mx-auto pt-[1rem] px-[1rem]",children:e.jsx(a.Header,{noTitle:!0,resolvedConfig:u})}),e.jsxs("div",{className:"flex-1",children:[s&&e.jsxs("div",{className:"px-[1rem]",children:[e.jsx("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:m?.(a.LanguageKeys.issueWithScan)}),e.jsx("p",{style:{fontFamily:u?.style?.base?.baseFontFamily||"Inter, sans-serif",fontSize:u?.style?.base?.baseFontSize||"16px",color:u?.style?.base?.baseTextColor||"#1E1E1E"},children:m?.(a.LanguageKeys.reason)}),e.jsx("p",{style:{fontFamily:u?.style?.base?.baseFontFamily||"Inter, sans-serif",fontSize:u?.style?.base?.baseFontSize||"16px",color:u?.style?.base?.baseTextColor||"#1E1E1E"},children:a.handleErrorMessage(s)}),e.jsx("img",{className:"my-[0.5rem] aspect-[2/1.4] w-full object-cover",onClick:g,src:a.VIDEO_POSTER_GENDER_BASED[c],alt:"icon"})]}),n&&e.jsxs("div",{className:"p-[1rem] text-center",children:[e.jsx("h3",{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:m?.(a.LanguageKeys.serverAtCapacity)}),e.jsx("p",{className:"text-base mt-[0.5rem]",style:{fontFamily:u?.style?.base?.baseFontFamily||"Inter, sans-serif",fontSize:u?.style?.base?.baseFontSize||"16px",color:u?.style?.base?.baseTextColor||"#1E1E1E"},children:m?.(a.LanguageKeys.serverAtCapacityDescription)})]})]}),s&&e.jsx("div",{className:"p-[1rem] flex gap-[0.5rem]",children:e.jsx(a.SpecificButton,{disabled:!1,buttonText:m?.(a.LanguageKeys.scanAgain),className:"!shadow-none",buttonFunc:()=>{r?r?.():l(a.generateUuid()),d(!1)},resolvedConfig:u})})]}),f&&e.jsxs(i.Dialog,{className:"w-screen h-screen video-modal",onClose:g,open:f,children:[e.jsx("div",{className:"flex justifyEnd ",children:e.jsx("span",{className:"closeBtn",onClick:g,children:e.jsx(o.Close,{className:"absolute right-[8px] top-[8px] text-white z-[9]"})})}),e.jsx("div",{className:"aspect-video object-cover rounded-[20px] ",children:e.jsx(E,{link:c?a.GENDER[c].PRE_LINK:a.GENDER.male.PRE_LINK,wrapperClassName:"w-screen h-screen fixed top-[0] left-[0]"})})]})]})}function k({scanId:n,userDetails:r,config:o,isFaceScan:c,isVideoUploadedCorrect:l,isMeasurementAvailable:u,onScanSuccess:d,isSuccess:m}){const{gender:f,shopDomain:h,heightInCm:g,deviceFocalLength:p,userName:x,email:y,scanType:S}=r,v=[a.CLOTHING_CUSTOM_SCAN,a.CLOTHING_BANNER_SCAN,a.CLOTHING_CUSTOM_FIT_SCAN].includes(S),[b,C]=t.useState(!0),w=t.useCallback(async()=>{try{v&&await a.swan.auth.addUser({scanId:n,email:y,name:x,gender:f,height:g}),s.posthog.capture(h,{scanID:n,email:y,height:g,focalLength:p,clothesFit:"0",gender:f})}catch(e){console.log(e)}},[v]),{translate:j}=t.useContext(a.LanguageContext)||{};t.useEffect(()=>{l&&w()},[l]);const N=m||(c?u&&l:l||u);return e.jsx(i.Box,{className:"flex h-full w-full flex-col ",children:e.jsxs("div",{className:"h-full w-full flex-col items-center justify-center flex",children:[e.jsx(F,{loader:o?.loader,setShowDrawer:C}),e.jsx(i.Drawer,{open:b,onClose:(e,t)=>{},className:"camera-drawer",anchor:"bottom",children:e.jsx("div",{className:"max-w-[28rem] mx-auto w-full h-full flex text-center flex-col justify-between items-center bg-primary rounded-t-[30px] p-[1rem]",style:{background:o?.style?.base?.backgroundColor},children:e.jsxs("div",{className:"w-full h-full flex flex-col",children:[e.jsx(a.Header,{title:j?.(a.LanguageKeys.measurementsBeingTaken),resolvedConfig:o}),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===a.GenderType.Male?a.maleMeasurementProgress:a.measurementProgress,type:"video/mp4"})})}),N&&e.jsx(a.SpecificButton,{resolvedConfig:o,className:"!w-[180px] mx-auto",buttonText:j?.(a.LanguageKeys.next),buttonFunc:d&&d})]})})})]})})}const I=()=>{const{userDetails:s,config:n,onRetry:r,isError:o,isSuccess:c,onScanSuccess:l,gender:u,scanUniqueKey:d,scanFailsError:m,setScanUniqueKey:f,setIsVideoUploaded:h,isMeasurementAvailable:g,isVideoUploadedCorrect:p,loading:x,showDeniedModal:y,uploadLoading:S,setStartGyro:v,handleFileUpload:b,setUploadLoading:C,setScanFailsError:w,setScanStartTime:E,handleShowStreamCamera:I}=t.useContext(a.ParamsContext),{setPreferredLanguage:T}=t.useContext(a.LanguageContext)||{},L=a.useLocalConfig(n);return t.useEffect(()=>{T?.(L?.language)},[L]),o?e.jsxs(e.Fragment,{children:[e.jsx(F,{}),e.jsx(i.Drawer,{anchor:"bottom",open:!0,className:"camera-drawer",onClose:(e,t)=>{},children:e.jsx(D,{scanFailsError:m||o,onNext:()=>{},setScanUniqueKey:f,gender:u,resolvedConfig:L,setIsVideoUploaded:h})})]}):c?e.jsx(k,{isFaceScan:!1,scanId:d,isMeasurementAvailable:g,userDetails:s,isVideoUploadedCorrect:p,config:L,isSuccess:c}):x?e.jsx("div",{className:"flex top-0 !mt-0 left-0 z-[999] bg-opacity-80 bg-[#1b1b1b] absolute justify-center items-center w-full h-full",children:e.jsx(a.LoadingScreen,{url:L?.loader})}):y.disabled?e.jsx(N,{}):S||m?!S&&!g||m?e.jsxs(e.Fragment,{children:[e.jsx(F,{}),e.jsx(i.Drawer,{anchor:"bottom",open:!0,className:"camera-drawer",onClose:(e,t)=>{},children:e.jsx(D,{scanFailsError:m,onNext:()=>{r?.(),I()},setScanUniqueKey:f,gender:u,resolvedConfig:L,setIsVideoUploaded:h})})]}):e.jsx(k,{isFaceScan:!1,scanId:d,isMeasurementAvailable:g,userDetails:s,onScanSuccess:l,isVideoUploadedCorrect:p,config:L}):e.jsx(j,{config:L,scanID:d,userDetails:s,setIsVideoUploaded:h,setScanFailsError:w,setScanStartTime:E,setScanUniqueKey:f})};exports.BodyScan=({userDetails:n,config:r,onRetry:o,onScanError:i,isError:c,isSuccess:l,onScanSuccess:u})=>{const{gender:d,scanType:m,shopDomain:h,heightInCm:g,email:p,deviceFocalLength:x,deviceModelName:y,callbackUrl:S}=n,[v,b]=t.useState(!1),[C,w]=t.useState(!1),[j,N]=t.useState(!1),[F,E]=t.useState({disabled:!1,message:""}),[D,k]=t.useState(""),[T,L]=t.useState(!1),[M,A]=t.useState(!0),[_,P]=t.useState(!1),[U,$]=t.useState(""),[z,R]=t.useState(a.getCurrentTimeInSeconds()),{gyroData:K}=function(e){const[s,a]=t.useState([]),[n,r]=t.useState(!1),o=t.useCallback(e=>{try{const{alpha:t,beta:s,gamma:n}=e;a(e=>[...e,{alpha:t?.toString()||void 0,beta:s?.toString()||void 0,gamma:n?.toString()||void 0,timestamp:(new Date).toISOString()}])}catch(e){console.log(e)}},[]),i=t.useCallback(async()=>{const e=DeviceOrientationEvent;if(void 0!==e&&"function"==typeof e.requestPermission)try{"granted"===await e.requestPermission()?r(!0):console.warn("Device orientation permission denied.")}catch(e){console.error("Error requesting device orientation permission:",e)}else r(!0)},[]);return t.useEffect(()=>(e&&n?window.addEventListener("deviceorientation",o):a([]),()=>{window.removeEventListener("deviceorientation",o)}),[e,n,o]),t.useEffect(()=>{e&&i()},[e,i]),{gyroData:s}}(_),O=t.useCallback(()=>{$(a.generateUuid()),k(""),b(!1),L(!1)},[]),q=e=>{i({...e,message:a.handleErrorMessage(e)}),B(),N(!1),k(e),w(!1),a.handleScanTimeCapture({eventName:`${h}/measurement_failed/fit-view`,scanID:U,status:"failed",email:p,message:a.handleErrorMessage(e)}),z&&a.handleScanTimeCapture({eventName:`${h}/scan_completion_time`,scanID:U,status:"failed",completionTime:a.getCurrentTimeInSeconds()-z,email:p})},B=()=>{R(null),$("")},V=t.useCallback(async e=>{if(e&&"success"===e?.scanStatus&&"intermediate"===e?.resultType&&200===e?.code)return void a.handleScanTimeCapture({eventName:`${h}/measurement_success/intermediate`,scanID:U,status:"success",email:p});B();const t=U;N(!0),a.handleScanTimeCapture({eventName:`${h}/measurement_success/fit-view`,scanID:t,status:"success",email:p}),z&&a.handleScanTimeCapture({eventName:`${h}/scan_completion_time`,scanID:t,status:"success",completionTime:a.getCurrentTimeInSeconds()-z,email:p})},[m,h,U]),W=e=>{N(!1),k(""),w(!1),a.swan.measurement.handleMeasurementSocket({scanId:e||U,onOpen:()=>{a.handleWebSocketCapture({eventName:`${h}/webSocket`,scanID:U,connection:"open",type:"measurement_recommendation",email:p})},onClose:()=>a.handleWebSocketCapture({eventName:`${h}/webSocket`,scanID:U,connection:"close",type:"measurement_recommendation",email:p}),onError:e=>{q(e),a.handleWebSocketCapture({eventName:`${h}/webSocket`,scanID:U,connection:"error",type:"measurement_recommendation",email:p})},onSuccess:e=>{a.handleWebSocketCapture({eventName:`${h}/webSocket`,scanID:U,connection:"success",type:"measurement_recommendation",email:p}),V(e)}})},H=t.useCallback(async e=>{const t=a.createObjectMetadataArray({gender:d,focal_length:`${x}`,height:`${g}`,customer_store_url:h,clothes_fit:"0",scan_type:m,callback_url:S||"https://example.com/webhook"});a.handleScanTimeCapture({eventName:`${h}/body_scan_meta_data`,scanID:U,email:p,data:JSON.stringify(t)});try{await a.swan.fileUpload.uploadFileFrontend({file:e,arrayMetaData:t,scanId:U,email:p}),await a.swan.fileUpload.setDeviceInfo({model:y,detection:"manual",gyro:K,scanId:U}),console.log("video successfully uploaded"),L(!1),a.handleScanTimeCapture({eventName:`${h}/scan_success`,scanID:U,status:"success",email:p,data:JSON.stringify(t)}),a.handleScanTimeCapture({eventName:"scan finished",scanID:U,status:"success",email:p}),R(a.getCurrentTimeInSeconds()),setTimeout(()=>{L(!0)},3e3)}catch(e){a.handleScanTimeCapture({eventName:"scan finished",scanID:U,status:"failed",email:p,message:a.handleErrorMessage(e)}),a.handleScanTimeCapture({eventName:`${h}/scan_failed`,scanID:U,status:"failed",email:p,message:a.handleErrorMessage(e),data:JSON.stringify(t)}),k(a.handleErrorMessage(e)),L(!1),console.log(e,"video upload failed")}finally{P(!1)}},[U,K]),G=t.useCallback(async e=>{try{const t=await a.swan.measurement.getMeasurementResult(e),s=t?.data?.isMeasured,n=z||a.getCurrentTimeInSeconds(),r=a.getCurrentTimeInSeconds(),o=300;if(A(!1),!1===s)return B(),void $(a.generateUuid());b(!0),!0===s?await V(null):null===s&&n>r+o?q(t?.data?.error):W(e)}catch(e){console.log(e),B(),$(a.generateUuid()),b(!1)}},[q,V,$]),J=t.useCallback(async()=>{if(+g<152.4||+g>213.36)return void i({message:"Height must be between 152.4cm (5ft) and 213.36cm (7ft)"});const e=await a.checkCameraPermission();if(e.disabled)a.handleScanTimeCapture({eventName:`${h}/camera_activation`,scanID:U,status:"failed",email:p}),A(!1);else{U?G(U):A(!1),a.handleScanTimeCapture({eventName:`${h}/camera_activation`,scanID:U,status:"success",email:p})}E(e),k(""),L(!1)},[G,p,U,$,h]);return t.useEffect(()=>{s.init(a.posthogPublicKey,{api_host:a.posthogPublicHost}),s.capture("$pageview")},[]),t.useEffect(()=>{c||l||h&&J()},[h,g,c,l]),t.useEffect(()=>{c||l||T&&h&&U&&W()},[T,h,U,c,l]),e.jsx(a.LanguageContextProvider,{children:e.jsx(f,{children:e.jsx(a.ParamsContext.Provider,{value:{userDetails:n,config:r,onRetry:o,onScanError:i,isError:c,isSuccess:l,onScanSuccess:u,gender:d,scanUniqueKey:U,scanFailsError:D,setScanUniqueKey:$,setIsVideoUploaded:L,isMeasurementAvailable:j,isVideoUploadedCorrect:C,loading:M,showDeniedModal:F,uploadLoading:v,setStartGyro:P,handleFileUpload:H,setUploadLoading:b,handleShowStreamCamera:O,setScanFailsError:k,setScanStartTime:R},children:e.jsx(I,{})})})})};
2
+ //# sourceMappingURL=BodyScan-BZkcosMS.js.map