@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.
Files changed (169) hide show
  1. package/dist/BodyScan-CCRXkFFL.mjs +3 -0
  2. package/dist/BodyScan-CCRXkFFL.mjs.map +1 -0
  3. package/dist/BodyScan-RBxSYdGc.js +3 -0
  4. package/dist/BodyScan-RBxSYdGc.js.map +1 -0
  5. package/dist/FaceScan-DQvhrp3K.mjs +3 -0
  6. package/dist/FaceScan-DQvhrp3K.mjs.map +1 -0
  7. package/dist/{FaceScan-BRdpV_Yn.js → FaceScan-Dva9De8x.js} +3 -2
  8. package/dist/{FaceScan-BRdpV_Yn.js.map → FaceScan-Dva9De8x.js.map} +1 -1
  9. package/dist/{Modal-BPtRtRVC.js → Modal-CZgyeNwW.mjs} +3 -2
  10. package/dist/Modal-CZgyeNwW.mjs.map +1 -0
  11. package/dist/{Modal-HTYYx7sM.js → Modal-CmbYIXgn.js} +3 -2
  12. package/dist/{Modal-YZScjwEm.js.map → Modal-CmbYIXgn.js.map} +1 -1
  13. package/dist/bodyScan.d.ts +2 -2
  14. package/dist/bodyScan.js +2 -1
  15. package/dist/bodyScan.mjs +2 -1
  16. package/dist/faceScan.js +2 -1
  17. package/dist/faceScan.mjs +2 -1
  18. package/dist/index.css +1 -1
  19. package/dist/index.js +2 -1
  20. package/dist/index.js.map +1 -1
  21. package/dist/index.mjs +2 -1
  22. package/dist/index.mjs.map +1 -1
  23. package/dist/{pose-detection.esm-Bc8T4UAD.js → pose-detection.esm-DFB9u8DH.js} +2 -1
  24. package/dist/{pose-detection.esm-Bc8T4UAD.js.map → pose-detection.esm-DFB9u8DH.js.map} +1 -1
  25. package/dist/{pose-detection.esm-DC0_P6R7.js → pose-detection.esm-EvS-BndH.mjs} +2 -1
  26. package/dist/pose-detection.esm-EvS-BndH.mjs.map +1 -0
  27. package/package.json +3 -2
  28. package/dist/BodyScan-3YoMZG7n.js +0 -2
  29. package/dist/BodyScan-8qgqyl5-.js +0 -2
  30. package/dist/BodyScan-B0qqqK3C.js +0 -2
  31. package/dist/BodyScan-B1VBoA6S.js +0 -2
  32. package/dist/BodyScan-B1afPG1Q.js +0 -2
  33. package/dist/BodyScan-B1afPG1Q.js.map +0 -1
  34. package/dist/BodyScan-B4-sO3R2.js +0 -2
  35. package/dist/BodyScan-B87W6dpH.js +0 -2
  36. package/dist/BodyScan-B8pglBAp.js +0 -2
  37. package/dist/BodyScan-BEFwluXG.js +0 -2
  38. package/dist/BodyScan-BHgnqB6A.js +0 -2
  39. package/dist/BodyScan-BLvWlYnA.js +0 -2
  40. package/dist/BodyScan-BMAkl5Iw.js +0 -2
  41. package/dist/BodyScan-BMTK6e-E.js +0 -2
  42. package/dist/BodyScan-BQri8pAO.js +0 -2
  43. package/dist/BodyScan-BVNPC7bJ.js +0 -2
  44. package/dist/BodyScan-BfLKF5PU.js +0 -2
  45. package/dist/BodyScan-BjYHCskz.js +0 -2
  46. package/dist/BodyScan-BoAbG01d.js +0 -2
  47. package/dist/BodyScan-Bq64fsmL.js +0 -2
  48. package/dist/BodyScan-Bre1BIHK.js +0 -2
  49. package/dist/BodyScan-BsDJmy0G.js +0 -2
  50. package/dist/BodyScan-ByMGumuH.js +0 -2
  51. package/dist/BodyScan-C0V-EDdB.js +0 -2
  52. package/dist/BodyScan-C1dWJ2qu.js +0 -2
  53. package/dist/BodyScan-C43x2o2T.js +0 -2
  54. package/dist/BodyScan-C57PuQgF.js +0 -2
  55. package/dist/BodyScan-C9hQU-dK.js +0 -2
  56. package/dist/BodyScan-CA4rNyqL.js +0 -2
  57. package/dist/BodyScan-CH-_x55M.js +0 -2
  58. package/dist/BodyScan-CKH_WyTt.js +0 -2
  59. package/dist/BodyScan-CKmPcrkx.js +0 -2
  60. package/dist/BodyScan-CLpL3Uwx.js +0 -2
  61. package/dist/BodyScan-CM12T_-T.js +0 -2
  62. package/dist/BodyScan-CNhb6UOX.js +0 -2
  63. package/dist/BodyScan-CWsaPB8W.js +0 -2
  64. package/dist/BodyScan-CXwtxfOd.js +0 -2
  65. package/dist/BodyScan-CYn7eLoz.js +0 -2
  66. package/dist/BodyScan-CYnHFqsR.js +0 -2
  67. package/dist/BodyScan-CZTiQzpy.js +0 -2
  68. package/dist/BodyScan-Cc68SnU1.js +0 -2
  69. package/dist/BodyScan-CfS4bPCN.js +0 -2
  70. package/dist/BodyScan-CiG19l_n.js +0 -2
  71. package/dist/BodyScan-CjvyMLT9.js +0 -2
  72. package/dist/BodyScan-CkmrPAq9.js +0 -2
  73. package/dist/BodyScan-CoObDhac.js +0 -2
  74. package/dist/BodyScan-Cyfo46EK.js +0 -2
  75. package/dist/BodyScan-Cz9ggKm6.js +0 -2
  76. package/dist/BodyScan-D6Y_W5e2.js +0 -2
  77. package/dist/BodyScan-DCEgmVbG.js +0 -2
  78. package/dist/BodyScan-DEDdENv7.js +0 -2
  79. package/dist/BodyScan-DEdrK-ld.js +0 -2
  80. package/dist/BodyScan-DHMf2V5R.js +0 -2
  81. package/dist/BodyScan-DK9UmNBr.js +0 -2
  82. package/dist/BodyScan-DPCd26i-.js +0 -2
  83. package/dist/BodyScan-DPCd26i-.js.map +0 -1
  84. package/dist/BodyScan-DPSQ1hKh.js +0 -2
  85. package/dist/BodyScan-DVKnmJuJ.js +0 -2
  86. package/dist/BodyScan-DX_KbG5U.js +0 -2
  87. package/dist/BodyScan-DbfP9-G3.js +0 -2
  88. package/dist/BodyScan-DeBJWo0L.js +0 -2
  89. package/dist/BodyScan-DgZpiChn.js +0 -2
  90. package/dist/BodyScan-DkPwUgVu.js +0 -2
  91. package/dist/BodyScan-DntA0MBx.js +0 -2
  92. package/dist/BodyScan-DxidLEhk.js +0 -2
  93. package/dist/BodyScan-DyDxGqfI.js +0 -2
  94. package/dist/BodyScan-Dysj7b77.js +0 -2
  95. package/dist/BodyScan-DzyamZmb.js +0 -2
  96. package/dist/BodyScan-Ehsr_cYc.js +0 -2
  97. package/dist/BodyScan-MSB66I12.js +0 -2
  98. package/dist/BodyScan-Ot6nAH1j.js +0 -2
  99. package/dist/BodyScan-Srq29PK8.js +0 -2
  100. package/dist/BodyScan-SzaquTgH.js +0 -2
  101. package/dist/BodyScan-TPpfyief.js +0 -2
  102. package/dist/BodyScan-XW2vsiE3.js +0 -2
  103. package/dist/BodyScan-eUuIC3jY.js +0 -2
  104. package/dist/BodyScan-enDyqSjO.js +0 -2
  105. package/dist/BodyScan-iOXndWaO.js +0 -2
  106. package/dist/BodyScan-qVHOWabf.js +0 -2
  107. package/dist/BodyScan-t9qdQAL-.js +0 -2
  108. package/dist/BodyScan-twE2YOwy.js +0 -2
  109. package/dist/BodyScan-z6h5fueJ.js +0 -2
  110. package/dist/FaceScan-3rVSqkKB.js +0 -2
  111. package/dist/FaceScan-6Aoz5uUy.js +0 -2
  112. package/dist/FaceScan-7fl5pLnb.js +0 -2
  113. package/dist/FaceScan-9kUfXRSv.js +0 -2
  114. package/dist/FaceScan-AHZ-ajep.js +0 -2
  115. package/dist/FaceScan-B0pFv4Us.js +0 -2
  116. package/dist/FaceScan-BE0PB0fZ.js +0 -2
  117. package/dist/FaceScan-BWSeJEqI.js +0 -2
  118. package/dist/FaceScan-BdjT7nMG.js +0 -2
  119. package/dist/FaceScan-Bji5lGcQ.js +0 -2
  120. package/dist/FaceScan-Bji5lGcQ.js.map +0 -1
  121. package/dist/FaceScan-BmDNM8tt.js +0 -2
  122. package/dist/FaceScan-CNoW9DIE.js +0 -2
  123. package/dist/FaceScan-CPf6-siO.js +0 -2
  124. package/dist/FaceScan-CQayY4q-.js +0 -2
  125. package/dist/FaceScan-CQkfSMC2.js +0 -2
  126. package/dist/FaceScan-CaxQ6fGF.js +0 -2
  127. package/dist/FaceScan-CxDcvM4f.js +0 -2
  128. package/dist/FaceScan-D2PL8KpZ.js +0 -2
  129. package/dist/FaceScan-D3T_l4nN.js +0 -2
  130. package/dist/FaceScan-DCm43Nrq.js +0 -2
  131. package/dist/FaceScan-DKP93c3l.js +0 -2
  132. package/dist/FaceScan-DW6Ix1a1.js +0 -2
  133. package/dist/FaceScan-DYJVZoZ4.js +0 -2
  134. package/dist/FaceScan-Da2XEApH.js +0 -2
  135. package/dist/FaceScan-DrW2yUSA.js +0 -2
  136. package/dist/FaceScan-DxnydFcx.js +0 -2
  137. package/dist/FaceScan-Gm4F4cO1.js +0 -2
  138. package/dist/FaceScan-Nhc7myLG.js +0 -2
  139. package/dist/FaceScan-VFLJ9h_T.js +0 -2
  140. package/dist/FaceScan-iUXyDuza.js +0 -2
  141. package/dist/LoadingScreen-BILrJVZm.js +0 -2
  142. package/dist/LoadingScreen-FKDLJRUj.js +0 -2
  143. package/dist/Modal-4T_aWWPQ.js +0 -2
  144. package/dist/Modal-BHfJVhRi.js +0 -2
  145. package/dist/Modal-BitizIvu.js +0 -2
  146. package/dist/Modal-BpgpPVxR.js +0 -2
  147. package/dist/Modal-BzH-_ch3.js +0 -2
  148. package/dist/Modal-CB_MHF7l.js +0 -2
  149. package/dist/Modal-CDiBoVXR.js +0 -2
  150. package/dist/Modal-CWoUZTh4.js +0 -2
  151. package/dist/Modal-CaPtqgjI.js +0 -2
  152. package/dist/Modal-CbZJwbLZ.js +0 -2
  153. package/dist/Modal-DRjJKUrw.js +0 -2
  154. package/dist/Modal-DU2Jymve.js +0 -2
  155. package/dist/Modal-D_XGokez.js +0 -2
  156. package/dist/Modal-DnweWp6L.js +0 -2
  157. package/dist/Modal-Do--CErH.js +0 -2
  158. package/dist/Modal-Do--CErH.js.map +0 -1
  159. package/dist/Modal-YZScjwEm.js +0 -2
  160. package/dist/fonts/Switzer-Regular.eot +0 -0
  161. package/dist/fonts/Switzer-Regular.svg +0 -0
  162. package/dist/fonts/Switzer-Regular.ttf +0 -0
  163. package/dist/fonts/Switzer-Regular.woff +0 -0
  164. package/dist/fonts/Switzer-Regular.woff2 +0 -0
  165. package/dist/interfaces-B5ysRXpa.d.ts +0 -209
  166. package/dist/interfaces-CaaERZjZ.d.ts +0 -209
  167. package/dist/pose-detection.esm-D08ZA0zl.js +0 -18
  168. package/dist/pose-detection.esm-DejsYGYM.js +0 -18
  169. 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 f,b as h,S as g,z as y,a as v,i as w,P as S,o as b,s as x,j as N,k as C,l as D,p as I,A as $,x as k,B as E,q as T,f as F,r as L,D as _,c as M,M as P,v as A,E as U,I as j,V as z,J as R,K as V,N as K,G as B,O as q,Q as O,R as W,h as H,n as G,w as J,T as Y,t as Q,C as X,y as Z}from"./Modal-D_XGokez.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`,[]),S=s((e=!1)=>{const t=y();return r?`text-[${g?.style?.angleDetector?.successAngleTextLightColor}]`:w(e,t)},[r,y]),b=s((e,t)=>t>70||e?g?.style?.angleDetector?.successAngleTextLightColor:g?.style?.angleDetector?.successAngleTextDarkColor,[]),x=s((e=!1)=>{const t=y();return r?g?.style?.angleDetector?.successAngleTextLightColor:b(e,t)},[r,y]),N=a;function C(){document.documentElement.style.setProperty("--real-vh",window.innerHeight+"px")}return C(),window.addEventListener("resize",C),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(f,{noTitle:!0})})}),null!==N?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 ${x()}`},children:e("div",{className:`text-[3rem] font-bold text-[${x()}]`,style:{fontFamily:g?.style?.base?.baseFontFamily||"Inter, sans-serif",color:x()},children:N})}):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 ${x()}`},children:[e("div",{className:`h-[1rem] w-[1rem] rounded-[9999px] bg-[${x()}]/80`,style:{backgroundColor:`${x()}B3`}}),t("div",{className:ee("mt-[.5rem] text-center w-[180px] flex-col flex items-center absolute top-[60px]",S()),style:{color:x()},children:[e(me,{size:30}),t("p",{style:{fontFamily:g?.style?.base?.baseFontFamily||"Inter, sans-serif"},children:[" ",u?.(h.startLevelCheck),e("br",{})]})]})]}),null!==N&&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",S()),style:{fontFamily:g?.style?.base?.baseFontFamily||"Inter, sans-serif",color:x()},children:u?.(h.leavePhone)})}),o&&null===N&&!r&&e("div",{className:"absolute bottom-[8rem] w-[12rem]",children:e("div",{className:`h-[.375rem] w-full bg-[${x()}]/20 rounded-[9999px] overflow-hidden`,style:{backgroundColor:`${x()}33`},children:e("div",{className:`h-full bg-[${x()}]/70 transition-all duration-300 rounded-[9999px]`,style:{width:`${n}%`,backgroundColor:`${x()}B3`}})})}),null===N&&!r&&e("div",{className:"absolute bottom-[5rem] text-center",children:t("div",{className:ee("text-[1.5rem] font-light",S()),style:{color:x()},children:[Math.round(n),"°"]})}),null===N&&!r&&e("div",{className:"absolute bottom-[2rem] text-center max-w-[20rem] mx-auto",children:e("div",{className:ee("text-[.75rem] opacity-50",S()),style:{fontFamily:g?.style?.base?.baseFontFamily||"Inter, sans-serif",color:x()},children:u?.(h.placePhoneUpright)})})]})});function fe({resetScan:n,loadingCam:a,onUserMedia:r,onPause:s,pause:o,onReScan:i,recordingStarted:c,startSendingVideoFrames:l,showPause:u,webcamRef:p,onUserMediaError:f,resetDetector:w,videoConstraints:S,webcamKey:b,faceDone:x,isScanning:N}){const{media:C}=d(de)||{},{translate:D}=d(m)||{};return t("div",{className:"App w-screen h-[100vh] relative common-ui-main","data-testid":"camera-scan","data-scan-phase":x?"spinning":c?"pose-detecting":N?"starting":"ready",children:[e("span",{onClick:()=>{n(),w()},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:p,screenshotQuality:1,videoConstraints:S,mirrored:!0,screenshotFormat:"image/jpeg",onUserMedia:r,onUserMediaError:f,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:[u&&e(g,{className:"!w-[180px] !h-[40px] !py-[0] mx-auto ",prefix:y,buttonText:D?.(h.pause),buttonFunc:s,btnSecondary:!0}),o?e("div",{children:e(g,{className:"!w-[180px] !h-[40px] !py-[0] mx-auto",buttonText:D?.(h.restart),buttonFunc:i,btnSecondary:!0})}):c?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:D?.(h.startScan),buttonFunc:l,disabled:a})]}),e("audio",{id:"audioElement",crossOrigin:"anonymous",preload:"auto",style:{position:"absolute",zIndex:-99999},src:`${v}scanAudioInstructions/silence.mp3`})]})}let he=null,ge=null,ye=null;let ve,we=null,Se=null;var be=a.memo(function({setIsScanLocked:t,resetDetector:n,scanID:a,setIsVideoUploaded:i,setScanFailsError:c,setScanStartTime:m,setScanUniqueKey:p,userDetails:f}){const{gender:h,heightInCm:g,email:y,shopDomain:_}=f,M=u(null),P=u(null),A=u(null),[U,j]=r([]),[z,R]=r(!0),[V,K]=r(!1),[B,q]=r(!1),[O,W]=r(!0),[H,G]=r(!1),J=u(null),[Y,Q]=r(""),[X,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),he=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 he||(he=m()),he.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||he||(he=m(),await he&&d.current&&i(!0))}}}(),be=u(!0),xe=u(!1),Ne=u(0),Ce=u(0),De=u(!1),Ie=u(!1),$e=u(!1),ke=u(()=>{}),Ee=u(()=>{}),[Te,Fe]=r([]),[Le,_e]=r(0),[Me,Pe]=r(w),{setStartGyro:Ae,uploadScanFile:Ue,setUploadLoading:je,swan:ze,onScanStart:Re,onCaptureComplete:Ve}=d(S),Ke=()=>{xe.current=!1,clearTimeout(ve),J.current&&clearTimeout(J.current),p(F()),c(""),je?.(!1),j([]),A.current=null,R(!0),K(!1),q(!1),W(!0),G(!1),J.current=null,Q(""),Z([]),te(""),ae(!ne),Ae(!1),x.stopAudio(),se(!1),ie(!1),Ne.current=0,Ce.current=0,De.current=!1,$e.current=!1,null!==P.current&&P.current.stop(),ce.forEach(e=>{P.current&&P.current.removeEventListener("dataavailable",e)}),le([]),me.current=!0,ue(!1),i(!1),M.current?.stream&&R(!1)},Be=s(()=>{setTimeout(()=>{R(!1)},1e3)},[]),qe=s(e=>{if(console.log("camera error",e),Me===w)return Pe(b),void _e(e=>e+1);R(!1)},[Me]),Oe=s(()=>{me.current=!1,ie(!0),ue(!1),J.current&&clearTimeout(J.current),P.current&&P.current.pause(),x.stopAudio(),ze.poseDetection.disconnect(),Ne.current=0,Ce.current=0,De.current=!1,$e.current=!1,P.current&&P.current.stop(),ce.forEach(e=>{P.current&&P.current.removeEventListener("dataavailable",e)}),le([]),clearTimeout(ve)},[P,ce,x,me]),We=l(()=>N(),[]),He=C(Te),Ge=D(He),Je=s(async()=>{me.current=!0,await x.playAudio(`${v}SpotOn.mp3`),ie(!1),ue(!1),J.current&&clearTimeout(J.current),K(!1)},[J,x]),Ye=s(async()=>{if(!Ie.current&&!we){Ie.current=!0;try{we=await ze.poseDetection.connect(),I.capture(`${_}/pose_detection_connected`,{scanID:a,email:y,id:we})}catch(e){console.log(e,"while connecting websocket")}finally{Ie.current=!1}}},[a,_,y]),Qe=s(async()=>{$({eventName:`${_}/rescan`,email:y,scanID:a,height:g,gender:h,status:!1}),me.current=!1,ze.poseDetection.disconnect(),we=null,Ke(),await Ye(),Ee.current()},[Ye,a,y]),Xe=s(({data:e})=>{e&&e.size>0&&me.current&&(j(t=>t.concat(e)),!xe.current&&M.current&&(xe.current=!0,pe(()=>{Je(),k({eventName:`${_}/tensorFlow`,scanID:a,email:y,message:"recording stopped by tensorflow "})},M)))},[Je,k,_,a,y,M]),Ze=s(async()=>{const e=X[X.length-1];e&&me.current&&(await x.playAudio(v+e),me.current&&(ve=setTimeout(Ze,2e3)))},[X,me]),et=s(()=>{P&&P.current&&P.current.stop(),K(!0);try{if(M&&M.current&&M.current.stream){const e=M.current.stream.getVideoTracks()[0];if(e){const t=e.getSettings();A.current=t.frameRate||null}const t={videoBitsPerSecond:15e5};Te[0]&&(t.mimeType=Te[0]),P.current=new MediaRecorder(M.current.stream,t),P.current.addEventListener("dataavailable",Xe),P.current.addEventListener("stop",()=>{W(!0)}),le([...ce,Xe]),P.current.start(1e3),W(!1)}}catch(e){console.log("error while using media recorder",e)}},[M,Te,Xe,ce]),tt=s(async()=>{J.current&&clearTimeout(J.current),et(),me.current&&(J.current=setTimeout(async()=>{me.current&&(await x.playAudio(`${v}SpotOn.mp3`),K(!1))},15e3)),q(!0),me.current&&await x.playAudio(`${v}Spin.mp3`)},[et,me,x]);o(()=>{ke.current=tt},[tt]);const nt="undefined"!=typeof window?window.__scanLog??[]:[],at=e=>{const t=`[${(new Date).toISOString().slice(11,23)}] [SCAN] ${e}`;console.log(t),nt.push(t)},rt=s(({data:e})=>{const t=ze.poseDetection.connected();e.size>0&&t?(De.current||(De.current=!0,at(`poseStatus listener REGISTERED | id=${we}`),ze.poseDetection.poseStatus(async e=>{if(e&&e.audio&&e.audio.length>0){const t=document.querySelector("#audioElement"),n=e.audio?.split("/").pop(),r=t?.paused,s=t?.src?.split("/").pop()||"empty";at(`poseStatus RECEIVED | status=${e.status} | file=${n} | sid=${e.sid} | id=${we} | sidMatch=${e.sid===we} | counter=${Ne.current} | consecFalse=${Ce.current} | audioPaused=${r} | audioSrc=${s} | audioEl=${t?"found":"NULL"} | lastPlayed=${Se?.audioName?.split("/").pop()??"none"} | skipped=${Se?.no_of_times_skipped??"-"}/${Se?.skipCount??"-"}`),I.capture(`${_}/pose_instruction_received`,{scanID:a,email:y,audio:e.audio,status:e.status,sid:e.sid,counter:Ne.current,consecutiveFalse:Ce.current,type:"body_scan_instruction"}),!0===e.status&&e.sid===we?(Ce.current=0,Ne.current<2?(Ne.current+=1,1!==Ne.current||$e.current?2===Ne.current&&t?.paused?(at(`PLAY good-posture-2 | file=${n}`),x.playAudio(v+e.audio)):2!==Ne.current||t?.paused?at(`SKIP good-posture-1 — brilliantPlayed already | counter=${Ne.current}`):at(`SKIP good-posture-2 — audio still playing | file=${n}`):(at(`PLAY good-posture-1 (brilliant) | file=${n}`),$e.current=!0,x.stopAudio(),await x.playAudio(v+e.audio))):(at(`TRIGGER SPIN | counter=${Ne.current} | file=${n}`),te(e.audio),clearTimeout(ve),ze.poseDetection.disconnect(),De.current=!1,setTimeout(()=>ke.current(),1e3))):!0===e.status&&e.sid!==we?at(`SKIP good-posture — sid MISMATCH | data.sid=${e.sid} | id=${we}`):(Ce.current+=1,Ce.current>=3&&(Ne.current=0,$e.current=!1,at(`RESET counter/brilliant — consecutiveFalse=${Ce.current}`)),!t?.paused||Se&&Se?.audioName===e.audio?t?.paused||Se&&Se?.audioName===e.audio?Se?.audioName===e.audio&&t?.paused?Se&&Se.no_of_times_skipped>=Se.skipCount?(Se.no_of_times_skipped=0,at(`PLAY wrong-posture REPEAT | file=${n}`),x.playAudio(v+e.audio)):(Se&&(Se.no_of_times_skipped+=1),at(`SKIP wrong-posture SAME — skip ${Se?.no_of_times_skipped}/${Se?.skipCount} | file=${n}`)):Se?.audioName!==e.audio||t?.paused||at(`SKIP wrong-posture SAME — audio still playing | file=${n}`):at(`SKIP wrong-posture NEW — audio playing | file=${n}`):(at(`PLAY wrong-posture NEW | file=${n}`),Se={skipCount:2,no_of_times_skipped:0,audioName:e.audio},x.playAudio(v+e.audio)))}})),M?.current&&null!==M.current.getScreenshot()&&ze.poseDetection.videoEmit({image:M.current.getScreenshot()||"",scanId:a})):e.size>0&&!t&&at(`handleDataAvailable — WS DISCONNECTED | id=${we} | poseListenerRegistered=${De.current}`)},[M,a,ze,we,x,_,y]),st=s(async()=>{G(!0),Ae(!0),Re?.(),be.current&&(be.current=!1,k({eventName:"scan started",scanID:a,status:"success",email:y})),m(E()),R(!0),me.current&&await x.playAudio(`${v}StartScan.mp3`),me.current&&await x.playAudio(`${v}LiftArmsAndHoldAtHip.mp3`),me.current&&(G(!1),K(!0),se(!0),ue(!0),Be());try{if(M&&M.current&&M.current.stream&&me.current){const e=M.current.stream.getVideoTracks()[0];if(e){const t=e.getSettings();A.current=t.frameRate||null}const t={videoBitsPerSecond:15e5};Te[0]&&(t.mimeType=Te[0]),me.current&&(P.current=new MediaRecorder(M.current.stream,t)),me.current&&P.current&&P.current.addEventListener("dataavailable",rt),le([...ce,rt]),P.current&&P.current.start(1e3),W(!1),me.current&&(ve=setTimeout(Ze,2e3))}}catch(e){console.log("error ----------",e)}},[M,Te,rt,ce,Ze,me,Re]);return o(()=>(_&&(t(!0),Ye()),()=>{const e=we;we=null,e&&(ze.poseDetection.disconnect(),I.capture(`${_}/pose_detection_disconnected`,{scanID:a,email:y,id:e})),ce.forEach(e=>{P?.current?.removeEventListener("dataavailable",e)})}),[_]),o(()=>{X.push(Y)},[Y]),o(()=>{Z([])},[ee]),o(()=>{const e=U.length&&U.length>0;O||!e||V||!me.current||oe||P&&P.current&&(V||P.current.stop())},[O,V,U,oe]),o(()=>{const e=U.length&&U.length>0;if(O&&e&&!V&&P&&P.current&&me.current&&!oe&&!V){const e=new File(U,`${a}.${Ge}`,{type:He});Ve?.(),je?.(!0),c(""),Ue?.(e,A.current)}},[O,V,U,oe,P,me]),o(()=>{Ee.current=st},[st]),o(()=>{const e=T(We,L);Fe(e)},[We]),o(()=>{Ke()},[]),e(fe,{resetDetector:n,resetScan:Ke,loadingCam:z,onPause:Oe,showRestart:re,pause:oe,onReScan:Qe,recordingStarted:V,isScanning:H,startSendingVideoFrames:st,faceDone:B,stopRecording:Je,showPause:de,webcamRef:M,onUserMedia:Be,onUserMediaError:qe,videoConstraints:Me,webcamKey:Le})});function xe({scanID:a,userDetails:s,setIsVideoUploaded:i,setScanFailsError:c,setScanStartTime:l,setScanUniqueKey:d}){const[m,p]=r(90),[f,h]=r(0),[g,y]=r(null),[v,w]=r(!1),[S,b]=r(0),x=u([]),[N,C]=r(!1),D=m-f,I=D>=80&&D<=95;o(()=>{if("undefined"!=typeof window&&window.DeviceOrientationEvent){const e=e=>{if(null!==e.beta){let t=Math.abs(e.beta);null!==e.gamma&&(t*=Math.cos(e.gamma*Math.PI/180)),t=Math.max(0,Math.min(180,t)),p(t)}},t=async()=>{const t=DeviceOrientationEvent;if(t&&"function"==typeof t.requestPermission)try{"granted"===await t.requestPermission()&&window.addEventListener("deviceorientation",e)}catch(e){console.error("Permission error",e)}else window.addEventListener("deviceorientation",e);return()=>{e&&window.removeEventListener("deviceorientation",e)}};document.addEventListener("click",t,{once:!0})}},[]),o(()=>{if(x.current=[...x.current.slice(-4),D],x.current.length>=5){const e=Math.max(...x.current)-Math.min(...x.current);b(I&&e<2?e=>Math.min(100,e+10):e=>Math.max(0,e-20))}I||null===g&&!v||k()},[D,I,g,v]),o(()=>{S>=100&&null===g&&!v&&$(),S<50&&null!==g&&k()},[S,g,v]);const $=()=>{y(3);const e=setInterval(()=>{y(t=>null===t||t<=1?(clearInterval(e),w(!0),null):t-1)},1e3)},k=()=>{y(null),N||w(!1)};return t(n,{children:[!v&&e(pe,{angle:D,countdown:g,isScanning:v,isInTargetRange:I,stabilityScore:S}),v&&e(be,{setIsScanLocked:C,resetDetector:()=>{p(90),h(0),y(null),w(!1),b(0),C(!1),x.current=[]},scanID:a,userDetails:s,setIsVideoUploaded:i,setScanFailsError:c,setScanStartTime:l,setScanUniqueKey:d})]})}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(M,{url:a,loaderType:"black"}):i?.disabled?e(P,{config:n,message:i?.message}):e(te,{audio:!1,ref:m,screenshotQuality:1,videoConstraints:A,mirrored:!0,onUserMedia:()=>t?.(!0),screenshotFormat:"image/jpeg",style:{position:"relative",top:0,bottom:0,zIndex:0,width:"100%",height:"100%",objectFit:"cover"}})}function Ce({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:U};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 De({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(f,{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?.(h.issueWithScan)}),e("p",{style:{fontFamily:u?.style?.base?.baseFontFamily||"Inter, sans-serif",fontSize:u?.style?.base?.baseFontSize||"16px",color:u?.style?.base?.baseTextColor||"#1E1E1E"},children:l?.(h.reason)}),e("p",{style:{fontFamily:u?.style?.base?.baseFontFamily||"Inter, sans-serif",fontSize:u?.style?.base?.baseFontSize||"16px",color:u?.style?.base?.baseTextColor||"#1E1E1E"},children:j(a)}),e("img",{className:"my-[0.5rem] aspect-[2/1.4] w-full object-cover",onClick:w,src:z[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?.(h.scanAgain),className:"!shadow-none",buttonFunc:()=>{s?s?.():i?.(F()),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(Ce,{link:o?R[o].PRE_LINK:R.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:S,heightInCm:b,deviceFocalLength:x,userName:N,email:C,scanType:D}=a||{},$=[q,O,W].includes(D??""),[k,E]=r(!0),T=s(async()=>{try{$&&(await(v?.auth.addUser({scanId:n,email:C,name:N,gender:w,height:b})),y?.()),I.capture(S??"",{scanID:n,email:C,height:b,focalLength:x,clothesFit:"0",gender:w})}catch(e){console.log(e)}},[$]),{translate:F}=d(m)||{};o(()=>{(c||l)&&T()},[c,l]);const L=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:E}),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(f,{title:F?.(h.measurementsBeingTaken)}),e("div",{className:"flex items-center justify-center flex-1",children:e("video",{preload:"auto",className:"max-h-[calc(100vh-450px)] mx-auto w-full object-contain border-none",muted:!0,loop:!0,autoPlay:!0,playsInline:!0,children:e("source",{src:w===B.Male?V:K,type:"video/mp4"})})}),L&&e(g,{className:"!w-[180px] mx-auto",buttonText:F?.(h.next),buttonFunc:()=>{u?.()}})]})})})]})})}const $e=()=>{const{userDetails:n,onRetry:a,isError:r,isSuccess:s,gender:o,scanUniqueKey:i,scanFailsError:c,setScanUniqueKey:l,setIsVideoUploaded:u,isMeasurementAvailable:m,isVideoUploadedCorrect:f,loading:h,showDeniedModal:g,uploadLoading:y,setScanFailsError:v,setScanStartTime:w,resetScan:b,onCustomScanSuccess:x,swan:N,onComplete:C}=d(S),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(De,{scanFailsError:!0,onNext:a,gender:o})})]}):s?e("div",{"data-scan-state":"success",children:e(Ie,{isSuccess:!0,onComplete:C})}):h?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(M,{url:D?.loader,loaderType:"black"})}):g.disabled?e("div",{"data-scan-state":"camera-denied",children:e(P,{})}):y||c||m||f?(y||m||f)&&!c?e("div",{"data-scan-state":"processing",children:e(Ie,{scanId:i,isMeasurementAvailable:m,userDetails:n,isVideoUploadedCorrect:f,onCustomScanSuccess:x,swan:N,onComplete:C})}):t("div",{"data-scan-state":"error-retry",children:[e(Ne,{}),e(se,{anchor:"bottom",open:!0,className:"camera-drawer",onClose:(e,t)=>{},children:e(De,{scanFailsError:c,onNext:()=>{a?.(),b()},setScanUniqueKey:l,gender:o,setIsVideoUploaded:u})})]}):e("div",{"data-scan-state":"scanning",children:e(xe,{scanID:i,userDetails:n,setIsVideoUploaded:u,setScanFailsError:v,setScanStartTime:w,setScanUniqueKey:l})})},ke=t=>{const{config:n,onRetry:a,onScanStart:i,onCaptureComplete:c,onUploadStart:d,onUploadEnd:u,onMeasurementSocketStart:m,onMeasurementSocketClose:p,onIntermediateScanSuccess:f,onScanError:h,onScanSuccess:g,onCustomScanSuccess:y,onComplete:v,isError:w,isSuccess:b}=t,x={email:"",shopDomain:"",gender:"male",heightInCm:0,scanType:"",deviceFocalLength:0,deviceModelName:"",sourceTag:"",callbackUrl:null,...t.userDetails??{}},N=t.token??"",{gender:C,scanType:D,shopDomain:I,heightInCm:$,email:T,deviceFocalLength:L,deviceModelName:M,callbackUrl:P,sourceTag:A}=x,U=l(()=>H(N),[N]),[z,R]=r(!1),[V,K]=r(!1),[B,q]=r(!1),[O,W]=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(E()),{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);G();const fe=s(()=>{le(F()),te(""),R(!1),ae(!1)},[]),he=()=>{me(null),le("")},ge=s(async e=>{if(e&&"success"===e?.scanStatus&&"intermediate"===e?.resultType&&200===e?.code)return k({eventName:`${I}/measurement_success/intermediate`,scanID:ce,status:"success",email:T}),K(!0),void f?.(e);g?.(e),K(!0),he();const t=ce;q(!0),k({eventName:`${I}/measurement_success/fit-view`,scanID:t,status:"success",email:T}),de&&k({eventName:`${I}/scan_completion_time`,scanID:t,status:"success",completionTime:E()-de,email:T})},[D,I,ce]),ye=e=>{q(!1),te(""),K(!1),U.measurement.handleMeasurementSocket({scanId:ce,onPreopen:()=>{Z({eventName:`${I}/webSocket`,scanID:ce,connection:"pre_open",type:"measurement_recommendation",email:T})},onOpen:()=>{m?.(),Z({eventName:`${I}/webSocket`,scanID:ce,connection:"open",type:"measurement_recommendation",email:T})},onClose:()=>{p?.(),Z({eventName:`${I}/webSocket`,scanID:ce,connection:"close",type:"measurement_recommendation",email:T})},onError:e=>{var t;t=e,h?.({...t,message:j(t)}),he(),q(!1),te(t),K(!1),k({eventName:`${I}/measurement_failed/fit-view`,scanID:ce,status:"failed",email:T,message:j(t)}),de&&k({eventName:`${I}/scan_completion_time`,scanID:ce,status:"failed",completionTime:E()-de,email:T}),Z({eventName:`${I}/webSocket`,scanID:ce,connection:"error",type:"measurement_recommendation",email:T})},onSuccess:e=>{Z({eventName:`${I}/webSocket`,scanID:ce,connection:"success",type:"measurement_recommendation",email:T}),ge(e)}})},ve=s(async(e,t)=>{const n=Number((e.size/1048576).toFixed(2)),a=null!=t?t:await J(e),r=Y({gender:C,focal_length:`${L}`,height:`${$}`,customer_store_url:I,clothes_fit:"0",scan_type:D,callback_url:P,source_tag:A});k({eventName:`${I}/body_scan_meta_data`,scanID:ce,email:T,data:JSON.stringify([...r,{fileSizeInMB:n,video_fps:a||0}])}),d?.();try{await U.fileUpload.uploadFileFrontend({file:e,arrayMetaData:r,scanId:ce,email:T}),await U.fileUpload.setDeviceInfo({model:M,detection:"manual",gyro:pe,scanId:ce}),console.log("video successfully uploaded"),ae(!1),k({eventName:`${I}/scan_success`,scanID:ce,status:"success",email:T,data:JSON.stringify(r)}),k({eventName:"scan finished",scanID:ce,status:"success",email:T}),me(E()),setTimeout(()=>{ae(!0)},3e3)}catch(e){k({eventName:"scan finished",scanID:ce,status:"failed",email:T,message:j(e)}),k({eventName:`${I}/scan_failed`,scanID:ce,status:"failed",email:T,message:j(e),data:JSON.stringify(r)}),te(j(e)),ae(!1),h?.({...e,message:j(e)}),he()}finally{ie(!1),u?.()}},[ce,pe,d,u]),we=s(async()=>{if(+$<152.4||+$>213.36)return void h?.({message:"Height must be between 152.4cm (5ft) and 213.36cm (7ft)"});const e=await _();e.disabled?(k({eventName:`${I}/camera_activation`,scanID:ce,status:"failed",email:T}),se(!1)):(se(!1),k({eventName:`${I}/camera_activation`,scanID:ce,status:"success",email:T})),W(e),te(""),ae(!1)},[T,ce,le,I]);return o(()=>{w||b||I&&we()},[I,$,w,b]),o(()=>{w||b||ne&&I&&ce&&ye()},[ne,I,ce,w,b]),e("div",{"data-testid":"body-scan-root",children:e(Q,{children:e(X,{config:n,children:e(ue,{children:e(S.Provider,{value:{userDetails:x,onRetry:a,onScanError:h,isError:w,isSuccess:b,onScanSuccess:g,gender:C,scanUniqueKey:ce,scanFailsError:ee,setScanUniqueKey:le,setIsVideoUploaded:ae,isMeasurementAvailable:B,isVideoUploadedCorrect:V,loading:re,showDeniedModal:O,uploadLoading:z,setStartGyro:ie,uploadScanFile:ve,setUploadLoading:R,resetScan:fe,setScanFailsError:te,setScanStartTime:me,onScanStart:i,onCaptureComplete:c,onCustomScanSuccess:y,onComplete:v,swan:U},children:e($e,{})})})})})})};export{ke as B};
