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