@swan-admin/swan-web-component 1.0.121 → 1.0.123
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/BodyScan-CCRXkFFL.mjs +3 -0
- package/dist/BodyScan-CCRXkFFL.mjs.map +1 -0
- package/dist/BodyScan-RBxSYdGc.js +3 -0
- package/dist/BodyScan-RBxSYdGc.js.map +1 -0
- package/dist/FaceScan-DQvhrp3K.mjs +3 -0
- package/dist/FaceScan-DQvhrp3K.mjs.map +1 -0
- package/dist/{FaceScan-BRdpV_Yn.js → FaceScan-Dva9De8x.js} +3 -2
- package/dist/{FaceScan-BRdpV_Yn.js.map → FaceScan-Dva9De8x.js.map} +1 -1
- package/dist/{Modal-BPtRtRVC.js → Modal-CZgyeNwW.mjs} +3 -2
- package/dist/Modal-CZgyeNwW.mjs.map +1 -0
- package/dist/{Modal-HTYYx7sM.js → Modal-CmbYIXgn.js} +3 -2
- package/dist/{Modal-YZScjwEm.js.map → Modal-CmbYIXgn.js.map} +1 -1
- package/dist/bodyScan.d.ts +2 -2
- package/dist/bodyScan.js +2 -1
- package/dist/bodyScan.mjs +2 -1
- package/dist/faceScan.js +2 -1
- package/dist/faceScan.mjs +2 -1
- package/dist/index.css +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -1
- package/dist/index.mjs.map +1 -1
- package/dist/{pose-detection.esm-Bc8T4UAD.js → pose-detection.esm-DFB9u8DH.js} +2 -1
- package/dist/{pose-detection.esm-Bc8T4UAD.js.map → pose-detection.esm-DFB9u8DH.js.map} +1 -1
- package/dist/{pose-detection.esm-DC0_P6R7.js → pose-detection.esm-EvS-BndH.mjs} +2 -1
- package/dist/pose-detection.esm-EvS-BndH.mjs.map +1 -0
- package/package.json +3 -2
- package/dist/BodyScan-3YoMZG7n.js +0 -2
- package/dist/BodyScan-8qgqyl5-.js +0 -2
- package/dist/BodyScan-B0qqqK3C.js +0 -2
- package/dist/BodyScan-B1VBoA6S.js +0 -2
- package/dist/BodyScan-B1afPG1Q.js +0 -2
- package/dist/BodyScan-B1afPG1Q.js.map +0 -1
- package/dist/BodyScan-B4-sO3R2.js +0 -2
- package/dist/BodyScan-B87W6dpH.js +0 -2
- package/dist/BodyScan-B8pglBAp.js +0 -2
- package/dist/BodyScan-BEFwluXG.js +0 -2
- package/dist/BodyScan-BHgnqB6A.js +0 -2
- package/dist/BodyScan-BLvWlYnA.js +0 -2
- package/dist/BodyScan-BMAkl5Iw.js +0 -2
- package/dist/BodyScan-BMTK6e-E.js +0 -2
- package/dist/BodyScan-BQri8pAO.js +0 -2
- package/dist/BodyScan-BVNPC7bJ.js +0 -2
- package/dist/BodyScan-BfLKF5PU.js +0 -2
- package/dist/BodyScan-BjYHCskz.js +0 -2
- package/dist/BodyScan-BoAbG01d.js +0 -2
- package/dist/BodyScan-Bq64fsmL.js +0 -2
- package/dist/BodyScan-Bre1BIHK.js +0 -2
- package/dist/BodyScan-BsDJmy0G.js +0 -2
- package/dist/BodyScan-ByMGumuH.js +0 -2
- package/dist/BodyScan-C0V-EDdB.js +0 -2
- package/dist/BodyScan-C1dWJ2qu.js +0 -2
- package/dist/BodyScan-C43x2o2T.js +0 -2
- package/dist/BodyScan-C57PuQgF.js +0 -2
- package/dist/BodyScan-C9hQU-dK.js +0 -2
- package/dist/BodyScan-CA4rNyqL.js +0 -2
- package/dist/BodyScan-CH-_x55M.js +0 -2
- package/dist/BodyScan-CKH_WyTt.js +0 -2
- package/dist/BodyScan-CKmPcrkx.js +0 -2
- package/dist/BodyScan-CLpL3Uwx.js +0 -2
- package/dist/BodyScan-CM12T_-T.js +0 -2
- package/dist/BodyScan-CNhb6UOX.js +0 -2
- package/dist/BodyScan-CWsaPB8W.js +0 -2
- package/dist/BodyScan-CXwtxfOd.js +0 -2
- package/dist/BodyScan-CYn7eLoz.js +0 -2
- package/dist/BodyScan-CYnHFqsR.js +0 -2
- package/dist/BodyScan-CZTiQzpy.js +0 -2
- package/dist/BodyScan-Cc68SnU1.js +0 -2
- package/dist/BodyScan-CfS4bPCN.js +0 -2
- package/dist/BodyScan-CiG19l_n.js +0 -2
- package/dist/BodyScan-CjvyMLT9.js +0 -2
- package/dist/BodyScan-CkmrPAq9.js +0 -2
- package/dist/BodyScan-CoObDhac.js +0 -2
- package/dist/BodyScan-Cyfo46EK.js +0 -2
- package/dist/BodyScan-Cz9ggKm6.js +0 -2
- package/dist/BodyScan-D6Y_W5e2.js +0 -2
- package/dist/BodyScan-DCEgmVbG.js +0 -2
- package/dist/BodyScan-DEDdENv7.js +0 -2
- package/dist/BodyScan-DEdrK-ld.js +0 -2
- package/dist/BodyScan-DHMf2V5R.js +0 -2
- package/dist/BodyScan-DK9UmNBr.js +0 -2
- package/dist/BodyScan-DPCd26i-.js +0 -2
- package/dist/BodyScan-DPCd26i-.js.map +0 -1
- package/dist/BodyScan-DPSQ1hKh.js +0 -2
- package/dist/BodyScan-DVKnmJuJ.js +0 -2
- package/dist/BodyScan-DX_KbG5U.js +0 -2
- package/dist/BodyScan-DbfP9-G3.js +0 -2
- package/dist/BodyScan-DeBJWo0L.js +0 -2
- package/dist/BodyScan-DgZpiChn.js +0 -2
- package/dist/BodyScan-DkPwUgVu.js +0 -2
- package/dist/BodyScan-DntA0MBx.js +0 -2
- package/dist/BodyScan-DxidLEhk.js +0 -2
- package/dist/BodyScan-DyDxGqfI.js +0 -2
- package/dist/BodyScan-Dysj7b77.js +0 -2
- package/dist/BodyScan-DzyamZmb.js +0 -2
- package/dist/BodyScan-Ehsr_cYc.js +0 -2
- package/dist/BodyScan-MSB66I12.js +0 -2
- package/dist/BodyScan-Ot6nAH1j.js +0 -2
- package/dist/BodyScan-Srq29PK8.js +0 -2
- package/dist/BodyScan-SzaquTgH.js +0 -2
- package/dist/BodyScan-TPpfyief.js +0 -2
- package/dist/BodyScan-XW2vsiE3.js +0 -2
- package/dist/BodyScan-eUuIC3jY.js +0 -2
- package/dist/BodyScan-enDyqSjO.js +0 -2
- package/dist/BodyScan-iOXndWaO.js +0 -2
- package/dist/BodyScan-qVHOWabf.js +0 -2
- package/dist/BodyScan-t9qdQAL-.js +0 -2
- package/dist/BodyScan-twE2YOwy.js +0 -2
- package/dist/BodyScan-z6h5fueJ.js +0 -2
- package/dist/FaceScan-3rVSqkKB.js +0 -2
- package/dist/FaceScan-6Aoz5uUy.js +0 -2
- package/dist/FaceScan-7fl5pLnb.js +0 -2
- package/dist/FaceScan-9kUfXRSv.js +0 -2
- package/dist/FaceScan-AHZ-ajep.js +0 -2
- package/dist/FaceScan-B0pFv4Us.js +0 -2
- package/dist/FaceScan-BE0PB0fZ.js +0 -2
- package/dist/FaceScan-BWSeJEqI.js +0 -2
- package/dist/FaceScan-BdjT7nMG.js +0 -2
- package/dist/FaceScan-Bji5lGcQ.js +0 -2
- package/dist/FaceScan-Bji5lGcQ.js.map +0 -1
- package/dist/FaceScan-BmDNM8tt.js +0 -2
- package/dist/FaceScan-CNoW9DIE.js +0 -2
- package/dist/FaceScan-CPf6-siO.js +0 -2
- package/dist/FaceScan-CQayY4q-.js +0 -2
- package/dist/FaceScan-CQkfSMC2.js +0 -2
- package/dist/FaceScan-CaxQ6fGF.js +0 -2
- package/dist/FaceScan-CxDcvM4f.js +0 -2
- package/dist/FaceScan-D2PL8KpZ.js +0 -2
- package/dist/FaceScan-D3T_l4nN.js +0 -2
- package/dist/FaceScan-DCm43Nrq.js +0 -2
- package/dist/FaceScan-DKP93c3l.js +0 -2
- package/dist/FaceScan-DW6Ix1a1.js +0 -2
- package/dist/FaceScan-DYJVZoZ4.js +0 -2
- package/dist/FaceScan-Da2XEApH.js +0 -2
- package/dist/FaceScan-DrW2yUSA.js +0 -2
- package/dist/FaceScan-DxnydFcx.js +0 -2
- package/dist/FaceScan-Gm4F4cO1.js +0 -2
- package/dist/FaceScan-Nhc7myLG.js +0 -2
- package/dist/FaceScan-VFLJ9h_T.js +0 -2
- package/dist/FaceScan-iUXyDuza.js +0 -2
- package/dist/LoadingScreen-BILrJVZm.js +0 -2
- package/dist/LoadingScreen-FKDLJRUj.js +0 -2
- package/dist/Modal-4T_aWWPQ.js +0 -2
- package/dist/Modal-BHfJVhRi.js +0 -2
- package/dist/Modal-BitizIvu.js +0 -2
- package/dist/Modal-BpgpPVxR.js +0 -2
- package/dist/Modal-BzH-_ch3.js +0 -2
- package/dist/Modal-CB_MHF7l.js +0 -2
- package/dist/Modal-CDiBoVXR.js +0 -2
- package/dist/Modal-CWoUZTh4.js +0 -2
- package/dist/Modal-CaPtqgjI.js +0 -2
- package/dist/Modal-CbZJwbLZ.js +0 -2
- package/dist/Modal-DRjJKUrw.js +0 -2
- package/dist/Modal-DU2Jymve.js +0 -2
- package/dist/Modal-D_XGokez.js +0 -2
- package/dist/Modal-DnweWp6L.js +0 -2
- package/dist/Modal-Do--CErH.js +0 -2
- package/dist/Modal-Do--CErH.js.map +0 -1
- package/dist/Modal-YZScjwEm.js +0 -2
- package/dist/fonts/Switzer-Regular.eot +0 -0
- package/dist/fonts/Switzer-Regular.svg +0 -0
- package/dist/fonts/Switzer-Regular.ttf +0 -0
- package/dist/fonts/Switzer-Regular.woff +0 -0
- package/dist/fonts/Switzer-Regular.woff2 +0 -0
- package/dist/interfaces-B5ysRXpa.d.ts +0 -209
- package/dist/interfaces-CaaERZjZ.d.ts +0 -209
- package/dist/pose-detection.esm-D08ZA0zl.js +0 -18
- package/dist/pose-detection.esm-DejsYGYM.js +0 -18
- package/dist/pose-detection.esm-DejsYGYM.js.map +0 -1
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{jsx as e,jsxs as t,Fragment as n}from"react/jsx-runtime";import a,{useState as r,useCallback as s,useEffect as o,createContext as i,useLayoutEffect as c,useMemo as l,useContext as d,useRef as u}from"react";import{L as m,u as p,H as h,b as f,S as g,y,v,h as w,P as b,n as x,s as S,i as C,j as N,k as D,p as F,z as I,w as k,A as T,o as E,e as L,q as M,B as $,D as _,c as U,a as z,E as A,I as j,V as P,J as V,K as R,M as B,G as q,N as K,O as W,Q as O,f as H,l as J,t as G,R as Q,r as X,C as Y,x as Z}from"./LoadingScreen-FKDLJRUj.js";import ee from"clsx";import te from"react-webcam";import{X as ne}from"lucide-react";import{Dialog as ae,Box as re,Drawer as se}from"@mui/material";import oe from"video.js";const ie="DESKTOP",ce="TAB",le="MOBILE",de=i(void 0);function ue({children:t}){const[n,a]=r([window?.innerWidth,window?.innerHeight]),[s,i]=r(!1),d=()=>{a([window?.innerWidth,window?.innerHeight])};o(()=>{d()},[]),c(()=>(window.addEventListener("resize",d),()=>window.removeEventListener("resize",d)),[d]);let u=ie;n[0]>768&&n[0]<1024&&(u=ce),n[0]<768&&(u=le);const m=l(()=>({size:n,setSize:a,clearInputs:s,setClearInputs:i,media:u}),[n,s,u]);return e(de.Provider,{value:m,children:t})}var me=a.memo(function({size:n=16}){return t("svg",{width:n,height:n,viewBox:"0 0 25 25",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[e("path",{d:"M22.6968 14.6968C22.6968 16.8185 21.8539 18.8533 20.3536 20.3536C18.8533 21.8539 16.8185 22.6968 14.6968 22.6968",stroke:"white",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),e("path",{d:"M18.6968 11.6968V10.6968C18.6968 10.1663 18.4861 9.65764 18.111 9.28256C17.7359 8.90749 17.2272 8.69678 16.6968 8.69678C16.1663 8.69678 15.6576 8.90749 15.2826 9.28256C14.9075 9.65764 14.6968 10.1663 14.6968 10.6968",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),e("path",{d:"M14.6968 10.6968V9.69678C14.6968 9.16634 14.4861 8.65764 14.111 8.28256C13.7359 7.90749 13.2272 7.69678 12.6968 7.69678C12.1663 7.69678 11.6576 7.90749 11.2826 8.28256C10.9075 8.65764 10.6968 9.16634 10.6968 9.69678V10.6968",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),e("path",{d:"M10.6968 10.1968V4.69678C10.6968 4.16634 10.4861 3.65764 10.111 3.28256C9.73592 2.90749 9.22721 2.69678 8.69678 2.69678C8.16634 2.69678 7.65764 2.90749 7.28256 3.28256C6.90749 3.65764 6.69678 4.16634 6.69678 4.69678V14.6968",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),e("path",{d:"M18.6969 11.6968C18.6969 11.1663 18.9076 10.6576 19.2827 10.2826C19.6577 9.90749 20.1664 9.69678 20.6969 9.69678C21.2273 9.69678 21.736 9.90749 22.1111 10.2826C22.4862 10.6576 22.6969 11.1663 22.6969 11.6968V14.6968C22.6969 16.8185 21.854 18.8533 20.3537 20.3536C18.8534 21.8539 16.8186 22.6968 14.6969 22.6968H12.6969C9.89688 22.6968 8.19688 21.8368 6.70688 20.3568L3.10688 16.7568C2.76282 16.3757 2.57847 15.8769 2.592 15.3637C2.60554 14.8505 2.81593 14.3621 3.1796 13.9997C3.54327 13.6373 4.03238 13.4287 4.54565 13.417C5.05892 13.4053 5.55704 13.5914 5.93688 13.9368L7.69688 15.6968",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]})});var pe=a.memo(function({angle:n,countdown:a,isScanning:r,isInTargetRange:o,stabilityScore:i,children:c}){const{translate:u}=d(m)||{},g=p(),y=s(()=>n<80?Math.max(0,Math.min(100,10*(n-60))):n>95?Math.max(0,Math.min(100,10*(105-n))):100,[n]),v=l(()=>{if(r)return g?.style?.angleDetector?.successAngleBackground||"#4f46e5";const e=y();if(0===e)return g?.style?.angleDetector?.successAngleLowBackground||"#ffffff";if(100===e)return g?.style?.angleDetector?.successAngleBackground||"#4f46e5";return`rgb(${Math.round(255-e/100*116)}, ${Math.round(255-e/100*163)}, ${Math.round(255-e/100*9)})`},[r,y]),w=s((e,t)=>t>70?e?`text-[${g?.style?.angleDetector?.successAngleTextLightColor}]/70`:`text-[${g?.style?.angleDetector?.successAngleTextLightColor}]`:e?`text-[${g?.style?.angleDetector?.successAngleTextLightColor}]/40`:`text-[${g?.style?.angleDetector?.successAngleTextDarkColor}]/70`,[]),b=s((e=!1)=>{const t=y();return r?`text-[${g?.style?.angleDetector?.successAngleTextLightColor}]`:w(e,t)},[r,y]),x=s((e,t)=>t>70||e?g?.style?.angleDetector?.successAngleTextLightColor:g?.style?.angleDetector?.successAngleTextDarkColor,[]),S=s((e=!1)=>{const t=y();return r?g?.style?.angleDetector?.successAngleTextLightColor:x(e,t)},[r,y]),C=a;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},"data-testid":"level-screen","data-angle-state":r?"locked":o?"target":"adjusting",children:[e("div",{className:"flex justify-start fixed top-[.5rem] max-w-[28rem] mx-auto w-full px-[1rem]",children:e("div",{className:"flex justify-start ",children:e(h,{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",r?{className:"relative flex flex-col items-center justify-center",children:[e("div",{className:"relative flex h-16 w-16 items-center justify-center rounded-[9999px] border-2 bg-[#fff]/30 border-[#fff]",children:e("div",{className:"h-4 w-4 rounded-[9999px] animate-pulse bg-[#fff]/80"})}),c]}:{className:ee("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:ee("mt-[.5rem] text-center w-[180px] flex-col flex items-center absolute top-[60px]",b()),style:{color:S()},children:[e(me,{size:30}),t("p",{style:{fontFamily:g?.style?.base?.baseFontFamily||"Inter, sans-serif"},children:[" ",u?.(f.startLevelCheck),e("br",{})]})]})]}),null!==C&&e("div",{className:"absolute bottom-[8rem] text-center",children:e("div",{className:ee("text-sm font-medium px-4 py-1.5 bg-black/20 rounded-[9999px] mt-8",b()),style:{fontFamily:g?.style?.base?.baseFontFamily||"Inter, sans-serif",color:S()},children:u?.(f.leavePhone)})}),o&&null===C&&!r&&e("div",{className:"absolute bottom-[8rem] w-[12rem]",children:e("div",{className:`h-[.375rem] w-full bg-[${S()}]/20 rounded-[9999px] overflow-hidden`,style:{backgroundColor:`${S()}33`},children:e("div",{className:`h-full bg-[${S()}]/70 transition-all duration-300 rounded-[9999px]`,style:{width:`${n}%`,backgroundColor:`${S()}B3`}})})}),null===C&&!r&&e("div",{className:"absolute bottom-[5rem] text-center",children:t("div",{className:ee("text-[1.5rem] font-light",b()),style:{color:S()},children:[Math.round(n),"°"]})}),null===C&&!r&&e("div",{className:"absolute bottom-[2rem] text-center max-w-[20rem] mx-auto",children:e("div",{className:ee("text-[.75rem] opacity-50",b()),style:{fontFamily:g?.style?.base?.baseFontFamily||"Inter, sans-serif",color:S()},children:u?.(f.placePhoneUpright)})})]})});function he({resetScan:n,loadingCam:a,onUserMedia:r,onPause:s,pause:o,recordingStarted:i,startSendingVideoFrames:c,showPause:l,webcamRef:u,onUserMediaError:p,resetDetector:h,videoConstraints:w,webcamKey:b,faceDone:x,isScanning:S}){const{media:C}=d(de)||{},{translate:N}=d(m)||{};return t("div",{className:"App w-screen h-[100vh] relative common-ui-main","data-testid":"camera-scan","data-scan-phase":x?"spinning":i?"pose-detecting":S?"starting":"ready",children:[e("span",{onClick:()=>{n(),h()},className:"fixed right-[20px] top-[20px] z-[999]",children:e(ne,{className:"text-[#fff]"})}),e("div",{className:"w-full h-full overflow-hidden ",children:C===le&&e(te,{audio:!1,ref:u,screenshotQuality:1,videoConstraints:w,mirrored:!0,screenshotFormat:"image/jpeg",onUserMedia:r,onUserMediaError:p,style:{position:"fixed",top:0,bottom:0,zIndex:0,width:"100%",height:"100%",objectFit:"cover"}},b)}),t("div",{className:"fixed bottom-[30px] w-full z-[999] flex flex-col gap-4 items-center justify-center",children:[l&&e(g,{className:"!w-[180px] !h-[40px] !py-[0] mx-auto ",prefix:y,buttonText:N?.(f.pause),buttonFunc:s,btnSecondary:!0}),o?e("div",{children:e(g,{className:"!w-[180px] !h-[40px] !py-[0] mx-auto",buttonText:N?.(f.restart),buttonFunc:n,btnSecondary:!0})}):i?null:e(g,{"data-testid":"start-scan-btn",className:"!w-[180px] !h-[40px] !py-[0] mx-auto !bg-[#ffffff] !text-[#000000] "+(a?"!opacity-50":""),buttonText:N?.(f.startScan),buttonFunc:c,disabled:a})]}),e("audio",{id:"audioElement",crossOrigin:"anonymous",preload:"auto",style:{position:"absolute",zIndex:-99999},src:`${v}scanAudioInstructions/silence.mp3`})]})}let fe=null,ge=null,ye=null;let ve,we=null,be=null;var xe=a.memo(function({setIsScanLocked:t,resetDetector:n,scanID:a,setIsVideoUploaded:i,setScanFailsError:c,setScanStartTime:m,setScanUniqueKey:p,userDetails:h}){const{gender:f,heightInCm:g,email:y,shopDomain:$}=h,_=u(null),U=u(null),z=u(null),[A,j]=r([]),[P,V]=r(!0),[R,B]=r(!1),[q,K]=r(!1),[W,O]=r(!0),[H,J]=r(!1),G=u(null),[Q,X]=r(""),[Y,Z]=r([]),[ee,te]=r(""),[ne,ae]=r(!1),[re,se]=r(!1),[oe,ie]=r(!1),[ce,le]=r([]),[de,ue]=r(!1),me=u(!0),{poseDetector:pe}=function(){const[e,t]=r(0),[n,a]=r(0),[s,i]=r(!1),c=u(0),l=u(0),d=u(!0);async function m(){if("undefined"==typeof window||"undefined"==typeof navigator)return!1;try{console.log("Starting TensorFlow preload...");const[e,t,n]=await Promise.all([import("./pose-detection.esm-DejsYGYM.js"),import("@tensorflow/tfjs-core"),import("@tensorflow/tfjs-backend-webgl")]);ye=e,await t.setBackend("webgl"),await t.ready(),console.log("TensorFlow backend ready (WebGL)");const a={runtime:"mediapipe",modelType:"full",solutionPath:"https://cdn.jsdelivr.net/npm/@mediapipe/pose"};try{ge=await ye.createDetector(ye.SupportedModels.BlazePose,a),console.log("MediaPipe detector created successfully")}catch(e){console.warn("MediaPipe failed, falling back to TFJS runtime:",e),ge=await ye.createDetector(ye.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),fe=null,!1}}function p(e){return!(!e||0===e.length)&&22===e.filter(e=>e[2]>.7).length}return o(()=>{if(d.current=!0,!ge)return fe||(fe=m()),fe.then(e=>{e&&d.current&&i(!0)}),()=>{d.current=!1};i(!0)},[]),o(()=>{l.current=e,e>6&&c.current<2&&(a(e=>e+1),t(0))},[e]),o(()=>{c.current=n},[n]),{poseDetector:async(e,n)=>{if(!ge||!d.current||!n?.current?.video)return;const a=n.current.video;if(!(a.readyState<2))try{const n=await ge.estimatePoses(a,{flipHorizontal:!1});if(!n||!n.length)return;const r=n[0].keypoints.slice(11).map(e=>[e.x>0&&e.x<720?e.x:-1,e.y>0&&e.y<1280?e.y:-1,e.score??0]);0!==c.current||p(r)||t(e=>e+1),1===c.current&&p(r)&&t(e=>e+1),2===c.current&&e()}catch(e){console.error("Pose detection error:",e)}},isLoaded:s,spinPhase:n,resetDetector:()=>{c.current=0,l.current=0,t(0),a(0)},retryLoading:async()=>{ge||fe||(fe=m(),await fe&&d.current&&i(!0))}}}(),xe=u(!0),Se=u(!1),Ce=u(0),Ne=u(0),De=u(!1);u(!1);const Fe=u(!1),Ie=u(()=>{}),[ke,Te]=r([]),[Ee,Le]=r(0),[Me,$e]=r(w),{setStartGyro:_e,uploadScanFile:Ue,setUploadLoading:ze,swan:Ae,onScanStart:je,onCaptureComplete:Pe}=d(b),Ve=()=>{Se.current=!1,clearTimeout(ve),G.current&&clearTimeout(G.current),p(L()),c(""),ze?.(!1),j([]),z.current=null,V(!0),B(!1),K(!1),O(!0),J(!1),G.current=null,X(""),Z([]),te(""),ae(!ne),_e(!1),S.stopAudio(),se(!1),ie(!1),Ce.current=0,Ne.current=0,De.current=!1,Fe.current=!1,null!==U.current&&U.current.stop(),ce.forEach(e=>{U.current&&U.current.removeEventListener("dataavailable",e)}),le([]),me.current=!0,ue(!1),i(!1),_.current?.stream&&V(!1)},Re=s(()=>{setTimeout(()=>{V(!1)},1e3)},[]),Be=s(e=>{if(console.log("camera error",e),Me===w)return $e(x),void Le(e=>e+1);V(!1)},[Me]),qe=s(()=>{me.current=!1,ie(!0),ue(!1),G.current&&clearTimeout(G.current),U.current&&U.current.pause(),S.stopAudio(),Ae.poseDetection.disconnect(),Ce.current=0,Ne.current=0,De.current=!1,Fe.current=!1,U.current&&U.current.stop(),ce.forEach(e=>{U.current&&U.current.removeEventListener("dataavailable",e)}),le([]),clearTimeout(ve)},[U,ce,S,me]),Ke=l(()=>C(),[]),We=N(ke),Oe=D(We),He=s(async()=>{me.current=!0,await S.playAudio(`${v}SpotOn.mp3`),ie(!1),ue(!1),G.current&&clearTimeout(G.current),B(!1)},[G,S]),Je=s(async()=>{try{we=await Ae.poseDetection.connect(),console.log(we,"websocket connected"),F.capture(`${$}/pose_detection_connected`,{scanID:a,email:y,id:we})}catch(e){console.log(e,"while connecting websocket")}},[a,$,y]),Ge=s(async()=>{I({eventName:`${$}/rescan`,email:y,scanID:a,height:g,gender:f,status:!1}),me.current=!1,Ae.poseDetection.disconnect(),Ve(),await Je(),tt()},[Je,a,y]),Qe=s(({data:e})=>{e&&e.size>0&&me.current&&(j(t=>t.concat(e)),!Se.current&&_.current&&(Se.current=!0,pe(()=>{He(),k({eventName:`${$}/tensorFlow`,scanID:a,email:y,message:"recording stopped by tensorflow "})},_)))},[He,k,$,a,y,_]),Xe=s(async()=>{Y.length>0&&me.current&&(await S.playAudio(v+Y[Y.length-1]),me.current&&(ve=setTimeout(Xe,2e3)))},[Y,me]),Ye=s(()=>{U&&U.current&&U.current.stop(),B(!0);try{if(_&&_.current&&_.current.stream){const e=_.current.stream.getVideoTracks()[0];if(e){const t=e.getSettings();z.current=t.frameRate||null}const t={videoBitsPerSecond:15e5};ke[0]&&(t.mimeType=ke[0]),U.current=new MediaRecorder(_.current.stream,t),U.current.addEventListener("dataavailable",Qe),U.current.addEventListener("stop",()=>{console.log("[FIX] MediaRecorder stop event — all chunks flushed, setting mediaRecorderStopped=true"),O(!0)}),le([...ce,Qe]),U.current.start(1e3),O(!1)}}catch(e){console.log("error while using media recorder",e)}},[_,ke,Qe,ce]),Ze=s(async()=>{G.current&&clearTimeout(G.current),Ye(),me.current&&(G.current=setTimeout(async()=>{me.current&&(await S.playAudio(`${v}SpotOn.mp3`),B(!1))},16e3)),K(!0),me.current&&await S.playAudio(`${v}Spin.mp3`)},[Ye,me,S]);o(()=>{Ie.current=Ze},[Ze]);const et=s(({data:e})=>{e.size>0&&Ae.poseDetection.connected()&&(De.current||(De.current=!0,Ae.poseDetection.poseStatus(async e=>{if(console.log("poseStatus data:",e),e&&e.audio&&e.audio.length>0){F.capture(`${$}/pose_instruction_received`,{scanID:a,email:y,audio:e.audio,status:e.status,sid:e.sid,counter:Ce.current,consecutiveFalse:Ne.current,type:"body_scan_instruction"});const t=document.querySelector("#audioElement");!0===e.status&&e.sid===we?(Ne.current=0,Ce.current<2?(Ce.current+=1,1!==Ce.current||Fe.current?2===Ce.current&&t?.paused&&S.playAudio(v+e.audio):(Fe.current=!0,S.stopAudio(),await S.playAudio(v+e.audio))):(te(e.audio),clearTimeout(ve),Ae.poseDetection.disconnect(),De.current=!1,setTimeout(()=>Ie.current(),1e3))):(Ne.current+=1,Ne.current>=3&&(Ce.current=0,Fe.current=!1),!t?.paused||be&&be?.audioName===e.audio?be?.audioName===e.audio&&t?.paused&&(be&&be.no_of_times_skipped>=be.skipCount?(be.no_of_times_skipped=0,S.playAudio(v+e.audio)):be&&(be.no_of_times_skipped+=1)):(be={skipCount:2,no_of_times_skipped:0,audioName:e.audio},S.playAudio(v+e.audio)))}})),_?.current&&null!==_.current.getScreenshot()&&Ae.poseDetection.videoEmit({image:_.current.getScreenshot()||"",scanId:a}))},[_,a,Ae,we,S,$,y]),tt=s(async()=>{J(!0),_e(!0),je?.(),xe.current&&(xe.current=!1,k({eventName:"scan started",scanID:a,status:"success",email:y})),m(T()),V(!0),me.current&&await S.playAudio(`${v}StartScan.mp3`),me.current&&await S.playAudio(`${v}LiftArmsAndHoldAtHip.mp3`),me.current&&(J(!1),B(!0),se(!0),ue(!0),Re());try{if(_&&_.current&&_.current.stream&&me.current){const e=_.current.stream.getVideoTracks()[0];if(e){const t=e.getSettings();z.current=t.frameRate||null}const t={videoBitsPerSecond:15e5};ke[0]&&(t.mimeType=ke[0]),me.current&&(U.current=new MediaRecorder(_.current.stream,t)),me.current&&U.current&&U.current.addEventListener("dataavailable",et),le([...ce,et]),U.current&&U.current.start(1e3),O(!1),me.current&&(ve=setTimeout(Xe,2e3))}}catch(e){console.log("error ----------",e)}},[_,ke,et,ce,Xe,me,je]);return o(()=>($&&(t(!0),Je()),()=>{we&&(Ae.poseDetection.disconnect(),F.capture(`${$}/pose_detection_disconnected`,{scanID:a,email:y,id:we})),ce.forEach(e=>{U?.current?.removeEventListener("dataavailable",e)})}),[$]),o(()=>{Y.push(Q)},[Q]),o(()=>{Z([])},[ee]),o(()=>{const e=A.length&&A.length>0;W||!e||R||!me.current||oe||U&&U.current&&(R||U.current.stop())},[W,R,A,oe]),o(()=>{const e=A.length&&A.length>0;if(W&&e&&!R){if(U&&U.current&&me.current&&!oe&&!R){const e=new File(A,`${a}.${Oe}`,{type:We});console.log("[FIX] Upload triggered — file size:",(e.size/1024).toFixed(1)+"KB, chunks:",A.length),Pe?.(),ze?.(!0),c(""),Ue?.(e,z.current)}}else console.log("No video found to upload.")},[W,R,A,oe,U,me]),o(()=>{const e=E(Ke,M);Te(e)},[Ke]),o(()=>{Ve()},[]),e(he,{resetDetector:n,resetScan:Ve,loadingCam:P,onPause:qe,showRestart:re,pause:oe,onReScan:Ge,recordingStarted:R,isScanning:H,startSendingVideoFrames:tt,faceDone:q,stopRecording:He,showPause:de,webcamRef:_,onUserMedia:Re,onUserMediaError:Be,videoConstraints:Me,webcamKey:Ee})});function Se({scanID:t,userDetails:n,setIsVideoUploaded:a,setScanFailsError:s,setScanStartTime:i,setScanUniqueKey:c}){const[l,d]=r(90),[m,p]=r(0),[h,f]=r(null),[g,y]=r(!1),[v,w]=r(0),b=u([]),[x,S]=r(!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(b.current=[...b.current.slice(-4),C],b.current.length>=5){const e=Math.max(...b.current)-Math.min(...b.current);w(N&&e<2?e=>Math.min(100,e+10):e=>Math.max(0,e-20))}N||null===h&&!g||F()},[C,N,h,g]),o(()=>{v>=100&&null===h&&!g&&D(),v<50&&null!==h&&F()},[v,h,g]);const D=()=>{f(3);const e=setInterval(()=>{f(t=>null===t||t<=1?(clearInterval(e),y(!0),null):t-1)},1e3)},F=()=>{f(null),x||y(!1)};return e(pe,{angle:C,countdown:h,isScanning:g,isInTargetRange:N,stabilityScore:v,children:g&&e(xe,{setIsScanLocked:S,resetDetector:()=>{d(90),p(0),f(null),y(!1),w(0),S(!1),b.current=[]},scanID:t,userDetails:n,setIsVideoUploaded:a,setScanFailsError:s,setScanStartTime:i,setScanUniqueKey:c})})}function Ce({message:a,config:r}){const{translate:s}=d(m)||{};return e(ae,{open:!0,className:"confirm-modal common-ui-main",children:e("div",{className:"modal-main",children:e("div",{className:"text-center",children:t(n,a?{children:[e("h2",{style:{fontFamily:r?.style?.heading?.headingFontFamily||"SeriouslyNostalgic Fn",fontSize:r?.style?.heading?.headingFontSize||"32px",color:r?.style?.heading?.headingColor||"#000",fontWeight:r?.style?.heading?.headingFontWeight||"normal"},children:s?.(f.cameraAlreadyInUse)}),e("p",{className:"mt-[0.5rem] text-sm",style:{fontFamily:r?.style?.base?.baseFontFamily||"Inter, sans-serif",fontSize:r?.style?.base?.baseFontSize||"16px",color:r?.style?.base?.baseTextColor||"#000"},children:s?.(f.tryClosingBrowser)})]}:{children:[e("h2",{style:{fontFamily:r?.style?.heading?.headingFontFamily||"SeriouslyNostalgic Fn",fontSize:r?.style?.heading?.headingFontSize||"32px",color:r?.style?.heading?.headingColor||"#000",fontWeight:r?.style?.heading?.headingFontWeight||"normal"},children:s?.(f.checkCameraSettings)}),e("p",{className:"mt-[0.5rem] text-sm",style:{fontFamily:r?.style?.base?.baseFontFamily||"Inter, sans-serif",fontSize:r?.style?.base?.baseFontSize||"16px",color:r?.style?.base?.baseTextColor||"#000"},children:`${s?.(f.setting)} > ${$()} > ${s?.(f.enableCameraPermissions)}`})]})})})})}function Ne({setShowDrawer:t,config:n,loader:a}){const[i,c]=r({disabled:!1,message:""}),[l,d]=r(!0),m=u(null),p=s(async()=>{const e=await _();c(e),d(!1)},[]);return o(()=>{p()},[]),l?e(U,{url:a,loaderType:"black"}):i?.disabled?e(Ce,{config:n,message:i?.message}):e(te,{audio:!1,ref:m,screenshotQuality:1,videoConstraints:z,mirrored:!0,onUserMedia:()=>t?.(!0),screenshotFormat:"image/jpeg",style:{position:"relative",top:0,bottom:0,zIndex:0,width:"100%",height:"100%",objectFit:"cover"}})}function De({link:t,onReady:n,wrapperClassName:a="[&_video]:rounded-t-[20px] w-full h-full"}){const r=u(null),s=u(null);let i={autoplay:!0,controls:!1,responsive:!0,fluid:!0,muted:!0,navigationUI:"hide",preload:"metadata",poster:A};return o(()=>{if(!s.current&&t&&r?.current){const e=oe(r.current,{...i});e.ready(()=>{s.current=e;const a={...i,sources:[{src:t,type:"application/x-mpegURL"}]};e.autoplay(a.autoplay),e.src(a.sources),n?.(e)})}},[t,r]),o(()=>{const e=s.current;return()=>{e&&!e.isDisposed()&&(e.dispose(),s.current=null)}},[s]),e("div",{className:a,children:e("video",{ref:r,muted:!0,className:"video-js",playsInline:!0,onDrag:e=>e.preventDefault()})})}function Fe({scanFailsError:a,onNext:s,gender:o,setScanUniqueKey:i,setIsVideoUploaded:c}){const{translate:l}=d(m)||{},u=p(),[y,v]=r(!1),w=()=>{v(!y)};return t(n,{children:[t("div",{"data-testid":"scan-error-message",className:"flex common-ui-main flex-col h-full max-w-[28rem] mx-auto w-full rounded-t-[20px] overflow-y-auto",style:{background:u?.style?.base?.backgroundColor},children:[e("div",{className:"w-full max-w-[28rem] mx-auto pt-[1rem] px-[1rem]",children:e(h,{noTitle:!0})}),e("div",{className:"flex-1",children:a&&t("div",{className:"px-[1rem]",children:[e("h2",{className:"text-center",style:{fontFamily:u?.style?.heading?.headingFontFamily||"SeriouslyNostalgic Fn",fontSize:u?.style?.heading?.headingFontSize||"32px",color:u?.style?.heading?.headingColor||"#000",fontWeight:u?.style?.heading?.headingFontWeight||"normal"},children:l?.(f.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?.(f.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:j(a)}),e("img",{className:"my-[0.5rem] aspect-[2/1.4] w-full object-cover",onClick:w,src:P[o],alt:"icon"})]})}),a&&e("div",{className:"p-[1rem] flex gap-[0.5rem]",children:e(g,{"data-testid":"scan-again-btn",disabled:!1,buttonText:l?.(f.scanAgain),className:"!shadow-none",buttonFunc:()=>{s?s?.():i?.(L()),c?.(!1)}})})]}),y&&t(ae,{className:"w-screen h-screen video-modal",onClose:w,open:y,children:[e("div",{className:"flex justifyEnd ",children:e("span",{className:"closeBtn",onClick:w,children:e(ne,{className:"absolute right-[8px] top-[8px] text-white z-[9]"})})}),e("div",{className:"aspect-video object-cover rounded-[20px] ",children:e(De,{link:o?V[o].PRE_LINK:V.male.PRE_LINK,wrapperClassName:"w-screen h-screen fixed top-[0] left-[0]"})})]})]})}function Ie({scanId:n,userDetails:a,config:i,isVideoUploadedCorrect:c,isMeasurementAvailable:l,onComplete:u,isSuccess:p,onCustomScanSuccess:y,swan:v}){const{gender:w,shopDomain:b,heightInCm:x,deviceFocalLength:S,userName:C,email:N,scanType:D}=a||{},I=[K,W,O].includes(D??""),[k,T]=r(!0),E=s(async()=>{try{I&&(await(v?.auth.addUser({scanId:n,email:N,name:C,gender:w,height:x})),y?.()),F.capture(b??"",{scanID:n,email:N,height:x,focalLength:S,clothesFit:"0",gender:w})}catch(e){console.log(e)}},[I]),{translate:L}=d(m)||{};o(()=>{(c||l)&&E()},[c,l]);const M=p||c||l;return e(re,{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(Ne,{loader:i?.loader,setShowDrawer:T}),e(se,{open:k,onClose:(e,t)=>{},className:"camera-drawer",anchor:"bottom",children:e("div",{className:"max-w-[28rem] mx-auto w-full h-full flex text-center flex-col justify-between items-center bg-primary rounded-t-[30px] p-[1rem]",style:{background:i?.style?.base?.backgroundColor},children:t("div",{className:"w-full h-full flex flex-col",children:[e(h,{title:L?.(f.measurementsBeingTaken)}),e("div",{className:"flex items-center justify-center flex-1",children:e("video",{preload:"auto",className:"max-h-[calc(100vh-450px)] mx-auto w-full object-contain border-none",muted:!0,loop:!0,autoPlay:!0,playsInline:!0,children:e("source",{src:w===q.Male?R:B,type:"video/mp4"})})}),M&&e(g,{className:"!w-[180px] mx-auto",buttonText:L?.(f.next),buttonFunc:()=>{u?.()}})]})})})]})})}const ke=()=>{const{userDetails:n,onRetry:a,isError:r,isSuccess:s,gender:o,scanUniqueKey:i,scanFailsError:c,setScanUniqueKey:l,setIsVideoUploaded:u,isMeasurementAvailable:m,isVideoUploadedCorrect:h,loading:f,showDeniedModal:g,uploadLoading:y,setScanFailsError:v,setScanStartTime:w,resetScan:x,onCustomScanSuccess:S,swan:C,onComplete:N}=d(b),D=p();return r?t("div",{"data-scan-state":"error",children:[e(Ne,{}),e(se,{anchor:"bottom",open:!0,className:"camera-drawer",onClose:(e,t)=>{},children:e(Fe,{scanFailsError:!0,onNext:a,gender:o})})]}):s?e("div",{"data-scan-state":"success",children:e(Ie,{isSuccess:!0,onComplete:N})}):f?e("div",{"data-scan-state":"loading",className:"flex top-0 !mt-0 left-0 z-[999] absolute justify-center items-center w-full h-full",style:{background:D?.style?.base?.backgroundColor},children:e(U,{url:D?.loader,loaderType:"black"})}):g.disabled?e("div",{"data-scan-state":"camera-denied",children:e(Ce,{})}):y||c||m||h?(y||m||h)&&!c?e("div",{"data-scan-state":"processing",children:e(Ie,{scanId:i,isMeasurementAvailable:m,userDetails:n,isVideoUploadedCorrect:h,onCustomScanSuccess:S,swan:C,onComplete:N})}):t("div",{"data-scan-state":"error-retry",children:[e(Ne,{}),e(se,{anchor:"bottom",open:!0,className:"camera-drawer",onClose:(e,t)=>{},children:e(Fe,{scanFailsError:c,onNext:()=>{a?.(),x()},setScanUniqueKey:l,gender:o,setIsVideoUploaded:u})})]}):e("div",{"data-scan-state":"scanning",children:e(Se,{scanID:i,userDetails:n,setIsVideoUploaded:u,setScanFailsError:v,setScanStartTime:w,setScanUniqueKey:l})})},Te=t=>{const{config:n,onRetry:a,onScanStart:i,onCaptureComplete:c,onUploadStart:d,onUploadEnd:u,onMeasurementSocketStart:m,onMeasurementSocketClose:p,onIntermediateScanSuccess:h,onScanError:f,onScanSuccess:g,onCustomScanSuccess:y,onComplete:v,isError:w,isSuccess:x}=t,S={email:"",shopDomain:"",gender:"male",heightInCm:0,scanType:"",deviceFocalLength:0,deviceModelName:"",sourceTag:"",...t.userDetails??{}},C=t.token??"",{gender:N,scanType:D,shopDomain:F,heightInCm:I,email:E,deviceFocalLength:M,deviceModelName:$,callbackUrl:U,sourceTag:z}=S,A=l(()=>H(C),[C]),[P,V]=r(!1),[R,B]=r(!1),[q,K]=r(!1),[W,O]=r({disabled:!1,message:""}),[ee,te]=r(""),[ne,ae]=r(!1),[re,se]=r(!0),[oe,ie]=r(!1),[ce,le]=r(""),[de,me]=r(T()),{gyroData:pe}=function(e){const[t,n]=r([]),[a,i]=r(!1),c=s(e=>{try{const{alpha:t,beta:a,gamma:r}=e;n(e=>[...e,{alpha:t?.toString()||void 0,beta:a?.toString()||void 0,gamma:r?.toString()||void 0,timestamp:(new Date).toISOString()}])}catch(e){console.log(e)}},[]),l=s(async()=>{const e=DeviceOrientationEvent;if(void 0!==e&&"function"==typeof e.requestPermission)try{"granted"===await e.requestPermission()?i(!0):console.warn("Device orientation permission denied.")}catch(e){console.error("Error requesting device orientation permission:",e)}else i(!0)},[]);return o(()=>(e&&a?window.addEventListener("deviceorientation",c):n([]),()=>{window.removeEventListener("deviceorientation",c)}),[e,a,c]),o(()=>{e&&l()},[e,l]),{gyroData:t}}(oe);J();const he=s(()=>{le(L()),te(""),V(!1),ae(!1)},[]),fe=()=>{me(null),le("")},ge=s(async e=>{if(e&&"success"===e?.scanStatus&&"intermediate"===e?.resultType&&200===e?.code)return k({eventName:`${F}/measurement_success/intermediate`,scanID:ce,status:"success",email:E}),B(!0),void h?.(e);g?.(e),B(!0),fe();const t=ce;K(!0),k({eventName:`${F}/measurement_success/fit-view`,scanID:t,status:"success",email:E}),de&&k({eventName:`${F}/scan_completion_time`,scanID:t,status:"success",completionTime:T()-de,email:E})},[D,F,ce]),ye=e=>{K(!1),te(""),B(!1),A.measurement.handleMeasurementSocket({scanId:ce,onPreopen:()=>{Z({eventName:`${F}/webSocket`,scanID:ce,connection:"pre_open",type:"measurement_recommendation",email:E})},onOpen:()=>{m?.(),Z({eventName:`${F}/webSocket`,scanID:ce,connection:"open",type:"measurement_recommendation",email:E})},onClose:()=>{p?.(),Z({eventName:`${F}/webSocket`,scanID:ce,connection:"close",type:"measurement_recommendation",email:E})},onError:e=>{var t;t=e,f?.({...t,message:j(t)}),fe(),K(!1),te(t),B(!1),k({eventName:`${F}/measurement_failed/fit-view`,scanID:ce,status:"failed",email:E,message:j(t)}),de&&k({eventName:`${F}/scan_completion_time`,scanID:ce,status:"failed",completionTime:T()-de,email:E}),Z({eventName:`${F}/webSocket`,scanID:ce,connection:"error",type:"measurement_recommendation",email:E})},onSuccess:e=>{Z({eventName:`${F}/webSocket`,scanID:ce,connection:"success",type:"measurement_recommendation",email:E}),ge(e)}})},ve=s(async(e,t)=>{const n=Number((e.size/1048576).toFixed(2)),a=null!=t?t:await G(e),r=Q({gender:N,focal_length:`${M}`,height:`${I}`,customer_store_url:F,clothes_fit:"0",scan_type:D,callback_url:U,source_tag:z});k({eventName:`${F}/body_scan_meta_data`,scanID:ce,email:E,data:JSON.stringify([...r,{fileSizeInMB:n,video_fps:a||0}])}),d?.();try{await A.fileUpload.uploadFileFrontend({file:e,arrayMetaData:r,scanId:ce,email:E}),await A.fileUpload.setDeviceInfo({model:$,detection:"manual",gyro:pe,scanId:ce}),console.log("video successfully uploaded"),ae(!1),k({eventName:`${F}/scan_success`,scanID:ce,status:"success",email:E,data:JSON.stringify(r)}),k({eventName:"scan finished",scanID:ce,status:"success",email:E}),me(T()),setTimeout(()=>{ae(!0)},3e3)}catch(e){k({eventName:"scan finished",scanID:ce,status:"failed",email:E,message:j(e)}),k({eventName:`${F}/scan_failed`,scanID:ce,status:"failed",email:E,message:j(e),data:JSON.stringify(r)}),te(j(e)),ae(!1),f?.({...e,message:j(e)}),fe()}finally{ie(!1),u?.()}},[ce,pe,d,u]),we=s(async()=>{if(+I<152.4||+I>213.36)return void f?.({message:"Height must be between 152.4cm (5ft) and 213.36cm (7ft)"});const e=await _();e.disabled?(k({eventName:`${F}/camera_activation`,scanID:ce,status:"failed",email:E}),se(!1)):(se(!1),k({eventName:`${F}/camera_activation`,scanID:ce,status:"success",email:E})),O(e),te(""),ae(!1)},[E,ce,le,F]);return o(()=>{w||x||F&&we()},[F,I,w,x]),o(()=>{w||x||ne&&F&&ce&&ye()},[ne,F,ce,w,x]),e("div",{"data-testid":"body-scan-root",children:e(X,{children:e(Y,{config:n,children:e(ue,{children:e(b.Provider,{value:{userDetails:S,onRetry:a,onScanError:f,isError:w,isSuccess:x,onScanSuccess:g,gender:N,scanUniqueKey:ce,scanFailsError:ee,setScanUniqueKey:le,setIsVideoUploaded:ae,isMeasurementAvailable:q,isVideoUploadedCorrect:R,loading:re,showDeniedModal:W,uploadLoading:P,setStartGyro:ie,uploadScanFile:ve,setUploadLoading:V,resetScan:he,setScanFailsError:te,setScanStartTime:me,onScanStart:i,onCaptureComplete:c,onCustomScanSuccess:y,onComplete:v,swan:A},children:e(ke,{})})})})})})};export{Te as B};
|
|
2
|
-
//# sourceMappingURL=BodyScan-CfS4bPCN.js.map
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";var e=require("react/jsx-runtime"),t=require("react"),a=require("./Modal-CWoUZTh4.js"),s=require("react-webcam"),n=require("lucide-react"),r=require("@mui/material"),o=require("video.js");const c="DESKTOP",i="TAB",u="MOBILE",l=t.createContext(void 0);function d({children:a}){const[s,n]=t.useState([window?.innerWidth,window?.innerHeight]),[r,o]=t.useState(!1),d=()=>{n([window?.innerWidth,window?.innerHeight])};t.useEffect(()=>{d()},[]),t.useLayoutEffect(()=>(window.addEventListener("resize",d),()=>window.removeEventListener("resize",d)),[d]);let m=c;s[0]>768&&s[0]<1024&&(m=i),s[0]<768&&(m=u);const p=t.useMemo(()=>({size:s,setSize:n,clearInputs:r,setClearInputs:o,media:m}),[s,r,m]);return e.jsx(l.Provider,{value:p,children:a})}function m({resetScan:r,loadingCam:o,onUserMedia:c,onPause:i,pause:d,onReScan:m,recordingStarted:p,startSendingVideoFrames:f,showPause:S,webcamRef:h,onUserMediaError:g,resetDetector:v,videoConstraints:y,webcamKey:x,faceDone:w,isScanning:C}){const{media:b}=t.useContext(l)||{},{translate:E}=t.useContext(a.LanguageContext)||{};return e.jsxs("div",{className:"App w-screen h-[100vh] relative common-ui-main","data-testid":"camera-scan","data-scan-phase":w?"spinning":p?"pose-detecting":C?"starting":"ready",children:[e.jsx("span",{onClick:()=>{r(),v()},className:"fixed right-[20px] top-[20px] z-[999]",children:e.jsx(n.X,{className:"text-[#fff]"})}),e.jsx("div",{className:"w-full h-full overflow-hidden ",children:b===u&&e.jsx(s,{audio:!1,ref:h,screenshotQuality:1,videoConstraints:y,mirrored:!0,screenshotFormat:"image/jpeg",onUserMedia:c,onUserMediaError:g,style:{position:"fixed",top:0,left:0,right:0,bottom:0,zIndex:0,width:"100%",height:"100%",objectFit:"cover"}},x)}),e.jsxs("div",{className:"fixed bottom-[30px] w-full z-[999] flex flex-col gap-4 items-center justify-center",children:[S&&e.jsx(a.SpecificButton,{className:"!w-[180px] !h-[40px] !py-[0] mx-auto ",prefix:a.pauseIcon,buttonText:E?.(a.LanguageKeys.pause),buttonFunc:i,btnSecondary:!0}),d?e.jsx("div",{children:e.jsx(a.SpecificButton,{className:"!w-[180px] !h-[40px] !py-[0] mx-auto",buttonText:E?.(a.LanguageKeys.restart),buttonFunc:m,btnSecondary:!0})}):p?null:e.jsx(a.SpecificButton,{"data-testid":"start-scan-btn",className:"!w-[180px] !h-[40px] !py-[0] mx-auto !bg-[#ffffff] !text-[#000000] "+(o?"!opacity-50":""),buttonText:E?.(a.LanguageKeys.startScan),buttonFunc:f,disabled:o})]}),e.jsx("audio",{id:"audioElement",crossOrigin:"anonymous",preload:"auto",style:{position:"absolute",zIndex:-99999},src:`${a.voiceOverAssetsPath}scanAudioInstructions/silence.mp3`})]})}let p=null,f=null,S=null;let h,g=null,v=null;var y=t.memo(function({setIsScanLocked:s,resetDetector:n,scanID:r,setIsVideoUploaded:o,setScanFailsError:c,setScanStartTime:i,setScanUniqueKey:u,userDetails:l}){const{gender:d,heightInCm:y,email:x,shopDomain:w}=l,C=t.useRef(null),b=t.useRef(null),E=t.useRef(null),[j,I]=t.useState([]),[N,D]=t.useState(!0),[T,k]=t.useState(!1),[P,_]=t.useState(!1),[$,M]=t.useState(!0),[F,L]=t.useState(!1),R=t.useRef(null),[A,U]=t.useState(""),[O,K]=t.useState([]),[z,q]=t.useState(""),[B,V]=t.useState(!1),[W,G]=t.useState(!1),[H,J]=t.useState(!1),[Y,Q]=t.useState([]),[X,Z]=t.useState(!1),ee=t.useRef(!0),{poseDetector:te}=function(){const[e,a]=t.useState(0),[s,n]=t.useState(0),[r,o]=t.useState(!1),c=t.useRef(0),i=t.useRef(0),u=t.useRef(!0);async function l(){if("undefined"==typeof window||"undefined"==typeof navigator)return!1;try{console.log("Starting TensorFlow preload...");const[e,t,a]=await Promise.all([Promise.resolve().then(function(){return require("./pose-detection.esm-Bc8T4UAD.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 s={runtime:"mediapipe",modelType:"full",solutionPath:"https://cdn.jsdelivr.net/npm/@mediapipe/pose"};try{f=await S.createDetector(S.SupportedModels.BlazePose,s),console.log("MediaPipe detector created successfully")}catch(e){console.warn("MediaPipe failed, falling back to TFJS runtime:",e),f=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),p=null,!1}}function d(e){return!(!e||0===e.length)&&22===e.filter(e=>e[2]>.7).length}return t.useEffect(()=>{if(u.current=!0,!f)return p||(p=l()),p.then(e=>{e&&u.current&&o(!0)}),()=>{u.current=!1};o(!0)},[]),t.useEffect(()=>{i.current=e,e>6&&c.current<2&&(n(e=>e+1),a(0))},[e]),t.useEffect(()=>{c.current=s},[s]),{poseDetector:async(e,t)=>{if(!f||!u.current||!t?.current?.video)return;const s=t.current.video;if(!(s.readyState<2))try{const t=await f.estimatePoses(s,{flipHorizontal:!1});if(!t||!t.length)return;const n=t[0].keypoints.slice(11).map(e=>[e.x>0&&e.x<720?e.x:-1,e.y>0&&e.y<1280?e.y:-1,e.score??0]);0!==c.current||d(n)||a(e=>e+1),1===c.current&&d(n)&&a(e=>e+1),2===c.current&&e()}catch(e){console.error("Pose detection error:",e)}},isLoaded:r,spinPhase:s,resetDetector:()=>{c.current=0,i.current=0,a(0),n(0)},retryLoading:async()=>{f||p||(p=l(),await p&&u.current&&o(!0))}}}(),ae=t.useRef(!0),se=t.useRef(!1),ne=t.useRef(0),re=t.useRef(0),oe=t.useRef(!1),ce=t.useRef(!1),ie=t.useRef(!1),ue=t.useRef(()=>{}),le=t.useRef(()=>{}),[de,me]=t.useState([]),[pe,fe]=t.useState(0),[Se,he]=t.useState(a.videoConstraintsExact),{setStartGyro:ge,uploadScanFile:ve,setUploadLoading:ye,swan:xe,onScanStart:we,onCaptureComplete:Ce}=t.useContext(a.ParamsContext),be=()=>{se.current=!1,clearTimeout(h),R.current&&clearTimeout(R.current),u(a.generateUuid()),c(""),ye?.(!1),I([]),E.current=null,D(!0),k(!1),_(!1),M(!0),L(!1),R.current=null,U(""),K([]),q(""),V(!B),ge(!1),a.speechService.stopAudio(),G(!1),J(!1),ne.current=0,re.current=0,oe.current=!1,ie.current=!1,null!==b.current&&b.current.stop(),Y.forEach(e=>{b.current&&b.current.removeEventListener("dataavailable",e)}),Q([]),ee.current=!0,Z(!1),o(!1),C.current?.stream&&D(!1)},Ee=t.useCallback(()=>{setTimeout(()=>{D(!1)},1e3)},[]),je=t.useCallback(e=>{if(console.log("camera error",e),Se===a.videoConstraintsExact)return he(a.videoConstraintsFallback),void fe(e=>e+1);D(!1)},[Se]),Ie=t.useCallback(()=>{ee.current=!1,J(!0),Z(!1),R.current&&clearTimeout(R.current),b.current&&b.current.pause(),a.speechService.stopAudio(),xe.poseDetection.disconnect(),ne.current=0,re.current=0,oe.current=!1,ie.current=!1,b.current&&b.current.stop(),Y.forEach(e=>{b.current&&b.current.removeEventListener("dataavailable",e)}),Q([]),clearTimeout(h)},[b,Y,a.speechService,ee]),Ne=t.useMemo(()=>a.getPreferredMediaRecorderTypes(),[]),De=a.getRecordingMimeType(de),Te=a.getRecordingExtension(De),ke=t.useCallback(async()=>{ee.current=!0,await a.speechService.playAudio(`${a.voiceOverAssetsPath}SpotOn.mp3`),J(!1),Z(!1),R.current&&clearTimeout(R.current),k(!1)},[R,a.speechService]),Pe=t.useCallback(async()=>{if(!ce.current&&!g){ce.current=!0;try{g=await xe.poseDetection.connect(),a.posthog.capture(`${w}/pose_detection_connected`,{scanID:r,email:x,id:g})}catch(e){console.log(e,"while connecting websocket")}finally{ce.current=!1}}},[r,w,x]),_e=t.useCallback(async()=>{a.rescanSupportCaptureEvent({eventName:`${w}/rescan`,email:x,scanID:r,height:y,gender:d,status:!1}),ee.current=!1,xe.poseDetection.disconnect(),g=null,be(),await Pe(),le.current()},[Pe,r,x]),$e=t.useCallback(({data:e})=>{e&&e.size>0&&ee.current&&(I(t=>t.concat(e)),!se.current&&C.current&&(se.current=!0,te(()=>{ke(),a.handleScanTimeCapture({eventName:`${w}/tensorFlow`,scanID:r,email:x,message:"recording stopped by tensorflow "})},C)))},[ke,a.handleScanTimeCapture,w,r,x,C]),Me=t.useCallback(async()=>{const e=O[O.length-1];e&&ee.current&&(await a.speechService.playAudio(a.voiceOverAssetsPath+e),ee.current&&(h=setTimeout(Me,2e3)))},[O,ee]),Fe=t.useCallback(()=>{b&&b.current&&b.current.stop(),k(!0);try{if(C&&C.current&&C.current.stream){const e=C.current.stream.getVideoTracks()[0];if(e){const t=e.getSettings();E.current=t.frameRate||null}const t={videoBitsPerSecond:15e5};de[0]&&(t.mimeType=de[0]),b.current=new MediaRecorder(C.current.stream,t),b.current.addEventListener("dataavailable",$e),b.current.addEventListener("stop",()=>{M(!0)}),Q([...Y,$e]),b.current.start(1e3),M(!1)}}catch(e){console.log("error while using media recorder",e)}},[C,de,$e,Y]),Le=t.useCallback(async()=>{R.current&&clearTimeout(R.current),Fe(),ee.current&&(R.current=setTimeout(async()=>{ee.current&&(await a.speechService.playAudio(`${a.voiceOverAssetsPath}SpotOn.mp3`),k(!1))},15e3)),_(!0),ee.current&&await a.speechService.playAudio(`${a.voiceOverAssetsPath}Spin.mp3`)},[Fe,ee,a.speechService]);t.useEffect(()=>{ue.current=Le},[Le]);const Re="undefined"!=typeof window?window.__scanLog??[]:[],Ae=e=>{const t=`[${(new Date).toISOString().slice(11,23)}] [SCAN] ${e}`;console.log(t),Re.push(t)},Ue=t.useCallback(({data:e})=>{const t=xe.poseDetection.connected();e.size>0&&t?(oe.current||(oe.current=!0,Ae(`poseStatus listener REGISTERED | id=${g}`),xe.poseDetection.poseStatus(async e=>{if(e&&e.audio&&e.audio.length>0){const t=document.querySelector("#audioElement"),s=e.audio?.split("/").pop(),n=t?.paused,o=t?.src?.split("/").pop()||"empty";Ae(`poseStatus RECEIVED | status=${e.status} | file=${s} | sid=${e.sid} | id=${g} | sidMatch=${e.sid===g} | counter=${ne.current} | consecFalse=${re.current} | audioPaused=${n} | audioSrc=${o} | audioEl=${t?"found":"NULL"} | lastPlayed=${v?.audioName?.split("/").pop()??"none"} | skipped=${v?.no_of_times_skipped??"-"}/${v?.skipCount??"-"}`),a.posthog.capture(`${w}/pose_instruction_received`,{scanID:r,email:x,audio:e.audio,status:e.status,sid:e.sid,counter:ne.current,consecutiveFalse:re.current,type:"body_scan_instruction"}),!0===e.status&&e.sid===g?(re.current=0,ne.current<2?(ne.current+=1,1!==ne.current||ie.current?2===ne.current&&t?.paused?(Ae(`PLAY good-posture-2 | file=${s}`),a.speechService.playAudio(a.voiceOverAssetsPath+e.audio)):2!==ne.current||t?.paused?Ae(`SKIP good-posture-1 — brilliantPlayed already | counter=${ne.current}`):Ae(`SKIP good-posture-2 — audio still playing | file=${s}`):(Ae(`PLAY good-posture-1 (brilliant) | file=${s}`),ie.current=!0,a.speechService.stopAudio(),await a.speechService.playAudio(a.voiceOverAssetsPath+e.audio))):(Ae(`TRIGGER SPIN | counter=${ne.current} | file=${s}`),q(e.audio),clearTimeout(h),xe.poseDetection.disconnect(),oe.current=!1,setTimeout(()=>ue.current(),1e3))):!0===e.status&&e.sid!==g?Ae(`SKIP good-posture — sid MISMATCH | data.sid=${e.sid} | id=${g}`):(re.current+=1,re.current>=3&&(ne.current=0,ie.current=!1,Ae(`RESET counter/brilliant — consecutiveFalse=${re.current}`)),!t?.paused||v&&v?.audioName===e.audio?t?.paused||v&&v?.audioName===e.audio?v?.audioName===e.audio&&t?.paused?v&&v.no_of_times_skipped>=v.skipCount?(v.no_of_times_skipped=0,Ae(`PLAY wrong-posture REPEAT | file=${s}`),a.speechService.playAudio(a.voiceOverAssetsPath+e.audio)):(v&&(v.no_of_times_skipped+=1),Ae(`SKIP wrong-posture SAME — skip ${v?.no_of_times_skipped}/${v?.skipCount} | file=${s}`)):v?.audioName!==e.audio||t?.paused||Ae(`SKIP wrong-posture SAME — audio still playing | file=${s}`):Ae(`SKIP wrong-posture NEW — audio playing | file=${s}`):(Ae(`PLAY wrong-posture NEW | file=${s}`),v={skipCount:2,no_of_times_skipped:0,audioName:e.audio},a.speechService.playAudio(a.voiceOverAssetsPath+e.audio)))}})),C?.current&&null!==C.current.getScreenshot()&&xe.poseDetection.videoEmit({image:C.current.getScreenshot()||"",scanId:r})):e.size>0&&!t&&Ae(`handleDataAvailable — WS DISCONNECTED | id=${g} | poseListenerRegistered=${oe.current}`)},[C,r,xe,g,a.speechService,w,x]),Oe=t.useCallback(async()=>{L(!0),ge(!0),we?.(),ae.current&&(ae.current=!1,a.handleScanTimeCapture({eventName:"scan started",scanID:r,status:"success",email:x})),i(a.getCurrentTimeInSeconds()),D(!0),ee.current&&await a.speechService.playAudio(`${a.voiceOverAssetsPath}StartScan.mp3`),ee.current&&await a.speechService.playAudio(`${a.voiceOverAssetsPath}LiftArmsAndHoldAtHip.mp3`),ee.current&&(L(!1),k(!0),G(!0),Z(!0),Ee());try{if(C&&C.current&&C.current.stream&&ee.current){const e=C.current.stream.getVideoTracks()[0];if(e){const t=e.getSettings();E.current=t.frameRate||null}const t={videoBitsPerSecond:15e5};de[0]&&(t.mimeType=de[0]),ee.current&&(b.current=new MediaRecorder(C.current.stream,t)),ee.current&&b.current&&b.current.addEventListener("dataavailable",Ue),Q([...Y,Ue]),b.current&&b.current.start(1e3),M(!1),ee.current&&(h=setTimeout(Me,2e3))}}catch(e){console.log("error ----------",e)}},[C,de,Ue,Y,Me,ee,we]);return t.useEffect(()=>(w&&(s(!0),Pe()),()=>{const e=g;g=null,e&&(xe.poseDetection.disconnect(),a.posthog.capture(`${w}/pose_detection_disconnected`,{scanID:r,email:x,id:e})),Y.forEach(e=>{b?.current?.removeEventListener("dataavailable",e)})}),[w]),t.useEffect(()=>{O.push(A)},[A]),t.useEffect(()=>{K([])},[z]),t.useEffect(()=>{const e=j.length&&j.length>0;$||!e||T||!ee.current||H||b&&b.current&&(T||b.current.stop())},[$,T,j,H]),t.useEffect(()=>{const e=j.length&&j.length>0;if($&&e&&!T&&b&&b.current&&ee.current&&!H&&!T){const e=new File(j,`${r}.${Te}`,{type:De});Ce?.(),ye?.(!0),c(""),ve?.(e,E.current)}},[$,T,j,H,b,ee]),t.useEffect(()=>{le.current=Oe},[Oe]),t.useEffect(()=>{const e=a.getSupportedMediaRecorderTypes(Ne,a.videoTypes);me(e)},[Ne]),t.useEffect(()=>{be()},[]),e.jsx(m,{resetDetector:n,resetScan:be,loadingCam:N,onPause:Ie,showRestart:W,pause:H,onReScan:_e,recordingStarted:T,isScanning:F,startSendingVideoFrames:Oe,faceDone:P,stopRecording:ke,showPause:X,webcamRef:C,onUserMedia:Ee,onUserMediaError:je,videoConstraints:Se,webcamKey:pe})});function x({scanID:a,userDetails:s,setIsVideoUploaded:n,setScanFailsError:r,setScanStartTime:o,setScanUniqueKey:c}){const[i,u]=t.useState(90),[l,d]=t.useState(0),[m,p]=t.useState(null),[f,S]=t.useState(!1),[h,g]=t.useState(0),v=t.useRef([]),[x,w]=t.useState(!1),C=i-l,b=C>=80&&C<=95;t.useEffect(()=>{if("undefined"!=typeof window&&window.DeviceOrientationEvent){const e=e=>{if(null!==e.beta){let t=Math.abs(e.beta);null!==e.gamma&&(t*=Math.cos(e.gamma*Math.PI/180)),t=Math.max(0,Math.min(180,t)),u(t)}},t=async()=>{const t=DeviceOrientationEvent;if(t&&"function"==typeof t.requestPermission)try{"granted"===await t.requestPermission()&&window.addEventListener("deviceorientation",e)}catch(e){console.error("Permission error",e)}else window.addEventListener("deviceorientation",e);return()=>{e&&window.removeEventListener("deviceorientation",e)}};document.addEventListener("click",t,{once:!0})}},[]),t.useEffect(()=>{if(v.current=[...v.current.slice(-4),C],v.current.length>=5){const e=Math.max(...v.current)-Math.min(...v.current);g(b&&e<2?e=>Math.min(100,e+10):e=>Math.max(0,e-20))}b||null===m&&!f||j()},[C,b,m,f]),t.useEffect(()=>{h>=100&&null===m&&!f&&E(),h<50&&null!==m&&j()},[h,m,f]);const E=()=>{p(3);const e=setInterval(()=>{p(t=>null===t||t<=1?(clearInterval(e),S(!0),null):t-1)},1e3)},j=()=>{p(null),x||S(!1)};return e.jsx(y,{setIsScanLocked:w,resetDetector:()=>{u(90),d(0),p(null),S(!1),g(0),w(!1),v.current=[]},scanID:a,userDetails:s,setIsVideoUploaded:n,setScanFailsError:r,setScanStartTime:o,setScanUniqueKey:c})}function w({setShowDrawer:n,config:r,loader:o}){const[c,i]=t.useState({disabled:!1,message:""}),[u,l]=t.useState(!0),d=t.useRef(null),m=t.useCallback(async()=>{const e=await a.checkCameraPermission();i(e),l(!1)},[]);return t.useEffect(()=>{m()},[]),u?e.jsx(a.LoadingScreen,{url:o,loaderType:"black"}):c?.disabled?e.jsx(a.Modal,{config:r,message:c?.message}):e.jsx(s,{audio:!1,ref:d,screenshotQuality:1,videoConstraints:a.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 C({link:s,onReady:n,wrapperClassName:r="[&_video]:rounded-t-[20px] w-full h-full"}){const c=t.useRef(null),i=t.useRef(null);let u={autoplay:!0,controls:!1,responsive:!0,fluid:!0,muted:!0,navigationUI:"hide",preload:"metadata",poster:a.videoPoster};return t.useEffect(()=>{if(!i.current&&s&&c?.current){const e=o(c.current,{...u});e.ready(()=>{i.current=e;const t={...u,sources:[{src:s,type:"application/x-mpegURL"}]};e.autoplay(t.autoplay),e.src(t.sources),n?.(e)})}},[s,c]),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:c,muted:!0,className:"video-js",playsInline:!0,onDrag:e=>e.preventDefault()})})}function b({scanFailsError:s,onNext:o,gender:c,setScanUniqueKey:i,setIsVideoUploaded:u}){const{translate:l}=t.useContext(a.LanguageContext)||{},d=a.useConfig(),[m,p]=t.useState(!1),f=()=>{p(!m)};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{"data-testid":"scan-error-message",className:"flex common-ui-main flex-col h-full max-w-[28rem] mx-auto w-full rounded-t-[20px] overflow-y-auto",style:{background:d?.style?.base?.backgroundColor},children:[e.jsx("div",{className:"w-full max-w-[28rem] mx-auto pt-[1rem] px-[1rem]",children:e.jsx(a.Header,{noTitle:!0})}),e.jsx("div",{className:"flex-1",children:s&&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:l?.(a.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:l?.(a.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:a.handleErrorMessage(s)}),e.jsx("img",{className:"my-[0.5rem] aspect-[2/1.4] w-full object-cover",onClick:f,src:a.VIDEO_POSTER_GENDER_BASED[c],alt:"icon"})]})}),s&&e.jsx("div",{className:"p-[1rem] flex gap-[0.5rem]",children:e.jsx(a.SpecificButton,{"data-testid":"scan-again-btn",disabled:!1,buttonText:l?.(a.LanguageKeys.scanAgain),className:"!shadow-none",buttonFunc:()=>{o?o?.():i?.(a.generateUuid()),u?.(!1)}})})]}),m&&e.jsxs(r.Dialog,{className:"w-screen h-screen video-modal",onClose:f,open:m,children:[e.jsx("div",{className:"flex justifyEnd ",children:e.jsx("span",{className:"closeBtn",onClick:f,children:e.jsx(n.X,{className:"absolute right-[8px] top-[8px] text-white z-[9]"})})}),e.jsx("div",{className:"aspect-video object-cover rounded-[20px] ",children:e.jsx(C,{link:c?a.GENDER[c].PRE_LINK:a.GENDER.male.PRE_LINK,wrapperClassName:"w-screen h-screen fixed top-[0] left-[0]"})})]})]})}function E({scanId:s,userDetails:n,config:o,isVideoUploadedCorrect:c,isMeasurementAvailable:i,onComplete:u,isSuccess:l,onCustomScanSuccess:d,swan:m}){const{gender:p,shopDomain:f,heightInCm:S,deviceFocalLength:h,userName:g,email:v,scanType:y}=n||{},x=[a.CLOTHING_CUSTOM_SCAN,a.CLOTHING_BANNER_SCAN,a.CLOTHING_CUSTOM_FIT_SCAN].includes(y??""),[C,b]=t.useState(!0),E=t.useCallback(async()=>{try{x&&(await(m?.auth.addUser({scanId:s,email:v,name:g,gender:p,height:S})),d?.()),a.posthog.capture(f??"",{scanID:s,email:v,height:S,focalLength:h,clothesFit:"0",gender:p})}catch(e){console.log(e)}},[x]),{translate:j}=t.useContext(a.LanguageContext)||{};t.useEffect(()=>{(c||i)&&E()},[c,i]);const I=l||c||i;return e.jsx(r.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(w,{loader:o?.loader,setShowDrawer:b}),e.jsx(r.Drawer,{open:C,onClose:(e,t)=>{},className:"camera-drawer",anchor:"bottom",children:e.jsx("div",{className:"max-w-[28rem] mx-auto w-full h-full flex text-center flex-col justify-between items-center bg-primary rounded-t-[30px] p-[1rem]",style:{background:o?.style?.base?.backgroundColor},children:e.jsxs("div",{className:"w-full h-full flex flex-col",children:[e.jsx(a.Header,{title:j?.(a.LanguageKeys.measurementsBeingTaken)}),e.jsx("div",{className:"flex items-center justify-center flex-1",children:e.jsx("video",{preload:"auto",className:"max-h-[calc(100vh-450px)] mx-auto w-full object-contain border-none",muted:!0,loop:!0,autoPlay:!0,playsInline:!0,children:e.jsx("source",{src:p===a.GenderType.Male?a.maleMeasurementProgress:a.measurementProgress,type:"video/mp4"})})}),I&&e.jsx(a.SpecificButton,{className:"!w-[180px] mx-auto",buttonText:j?.(a.LanguageKeys.next),buttonFunc:()=>{u?.()}})]})})})]})})}const j=()=>{const{userDetails:s,onRetry:n,isError:o,isSuccess:c,gender:i,scanUniqueKey:u,scanFailsError:l,setScanUniqueKey:d,setIsVideoUploaded:m,isMeasurementAvailable:p,isVideoUploadedCorrect:f,loading:S,showDeniedModal:h,uploadLoading:g,setScanFailsError:v,setScanStartTime:y,resetScan:C,onCustomScanSuccess:j,swan:I,onComplete:N}=t.useContext(a.ParamsContext),D=a.useConfig();return o?e.jsxs("div",{"data-scan-state":"error",children:[e.jsx(w,{}),e.jsx(r.Drawer,{anchor:"bottom",open:!0,className:"camera-drawer",onClose:(e,t)=>{},children:e.jsx(b,{scanFailsError:!0,onNext:n,gender:i})})]}):c?e.jsx("div",{"data-scan-state":"success",children:e.jsx(E,{isSuccess:!0,onComplete:N})}):S?e.jsx("div",{"data-scan-state":"loading",className:"flex top-0 !mt-0 left-0 z-[999] absolute justify-center items-center w-full h-full",style:{background:D?.style?.base?.backgroundColor},children:e.jsx(a.LoadingScreen,{url:D?.loader,loaderType:"black"})}):h.disabled?e.jsx("div",{"data-scan-state":"camera-denied",children:e.jsx(a.Modal,{})}):g||l||p||f?(g||p||f)&&!l?e.jsx("div",{"data-scan-state":"processing",children:e.jsx(E,{scanId:u,isMeasurementAvailable:p,userDetails:s,isVideoUploadedCorrect:f,onCustomScanSuccess:j,swan:I,onComplete:N})}):e.jsxs("div",{"data-scan-state":"error-retry",children:[e.jsx(w,{}),e.jsx(r.Drawer,{anchor:"bottom",open:!0,className:"camera-drawer",onClose:(e,t)=>{},children:e.jsx(b,{scanFailsError:l,onNext:()=>{n?.(),C()},setScanUniqueKey:d,gender:i,setIsVideoUploaded:m})})]}):e.jsx("div",{"data-scan-state":"scanning",children:e.jsx(x,{scanID:u,userDetails:s,setIsVideoUploaded:m,setScanFailsError:v,setScanStartTime:y,setScanUniqueKey:d})})};exports.BodyScan=s=>{const{config:n,onRetry:r,onScanStart:o,onCaptureComplete:c,onUploadStart:i,onUploadEnd:u,onMeasurementSocketStart:l,onMeasurementSocketClose:m,onIntermediateScanSuccess:p,onScanError:f,onScanSuccess:S,onCustomScanSuccess:h,onComplete:g,isError:v,isSuccess:y}=s,x={email:"",shopDomain:"",gender:"male",heightInCm:0,scanType:"",deviceFocalLength:0,deviceModelName:"",sourceTag:"",callbackUrl:null,...s.userDetails??{}},w=s.token??"",{gender:C,scanType:b,shopDomain:E,heightInCm:I,email:N,deviceFocalLength:D,deviceModelName:T,callbackUrl:k,sourceTag:P}=x,_=t.useMemo(()=>a.getSwanService(w),[w]),[$,M]=t.useState(!1),[F,L]=t.useState(!1),[R,A]=t.useState(!1),[U,O]=t.useState({disabled:!1,message:""}),[K,z]=t.useState(""),[q,B]=t.useState(!1),[V,W]=t.useState(!0),[G,H]=t.useState(!1),[J,Y]=t.useState(""),[Q,X]=t.useState(a.getCurrentTimeInSeconds()),{gyroData:Z}=function(e){const[a,s]=t.useState([]),[n,r]=t.useState(!1),o=t.useCallback(e=>{try{const{alpha:t,beta:a,gamma:n}=e;s(e=>[...e,{alpha:t?.toString()||void 0,beta:a?.toString()||void 0,gamma:n?.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&&n?window.addEventListener("deviceorientation",o):s([]),()=>{window.removeEventListener("deviceorientation",o)}),[e,n,o]),t.useEffect(()=>{e&&c()},[e,c]),{gyroData:a}}(G);a.usePosthogPageview();const ee=t.useCallback(()=>{Y(a.generateUuid()),z(""),M(!1),B(!1)},[]),te=()=>{X(null),Y("")},ae=t.useCallback(async e=>{if(e&&"success"===e?.scanStatus&&"intermediate"===e?.resultType&&200===e?.code)return a.handleScanTimeCapture({eventName:`${E}/measurement_success/intermediate`,scanID:J,status:"success",email:N}),L(!0),void p?.(e);S?.(e),L(!0),te();const t=J;A(!0),a.handleScanTimeCapture({eventName:`${E}/measurement_success/fit-view`,scanID:t,status:"success",email:N}),Q&&a.handleScanTimeCapture({eventName:`${E}/scan_completion_time`,scanID:t,status:"success",completionTime:a.getCurrentTimeInSeconds()-Q,email:N})},[b,E,J]),se=e=>{A(!1),z(""),L(!1),_.measurement.handleMeasurementSocket({scanId:J,onPreopen:()=>{a.handleWebSocketCapture({eventName:`${E}/webSocket`,scanID:J,connection:"pre_open",type:"measurement_recommendation",email:N})},onOpen:()=>{l?.(),a.handleWebSocketCapture({eventName:`${E}/webSocket`,scanID:J,connection:"open",type:"measurement_recommendation",email:N})},onClose:()=>{m?.(),a.handleWebSocketCapture({eventName:`${E}/webSocket`,scanID:J,connection:"close",type:"measurement_recommendation",email:N})},onError:e=>{var t;t=e,f?.({...t,message:a.handleErrorMessage(t)}),te(),A(!1),z(t),L(!1),a.handleScanTimeCapture({eventName:`${E}/measurement_failed/fit-view`,scanID:J,status:"failed",email:N,message:a.handleErrorMessage(t)}),Q&&a.handleScanTimeCapture({eventName:`${E}/scan_completion_time`,scanID:J,status:"failed",completionTime:a.getCurrentTimeInSeconds()-Q,email:N}),a.handleWebSocketCapture({eventName:`${E}/webSocket`,scanID:J,connection:"error",type:"measurement_recommendation",email:N})},onSuccess:e=>{a.handleWebSocketCapture({eventName:`${E}/webSocket`,scanID:J,connection:"success",type:"measurement_recommendation",email:N}),ae(e)}})},ne=t.useCallback(async(e,t)=>{const s=Number((e.size/1048576).toFixed(2)),n=null!=t?t:await a.getVideoFPS(e),r=a.createObjectMetadataArray({gender:C,focal_length:`${D}`,height:`${I}`,customer_store_url:E,clothes_fit:"0",scan_type:b,callback_url:k,source_tag:P});a.handleScanTimeCapture({eventName:`${E}/body_scan_meta_data`,scanID:J,email:N,data:JSON.stringify([...r,{fileSizeInMB:s,video_fps:n||0}])}),i?.();try{await _.fileUpload.uploadFileFrontend({file:e,arrayMetaData:r,scanId:J,email:N}),await _.fileUpload.setDeviceInfo({model:T,detection:"manual",gyro:Z,scanId:J}),console.log("video successfully uploaded"),B(!1),a.handleScanTimeCapture({eventName:`${E}/scan_success`,scanID:J,status:"success",email:N,data:JSON.stringify(r)}),a.handleScanTimeCapture({eventName:"scan finished",scanID:J,status:"success",email:N}),X(a.getCurrentTimeInSeconds()),setTimeout(()=>{B(!0)},3e3)}catch(e){a.handleScanTimeCapture({eventName:"scan finished",scanID:J,status:"failed",email:N,message:a.handleErrorMessage(e)}),a.handleScanTimeCapture({eventName:`${E}/scan_failed`,scanID:J,status:"failed",email:N,message:a.handleErrorMessage(e),data:JSON.stringify(r)}),z(a.handleErrorMessage(e)),B(!1),f?.({...e,message:a.handleErrorMessage(e)}),te()}finally{H(!1),u?.()}},[J,Z,i,u]),re=t.useCallback(async()=>{if(+I<152.4||+I>213.36)return void f?.({message:"Height must be between 152.4cm (5ft) and 213.36cm (7ft)"});const e=await a.checkCameraPermission();e.disabled?(a.handleScanTimeCapture({eventName:`${E}/camera_activation`,scanID:J,status:"failed",email:N}),W(!1)):(W(!1),a.handleScanTimeCapture({eventName:`${E}/camera_activation`,scanID:J,status:"success",email:N})),O(e),z(""),B(!1)},[N,J,Y,E]);return t.useEffect(()=>{v||y||E&&re()},[E,I,v,y]),t.useEffect(()=>{v||y||q&&E&&J&&se()},[q,E,J,v,y]),e.jsx("div",{"data-testid":"body-scan-root",children:e.jsx(a.LanguageContextProvider,{children:e.jsx(a.ConfigProvider,{config:n,children:e.jsx(d,{children:e.jsx(a.ParamsContext.Provider,{value:{userDetails:x,onRetry:r,onScanError:f,isError:v,isSuccess:y,onScanSuccess:S,gender:C,scanUniqueKey:J,scanFailsError:K,setScanUniqueKey:Y,setIsVideoUploaded:B,isMeasurementAvailable:R,isVideoUploadedCorrect:F,loading:V,showDeniedModal:U,uploadLoading:$,setStartGyro:H,uploadScanFile:ne,setUploadLoading:M,resetScan:ee,setScanFailsError:z,setScanStartTime:X,onScanStart:o,onCaptureComplete:c,onCustomScanSuccess:h,onComplete:g,swan:_},children:e.jsx(j,{})})})})})})};
|
|
2
|
-
//# sourceMappingURL=BodyScan-CiG19l_n.js.map
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";var e=require("react/jsx-runtime"),t=require("react"),s=require("./Modal-4T_aWWPQ.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,[]),v=t.useCallback((e=!1)=>{const t=m();return o?d?.style?.angleDetector?.successAngleTextLightColor:x(e,t)},[o,m]),S=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},"data-testid":"level-screen","data-angle-state":o?"locked":c?"target":"adjusting",children:[e.jsx("div",{className:"flex justify-start fixed top-[.5rem] max-w-[28rem] mx-auto w-full px-[1rem]",children:e.jsx("div",{className:"flex justify-start ",children:e.jsx(s.Header,{noTitle:!0})})}),null!==S?e.jsx("div",{className:"relative flex h-[6rem] w-[6rem] items-center justify-center rounded-[9999px] bg-[#fff]/20 transition-all duration-300",style:{border:`2px solid ${v()}`},children:e.jsx("div",{className:`text-[3rem] font-bold text-[${v()}]`,style:{fontFamily:d?.style?.base?.baseFontFamily||"Inter, sans-serif",color:v()},children:S})}):o?e.jsxs("div",{className:"relative flex flex-col items-center justify-center",children:[e.jsx("div",{className:"relative flex h-16 w-16 items-center justify-center rounded-[9999px] border-2 bg-[#fff]/30 border-[#fff]",children:e.jsx("div",{className:"h-4 w-4 rounded-[9999px] animate-pulse bg-[#fff]/80"})}),l]}):e.jsxs("div",{className:n("relative flex h-[4rem] w-[4rem] items-center justify-center rounded-[9999px] ",c?"bg-[#fff]/20 border-[#fff]":"bg-[#fff]/10 border-[#fff]"),style:{transform:`translateY(${3*(90-a)}px)`,transition:"transform 0.2s ease-out",border:`2px solid ${v()}`},children:[e.jsx("div",{className:`h-[1rem] w-[1rem] rounded-[9999px] bg-[${v()}]/80`,style:{backgroundColor:`${v()}B3`}}),e.jsxs("div",{className:n("mt-[.5rem] text-center w-[180px] flex-col flex items-center absolute top-[60px]",g()),style:{color:v()},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!==S&&e.jsx("div",{className:"absolute bottom-[8rem] text-center",children:e.jsx("div",{className:n("text-sm font-medium px-4 py-1.5 bg-black/20 rounded-[9999px] mt-8",g()),style:{fontFamily:d?.style?.base?.baseFontFamily||"Inter, sans-serif",color:v()},children:u?.(s.LanguageKeys.leavePhone)})}),c&&null===S&&!o&&e.jsx("div",{className:"absolute bottom-[8rem] w-[12rem]",children:e.jsx("div",{className:`h-[.375rem] w-full bg-[${v()}]/20 rounded-[9999px] overflow-hidden`,style:{backgroundColor:`${v()}33`},children:e.jsx("div",{className:`h-full bg-[${v()}]/70 transition-all duration-300 rounded-[9999px]`,style:{width:`${a}%`,backgroundColor:`${v()}B3`}})})}),null===S&&!o&&e.jsx("div",{className:"absolute bottom-[5rem] text-center",children:e.jsxs("div",{className:n("text-[1.5rem] font-light",g()),style:{color:v()},children:[Math.round(a),"°"]})}),null===S&&!o&&e.jsx("div",{className:"absolute bottom-[2rem] text-center max-w-[20rem] mx-auto",children:e.jsx("div",{className:n("text-[.75rem] opacity-50",g()),style:{fontFamily:d?.style?.base?.baseFontFamily||"Inter, sans-serif",color:v()},children:u?.(s.LanguageKeys.placePhoneUpright)})})]})});function h({resetScan:n,loadingCam:o,onUserMedia:c,onPause:i,pause:l,onReScan:m,recordingStarted:p,startSendingVideoFrames:f,showPause:h,webcamRef:g,onUserMediaError:x,resetDetector:v,videoConstraints:S,webcamKey:y,faceDone:C,isScanning:b}){const{media:w}=t.useContext(d)||{},{translate:j}=t.useContext(s.LanguageContext)||{};return e.jsxs("div",{className:"App w-screen h-[100vh] relative common-ui-main","data-testid":"camera-scan","data-scan-phase":C?"spinning":p?"pose-detecting":b?"starting":"ready",children:[e.jsx("span",{onClick:()=>{n(),v()},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:w===u&&e.jsx(a,{audio:!1,ref:g,screenshotQuality:1,videoConstraints:S,mirrored:!0,screenshotFormat:"image/jpeg",onUserMedia:c,onUserMediaError:x,style:{position:"fixed",top:0,bottom:0,zIndex:0,width:"100%",height:"100%",objectFit:"cover"}},y)}),e.jsxs("div",{className:"fixed bottom-[30px] w-full z-[999] flex flex-col gap-4 items-center justify-center",children:[h&&e.jsx(s.SpecificButton,{className:"!w-[180px] !h-[40px] !py-[0] mx-auto ",prefix:s.pauseIcon,buttonText:j?.(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:j?.(s.LanguageKeys.restart),buttonFunc:m,btnSecondary:!0})}):p?null:e.jsx(s.SpecificButton,{"data-testid":"start-scan-btn",className:"!w-[180px] !h-[40px] !py-[0] mx-auto !bg-[#ffffff] !text-[#000000] "+(o?"!opacity-50":""),buttonText:j?.(s.LanguageKeys.startScan),buttonFunc:f,disabled:o})]}),e.jsx("audio",{id:"audioElement",crossOrigin:"anonymous",preload:"auto",style:{position:"absolute",zIndex:-99999},src:`${s.voiceOverAssetsPath}scanAudioInstructions/silence.mp3`})]})}let g=null,x=null,v=null;let S,y=null,C=null;var b=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,b=t.useRef(null),w=t.useRef(null),j=t.useRef(null),[k,E]=t.useState([]),[N,D]=t.useState(!0),[T,I]=t.useState(!1),[L,M]=t.useState(!1),[F,_]=t.useState(!0),[P,A]=t.useState(!1),R=t.useRef(null),[$,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-Bc8T4UAD.js")}),import("@tensorflow/tfjs-core"),import("@tensorflow/tfjs-backend-webgl")]);v=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 v.createDetector(v.SupportedModels.BlazePose,n),console.log("MediaPipe detector created successfully")}catch(e){console.warn("MediaPipe failed, falling back to TFJS runtime:",e),x=await v.createDetector(v.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(!1),le=t.useRef(!1),ue=t.useRef(0),de=t.useRef(()=>{}),me=t.useRef(()=>{}),[pe,fe]=t.useState([]),[he,ge]=t.useState(0),[xe,ve]=t.useState(s.videoConstraintsExact),{setStartGyro:Se,uploadScanFile:ye,setUploadLoading:Ce,swan:be,onScanStart:we,onCaptureComplete:je}=t.useContext(s.ParamsContext),ke=()=>{ne.current=!1,clearTimeout(S),R.current&&clearTimeout(R.current),l(s.generateUuid()),c(""),Ce?.(!1),E([]),j.current=null,D(!0),I(!1),M(!1),_(!0),A(!1),R.current=null,U(""),z([]),B(""),V(!q),Se(!1),s.speechService.stopAudio(),H(!1),J(!1),ae.current=0,re.current=0,oe.current=!1,ie.current=!1,le.current=!1,ue.current=0,C=null,y=null,null!==w.current&&w.current.stop(),Q.forEach(e=>{w.current&&w.current.removeEventListener("dataavailable",e)}),X([]),ee.current=!0,Z(!1),o(!1),b.current?.stream&&D(!1)},Ee=t.useCallback(()=>{setTimeout(()=>{D(!1)},1e3)},[]),Ne=t.useCallback(e=>{if(console.log("camera error",e),xe===s.videoConstraintsExact)return ve(s.videoConstraintsFallback),void ge(e=>e+1);D(!1)},[xe]),De=t.useCallback(()=>{ee.current=!1,le.current=!1,J(!0),Z(!1),R.current&&clearTimeout(R.current),w.current&&w.current.pause(),s.speechService.stopAudio(),be.poseDetection.disconnect(),ae.current=0,re.current=0,oe.current=!1,ie.current=!1,w.current&&w.current.stop(),Q.forEach(e=>{w.current&&w.current.removeEventListener("dataavailable",e)}),X([]),clearTimeout(S)},[w,Q,s.speechService,ee]),Te=t.useMemo(()=>s.getPreferredMediaRecorderTypes(),[]),Ie=s.getRecordingMimeType(pe),Le=s.getRecordingExtension(Ie),Me=t.useCallback(async()=>{ee.current=!0,await s.speechService.playAudio(`${s.voiceOverAssetsPath}SpotOn.mp3`),J(!1),Z(!1),R.current&&clearTimeout(R.current),I(!1)},[R,s.speechService]),Fe=t.useCallback(async()=>{if(!ce.current&&!y){ce.current=!0;try{y=await be.poseDetection.connect(),s.posthog.capture(`${f}/pose_detection_connected`,{scanID:r,email:p,id:y})}catch(e){console.log(e,"while connecting websocket"),c("Could not connect. Please try again.")}finally{ce.current=!1}}},[r,f,p,c]),_e=t.useCallback(async()=>{s.rescanSupportCaptureEvent({eventName:`${f}/rescan`,email:p,scanID:r,height:m,gender:d,status:!1}),ee.current=!1,be.poseDetection.disconnect(),y=null,ke(),await Fe(),me.current()},[Fe,r,p]),Pe=t.useCallback(({data:e})=>{e&&e.size>0&&ee.current&&(E(t=>t.concat(e)),!ne.current&&b.current&&(ne.current=!0,te(()=>{Me(),s.handleScanTimeCapture({eventName:`${f}/tensorFlow`,scanID:r,email:p,message:"recording stopped by tensorflow "})},b)))},[Me,s.handleScanTimeCapture,f,r,p,b]),Ae=t.useCallback(async()=>{const e=O[O.length-1];e&&ee.current&&(await s.speechService.playAudio(s.voiceOverAssetsPath+e),ee.current&&(S=setTimeout(Ae,2e3)))},[O,ee]),Re=t.useCallback(()=>{w&&w.current&&w.current.stop(),I(!0);try{if(b&&b.current&&b.current.stream){const e=b.current.stream.getVideoTracks()[0];if(e){const t=e.getSettings();j.current=t.frameRate||null}const t={videoBitsPerSecond:15e5};pe[0]&&(t.mimeType=pe[0]),w.current=new MediaRecorder(b.current.stream,t),w.current.addEventListener("dataavailable",Pe),w.current.addEventListener("stop",()=>{_(!0)}),X([...Q,Pe]),w.current.start(1e3),_(!1)}}catch(e){console.log("error while using media recorder",e)}},[b,pe,Pe,Q]),$e=t.useCallback(async()=>{R.current&&clearTimeout(R.current),Re(),ee.current&&(R.current=setTimeout(async()=>{ee.current&&(await s.speechService.playAudio(`${s.voiceOverAssetsPath}SpotOn.mp3`),I(!1))},15e3)),M(!0),ee.current&&await s.speechService.playAudio(`${s.voiceOverAssetsPath}Spin.mp3`)},[Re,ee,s.speechService]);t.useEffect(()=>{de.current=$e},[$e]);const Ue=t.useCallback(({data:e})=>{e.size>0&&be.poseDetection.connected()?(ue.current=0,oe.current||(oe.current=!0,be.poseDetection.poseStatus(async 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"}),!0===e.status?(re.current=0,ae.current<2?(ae.current+=1,1!==ae.current||ie.current?2!==ae.current||le.current||(le.current=!0,s.speechService.playAudio(s.voiceOverAssetsPath+e.audio).finally(()=>{le.current=!1})):(ie.current=!0,s.speechService.stopAudio(),le.current=!0,await s.speechService.playAudio(s.voiceOverAssetsPath+e.audio),le.current=!1)):(B(e.audio),clearTimeout(S),be.poseDetection.disconnect(),oe.current=!1,setTimeout(()=>de.current(),1e3))):(re.current+=1,re.current>=3&&(ae.current=0,ie.current=!1),le.current||C&&C?.audioName===e.audio?C?.audioName!==e.audio||le.current||(C&&C.no_of_times_skipped>=C.skipCount?(C.no_of_times_skipped=0,le.current=!0,s.speechService.playAudio(s.voiceOverAssetsPath+e.audio).finally(()=>{le.current=!1})):C&&(C.no_of_times_skipped+=1)):(C={skipCount:2,no_of_times_skipped:0,audioName:e.audio},le.current=!0,s.speechService.playAudio(s.voiceOverAssetsPath+e.audio).finally(()=>{le.current=!1}))))})),b?.current&&null!==b.current.getScreenshot()&&be.poseDetection.videoEmit({image:b.current.getScreenshot()||"",scanId:r})):e.size>0&&(ue.current+=1,ue.current>=5&&(ee.current=!1,s.speechService.stopAudio(),be.poseDetection.disconnect(),w.current&&w.current.stop(),c("Connection lost during scan. Please try again.")))},[b,r,be,y,s.speechService,f,p,c]),Oe=t.useCallback(async()=>{A(!0),Se(!0),we?.(),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),Ee());try{if(b&&b.current&&b.current.stream&&ee.current){const e=b.current.stream.getVideoTracks()[0];if(e){const t=e.getSettings();j.current=t.frameRate||null}const t={videoBitsPerSecond:15e5};pe[0]&&(t.mimeType=pe[0]),ee.current&&(w.current=new MediaRecorder(b.current.stream,t)),ee.current&&w.current&&w.current.addEventListener("dataavailable",Ue),X([...Q,Ue]),w.current&&w.current.start(1e3),_(!1),ee.current&&(S=setTimeout(Ae,2e3))}}catch(e){console.log("error ----------",e)}},[b,pe,Ue,Q,Ae,ee,we]);return t.useEffect(()=>(f&&(n(!0),Fe()),()=>{const e=y;y=null,e&&(be.poseDetection.disconnect(),s.posthog.capture(`${f}/pose_detection_disconnected`,{scanID:r,email:p,id:e})),Q.forEach(e=>{w?.current?.removeEventListener("dataavailable",e)})}),[f]),t.useEffect(()=>{O.push($)},[$]),t.useEffect(()=>{z([])},[K]),t.useEffect(()=>{const e=k.length&&k.length>0;F||!e||T||!ee.current||G||w&&w.current&&(T||w.current.stop())},[F,T,k,G]),t.useEffect(()=>{const e=k.length&&k.length>0;if(F&&e&&!T&&w&&w.current&&ee.current&&!G&&!T){const e=new File(k,`${r}.${Le}`,{type:Ie});je?.(),Ce?.(!0),c(""),ye?.(e,j.current)}},[F,T,k,G,w,ee]),t.useEffect(()=>{me.current=Oe},[Oe]),t.useEffect(()=>{const e=s.getSupportedMediaRecorderTypes(Te,s.videoTypes);fe(e)},[Te]),t.useEffect(()=>{ke()},[]),e.jsx(h,{resetDetector:a,resetScan:ke,loadingCam:N,onPause:De,showRestart:W,pause:G,onReScan:_e,recordingStarted:T,isScanning:P,startSendingVideoFrames:Oe,faceDone:L,stopRecording:Me,showPause:Y,webcamRef:b,onUserMedia:Ee,onUserMediaError:Ne,videoConstraints:xe,webcamKey:he})});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,v]=t.useState(0),S=t.useRef([]),[y,C]=t.useState(!1),w=i-u,j=w>=80&&w<=95;t.useEffect(()=>{if("undefined"!=typeof window&&window.DeviceOrientationEvent){const e=e=>{if(null!==e.beta){let t=Math.abs(e.beta);null!==e.gamma&&(t*=Math.cos(e.gamma*Math.PI/180)),t=Math.max(0,Math.min(180,t)),l(t)}},t=async()=>{const t=DeviceOrientationEvent;if(t&&"function"==typeof t.requestPermission)try{"granted"===await t.requestPermission()&&window.addEventListener("deviceorientation",e)}catch(e){console.error("Permission error",e)}else window.addEventListener("deviceorientation",e);return()=>{e&&window.removeEventListener("deviceorientation",e)}};document.addEventListener("click",t,{once:!0})}},[]),t.useEffect(()=>{if(S.current=[...S.current.slice(-4),w],S.current.length>=5){const e=Math.max(...S.current)-Math.min(...S.current);v(j&&e<2?e=>Math.min(100,e+10):e=>Math.max(0,e-20))}j||null===m&&!h||E()},[w,j,m,h]),t.useEffect(()=>{x>=100&&null===m&&!h&&k(),x<50&&null!==m&&E()},[x,m,h]);const k=()=>{p(3);const e=setInterval(()=>{p(t=>null===t||t<=1?(clearInterval(e),g(!0),null):t-1)},1e3)},E=()=>{p(null),y||g(!1)};return e.jsx(f,{angle:w,countdown:m,isScanning:h,isInTargetRange:j,stabilityScore:x,children:h&&e.jsx(b,{setIsScanLocked:C,resetDetector:()=>{l(90),d(0),p(null),g(!1),v(0),C(!1),S.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 E({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",{"data-testid":"scan-error-message",className:"flex common-ui-main flex-col h-full max-w-[28rem] mx-auto w-full rounded-t-[20px] overflow-y-auto",style:{background:d?.style?.base?.backgroundColor},children:[e.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,{"data-testid":"scan-again-btn",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,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 N({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:v,scanType:S}=a||{},y=[s.CLOTHING_CUSTOM_SCAN,s.CLOTHING_BANNER_SCAN,s.CLOTHING_CUSTOM_FIT_SCAN].includes(S??""),[C,b]=t.useState(!0),w=t.useCallback(async()=>{try{y&&(await(m?.auth.addUser({scanId:n,email:v,name:x,gender:p,height:h})),d?.()),s.posthog.capture(f??"",{scanID:n,email:v,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 E=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:b}),e.jsx(o.Drawer,{open:C,onClose:(e,t)=>{},className:"camera-drawer",anchor:"bottom",children:e.jsx("div",{className:"max-w-[28rem] mx-auto w-full h-full flex text-center flex-col justify-between items-center bg-primary rounded-t-[30px] p-[1rem]",style:{background:r?.style?.base?.backgroundColor},children:e.jsxs("div",{className:"w-full h-full flex flex-col",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",muted:!0,loop:!0,autoPlay:!0,playsInline:!0,children:e.jsx("source",{src:p===s.GenderType.Male?s.maleMeasurementProgress:s.measurementProgress,type:"video/mp4"})})}),E&&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,setScanFailsError:v,setScanStartTime:S,resetScan:y,onCustomScanSuccess:C,swan:b,onComplete:k}=t.useContext(s.ParamsContext),D=s.useConfig();return r?e.jsxs("div",{"data-scan-state":"error",children:[e.jsx(j,{}),e.jsx(o.Drawer,{anchor:"bottom",open:!0,className:"camera-drawer",onClose:(e,t)=>{},children:e.jsx(E,{scanFailsError:!0,onNext:a,gender:i})})]}):c?e.jsx("div",{"data-scan-state":"success",children:e.jsx(N,{isSuccess:!0,onComplete:k})}):h?e.jsx("div",{"data-scan-state":"loading",className:"flex top-0 !mt-0 left-0 z-[999] absolute justify-center items-center w-full h-full",style:{background:D?.style?.base?.backgroundColor},children:e.jsx(s.LoadingScreen,{url:D?.loader,loaderType:"black"})}):g.disabled?e.jsx("div",{"data-scan-state":"camera-denied",children:e.jsx(s.Modal,{})}):x||u||p||f?(x||p||f)&&!u?e.jsx("div",{"data-scan-state":"processing",children:e.jsx(N,{scanId:l,isMeasurementAvailable:p,userDetails:n,isVideoUploadedCorrect:f,onCustomScanSuccess:C,swan:b,onComplete:k})}):e.jsxs("div",{"data-scan-state":"error-retry",children:[e.jsx(j,{}),e.jsx(o.Drawer,{anchor:"bottom",open:!0,className:"camera-drawer",onClose:(e,t)=>{},children:e.jsx(E,{scanFailsError:u,onNext:()=>{a?.(),y()},setScanUniqueKey:d,gender:i,setIsVideoUploaded:m})})]}):e.jsx("div",{"data-scan-state":"scanning",children:e.jsx(w,{scanID:l,userDetails:n,setIsVideoUploaded:m,setScanFailsError:v,setScanStartTime:S,setScanUniqueKey:d})})};exports.BodyScan=n=>{const{config:a,onRetry:r,onScanStart:o,onCaptureComplete:c,onUploadStart:i,onUploadEnd:l,onMeasurementSocketStart:u,onMeasurementSocketClose:d,onIntermediateScanSuccess:p,onScanError:f,onScanSuccess:h,onCustomScanSuccess:g,onComplete:x,isError:v,isSuccess:S}=n,y={email:"",shopDomain:"",gender:"male",heightInCm:0,scanType:"",deviceFocalLength:0,deviceModelName:"",sourceTag:"",callbackUrl:null,...n.userDetails??{}},C=n.token??"",{gender:b,scanType:w,shopDomain:j,heightInCm:k,email:E,deviceFocalLength:N,deviceModelName:T,callbackUrl:I,sourceTag:L}=y,M=t.useMemo(()=>s.getSwanService(C),[C]),[F,_]=t.useState(!1),[P,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);s.usePosthogPageview();const ee=t.useCallback(()=>{Q(s.generateUuid()),K(""),_(!1),q(!1)},[]),te=()=>{Y(null),Q("")},se=t.useCallback(async e=>{if(e&&"success"===e?.scanStatus&&"intermediate"===e?.resultType&&200===e?.code)return s.handleScanTimeCapture({eventName:`${j}/measurement_success/intermediate`,scanID:J,status:"success",email:E}),A(!0),void p?.(e);h?.(e),A(!0),te();const t=J;$(!0),s.handleScanTimeCapture({eventName:`${j}/measurement_success/fit-view`,scanID:t,status:"success",email:E}),X&&s.handleScanTimeCapture({eventName:`${j}/scan_completion_time`,scanID:t,status:"success",completionTime:s.getCurrentTimeInSeconds()-X,email:E})},[w,j,J]),ne=e=>{$(!1),K(""),A(!1),M.measurement.handleMeasurementSocket({scanId:J,onPreopen:()=>{s.handleWebSocketCapture({eventName:`${j}/webSocket`,scanID:J,connection:"pre_open",type:"measurement_recommendation",email:E})},onOpen:()=>{u?.(),s.handleWebSocketCapture({eventName:`${j}/webSocket`,scanID:J,connection:"open",type:"measurement_recommendation",email:E})},onClose:()=>{d?.(),s.handleWebSocketCapture({eventName:`${j}/webSocket`,scanID:J,connection:"close",type:"measurement_recommendation",email:E})},onError:e=>{var t;t=e,f?.({...t,message:s.handleErrorMessage(t)}),te(),$(!1),K(t),A(!1),s.handleScanTimeCapture({eventName:`${j}/measurement_failed/fit-view`,scanID:J,status:"failed",email:E,message:s.handleErrorMessage(t)}),X&&s.handleScanTimeCapture({eventName:`${j}/scan_completion_time`,scanID:J,status:"failed",completionTime:s.getCurrentTimeInSeconds()-X,email:E}),s.handleWebSocketCapture({eventName:`${j}/webSocket`,scanID:J,connection:"error",type:"measurement_recommendation",email:E})},onSuccess:e=>{s.handleWebSocketCapture({eventName:`${j}/webSocket`,scanID:J,connection:"success",type:"measurement_recommendation",email:E}),se(e)}})},ae=t.useCallback(async(e,t)=>{const n=Number((e.size/1048576).toFixed(2)),a=null!=t?t:await s.getVideoFPS(e),r=s.createObjectMetadataArray({gender:b,focal_length:`${N}`,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:E,data:JSON.stringify([...r,{fileSizeInMB:n,video_fps:a||0}])}),i?.();try{await M.fileUpload.uploadFileFrontend({file:e,arrayMetaData:r,scanId:J,email:E}),await M.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:E,data:JSON.stringify(r)}),s.handleScanTimeCapture({eventName:"scan finished",scanID:J,status:"success",email:E}),Y(s.getCurrentTimeInSeconds()),setTimeout(()=>{q(!0)},3e3)}catch(e){s.handleScanTimeCapture({eventName:"scan finished",scanID:J,status:"failed",email:E,message:s.handleErrorMessage(e)}),s.handleScanTimeCapture({eventName:`${j}/scan_failed`,scanID:J,status:"failed",email:E,message:s.handleErrorMessage(e),data:JSON.stringify(r)}),K(s.handleErrorMessage(e)),q(!1),f?.({...e,message:s.handleErrorMessage(e)}),te()}finally{G(!1),l?.()}},[J,Z,i,l]),re=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:E}),W(!1)):(W(!1),s.handleScanTimeCapture({eventName:`${j}/camera_activation`,scanID:J,status:"success",email:E})),O(e),K(""),q(!1)},[E,J,Q,j]);return t.useEffect(()=>{v||S||j&&re()},[j,k,v,S]),t.useEffect(()=>{v||S||B&&j&&J&&ne()},[B,j,J,v,S]),e.jsx("div",{"data-testid":"body-scan-root",children: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:v,isSuccess:S,onScanSuccess:h,gender:b,scanUniqueKey:J,scanFailsError:z,setScanUniqueKey:Q,setIsVideoUploaded:q,isMeasurementAvailable:R,isVideoUploadedCorrect:P,loading:V,showDeniedModal:U,uploadLoading:F,setStartGyro:G,uploadScanFile:ae,setUploadLoading:_,resetScan:ee,setScanFailsError:K,setScanStartTime:Y,onScanStart:o,onCaptureComplete:c,onCustomScanSuccess:g,onComplete:x,swan:M},children:e.jsx(D,{})})})})})})};
|
|
2
|
-
//# sourceMappingURL=BodyScan-CjvyMLT9.js.map
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";var e=require("react/jsx-runtime"),t=require("react"),s=require("./Modal-DnweWp6L.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]),g=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`,[]),h=t.useCallback((e=!1)=>{const t=m();return o?`text-[${d?.style?.angleDetector?.successAngleTextLightColor}]`:g(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},"data-testid":"level-screen","data-angle-state":o?"locked":c?"target":"adjusting",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]",h()),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",h()),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",h()),style:{color:S()},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",h()),style:{fontFamily:d?.style?.base?.baseFontFamily||"Inter, sans-serif",color:S()},children:u?.(s.LanguageKeys.placePhoneUpright)})})]})});function g({resetScan:n,loadingCam:o,onUserMedia:c,onPause:i,pause:l,onReScan:m,recordingStarted:p,startSendingVideoFrames:f,showPause:g,webcamRef:h,onUserMediaError:x,resetDetector:S,videoConstraints:v,webcamKey:y,faceDone:C,isScanning:b}){const{media:w}=t.useContext(d)||{},{translate:j}=t.useContext(s.LanguageContext)||{};return e.jsxs("div",{className:"App w-screen h-[100vh] relative common-ui-main","data-testid":"camera-scan","data-scan-phase":C?"spinning":p?"pose-detecting":b?"starting":"ready",children:[e.jsx("span",{onClick:()=>{n(),S()},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:w===u&&e.jsx(a,{audio:!1,ref:h,screenshotQuality:1,videoConstraints:v,mirrored:!0,screenshotFormat:"image/jpeg",onUserMedia:c,onUserMediaError:x,style:{position:"fixed",top:0,left:0,right:0,bottom:0,zIndex:0,width:"100%",height:"100%",objectFit:"cover"}},y)}),e.jsxs("div",{className:"fixed bottom-[30px] w-full z-[999] flex flex-col gap-4 items-center justify-center",children:[g&&e.jsx(s.SpecificButton,{className:"!w-[180px] !h-[40px] !py-[0] mx-auto ",prefix:s.pauseIcon,buttonText:j?.(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:j?.(s.LanguageKeys.restart),buttonFunc:m,btnSecondary:!0})}):p?null:e.jsx(s.SpecificButton,{"data-testid":"start-scan-btn",className:"!w-[180px] !h-[40px] !py-[0] mx-auto !bg-[#ffffff] !text-[#000000] "+(o?"!opacity-50":""),buttonText:j?.(s.LanguageKeys.startScan),buttonFunc:f,disabled:o})]}),e.jsx("audio",{id:"audioElement",crossOrigin:"anonymous",preload:"auto",style:{position:"absolute",zIndex:-99999},src:`${s.voiceOverAssetsPath}scanAudioInstructions/silence.mp3`})]})}let h=null,x=null,S=null;let v,y=null,C=null;var b=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,b=t.useRef(null),w=t.useRef(null),j=t.useRef(null),[E,k]=t.useState([]),[N,D]=t.useState(!0),[I,T]=t.useState(!1),[L,$]=t.useState(!1),[M,P]=t.useState(!0),[F,_]=t.useState(!1),A=t.useRef(null),[R,U]=t.useState(""),[O,K]=t.useState([]),[z,q]=t.useState(""),[B,V]=t.useState(!1),[W,H]=t.useState(!1),[G,J]=t.useState(!1),[Y,Q]=t.useState([]),[X,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-Bc8T4UAD.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),h=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 h||(h=u()),h.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||h||(h=u(),await h&&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(!1),le=t.useRef(()=>{}),ue=t.useRef(()=>{}),[de,me]=t.useState([]),[pe,fe]=t.useState(0),[ge,he]=t.useState(s.videoConstraintsExact),{setStartGyro:xe,uploadScanFile:Se,setUploadLoading:ve,swan:ye,onScanStart:Ce,onCaptureComplete:be}=t.useContext(s.ParamsContext),we=()=>{ne.current=!1,clearTimeout(v),A.current&&clearTimeout(A.current),l(s.generateUuid()),c(""),ve?.(!1),k([]),j.current=null,D(!0),T(!1),$(!1),P(!0),_(!1),A.current=null,U(""),K([]),q(""),V(!B),xe(!1),s.speechService.stopAudio(),H(!1),J(!1),ae.current=0,re.current=0,oe.current=!1,ie.current=!1,null!==w.current&&w.current.stop(),Y.forEach(e=>{w.current&&w.current.removeEventListener("dataavailable",e)}),Q([]),ee.current=!0,Z(!1),o(!1),b.current?.stream&&D(!1)},je=t.useCallback(()=>{setTimeout(()=>{D(!1)},1e3)},[]),Ee=t.useCallback(e=>{if(console.log("camera error",e),ge===s.videoConstraintsExact)return he(s.videoConstraintsFallback),void fe(e=>e+1);D(!1)},[ge]),ke=t.useCallback(()=>{ee.current=!1,J(!0),Z(!1),A.current&&clearTimeout(A.current),w.current&&w.current.pause(),s.speechService.stopAudio(),ye.poseDetection.disconnect(),ae.current=0,re.current=0,oe.current=!1,ie.current=!1,w.current&&w.current.stop(),Y.forEach(e=>{w.current&&w.current.removeEventListener("dataavailable",e)}),Q([]),clearTimeout(v)},[w,Y,s.speechService,ee]),Ne=t.useMemo(()=>s.getPreferredMediaRecorderTypes(),[]),De=s.getRecordingMimeType(de),Ie=s.getRecordingExtension(De),Te=t.useCallback(async()=>{ee.current=!0,await s.speechService.playAudio(`${s.voiceOverAssetsPath}SpotOn.mp3`),J(!1),Z(!1),A.current&&clearTimeout(A.current),T(!1)},[A,s.speechService]),Le=t.useCallback(async()=>{if(!ce.current&&!y){ce.current=!0;try{y=await ye.poseDetection.connect(),s.posthog.capture(`${f}/pose_detection_connected`,{scanID:r,email:p,id:y})}catch(e){console.log(e,"while connecting websocket")}finally{ce.current=!1}}},[r,f,p]),$e=t.useCallback(async()=>{s.rescanSupportCaptureEvent({eventName:`${f}/rescan`,email:p,scanID:r,height:m,gender:d,status:!1}),ee.current=!1,ye.poseDetection.disconnect(),y=null,we(),await Le(),ue.current()},[Le,r,p]),Me=t.useCallback(({data:e})=>{e&&e.size>0&&ee.current&&(k(t=>t.concat(e)),!ne.current&&b.current&&(ne.current=!0,te(()=>{Te(),s.handleScanTimeCapture({eventName:`${f}/tensorFlow`,scanID:r,email:p,message:"recording stopped by tensorflow "})},b)))},[Te,s.handleScanTimeCapture,f,r,p,b]),Pe=t.useCallback(async()=>{const e=O[O.length-1];e&&ee.current&&(await s.speechService.playAudio(s.voiceOverAssetsPath+e),ee.current&&(v=setTimeout(Pe,2e3)))},[O,ee]),Fe=t.useCallback(()=>{w&&w.current&&w.current.stop(),T(!0);try{if(b&&b.current&&b.current.stream){const e=b.current.stream.getVideoTracks()[0];if(e){const t=e.getSettings();j.current=t.frameRate||null}const t={videoBitsPerSecond:15e5};de[0]&&(t.mimeType=de[0]),w.current=new MediaRecorder(b.current.stream,t),w.current.addEventListener("dataavailable",Me),w.current.addEventListener("stop",()=>{P(!0)}),Q([...Y,Me]),w.current.start(1e3),P(!1)}}catch(e){console.log("error while using media recorder",e)}},[b,de,Me,Y]),_e=t.useCallback(async()=>{A.current&&clearTimeout(A.current),Fe(),ee.current&&(A.current=setTimeout(async()=>{ee.current&&(await s.speechService.playAudio(`${s.voiceOverAssetsPath}SpotOn.mp3`),T(!1))},15e3)),$(!0),ee.current&&await s.speechService.playAudio(`${s.voiceOverAssetsPath}Spin.mp3`)},[Fe,ee,s.speechService]);t.useEffect(()=>{le.current=_e},[_e]);const Ae="undefined"!=typeof window?window.__scanLog??[]:[],Re=e=>{const t=`[${(new Date).toISOString().slice(11,23)}] [SCAN] ${e}`;console.log(t),Ae.push(t)},Ue=t.useCallback(({data:e})=>{const t=ye.poseDetection.connected();e.size>0&&t?(oe.current||(oe.current=!0,Re(`poseStatus listener REGISTERED | id=${y}`),ye.poseDetection.poseStatus(async e=>{if(e&&e.audio&&e.audio.length>0){const t=document.querySelector("#audioElement"),n=e.audio?.split("/").pop(),a=t?.paused,o=t?.src?.split("/").pop()||"empty";Re(`poseStatus RECEIVED | status=${e.status} | file=${n} | sid=${e.sid} | id=${y} | sidMatch=${e.sid===y} | counter=${ae.current} | consecFalse=${re.current} | audioPaused=${a} | audioSrc=${o} | audioEl=${t?"found":"NULL"} | lastPlayed=${C?.audioName?.split("/").pop()??"none"} | skipped=${C?.no_of_times_skipped??"-"}/${C?.skipCount??"-"}`),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"}),!0===e.status&&e.sid===y?(re.current=0,ae.current<2?(ae.current+=1,1!==ae.current||ie.current?2===ae.current&&t?.paused?(Re(`PLAY good-posture-2 | file=${n}`),s.speechService.playAudio(s.voiceOverAssetsPath+e.audio)):2!==ae.current||t?.paused?Re(`SKIP good-posture-1 — brilliantPlayed already | counter=${ae.current}`):Re(`SKIP good-posture-2 — audio still playing | file=${n}`):(Re(`PLAY good-posture-1 (brilliant) | file=${n}`),ie.current=!0,s.speechService.stopAudio(),await s.speechService.playAudio(s.voiceOverAssetsPath+e.audio))):(Re(`TRIGGER SPIN | counter=${ae.current} | file=${n}`),q(e.audio),clearTimeout(v),ye.poseDetection.disconnect(),oe.current=!1,setTimeout(()=>le.current(),1e3))):!0===e.status&&e.sid!==y?Re(`SKIP good-posture — sid MISMATCH | data.sid=${e.sid} | id=${y}`):(re.current+=1,re.current>=3&&(ae.current=0,ie.current=!1,Re(`RESET counter/brilliant — consecutiveFalse=${re.current}`)),!t?.paused||C&&C?.audioName===e.audio?t?.paused||C&&C?.audioName===e.audio?C?.audioName===e.audio&&t?.paused?C&&C.no_of_times_skipped>=C.skipCount?(C.no_of_times_skipped=0,Re(`PLAY wrong-posture REPEAT | file=${n}`),s.speechService.playAudio(s.voiceOverAssetsPath+e.audio)):(C&&(C.no_of_times_skipped+=1),Re(`SKIP wrong-posture SAME — skip ${C?.no_of_times_skipped}/${C?.skipCount} | file=${n}`)):C?.audioName!==e.audio||t?.paused||Re(`SKIP wrong-posture SAME — audio still playing | file=${n}`):Re(`SKIP wrong-posture NEW — audio playing | file=${n}`):(Re(`PLAY wrong-posture NEW | file=${n}`),C={skipCount:2,no_of_times_skipped:0,audioName:e.audio},s.speechService.playAudio(s.voiceOverAssetsPath+e.audio)))}})),b?.current&&null!==b.current.getScreenshot()&&ye.poseDetection.videoEmit({image:b.current.getScreenshot()||"",scanId:r})):e.size>0&&!t&&Re(`handleDataAvailable — WS DISCONNECTED | id=${y} | poseListenerRegistered=${oe.current}`)},[b,r,ye,y,s.speechService,f,p]),Oe=t.useCallback(async()=>{_(!0),xe(!0),Ce?.(),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&&(_(!1),T(!0),H(!0),Z(!0),je());try{if(b&&b.current&&b.current.stream&&ee.current){const e=b.current.stream.getVideoTracks()[0];if(e){const t=e.getSettings();j.current=t.frameRate||null}const t={videoBitsPerSecond:15e5};de[0]&&(t.mimeType=de[0]),ee.current&&(w.current=new MediaRecorder(b.current.stream,t)),ee.current&&w.current&&w.current.addEventListener("dataavailable",Ue),Q([...Y,Ue]),w.current&&w.current.start(1e3),P(!1),ee.current&&(v=setTimeout(Pe,2e3))}}catch(e){console.log("error ----------",e)}},[b,de,Ue,Y,Pe,ee,Ce]);return t.useEffect(()=>(f&&(n(!0),Le()),()=>{const e=y;y=null,e&&(ye.poseDetection.disconnect(),s.posthog.capture(`${f}/pose_detection_disconnected`,{scanID:r,email:p,id:e})),Y.forEach(e=>{w?.current?.removeEventListener("dataavailable",e)})}),[f]),t.useEffect(()=>{O.push(R)},[R]),t.useEffect(()=>{K([])},[z]),t.useEffect(()=>{const e=E.length&&E.length>0;M||!e||I||!ee.current||G||w&&w.current&&(I||w.current.stop())},[M,I,E,G]),t.useEffect(()=>{const e=E.length&&E.length>0;if(M&&e&&!I&&w&&w.current&&ee.current&&!G&&!I){const e=new File(E,`${r}.${Ie}`,{type:De});be?.(),ve?.(!0),c(""),Se?.(e,j.current)}},[M,I,E,G,w,ee]),t.useEffect(()=>{ue.current=Oe},[Oe]),t.useEffect(()=>{const e=s.getSupportedMediaRecorderTypes(Ne,s.videoTypes);me(e)},[Ne]),t.useEffect(()=>{we()},[]),e.jsx(g,{resetDetector:a,resetScan:we,loadingCam:N,onPause:ke,showRestart:W,pause:G,onReScan:$e,recordingStarted:I,isScanning:F,startSendingVideoFrames:Oe,faceDone:L,stopRecording:Te,showPause:X,webcamRef:b,onUserMedia:je,onUserMediaError:Ee,videoConstraints:ge,webcamKey:pe})});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),[g,h]=t.useState(!1),[x,S]=t.useState(0),v=t.useRef([]),[y,C]=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&&!g||k()},[w,j,m,g]),t.useEffect(()=>{x>=100&&null===m&&!g&&E(),x<50&&null!==m&&k()},[x,m,g]);const E=()=>{p(3);const e=setInterval(()=>{p(t=>null===t||t<=1?(clearInterval(e),h(!0),null):t-1)},1e3)},k=()=>{p(null),y||h(!1)};return e.jsx(f,{angle:w,countdown:m,isScanning:g,isInTargetRange:j,stabilityScore:x,children:g&&e.jsx(b,{setIsScanLocked:C,resetDetector:()=>{l(90),d(0),p(null),h(!1),S(0),C(!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 E({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 k({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",{"data-testid":"scan-error-message",className:"flex common-ui-main flex-col h-full max-w-[28rem] mx-auto w-full rounded-t-[20px] overflow-y-auto",style:{background:d?.style?.base?.backgroundColor},children:[e.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,{"data-testid":"scan-again-btn",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,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(E,{link:c?s.GENDER[c].PRE_LINK:s.GENDER.male.PRE_LINK,wrapperClassName:"w-screen h-screen fixed top-[0] left-[0]"})})]})]})}function N({scanId:n,userDetails:a,config:r,isVideoUploadedCorrect:c,isMeasurementAvailable:i,onComplete:l,isSuccess:u,onCustomScanSuccess:d,swan:m}){const{gender:p,shopDomain:f,heightInCm:g,deviceFocalLength:h,userName:x,email:S,scanType:v}=a||{},y=[s.CLOTHING_CUSTOM_SCAN,s.CLOTHING_BANNER_SCAN,s.CLOTHING_CUSTOM_FIT_SCAN].includes(v??""),[C,b]=t.useState(!0),w=t.useCallback(async()=>{try{y&&(await(m?.auth.addUser({scanId:n,email:S,name:x,gender:p,height:g})),d?.()),s.posthog.capture(f??"",{scanID:n,email:S,height:g,focalLength:h,clothesFit:"0",gender:p})}catch(e){console.log(e)}},[y]),{translate:E}=t.useContext(s.LanguageContext)||{};t.useEffect(()=>{(c||i)&&w()},[c,i]);const k=u||c||i;return e.jsx(o.Box,{className:"flex h-full w-full flex-col common-ui-main",children:e.jsxs("div",{className:"h-full w-full flex-col items-center justify-center flex",children:[e.jsx(j,{loader:r?.loader,setShowDrawer:b}),e.jsx(o.Drawer,{open:C,onClose:(e,t)=>{},className:"camera-drawer",anchor:"bottom",children:e.jsx("div",{className:"max-w-[28rem] mx-auto w-full h-full flex text-center flex-col justify-between items-center bg-primary rounded-t-[30px] p-[1rem]",style:{background:r?.style?.base?.backgroundColor},children:e.jsxs("div",{className:"w-full h-full flex flex-col",children:[e.jsx(s.Header,{title:E?.(s.LanguageKeys.measurementsBeingTaken)}),e.jsx("div",{className:"flex items-center justify-center flex-1",children:e.jsx("video",{preload:"auto",className:"max-h-[calc(100vh-450px)] mx-auto w-full object-contain border-none",muted:!0,loop:!0,autoPlay:!0,playsInline:!0,children:e.jsx("source",{src:p===s.GenderType.Male?s.maleMeasurementProgress:s.measurementProgress,type:"video/mp4"})})}),k&&e.jsx(s.SpecificButton,{className:"!w-[180px] mx-auto",buttonText:E?.(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:g,showDeniedModal:h,uploadLoading:x,setScanFailsError:S,setScanStartTime:v,resetScan:y,onCustomScanSuccess:C,swan:b,onComplete:E}=t.useContext(s.ParamsContext),D=s.useConfig();return r?e.jsxs("div",{"data-scan-state":"error",children:[e.jsx(j,{}),e.jsx(o.Drawer,{anchor:"bottom",open:!0,className:"camera-drawer",onClose:(e,t)=>{},children:e.jsx(k,{scanFailsError:!0,onNext:a,gender:i})})]}):c?e.jsx("div",{"data-scan-state":"success",children:e.jsx(N,{isSuccess:!0,onComplete:E})}):g?e.jsx("div",{"data-scan-state":"loading",className:"flex top-0 !mt-0 left-0 z-[999] absolute justify-center items-center w-full h-full",style:{background:D?.style?.base?.backgroundColor},children:e.jsx(s.LoadingScreen,{url:D?.loader,loaderType:"black"})}):h.disabled?e.jsx("div",{"data-scan-state":"camera-denied",children:e.jsx(s.Modal,{})}):x||u||p||f?(x||p||f)&&!u?e.jsx("div",{"data-scan-state":"processing",children:e.jsx(N,{scanId:l,isMeasurementAvailable:p,userDetails:n,isVideoUploadedCorrect:f,onCustomScanSuccess:C,swan:b,onComplete:E})}):e.jsxs("div",{"data-scan-state":"error-retry",children:[e.jsx(j,{}),e.jsx(o.Drawer,{anchor:"bottom",open:!0,className:"camera-drawer",onClose:(e,t)=>{},children:e.jsx(k,{scanFailsError:u,onNext:()=>{a?.(),y()},setScanUniqueKey:d,gender:i,setIsVideoUploaded:m})})]}):e.jsx("div",{"data-scan-state":"scanning",children:e.jsx(w,{scanID:l,userDetails:n,setIsVideoUploaded:m,setScanFailsError:S,setScanStartTime:v,setScanUniqueKey:d})})};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:g,onCustomScanSuccess:h,onComplete:x,isError:S,isSuccess:v}=n,y={email:"",shopDomain:"",gender:"male",heightInCm:0,scanType:"",deviceFocalLength:0,deviceModelName:"",sourceTag:"",callbackUrl:null,...n.userDetails??{}},C=n.token??"",{gender:b,scanType:w,shopDomain:j,heightInCm:E,email:k,deviceFocalLength:N,deviceModelName:I,callbackUrl:T,sourceTag:L}=y,$=t.useMemo(()=>s.getSwanService(C),[C]),[M,P]=t.useState(!1),[F,_]=t.useState(!1),[A,R]=t.useState(!1),[U,O]=t.useState({disabled:!1,message:""}),[K,z]=t.useState(""),[q,B]=t.useState(!1),[V,W]=t.useState(!0),[H,G]=t.useState(!1),[J,Y]=t.useState(""),[Q,X]=t.useState(s.getCurrentTimeInSeconds()),{gyroData:Z}=function(e){const[s,n]=t.useState([]),[a,r]=t.useState(!1),o=t.useCallback(e=>{try{const{alpha:t,beta:s,gamma:a}=e;n(e=>[...e,{alpha:t?.toString()||void 0,beta:s?.toString()||void 0,gamma:a?.toString()||void 0,timestamp:(new Date).toISOString()}])}catch(e){console.log(e)}},[]),c=t.useCallback(async()=>{const e=DeviceOrientationEvent;if(void 0!==e&&"function"==typeof e.requestPermission)try{"granted"===await e.requestPermission()?r(!0):console.warn("Device orientation permission denied.")}catch(e){console.error("Error requesting device orientation permission:",e)}else r(!0)},[]);return t.useEffect(()=>(e&&a?window.addEventListener("deviceorientation",o):n([]),()=>{window.removeEventListener("deviceorientation",o)}),[e,a,o]),t.useEffect(()=>{e&&c()},[e,c]),{gyroData:s}}(H);s.usePosthogPageview();const ee=t.useCallback(()=>{Y(s.generateUuid()),z(""),P(!1),B(!1)},[]),te=()=>{X(null),Y("")},se=t.useCallback(async e=>{if(e&&"success"===e?.scanStatus&&"intermediate"===e?.resultType&&200===e?.code)return s.handleScanTimeCapture({eventName:`${j}/measurement_success/intermediate`,scanID:J,status:"success",email:k}),_(!0),void p?.(e);g?.(e),_(!0),te();const t=J;R(!0),s.handleScanTimeCapture({eventName:`${j}/measurement_success/fit-view`,scanID:t,status:"success",email:k}),Q&&s.handleScanTimeCapture({eventName:`${j}/scan_completion_time`,scanID:t,status:"success",completionTime:s.getCurrentTimeInSeconds()-Q,email:k})},[w,j,J]),ne=e=>{R(!1),z(""),_(!1),$.measurement.handleMeasurementSocket({scanId:J,onPreopen:()=>{s.handleWebSocketCapture({eventName:`${j}/webSocket`,scanID:J,connection:"pre_open",type:"measurement_recommendation",email:k})},onOpen:()=>{u?.(),s.handleWebSocketCapture({eventName:`${j}/webSocket`,scanID:J,connection:"open",type:"measurement_recommendation",email:k})},onClose:()=>{d?.(),s.handleWebSocketCapture({eventName:`${j}/webSocket`,scanID:J,connection:"close",type:"measurement_recommendation",email:k})},onError:e=>{var t;t=e,f?.({...t,message:s.handleErrorMessage(t)}),te(),R(!1),z(t),_(!1),s.handleScanTimeCapture({eventName:`${j}/measurement_failed/fit-view`,scanID:J,status:"failed",email:k,message:s.handleErrorMessage(t)}),Q&&s.handleScanTimeCapture({eventName:`${j}/scan_completion_time`,scanID:J,status:"failed",completionTime:s.getCurrentTimeInSeconds()-Q,email:k}),s.handleWebSocketCapture({eventName:`${j}/webSocket`,scanID:J,connection:"error",type:"measurement_recommendation",email:k})},onSuccess:e=>{s.handleWebSocketCapture({eventName:`${j}/webSocket`,scanID:J,connection:"success",type:"measurement_recommendation",email:k}),se(e)}})},ae=t.useCallback(async(e,t)=>{const n=Number((e.size/1048576).toFixed(2)),a=null!=t?t:await s.getVideoFPS(e),r=s.createObjectMetadataArray({gender:b,focal_length:`${N}`,height:`${E}`,customer_store_url:j,clothes_fit:"0",scan_type:w,callback_url:T,source_tag:L});s.handleScanTimeCapture({eventName:`${j}/body_scan_meta_data`,scanID:J,email:k,data:JSON.stringify([...r,{fileSizeInMB:n,video_fps:a||0}])}),i?.();try{await $.fileUpload.uploadFileFrontend({file:e,arrayMetaData:r,scanId:J,email:k}),await $.fileUpload.setDeviceInfo({model:I,detection:"manual",gyro:Z,scanId:J}),console.log("video successfully uploaded"),B(!1),s.handleScanTimeCapture({eventName:`${j}/scan_success`,scanID:J,status:"success",email:k,data:JSON.stringify(r)}),s.handleScanTimeCapture({eventName:"scan finished",scanID:J,status:"success",email:k}),X(s.getCurrentTimeInSeconds()),setTimeout(()=>{B(!0)},3e3)}catch(e){s.handleScanTimeCapture({eventName:"scan finished",scanID:J,status:"failed",email:k,message:s.handleErrorMessage(e)}),s.handleScanTimeCapture({eventName:`${j}/scan_failed`,scanID:J,status:"failed",email:k,message:s.handleErrorMessage(e),data:JSON.stringify(r)}),z(s.handleErrorMessage(e)),B(!1),f?.({...e,message:s.handleErrorMessage(e)}),te()}finally{G(!1),l?.()}},[J,Z,i,l]),re=t.useCallback(async()=>{if(+E<152.4||+E>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:k}),W(!1)):(W(!1),s.handleScanTimeCapture({eventName:`${j}/camera_activation`,scanID:J,status:"success",email:k})),O(e),z(""),B(!1)},[k,J,Y,j]);return t.useEffect(()=>{S||v||j&&re()},[j,E,S,v]),t.useEffect(()=>{S||v||q&&j&&J&&ne()},[q,j,J,S,v]),e.jsx("div",{"data-testid":"body-scan-root",children: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:g,gender:b,scanUniqueKey:J,scanFailsError:K,setScanUniqueKey:Y,setIsVideoUploaded:B,isMeasurementAvailable:A,isVideoUploadedCorrect:F,loading:V,showDeniedModal:U,uploadLoading:M,setStartGyro:G,uploadScanFile:ae,setUploadLoading:P,resetScan:ee,setScanFailsError:z,setScanStartTime:X,onScanStart:o,onCaptureComplete:c,onCustomScanSuccess:h,onComplete:x,swan:$},children:e.jsx(D,{})})})})})})};
|
|
2
|
-
//# sourceMappingURL=BodyScan-CkmrPAq9.js.map
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";var e=require("react/jsx-runtime"),t=require("react"),a=require("./Modal-BpgpPVxR.js"),s=require("react-webcam"),n=require("lucide-react"),r=require("@mui/material"),o=require("video.js");const c="DESKTOP",i="TAB",u="MOBILE",l=t.createContext(void 0);function d({children:a}){const[s,n]=t.useState([window?.innerWidth,window?.innerHeight]),[r,o]=t.useState(!1),d=()=>{n([window?.innerWidth,window?.innerHeight])};t.useEffect(()=>{d()},[]),t.useLayoutEffect(()=>(window.addEventListener("resize",d),()=>window.removeEventListener("resize",d)),[d]);let m=c;s[0]>768&&s[0]<1024&&(m=i),s[0]<768&&(m=u);const p=t.useMemo(()=>({size:s,setSize:n,clearInputs:r,setClearInputs:o,media:m}),[s,r,m]);return e.jsx(l.Provider,{value:p,children:a})}function m({resetScan:r,loadingCam:o,onUserMedia:c,onPause:i,pause:d,onReScan:m,recordingStarted:p,startSendingVideoFrames:f,showPause:S,webcamRef:h,onUserMediaError:g,resetDetector:v,videoConstraints:y,webcamKey:x,faceDone:w,isScanning:C}){const{media:b}=t.useContext(l)||{},{translate:E}=t.useContext(a.LanguageContext)||{};return e.jsxs("div",{className:"App w-screen h-[100vh] relative common-ui-main","data-testid":"camera-scan","data-scan-phase":w?"spinning":p?"pose-detecting":C?"starting":"ready",children:[e.jsx("span",{onClick:()=>{r(),v()},className:"fixed right-[20px] top-[20px] z-[999]",children:e.jsx(n.X,{className:"text-[#fff]"})}),e.jsx("div",{className:"w-full h-full overflow-hidden ",children:b===u&&e.jsx(s,{audio:!1,ref:h,screenshotQuality:1,videoConstraints:y,mirrored:!0,screenshotFormat:"image/jpeg",onUserMedia:c,onUserMediaError:g,style:{position:"fixed",top:0,left:0,right:0,bottom:0,zIndex:0,width:"100%",height:"100%",objectFit:"cover"}},x)}),e.jsxs("div",{className:"fixed bottom-[30px] w-full z-[999] flex flex-col gap-4 items-center justify-center",children:[S&&e.jsx(a.SpecificButton,{className:"!w-[180px] !h-[40px] !py-[0] mx-auto ",prefix:a.pauseIcon,buttonText:E?.(a.LanguageKeys.pause),buttonFunc:i,btnSecondary:!0}),d?e.jsx("div",{children:e.jsx(a.SpecificButton,{className:"!w-[180px] !h-[40px] !py-[0] mx-auto",buttonText:E?.(a.LanguageKeys.restart),buttonFunc:m,btnSecondary:!0})}):p?null:e.jsx(a.SpecificButton,{"data-testid":"start-scan-btn",className:"!w-[180px] !h-[40px] !py-[0] mx-auto !bg-[#ffffff] !text-[#000000] "+(o?"!opacity-50":""),buttonText:E?.(a.LanguageKeys.startScan),buttonFunc:f,disabled:o})]}),e.jsx("audio",{id:"audioElement",crossOrigin:"anonymous",preload:"auto",style:{position:"absolute",zIndex:-99999},src:`${a.voiceOverAssetsPath}scanAudioInstructions/silence.mp3`})]})}let p=null,f=null,S=null;let h,g=null,v=null;var y=t.memo(function({setIsScanLocked:s,resetDetector:n,scanID:r,setIsVideoUploaded:o,setScanFailsError:c,setScanStartTime:i,setScanUniqueKey:u,userDetails:l}){const{gender:d,heightInCm:y,email:x,shopDomain:w}=l,C=t.useRef(null),b=t.useRef(null),E=t.useRef(null),[j,I]=t.useState([]),[N,D]=t.useState(!0),[T,k]=t.useState(!1),[P,_]=t.useState(!1),[$,M]=t.useState(!0),[F,L]=t.useState(!1),R=t.useRef(null),[A,U]=t.useState(""),[O,K]=t.useState([]),[z,q]=t.useState(""),[B,V]=t.useState(!1),[W,G]=t.useState(!1),[H,J]=t.useState(!1),[Y,Q]=t.useState([]),[X,Z]=t.useState(!1),ee=t.useRef(!0),{poseDetector:te}=function(){const[e,a]=t.useState(0),[s,n]=t.useState(0),[r,o]=t.useState(!1),c=t.useRef(0),i=t.useRef(0),u=t.useRef(!0);async function l(){if("undefined"==typeof window||"undefined"==typeof navigator)return!1;try{console.log("Starting TensorFlow preload...");const[e,t,a]=await Promise.all([Promise.resolve().then(function(){return require("./pose-detection.esm-Bc8T4UAD.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 s={runtime:"mediapipe",modelType:"full",solutionPath:"https://cdn.jsdelivr.net/npm/@mediapipe/pose"};try{f=await S.createDetector(S.SupportedModels.BlazePose,s),console.log("MediaPipe detector created successfully")}catch(e){console.warn("MediaPipe failed, falling back to TFJS runtime:",e),f=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),p=null,!1}}function d(e){return!(!e||0===e.length)&&22===e.filter(e=>e[2]>.7).length}return t.useEffect(()=>{if(u.current=!0,!f)return p||(p=l()),p.then(e=>{e&&u.current&&o(!0)}),()=>{u.current=!1};o(!0)},[]),t.useEffect(()=>{i.current=e,e>6&&c.current<2&&(n(e=>e+1),a(0))},[e]),t.useEffect(()=>{c.current=s},[s]),{poseDetector:async(e,t)=>{if(!f||!u.current||!t?.current?.video)return;const s=t.current.video;if(!(s.readyState<2))try{const t=await f.estimatePoses(s,{flipHorizontal:!1});if(!t||!t.length)return;const n=t[0].keypoints.slice(11).map(e=>[e.x>0&&e.x<720?e.x:-1,e.y>0&&e.y<1280?e.y:-1,e.score??0]);0!==c.current||d(n)||a(e=>e+1),1===c.current&&d(n)&&a(e=>e+1),2===c.current&&e()}catch(e){console.error("Pose detection error:",e)}},isLoaded:r,spinPhase:s,resetDetector:()=>{c.current=0,i.current=0,a(0),n(0)},retryLoading:async()=>{f||p||(p=l(),await p&&u.current&&o(!0))}}}(),ae=t.useRef(!0),se=t.useRef(!1),ne=t.useRef(0),re=t.useRef(0),oe=t.useRef(!1),ce=t.useRef(!1),ie=t.useRef(!1),ue=t.useRef(()=>{}),le=t.useRef(()=>{}),[de,me]=t.useState([]),[pe,fe]=t.useState(0),[Se,he]=t.useState(a.videoConstraintsExact),{setStartGyro:ge,uploadScanFile:ve,setUploadLoading:ye,swan:xe,onScanStart:we,onCaptureComplete:Ce}=t.useContext(a.ParamsContext),be=()=>{se.current=!1,clearTimeout(h),R.current&&clearTimeout(R.current),u(a.generateUuid()),c(""),ye?.(!1),I([]),E.current=null,D(!0),k(!1),_(!1),M(!0),L(!1),R.current=null,U(""),K([]),q(""),V(!B),ge(!1),a.speechService.stopAudio(),G(!1),J(!1),ne.current=0,re.current=0,oe.current=!1,ie.current=!1,null!==b.current&&b.current.stop(),Y.forEach(e=>{b.current&&b.current.removeEventListener("dataavailable",e)}),Q([]),ee.current=!0,Z(!1),o(!1),C.current?.stream&&D(!1)},Ee=t.useCallback(()=>{setTimeout(()=>{D(!1)},1e3)},[]),je=t.useCallback(e=>{if(console.log("camera error",e),Se===a.videoConstraintsExact)return he(a.videoConstraintsFallback),void fe(e=>e+1);D(!1)},[Se]),Ie=t.useCallback(()=>{ee.current=!1,J(!0),Z(!1),R.current&&clearTimeout(R.current),b.current&&b.current.pause(),a.speechService.stopAudio(),xe.poseDetection.disconnect(),ne.current=0,re.current=0,oe.current=!1,ie.current=!1,b.current&&b.current.stop(),Y.forEach(e=>{b.current&&b.current.removeEventListener("dataavailable",e)}),Q([]),clearTimeout(h)},[b,Y,a.speechService,ee]),Ne=t.useMemo(()=>a.getPreferredMediaRecorderTypes(),[]),De=a.getRecordingMimeType(de),Te=a.getRecordingExtension(De),ke=t.useCallback(async()=>{ee.current=!0,await a.speechService.playAudio(`${a.voiceOverAssetsPath}SpotOn.mp3`),J(!1),Z(!1),R.current&&clearTimeout(R.current),k(!1)},[R,a.speechService]),Pe=t.useCallback(async()=>{if(!ce.current&&!g){ce.current=!0;try{g=await xe.poseDetection.connect(),a.posthog.capture(`${w}/pose_detection_connected`,{scanID:r,email:x,id:g})}catch(e){console.log(e,"while connecting websocket")}finally{ce.current=!1}}},[r,w,x]),_e=t.useCallback(async()=>{a.rescanSupportCaptureEvent({eventName:`${w}/rescan`,email:x,scanID:r,height:y,gender:d,status:!1}),ee.current=!1,xe.poseDetection.disconnect(),g=null,be(),await Pe(),le.current()},[Pe,r,x]),$e=t.useCallback(({data:e})=>{e&&e.size>0&&ee.current&&(I(t=>t.concat(e)),!se.current&&C.current&&(se.current=!0,te(()=>{ke(),a.handleScanTimeCapture({eventName:`${w}/tensorFlow`,scanID:r,email:x,message:"recording stopped by tensorflow "})},C)))},[ke,a.handleScanTimeCapture,w,r,x,C]),Me=t.useCallback(async()=>{const e=O[O.length-1];e&&ee.current&&(await a.speechService.playAudio(a.voiceOverAssetsPath+e),ee.current&&(h=setTimeout(Me,2e3)))},[O,ee]),Fe=t.useCallback(()=>{b&&b.current&&b.current.stop(),k(!0);try{if(C&&C.current&&C.current.stream){const e=C.current.stream.getVideoTracks()[0];if(e){const t=e.getSettings();E.current=t.frameRate||null}const t={videoBitsPerSecond:15e5};de[0]&&(t.mimeType=de[0]),b.current=new MediaRecorder(C.current.stream,t),b.current.addEventListener("dataavailable",$e),b.current.addEventListener("stop",()=>{M(!0)}),Q([...Y,$e]),b.current.start(1e3),M(!1)}}catch(e){console.log("error while using media recorder",e)}},[C,de,$e,Y]),Le=t.useCallback(async()=>{R.current&&clearTimeout(R.current),Fe(),ee.current&&(R.current=setTimeout(async()=>{ee.current&&(await a.speechService.playAudio(`${a.voiceOverAssetsPath}SpotOn.mp3`),k(!1))},15e3)),_(!0),ee.current&&await a.speechService.playAudio(`${a.voiceOverAssetsPath}Spin.mp3`)},[Fe,ee,a.speechService]);t.useEffect(()=>{ue.current=Le},[Le]);const Re="undefined"!=typeof window?window.__scanLog??[]:[],Ae=e=>{const t=`[${(new Date).toISOString().slice(11,23)}] [SCAN] ${e}`;console.log(t),Re.push(t)},Ue=t.useCallback(({data:e})=>{const t=xe.poseDetection.connected();e.size>0&&t?(oe.current||(oe.current=!0,Ae(`poseStatus listener REGISTERED | id=${g}`),xe.poseDetection.poseStatus(async e=>{if(e&&e.audio&&e.audio.length>0){const t=document.querySelector("#audioElement"),s=e.audio?.split("/").pop(),n=t?.paused,o=t?.src?.split("/").pop()||"empty";Ae(`poseStatus RECEIVED | status=${e.status} | file=${s} | sid=${e.sid} | id=${g} | sidMatch=${e.sid===g} | counter=${ne.current} | consecFalse=${re.current} | audioPaused=${n} | audioSrc=${o} | audioEl=${t?"found":"NULL"} | lastPlayed=${v?.audioName?.split("/").pop()??"none"} | skipped=${v?.no_of_times_skipped??"-"}/${v?.skipCount??"-"}`),a.posthog.capture(`${w}/pose_instruction_received`,{scanID:r,email:x,audio:e.audio,status:e.status,sid:e.sid,counter:ne.current,consecutiveFalse:re.current,type:"body_scan_instruction"}),!0===e.status&&e.sid===g?(re.current=0,ne.current<2?(ne.current+=1,1!==ne.current||ie.current?2===ne.current&&t?.paused?(Ae(`PLAY good-posture-2 | file=${s}`),a.speechService.playAudio(a.voiceOverAssetsPath+e.audio)):2!==ne.current||t?.paused?Ae(`SKIP good-posture-1 — brilliantPlayed already | counter=${ne.current}`):Ae(`SKIP good-posture-2 — audio still playing | file=${s}`):(Ae(`PLAY good-posture-1 (brilliant) | file=${s}`),ie.current=!0,a.speechService.stopAudio(),await a.speechService.playAudio(a.voiceOverAssetsPath+e.audio))):(Ae(`TRIGGER SPIN | counter=${ne.current} | file=${s}`),q(e.audio),clearTimeout(h),xe.poseDetection.disconnect(),oe.current=!1,setTimeout(()=>ue.current(),1e3))):!0===e.status&&e.sid!==g?Ae(`SKIP good-posture — sid MISMATCH | data.sid=${e.sid} | id=${g}`):(re.current+=1,re.current>=3&&(ne.current=0,ie.current=!1,Ae(`RESET counter/brilliant — consecutiveFalse=${re.current}`)),!t?.paused||v&&v?.audioName===e.audio?t?.paused||v&&v?.audioName===e.audio?v?.audioName===e.audio&&t?.paused?v&&v.no_of_times_skipped>=v.skipCount?(v.no_of_times_skipped=0,Ae(`PLAY wrong-posture REPEAT | file=${s}`),a.speechService.playAudio(a.voiceOverAssetsPath+e.audio)):(v&&(v.no_of_times_skipped+=1),Ae(`SKIP wrong-posture SAME — skip ${v?.no_of_times_skipped}/${v?.skipCount} | file=${s}`)):v?.audioName!==e.audio||t?.paused||Ae(`SKIP wrong-posture SAME — audio still playing | file=${s}`):Ae(`SKIP wrong-posture NEW — audio playing | file=${s}`):(Ae(`PLAY wrong-posture NEW | file=${s}`),v={skipCount:2,no_of_times_skipped:0,audioName:e.audio},a.speechService.playAudio(a.voiceOverAssetsPath+e.audio)))}})),C?.current&&null!==C.current.getScreenshot()&&xe.poseDetection.videoEmit({image:C.current.getScreenshot()||"",scanId:r})):e.size>0&&!t&&Ae(`handleDataAvailable — WS DISCONNECTED | id=${g} | poseListenerRegistered=${oe.current}`)},[C,r,xe,g,a.speechService,w,x]),Oe=t.useCallback(async()=>{L(!0),ge(!0),we?.(),ae.current&&(ae.current=!1,a.handleScanTimeCapture({eventName:"scan started",scanID:r,status:"success",email:x})),i(a.getCurrentTimeInSeconds()),D(!0),ee.current&&await a.speechService.playAudio(`${a.voiceOverAssetsPath}StartScan.mp3`),ee.current&&await a.speechService.playAudio(`${a.voiceOverAssetsPath}LiftArmsAndHoldAtHip.mp3`),ee.current&&(L(!1),k(!0),G(!0),Z(!0),Ee());try{if(C&&C.current&&C.current.stream&&ee.current){const e=C.current.stream.getVideoTracks()[0];if(e){const t=e.getSettings();E.current=t.frameRate||null}const t={videoBitsPerSecond:15e5};de[0]&&(t.mimeType=de[0]),ee.current&&(b.current=new MediaRecorder(C.current.stream,t)),ee.current&&b.current&&b.current.addEventListener("dataavailable",Ue),Q([...Y,Ue]),b.current&&b.current.start(1e3),M(!1),ee.current&&(h=setTimeout(Me,2e3))}}catch(e){console.log("error ----------",e)}},[C,de,Ue,Y,Me,ee,we]);return t.useEffect(()=>(w&&(s(!0),Pe()),()=>{const e=g;g=null,e&&(xe.poseDetection.disconnect(),a.posthog.capture(`${w}/pose_detection_disconnected`,{scanID:r,email:x,id:e})),Y.forEach(e=>{b?.current?.removeEventListener("dataavailable",e)})}),[w]),t.useEffect(()=>{O.push(A)},[A]),t.useEffect(()=>{K([])},[z]),t.useEffect(()=>{const e=j.length&&j.length>0;$||!e||T||!ee.current||H||b&&b.current&&(T||b.current.stop())},[$,T,j,H]),t.useEffect(()=>{const e=j.length&&j.length>0;if($&&e&&!T&&b&&b.current&&ee.current&&!H&&!T){const e=new File(j,`${r}.${Te}`,{type:De});Ce?.(),ye?.(!0),c(""),ve?.(e,E.current)}},[$,T,j,H,b,ee]),t.useEffect(()=>{le.current=Oe},[Oe]),t.useEffect(()=>{const e=a.getSupportedMediaRecorderTypes(Ne,a.videoTypes);me(e)},[Ne]),t.useEffect(()=>{be()},[]),e.jsx(m,{resetDetector:n,resetScan:be,loadingCam:N,onPause:Ie,showRestart:W,pause:H,onReScan:_e,recordingStarted:T,isScanning:F,startSendingVideoFrames:Oe,faceDone:P,stopRecording:ke,showPause:X,webcamRef:C,onUserMedia:Ee,onUserMediaError:je,videoConstraints:Se,webcamKey:pe})});function x({scanID:a,userDetails:s,setIsVideoUploaded:n,setScanFailsError:r,setScanStartTime:o,setScanUniqueKey:c}){const[i,u]=t.useState(90),[l,d]=t.useState(0),[m,p]=t.useState(null),[f,S]=t.useState(!1),[h,g]=t.useState(0),v=t.useRef([]),[x,w]=t.useState(!1),C=i-l,b=C>=80&&C<=95;t.useEffect(()=>{if("undefined"!=typeof window&&window.DeviceOrientationEvent){const e=e=>{if(null!==e.beta){let t=Math.abs(e.beta);null!==e.gamma&&(t*=Math.cos(e.gamma*Math.PI/180)),t=Math.max(0,Math.min(180,t)),u(t)}},t=async()=>{const t=DeviceOrientationEvent;if(t&&"function"==typeof t.requestPermission)try{"granted"===await t.requestPermission()&&window.addEventListener("deviceorientation",e)}catch(e){console.error("Permission error",e)}else window.addEventListener("deviceorientation",e);return()=>{e&&window.removeEventListener("deviceorientation",e)}};document.addEventListener("click",t,{once:!0})}},[]),t.useEffect(()=>{if(v.current=[...v.current.slice(-4),C],v.current.length>=5){const e=Math.max(...v.current)-Math.min(...v.current);g(b&&e<2?e=>Math.min(100,e+10):e=>Math.max(0,e-20))}b||null===m&&!f||j()},[C,b,m,f]),t.useEffect(()=>{h>=100&&null===m&&!f&&E(),h<50&&null!==m&&j()},[h,m,f]);const E=()=>{p(3);const e=setInterval(()=>{p(t=>null===t||t<=1?(clearInterval(e),S(!0),null):t-1)},1e3)},j=()=>{p(null),x||S(!1)};return e.jsx(y,{setIsScanLocked:w,resetDetector:()=>{u(90),d(0),p(null),S(!1),g(0),w(!1),v.current=[]},scanID:a,userDetails:s,setIsVideoUploaded:n,setScanFailsError:r,setScanStartTime:o,setScanUniqueKey:c})}function w({setShowDrawer:n,config:r,loader:o}){const[c,i]=t.useState({disabled:!1,message:""}),[u,l]=t.useState(!0),d=t.useRef(null),m=t.useCallback(async()=>{const e=await a.checkCameraPermission();i(e),l(!1)},[]);return t.useEffect(()=>{m()},[]),u?e.jsx(a.LoadingScreen,{url:o,loaderType:"black"}):c?.disabled?e.jsx(a.Modal,{config:r,message:c?.message}):e.jsx(s,{audio:!1,ref:d,screenshotQuality:1,videoConstraints:a.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 C({link:s,onReady:n,wrapperClassName:r="[&_video]:rounded-t-[20px] w-full h-full"}){const c=t.useRef(null),i=t.useRef(null);let u={autoplay:!0,controls:!1,responsive:!0,fluid:!0,muted:!0,navigationUI:"hide",preload:"metadata",poster:a.videoPoster};return t.useEffect(()=>{if(!i.current&&s&&c?.current){const e=o(c.current,{...u});e.ready(()=>{i.current=e;const t={...u,sources:[{src:s,type:"application/x-mpegURL"}]};e.autoplay(t.autoplay),e.src(t.sources),n?.(e)})}},[s,c]),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:c,muted:!0,className:"video-js",playsInline:!0,onDrag:e=>e.preventDefault()})})}function b({scanFailsError:s,onNext:o,gender:c,setScanUniqueKey:i,setIsVideoUploaded:u}){const{translate:l}=t.useContext(a.LanguageContext)||{},d=a.useConfig(),[m,p]=t.useState(!1),f=()=>{p(!m)};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{"data-testid":"scan-error-message",className:"flex common-ui-main flex-col h-full max-w-[28rem] mx-auto w-full rounded-t-[20px] overflow-y-auto",style:{background:d?.style?.base?.backgroundColor},children:[e.jsx("div",{className:"w-full max-w-[28rem] mx-auto pt-[1rem] px-[1rem]",children:e.jsx(a.Header,{noTitle:!0})}),e.jsx("div",{className:"flex-1",children:s&&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:l?.(a.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:l?.(a.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:a.handleErrorMessage(s)}),e.jsx("img",{className:"my-[0.5rem] aspect-[2/1.4] w-full object-cover",onClick:f,src:a.VIDEO_POSTER_GENDER_BASED[c],alt:"icon"})]})}),s&&e.jsx("div",{className:"p-[1rem] flex gap-[0.5rem]",children:e.jsx(a.SpecificButton,{"data-testid":"scan-again-btn",disabled:!1,buttonText:l?.(a.LanguageKeys.scanAgain),className:"!shadow-none",buttonFunc:()=>{o?o?.():i?.(a.generateUuid()),u?.(!1)}})})]}),m&&e.jsxs(r.Dialog,{className:"w-screen h-screen video-modal",onClose:f,open:m,children:[e.jsx("div",{className:"flex justifyEnd ",children:e.jsx("span",{className:"closeBtn",onClick:f,children:e.jsx(n.X,{className:"absolute right-[8px] top-[8px] text-white z-[9]"})})}),e.jsx("div",{className:"aspect-video object-cover rounded-[20px] ",children:e.jsx(C,{link:c?a.GENDER[c].PRE_LINK:a.GENDER.male.PRE_LINK,wrapperClassName:"w-screen h-screen fixed top-[0] left-[0]"})})]})]})}function E({scanId:s,userDetails:n,config:o,isVideoUploadedCorrect:c,isMeasurementAvailable:i,onComplete:u,isSuccess:l,onCustomScanSuccess:d,swan:m}){const{gender:p,shopDomain:f,heightInCm:S,deviceFocalLength:h,userName:g,email:v,scanType:y}=n||{},x=[a.CLOTHING_CUSTOM_SCAN,a.CLOTHING_BANNER_SCAN,a.CLOTHING_CUSTOM_FIT_SCAN].includes(y??""),[C,b]=t.useState(!0),E=t.useCallback(async()=>{try{x&&(await(m?.auth.addUser({scanId:s,email:v,name:g,gender:p,height:S})),d?.()),a.posthog.capture(f??"",{scanID:s,email:v,height:S,focalLength:h,clothesFit:"0",gender:p})}catch(e){console.log(e)}},[x]),{translate:j}=t.useContext(a.LanguageContext)||{};t.useEffect(()=>{(c||i)&&E()},[c,i]);const I=l||c||i;return e.jsx(r.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(w,{loader:o?.loader,setShowDrawer:b}),e.jsx(r.Drawer,{open:C,onClose:(e,t)=>{},className:"camera-drawer",anchor:"bottom",children:e.jsx("div",{className:"max-w-[28rem] mx-auto w-full h-full flex text-center flex-col justify-between items-center bg-primary rounded-t-[30px] p-[1rem]",style:{background:o?.style?.base?.backgroundColor},children:e.jsxs("div",{className:"w-full h-full flex flex-col",children:[e.jsx(a.Header,{title:j?.(a.LanguageKeys.measurementsBeingTaken)}),e.jsx("div",{className:"flex items-center justify-center flex-1",children:e.jsx("video",{preload:"auto",className:"max-h-[calc(100vh-450px)] mx-auto w-full object-contain border-none",muted:!0,loop:!0,autoPlay:!0,playsInline:!0,children:e.jsx("source",{src:p===a.GenderType.Male?a.maleMeasurementProgress:a.measurementProgress,type:"video/mp4"})})}),I&&e.jsx(a.SpecificButton,{className:"!w-[180px] mx-auto",buttonText:j?.(a.LanguageKeys.next),buttonFunc:()=>{u?.()}})]})})})]})})}const j=()=>{const{userDetails:s,onRetry:n,isError:o,isSuccess:c,gender:i,scanUniqueKey:u,scanFailsError:l,setScanUniqueKey:d,setIsVideoUploaded:m,isMeasurementAvailable:p,isVideoUploadedCorrect:f,loading:S,showDeniedModal:h,uploadLoading:g,setScanFailsError:v,setScanStartTime:y,resetScan:C,onCustomScanSuccess:j,swan:I,onComplete:N}=t.useContext(a.ParamsContext),D=a.useConfig();return o?e.jsxs("div",{"data-scan-state":"error",children:[e.jsx(w,{}),e.jsx(r.Drawer,{anchor:"bottom",open:!0,className:"camera-drawer",onClose:(e,t)=>{},children:e.jsx(b,{scanFailsError:!0,onNext:n,gender:i})})]}):c?e.jsx("div",{"data-scan-state":"success",children:e.jsx(E,{isSuccess:!0,onComplete:N})}):S?e.jsx("div",{"data-scan-state":"loading",className:"flex top-0 !mt-0 left-0 z-[999] absolute justify-center items-center w-full h-full",style:{background:D?.style?.base?.backgroundColor},children:e.jsx(a.LoadingScreen,{url:D?.loader,loaderType:"black"})}):h.disabled?e.jsx("div",{"data-scan-state":"camera-denied",children:e.jsx(a.Modal,{})}):g||l||p||f?(g||p||f)&&!l?e.jsx("div",{"data-scan-state":"processing",children:e.jsx(E,{scanId:u,isMeasurementAvailable:p,userDetails:s,isVideoUploadedCorrect:f,onCustomScanSuccess:j,swan:I,onComplete:N})}):e.jsxs("div",{"data-scan-state":"error-retry",children:[e.jsx(w,{}),e.jsx(r.Drawer,{anchor:"bottom",open:!0,className:"camera-drawer",onClose:(e,t)=>{},children:e.jsx(b,{scanFailsError:l,onNext:()=>{n?.(),C()},setScanUniqueKey:d,gender:i,setIsVideoUploaded:m})})]}):e.jsx("div",{"data-scan-state":"scanning",children:e.jsx(x,{scanID:u,userDetails:s,setIsVideoUploaded:m,setScanFailsError:v,setScanStartTime:y,setScanUniqueKey:d})})};exports.BodyScan=s=>{const{config:n,onRetry:r,onScanStart:o,onCaptureComplete:c,onUploadStart:i,onUploadEnd:u,onMeasurementSocketStart:l,onMeasurementSocketClose:m,onIntermediateScanSuccess:p,onScanError:f,onScanSuccess:S,onCustomScanSuccess:h,onComplete:g,isError:v,isSuccess:y}=s,x={email:"",shopDomain:"",gender:"male",heightInCm:0,scanType:"",deviceFocalLength:0,deviceModelName:"",sourceTag:"",callbackUrl:null,...s.userDetails??{}},w=s.token??"",{gender:C,scanType:b,shopDomain:E,heightInCm:I,email:N,deviceFocalLength:D,deviceModelName:T,callbackUrl:k,sourceTag:P}=x,_=t.useMemo(()=>a.getSwanService(w),[w]),[$,M]=t.useState(!1),[F,L]=t.useState(!1),[R,A]=t.useState(!1),[U,O]=t.useState({disabled:!1,message:""}),[K,z]=t.useState(""),[q,B]=t.useState(!1),[V,W]=t.useState(!0),[G,H]=t.useState(!1),[J,Y]=t.useState(""),[Q,X]=t.useState(a.getCurrentTimeInSeconds()),{gyroData:Z}=function(e){const[a,s]=t.useState([]),[n,r]=t.useState(!1),o=t.useCallback(e=>{try{const{alpha:t,beta:a,gamma:n}=e;s(e=>[...e,{alpha:t?.toString()||void 0,beta:a?.toString()||void 0,gamma:n?.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&&n?window.addEventListener("deviceorientation",o):s([]),()=>{window.removeEventListener("deviceorientation",o)}),[e,n,o]),t.useEffect(()=>{e&&c()},[e,c]),{gyroData:a}}(G);a.usePosthogPageview();const ee=t.useCallback(()=>{Y(a.generateUuid()),z(""),M(!1),B(!1)},[]),te=()=>{X(null),Y("")},ae=t.useCallback(async e=>{if(e&&"success"===e?.scanStatus&&"intermediate"===e?.resultType&&200===e?.code)return a.handleScanTimeCapture({eventName:`${E}/measurement_success/intermediate`,scanID:J,status:"success",email:N}),L(!0),void p?.(e);S?.(e),L(!0),te();const t=J;A(!0),a.handleScanTimeCapture({eventName:`${E}/measurement_success/fit-view`,scanID:t,status:"success",email:N}),Q&&a.handleScanTimeCapture({eventName:`${E}/scan_completion_time`,scanID:t,status:"success",completionTime:a.getCurrentTimeInSeconds()-Q,email:N})},[b,E,J]),se=e=>{A(!1),z(""),L(!1),_.measurement.handleMeasurementSocket({scanId:J,onPreopen:()=>{a.handleWebSocketCapture({eventName:`${E}/webSocket`,scanID:J,connection:"pre_open",type:"measurement_recommendation",email:N})},onOpen:()=>{l?.(),a.handleWebSocketCapture({eventName:`${E}/webSocket`,scanID:J,connection:"open",type:"measurement_recommendation",email:N})},onClose:()=>{m?.(),a.handleWebSocketCapture({eventName:`${E}/webSocket`,scanID:J,connection:"close",type:"measurement_recommendation",email:N})},onError:e=>{var t;t=e,f?.({...t,message:a.handleErrorMessage(t)}),te(),A(!1),z(t),L(!1),a.handleScanTimeCapture({eventName:`${E}/measurement_failed/fit-view`,scanID:J,status:"failed",email:N,message:a.handleErrorMessage(t)}),Q&&a.handleScanTimeCapture({eventName:`${E}/scan_completion_time`,scanID:J,status:"failed",completionTime:a.getCurrentTimeInSeconds()-Q,email:N}),a.handleWebSocketCapture({eventName:`${E}/webSocket`,scanID:J,connection:"error",type:"measurement_recommendation",email:N})},onSuccess:e=>{a.handleWebSocketCapture({eventName:`${E}/webSocket`,scanID:J,connection:"success",type:"measurement_recommendation",email:N}),ae(e)}})},ne=t.useCallback(async(e,t)=>{const s=Number((e.size/1048576).toFixed(2)),n=null!=t?t:await a.getVideoFPS(e),r=a.createObjectMetadataArray({gender:C,focal_length:`${D}`,height:`${I}`,customer_store_url:E,clothes_fit:"0",scan_type:b,callback_url:k,source_tag:P});a.handleScanTimeCapture({eventName:`${E}/body_scan_meta_data`,scanID:J,email:N,data:JSON.stringify([...r,{fileSizeInMB:s,video_fps:n||0}])}),i?.();try{await _.fileUpload.uploadFileFrontend({file:e,arrayMetaData:r,scanId:J,email:N}),await _.fileUpload.setDeviceInfo({model:T,detection:"manual",gyro:Z,scanId:J}),console.log("video successfully uploaded"),B(!1),a.handleScanTimeCapture({eventName:`${E}/scan_success`,scanID:J,status:"success",email:N,data:JSON.stringify(r)}),a.handleScanTimeCapture({eventName:"scan finished",scanID:J,status:"success",email:N}),X(a.getCurrentTimeInSeconds()),setTimeout(()=>{B(!0)},3e3)}catch(e){a.handleScanTimeCapture({eventName:"scan finished",scanID:J,status:"failed",email:N,message:a.handleErrorMessage(e)}),a.handleScanTimeCapture({eventName:`${E}/scan_failed`,scanID:J,status:"failed",email:N,message:a.handleErrorMessage(e),data:JSON.stringify(r)}),z(a.handleErrorMessage(e)),B(!1),f?.({...e,message:a.handleErrorMessage(e)}),te()}finally{H(!1),u?.()}},[J,Z,i,u]),re=t.useCallback(async()=>{if(+I<152.4||+I>213.36)return void f?.({message:"Height must be between 152.4cm (5ft) and 213.36cm (7ft)"});const e=await a.checkCameraPermission();e.disabled?(a.handleScanTimeCapture({eventName:`${E}/camera_activation`,scanID:J,status:"failed",email:N}),W(!1)):(W(!1),a.handleScanTimeCapture({eventName:`${E}/camera_activation`,scanID:J,status:"success",email:N})),O(e),z(""),B(!1)},[N,J,Y,E]);return t.useEffect(()=>{v||y||E&&re()},[E,I,v,y]),t.useEffect(()=>{v||y||q&&E&&J&&se()},[q,E,J,v,y]),e.jsx("div",{"data-testid":"body-scan-root",children:e.jsx(a.LanguageContextProvider,{children:e.jsx(a.ConfigProvider,{config:n,children:e.jsx(d,{children:e.jsx(a.ParamsContext.Provider,{value:{userDetails:x,onRetry:r,onScanError:f,isError:v,isSuccess:y,onScanSuccess:S,gender:C,scanUniqueKey:J,scanFailsError:K,setScanUniqueKey:Y,setIsVideoUploaded:B,isMeasurementAvailable:R,isVideoUploadedCorrect:F,loading:V,showDeniedModal:U,uploadLoading:$,setStartGyro:H,uploadScanFile:ne,setUploadLoading:M,resetScan:ee,setScanFailsError:z,setScanStartTime:X,onScanStart:o,onCaptureComplete:c,onCustomScanSuccess:h,onComplete:g,swan:_},children:e.jsx(j,{})})})})})})};
|
|
2
|
-
//# sourceMappingURL=BodyScan-CoObDhac.js.map
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";var e=require("react/jsx-runtime"),t=require("react"),s=require("./LoadingScreen-BILrJVZm.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]),g=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`,[]),h=t.useCallback((e=!1)=>{const t=m();return o?`text-[${d?.style?.angleDetector?.successAngleTextLightColor}]`:g(e,t)},[o,m]),x=t.useCallback((e,t)=>t>70||e?d?.style?.angleDetector?.successAngleTextLightColor:d?.style?.angleDetector?.successAngleTextDarkColor,[]),y=t.useCallback((e=!1)=>{const t=m();return o?d?.style?.angleDetector?.successAngleTextLightColor:x(e,t)},[o,m]),S=r;function v(){document.documentElement.style.setProperty("--real-vh",window.innerHeight+"px")}return v(),window.addEventListener("resize",v),e.jsxs("div",{className:"flex common-ui-main w-screen flex-col items-center h-[var(--real-vh)] overflow-hidden touch-none justify-center transition-all duration-300 max-w-[28rem] mx-auto",style:{backgroundColor:f},"data-testid":"level-screen","data-angle-state":o?"locked":c?"target":"adjusting",children:[e.jsx("div",{className:"flex justify-start fixed top-[.5rem] max-w-[28rem] mx-auto w-full px-[1rem]",children:e.jsx("div",{className:"flex justify-start ",children:e.jsx(s.Header,{noTitle:!0})})}),null!==S?e.jsx("div",{className:"relative flex h-[6rem] w-[6rem] items-center justify-center rounded-[9999px] bg-[#fff]/20 transition-all duration-300",style:{border:`2px solid ${y()}`},children:e.jsx("div",{className:`text-[3rem] font-bold text-[${y()}]`,style:{fontFamily:d?.style?.base?.baseFontFamily||"Inter, sans-serif",color:y()},children:S})}):o?e.jsxs("div",{className:"relative flex flex-col items-center justify-center",children:[e.jsx("div",{className:"relative flex h-16 w-16 items-center justify-center rounded-[9999px] border-2 bg-[#fff]/30 border-[#fff]",children:e.jsx("div",{className:"h-4 w-4 rounded-[9999px] animate-pulse bg-[#fff]/80"})}),l]}):e.jsxs("div",{className:n("relative flex h-[4rem] w-[4rem] items-center justify-center rounded-[9999px] ",c?"bg-[#fff]/20 border-[#fff]":"bg-[#fff]/10 border-[#fff]"),style:{transform:`translateY(${3*(90-a)}px)`,transition:"transform 0.2s ease-out",border:`2px solid ${y()}`},children:[e.jsx("div",{className:`h-[1rem] w-[1rem] rounded-[9999px] bg-[${y()}]/80`,style:{backgroundColor:`${y()}B3`}}),e.jsxs("div",{className:n("mt-[.5rem] text-center w-[180px] flex-col flex items-center absolute top-[60px]",h()),style:{color:y()},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!==S&&e.jsx("div",{className:"absolute bottom-[8rem] text-center",children:e.jsx("div",{className:n("text-sm font-medium px-4 py-1.5 bg-black/20 rounded-[9999px] mt-8",h()),style:{fontFamily:d?.style?.base?.baseFontFamily||"Inter, sans-serif",color:y()},children:u?.(s.LanguageKeys.leavePhone)})}),c&&null===S&&!o&&e.jsx("div",{className:"absolute bottom-[8rem] w-[12rem]",children:e.jsx("div",{className:`h-[.375rem] w-full bg-[${y()}]/20 rounded-[9999px] overflow-hidden`,style:{backgroundColor:`${y()}33`},children:e.jsx("div",{className:`h-full bg-[${y()}]/70 transition-all duration-300 rounded-[9999px]`,style:{width:`${a}%`,backgroundColor:`${y()}B3`}})})}),null===S&&!o&&e.jsx("div",{className:"absolute bottom-[5rem] text-center",children:e.jsxs("div",{className:n("text-[1.5rem] font-light",h()),style:{color:y()},children:[Math.round(a),"°"]})}),null===S&&!o&&e.jsx("div",{className:"absolute bottom-[2rem] text-center max-w-[20rem] mx-auto",children:e.jsx("div",{className:n("text-[.75rem] opacity-50",h()),style:{fontFamily:d?.style?.base?.baseFontFamily||"Inter, sans-serif",color:y()},children:u?.(s.LanguageKeys.placePhoneUpright)})})]})});function g({resetScan:n,loadingCam:o,onUserMedia:c,onPause:i,pause:l,recordingStarted:m,startSendingVideoFrames:p,showPause:f,webcamRef:g,onUserMediaError:h,resetDetector:x,videoConstraints:y,webcamKey:S,faceDone:v,isScanning:b}){const{media:C}=t.useContext(d)||{},{translate:w}=t.useContext(s.LanguageContext)||{};return e.jsxs("div",{className:"App w-screen h-[100vh] relative common-ui-main","data-testid":"camera-scan","data-scan-phase":v?"spinning":m?"pose-detecting":b?"starting":"ready",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:C===u&&e.jsx(a,{audio:!1,ref:g,screenshotQuality:1,videoConstraints:y,mirrored:!0,screenshotFormat:"image/jpeg",onUserMedia:c,onUserMediaError:h,style:{position:"fixed",top:0,bottom:0,zIndex:0,width:"100%",height:"100%",objectFit:"cover"}},S)}),e.jsxs("div",{className:"fixed bottom-[30px] w-full z-[999] flex flex-col gap-4 items-center justify-center",children:[f&&e.jsx(s.SpecificButton,{className:"!w-[180px] !h-[40px] !py-[0] mx-auto ",prefix:s.pauseIcon,buttonText:w?.(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:w?.(s.LanguageKeys.restart),buttonFunc:n,btnSecondary:!0})}):m?null:e.jsx(s.SpecificButton,{"data-testid":"start-scan-btn",className:"!w-[180px] !h-[40px] !py-[0] mx-auto !bg-[#ffffff] !text-[#000000] "+(o?"!opacity-50":""),buttonText:w?.(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 h=null,x=null,y=null;let S,v=null,b=null;var C=t.memo(function({setIsScanLocked:n,resetDetector:a,scanID:r,setIsVideoUploaded:o,setScanFailsError:c,setScanStartTime:i,setScanUniqueKey:l,userDetails:u}){const{gender:d,heightInCm:m,email:p,shopDomain:f}=u,C=t.useRef(null),w=t.useRef(null),j=t.useRef(null),[N,k]=t.useState([]),[E,D]=t.useState(!0),[T,F]=t.useState(!1),[I,L]=t.useState(!1),[M,_]=t.useState(!0),[P,A]=t.useState(!1),$=t.useRef(null),[R,U]=t.useState(""),[z,K]=t.useState([]),[O,B]=t.useState(""),[q,V]=t.useState(!1),[W,H]=t.useState(!1),[G,J]=t.useState(!1),[X,Q]=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-Bc8T4UAD.js")}),import("@tensorflow/tfjs-core"),import("@tensorflow/tfjs-backend-webgl")]);y=e,await t.setBackend("webgl"),await t.ready(),console.log("TensorFlow backend ready (WebGL)");const n={runtime:"mediapipe",modelType:"full",solutionPath:"https://cdn.jsdelivr.net/npm/@mediapipe/pose"};try{x=await y.createDetector(y.SupportedModels.BlazePose,n),console.log("MediaPipe detector created successfully")}catch(e){console.warn("MediaPipe failed, falling back to TFJS runtime:",e),x=await y.createDetector(y.SupportedModels.BlazePose,{runtime:"tfjs",modelType:"full"}),console.log("TFJS detector created successfully")}return!0}catch(e){return console.error("Failed to load TensorFlow dependencies:",e),h=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 h||(h=u()),h.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||h||(h=u(),await h&&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(!1),le=t.useRef(()=>{}),[ue,de]=t.useState([]),[me,pe]=t.useState(0),[fe,ge]=t.useState(s.videoConstraintsExact),{setStartGyro:he,uploadScanFile:xe,setUploadLoading:ye,swan:Se,onScanStart:ve,onCaptureComplete:be}=t.useContext(s.ParamsContext),Ce=()=>{ne.current=!1,clearTimeout(S),$.current&&clearTimeout($.current),l(s.generateUuid()),c(""),ye?.(!1),k([]),j.current=null,D(!0),F(!1),L(!1),_(!0),A(!1),$.current=null,U(""),K([]),B(""),V(!q),he(!1),s.speechService.stopAudio(),H(!1),J(!1),ae.current=0,re.current=0,oe.current=!1,ie.current=!1,null!==w.current&&w.current.stop(),X.forEach(e=>{w.current&&w.current.removeEventListener("dataavailable",e)}),Q([]),ee.current=!0,Z(!1),o(!1),C.current?.stream&&D(!1)},we=t.useCallback(()=>{setTimeout(()=>{D(!1)},1e3)},[]),je=t.useCallback(e=>{if(console.log("camera error",e),fe===s.videoConstraintsExact)return ge(s.videoConstraintsFallback),void pe(e=>e+1);D(!1)},[fe]),Ne=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,ie.current=!1,w.current&&w.current.stop(),X.forEach(e=>{w.current&&w.current.removeEventListener("dataavailable",e)}),Q([]),clearTimeout(S)},[w,X,s.speechService,ee]),ke=t.useMemo(()=>s.getPreferredMediaRecorderTypes(),[]),Ee=s.getRecordingMimeType(ue),De=s.getRecordingExtension(Ee),Te=t.useCallback(async()=>{ee.current=!0,await s.speechService.playAudio(`${s.voiceOverAssetsPath}SpotOn.mp3`),J(!1),Z(!1),$.current&&clearTimeout($.current),F(!1)},[$,s.speechService]),Fe=t.useCallback(async()=>{if(!ce.current&&!v){ce.current=!0;try{v=await Se.poseDetection.connect(),console.log(v,"websocket connected"),s.posthog.capture(`${f}/pose_detection_connected`,{scanID:r,email:p,id:v})}catch(e){console.log(e,"while connecting websocket")}finally{ce.current=!1}}},[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(),Ce(),await Fe(),$e()},[Fe,r,p]),Le=t.useCallback(({data:e})=>{e&&e.size>0&&ee.current&&(k(t=>t.concat(e)),!ne.current&&C.current&&(ne.current=!0,te(()=>{Te(),s.handleScanTimeCapture({eventName:`${f}/tensorFlow`,scanID:r,email:p,message:"recording stopped by tensorflow "})},C)))},[Te,s.handleScanTimeCapture,f,r,p,C]),Me=t.useCallback(async()=>{z.length>0&&ee.current&&(await s.speechService.playAudio(s.voiceOverAssetsPath+z[z.length-1]),ee.current&&(S=setTimeout(Me,2e3)))},[z,ee]),_e=t.useCallback(()=>{w&&w.current&&w.current.stop(),F(!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};ue[0]&&(t.mimeType=ue[0]),w.current=new MediaRecorder(C.current.stream,t),w.current.addEventListener("dataavailable",Le),w.current.addEventListener("stop",()=>{console.log("[FIX] MediaRecorder stop event — all chunks flushed, setting mediaRecorderStopped=true"),_(!0)}),Q([...X,Le]),w.current.start(1e3),_(!1)}}catch(e){console.log("error while using media recorder",e)}},[C,ue,Le,X]),Pe=t.useCallback(async()=>{$.current&&clearTimeout($.current),_e(),ee.current&&($.current=setTimeout(async()=>{ee.current&&(await s.speechService.playAudio(`${s.voiceOverAssetsPath}SpotOn.mp3`),F(!1))},15e3)),L(!0),ee.current&&await s.speechService.playAudio(`${s.voiceOverAssetsPath}Spin.mp3`)},[_e,ee,s.speechService]);t.useEffect(()=>{le.current=Pe},[Pe]);const Ae=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=document.querySelector("#audioElement");!0===e.status&&e.sid===v?(re.current=0,ae.current<2?(ae.current+=1,1!==ae.current||ie.current?2===ae.current&&t?.paused&&s.speechService.playAudio(s.voiceOverAssetsPath+e.audio):(ie.current=!0,s.speechService.stopAudio(),await s.speechService.playAudio(s.voiceOverAssetsPath+e.audio))):(B(e.audio),clearTimeout(S),Se.poseDetection.disconnect(),oe.current=!1,setTimeout(()=>le.current(),1e3))):(re.current+=1,re.current>=3&&(ae.current=0,ie.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,v,s.speechService,f,p]),$e=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),F(!0),H(!0),Z(!0),we());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};ue[0]&&(t.mimeType=ue[0]),ee.current&&(w.current=new MediaRecorder(C.current.stream,t)),ee.current&&w.current&&w.current.addEventListener("dataavailable",Ae),Q([...X,Ae]),w.current&&w.current.start(1e3),_(!1),ee.current&&(S=setTimeout(Me,2e3))}}catch(e){console.log("error ----------",e)}},[C,ue,Ae,X,Me,ee,ve]);return t.useEffect(()=>(f&&(n(!0),Fe()),()=>{ce.current=!1,v&&(Se.poseDetection.disconnect(),s.posthog.capture(`${f}/pose_detection_disconnected`,{scanID:r,email:p,id:v})),X.forEach(e=>{w?.current?.removeEventListener("dataavailable",e)})}),[f]),t.useEffect(()=>{z.push(R)},[R]),t.useEffect(()=>{K([])},[O]),t.useEffect(()=>{const e=N.length&&N.length>0;M||!e||T||!ee.current||G||w&&w.current&&(T||w.current.stop())},[M,T,N,G]),t.useEffect(()=>{const e=N.length&&N.length>0;if(M&&e&&!T){if(w&&w.current&&ee.current&&!G&&!T){const e=new File(N,`${r}.${De}`,{type:Ee});console.log("[FIX] Upload triggered — file size:",(e.size/1024).toFixed(1)+"KB, chunks:",N.length),be?.(),ye?.(!0),c(""),xe?.(e,j.current)}}else console.log("No video found to upload.")},[M,T,N,G,w,ee]),t.useEffect(()=>{const e=s.getSupportedMediaRecorderTypes(ke,s.videoTypes);de(e)},[ke]),t.useEffect(()=>{Ce()},[]),e.jsx(g,{resetDetector:a,resetScan:Ce,loadingCam:E,onPause:Ne,showRestart:W,pause:G,onReScan:Ie,recordingStarted:T,isScanning:P,startSendingVideoFrames:$e,faceDone:I,stopRecording:Te,showPause:Y,webcamRef:C,onUserMedia:we,onUserMediaError:je,videoConstraints:fe,webcamKey:me})});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),[g,h]=t.useState(!1),[x,y]=t.useState(0),S=t.useRef([]),[v,b]=t.useState(!1),w=i-u,j=w>=80&&w<=95;t.useEffect(()=>{if("undefined"!=typeof window&&window.DeviceOrientationEvent){const e=e=>{if(null!==e.beta){let t=Math.abs(e.beta);null!==e.gamma&&(t*=Math.cos(e.gamma*Math.PI/180)),t=Math.max(0,Math.min(180,t)),l(t)}},t=async()=>{const t=DeviceOrientationEvent;if(t&&"function"==typeof t.requestPermission)try{"granted"===await t.requestPermission()&&window.addEventListener("deviceorientation",e)}catch(e){console.error("Permission error",e)}else window.addEventListener("deviceorientation",e);return()=>{e&&window.removeEventListener("deviceorientation",e)}};document.addEventListener("click",t,{once:!0})}},[]),t.useEffect(()=>{if(S.current=[...S.current.slice(-4),w],S.current.length>=5){const e=Math.max(...S.current)-Math.min(...S.current);y(j&&e<2?e=>Math.min(100,e+10):e=>Math.max(0,e-20))}j||null===m&&!g||k()},[w,j,m,g]),t.useEffect(()=>{x>=100&&null===m&&!g&&N(),x<50&&null!==m&&k()},[x,m,g]);const N=()=>{p(3);const e=setInterval(()=>{p(t=>null===t||t<=1?(clearInterval(e),h(!0),null):t-1)},1e3)},k=()=>{p(null),v||h(!1)};return e.jsx(f,{angle:w,countdown:m,isScanning:g,isInTargetRange:j,stabilityScore:x,children:g&&e.jsx(C,{setIsScanLocked:b,resetDetector:()=>{l(90),d(0),p(null),h(!1),y(0),b(!1),S.current=[]},scanID:s,userDetails:n,setIsVideoUploaded:a,setScanFailsError:r,setScanStartTime:o,setScanUniqueKey:c})})}function j({message:n,config:a}){const{translate:r}=t.useContext(s.LanguageContext)||{};return e.jsx(o.Dialog,{open:!0,className:"confirm-modal common-ui-main",children:e.jsx("div",{className:"modal-main",children:e.jsx("div",{className:"text-center",children:n?e.jsxs(e.Fragment,{children:[e.jsx("h2",{style:{fontFamily:a?.style?.heading?.headingFontFamily||"SeriouslyNostalgic Fn",fontSize:a?.style?.heading?.headingFontSize||"32px",color:a?.style?.heading?.headingColor||"#000",fontWeight:a?.style?.heading?.headingFontWeight||"normal"},children:r?.(s.LanguageKeys.cameraAlreadyInUse)}),e.jsx("p",{className:"mt-[0.5rem] text-sm",style:{fontFamily:a?.style?.base?.baseFontFamily||"Inter, sans-serif",fontSize:a?.style?.base?.baseFontSize||"16px",color:a?.style?.base?.baseTextColor||"#000"},children:r?.(s.LanguageKeys.tryClosingBrowser)})]}):e.jsxs(e.Fragment,{children:[e.jsx("h2",{style:{fontFamily:a?.style?.heading?.headingFontFamily||"SeriouslyNostalgic Fn",fontSize:a?.style?.heading?.headingFontSize||"32px",color:a?.style?.heading?.headingColor||"#000",fontWeight:a?.style?.heading?.headingFontWeight||"normal"},children:r?.(s.LanguageKeys.checkCameraSettings)}),e.jsx("p",{className:"mt-[0.5rem] text-sm",style:{fontFamily:a?.style?.base?.baseFontFamily||"Inter, sans-serif",fontSize:a?.style?.base?.baseFontSize||"16px",color:a?.style?.base?.baseTextColor||"#000"},children:`${r?.(s.LanguageKeys.setting)} > ${s.getBrowserName()} > ${r?.(s.LanguageKeys.enableCameraPermissions)}`})]})})})})}function N({setShowDrawer:n,config:r,loader:o}){const[c,i]=t.useState({disabled:!1,message:""}),[l,u]=t.useState(!0),d=t.useRef(null),m=t.useCallback(async()=>{const e=await s.checkCameraPermission();i(e),u(!1)},[]);return t.useEffect(()=>{m()},[]),l?e.jsx(s.LoadingScreen,{url:o,loaderType:"black"}):c?.disabled?e.jsx(j,{config:r,message:c?.message}):e.jsx(a,{audio:!1,ref:d,screenshotQuality:1,videoConstraints:s.videoConstraints,mirrored:!0,onUserMedia:()=>n?.(!0),screenshotFormat:"image/jpeg",style:{position:"relative",top:0,bottom:0,zIndex:0,width:"100%",height:"100%",objectFit:"cover"}})}function k({link:n,onReady:a,wrapperClassName:r="[&_video]:rounded-t-[20px] w-full h-full"}){const o=t.useRef(null),i=t.useRef(null);let l={autoplay:!0,controls:!1,responsive:!0,fluid:!0,muted:!0,navigationUI:"hide",preload:"metadata",poster:s.videoPoster};return t.useEffect(()=>{if(!i.current&&n&&o?.current){const e=c(o.current,{...l});e.ready(()=>{i.current=e;const t={...l,sources:[{src:n,type:"application/x-mpegURL"}]};e.autoplay(t.autoplay),e.src(t.sources),a?.(e)})}},[n,o]),t.useEffect(()=>{const e=i.current;return()=>{e&&!e.isDisposed()&&(e.dispose(),i.current=null)}},[i]),e.jsx("div",{className:r,children:e.jsx("video",{ref:o,muted:!0,className:"video-js",playsInline:!0,onDrag:e=>e.preventDefault()})})}function E({scanFailsError:n,onNext:a,gender:c,setScanUniqueKey:i,setIsVideoUploaded:l}){const{translate:u}=t.useContext(s.LanguageContext)||{},d=s.useConfig(),[m,p]=t.useState(!1),f=()=>{p(!m)};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{"data-testid":"scan-error-message",className:"flex common-ui-main flex-col h-full max-w-[28rem] mx-auto w-full rounded-t-[20px] overflow-y-auto",style:{background:d?.style?.base?.backgroundColor},children:[e.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,{"data-testid":"scan-again-btn",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,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 D({scanId:n,userDetails:a,config:r,isVideoUploadedCorrect:c,isMeasurementAvailable:i,onComplete:l,isSuccess:u,onCustomScanSuccess:d,swan:m}){const{gender:p,shopDomain:f,heightInCm:g,deviceFocalLength:h,userName:x,email:y,scanType:S}=a||{},v=[s.CLOTHING_CUSTOM_SCAN,s.CLOTHING_BANNER_SCAN,s.CLOTHING_CUSTOM_FIT_SCAN].includes(S??""),[b,C]=t.useState(!0),w=t.useCallback(async()=>{try{v&&(await(m?.auth.addUser({scanId:n,email:y,name:x,gender:p,height:g})),d?.()),s.posthog.capture(f??"",{scanID:n,email:y,height:g,focalLength:h,clothesFit:"0",gender:p})}catch(e){console.log(e)}},[v]),{translate:j}=t.useContext(s.LanguageContext)||{};t.useEffect(()=>{(c||i)&&w()},[c,i]);const k=u||c||i;return e.jsx(o.Box,{className:"flex h-full w-full flex-col common-ui-main",children:e.jsxs("div",{className:"h-full w-full flex-col items-center justify-center flex",children:[e.jsx(N,{loader:r?.loader,setShowDrawer:C}),e.jsx(o.Drawer,{open:b,onClose:(e,t)=>{},className:"camera-drawer",anchor:"bottom",children:e.jsx("div",{className:"max-w-[28rem] mx-auto w-full h-full flex text-center flex-col justify-between items-center bg-primary rounded-t-[30px] p-[1rem]",style:{background:r?.style?.base?.backgroundColor},children:e.jsxs("div",{className:"w-full h-full flex flex-col",children:[e.jsx(s.Header,{title:j?.(s.LanguageKeys.measurementsBeingTaken)}),e.jsx("div",{className:"flex items-center justify-center flex-1",children:e.jsx("video",{preload:"auto",className:"max-h-[calc(100vh-450px)] mx-auto w-full object-contain border-none",muted:!0,loop:!0,autoPlay:!0,playsInline:!0,children:e.jsx("source",{src:p===s.GenderType.Male?s.maleMeasurementProgress:s.measurementProgress,type:"video/mp4"})})}),k&&e.jsx(s.SpecificButton,{className:"!w-[180px] mx-auto",buttonText:j?.(s.LanguageKeys.next),buttonFunc:()=>{l?.()}})]})})})]})})}const T=()=>{const{userDetails:n,onRetry:a,isError:r,isSuccess:c,gender:i,scanUniqueKey:l,scanFailsError:u,setScanUniqueKey:d,setIsVideoUploaded:m,isMeasurementAvailable:p,isVideoUploadedCorrect:f,loading:g,showDeniedModal:h,uploadLoading:x,setScanFailsError:y,setScanStartTime:S,resetScan:v,onCustomScanSuccess:b,swan:C,onComplete:k}=t.useContext(s.ParamsContext),T=s.useConfig();return r?e.jsxs("div",{"data-scan-state":"error",children:[e.jsx(N,{}),e.jsx(o.Drawer,{anchor:"bottom",open:!0,className:"camera-drawer",onClose:(e,t)=>{},children:e.jsx(E,{scanFailsError:!0,onNext:a,gender:i})})]}):c?e.jsx("div",{"data-scan-state":"success",children:e.jsx(D,{isSuccess:!0,onComplete:k})}):g?e.jsx("div",{"data-scan-state":"loading",className:"flex top-0 !mt-0 left-0 z-[999] absolute justify-center items-center w-full h-full",style:{background:T?.style?.base?.backgroundColor},children:e.jsx(s.LoadingScreen,{url:T?.loader,loaderType:"black"})}):h.disabled?e.jsx("div",{"data-scan-state":"camera-denied",children:e.jsx(j,{})}):x||u||p||f?(x||p||f)&&!u?e.jsx("div",{"data-scan-state":"processing",children:e.jsx(D,{scanId:l,isMeasurementAvailable:p,userDetails:n,isVideoUploadedCorrect:f,onCustomScanSuccess:b,swan:C,onComplete:k})}):e.jsxs("div",{"data-scan-state":"error-retry",children:[e.jsx(N,{}),e.jsx(o.Drawer,{anchor:"bottom",open:!0,className:"camera-drawer",onClose:(e,t)=>{},children:e.jsx(E,{scanFailsError:u,onNext:()=>{a?.(),v()},setScanUniqueKey:d,gender:i,setIsVideoUploaded:m})})]}):e.jsx("div",{"data-scan-state":"scanning",children:e.jsx(w,{scanID:l,userDetails:n,setIsVideoUploaded:m,setScanFailsError:y,setScanStartTime:S,setScanUniqueKey:d})})};exports.BodyScan=n=>{const{config:a,onRetry:r,onScanStart:o,onCaptureComplete:c,onUploadStart:i,onUploadEnd:l,onMeasurementSocketStart:u,onMeasurementSocketClose:d,onIntermediateScanSuccess:p,onScanError:f,onScanSuccess:g,onCustomScanSuccess:h,onComplete:x,isError:y,isSuccess:S}=n,v={email:"",shopDomain:"",gender:"male",heightInCm:0,scanType:"",deviceFocalLength:0,deviceModelName:"",sourceTag:"",...n.userDetails??{}},b=n.token??"",{gender:C,scanType:w,shopDomain:j,heightInCm:N,email:k,deviceFocalLength:E,deviceModelName:D,callbackUrl:F,sourceTag:I}=v,L=t.useMemo(()=>s.getSwanService(b),[b]),[M,_]=t.useState(!1),[P,A]=t.useState(!1),[$,R]=t.useState(!1),[U,z]=t.useState({disabled:!1,message:""}),[K,O]=t.useState(""),[B,q]=t.useState(!1),[V,W]=t.useState(!0),[H,G]=t.useState(!1),[J,X]=t.useState(""),[Q,Y]=t.useState(s.getCurrentTimeInSeconds()),{gyroData:Z}=function(e){const[s,n]=t.useState([]),[a,r]=t.useState(!1),o=t.useCallback(e=>{try{const{alpha:t,beta:s,gamma:a}=e;n(e=>[...e,{alpha:t?.toString()||void 0,beta:s?.toString()||void 0,gamma:a?.toString()||void 0,timestamp:(new Date).toISOString()}])}catch(e){console.log(e)}},[]),c=t.useCallback(async()=>{const e=DeviceOrientationEvent;if(void 0!==e&&"function"==typeof e.requestPermission)try{"granted"===await e.requestPermission()?r(!0):console.warn("Device orientation permission denied.")}catch(e){console.error("Error requesting device orientation permission:",e)}else r(!0)},[]);return t.useEffect(()=>(e&&a?window.addEventListener("deviceorientation",o):n([]),()=>{window.removeEventListener("deviceorientation",o)}),[e,a,o]),t.useEffect(()=>{e&&c()},[e,c]),{gyroData:s}}(H);s.usePosthogPageview();const ee=t.useCallback(()=>{X(s.generateUuid()),O(""),_(!1),q(!1)},[]),te=()=>{Y(null),X("")},se=t.useCallback(async e=>{if(e&&"success"===e?.scanStatus&&"intermediate"===e?.resultType&&200===e?.code)return s.handleScanTimeCapture({eventName:`${j}/measurement_success/intermediate`,scanID:J,status:"success",email:k}),A(!0),void p?.(e);g?.(e),A(!0),te();const t=J;R(!0),s.handleScanTimeCapture({eventName:`${j}/measurement_success/fit-view`,scanID:t,status:"success",email:k}),Q&&s.handleScanTimeCapture({eventName:`${j}/scan_completion_time`,scanID:t,status:"success",completionTime:s.getCurrentTimeInSeconds()-Q,email:k})},[w,j,J]),ne=e=>{R(!1),O(""),A(!1),L.measurement.handleMeasurementSocket({scanId:J,onPreopen:()=>{s.handleWebSocketCapture({eventName:`${j}/webSocket`,scanID:J,connection:"pre_open",type:"measurement_recommendation",email:k})},onOpen:()=>{u?.(),s.handleWebSocketCapture({eventName:`${j}/webSocket`,scanID:J,connection:"open",type:"measurement_recommendation",email:k})},onClose:()=>{d?.(),s.handleWebSocketCapture({eventName:`${j}/webSocket`,scanID:J,connection:"close",type:"measurement_recommendation",email:k})},onError:e=>{var t;t=e,f?.({...t,message:s.handleErrorMessage(t)}),te(),R(!1),O(t),A(!1),s.handleScanTimeCapture({eventName:`${j}/measurement_failed/fit-view`,scanID:J,status:"failed",email:k,message:s.handleErrorMessage(t)}),Q&&s.handleScanTimeCapture({eventName:`${j}/scan_completion_time`,scanID:J,status:"failed",completionTime:s.getCurrentTimeInSeconds()-Q,email:k}),s.handleWebSocketCapture({eventName:`${j}/webSocket`,scanID:J,connection:"error",type:"measurement_recommendation",email:k})},onSuccess:e=>{s.handleWebSocketCapture({eventName:`${j}/webSocket`,scanID:J,connection:"success",type:"measurement_recommendation",email:k}),se(e)}})},ae=t.useCallback(async(e,t)=>{const n=Number((e.size/1048576).toFixed(2)),a=null!=t?t:await s.getVideoFPS(e),r=s.createObjectMetadataArray({gender:C,focal_length:`${E}`,height:`${N}`,customer_store_url:j,clothes_fit:"0",scan_type:w,callback_url:F,source_tag:I});s.handleScanTimeCapture({eventName:`${j}/body_scan_meta_data`,scanID:J,email:k,data:JSON.stringify([...r,{fileSizeInMB:n,video_fps:a||0}])}),i?.();try{await L.fileUpload.uploadFileFrontend({file:e,arrayMetaData:r,scanId:J,email:k}),await L.fileUpload.setDeviceInfo({model:D,detection:"manual",gyro:Z,scanId:J}),console.log("video successfully uploaded"),q(!1),s.handleScanTimeCapture({eventName:`${j}/scan_success`,scanID:J,status:"success",email:k,data:JSON.stringify(r)}),s.handleScanTimeCapture({eventName:"scan finished",scanID:J,status:"success",email:k}),Y(s.getCurrentTimeInSeconds()),setTimeout(()=>{q(!0)},3e3)}catch(e){s.handleScanTimeCapture({eventName:"scan finished",scanID:J,status:"failed",email:k,message:s.handleErrorMessage(e)}),s.handleScanTimeCapture({eventName:`${j}/scan_failed`,scanID:J,status:"failed",email:k,message:s.handleErrorMessage(e),data:JSON.stringify(r)}),O(s.handleErrorMessage(e)),q(!1),f?.({...e,message:s.handleErrorMessage(e)}),te()}finally{G(!1),l?.()}},[J,Z,i,l]),re=t.useCallback(async()=>{if(+N<152.4||+N>213.36)return void 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:k}),W(!1)):(W(!1),s.handleScanTimeCapture({eventName:`${j}/camera_activation`,scanID:J,status:"success",email:k})),z(e),O(""),q(!1)},[k,J,X,j]);return t.useEffect(()=>{y||S||j&&re()},[j,N,y,S]),t.useEffect(()=>{y||S||B&&j&&J&&ne()},[B,j,J,y,S]),e.jsx("div",{"data-testid":"body-scan-root",children:e.jsx(s.LanguageContextProvider,{children:e.jsx(s.ConfigProvider,{config:a,children:e.jsx(m,{children:e.jsx(s.ParamsContext.Provider,{value:{userDetails:v,onRetry:r,onScanError:f,isError:y,isSuccess:S,onScanSuccess:g,gender:C,scanUniqueKey:J,scanFailsError:K,setScanUniqueKey:X,setIsVideoUploaded:q,isMeasurementAvailable:$,isVideoUploadedCorrect:P,loading:V,showDeniedModal:U,uploadLoading:M,setStartGyro:G,uploadScanFile:ae,setUploadLoading:_,resetScan:ee,setScanFailsError:O,setScanStartTime:Y,onScanStart:o,onCaptureComplete:c,onCustomScanSuccess:h,onComplete:x,swan:L},children:e.jsx(T,{})})})})})})};
|
|
2
|
-
//# sourceMappingURL=BodyScan-Cyfo46EK.js.map
|