2
- //# sourceMappingURL=BodyScan-BsDJmy0G.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]),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,q]=t.useState(""),[B,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(()=>{}),ue=t.useRef(()=>{}),[de,me]=t.useState([]),[pe,fe]=t.useState(0),[he,ge]=t.useState(s.videoConstraintsExact),{setStartGyro:xe,uploadScanFile:ve,setUploadLoading:Se,swan:ye,onScanStart:Ce,onCaptureComplete:be}=t.useContext(s.ParamsContext),we=()=>{ne.current=!1,clearTimeout(S),R.current&&clearTimeout(R.current),l(s.generateUuid()),c(""),Se?.(!1),E([]),j.current=null,D(!0),I(!1),M(!1),_(!0),A(!1),R.current=null,U(""),z([]),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(),Q.forEach(e=>{w.current&&w.current.removeEventListener("dataavailable",e)}),X([]),ee.current=!0,Z(!1),o(!1),b.current?.stream&&D(!1)},je=t.useCallback(()=>{setTimeout(()=>{D(!1)},1e3)},[]),ke=t.useCallback(e=>{if(console.log("camera error",e),he===s.videoConstraintsExact)return ge(s.videoConstraintsFallback),void fe(e=>e+1);D(!1)},[he]),Ee=t.useCallback(()=>{ee.current=!1,J(!0),Z(!1),R.current&&clearTimeout(R.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(),Q.forEach(e=>{w.current&&w.current.removeEventListener("dataavailable",e)}),X([]),clearTimeout(S)},[w,Q,s.speechService,ee]),Ne=t.useMemo(()=>s.getPreferredMediaRecorderTypes(),[]),De=s.getRecordingMimeType(de),Te=s.getRecordingExtension(De),Ie=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]),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]),Me=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]),Fe=t.useCallback(({data:e})=>{e&&e.size>0&&ee.current&&(E(t=>t.concat(e)),!ne.current&&b.current&&(ne.current=!0,te(()=>{Ie(),s.handleScanTimeCapture({eventName:`${f}/tensorFlow`,scanID:r,email:p,message:"recording stopped by tensorflow "})},b)))},[Ie,s.handleScanTimeCapture,f,r,p,b]),_e=t.useCallback(async()=>{const e=O[O.length-1];e&&ee.current&&(await s.speechService.playAudio(s.voiceOverAssetsPath+e),ee.current&&(S=setTimeout(_e,2e3)))},[O,ee]),Pe=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};de[0]&&(t.mimeType=de[0]),w.current=new MediaRecorder(b.current.stream,t),w.current.addEventListener("dataavailable",Fe),w.current.addEventListener("stop",()=>{_(!0)}),X([...Q,Fe]),w.current.start(1e3),_(!1)}}catch(e){console.log("error while using media recorder",e)}},[b,de,Fe,Q]),Ae=t.useCallback(async()=>{R.current&&clearTimeout(R.current),Pe(),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`)},[Pe,ee,s.speechService]);t.useEffect(()=>{le.current=Ae},[Ae]);const Re=t.useCallback(({data:e})=>{const t=ye.poseDetection.connected();e.size>0&&t&&(oe.current||(oe.current=!0,ye.poseDetection.poseStatus(async e=>{if(e&&e.audio&&e.audio.length>0){const t=document.querySelector("#audioElement");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&&s.speechService.playAudio(s.voiceOverAssetsPath+e.audio):(ie.current=!0,s.speechService.stopAudio(),await s.speechService.playAudio(s.voiceOverAssetsPath+e.audio))):(q(e.audio),clearTimeout(S),ye.poseDetection.disconnect(),oe.current=!1,setTimeout(()=>le.current(),1e3))):(re.current+=1,re.current>=3&&(ae.current=0,ie.current=!1),!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,s.speechService.playAudio(s.voiceOverAssetsPath+e.audio)):C&&(C.no_of_times_skipped+=1)):(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}))},[b,r,ye,y,s.speechService,f,p]),$e=t.useCallback(async()=>{A(!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&&(A(!1),I(!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",Re),X([...Q,Re]),w.current&&w.current.start(1e3),_(!1),ee.current&&(S=setTimeout(_e,2e3))}}catch(e){console.log("error ----------",e)}},[b,de,Re,Q,_e,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})),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}.${Te}`,{type:De});be?.(),Se?.(!0),c(""),ve?.(e,j.current)}},[F,T,k,G,w,ee]),t.useEffect(()=>{ue.current=$e},[$e]),t.useEffect(()=>{const e=s.getSupportedMediaRecorderTypes(Ne,s.videoTypes);me(e)},[Ne]),t.useEffect(()=>{we()},[]),e.jsx(h,{resetDetector:a,resetScan:we,loadingCam:N,onPause:Ee,showRestart:W,pause:G,onReScan:Me,recordingStarted:T,isScanning:P,startSendingVideoFrames:$e,faceDone:L,stopRecording:Ie,showPause:Y,webcamRef:b,onUserMedia:je,onUserMediaError:ke,videoConstraints:he,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),[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(""),[q,B]=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),B(!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"),B(!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(()=>{B(!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)),B(!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(""),B(!1)},[E,J,Q,j]);return t.useEffect(()=>{v||S||j&&re()},[j,k,v,S]),t.useEffect(()=>{v||S||q&&j&&J&&ne()},[q,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:B,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-ByMGumuH.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]),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,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:[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,q]=t.useState(""),[B,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(()=>{}),ue=t.useRef(()=>{}),[de,me]=t.useState([]),[pe,fe]=t.useState(0),[he,ge]=t.useState(s.videoConstraintsExact),{setStartGyro:xe,uploadScanFile:ve,setUploadLoading:Se,swan:ye,onScanStart:Ce,onCaptureComplete:be}=t.useContext(s.ParamsContext),we=()=>{ne.current=!1,clearTimeout(S),R.current&&clearTimeout(R.current),l(s.generateUuid()),c(""),Se?.(!1),E([]),j.current=null,D(!0),I(!1),M(!1),_(!0),A(!1),R.current=null,U(""),z([]),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(),Q.forEach(e=>{w.current&&w.current.removeEventListener("dataavailable",e)}),X([]),ee.current=!0,Z(!1),o(!1),b.current?.stream&&D(!1)},je=t.useCallback(()=>{setTimeout(()=>{D(!1)},1e3)},[]),ke=t.useCallback(e=>{if(console.log("camera error",e),he===s.videoConstraintsExact)return ge(s.videoConstraintsFallback),void fe(e=>e+1);D(!1)},[he]),Ee=t.useCallback(()=>{ee.current=!1,J(!0),Z(!1),R.current&&clearTimeout(R.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(),Q.forEach(e=>{w.current&&w.current.removeEventListener("dataavailable",e)}),X([]),clearTimeout(S)},[w,Q,s.speechService,ee]),Ne=t.useMemo(()=>s.getPreferredMediaRecorderTypes(),[]),De=s.getRecordingMimeType(de),Te=s.getRecordingExtension(De),Ie=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]),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]),Me=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]),Fe=t.useCallback(({data:e})=>{e&&e.size>0&&ee.current&&(E(t=>t.concat(e)),!ne.current&&b.current&&(ne.current=!0,te(()=>{Ie(),s.handleScanTimeCapture({eventName:`${f}/tensorFlow`,scanID:r,email:p,message:"recording stopped by tensorflow "})},b)))},[Ie,s.handleScanTimeCapture,f,r,p,b]),_e=t.useCallback(async()=>{const e=O[O.length-1];e&&ee.current&&(await s.speechService.playAudio(s.voiceOverAssetsPath+e),ee.current&&(S=setTimeout(_e,2e3)))},[O,ee]),Pe=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};de[0]&&(t.mimeType=de[0]),w.current=new MediaRecorder(b.current.stream,t),w.current.addEventListener("dataavailable",Fe),w.current.addEventListener("stop",()=>{_(!0)}),X([...Q,Fe]),w.current.start(1e3),_(!1)}}catch(e){console.log("error while using media recorder",e)}},[b,de,Fe,Q]),Ae=t.useCallback(async()=>{R.current&&clearTimeout(R.current),Pe(),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`)},[Pe,ee,s.speechService]);t.useEffect(()=>{le.current=Ae},[Ae]);const Re=t.useCallback(({data:e})=>{const t=ye.poseDetection.connected();e.size>0&&t&&(oe.current||(oe.current=!0,ye.poseDetection.poseStatus(async e=>{if(e&&e.audio&&e.audio.length>0){const t=document.querySelector("#audioElement");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&&s.speechService.playAudio(s.voiceOverAssetsPath+e.audio):(ie.current=!0,s.speechService.stopAudio(),await s.speechService.playAudio(s.voiceOverAssetsPath+e.audio))):(q(e.audio),clearTimeout(S),ye.poseDetection.disconnect(),oe.current=!1,setTimeout(()=>le.current(),1e3))):(re.current+=1,re.current>=3&&(ae.current=0,ie.current=!1),!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,s.speechService.playAudio(s.voiceOverAssetsPath+e.audio)):C&&(C.no_of_times_skipped+=1)):(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}))},[b,r,ye,y,s.speechService,f,p]),$e=t.useCallback(async()=>{A(!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&&(A(!1),I(!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",Re),X([...Q,Re]),w.current&&w.current.start(1e3),_(!1),ee.current&&(S=setTimeout(_e,2e3))}}catch(e){console.log("error ----------",e)}},[b,de,Re,Q,_e,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})),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}.${Te}`,{type:De});be?.(),Se?.(!0),c(""),ve?.(e,j.current)}},[F,T,k,G,w,ee]),t.useEffect(()=>{ue.current=$e},[$e]),t.useEffect(()=>{const e=s.getSupportedMediaRecorderTypes(Ne,s.videoTypes);me(e)},[Ne]),t.useEffect(()=>{we()},[]),e.jsx(h,{resetDetector:a,resetScan:we,loadingCam:N,onPause:Ee,showRestart:W,pause:G,onReScan:Me,recordingStarted:T,isScanning:P,startSendingVideoFrames:$e,faceDone:L,stopRecording:Ie,showPause:Y,webcamRef:b,onUserMedia:je,onUserMediaError:ke,videoConstraints:he,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),[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(""),[q,B]=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),B(!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"),B(!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(()=>{B(!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)),B(!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(""),B(!1)},[E,J,Q,j]);return t.useEffect(()=>{v||S||j&&re()},[j,k,v,S]),t.useEffect(()=>{v||S||q&&j&&J&&ne()},[q,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:B,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-C0V-EDdB.js.map
@@ -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 c,useLayoutEffect as i,useMemo as l,useContext as d,useRef as u}from"react";import{L as m,u as p,H as f,b as h,S as g,z as y,a as v,i as w,P as x,o as b,s as S,j as C,k as N,l as D,p as I,A as k,x as F,B as T,q as E,f as L,r as M,D as _,c as $,M as U,v as j,E as A,I as P,V as z,J as V,K as R,N as B,G as q,O as K,Q as O,R as W,h as H,n as J,w as G,T as Q,t as Y,C as X,y as Z}from"./Modal-BPtRtRVC.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 ce="DESKTOP",ie="TAB",le="MOBILE",de=c(void 0);function ue({children:t}){const[n,a]=r([window?.innerWidth,window?.innerHeight]),[s,c]=r(!1),d=()=>{a([window?.innerWidth,window?.innerHeight])};o(()=>{d()},[]),i(()=>(window.addEventListener("resize",d),()=>window.removeEventListener("resize",d)),[d]);let u=ce;n[0]>768&&n[0]<1024&&(u=ie),n[0]<768&&(u=le);const m=l(()=>({size:n,setSize:a,clearInputs:s,setClearInputs:c,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:c,children:i}){const{translate:u}=d(m)||{},g=p(),y=s(()=>n<80?Math.max(0,Math.min(100,10*(n-60))):n>95?Math.max(0,Math.min(100,10*(105-n))):100,[n]),v=l(()=>{if(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`,[]),x=s((e=!1)=>{const t=y();return r?`text-[${g?.style?.angleDetector?.successAngleTextLightColor}]`:w(e,t)},[r,y]),b=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:b(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(f,{noTitle:!0})})}),null!==C?e("div",{className:"relative flex h-[6rem] w-[6rem] items-center justify-center rounded-[9999px] bg-[#fff]/20 transition-all duration-300",style:{border:`2px solid ${S()}`},children:e("div",{className:`text-[3rem] font-bold text-[${S()}]`,style:{fontFamily:g?.style?.base?.baseFontFamily||"Inter, sans-serif",color:S()},children:C})}):t("div",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"})}),i]}:{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]",x()),style:{color:S()},children:[e(me,{size:30}),t("p",{style:{fontFamily:g?.style?.base?.baseFontFamily||"Inter, sans-serif"},children:[" ",u?.(h.startLevelCheck),e("br",{})]})]})]}),null!==C&&e("div",{className:"absolute bottom-[8rem] text-center",children:e("div",{className:ee("text-sm font-medium px-4 py-1.5 bg-black/20 rounded-[9999px] mt-8",x()),style:{fontFamily:g?.style?.base?.baseFontFamily||"Inter, sans-serif",color:S()},children:u?.(h.leavePhone)})}),o&&null===C&&!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",x()),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",x()),style:{fontFamily:g?.style?.base?.baseFontFamily||"Inter, sans-serif",color:S()},children:u?.(h.placePhoneUpright)})})]})});function fe({resetScan:n,loadingCam:a,onUserMedia:r,onPause:s,pause:o,onReScan:c,recordingStarted:i,startSendingVideoFrames:l,showPause:u,webcamRef:p,onUserMediaError:f,resetDetector:w,videoConstraints:x,webcamKey:b,faceDone:S,isScanning:C}){const{media:N}=d(de)||{},{translate:D}=d(m)||{};return t("div",{className:"App w-screen h-[100vh] relative common-ui-main","data-testid":"camera-scan","data-scan-phase":S?"spinning":i?"pose-detecting":C?"starting":"ready",children:[e("span",{onClick:()=>{n(),w()},className:"fixed right-[20px] top-[20px] z-[999]",children:e(ne,{className:"text-[#fff]"})}),e("div",{className:"w-full h-full overflow-hidden ",children:N===le&&e(te,{audio:!1,ref:p,screenshotQuality:1,videoConstraints:x,mirrored:!0,screenshotFormat:"image/jpeg",onUserMedia:r,onUserMediaError:f,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:[u&&e(g,{className:"!w-[180px] !h-[40px] !py-[0] mx-auto ",prefix:y,buttonText:D?.(h.pause),buttonFunc:s,btnSecondary:!0}),o?e("div",{children:e(g,{className:"!w-[180px] !h-[40px] !py-[0] mx-auto",buttonText:D?.(h.restart),buttonFunc:c,btnSecondary:!0})}):i?null:e(g,{"data-testid":"start-scan-btn",className:"!w-[180px] !h-[40px] !py-[0] mx-auto !bg-[#ffffff] !text-[#000000] "+(a?"!opacity-50":""),buttonText:D?.(h.startScan),buttonFunc:l,disabled:a})]}),e("audio",{id:"audioElement",crossOrigin:"anonymous",preload:"auto",style:{position:"absolute",zIndex:-99999},src:`${v}scanAudioInstructions/silence.mp3`})]})}let he=null,ge=null,ye=null;let ve,we=null,xe=null;var be=a.memo(function({setIsScanLocked:t,resetDetector:n,scanID:a,setIsVideoUploaded:c,setScanFailsError:i,setScanStartTime:m,setScanUniqueKey:p,userDetails:f}){const{gender:h,heightInCm:g,email:y,shopDomain:_}=f,$=u(null),U=u(null),j=u(null),[A,P]=r([]),[z,V]=r(!0),[R,B]=r(!1),[q,K]=r(!1),[O,W]=r(!0),[H,J]=r(!1),G=u(null),[Q,Y]=r(""),[X,Z]=r([]),[ee,te]=r(""),[ne,ae]=r(!1),[re,se]=r(!1),[oe,ce]=r(!1),[ie,le]=r([]),[de,ue]=r(!1),me=u(!0),{poseDetector:pe}=function(){const[e,t]=r(0),[n,a]=r(0),[s,c]=r(!1),i=u(0),l=u(0),d=u(!0);async function m(){if("undefined"==typeof window||"undefined"==typeof navigator)return!1;try{console.log("Starting TensorFlow preload...");const[e,t,n]=await Promise.all([import("./pose-detection.esm-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),he=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 he||(he=m()),he.then(e=>{e&&d.current&&c(!0)}),()=>{d.current=!1};c(!0)},[]),o(()=>{l.current=e,e>6&&i.current<2&&(a(e=>e+1),t(0))},[e]),o(()=>{i.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!==i.current||p(r)||t(e=>e+1),1===i.current&&p(r)&&t(e=>e+1),2===i.current&&e()}catch(e){console.error("Pose detection error:",e)}},isLoaded:s,spinPhase:n,resetDetector:()=>{i.current=0,l.current=0,t(0),a(0)},retryLoading:async()=>{ge||he||(he=m(),await he&&d.current&&c(!0))}}}(),be=u(!0),Se=u(!1),Ce=u(0),Ne=u(0),De=u(!1),Ie=u(!1),ke=u(!1),Fe=u(()=>{}),Te=u(()=>{}),[Ee,Le]=r([]),[Me,_e]=r(0),[$e,Ue]=r(w),{setStartGyro:je,uploadScanFile:Ae,setUploadLoading:Pe,swan:ze,onScanStart:Ve,onCaptureComplete:Re}=d(x),Be=()=>{Se.current=!1,clearTimeout(ve),G.current&&clearTimeout(G.current),p(L()),i(""),Pe?.(!1),P([]),j.current=null,V(!0),B(!1),K(!1),W(!0),J(!1),G.current=null,Y(""),Z([]),te(""),ae(!ne),je(!1),S.stopAudio(),se(!1),ce(!1),Ce.current=0,Ne.current=0,De.current=!1,ke.current=!1,null!==U.current&&U.current.stop(),ie.forEach(e=>{U.current&&U.current.removeEventListener("dataavailable",e)}),le([]),me.current=!0,ue(!1),c(!1),$.current?.stream&&V(!1)},qe=s(()=>{setTimeout(()=>{V(!1)},1e3)},[]),Ke=s(e=>{if(console.log("camera error",e),$e===w)return Ue(b),void _e(e=>e+1);V(!1)},[$e]),Oe=s(()=>{me.current=!1,ce(!0),ue(!1),G.current&&clearTimeout(G.current),U.current&&U.current.pause(),S.stopAudio(),ze.poseDetection.disconnect(),Ce.current=0,Ne.current=0,De.current=!1,ke.current=!1,U.current&&U.current.stop(),ie.forEach(e=>{U.current&&U.current.removeEventListener("dataavailable",e)}),le([]),clearTimeout(ve)},[U,ie,S,me]),We=l(()=>C(),[]),He=N(Ee),Je=D(He),Ge=s(async()=>{me.current=!0,await S.playAudio(`${v}SpotOn.mp3`),ce(!1),ue(!1),G.current&&clearTimeout(G.current),B(!1)},[G,S]),Qe=s(async()=>{if(!Ie.current&&!we){Ie.current=!0;try{we=await ze.poseDetection.connect(),I.capture(`${_}/pose_detection_connected`,{scanID:a,email:y,id:we})}catch(e){console.log(e,"while connecting websocket")}finally{Ie.current=!1}}},[a,_,y]),Ye=s(async()=>{k({eventName:`${_}/rescan`,email:y,scanID:a,height:g,gender:h,status:!1}),me.current=!1,ze.poseDetection.disconnect(),we=null,Be(),await Qe(),Te.current()},[Qe,a,y]),Xe=s(({data:e})=>{e&&e.size>0&&me.current&&(P(t=>t.concat(e)),!Se.current&&$.current&&(Se.current=!0,pe(()=>{Ge(),F({eventName:`${_}/tensorFlow`,scanID:a,email:y,message:"recording stopped by tensorflow "})},$)))},[Ge,F,_,a,y,$]),Ze=s(async()=>{const e=X[X.length-1];e&&me.current&&(await S.playAudio(v+e),me.current&&(ve=setTimeout(Ze,2e3)))},[X,me]),et=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();j.current=t.frameRate||null}const t={videoBitsPerSecond:15e5};Ee[0]&&(t.mimeType=Ee[0]),U.current=new MediaRecorder($.current.stream,t),U.current.addEventListener("dataavailable",Xe),U.current.addEventListener("stop",()=>{W(!0)}),le([...ie,Xe]),U.current.start(1e3),W(!1)}}catch(e){console.log("error while using media recorder",e)}},[$,Ee,Xe,ie]),tt=s(async()=>{G.current&&clearTimeout(G.current),et(),me.current&&(G.current=setTimeout(async()=>{me.current&&(await S.playAudio(`${v}SpotOn.mp3`),B(!1))},15e3)),K(!0),me.current&&await S.playAudio(`${v}Spin.mp3`)},[et,me,S]);o(()=>{Fe.current=tt},[tt]);const nt=s(({data:e})=>{e.size>0&&ze.poseDetection.connected()&&(De.current||(De.current=!0,ze.poseDetection.poseStatus(async e=>{if(e&&e.audio&&e.audio.length>0){I.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||ke.current?2===Ce.current&&t?.paused&&S.playAudio(v+e.audio):(ke.current=!0,S.stopAudio(),await S.playAudio(v+e.audio))):(te(e.audio),clearTimeout(ve),ze.poseDetection.disconnect(),De.current=!1,setTimeout(()=>Fe.current(),1e3))):(Ne.current+=1,Ne.current>=3&&(Ce.current=0,ke.current=!1),!t?.paused||xe&&xe?.audioName===e.audio?xe?.audioName===e.audio&&t?.paused&&(xe&&xe.no_of_times_skipped>=xe.skipCount?(xe.no_of_times_skipped=0,S.playAudio(v+e.audio)):xe&&(xe.no_of_times_skipped+=1)):(xe={skipCount:2,no_of_times_skipped:0,audioName:e.audio},S.playAudio(v+e.audio)))}})),$?.current&&null!==$.current.getScreenshot()&&ze.poseDetection.videoEmit({image:$.current.getScreenshot()||"",scanId:a}))},[$,a,ze,we,S,_,y]),at=s(async()=>{J(!0),je(!0),Ve?.(),be.current&&(be.current=!1,F({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),qe());try{if($&&$.current&&$.current.stream&&me.current){const e=$.current.stream.getVideoTracks()[0];if(e){const t=e.getSettings();j.current=t.frameRate||null}const t={videoBitsPerSecond:15e5};Ee[0]&&(t.mimeType=Ee[0]),me.current&&(U.current=new MediaRecorder($.current.stream,t)),me.current&&U.current&&U.current.addEventListener("dataavailable",nt),le([...ie,nt]),U.current&&U.current.start(1e3),W(!1),me.current&&(ve=setTimeout(Ze,2e3))}}catch(e){console.log("error ----------",e)}},[$,Ee,nt,ie,Ze,me,Ve]);return o(()=>(_&&(t(!0),Qe()),()=>{const e=we;we=null,e&&(ze.poseDetection.disconnect(),I.capture(`${_}/pose_detection_disconnected`,{scanID:a,email:y,id:e})),ie.forEach(e=>{U?.current?.removeEventListener("dataavailable",e)})}),[_]),o(()=>{X.push(Q)},[Q]),o(()=>{Z([])},[ee]),o(()=>{const e=A.length&&A.length>0;O||!e||R||!me.current||oe||U&&U.current&&(R||U.current.stop())},[O,R,A,oe]),o(()=>{const e=A.length&&A.length>0;if(O&&e&&!R&&U&&U.current&&me.current&&!oe&&!R){const e=new File(A,`${a}.${Je}`,{type:He});Re?.(),Pe?.(!0),i(""),Ae?.(e,j.current)}},[O,R,A,oe,U,me]),o(()=>{Te.current=at},[at]),o(()=>{const e=E(We,M);Le(e)},[We]),o(()=>{Be()},[]),e(fe,{resetDetector:n,resetScan:Be,loadingCam:z,onPause:Oe,showRestart:re,pause:oe,onReScan:Ye,recordingStarted:R,isScanning:H,startSendingVideoFrames:at,faceDone:q,stopRecording:Ge,showPause:de,webcamRef:$,onUserMedia:qe,onUserMediaError:Ke,videoConstraints:$e,webcamKey:Me})});function Se({scanID:t,userDetails:n,setIsVideoUploaded:a,setScanFailsError:s,setScanStartTime:c,setScanUniqueKey:i}){const[l,d]=r(90),[m,p]=r(0),[f,h]=r(null),[g,y]=r(!1),[v,w]=r(0),x=u([]),[b,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(x.current=[...x.current.slice(-4),C],x.current.length>=5){const e=Math.max(...x.current)-Math.min(...x.current);w(N&&e<2?e=>Math.min(100,e+10):e=>Math.max(0,e-20))}N||null===f&&!g||I()},[C,N,f,g]),o(()=>{v>=100&&null===f&&!g&&D(),v<50&&null!==f&&I()},[v,f,g]);const D=()=>{h(3);const e=setInterval(()=>{h(t=>null===t||t<=1?(clearInterval(e),y(!0),null):t-1)},1e3)},I=()=>{h(null),b||y(!1)};return e(pe,{angle:C,countdown:f,isScanning:g,isInTargetRange:N,stabilityScore:v,children:g&&e(be,{setIsScanLocked:S,resetDetector:()=>{d(90),p(0),h(null),y(!1),w(0),S(!1),x.current=[]},scanID:t,userDetails:n,setIsVideoUploaded:a,setScanFailsError:s,setScanStartTime:c,setScanUniqueKey:i})})}function Ce({setShowDrawer:t,config:n,loader:a}){const[c,i]=r({disabled:!1,message:""}),[l,d]=r(!0),m=u(null),p=s(async()=>{const e=await _();i(e),d(!1)},[]);return o(()=>{p()},[]),l?e($,{url:a,loaderType:"black"}):c?.disabled?e(U,{config:n,message:c?.message}):e(te,{audio:!1,ref:m,screenshotQuality:1,videoConstraints:j,mirrored:!0,onUserMedia:()=>t?.(!0),screenshotFormat:"image/jpeg",style:{position:"relative",top:0,bottom:0,zIndex:0,width:"100%",height:"100%",objectFit:"cover"}})}function Ne({link:t,onReady:n,wrapperClassName:a="[&_video]:rounded-t-[20px] w-full h-full"}){const r=u(null),s=u(null);let c={autoplay:!0,controls:!1,responsive:!0,fluid:!0,muted:!0,navigationUI:"hide",preload:"metadata",poster:A};return o(()=>{if(!s.current&&t&&r?.current){const e=oe(r.current,{...c});e.ready(()=>{s.current=e;const a={...c,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 De({scanFailsError:a,onNext:s,gender:o,setScanUniqueKey:c,setIsVideoUploaded:i}){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(f,{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?.(h.issueWithScan)}),e("p",{style:{fontFamily:u?.style?.base?.baseFontFamily||"Inter, sans-serif",fontSize:u?.style?.base?.baseFontSize||"16px",color:u?.style?.base?.baseTextColor||"#1E1E1E"},children:l?.(h.reason)}),e("p",{style:{fontFamily:u?.style?.base?.baseFontFamily||"Inter, sans-serif",fontSize:u?.style?.base?.baseFontSize||"16px",color:u?.style?.base?.baseTextColor||"#1E1E1E"},children:P(a)}),e("img",{className:"my-[0.5rem] aspect-[2/1.4] w-full object-cover",onClick:w,src:z[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?.(h.scanAgain),className:"!shadow-none",buttonFunc:()=>{s?s?.():c?.(L()),i?.(!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(Ne,{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:c,isVideoUploadedCorrect:i,isMeasurementAvailable:l,onComplete:u,isSuccess:p,onCustomScanSuccess:y,swan:v}){const{gender:w,shopDomain:x,heightInCm:b,deviceFocalLength:S,userName:C,email:N,scanType:D}=a||{},k=[K,O,W].includes(D??""),[F,T]=r(!0),E=s(async()=>{try{k&&(await(v?.auth.addUser({scanId:n,email:N,name:C,gender:w,height:b})),y?.()),I.capture(x??"",{scanID:n,email:N,height:b,focalLength:S,clothesFit:"0",gender:w})}catch(e){console.log(e)}},[k]),{translate:L}=d(m)||{};o(()=>{(i||l)&&E()},[i,l]);const M=p||i||l;return e(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(Ce,{loader:c?.loader,setShowDrawer:T}),e(se,{open:F,onClose:(e,t)=>{},className:"camera-drawer",anchor:"bottom",children:e("div",{className:"max-w-[28rem] mx-auto w-full h-full flex text-center flex-col justify-between items-center bg-primary rounded-t-[30px] p-[1rem]",style:{background:c?.style?.base?.backgroundColor},children:t("div",{className:"w-full h-full flex flex-col",children:[e(f,{title:L?.(h.measurementsBeingTaken)}),e("div",{className:"flex items-center justify-center flex-1",children:e("video",{preload:"auto",className:"max-h-[calc(100vh-450px)] mx-auto w-full object-contain border-none",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?.(h.next),buttonFunc:()=>{u?.()}})]})})})]})})}const ke=()=>{const{userDetails:n,onRetry:a,isError:r,isSuccess:s,gender:o,scanUniqueKey:c,scanFailsError:i,setScanUniqueKey:l,setIsVideoUploaded:u,isMeasurementAvailable:m,isVideoUploadedCorrect:f,loading:h,showDeniedModal:g,uploadLoading:y,setScanFailsError:v,setScanStartTime:w,resetScan:b,onCustomScanSuccess:S,swan:C,onComplete:N}=d(x),D=p();return r?t("div",{"data-scan-state":"error",children:[e(Ce,{}),e(se,{anchor:"bottom",open:!0,className:"camera-drawer",onClose:(e,t)=>{},children:e(De,{scanFailsError:!0,onNext:a,gender:o})})]}):s?e("div",{"data-scan-state":"success",children:e(Ie,{isSuccess:!0,onComplete:N})}):h?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($,{url:D?.loader,loaderType:"black"})}):g.disabled?e("div",{"data-scan-state":"camera-denied",children:e(U,{})}):y||i||m||f?(y||m||f)&&!i?e("div",{"data-scan-state":"processing",children:e(Ie,{scanId:c,isMeasurementAvailable:m,userDetails:n,isVideoUploadedCorrect:f,onCustomScanSuccess:S,swan:C,onComplete:N})}):t("div",{"data-scan-state":"error-retry",children:[e(Ce,{}),e(se,{anchor:"bottom",open:!0,className:"camera-drawer",onClose:(e,t)=>{},children:e(De,{scanFailsError:i,onNext:()=>{a?.(),b()},setScanUniqueKey:l,gender:o,setIsVideoUploaded:u})})]}):e("div",{"data-scan-state":"scanning",children:e(Se,{scanID:c,userDetails:n,setIsVideoUploaded:u,setScanFailsError:v,setScanStartTime:w,setScanUniqueKey:l})})},Fe=t=>{const{config:n,onRetry:a,onScanStart:c,onCaptureComplete:i,onUploadStart:d,onUploadEnd:u,onMeasurementSocketStart:m,onMeasurementSocketClose:p,onIntermediateScanSuccess:f,onScanError:h,onScanSuccess:g,onCustomScanSuccess:y,onComplete:v,isError:w,isSuccess:b}=t,S={email:"",shopDomain:"",gender:"male",heightInCm:0,scanType:"",deviceFocalLength:0,deviceModelName:"",sourceTag:"",callbackUrl:null,...t.userDetails??{}},C=t.token??"",{gender:N,scanType:D,shopDomain:I,heightInCm:k,email:E,deviceFocalLength:M,deviceModelName:$,callbackUrl:U,sourceTag:j}=S,A=l(()=>H(C),[C]),[z,V]=r(!1),[R,B]=r(!1),[q,K]=r(!1),[O,W]=r({disabled:!1,message:""}),[ee,te]=r(""),[ne,ae]=r(!1),[re,se]=r(!0),[oe,ce]=r(!1),[ie,le]=r(""),[de,me]=r(T()),{gyroData:pe}=function(e){const[t,n]=r([]),[a,c]=r(!1),i=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()?c(!0):console.warn("Device orientation permission denied.")}catch(e){console.error("Error requesting device orientation permission:",e)}else c(!0)},[]);return o(()=>(e&&a?window.addEventListener("deviceorientation",i):n([]),()=>{window.removeEventListener("deviceorientation",i)}),[e,a,i]),o(()=>{e&&l()},[e,l]),{gyroData:t}}(oe);J();const fe=s(()=>{le(L()),te(""),V(!1),ae(!1)},[]),he=()=>{me(null),le("")},ge=s(async e=>{if(e&&"success"===e?.scanStatus&&"intermediate"===e?.resultType&&200===e?.code)return F({eventName:`${I}/measurement_success/intermediate`,scanID:ie,status:"success",email:E}),B(!0),void f?.(e);g?.(e),B(!0),he();const t=ie;K(!0),F({eventName:`${I}/measurement_success/fit-view`,scanID:t,status:"success",email:E}),de&&F({eventName:`${I}/scan_completion_time`,scanID:t,status:"success",completionTime:T()-de,email:E})},[D,I,ie]),ye=e=>{K(!1),te(""),B(!1),A.measurement.handleMeasurementSocket({scanId:ie,onPreopen:()=>{Z({eventName:`${I}/webSocket`,scanID:ie,connection:"pre_open",type:"measurement_recommendation",email:E})},onOpen:()=>{m?.(),Z({eventName:`${I}/webSocket`,scanID:ie,connection:"open",type:"measurement_recommendation",email:E})},onClose:()=>{p?.(),Z({eventName:`${I}/webSocket`,scanID:ie,connection:"close",type:"measurement_recommendation",email:E})},onError:e=>{var t;t=e,h?.({...t,message:P(t)}),he(),K(!1),te(t),B(!1),F({eventName:`${I}/measurement_failed/fit-view`,scanID:ie,status:"failed",email:E,message:P(t)}),de&&F({eventName:`${I}/scan_completion_time`,scanID:ie,status:"failed",completionTime:T()-de,email:E}),Z({eventName:`${I}/webSocket`,scanID:ie,connection:"error",type:"measurement_recommendation",email:E})},onSuccess:e=>{Z({eventName:`${I}/webSocket`,scanID:ie,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:`${k}`,customer_store_url:I,clothes_fit:"0",scan_type:D,callback_url:U,source_tag:j});F({eventName:`${I}/body_scan_meta_data`,scanID:ie,email:E,data:JSON.stringify([...r,{fileSizeInMB:n,video_fps:a||0}])}),d?.();try{await A.fileUpload.uploadFileFrontend({file:e,arrayMetaData:r,scanId:ie,email:E}),await A.fileUpload.setDeviceInfo({model:$,detection:"manual",gyro:pe,scanId:ie}),console.log("video successfully uploaded"),ae(!1),F({eventName:`${I}/scan_success`,scanID:ie,status:"success",email:E,data:JSON.stringify(r)}),F({eventName:"scan finished",scanID:ie,status:"success",email:E}),me(T()),setTimeout(()=>{ae(!0)},3e3)}catch(e){F({eventName:"scan finished",scanID:ie,status:"failed",email:E,message:P(e)}),F({eventName:`${I}/scan_failed`,scanID:ie,status:"failed",email:E,message:P(e),data:JSON.stringify(r)}),te(P(e)),ae(!1),h?.({...e,message:P(e)}),he()}finally{ce(!1),u?.()}},[ie,pe,d,u]),we=s(async()=>{if(+k<152.4||+k>213.36)return void h?.({message:"Height must be between 152.4cm (5ft) and 213.36cm (7ft)"});const e=await _();e.disabled?(F({eventName:`${I}/camera_activation`,scanID:ie,status:"failed",email:E}),se(!1)):(se(!1),F({eventName:`${I}/camera_activation`,scanID:ie,status:"success",email:E})),W(e),te(""),ae(!1)},[E,ie,le,I]);return o(()=>{w||b||I&&we()},[I,k,w,b]),o(()=>{w||b||ne&&I&&ie&&ye()},[ne,I,ie,w,b]),e("div",{"data-testid":"body-scan-root",children:e(Y,{children:e(X,{config:n,children:e(ue,{children:e(x.Provider,{value:{userDetails:S,onRetry:a,onScanError:h,isError:w,isSuccess:b,onScanSuccess:g,gender:N,scanUniqueKey:ie,scanFailsError:ee,setScanUniqueKey:le,setIsVideoUploaded:ae,isMeasurementAvailable:q,isVideoUploadedCorrect:R,loading:re,showDeniedModal:O,uploadLoading:z,setStartGyro:ce,uploadScanFile:ve,setUploadLoading:V,resetScan:fe,setScanFailsError:te,setScanStartTime:me,onScanStart:c,onCaptureComplete:i,onCustomScanSuccess:y,onComplete:v,swan:A},children:e(ke,{})})})})})})};export{Fe as B};
2
- //# sourceMappingURL=BodyScan-C1dWJ2qu.js.map
@@ -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 u,useRef as d}from"react";import{L as m,S as p,z as f,b as h,a as g,i as y,P as v,o as S,s as w,j as b,k as x,l as D,p as I,A as N,x as E,B as $,q as C,f as _,r as T,D as F,c as k,M,v as P,E as L,u as U,H as A,I as z,V as R,J as j,K,N as V,G as q,O,Q as B,R as W,h as H,n as G,w as J,T as Y,t as Q,C as X,y as Z}from"./Modal-D_XGokez.js";import ee from"react-webcam";import{X as te}from"lucide-react";import{Dialog as ne,Box as ae,Drawer as re}from"@mui/material";import se from"video.js";const oe="DESKTOP",ie="TAB",ce="MOBILE",le=i(void 0);function ue({children:t}){const[n,a]=r([window?.innerWidth,window?.innerHeight]),[s,i]=r(!1),u=()=>{a([window?.innerWidth,window?.innerHeight])};o(()=>{u()},[]),c(()=>(window.addEventListener("resize",u),()=>window.removeEventListener("resize",u)),[u]);let d=oe;n[0]>768&&n[0]<1024&&(d=ie),n[0]<768&&(d=ce);const m=l(()=>({size:n,setSize:a,clearInputs:s,setClearInputs:i,media:d}),[n,s,d]);return e(le.Provider,{value:m,children:t})}function de({resetScan:n,loadingCam:a,onUserMedia:r,onPause:s,pause:o,onReScan:i,recordingStarted:c,startSendingVideoFrames:l,showPause:d,webcamRef:y,onUserMediaError:v,resetDetector:S,videoConstraints:w,webcamKey:b,faceDone:x,isScanning:D}){const{media:I}=u(le)||{},{translate:N}=u(m)||{};return t("div",{className:"App w-screen h-[100vh] relative common-ui-main","data-testid":"camera-scan","data-scan-phase":x?"spinning":c?"pose-detecting":D?"starting":"ready",children:[e("span",{onClick:()=>{n(),S()},className:"fixed right-[20px] top-[20px] z-[999]",children:e(te,{className:"text-[#fff]"})}),e("div",{className:"w-full h-full overflow-hidden ",children:I===ce&&e(ee,{audio:!1,ref:y,screenshotQuality:1,videoConstraints:w,mirrored:!0,screenshotFormat:"image/jpeg",onUserMedia:r,onUserMediaError:v,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:[d&&e(p,{className:"!w-[180px] !h-[40px] !py-[0] mx-auto ",prefix:f,buttonText:N?.(h.pause),buttonFunc:s,btnSecondary:!0}),o?e("div",{children:e(p,{className:"!w-[180px] !h-[40px] !py-[0] mx-auto",buttonText:N?.(h.restart),buttonFunc:i,btnSecondary:!0})}):c?null:e(p,{"data-testid":"start-scan-btn",className:"!w-[180px] !h-[40px] !py-[0] mx-auto !bg-[#ffffff] !text-[#000000] "+(a?"!opacity-50":""),buttonText:N?.(h.startScan),buttonFunc:l,disabled:a})]}),e("audio",{id:"audioElement",crossOrigin:"anonymous",preload:"auto",style:{position:"absolute",zIndex:-99999},src:`${g}scanAudioInstructions/silence.mp3`})]})}let me=null,pe=null,fe=null;let he,ge=null,ye=null;var ve=a.memo(function({setIsScanLocked:t,resetDetector:n,scanID:a,setIsVideoUploaded:i,setScanFailsError:c,setScanStartTime:m,setScanUniqueKey:p,userDetails:f}){const{gender:h,heightInCm:F,email:k,shopDomain:M}=f,P=d(null),L=d(null),U=d(null),[A,z]=r([]),[R,j]=r(!0),[K,V]=r(!1),[q,O]=r(!1),[B,W]=r(!0),[H,G]=r(!1),J=d(null),[Y,Q]=r(""),[X,Z]=r([]),[ee,te]=r(""),[ne,ae]=r(!1),[re,se]=r(!1),[oe,ie]=r(!1),[ce,le]=r([]),[ue,ve]=r(!1),Se=d(!0),{poseDetector:we}=function(){const[e,t]=r(0),[n,a]=r(0),[s,i]=r(!1),c=d(0),l=d(0),u=d(!0);async function m(){if("undefined"==typeof window||"undefined"==typeof navigator)return!1;try{console.log("Starting TensorFlow preload...");const[e,t,n]=await Promise.all([import("./pose-detection.esm-DejsYGYM.js"),import("@tensorflow/tfjs-core"),import("@tensorflow/tfjs-backend-webgl")]);fe=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{pe=await fe.createDetector(fe.SupportedModels.BlazePose,a),console.log("MediaPipe detector created successfully")}catch(e){console.warn("MediaPipe failed, falling back to TFJS runtime:",e),pe=await fe.createDetector(fe.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),me=null,!1}}function p(e){return!(!e||0===e.length)&&22===e.filter(e=>e[2]>.7).length}return o(()=>{if(u.current=!0,!pe)return me||(me=m()),me.then(e=>{e&&u.current&&i(!0)}),()=>{u.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(!pe||!u.current||!n?.current?.video)return;const a=n.current.video;if(!(a.readyState<2))try{const n=await pe.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()=>{pe||me||(me=m(),await me&&u.current&&i(!0))}}}(),be=d(!0),xe=d(!1),De=d(0),Ie=d(0),Ne=d(!1),Ee=d(!1),$e=d(!1),Ce=d(()=>{}),_e=d(()=>{}),[Te,Fe]=r([]),[ke,Me]=r(0),[Pe,Le]=r(y),{setStartGyro:Ue,uploadScanFile:Ae,setUploadLoading:ze,swan:Re,onScanStart:je,onCaptureComplete:Ke}=u(v),Ve=()=>{xe.current=!1,clearTimeout(he),J.current&&clearTimeout(J.current),p(_()),c(""),ze?.(!1),z([]),U.current=null,j(!0),V(!1),O(!1),W(!0),G(!1),J.current=null,Q(""),Z([]),te(""),ae(!ne),Ue(!1),w.stopAudio(),se(!1),ie(!1),De.current=0,Ie.current=0,Ne.current=!1,$e.current=!1,null!==L.current&&L.current.stop(),ce.forEach(e=>{L.current&&L.current.removeEventListener("dataavailable",e)}),le([]),Se.current=!0,ve(!1),i(!1),P.current?.stream&&j(!1)},qe=s(()=>{setTimeout(()=>{j(!1)},1e3)},[]),Oe=s(e=>{if(console.log("camera error",e),Pe===y)return Le(S),void Me(e=>e+1);j(!1)},[Pe]),Be=s(()=>{Se.current=!1,ie(!0),ve(!1),J.current&&clearTimeout(J.current),L.current&&L.current.pause(),w.stopAudio(),Re.poseDetection.disconnect(),De.current=0,Ie.current=0,Ne.current=!1,$e.current=!1,L.current&&L.current.stop(),ce.forEach(e=>{L.current&&L.current.removeEventListener("dataavailable",e)}),le([]),clearTimeout(he)},[L,ce,w,Se]),We=l(()=>b(),[]),He=x(Te),Ge=D(He),Je=s(async()=>{Se.current=!0,await w.playAudio(`${g}SpotOn.mp3`),ie(!1),ve(!1),J.current&&clearTimeout(J.current),V(!1)},[J,w]),Ye=s(async()=>{if(!Ee.current&&!ge){Ee.current=!0;try{ge=await Re.poseDetection.connect(),I.capture(`${M}/pose_detection_connected`,{scanID:a,email:k,id:ge})}catch(e){console.log(e,"while connecting websocket")}finally{Ee.current=!1}}},[a,M,k]),Qe=s(async()=>{N({eventName:`${M}/rescan`,email:k,scanID:a,height:F,gender:h,status:!1}),Se.current=!1,Re.poseDetection.disconnect(),ge=null,Ve(),await Ye(),_e.current()},[Ye,a,k]),Xe=s(({data:e})=>{e&&e.size>0&&Se.current&&(z(t=>t.concat(e)),!xe.current&&P.current&&(xe.current=!0,we(()=>{Je(),E({eventName:`${M}/tensorFlow`,scanID:a,email:k,message:"recording stopped by tensorflow "})},P)))},[Je,E,M,a,k,P]),Ze=s(async()=>{const e=X[X.length-1];e&&Se.current&&(await w.playAudio(g+e),Se.current&&(he=setTimeout(Ze,2e3)))},[X,Se]),et=s(()=>{L&&L.current&&L.current.stop(),V(!0);try{if(P&&P.current&&P.current.stream){const e=P.current.stream.getVideoTracks()[0];if(e){const t=e.getSettings();U.current=t.frameRate||null}const t={videoBitsPerSecond:15e5};Te[0]&&(t.mimeType=Te[0]),L.current=new MediaRecorder(P.current.stream,t),L.current.addEventListener("dataavailable",Xe),L.current.addEventListener("stop",()=>{W(!0)}),le([...ce,Xe]),L.current.start(1e3),W(!1)}}catch(e){console.log("error while using media recorder",e)}},[P,Te,Xe,ce]),tt=s(async()=>{J.current&&clearTimeout(J.current),et(),Se.current&&(J.current=setTimeout(async()=>{Se.current&&(await w.playAudio(`${g}SpotOn.mp3`),V(!1))},15e3)),O(!0),Se.current&&await w.playAudio(`${g}Spin.mp3`)},[et,Se,w]);o(()=>{Ce.current=tt},[tt]);const nt="undefined"!=typeof window?window.__scanLog??[]:[],at=e=>{const t=`[${(new Date).toISOString().slice(11,23)}] [SCAN] ${e}`;console.log(t),nt.push(t)},rt=s(({data:e})=>{const t=Re.poseDetection.connected();e.size>0&&t?(Ne.current||(Ne.current=!0,at(`poseStatus listener REGISTERED | id=${ge}`),Re.poseDetection.poseStatus(async e=>{if(e&&e.audio&&e.audio.length>0){const t=document.querySelector("#audioElement"),n=e.audio?.split("/").pop(),r=t?.paused,s=t?.src?.split("/").pop()||"empty";at(`poseStatus RECEIVED | status=${e.status} | file=${n} | sid=${e.sid} | id=${ge} | sidMatch=${e.sid===ge} | counter=${De.current} | consecFalse=${Ie.current} | audioPaused=${r} | audioSrc=${s} | audioEl=${t?"found":"NULL"} | lastPlayed=${ye?.audioName?.split("/").pop()??"none"} | skipped=${ye?.no_of_times_skipped??"-"}/${ye?.skipCount??"-"}`),I.capture(`${M}/pose_instruction_received`,{scanID:a,email:k,audio:e.audio,status:e.status,sid:e.sid,counter:De.current,consecutiveFalse:Ie.current,type:"body_scan_instruction"}),!0===e.status&&e.sid===ge?(Ie.current=0,De.current<2?(De.current+=1,1!==De.current||$e.current?2===De.current&&t?.paused?(at(`PLAY good-posture-2 | file=${n}`),w.playAudio(g+e.audio)):2!==De.current||t?.paused?at(`SKIP good-posture-1 — brilliantPlayed already | counter=${De.current}`):at(`SKIP good-posture-2 — audio still playing | file=${n}`):(at(`PLAY good-posture-1 (brilliant) | file=${n}`),$e.current=!0,w.stopAudio(),await w.playAudio(g+e.audio))):(at(`TRIGGER SPIN | counter=${De.current} | file=${n}`),te(e.audio),clearTimeout(he),Re.poseDetection.disconnect(),Ne.current=!1,setTimeout(()=>Ce.current(),1e3))):!0===e.status&&e.sid!==ge?at(`SKIP good-posture — sid MISMATCH | data.sid=${e.sid} | id=${ge}`):(Ie.current+=1,Ie.current>=3&&(De.current=0,$e.current=!1,at(`RESET counter/brilliant — consecutiveFalse=${Ie.current}`)),!t?.paused||ye&&ye?.audioName===e.audio?t?.paused||ye&&ye?.audioName===e.audio?ye?.audioName===e.audio&&t?.paused?ye&&ye.no_of_times_skipped>=ye.skipCount?(ye.no_of_times_skipped=0,at(`PLAY wrong-posture REPEAT | file=${n}`),w.playAudio(g+e.audio)):(ye&&(ye.no_of_times_skipped+=1),at(`SKIP wrong-posture SAME — skip ${ye?.no_of_times_skipped}/${ye?.skipCount} | file=${n}`)):ye?.audioName!==e.audio||t?.paused||at(`SKIP wrong-posture SAME — audio still playing | file=${n}`):at(`SKIP wrong-posture NEW — audio playing | file=${n}`):(at(`PLAY wrong-posture NEW | file=${n}`),ye={skipCount:2,no_of_times_skipped:0,audioName:e.audio},w.playAudio(g+e.audio)))}})),P?.current&&null!==P.current.getScreenshot()&&Re.poseDetection.videoEmit({image:P.current.getScreenshot()||"",scanId:a})):e.size>0&&!t&&at(`handleDataAvailable — WS DISCONNECTED | id=${ge} | poseListenerRegistered=${Ne.current}`)},[P,a,Re,ge,w,M,k]),st=s(async()=>{G(!0),Ue(!0),je?.(),be.current&&(be.current=!1,E({eventName:"scan started",scanID:a,status:"success",email:k})),m($()),j(!0),Se.current&&await w.playAudio(`${g}StartScan.mp3`),Se.current&&await w.playAudio(`${g}LiftArmsAndHoldAtHip.mp3`),Se.current&&(G(!1),V(!0),se(!0),ve(!0),qe());try{if(P&&P.current&&P.current.stream&&Se.current){const e=P.current.stream.getVideoTracks()[0];if(e){const t=e.getSettings();U.current=t.frameRate||null}const t={videoBitsPerSecond:15e5};Te[0]&&(t.mimeType=Te[0]),Se.current&&(L.current=new MediaRecorder(P.current.stream,t)),Se.current&&L.current&&L.current.addEventListener("dataavailable",rt),le([...ce,rt]),L.current&&L.current.start(1e3),W(!1),Se.current&&(he=setTimeout(Ze,2e3))}}catch(e){console.log("error ----------",e)}},[P,Te,rt,ce,Ze,Se,je]);return o(()=>(M&&(t(!0),Ye()),()=>{const e=ge;ge=null,e&&(Re.poseDetection.disconnect(),I.capture(`${M}/pose_detection_disconnected`,{scanID:a,email:k,id:e})),ce.forEach(e=>{L?.current?.removeEventListener("dataavailable",e)})}),[M]),o(()=>{X.push(Y)},[Y]),o(()=>{Z([])},[ee]),o(()=>{const e=A.length&&A.length>0;B||!e||K||!Se.current||oe||L&&L.current&&(K||L.current.stop())},[B,K,A,oe]),o(()=>{const e=A.length&&A.length>0;if(B&&e&&!K&&L&&L.current&&Se.current&&!oe&&!K){const e=new File(A,`${a}.${Ge}`,{type:He});Ke?.(),ze?.(!0),c(""),Ae?.(e,U.current)}},[B,K,A,oe,L,Se]),o(()=>{_e.current=st},[st]),o(()=>{const e=C(We,T);Fe(e)},[We]),o(()=>{Ve()},[]),e(de,{resetDetector:n,resetScan:Ve,loadingCam:R,onPause:Be,showRestart:re,pause:oe,onReScan:Qe,recordingStarted:K,isScanning:H,startSendingVideoFrames:st,faceDone:q,stopRecording:Je,showPause:ue,webcamRef:P,onUserMedia:qe,onUserMediaError:Oe,videoConstraints:Pe,webcamKey:ke})});function Se({scanID:t,userDetails:n,setIsVideoUploaded:a,setScanFailsError:s,setScanStartTime:i,setScanUniqueKey:c}){const[l,u]=r(90),[m,p]=r(0),[f,h]=r(null),[g,y]=r(!1),[v,S]=r(0),w=d([]),[b,x]=r(!1),D=l-m,I=D>=80&&D<=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)),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})}},[]),o(()=>{if(w.current=[...w.current.slice(-4),D],w.current.length>=5){const e=Math.max(...w.current)-Math.min(...w.current);S(I&&e<2?e=>Math.min(100,e+10):e=>Math.max(0,e-20))}I||null===f&&!g||E()},[D,I,f,g]),o(()=>{v>=100&&null===f&&!g&&N(),v<50&&null!==f&&E()},[v,f,g]);const N=()=>{h(3);const e=setInterval(()=>{h(t=>null===t||t<=1?(clearInterval(e),y(!0),null):t-1)},1e3)},E=()=>{h(null),b||y(!1)};return e(ve,{setIsScanLocked:x,resetDetector:()=>{u(90),p(0),h(null),y(!1),S(0),x(!1),w.current=[]},scanID:t,userDetails:n,setIsVideoUploaded:a,setScanFailsError:s,setScanStartTime:i,setScanUniqueKey:c})}function we({setShowDrawer:t,config:n,loader:a}){const[i,c]=r({disabled:!1,message:""}),[l,u]=r(!0),m=d(null),p=s(async()=>{const e=await F();c(e),u(!1)},[]);return o(()=>{p()},[]),l?e(k,{url:a,loaderType:"black"}):i?.disabled?e(M,{config:n,message:i?.message}):e(ee,{audio:!1,ref:m,screenshotQuality:1,videoConstraints:P,mirrored:!0,onUserMedia:()=>t?.(!0),screenshotFormat:"image/jpeg",style:{position:"relative",top:0,bottom:0,zIndex:0,width:"100%",height:"100%",objectFit:"cover"}})}function be({link:t,onReady:n,wrapperClassName:a="[&_video]:rounded-t-[20px] w-full h-full"}){const r=d(null),s=d(null);let i={autoplay:!0,controls:!1,responsive:!0,fluid:!0,muted:!0,navigationUI:"hide",preload:"metadata",poster:L};return o(()=>{if(!s.current&&t&&r?.current){const e=se(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 xe({scanFailsError:a,onNext:s,gender:o,setScanUniqueKey:i,setIsVideoUploaded:c}){const{translate:l}=u(m)||{},d=U(),[f,g]=r(!1),y=()=>{g(!f)};return t(n,{children:[t("div",{"data-testid":"scan-error-message",className:"flex common-ui-main flex-col h-full max-w-[28rem] mx-auto w-full rounded-t-[20px] overflow-y-auto",style:{background:d?.style?.base?.backgroundColor},children:[e("div",{className:"w-full max-w-[28rem] mx-auto pt-[1rem] px-[1rem]",children:e(A,{noTitle:!0})}),e("div",{className:"flex-1",children:a&&t("div",{className:"px-[1rem]",children:[e("h2",{className:"text-center",style:{fontFamily:d?.style?.heading?.headingFontFamily||"SeriouslyNostalgic Fn",fontSize:d?.style?.heading?.headingFontSize||"32px",color:d?.style?.heading?.headingColor||"#000",fontWeight:d?.style?.heading?.headingFontWeight||"normal"},children:l?.(h.issueWithScan)}),e("p",{style:{fontFamily:d?.style?.base?.baseFontFamily||"Inter, sans-serif",fontSize:d?.style?.base?.baseFontSize||"16px",color:d?.style?.base?.baseTextColor||"#1E1E1E"},children:l?.(h.reason)}),e("p",{style:{fontFamily:d?.style?.base?.baseFontFamily||"Inter, sans-serif",fontSize:d?.style?.base?.baseFontSize||"16px",color:d?.style?.base?.baseTextColor||"#1E1E1E"},children:z(a)}),e("img",{className:"my-[0.5rem] aspect-[2/1.4] w-full object-cover",onClick:y,src:R[o],alt:"icon"})]})}),a&&e("div",{className:"p-[1rem] flex gap-[0.5rem]",children:e(p,{"data-testid":"scan-again-btn",disabled:!1,buttonText:l?.(h.scanAgain),className:"!shadow-none",buttonFunc:()=>{s?s?.():i?.(_()),c?.(!1)}})})]}),f&&t(ne,{className:"w-screen h-screen video-modal",onClose:y,open:f,children:[e("div",{className:"flex justifyEnd ",children:e("span",{className:"closeBtn",onClick:y,children:e(te,{className:"absolute right-[8px] top-[8px] text-white z-[9]"})})}),e("div",{className:"aspect-video object-cover rounded-[20px] ",children:e(be,{link:o?j[o].PRE_LINK:j.male.PRE_LINK,wrapperClassName:"w-screen h-screen fixed top-[0] left-[0]"})})]})]})}function De({scanId:n,userDetails:a,config:i,isVideoUploadedCorrect:c,isMeasurementAvailable:l,onComplete:d,isSuccess:f,onCustomScanSuccess:g,swan:y}){const{gender:v,shopDomain:S,heightInCm:w,deviceFocalLength:b,userName:x,email:D,scanType:N}=a||{},E=[O,B,W].includes(N??""),[$,C]=r(!0),_=s(async()=>{try{E&&(await(y?.auth.addUser({scanId:n,email:D,name:x,gender:v,height:w})),g?.()),I.capture(S??"",{scanID:n,email:D,height:w,focalLength:b,clothesFit:"0",gender:v})}catch(e){console.log(e)}},[E]),{translate:T}=u(m)||{};o(()=>{(c||l)&&_()},[c,l]);const F=f||c||l;return e(ae,{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(we,{loader:i?.loader,setShowDrawer:C}),e(re,{open:$,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(A,{title:T?.(h.measurementsBeingTaken)}),e("div",{className:"flex items-center justify-center flex-1",children:e("video",{preload:"auto",className:"max-h-[calc(100vh-450px)] mx-auto w-full object-contain border-none",muted:!0,loop:!0,autoPlay:!0,playsInline:!0,children:e("source",{src:v===q.Male?K:V,type:"video/mp4"})})}),F&&e(p,{className:"!w-[180px] mx-auto",buttonText:T?.(h.next),buttonFunc:()=>{d?.()}})]})})})]})})}const Ie=()=>{const{userDetails:n,onRetry:a,isError:r,isSuccess:s,gender:o,scanUniqueKey:i,scanFailsError:c,setScanUniqueKey:l,setIsVideoUploaded:d,isMeasurementAvailable:m,isVideoUploadedCorrect:p,loading:f,showDeniedModal:h,uploadLoading:g,setScanFailsError:y,setScanStartTime:S,resetScan:w,onCustomScanSuccess:b,swan:x,onComplete:D}=u(v),I=U();return r?t("div",{"data-scan-state":"error",children:[e(we,{}),e(re,{anchor:"bottom",open:!0,className:"camera-drawer",onClose:(e,t)=>{},children:e(xe,{scanFailsError:!0,onNext:a,gender:o})})]}):s?e("div",{"data-scan-state":"success",children:e(De,{isSuccess:!0,onComplete:D})}):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:I?.style?.base?.backgroundColor},children:e(k,{url:I?.loader,loaderType:"black"})}):h.disabled?e("div",{"data-scan-state":"camera-denied",children:e(M,{})}):g||c||m||p?(g||m||p)&&!c?e("div",{"data-scan-state":"processing",children:e(De,{scanId:i,isMeasurementAvailable:m,userDetails:n,isVideoUploadedCorrect:p,onCustomScanSuccess:b,swan:x,onComplete:D})}):t("div",{"data-scan-state":"error-retry",children:[e(we,{}),e(re,{anchor:"bottom",open:!0,className:"camera-drawer",onClose:(e,t)=>{},children:e(xe,{scanFailsError:c,onNext:()=>{a?.(),w()},setScanUniqueKey:l,gender:o,setIsVideoUploaded:d})})]}):e("div",{"data-scan-state":"scanning",children:e(Se,{scanID:i,userDetails:n,setIsVideoUploaded:d,setScanFailsError:y,setScanStartTime:S,setScanUniqueKey:l})})},Ne=t=>{const{config:n,onRetry:a,onScanStart:i,onCaptureComplete:c,onUploadStart:u,onUploadEnd:d,onMeasurementSocketStart:m,onMeasurementSocketClose:p,onIntermediateScanSuccess:f,onScanError:h,onScanSuccess:g,onCustomScanSuccess:y,onComplete:S,isError:w,isSuccess:b}=t,x={email:"",shopDomain:"",gender:"male",heightInCm:0,scanType:"",deviceFocalLength:0,deviceModelName:"",sourceTag:"",callbackUrl:null,...t.userDetails??{}},D=t.token??"",{gender:I,scanType:N,shopDomain:C,heightInCm:T,email:k,deviceFocalLength:M,deviceModelName:P,callbackUrl:L,sourceTag:U}=x,A=l(()=>H(D),[D]),[R,j]=r(!1),[K,V]=r(!1),[q,O]=r(!1),[B,W]=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($()),{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);G();const fe=s(()=>{le(_()),te(""),j(!1),ae(!1)},[]),he=()=>{me(null),le("")},ge=s(async e=>{if(e&&"success"===e?.scanStatus&&"intermediate"===e?.resultType&&200===e?.code)return E({eventName:`${C}/measurement_success/intermediate`,scanID:ce,status:"success",email:k}),V(!0),void f?.(e);g?.(e),V(!0),he();const t=ce;O(!0),E({eventName:`${C}/measurement_success/fit-view`,scanID:t,status:"success",email:k}),de&&E({eventName:`${C}/scan_completion_time`,scanID:t,status:"success",completionTime:$()-de,email:k})},[N,C,ce]),ye=e=>{O(!1),te(""),V(!1),A.measurement.handleMeasurementSocket({scanId:ce,onPreopen:()=>{Z({eventName:`${C}/webSocket`,scanID:ce,connection:"pre_open",type:"measurement_recommendation",email:k})},onOpen:()=>{m?.(),Z({eventName:`${C}/webSocket`,scanID:ce,connection:"open",type:"measurement_recommendation",email:k})},onClose:()=>{p?.(),Z({eventName:`${C}/webSocket`,scanID:ce,connection:"close",type:"measurement_recommendation",email:k})},onError:e=>{var t;t=e,h?.({...t,message:z(t)}),he(),O(!1),te(t),V(!1),E({eventName:`${C}/measurement_failed/fit-view`,scanID:ce,status:"failed",email:k,message:z(t)}),de&&E({eventName:`${C}/scan_completion_time`,scanID:ce,status:"failed",completionTime:$()-de,email:k}),Z({eventName:`${C}/webSocket`,scanID:ce,connection:"error",type:"measurement_recommendation",email:k})},onSuccess:e=>{Z({eventName:`${C}/webSocket`,scanID:ce,connection:"success",type:"measurement_recommendation",email:k}),ge(e)}})},ve=s(async(e,t)=>{const n=Number((e.size/1048576).toFixed(2)),a=null!=t?t:await J(e),r=Y({gender:I,focal_length:`${M}`,height:`${T}`,customer_store_url:C,clothes_fit:"0",scan_type:N,callback_url:L,source_tag:U});E({eventName:`${C}/body_scan_meta_data`,scanID:ce,email:k,data:JSON.stringify([...r,{fileSizeInMB:n,video_fps:a||0}])}),u?.();try{await A.fileUpload.uploadFileFrontend({file:e,arrayMetaData:r,scanId:ce,email:k}),await A.fileUpload.setDeviceInfo({model:P,detection:"manual",gyro:pe,scanId:ce}),console.log("video successfully uploaded"),ae(!1),E({eventName:`${C}/scan_success`,scanID:ce,status:"success",email:k,data:JSON.stringify(r)}),E({eventName:"scan finished",scanID:ce,status:"success",email:k}),me($()),setTimeout(()=>{ae(!0)},3e3)}catch(e){E({eventName:"scan finished",scanID:ce,status:"failed",email:k,message:z(e)}),E({eventName:`${C}/scan_failed`,scanID:ce,status:"failed",email:k,message:z(e),data:JSON.stringify(r)}),te(z(e)),ae(!1),h?.({...e,message:z(e)}),he()}finally{ie(!1),d?.()}},[ce,pe,u,d]),Se=s(async()=>{if(+T<152.4||+T>213.36)return void h?.({message:"Height must be between 152.4cm (5ft) and 213.36cm (7ft)"});const e=await F();e.disabled?(E({eventName:`${C}/camera_activation`,scanID:ce,status:"failed",email:k}),se(!1)):(se(!1),E({eventName:`${C}/camera_activation`,scanID:ce,status:"success",email:k})),W(e),te(""),ae(!1)},[k,ce,le,C]);return o(()=>{w||b||C&&Se()},[C,T,w,b]),o(()=>{w||b||ne&&C&&ce&&ye()},[ne,C,ce,w,b]),e("div",{"data-testid":"body-scan-root",children:e(Q,{children:e(X,{config:n,children:e(ue,{children:e(v.Provider,{value:{userDetails:x,onRetry:a,onScanError:h,isError:w,isSuccess:b,onScanSuccess:g,gender:I,scanUniqueKey:ce,scanFailsError:ee,setScanUniqueKey:le,setIsVideoUploaded:ae,isMeasurementAvailable:q,isVideoUploadedCorrect:K,loading:re,showDeniedModal:B,uploadLoading:R,setStartGyro:ie,uploadScanFile:ve,setUploadLoading:j,resetScan:fe,setScanFailsError:te,setScanStartTime:me,onScanStart:i,onCaptureComplete:c,onCustomScanSuccess:y,onComplete:S,swan:A},children:e(Ie,{})})})})})})};export{Ne as B};
2
- //# sourceMappingURL=BodyScan-C43x2o2T.js.map
@@ -1,2 +0,0 @@
1
- "use strict";var e=require("react/jsx-runtime"),t=require("react"),s=require("./Modal-BpgpPVxR.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-C57PuQgF.js.map
@@ -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 u,useRef as d}from"react";import{L as m,S as p,z as f,b as h,a as g,i as y,P as v,o as S,s as w,j as b,k as x,l as D,p as I,A as N,x as E,B as $,q as C,f as _,r as T,D as F,c as k,M,v as P,E as L,u as U,H as A,I as z,V as R,J as j,K,N as V,G as q,O,Q as B,R as W,h as H,n as G,w as J,T as Y,t as Q,C as X,y as Z}from"./Modal-CaPtqgjI.js";import ee from"react-webcam";import{X as te}from"lucide-react";import{Dialog as ne,Box as ae,Drawer as re}from"@mui/material";import se from"video.js";const oe="DESKTOP",ie="TAB",ce="MOBILE",le=i(void 0);function ue({children:t}){const[n,a]=r([window?.innerWidth,window?.innerHeight]),[s,i]=r(!1),u=()=>{a([window?.innerWidth,window?.innerHeight])};o(()=>{u()},[]),c(()=>(window.addEventListener("resize",u),()=>window.removeEventListener("resize",u)),[u]);let d=oe;n[0]>768&&n[0]<1024&&(d=ie),n[0]<768&&(d=ce);const m=l(()=>({size:n,setSize:a,clearInputs:s,setClearInputs:i,media:d}),[n,s,d]);return e(le.Provider,{value:m,children:t})}function de({resetScan:n,loadingCam:a,onUserMedia:r,onPause:s,pause:o,onReScan:i,recordingStarted:c,startSendingVideoFrames:l,showPause:d,webcamRef:y,onUserMediaError:v,resetDetector:S,videoConstraints:w,webcamKey:b,faceDone:x,isScanning:D}){const{media:I}=u(le)||{},{translate:N}=u(m)||{};return t("div",{className:"App w-screen h-[100vh] relative common-ui-main","data-testid":"camera-scan","data-scan-phase":x?"spinning":c?"pose-detecting":D?"starting":"ready",children:[e("span",{onClick:()=>{n(),S()},className:"fixed right-[20px] top-[20px] z-[999]",children:e(te,{className:"text-[#fff]"})}),e("div",{className:"w-full h-full overflow-hidden ",children:I===ce&&e(ee,{audio:!1,ref:y,screenshotQuality:1,videoConstraints:w,mirrored:!0,screenshotFormat:"image/jpeg",onUserMedia:r,onUserMediaError:v,style:{position:"fixed",top:0,left:0,right: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:[d&&e(p,{className:"!w-[180px] !h-[40px] !py-[0] mx-auto ",prefix:f,buttonText:N?.(h.pause),buttonFunc:s,btnSecondary:!0}),o?e("div",{children:e(p,{className:"!w-[180px] !h-[40px] !py-[0] mx-auto",buttonText:N?.(h.restart),buttonFunc:i,btnSecondary:!0})}):c?null:e(p,{"data-testid":"start-scan-btn",className:"!w-[180px] !h-[40px] !py-[0] mx-auto !bg-[#ffffff] !text-[#000000] "+(a?"!opacity-50":""),buttonText:N?.(h.startScan),buttonFunc:l,disabled:a})]}),e("audio",{id:"audioElement",crossOrigin:"anonymous",preload:"auto",style:{position:"absolute",zIndex:-99999},src:`${g}scanAudioInstructions/silence.mp3`})]})}let me=null,pe=null,fe=null;let he,ge=null,ye=null;var ve=a.memo(function({setIsScanLocked:t,resetDetector:n,scanID:a,setIsVideoUploaded:i,setScanFailsError:c,setScanStartTime:m,setScanUniqueKey:p,userDetails:f}){const{gender:h,heightInCm:F,email:k,shopDomain:M}=f,P=d(null),L=d(null),U=d(null),[A,z]=r([]),[R,j]=r(!0),[K,V]=r(!1),[q,O]=r(!1),[B,W]=r(!0),[H,G]=r(!1),J=d(null),[Y,Q]=r(""),[X,Z]=r([]),[ee,te]=r(""),[ne,ae]=r(!1),[re,se]=r(!1),[oe,ie]=r(!1),[ce,le]=r([]),[ue,ve]=r(!1),Se=d(!0),{poseDetector:we}=function(){const[e,t]=r(0),[n,a]=r(0),[s,i]=r(!1),c=d(0),l=d(0),u=d(!0);async function m(){if("undefined"==typeof window||"undefined"==typeof navigator)return!1;try{console.log("Starting TensorFlow preload...");const[e,t,n]=await Promise.all([import("./pose-detection.esm-DejsYGYM.js"),import("@tensorflow/tfjs-core"),import("@tensorflow/tfjs-backend-webgl")]);fe=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{pe=await fe.createDetector(fe.SupportedModels.BlazePose,a),console.log("MediaPipe detector created successfully")}catch(e){console.warn("MediaPipe failed, falling back to TFJS runtime:",e),pe=await fe.createDetector(fe.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),me=null,!1}}function p(e){return!(!e||0===e.length)&&22===e.filter(e=>e[2]>.7).length}return o(()=>{if(u.current=!0,!pe)return me||(me=m()),me.then(e=>{e&&u.current&&i(!0)}),()=>{u.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(!pe||!u.current||!n?.current?.video)return;const a=n.current.video;if(!(a.readyState<2))try{const n=await pe.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()=>{pe||me||(me=m(),await me&&u.current&&i(!0))}}}(),be=d(!0),xe=d(!1),De=d(0),Ie=d(0),Ne=d(!1),Ee=d(!1),$e=d(!1),Ce=d(()=>{}),_e=d(()=>{}),[Te,Fe]=r([]),[ke,Me]=r(0),[Pe,Le]=r(y),{setStartGyro:Ue,uploadScanFile:Ae,setUploadLoading:ze,swan:Re,onScanStart:je,onCaptureComplete:Ke}=u(v),Ve=()=>{xe.current=!1,clearTimeout(he),J.current&&clearTimeout(J.current),p(_()),c(""),ze?.(!1),z([]),U.current=null,j(!0),V(!1),O(!1),W(!0),G(!1),J.current=null,Q(""),Z([]),te(""),ae(!ne),Ue(!1),w.stopAudio(),se(!1),ie(!1),De.current=0,Ie.current=0,Ne.current=!1,$e.current=!1,null!==L.current&&L.current.stop(),ce.forEach(e=>{L.current&&L.current.removeEventListener("dataavailable",e)}),le([]),Se.current=!0,ve(!1),i(!1),P.current?.stream&&j(!1)},qe=s(()=>{setTimeout(()=>{j(!1)},1e3)},[]),Oe=s(e=>{if(console.log("camera error",e),Pe===y)return Le(S),void Me(e=>e+1);j(!1)},[Pe]),Be=s(()=>{Se.current=!1,ie(!0),ve(!1),J.current&&clearTimeout(J.current),L.current&&L.current.pause(),w.stopAudio(),Re.poseDetection.disconnect(),De.current=0,Ie.current=0,Ne.current=!1,$e.current=!1,L.current&&L.current.stop(),ce.forEach(e=>{L.current&&L.current.removeEventListener("dataavailable",e)}),le([]),clearTimeout(he)},[L,ce,w,Se]),We=l(()=>b(),[]),He=x(Te),Ge=D(He),Je=s(async()=>{Se.current=!0,await w.playAudio(`${g}SpotOn.mp3`),ie(!1),ve(!1),J.current&&clearTimeout(J.current),V(!1)},[J,w]),Ye=s(async()=>{if(!Ee.current&&!ge){Ee.current=!0;try{ge=await Re.poseDetection.connect(),I.capture(`${M}/pose_detection_connected`,{scanID:a,email:k,id:ge})}catch(e){console.log(e,"while connecting websocket")}finally{Ee.current=!1}}},[a,M,k]),Qe=s(async()=>{N({eventName:`${M}/rescan`,email:k,scanID:a,height:F,gender:h,status:!1}),Se.current=!1,Re.poseDetection.disconnect(),ge=null,Ve(),await Ye(),_e.current()},[Ye,a,k]),Xe=s(({data:e})=>{e&&e.size>0&&Se.current&&(z(t=>t.concat(e)),!xe.current&&P.current&&(xe.current=!0,we(()=>{Je(),E({eventName:`${M}/tensorFlow`,scanID:a,email:k,message:"recording stopped by tensorflow "})},P)))},[Je,E,M,a,k,P]),Ze=s(async()=>{const e=X[X.length-1];e&&Se.current&&(await w.playAudio(g+e),Se.current&&(he=setTimeout(Ze,2e3)))},[X,Se]),et=s(()=>{L&&L.current&&L.current.stop(),V(!0);try{if(P&&P.current&&P.current.stream){const e=P.current.stream.getVideoTracks()[0];if(e){const t=e.getSettings();U.current=t.frameRate||null}const t={videoBitsPerSecond:15e5};Te[0]&&(t.mimeType=Te[0]),L.current=new MediaRecorder(P.current.stream,t),L.current.addEventListener("dataavailable",Xe),L.current.addEventListener("stop",()=>{W(!0)}),le([...ce,Xe]),L.current.start(1e3),W(!1)}}catch(e){console.log("error while using media recorder",e)}},[P,Te,Xe,ce]),tt=s(async()=>{J.current&&clearTimeout(J.current),et(),Se.current&&(J.current=setTimeout(async()=>{Se.current&&(await w.playAudio(`${g}SpotOn.mp3`),V(!1))},15e3)),O(!0),Se.current&&await w.playAudio(`${g}Spin.mp3`)},[et,Se,w]);o(()=>{Ce.current=tt},[tt]);const nt="undefined"!=typeof window?window.__scanLog??[]:[],at=e=>{const t=`[${(new Date).toISOString().slice(11,23)}] [SCAN] ${e}`;console.log(t),nt.push(t)},rt=s(({data:e})=>{const t=Re.poseDetection.connected();e.size>0&&t?(Ne.current||(Ne.current=!0,at(`poseStatus listener REGISTERED | id=${ge}`),Re.poseDetection.poseStatus(async e=>{if(e&&e.audio&&e.audio.length>0){const t=document.querySelector("#audioElement"),n=e.audio?.split("/").pop(),r=t?.paused,s=t?.src?.split("/").pop()||"empty";at(`poseStatus RECEIVED | status=${e.status} | file=${n} | sid=${e.sid} | id=${ge} | sidMatch=${e.sid===ge} | counter=${De.current} | consecFalse=${Ie.current} | audioPaused=${r} | audioSrc=${s} | audioEl=${t?"found":"NULL"} | lastPlayed=${ye?.audioName?.split("/").pop()??"none"} | skipped=${ye?.no_of_times_skipped??"-"}/${ye?.skipCount??"-"}`),I.capture(`${M}/pose_instruction_received`,{scanID:a,email:k,audio:e.audio,status:e.status,sid:e.sid,counter:De.current,consecutiveFalse:Ie.current,type:"body_scan_instruction"}),!0===e.status&&e.sid===ge?(Ie.current=0,De.current<2?(De.current+=1,1!==De.current||$e.current?2===De.current&&t?.paused?(at(`PLAY good-posture-2 | file=${n}`),w.playAudio(g+e.audio)):2!==De.current||t?.paused?at(`SKIP good-posture-1 — brilliantPlayed already | counter=${De.current}`):at(`SKIP good-posture-2 — audio still playing | file=${n}`):(at(`PLAY good-posture-1 (brilliant) | file=${n}`),$e.current=!0,w.stopAudio(),await w.playAudio(g+e.audio))):(at(`TRIGGER SPIN | counter=${De.current} | file=${n}`),te(e.audio),clearTimeout(he),Re.poseDetection.disconnect(),Ne.current=!1,setTimeout(()=>Ce.current(),1e3))):!0===e.status&&e.sid!==ge?at(`SKIP good-posture — sid MISMATCH | data.sid=${e.sid} | id=${ge}`):(Ie.current+=1,Ie.current>=3&&(De.current=0,$e.current=!1,at(`RESET counter/brilliant — consecutiveFalse=${Ie.current}`)),!t?.paused||ye&&ye?.audioName===e.audio?t?.paused||ye&&ye?.audioName===e.audio?ye?.audioName===e.audio&&t?.paused?ye&&ye.no_of_times_skipped>=ye.skipCount?(ye.no_of_times_skipped=0,at(`PLAY wrong-posture REPEAT | file=${n}`),w.playAudio(g+e.audio)):(ye&&(ye.no_of_times_skipped+=1),at(`SKIP wrong-posture SAME — skip ${ye?.no_of_times_skipped}/${ye?.skipCount} | file=${n}`)):ye?.audioName!==e.audio||t?.paused||at(`SKIP wrong-posture SAME — audio still playing | file=${n}`):at(`SKIP wrong-posture NEW — audio playing | file=${n}`):(at(`PLAY wrong-posture NEW | file=${n}`),ye={skipCount:2,no_of_times_skipped:0,audioName:e.audio},w.playAudio(g+e.audio)))}})),P?.current&&null!==P.current.getScreenshot()&&Re.poseDetection.videoEmit({image:P.current.getScreenshot()||"",scanId:a})):e.size>0&&!t&&at(`handleDataAvailable — WS DISCONNECTED | id=${ge} | poseListenerRegistered=${Ne.current}`)},[P,a,Re,ge,w,M,k]),st=s(async()=>{G(!0),Ue(!0),je?.(),be.current&&(be.current=!1,E({eventName:"scan started",scanID:a,status:"success",email:k})),m($()),j(!0),Se.current&&await w.playAudio(`${g}StartScan.mp3`),Se.current&&await w.playAudio(`${g}LiftArmsAndHoldAtHip.mp3`),Se.current&&(G(!1),V(!0),se(!0),ve(!0),qe());try{if(P&&P.current&&P.current.stream&&Se.current){const e=P.current.stream.getVideoTracks()[0];if(e){const t=e.getSettings();U.current=t.frameRate||null}const t={videoBitsPerSecond:15e5};Te[0]&&(t.mimeType=Te[0]),Se.current&&(L.current=new MediaRecorder(P.current.stream,t)),Se.current&&L.current&&L.current.addEventListener("dataavailable",rt),le([...ce,rt]),L.current&&L.current.start(1e3),W(!1),Se.current&&(he=setTimeout(Ze,2e3))}}catch(e){console.log("error ----------",e)}},[P,Te,rt,ce,Ze,Se,je]);return o(()=>(M&&(t(!0),Ye()),()=>{const e=ge;ge=null,e&&(Re.poseDetection.disconnect(),I.capture(`${M}/pose_detection_disconnected`,{scanID:a,email:k,id:e})),ce.forEach(e=>{L?.current?.removeEventListener("dataavailable",e)})}),[M]),o(()=>{X.push(Y)},[Y]),o(()=>{Z([])},[ee]),o(()=>{const e=A.length&&A.length>0;B||!e||K||!Se.current||oe||L&&L.current&&(K||L.current.stop())},[B,K,A,oe]),o(()=>{const e=A.length&&A.length>0;if(B&&e&&!K&&L&&L.current&&Se.current&&!oe&&!K){const e=new File(A,`${a}.${Ge}`,{type:He});Ke?.(),ze?.(!0),c(""),Ae?.(e,U.current)}},[B,K,A,oe,L,Se]),o(()=>{_e.current=st},[st]),o(()=>{const e=C(We,T);Fe(e)},[We]),o(()=>{Ve()},[]),e(de,{resetDetector:n,resetScan:Ve,loadingCam:R,onPause:Be,showRestart:re,pause:oe,onReScan:Qe,recordingStarted:K,isScanning:H,startSendingVideoFrames:st,faceDone:q,stopRecording:Je,showPause:ue,webcamRef:P,onUserMedia:qe,onUserMediaError:Oe,videoConstraints:Pe,webcamKey:ke})});function Se({scanID:t,userDetails:n,setIsVideoUploaded:a,setScanFailsError:s,setScanStartTime:i,setScanUniqueKey:c}){const[l,u]=r(90),[m,p]=r(0),[f,h]=r(null),[g,y]=r(!1),[v,S]=r(0),w=d([]),[b,x]=r(!1),D=l-m,I=D>=80&&D<=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)),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})}},[]),o(()=>{if(w.current=[...w.current.slice(-4),D],w.current.length>=5){const e=Math.max(...w.current)-Math.min(...w.current);S(I&&e<2?e=>Math.min(100,e+10):e=>Math.max(0,e-20))}I||null===f&&!g||E()},[D,I,f,g]),o(()=>{v>=100&&null===f&&!g&&N(),v<50&&null!==f&&E()},[v,f,g]);const N=()=>{h(3);const e=setInterval(()=>{h(t=>null===t||t<=1?(clearInterval(e),y(!0),null):t-1)},1e3)},E=()=>{h(null),b||y(!1)};return e(ve,{setIsScanLocked:x,resetDetector:()=>{u(90),p(0),h(null),y(!1),S(0),x(!1),w.current=[]},scanID:t,userDetails:n,setIsVideoUploaded:a,setScanFailsError:s,setScanStartTime:i,setScanUniqueKey:c})}function we({setShowDrawer:t,config:n,loader:a}){const[i,c]=r({disabled:!1,message:""}),[l,u]=r(!0),m=d(null),p=s(async()=>{const e=await F();c(e),u(!1)},[]);return o(()=>{p()},[]),l?e(k,{url:a,loaderType:"black"}):i?.disabled?e(M,{config:n,message:i?.message}):e(ee,{audio:!1,ref:m,screenshotQuality:1,videoConstraints:P,mirrored:!0,onUserMedia:()=>t?.(!0),screenshotFormat:"image/jpeg",style:{position:"relative",top:0,bottom:0,zIndex:0,width:"100%",height:"100%",objectFit:"cover"}})}function be({link:t,onReady:n,wrapperClassName:a="[&_video]:rounded-t-[20px] w-full h-full"}){const r=d(null),s=d(null);let i={autoplay:!0,controls:!1,responsive:!0,fluid:!0,muted:!0,navigationUI:"hide",preload:"metadata",poster:L};return o(()=>{if(!s.current&&t&&r?.current){const e=se(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 xe({scanFailsError:a,onNext:s,gender:o,setScanUniqueKey:i,setIsVideoUploaded:c}){const{translate:l}=u(m)||{},d=U(),[f,g]=r(!1),y=()=>{g(!f)};return t(n,{children:[t("div",{"data-testid":"scan-error-message",className:"flex common-ui-main flex-col h-full max-w-[28rem] mx-auto w-full rounded-t-[20px] overflow-y-auto",style:{background:d?.style?.base?.backgroundColor},children:[e("div",{className:"w-full max-w-[28rem] mx-auto pt-[1rem] px-[1rem]",children:e(A,{noTitle:!0})}),e("div",{className:"flex-1",children:a&&t("div",{className:"px-[1rem]",children:[e("h2",{className:"text-center",style:{fontFamily:d?.style?.heading?.headingFontFamily||"SeriouslyNostalgic Fn",fontSize:d?.style?.heading?.headingFontSize||"32px",color:d?.style?.heading?.headingColor||"#000",fontWeight:d?.style?.heading?.headingFontWeight||"normal"},children:l?.(h.issueWithScan)}),e("p",{style:{fontFamily:d?.style?.base?.baseFontFamily||"Inter, sans-serif",fontSize:d?.style?.base?.baseFontSize||"16px",color:d?.style?.base?.baseTextColor||"#1E1E1E"},children:l?.(h.reason)}),e("p",{style:{fontFamily:d?.style?.base?.baseFontFamily||"Inter, sans-serif",fontSize:d?.style?.base?.baseFontSize||"16px",color:d?.style?.base?.baseTextColor||"#1E1E1E"},children:z(a)}),e("img",{className:"my-[0.5rem] aspect-[2/1.4] w-full object-cover",onClick:y,src:R[o],alt:"icon"})]})}),a&&e("div",{className:"p-[1rem] flex gap-[0.5rem]",children:e(p,{"data-testid":"scan-again-btn",disabled:!1,buttonText:l?.(h.scanAgain),className:"!shadow-none",buttonFunc:()=>{s?s?.():i?.(_()),c?.(!1)}})})]}),f&&t(ne,{className:"w-screen h-screen video-modal",onClose:y,open:f,children:[e("div",{className:"flex justifyEnd ",children:e("span",{className:"closeBtn",onClick:y,children:e(te,{className:"absolute right-[8px] top-[8px] text-white z-[9]"})})}),e("div",{className:"aspect-video object-cover rounded-[20px] ",children:e(be,{link:o?j[o].PRE_LINK:j.male.PRE_LINK,wrapperClassName:"w-screen h-screen fixed top-[0] left-[0]"})})]})]})}function De({scanId:n,userDetails:a,config:i,isVideoUploadedCorrect:c,isMeasurementAvailable:l,onComplete:d,isSuccess:f,onCustomScanSuccess:g,swan:y}){const{gender:v,shopDomain:S,heightInCm:w,deviceFocalLength:b,userName:x,email:D,scanType:N}=a||{},E=[O,B,W].includes(N??""),[$,C]=r(!0),_=s(async()=>{try{E&&(await(y?.auth.addUser({scanId:n,email:D,name:x,gender:v,height:w})),g?.()),I.capture(S??"",{scanID:n,email:D,height:w,focalLength:b,clothesFit:"0",gender:v})}catch(e){console.log(e)}},[E]),{translate:T}=u(m)||{};o(()=>{(c||l)&&_()},[c,l]);const F=f||c||l;return e(ae,{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(we,{loader:i?.loader,setShowDrawer:C}),e(re,{open:$,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(A,{title:T?.(h.measurementsBeingTaken)}),e("div",{className:"flex items-center justify-center flex-1",children:e("video",{preload:"auto",className:"max-h-[calc(100vh-450px)] mx-auto w-full object-contain border-none",muted:!0,loop:!0,autoPlay:!0,playsInline:!0,children:e("source",{src:v===q.Male?K:V,type:"video/mp4"})})}),F&&e(p,{className:"!w-[180px] mx-auto",buttonText:T?.(h.next),buttonFunc:()=>{d?.()}})]})})})]})})}const Ie=()=>{const{userDetails:n,onRetry:a,isError:r,isSuccess:s,gender:o,scanUniqueKey:i,scanFailsError:c,setScanUniqueKey:l,setIsVideoUploaded:d,isMeasurementAvailable:m,isVideoUploadedCorrect:p,loading:f,showDeniedModal:h,uploadLoading:g,setScanFailsError:y,setScanStartTime:S,resetScan:w,onCustomScanSuccess:b,swan:x,onComplete:D}=u(v),I=U();return r?t("div",{"data-scan-state":"error",children:[e(we,{}),e(re,{anchor:"bottom",open:!0,className:"camera-drawer",onClose:(e,t)=>{},children:e(xe,{scanFailsError:!0,onNext:a,gender:o})})]}):s?e("div",{"data-scan-state":"success",children:e(De,{isSuccess:!0,onComplete:D})}):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:I?.style?.base?.backgroundColor},children:e(k,{url:I?.loader,loaderType:"black"})}):h.disabled?e("div",{"data-scan-state":"camera-denied",children:e(M,{})}):g||c||m||p?(g||m||p)&&!c?e("div",{"data-scan-state":"processing",children:e(De,{scanId:i,isMeasurementAvailable:m,userDetails:n,isVideoUploadedCorrect:p,onCustomScanSuccess:b,swan:x,onComplete:D})}):t("div",{"data-scan-state":"error-retry",children:[e(we,{}),e(re,{anchor:"bottom",open:!0,className:"camera-drawer",onClose:(e,t)=>{},children:e(xe,{scanFailsError:c,onNext:()=>{a?.(),w()},setScanUniqueKey:l,gender:o,setIsVideoUploaded:d})})]}):e("div",{"data-scan-state":"scanning",children:e(Se,{scanID:i,userDetails:n,setIsVideoUploaded:d,setScanFailsError:y,setScanStartTime:S,setScanUniqueKey:l})})},Ne=t=>{const{config:n,onRetry:a,onScanStart:i,onCaptureComplete:c,onUploadStart:u,onUploadEnd:d,onMeasurementSocketStart:m,onMeasurementSocketClose:p,onIntermediateScanSuccess:f,onScanError:h,onScanSuccess:g,onCustomScanSuccess:y,onComplete:S,isError:w,isSuccess:b}=t,x={email:"",shopDomain:"",gender:"male",heightInCm:0,scanType:"",deviceFocalLength:0,deviceModelName:"",sourceTag:"",callbackUrl:null,...t.userDetails??{}},D=t.token??"",{gender:I,scanType:N,shopDomain:C,heightInCm:T,email:k,deviceFocalLength:M,deviceModelName:P,callbackUrl:L,sourceTag:U}=x,A=l(()=>H(D),[D]),[R,j]=r(!1),[K,V]=r(!1),[q,O]=r(!1),[B,W]=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($()),{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);G();const fe=s(()=>{le(_()),te(""),j(!1),ae(!1)},[]),he=()=>{me(null),le("")},ge=s(async e=>{if(e&&"success"===e?.scanStatus&&"intermediate"===e?.resultType&&200===e?.code)return E({eventName:`${C}/measurement_success/intermediate`,scanID:ce,status:"success",email:k}),V(!0),void f?.(e);g?.(e),V(!0),he();const t=ce;O(!0),E({eventName:`${C}/measurement_success/fit-view`,scanID:t,status:"success",email:k}),de&&E({eventName:`${C}/scan_completion_time`,scanID:t,status:"success",completionTime:$()-de,email:k})},[N,C,ce]),ye=e=>{O(!1),te(""),V(!1),A.measurement.handleMeasurementSocket({scanId:ce,onPreopen:()=>{Z({eventName:`${C}/webSocket`,scanID:ce,connection:"pre_open",type:"measurement_recommendation",email:k})},onOpen:()=>{m?.(),Z({eventName:`${C}/webSocket`,scanID:ce,connection:"open",type:"measurement_recommendation",email:k})},onClose:()=>{p?.(),Z({eventName:`${C}/webSocket`,scanID:ce,connection:"close",type:"measurement_recommendation",email:k})},onError:e=>{var t;t=e,h?.({...t,message:z(t)}),he(),O(!1),te(t),V(!1),E({eventName:`${C}/measurement_failed/fit-view`,scanID:ce,status:"failed",email:k,message:z(t)}),de&&E({eventName:`${C}/scan_completion_time`,scanID:ce,status:"failed",completionTime:$()-de,email:k}),Z({eventName:`${C}/webSocket`,scanID:ce,connection:"error",type:"measurement_recommendation",email:k})},onSuccess:e=>{Z({eventName:`${C}/webSocket`,scanID:ce,connection:"success",type:"measurement_recommendation",email:k}),ge(e)}})},ve=s(async(e,t)=>{const n=Number((e.size/1048576).toFixed(2)),a=null!=t?t:await J(e),r=Y({gender:I,focal_length:`${M}`,height:`${T}`,customer_store_url:C,clothes_fit:"0",scan_type:N,callback_url:L,source_tag:U});E({eventName:`${C}/body_scan_meta_data`,scanID:ce,email:k,data:JSON.stringify([...r,{fileSizeInMB:n,video_fps:a||0}])}),u?.();try{await A.fileUpload.uploadFileFrontend({file:e,arrayMetaData:r,scanId:ce,email:k}),await A.fileUpload.setDeviceInfo({model:P,detection:"manual",gyro:pe,scanId:ce}),console.log("video successfully uploaded"),ae(!1),E({eventName:`${C}/scan_success`,scanID:ce,status:"success",email:k,data:JSON.stringify(r)}),E({eventName:"scan finished",scanID:ce,status:"success",email:k}),me($()),setTimeout(()=>{ae(!0)},3e3)}catch(e){E({eventName:"scan finished",scanID:ce,status:"failed",email:k,message:z(e)}),E({eventName:`${C}/scan_failed`,scanID:ce,status:"failed",email:k,message:z(e),data:JSON.stringify(r)}),te(z(e)),ae(!1),h?.({...e,message:z(e)}),he()}finally{ie(!1),d?.()}},[ce,pe,u,d]),Se=s(async()=>{if(+T<152.4||+T>213.36)return void h?.({message:"Height must be between 152.4cm (5ft) and 213.36cm (7ft)"});const e=await F();e.disabled?(E({eventName:`${C}/camera_activation`,scanID:ce,status:"failed",email:k}),se(!1)):(se(!1),E({eventName:`${C}/camera_activation`,scanID:ce,status:"success",email:k})),W(e),te(""),ae(!1)},[k,ce,le,C]);return o(()=>{w||b||C&&Se()},[C,T,w,b]),o(()=>{w||b||ne&&C&&ce&&ye()},[ne,C,ce,w,b]),e("div",{"data-testid":"body-scan-root",children:e(Q,{children:e(X,{config:n,children:e(ue,{children:e(v.Provider,{value:{userDetails:x,onRetry:a,onScanError:h,isError:w,isSuccess:b,onScanSuccess:g,gender:I,scanUniqueKey:ce,scanFailsError:ee,setScanUniqueKey:le,setIsVideoUploaded:ae,isMeasurementAvailable:q,isVideoUploadedCorrect:K,loading:re,showDeniedModal:B,uploadLoading:R,setStartGyro:ie,uploadScanFile:ve,setUploadLoading:j,resetScan:fe,setScanFailsError:te,setScanStartTime:me,onScanStart:i,onCaptureComplete:c,onCustomScanSuccess:y,onComplete:S,swan:A},children:e(Ie,{})})})})})})};export{Ne as B};
2
- //# sourceMappingURL=BodyScan-C9hQU-dK.js.map