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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/dist/{BodyScan-BEFE9I0D.js → BodyScan-97yio9Oh.js} +2 -2
  2. package/dist/{BodyScan-BEFE9I0D.js.map → BodyScan-97yio9Oh.js.map} +1 -1
  3. package/dist/{BodyScan-CQw0C6WC.js → BodyScan-CW2FEtza.js} +2 -2
  4. package/dist/{BodyScan-CQw0C6WC.js.map → BodyScan-CW2FEtza.js.map} +1 -1
  5. package/dist/{FaceScan-DVAAtG8v.js → FaceScan-CD16KBC-.js} +2 -2
  6. package/dist/FaceScan-CD16KBC-.js.map +1 -0
  7. package/dist/{FaceScan-BmbbbsFP.js → FaceScan-CNQpL2rm.js} +2 -2
  8. package/dist/FaceScan-CNQpL2rm.js.map +1 -0
  9. package/dist/{LoadingScreen-vewtx75y.js → LoadingScreen--G_kIDCD.js} +2 -2
  10. package/dist/LoadingScreen--G_kIDCD.js.map +1 -0
  11. package/dist/{LoadingScreen-DCHEgS3u.js → LoadingScreen-bsnFuMYp.js} +2 -2
  12. package/dist/LoadingScreen-bsnFuMYp.js.map +1 -0
  13. package/dist/bodyScan.js +1 -1
  14. package/dist/bodyScan.mjs +1 -1
  15. package/dist/faceScan.js +1 -1
  16. package/dist/faceScan.mjs +1 -1
  17. package/dist/index.js +1 -1
  18. package/dist/index.mjs +1 -1
  19. package/package.json +1 -1
  20. package/dist/BodyScan-CP2sxAs_.js +0 -2
  21. package/dist/BodyScan-CP2sxAs_.js.map +0 -1
  22. package/dist/BodyScan-M3PbHzI8.js +0 -2
  23. package/dist/BodyScan-M3PbHzI8.js.map +0 -1
  24. package/dist/FaceScan-1AZEq6lq.js +0 -2
  25. package/dist/FaceScan-1AZEq6lq.js.map +0 -1
  26. package/dist/FaceScan-BmbbbsFP.js.map +0 -1
  27. package/dist/FaceScan-CiFQac3v.js +0 -2
  28. package/dist/FaceScan-CiFQac3v.js.map +0 -1
  29. package/dist/FaceScan-DVAAtG8v.js.map +0 -1
  30. package/dist/LoadingScreen-BOlJ0UJI.js +0 -2
  31. package/dist/LoadingScreen-BOlJ0UJI.js.map +0 -1
  32. package/dist/LoadingScreen-BYooRTYi.js +0 -2
  33. package/dist/LoadingScreen-BYooRTYi.js.map +0 -1
  34. package/dist/LoadingScreen-DCHEgS3u.js.map +0 -1
  35. package/dist/LoadingScreen-vewtx75y.js.map +0 -1
  36. package/dist/pose-detection.esm-BehJiApJ.js +0 -18
  37. package/dist/pose-detection.esm-BehJiApJ.js.map +0 -1
  38. package/dist/pose-detection.esm-DouwBFG2.js +0 -18
  39. package/dist/pose-detection.esm-DouwBFG2.js.map +0 -1
