@swan-admin/swan-dev-web-component 0.1.0-alpha.1775459481 → 0.1.0-alpha.1775461549

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2 @@
1
+ import{jsx as e,jsxs as t,Fragment as n}from"react/jsx-runtime";import r,{useState as a,useCallback as s,useEffect as o,createContext as c,useLayoutEffect as i,useMemo as l,useContext as d,useRef as u}from"react";import{L as m,u as p,H as f,b as h,S as g,A as y,v,i as w,P as x,o as b,s as S,j as C,k as N,l as D,p as I,B as k,y as F,D as T,E,q as L,e as M,r as _,I as $,c as U,M as A,a as P,J as j,K as z,V,N as R,O as B,Q as q,G as K,R as O,T as W,U as H,f as J,h as G,n as Q,x as Y,W as X,t as Z,C as ee,w as te,z as ne}from"./Modal-Bcg-awuT.js";import re from"clsx";import ae from"react-webcam";import{X as se}from"lucide-react";import{Dialog as oe,Box as ce,Drawer as ie}from"@mui/material";import le from"video.js";const de="DESKTOP",ue="TAB",me="MOBILE",pe=c(void 0);function fe({children:t}){const[n,r]=a([window?.innerWidth,window?.innerHeight]),[s,c]=a(!1),d=()=>{r([window?.innerWidth,window?.innerHeight])};o(()=>{d()},[]),i(()=>(window.addEventListener("resize",d),()=>window.removeEventListener("resize",d)),[d]);let u=de;n[0]>768&&n[0]<1024&&(u=ue),n[0]<768&&(u=me);const m=l(()=>({size:n,setSize:r,clearInputs:s,setClearInputs:c,media:u}),[n,s,u]);return e(pe.Provider,{value:m,children:t})}var he=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 ge=r.memo(function({angle:n,countdown:r,isScanning:a,isInTargetRange:o,stabilityScore:c,children:i}){const{translate:u}=d(m)||{},g=p(),y=s(()=>n<80?Math.max(0,Math.min(100,10*(n-60))):n>95?Math.max(0,Math.min(100,10*(105-n))):100,[n]),v=l(()=>{if(a)return g?.style?.angleDetector?.successAngleBackground||"#4f46e5";const e=y();if(0===e)return g?.style?.angleDetector?.successAngleLowBackground||"#ffffff";if(100===e)return g?.style?.angleDetector?.successAngleBackground||"#4f46e5";return`rgb(${Math.round(255-e/100*116)}, ${Math.round(255-e/100*163)}, ${Math.round(255-e/100*9)})`},[a,y]),w=s((e,t)=>t>70?e?`text-[${g?.style?.angleDetector?.successAngleTextLightColor}]/70`:`text-[${g?.style?.angleDetector?.successAngleTextLightColor}]`:e?`text-[${g?.style?.angleDetector?.successAngleTextLightColor}]/40`:`text-[${g?.style?.angleDetector?.successAngleTextDarkColor}]/70`,[]),x=s((e=!1)=>{const t=y();return a?`text-[${g?.style?.angleDetector?.successAngleTextLightColor}]`:w(e,t)},[a,y]),b=s((e,t)=>t>70||e?g?.style?.angleDetector?.successAngleTextLightColor:g?.style?.angleDetector?.successAngleTextDarkColor,[]),S=s((e=!1)=>{const t=y();return a?g?.style?.angleDetector?.successAngleTextLightColor:b(e,t)},[a,y]),C=r;function N(){document.documentElement.style.setProperty("--real-vh",window.innerHeight+"px")}return N(),window.addEventListener("resize",N),t("div",{className:"flex common-ui-main w-screen flex-col items-center h-[var(--real-vh)] overflow-hidden touch-none justify-center transition-all duration-300 max-w-[28rem] mx-auto",style:{backgroundColor:v},children:[e("div",{className:"flex justify-start fixed top-[.5rem] max-w-[28rem] mx-auto w-full px-[1rem]",children:e("div",{className:"flex justify-start ",children:e(f,{noTitle:!0})})}),null!==C?e("div",{className:"relative flex h-[6rem] w-[6rem] items-center justify-center rounded-[9999px] bg-[#fff]/20 transition-all duration-300",style:{border:`2px solid ${S()}`},children:e("div",{className:`text-[3rem] font-bold text-[${S()}]`,style:{fontFamily:g?.style?.base?.baseFontFamily||"Inter, sans-serif",color:S()},children:C})}):t("div",a?{className:"relative flex flex-col items-center justify-center",children:[e("div",{className:"relative flex h-16 w-16 items-center justify-center rounded-[9999px] border-2 bg-[#fff]/30 border-[#fff]",children:e("div",{className:"h-4 w-4 rounded-[9999px] animate-pulse bg-[#fff]/80"})}),i]}:{className:re("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:re("mt-[.5rem] text-center w-[180px] flex-col flex items-center absolute top-[60px]",x()),style:{color:S()},children:[e(he,{size:30}),t("p",{style:{fontFamily:g?.style?.base?.baseFontFamily||"Inter, sans-serif"},children:[" ",u?.(h.startLevelCheck),e("br",{})]})]})]}),null!==C&&e("div",{className:"absolute bottom-[8rem] text-center",children:e("div",{className:re("text-sm font-medium px-4 py-1.5 bg-black/20 rounded-[9999px] mt-8",x()),style:{fontFamily:g?.style?.base?.baseFontFamily||"Inter, sans-serif",color:S()},children:u?.(h.leavePhone)})}),o&&null===C&&!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:re("text-[1.5rem] font-light",x()),style:{color:S(),fontFamily:g?.style?.base?.baseFontFamily||"Inter, sans-serif"},children:[Math.round(n),"°"]})}),null===C&&!a&&e("div",{className:"absolute bottom-[2rem] text-center max-w-[20rem] mx-auto",children:e("div",{className:re("text-[.75rem] opacity-50",x()),style:{fontFamily:g?.style?.base?.baseFontFamily||"Inter, sans-serif",color:S()},children:u?.(h.placePhoneUpright)})})]})});function ye({resetScan:n,loadingCam:r,onUserMedia:a,onPause:s,pause:o,recordingStarted:c,startSendingVideoFrames:i,showPause:l,webcamRef:u,onUserMediaError:p,resetDetector:f,videoConstraints:w,webcamKey:x}){const{media:b}=d(pe)||{},{translate:S}=d(m)||{};return t("div",{className:"App w-screen h-[100vh] relative common-ui-main",children:[e("span",{onClick:()=>{n(),f()},className:"fixed right-[20px] top-[20px] z-[999]",children:e(se,{className:"text-[#fff]"})}),e("div",{className:"w-full h-full overflow-hidden ",children:b===me&&e(ae,{audio:!1,ref:u,screenshotQuality:1,videoConstraints:w,mirrored:!0,screenshotFormat:"image/jpeg",onUserMedia:a,onUserMediaError:p,style:{position:"fixed",top:0,bottom:0,zIndex:0,width:"100%",height:"100%",objectFit:"cover"}},x)}),t("div",{className:"fixed bottom-[30px] w-full z-[999] flex flex-col gap-4 items-center justify-center",children:[l&&e(g,{className:"!w-[180px] !h-[40px] !py-[0] mx-auto ",prefix:y,buttonText:S?.(h.pause),buttonFunc:s,btnSecondary:!0}),o?e("div",{children:e(g,{className:"!w-[180px] !h-[40px] !py-[0] mx-auto",buttonText:S?.(h.restart),buttonFunc:n,btnSecondary:!0})}):c?null:e(g,{className:"!w-[180px] !h-[40px] !py-[0] mx-auto !bg-[#ffffff] !text-[#000000] "+(r?"!opacity-50":""),buttonText:S?.(h.startScan),buttonFunc:i,disabled:r})]}),e("audio",{id:"audioElement",crossOrigin:"anonymous",preload:"auto",style:{position:"absolute",zIndex:-99999},src:`${v}scanAudioInstructions/silence.mp3`})]})}let ve=null,we=null,xe=null;let be,Se=null,Ce=null;var Ne=r.memo(function({setIsScanLocked:t,resetDetector:n,scanID:r,setIsVideoUploaded:c,setScanFailsError:i,setScanStartTime:m,setScanUniqueKey:p,userDetails:f}){const{gender:h,heightInCm:g,email:y,shopDomain:$}=f,U=u(null),A=u(null),P=u(null),[j,z]=a([]),[V,R]=a(!0),[B,q]=a(!1),[K,O]=a(!1),[W,H]=a(!0),[J,G]=a(!1),Q=u(null),[Y,X]=a(""),[Z,ee]=a([]),[te,ne]=a(""),[re,ae]=a(!1),[se,oe]=a(!1),[ce,ie]=a(!1),[le,de]=a([]),[ue,me]=a(!1),pe=u(!0),{poseDetector:fe}=function(){const[e,t]=a(0),[n,r]=a(0),[s,c]=a(!1),i=u(0),l=u(0),d=u(!0);async function m(){if("undefined"==typeof window||"undefined"==typeof navigator)return!1;try{console.log("Starting TensorFlow preload...");const[e,t,n]=await Promise.all([import("./pose-detection.esm-D0xuKZKx.js"),import("@tensorflow/tfjs-core"),import("@tensorflow/tfjs-backend-webgl")]);xe=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{we=await xe.createDetector(xe.SupportedModels.BlazePose,r),console.log("MediaPipe detector created successfully")}catch(e){console.warn("MediaPipe failed, falling back to TFJS runtime:",e),we=await xe.createDetector(xe.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),ve=null,!1}}function p(e){return!(!e||0===e.length)&&22===e.filter(e=>e[2]>.7).length}return o(()=>{if(d.current=!0,!we)return ve||(ve=m()),ve.then(e=>{e&&d.current&&c(!0)}),()=>{d.current=!1};c(!0)},[]),o(()=>{l.current=e,e>6&&i.current<2&&(r(e=>e+1),t(0))},[e]),o(()=>{i.current=n},[n]),{poseDetector:async(e,n)=>{if(!we||!d.current||!n?.current?.video)return;const r=n.current.video;if(!(r.readyState<2))try{const n=await we.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()=>{we||ve||(ve=m(),await ve&&d.current&&c(!0))}}}(),he=u(!0),ge=u(!1),Ne=u(0),De=u(0),Ie=u(!1),ke=u(!1),Fe=u(()=>{}),[Te,Ee]=a([]),[Le,Me]=a(0),[_e,$e]=a(w),{setStartGyro:Ue,uploadScanFile:Ae,setUploadLoading:Pe,swan:je,onScanStart:ze,onCaptureComplete:Ve}=d(x),Re=()=>{ge.current=!1,clearTimeout(be),Q.current&&clearTimeout(Q.current),p(M()),i(""),Pe?.(!1),z([]),P.current=null,R(!0),q(!1),O(!1),H(!0),G(!1),Q.current=null,X(""),ee([]),ne(""),ae(!re),Ue(!1),S.stopAudio(),oe(!1),ie(!1),Ne.current=0,De.current=0,Ie.current=!1,ke.current=!1,null!==A.current&&A.current.stop(),le.forEach(e=>{A.current&&A.current.removeEventListener("dataavailable",e)}),de([]),pe.current=!0,me(!1),c(!1),U.current?.stream&&R(!1)},Be=s(()=>{setTimeout(()=>{R(!1)},1e3)},[]),qe=s(e=>{if(console.log("camera error",e),_e===w)return $e(b),void Me(e=>e+1);R(!1)},[_e]),Ke=s(()=>{pe.current=!1,ie(!0),me(!1),Q.current&&clearTimeout(Q.current),A.current&&A.current.pause(),S.stopAudio(),je.poseDetection.disconnect(),Ne.current=0,De.current=0,Ie.current=!1,ke.current=!1,A.current&&A.current.stop(),le.forEach(e=>{A.current&&A.current.removeEventListener("dataavailable",e)}),de([]),clearTimeout(be)},[A,le,S,pe]),Oe=l(()=>C(),[]),We=N(Te),He=D(We),Je=s(async()=>{pe.current=!0,await S.playAudio(`${v}SpotOn.mp3`),ie(!1),me(!1),Q.current&&clearTimeout(Q.current),q(!1)},[Q,S]),Ge=s(async()=>{try{Se=await je.poseDetection.connect(),console.log(Se,"websocket connected"),I.capture(`${$}/pose_detection_connected`,{scanID:r,email:y,id:Se})}catch(e){console.log(e,"while connecting websocket")}},[r,$,y]),Qe=s(async()=>{k({eventName:`${$}/rescan`,email:y,scanID:r,height:g,gender:h,status:!1}),pe.current=!1,je.poseDetection.disconnect(),Re(),await Ge(),nt()},[Ge,r,y]),Ye=s(({data:e})=>{e&&e.size>0&&pe.current&&(z(t=>t.concat(e)),!ge.current&&U.current&&(ge.current=!0,fe(()=>{Je(),F({eventName:`${$}/tensorFlow`,scanID:r,email:y,message:"recording stopped by tensorflow "})},U)))},[Je,F,$,r,y,U]),Xe=s(async()=>{Z.length>0&&pe.current&&(await S.playAudio(v+Z[Z.length-1]),pe.current&&(be=setTimeout(Xe,2e3)))},[Z,pe]),Ze=s(()=>{A&&A.current&&A.current.stop(),q(!0);try{if(U&&U.current&&U.current.stream){const e=U.current.stream.getVideoTracks()[0];if(e){const t=e.getSettings();P.current=t.frameRate||null}const t={videoBitsPerSecond:15e5};Te[0]&&(t.mimeType=Te[0]),A.current=new MediaRecorder(U.current.stream,t),A.current.addEventListener("dataavailable",Ye),de([...le,Ye]),A.current.start(1e3),H(!1)}}catch(e){console.log("error while using media recorder",e)}},[U,Te,Ye,le]),et=s(async()=>{Q.current&&clearTimeout(Q.current),Ze(),pe.current&&(Q.current=setTimeout(async()=>{pe.current&&(await S.playAudio(`${v}SpotOn.mp3`),q(!1))},15e3)),O(!0),pe.current&&await S.playAudio(`${v}Spin.mp3`)},[Ze,pe,S]);o(()=>{Fe.current=et},[et]);const tt=s(({data:e})=>{e.size>0&&je.poseDetection.connected()&&(Ie.current||(Ie.current=!0,je.poseDetection.poseStatus(async e=>{if(console.log("poseStatus data:",e),e&&e.audio&&e.audio.length>0){I.capture(`${$}/pose_instruction_received`,{scanID:r,email:y,audio:e.audio,status:e.status,sid:e.sid,counter:Ne.current,consecutiveFalse:De.current,type:"body_scan_instruction"});const t=T();!0===e.status&&e.sid===Se?(De.current=0,Ne.current<2?(Ne.current+=1,1!==Ne.current||ke.current?2===Ne.current&&t?.paused&&S.playAudio(v+e.audio):(ke.current=!0,S.stopAudio(),await S.playAudio(v+e.audio))):(ne(e.audio),clearTimeout(be),je.poseDetection.disconnect(),Ie.current=!1,setTimeout(()=>Fe.current(),1e3))):(De.current+=1,De.current>=3&&(Ne.current=0,ke.current=!1),!t?.paused||Ce&&Ce?.audioName===e.audio?Ce?.audioName===e.audio&&t?.paused&&(Ce&&Ce.no_of_times_skipped>=Ce.skipCount?(Ce.no_of_times_skipped=0,S.playAudio(v+e.audio)):Ce&&(Ce.no_of_times_skipped+=1)):(Ce={skipCount:2,no_of_times_skipped:0,audioName:e.audio},S.playAudio(v+e.audio)))}})),U?.current&&null!==U.current.getScreenshot()&&je.poseDetection.videoEmit({image:U.current.getScreenshot()||"",scanId:r}))},[U,r,je,Se,S,$,y]),nt=s(async()=>{G(!0),Ue(!0),ze?.(),he.current&&(he.current=!1,F({eventName:"scan started",scanID:r,status:"success",email:y})),m(E()),R(!0),pe.current&&await S.playAudio(`${v}StartScan.mp3`),pe.current&&await S.playAudio(`${v}LiftArmsAndHoldAtHip.mp3`),pe.current&&(G(!1),q(!0),oe(!0),me(!0),Be());try{if(U&&U.current&&U.current.stream&&pe.current){const e=U.current.stream.getVideoTracks()[0];if(e){const t=e.getSettings();P.current=t.frameRate||null}const t={videoBitsPerSecond:15e5};Te[0]&&(t.mimeType=Te[0]),pe.current&&(A.current=new MediaRecorder(U.current.stream,t)),pe.current&&A.current&&A.current.addEventListener("dataavailable",tt),de([...le,tt]),A.current&&A.current.start(1e3),H(!1),pe.current&&(be=setTimeout(Xe,2e3))}}catch(e){console.log("error ----------",e)}},[U,Te,tt,le,Xe,pe,ze]);return o(()=>($&&(t(!0),Ge()),()=>{Se&&(je.poseDetection.disconnect(),I.capture(`${$}/pose_detection_disconnected`,{scanID:r,email:y,id:Se})),le.forEach(e=>{A?.current?.removeEventListener("dataavailable",e)})}),[$]),o(()=>{Z.push(Y)},[Y]),o(()=>{ee([])},[te]),o(()=>{const e=j.length&&j.length>0;W||!e||B||!pe.current||ce||A&&A.current&&(B||(A.current.stop(),H(!0)))},[W,B,j,ce]),o(()=>{const e=j.length&&j.length>0;if(W||!e||B)console.log("No video found to upload.");else if(A&&A.current&&pe.current&&!ce&&!B){const e=new File(j,`${r}.${He}`,{type:We});Ve?.(),Pe?.(!0),i(""),Ae?.(e,P.current)}},[W,B,j,ce,A,pe]),o(()=>{const e=L(Oe,_);Ee(e)},[Oe]),o(()=>{Re()},[]),e(ye,{resetDetector:n,resetScan:Re,loadingCam:V,onPause:Ke,showRestart:se,pause:ce,onReScan:Qe,recordingStarted:B,isScanning:J,startSendingVideoFrames:nt,faceDone:K,stopRecording:Je,showPause:ue,webcamRef:U,onUserMedia:Be,onUserMediaError:qe,videoConstraints:_e,webcamKey:Le})});function De({scanID:t,userDetails:n,setIsVideoUploaded:r,setScanFailsError:s,setScanStartTime:c,setScanUniqueKey:i}){const[l,d]=a(90),[m,p]=a(0),[f,h]=a(null),[g,y]=a(!1),[v,w]=a(0),x=u([]),[b,S]=a(!1),C=l-m,N=C>=80&&C<=95;o(()=>{if("undefined"!=typeof window&&window.DeviceOrientationEvent){const e=e=>{if(null!==e.beta){let t=Math.abs(e.beta);null!==e.gamma&&(t*=Math.cos(e.gamma*Math.PI/180)),t=Math.max(0,Math.min(180,t)),d(t)}},t=async()=>{const t=DeviceOrientationEvent;if(t&&"function"==typeof t.requestPermission)try{"granted"===await t.requestPermission()&&window.addEventListener("deviceorientation",e)}catch(e){console.error("Permission error",e)}else window.addEventListener("deviceorientation",e);return()=>{e&&window.removeEventListener("deviceorientation",e)}};document.addEventListener("click",t,{once:!0})}},[]),o(()=>{if(x.current=[...x.current.slice(-4),C],x.current.length>=5){const e=Math.max(...x.current)-Math.min(...x.current);w(N&&e<2?e=>Math.min(100,e+10):e=>Math.max(0,e-20))}N||null===f&&!g||I()},[C,N,f,g]),o(()=>{v>=100&&null===f&&!g&&D(),v<50&&null!==f&&I()},[v,f,g]);const D=()=>{h(3);const e=setInterval(()=>{h(t=>null===t||t<=1?(clearInterval(e),y(!0),null):t-1)},1e3)},I=()=>{h(null),b||y(!1)};return e(ge,{angle:C,countdown:f,isScanning:g,isInTargetRange:N,stabilityScore:v,children:g&&e(Ne,{setIsScanLocked:S,resetDetector:()=>{d(90),p(0),h(null),y(!1),w(0),S(!1),x.current=[]},scanID:t,userDetails:n,setIsVideoUploaded:r,setScanFailsError:s,setScanStartTime:c,setScanUniqueKey:i})})}function Ie({setShowDrawer:t,config:n,loader:r}){const[c,i]=a({disabled:!1,message:""}),[l,d]=a(!0),m=u(null),p=s(async()=>{const e=await $();i(e),d(!1)},[]);return o(()=>{p()},[]),l?e(U,{url:r,loaderType:"black"}):c?.disabled?e(A,{config:n,message:c?.message}):e(ae,{audio:!1,ref:m,screenshotQuality:1,videoConstraints:P,mirrored:!0,onUserMedia:()=>t?.(!0),screenshotFormat:"image/jpeg",style:{position:"relative",top:0,bottom:0,zIndex:0,width:"100%",height:"100%",objectFit:"cover"}})}function ke({link:t,onReady:n,wrapperClassName:r="[&_video]:rounded-t-[20px] w-full h-full"}){const a=u(null),s=u(null);let c={autoplay:!0,controls:!1,responsive:!0,fluid:!0,muted:!0,navigationUI:"hide",preload:"metadata",poster:j};return o(()=>{if(!s.current&&t&&a?.current){const e=le(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 Fe({scanFailsError:r,onNext:s,gender:o,setScanUniqueKey:c,setIsVideoUploaded:i}){const{translate:l}=d(m)||{},u=p(),[y,v]=a(!1),w=()=>{v(!y)};return t(n,{children:[t("div",{className:"flex common-ui-main flex-col h-full max-w-[28rem] mx-auto w-full rounded-t-[20px] overflow-y-auto",style:{background:u?.style?.base?.backgroundColor},children:[e("div",{className:"w-full max-w-[28rem] mx-auto pt-[1rem] px-[1rem]",children:e(f,{noTitle:!0})}),e("div",{className:"flex-1",children:r&&t("div",{className:"px-[1rem]",children:[e("h2",{className:"text-center",style:{fontFamily:u?.style?.heading?.headingFontFamily||"SeriouslyNostalgic Fn",fontSize:u?.style?.heading?.headingFontSize||"32px",color:u?.style?.heading?.headingColor||"#000",fontWeight:u?.style?.heading?.headingFontWeight||"normal"},children:l?.(h.issueWithScan)}),e("p",{style:{fontFamily:u?.style?.base?.baseFontFamily||"Inter, sans-serif",fontSize:u?.style?.base?.baseFontSize||"16px",color:u?.style?.base?.baseTextColor||"#1E1E1E"},children:l?.(h.reason)}),e("p",{style:{fontFamily:u?.style?.base?.baseFontFamily||"Inter, sans-serif",fontSize:u?.style?.base?.baseFontSize||"16px",color:u?.style?.base?.baseTextColor||"#1E1E1E"},children:z(r)}),e("img",{className:"my-[0.5rem] aspect-[2/1.4] w-full object-cover",onClick:w,src:V[o],alt:"icon"})]})}),r&&e("div",{className:"p-[1rem] flex gap-[0.5rem]",children:e(g,{disabled:!1,buttonText:l?.(h.scanAgain),className:"!shadow-none",buttonFunc:()=>{s?s?.():c?.(M()),i?.(!1)}})})]}),y&&t(oe,{className:"w-screen h-screen video-modal",onClose:w,open:y,disablePortal:!0,children:[e("div",{className:"flex justifyEnd ",children:e("span",{className:"closeBtn",onClick:w,children:e(se,{className:"absolute right-[8px] top-[8px] text-white z-[9]"})})}),e("div",{className:"aspect-video object-cover rounded-[20px] ",children:e(ke,{link:o?R[o].PRE_LINK:R.male.PRE_LINK,wrapperClassName:"w-screen h-screen fixed top-[0] left-[0]"})})]})]})}function Te({scanId:n,userDetails:r,config:c,isVideoUploadedCorrect:i,isMeasurementAvailable:l,onComplete:u,isSuccess:p,onCustomScanSuccess:y,swan:v}){const{gender:w,shopDomain:x,heightInCm:b,deviceFocalLength:S,userName:C,email:N,scanType:D}=r||{},k=[O,W,H].includes(D??""),[F,T]=a(!0),E=s(async()=>{try{k&&(await(v?.auth.addUser({scanId:n,email:N,name:C,gender:w,height:b})),y?.()),I.capture(x??"",{scanID:n,email:N,height:b,focalLength:S,clothesFit:"0",gender:w})}catch(e){console.log(e)}},[k]),{translate:L}=d(m)||{};o(()=>{(i||l)&&E()},[i,l]);const M=p||i||l;return e(ce,{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(Ie,{loader:c?.loader,setShowDrawer:T}),e(ie,{open:F,onClose:(e,t)=>{},disablePortal:!0,className:"camera-drawer",anchor:"bottom",children:e("div",{className:"max-w-[28rem] mx-auto w-full h-full flex text-center flex-col justify-between items-center bg-primary rounded-t-[30px] p-[1rem] common-ui-main overflow-y-auto",style:{background:c?.style?.base?.backgroundColor},children:t("div",{className:"w-full flex-1 flex flex-col min-h-[400px]",children:[e(f,{title:L?.(h.measurementsBeingTaken)}),e("div",{className:"flex items-center justify-center flex-1",children:e("video",{preload:"auto",className:"max-h-[calc(100vh-450px)] mx-auto w-full object-contain border-none min-h-[170px]",muted:!0,loop:!0,autoPlay:!0,playsInline:!0,children:e("source",{src:w===K.Male?B:q,type:"video/mp4"})})}),M&&e(g,{className:"!w-[180px] mx-auto",buttonText:L?.(h.next),buttonFunc:()=>{u?.()}})]})})})]})})}const Ee=()=>{const{userDetails:r,onRetry:a,isError:s,isSuccess:o,gender:c,scanUniqueKey:i,scanFailsError:l,setScanUniqueKey:u,setIsVideoUploaded:m,isMeasurementAvailable:f,isVideoUploadedCorrect:h,loading:g,showDeniedModal:y,uploadLoading:v,isLandscape:w,setScanFailsError:b,setScanStartTime:S,resetScan:C,onCustomScanSuccess:N,swan:D,onComplete:I}=d(x),k=p();return s?t(n,{children:[e(Ie,{}),e(ie,{anchor:"bottom",open:!0,className:"camera-drawer",onClose:(e,t)=>{},disablePortal:!0,children:e(Fe,{scanFailsError:!0,onNext:a,gender:c})})]}):o?e(Te,{isSuccess:!0,onComplete:I,config:k}):g?e("div",{className:"flex top-0 !mt-0 left-0 z-[999] absolute justify-center items-center w-full h-full",style:{background:k?.style?.base?.backgroundColor},children:e(U,{url:k?.loader,loaderType:"black"})}):!w||v||l?y.disabled?e(A,{}):v||l||f||h?(v||f||h)&&!l?e(Te,{scanId:i,isMeasurementAvailable:f,userDetails:r,isVideoUploadedCorrect:h,onCustomScanSuccess:N,swan:D,onComplete:I,config:k}):t(n,{children:[e(Ie,{}),e(ie,{anchor:"bottom",open:!0,className:"camera-drawer",onClose:(e,t)=>{},disablePortal:!0,children:e(Fe,{scanFailsError:l,onNext:()=>{a?.(),C()},setScanUniqueKey:u,gender:c,setIsVideoUploaded:m})})]}):e(De,{scanID:i,userDetails:r,setIsVideoUploaded:m,setScanFailsError:b,setScanStartTime:S,setScanUniqueKey:u}):e(A,{variant:"portrait",config:k})},Le=t=>{const{config:n,onRetry:r,onScanStart:c,onCaptureComplete:i,onUploadStart:d,onUploadEnd:m,onMeasurementSocketStart:p,onMeasurementSocketClose:f,onIntermediateScanSuccess:h,onScanError:g,onScanSuccess:y,onCustomScanSuccess:v,onComplete:w,isError:b,isSuccess:C}=t,N={email:"",shopDomain:"",gender:"male",heightInCm:0,scanType:"",deviceFocalLength:0,deviceModelName:"",sourceTag:"",...t.userDetails??{}},D=t.token??"",{gender:I,scanType:k,shopDomain:T,heightInCm:L,email:_,deviceFocalLength:U,deviceModelName:A,callbackUrl:P,sourceTag:j}=N,V=l(()=>J(D),[D]),[R,B]=a(!1),[q,K]=a(!1),[O,W]=a(!1),[H,re]=a({disabled:!1,message:""}),[ae,se]=a(""),[oe,ce]=a(!1),[ie,le]=a(!0),[de,ue]=a(!1),[me,pe]=a(""),[he,ge]=a(E()),{gyroData:ye}=function(e){const[t,n]=a([]),[r,c]=a(!1),i=s(e=>{try{const{alpha:t,beta:r,gamma:a}=e;n(e=>[...e,{alpha:t?.toString()||void 0,beta:r?.toString()||void 0,gamma:a?.toString()||void 0,timestamp:(new Date).toISOString()}])}catch(e){console.log(e)}},[]),l=s(async()=>{const e=DeviceOrientationEvent;if(void 0!==e&&"function"==typeof e.requestPermission)try{"granted"===await e.requestPermission()?c(!0):console.warn("Device orientation permission denied.")}catch(e){console.error("Error requesting device orientation permission:",e)}else c(!0)},[]);return o(()=>(e&&r?window.addEventListener("deviceorientation",i):n([]),()=>{window.removeEventListener("deviceorientation",i)}),[e,r,i]),o(()=>{e&&l()},[e,l]),{gyroData:t}}(de),{isLandscape:ve}=G();Q();const we=s(()=>{pe(M()),se(""),B(!1),ce(!1)},[]),xe=u(!1);o(()=>{!ve||xe.current||R||b||C||ae||(S.stopAudio(),we()),xe.current=ve},[ve,R,b,C,ae,we]);const be=()=>{ge(null),pe("")},Se=s(async e=>{if(e&&"success"===e?.scanStatus&&"intermediate"===e?.resultType&&200===e?.code)return F({eventName:`${T}/measurement_success/intermediate`,scanID:me,status:"success",email:_}),K(!0),void h?.(e);y?.(e),K(!0),be();const t=me;W(!0),F({eventName:`${T}/measurement_success/fit-view`,scanID:t,status:"success",email:_}),he&&F({eventName:`${T}/scan_completion_time`,scanID:t,status:"success",completionTime:E()-he,email:_})},[k,T,me]),Ce=e=>{W(!1),se(""),K(!1),V.measurement.handleMeasurementSocket({scanId:me,onPreopen:()=>{ne({eventName:`${T}/webSocket`,scanID:me,connection:"pre_open",type:"measurement_recommendation",email:_})},onOpen:()=>{p?.(),ne({eventName:`${T}/webSocket`,scanID:me,connection:"open",type:"measurement_recommendation",email:_})},onClose:()=>{f?.(),ne({eventName:`${T}/webSocket`,scanID:me,connection:"close",type:"measurement_recommendation",email:_})},onError:e=>{var t;t=e,g?.({...t,message:z(t)}),be(),W(!1),se(t),K(!1),F({eventName:`${T}/measurement_failed/fit-view`,scanID:me,status:"failed",email:_,message:z(t)}),he&&F({eventName:`${T}/scan_completion_time`,scanID:me,status:"failed",completionTime:E()-he,email:_}),ne({eventName:`${T}/webSocket`,scanID:me,connection:"error",type:"measurement_recommendation",email:_})},onSuccess:e=>{ne({eventName:`${T}/webSocket`,scanID:me,connection:"success",type:"measurement_recommendation",email:_}),Se(e)}})},Ne=s(async(e,t)=>{const n=Number((e.size/1048576).toFixed(2)),r=null!=t?t:await Y(e),a=X({gender:I,focal_length:`${U}`,height:`${L}`,customer_store_url:T,clothes_fit:"0",scan_type:k,callback_url:P,source_tag:j});F({eventName:`${T}/body_scan_meta_data`,scanID:me,email:_,data:JSON.stringify([...a,{fileSizeInMB:n,video_fps:r||0}])}),d?.();try{await V.fileUpload.uploadFileFrontend({file:e,arrayMetaData:a,scanId:me,email:_}),await V.fileUpload.setDeviceInfo({model:A,detection:"manual",gyro:ye,scanId:me}),console.log("video successfully uploaded"),ce(!1),F({eventName:`${T}/scan_success`,scanID:me,status:"success",email:_,data:JSON.stringify(a)}),F({eventName:"scan finished",scanID:me,status:"success",email:_}),ge(E()),setTimeout(()=>{ce(!0)},3e3)}catch(e){F({eventName:"scan finished",scanID:me,status:"failed",email:_,message:z(e)}),F({eventName:`${T}/scan_failed`,scanID:me,status:"failed",email:_,message:z(e),data:JSON.stringify(a)}),se(z(e)),ce(!1),g?.({...e,message:z(e)}),be()}finally{ue(!1),m?.()}},[me,ye,d,m]),De=s(async()=>{if(+L<152.4||+L>213.36)return void g?.({message:"Height must be between 152.4cm (5ft) and 213.36cm (7ft)"});const e=await $();e.disabled?(F({eventName:`${T}/camera_activation`,scanID:me,status:"failed",email:_}),le(!1)):(le(!1),F({eventName:`${T}/camera_activation`,scanID:me,status:"success",email:_})),re(e),se(""),ce(!1)},[_,me,pe,T]);return o(()=>{b||C||T&&De()},[T,L,b,C]),o(()=>{b||C||oe&&T&&me&&Ce()},[oe,T,me,b,C]),e(Z,{children:e(ee,{config:n,children:e(fe,{children:e(x.Provider,{value:{userDetails:N,onRetry:r,onScanError:g,isError:b,isSuccess:C,onScanSuccess:y,gender:I,scanUniqueKey:me,scanFailsError:ae,setScanUniqueKey:pe,setIsVideoUploaded:ce,isMeasurementAvailable:O,isVideoUploadedCorrect:q,loading:ie,showDeniedModal:H,uploadLoading:R,isLandscape:ve,setStartGyro:ue,uploadScanFile:Ne,setUploadLoading:B,resetScan:we,setScanFailsError:se,setScanStartTime:ge,onScanStart:c,onCaptureComplete:i,onCustomScanSuccess:v,onComplete:w,swan:V},children:e(te,{children:e(Ee,{})})})})})})};export{Le as B};
2
+ //# sourceMappingURL=BodyScan-CUUJUjcv.js.map
@@ -0,0 +1,2 @@
1
+ "use strict";var e=require("react/jsx-runtime"),t=require("react"),s=require("./Modal-DexL716x.js"),n=require("clsx"),a=require("react-webcam"),r=require("lucide-react"),o=require("@mui/material"),c=require("video.js");const i="DESKTOP",l="TAB",u="MOBILE",d=t.createContext(void 0);function m({children:s}){const[n,a]=t.useState([window?.innerWidth,window?.innerHeight]),[r,o]=t.useState(!1),c=()=>{a([window?.innerWidth,window?.innerHeight])};t.useEffect(()=>{c()},[]),t.useLayoutEffect(()=>(window.addEventListener("resize",c),()=>window.removeEventListener("resize",c)),[c]);let m=i;n[0]>768&&n[0]<1024&&(m=l),n[0]<768&&(m=u);const p=t.useMemo(()=>({size:n,setSize:a,clearInputs:r,setClearInputs:o,media:m}),[n,r,m]);return e.jsx(d.Provider,{value:p,children:s})}var p=t.memo(function({size:t=16}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 25 25",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[e.jsx("path",{d:"M22.6968 14.6968C22.6968 16.8185 21.8539 18.8533 20.3536 20.3536C18.8533 21.8539 16.8185 22.6968 14.6968 22.6968",stroke:"white",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),e.jsx("path",{d:"M18.6968 11.6968V10.6968C18.6968 10.1663 18.4861 9.65764 18.111 9.28256C17.7359 8.90749 17.2272 8.69678 16.6968 8.69678C16.1663 8.69678 15.6576 8.90749 15.2826 9.28256C14.9075 9.65764 14.6968 10.1663 14.6968 10.6968",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),e.jsx("path",{d:"M14.6968 10.6968V9.69678C14.6968 9.16634 14.4861 8.65764 14.111 8.28256C13.7359 7.90749 13.2272 7.69678 12.6968 7.69678C12.1663 7.69678 11.6576 7.90749 11.2826 8.28256C10.9075 8.65764 10.6968 9.16634 10.6968 9.69678V10.6968",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),e.jsx("path",{d:"M10.6968 10.1968V4.69678C10.6968 4.16634 10.4861 3.65764 10.111 3.28256C9.73592 2.90749 9.22721 2.69678 8.69678 2.69678C8.16634 2.69678 7.65764 2.90749 7.28256 3.28256C6.90749 3.65764 6.69678 4.16634 6.69678 4.69678V14.6968",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),e.jsx("path",{d:"M18.6969 11.6968C18.6969 11.1663 18.9076 10.6576 19.2827 10.2826C19.6577 9.90749 20.1664 9.69678 20.6969 9.69678C21.2273 9.69678 21.736 9.90749 22.1111 10.2826C22.4862 10.6576 22.6969 11.1663 22.6969 11.6968V14.6968C22.6969 16.8185 21.854 18.8533 20.3537 20.3536C18.8534 21.8539 16.8186 22.6968 14.6969 22.6968H12.6969C9.89688 22.6968 8.19688 21.8368 6.70688 20.3568L3.10688 16.7568C2.76282 16.3757 2.57847 15.8769 2.592 15.3637C2.60554 14.8505 2.81593 14.3621 3.1796 13.9997C3.54327 13.6373 4.03238 13.4287 4.54565 13.417C5.05892 13.4053 5.55704 13.5914 5.93688 13.9368L7.69688 15.6968",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]})});var f=t.memo(function({angle:a,countdown:r,isScanning:o,isInTargetRange:c,stabilityScore:i,children:l}){const{translate:u}=t.useContext(s.LanguageContext)||{},d=s.useConfig(),m=t.useCallback(()=>a<80?Math.max(0,Math.min(100,10*(a-60))):a>95?Math.max(0,Math.min(100,10*(105-a))):100,[a]),f=t.useMemo(()=>{if(o)return d?.style?.angleDetector?.successAngleBackground||"#4f46e5";const e=m();if(0===e)return d?.style?.angleDetector?.successAngleLowBackground||"#ffffff";if(100===e)return d?.style?.angleDetector?.successAngleBackground||"#4f46e5";return`rgb(${Math.round(255-e/100*116)}, ${Math.round(255-e/100*163)}, ${Math.round(255-e/100*9)})`},[o,m]),h=t.useCallback((e,t)=>t>70?e?`text-[${d?.style?.angleDetector?.successAngleTextLightColor}]/70`:`text-[${d?.style?.angleDetector?.successAngleTextLightColor}]`:e?`text-[${d?.style?.angleDetector?.successAngleTextLightColor}]/40`:`text-[${d?.style?.angleDetector?.successAngleTextDarkColor}]/70`,[]),g=t.useCallback((e=!1)=>{const t=m();return o?`text-[${d?.style?.angleDetector?.successAngleTextLightColor}]`:h(e,t)},[o,m]),x=t.useCallback((e,t)=>t>70||e?d?.style?.angleDetector?.successAngleTextLightColor:d?.style?.angleDetector?.successAngleTextDarkColor,[]),S=t.useCallback((e=!1)=>{const t=m();return o?d?.style?.angleDetector?.successAngleTextLightColor:x(e,t)},[o,m]),v=r;function y(){document.documentElement.style.setProperty("--real-vh",window.innerHeight+"px")}return y(),window.addEventListener("resize",y),e.jsxs("div",{className:"flex common-ui-main w-screen flex-col items-center h-[var(--real-vh)] overflow-hidden touch-none justify-center transition-all duration-300 max-w-[28rem] mx-auto",style:{backgroundColor:f},children:[e.jsx("div",{className:"flex justify-start fixed top-[.5rem] max-w-[28rem] mx-auto w-full px-[1rem]",children:e.jsx("div",{className:"flex justify-start ",children:e.jsx(s.Header,{noTitle:!0})})}),null!==v?e.jsx("div",{className:"relative flex h-[6rem] w-[6rem] items-center justify-center rounded-[9999px] bg-[#fff]/20 transition-all duration-300",style:{border:`2px solid ${S()}`},children:e.jsx("div",{className:`text-[3rem] font-bold text-[${S()}]`,style:{fontFamily:d?.style?.base?.baseFontFamily||"Inter, sans-serif",color:S()},children:v})}):o?e.jsxs("div",{className:"relative flex flex-col items-center justify-center",children:[e.jsx("div",{className:"relative flex h-16 w-16 items-center justify-center rounded-[9999px] border-2 bg-[#fff]/30 border-[#fff]",children:e.jsx("div",{className:"h-4 w-4 rounded-[9999px] animate-pulse bg-[#fff]/80"})}),l]}):e.jsxs("div",{className:n("relative flex h-[4rem] w-[4rem] items-center justify-center rounded-[9999px] ",c?"bg-[#fff]/20 border-[#fff]":"bg-[#fff]/10 border-[#fff]"),style:{transform:`translateY(${3*(90-a)}px)`,transition:"transform 0.2s ease-out",border:`2px solid ${S()}`},children:[e.jsx("div",{className:`h-[1rem] w-[1rem] rounded-[9999px] bg-[${S()}]/80`,style:{backgroundColor:`${S()}B3`}}),e.jsxs("div",{className:n("mt-[.5rem] text-center w-[180px] flex-col flex items-center absolute top-[60px]",g()),style:{color:S()},children:[e.jsx(p,{size:30}),e.jsxs("p",{style:{fontFamily:d?.style?.base?.baseFontFamily||"Inter, sans-serif"},children:[" ",u?.(s.LanguageKeys.startLevelCheck),e.jsx("br",{})]})]})]}),null!==v&&e.jsx("div",{className:"absolute bottom-[8rem] text-center",children:e.jsx("div",{className:n("text-sm font-medium px-4 py-1.5 bg-black/20 rounded-[9999px] mt-8",g()),style:{fontFamily:d?.style?.base?.baseFontFamily||"Inter, sans-serif",color:S()},children:u?.(s.LanguageKeys.leavePhone)})}),c&&null===v&&!o&&e.jsx("div",{className:"absolute bottom-[8rem] w-[12rem]",children:e.jsx("div",{className:`h-[.375rem] w-full bg-[${S()}]/20 rounded-[9999px] overflow-hidden`,style:{backgroundColor:`${S()}33`},children:e.jsx("div",{className:`h-full bg-[${S()}]/70 transition-all duration-300 rounded-[9999px]`,style:{width:`${a}%`,backgroundColor:`${S()}B3`}})})}),null===v&&!o&&e.jsx("div",{className:"absolute bottom-[5rem] text-center",children:e.jsxs("div",{className:n("text-[1.5rem] font-light",g()),style:{color:S(),fontFamily:d?.style?.base?.baseFontFamily||"Inter, sans-serif"},children:[Math.round(a),"°"]})}),null===v&&!o&&e.jsx("div",{className:"absolute bottom-[2rem] text-center max-w-[20rem] mx-auto",children:e.jsx("div",{className:n("text-[.75rem] opacity-50",g()),style:{fontFamily:d?.style?.base?.baseFontFamily||"Inter, sans-serif",color:S()},children:u?.(s.LanguageKeys.placePhoneUpright)})})]})});function h({resetScan:n,loadingCam:o,onUserMedia:c,onPause:i,pause:l,recordingStarted:m,startSendingVideoFrames:p,showPause:f,webcamRef:h,onUserMediaError:g,resetDetector:x,videoConstraints:S,webcamKey:v}){const{media:y}=t.useContext(d)||{},{translate:b}=t.useContext(s.LanguageContext)||{};return e.jsxs("div",{className:"App w-screen h-[100vh] relative common-ui-main",children:[e.jsx("span",{onClick:()=>{n(),x()},className:"fixed right-[20px] top-[20px] z-[999]",children:e.jsx(r.X,{className:"text-[#fff]"})}),e.jsx("div",{className:"w-full h-full overflow-hidden ",children:y===u&&e.jsx(a,{audio:!1,ref:h,screenshotQuality:1,videoConstraints:S,mirrored:!0,screenshotFormat:"image/jpeg",onUserMedia:c,onUserMediaError:g,style:{position:"fixed",top:0,bottom:0,zIndex:0,width:"100%",height:"100%",objectFit:"cover"}},v)}),e.jsxs("div",{className:"fixed bottom-[30px] w-full z-[999] flex flex-col gap-4 items-center justify-center",children:[f&&e.jsx(s.SpecificButton,{className:"!w-[180px] !h-[40px] !py-[0] mx-auto ",prefix:s.pauseIcon,buttonText:b?.(s.LanguageKeys.pause),buttonFunc:i,btnSecondary:!0}),l?e.jsx("div",{children:e.jsx(s.SpecificButton,{className:"!w-[180px] !h-[40px] !py-[0] mx-auto",buttonText:b?.(s.LanguageKeys.restart),buttonFunc:n,btnSecondary:!0})}):m?null:e.jsx(s.SpecificButton,{className:"!w-[180px] !h-[40px] !py-[0] mx-auto !bg-[#ffffff] !text-[#000000] "+(o?"!opacity-50":""),buttonText:b?.(s.LanguageKeys.startScan),buttonFunc:p,disabled:o})]}),e.jsx("audio",{id:"audioElement",crossOrigin:"anonymous",preload:"auto",style:{position:"absolute",zIndex:-99999},src:`${s.voiceOverAssetsPath}scanAudioInstructions/silence.mp3`})]})}let g=null,x=null,S=null;let v,y=null,b=null;var C=t.memo(function({setIsScanLocked:n,resetDetector:a,scanID:r,setIsVideoUploaded:o,setScanFailsError:c,setScanStartTime:i,setScanUniqueKey:l,userDetails:u}){const{gender:d,heightInCm:m,email:p,shopDomain:f}=u,C=t.useRef(null),w=t.useRef(null),j=t.useRef(null),[k,N]=t.useState([]),[E,D]=t.useState(!0),[T,I]=t.useState(!1),[L,F]=t.useState(!1),[M,P]=t.useState(!0),[_,A]=t.useState(!1),$=t.useRef(null),[R,U]=t.useState(""),[O,z]=t.useState([]),[K,B]=t.useState(""),[q,V]=t.useState(!1),[W,H]=t.useState(!1),[G,J]=t.useState(!1),[Q,X]=t.useState([]),[Y,Z]=t.useState(!1),ee=t.useRef(!0),{poseDetector:te}=function(){const[e,s]=t.useState(0),[n,a]=t.useState(0),[r,o]=t.useState(!1),c=t.useRef(0),i=t.useRef(0),l=t.useRef(!0);async function u(){if("undefined"==typeof window||"undefined"==typeof navigator)return!1;try{console.log("Starting TensorFlow preload...");const[e,t,s]=await Promise.all([Promise.resolve().then(function(){return require("./pose-detection.esm-LbnXZ-R6.js")}),import("@tensorflow/tfjs-core"),import("@tensorflow/tfjs-backend-webgl")]);S=e,await t.setBackend("webgl"),await t.ready(),console.log("TensorFlow backend ready (WebGL)");const n={runtime:"mediapipe",modelType:"full",solutionPath:"https://cdn.jsdelivr.net/npm/@mediapipe/pose"};try{x=await S.createDetector(S.SupportedModels.BlazePose,n),console.log("MediaPipe detector created successfully")}catch(e){console.warn("MediaPipe failed, falling back to TFJS runtime:",e),x=await S.createDetector(S.SupportedModels.BlazePose,{runtime:"tfjs",modelType:"full"}),console.log("TFJS detector created successfully")}return!0}catch(e){return console.error("Failed to load TensorFlow dependencies:",e),g=null,!1}}function d(e){return!(!e||0===e.length)&&22===e.filter(e=>e[2]>.7).length}return t.useEffect(()=>{if(l.current=!0,!x)return g||(g=u()),g.then(e=>{e&&l.current&&o(!0)}),()=>{l.current=!1};o(!0)},[]),t.useEffect(()=>{i.current=e,e>6&&c.current<2&&(a(e=>e+1),s(0))},[e]),t.useEffect(()=>{c.current=n},[n]),{poseDetector:async(e,t)=>{if(!x||!l.current||!t?.current?.video)return;const n=t.current.video;if(!(n.readyState<2))try{const t=await x.estimatePoses(n,{flipHorizontal:!1});if(!t||!t.length)return;const a=t[0].keypoints.slice(11).map(e=>[e.x>0&&e.x<720?e.x:-1,e.y>0&&e.y<1280?e.y:-1,e.score??0]);0!==c.current||d(a)||s(e=>e+1),1===c.current&&d(a)&&s(e=>e+1),2===c.current&&e()}catch(e){console.error("Pose detection error:",e)}},isLoaded:r,spinPhase:n,resetDetector:()=>{c.current=0,i.current=0,s(0),a(0)},retryLoading:async()=>{x||g||(g=u(),await g&&l.current&&o(!0))}}}(),se=t.useRef(!0),ne=t.useRef(!1),ae=t.useRef(0),re=t.useRef(0),oe=t.useRef(!1),ce=t.useRef(!1),ie=t.useRef(()=>{}),[le,ue]=t.useState([]),[de,me]=t.useState(0),[pe,fe]=t.useState(s.videoConstraintsExact),{setStartGyro:he,uploadScanFile:ge,setUploadLoading:xe,swan:Se,onScanStart:ve,onCaptureComplete:ye}=t.useContext(s.ParamsContext),be=()=>{ne.current=!1,clearTimeout(v),$.current&&clearTimeout($.current),l(s.generateUuid()),c(""),xe?.(!1),N([]),j.current=null,D(!0),I(!1),F(!1),P(!0),A(!1),$.current=null,U(""),z([]),B(""),V(!q),he(!1),s.speechService.stopAudio(),H(!1),J(!1),ae.current=0,re.current=0,oe.current=!1,ce.current=!1,null!==w.current&&w.current.stop(),Q.forEach(e=>{w.current&&w.current.removeEventListener("dataavailable",e)}),X([]),ee.current=!0,Z(!1),o(!1),C.current?.stream&&D(!1)},Ce=t.useCallback(()=>{setTimeout(()=>{D(!1)},1e3)},[]),we=t.useCallback(e=>{if(console.log("camera error",e),pe===s.videoConstraintsExact)return fe(s.videoConstraintsFallback),void me(e=>e+1);D(!1)},[pe]),je=t.useCallback(()=>{ee.current=!1,J(!0),Z(!1),$.current&&clearTimeout($.current),w.current&&w.current.pause(),s.speechService.stopAudio(),Se.poseDetection.disconnect(),ae.current=0,re.current=0,oe.current=!1,ce.current=!1,w.current&&w.current.stop(),Q.forEach(e=>{w.current&&w.current.removeEventListener("dataavailable",e)}),X([]),clearTimeout(v)},[w,Q,s.speechService,ee]),ke=t.useMemo(()=>s.getPreferredMediaRecorderTypes(),[]),Ne=s.getRecordingMimeType(le),Ee=s.getRecordingExtension(Ne),De=t.useCallback(async()=>{ee.current=!0,await s.speechService.playAudio(`${s.voiceOverAssetsPath}SpotOn.mp3`),J(!1),Z(!1),$.current&&clearTimeout($.current),I(!1)},[$,s.speechService]),Te=t.useCallback(async()=>{try{y=await Se.poseDetection.connect(),console.log(y,"websocket connected"),s.posthog.capture(`${f}/pose_detection_connected`,{scanID:r,email:p,id:y})}catch(e){console.log(e,"while connecting websocket")}},[r,f,p]),Ie=t.useCallback(async()=>{s.rescanSupportCaptureEvent({eventName:`${f}/rescan`,email:p,scanID:r,height:m,gender:d,status:!1}),ee.current=!1,Se.poseDetection.disconnect(),be(),await Te(),Ae()},[Te,r,p]),Le=t.useCallback(({data:e})=>{e&&e.size>0&&ee.current&&(N(t=>t.concat(e)),!ne.current&&C.current&&(ne.current=!0,te(()=>{De(),s.handleScanTimeCapture({eventName:`${f}/tensorFlow`,scanID:r,email:p,message:"recording stopped by tensorflow "})},C)))},[De,s.handleScanTimeCapture,f,r,p,C]),Fe=t.useCallback(async()=>{O.length>0&&ee.current&&(await s.speechService.playAudio(s.voiceOverAssetsPath+O[O.length-1]),ee.current&&(v=setTimeout(Fe,2e3)))},[O,ee]),Me=t.useCallback(()=>{w&&w.current&&w.current.stop(),I(!0);try{if(C&&C.current&&C.current.stream){const e=C.current.stream.getVideoTracks()[0];if(e){const t=e.getSettings();j.current=t.frameRate||null}const t={videoBitsPerSecond:15e5};le[0]&&(t.mimeType=le[0]),w.current=new MediaRecorder(C.current.stream,t),w.current.addEventListener("dataavailable",Le),X([...Q,Le]),w.current.start(1e3),P(!1)}}catch(e){console.log("error while using media recorder",e)}},[C,le,Le,Q]),Pe=t.useCallback(async()=>{$.current&&clearTimeout($.current),Me(),ee.current&&($.current=setTimeout(async()=>{ee.current&&(await s.speechService.playAudio(`${s.voiceOverAssetsPath}SpotOn.mp3`),I(!1))},15e3)),F(!0),ee.current&&await s.speechService.playAudio(`${s.voiceOverAssetsPath}Spin.mp3`)},[Me,ee,s.speechService]);t.useEffect(()=>{ie.current=Pe},[Pe]);const _e=t.useCallback(({data:e})=>{e.size>0&&Se.poseDetection.connected()&&(oe.current||(oe.current=!0,Se.poseDetection.poseStatus(async e=>{if(console.log("poseStatus data:",e),e&&e.audio&&e.audio.length>0){s.posthog.capture(`${f}/pose_instruction_received`,{scanID:r,email:p,audio:e.audio,status:e.status,sid:e.sid,counter:ae.current,consecutiveFalse:re.current,type:"body_scan_instruction"});const t=s.findAudioElement();!0===e.status&&e.sid===y?(re.current=0,ae.current<2?(ae.current+=1,1!==ae.current||ce.current?2===ae.current&&t?.paused&&s.speechService.playAudio(s.voiceOverAssetsPath+e.audio):(ce.current=!0,s.speechService.stopAudio(),await s.speechService.playAudio(s.voiceOverAssetsPath+e.audio))):(B(e.audio),clearTimeout(v),Se.poseDetection.disconnect(),oe.current=!1,setTimeout(()=>ie.current(),1e3))):(re.current+=1,re.current>=3&&(ae.current=0,ce.current=!1),!t?.paused||b&&b?.audioName===e.audio?b?.audioName===e.audio&&t?.paused&&(b&&b.no_of_times_skipped>=b.skipCount?(b.no_of_times_skipped=0,s.speechService.playAudio(s.voiceOverAssetsPath+e.audio)):b&&(b.no_of_times_skipped+=1)):(b={skipCount:2,no_of_times_skipped:0,audioName:e.audio},s.speechService.playAudio(s.voiceOverAssetsPath+e.audio)))}})),C?.current&&null!==C.current.getScreenshot()&&Se.poseDetection.videoEmit({image:C.current.getScreenshot()||"",scanId:r}))},[C,r,Se,y,s.speechService,f,p]),Ae=t.useCallback(async()=>{A(!0),he(!0),ve?.(),se.current&&(se.current=!1,s.handleScanTimeCapture({eventName:"scan started",scanID:r,status:"success",email:p})),i(s.getCurrentTimeInSeconds()),D(!0),ee.current&&await s.speechService.playAudio(`${s.voiceOverAssetsPath}StartScan.mp3`),ee.current&&await s.speechService.playAudio(`${s.voiceOverAssetsPath}LiftArmsAndHoldAtHip.mp3`),ee.current&&(A(!1),I(!0),H(!0),Z(!0),Ce());try{if(C&&C.current&&C.current.stream&&ee.current){const e=C.current.stream.getVideoTracks()[0];if(e){const t=e.getSettings();j.current=t.frameRate||null}const t={videoBitsPerSecond:15e5};le[0]&&(t.mimeType=le[0]),ee.current&&(w.current=new MediaRecorder(C.current.stream,t)),ee.current&&w.current&&w.current.addEventListener("dataavailable",_e),X([...Q,_e]),w.current&&w.current.start(1e3),P(!1),ee.current&&(v=setTimeout(Fe,2e3))}}catch(e){console.log("error ----------",e)}},[C,le,_e,Q,Fe,ee,ve]);return t.useEffect(()=>(f&&(n(!0),Te()),()=>{y&&(Se.poseDetection.disconnect(),s.posthog.capture(`${f}/pose_detection_disconnected`,{scanID:r,email:p,id:y})),Q.forEach(e=>{w?.current?.removeEventListener("dataavailable",e)})}),[f]),t.useEffect(()=>{O.push(R)},[R]),t.useEffect(()=>{z([])},[K]),t.useEffect(()=>{const e=k.length&&k.length>0;M||!e||T||!ee.current||G||w&&w.current&&(T||(w.current.stop(),P(!0)))},[M,T,k,G]),t.useEffect(()=>{const e=k.length&&k.length>0;if(M||!e||T)console.log("No video found to upload.");else if(w&&w.current&&ee.current&&!G&&!T){const e=new File(k,`${r}.${Ee}`,{type:Ne});ye?.(),xe?.(!0),c(""),ge?.(e,j.current)}},[M,T,k,G,w,ee]),t.useEffect(()=>{const e=s.getSupportedMediaRecorderTypes(ke,s.videoTypes);ue(e)},[ke]),t.useEffect(()=>{be()},[]),e.jsx(h,{resetDetector:a,resetScan:be,loadingCam:E,onPause:je,showRestart:W,pause:G,onReScan:Ie,recordingStarted:T,isScanning:_,startSendingVideoFrames:Ae,faceDone:L,stopRecording:De,showPause:Y,webcamRef:C,onUserMedia:Ce,onUserMediaError:we,videoConstraints:pe,webcamKey:de})});function w({scanID:s,userDetails:n,setIsVideoUploaded:a,setScanFailsError:r,setScanStartTime:o,setScanUniqueKey:c}){const[i,l]=t.useState(90),[u,d]=t.useState(0),[m,p]=t.useState(null),[h,g]=t.useState(!1),[x,S]=t.useState(0),v=t.useRef([]),[y,b]=t.useState(!1),w=i-u,j=w>=80&&w<=95;t.useEffect(()=>{if("undefined"!=typeof window&&window.DeviceOrientationEvent){const e=e=>{if(null!==e.beta){let t=Math.abs(e.beta);null!==e.gamma&&(t*=Math.cos(e.gamma*Math.PI/180)),t=Math.max(0,Math.min(180,t)),l(t)}},t=async()=>{const t=DeviceOrientationEvent;if(t&&"function"==typeof t.requestPermission)try{"granted"===await t.requestPermission()&&window.addEventListener("deviceorientation",e)}catch(e){console.error("Permission error",e)}else window.addEventListener("deviceorientation",e);return()=>{e&&window.removeEventListener("deviceorientation",e)}};document.addEventListener("click",t,{once:!0})}},[]),t.useEffect(()=>{if(v.current=[...v.current.slice(-4),w],v.current.length>=5){const e=Math.max(...v.current)-Math.min(...v.current);S(j&&e<2?e=>Math.min(100,e+10):e=>Math.max(0,e-20))}j||null===m&&!h||N()},[w,j,m,h]),t.useEffect(()=>{x>=100&&null===m&&!h&&k(),x<50&&null!==m&&N()},[x,m,h]);const k=()=>{p(3);const e=setInterval(()=>{p(t=>null===t||t<=1?(clearInterval(e),g(!0),null):t-1)},1e3)},N=()=>{p(null),y||g(!1)};return e.jsx(f,{angle:w,countdown:m,isScanning:h,isInTargetRange:j,stabilityScore:x,children:h&&e.jsx(C,{setIsScanLocked:b,resetDetector:()=>{l(90),d(0),p(null),g(!1),S(0),b(!1),v.current=[]},scanID:s,userDetails:n,setIsVideoUploaded:a,setScanFailsError:r,setScanStartTime:o,setScanUniqueKey:c})})}function j({setShowDrawer:n,config:r,loader:o}){const[c,i]=t.useState({disabled:!1,message:""}),[l,u]=t.useState(!0),d=t.useRef(null),m=t.useCallback(async()=>{const e=await s.checkCameraPermission();i(e),u(!1)},[]);return t.useEffect(()=>{m()},[]),l?e.jsx(s.LoadingScreen,{url:o,loaderType:"black"}):c?.disabled?e.jsx(s.Modal,{config:r,message:c?.message}):e.jsx(a,{audio:!1,ref:d,screenshotQuality:1,videoConstraints:s.videoConstraints,mirrored:!0,onUserMedia:()=>n?.(!0),screenshotFormat:"image/jpeg",style:{position:"relative",top:0,bottom:0,zIndex:0,width:"100%",height:"100%",objectFit:"cover"}})}function k({link:n,onReady:a,wrapperClassName:r="[&_video]:rounded-t-[20px] w-full h-full"}){const o=t.useRef(null),i=t.useRef(null);let l={autoplay:!0,controls:!1,responsive:!0,fluid:!0,muted:!0,navigationUI:"hide",preload:"metadata",poster:s.videoPoster};return t.useEffect(()=>{if(!i.current&&n&&o?.current){const e=c(o.current,{...l});e.ready(()=>{i.current=e;const t={...l,sources:[{src:n,type:"application/x-mpegURL"}]};e.autoplay(t.autoplay),e.src(t.sources),a?.(e)})}},[n,o]),t.useEffect(()=>{const e=i.current;return()=>{e&&!e.isDisposed()&&(e.dispose(),i.current=null)}},[i]),e.jsx("div",{className:r,children:e.jsx("video",{ref:o,muted:!0,className:"video-js",playsInline:!0,onDrag:e=>e.preventDefault()})})}function N({scanFailsError:n,onNext:a,gender:c,setScanUniqueKey:i,setIsVideoUploaded:l}){const{translate:u}=t.useContext(s.LanguageContext)||{},d=s.useConfig(),[m,p]=t.useState(!1),f=()=>{p(!m)};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex common-ui-main flex-col h-full max-w-[28rem] mx-auto w-full rounded-t-[20px] overflow-y-auto",style:{background:d?.style?.base?.backgroundColor},children:[e.jsx("div",{className:"w-full max-w-[28rem] mx-auto pt-[1rem] px-[1rem]",children:e.jsx(s.Header,{noTitle:!0})}),e.jsx("div",{className:"flex-1",children:n&&e.jsxs("div",{className:"px-[1rem]",children:[e.jsx("h2",{className:"text-center",style:{fontFamily:d?.style?.heading?.headingFontFamily||"SeriouslyNostalgic Fn",fontSize:d?.style?.heading?.headingFontSize||"32px",color:d?.style?.heading?.headingColor||"#000",fontWeight:d?.style?.heading?.headingFontWeight||"normal"},children:u?.(s.LanguageKeys.issueWithScan)}),e.jsx("p",{style:{fontFamily:d?.style?.base?.baseFontFamily||"Inter, sans-serif",fontSize:d?.style?.base?.baseFontSize||"16px",color:d?.style?.base?.baseTextColor||"#1E1E1E"},children:u?.(s.LanguageKeys.reason)}),e.jsx("p",{style:{fontFamily:d?.style?.base?.baseFontFamily||"Inter, sans-serif",fontSize:d?.style?.base?.baseFontSize||"16px",color:d?.style?.base?.baseTextColor||"#1E1E1E"},children:s.handleErrorMessage(n)}),e.jsx("img",{className:"my-[0.5rem] aspect-[2/1.4] w-full object-cover",onClick:f,src:s.VIDEO_POSTER_GENDER_BASED[c],alt:"icon"})]})}),n&&e.jsx("div",{className:"p-[1rem] flex gap-[0.5rem]",children:e.jsx(s.SpecificButton,{disabled:!1,buttonText:u?.(s.LanguageKeys.scanAgain),className:"!shadow-none",buttonFunc:()=>{a?a?.():i?.(s.generateUuid()),l?.(!1)}})})]}),m&&e.jsxs(o.Dialog,{className:"w-screen h-screen video-modal",onClose:f,open:m,disablePortal:!0,children:[e.jsx("div",{className:"flex justifyEnd ",children:e.jsx("span",{className:"closeBtn",onClick:f,children:e.jsx(r.X,{className:"absolute right-[8px] top-[8px] text-white z-[9]"})})}),e.jsx("div",{className:"aspect-video object-cover rounded-[20px] ",children:e.jsx(k,{link:c?s.GENDER[c].PRE_LINK:s.GENDER.male.PRE_LINK,wrapperClassName:"w-screen h-screen fixed top-[0] left-[0]"})})]})]})}function E({scanId:n,userDetails:a,config:r,isVideoUploadedCorrect:c,isMeasurementAvailable:i,onComplete:l,isSuccess:u,onCustomScanSuccess:d,swan:m}){const{gender:p,shopDomain:f,heightInCm:h,deviceFocalLength:g,userName:x,email:S,scanType:v}=a||{},y=[s.CLOTHING_CUSTOM_SCAN,s.CLOTHING_BANNER_SCAN,s.CLOTHING_CUSTOM_FIT_SCAN].includes(v??""),[b,C]=t.useState(!0),w=t.useCallback(async()=>{try{y&&(await(m?.auth.addUser({scanId:n,email:S,name:x,gender:p,height:h})),d?.()),s.posthog.capture(f??"",{scanID:n,email:S,height:h,focalLength:g,clothesFit:"0",gender:p})}catch(e){console.log(e)}},[y]),{translate:k}=t.useContext(s.LanguageContext)||{};t.useEffect(()=>{(c||i)&&w()},[c,i]);const N=u||c||i;return e.jsx(o.Box,{className:"flex h-full w-full flex-col common-ui-main",children:e.jsxs("div",{className:"h-full w-full flex-col items-center justify-center flex",children:[e.jsx(j,{loader:r?.loader,setShowDrawer:C}),e.jsx(o.Drawer,{open:b,onClose:(e,t)=>{},disablePortal:!0,className:"camera-drawer",anchor:"bottom",children:e.jsx("div",{className:"max-w-[28rem] mx-auto w-full h-full flex text-center flex-col justify-between items-center bg-primary rounded-t-[30px] p-[1rem] common-ui-main overflow-y-auto",style:{background:r?.style?.base?.backgroundColor},children:e.jsxs("div",{className:"w-full flex-1 flex flex-col min-h-[400px]",children:[e.jsx(s.Header,{title:k?.(s.LanguageKeys.measurementsBeingTaken)}),e.jsx("div",{className:"flex items-center justify-center flex-1",children:e.jsx("video",{preload:"auto",className:"max-h-[calc(100vh-450px)] mx-auto w-full object-contain border-none min-h-[170px]",muted:!0,loop:!0,autoPlay:!0,playsInline:!0,children:e.jsx("source",{src:p===s.GenderType.Male?s.maleMeasurementProgress:s.measurementProgress,type:"video/mp4"})})}),N&&e.jsx(s.SpecificButton,{className:"!w-[180px] mx-auto",buttonText:k?.(s.LanguageKeys.next),buttonFunc:()=>{l?.()}})]})})})]})})}const D=()=>{const{userDetails:n,onRetry:a,isError:r,isSuccess:c,gender:i,scanUniqueKey:l,scanFailsError:u,setScanUniqueKey:d,setIsVideoUploaded:m,isMeasurementAvailable:p,isVideoUploadedCorrect:f,loading:h,showDeniedModal:g,uploadLoading:x,isLandscape:S,setScanFailsError:v,setScanStartTime:y,resetScan:b,onCustomScanSuccess:C,swan:k,onComplete:D}=t.useContext(s.ParamsContext),T=s.useConfig();return r?e.jsxs(e.Fragment,{children:[e.jsx(j,{}),e.jsx(o.Drawer,{anchor:"bottom",open:!0,className:"camera-drawer",onClose:(e,t)=>{},disablePortal:!0,children:e.jsx(N,{scanFailsError:!0,onNext:a,gender:i})})]}):c?e.jsx(E,{isSuccess:!0,onComplete:D,config:T}):h?e.jsx("div",{className:"flex top-0 !mt-0 left-0 z-[999] absolute justify-center items-center w-full h-full",style:{background:T?.style?.base?.backgroundColor},children:e.jsx(s.LoadingScreen,{url:T?.loader,loaderType:"black"})}):!S||x||u?g.disabled?e.jsx(s.Modal,{}):x||u||p||f?(x||p||f)&&!u?e.jsx(E,{scanId:l,isMeasurementAvailable:p,userDetails:n,isVideoUploadedCorrect:f,onCustomScanSuccess:C,swan:k,onComplete:D,config:T}):e.jsxs(e.Fragment,{children:[e.jsx(j,{}),e.jsx(o.Drawer,{anchor:"bottom",open:!0,className:"camera-drawer",onClose:(e,t)=>{},disablePortal:!0,children:e.jsx(N,{scanFailsError:u,onNext:()=>{a?.(),b()},setScanUniqueKey:d,gender:i,setIsVideoUploaded:m})})]}):e.jsx(w,{scanID:l,userDetails:n,setIsVideoUploaded:m,setScanFailsError:v,setScanStartTime:y,setScanUniqueKey:d}):e.jsx(s.Modal,{variant:"portrait",config:T})};exports.BodyScan=n=>{const{config:a,onRetry:r,onScanStart:o,onCaptureComplete:c,onUploadStart:i,onUploadEnd:l,onMeasurementSocketStart:u,onMeasurementSocketClose:d,onIntermediateScanSuccess:p,onScanError:f,onScanSuccess:h,onCustomScanSuccess:g,onComplete:x,isError:S,isSuccess:v}=n,y={email:"",shopDomain:"",gender:"male",heightInCm:0,scanType:"",deviceFocalLength:0,deviceModelName:"",sourceTag:"",...n.userDetails??{}},b=n.token??"",{gender:C,scanType:w,shopDomain:j,heightInCm:k,email:N,deviceFocalLength:E,deviceModelName:T,callbackUrl:I,sourceTag:L}=y,F=t.useMemo(()=>s.getSwanService(b),[b]),[M,P]=t.useState(!1),[_,A]=t.useState(!1),[$,R]=t.useState(!1),[U,O]=t.useState({disabled:!1,message:""}),[z,K]=t.useState(""),[B,q]=t.useState(!1),[V,W]=t.useState(!0),[H,G]=t.useState(!1),[J,Q]=t.useState(""),[X,Y]=t.useState(s.getCurrentTimeInSeconds()),{gyroData:Z}=function(e){const[s,n]=t.useState([]),[a,r]=t.useState(!1),o=t.useCallback(e=>{try{const{alpha:t,beta:s,gamma:a}=e;n(e=>[...e,{alpha:t?.toString()||void 0,beta:s?.toString()||void 0,gamma:a?.toString()||void 0,timestamp:(new Date).toISOString()}])}catch(e){console.log(e)}},[]),c=t.useCallback(async()=>{const e=DeviceOrientationEvent;if(void 0!==e&&"function"==typeof e.requestPermission)try{"granted"===await e.requestPermission()?r(!0):console.warn("Device orientation permission denied.")}catch(e){console.error("Error requesting device orientation permission:",e)}else r(!0)},[]);return t.useEffect(()=>(e&&a?window.addEventListener("deviceorientation",o):n([]),()=>{window.removeEventListener("deviceorientation",o)}),[e,a,o]),t.useEffect(()=>{e&&c()},[e,c]),{gyroData:s}}(H),{isLandscape:ee}=s.usePortraitLock();s.usePosthogPageview();const te=t.useCallback(()=>{Q(s.generateUuid()),K(""),P(!1),q(!1)},[]),se=t.useRef(!1);t.useEffect(()=>{!ee||se.current||M||S||v||z||(s.speechService.stopAudio(),te()),se.current=ee},[ee,M,S,v,z,te]);const ne=()=>{Y(null),Q("")},ae=t.useCallback(async e=>{if(e&&"success"===e?.scanStatus&&"intermediate"===e?.resultType&&200===e?.code)return s.handleScanTimeCapture({eventName:`${j}/measurement_success/intermediate`,scanID:J,status:"success",email:N}),A(!0),void p?.(e);h?.(e),A(!0),ne();const t=J;R(!0),s.handleScanTimeCapture({eventName:`${j}/measurement_success/fit-view`,scanID:t,status:"success",email:N}),X&&s.handleScanTimeCapture({eventName:`${j}/scan_completion_time`,scanID:t,status:"success",completionTime:s.getCurrentTimeInSeconds()-X,email:N})},[w,j,J]),re=e=>{R(!1),K(""),A(!1),F.measurement.handleMeasurementSocket({scanId:J,onPreopen:()=>{s.handleWebSocketCapture({eventName:`${j}/webSocket`,scanID:J,connection:"pre_open",type:"measurement_recommendation",email:N})},onOpen:()=>{u?.(),s.handleWebSocketCapture({eventName:`${j}/webSocket`,scanID:J,connection:"open",type:"measurement_recommendation",email:N})},onClose:()=>{d?.(),s.handleWebSocketCapture({eventName:`${j}/webSocket`,scanID:J,connection:"close",type:"measurement_recommendation",email:N})},onError:e=>{var t;t=e,f?.({...t,message:s.handleErrorMessage(t)}),ne(),R(!1),K(t),A(!1),s.handleScanTimeCapture({eventName:`${j}/measurement_failed/fit-view`,scanID:J,status:"failed",email:N,message:s.handleErrorMessage(t)}),X&&s.handleScanTimeCapture({eventName:`${j}/scan_completion_time`,scanID:J,status:"failed",completionTime:s.getCurrentTimeInSeconds()-X,email:N}),s.handleWebSocketCapture({eventName:`${j}/webSocket`,scanID:J,connection:"error",type:"measurement_recommendation",email:N})},onSuccess:e=>{s.handleWebSocketCapture({eventName:`${j}/webSocket`,scanID:J,connection:"success",type:"measurement_recommendation",email:N}),ae(e)}})},oe=t.useCallback(async(e,t)=>{const n=Number((e.size/1048576).toFixed(2)),a=null!=t?t:await s.getVideoFPS(e),r=s.createObjectMetadataArray({gender:C,focal_length:`${E}`,height:`${k}`,customer_store_url:j,clothes_fit:"0",scan_type:w,callback_url:I,source_tag:L});s.handleScanTimeCapture({eventName:`${j}/body_scan_meta_data`,scanID:J,email:N,data:JSON.stringify([...r,{fileSizeInMB:n,video_fps:a||0}])}),i?.();try{await F.fileUpload.uploadFileFrontend({file:e,arrayMetaData:r,scanId:J,email:N}),await F.fileUpload.setDeviceInfo({model:T,detection:"manual",gyro:Z,scanId:J}),console.log("video successfully uploaded"),q(!1),s.handleScanTimeCapture({eventName:`${j}/scan_success`,scanID:J,status:"success",email:N,data:JSON.stringify(r)}),s.handleScanTimeCapture({eventName:"scan finished",scanID:J,status:"success",email:N}),Y(s.getCurrentTimeInSeconds()),setTimeout(()=>{q(!0)},3e3)}catch(e){s.handleScanTimeCapture({eventName:"scan finished",scanID:J,status:"failed",email:N,message:s.handleErrorMessage(e)}),s.handleScanTimeCapture({eventName:`${j}/scan_failed`,scanID:J,status:"failed",email:N,message:s.handleErrorMessage(e),data:JSON.stringify(r)}),K(s.handleErrorMessage(e)),q(!1),f?.({...e,message:s.handleErrorMessage(e)}),ne()}finally{G(!1),l?.()}},[J,Z,i,l]),ce=t.useCallback(async()=>{if(+k<152.4||+k>213.36)return void f?.({message:"Height must be between 152.4cm (5ft) and 213.36cm (7ft)"});const e=await s.checkCameraPermission();e.disabled?(s.handleScanTimeCapture({eventName:`${j}/camera_activation`,scanID:J,status:"failed",email:N}),W(!1)):(W(!1),s.handleScanTimeCapture({eventName:`${j}/camera_activation`,scanID:J,status:"success",email:N})),O(e),K(""),q(!1)},[N,J,Q,j]);return t.useEffect(()=>{S||v||j&&ce()},[j,k,S,v]),t.useEffect(()=>{S||v||B&&j&&J&&re()},[B,j,J,S,v]),e.jsx(s.LanguageContextProvider,{children:e.jsx(s.ConfigProvider,{config:a,children:e.jsx(m,{children:e.jsx(s.ParamsContext.Provider,{value:{userDetails:y,onRetry:r,onScanError:f,isError:S,isSuccess:v,onScanSuccess:h,gender:C,scanUniqueKey:J,scanFailsError:z,setScanUniqueKey:Q,setIsVideoUploaded:q,isMeasurementAvailable:$,isVideoUploadedCorrect:_,loading:V,showDeniedModal:U,uploadLoading:M,isLandscape:ee,setStartGyro:G,uploadScanFile:oe,setUploadLoading:P,resetScan:te,setScanFailsError:K,setScanStartTime:Y,onScanStart:o,onCaptureComplete:c,onCustomScanSuccess:g,onComplete:x,swan:F},children:e.jsx(s.ShadowRoot,{children:e.jsx(D,{})})})})})})};
2
+ //# sourceMappingURL=BodyScan-pk8BpTW_.js.map
@@ -0,0 +1,2 @@
1
+ "use strict";var e=require("react/jsx-runtime"),t=require("react"),a=require("./Modal-DexL716x.js"),n=require("lucide-react"),o=require("@mui/material");let r=null,s=!1;function c({faceScanId:e,onValidPose:n,onScanComplete:o,onModelReady:c,onStartRecording:i,shopDomain:l,isError:d,isSuccess:u}){const f=t.useRef(null),[g,h]=t.useState(0),[m,p]=t.useState(0),[y,S]=t.useState(!1),[x,v]=t.useState(!1),b=t.useRef(null),w=t.useRef(g),C=t.useRef(m),F=t.useRef([]),j=t.useRef(""),_=t.useRef(0),N=t.useRef(!1),E=t.useRef(0),k="undefined"!=typeof navigator&&(/iPad|iPhone|iPod/.test(navigator.userAgent)||"MacIntel"===navigator.platform&&navigator.maxTouchPoints>1),T=t.useMemo(()=>["Face front","Turn head fully left","Turn head fully right","Smile facing front"],[]),I=t.useMemo(()=>function(e,t){let a;return(...n)=>{a&&clearTimeout(a),a=setTimeout(()=>e(...n),t)}}(e=>{a.posthog.capture(`${l}/face_scan_pose_detection`,e)},4e3),[l]),R=t.useCallback((t,a,n,o,r,s)=>{const c=Date.now();if(!(c-E.current<4e3)){E.current=c;try{const c=t[0]||[0,0,0],i=t[2]||[0,0,0],l=t[5]||[0,0,0],d=t[9]||[0,0,0],u=t[10]||[0,0,0],f=t.map(e=>e[2]).filter(e=>e>0),g=f.length>0?f.reduce((e,t)=>e+t,0)/f.length:0,h=a.map(e=>e[2]).filter(e=>e>0),m=h.length>0?h.reduce((e,t)=>e+t,0)/h.length:0,p=Math.abs(i[0]-l[0]),y=c[0]-l[0],S=i[0]-c[0];let x="frontal";1===n?x="left":2===n?x="right":3===n&&(x="frontal_smile");const v={faceScanId:e,stage:n,timestamp:(new Date).toISOString(),data:JSON.stringify({headValid:o,bodyInvalid:r,consecutiveValid:s,avgFaceScore:parseFloat(g.toFixed(3)),avgBodyScore:parseFloat(m.toFixed(3)),faceKeypointsDetected:f.length,bodyKeypointsDetected:h.length,eyeDistance:parseFloat(p.toFixed(2)),noseToRightRatio:parseFloat((y/p).toFixed(3)),noseToLeftRatio:parseFloat((S/p).toFixed(3)),noseScore:parseFloat(c[2].toFixed(3)),leftEyeScore:parseFloat(i[2].toFixed(3)),rightEyeScore:parseFloat(l[2].toFixed(3)),leftMouthScore:parseFloat(d[2].toFixed(3)),rightMouthScore:parseFloat(u[2].toFixed(3)),expectedPosition:x})};I(v)}catch(e){console.warn("Failed to track pose detection:",e)}}},[e,I]),M=()=>{a.posthog.capture(`${l}/face_scan_detection_started`,{faceScanId:e,stage:w.current,timestamp:(new Date).toISOString(),stageName:T[w.current]}),setTimeout(()=>{v(!0)},1500)},P=async()=>{if("undefined"!=typeof window)try{console.log("Initializing Face Scan...");const e=await(async()=>{if("undefined"==typeof window)return null;if(r)return r;if(s)for(;s;)if(await new Promise(e=>setTimeout(e,100)),r)return r;s=!0;try{const[e,t]=await Promise.all([import("@tensorflow/tfjs"),Promise.resolve().then(function(){return require("./pose-detection.esm-LbnXZ-R6.js")})]);await e.setBackend("webgl"),await e.ready();const n=await t.createDetector(t.SupportedModels.BlazePose,{runtime:"tfjs",modelType:"full"}),o=document.createElement("canvas");o.width="number"==typeof a.videoConstraints.width?a.videoConstraints.width:a.videoConstraints.width.ideal??a.videoConstraints.width.max??1280,o.height="number"==typeof a.videoConstraints.height?a.videoConstraints.height:a.videoConstraints.height.ideal??a.videoConstraints.height.max??720;const s=o.getContext("2d");if(s){s.fillStyle="black",s.fillRect(0,0,o.width,o.height);try{await n.estimatePoses(o)}catch(e){console.warn("Warmup frame failed (non-fatal):",e)}}return r=n,n}catch(e){return console.error("Failed to preload detector:",e),null}finally{s=!1}})();e&&(f.current=e,console.log("Face scan model loaded successfully"),S(!0),c?.())}catch(e){console.error("Error initializing face scan:",e)}};return t.useEffect(()=>{if(!d&&!u)return P(),()=>{(async()=>{try{S(!1)}catch(e){console.error("Error disposing resources:",e)}finally{h(0),p(0),w.current=0,C.current=0,F.current=[]}})()}},[d,u]),t.useEffect(()=>{w.current=g},[g]),t.useEffect(()=>{C.current=m},[m]),{faceScanDetector:async(t,r)=>{if(f.current&&t.current&&y&&x&&!(t.current.readyState<2))try{const s=await f.current.estimatePoses(t.current);if(s.length>0){const t=[],c=[];if(s[0].keypoints.forEach((e,a)=>{const n=e.score??0,o=[e.x??-1,e.y??-1,n];a<=10?t.push(o):c.push(o)}),r?.current){const e=r.current.getContext("2d"),{width:t,height:a}=r.current;if(e){e.clearRect(0,0,t,a);const n=Math.min(C.current/2,1),o=.35*a;e.beginPath(),e.strokeStyle="#00ff00",e.lineWidth=6,e.arc(t/2,a/2,o+10,-Math.PI/2,-Math.PI/2+2*n*Math.PI),e.stroke()}}const d=((e,t)=>{if(!t[0]||!t[2]||!t[5]||t[0][2]<.2||t[2][2]<.2||t[5][2]<.2)return!1;const a=.5*(t[10][1]+t[9][1])-.5*(t[5][1]+t[2][1]),n=(.5*(t[10][1]+t[9][1])-t[0][1])/a,o=n>.7||n<.3,r=Math.abs(t[2][1]-t[5][1])<.5*a&&Math.abs(t[9][1]-t[10][1])<.5*a,s=t[2][0]-t[5][0],c=t[0][0]-t[5][0],i=c>.4*s&&c<.6*s,l=c>.85*s,d=t[2][0]-t[0][0]>.85*s;switch(e){case 0:case 3:return!o&&r&&i;case 1:return!o&&r&&l;case 2:return!o&&r&&d;default:return!1}})(w.current,t),u=c.slice(2).filter(e=>e[2]>.7).length<=2;F.current.push(d&&u),F.current.length>10&&F.current.shift();if(F.current.filter(Boolean).length>=2){const e=C.current+1;p(e)}else p(Math.max(0,C.current-1));if(C.current>=2){n?.();const t=w.current+1;p(0),F.current=[],h(t),v(!1),(async()=>{if(await a.speechService.playAudio(`${a.voiceOverAssetsPath}face-scan-vos/Sound-effect.mp3`),a.posthog.capture(`${l}/face_scan_detection_stage_completed`,{faceScanId:e,completedStage:w.current,nextStage:t,timestamp:(new Date).toISOString(),totalStages:4,stageName:T[w.current]}),1===t&&i&&i(),t>=4)o?.();else{let e=null;switch(t){case 1:e="Left.mp3";break;case 2:e="Right.mp3";break;case 3:e="Smile.mp3"}e&&await a.speechService.playAudio(`${a.voiceOverAssetsPath}face-scan-vos/${e}`),M()}})()}R(t,c,w.current,d,u,C.current)}}catch(e){console.error("Pose detection error:",e)}},scanStage:g,setScanStage:h,consecutiveValid:m,isModelLoaded:y,resetScan:()=>{a.posthog.capture(`${l}/face_scan_reset`,{faceScanId:e,stage:w.current,timestamp:(new Date).toISOString(),stageName:T[w.current],consecutiveValid:C.current}),h(0),p(0),v(!1),w.current=0,C.current=0,F.current=[],j.current="",_.current=0,N.current=!1,b.current&&(speechSynthesis.cancel(),b.current=null)},enableVoiceCommands:()=>{if(N.current=!0,"undefined"!=typeof window&&k&&"speechSynthesis"in window){const e=new SpeechSynthesisUtterance("");e.volume=0,speechSynthesis.speak(e)}},startScanSequence:M,isScanningActive:x}}function i({onRetry:o,loading:r}){const{translate:s}=t.useContext(a.LanguageContext)||{},c=a.useConfig();return e.jsx("div",{className:"fixed common-ui-main top-[0] left-[0] z-[999] flex justify-center items-center w-full h-full overflow-y-auto",style:{background:c?.style?.base?.backgroundColor},children:e.jsxs("div",{className:"flex flex-col w-full items-center p-[1rem] rounded-lg ",children:[e.jsx(a.Header,{noTitle:!0}),e.jsxs("div",{className:"flex flex-col items-center w-full",children:[e.jsx("h2",{className:"text-xl my-[0] font-semibold text-gray-800 ",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:s?.(a.LanguageKeys.scanFailed)}),e.jsx("p",{className:"mb-[1.5rem]",style:{fontFamily:c?.style?.subheading?.subheadingFontFamily||"'Inter', sans-serif",fontSize:c?.style?.subheading?.subheadingFontSize||"14px",color:c?.style?.subheading?.subheadingColor||"#4b5563",fontWeight:c?.style?.subheading?.subheadingFontWeight||"normal"},children:s?.(a.LanguageKeys.clickToResetScan)}),e.jsx(a.SpecificButton,{disabled:r,className:"w-full h-[45px] shadow-[0px_1px_2px_0px_#00000040] text-[16px]",buttonText:s?.(a.LanguageKeys.resetScan),postfixIcon:e.jsx(n.ArrowRight,{}),buttonFunc:()=>o?.()})]})]})})}function l({stage:n,videoLoading:o,setVideoLoading:r,videoError:s,setVideoError:c,gender:i,btnConfig:l}){const{translate:d}=t.useContext(a.LanguageContext)||{},u=a.useConfig();return-1===n?e.jsxs("div",{className:"text-center common-ui-main p-[16px] w-full h-full",style:{background:u?.style?.base?.backgroundColor},children:[e.jsxs("div",{className:"w-full",children:[e.jsx(a.Header,{noTitle:!0}),e.jsx("h2",{className:"my-[0]",style:{fontFamily:u?.style?.heading?.headingFontFamily||"SeriouslyNostalgic Fn",fontSize:u?.style?.heading?.headingFontSize||"32px",color:u?.style?.heading?.headingColor||"#000",fontWeight:u?.style?.heading?.headingFontWeight||"normal"},children:d?.(a.LanguageKeys.faceVisible)}),o&&e.jsx("div",{className:"mb-4 flex items-center justify-center",style:{fontFamily:u?.style?.subheading?.subheadingFontFamily||"'Inter', sans-serif",fontSize:u?.style?.subheading?.subheadingFontSize||"14px",color:u?.style?.subheading?.subheadingColor||"#4b5563",fontWeight:u?.style?.subheading?.subheadingFontWeight||"normal"},children:d?.(a.LanguageKeys.loadingVideo)}),s&&e.jsx("div",{className:"mb-4 text-red-600",style:{fontFamily:u?.style?.subheading?.subheadingFontFamily||"'Inter', sans-serif",fontSize:u?.style?.subheading?.subheadingFontSize||"14px",color:"#ff0000",fontWeight:u?.style?.subheading?.subheadingFontWeight||"normal"},children:d?.(a.LanguageKeys.videoLoadFailed)}),!s&&e.jsx("div",{className:" w-[100px] mx-auto",children:e.jsx("video",{src:i===a.GenderType.Male?a.maleGlassesOffVideo:a.glassesOffVideo,autoPlay:!0,loop:!0,controls:!1,muted:!0,playsInline:!0,className:"h-full w-full object-contain border-none",onCanPlay:()=>r(!1),onLoadStart:()=>r(!0),onError:()=>c(!0),"aria-label":"Instructional video: Please remove your glasses before starting the scan."})})]}),e.jsx("div",{className:"flex justify-center w-full p-[1rem]",children:e.jsx(a.SpecificButton,{disabled:l.isDisabled,className:"!w-[60px] !h-[35px] !py-0 !px-0",buttonText:d?.(l.label),postfixIcon:l?.icon,buttonFunc:l.onClick})})]}):e.jsx("div",{className:"text-center common-ui-main p-[16px] w-full h-full",style:{background:u?.style?.base?.backgroundColor},children:e.jsxs("div",{className:"w-full",children:[e.jsx(a.Header,{noTitle:!0}),e.jsx("h3",{className:"mb-[0.5rem] mt-[0]",style:{fontFamily:u?.style?.heading?.headingFontFamily||"SeriouslyNostalgic Fn",fontSize:u?.style?.heading?.headingFontSize||"32px",color:u?.style?.heading?.headingColor||"#000",fontWeight:u?.style?.heading?.headingFontWeight||"normal"},children:d?.(a.directionMessages[n])}),e.jsxs("div",{className:"max-w-[400px] justify-center gap-1 mx-auto flex items-center",children:[e.jsx("div",{className:` w-[120px] overflow-hidden ${0===n?"opacity-100":"opacity-0 hidden"} `,children:e.jsx("video",{className:"h-full w-full object-contain border-none",muted:!0,loop:!0,autoPlay:!0,playsInline:!0,children:e.jsx("source",{src:i===a.GenderType.Male?a.FACE_SCAN_HEADSHOT.male.forward:a.FACE_SCAN_HEADSHOT.female.forward,type:"video/mp4"})})}),e.jsx("div",{className:` w-[120px] overflow-hidden ${1===n?"opacity-100":"opacity-0 hidden"} `,children:e.jsx("video",{className:"h-full w-full object-contain border-none",muted:!0,loop:!0,autoPlay:!0,playsInline:!0,children:e.jsx("source",{src:i===a.GenderType.Male?a.FACE_SCAN_HEADSHOT.male.left:a.FACE_SCAN_HEADSHOT.female.left,type:"video/mp4"})})}),e.jsx("div",{className:` w-[120px] overflow-hidden ${2===n?"opacity-100":"opacity-0 hidden"} `,children:e.jsx("video",{className:"h-full w-full object-contain border-none",muted:!0,loop:!0,autoPlay:!0,playsInline:!0,children:e.jsx("source",{src:i===a.GenderType.Male?a.FACE_SCAN_HEADSHOT.male.right:a.FACE_SCAN_HEADSHOT.female.right,type:"video/mp4"})})}),e.jsx("div",{className:` w-[120px] overflow-hidden ${3===n?"opacity-100":"opacity-0 hidden"} `,children:e.jsx("video",{className:"h-full w-full object-contain border-none",muted:!0,loop:!0,autoPlay:!0,playsInline:!0,children:e.jsx("source",{src:i===a.GenderType.Male?a.FACE_SCAN_HEADSHOT.male.smile:a.FACE_SCAN_HEADSHOT.female.smile,type:"video/mp4"})})})]})]})})}const d=({webcamRef:r,canvasRef:s})=>{const{isError:c,isSuccess:d,showLoader:u,hasError:f,resetScanState:g,showGuideCard:h,scanStage:m,videoLoading:p,setVideoLoading:y,videoError:S,setVideoError:x,gender:v,getButtonText:b,isScanning:w,startScan:C,isModelLoaded:F,isLandscape:j,onRetry:_}=t.useContext(a.ParamsContext),N=a.useConfig();return c?e.jsx(i,{onRetry:_}):d?e.jsx("div",{className:"fixed z-[9] common-ui-main w-full h-full",style:{background:N?.style?.base?.backgroundColor},children:e.jsx(a.LoadingScreen,{url:N?.loader,loaderType:"black"})}):e.jsxs(e.Fragment,{children:[e.jsx("audio",{id:"audioElement",crossOrigin:"anonymous",preload:"auto",style:{position:"absolute",zIndex:-99999},src:void 0}),j&&!u&&!f&&e.jsx("div",{className:"fixed inset-0 z-[9999] common-ui-main",style:{background:"#fff"},children:e.jsx(a.Modal,{variant:"portrait",config:N})}),u&&!f&&e.jsx("div",{className:"fixed z-[9] common-ui-main w-full h-full",style:{background:N?.style?.base?.backgroundColor},children:e.jsx(a.LoadingScreen,{url:N?.loader,loaderType:"black"})}),e.jsx("div",{className:"h-full flex-col common-ui-main relative w-full flex justify-center items-center text-center rounded-t-[20px]",style:{background:N?.style?.base?.backgroundColor},children:e.jsx("div",{className:"flex-1 w-full max-w-md overflow-hidden",children:e.jsxs("div",{className:"w-full h-full",children:[e.jsx("video",{ref:r,autoPlay:!0,playsInline:!0,muted:!0,width:a.videoConstraints.width.ideal,height:a.videoConstraints.height.ideal,className:"w-full h-full object-cover fixed left-0 top-0 z-0",style:{transform:"scaleX(-1)",visibility:j?"hidden":"visible"}}),e.jsx("canvas",{ref:s,width:a.videoConstraints.width.ideal,height:a.videoConstraints.height.ideal,style:{transform:"scaleX(-1)",opacity:"0"}})]})})}),!u&&f&&e.jsx(i,{loading:u,onRetry:g}),h&&!f&&!u&&!j&&e.jsx(o.Drawer,{open:!0,className:"face-scan-small camera-draw",anchor:"bottom",onClose:(e,t)=>{},disablePortal:!0,hideBackdrop:!0,children:e.jsx(l,{stage:m,videoLoading:p,setVideoLoading:y,videoError:S,setVideoError:x,gender:v,btnConfig:{label:b(),onClick:w?g:C,isDisabled:u||!F,icon:w?e.jsx(n.ArrowRight,{}):e.jsx(e.Fragment,{})}})})]})};exports.FaceScan=n=>{const{onScanSuccess:o,onScanError:r,onRetry:s,onScanStart:i,onCaptureComplete:l,onUploadStart:u,onUploadEnd:f,onMeasurementSocketStart:g,onMeasurementSocketClose:h,config:m,isError:p,isSuccess:y}=n,S=n.userDetails??{email:"",gender:"male",deviceFocalLength:0,shopDomain:"",bodyScanId:""},x=n.token??"",v=t.useRef(null),b=t.useRef(null),w=t.useRef(null),C=t.useRef([]),F=t.useRef(null),j=t.useRef(null),[_,N]=t.useState(!1),[E,k]=t.useState(!1),[T,I]=t.useState(!1),[R,M]=t.useState(!0),[P,D]=t.useState(!1),[L,A]=t.useState(!1),[O,z]=t.useState(!1),[$,H]=t.useState(a.generateUuid()),V=t.useMemo(()=>a.getSwanService(x),[x]),{isLandscape:W}=a.usePortraitLock(),{email:K,gender:U,deviceFocalLength:B,shopDomain:q,callbackUrl:G,bodyScanId:J}=S,[X,Q]=t.useState([]),[Y,Z]=t.useState(a.videoConstraintsExact),ee=t.useMemo(()=>a.getPreferredMediaRecorderTypes(),[]),te=a.getRecordingMimeType(X),ae=a.getRecordingExtension(te);a.usePosthogPageview();const ne=t.useCallback(()=>{console.log("Stopping recording..."),w.current&&"recording"===w.current.state&&w.current.stop(),w.current=null},[]),oe=async()=>{if(l?.(),C.current){if(0===C.current.length)return console.error("No video data recorded"),z(!0),void N(!1);u?.(),N(!0);const e=new File(C.current,`${$}.${ae}`,{type:te}),t=j.current??await a.getVideoFPS(e),n=e.size,o=(n/1048576).toFixed(2),r=Math.round(n/1e4),s={video_size_mb:parseFloat(o),video_size_bytes:n,video_fps:t||0,blob_count:C.current.length,estimated_duration_seconds:r},c=[{gender:U},{face_scan_id:$},{focal_length:`${B}`},{customer_store_url:q},{scan_type:"face_scan"},{body_scan_id:J}];G&&c.push({callback_url:G}),a.handleScanTimeCapture({eventName:`${q}/face_scan_meta_data`,faceScanId:$,email:K,data:JSON.stringify({metaData:c,videoData:s})});const i=Date.now();a.handleScanTimeCapture({eventName:`${q}/face_scan_upload_start`,faceScanId:$,email:K,startTime:i});try{const t=await V.fileUpload.faceScanFileUploader({file:e,arrayMetaData:c,objectKey:$,email:K,contentType:e.type}),n=Date.now(),o=n-i;a.handleScanTimeCapture({eventName:`${q}/face_scan_upload_complete`,faceScanId:$,email:K,completionTime:n,uploadDuration:o}),f?.(),console.log("✅ Upload successful",t),V.measurement.handlFaceScaneSocket({onPreopen:()=>{g?.(),a.handleWebSocketCapture({eventName:`${q}/webSocket`,faceScanID:$,connection:"pre_open",type:"faceScan_recommendation",email:K})},faceScanId:$,onOpen:()=>{a.handleWebSocketCapture({eventName:`${q}/webSocket`,faceScanID:$,connection:"open",type:"faceScan_recommendation",email:K}),console.log("websocket connect open")},onError:e=>{a.handleWebSocketCapture({eventName:`${q}/webSocket`,faceScanID:$,connection:"error",type:"faceScan_recommendation",email:K}),me(e)},onSuccess:e=>{a.handleWebSocketCapture({eventName:`${q}/webSocket`,faceScanID:$,connection:"success",type:"faceScan_recommendation",email:K}),pe(e)},onClose:()=>{h?.(),console.log("websocket connect close"),a.handleWebSocketCapture({eventName:`${q}/webSocket`,faceScanID:$,connection:"close",type:"faceScan_recommendation",email:K})}})}catch(e){f?.(),me(e)}}},re=t.useCallback(()=>{const e=v.current?.srcObject;if(!e)return;const t=e.getVideoTracks()[0].getSettings(),{width:a=1280,height:n=720}=t,o=document.createElement("canvas"),r=o.getContext("2d");a>n?(o.width=n,o.height=a):(o.width=a,o.height=n);const s=document.createElement("video");s.srcObject=e,s.muted=!0,s.playsInline=!0,s.play();const c=()=>{a>n?(r?.save(),r?.translate(o.width,0),r?.rotate(Math.PI/2),r?.drawImage(s,0,0,n,a),r?.restore()):r?.drawImage(s,0,0,a,n),requestAnimationFrame(c)};c();const i=t.frameRate??10;j.current=i;const l=o.captureStream(i),d={videoBitsPerSecond:15e5};let u;X.length>0&&(d.mimeType=X[0]);try{u=new MediaRecorder(l,d)}catch(e){return console.error("MediaRecorder init failed:",e),z(!0),void N(!1)}C.current=[],u.ondataavailable=e=>{e?.data&&e.data.size>0&&C.current&&C.current.push(e.data)},u.onstop=()=>{console.log("Recording stopped, total blobs:",C?.current?.length),oe()},u.start(100),w.current=u,console.log("Recording started successfully (portrait normalized)")},[X,oe]),{faceScanDetector:se,scanStage:ce,setScanStage:ie,resetScan:le,isModelLoaded:de,startScanSequence:ue}=c({faceScanId:$,shopDomain:q,isError:p,isSuccess:y,onScanComplete:()=>{ne()},onModelReady:()=>{k(!0)},onStartRecording:()=>{console.log("Stage 0 completed - starting recording for stages 1-3"),re()}}),fe=t.useCallback(()=>{de&&(i?.(),ie(0),a.speechService.playAudio(`${a.voiceOverAssetsPath}face-scan-vos/Face-forward.mp3`),setTimeout(()=>{I(!0),setTimeout(()=>{ue()},200)},200))},[ie,I,ue,de,i]),ge=t.useCallback(()=>{I(!1),M(!0),ne(),le(),s?.(),C.current=[],j.current=null,w.current&&(w.current=null),z(!1),ie(-1),H(a.generateUuid()),v.current&&F.current&&(v.current.srcObject=F.current,console.log("Camera stream restored after reset"))},[ie,I,M,ne,le,H]),he=t.useRef(!1);t.useEffect(()=>{!W||he.current||_||p||y||O||(a.speechService.stopAudio(),w.current&&(w.current.onstop=null,"recording"===w.current.state&&w.current.stop(),w.current=null),C.current=[],j.current=null,ge()),he.current=W},[W,_,p,y,O,ge]);const me=e=>{console.log(e,"ws error"),r?.(e),z(!0),N(!1),M(!1),a.handleScanTimeCapture({eventName:`${q}/faceScan`,faceScanId:$,status:"failed",email:K,data:JSON.stringify(e)})},pe=e=>{console.log(e,"ws success"),e&&"intermediate"===e?.resultType&&a.handleScanTimeCapture({eventName:`${q}/faceScan_success/intermediate`,faceScanId:$,status:"success",email:K,data:JSON.stringify(e)}),o?.(e)};t.useEffect(()=>{if(!p&&!y)return navigator.mediaDevices.getUserMedia&&navigator.mediaDevices.getUserMedia({video:Y}).then(e=>{F.current=e,v.current&&(v.current.srcObject=e)}).catch(e=>{console.error("Error accessing webcam:",e),Y!==a.videoConstraintsExact?z(!0):Z(a.videoConstraintsFallback)}),()=>{F.current&&F.current.getTracks().forEach(e=>e.stop())}},[p,y,Y]),t.useEffect(()=>{if(!E||!T)return;const e=setInterval(()=>{se(v,b)},500);return()=>clearInterval(e)},[se,E,T]);return console.log("Model ready:",E,"Has error:",O,"Is scanning:",T,"showLoader",_),t.useEffect(()=>{const e=a.getSupportedMediaRecorderTypes(ee,a.videoTypes);Q(e)},[ee]),t.useEffect(()=>{ie(-1)},[]),e.jsx(a.LanguageContextProvider,{children:e.jsx(a.ConfigProvider,{config:m,children:e.jsx(a.ParamsContext.Provider,{value:{isError:p,isSuccess:y,showLoader:_,hasError:O,resetScanState:ge,showGuideCard:R,scanStage:ce,videoLoading:P,setVideoLoading:D,videoError:L,setVideoError:A,gender:U,getButtonText:()=>T?a.LanguageKeys.reset:de?a.LanguageKeys.start:a.LanguageKeys.loading,isScanning:T,startScan:fe,isModelLoaded:de,isLandscape:W,onRetry:s},children:e.jsx(a.ShadowRoot,{children:e.jsx(d,{webcamRef:v,canvasRef:b})})})})})};
2
+ //# sourceMappingURL=FaceScan-DmhlE48V.js.map
@@ -0,0 +1,2 @@
1
+ import{jsx as e,jsxs as t,Fragment as a}from"react/jsx-runtime";import{useRef as n,useState as o,useMemo as r,useCallback as c,useEffect as i,useContext as s}from"react";import{p as l,s as d,v as u,a as m,L as h,u as f,H as g,b as p,S as y,m as S,g as b,G as w,d as v,F as x,P as F,c as N,M as _,e as I,f as k,h as M,i as C,j as D,k as E,l as P,n as T,o as z,q as R,r as L,t as $,C as j,w as V,x as O,y as W,z as U}from"./Modal-Bcg-awuT.js";import{ArrowRight as B}from"lucide-react";import{Drawer as A}from"@mui/material";let q=null,J=!1;function G({faceScanId:e,onValidPose:t,onScanComplete:a,onModelReady:s,onStartRecording:h,shopDomain:f,isError:g,isSuccess:p}){const y=n(null),[S,b]=o(0),[w,v]=o(0),[x,F]=o(!1),[N,_]=o(!1),I=n(null),k=n(S),M=n(w),C=n([]),D=n(""),E=n(0),P=n(!1),T=n(0),z="undefined"!=typeof navigator&&(/iPad|iPhone|iPod/.test(navigator.userAgent)||"MacIntel"===navigator.platform&&navigator.maxTouchPoints>1),R=r(()=>["Face front","Turn head fully left","Turn head fully right","Smile facing front"],[]),L=r(()=>function(e,t){let a;return(...n)=>{a&&clearTimeout(a),a=setTimeout(()=>e(...n),t)}}(e=>{l.capture(`${f}/face_scan_pose_detection`,e)},4e3),[f]),$=c((t,a,n,o,r,c)=>{const i=Date.now();if(!(i-T.current<4e3)){T.current=i;try{const i=t[0]||[0,0,0],s=t[2]||[0,0,0],l=t[5]||[0,0,0],d=t[9]||[0,0,0],u=t[10]||[0,0,0],m=t.map(e=>e[2]).filter(e=>e>0),h=m.length>0?m.reduce((e,t)=>e+t,0)/m.length:0,f=a.map(e=>e[2]).filter(e=>e>0),g=f.length>0?f.reduce((e,t)=>e+t,0)/f.length:0,p=Math.abs(s[0]-l[0]),y=i[0]-l[0],S=s[0]-i[0];let b="frontal";1===n?b="left":2===n?b="right":3===n&&(b="frontal_smile");const w={faceScanId:e,stage:n,timestamp:(new Date).toISOString(),data:JSON.stringify({headValid:o,bodyInvalid:r,consecutiveValid:c,avgFaceScore:parseFloat(h.toFixed(3)),avgBodyScore:parseFloat(g.toFixed(3)),faceKeypointsDetected:m.length,bodyKeypointsDetected:f.length,eyeDistance:parseFloat(p.toFixed(2)),noseToRightRatio:parseFloat((y/p).toFixed(3)),noseToLeftRatio:parseFloat((S/p).toFixed(3)),noseScore:parseFloat(i[2].toFixed(3)),leftEyeScore:parseFloat(s[2].toFixed(3)),rightEyeScore:parseFloat(l[2].toFixed(3)),leftMouthScore:parseFloat(d[2].toFixed(3)),rightMouthScore:parseFloat(u[2].toFixed(3)),expectedPosition:b})};L(w)}catch(e){console.warn("Failed to track pose detection:",e)}}},[e,L]),j=()=>{l.capture(`${f}/face_scan_detection_started`,{faceScanId:e,stage:k.current,timestamp:(new Date).toISOString(),stageName:R[k.current]}),setTimeout(()=>{_(!0)},1500)},V=async()=>{if("undefined"!=typeof window)try{console.log("Initializing Face Scan...");const e=await(async()=>{if("undefined"==typeof window)return null;if(q)return q;if(J)for(;J;)if(await new Promise(e=>setTimeout(e,100)),q)return q;J=!0;try{const[e,t]=await Promise.all([import("@tensorflow/tfjs"),import("./pose-detection.esm-D0xuKZKx.js")]);await e.setBackend("webgl"),await e.ready();const a=await t.createDetector(t.SupportedModels.BlazePose,{runtime:"tfjs",modelType:"full"}),n=document.createElement("canvas");n.width="number"==typeof m.width?m.width:m.width.ideal??m.width.max??1280,n.height="number"==typeof m.height?m.height:m.height.ideal??m.height.max??720;const o=n.getContext("2d");if(o){o.fillStyle="black",o.fillRect(0,0,n.width,n.height);try{await a.estimatePoses(n)}catch(e){console.warn("Warmup frame failed (non-fatal):",e)}}return q=a,a}catch(e){return console.error("Failed to preload detector:",e),null}finally{J=!1}})();e&&(y.current=e,console.log("Face scan model loaded successfully"),F(!0),s?.())}catch(e){console.error("Error initializing face scan:",e)}};return i(()=>{if(!g&&!p)return V(),()=>{(async()=>{try{F(!1)}catch(e){console.error("Error disposing resources:",e)}finally{b(0),v(0),k.current=0,M.current=0,C.current=[]}})()}},[g,p]),i(()=>{k.current=S},[S]),i(()=>{M.current=w},[w]),{faceScanDetector:async(n,o)=>{if(y.current&&n.current&&x&&N&&!(n.current.readyState<2))try{const r=await y.current.estimatePoses(n.current);if(r.length>0){const n=[],c=[];if(r[0].keypoints.forEach((e,t)=>{const a=e.score??0,o=[e.x??-1,e.y??-1,a];t<=10?n.push(o):c.push(o)}),o?.current){const e=o.current.getContext("2d"),{width:t,height:a}=o.current;if(e){e.clearRect(0,0,t,a);const n=Math.min(M.current/2,1),o=.35*a;e.beginPath(),e.strokeStyle="#00ff00",e.lineWidth=6,e.arc(t/2,a/2,o+10,-Math.PI/2,-Math.PI/2+2*n*Math.PI),e.stroke()}}const i=((e,t)=>{if(!t[0]||!t[2]||!t[5]||t[0][2]<.2||t[2][2]<.2||t[5][2]<.2)return!1;const a=.5*(t[10][1]+t[9][1])-.5*(t[5][1]+t[2][1]),n=(.5*(t[10][1]+t[9][1])-t[0][1])/a,o=n>.7||n<.3,r=Math.abs(t[2][1]-t[5][1])<.5*a&&Math.abs(t[9][1]-t[10][1])<.5*a,c=t[2][0]-t[5][0],i=t[0][0]-t[5][0],s=i>.4*c&&i<.6*c,l=i>.85*c,d=t[2][0]-t[0][0]>.85*c;switch(e){case 0:case 3:return!o&&r&&s;case 1:return!o&&r&&l;case 2:return!o&&r&&d;default:return!1}})(k.current,n),s=c.slice(2).filter(e=>e[2]>.7).length<=2;C.current.push(i&&s),C.current.length>10&&C.current.shift();if(C.current.filter(Boolean).length>=2){const e=M.current+1;v(e)}else v(Math.max(0,M.current-1));if(M.current>=2){t?.();const n=k.current+1;v(0),C.current=[],b(n),_(!1),(async()=>{if(await d.playAudio(`${u}face-scan-vos/Sound-effect.mp3`),l.capture(`${f}/face_scan_detection_stage_completed`,{faceScanId:e,completedStage:k.current,nextStage:n,timestamp:(new Date).toISOString(),totalStages:4,stageName:R[k.current]}),1===n&&h&&h(),n>=4)a?.();else{let e=null;switch(n){case 1:e="Left.mp3";break;case 2:e="Right.mp3";break;case 3:e="Smile.mp3"}e&&await d.playAudio(`${u}face-scan-vos/${e}`),j()}})()}$(n,c,k.current,i,s,M.current)}}catch(e){console.error("Pose detection error:",e)}},scanStage:S,setScanStage:b,consecutiveValid:w,isModelLoaded:x,resetScan:()=>{l.capture(`${f}/face_scan_reset`,{faceScanId:e,stage:k.current,timestamp:(new Date).toISOString(),stageName:R[k.current],consecutiveValid:M.current}),b(0),v(0),_(!1),k.current=0,M.current=0,C.current=[],D.current="",E.current=0,P.current=!1,I.current&&(speechSynthesis.cancel(),I.current=null)},enableVoiceCommands:()=>{if(P.current=!0,"undefined"!=typeof window&&z&&"speechSynthesis"in window){const e=new SpeechSynthesisUtterance("");e.volume=0,speechSynthesis.speak(e)}},startScanSequence:j,isScanningActive:N}}function K({onRetry:a,loading:n}){const{translate:o}=s(h)||{},r=f();return e("div",{className:"fixed common-ui-main top-[0] left-[0] z-[999] flex justify-center items-center w-full h-full overflow-y-auto",style:{background:r?.style?.base?.backgroundColor},children:t("div",{className:"flex flex-col w-full items-center p-[1rem] rounded-lg ",children:[e(g,{noTitle:!0}),t("div",{className:"flex flex-col items-center w-full",children:[e("h2",{className:"text-xl my-[0] font-semibold text-gray-800 ",style:{fontFamily:r?.style?.heading?.headingFontFamily||"SeriouslyNostalgic Fn",fontSize:r?.style?.heading?.headingFontSize||"32px",color:r?.style?.heading?.headingColor||"#000",fontWeight:r?.style?.heading?.headingFontWeight||"normal"},children:o?.(p.scanFailed)}),e("p",{className:"mb-[1.5rem]",style:{fontFamily:r?.style?.subheading?.subheadingFontFamily||"'Inter', sans-serif",fontSize:r?.style?.subheading?.subheadingFontSize||"14px",color:r?.style?.subheading?.subheadingColor||"#4b5563",fontWeight:r?.style?.subheading?.subheadingFontWeight||"normal"},children:o?.(p.clickToResetScan)}),e(y,{disabled:n,className:"w-full h-[45px] shadow-[0px_1px_2px_0px_#00000040] text-[16px]",buttonText:o?.(p.resetScan),postfixIcon:e(B,{}),buttonFunc:()=>a?.()})]})]})})}function H({stage:a,videoLoading:n,setVideoLoading:o,videoError:r,setVideoError:c,gender:i,btnConfig:l}){const{translate:d}=s(h)||{},u=f();return-1===a?t("div",{className:"text-center common-ui-main p-[16px] w-full h-full",style:{background:u?.style?.base?.backgroundColor},children:[t("div",{className:"w-full",children:[e(g,{noTitle:!0}),e("h2",{className:"my-[0]",style:{fontFamily:u?.style?.heading?.headingFontFamily||"SeriouslyNostalgic Fn",fontSize:u?.style?.heading?.headingFontSize||"32px",color:u?.style?.heading?.headingColor||"#000",fontWeight:u?.style?.heading?.headingFontWeight||"normal"},children:d?.(p.faceVisible)}),n&&e("div",{className:"mb-4 flex items-center justify-center",style:{fontFamily:u?.style?.subheading?.subheadingFontFamily||"'Inter', sans-serif",fontSize:u?.style?.subheading?.subheadingFontSize||"14px",color:u?.style?.subheading?.subheadingColor||"#4b5563",fontWeight:u?.style?.subheading?.subheadingFontWeight||"normal"},children:d?.(p.loadingVideo)}),r&&e("div",{className:"mb-4 text-red-600",style:{fontFamily:u?.style?.subheading?.subheadingFontFamily||"'Inter', sans-serif",fontSize:u?.style?.subheading?.subheadingFontSize||"14px",color:"#ff0000",fontWeight:u?.style?.subheading?.subheadingFontWeight||"normal"},children:d?.(p.videoLoadFailed)}),!r&&e("div",{className:" w-[100px] mx-auto",children:e("video",{src:i===w.Male?S:b,autoPlay:!0,loop:!0,controls:!1,muted:!0,playsInline:!0,className:"h-full w-full object-contain border-none",onCanPlay:()=>o(!1),onLoadStart:()=>o(!0),onError:()=>c(!0),"aria-label":"Instructional video: Please remove your glasses before starting the scan."})})]}),e("div",{className:"flex justify-center w-full p-[1rem]",children:e(y,{disabled:l.isDisabled,className:"!w-[60px] !h-[35px] !py-0 !px-0",buttonText:d?.(l.label),postfixIcon:l?.icon,buttonFunc:l.onClick})})]}):e("div",{className:"text-center common-ui-main p-[16px] w-full h-full",style:{background:u?.style?.base?.backgroundColor},children:t("div",{className:"w-full",children:[e(g,{noTitle:!0}),e("h3",{className:"mb-[0.5rem] mt-[0]",style:{fontFamily:u?.style?.heading?.headingFontFamily||"SeriouslyNostalgic Fn",fontSize:u?.style?.heading?.headingFontSize||"32px",color:u?.style?.heading?.headingColor||"#000",fontWeight:u?.style?.heading?.headingFontWeight||"normal"},children:d?.(v[a])}),t("div",{className:"max-w-[400px] justify-center gap-1 mx-auto flex items-center",children:[e("div",{className:` w-[120px] overflow-hidden ${0===a?"opacity-100":"opacity-0 hidden"} `,children:e("video",{className:"h-full w-full object-contain border-none",muted:!0,loop:!0,autoPlay:!0,playsInline:!0,children:e("source",{src:i===w.Male?x.male.forward:x.female.forward,type:"video/mp4"})})}),e("div",{className:` w-[120px] overflow-hidden ${1===a?"opacity-100":"opacity-0 hidden"} `,children:e("video",{className:"h-full w-full object-contain border-none",muted:!0,loop:!0,autoPlay:!0,playsInline:!0,children:e("source",{src:i===w.Male?x.male.left:x.female.left,type:"video/mp4"})})}),e("div",{className:` w-[120px] overflow-hidden ${2===a?"opacity-100":"opacity-0 hidden"} `,children:e("video",{className:"h-full w-full object-contain border-none",muted:!0,loop:!0,autoPlay:!0,playsInline:!0,children:e("source",{src:i===w.Male?x.male.right:x.female.right,type:"video/mp4"})})}),e("div",{className:` w-[120px] overflow-hidden ${3===a?"opacity-100":"opacity-0 hidden"} `,children:e("video",{className:"h-full w-full object-contain border-none",muted:!0,loop:!0,autoPlay:!0,playsInline:!0,children:e("source",{src:i===w.Male?x.male.smile:x.female.smile,type:"video/mp4"})})})]})]})})}const X=({webcamRef:n,canvasRef:o})=>{const{isError:r,isSuccess:c,showLoader:i,hasError:l,resetScanState:d,showGuideCard:u,scanStage:h,videoLoading:g,setVideoLoading:p,videoError:y,setVideoError:S,gender:b,getButtonText:w,isScanning:v,startScan:x,isModelLoaded:I,isLandscape:k,onRetry:M}=s(F),C=f();return r?e(K,{onRetry:M}):c?e("div",{className:"fixed z-[9] common-ui-main w-full h-full",style:{background:C?.style?.base?.backgroundColor},children:e(N,{url:C?.loader,loaderType:"black"})}):t(a,{children:[e("audio",{id:"audioElement",crossOrigin:"anonymous",preload:"auto",style:{position:"absolute",zIndex:-99999},src:void 0}),k&&!i&&!l&&e("div",{className:"fixed inset-0 z-[9999] common-ui-main",style:{background:"#fff"},children:e(_,{variant:"portrait",config:C})}),i&&!l&&e("div",{className:"fixed z-[9] common-ui-main w-full h-full",style:{background:C?.style?.base?.backgroundColor},children:e(N,{url:C?.loader,loaderType:"black"})}),e("div",{className:"h-full flex-col common-ui-main relative w-full flex justify-center items-center text-center rounded-t-[20px]",style:{background:C?.style?.base?.backgroundColor},children:e("div",{className:"flex-1 w-full max-w-md overflow-hidden",children:t("div",{className:"w-full h-full",children:[e("video",{ref:n,autoPlay:!0,playsInline:!0,muted:!0,width:m.width.ideal,height:m.height.ideal,className:"w-full h-full object-cover fixed left-0 top-0 z-0",style:{transform:"scaleX(-1)",visibility:k?"hidden":"visible"}}),e("canvas",{ref:o,width:m.width.ideal,height:m.height.ideal,style:{transform:"scaleX(-1)",opacity:"0"}})]})})}),!i&&l&&e(K,{loading:i,onRetry:d}),u&&!l&&!i&&!k&&e(A,{open:!0,className:"face-scan-small camera-draw",anchor:"bottom",onClose:(e,t)=>{},disablePortal:!0,hideBackdrop:!0,children:e(H,{stage:h,videoLoading:g,setVideoLoading:p,videoError:y,setVideoError:S,gender:b,btnConfig:{label:w(),onClick:v?d:x,isDisabled:i||!I,icon:e(v?B:a,{})}})})]})},Q=t=>{const{onScanSuccess:a,onScanError:s,onRetry:l,onScanStart:m,onCaptureComplete:h,onUploadStart:f,onUploadEnd:g,onMeasurementSocketStart:y,onMeasurementSocketClose:S,config:b,isError:w,isSuccess:v}=t,x=t.userDetails??{email:"",gender:"male",deviceFocalLength:0,shopDomain:"",bodyScanId:""},N=t.token??"",_=n(null),B=n(null),A=n(null),q=n([]),J=n(null),K=n(null),[H,Q]=o(!1),[Y,Z]=o(!1),[ee,te]=o(!1),[ae,ne]=o(!0),[oe,re]=o(!1),[ce,ie]=o(!1),[se,le]=o(!1),[de,ue]=o(I()),me=r(()=>k(N),[N]),{isLandscape:he}=M(),{email:fe,gender:ge,deviceFocalLength:pe,shopDomain:ye,callbackUrl:Se,bodyScanId:be}=x,[we,ve]=o([]),[xe,Fe]=o(C),Ne=r(()=>D(),[]),_e=E(we),Ie=P(_e);T();const ke=c(()=>{console.log("Stopping recording..."),A.current&&"recording"===A.current.state&&A.current.stop(),A.current=null},[]),Me=async()=>{if(h?.(),q.current){if(0===q.current.length)return console.error("No video data recorded"),le(!0),void Q(!1);f?.(),Q(!0);const e=new File(q.current,`${de}.${Ie}`,{type:_e}),t=K.current??await O(e),a=e.size,n=(a/1048576).toFixed(2),o=Math.round(a/1e4),r={video_size_mb:parseFloat(n),video_size_bytes:a,video_fps:t||0,blob_count:q.current.length,estimated_duration_seconds:o},c=[{gender:ge},{face_scan_id:de},{focal_length:`${pe}`},{customer_store_url:ye},{scan_type:"face_scan"},{body_scan_id:be}];Se&&c.push({callback_url:Se}),W({eventName:`${ye}/face_scan_meta_data`,faceScanId:de,email:fe,data:JSON.stringify({metaData:c,videoData:r})});const i=Date.now();W({eventName:`${ye}/face_scan_upload_start`,faceScanId:de,email:fe,startTime:i});try{const t=await me.fileUpload.faceScanFileUploader({file:e,arrayMetaData:c,objectKey:de,email:fe,contentType:e.type}),a=Date.now();W({eventName:`${ye}/face_scan_upload_complete`,faceScanId:de,email:fe,completionTime:a,uploadDuration:a-i}),g?.(),console.log("✅ Upload successful",t),me.measurement.handlFaceScaneSocket({onPreopen:()=>{y?.(),U({eventName:`${ye}/webSocket`,faceScanID:de,connection:"pre_open",type:"faceScan_recommendation",email:fe})},faceScanId:de,onOpen:()=>{U({eventName:`${ye}/webSocket`,faceScanID:de,connection:"open",type:"faceScan_recommendation",email:fe}),console.log("websocket connect open")},onError:e=>{U({eventName:`${ye}/webSocket`,faceScanID:de,connection:"error",type:"faceScan_recommendation",email:fe}),Ve(e)},onSuccess:e=>{U({eventName:`${ye}/webSocket`,faceScanID:de,connection:"success",type:"faceScan_recommendation",email:fe}),Oe(e)},onClose:()=>{S?.(),console.log("websocket connect close"),U({eventName:`${ye}/webSocket`,faceScanID:de,connection:"close",type:"faceScan_recommendation",email:fe})}})}catch(e){g?.(),Ve(e)}}},Ce=c(()=>{const e=_.current?.srcObject;if(!e)return;const t=e.getVideoTracks()[0].getSettings(),{width:a=1280,height:n=720}=t,o=document.createElement("canvas"),r=o.getContext("2d");a>n?(o.width=n,o.height=a):(o.width=a,o.height=n);const c=document.createElement("video");c.srcObject=e,c.muted=!0,c.playsInline=!0,c.play();const i=()=>{a>n?(r?.save(),r?.translate(o.width,0),r?.rotate(Math.PI/2),r?.drawImage(c,0,0,n,a),r?.restore()):r?.drawImage(c,0,0,a,n),requestAnimationFrame(i)};i();const s=t.frameRate??10;K.current=s;const l=o.captureStream(s),d={videoBitsPerSecond:15e5};let u;we.length>0&&(d.mimeType=we[0]);try{u=new MediaRecorder(l,d)}catch(e){return console.error("MediaRecorder init failed:",e),le(!0),void Q(!1)}q.current=[],u.ondataavailable=e=>{e?.data&&e.data.size>0&&q.current&&q.current.push(e.data)},u.onstop=()=>{console.log("Recording stopped, total blobs:",q?.current?.length),Me()},u.start(100),A.current=u,console.log("Recording started successfully (portrait normalized)")},[we,Me]),{faceScanDetector:De,scanStage:Ee,setScanStage:Pe,resetScan:Te,isModelLoaded:ze,startScanSequence:Re}=G({faceScanId:de,shopDomain:ye,isError:w,isSuccess:v,onScanComplete:()=>{ke()},onModelReady:()=>{Z(!0)},onStartRecording:()=>{console.log("Stage 0 completed - starting recording for stages 1-3"),Ce()}}),Le=c(()=>{ze&&(m?.(),Pe(0),d.playAudio(`${u}face-scan-vos/Face-forward.mp3`),setTimeout(()=>{te(!0),setTimeout(()=>{Re()},200)},200))},[Pe,te,Re,ze,m]),$e=c(()=>{te(!1),ne(!0),ke(),Te(),l?.(),q.current=[],K.current=null,A.current&&(A.current=null),le(!1),Pe(-1),ue(I()),_.current&&J.current&&(_.current.srcObject=J.current,console.log("Camera stream restored after reset"))},[Pe,te,ne,ke,Te,ue]),je=n(!1);i(()=>{!he||je.current||H||w||v||se||(d.stopAudio(),A.current&&(A.current.onstop=null,"recording"===A.current.state&&A.current.stop(),A.current=null),q.current=[],K.current=null,$e()),je.current=he},[he,H,w,v,se,$e]);const Ve=e=>{console.log(e,"ws error"),s?.(e),le(!0),Q(!1),ne(!1),W({eventName:`${ye}/faceScan`,faceScanId:de,status:"failed",email:fe,data:JSON.stringify(e)})},Oe=e=>{console.log(e,"ws success"),e&&"intermediate"===e?.resultType&&W({eventName:`${ye}/faceScan_success/intermediate`,faceScanId:de,status:"success",email:fe,data:JSON.stringify(e)}),a?.(e)};i(()=>{if(!w&&!v)return navigator.mediaDevices.getUserMedia&&navigator.mediaDevices.getUserMedia({video:xe}).then(e=>{J.current=e,_.current&&(_.current.srcObject=e)}).catch(e=>{console.error("Error accessing webcam:",e),xe!==C?le(!0):Fe(z)}),()=>{J.current&&J.current.getTracks().forEach(e=>e.stop())}},[w,v,xe]),i(()=>{if(!Y||!ee)return;const e=setInterval(()=>{De(_,B)},500);return()=>clearInterval(e)},[De,Y,ee]);return console.log("Model ready:",Y,"Has error:",se,"Is scanning:",ee,"showLoader",H),i(()=>{const e=R(Ne,L);ve(e)},[Ne]),i(()=>{Pe(-1)},[]),e($,{children:e(j,{config:b,children:e(F.Provider,{value:{isError:w,isSuccess:v,showLoader:H,hasError:se,resetScanState:$e,showGuideCard:ae,scanStage:Ee,videoLoading:oe,setVideoLoading:re,videoError:ce,setVideoError:ie,gender:ge,getButtonText:()=>ee?p.reset:ze?p.start:p.loading,isScanning:ee,startScan:Le,isModelLoaded:ze,isLandscape:he,onRetry:l},children:e(V,{children:e(X,{webcamRef:_,canvasRef:B})})})})})};export{Q as F};
2
+ //# sourceMappingURL=FaceScan-EBQQKpa-.js.map
package/dist/bodyScan.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var e=require("./BodyScan-D_jb2WQl.js");require("react/jsx-runtime"),require("react"),require("./Modal-DexL716x.js"),require("react-dom"),require("@emotion/react"),require("@emotion/cache"),require("@swan-admin/swan-ai-measurements"),require("@mui/material"),require("tailwind-merge"),require("clsx"),require("posthog-js"),require("mic-check"),require("uuid"),require("react-webcam"),require("lucide-react"),require("video.js"),exports.BodyScan=e.BodyScan;
1
+ "use strict";var e=require("./BodyScan-pk8BpTW_.js");require("react/jsx-runtime"),require("react"),require("./Modal-DexL716x.js"),require("react-dom"),require("@emotion/react"),require("@emotion/cache"),require("@swan-admin/swan-ai-measurements"),require("@mui/material"),require("tailwind-merge"),require("clsx"),require("posthog-js"),require("mic-check"),require("uuid"),require("react-webcam"),require("lucide-react"),require("video.js"),exports.BodyScan=e.BodyScan;
2
2
  //# sourceMappingURL=bodyScan.js.map
package/dist/bodyScan.mjs CHANGED
@@ -1,2 +1,2 @@
1
- export{B as BodyScan}from"./BodyScan-yuUMPal1.js";import"react/jsx-runtime";import"react";import"./Modal-Bcg-awuT.js";import"react-dom";import"@emotion/react";import"@emotion/cache";import"@swan-admin/swan-ai-measurements";import"@mui/material";import"tailwind-merge";import"clsx";import"posthog-js";import"mic-check";import"uuid";import"react-webcam";import"lucide-react";import"video.js";
1
+ export{B as BodyScan}from"./BodyScan-CUUJUjcv.js";import"react/jsx-runtime";import"react";import"./Modal-Bcg-awuT.js";import"react-dom";import"@emotion/react";import"@emotion/cache";import"@swan-admin/swan-ai-measurements";import"@mui/material";import"tailwind-merge";import"clsx";import"posthog-js";import"mic-check";import"uuid";import"react-webcam";import"lucide-react";import"video.js";
2
2
  //# sourceMappingURL=bodyScan.mjs.map
package/dist/faceScan.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var e=require("./FaceScan-BaXtKSTO.js");require("react/jsx-runtime"),require("react"),require("./Modal-DexL716x.js"),require("react-dom"),require("@emotion/react"),require("@emotion/cache"),require("@swan-admin/swan-ai-measurements"),require("@mui/material"),require("tailwind-merge"),require("clsx"),require("posthog-js"),require("mic-check"),require("uuid"),require("lucide-react"),exports.FaceScan=e.FaceScan;
1
+ "use strict";var e=require("./FaceScan-DmhlE48V.js");require("react/jsx-runtime"),require("react"),require("./Modal-DexL716x.js"),require("react-dom"),require("@emotion/react"),require("@emotion/cache"),require("@swan-admin/swan-ai-measurements"),require("@mui/material"),require("tailwind-merge"),require("clsx"),require("posthog-js"),require("mic-check"),require("uuid"),require("lucide-react"),exports.FaceScan=e.FaceScan;
2
2
  //# sourceMappingURL=faceScan.js.map
package/dist/faceScan.mjs CHANGED
@@ -1,2 +1,2 @@
1
- export{F as FaceScan}from"./FaceScan-B5TPbwlQ.js";import"react/jsx-runtime";import"react";import"./Modal-Bcg-awuT.js";import"react-dom";import"@emotion/react";import"@emotion/cache";import"@swan-admin/swan-ai-measurements";import"@mui/material";import"tailwind-merge";import"clsx";import"posthog-js";import"mic-check";import"uuid";import"lucide-react";
1
+ export{F as FaceScan}from"./FaceScan-EBQQKpa-.js";import"react/jsx-runtime";import"react";import"./Modal-Bcg-awuT.js";import"react-dom";import"@emotion/react";import"@emotion/cache";import"@swan-admin/swan-ai-measurements";import"@mui/material";import"tailwind-merge";import"clsx";import"posthog-js";import"mic-check";import"uuid";import"lucide-react";
2
2
  //# sourceMappingURL=faceScan.mjs.map