@@ -1,2 +1,2 @@
1
- import{jsx as e,jsxs as t,Fragment as n}from"react/jsx-runtime";import a,{useState as s,useCallback as r,useEffect as o,createContext as i,useLayoutEffect as l,useMemo as c,useContext as d,useRef as u}from"react";import m,{posthog as f}from"posthog-js";import{L as h,H as p,b as g,a as y,S as v,n as w,v as x,P as b,r as S,s as C,k as N,j as F,o as D,f as I,e as k,q as T,t as E,c as L,w as $,x as M,V as _,y as U,C as A,z,A as j,B as P,D as V,G as R,u as q,E as W,p as B,h as K,i as O,l as H}from"./LoadingScreen-BYooRTYi.js";import G from"clsx";import J from"react-webcam";import{Close as Q}from"@mui/icons-material";import{Dialog as Y,Box as X,Drawer as Z}from"@mui/material";import ee from"video.js";const te="DESKTOP",ne="TAB",ae="MOBILE",se=i(void 0);function re({children:t}){const[n,a]=s([window?.innerWidth,window?.innerHeight]),[r,i]=s(!1),d=()=>{a([window?.innerWidth,window?.innerHeight])};o(()=>{d()},[]),l(()=>(window.addEventListener("resize",d),()=>window.removeEventListener("resize",d)),[d]);let u=te;n[0]>768&&n[0]<1024&&(u=ne),n[0]<768&&(u=ae);const m=c(()=>({size:n,setSize:a,clearInputs:r,setClearInputs:i,media:u}),[n,r,u]);return e(se.Provider,{value:m,children:t})}var oe=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 ie=a.memo(function({angle:n,countdown:a,isScanning:s,isInTargetRange:o,stabilityScore:i,children:l,config:u}){const{translate:m}=d(h)||{},f=r(()=>n<80?Math.max(0,Math.min(100,10*(n-60))):n>95?Math.max(0,Math.min(100,10*(105-n))):100,[n]),y=c(()=>{if(s)return u?.style?.angleDetector?.successAngleBackground||"#4f46e5";const e=f();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)})`},[s,f]),v=r((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`,[]),w=r((e=!1)=>{const t=f();return s?`text-[${u?.style?.angleDetector?.successAngleTextLightColor}]`:v(e,t)},[s,f]),x=r((e,t)=>t>70||e?u?.style?.angleDetector?.successAngleTextLightColor:u?.style?.angleDetector?.successAngleTextDarkColor,[]),b=r((e=!1)=>{const t=f();return s?u?.style?.angleDetector?.successAngleTextLightColor:x(e,t)},[s,f]),S=a;function C(){document.documentElement.style.setProperty("--real-vh",window.innerHeight+"px")}return C(),window.addEventListener("resize",C),t("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:y},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(p,{noTitle:!0,resolvedConfig:u})})}),null!==S?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 ${b()}`},children:e("div",{className:`text-[3rem] font-bold text-[${b()}]`,style:{fontFamily:u?.style?.base?.baseFontFamily||"Inter, sans-serif",color:b()},children:S})}):t("div",s?{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"})}),l]}:{className:G("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 ${b()}`},children:[e("div",{className:`h-[1rem] w-[1rem] rounded-[9999px] bg-[${b()}]/80`,style:{backgroundColor:`${b()}B3`}}),t("div",{className:G("mt-[.5rem] text-center w-[180px] flex-col flex items-center absolute top-[60px]",w()),style:{color:b()},children:[e(oe,{size:30}),t("p",{style:{fontFamily:u?.style?.base?.baseFontFamily||"Inter, sans-serif"},children:[" ",m?.(g.startLevelCheck),e("br",{})]})]})]}),null!==S&&e("div",{className:"absolute bottom-[8rem] text-center",children:e("div",{className:G("text-sm font-medium px-4 py-1.5 bg-black/20 rounded-[9999px] mt-8",w()),style:{fontFamily:u?.style?.base?.baseFontFamily||"Inter, sans-serif",color:b()},children:m?.(g.leavePhone)})}),o&&null===S&&!s&&e("div",{className:"absolute bottom-[8rem] w-[12rem]",children:e("div",{className:`h-[.375rem] w-full bg-[${b()}]/20 rounded-[9999px] overflow-hidden`,style:{backgroundColor:`${b()}33`},children:e("div",{className:`h-full bg-[${b()}]/70 transition-all duration-300 rounded-[9999px]`,style:{width:`${n}%`,backgroundColor:`${b()}B3`}})})}),null===S&&!s&&e("div",{className:"absolute bottom-[5rem] text-center",children:t("div",{className:G("text-[1.5rem] font-light",w()),style:{color:b()},children:[Math.round(n),"°"]})}),null===S&&!s&&e("div",{className:"absolute bottom-[2rem] text-center max-w-[20rem] mx-auto",children:e("div",{className:G("text-[.75rem] opacity-50",w()),style:{fontFamily:u?.style?.base?.baseFontFamily||"Inter, sans-serif",color:b()},children:m?.(g.placePhoneUpright)})})]})});function le({handleShowStreamCamera:n,loadingCam:a,handleUserMedia:s,handlePause:r,pause:o,recordingStarted:i,startSendingVideoFrames:l,showPause:c,webcamRef:u,resetDetector:m,config:f}){const{media:p}=d(se)||{},{translate:b}=d(h)||{};return t("div",{className:"App w-screen h-[100vh] relative ",children:[e("span",{onClick:()=>{n(),m()},className:"fixed right-[20px] top-[20px] z-[999]",children:e(Q,{className:"text-[#fff]"})}),e("div",{className:"w-full h-full overflow-hidden ",children:p===ae&&e(J,{audio:!1,ref:u,screenshotQuality:1,videoConstraints:y,mirrored:!0,screenshotFormat:"image/jpeg",onUserMedia:s,style:{position:"fixed",top:0,bottom:0,zIndex:0,width:"100%",height:"100%",objectFit:"cover"}})}),t("div",{className:"fixed bottom-[30px] w-full z-[999] flex flex-col gap-4 items-center justify-center",children:[c&&e(v,{className:"!w-[180px] !h-[40px] !py-[0] mx-auto ",prefix:w,buttonText:b?.(g.pause),buttonFunc:r,resolvedConfig:f,btnSecondary:!0}),o?e("div",{children:e(v,{className:"!w-[180px] !h-[40px] !py-[0] mx-auto",buttonText:b?.(g.restart),buttonFunc:n,resolvedConfig:f,btnSecondary:!0})}):i?null:e(v,{className:"!w-[180px] !h-[40px] !py-[0] mx-auto !bg-[#ffffff] !text-[#000000] "+(a?"!opacity-50":""),buttonText:b?.(g.startScan),buttonFunc:l,disabled:a,resolvedConfig:f})]}),e("audio",{id:"audioElement",crossOrigin:"anonymous",preload:"auto",style:{position:"absolute",zIndex:-99999},src:`${x}scanAudioInstructions/silence.mp3`})]})}let ce=null,de=null,ue=null;let me,fe=null,he=null;var pe=a.memo(function({setIsScanLocked:t,resetDetector:n,scanID:a,setIsVideoUploaded:i,setScanFailsError:l,setScanStartTime:c,setScanUniqueKey:f,userDetails:h,config:p}){const{gender:g,heightInCm:y,email:v,shopDomain:w}=h,T=u(null),E=u(null),[L,$]=s([]),[M,_]=s(!0),[U,A]=s(!1),[z,j]=s(!1),[P,V]=s(!0),[R,q]=s(!1),W=u(null),[B,K]=s(""),[O,H]=s([]),[G,J]=s(""),[Q,Y]=s(!1),[X,Z]=s(!1),[ee,te]=s(!1),[ne,ae]=s([]),[se,re]=s(!1),oe=u(!0),{poseDetector:ie}=function(){const[e,t]=s(0),[n,a]=s(0),[r,i]=s(!1),l=u(0),c=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-CgI8fYpB.js"),import("@tensorflow/tfjs-core"),import("@tensorflow/tfjs-backend-webgl")]);ue=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{de=await ue.createDetector(ue.SupportedModels.BlazePose,a),console.log("MediaPipe detector created successfully")}catch(e){console.warn("MediaPipe failed, falling back to TFJS runtime:",e),de=await ue.createDetector(ue.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),ce=null,!1}}function f(e){return!(!e||0===e.length)&&22===e.filter(e=>e[2]>.7).length}return o(()=>{if(d.current=!0,!de)return ce||(ce=m()),ce.then(e=>{e&&d.current&&i(!0)}),()=>{d.current=!1};i(!0)},[]),o(()=>{c.current=e,e>6&&l.current<2&&(a(e=>e+1),t(0))},[e]),o(()=>{l.current=n},[n]),{poseDetector:async(e,n)=>{if(!de||!d.current||!n?.current?.video)return;const a=n.current.video;if(!(a.readyState<2))try{const n=await de.estimatePoses(a,{flipHorizontal:!1});if(!n||!n.length)return;const s=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!==l.current||f(s)||t(e=>e+1),1===l.current&&f(s)&&t(e=>e+1),2===l.current&&e()}catch(e){console.error("Pose detection error:",e)}},isLoaded:r,spinPhase:n,resetDetector:()=>{l.current=0,c.current=0,t(0),a(0)},retryLoading:async()=>{de||ce||(ce=m(),await ce&&d.current&&i(!0))}}}(),pe=u(!0),ge=u(!1),[ye,ve]=s([]);let we=0;const{setStartGyro:xe,handleFileUpload:be,setUploadLoading:Se}=d(b),Ce=()=>{ge.current=!1,clearTimeout(me),W.current&&clearTimeout(W.current),f(k()),l(""),Se?.(!1),$([]),_(!0),A(!1),j(!1),V(!0),q(!1),W.current=null,K(""),H([]),J(""),Y(!Q),xe(!1),C.stopAudio(),Z(!1),te(!1),we=0,null!==E.current&&E.current.stop(),ne.forEach(e=>{E.current&&E.current.removeEventListener("dataavailable",e)}),ae([]),oe.current=!0,re(!1),i(!1)},Ne=r(()=>{setTimeout(()=>{_(!1)},1e3)},[]),Fe=r(()=>{S({eventName:`${w}/rescan`,email:v,scanID:a,height:y,gender:g,status:!1}),oe.current=!1,Ce(),_e()},[Ce,a,v]),De=r(()=>{oe.current=!1,te(!0),re(!1),W.current&&clearTimeout(W.current),E.current&&E.current.pause(),C.stopAudio(),N.poseDetection.disconnect(),we=0,E.current&&E.current.stop(),ne.forEach(e=>{E.current&&E.current.removeEventListener("dataavailable",e)}),ae([]),clearTimeout(me)},[E,ne,C,oe]),Ie=r(async()=>{oe.current=!0,await C.playAudio(`${x}SpotOn.mp3`),te(!1),re(!1),W.current&&clearTimeout(W.current),A(!1)},[W,C]),ke=r(async()=>{try{fe=await N.poseDetection.connect(),m.capture(`${w}/pose_detection_connected`,{scanID:a,email:v,id:fe})}catch(e){console.log(e,"while connecting websocket")}},[a,w,v]),Te=r(({data:e})=>{e&&e.size>0&&oe.current&&($(t=>t.concat(e)),!ge.current&&T.current&&(ge.current=!0,ie(()=>{Ie(),F({eventName:`${w}/tensorFlow`,scanID:a,email:v,message:"recording stopped by tensorflow "})},T)))},[Ie,F,w,a,v,T]),Ee=r(async()=>{O.length>0&&oe.current&&(await C.playAudio(x+O[O.length-1]),oe.current&&(me=setTimeout(Ee,2e3)))},[O,oe]),Le=r(()=>{E&&E.current&&E.current.stop(),A(!0);try{if(T&&T.current&&T.current.stream){const e={mimeType:ye[0]};E.current=new MediaRecorder(T.current.stream,e),E.current.addEventListener("dataavailable",Te),ae([...ne,Te]),E.current.start(1e3),V(!1)}}catch(e){console.log("error while using media recorder",e)}},[T,ye,Te,ne]),$e=r(async()=>{W.current&&clearTimeout(W.current),Le(),oe.current&&(W.current=setTimeout(async()=>{oe.current&&(await C.playAudio(`${x}SpotOn.mp3`),A(!1))},15e3)),j(!0),oe.current&&await C.playAudio(`${x}Spin.mp3`)},[Le,oe,C]),Me=r(({data:e})=>{e.size>0&&N.poseDetection.connected()&&(N.poseDetection.poseStatus(async e=>{if(e&&e.audio&&e.audio.length>0){const t=document.querySelector("#audioElement");!0===e.status&&e.sid===fe?we<2?(0===we&&t?.paused&&await C.playAudio(x+e.audio),we+=1):(J(e.audio),clearTimeout(me),N.poseDetection.disconnect(),setTimeout($e,1e3)):(we=0,!t?.paused||he&&he?.audioName===e.audio?he?.audioName===e.audio&&t?.paused&&(he&&he.no_of_times_skipped>=he.skipCount?(he.no_of_times_skipped=0,C.playAudio(x+e.audio)):he&&(he.no_of_times_skipped+=1)):(he={skipCount:2,no_of_times_skipped:0,audioName:e.audio},C.playAudio(x+e.audio)))}}),T?.current&&null!==T.current.getScreenshot()&&N.poseDetection.videoEmit({image:T.current.getScreenshot()||"",scanId:a}))},[T,a,N,fe,we,$e,C]),_e=r(async()=>{q(!0),xe(!0),pe.current&&(pe.current=!1,F({eventName:"scan started",scanID:a,status:"success",email:v})),c(D()),_(!0),oe.current&&await C.playAudio(`${x}StartScan.mp3`),oe.current&&await C.playAudio(`${x}LiftArmsAndHoldAtHip.mp3`),oe.current&&(q(!1),A(!0),Z(!0),re(!0),Ne());try{if(T&&T.current&&T.current.stream&&oe.current){const e={mimeType:ye[0]};oe.current&&(E.current=new MediaRecorder(T.current.stream,e)),oe.current&&E.current&&E.current.addEventListener("dataavailable",Me),ae([...ne,Me]),E.current&&E.current.start(1e3),V(!1),oe.current&&(me=setTimeout(Ee,2e3))}}catch(e){console.log("error ----------",e)}},[T,ye,Me,ne,Ee,oe]);return o(()=>(w&&(t(!0),ke()),()=>{fe&&(N.poseDetection.disconnect(),m.capture(`${w}/pose_detection_disconnected`,{scanID:a,email:v,id:fe})),ne.forEach(e=>{E?.current?.removeEventListener("dataavailable",e)})}),[Q,w]),o(()=>{O.push(B)},[B]),o(()=>{H([])},[G]),o(()=>{const e=L.length&&L.length>0;P||!e||U||!oe.current||ee||E&&E.current&&(U||(E.current.stop(),V(!0)))},[P,U,L,ee]),o(()=>{const e=L.length&&L.length>0;if(P||!e||U)console.log("No video found to upload");else if(E&&E.current&&oe.current&&!ee&&!U){const e=new File(L,`${a}.webm`,{type:"video/webm"});Se?.(!0),l(""),be?.(e)}},[P,U,L,ee,E,oe]),o(()=>{if("undefined"!=typeof MediaRecorder){const e=I.filter(e=>MediaRecorder.isTypeSupported(e));ve(e)}},[]),o(()=>{Ce()},[]),e(le,{resetDetector:n,handleShowStreamCamera:Ce,loadingCam:M,handlePause:De,showRestart:X,pause:ee,handleReScan:Fe,recordingStarted:U,isScanning:R,startSendingVideoFrames:_e,faceDone:z,stopRecording:Ie,showPause:se,webcamRef:T,handleUserMedia:Ne,config:p})});function ge({scanID:t,userDetails:n,setIsVideoUploaded:a,setScanFailsError:r,setScanStartTime:i,setScanUniqueKey:l,config:c}){const[d,m]=s(90),[f,h]=s(0),[p,g]=s(null),[y,v]=s(!1),[w,x]=s(0),b=u([]),[S,C]=s(!1),N=d-f,F=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)),m(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);x(F&&e<2?e=>Math.min(100,e+10):e=>Math.max(0,e-20))}F||null===p&&!y||I()},[N,F,p,y]),o(()=>{w>=100&&null===p&&!y&&D(),w<50&&null!==p&&I()},[w,p,y]);const D=()=>{g(3);const e=setInterval(()=>{g(t=>null===t||t<=1?(clearInterval(e),v(!0),null):t-1)},1e3)},I=()=>{g(null),S||v(!1)};return e(ie,{angle:N,countdown:p,isScanning:y,isInTargetRange:F,stabilityScore:w,config:c,children:y&&e(pe,{setIsScanLocked:C,resetDetector:()=>{m(90),h(0),g(null),v(!1),x(0),C(!1),b.current=[]},scanID:t,userDetails:n,setIsVideoUploaded:a,setScanFailsError:r,setScanStartTime:i,setScanUniqueKey:l,config:c})})}function ye({message:a,config:s}){const{translate:r}=d(h)||{};return e(Y,{open:!0,className:"confirm-modal",children:e("div",{className:"modal-main",children:e("div",{className:"text-center",children:t(n,a?{children:[e("h2",{style:{fontFamily:s?.style?.heading?.headingFontFamily||"SeriouslyNostalgic Fn",fontSize:s?.style?.heading?.headingFontSize||"32px",color:s?.style?.heading?.headingColor||"#000",fontWeight:s?.style?.heading?.headingFontWeight||"normal"},children:r?.(g.cameraAlreadyInUse)}),e("p",{className:"mt-[0.5rem] text-sm",style:{fontFamily:s?.style?.base?.baseFontFamily||"Inter, sans-serif",fontSize:s?.style?.base?.baseFontSize||"16px",color:s?.style?.base?.baseTextColor||"#000"},children:r?.(g.tryClosingBrowser)})]}:{children:[e("h2",{style:{fontFamily:s?.style?.heading?.headingFontFamily||"SeriouslyNostalgic Fn",fontSize:s?.style?.heading?.headingFontSize||"32px",color:s?.style?.heading?.headingColor||"#000",fontWeight:s?.style?.heading?.headingFontWeight||"normal"},children:r?.(g.checkCameraSettings)}),e("p",{className:"mt-[0.5rem] text-sm",style:{fontFamily:s?.style?.base?.baseFontFamily||"Inter, sans-serif",fontSize:s?.style?.base?.baseFontSize||"16px",color:s?.style?.base?.baseTextColor||"#000"},children:`${r?.(g.setting)} > ${T()} > ${r?.(g.enableCameraPermissions)}`})]})})})})}function ve({setShowDrawer:t,config:n,loader:a}){const[i,l]=s({disabled:!1,message:""}),[c,d]=s(!0),m=u(null),f=r(async()=>{const e=await E();l(e),d(!1)},[]);return o(()=>{f()},[]),c?e(L,{url:a}):i?.disabled?e(ye,{config:n,message:i?.message}):e(J,{audio:!1,ref:m,screenshotQuality:1,videoConstraints:y,mirrored:!0,onUserMedia:()=>t?.(!0),screenshotFormat:"image/jpeg",style:{position:"relative",top:0,bottom:0,zIndex:0,width:"100%",height:"100%",objectFit:"cover"}})}function we({link:t,onReady:n,wrapperClassName:a="[&_video]:rounded-t-[20px] w-full h-full"}){const s=u(null),r=u(null);let i={autoplay:!0,controls:!1,responsive:!0,fluid:!0,muted:!0,navigationUI:"hide",preload:"metadata",poster:$};return o(()=>{if(!r.current&&t&&s?.current){const e=ee(s.current,{...i});e.ready(()=>{r.current=e;const a={...i,sources:[{src:t,type:"application/x-mpegURL"}]};e.autoplay(a.autoplay),e.src(a.sources),n?.(e)})}},[t,s]),o(()=>{const e=r.current;return()=>{e&&!e.isDisposed()&&(e.dispose(),r.current=null)}},[r]),e("div",{className:a,children:e("video",{ref:s,muted:!0,className:"video-js",playsInline:!0,onDrag:e=>e.preventDefault()})})}function xe({scanFailsError:a,serverAtCapacity:r=!1,onNext:o,gender:i,setScanUniqueKey:l,resolvedConfig:c,setIsVideoUploaded:u}){const{translate:m}=d(h)||{},[f,y]=s(!1),w=()=>{y(!f)};return t(n,{children:[t("div",{className:"flex flex-col h-full max-w-[28rem] mx-auto w-full rounded-t-[20px] overflow-y-auto",style:{background:c?.style?.base?.backgroundColor},children:[e("div",{className:"w-full max-w-[28rem] mx-auto pt-[1rem] px-[1rem]",children:e(p,{noTitle:!0,resolvedConfig:c})}),t("div",{className:"flex-1",children:[a&&t("div",{className:"px-[1rem]",children:[e("h2",{className:"text-center",style:{fontFamily:c?.style?.heading?.headingFontFamily||"SeriouslyNostalgic Fn",fontSize:c?.style?.heading?.headingFontSize||"32px",color:c?.style?.heading?.headingColor||"#000",fontWeight:c?.style?.heading?.headingFontWeight||"normal"},children:m?.(g.issueWithScan)}),e("p",{style:{fontFamily:c?.style?.base?.baseFontFamily||"Inter, sans-serif",fontSize:c?.style?.base?.baseFontSize||"16px",color:c?.style?.base?.baseTextColor||"#1E1E1E"},children:m?.(g.reason)}),e("p",{style:{fontFamily:c?.style?.base?.baseFontFamily||"Inter, sans-serif",fontSize:c?.style?.base?.baseFontSize||"16px",color:c?.style?.base?.baseTextColor||"#1E1E1E"},children:M(a)}),e("img",{className:"my-[0.5rem] aspect-[2/1.4] w-full object-cover",onClick:w,src:_[i],alt:"icon"})]}),r&&t("div",{className:"p-[1rem] text-center",children:[e("h3",{style:{fontFamily:c?.style?.heading?.headingFontFamily||"SeriouslyNostalgic Fn",fontSize:c?.style?.heading?.headingFontSize||"32px",color:c?.style?.heading?.headingColor||"#000",fontWeight:c?.style?.heading?.headingFontWeight||"normal"},children:m?.(g.serverAtCapacity)}),e("p",{className:"text-base mt-[0.5rem]",style:{fontFamily:c?.style?.base?.baseFontFamily||"Inter, sans-serif",fontSize:c?.style?.base?.baseFontSize||"16px",color:c?.style?.base?.baseTextColor||"#1E1E1E"},children:m?.(g.serverAtCapacityDescription)})]})]}),a&&e("div",{className:"p-[1rem] flex gap-[0.5rem]",children:e(v,{disabled:!1,buttonText:m?.(g.scanAgain),className:"!shadow-none",buttonFunc:()=>{o?o?.():l(k()),u(!1)},resolvedConfig:c})})]}),f&&t(Y,{className:"w-screen h-screen video-modal",onClose:w,open:f,children:[e("div",{className:"flex justifyEnd ",children:e("span",{className:"closeBtn",onClick:w,children:e(Q,{className:"absolute right-[8px] top-[8px] text-white z-[9]"})})}),e("div",{className:"aspect-video object-cover rounded-[20px] ",children:e(we,{link:i?U[i].PRE_LINK:U.male.PRE_LINK,wrapperClassName:"w-screen h-screen fixed top-[0] left-[0]"})})]})]})}function be({scanId:n,userDetails:a,config:i,isFaceScan:l,isVideoUploadedCorrect:c,isMeasurementAvailable:u,onScanSuccess:m,isSuccess:y}){const{gender:w,shopDomain:x,heightInCm:b,deviceFocalLength:S,userName:C,email:F,scanType:D}=a,I=[A,z,j].includes(D),[k,T]=s(!0),E=r(async()=>{try{I&&await N.auth.addUser({scanId:n,email:F,name:C,gender:w,height:b}),f.capture(x,{scanID:n,email:F,height:b,focalLength:S,clothesFit:"0",gender:w})}catch(e){console.log(e)}},[I]),{translate:L}=d(h)||{};o(()=>{c&&E()},[c]);const $=y||(l?u&&c:c||u);return e(X,{className:"flex h-full w-full flex-col ",children:t("div",{className:"h-full w-full flex-col items-center justify-center flex",children:[e(ve,{loader:i?.loader,setShowDrawer:T}),e(Z,{open:k,onClose:(e,t)=>{},className:"camera-drawer",anchor:"bottom",children:e("div",{className:"max-w-[28rem] mx-auto w-full h-full flex text-center flex-col justify-between items-center bg-primary rounded-t-[30px] p-[1rem]",style:{background:i?.style?.base?.backgroundColor},children:t("div",{className:"w-full h-full flex flex-col",children:[e(p,{title:L?.(g.measurementsBeingTaken),resolvedConfig:i}),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===R.Male?P:V,type:"video/mp4"})})}),$&&e(v,{resolvedConfig:i,className:"!w-[180px] mx-auto",buttonText:L?.(g.next),buttonFunc:m&&m})]})})})]})})}const Se=()=>{const{userDetails:a,config:s,onRetry:r,isError:i,isSuccess:l,onScanSuccess:c,gender:u,scanUniqueKey:m,scanFailsError:f,setScanUniqueKey:p,setIsVideoUploaded:g,isMeasurementAvailable:y,isVideoUploadedCorrect:v,loading:w,showDeniedModal:x,uploadLoading:S,setStartGyro:C,handleFileUpload:N,setUploadLoading:F,setScanFailsError:D,setScanStartTime:I,handleShowStreamCamera:k}=d(b),{setPreferredLanguage:T}=d(h)||{},E=q(s);return o(()=>{T?.(E?.language)},[E]),i?t(n,{children:[e(ve,{}),e(Z,{anchor:"bottom",open:!0,className:"camera-drawer",onClose:(e,t)=>{},children:e(xe,{scanFailsError:f||i,onNext:()=>{},setScanUniqueKey:p,gender:u,resolvedConfig:E,setIsVideoUploaded:g})})]}):l?e(be,{isFaceScan:!1,scanId:m,isMeasurementAvailable:y,userDetails:a,isVideoUploadedCorrect:v,config:E,isSuccess:l}):w?e("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(L,{url:E?.loader})}):x.disabled?e(ye,{}):S||f?!S&&!y||f?t(n,{children:[e(ve,{}),e(Z,{anchor:"bottom",open:!0,className:"camera-drawer",onClose:(e,t)=>{},children:e(xe,{scanFailsError:f,onNext:()=>{r?.(),k()},setScanUniqueKey:p,gender:u,resolvedConfig:E,setIsVideoUploaded:g})})]}):e(be,{isFaceScan:!1,scanId:m,isMeasurementAvailable:y,userDetails:a,onScanSuccess:c,isVideoUploadedCorrect:v,config:E}):e(ge,{config:E,scanID:m,userDetails:a,setIsVideoUploaded:g,setScanFailsError:D,setScanStartTime:I,setScanUniqueKey:p})},Ce=({userDetails:t,config:n,onRetry:a,onScanError:i,isError:l,isSuccess:c,onScanSuccess:d})=>{const{gender:u,scanType:f,shopDomain:h,heightInCm:p,email:g,deviceFocalLength:y,deviceModelName:v,callbackUrl:w}=t,[x,S]=s(!1),[C,I]=s(!1),[T,L]=s(!1),[$,_]=s({disabled:!1,message:""}),[U,A]=s(""),[z,j]=s(!1),[P,V]=s(!0),[R,q]=s(!1),[G,J]=s(""),[Q,Y]=s(D()),{gyroData:X}=function(e){const[t,n]=s([]),[a,i]=s(!1),l=r(e=>{try{const{alpha:t,beta:a,gamma:s}=e;n(e=>[...e,{alpha:t?.toString()||void 0,beta:a?.toString()||void 0,gamma:s?.toString()||void 0,timestamp:(new Date).toISOString()}])}catch(e){console.log(e)}},[]),c=r(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",l):n([]),()=>{window.removeEventListener("deviceorientation",l)}),[e,a,l]),o(()=>{e&&c()},[e,c]),{gyroData:t}}(R),Z=r(()=>{J(k()),A(""),S(!1),j(!1)},[]),ee=e=>{i({...e,message:M(e)}),te(),L(!1),A(e),I(!1),F({eventName:`${h}/measurement_failed/fit-view`,scanID:G,status:"failed",email:g,message:M(e)}),Q&&F({eventName:`${h}/scan_completion_time`,scanID:G,status:"failed",completionTime:D()-Q,email:g})},te=()=>{Y(null),J("")},ne=r(async e=>{if(e&&"success"===e?.scanStatus&&"intermediate"===e?.resultType&&200===e?.code)return void F({eventName:`${h}/measurement_success/intermediate`,scanID:G,status:"success",email:g});te();const t=G;L(!0),F({eventName:`${h}/measurement_success/fit-view`,scanID:t,status:"success",email:g}),Q&&F({eventName:`${h}/scan_completion_time`,scanID:t,status:"success",completionTime:D()-Q,email:g})},[f,h,G]),ae=e=>{L(!1),A(""),I(!1),N.measurement.handleMeasurementSocket({scanId:e||G,onOpen:()=>{H({eventName:`${h}/webSocket`,scanID:G,connection:"open",type:"measurement_recommendation",email:g})},onClose:()=>H({eventName:`${h}/webSocket`,scanID:G,connection:"close",type:"measurement_recommendation",email:g}),onError:e=>{ee(e),H({eventName:`${h}/webSocket`,scanID:G,connection:"error",type:"measurement_recommendation",email:g})},onSuccess:e=>{H({eventName:`${h}/webSocket`,scanID:G,connection:"success",type:"measurement_recommendation",email:g}),ne(e)}})},se=r(async e=>{const t=W({gender:u,focal_length:`${y}`,height:`${p}`,customer_store_url:h,clothes_fit:"0",scan_type:f,callback_url:w||"https://example.com/webhook"});F({eventName:`${h}/body_scan_meta_data`,scanID:G,email:g,data:JSON.stringify(t)});try{await N.fileUpload.uploadFileFrontend({file:e,arrayMetaData:t,scanId:G,email:g}),await N.fileUpload.setDeviceInfo({model:v,detection:"manual",gyro:X,scanId:G}),console.log("video successfully uploaded"),j(!1),F({eventName:`${h}/scan_success`,scanID:G,status:"success",email:g,data:JSON.stringify(t)}),F({eventName:"scan finished",scanID:G,status:"success",email:g}),Y(D()),setTimeout(()=>{j(!0)},3e3)}catch(e){F({eventName:"scan finished",scanID:G,status:"failed",email:g,message:M(e)}),F({eventName:`${h}/scan_failed`,scanID:G,status:"failed",email:g,message:M(e),data:JSON.stringify(t)}),A(M(e)),j(!1),console.log(e,"video upload failed")}finally{q(!1)}},[G,X]),oe=r(async e=>{try{const t=await N.measurement.getMeasurementResult(e),n=t?.data?.isMeasured,a=Q||D(),s=D(),r=300;if(V(!1),!1===n)return te(),void J(k());S(!0),!0===n?await ne(null):null===n&&a>s+r?ee(t?.data?.error):ae(e)}catch(e){console.log(e),te(),J(k()),S(!1)}},[ee,ne,J]),ie=r(async()=>{if(+p<152.4||+p>213.36)return void i({message:"Height must be between 152.4cm (5ft) and 213.36cm (7ft)"});const e=await E();if(e.disabled)F({eventName:`${h}/camera_activation`,scanID:G,status:"failed",email:g}),V(!1);else{G?oe(G):V(!1),F({eventName:`${h}/camera_activation`,scanID:G,status:"success",email:g})}_(e),A(""),j(!1)},[oe,g,G,J,h]);return o(()=>{m.init(B,{api_host:K}),m.capture("$pageview")},[]),o(()=>{l||c||h&&ie()},[h,p,l,c]),o(()=>{l||c||z&&h&&G&&ae()},[z,h,G,l,c]),e(O,{children:e(re,{children:e(b.Provider,{value:{userDetails:t,config:n,onRetry:a,onScanError:i,isError:l,isSuccess:c,onScanSuccess:d,gender:u,scanUniqueKey:G,scanFailsError:U,setScanUniqueKey:J,setIsVideoUploaded:j,isMeasurementAvailable:T,isVideoUploadedCorrect:C,loading:P,showDeniedModal:$,uploadLoading:x,setStartGyro:q,handleFileUpload:se,setUploadLoading:S,handleShowStreamCamera:Z,setScanFailsError:A,setScanStartTime:Y},children:e(Se,{})})})})};export{Ce as B};
2
- //# sourceMappingURL=BodyScan-CQw0C6WC.js.map
1
+ import{jsx as e,jsxs as t,Fragment as n}from"react/jsx-runtime";import a,{useState as s,useCallback as r,useEffect as o,createContext as i,useLayoutEffect as l,useMemo as c,useContext as d,useRef as u}from"react";import m,{posthog as f}from"posthog-js";import{L as h,H as p,b as g,a as y,S as v,n as w,v as x,P as b,r as S,s as C,k as N,j as F,o as D,f as I,e as k,q as T,t as E,c as L,w as $,x as M,V as _,y as U,C as A,z,A as j,B as P,D as V,G as R,u as q,E as W,p as B,h as K,i as O,l as H}from"./LoadingScreen-bsnFuMYp.js";import G from"clsx";import J from"react-webcam";import{Close as Q}from"@mui/icons-material";import{Dialog as Y,Box as X,Drawer as Z}from"@mui/material";import ee from"video.js";const te="DESKTOP",ne="TAB",ae="MOBILE",se=i(void 0);function re({children:t}){const[n,a]=s([window?.innerWidth,window?.innerHeight]),[r,i]=s(!1),d=()=>{a([window?.innerWidth,window?.innerHeight])};o(()=>{d()},[]),l(()=>(window.addEventListener("resize",d),()=>window.removeEventListener("resize",d)),[d]);let u=te;n[0]>768&&n[0]<1024&&(u=ne),n[0]<768&&(u=ae);const m=c(()=>({size:n,setSize:a,clearInputs:r,setClearInputs:i,media:u}),[n,r,u]);return e(se.Provider,{value:m,children:t})}var oe=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 ie=a.memo(function({angle:n,countdown:a,isScanning:s,isInTargetRange:o,stabilityScore:i,children:l,config:u}){const{translate:m}=d(h)||{},f=r(()=>n<80?Math.max(0,Math.min(100,10*(n-60))):n>95?Math.max(0,Math.min(100,10*(105-n))):100,[n]),y=c(()=>{if(s)return u?.style?.angleDetector?.successAngleBackground||"#4f46e5";const e=f();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)})`},[s,f]),v=r((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`,[]),w=r((e=!1)=>{const t=f();return s?`text-[${u?.style?.angleDetector?.successAngleTextLightColor}]`:v(e,t)},[s,f]),x=r((e,t)=>t>70||e?u?.style?.angleDetector?.successAngleTextLightColor:u?.style?.angleDetector?.successAngleTextDarkColor,[]),b=r((e=!1)=>{const t=f();return s?u?.style?.angleDetector?.successAngleTextLightColor:x(e,t)},[s,f]),S=a;function C(){document.documentElement.style.setProperty("--real-vh",window.innerHeight+"px")}return C(),window.addEventListener("resize",C),t("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:y},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(p,{noTitle:!0,resolvedConfig:u})})}),null!==S?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 ${b()}`},children:e("div",{className:`text-[3rem] font-bold text-[${b()}]`,style:{fontFamily:u?.style?.base?.baseFontFamily||"Inter, sans-serif",color:b()},children:S})}):t("div",s?{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"})}),l]}:{className:G("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 ${b()}`},children:[e("div",{className:`h-[1rem] w-[1rem] rounded-[9999px] bg-[${b()}]/80`,style:{backgroundColor:`${b()}B3`}}),t("div",{className:G("mt-[.5rem] text-center w-[180px] flex-col flex items-center absolute top-[60px]",w()),style:{color:b()},children:[e(oe,{size:30}),t("p",{style:{fontFamily:u?.style?.base?.baseFontFamily||"Inter, sans-serif"},children:[" ",m?.(g.startLevelCheck),e("br",{})]})]})]}),null!==S&&e("div",{className:"absolute bottom-[8rem] text-center",children:e("div",{className:G("text-sm font-medium px-4 py-1.5 bg-black/20 rounded-[9999px] mt-8",w()),style:{fontFamily:u?.style?.base?.baseFontFamily||"Inter, sans-serif",color:b()},children:m?.(g.leavePhone)})}),o&&null===S&&!s&&e("div",{className:"absolute bottom-[8rem] w-[12rem]",children:e("div",{className:`h-[.375rem] w-full bg-[${b()}]/20 rounded-[9999px] overflow-hidden`,style:{backgroundColor:`${b()}33`},children:e("div",{className:`h-full bg-[${b()}]/70 transition-all duration-300 rounded-[9999px]`,style:{width:`${n}%`,backgroundColor:`${b()}B3`}})})}),null===S&&!s&&e("div",{className:"absolute bottom-[5rem] text-center",children:t("div",{className:G("text-[1.5rem] font-light",w()),style:{color:b()},children:[Math.round(n),"°"]})}),null===S&&!s&&e("div",{className:"absolute bottom-[2rem] text-center max-w-[20rem] mx-auto",children:e("div",{className:G("text-[.75rem] opacity-50",w()),style:{fontFamily:u?.style?.base?.baseFontFamily||"Inter, sans-serif",color:b()},children:m?.(g.placePhoneUpright)})})]})});function le({handleShowStreamCamera:n,loadingCam:a,handleUserMedia:s,handlePause:r,pause:o,recordingStarted:i,startSendingVideoFrames:l,showPause:c,webcamRef:u,resetDetector:m,config:f}){const{media:p}=d(se)||{},{translate:b}=d(h)||{};return t("div",{className:"App w-screen h-[100vh] relative ",children:[e("span",{onClick:()=>{n(),m()},className:"fixed right-[20px] top-[20px] z-[999]",children:e(Q,{className:"text-[#fff]"})}),e("div",{className:"w-full h-full overflow-hidden ",children:p===ae&&e(J,{audio:!1,ref:u,screenshotQuality:1,videoConstraints:y,mirrored:!0,screenshotFormat:"image/jpeg",onUserMedia:s,style:{position:"fixed",top:0,bottom:0,zIndex:0,width:"100%",height:"100%",objectFit:"cover"}})}),t("div",{className:"fixed bottom-[30px] w-full z-[999] flex flex-col gap-4 items-center justify-center",children:[c&&e(v,{className:"!w-[180px] !h-[40px] !py-[0] mx-auto ",prefix:w,buttonText:b?.(g.pause),buttonFunc:r,resolvedConfig:f,btnSecondary:!0}),o?e("div",{children:e(v,{className:"!w-[180px] !h-[40px] !py-[0] mx-auto",buttonText:b?.(g.restart),buttonFunc:n,resolvedConfig:f,btnSecondary:!0})}):i?null:e(v,{className:"!w-[180px] !h-[40px] !py-[0] mx-auto !bg-[#ffffff] !text-[#000000] "+(a?"!opacity-50":""),buttonText:b?.(g.startScan),buttonFunc:l,disabled:a,resolvedConfig:f})]}),e("audio",{id:"audioElement",crossOrigin:"anonymous",preload:"auto",style:{position:"absolute",zIndex:-99999},src:`${x}scanAudioInstructions/silence.mp3`})]})}let ce=null,de=null,ue=null;let me,fe=null,he=null;var pe=a.memo(function({setIsScanLocked:t,resetDetector:n,scanID:a,setIsVideoUploaded:i,setScanFailsError:l,setScanStartTime:c,setScanUniqueKey:f,userDetails:h,config:p}){const{gender:g,heightInCm:y,email:v,shopDomain:w}=h,T=u(null),E=u(null),[L,$]=s([]),[M,_]=s(!0),[U,A]=s(!1),[z,j]=s(!1),[P,V]=s(!0),[R,q]=s(!1),W=u(null),[B,K]=s(""),[O,H]=s([]),[G,J]=s(""),[Q,Y]=s(!1),[X,Z]=s(!1),[ee,te]=s(!1),[ne,ae]=s([]),[se,re]=s(!1),oe=u(!0),{poseDetector:ie}=function(){const[e,t]=s(0),[n,a]=s(0),[r,i]=s(!1),l=u(0),c=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-CgI8fYpB.js"),import("@tensorflow/tfjs-core"),import("@tensorflow/tfjs-backend-webgl")]);ue=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{de=await ue.createDetector(ue.SupportedModels.BlazePose,a),console.log("MediaPipe detector created successfully")}catch(e){console.warn("MediaPipe failed, falling back to TFJS runtime:",e),de=await ue.createDetector(ue.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),ce=null,!1}}function f(e){return!(!e||0===e.length)&&22===e.filter(e=>e[2]>.7).length}return o(()=>{if(d.current=!0,!de)return ce||(ce=m()),ce.then(e=>{e&&d.current&&i(!0)}),()=>{d.current=!1};i(!0)},[]),o(()=>{c.current=e,e>6&&l.current<2&&(a(e=>e+1),t(0))},[e]),o(()=>{l.current=n},[n]),{poseDetector:async(e,n)=>{if(!de||!d.current||!n?.current?.video)return;const a=n.current.video;if(!(a.readyState<2))try{const n=await de.estimatePoses(a,{flipHorizontal:!1});if(!n||!n.length)return;const s=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!==l.current||f(s)||t(e=>e+1),1===l.current&&f(s)&&t(e=>e+1),2===l.current&&e()}catch(e){console.error("Pose detection error:",e)}},isLoaded:r,spinPhase:n,resetDetector:()=>{l.current=0,c.current=0,t(0),a(0)},retryLoading:async()=>{de||ce||(ce=m(),await ce&&d.current&&i(!0))}}}(),pe=u(!0),ge=u(!1),[ye,ve]=s([]);let we=0;const{setStartGyro:xe,handleFileUpload:be,setUploadLoading:Se}=d(b),Ce=()=>{ge.current=!1,clearTimeout(me),W.current&&clearTimeout(W.current),f(k()),l(""),Se?.(!1),$([]),_(!0),A(!1),j(!1),V(!0),q(!1),W.current=null,K(""),H([]),J(""),Y(!Q),xe(!1),C.stopAudio(),Z(!1),te(!1),we=0,null!==E.current&&E.current.stop(),ne.forEach(e=>{E.current&&E.current.removeEventListener("dataavailable",e)}),ae([]),oe.current=!0,re(!1),i(!1)},Ne=r(()=>{setTimeout(()=>{_(!1)},1e3)},[]),Fe=r(()=>{S({eventName:`${w}/rescan`,email:v,scanID:a,height:y,gender:g,status:!1}),oe.current=!1,Ce(),_e()},[Ce,a,v]),De=r(()=>{oe.current=!1,te(!0),re(!1),W.current&&clearTimeout(W.current),E.current&&E.current.pause(),C.stopAudio(),N.poseDetection.disconnect(),we=0,E.current&&E.current.stop(),ne.forEach(e=>{E.current&&E.current.removeEventListener("dataavailable",e)}),ae([]),clearTimeout(me)},[E,ne,C,oe]),Ie=r(async()=>{oe.current=!0,await C.playAudio(`${x}SpotOn.mp3`),te(!1),re(!1),W.current&&clearTimeout(W.current),A(!1)},[W,C]),ke=r(async()=>{try{fe=await N.poseDetection.connect(),m.capture(`${w}/pose_detection_connected`,{scanID:a,email:v,id:fe})}catch(e){console.log(e,"while connecting websocket")}},[a,w,v]),Te=r(({data:e})=>{e&&e.size>0&&oe.current&&($(t=>t.concat(e)),!ge.current&&T.current&&(ge.current=!0,ie(()=>{Ie(),F({eventName:`${w}/tensorFlow`,scanID:a,email:v,message:"recording stopped by tensorflow "})},T)))},[Ie,F,w,a,v,T]),Ee=r(async()=>{O.length>0&&oe.current&&(await C.playAudio(x+O[O.length-1]),oe.current&&(me=setTimeout(Ee,2e3)))},[O,oe]),Le=r(()=>{E&&E.current&&E.current.stop(),A(!0);try{if(T&&T.current&&T.current.stream){const e={mimeType:ye[0]};E.current=new MediaRecorder(T.current.stream,e),E.current.addEventListener("dataavailable",Te),ae([...ne,Te]),E.current.start(1e3),V(!1)}}catch(e){console.log("error while using media recorder",e)}},[T,ye,Te,ne]),$e=r(async()=>{W.current&&clearTimeout(W.current),Le(),oe.current&&(W.current=setTimeout(async()=>{oe.current&&(await C.playAudio(`${x}SpotOn.mp3`),A(!1))},15e3)),j(!0),oe.current&&await C.playAudio(`${x}Spin.mp3`)},[Le,oe,C]),Me=r(({data:e})=>{e.size>0&&N.poseDetection.connected()&&(N.poseDetection.poseStatus(async e=>{if(e&&e.audio&&e.audio.length>0){const t=document.querySelector("#audioElement");!0===e.status&&e.sid===fe?we<2?(0===we&&t?.paused&&await C.playAudio(x+e.audio),we+=1):(J(e.audio),clearTimeout(me),N.poseDetection.disconnect(),setTimeout($e,1e3)):(we=0,!t?.paused||he&&he?.audioName===e.audio?he?.audioName===e.audio&&t?.paused&&(he&&he.no_of_times_skipped>=he.skipCount?(he.no_of_times_skipped=0,C.playAudio(x+e.audio)):he&&(he.no_of_times_skipped+=1)):(he={skipCount:2,no_of_times_skipped:0,audioName:e.audio},C.playAudio(x+e.audio)))}}),T?.current&&null!==T.current.getScreenshot()&&N.poseDetection.videoEmit({image:T.current.getScreenshot()||"",scanId:a}))},[T,a,N,fe,we,$e,C]),_e=r(async()=>{q(!0),xe(!0),pe.current&&(pe.current=!1,F({eventName:"scan started",scanID:a,status:"success",email:v})),c(D()),_(!0),oe.current&&await C.playAudio(`${x}StartScan.mp3`),oe.current&&await C.playAudio(`${x}LiftArmsAndHoldAtHip.mp3`),oe.current&&(q(!1),A(!0),Z(!0),re(!0),Ne());try{if(T&&T.current&&T.current.stream&&oe.current){const e={mimeType:ye[0]};oe.current&&(E.current=new MediaRecorder(T.current.stream,e)),oe.current&&E.current&&E.current.addEventListener("dataavailable",Me),ae([...ne,Me]),E.current&&E.current.start(1e3),V(!1),oe.current&&(me=setTimeout(Ee,2e3))}}catch(e){console.log("error ----------",e)}},[T,ye,Me,ne,Ee,oe]);return o(()=>(w&&(t(!0),ke()),()=>{fe&&(N.poseDetection.disconnect(),m.capture(`${w}/pose_detection_disconnected`,{scanID:a,email:v,id:fe})),ne.forEach(e=>{E?.current?.removeEventListener("dataavailable",e)})}),[Q,w]),o(()=>{O.push(B)},[B]),o(()=>{H([])},[G]),o(()=>{const e=L.length&&L.length>0;P||!e||U||!oe.current||ee||E&&E.current&&(U||(E.current.stop(),V(!0)))},[P,U,L,ee]),o(()=>{const e=L.length&&L.length>0;if(P||!e||U)console.log("No video found to upload");else if(E&&E.current&&oe.current&&!ee&&!U){const e=new File(L,`${a}.webm`,{type:"video/webm"});Se?.(!0),l(""),be?.(e)}},[P,U,L,ee,E,oe]),o(()=>{if("undefined"!=typeof MediaRecorder){const e=I.filter(e=>MediaRecorder.isTypeSupported(e));ve(e)}},[]),o(()=>{Ce()},[]),e(le,{resetDetector:n,handleShowStreamCamera:Ce,loadingCam:M,handlePause:De,showRestart:X,pause:ee,handleReScan:Fe,recordingStarted:U,isScanning:R,startSendingVideoFrames:_e,faceDone:z,stopRecording:Ie,showPause:se,webcamRef:T,handleUserMedia:Ne,config:p})});function ge({scanID:t,userDetails:n,setIsVideoUploaded:a,setScanFailsError:r,setScanStartTime:i,setScanUniqueKey:l,config:c}){const[d,m]=s(90),[f,h]=s(0),[p,g]=s(null),[y,v]=s(!1),[w,x]=s(0),b=u([]),[S,C]=s(!1),N=d-f,F=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)),m(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);x(F&&e<2?e=>Math.min(100,e+10):e=>Math.max(0,e-20))}F||null===p&&!y||I()},[N,F,p,y]),o(()=>{w>=100&&null===p&&!y&&D(),w<50&&null!==p&&I()},[w,p,y]);const D=()=>{g(3);const e=setInterval(()=>{g(t=>null===t||t<=1?(clearInterval(e),v(!0),null):t-1)},1e3)},I=()=>{g(null),S||v(!1)};return e(ie,{angle:N,countdown:p,isScanning:y,isInTargetRange:F,stabilityScore:w,config:c,children:y&&e(pe,{setIsScanLocked:C,resetDetector:()=>{m(90),h(0),g(null),v(!1),x(0),C(!1),b.current=[]},scanID:t,userDetails:n,setIsVideoUploaded:a,setScanFailsError:r,setScanStartTime:i,setScanUniqueKey:l,config:c})})}function ye({message:a,config:s}){const{translate:r}=d(h)||{};return e(Y,{open:!0,className:"confirm-modal",children:e("div",{className:"modal-main",children:e("div",{className:"text-center",children:t(n,a?{children:[e("h2",{style:{fontFamily:s?.style?.heading?.headingFontFamily||"SeriouslyNostalgic Fn",fontSize:s?.style?.heading?.headingFontSize||"32px",color:s?.style?.heading?.headingColor||"#000",fontWeight:s?.style?.heading?.headingFontWeight||"normal"},children:r?.(g.cameraAlreadyInUse)}),e("p",{className:"mt-[0.5rem] text-sm",style:{fontFamily:s?.style?.base?.baseFontFamily||"Inter, sans-serif",fontSize:s?.style?.base?.baseFontSize||"16px",color:s?.style?.base?.baseTextColor||"#000"},children:r?.(g.tryClosingBrowser)})]}:{children:[e("h2",{style:{fontFamily:s?.style?.heading?.headingFontFamily||"SeriouslyNostalgic Fn",fontSize:s?.style?.heading?.headingFontSize||"32px",color:s?.style?.heading?.headingColor||"#000",fontWeight:s?.style?.heading?.headingFontWeight||"normal"},children:r?.(g.checkCameraSettings)}),e("p",{className:"mt-[0.5rem] text-sm",style:{fontFamily:s?.style?.base?.baseFontFamily||"Inter, sans-serif",fontSize:s?.style?.base?.baseFontSize||"16px",color:s?.style?.base?.baseTextColor||"#000"},children:`${r?.(g.setting)} > ${T()} > ${r?.(g.enableCameraPermissions)}`})]})})})})}function ve({setShowDrawer:t,config:n,loader:a}){const[i,l]=s({disabled:!1,message:""}),[c,d]=s(!0),m=u(null),f=r(async()=>{const e=await E();l(e),d(!1)},[]);return o(()=>{f()},[]),c?e(L,{url:a}):i?.disabled?e(ye,{config:n,message:i?.message}):e(J,{audio:!1,ref:m,screenshotQuality:1,videoConstraints:y,mirrored:!0,onUserMedia:()=>t?.(!0),screenshotFormat:"image/jpeg",style:{position:"relative",top:0,bottom:0,zIndex:0,width:"100%",height:"100%",objectFit:"cover"}})}function we({link:t,onReady:n,wrapperClassName:a="[&_video]:rounded-t-[20px] w-full h-full"}){const s=u(null),r=u(null);let i={autoplay:!0,controls:!1,responsive:!0,fluid:!0,muted:!0,navigationUI:"hide",preload:"metadata",poster:$};return o(()=>{if(!r.current&&t&&s?.current){const e=ee(s.current,{...i});e.ready(()=>{r.current=e;const a={...i,sources:[{src:t,type:"application/x-mpegURL"}]};e.autoplay(a.autoplay),e.src(a.sources),n?.(e)})}},[t,s]),o(()=>{const e=r.current;return()=>{e&&!e.isDisposed()&&(e.dispose(),r.current=null)}},[r]),e("div",{className:a,children:e("video",{ref:s,muted:!0,className:"video-js",playsInline:!0,onDrag:e=>e.preventDefault()})})}function xe({scanFailsError:a,serverAtCapacity:r=!1,onNext:o,gender:i,setScanUniqueKey:l,resolvedConfig:c,setIsVideoUploaded:u}){const{translate:m}=d(h)||{},[f,y]=s(!1),w=()=>{y(!f)};return t(n,{children:[t("div",{className:"flex flex-col h-full max-w-[28rem] mx-auto w-full rounded-t-[20px] overflow-y-auto",style:{background:c?.style?.base?.backgroundColor},children:[e("div",{className:"w-full max-w-[28rem] mx-auto pt-[1rem] px-[1rem]",children:e(p,{noTitle:!0,resolvedConfig:c})}),t("div",{className:"flex-1",children:[a&&t("div",{className:"px-[1rem]",children:[e("h2",{className:"text-center",style:{fontFamily:c?.style?.heading?.headingFontFamily||"SeriouslyNostalgic Fn",fontSize:c?.style?.heading?.headingFontSize||"32px",color:c?.style?.heading?.headingColor||"#000",fontWeight:c?.style?.heading?.headingFontWeight||"normal"},children:m?.(g.issueWithScan)}),e("p",{style:{fontFamily:c?.style?.base?.baseFontFamily||"Inter, sans-serif",fontSize:c?.style?.base?.baseFontSize||"16px",color:c?.style?.base?.baseTextColor||"#1E1E1E"},children:m?.(g.reason)}),e("p",{style:{fontFamily:c?.style?.base?.baseFontFamily||"Inter, sans-serif",fontSize:c?.style?.base?.baseFontSize||"16px",color:c?.style?.base?.baseTextColor||"#1E1E1E"},children:M(a)}),e("img",{className:"my-[0.5rem] aspect-[2/1.4] w-full object-cover",onClick:w,src:_[i],alt:"icon"})]}),r&&t("div",{className:"p-[1rem] text-center",children:[e("h3",{style:{fontFamily:c?.style?.heading?.headingFontFamily||"SeriouslyNostalgic Fn",fontSize:c?.style?.heading?.headingFontSize||"32px",color:c?.style?.heading?.headingColor||"#000",fontWeight:c?.style?.heading?.headingFontWeight||"normal"},children:m?.(g.serverAtCapacity)}),e("p",{className:"text-base mt-[0.5rem]",style:{fontFamily:c?.style?.base?.baseFontFamily||"Inter, sans-serif",fontSize:c?.style?.base?.baseFontSize||"16px",color:c?.style?.base?.baseTextColor||"#1E1E1E"},children:m?.(g.serverAtCapacityDescription)})]})]}),a&&e("div",{className:"p-[1rem] flex gap-[0.5rem]",children:e(v,{disabled:!1,buttonText:m?.(g.scanAgain),className:"!shadow-none",buttonFunc:()=>{o?o?.():l(k()),u(!1)},resolvedConfig:c})})]}),f&&t(Y,{className:"w-screen h-screen video-modal",onClose:w,open:f,children:[e("div",{className:"flex justifyEnd ",children:e("span",{className:"closeBtn",onClick:w,children:e(Q,{className:"absolute right-[8px] top-[8px] text-white z-[9]"})})}),e("div",{className:"aspect-video object-cover rounded-[20px] ",children:e(we,{link:i?U[i].PRE_LINK:U.male.PRE_LINK,wrapperClassName:"w-screen h-screen fixed top-[0] left-[0]"})})]})]})}function be({scanId:n,userDetails:a,config:i,isFaceScan:l,isVideoUploadedCorrect:c,isMeasurementAvailable:u,onScanSuccess:m,isSuccess:y}){const{gender:w,shopDomain:x,heightInCm:b,deviceFocalLength:S,userName:C,email:F,scanType:D}=a,I=[A,z,j].includes(D),[k,T]=s(!0),E=r(async()=>{try{I&&await N.auth.addUser({scanId:n,email:F,name:C,gender:w,height:b}),f.capture(x,{scanID:n,email:F,height:b,focalLength:S,clothesFit:"0",gender:w})}catch(e){console.log(e)}},[I]),{translate:L}=d(h)||{};o(()=>{c&&E()},[c]);const $=y||(l?u&&c:c||u);return e(X,{className:"flex h-full w-full flex-col ",children:t("div",{className:"h-full w-full flex-col items-center justify-center flex",children:[e(ve,{loader:i?.loader,setShowDrawer:T}),e(Z,{open:k,onClose:(e,t)=>{},className:"camera-drawer",anchor:"bottom",children:e("div",{className:"max-w-[28rem] mx-auto w-full h-full flex text-center flex-col justify-between items-center bg-primary rounded-t-[30px] p-[1rem]",style:{background:i?.style?.base?.backgroundColor},children:t("div",{className:"w-full h-full flex flex-col",children:[e(p,{title:L?.(g.measurementsBeingTaken),resolvedConfig:i}),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===R.Male?P:V,type:"video/mp4"})})}),$&&e(v,{resolvedConfig:i,className:"!w-[180px] mx-auto",buttonText:L?.(g.next),buttonFunc:m&&m})]})})})]})})}const Se=()=>{const{userDetails:a,config:s,onRetry:r,isError:i,isSuccess:l,onScanSuccess:c,gender:u,scanUniqueKey:m,scanFailsError:f,setScanUniqueKey:p,setIsVideoUploaded:g,isMeasurementAvailable:y,isVideoUploadedCorrect:v,loading:w,showDeniedModal:x,uploadLoading:S,setStartGyro:C,handleFileUpload:N,setUploadLoading:F,setScanFailsError:D,setScanStartTime:I,handleShowStreamCamera:k}=d(b),{setPreferredLanguage:T}=d(h)||{},E=q(s);return o(()=>{T?.(E?.language)},[E]),i?t(n,{children:[e(ve,{}),e(Z,{anchor:"bottom",open:!0,className:"camera-drawer",onClose:(e,t)=>{},children:e(xe,{scanFailsError:f||i,onNext:()=>{},setScanUniqueKey:p,gender:u,resolvedConfig:E,setIsVideoUploaded:g})})]}):l?e(be,{isFaceScan:!1,scanId:m,isMeasurementAvailable:y,userDetails:a,isVideoUploadedCorrect:v,config:E,isSuccess:l}):w?e("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(L,{url:E?.loader})}):x.disabled?e(ye,{}):S||f?!S&&!y||f?t(n,{children:[e(ve,{}),e(Z,{anchor:"bottom",open:!0,className:"camera-drawer",onClose:(e,t)=>{},children:e(xe,{scanFailsError:f,onNext:()=>{r?.(),k()},setScanUniqueKey:p,gender:u,resolvedConfig:E,setIsVideoUploaded:g})})]}):e(be,{isFaceScan:!1,scanId:m,isMeasurementAvailable:y,userDetails:a,onScanSuccess:c,isVideoUploadedCorrect:v,config:E}):e(ge,{config:E,scanID:m,userDetails:a,setIsVideoUploaded:g,setScanFailsError:D,setScanStartTime:I,setScanUniqueKey:p})},Ce=({userDetails:t,config:n,onRetry:a,onScanError:i,isError:l,isSuccess:c,onScanSuccess:d})=>{const{gender:u,scanType:f,shopDomain:h,heightInCm:p,email:g,deviceFocalLength:y,deviceModelName:v,callbackUrl:w}=t,[x,S]=s(!1),[C,I]=s(!1),[T,L]=s(!1),[$,_]=s({disabled:!1,message:""}),[U,A]=s(""),[z,j]=s(!1),[P,V]=s(!0),[R,q]=s(!1),[G,J]=s(""),[Q,Y]=s(D()),{gyroData:X}=function(e){const[t,n]=s([]),[a,i]=s(!1),l=r(e=>{try{const{alpha:t,beta:a,gamma:s}=e;n(e=>[...e,{alpha:t?.toString()||void 0,beta:a?.toString()||void 0,gamma:s?.toString()||void 0,timestamp:(new Date).toISOString()}])}catch(e){console.log(e)}},[]),c=r(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",l):n([]),()=>{window.removeEventListener("deviceorientation",l)}),[e,a,l]),o(()=>{e&&c()},[e,c]),{gyroData:t}}(R),Z=r(()=>{J(k()),A(""),S(!1),j(!1)},[]),ee=e=>{i({...e,message:M(e)}),te(),L(!1),A(e),I(!1),F({eventName:`${h}/measurement_failed/fit-view`,scanID:G,status:"failed",email:g,message:M(e)}),Q&&F({eventName:`${h}/scan_completion_time`,scanID:G,status:"failed",completionTime:D()-Q,email:g})},te=()=>{Y(null),J("")},ne=r(async e=>{if(e&&"success"===e?.scanStatus&&"intermediate"===e?.resultType&&200===e?.code)return void F({eventName:`${h}/measurement_success/intermediate`,scanID:G,status:"success",email:g});te();const t=G;L(!0),F({eventName:`${h}/measurement_success/fit-view`,scanID:t,status:"success",email:g}),Q&&F({eventName:`${h}/scan_completion_time`,scanID:t,status:"success",completionTime:D()-Q,email:g})},[f,h,G]),ae=e=>{L(!1),A(""),I(!1),N.measurement.handleMeasurementSocket({scanId:e||G,onOpen:()=>{H({eventName:`${h}/webSocket`,scanID:G,connection:"open",type:"measurement_recommendation",email:g})},onClose:()=>H({eventName:`${h}/webSocket`,scanID:G,connection:"close",type:"measurement_recommendation",email:g}),onError:e=>{ee(e),H({eventName:`${h}/webSocket`,scanID:G,connection:"error",type:"measurement_recommendation",email:g})},onSuccess:e=>{H({eventName:`${h}/webSocket`,scanID:G,connection:"success",type:"measurement_recommendation",email:g}),ne(e)}})},se=r(async e=>{const t=W({gender:u,focal_length:`${y}`,height:`${p}`,customer_store_url:h,clothes_fit:"0",scan_type:f,callback_url:w||"https://example.com/webhook"});F({eventName:`${h}/body_scan_meta_data`,scanID:G,email:g,data:JSON.stringify(t)});try{await N.fileUpload.uploadFileFrontend({file:e,arrayMetaData:t,scanId:G,email:g}),await N.fileUpload.setDeviceInfo({model:v,detection:"manual",gyro:X,scanId:G}),console.log("video successfully uploaded"),j(!1),F({eventName:`${h}/scan_success`,scanID:G,status:"success",email:g,data:JSON.stringify(t)}),F({eventName:"scan finished",scanID:G,status:"success",email:g}),Y(D()),setTimeout(()=>{j(!0)},3e3)}catch(e){F({eventName:"scan finished",scanID:G,status:"failed",email:g,message:M(e)}),F({eventName:`${h}/scan_failed`,scanID:G,status:"failed",email:g,message:M(e),data:JSON.stringify(t)}),A(M(e)),j(!1),console.log(e,"video upload failed")}finally{q(!1)}},[G,X]),oe=r(async e=>{try{const t=await N.measurement.getMeasurementResult(e),n=t?.data?.isMeasured,a=Q||D(),s=D(),r=300;if(V(!1),!1===n)return te(),void J(k());S(!0),!0===n?await ne(null):null===n&&a>s+r?ee(t?.data?.error):ae(e)}catch(e){console.log(e),te(),J(k()),S(!1)}},[ee,ne,J]),ie=r(async()=>{if(+p<152.4||+p>213.36)return void i({message:"Height must be between 152.4cm (5ft) and 213.36cm (7ft)"});const e=await E();if(e.disabled)F({eventName:`${h}/camera_activation`,scanID:G,status:"failed",email:g}),V(!1);else{G?oe(G):V(!1),F({eventName:`${h}/camera_activation`,scanID:G,status:"success",email:g})}_(e),A(""),j(!1)},[oe,g,G,J,h]);return o(()=>{m.init(B,{api_host:K}),m.capture("$pageview")},[]),o(()=>{l||c||h&&ie()},[h,p,l,c]),o(()=>{l||c||z&&h&&G&&ae()},[z,h,G,l,c]),e(O,{children:e(re,{children:e(b.Provider,{value:{userDetails:t,config:n,onRetry:a,onScanError:i,isError:l,isSuccess:c,onScanSuccess:d,gender:u,scanUniqueKey:G,scanFailsError:U,setScanUniqueKey:J,setIsVideoUploaded:j,isMeasurementAvailable:T,isVideoUploadedCorrect:C,loading:P,showDeniedModal:$,uploadLoading:x,setStartGyro:q,handleFileUpload:se,setUploadLoading:S,handleShowStreamCamera:Z,setScanFailsError:A,setScanStartTime:Y},children:e(Se,{})})})})};export{Ce as B};
2
+ //# sourceMappingURL=BodyScan-CW2FEtza.js.map