@vincentt-xr/sdk 2.0.0-alpha.1 → 2.0.0-alpha.11

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 (885) hide show
  1. package/GROUNDING.md +8066 -120
  2. package/README.md +86 -52
  3. package/dist/CanonicalHeadFrame-CZFvPzN_.cjs +1 -0
  4. package/dist/CanonicalHeadFrame-vn-jM9fG.js +1506 -0
  5. package/dist/DebuggerUI-DDpU-nBF.js +275 -0
  6. package/dist/DebuggerUI-Db-1VtQJ.cjs +1 -0
  7. package/dist/FaceRetouch-D2xH5OpW.js +1071 -0
  8. package/dist/FaceRetouch-DHhn1nSV.cjs +134 -0
  9. package/dist/FaceSurface-CHAMEeG1.cjs +1 -0
  10. package/dist/FaceSurface-DmP9AEeC.js +27 -0
  11. package/dist/SkeletonUtils-C2r90MtN.js +21 -0
  12. package/dist/SkeletonUtils-CddIup1F.cjs +1 -0
  13. package/dist/TextLabel-Ctp-a7g9.cjs +2 -0
  14. package/dist/TextLabel-Dgt-uNN9.js +984 -0
  15. package/dist/assets/cache.d.ts +99 -0
  16. package/dist/assets/estimate.d.ts +11 -0
  17. package/dist/assets/gltfLoader.d.ts +16 -0
  18. package/dist/assets/index.d.ts +7 -0
  19. package/dist/assets/loaders.d.ts +43 -0
  20. package/dist/assets/react.d.ts +33 -0
  21. package/dist/assets/sdkModels.d.ts +22 -0
  22. package/dist/audio/AudioEngine.d.ts +3 -1
  23. package/dist/audio/AudioPlayer.d.ts +29 -0
  24. package/dist/audio/AudioPlayerLogic.d.ts +4 -0
  25. package/dist/audio/index.d.ts +2 -0
  26. package/dist/body/__fixtures__/syntheticRig.d.ts +21 -0
  27. package/dist/body/bodyFlipGuard.d.ts +39 -0
  28. package/dist/body/bodyIdentity.d.ts +72 -0
  29. package/dist/body/bodyMask.d.ts +79 -0
  30. package/dist/body/bodyMaskMaterial.d.ts +15 -0
  31. package/dist/body/bodyPose.d.ts +58 -0
  32. package/dist/body/bodyRigFit.d.ts +148 -0
  33. package/dist/body/bodyRigSolver.d.ts +114 -0
  34. package/dist/body/bodySubject.d.ts +46 -0
  35. package/dist/body-pose/index.d.ts +521 -0
  36. package/dist/body-trigger/__fixtures__/syntheticBody.d.ts +83 -0
  37. package/dist/body-trigger/frame.d.ts +88 -0
  38. package/dist/body-trigger/index.d.ts +6 -0
  39. package/dist/body-trigger/moves.d.ts +235 -0
  40. package/dist/body-trigger/trigger.d.ts +75 -0
  41. package/dist/bodyMaskMaterial-C3aXItLo.js +207 -0
  42. package/dist/bodyMaskMaterial-Q6rYywwW.cjs +68 -0
  43. package/dist/cache-C85JjyZA.js +212 -0
  44. package/dist/cache-DFqZYsHC.cjs +1 -0
  45. package/dist/calibration/calibration.d.ts +75 -0
  46. package/dist/calibration/index.d.ts +6 -0
  47. package/dist/calibration/storage.d.ts +13 -0
  48. package/dist/calibration/types.d.ts +53 -0
  49. package/dist/calibration/useXRCalibration.d.ts +46 -0
  50. package/dist/camera/CameraPermissionGate.d.ts +26 -0
  51. package/dist/camera/devices.d.ts +26 -0
  52. package/dist/camera/index.d.ts +8 -0
  53. package/dist/camera/permission.d.ts +86 -0
  54. package/dist/camera/useCameraPermission.d.ts +35 -0
  55. package/dist/canonicalFace-BHwyCx1c.js +9 -0
  56. package/dist/canonicalFace-C83I225R.cjs +1 -0
  57. package/dist/capabilities/detect.d.ts +45 -0
  58. package/dist/capabilities/index.d.ts +5 -0
  59. package/dist/capabilities/types.d.ts +120 -0
  60. package/dist/capabilities/useXRCapabilities.d.ts +18 -0
  61. package/dist/compat/environment.d.ts +5 -0
  62. package/dist/compat/index.d.ts +4 -0
  63. package/dist/compat/run.d.ts +18 -0
  64. package/dist/compat/scenarios.d.ts +10 -0
  65. package/dist/compat/types.d.ts +101 -0
  66. package/dist/components/Axes/index.d.ts +6 -0
  67. package/dist/components/BodyInstruction/BodyPoseHint.d.ts +63 -0
  68. package/dist/components/BodyInstruction/index.d.ts +76 -0
  69. package/dist/components/BodyInstruction/useBodyPose.d.ts +30 -0
  70. package/dist/components/BodyRig/BodyAttachment.d.ts +28 -0
  71. package/dist/components/BodyRig/BodyOccluder.d.ts +27 -0
  72. package/dist/components/BodyRig/bodyDepth.d.ts +57 -0
  73. package/dist/components/BodyRig/index.d.ts +129 -0
  74. package/dist/components/BodyRig/useBodyDepthTexture.d.ts +40 -0
  75. package/dist/components/BodyTracker/index.d.ts +26 -1
  76. package/dist/components/BodyTrigger/index.d.ts +56 -0
  77. package/dist/components/Debugger/DebuggerProvider.d.ts +14 -1
  78. package/dist/components/Debugger/DebuggerUI.d.ts +3 -1
  79. package/dist/components/FaceAtlas/FaceAtlasLayer.d.ts +114 -0
  80. package/dist/components/FaceAtlas/MadeUpCamera.d.ts +80 -0
  81. package/dist/components/FaceAtlas/constants.d.ts +8 -0
  82. package/dist/components/FaceAtlas/index.d.ts +7 -0
  83. package/dist/components/FaceAtlas/useFaceAtlasSurface.d.ts +84 -0
  84. package/dist/components/FaceAtlas/useFaceSkin.d.ts +84 -0
  85. package/dist/components/FaceCharacter/ExternalFaceMesh.d.ts +109 -0
  86. package/dist/components/FaceCharacter/FaceExpressionController.d.ts +53 -0
  87. package/dist/components/FaceCharacter/FaceMorph.d.ts +71 -0
  88. package/dist/components/FaceCharacter/FacePiercing.d.ts +65 -0
  89. package/dist/components/FaceCharacter/FaceReprojection.d.ts +85 -0
  90. package/dist/components/FaceCharacter/FaceRig.d.ts +38 -0
  91. package/dist/components/FaceCharacter/FaceSurface.d.ts +49 -0
  92. package/dist/components/FaceCharacter/FaceSurfaceOccluder.d.ts +39 -0
  93. package/dist/components/FaceCharacter/PinToFaceMesh.d.ts +68 -0
  94. package/dist/components/FaceCharacter/index.d.ts +18 -0
  95. package/dist/components/FaceCharacter/useFaceReprojector.d.ts +10 -0
  96. package/dist/components/FaceInset/FaceInset.d.ts +68 -0
  97. package/dist/components/FaceInset/frame.d.ts +94 -0
  98. package/dist/components/FaceInset/index.d.ts +6 -0
  99. package/dist/components/FaceInset/material.d.ts +40 -0
  100. package/dist/components/FaceInset/useFaceInsetTexture.d.ts +37 -0
  101. package/dist/components/FaceInstruction/FaceExpressionHint.d.ts +43 -0
  102. package/dist/components/FaceInstruction/index.d.ts +56 -0
  103. package/dist/components/FaceInstruction/useFaceExpression.d.ts +20 -0
  104. package/dist/components/FaceLiquify/FaceLiquify.d.ts +49 -0
  105. package/dist/components/FaceLiquify/debug.d.ts +37 -0
  106. package/dist/components/FaceLiquify/frame.d.ts +55 -0
  107. package/dist/components/FaceLiquify/index.d.ts +10 -0
  108. package/dist/components/FaceLiquify/material.d.ts +39 -0
  109. package/dist/components/FaceLiquify/pass.d.ts +49 -0
  110. package/dist/components/FaceLiquify/presence.d.ts +25 -0
  111. package/dist/components/FaceLiquify/presets.d.ts +82 -0
  112. package/dist/components/FaceLiquify/selfTest.d.ts +66 -0
  113. package/dist/components/FaceLiquify/target.d.ts +85 -0
  114. package/dist/components/FaceLiquify/warp.d.ts +72 -0
  115. package/dist/components/FaceMesh/FaceMeshRenderer.d.ts +25 -0
  116. package/dist/components/FaceMesh/canonical/CanonicalFaceMeshRenderer.d.ts +67 -3
  117. package/dist/components/FaceMesh/canonical/FaceMeshMaterial.d.ts +25 -0
  118. package/dist/components/FaceMesh/canonical/assets.d.ts +3 -0
  119. package/dist/components/FaceMesh/canonical/geometryGroups.d.ts +30 -0
  120. package/dist/components/FaceMesh/canonical/parseCanonicalFaceModel.d.ts +24 -0
  121. package/dist/components/FaceMesh/canonical/shaders.d.ts +2 -0
  122. package/dist/components/FaceMesh/deform.d.ts +3 -0
  123. package/dist/components/FaceMesh/index.d.ts +6 -1
  124. package/dist/components/FaceMesh/material/defaults.d.ts +70 -0
  125. package/dist/components/FaceMesh/material/index.d.ts +1 -0
  126. package/dist/components/FaceMesh/material/options.d.ts +5 -1
  127. package/dist/components/FaceMesh/material/support.d.ts +7 -2
  128. package/dist/components/FaceMesh/material/textures.d.ts +4 -0
  129. package/dist/components/FaceMesh/material/types.d.ts +2 -2
  130. package/dist/components/FaceRetouch/Background.d.ts +7 -6
  131. package/dist/components/FaceRetouch/FaceRetouch.d.ts +52 -0
  132. package/dist/components/FaceRetouch/index.d.ts +2 -8
  133. package/dist/components/FaceRetouch/landmarkMask.d.ts +0 -5
  134. package/dist/components/FaceRetouch/renderState.d.ts +19 -0
  135. package/dist/components/FaceRetouch/useFaceRetouchMask.d.ts +3 -7
  136. package/dist/components/FaceSwap/FaceMirror.d.ts +46 -0
  137. package/dist/components/FaceSwap/FaceSwap.d.ts +58 -0
  138. package/dist/components/FaceSwap/FaceTextureLayer.d.ts +72 -0
  139. package/dist/components/FaceSwap/faceSwapPlan.d.ts +91 -0
  140. package/dist/components/FaceSwap/index.d.ts +13 -0
  141. package/dist/components/FaceSwap/settings.d.ts +300 -0
  142. package/dist/components/FaceSwap/useFaceTexture.d.ts +35 -0
  143. package/dist/components/FaceSwap/useLiveFace.d.ts +38 -0
  144. package/dist/components/FaceSwap/useLiveFaceTexture.d.ts +31 -0
  145. package/dist/components/FaceTracker/index.d.ts +5 -3
  146. package/dist/components/FaceWarp3D/FaceWarp3D.d.ts +50 -0
  147. package/dist/components/FaceWarp3D/index.d.ts +2 -3
  148. package/dist/components/Faceless/Faceless.d.ts +51 -0
  149. package/dist/components/Faceless/index.d.ts +2 -0
  150. package/dist/components/GestureListener/index.d.ts +11 -0
  151. package/dist/components/HairLock/HairLock.d.ts +39 -0
  152. package/dist/components/HairLock/index.d.ts +2 -0
  153. package/dist/components/HairLock/lockGeometry.d.ts +15 -0
  154. package/dist/components/HandCutout/index.d.ts +35 -0
  155. package/dist/components/HandEffect/index.d.ts +36 -0
  156. package/dist/components/HandInstruction/HandGestureHint.d.ts +70 -0
  157. package/dist/components/HandInstruction/index.d.ts +74 -0
  158. package/dist/components/HandInstruction/useHandGesture.d.ts +22 -0
  159. package/dist/components/HandJoints2D/index.d.ts +1 -1
  160. package/dist/components/HandRig/ForearmOccluder.d.ts +29 -0
  161. package/dist/components/HandRig/HandAttachment.d.ts +34 -0
  162. package/dist/components/HandRig/HandNails.d.ts +61 -0
  163. package/dist/components/HandRig/HandOccluder.d.ts +45 -0
  164. package/dist/components/HandRig/HandTattoo.d.ts +61 -0
  165. package/dist/components/HandRig/WristAttachment.d.ts +34 -0
  166. package/dist/components/HandRig/index.d.ts +127 -0
  167. package/dist/components/HandRig/useArmMask.d.ts +29 -0
  168. package/dist/components/HandRig/wristSolve.d.ts +96 -0
  169. package/dist/components/HandTouch/HandTouch.d.ts +62 -0
  170. package/dist/components/HandTouch/Touchable.d.ts +36 -0
  171. package/dist/components/HandTouch/index.d.ts +2 -0
  172. package/dist/components/HandTracker/index.d.ts +10 -0
  173. package/dist/components/HandTracking2D/HandVisual.d.ts +1 -1
  174. package/dist/components/HandTracking2D/index.d.ts +1 -1
  175. package/dist/components/HandTracking2DController/index.d.ts +1 -1
  176. package/dist/components/HandTracking3D/index.d.ts +1 -1
  177. package/dist/components/HeadBinding/index.d.ts +14 -0
  178. package/dist/components/HeadOccluder/CanonicalHeadFrame.d.ts +22 -0
  179. package/dist/components/HeadOccluder/Earrings.d.ts +55 -0
  180. package/dist/components/HeadOccluder/HeadAttachment.d.ts +38 -0
  181. package/dist/components/HeadOccluder/NeckOccluder.d.ts +67 -0
  182. package/dist/components/HeadOccluder/earringPlacement.d.ts +31 -0
  183. package/dist/components/HeadOccluder/headAttachmentPoints.d.ts +69 -0
  184. package/dist/components/HeadOccluder/index.d.ts +57 -3
  185. package/dist/components/HeadOccluder/useCanonicalHeadFit.d.ts +36 -0
  186. package/dist/components/HeadOccluder/useLandmarkPoseFit.d.ts +80 -0
  187. package/dist/components/HolisticTracker/index.d.ts +69 -0
  188. package/dist/components/HolisticTracker/settings.d.ts +58 -0
  189. package/dist/components/HolisticTracker/signals.d.ts +49 -0
  190. package/dist/components/Instruction/HintStage.d.ts +29 -0
  191. package/dist/components/Instruction/InstructionCue.d.ts +126 -0
  192. package/dist/components/Instruction/gestureHold.d.ts +20 -0
  193. package/dist/components/Instruction/ghost.d.ts +129 -0
  194. package/dist/components/Instruction/hintBlend.d.ts +19 -0
  195. package/dist/components/Instruction/hintLook.d.ts +81 -0
  196. package/dist/components/Instruction/hintLoop.d.ts +36 -0
  197. package/dist/components/Instruction/index.d.ts +41 -0
  198. package/dist/components/Instruction/useGhostModel.d.ts +33 -0
  199. package/dist/components/Instruction/useInstructionHold.d.ts +72 -0
  200. package/dist/components/IrisEffect/IrisMaterial.d.ts +73 -0
  201. package/dist/components/IrisEffect/index.d.ts +51 -0
  202. package/dist/components/IrisEffect/settings.d.ts +117 -0
  203. package/dist/components/LightObject/index.d.ts +20 -0
  204. package/dist/components/LipEffect/LipEffect.d.ts +28 -0
  205. package/dist/components/LipEffect/LipEffectMaterial.d.ts +98 -0
  206. package/dist/components/LipEffect/LipEffects.d.ts +12 -0
  207. package/dist/components/LipEffect/defaults.d.ts +51 -0
  208. package/dist/components/LipEffect/index.d.ts +12 -0
  209. package/dist/components/LipEffect/lipShading.d.ts +73 -0
  210. package/dist/components/LipEffect/settings.d.ts +375 -0
  211. package/dist/components/LipEffect/shader.d.ts +39 -0
  212. package/dist/components/LipEffect/types.d.ts +141 -0
  213. package/dist/components/LipEffect/useLipDesignTextures.d.ts +17 -0
  214. package/dist/components/LipEffect/uvGuide.d.ts +74 -0
  215. package/dist/components/LookAt/index.d.ts +23 -0
  216. package/dist/components/Makeup/Blush.d.ts +18 -0
  217. package/dist/components/Makeup/Brows.d.ts +20 -0
  218. package/dist/components/Makeup/Contour.d.ts +17 -0
  219. package/dist/components/Makeup/Eyeliner.d.ts +20 -0
  220. package/dist/components/Makeup/Eyeshadow.d.ts +20 -0
  221. package/dist/components/Makeup/Highlighter.d.ts +18 -0
  222. package/dist/components/Makeup/MakeupDesign.d.ts +37 -0
  223. package/dist/components/Makeup/MakeupRegion.d.ts +132 -0
  224. package/dist/components/Makeup/constants.d.ts +44 -0
  225. package/dist/components/Makeup/design.d.ts +106 -0
  226. package/dist/components/Makeup/designSamples.d.ts +42 -0
  227. package/dist/components/Makeup/eyes.d.ts +114 -0
  228. package/dist/components/Makeup/fields.d.ts +10 -0
  229. package/dist/components/Makeup/geometry.d.ts +106 -0
  230. package/dist/components/Makeup/index.d.ts +26 -0
  231. package/dist/components/Makeup/looks.d.ts +28 -0
  232. package/dist/components/Makeup/material.d.ts +239 -0
  233. package/dist/components/Makeup/settings.d.ts +54 -0
  234. package/dist/components/Makeup/shades.d.ts +143 -0
  235. package/dist/components/Makeup/shapes.d.ts +27 -0
  236. package/dist/components/Makeup/skinTone.d.ts +135 -0
  237. package/dist/components/Makeup/types.d.ts +110 -0
  238. package/dist/components/Makeup/useMakeupSkinTone.d.ts +40 -0
  239. package/dist/components/MeshRenderer/index.d.ts +59 -0
  240. package/dist/components/Necklace/Necklace.d.ts +44 -0
  241. package/dist/components/Necklace/index.d.ts +1 -0
  242. package/dist/components/ParticleEmitter/ParticleEmitter.d.ts +69 -0
  243. package/dist/components/ParticleEmitter/index.d.ts +1 -0
  244. package/dist/components/PersonCutout/index.d.ts +46 -0
  245. package/dist/components/PersonCutout/personCutout.d.ts +16 -0
  246. package/dist/components/PersonCutout/personMask.d.ts +19 -0
  247. package/dist/components/PersonCutout/useBodyMaskTexture.d.ts +35 -0
  248. package/dist/components/PerspectiveCamera/index.d.ts +2 -8
  249. package/dist/components/PinToMesh/index.d.ts +47 -0
  250. package/dist/components/RenderGroupLayer/index.d.ts +6 -0
  251. package/dist/components/SceneObjectRenderer/index.d.ts +23 -0
  252. package/dist/components/Screen2D/ScreenTransformFrame.d.ts +11 -0
  253. package/dist/components/Screen2D/ScreenTransformHelpers.d.ts +19 -0
  254. package/dist/components/Screen2D/ScreenTransformInteraction.d.ts +18 -0
  255. package/dist/components/Screen2D/index.d.ts +5 -0
  256. package/dist/components/ScreenGlass/defaults.d.ts +3 -0
  257. package/dist/components/ScreenGlass/index.d.ts +5 -0
  258. package/dist/components/ScreenGlass/shaders.d.ts +2 -0
  259. package/dist/components/ScreenGlass/types.d.ts +10 -0
  260. package/dist/components/ScreenGradient/defaults.d.ts +5 -0
  261. package/dist/components/ScreenGradient/index.d.ts +5 -0
  262. package/dist/components/ScreenGradient/shaders.d.ts +2 -0
  263. package/dist/components/ScreenGradient/types.d.ts +19 -0
  264. package/dist/components/ScreenImage/ScreenImage.d.ts +7 -0
  265. package/dist/components/ScreenImage/components/DynamicTextureSync.d.ts +9 -0
  266. package/dist/components/ScreenImage/components/ScreenImageBody.d.ts +9 -0
  267. package/dist/components/ScreenImage/components/ScreenImageFrame.d.ts +9 -0
  268. package/dist/components/ScreenImage/components/ScreenImageTransformFrame.d.ts +9 -0
  269. package/dist/components/ScreenImage/fit.d.ts +52 -0
  270. package/dist/components/ScreenImage/index.d.ts +10 -87
  271. package/dist/components/ScreenImage/materials/ScreenImageBlendMaterial.d.ts +9 -0
  272. package/dist/components/ScreenImage/materials/ScreenImageMaskMaterial.d.ts +11 -0
  273. package/dist/components/ScreenImage/materials/ScreenImageMatcap.d.ts +3 -0
  274. package/dist/components/ScreenImage/source.d.ts +25 -0
  275. package/dist/components/ScreenImage/types.d.ts +64 -0
  276. package/dist/components/ScreenImage/utils/ScreenImageConstants.d.ts +9 -0
  277. package/dist/components/ScreenImage/utils/ScreenImageHelpers.d.ts +4 -0
  278. package/dist/components/ScreenShape/geometry.d.ts +5 -0
  279. package/dist/components/ScreenShape/index.d.ts +8 -0
  280. package/dist/components/ScreenShape/types.d.ts +54 -0
  281. package/dist/components/ScreenSpaceUI/ScreenTransformGuide.d.ts +15 -0
  282. package/dist/components/ScreenSpaceUI/ScreenTransformOverlayGuide.d.ts +9 -0
  283. package/dist/components/ScreenSpaceUI/index.d.ts +3 -0
  284. package/dist/components/ScreenText/components/ScreenTextBody.d.ts +2 -0
  285. package/dist/components/ScreenText/components/ScreenTextTransformFrame.d.ts +9 -0
  286. package/dist/components/ScreenText/constants.d.ts +5 -0
  287. package/dist/components/ScreenText/index.d.ts +9 -20
  288. package/dist/components/ScreenText/types.d.ts +31 -0
  289. package/dist/components/ScreenText/utils/ScreenTextHelpers.d.ts +14 -0
  290. package/dist/components/ScreenText/utils/ScreenTextMappings.d.ts +17 -0
  291. package/dist/components/SegmentationOverlay/SegmentationOverlay.d.ts +37 -0
  292. package/dist/components/SegmentationOverlay/SegmentationOverlayMaterial.d.ts +31 -0
  293. package/dist/components/SegmentationOverlay/index.d.ts +9 -0
  294. package/dist/components/SegmentationOverlay/maskTexture.d.ts +23 -0
  295. package/dist/components/SegmentationOverlay/providers.d.ts +72 -0
  296. package/dist/components/SegmentationOverlay/settings.d.ts +65 -0
  297. package/dist/components/SequentialRenderPasses/index.d.ts +6 -0
  298. package/dist/components/ShoulderOccluder/index.d.ts +46 -0
  299. package/dist/components/ShoulderOccluder/useCanonicalTorsoFit.d.ts +27 -0
  300. package/dist/components/SpringSwing/SpringSwing.d.ts +22 -0
  301. package/dist/components/SpringSwing/index.d.ts +1 -0
  302. package/dist/components/TextLabel/TextLabel.d.ts +5 -0
  303. package/dist/components/TextLabel/alignment.d.ts +4 -0
  304. package/dist/components/TextLabel/bend.d.ts +9 -0
  305. package/dist/components/TextLabel/canvas/buildTextLabelTexture.d.ts +4 -0
  306. package/dist/components/TextLabel/canvas/canvasTypography.d.ts +13 -0
  307. package/dist/components/TextLabel/canvas/drawBackground.d.ts +21 -0
  308. package/dist/components/TextLabel/canvas/drawEffects.d.ts +34 -0
  309. package/dist/components/TextLabel/canvas/drawText.d.ts +19 -0
  310. package/dist/components/TextLabel/components/TextLabelMesh.d.ts +13 -0
  311. package/dist/components/TextLabel/constants.d.ts +2 -0
  312. package/dist/components/TextLabel/hooks/useTextLabelTexture.d.ts +7 -0
  313. package/dist/components/TextLabel/index.d.ts +2 -161
  314. package/dist/components/TextLabel/layout/measurement.d.ts +8 -0
  315. package/dist/components/TextLabel/layout/resolveTextLayout.d.ts +25 -0
  316. package/dist/components/TextLabel/layout/wrapText.d.ts +6 -0
  317. package/dist/components/TextLabel/types.d.ts +337 -0
  318. package/dist/components/TrackingAnchor/index.d.ts +18 -2
  319. package/dist/components/Transform3D/index.d.ts +30 -0
  320. package/dist/components/XRMediaSurface/index.d.ts +8 -7
  321. package/dist/components/XRProvider/index.d.ts +16 -2
  322. package/dist/components/XRScene/renderOutputTarget.d.ts +12 -0
  323. package/dist/components/XRViewport/XRViewport.d.ts +11 -0
  324. package/dist/components/XRViewport/components/HiddenMedia.d.ts +7 -0
  325. package/dist/components/XRViewport/components/MediaAssetPicker.d.ts +8 -0
  326. package/dist/components/XRViewport/components/MediaControlStack.d.ts +13 -0
  327. package/dist/components/XRViewport/components/XRViewportLayers.d.ts +30 -0
  328. package/dist/components/XRViewport/constants.d.ts +24 -0
  329. package/dist/components/XRViewport/contexts.d.ts +6 -0
  330. package/dist/components/XRViewport/hooks/useViewportExternalFaces.d.ts +13 -0
  331. package/dist/components/XRViewport/hooks/useViewportMediaSource.d.ts +16 -0
  332. package/dist/components/XRViewport/hooks/useViewportMediaTexture.d.ts +10 -0
  333. package/dist/components/XRViewport/hooks/useViewportPipeline.d.ts +41 -0
  334. package/dist/components/XRViewport/hooks/useViewportRenderState.d.ts +47 -0
  335. package/dist/components/XRViewport/index.d.ts +3 -118
  336. package/dist/components/XRViewport/layout.d.ts +16 -0
  337. package/dist/components/XRViewport/slots.d.ts +16 -0
  338. package/dist/components/XRViewport/types.d.ts +89 -0
  339. package/dist/components/XRViewport/useViewportSize.d.ts +3 -0
  340. package/dist/components/index.d.ts +24 -0
  341. package/dist/components/occluder/skinnedOccluder.d.ts +39 -0
  342. package/dist/config/index.d.ts +1 -1
  343. package/dist/constants/index.d.ts +4 -1
  344. package/dist/context-DTxSQvp4.js +13 -0
  345. package/dist/context-hA0Rb2Xa.cjs +1 -0
  346. package/dist/contexts-B5GODwuV.js +667 -0
  347. package/dist/contexts-CSz9stBV.cjs +1 -0
  348. package/dist/coordinates/feed.d.ts +52 -0
  349. package/dist/coordinates/index.d.ts +7 -0
  350. package/dist/coordinates/side.d.ts +40 -0
  351. package/dist/coordinates/spaces.d.ts +49 -0
  352. package/dist/coordinates/viewport.d.ts +32 -0
  353. package/dist/coordinates/world.d.ts +15 -0
  354. package/dist/debug-ui/component-editor/index.d.ts +19 -0
  355. package/dist/debug-ui/default-setting.cjs +2 -2
  356. package/dist/debug-ui/face-mesh-renderer-settings/index.d.ts +8 -0
  357. package/dist/debug-ui/face-retouch/index.d.ts +11 -0
  358. package/dist/debug-ui/face-swap-settings/index.d.ts +22 -0
  359. package/dist/debug-ui/gesture-settings/index.d.ts +14 -0
  360. package/dist/debug-ui/hand-joints-2d/index.d.ts +1 -1
  361. package/dist/debug-ui/hand-tracking-2d/index.d.ts +1 -1
  362. package/dist/debug-ui/hand-tracking-2d-controller/index.d.ts +1 -1
  363. package/dist/debug-ui/hand-tracking-3d/index.d.ts +1 -1
  364. package/dist/debug-ui/hierarchy-panel/index.d.ts +30 -0
  365. package/dist/debug-ui/holistic-tracker-settings/index.d.ts +16 -0
  366. package/dist/debug-ui/index.d.ts +43 -5
  367. package/dist/debug-ui/iris-effect-settings/index.d.ts +12 -0
  368. package/dist/debug-ui/layer-panel/index.d.ts +3 -2
  369. package/dist/debug-ui/lip-effect-settings/index.d.ts +15 -0
  370. package/dist/debug-ui/media-source/index.d.ts +4 -2
  371. package/dist/debug-ui/media-source/media-preset.d.ts +12 -0
  372. package/dist/debug-ui/media-source/session.d.ts +40 -0
  373. package/dist/debug-ui/media-source.cjs +1 -1
  374. package/dist/debug-ui/media-source.js +8 -4
  375. package/dist/debug-ui/mesh-renderer-settings/index.d.ts +6 -0
  376. package/dist/debug-ui/object-inspector-panel/index.d.ts +26 -0
  377. package/dist/debug-ui/pin-to-mesh-settings/index.d.ts +10 -0
  378. package/dist/debug-ui/product-hotspots/index.d.ts +25 -0
  379. package/dist/debug-ui/scene-editor/context.d.ts +38 -0
  380. package/dist/debug-ui/scene-editor/hierarchy-panel.d.ts +11 -0
  381. package/dist/debug-ui/scene-editor/index.d.ts +11 -0
  382. package/dist/debug-ui/scene-editor/inspector-panel.d.ts +9 -0
  383. package/dist/debug-ui/scene-editor/store-utils.d.ts +2 -0
  384. package/dist/debug-ui/scene-editor/viewport-toolbar.d.ts +4 -0
  385. package/dist/debug-ui/scene-editor/viewport.d.ts +21 -0
  386. package/dist/debug-ui/screen-glass-settings/index.d.ts +6 -0
  387. package/dist/debug-ui/screen-gradient-settings/GradientStopsEditor.d.ts +5 -0
  388. package/dist/debug-ui/screen-gradient-settings/index.d.ts +6 -0
  389. package/dist/debug-ui/screen-gradient-settings/styles.d.ts +3 -0
  390. package/dist/debug-ui/screen-image-settings/index.d.ts +6 -2
  391. package/dist/debug-ui/screen-shape-settings/index.d.ts +6 -0
  392. package/dist/debug-ui/screen-text-settings/NumberField.d.ts +9 -0
  393. package/dist/debug-ui/screen-text-settings/ScreenTextSettingsPanel.d.ts +3 -0
  394. package/dist/debug-ui/screen-text-settings/controls/NestedSection.d.ts +7 -0
  395. package/dist/debug-ui/screen-text-settings/controls/Section.d.ts +8 -0
  396. package/dist/debug-ui/screen-text-settings/controls/icons.d.ts +4 -0
  397. package/dist/debug-ui/screen-text-settings/index.d.ts +2 -122
  398. package/dist/debug-ui/screen-text-settings/sections/BackgroundSection.d.ts +8 -0
  399. package/dist/debug-ui/screen-text-settings/sections/ContentSection.d.ts +5 -0
  400. package/dist/debug-ui/screen-text-settings/sections/EffectsSection.d.ts +25 -0
  401. package/dist/debug-ui/screen-text-settings/sections/StyleSection.d.ts +5 -0
  402. package/dist/debug-ui/screen-text-settings/sections/TransformSection.d.ts +5 -0
  403. package/dist/debug-ui/screen-text-settings/sections/background/BackgroundFillControls.d.ts +2 -0
  404. package/dist/debug-ui/screen-text-settings/sections/background/BackgroundSizeControls.d.ts +2 -0
  405. package/dist/debug-ui/screen-text-settings/sections/background/BackgroundStrokeControls.d.ts +2 -0
  406. package/dist/debug-ui/screen-text-settings/sections/background/types.d.ts +7 -0
  407. package/dist/debug-ui/screen-text-settings/sections/effects/BendEffectSection.d.ts +4 -0
  408. package/dist/debug-ui/screen-text-settings/sections/effects/EffectChrome.d.ts +21 -0
  409. package/dist/debug-ui/screen-text-settings/sections/effects/GlowEffectSection.d.ts +4 -0
  410. package/dist/debug-ui/screen-text-settings/sections/effects/InnerShadowEffectSection.d.ts +4 -0
  411. package/dist/debug-ui/screen-text-settings/sections/effects/OutlineEffectSection.d.ts +4 -0
  412. package/dist/debug-ui/screen-text-settings/sections/effects/ShadowEffectSection.d.ts +4 -0
  413. package/dist/debug-ui/screen-text-settings/sections/effects/types.d.ts +14 -0
  414. package/dist/debug-ui/screen-text-settings/settings.d.ts +90 -0
  415. package/dist/debug-ui/screen-text-settings/styles.d.ts +26 -0
  416. package/dist/debug-ui/screen-text-settings/transform.d.ts +6 -0
  417. package/dist/debug-ui/screen-text-settings/types.d.ts +11 -0
  418. package/dist/debug-ui/segmentation-overlay-settings/index.d.ts +12 -0
  419. package/dist/debug-ui/settings-panel/index.d.ts +6 -1
  420. package/dist/debug-ui/shared/ScreenTransformSection.d.ts +6 -3
  421. package/dist/debug-ui/shared/debugWindow.d.ts +51 -0
  422. package/dist/debug-ui/transform-3d-settings/index.d.ts +11 -0
  423. package/dist/debug-ui/xr-diagnostics/index.d.ts +26 -0
  424. package/dist/debug-ui.cjs +3 -13
  425. package/dist/debug-ui.js +8166 -5178
  426. package/dist/detector-K8aej4MB.js +59 -0
  427. package/dist/detector-ijypGtse.cjs +1 -0
  428. package/dist/drawNormalizedCrop-BLfB484W.js +135 -0
  429. package/dist/drawNormalizedCrop-DaGT5mZ5.cjs +1 -0
  430. package/dist/entries/all.d.ts +4 -1
  431. package/dist/entries/core.d.ts +74 -8
  432. package/dist/entries/face-effects.d.ts +130 -12
  433. package/dist/entries/instructions.d.ts +48 -0
  434. package/dist/entries/internal.d.ts +5 -2
  435. package/dist/entries/low-level.d.ts +101 -6
  436. package/dist/entries/particles.d.ts +15 -0
  437. package/dist/entries/product.d.ts +11 -0
  438. package/dist/entries/scene-object.d.ts +10 -0
  439. package/dist/entries/tracking.d.ts +110 -2
  440. package/dist/face-action/index.d.ts +34 -0
  441. package/dist/face-atlas/attributes.d.ts +30 -0
  442. package/dist/face-atlas/eyes.d.ts +272 -0
  443. package/dist/face-atlas/faceAtlas.generated.d.ts +46 -0
  444. package/dist/face-atlas/glsl/atlasVertex.d.ts +46 -0
  445. package/dist/face-atlas/glsl/common.d.ts +55 -0
  446. package/dist/face-atlas/glsl/design.d.ts +49 -0
  447. package/dist/face-atlas/glsl/eyes.d.ts +73 -0
  448. package/dist/face-atlas/glsl/finish.d.ts +24 -0
  449. package/dist/face-atlas/glsl/format.d.ts +4 -0
  450. package/dist/face-atlas/glsl/index.d.ts +59 -0
  451. package/dist/face-atlas/glsl/shading.d.ts +15 -0
  452. package/dist/face-atlas/glsl/shapes.d.ts +66 -0
  453. package/dist/face-atlas/glsl/sparkle.d.ts +19 -0
  454. package/dist/face-atlas/glsl/uniforms.d.ts +106 -0
  455. package/dist/face-atlas/guide.d.ts +51 -0
  456. package/dist/face-atlas/index.d.ts +25 -0
  457. package/dist/face-atlas/lead.d.ts +117 -0
  458. package/dist/face-atlas/madeUpCamera.d.ts +125 -0
  459. package/dist/face-atlas/masks.d.ts +53 -0
  460. package/dist/face-atlas/obj.d.ts +69 -0
  461. package/dist/face-atlas/polylines.d.ts +63 -0
  462. package/dist/face-atlas/probe/FaceSkinProbe.d.ts +208 -0
  463. package/dist/face-atlas/probe/__fixtures__/emulate.d.ts +9 -0
  464. package/dist/face-atlas/probe/__fixtures__/face.d.ts +24 -0
  465. package/dist/face-atlas/probe/constants.d.ts +137 -0
  466. package/dist/face-atlas/probe/glsl.d.ts +43 -0
  467. package/dist/face-atlas/probe/lightFit.d.ts +108 -0
  468. package/dist/face-atlas/probe/schedule.d.ts +44 -0
  469. package/dist/face-atlas/probe/selfTest.d.ts +87 -0
  470. package/dist/face-atlas/probe/stats.d.ts +143 -0
  471. package/dist/face-atlas/probe/targets.d.ts +70 -0
  472. package/dist/face-atlas/probe/unwrap.d.ts +76 -0
  473. package/dist/face-atlas/quality.d.ts +28 -0
  474. package/dist/face-atlas/regions.d.ts +31 -0
  475. package/dist/face-atlas/registry.d.ts +252 -0
  476. package/dist/face-atlas/renderState.d.ts +86 -0
  477. package/dist/face-atlas/selfOcclusion.d.ts +62 -0
  478. package/dist/face-atlas/shading.d.ts +406 -0
  479. package/dist/face-atlas/shapes.d.ts +86 -0
  480. package/dist/face-atlas/sides.d.ts +41 -0
  481. package/dist/face-atlas/skinMask.d.ts +35 -0
  482. package/dist/face-atlas/surface.d.ts +155 -0
  483. package/dist/face-atlas/topology.d.ts +44 -0
  484. package/dist/face-attribute-expression/index.d.ts +10 -0
  485. package/dist/face-character/__fixtures__/faceImageDetections.d.ts +25 -0
  486. package/dist/face-character/__fixtures__/faceNode.d.ts +22 -0
  487. package/dist/face-character/bindFaceModel.d.ts +106 -0
  488. package/dist/face-character/canonicalFace.d.ts +17 -0
  489. package/dist/face-character/canonicalFaceGeometry.d.ts +11 -0
  490. package/dist/face-character/canonicalFacePositions.d.ts +7 -0
  491. package/dist/face-character/driveFaceModel.d.ts +57 -0
  492. package/dist/face-character/expressionOutputs.d.ts +45 -0
  493. package/dist/face-character/faceExpressions.d.ts +104 -0
  494. package/dist/face-character/faceImageLandmarker.d.ts +93 -0
  495. package/dist/face-character/faceMeshBinding.d.ts +62 -0
  496. package/dist/face-character/faceMorph.d.ts +77 -0
  497. package/dist/face-character/faceMorphs.d.ts +46 -0
  498. package/dist/face-character/facePhoto.d.ts +138 -0
  499. package/dist/face-character/facePiercings.d.ts +116 -0
  500. package/dist/face-character/facePin.d.ts +131 -0
  501. package/dist/face-character/faceReprojection.d.ts +273 -0
  502. package/dist/face-character/faceReprojector.d.ts +171 -0
  503. package/dist/face-character/faceRig.d.ts +176 -0
  504. package/dist/face-character/faceSwapPresence.d.ts +85 -0
  505. package/dist/face-character/faceTexture.d.ts +169 -0
  506. package/dist/face-character/faceTextureBaker.d.ts +86 -0
  507. package/dist/face-character/faceTextureGuide.d.ts +106 -0
  508. package/dist/face-character/faceTextureStats.d.ts +298 -0
  509. package/dist/face-character/faceTransfer.d.ts +396 -0
  510. package/dist/face-character/faceTransferGeometry.d.ts +109 -0
  511. package/dist/face-character/faceTransferSelfTest.d.ts +94 -0
  512. package/dist/face-character/faceWarp3D.d.ts +101 -0
  513. package/dist/face-character/faceless.d.ts +79 -0
  514. package/dist/face-character/featureWarp.d.ts +28 -0
  515. package/dist/face-character/liveFaceRegistry.d.ts +370 -0
  516. package/dist/face-character/liveValue.d.ts +12 -0
  517. package/dist/face-character/memo.d.ts +15 -0
  518. package/dist/face-effects.cjs +2271 -289
  519. package/dist/face-effects.js +14240 -3562
  520. package/dist/face-expression/index.d.ts +182 -0
  521. package/dist/face-info/blendshapes.d.ts +3 -0
  522. package/dist/face-info/derive.d.ts +8 -0
  523. package/dist/face-info/drawFaceCrop.d.ts +10 -0
  524. package/dist/face-info/getFaceInfo.d.ts +8 -0
  525. package/dist/face-info/index.d.ts +8 -0
  526. package/dist/face-info/landmarks.d.ts +35 -0
  527. package/dist/face-info/types.d.ts +69 -0
  528. package/dist/footage-input/index.d.ts +46 -0
  529. package/dist/gestures/definitions.d.ts +98 -0
  530. package/dist/gestures/detector.d.ts +87 -0
  531. package/dist/gestures/index.d.ts +8 -0
  532. package/dist/gestures/measures.d.ts +114 -0
  533. package/dist/gestures/settings.d.ts +49 -0
  534. package/dist/getFaceInfo-BbcKq8PJ.cjs +1 -0
  535. package/dist/getFaceInfo-D_tCSQC7.js +62 -0
  536. package/dist/hand/armFit.d.ts +46 -0
  537. package/dist/hand/armMask.d.ts +190 -0
  538. package/dist/hand/forearm.d.ts +114 -0
  539. package/dist/hand/handCutout.d.ts +23 -0
  540. package/dist/hand/handCutoutRegistry.d.ts +7 -0
  541. package/dist/hand/handEffect.d.ts +38 -0
  542. package/dist/hand/handGestures.d.ts +524 -0
  543. package/dist/{handJoints2d.d.ts → hand/handJoints2d.d.ts} +1 -1
  544. package/dist/hand/handNail.d.ts +73 -0
  545. package/dist/hand/handPose.d.ts +98 -0
  546. package/dist/hand/handRigSolver.d.ts +159 -0
  547. package/dist/hand/handTattoo.d.ts +81 -0
  548. package/dist/hand/handTouch.d.ts +240 -0
  549. package/dist/{handTracking2d.d.ts → hand/handTracking2d.d.ts} +1 -1
  550. package/dist/{handTracking2dController.d.ts → hand/handTracking2dController.d.ts} +1 -1
  551. package/dist/{handTracking3d.d.ts → hand/handTracking3d.d.ts} +1 -1
  552. package/dist/hand/nailImageMask.d.ts +40 -0
  553. package/dist/hand/nailMaskFingers.d.ts +23 -0
  554. package/dist/hand/nailTipRefine.d.ts +37 -0
  555. package/dist/hand/wrist.d.ts +44 -0
  556. package/dist/hand/wristFilter.d.ts +44 -0
  557. package/dist/hooks/faceResults.d.ts +1 -1
  558. package/dist/hooks/selectors.d.ts +77 -4
  559. package/dist/hooks/useBodies.d.ts +39 -0
  560. package/dist/hooks/useCalibrationFaceTracker.d.ts +1 -1
  561. package/dist/hooks/useFaceAction.d.ts +3 -0
  562. package/dist/hooks/useFaceAttributeExpression.d.ts +16 -0
  563. package/dist/hooks/useFaceDetection.d.ts +18 -0
  564. package/dist/hooks/useFaceInfo.d.ts +19 -0
  565. package/dist/hooks/useFaceInfos.d.ts +15 -0
  566. package/dist/hooks/useFaceModelAcquisition.d.ts +38 -0
  567. package/dist/hooks/useFaceResultReader.d.ts +10 -0
  568. package/dist/hooks/useFrameCapture.d.ts +18 -0
  569. package/dist/hooks/useGesture.d.ts +39 -0
  570. package/dist/hooks/useIrisTracking.d.ts +45 -0
  571. package/dist/hooks/useMediaRecorder.d.ts +14 -2
  572. package/dist/hooks/useOwnedTexture.d.ts +6 -0
  573. package/dist/hooks/useTrackerContext.d.ts +14 -2
  574. package/dist/hooks/useXRDiagnostics.d.ts +81 -0
  575. package/dist/hooks/useXRModel.d.ts +12 -0
  576. package/dist/hooks/useXRSession/facade.d.ts +47 -2
  577. package/dist/hooks/useXRSession/index.d.ts +2 -2
  578. package/dist/hooks/useXRSession/reason.d.ts +21 -0
  579. package/dist/hooks/useXRSession/registry.d.ts +23 -0
  580. package/dist/hooks/useXRSession/store.d.ts +64 -7
  581. package/dist/index-B9DdHE4u.js +442 -0
  582. package/dist/index-Bxb_UcfF.cjs +46 -0
  583. package/dist/index-CNt8esFO.js +240 -0
  584. package/dist/index-CTqQJj5p.js +3814 -0
  585. package/dist/index-CXaj3tOT.js +1108 -0
  586. package/dist/index-CYwAL_d7.cjs +21 -0
  587. package/dist/index-CelqbDSR.cjs +1 -0
  588. package/dist/index-D10O6vqR.js +190 -0
  589. package/dist/index-DIYaENN3.cjs +1 -0
  590. package/dist/index-DlP4xxaT.js +188 -0
  591. package/dist/index-DzdKBXGE.cjs +1 -0
  592. package/dist/index-J3Qy6hi3.cjs +1 -0
  593. package/dist/index-LC2Xs08E.cjs +1 -0
  594. package/dist/index-WkEZBuB4.js +1432 -0
  595. package/dist/instructions.cjs +30 -0
  596. package/dist/instructions.js +1528 -0
  597. package/dist/internal-DS8Pdlsm.cjs +1 -0
  598. package/dist/{internal-Cae1ps15.js → internal-TD4QhIry.js} +152 -127
  599. package/dist/internal.cjs +1 -1
  600. package/dist/internal.js +16 -9
  601. package/dist/iris/compute.d.ts +27 -0
  602. package/dist/iris/index.d.ts +4 -0
  603. package/dist/iris/lead.d.ts +19 -0
  604. package/dist/iris/types.d.ts +89 -0
  605. package/dist/landmarkMask-CvN-L5NT.cjs +1 -0
  606. package/dist/landmarkMask-DHivVjJm.js +225 -0
  607. package/dist/landmarks-BP6RbRHN.cjs +1 -0
  608. package/dist/landmarks-vLy5QKt6.js +76 -0
  609. package/dist/low-level.cjs +1 -1
  610. package/dist/low-level.js +1766 -85
  611. package/dist/main.cjs +1 -73
  612. package/dist/main.js +1299 -1713
  613. package/dist/material/MaterialFill.d.ts +20 -0
  614. package/dist/material/MeshMaterial.d.ts +14 -0
  615. package/dist/material/index.d.ts +2 -0
  616. package/dist/models/Base/index.d.ts +49 -0
  617. package/dist/models/Body/index.d.ts +30 -1
  618. package/dist/models/Face/constants.d.ts +8 -0
  619. package/dist/models/Face/index.d.ts +5 -12
  620. package/dist/models/Face/rotation.d.ts +18 -0
  621. package/dist/models/Hand/GestureTracking.d.ts +1 -1
  622. package/dist/models/Hand/HandTracking.d.ts +17 -1
  623. package/dist/models/Holistic/index.d.ts +49 -0
  624. package/dist/models/Holistic/result.d.ts +68 -0
  625. package/dist/models/Segmentation/index.d.ts +6 -3
  626. package/dist/models/SemanticSegmentation/index.d.ts +31 -0
  627. package/dist/models/SemanticSegmentation/presets.d.ts +28 -0
  628. package/dist/models/index.d.ts +2 -0
  629. package/dist/models/nodeSource.d.ts +9 -0
  630. package/dist/particles/emission.d.ts +24 -0
  631. package/dist/particles/eyes.d.ts +24 -0
  632. package/dist/particles/glsl.d.ts +14 -0
  633. package/dist/particles/index.d.ts +10 -0
  634. package/dist/particles/motion.d.ts +42 -0
  635. package/dist/particles/presets.d.ts +12 -0
  636. package/dist/particles/ring.d.ts +58 -0
  637. package/dist/particles/selfTest.d.ts +53 -0
  638. package/dist/particles/settings.d.ts +127 -0
  639. package/dist/particles/shapes.d.ts +29 -0
  640. package/dist/particles/spawner.d.ts +71 -0
  641. package/dist/particles/system.d.ts +66 -0
  642. package/dist/particles.cjs +122 -0
  643. package/dist/particles.js +999 -0
  644. package/dist/product/ProductDimensions.d.ts +16 -0
  645. package/dist/product/ProductHotspot.d.ts +16 -0
  646. package/dist/product/ProductViewer.d.ts +9 -0
  647. package/dist/product/details.d.ts +53 -0
  648. package/dist/product/index.d.ts +14 -0
  649. package/dist/product/loadModelViewer.d.ts +4 -0
  650. package/dist/product/types.d.ts +71 -0
  651. package/dist/product/useProductAr.d.ts +37 -0
  652. package/dist/product/useProductDetails.d.ts +60 -0
  653. package/dist/product.cjs +1 -0
  654. package/dist/product.js +414 -0
  655. package/dist/providers-BRSbw214.cjs +62 -0
  656. package/dist/providers-DmJlgrDD.js +424 -0
  657. package/dist/quality/XRQualityController.d.ts +25 -0
  658. package/dist/quality/controller.d.ts +33 -0
  659. package/dist/quality/index.d.ts +6 -0
  660. package/dist/quality/types.d.ts +100 -0
  661. package/dist/quality/useXRQuality.d.ts +28 -0
  662. package/dist/render/renderGroups.d.ts +47 -0
  663. package/dist/render/renderPasses.d.ts +26 -0
  664. package/dist/render/sceneBeforeRender.d.ts +12 -0
  665. package/dist/renderGroups-B0N58SIA.cjs +1 -0
  666. package/dist/renderGroups-BcQYy_J2.js +152 -0
  667. package/dist/renderPasses-Bt8k0dkm.cjs +158 -0
  668. package/dist/renderPasses-DIPTIU_x.js +1290 -0
  669. package/dist/renderState-CJNmj5jz.js +39 -0
  670. package/dist/renderState-apSfg4eR.cjs +1 -0
  671. package/dist/scene-object/index.d.ts +146 -0
  672. package/dist/scene-object/runtimeRegistry.d.ts +14 -0
  673. package/dist/scene-object.cjs +1 -0
  674. package/dist/scene-object.js +40 -0
  675. package/dist/{screenImageSettings.d.ts → screen-image/screenImageSettings.d.ts} +9 -2
  676. package/dist/{screenTextSettings.d.ts → screen-text/screenTextSettings.d.ts} +18 -2
  677. package/dist/screen2d/coordinates.d.ts +144 -0
  678. package/dist/screen2d/index.d.ts +3 -0
  679. package/dist/screen2d/screenTransform.d.ts +60 -0
  680. package/dist/screen2d/smoothing.d.ts +5 -0
  681. package/dist/segmentation-CZs5aVvY.js +1911 -0
  682. package/dist/segmentation-Cz7oeNcS.cjs +1 -0
  683. package/dist/segmentation2d/faceMemory.d.ts +28 -0
  684. package/dist/segmentation2d/faceRegions.d.ts +24 -0
  685. package/dist/segmentation2d/index.d.ts +9 -0
  686. package/dist/segmentation2d/maskUv.d.ts +23 -0
  687. package/dist/segmentation2d/rasterize.d.ts +14 -0
  688. package/dist/segmentation2d/types.d.ts +52 -0
  689. package/dist/selectors-Bq6tSgOY.cjs +1 -0
  690. package/dist/selectors-K5JKCWxw.js +196 -0
  691. package/dist/services/MetricsCollector/index.d.ts +7 -1
  692. package/dist/services/MetricsCollector/utils.d.ts +1 -1
  693. package/dist/session-3aCMNb8W.cjs +31 -0
  694. package/dist/session-DHBNTyJJ.js +493 -0
  695. package/dist/settings-BJ7FMBsO.js +111 -0
  696. package/dist/settings-C63FMBlF.cjs +1 -0
  697. package/dist/similarityFit-BFqHND2e.cjs +1 -0
  698. package/dist/similarityFit-Bbz-R8AY.js +91 -0
  699. package/dist/spring/index.d.ts +2 -0
  700. package/dist/spring/spring.d.ts +69 -0
  701. package/dist/spring/swing.d.ts +54 -0
  702. package/dist/subjects/index.d.ts +2 -0
  703. package/dist/subjects/select.d.ts +70 -0
  704. package/dist/subjects/types.d.ts +59 -0
  705. package/dist/texture/animatedTexture.d.ts +63 -0
  706. package/dist/texture/animationMath.d.ts +8 -0
  707. package/dist/texture/gifReader.d.ts +17 -0
  708. package/dist/texture/gifTextureSource.d.ts +16 -0
  709. package/dist/texture/sourceResolver.d.ts +30 -0
  710. package/dist/textures-BVwo9Z7z.js +38 -0
  711. package/dist/textures-DAfc61zz.cjs +1 -0
  712. package/dist/tracking/coordinates.d.ts +5 -0
  713. package/dist/tracking-config/apply.d.ts +57 -0
  714. package/dist/tracking-config/index.d.ts +7 -0
  715. package/dist/tracking-config/resolve.d.ts +25 -0
  716. package/dist/tracking-config/storage.d.ts +8 -0
  717. package/dist/tracking-config/types.d.ts +106 -0
  718. package/dist/tracking-config/useXRTrackingConfig.d.ts +38 -0
  719. package/dist/tracking.cjs +10 -1
  720. package/dist/tracking.js +1529 -317
  721. package/dist/trigger-BwZ81ENx.js +3726 -0
  722. package/dist/trigger-UjeJY5uh.cjs +147 -0
  723. package/dist/types/common.d.ts +11 -1
  724. package/dist/types/compositor.d.ts +21 -0
  725. package/dist/types/face.d.ts +21 -14
  726. package/dist/types/gesture-tracking.d.ts +2 -2
  727. package/dist/types/hand-tracking.d.ts +12 -3
  728. package/dist/types/holistic.d.ts +121 -0
  729. package/dist/types/index.d.ts +1 -1
  730. package/dist/types/model.d.ts +22 -2
  731. package/dist/types/nodes.d.ts +81 -6
  732. package/dist/types/segmentation.d.ts +26 -0
  733. package/dist/types/session.d.ts +50 -4
  734. package/dist/types/tracking.d.ts +8 -2
  735. package/dist/types/util-types.d.ts +1 -1
  736. package/dist/useBodies-BMKHXAOL.js +75 -0
  737. package/dist/useBodies-CXomEo0i.cjs +1 -0
  738. package/dist/useFaceInfo-BEMMiZxw.cjs +1 -0
  739. package/dist/useFaceInfo-BNVdnprN.js +75 -0
  740. package/dist/useFaceResultReader-B15wn6RB.js +61 -0
  741. package/dist/useFaceResultReader-D9qibKmm.cjs +1 -0
  742. package/dist/useInstructionHold-DOu-RpCM.js +53 -0
  743. package/dist/useInstructionHold-DwJY1Alr.cjs +1 -0
  744. package/dist/useIrisTracking-CYm-KDIZ.js +6190 -0
  745. package/dist/useIrisTracking-DExhnhlt.cjs +35 -0
  746. package/dist/useLandmarkPoseFit-Bg-h9BPb.cjs +1 -0
  747. package/dist/useLandmarkPoseFit-Bmb3h6Mw.js +87 -0
  748. package/dist/useXRCapabilities-ClWlG5_Y.js +30 -0
  749. package/dist/useXRCapabilities-D-EhcDzM.cjs +1 -0
  750. package/dist/utils/canonicalRigidLandmarks.d.ts +8 -0
  751. package/dist/utils/drawNormalizedCrop.d.ts +22 -0
  752. package/dist/utils/fns.d.ts +6 -3
  753. package/dist/utils/headOccluderFit.d.ts +42 -0
  754. package/dist/utils/integrity.d.ts +25 -26
  755. package/dist/utils/landmarkBounds.d.ts +1 -1
  756. package/dist/utils/logger.d.ts +2 -2
  757. package/dist/utils/resolveNumFaces.d.ts +13 -0
  758. package/dist/utils/shoulderOccluderFit.d.ts +38 -0
  759. package/dist/utils/similarityFit.d.ts +23 -0
  760. package/dist/utils/updateThrottle.d.ts +2 -0
  761. package/dist/utils/useEditOverrides.d.ts +26 -0
  762. package/dist/utils/useStableUniforms.d.ts +18 -0
  763. package/dist/utils/visionWasm.d.ts +18 -0
  764. package/dist/uv-BMFt19bg.cjs +1 -0
  765. package/dist/{index-BGNbrc4C.js → uv-DJU_XfmN.js} +15 -156
  766. package/docs/MIGRATION_GUIDE.md +589 -0
  767. package/docs/SDK_DOCUMENTATION.md +1157 -0
  768. package/docs/api/adaptive-quality.mdx +104 -0
  769. package/docs/api/asset-lifecycle.mdx +78 -0
  770. package/docs/api/audio.mdx +36 -0
  771. package/docs/api/behavior-components.mdx +164 -0
  772. package/docs/api/body-instructions.mdx +287 -0
  773. package/docs/api/body-rig.mdx +384 -0
  774. package/docs/api/body-triggers.mdx +235 -0
  775. package/docs/api/camera-permission.mdx +142 -0
  776. package/docs/api/capture-recording.mdx +111 -0
  777. package/docs/api/coordinate-spaces.mdx +168 -0
  778. package/docs/api/cross-camera.mdx +89 -0
  779. package/docs/api/debug-ui-scene-editor.mdx +270 -0
  780. package/docs/api/diagnostics-calibration.mdx +97 -0
  781. package/docs/api/external-face-mesh.mdx +231 -0
  782. package/docs/api/face-actions.mdx +108 -0
  783. package/docs/api/face-attribute-expression.mdx +87 -0
  784. package/docs/api/face-binding-anchors.mdx +55 -0
  785. package/docs/api/face-character.mdx +157 -0
  786. package/docs/api/face-effects.mdx +28 -0
  787. package/docs/api/face-expression-controller.mdx +153 -0
  788. package/docs/api/face-info.mdx +118 -0
  789. package/docs/api/face-inset.mdx +204 -0
  790. package/docs/api/face-instructions.mdx +183 -0
  791. package/docs/api/face-liquify.mdx +196 -0
  792. package/docs/api/face-mesh.mdx +130 -0
  793. package/docs/api/face-morph.mdx +117 -0
  794. package/docs/api/face-painting.mdx +40 -0
  795. package/docs/api/face-reprojection.mdx +154 -0
  796. package/docs/api/face-retouching.mdx +81 -0
  797. package/docs/api/face-swap.mdx +350 -0
  798. package/docs/api/face-warp-3d.mdx +166 -0
  799. package/docs/api/faceless.mdx +143 -0
  800. package/docs/api/gestures.mdx +210 -0
  801. package/docs/api/hair.mdx +97 -0
  802. package/docs/api/hand-instructions.mdx +222 -0
  803. package/docs/api/hand-rig.mdx +661 -0
  804. package/docs/api/hand-touch.mdx +162 -0
  805. package/docs/api/head-occluder.mdx +563 -0
  806. package/docs/api/holistic-tracker.mdx +164 -0
  807. package/docs/api/instructions.mdx +323 -0
  808. package/docs/api/iris-tracking.mdx +247 -0
  809. package/docs/api/made-up-camera.mdx +131 -0
  810. package/docs/api/makeup-skin-tone.mdx +135 -0
  811. package/docs/api/makeup.mdx +353 -0
  812. package/docs/api/material-render-state.mdx +132 -0
  813. package/docs/api/multi-subject.mdx +185 -0
  814. package/docs/api/particles.mdx +183 -0
  815. package/docs/api/person-cutout.mdx +171 -0
  816. package/docs/api/pin-to-face-mesh.mdx +274 -0
  817. package/docs/api/product-ar.mdx +114 -0
  818. package/docs/api/product-details.mdx +78 -0
  819. package/docs/api/runtime-3d.mdx +316 -0
  820. package/docs/api/scene-object-store.mdx +213 -0
  821. package/docs/api/screen-image.mdx +67 -0
  822. package/docs/api/screen-shape.mdx +64 -0
  823. package/docs/api/screen-space-coordinates.mdx +83 -0
  824. package/docs/api/screen-text.mdx +39 -0
  825. package/docs/api/segmentation-overlay.mdx +301 -0
  826. package/docs/api/session-lifecycle.mdx +165 -0
  827. package/docs/api/texture-sources.mdx +74 -0
  828. package/docs/api/trackers.mdx +65 -0
  829. package/docs/api/tracking-config.mdx +108 -0
  830. package/docs/docs.json +121 -0
  831. package/docs/examples/lip-shaders.mdx +273 -0
  832. package/docs/examples/scene-object-recipes.mdx +194 -0
  833. package/docs/guides/face-atlas-template.svg +1 -0
  834. package/docs/guides/face-atlas-textures.mdx +186 -0
  835. package/docs/guides/face-texture-template.svg +1 -0
  836. package/docs/guides/harness-debug-ui.mdx +139 -0
  837. package/docs/guides/lip-effect-textures.mdx +368 -0
  838. package/docs/guides/lip-uv-template.png +0 -0
  839. package/docs/guides/lip-uv-template.svg +1 -0
  840. package/docs/guides/makeup-design-textures.mdx +109 -0
  841. package/docs/inspector/hierarchy-panel.mdx +51 -0
  842. package/docs/inspector/object-inspector-panel.mdx +51 -0
  843. package/docs/introduction.mdx +120 -0
  844. package/docs/scene-objects/overview.mdx +127 -0
  845. package/docs/scene-objects/render-groups.mdx +77 -0
  846. package/docs/scene-objects/runtime-rendering.mdx +75 -0
  847. package/docs/texture-api-consumer.md +84 -0
  848. package/package.json +69 -9
  849. package/settings.json +2049 -0
  850. package/dist/DebuggerUI-CatYc-RG.cjs +0 -1
  851. package/dist/DebuggerUI-gLMKiVwJ.js +0 -269
  852. package/dist/MediaSourceSwitcher-C-xYg0nQ.js +0 -317
  853. package/dist/MediaSourceSwitcher-Cq3g4IKw.cjs +0 -31
  854. package/dist/components/FaceRetouch/defaults.d.ts +0 -13
  855. package/dist/components/FaceRetouch/retouchRegions.d.ts +0 -23
  856. package/dist/components/FaceRetouch/useFaceRetouchRegions.d.ts +0 -12
  857. package/dist/components/FaceWarp3D/FaceWarp3DHead.d.ts +0 -15
  858. package/dist/components/FaceWarp3D/defaults.d.ts +0 -37
  859. package/dist/components/FaceWarp3D/warp.d.ts +0 -13
  860. package/dist/debug-ui/face-warp-3d/index.d.ts +0 -6
  861. package/dist/defaults-BLpcN3pG.cjs +0 -1
  862. package/dist/defaults-LtY4M7dg.js +0 -55
  863. package/dist/index-BXyObVHF.cjs +0 -1
  864. package/dist/index-CY3bUAcW.js +0 -12
  865. package/dist/index-C_Duh13c.cjs +0 -1
  866. package/dist/index-D8fpPQkC.cjs +0 -1
  867. package/dist/index-DxshgBu0.cjs +0 -1
  868. package/dist/index-O-2crZ3M.js +0 -1102
  869. package/dist/index-safCs_af.js +0 -1341
  870. package/dist/internal-BjyhBP8i.cjs +0 -1
  871. package/dist/modules/XRClient/index.d.ts +0 -9
  872. package/dist/modules/index.d.ts +0 -1
  873. package/dist/screenImageSettings-6NRg4cx9.js +0 -39
  874. package/dist/screenImageSettings-y_B4_767.cjs +0 -1
  875. package/dist/selectors-BLl2JUWW.cjs +0 -1
  876. package/dist/selectors-CXd_x-6t.js +0 -59
  877. package/dist/services/ApiService.d.ts +0 -12
  878. package/dist/types/client.d.ts +0 -3
  879. package/dist/useFaceResults-cpsSmKKc.js +0 -81
  880. package/dist/useFaceResults-hVUJYSEY.cjs +0 -1
  881. package/dist/useXRModel-3DcUa28n.cjs +0 -1
  882. package/dist/useXRModel-BMJE1hrk.js +0 -28
  883. /package/dist/{layerStack.d.ts → render/layerStack.d.ts} +0 -0
  884. /package/dist/{screenImagePresets.d.ts → screen-image/screenImagePresets.d.ts} +0 -0
  885. /package/dist/{screenTextPresets.d.ts → screen-text/screenTextPresets.d.ts} +0 -0
@@ -0,0 +1,3814 @@
1
+ var Ps = Object.defineProperty;
2
+ var _s = (e, s, t) => s in e ? Ps(e, s, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[s] = t;
3
+ var m = (e, s, t) => _s(e, typeof s != "symbol" ? s + "" : s, t);
4
+ import { jsxs as Ds, jsx as xt } from "react/jsx-runtime";
5
+ import { useRef as ue, useMemo as xe, useEffect as de, useContext as et, useCallback as St, createElement as Os, createContext as Lt, useState as Ls } from "react";
6
+ import { FilesetResolver as $, PoseLandmarker as Ns, FaceLandmarker as Bs, GestureRecognizer as Hs, HolisticLandmarker as Us, HandLandmarker as zs, ImageSegmenter as Nt, DrawingUtils as Ws } from "@mediapipe/tasks-vision";
7
+ import * as W from "three";
8
+ import { Vector2 as qs, Raycaster as Vs, Ray as Ks, Vector3 as Gs, RGBAFormat as Bt, LinearFilter as Ie, CanvasTexture as Ht, SRGBColorSpace as Xs } from "three";
9
+ var I = /* @__PURE__ */ ((e) => (e.WEBCAM = "webcam", e.STREAM = "stream", e.CANVAS = "canvas", e))(I || {}), P = /* @__PURE__ */ ((e) => (e.HAND_TRACKER = "vincentt.xr.hand-tracker", e.GESTURE_TRACKER = "vincentt.xr.gesture-tracker", e.FACE_TRACKER = "vincentt.xr.face-tracker", e.BODY_TRACKER = "vincentt.xr.body-tracker", e.HOLISTIC_TRACKER = "vincentt.xr.holistic-tracker", e.BACKGROUND_SEGMENTATION = "vincentt.xr.background-segmentation", e.SEMANTIC_SEGMENTATION = "vincentt.xr.semantic-segmentation", e))(P || {});
10
+ class O extends Error {
11
+ constructor(s) {
12
+ super(s), this.name = "VincenttXRError";
13
+ }
14
+ }
15
+ const Ce = Symbol.for("vincentt.xr.footage-input"), js = (e) => {
16
+ if (!e) return !1;
17
+ try {
18
+ return e.self !== e.top;
19
+ } catch {
20
+ return !1;
21
+ }
22
+ }, Ys = "FootageSupersededError", ze = () => {
23
+ const e = new Error("superseded");
24
+ return e.name = Ys, e;
25
+ }, Qs = (e) => {
26
+ let s = null, t = !1, n = !1;
27
+ const i = () => {
28
+ if (n || t || !s || e.store.getSnapshot().lifecycle !== "running") return;
29
+ const h = s;
30
+ s = null, t = !0;
31
+ let u;
32
+ try {
33
+ u = e.setMediaSource(h.params);
34
+ } catch (p) {
35
+ u = Promise.reject(p);
36
+ }
37
+ u.then(h.resolve, h.reject).finally(() => {
38
+ t = !1, i();
39
+ });
40
+ }, r = e.store.subscribe(i), a = (h) => n ? Promise.reject(ze()) : new Promise((u, p) => {
41
+ s == null || s.reject(ze()), s = { params: h, resolve: u, reject: p }, i();
42
+ }), o = (h, u) => {
43
+ let p;
44
+ if (u === "video") p = "video";
45
+ else if (u === "image") p = "image";
46
+ else return Promise.reject(new O(`Invalid footage kind: ${String(u)}`));
47
+ return typeof h != "object" || h === null || typeof h.getTracks != "function" ? Promise.reject(new O("Footage stream must be a MediaStream")) : a({ source: I.STREAM, stream: h, sourceKind: p });
48
+ }, d = () => a({ source: I.WEBCAM }), l = () => {
49
+ n || (n = !0, r(), s == null || s.reject(ze()), s = null);
50
+ };
51
+ return { handle: Object.freeze({ v: 1, setStream: o, useCamera: d }), dispose: l };
52
+ }, Js = (e, s = typeof window > "u" ? void 0 : window) => {
53
+ if (!s || !js(s)) return () => {
54
+ };
55
+ const t = s;
56
+ if (t[Ce] !== void 0) return () => {
57
+ };
58
+ const n = Qs(e);
59
+ return Object.defineProperty(s, Ce, {
60
+ value: n.handle,
61
+ configurable: !0,
62
+ enumerable: !1,
63
+ writable: !1
64
+ }), () => {
65
+ n.dispose(), t[Ce] === n.handle && delete t[Ce];
66
+ };
67
+ }, q = {
68
+ // Pinned to the CDN, NOT build-env-driven: a stale VITE_ASSET_STORAGE_ENDPOINT
69
+ // baked a now-deleted CloudFront domain into every published bundle, breaking
70
+ // WASM/model loads at runtime. The host must never come from a mutable env value.
71
+ assetStorageEndpoint: "https://cdn.vincentt.studio",
72
+ // Versioned bucket for SDK-shipped reference assets (canonical face model, face textures, etc.).
73
+ sdkAssetsBaseUrl: "https://cdn.vincentt.studio/assets/sdk/face/v1",
74
+ // Debug-ui sample media (the preview presets: clips and stills). Overridable
75
+ // at app start — the playground points it at a local folder while new clips
76
+ // are reviewed before they are published to the CDN.
77
+ debugMediaBaseUrl: "https://cdn.vincentt.studio/assets/sdk/debug-ui/v1",
78
+ loggerPrefix: "[vincentt-xr]:",
79
+ sessionCheckInterval: 3e4
80
+ }, We = (e) => Array.from({ length: e }, () => ({ x: 0, y: 0, z: 0 }));
81
+ class Zs {
82
+ constructor(s) {
83
+ m(this, "slots", []);
84
+ this.options = s;
85
+ }
86
+ setOptions(s) {
87
+ this.options = s;
88
+ }
89
+ /** Landmark sets to draw this frame: live faces, plus held/predicted ones. */
90
+ update(s, t) {
91
+ const { holdMs: n, predictMs: i, maxVelocityGapMs: r = 250 } = this.options, a = [], o = Math.max(s.length, this.slots.length);
92
+ for (let d = 0; d < o; d += 1) {
93
+ const l = s[d], h = this.slots[d] ?? null;
94
+ if (l && l.length > 0) {
95
+ const M = h && h.points.length === l.length ? h : null, x = M ?? {
96
+ points: We(l.length),
97
+ velocity: We(l.length),
98
+ lastSeen: t,
99
+ output: We(l.length)
100
+ }, b = (t - x.lastSeen) / 1e3, T = M !== null && b > 0 && b * 1e3 <= r;
101
+ for (let R = 0; R < l.length; R += 1) {
102
+ const w = l[R], g = x.points[R], y = x.velocity[R], v = w.z ?? 0;
103
+ T ? (y.x = 0.5 * y.x + 0.5 * ((w.x - g.x) / b), y.y = 0.5 * y.y + 0.5 * ((w.y - g.y) / b), y.z = 0.5 * y.z + 0.5 * ((v - g.z) / b)) : (y.x = 0, y.y = 0, y.z = 0), g.x = w.x, g.y = w.y, g.z = v;
104
+ }
105
+ x.lastSeen = t, this.slots[d] = x, a.push(l);
106
+ continue;
107
+ }
108
+ if (!h) continue;
109
+ const u = t - h.lastSeen;
110
+ if (u > n) {
111
+ this.slots[d] = null;
112
+ continue;
113
+ }
114
+ const p = Math.max(0, Math.min(u, i)) / 1e3;
115
+ for (let M = 0; M < h.points.length; M += 1)
116
+ h.output[M].x = h.points[M].x + h.velocity[M].x * p, h.output[M].y = h.points[M].y + h.velocity[M].y * p, h.output[M].z = h.points[M].z + h.velocity[M].z * p;
117
+ a.push(h.output);
118
+ }
119
+ for (; this.slots.length > 0 && this.slots[this.slots.length - 1] === null; ) this.slots.pop();
120
+ return a;
121
+ }
122
+ reset() {
123
+ this.slots = [];
124
+ }
125
+ }
126
+ const me = (e, s = { x: 0, y: 0, z: 0 }) => (s.x = e.x * 2 - 1, s.y = 1 - e.y * 2, s.z = -e.z, s), $s = (e, s = { x: 0, y: 0, z: 0 }) => (s.x = (e.x + 1) / 2, s.y = (1 - e.y) / 2, s.z = -e.z, s), Ut = "https://storage.googleapis.com/mediapipe-models/holistic_landmarker/holistic_landmarker/float16/latest/holistic_landmarker.task", en = 250, tn = 0, sn = 768, Ze = (e) => ({
127
+ hands: (e == null ? void 0 : e.hands) ?? "both",
128
+ analysisMaxDimension: (e == null ? void 0 : e.analysisMaxDimension) ?? sn,
129
+ holdMs: (e == null ? void 0 : e.holdMs) ?? en,
130
+ predictMs: (e == null ? void 0 : e.predictMs) ?? tn
131
+ }), nn = () => ({
132
+ version: 0,
133
+ timestampMs: 0,
134
+ face: null,
135
+ leftHand: null,
136
+ rightHand: null,
137
+ pose: null
138
+ }), Mt = [
139
+ 0,
140
+ 4,
141
+ 5,
142
+ 6,
143
+ 1,
144
+ 2,
145
+ 3,
146
+ 8,
147
+ 7,
148
+ 10,
149
+ 9,
150
+ 12,
151
+ 11,
152
+ 14,
153
+ 13,
154
+ 16,
155
+ 15,
156
+ 18,
157
+ 17,
158
+ 20,
159
+ 19,
160
+ 22,
161
+ 21,
162
+ 24,
163
+ 23,
164
+ 26,
165
+ 25,
166
+ 28,
167
+ 27,
168
+ 30,
169
+ 29,
170
+ 32,
171
+ 31
172
+ ], bt = (e, s) => {
173
+ if (e.length !== Mt.length) return e;
174
+ s.length = e.length;
175
+ for (let t = 0; t < e.length; t += 1) s[t] = e[Mt[t]];
176
+ return s;
177
+ };
178
+ class Te {
179
+ constructor(s, t) {
180
+ m(this, "memory");
181
+ m(this, "holdMs");
182
+ m(this, "lastLiveMs", -1 / 0);
183
+ m(this, "lastConfidence", 0);
184
+ this.holdMs = s, this.memory = new Zs({ holdMs: s, predictMs: t });
185
+ }
186
+ setOptions(s, t) {
187
+ this.holdMs = s, this.memory.setOptions({ holdMs: s, predictMs: t });
188
+ }
189
+ reset() {
190
+ this.memory.reset(), this.lastLiveMs = -1 / 0, this.lastConfidence = 0;
191
+ }
192
+ /**
193
+ * Returns the landmarks to publish this frame (live, or replayed from
194
+ * memory), or `undefined` when the stream is neither detected nor held.
195
+ * A held stream's confidence decays linearly from the last live value to
196
+ * 0 at `holdMs`.
197
+ */
198
+ bridge(s, t, n) {
199
+ const i = s !== void 0 && s.length > 0, r = this.memory.update(i ? [s] : [], n)[0];
200
+ if (!r) return;
201
+ if (i)
202
+ return this.lastLiveMs = n, this.lastConfidence = t, { points: r, held: !1, confidence: t };
203
+ const a = n - this.lastLiveMs, o = this.holdMs > 0 ? Math.max(0, 1 - a / this.holdMs) : 0;
204
+ return { points: r, held: !0, confidence: this.lastConfidence * o };
205
+ }
206
+ }
207
+ const ce = (e, s, t) => {
208
+ for (e.length > s && (e.length = s); e.length < s; ) e.push(t());
209
+ return e;
210
+ }, qe = (e, s) => {
211
+ e.x = s.x, e.y = s.y, e.z = s.z;
212
+ }, rn = (e) => {
213
+ if (e.length === 0) return 0;
214
+ let s = 0;
215
+ for (let t = 0; t < e.length; t += 1) s += e[t].visibility ?? 0;
216
+ return s / e.length;
217
+ };
218
+ class an {
219
+ constructor(s) {
220
+ m(this, "options", Ze());
221
+ m(this, "faceMemory", new Te(this.options.holdMs, this.options.predictMs));
222
+ m(this, "leftHandMemory", new Te(this.options.holdMs, this.options.predictMs));
223
+ m(this, "rightHandMemory", new Te(this.options.holdMs, this.options.predictMs));
224
+ m(this, "poseMemory", new Te(this.options.holdMs, this.options.predictMs));
225
+ m(this, "face", {
226
+ landmarks: [],
227
+ blendshapes: {},
228
+ confidence: 0,
229
+ held: !1
230
+ });
231
+ m(this, "leftHand", {
232
+ handedness: "left",
233
+ landmarks: [],
234
+ worldLandmarks: [],
235
+ confidence: 0,
236
+ held: !1
237
+ });
238
+ m(this, "rightHand", {
239
+ handedness: "right",
240
+ landmarks: [],
241
+ worldLandmarks: [],
242
+ confidence: 0,
243
+ held: !1
244
+ });
245
+ m(this, "poseScratch", []);
246
+ m(this, "poseWorldScratch", []);
247
+ m(this, "pose", {
248
+ landmarks: [],
249
+ worldLandmarks: [],
250
+ visibility: [],
251
+ confidence: 0,
252
+ held: !1
253
+ });
254
+ this.setOptions(s);
255
+ }
256
+ getOptions() {
257
+ return this.options;
258
+ }
259
+ setOptions(s) {
260
+ this.options = Ze({ ...this.options, ...s });
261
+ const { holdMs: t, predictMs: n } = this.options;
262
+ for (const i of this.memories()) i.setOptions(t, n);
263
+ }
264
+ reset() {
265
+ for (const s of this.memories()) s.reset();
266
+ }
267
+ memories() {
268
+ return [this.faceMemory, this.leftHandMemory, this.rightHandMemory, this.poseMemory];
269
+ }
270
+ /**
271
+ * Publish `raw` (or a miss when `undefined`) into `result` at `nowMs`.
272
+ *
273
+ * `mirrored` says the analysed frame is a mirror of the person (the
274
+ * session's webcam feed). Pose left/right follow the image, and holistic
275
+ * assigns hands from the pose, so on a mirrored frame MediaPipe's "left"
276
+ * is the person's right. Swap both the hands and the pose's left/right
277
+ * landmarks so the whole result is anatomical and self-consistent
278
+ * (`leftHand` and pose wrist 15 are the same physical hand), matching the
279
+ * convention `HandTracker` reports on that feed.
280
+ */
281
+ update(s, t, n, i = !1) {
282
+ var l, h, u, p;
283
+ n.face = this.updateFace(s, t);
284
+ const r = {
285
+ landmarks: (l = s == null ? void 0 : s.leftHandLandmarks) == null ? void 0 : l[0],
286
+ world: (h = s == null ? void 0 : s.leftHandWorldLandmarks) == null ? void 0 : h[0]
287
+ }, a = {
288
+ landmarks: (u = s == null ? void 0 : s.rightHandLandmarks) == null ? void 0 : u[0],
289
+ world: (p = s == null ? void 0 : s.rightHandWorldLandmarks) == null ? void 0 : p[0]
290
+ }, o = i ? a : r, d = i ? r : a;
291
+ return n.leftHand = this.updateHand("left", o.landmarks, o.world, t), n.rightHand = this.updateHand("right", d.landmarks, d.world, t), n.pose = this.updatePose(s, t, i), n.timestampMs = t, n.version += 1, n;
292
+ }
293
+ updateFace(s, t) {
294
+ var o, d, l, h;
295
+ const n = (o = s == null ? void 0 : s.faceLandmarks) == null ? void 0 : o[0], i = this.faceMemory.bridge(n, 1, t);
296
+ if (!i) return null;
297
+ const { face: r } = this, a = !i.held && n;
298
+ ce(r.landmarks, i.points.length, () => ({
299
+ x: 0,
300
+ y: 0,
301
+ z: 0,
302
+ visibility: 0
303
+ }));
304
+ for (let u = 0; u < i.points.length; u += 1) {
305
+ const p = r.landmarks[u];
306
+ qe(p, i.points[u]), p.visibility = a ? ((d = n[u]) == null ? void 0 : d.visibility) ?? 0 : 0;
307
+ }
308
+ if (a) {
309
+ const u = (h = (l = s == null ? void 0 : s.faceBlendshapes) == null ? void 0 : l[0]) == null ? void 0 : h.categories;
310
+ if (u)
311
+ for (const p of u) r.blendshapes[p.categoryName] = p.score;
312
+ }
313
+ return r.confidence = i.confidence, r.held = i.held, r;
314
+ }
315
+ updateHand(s, t, n, i) {
316
+ const r = s === "left" ? this.leftHandMemory : this.rightHandMemory, { hands: a } = this.options;
317
+ if (a === "none" || a !== "both" && a !== s)
318
+ return r.reset(), null;
319
+ const o = r.bridge(t, 1, i);
320
+ if (!o) return null;
321
+ const d = s === "left" ? this.leftHand : this.rightHand;
322
+ ce(d.landmarks, o.points.length, () => ({ x: 0, y: 0, z: 0 }));
323
+ for (let l = 0; l < o.points.length; l += 1)
324
+ me(o.points[l], d.landmarks[l]);
325
+ if (!o.held && n) {
326
+ ce(d.worldLandmarks, n.length, () => ({ x: 0, y: 0, z: 0 }));
327
+ for (let l = 0; l < n.length; l += 1) qe(d.worldLandmarks[l], n[l]);
328
+ }
329
+ return d.confidence = o.confidence, d.held = o.held, d;
330
+ }
331
+ updatePose(s, t, n) {
332
+ var u, p, M;
333
+ const i = (u = s == null ? void 0 : s.poseLandmarks) == null ? void 0 : u[0], r = i && n ? bt(i, this.poseScratch) : i, a = this.poseMemory.bridge(r, r ? rn(r) : 0, t);
334
+ if (!a) return null;
335
+ const { pose: o } = this, d = !a.held && r;
336
+ ce(o.landmarks, a.points.length, () => ({ x: 0, y: 0, z: 0 })), ce(o.visibility, a.points.length, () => 0);
337
+ for (let x = 0; x < a.points.length; x += 1)
338
+ me(a.points[x], o.landmarks[x]), d && (o.visibility[x] = ((p = r[x]) == null ? void 0 : p.visibility) ?? 0);
339
+ const l = (M = s == null ? void 0 : s.poseWorldLandmarks) == null ? void 0 : M[0], h = l && n ? bt(l, this.poseWorldScratch) : l;
340
+ if (d && h) {
341
+ ce(o.worldLandmarks, h.length, () => ({ x: 0, y: 0, z: 0 }));
342
+ for (let x = 0; x < h.length; x += 1) qe(o.worldLandmarks[x], h[x]);
343
+ }
344
+ return o.confidence = a.confidence, o.held = a.held, o;
345
+ }
346
+ }
347
+ const zt = {
348
+ "camera-permission-denied": "Camera access was blocked. Allow camera permissions in your browser, then refresh.",
349
+ "camera-in-use": "Camera is already in use by another app or browser tab. Close it and refresh.",
350
+ "no-camera": "No camera was found on this device.",
351
+ "camera-insecure-context": "Camera access needs HTTPS (or localhost). Open the page over HTTPS.",
352
+ "camera-unsupported": "This browser cannot open the camera.",
353
+ "camera-lost": "The camera stopped sending frames (disconnected, revoked, or taken by another app).",
354
+ "webgl-unavailable": "WebGL is unavailable, so nothing can render or track.",
355
+ "offscreen-canvas-unavailable": "OffscreenCanvas is unavailable; the tracker feed cannot be built.",
356
+ "wasm-unavailable": "WebAssembly is unavailable; the tracking engine cannot load.",
357
+ "model-unreachable": "The tracker model could not be downloaded.",
358
+ "model-integrity": "The tracker model failed its integrity check.",
359
+ "model-init-failed": "The tracker failed to initialize on this device.",
360
+ "placement-unsupported": "This device cannot place 3D objects in the room (no WebXR, Scene Viewer or Quick Look).",
361
+ unknown: "Tracking is unavailable for an unknown reason."
362
+ }, on = {
363
+ "camera-permission-denied": !0,
364
+ "camera-in-use": !0,
365
+ "no-camera": !1,
366
+ "camera-insecure-context": !1,
367
+ "camera-unsupported": !1,
368
+ "camera-lost": !0,
369
+ "webgl-unavailable": !1,
370
+ "offscreen-canvas-unavailable": !1,
371
+ "wasm-unavailable": !1,
372
+ "model-unreachable": !0,
373
+ "model-integrity": !1,
374
+ "model-init-failed": !1,
375
+ "placement-unsupported": !1,
376
+ unknown: !0
377
+ }, _ = (e, s = zt[e]) => ({ code: e, message: s, recoverable: on[e] }), cn = {
378
+ [P.FACE_TRACKER]: "/assets/xr/models/face_tracking.task",
379
+ [P.HAND_TRACKER]: "/assets/xr/models/hand_tracking.task",
380
+ [P.GESTURE_TRACKER]: "/assets/xr/models/gesture_tracking.task",
381
+ [P.BODY_TRACKER]: "/assets/xr/models/body_tracking.task",
382
+ [P.BACKGROUND_SEGMENTATION]: "/assets/xr/models/segmentation.tflite",
383
+ [P.SEMANTIC_SEGMENTATION]: "/assets/xr/models/selfie_multiclass_256x256.tflite",
384
+ [P.HOLISTIC_TRACKER]: Ut
385
+ }, Wt = (e) => {
386
+ const s = cn[e];
387
+ return s ? /^https?:/.test(s) ? s : new URL(s, q.assetStorageEndpoint).toString() : null;
388
+ }, ln = Object.values(P), dn = () => {
389
+ var t, n, i;
390
+ const e = typeof window < "u", s = typeof document < "u";
391
+ return {
392
+ navigator: typeof navigator < "u" ? navigator : void 0,
393
+ isSecureContext: e ? window.isSecureContext : void 0,
394
+ createCanvas: s ? () => document.createElement("canvas") : void 0,
395
+ offscreenCanvas: typeof OffscreenCanvas < "u",
396
+ wasm: typeof WebAssembly < "u",
397
+ fetch: typeof fetch < "u" ? fetch.bind(globalThis) : void 0,
398
+ now: () => typeof performance < "u" ? performance.now() : Date.now(),
399
+ xrSessionSupported: typeof navigator < "u" && ((t = navigator.xr) != null && t.isSessionSupported) ? (r) => navigator.xr.isSessionSupported(r).catch(() => !1) : void 0,
400
+ relSupportsAr: s ? ((i = (n = document.createElement("a").relList) == null ? void 0 : n.supports) == null ? void 0 : i.call(n, "ar")) === !0 : void 0,
401
+ userAgent: typeof navigator < "u" ? navigator.userAgent : void 0
402
+ };
403
+ }, hn = (e) => !!e && /Android/.test(e) && /(Chrome|SamsungBrowser)\//.test(e) && !/Firefox|OPR\//.test(e), un = async (e) => {
404
+ let s = !1;
405
+ if (e.xrSessionSupported)
406
+ try {
407
+ s = await e.xrSessionSupported("immersive-ar");
408
+ } catch {
409
+ s = !1;
410
+ }
411
+ const t = hn(e.userAgent), n = e.relSupportsAr === !0, i = s || t || n;
412
+ return {
413
+ webxr: s,
414
+ sceneViewer: t,
415
+ quickLook: n,
416
+ any: i,
417
+ reason: i ? null : _("placement-unsupported")
418
+ };
419
+ }, mn = (e) => {
420
+ switch (e) {
421
+ case "granted":
422
+ return "supported";
423
+ case "denied":
424
+ return "permission-denied";
425
+ case "prompt":
426
+ return "permission-prompt";
427
+ default:
428
+ return "unknown";
429
+ }
430
+ }, fn = async (e, s) => {
431
+ var o, d, l;
432
+ const t = e.isSecureContext ?? !0, n = (o = e.navigator) == null ? void 0 : o.mediaDevices;
433
+ if (!t)
434
+ return {
435
+ status: "unsupported",
436
+ reason: _("camera-insecure-context"),
437
+ deviceCount: null,
438
+ secureContext: t
439
+ };
440
+ if (!n || typeof n.getUserMedia != "function")
441
+ return {
442
+ status: "unsupported",
443
+ reason: _("camera-unsupported"),
444
+ deviceCount: null,
445
+ secureContext: t
446
+ };
447
+ let i = "unknown";
448
+ if (s && ((l = (d = e.navigator) == null ? void 0 : d.permissions) != null && l.query))
449
+ try {
450
+ const h = await e.navigator.permissions.query({ name: "camera" });
451
+ i = mn(h.state);
452
+ } catch {
453
+ i = "unknown";
454
+ }
455
+ let r = null, a = !1;
456
+ if (typeof n.enumerateDevices == "function")
457
+ try {
458
+ const h = await n.enumerateDevices();
459
+ r = h.filter((u) => u.kind === "videoinput").length, a = h.some((u) => !!u.label);
460
+ } catch {
461
+ r = null;
462
+ }
463
+ return i === "permission-denied" ? {
464
+ status: i,
465
+ reason: _("camera-permission-denied"),
466
+ deviceCount: r,
467
+ secureContext: t
468
+ } : r === 0 && (i === "supported" || a) ? {
469
+ status: "unsupported",
470
+ reason: _("no-camera"),
471
+ deviceCount: r,
472
+ secureContext: t
473
+ } : { status: i, reason: null, deviceCount: r, secureContext: t };
474
+ }, gn = (e) => {
475
+ var t;
476
+ const s = (t = e.createCanvas) == null ? void 0 : t.call(e);
477
+ if (!s) return 0;
478
+ try {
479
+ if (s.getContext("webgl2")) return 2;
480
+ if (s.getContext("webgl") || s.getContext("experimental-webgl")) return 1;
481
+ } catch {
482
+ return 0;
483
+ }
484
+ return 0;
485
+ }, pn = (e) => {
486
+ var a;
487
+ const s = gn(e), t = e.offscreenCanvas ?? !1, n = e.wasm ?? !1, i = !!((a = e.navigator) != null && a.gpu);
488
+ let r = null;
489
+ return s === 0 ? r = _("webgl-unavailable") : t ? n || (r = _("wasm-unavailable")) : r = _("offscreen-canvas-unavailable"), {
490
+ status: r ? "unsupported" : "supported",
491
+ reason: r,
492
+ webglVersion: s,
493
+ webgpu: i,
494
+ offscreenCanvas: t,
495
+ wasm: n
496
+ };
497
+ }, yn = async (e, s, t) => {
498
+ var a, o;
499
+ const n = Wt(e);
500
+ if (!n || !s.fetch)
501
+ return { model: e, status: "unknown", reason: null, url: n, bytes: null };
502
+ const i = typeof AbortController < "u" ? new AbortController() : void 0, r = setTimeout(() => i == null ? void 0 : i.abort(), t);
503
+ try {
504
+ const d = await s.fetch(n, { method: "HEAD", signal: i == null ? void 0 : i.signal });
505
+ if (!d.ok)
506
+ return {
507
+ model: e,
508
+ status: "unsupported",
509
+ reason: _(
510
+ "model-unreachable",
511
+ `${zt["model-unreachable"]} (${d.status})`
512
+ ),
513
+ url: n,
514
+ bytes: null
515
+ };
516
+ const l = Number(((o = (a = d.headers) == null ? void 0 : a.get) == null ? void 0 : o.call(a, "content-length")) ?? NaN);
517
+ return {
518
+ model: e,
519
+ status: "supported",
520
+ reason: null,
521
+ url: n,
522
+ bytes: Number.isFinite(l) && l > 0 ? l : null
523
+ };
524
+ } catch {
525
+ return {
526
+ model: e,
527
+ status: "unsupported",
528
+ reason: _("model-unreachable"),
529
+ url: n,
530
+ bytes: null
531
+ };
532
+ } finally {
533
+ clearTimeout(r);
534
+ }
535
+ }, dr = async (e = {}, s = dn()) => {
536
+ const t = e.timeoutMs ?? 4e3, n = new Set(e.models ?? []), [i, r, a] = await Promise.all([
537
+ fn(s, e.queryPermission ?? !0),
538
+ Promise.all(
539
+ ln.map(
540
+ async (l) => n.has(l) ? yn(l, s, t) : {
541
+ model: l,
542
+ status: "unknown",
543
+ reason: null,
544
+ url: Wt(l),
545
+ bytes: null
546
+ }
547
+ )
548
+ ),
549
+ un(s)
550
+ ]), o = pn(s), d = Object.fromEntries(r.map((l) => [l.model, l]));
551
+ return {
552
+ camera: i,
553
+ rendering: o,
554
+ placement: a,
555
+ models: d,
556
+ canRunTracking: o.status === "supported" && i.status !== "unsupported",
557
+ checkedAt: s.now ? s.now() : Date.now()
558
+ };
559
+ }, qt = (e) => {
560
+ switch (e) {
561
+ case "permission-denied":
562
+ return _("camera-permission-denied");
563
+ case "camera-in-use":
564
+ return _("camera-in-use");
565
+ case "no-camera":
566
+ return _("no-camera");
567
+ case "camera-lost":
568
+ return _("camera-lost");
569
+ case "unsupported":
570
+ return _("camera-unsupported");
571
+ default:
572
+ return _("unknown");
573
+ }
574
+ }, hr = (e, s) => {
575
+ const { camera: t, rendering: n } = e, i = e.models[s], r = t.status === "permission-prompt" || t.status === "unknown";
576
+ return n.reason ? { supported: !1, reason: n.reason, needsPermission: r } : t.reason ? { supported: !1, reason: t.reason, needsPermission: r } : i != null && i.reason ? { supported: !1, reason: i.reason, needsPermission: r } : { supported: !0, reason: null, needsPermission: r };
577
+ }, ur = (e) => {
578
+ const s = e instanceof Error ? e.message : String(e ?? ""), t = s.toLowerCase();
579
+ return t.includes("integrity") || t.includes("sha-384") || t.includes("sha384") ? _("model-integrity", s) : t.includes("failed to fetch") || t.includes("networkerror") || t.includes("load failed") || /\b(404|403|5\d\d)\b/.test(t) || t.includes("fetch") ? _("model-unreachable", s) : t.includes("webgl") || t.includes("gpu") ? _("webgl-unavailable", s) : s ? _("model-init-failed", s) : _("unknown");
580
+ }, Vt = (e) => {
581
+ switch (e instanceof DOMException ? e.name : "") {
582
+ case "NotAllowedError":
583
+ case "PermissionDeniedError":
584
+ return "permission-denied";
585
+ case "NotReadableError":
586
+ case "TrackStartError":
587
+ return "camera-in-use";
588
+ case "NotFoundError":
589
+ case "DevicesNotFoundError":
590
+ return "no-camera";
591
+ case "NotSupportedError":
592
+ case "SecurityError":
593
+ case "OverconstrainedError":
594
+ return "unsupported";
595
+ default:
596
+ return e instanceof TypeError ? "unsupported" : "unknown";
597
+ }
598
+ }, kt = {
599
+ "permission-denied": "Camera access was blocked. Allow camera permissions in your browser, then refresh.",
600
+ "camera-in-use": "Camera is already in use by another app or browser tab. Close it and refresh.",
601
+ "no-camera": "No camera was found on this device.",
602
+ "camera-lost": "The camera stopped sending frames. Reconnect it or re-allow access, then start again.",
603
+ unsupported: "Unable to access camera. Allow camera permissions in your browser, then refresh.",
604
+ unknown: "Unable to access camera. Allow camera permissions in your browser, then refresh."
605
+ }, tt = () => ({
606
+ mediaDevices: typeof navigator < "u" ? navigator.mediaDevices : void 0,
607
+ permissions: typeof navigator < "u" ? navigator.permissions : void 0,
608
+ isSecureContext: typeof window < "u" ? window.isSecureContext : void 0
609
+ }), Kt = async (e = tt()) => {
610
+ var s;
611
+ if (!((s = e.permissions) != null && s.query)) return { state: "unknown", prompt: !1 };
612
+ try {
613
+ const t = await e.permissions.query({ name: "camera" });
614
+ return t.state === "granted" ? { state: "granted", prompt: !1 } : t.state === "denied" ? { state: "blocked", prompt: !1 } : { state: "unknown", prompt: t.state === "prompt" };
615
+ } catch {
616
+ return { state: "unknown", prompt: !1 };
617
+ }
618
+ }, Gt = (e, s) => e === "permission-denied" ? {
619
+ state: s === "blocked" ? "blocked" : "denied",
620
+ reason: _("camera-permission-denied")
621
+ } : { state: "unavailable", reason: qt(e) }, mr = async (e = {}, s = tt()) => {
622
+ var n;
623
+ if (s.isSecureContext === !1)
624
+ return {
625
+ state: "unavailable",
626
+ reason: _("camera-insecure-context"),
627
+ stream: null
628
+ };
629
+ const t = (n = s.mediaDevices) == null ? void 0 : n.getUserMedia;
630
+ if (typeof t != "function")
631
+ return {
632
+ state: "unavailable",
633
+ reason: _("camera-unsupported"),
634
+ stream: null
635
+ };
636
+ try {
637
+ const i = await t.call(
638
+ s.mediaDevices,
639
+ e.constraints ?? { video: { facingMode: "user" } }
640
+ );
641
+ return e.keepStream ? { state: "granted", reason: null, stream: i } : (i.getTracks().forEach((r) => r.stop()), { state: "granted", reason: null, stream: null });
642
+ } catch (i) {
643
+ const r = Vt(i), a = await Kt(s);
644
+ return { ...Gt(r, a.state), stream: null };
645
+ }
646
+ }, fr = async (e, s = tt()) => {
647
+ var t, n;
648
+ if (!((t = s.permissions) != null && t.query)) return () => {
649
+ };
650
+ try {
651
+ const i = await s.permissions.query({ name: "camera" }), r = () => {
652
+ i.state === "granted" ? e({ state: "granted", prompt: !1 }) : i.state === "denied" ? e({ state: "blocked", prompt: !1 }) : e({ state: "unknown", prompt: i.state === "prompt" });
653
+ };
654
+ return (n = i.addEventListener) == null || n.call(i, "change", r), () => {
655
+ var a;
656
+ return (a = i.removeEventListener) == null ? void 0 : a.call(i, "change", r);
657
+ };
658
+ } catch {
659
+ return () => {
660
+ };
661
+ }
662
+ }, gr = (e) => e === "unknown" || e === "denied" || e === "granted", pr = {
663
+ unknown: "This experience uses your camera. Nothing is recorded or uploaded.",
664
+ requesting: "Waiting for you to allow the camera…",
665
+ granted: "Camera access granted.",
666
+ denied: "Camera access was not allowed. You can try again.",
667
+ blocked: "Camera access is blocked for this site. Allow it in your browser's site settings, then reload.",
668
+ unavailable: "The camera is unavailable on this device right now."
669
+ }, wn = (e, s, t = "cover", n = 1) => {
670
+ if (e.width <= 0 || e.height <= 0 || s.width <= 0 || s.height <= 0)
671
+ return null;
672
+ const i = Number.isFinite(n) && n > 0 ? n : 1, r = s.width / e.width, a = s.height / e.height, o = t === "contain" ? a <= r : a >= r, d = (o ? a : r) * i, l = o ? e.width * a * i : s.width * i, h = o ? s.height * i : e.height * r * i;
673
+ return {
674
+ scale: d,
675
+ drawWidth: l,
676
+ drawHeight: h,
677
+ offsetX: (s.width - l) / 2,
678
+ offsetY: (s.height - h) / 2
679
+ };
680
+ }, Se = (e) => e === "webcam" || e === void 0, vn = ({
681
+ source: e,
682
+ feed: s,
683
+ zoom: t = 1,
684
+ mirrored: n = !1
685
+ }) => {
686
+ const i = wn(e, s, "cover", t);
687
+ return i ? { ...i, source: e, feed: s, zoom: Number.isFinite(t) && t > 0 ? t : 1, mirrored: n } : null;
688
+ }, yr = (e, s, t = { x: 0, y: 0 }) => {
689
+ const n = s.mirrored ? s.source.width - e.x : e.x;
690
+ return t.x = (s.offsetX + n * s.scale) / s.feed.width, t.y = (s.offsetY + e.y * s.scale) / s.feed.height, t;
691
+ }, xn = (e, s, t = { x: 0, y: 0 }) => {
692
+ const n = (e.x * s.feed.width - s.offsetX) / s.scale;
693
+ return t.x = s.mirrored ? s.source.width - n : n, t.y = (e.y * s.feed.height - s.offsetY) / s.scale, t;
694
+ }, wr = (e, s) => {
695
+ const t = xn(e, s);
696
+ return t.x >= 0 && t.x <= s.source.width && t.y >= 0 && t.y <= s.source.height;
697
+ }, vr = (e, s = { x: 0, y: 0 }) => (s.x = 1 - e.x, s.y = e.y, e.z !== void 0 && (s.z = e.z), s), xr = (e, s, t, n = { x: 0, y: 0 }) => {
698
+ switch (t) {
699
+ case 90:
700
+ return n.x = s.height - e.y, n.y = e.x, n;
701
+ case 180:
702
+ return n.x = s.width - e.x, n.y = s.height - e.y, n;
703
+ case 270:
704
+ return n.x = e.y, n.y = s.width - e.x, n;
705
+ default:
706
+ return n.x = e.x, n.y = e.y, n;
707
+ }
708
+ }, Sr = (e, s) => s === 90 || s === 270 ? { width: e.height, height: e.width } : { width: e.width, height: e.height };
709
+ class Sn {
710
+ constructor(s) {
711
+ m(this, "options");
712
+ const t = {
713
+ verbose: !1,
714
+ prefix: q.loggerPrefix
715
+ };
716
+ this.options = { ...t, ...s };
717
+ }
718
+ log(...s) {
719
+ const { verbose: t, prefix: n } = this.options;
720
+ t && console.info(n, ...s);
721
+ }
722
+ error(...s) {
723
+ const { verbose: t, prefix: n } = this.options;
724
+ t && console.error(n, ...s);
725
+ }
726
+ }
727
+ const Xt = [
728
+ "nose",
729
+ "leftEyeInner",
730
+ "leftEye",
731
+ "leftEyeOuter",
732
+ "rightEyeInner",
733
+ "rightEye",
734
+ "rightEyeOuter",
735
+ "leftEar",
736
+ "rightEar",
737
+ "mouthLeft",
738
+ "mouthRight",
739
+ "leftShoulder",
740
+ "rightShoulder",
741
+ "leftElbow",
742
+ "rightElbow",
743
+ "leftWrist",
744
+ "rightWrist",
745
+ "leftPinky",
746
+ "rightPinky",
747
+ "leftIndex",
748
+ "rightIndex",
749
+ "leftThumb",
750
+ "rightThumb",
751
+ "leftHip",
752
+ "rightHip",
753
+ "leftKnee",
754
+ "rightKnee",
755
+ "leftAnkle",
756
+ "rightAnkle",
757
+ "leftHeel",
758
+ "rightHeel",
759
+ "leftFootIndex",
760
+ "rightFootIndex"
761
+ ], ye = Object.fromEntries(
762
+ Xt.map((e, s) => [e, s])
763
+ ), Mn = (e) => e === "mouthLeft" ? "mouthRight" : e === "mouthRight" ? "mouthLeft" : e.startsWith("left") ? `right${e.slice(4)}` : e.startsWith("right") ? `left${e.slice(5)}` : e, bn = Object.freeze(
764
+ Xt.map((e) => ye[Mn(e)])
765
+ ), kn = (e, s = { x: 0, y: 0, z: 0 }) => (s.x = e.x * 100, s.y = -e.y * 100, s.z = -e.z * 100, s), Cn = (e, s, t) => {
766
+ if (!s) return { ...e, timestampMs: t };
767
+ const n = (i) => i.map((r, a) => i[bn[a] ?? a] ?? i[a]);
768
+ return {
769
+ world: n(e.world),
770
+ image: n(e.image),
771
+ visibility: n(e.visibility),
772
+ timestampMs: t
773
+ };
774
+ }, Tn = Object.freeze({
775
+ holdMs: 250,
776
+ maxJump: 1,
777
+ duplicate: 0.1,
778
+ confirm: 3,
779
+ confirmMs: 100
780
+ }), En = 1, Rn = 1.2, An = 200, Ve = [ye.leftShoulder, ye.rightShoulder, ye.leftHip, ye.rightHip], In = (e, s) => {
781
+ const t = Ve.map((p) => e.image[p]);
782
+ if (t.some((p) => !p)) return null;
783
+ const n = (p) => ({ x: p.x * s, y: p.y }), [i, r, a, o] = t.map(n), d = { x: (i.x + r.x) / 2, y: (i.y + r.y) / 2 }, l = { x: (a.x + o.x) / 2, y: (a.y + o.y) / 2 }, h = Math.max(
784
+ Math.hypot(d.x - l.x, d.y - l.y),
785
+ Math.hypot(i.x - r.x, i.y - r.y)
786
+ );
787
+ if (!(h > 1e-6)) return null;
788
+ const u = Ve.reduce((p, M) => p + (e.visibility[M] ?? 0), 0) / Ve.length;
789
+ return {
790
+ pose: e,
791
+ center: { x: (d.x + l.x) / 2, y: (d.y + l.y) / 2 },
792
+ size: h,
793
+ visibility: u
794
+ };
795
+ };
796
+ class Fn {
797
+ constructor(s = {}) {
798
+ m(this, "settings");
799
+ m(this, "tracks", []);
800
+ m(this, "nextId", 1);
801
+ this.settings = { ...Tn, ...s };
802
+ }
803
+ /**
804
+ * One detection's bodies (any order) at `nowMs`; `aspect` is the analysed
805
+ * frame's width / height. Returns every tracked body, by id.
806
+ */
807
+ update(s, t, n = 1) {
808
+ const { holdMs: i, maxJump: r, duplicate: a, confirm: o, confirmMs: d } = this.settings, l = this.dedupe(
809
+ s.map((g) => In(g, n)).filter((g) => !!g),
810
+ a
811
+ ), h = l.map(
812
+ (g) => this.tracks.map((y) => {
813
+ const v = Math.min(Math.max(t - y.lastSeenMs, 0), An), A = y.center.x + y.velocity.x * v, E = y.center.y + y.velocity.y * v, B = Math.max(y.size, g.size), K = Math.hypot(g.center.x - A, g.center.y - E) / B;
814
+ return K > r ? 1 / 0 : K + En * Math.abs(Math.log(g.size / y.size));
815
+ })
816
+ );
817
+ let u = l.map(() => -1), p = 1 / 0;
818
+ const M = [], x = /* @__PURE__ */ new Set(), b = (g, y) => {
819
+ if (!(y >= p)) {
820
+ if (g === l.length) {
821
+ u = [...M], p = y;
822
+ return;
823
+ }
824
+ for (let v = 0; v < this.tracks.length; v += 1) {
825
+ const A = h[g][v];
826
+ x.has(v) || A === 1 / 0 || (x.add(v), M[g] = v, b(g + 1, y + A), x.delete(v));
827
+ }
828
+ M[g] = -1, b(g + 1, y + Rn);
829
+ }
830
+ };
831
+ b(0, 0);
832
+ const T = /* @__PURE__ */ new Set(), w = !this.tracks.some((g) => g.id !== null) ? l.reduce(
833
+ (g, y, v) => u[v] < 0 && (!g || y.visibility > g.visibility) ? y : g,
834
+ null
835
+ ) : null;
836
+ l.forEach((g, y) => {
837
+ const v = u[y] >= 0 ? this.tracks[u[y]] : null;
838
+ if (!v) {
839
+ const E = {
840
+ id: null,
841
+ hits: 1,
842
+ firstSeenMs: t,
843
+ pose: g.pose,
844
+ center: g.center,
845
+ size: g.size,
846
+ velocity: { x: 0, y: 0 },
847
+ lastSeenMs: t
848
+ };
849
+ (g === w || o <= 1 && d <= 0) && this.confirm(E), this.tracks.push(E), T.add(E);
850
+ return;
851
+ }
852
+ v.hits += 1, v.id === null && v.hits >= o && t - v.firstSeenMs >= d && this.confirm(v);
853
+ const A = t - v.lastSeenMs;
854
+ A > 0 && (v.velocity = {
855
+ x: (v.velocity.x + (g.center.x - v.center.x) / A) / 2,
856
+ y: (v.velocity.y + (g.center.y - v.center.y) / A) / 2
857
+ }), v.pose = g.pose, v.center = g.center, v.size = g.size, v.lastSeenMs = t, T.add(v);
858
+ }), this.tracks = this.tracks.filter(
859
+ (g) => T.has(g) || g.id !== null && t - g.lastSeenMs <= i
860
+ );
861
+ for (const g of this.tracks) T.has(g) || (g.hits = 0);
862
+ return this.tracks.filter((g) => g.id !== null).map((g) => ({ id: g.id, pose: g.pose, held: !T.has(g) })).sort((g, y) => g.id - y.id);
863
+ }
864
+ confirm(s) {
865
+ s.id = this.nextId, this.nextId += 1;
866
+ }
867
+ /** Forget every body; ids keep counting up. */
868
+ reset() {
869
+ this.tracks = [];
870
+ }
871
+ /** One person detected twice (overlapping tracking regions): keep the more visible. */
872
+ dedupe(s, t) {
873
+ const n = [], i = [...s].sort((r, a) => a.visibility - r.visibility);
874
+ for (const r of i)
875
+ n.some(
876
+ (o) => Math.hypot(o.center.x - r.center.x, o.center.y - r.center.y) / Math.max(o.size, r.size) < t && Math.abs(Math.log(o.size / r.size)) < 0.1
877
+ ) || n.push(r);
878
+ return s.filter((r) => n.includes(r));
879
+ }
880
+ }
881
+ const Ct = (e, s) => {
882
+ let t = 1;
883
+ for (const n of e) Number.isFinite(n) && (t = Math.max(t, Math.round(n)));
884
+ return Math.min(t, s);
885
+ }, z = {
886
+ width: 720,
887
+ height: 1280
888
+ }, J = 32, Pn = 0.5, Ee = {
889
+ enabled: !0,
890
+ position: { x: 0, y: 0 },
891
+ size: { width: 680, height: 1230 },
892
+ pivot: [0.5, 0.5],
893
+ rotation: 0,
894
+ scale2D: { x: 1, y: 1 },
895
+ referencePixelsPerUnit: J,
896
+ renderOrder: 999,
897
+ overlay: !0,
898
+ visible: !0,
899
+ showTransformGuides: !1
900
+ }, _n = Math.PI / 180, Tt = (e, s) => s <= 0 ? e : Math.round(e / s) * s, Mr = ({
901
+ transform: e,
902
+ parentSize: s,
903
+ root: t = z,
904
+ snapIncrement: n = Pn
905
+ }) => {
906
+ const r = Math.min(s.width / t.width, s.height / t.height) * (J / e.referencePixelsPerUnit), a = e.size.width * e.scale2D.x * r, o = e.size.height * e.scale2D.y * r, d = Tt(e.position.x, n) * r, l = Tt(e.position.y, n) * r, h = (e.pivot[0] - 0.5) * a, u = (e.pivot[1] - 0.5) * o;
907
+ return {
908
+ center: [d - h, l - u, 0],
909
+ size: [a, o, 1],
910
+ rotation: [0, 0, e.rotation * _n],
911
+ pivotOffset: [h / Math.max(a, 1e-6), u / Math.max(o, 1e-6), 0],
912
+ aspect: a > 0 && o > 0 ? Math.abs(a / o) : 1
913
+ };
914
+ }, br = (e) => ({
915
+ ...Ee,
916
+ ...e,
917
+ position: { ...Ee.position, ...e == null ? void 0 : e.position },
918
+ size: { ...Ee.size, ...e == null ? void 0 : e.size },
919
+ scale2D: { ...Ee.scale2D, ...e == null ? void 0 : e.scale2D }
920
+ }), U = (e, s) => {
921
+ if (!Number.isFinite(e) || e <= 0) throw new RangeError(`${s} must be positive`);
922
+ return e;
923
+ }, Me = (e, s) => {
924
+ const t = U(s.width, "root.width"), n = U(s.height, "root.height");
925
+ return !Number.isFinite(e.width) || !Number.isFinite(e.height) || e.width <= 0 || e.height <= 0 ? 0 : Math.min(e.width / t, e.height / n);
926
+ }, st = (e, s, t, n) => s.width <= 0 || s.height <= 0 ? Object.assign(n, { x: 0, y: 0 }) : (U(t.width, "root.width"), U(t.height, "root.height"), n.x = (e.x / s.width - 0.5) * t.width, n.y = (0.5 - e.y / s.height) * t.height, n), nt = (e, s, t, n) => s.width <= 0 || s.height <= 0 ? Object.assign(n, { x: 0, y: 0 }) : (U(t.width, "root.width"), U(t.height, "root.height"), n.x = (e.x / t.width + 0.5) * s.width, n.y = (0.5 - e.y / t.height) * s.height, n), jt = ({
927
+ parentSize: e,
928
+ referencePixelsPerUnit: s = J,
929
+ root: t = z
930
+ }) => Me(e, t) * (J / U(s, "referencePixelsPerUnit")), kr = (e, s) => e * jt(s), Cr = (e, s) => {
931
+ const t = jt(s);
932
+ return t === 0 ? 0 : e / t;
933
+ }, Tr = ({
934
+ point: e,
935
+ parentSize: s,
936
+ referencePixelsPerUnit: t = J,
937
+ root: n = z,
938
+ target: i = { x: 0, y: 0 }
939
+ }) => {
940
+ if (s.width <= 0 || s.height <= 0) return Object.assign(i, { x: 0, y: 0 });
941
+ const r = J / U(t, "referencePixelsPerUnit");
942
+ return i.x = e.x * (s.width / U(n.width, "root.width")) * r, i.y = e.y * (s.height / U(n.height, "root.height")) * r, i;
943
+ }, Er = ({
944
+ point: e,
945
+ parentSize: s,
946
+ referencePixelsPerUnit: t = J,
947
+ root: n = z,
948
+ target: i = { x: 0, y: 0 }
949
+ }) => {
950
+ if (s.width <= 0 || s.height <= 0) return Object.assign(i, { x: 0, y: 0 });
951
+ const r = J / U(t, "referencePixelsPerUnit");
952
+ return i.x = e.x / (s.width / U(n.width, "root.width") * r), i.y = e.y / (s.height / U(n.height, "root.height") * r), i;
953
+ }, Rr = ({
954
+ point: e,
955
+ rect: s,
956
+ root: t = z,
957
+ target: n = { x: 0, y: 0 }
958
+ }) => st({ x: e.x - s.left, y: e.y - s.top }, s, t, n), Ar = ({
959
+ point: e,
960
+ rect: s,
961
+ root: t = z,
962
+ target: n = { x: 0, y: 0 }
963
+ }) => (nt(e, s, t, n), n.x += s.left, n.y += s.top, n), Yt = ({
964
+ point: e,
965
+ root: s = z,
966
+ target: t = { x: 0, y: 0 },
967
+ viewportSize: n
968
+ }) => st(
969
+ { x: e.x * n.width, y: e.y * n.height },
970
+ n,
971
+ s,
972
+ t
973
+ ), Ir = (e, s = z) => Me(e, s), Fr = ({
974
+ point: e,
975
+ root: s = z,
976
+ target: t = { x: 0, y: 0 },
977
+ viewportSize: n
978
+ }) => {
979
+ const i = Me(n, s);
980
+ return i <= 0 ? Object.assign(t, { x: 0, y: 0 }) : (t.x = (e.x - 0.5) * n.width / i, t.y = (0.5 - e.y) * n.height / i, t);
981
+ }, Pr = ({
982
+ point: e,
983
+ root: s = z,
984
+ target: t = { x: 0, y: 0 },
985
+ viewportSize: n
986
+ }) => {
987
+ const i = Me(n, s);
988
+ return i <= 0 || n.width <= 0 || n.height <= 0 ? Object.assign(t, { x: 0, y: 0 }) : (t.x = e.x * i / n.width + 0.5, t.y = 0.5 - e.y * i / n.height, t);
989
+ }, _r = (e, s, t = z, n = { width: 0, height: 0 }) => {
990
+ const i = Me(s, t);
991
+ return i <= 0 ? Object.assign(n, { width: 0, height: 0 }) : (n.width = e.width / i, n.height = e.height / i, n);
992
+ }, Dn = ({
993
+ point: e,
994
+ root: s = z,
995
+ target: t = { x: 0, y: 0 },
996
+ viewportSize: n
997
+ }) => n.width <= 0 || n.height <= 0 ? Object.assign(t, { x: 0, y: 0 }) : (nt(e, n, s, t), t.x /= n.width, t.y /= n.height, t), Dr = ({
998
+ point: e,
999
+ root: s = z,
1000
+ target: t = { x: 0, y: 0 },
1001
+ viewportSize: n
1002
+ }) => Yt({
1003
+ point: { x: (e.x + 1) / 2, y: (1 - e.y) / 2 },
1004
+ viewportSize: n,
1005
+ root: s,
1006
+ target: t
1007
+ }), Or = ({
1008
+ layout: e,
1009
+ mirrored: s = !1,
1010
+ point: t,
1011
+ root: n = z,
1012
+ target: i = { x: 0, y: 0 }
1013
+ }) => {
1014
+ if (e.scale <= 0) return Object.assign(i, { x: 0, y: 0 });
1015
+ const r = e.offsetX + t.x * e.scale;
1016
+ return st(
1017
+ {
1018
+ x: s ? e.destination.width - r : r,
1019
+ y: e.offsetY + t.y * e.scale
1020
+ },
1021
+ e.destination,
1022
+ n,
1023
+ i
1024
+ );
1025
+ }, Lr = ({
1026
+ layout: e,
1027
+ mirrored: s = !1,
1028
+ point: t,
1029
+ root: n = z,
1030
+ target: i = { x: 0, y: 0 }
1031
+ }) => {
1032
+ if (e.scale <= 0) return Object.assign(i, { x: 0, y: 0 });
1033
+ nt(t, e.destination, n, i);
1034
+ const r = s ? e.destination.width - i.x : i.x;
1035
+ return i.x = (r - e.offsetX) / e.scale, i.y = (i.y - e.offsetY) / e.scale, i;
1036
+ }, Re = new Gs(), Et = new qs(), Rt = new Vs(), Nr = ({
1037
+ camera: e,
1038
+ point: s,
1039
+ root: t = z,
1040
+ target: n = { x: 0, y: 0, depth: 0 },
1041
+ viewportSize: i
1042
+ }) => (U(t.width, "root.width"), U(t.height, "root.height"), Re.set(s.x, s.y, s.z).project(e), n.x = Re.x * t.width / 2, n.y = Re.y * t.height / 2, n.depth = Re.z, n), Br = ({
1043
+ camera: e,
1044
+ point: s,
1045
+ root: t = z,
1046
+ target: n = new Ks(),
1047
+ viewportSize: i
1048
+ }) => (U(t.width, "root.width"), U(t.height, "root.height"), Et.set(s.x * 2 / t.width, s.y * 2 / t.height), Rt.setFromCamera(Et, e), n.copy(Rt.ray)), Hr = (e, s) => me({ x: e.x, y: e.y, z: e.z ?? 0 }, s), On = (e, s = { x: 0, y: 0 }) => {
1049
+ const t = $s(e);
1050
+ return s.x = t.x, s.y = t.y, s.z = t.z, s;
1051
+ }, Ur = (e, s, t = { x: 0, y: 0 }) => (t.x = e.x * s.width, t.y = e.y * s.height, t), zr = (e, s, t = { x: 0, y: 0 }) => s.width <= 0 || s.height <= 0 ? Object.assign(t, { x: 0, y: 0 }) : (t.x = e.x / s.width, t.y = e.y / s.height, t), Wr = (e, s, t = {}) => Yt({
1052
+ point: e,
1053
+ viewportSize: s,
1054
+ root: t.root,
1055
+ target: t.target
1056
+ }), qr = (e, s, t = {}) => {
1057
+ const n = t.target ?? { x: 0, y: 0 };
1058
+ return Dn({ point: e, viewportSize: s, root: t.root, target: n }), n;
1059
+ }, Ln = { selection: "index", index: 0 }, At = Object.freeze({
1060
+ face: { max: 10, default: 1, option: "numFaces" },
1061
+ hand: { max: 2, default: 2, option: null },
1062
+ gesture: { max: 1, default: 1, option: null },
1063
+ body: { max: 2, default: 1, option: "numBodies" },
1064
+ holistic: { max: 1, default: 1, option: null }
1065
+ }), Nn = { center: null }, he = (e, s) => Math.hypot(e.x - s.x, e.y - s.y), Ae = (e) => ({
1066
+ center: { ...e.center },
1067
+ ...e.label === void 0 ? {} : { label: e.label },
1068
+ ...e.id === void 0 ? {} : { id: e.id }
1069
+ }), It = (e, s, t) => {
1070
+ if (!e.length) return null;
1071
+ switch (s) {
1072
+ case "largest":
1073
+ return e.reduce((n, i) => i.size > n.size ? i : n);
1074
+ case "nearest-center":
1075
+ return e.reduce(
1076
+ (n, i) => he(i.center, { x: 0.5, y: 0.5 }) < he(n.center, { x: 0.5, y: 0.5 }) ? i : n
1077
+ );
1078
+ case "leftmost":
1079
+ return e.reduce((n, i) => i.center.x < n.center.x ? i : n);
1080
+ case "rightmost":
1081
+ return e.reduce((n, i) => i.center.x > n.center.x ? i : n);
1082
+ default:
1083
+ return e.find((n) => n.index === t) ?? null;
1084
+ }
1085
+ }, Vr = (e, s = Ln, t = Nn) => {
1086
+ const n = s.index ?? 0;
1087
+ if (s.selection !== "sticky") {
1088
+ const o = It(e, s.selection, n);
1089
+ return {
1090
+ index: (o == null ? void 0 : o.index) ?? null,
1091
+ reason: o ? s.selection : "none",
1092
+ memory: o ? Ae(o) : t
1093
+ };
1094
+ }
1095
+ const i = t.id === void 0 ? void 0 : e.find((o) => o.id === t.id);
1096
+ if (i) return { index: i.index, reason: "sticky", memory: Ae(i) };
1097
+ const r = s.stickyRadius ?? 0.2;
1098
+ if (t.center) {
1099
+ const o = t.center, d = e.filter((u) => he(u.center, o) <= r).sort((u, p) => he(u.center, o) - he(p.center, o)), h = (t.label ? d.find((u) => u.label === t.label) : void 0) ?? d[0];
1100
+ if (h)
1101
+ return { index: h.index, reason: "sticky", memory: Ae(h) };
1102
+ }
1103
+ const a = It(e, s.fallback ?? "largest", n);
1104
+ return {
1105
+ index: (a == null ? void 0 : a.index) ?? null,
1106
+ reason: a ? "sticky-fallback" : "none",
1107
+ // Keep the old memory on a miss so a brief dropout does not forget the subject.
1108
+ memory: a ? Ae(a) : t
1109
+ };
1110
+ }, Kr = (e) => e.map((s, t) => {
1111
+ let n = 1 / 0, i = -1 / 0, r = 1 / 0, a = -1 / 0;
1112
+ for (const d of s)
1113
+ d.x < n && (n = d.x), d.x > i && (i = d.x), d.y < r && (r = d.y), d.y > a && (a = d.y);
1114
+ const o = s.length > 0 && Number.isFinite(n);
1115
+ return {
1116
+ index: t,
1117
+ center: o ? { x: (n + i) / 2, y: (r + a) / 2 } : { x: 0.5, y: 0.5 },
1118
+ size: o ? i - n : 0
1119
+ };
1120
+ }), Bn = (e) => e.map((s, t) => {
1121
+ const n = (s.coordinates ?? []).map((l) => On(l));
1122
+ let i = 1 / 0, r = -1 / 0, a = 1 / 0, o = -1 / 0;
1123
+ for (const l of n)
1124
+ l.x < i && (i = l.x), l.x > r && (r = l.x), l.y < a && (a = l.y), l.y > o && (o = l.y);
1125
+ const d = n.length > 0;
1126
+ return {
1127
+ index: t,
1128
+ center: d ? { x: (i + r) / 2, y: (a + o) / 2 } : { x: 0.5, y: 0.5 },
1129
+ size: d ? Math.max(r - i, o - a) : 0,
1130
+ ...s.label ? { label: s.label } : {}
1131
+ };
1132
+ }), Gr = (e) => Bn(e.map((s) => ({ coordinates: s.pose.image }))).map((s, t) => ({
1133
+ ...s,
1134
+ id: e[t].id
1135
+ })), Xr = (e, s, t = 0.35) => {
1136
+ const n = [];
1137
+ for (const a of e)
1138
+ for (const o of s) {
1139
+ const d = he(a.center, o.center);
1140
+ d <= t && n.push({ primaryIndex: a.index, secondaryIndex: o.index, distance: d });
1141
+ }
1142
+ n.sort((a, o) => a.distance - o.distance);
1143
+ const i = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new Set();
1144
+ return n.filter((a) => i.has(a.primaryIndex) || r.has(a.secondaryIndex) ? !1 : (i.add(a.primaryIndex), r.add(a.secondaryIndex), !0));
1145
+ }, Ft = new W.Vector3(), Ke = new W.Vector3(), Qt = (e, s, t, n, i) => {
1146
+ Ft.set(e, s, 0).unproject(t), Ke.copy(Ft).sub(t.position).normalize();
1147
+ const r = (n - t.position.z) / Ke.z;
1148
+ return i.copy(t.position).addScaledVector(Ke, r);
1149
+ }, Hn = (e, s, t = new W.Vector3(), n = 0) => Qt((e.x - 0.5) * 2, (0.5 - e.y) * 2, s, n, t), jr = (e, s, t = new W.Vector3(), n = 0) => Qt(e.x, e.y, s, n, t), Y = new W.Vector3(), Yr = (e, s, t = { x: 0, y: 0, z: 0 }) => (Y.set(e.x, e.y, e.z).project(s), t.x = Y.x / 2 + 0.5, t.y = 0.5 - Y.y / 2, t.z = Y.z, t), Qr = (e, s, t = { x: 0, y: 0, z: 0 }) => (Y.set(e.x, e.y, e.z).project(s), t.x = Y.x, t.y = Y.y, t.z = Y.z, t), Ge = (e, s, t) => Hn(e, s, t, 0), Un = (e, s, t = 0.2) => t * s + (1 - t) * e;
1150
+ class we {
1151
+ constructor(s) {
1152
+ m(this, "canvas");
1153
+ m(this, "scale", 1);
1154
+ this.maxDimension = s;
1155
+ }
1156
+ /** Multiply the cap (0.25..1); the adaptive-quality tier sets it. */
1157
+ setScale(s) {
1158
+ this.scale = Math.min(1, Math.max(0.25, Number.isFinite(s) && s > 0 ? s : 1));
1159
+ }
1160
+ /**
1161
+ * Returns a downscaled copy of `source` capped to `maxDimension` on its
1162
+ * longest side (or `source` unchanged if it's already within the cap, or if a
1163
+ * 2D context can't be obtained). The returned canvas is reused across calls.
1164
+ */
1165
+ draw(s) {
1166
+ const t = s.width, n = s.height, i = Math.min(
1167
+ 1,
1168
+ this.maxDimension * this.scale / Math.max(t, n)
1169
+ );
1170
+ if (i >= 1) return s;
1171
+ const r = Math.max(1, Math.round(t * i)), a = Math.max(1, Math.round(n * i));
1172
+ (!this.canvas || this.canvas.width !== r || this.canvas.height !== a) && (this.canvas = new OffscreenCanvas(r, a));
1173
+ const o = this.canvas.getContext("2d");
1174
+ return o ? (o.setTransform(1, 0, 0, 1, 0, 0), o.clearRect(0, 0, r, a), o.drawImage(s, 0, 0, r, a), this.canvas) : s;
1175
+ }
1176
+ dispose() {
1177
+ this.canvas = void 0;
1178
+ }
1179
+ }
1180
+ const zn = {
1181
+ "/assets/xr/models/face_tracking.task": "sha384-tYQh+yJE8llY+zO4RviZmWaSKs5W9tsB0ix5rjQVpF5/CLTqmwtP7bYtkUi2w65P",
1182
+ "/assets/xr/models/hand_tracking.task": "sha384-uWvruVKd887ov8k43S+DBHCsi7UXXS+CKvvdM1PX00rjPzx/B0QrAPfJ1U9yKcze",
1183
+ "/assets/xr/models/gesture_tracking.task": "sha384-2zuseP9JKKWAYlWQGKA2N+ooabB8V/yIxu23Mv8mtY7SowcySB+xKiOmqBhVvlUC",
1184
+ "/assets/xr/models/body_tracking.task": "sha384-3Wk9dvRYo36b3Nc9xVjKamb4wCKt9FwiPjcHKfrvyJL/jXoGs+uRLnii6yjWLKul",
1185
+ "/assets/xr/models/segmentation.tflite": "sha384-A2bQ8+iZyQM3KIGVBUf0FyetqxuynyKpjsjCE8uzoJEnj1ghCu6ge2daiRffAiS5",
1186
+ "/assets/xr/3d-models/head-occluder-v2.glb": "sha384-+0G60Q6EBVE6hpITxGzQgofAeKexPltpsfPq5T5et9GGBjRhFP5HOdsKAhe73OaI",
1187
+ // v3: canonical-frame head (first 468 vertices = the canonical face landmarks),
1188
+ // authored in assets-src/head-occluder/head-occluder-v3.blend. Hash of the
1189
+ // exported GLB; the CDN copy must be byte-identical to example/src/assets/models.
1190
+ "/assets/xr/3d-models/head-occluder-v3.glb": "sha384-bmKKYb7k1qsGqkOSUBwv3oqI9eOche97/OvRxXDxrqZAgqpy+4PJ5HU9O94lrjFO",
1191
+ // Shoulder / upper-torso occluder in the canonical torso frame (same .blend).
1192
+ "/assets/xr/3d-models/shoulder-occluder-v1.glb": "sha384-iXxOvC+IoXfgpf8S/JSsV6lLzzLs6vtmaslJy7R0iLtl5Yb17U+/ATfGdhpmamae",
1193
+ // SDK-hosted rig models (lib/assets/sdkModels.ts): the CDN copies must be
1194
+ // byte-identical to example/src/assets/models/{hand-v1,glove-v1,ybot}.glb.
1195
+ // Upload pending: the default URLs fail closed until then.
1196
+ "/assets/xr/3d-models/hand-v1.glb": "sha384-noiRM38+PSoOZVgKaRLPf1001gHN38vMDPkSX2mL/Wgtj9o7TP/L05rHs6ubsGIK",
1197
+ "/assets/xr/3d-models/glove-v1.glb": "sha384-dZkRdB4URmKS2RBaDb4A7E95pLt4KKLlkxKsqA6L5N8elSbfiyyBoi7S9GcSVbDJ",
1198
+ "/assets/xr/3d-models/ybot-v1.glb": "sha384-pJY/JqDrnL8qPVtTC52G1GVsbBwBkEN5Z2TX3mm921l/iLsFTJDHbEMWcLd+icZ9",
1199
+ // Category segmenters behind XRModel.SEMANTIC_SEGMENTATION. The same bytes
1200
+ // are pinned under the SDK CDN paths (not yet published) and under
1201
+ // MediaPipe's published paths, which the presets load by default.
1202
+ "/assets/xr/models/hair_segmenter.tflite": "sha384-1Eu/EdJcYV/7talPYVVbxPZBLg7UIxqsKisUNh/pEsyvAuUcE49HuqijSXWSHXHK",
1203
+ "/mediapipe-models/image_segmenter/hair_segmenter/float32/latest/hair_segmenter.tflite": "sha384-1Eu/EdJcYV/7talPYVVbxPZBLg7UIxqsKisUNh/pEsyvAuUcE49HuqijSXWSHXHK",
1204
+ "/assets/xr/models/selfie_multiclass_256x256.tflite": "sha384-LPLPyzBZ6TTE8146rnDx8CZ5LykB8memkmeO8FNVbGlNthvlUltn3W3KeJmtq9bL",
1205
+ "/mediapipe-models/image_segmenter/selfie_multiclass_256x256/float32/latest/selfie_multiclass_256x256.tflite": "sha384-LPLPyzBZ6TTE8146rnDx8CZ5LykB8memkmeO8FNVbGlNthvlUltn3W3KeJmtq9bL",
1206
+ // Fingernail segmenter behind the `nails` preset (assets-src/nail-segmenter):
1207
+ // the CDN copy must be byte-identical to example/src/assets/models.
1208
+ "/assets/xr/models/nail_segmenter_v1.tflite": "sha384-sxkDgbQcK1Q/bxxzAHGvmSG00wm11UlrlH9dS242lo9QGBqBCEr4zj6sZE3mND43",
1209
+ // MediaPipe Holistic Landmarker (face + hands + pose in one graph) behind
1210
+ // XRModel.HOLISTIC_TRACKER. Same bytes pinned under the SDK CDN path (not yet
1211
+ // published) and MediaPipe's published path, which the tracker loads by default.
1212
+ "/assets/xr/models/holistic_landmarker.task": "sha384-6Y2fQ5yP5QtlvJIasfv0fHEyoMqRYYpLtEpsyeXjYDOuFCEXfKIZPZSXq8TLXmsg",
1213
+ "/mediapipe-models/holistic_landmarker/holistic_landmarker/float16/latest/holistic_landmarker.task": "sha384-6Y2fQ5yP5QtlvJIasfv0fHEyoMqRYYpLtEpsyeXjYDOuFCEXfKIZPZSXq8TLXmsg",
1214
+ "/assets/sdk/face/v1/canonical_face_model.obj": "sha384-xP8YM/72TXKvbMptXB9a8JUlUf3MZQ8uLurExrsZc05v6/P5RrsaNGMUYS/BZx8A",
1215
+ "/opencv/facial_expression_recognition/resolve/main/facial_expression_recognition_mobilefacenet_2022july_int8.onnx": "sha384-g8mtFubiIc/yhqi591RsxD76AJLw2CfYgKhKbVkIiFlwBmIyG7ZAIVyGPXafrDGB"
1216
+ };
1217
+ async function Wn(e, s) {
1218
+ const t = await fetch(e, s != null && s.signal ? { signal: s.signal } : void 0);
1219
+ if (!t.ok)
1220
+ throw new Error(`fetchAndVerify: ${t.status} ${e}`);
1221
+ const n = await t.arrayBuffer(), i = Kn(e);
1222
+ if (!i) {
1223
+ if (qn(e))
1224
+ throw new Error(`[xr-sdk integrity] no SRI hash for SDK asset ${e}`);
1225
+ return console.warn(`[xr-sdk integrity] no SRI hash for ${e} — passing through`), n;
1226
+ }
1227
+ const r = await Gn(n);
1228
+ if (r !== i)
1229
+ throw new Error(
1230
+ `[xr-sdk integrity] SRI mismatch for ${e}: expected ${i}, got ${r}`
1231
+ );
1232
+ return n;
1233
+ }
1234
+ function qn(e) {
1235
+ try {
1236
+ return new URL(e).origin === new URL(q.assetStorageEndpoint).origin;
1237
+ } catch {
1238
+ return !1;
1239
+ }
1240
+ }
1241
+ async function ee(e) {
1242
+ const s = await Wn(e);
1243
+ return new Uint8Array(s);
1244
+ }
1245
+ const le = /* @__PURE__ */ new Map();
1246
+ function Vn(e) {
1247
+ let s = le.get(e);
1248
+ if (!s) {
1249
+ const i = { bytes: ee(e), holders: 0 };
1250
+ i.bytes.catch(() => {
1251
+ le.get(e) === i && le.delete(e);
1252
+ }), le.set(e, i), s = i;
1253
+ }
1254
+ const t = s;
1255
+ t.holders += 1;
1256
+ let n = !1;
1257
+ return {
1258
+ bytes: t.bytes,
1259
+ release: () => {
1260
+ n || (n = !0, t.holders -= 1, t.holders <= 0 && le.get(e) === t && le.delete(e));
1261
+ }
1262
+ };
1263
+ }
1264
+ function Kn(e) {
1265
+ try {
1266
+ const s = new URL(e);
1267
+ return zn[s.pathname];
1268
+ } catch {
1269
+ return;
1270
+ }
1271
+ }
1272
+ async function Gn(e) {
1273
+ const s = await crypto.subtle.digest("SHA-384", e), t = new Uint8Array(s);
1274
+ let n = "";
1275
+ for (let i = 0; i < t.byteLength; i++)
1276
+ n += String.fromCharCode(t[i]);
1277
+ return `sha384-${btoa(n)}`;
1278
+ }
1279
+ const Xe = /* @__PURE__ */ new Map();
1280
+ function te(e) {
1281
+ const s = e.wasmBinaryPath;
1282
+ let t = Xe.get(s);
1283
+ return t || (t = Xn(s).catch(() => {
1284
+ Xe.delete(s);
1285
+ }), Xe.set(s, t)), t;
1286
+ }
1287
+ async function Xn(e) {
1288
+ const s = await fetch(e, { credentials: "same-origin" });
1289
+ if (!s.ok || !s.body)
1290
+ throw new Error(`warmVisionWasm: ${s.status} ${e}`);
1291
+ const t = s.body.getReader();
1292
+ for (; ; ) {
1293
+ const { done: n } = await t.read();
1294
+ if (n) return;
1295
+ }
1296
+ }
1297
+ class se {
1298
+ constructor() {
1299
+ m(this, "disposed", !1);
1300
+ m(this, "paused", !1);
1301
+ m(this, "rafId", null);
1302
+ // Inference bookkeeping behind `getDiagnostics()`. Subclasses call
1303
+ // `recordInference(startMs)` right after their detect call and
1304
+ // `recordDetections(count, confidence)` after reading the result.
1305
+ m(this, "statInferenceMs", null);
1306
+ m(this, "statInferences", 0);
1307
+ m(this, "statWindowStart", 0);
1308
+ m(this, "statWindowCount", 0);
1309
+ m(this, "statFps", 0);
1310
+ m(this, "statSkipped", 0);
1311
+ m(this, "statDetections", null);
1312
+ m(this, "statConfidence", null);
1313
+ m(this, "statStatus", "ready");
1314
+ m(this, "statError", null);
1315
+ // Inference-rate throttle. `targetFrameIntervalMs` is 0 when uncapped
1316
+ // (detect every frame); a positive value skips detection until that many ms
1317
+ // have elapsed since the last inference. `run()` sets this from
1318
+ // `params.targetFps`; subclasses call `shouldRunInference()` in their RAF
1319
+ // loop to gate the expensive MediaPipe call.
1320
+ m(this, "targetFrameIntervalMs", 0);
1321
+ m(this, "lastInferenceMs", 0);
1322
+ /** Analysis-resolution multiplier (0.25..1) from the quality tier; subclasses read it where they downscale. */
1323
+ m(this, "analysisScale", 1);
1324
+ }
1325
+ /** Record one completed inference that started at `startMs` (`performance.now()`). */
1326
+ recordInference(s, t = performance.now()) {
1327
+ const n = t - s;
1328
+ this.statInferenceMs = n, this.statInferences += 1, this.statWindowCount += 1, this.statWindowStart === 0 && (this.statWindowStart = t);
1329
+ const i = t - this.statWindowStart;
1330
+ return i >= 1e3 && (this.statFps = this.statWindowCount * 1e3 / i, this.statWindowStart = t, this.statWindowCount = 0), n;
1331
+ }
1332
+ /** Record what the last inference found (subjects and the primary confidence). */
1333
+ recordDetections(s, t = null) {
1334
+ this.statDetections = s, this.statConfidence = t;
1335
+ }
1336
+ /** Record an inference failure (or clear it with `null`). */
1337
+ recordInferenceError(s) {
1338
+ this.statStatus = s ? "error" : "ready", this.statError = s;
1339
+ }
1340
+ /** Current health snapshot. Allocates a small object; sample it at UI rate, not per frame. */
1341
+ getDiagnostics() {
1342
+ const s = this.statWindowStart > 0 && performance.now() - this.statWindowStart > 1500;
1343
+ return {
1344
+ inferenceMs: this.statInferenceMs,
1345
+ inferenceFps: s ? 0 : this.statFps,
1346
+ inferences: this.statInferences,
1347
+ skippedFrames: this.statSkipped,
1348
+ detections: this.statDetections,
1349
+ confidence: this.statConfidence,
1350
+ status: this.statStatus,
1351
+ error: this.statError,
1352
+ paused: this.paused,
1353
+ disposed: this.disposed
1354
+ };
1355
+ }
1356
+ /** Clamp and store the analysis scale; subclasses with a downscaler forward it. */
1357
+ setAnalysisScale(s) {
1358
+ this.analysisScale = s !== void 0 && Number.isFinite(s) && s > 0 ? Math.min(1, Math.max(0.25, s)) : 1;
1359
+ }
1360
+ /** Set the per-frame inference cap. fps <= 0 (or undefined) → uncapped. */
1361
+ setTargetFps(s) {
1362
+ this.targetFrameIntervalMs = s && s > 0 ? 1e3 / s : 0;
1363
+ }
1364
+ /**
1365
+ * True if enough time has elapsed to run inference this frame (and records
1366
+ * the timestamp). Always true when uncapped. Call once per RAF tick, right
1367
+ * before the detect call; skip the detect (but keep rescheduling RAF) when
1368
+ * it returns false.
1369
+ */
1370
+ shouldRunInference() {
1371
+ if (this.targetFrameIntervalMs <= 0) return !0;
1372
+ const s = performance.now();
1373
+ return s - this.lastInferenceMs < this.targetFrameIntervalMs ? (this.statSkipped += 1, !1) : (this.lastInferenceMs = s, !0);
1374
+ }
1375
+ // load models
1376
+ async initialize(s) {
1377
+ }
1378
+ // setup for running + start running
1379
+ async run(s) {
1380
+ }
1381
+ // get model's data while processing
1382
+ getModelNode() {
1383
+ return {};
1384
+ }
1385
+ async getPerformanceData() {
1386
+ return {
1387
+ name: this.constructor.name,
1388
+ processingTime: null
1389
+ };
1390
+ }
1391
+ // Cancel the per-frame RAF loop without releasing MediaPipe resources or
1392
+ // dropping refs. Subclasses' process* methods check `paused` and return
1393
+ // without rescheduling. Idempotent.
1394
+ pause() {
1395
+ this.paused = !0, this.rafId !== null && (cancelAnimationFrame(this.rafId), this.rafId = null);
1396
+ }
1397
+ // Resume a paused loop by running the process function once. Subclasses
1398
+ // override to kick their specific process* method. Idempotent — no-op if
1399
+ // not paused. Calling resume() before run() is a no-op.
1400
+ resume() {
1401
+ this.paused = !1;
1402
+ }
1403
+ // Release MediaPipe landmarkers, cancel rAF loops, drop refs.
1404
+ // Subclasses MUST override and call super.dispose() at the end.
1405
+ dispose() {
1406
+ this.disposed = !0, this.rafId !== null && (cancelAnimationFrame(this.rafId), this.rafId = null);
1407
+ }
1408
+ }
1409
+ const jn = 768, je = (e) => e > 1 ? "IMAGE" : "VIDEO";
1410
+ class Yn extends se {
1411
+ constructor() {
1412
+ super();
1413
+ m(this, "landmarker", null);
1414
+ m(this, "processingTime", null);
1415
+ m(this, "coordinates");
1416
+ m(this, "visibility");
1417
+ /** Per body, sided as the person's own left / right (see `anatomicalBodyPose`). */
1418
+ m(this, "poses", []);
1419
+ /** The same bodies with a stable id each (`BodyIdentity`), by id. */
1420
+ m(this, "bodies", []);
1421
+ m(this, "identity", new Fn());
1422
+ /** How many bodies the landmarker looks for now, and what each consumer asked for. */
1423
+ m(this, "numPoses", 1);
1424
+ m(this, "bodyRequests", /* @__PURE__ */ new Map());
1425
+ /** While `setOptions` rebuilds the landmarker, inference waits. */
1426
+ m(this, "reconfiguring", !1);
1427
+ m(this, "getSource");
1428
+ m(this, "sourceCanvas");
1429
+ m(this, "downscaler", new we(jn));
1430
+ }
1431
+ async getBodyData() {
1432
+ var p;
1433
+ if (!this.landmarker || !this.sourceCanvas)
1434
+ return;
1435
+ const t = this.downscaler.draw(this.sourceCanvas), n = performance.now(), i = je(this.numPoses) === "IMAGE" ? this.landmarker.detect(t) : this.landmarker.detectForVideo(t, n), r = performance.now();
1436
+ this.processingTime = r - n, this.recordInference(n, r);
1437
+ const a = i.landmarks, o = a == null ? void 0 : a[0];
1438
+ this.recordDetections(
1439
+ (a == null ? void 0 : a.length) ?? 0,
1440
+ o && o.length ? o.reduce((M, x) => M + (x.visibility ?? 0), 0) / o.length : null
1441
+ );
1442
+ const d = [], l = [], h = [], u = Se((p = this.getSource) == null ? void 0 : p.call(this));
1443
+ if (a)
1444
+ return a.forEach((M, x) => {
1445
+ var T;
1446
+ d[x] || (d[x] = [], l[x] = []), M.forEach((R) => {
1447
+ d[x].push(me(R)), l[x].push(R.visibility ?? 1);
1448
+ });
1449
+ const b = (((T = i.worldLandmarks) == null ? void 0 : T[x]) ?? []).map(
1450
+ (R) => kn(R)
1451
+ );
1452
+ b.length === M.length && (h[x] = Cn(
1453
+ { world: b, image: d[x], visibility: l[x] },
1454
+ u,
1455
+ n
1456
+ ));
1457
+ }), {
1458
+ coordinatesList: d,
1459
+ visibilityList: l,
1460
+ poses: h
1461
+ };
1462
+ }
1463
+ async processBodyTracking() {
1464
+ var t;
1465
+ if (!(this.disposed || this.paused || !this.landmarker)) {
1466
+ if (!this.reconfiguring && this.shouldRunInference()) {
1467
+ const n = await this.getBodyData();
1468
+ if (n) {
1469
+ this.coordinates = n.coordinatesList, this.visibility = n.visibilityList, this.poses = n.poses;
1470
+ const i = this.sourceCanvas, r = i && i.height > 0 ? i.width / i.height : 1;
1471
+ this.bodies = this.identity.update(
1472
+ n.poses.filter(Boolean),
1473
+ ((t = n.poses.find(Boolean)) == null ? void 0 : t.timestampMs) ?? performance.now(),
1474
+ r
1475
+ );
1476
+ }
1477
+ }
1478
+ this.disposed || this.paused || (this.rafId = requestAnimationFrame(this.processBodyTracking.bind(this)));
1479
+ }
1480
+ }
1481
+ resume() {
1482
+ this.paused && (super.resume(), this.processBodyTracking());
1483
+ }
1484
+ dispose() {
1485
+ if (super.dispose(), this.landmarker) {
1486
+ try {
1487
+ this.landmarker.close();
1488
+ } catch {
1489
+ }
1490
+ this.landmarker = null;
1491
+ }
1492
+ this.sourceCanvas = void 0, this.downscaler.dispose(), this.coordinates = void 0, this.visibility = void 0, this.poses = [], this.bodies = [], this.identity.reset(), this.bodyRequests.clear(), this.getSource = void 0;
1493
+ }
1494
+ getLandmarks2D(t = 0) {
1495
+ if (this.coordinates)
1496
+ return this.coordinates[t];
1497
+ }
1498
+ getVisibility(t = 0) {
1499
+ var n;
1500
+ return (n = this.visibility) == null ? void 0 : n[t];
1501
+ }
1502
+ getBodyPose(t = 0) {
1503
+ return this.poses[t] ?? null;
1504
+ }
1505
+ getBodyPoseById(t) {
1506
+ var n;
1507
+ return ((n = this.bodies.find((i) => i.id === t)) == null ? void 0 : n.pose) ?? null;
1508
+ }
1509
+ /** Records `owner`'s wish for `count` bodies; the landmarker looks for the most asked. */
1510
+ requestBodies(t, n) {
1511
+ return this.bodyRequests.set(t, n), this.applyNumBodies(), () => {
1512
+ this.bodyRequests.delete(t) && this.applyNumBodies();
1513
+ };
1514
+ }
1515
+ async applyNumBodies() {
1516
+ const t = Ct(this.bodyRequests.values(), At.body.max);
1517
+ if (!(t === this.numPoses || this.disposed || this.reconfiguring || !this.landmarker)) {
1518
+ this.reconfiguring = !0;
1519
+ try {
1520
+ await this.landmarker.setOptions({ numPoses: t, runningMode: je(t) }), this.numPoses = t;
1521
+ } catch (n) {
1522
+ console.warn("[BodyTrackingModel] numPoses change failed", n);
1523
+ return;
1524
+ } finally {
1525
+ this.reconfiguring = !1;
1526
+ }
1527
+ this.applyNumBodies();
1528
+ }
1529
+ }
1530
+ async initialize(t) {
1531
+ const n = await $.forVisionTasks(
1532
+ new URL("/assets/xr/wasm", q.assetStorageEndpoint).toString()
1533
+ ), [i] = await Promise.all([
1534
+ ee(
1535
+ new URL("/assets/xr/models/body_tracking.task", q.assetStorageEndpoint).toString()
1536
+ ),
1537
+ te(n)
1538
+ ]);
1539
+ t != null && t.numPoses && this.bodyRequests.set("options", t.numPoses);
1540
+ const r = Ct(this.bodyRequests.values(), At.body.max);
1541
+ this.landmarker = await Ns.createFromOptions(n, {
1542
+ baseOptions: {
1543
+ modelAssetBuffer: i,
1544
+ delegate: "GPU"
1545
+ },
1546
+ runningMode: je(r),
1547
+ numPoses: r
1548
+ }), this.numPoses = r, this.applyNumBodies();
1549
+ }
1550
+ async run({
1551
+ sourceCanvas: t,
1552
+ getSource: n,
1553
+ targetFps: i,
1554
+ analysisScale: r
1555
+ }) {
1556
+ this.getSource = n, this.setAnalysisScale(r), this.downscaler.setScale(this.analysisScale), this.sourceCanvas = t, this.setTargetFps(i), this.rafId === null && await this.processBodyTracking();
1557
+ }
1558
+ getModelNode() {
1559
+ const t = this;
1560
+ return {
1561
+ getLandmarks2D: this.getLandmarks2D.bind(this),
1562
+ getVisibility: this.getVisibility.bind(this),
1563
+ getBodyPose: this.getBodyPose.bind(this),
1564
+ getBodies: () => this.bodies,
1565
+ getBodyPoseById: this.getBodyPoseById.bind(this),
1566
+ requestBodies: this.requestBodies.bind(this),
1567
+ get numBodies() {
1568
+ return t.numPoses;
1569
+ }
1570
+ };
1571
+ }
1572
+ async getPerformanceData() {
1573
+ return {
1574
+ name: this.constructor.name,
1575
+ processingTime: this.processingTime
1576
+ };
1577
+ }
1578
+ }
1579
+ const Jt = Symbol("xr.modelNodeSource"), Jr = (e) => e[Jt] ?? e, Qn = 0.11, Jn = 4e-3, Zn = "/assets/xr/models/face_tracking.task", $n = "/assets/xr/wasm", ei = (e, s, t = !0) => t ? s.set(e.x, -e.y, e.z) : s.set(e.x, e.y, -e.z), ti = (e, s) => s.setFromRotationMatrix(e).normalize();
1580
+ class si extends se {
1581
+ constructor() {
1582
+ super();
1583
+ m(this, "landmarker", null);
1584
+ /** The face model bytes, held while this model is alive (shared with the still-image detector). */
1585
+ m(this, "modelBytes", null);
1586
+ m(this, "processingTime", null);
1587
+ m(this, "sourceCanvas");
1588
+ m(this, "analysisCanvas");
1589
+ m(this, "getSource");
1590
+ m(this, "detectionResults");
1591
+ m(this, "numFaces", 1);
1592
+ m(this, "cameras", []);
1593
+ // camera object to unproject each face's translation
1594
+ m(this, "faces", []);
1595
+ // Reused per-face work vectors. Allocated once per face index and mutated
1596
+ // in place each frame, so the published Face[] doesn't churn the GC at
1597
+ // 30+ fps. Per-face indexing means two faces don't alias each other's
1598
+ // transforms; consumers see "current value" each frame.
1599
+ m(this, "leftCheekScratch", []);
1600
+ m(this, "rightCheekScratch", []);
1601
+ // Reused per-frame rotation scratch (matrix -> quaternion -> mirror -> euler),
1602
+ // allocated once to avoid per-frame churn at 30+ fps.
1603
+ m(this, "rotMatrixScratch", new W.Matrix4());
1604
+ m(this, "rotQuatScratch", new W.Quaternion());
1605
+ m(this, "rotEulerScratch", new W.Euler());
1606
+ }
1607
+ extractAndUpdateFaceData(t) {
1608
+ var r;
1609
+ if (!t.faceLandmarks.length) {
1610
+ this.faces = [];
1611
+ return;
1612
+ }
1613
+ const n = t.faceLandmarks.length;
1614
+ this.faces.length > n && (this.faces.length = n, this.leftCheekScratch.length = n, this.rightCheekScratch.length = n);
1615
+ const i = Se((r = this.getSource) == null ? void 0 : r.call(this));
1616
+ for (; this.faces.length < n; )
1617
+ this.faces.push({
1618
+ transform: {
1619
+ position: new W.Vector3(),
1620
+ rotation: new W.Vector3(),
1621
+ quaternion: new W.Quaternion(),
1622
+ scale: new W.Vector3()
1623
+ },
1624
+ gestures: {},
1625
+ mirrored: i
1626
+ }), this.leftCheekScratch.push(new W.Vector3()), this.rightCheekScratch.push(new W.Vector3());
1627
+ for (let a = 0; a < n; a += 1)
1628
+ this.faces[a].mirrored = i;
1629
+ for (let a = 0; a < n; a += 1) {
1630
+ if (!this.cameras[a])
1631
+ continue;
1632
+ const o = this.faces[a], d = t.faceLandmarks[a], l = t.facialTransformationMatrixes[a];
1633
+ this.rotMatrixScratch.fromArray(l.data), ti(this.rotMatrixScratch, o.transform.quaternion), this.rotQuatScratch.copy(o.transform.quaternion), this.rotQuatScratch.set(
1634
+ -this.rotQuatScratch.x,
1635
+ this.rotQuatScratch.y,
1636
+ this.rotQuatScratch.z,
1637
+ this.rotQuatScratch.w
1638
+ ), this.rotEulerScratch.setFromQuaternion(this.rotQuatScratch, "XYZ"), ei(this.rotEulerScratch, o.transform.rotation, i), Ge(d[4], this.cameras[a], o.transform.position), Ge(d[50], this.cameras[a], this.leftCheekScratch[a]), Ge(d[280], this.cameras[a], this.rightCheekScratch[a]);
1639
+ const u = this.leftCheekScratch[a].distanceTo(this.rightCheekScratch[a]) * Qn, p = Math.abs(W.MathUtils.radToDeg(this.rotEulerScratch.y)), M = u + p * Jn, x = o.transform.scale.x, b = Un(
1640
+ isNaN(x) ? 0 : x,
1641
+ M
1642
+ );
1643
+ o.transform.scale.set(b, b, b);
1644
+ const T = o.gestures, R = t.faceBlendshapes[a].categories;
1645
+ for (const w of R)
1646
+ T[w.categoryName] = w.score;
1647
+ }
1648
+ }
1649
+ async processFaceTracking() {
1650
+ if (this.disposed || this.paused || !this.landmarker || !this.sourceCanvas)
1651
+ return null;
1652
+ if (!this.shouldRunInference()) {
1653
+ this.rafId = requestAnimationFrame(this.processFaceTracking.bind(this));
1654
+ return;
1655
+ }
1656
+ const t = ni(this.numFaces) * this.analysisScale, n = this.sourceCanvas.width, i = this.sourceCanvas.height, r = Math.min(1, t / Math.max(n, i)), a = Math.max(1, Math.round(n * r)), o = Math.max(1, Math.round(i * r));
1657
+ (!this.analysisCanvas || this.analysisCanvas.width !== a || this.analysisCanvas.height !== o) && (this.analysisCanvas = new OffscreenCanvas(a, o));
1658
+ const d = this.analysisCanvas.getContext("2d");
1659
+ if (!d) {
1660
+ this.rafId = requestAnimationFrame(this.processFaceTracking.bind(this));
1661
+ return;
1662
+ }
1663
+ d.setTransform(1, 0, 0, 1, 0, 0), d.clearRect(0, 0, a, o), d.drawImage(this.sourceCanvas, 0, 0, a, o);
1664
+ const l = performance.now(), h = this.landmarker.detectForVideo(this.analysisCanvas, l), u = performance.now();
1665
+ this.processingTime = u - l, this.recordInference(l, u), this.recordDetections(h.faceLandmarks.length, null), this.detectionResults = h, this.extractAndUpdateFaceData(h), !(this.disposed || this.paused) && (this.rafId = requestAnimationFrame(this.processFaceTracking.bind(this)));
1666
+ }
1667
+ resume() {
1668
+ this.paused && (super.resume(), this.processFaceTracking());
1669
+ }
1670
+ dispose() {
1671
+ if (super.dispose(), this.landmarker) {
1672
+ try {
1673
+ this.landmarker.close();
1674
+ } catch {
1675
+ }
1676
+ this.landmarker = null;
1677
+ }
1678
+ this.releaseModelBytes(), this.sourceCanvas = void 0, this.getSource = void 0, this.analysisCanvas = void 0, this.detectionResults = void 0, this.processingTime = null, this.cameras = [], this.faces = [], this.leftCheekScratch = [], this.rightCheekScratch = [];
1679
+ }
1680
+ getFace(t = 0) {
1681
+ return this.faces[t];
1682
+ }
1683
+ getDetectionResults() {
1684
+ return this.detectionResults;
1685
+ }
1686
+ getRawFaceTrackingData(t = 0) {
1687
+ var n, i, r, a;
1688
+ if (this.detectionResults)
1689
+ return {
1690
+ landmarks: (n = this.detectionResults.faceLandmarks) == null ? void 0 : n[t],
1691
+ blendshapes: (r = (i = this.detectionResults.faceBlendshapes) == null ? void 0 : i[t]) == null ? void 0 : r.categories,
1692
+ transformationMatrix: (a = this.detectionResults.facialTransformationMatrixes) == null ? void 0 : a[t]
1693
+ };
1694
+ }
1695
+ async initialize(t) {
1696
+ var a;
1697
+ this.numFaces = (t == null ? void 0 : t.numFaces) || 1;
1698
+ const n = await $.forVisionTasks(
1699
+ new URL($n, q.assetStorageEndpoint).toString()
1700
+ );
1701
+ (a = this.modelBytes) == null || a.release();
1702
+ const i = Vn(
1703
+ new URL(Zn, q.assetStorageEndpoint).toString()
1704
+ );
1705
+ this.modelBytes = i;
1706
+ let r;
1707
+ try {
1708
+ const [o] = await Promise.all([i.bytes, te(n)]);
1709
+ r = await Bs.createFromOptions(n, {
1710
+ baseOptions: {
1711
+ modelAssetBuffer: o,
1712
+ delegate: "GPU"
1713
+ },
1714
+ // Keep detection permissive for calibration workflows with dark webcam input.
1715
+ minFaceDetectionConfidence: 0.3,
1716
+ minFacePresenceConfidence: 0.3,
1717
+ minTrackingConfidence: 0.3,
1718
+ outputFaceBlendshapes: !0,
1719
+ outputFacialTransformationMatrixes: !0,
1720
+ runningMode: "VIDEO",
1721
+ numFaces: this.numFaces
1722
+ });
1723
+ } catch (o) {
1724
+ throw this.releaseModelBytes(i), o;
1725
+ }
1726
+ if (this.disposed) {
1727
+ r.close(), this.releaseModelBytes(i);
1728
+ return;
1729
+ }
1730
+ this.landmarker = r;
1731
+ }
1732
+ releaseModelBytes(t = this.modelBytes) {
1733
+ t == null || t.release(), this.modelBytes === t && (this.modelBytes = null);
1734
+ }
1735
+ async run({
1736
+ sourceCanvas: t,
1737
+ getSource: n,
1738
+ targetFps: i,
1739
+ analysisScale: r
1740
+ }) {
1741
+ this.sourceCanvas = t, this.getSource = n, this.setTargetFps(i), this.setAnalysisScale(r), this.analysisCanvas = void 0, this.rafId === null && this.processFaceTracking();
1742
+ }
1743
+ getModelNode() {
1744
+ const t = this, n = {
1745
+ get detectionResults() {
1746
+ return t.detectionResults;
1747
+ },
1748
+ get numFaces() {
1749
+ return t.numFaces;
1750
+ },
1751
+ getDetectionResults: this.getDetectionResults.bind(this),
1752
+ getFace: this.getFace.bind(this),
1753
+ getRawFaceTrackingData: this.getRawFaceTrackingData.bind(this),
1754
+ setCamera: (i, r = 0) => {
1755
+ this.cameras[r] = i;
1756
+ }
1757
+ };
1758
+ return Object.defineProperty(n, Jt, { value: t }), n;
1759
+ }
1760
+ async getPerformanceData() {
1761
+ return {
1762
+ name: this.constructor.name,
1763
+ processingTime: this.processingTime
1764
+ };
1765
+ }
1766
+ }
1767
+ const ni = (e) => e > 1 ? 1024 : 512;
1768
+ var j = /* @__PURE__ */ ((e) => (e.ClosedFist = "closed_fist", e.OpenPalm = "open_palm", e.PointingUp = "pointing_up", e.ThumbDown = "thumb_down", e.ThumbUp = "thumb_up", e.Victory = "victory", e.ILoveYou = "i_love_you", e.None = "none", e))(j || {});
1769
+ const ii = 512, ri = {
1770
+ Closed_Fist: j.ClosedFist,
1771
+ Open_Palm: j.OpenPalm,
1772
+ Pointing_Up: j.PointingUp,
1773
+ Thumb_Down: j.ThumbDown,
1774
+ Thumb_Up: j.ThumbUp,
1775
+ Victory: j.Victory,
1776
+ ILoveYou: j.ILoveYou,
1777
+ None: j.None
1778
+ }, ai = 15;
1779
+ class oi extends se {
1780
+ constructor() {
1781
+ super();
1782
+ m(this, "landmarker", null);
1783
+ m(this, "processingTime", null);
1784
+ m(this, "coordinates");
1785
+ m(this, "gesture");
1786
+ m(this, "sourceCanvas");
1787
+ m(this, "downscaler", new we(ii));
1788
+ }
1789
+ async getGestureData() {
1790
+ var d, l;
1791
+ if (!this.landmarker || !this.sourceCanvas)
1792
+ return;
1793
+ const t = this.downscaler.draw(this.sourceCanvas), n = performance.now(), i = this.landmarker.recognizeForVideo(t, n), r = performance.now();
1794
+ this.processingTime = r - n, this.recordInference(n, r), this.recordDetections(i.landmarks.length, ((l = (d = i.gestures[0]) == null ? void 0 : d[0]) == null ? void 0 : l.score) ?? null);
1795
+ const a = i.landmarks[0], o = [];
1796
+ if (a) {
1797
+ const h = i.gestures[0][0].categoryName;
1798
+ return a.forEach((u) => {
1799
+ o.push(me(u));
1800
+ }), {
1801
+ coordinates: o,
1802
+ gesture: ri[h]
1803
+ };
1804
+ }
1805
+ return { coordinates: void 0, gesture: void 0 };
1806
+ }
1807
+ async processGestureTracking() {
1808
+ if (!this.disposed) {
1809
+ if (this.shouldRunInference()) {
1810
+ const t = await this.getGestureData();
1811
+ t && (this.coordinates = t.coordinates, this.gesture = t.gesture);
1812
+ }
1813
+ this.disposed || this.paused || (this.rafId = requestAnimationFrame(this.processGestureTracking.bind(this)));
1814
+ }
1815
+ }
1816
+ resume() {
1817
+ this.paused && (super.resume(), this.processGestureTracking());
1818
+ }
1819
+ dispose() {
1820
+ if (super.dispose(), this.landmarker) {
1821
+ try {
1822
+ this.landmarker.close();
1823
+ } catch {
1824
+ }
1825
+ this.landmarker = null;
1826
+ }
1827
+ this.sourceCanvas = void 0, this.downscaler.dispose(), this.coordinates = void 0, this.gesture = void 0;
1828
+ }
1829
+ async initialize() {
1830
+ const t = await $.forVisionTasks(
1831
+ new URL("/assets/xr/wasm", q.assetStorageEndpoint).toString()
1832
+ ), [n] = await Promise.all([
1833
+ ee(
1834
+ new URL(
1835
+ "/assets/xr/models/gesture_tracking.task",
1836
+ q.assetStorageEndpoint
1837
+ ).toString()
1838
+ ),
1839
+ te(t)
1840
+ ]), i = await Hs.createFromOptions(t, {
1841
+ baseOptions: {
1842
+ modelAssetBuffer: n,
1843
+ delegate: "GPU"
1844
+ },
1845
+ runningMode: "VIDEO",
1846
+ numHands: 1
1847
+ });
1848
+ this.landmarker = i;
1849
+ }
1850
+ async run({ sourceCanvas: t, targetFps: n, analysisScale: i }) {
1851
+ this.setAnalysisScale(i), this.downscaler.setScale(this.analysisScale), this.sourceCanvas = t, this.setTargetFps(n ?? ai), this.rafId === null && await this.processGestureTracking();
1852
+ }
1853
+ getModelNode() {
1854
+ const t = this;
1855
+ return {
1856
+ get coordinates() {
1857
+ return t.coordinates;
1858
+ },
1859
+ get gesture() {
1860
+ return t.gesture;
1861
+ }
1862
+ };
1863
+ }
1864
+ async getPerformanceData() {
1865
+ return {
1866
+ name: this.constructor.name,
1867
+ processingTime: this.processingTime
1868
+ };
1869
+ }
1870
+ }
1871
+ class ci extends se {
1872
+ constructor() {
1873
+ super();
1874
+ m(this, "landmarker", null);
1875
+ m(this, "status", "loading");
1876
+ m(this, "error", null);
1877
+ m(this, "processingTime", null);
1878
+ m(this, "sourceCanvas");
1879
+ m(this, "getSource");
1880
+ m(this, "downscaler", new we(Ze().analysisMaxDimension));
1881
+ m(this, "raw");
1882
+ m(this, "delegatePolicy", "auto");
1883
+ m(this, "delegate", "GPU");
1884
+ /** Kept so the graph can be rebuilt on another delegate without refetching. */
1885
+ m(this, "vision", null);
1886
+ m(this, "modelBuffer", null);
1887
+ m(this, "graphOptions", {});
1888
+ m(this, "rebuilding", !1);
1889
+ m(this, "fallbackAttempted", !1);
1890
+ m(this, "result", nn());
1891
+ m(this, "builder", new an());
1892
+ m(this, "node");
1893
+ this.node = {
1894
+ getResult: () => this.result,
1895
+ getRawResult: () => this.raw,
1896
+ getStatus: () => this.status,
1897
+ getError: () => this.error,
1898
+ getDelegate: () => this.delegate,
1899
+ setOptions: (t) => this.setRuntimeOptions(t)
1900
+ };
1901
+ }
1902
+ setRuntimeOptions(t) {
1903
+ const n = this.builder.getOptions().analysisMaxDimension;
1904
+ this.builder.setOptions(t);
1905
+ const i = this.builder.getOptions().analysisMaxDimension;
1906
+ i !== n && (this.downscaler.dispose(), this.downscaler = new we(i), this.downscaler.setScale(this.analysisScale));
1907
+ }
1908
+ async initialize(t) {
1909
+ this.status = "loading", this.error = null, this.setRuntimeOptions(t ?? {});
1910
+ try {
1911
+ const n = await $.forVisionTasks(
1912
+ new URL("/assets/xr/wasm", q.assetStorageEndpoint).toString()
1913
+ ), [i] = await Promise.all([
1914
+ ee((t == null ? void 0 : t.modelUrl) ?? Ut),
1915
+ te(n)
1916
+ ]);
1917
+ this.vision = n, this.modelBuffer = i, this.graphOptions = {
1918
+ runningMode: "VIDEO",
1919
+ outputFaceBlendshapes: (t == null ? void 0 : t.outputFaceBlendshapes) ?? !0,
1920
+ minFaceDetectionConfidence: t == null ? void 0 : t.minFaceDetectionConfidence,
1921
+ minFacePresenceConfidence: t == null ? void 0 : t.minFacePresenceConfidence,
1922
+ minPoseDetectionConfidence: t == null ? void 0 : t.minPoseDetectionConfidence,
1923
+ minPosePresenceConfidence: t == null ? void 0 : t.minPosePresenceConfidence,
1924
+ minHandLandmarksConfidence: t == null ? void 0 : t.minHandLandmarksConfidence
1925
+ }, this.delegatePolicy = (t == null ? void 0 : t.delegate) ?? "auto", this.delegate = this.delegatePolicy === "CPU" ? "CPU" : "GPU";
1926
+ const r = await this.createLandmarker(this.delegate);
1927
+ if (this.disposed) {
1928
+ r.close();
1929
+ return;
1930
+ }
1931
+ this.landmarker = r, this.status = "ready";
1932
+ } catch (n) {
1933
+ throw this.status = "error", this.error = n instanceof Error ? n : new Error(String(n)), this.error;
1934
+ }
1935
+ }
1936
+ createLandmarker(t) {
1937
+ if (!this.vision || !this.modelBuffer)
1938
+ throw new Error("HolisticTrackingModel: initialize() has not loaded the model");
1939
+ return Us.createFromOptions(this.vision, {
1940
+ baseOptions: { modelAssetBuffer: this.modelBuffer, delegate: t },
1941
+ ...this.graphOptions
1942
+ });
1943
+ }
1944
+ /**
1945
+ * The GPU graph can fail on its first run (the face-blendshape stage has no
1946
+ * WebGL kernel for one of its ops). Rebuild on the CPU once, keep the RAF
1947
+ * loop alive meanwhile, and run one detection right away so static sources
1948
+ * (which pulse models once) still get a result.
1949
+ */
1950
+ async fallbackToCpu(t) {
1951
+ this.fallbackAttempted = !0, this.rebuilding = !0, this.status = "loading", console.warn(
1952
+ "[xr-sdk holistic] GPU inference failed; rebuilding the graph on the CPU delegate.",
1953
+ t.message
1954
+ );
1955
+ const n = this.landmarker;
1956
+ try {
1957
+ const i = await this.createLandmarker("CPU");
1958
+ if (this.disposed) {
1959
+ i.close();
1960
+ return;
1961
+ }
1962
+ this.landmarker = i, this.delegate = "CPU", this.status = "ready", this.error = null;
1963
+ try {
1964
+ n == null || n.close();
1965
+ } catch {
1966
+ }
1967
+ this.rebuilding = !1, this.detectOnce();
1968
+ } catch (i) {
1969
+ this.rebuilding = !1, this.status = "error", this.error = i instanceof Error ? i : new Error(String(i));
1970
+ }
1971
+ }
1972
+ /** One detect + publish outside the loop (used after a delegate rebuild). */
1973
+ detectOnce() {
1974
+ this.disposed || !this.landmarker || !this.sourceCanvas || (this.detect(), this.builder.update(this.raw, performance.now(), this.result, this.isMirrored()));
1975
+ }
1976
+ detect() {
1977
+ var i, r, a, o, d;
1978
+ if (!this.landmarker || !this.sourceCanvas) return;
1979
+ const t = this.downscaler.draw(this.sourceCanvas), n = performance.now();
1980
+ try {
1981
+ this.raw = this.landmarker.detectForVideo(t, n), this.status === "error" && (this.status = "ready", this.error = null), this.recordInferenceError(null);
1982
+ const l = this.raw, h = ((i = l.faceLandmarks) != null && i.length ? 1 : 0) + ((r = l.leftHandLandmarks) != null && r.length ? 1 : 0) + ((a = l.rightHandLandmarks) != null && a.length ? 1 : 0) + ((o = l.poseLandmarks) != null && o.length ? 1 : 0), u = (d = l.poseLandmarks) == null ? void 0 : d[0];
1983
+ this.recordDetections(
1984
+ h,
1985
+ u && u.length ? u.reduce((p, M) => p + (M.visibility ?? 0), 0) / u.length : null
1986
+ );
1987
+ } catch (l) {
1988
+ const h = l instanceof Error ? l : new Error(String(l));
1989
+ this.delegatePolicy === "auto" && this.delegate === "GPU" && !this.fallbackAttempted ? this.fallbackToCpu(h) : (this.status = "error", this.error = h, this.recordInferenceError(h));
1990
+ }
1991
+ this.processingTime = performance.now() - n, this.recordInference(n);
1992
+ }
1993
+ /** The session mirrors only the webcam feed (an unknown kind is treated as webcam). */
1994
+ isMirrored() {
1995
+ var t;
1996
+ return Se((t = this.getSource) == null ? void 0 : t.call(this));
1997
+ }
1998
+ async run({
1999
+ sourceCanvas: t,
2000
+ getSource: n,
2001
+ targetFps: i,
2002
+ analysisScale: r
2003
+ }) {
2004
+ this.sourceCanvas = t, this.getSource = n, this.setTargetFps(i), this.setAnalysisScale(r), this.downscaler.setScale(this.analysisScale), this.rafId === null && await this.process();
2005
+ }
2006
+ async process() {
2007
+ this.disposed || this.paused || !this.landmarker || (!this.rebuilding && this.shouldRunInference() && this.detect(), this.builder.update(this.raw, performance.now(), this.result, this.isMirrored()), !(this.disposed || this.paused) && (this.rafId = requestAnimationFrame(this.process.bind(this))));
2008
+ }
2009
+ resume() {
2010
+ this.paused && (super.resume(), this.process());
2011
+ }
2012
+ dispose() {
2013
+ if (super.dispose(), this.landmarker) {
2014
+ try {
2015
+ this.landmarker.close();
2016
+ } catch {
2017
+ }
2018
+ this.landmarker = null;
2019
+ }
2020
+ this.sourceCanvas = void 0, this.getSource = void 0, this.downscaler.dispose(), this.vision = null, this.modelBuffer = null, this.raw = void 0, this.builder.reset(), this.result.face = null, this.result.leftHand = null, this.result.rightHand = null, this.result.pose = null;
2021
+ }
2022
+ getModelNode() {
2023
+ return this.node;
2024
+ }
2025
+ async getPerformanceData() {
2026
+ return { name: this.constructor.name, processingTime: this.processingTime };
2027
+ }
2028
+ }
2029
+ const li = (e) => e === "left" ? "right" : "left", di = (e, s) => s ? li(e) : e, hi = /left|right|Left|Right/, ui = {
2030
+ left: "right",
2031
+ right: "left",
2032
+ Left: "Right",
2033
+ Right: "Left"
2034
+ }, mi = (e) => e.replace(hi, (s) => ui[s]), Zr = (e, s) => s ? mi(e) : e, $r = (e) => e ? -1 : 1, fi = [
2035
+ "wrist",
2036
+ "thumbCmc",
2037
+ "thumbMcp",
2038
+ "thumbIp",
2039
+ "thumbTip",
2040
+ "indexMcp",
2041
+ "indexPip",
2042
+ "indexDip",
2043
+ "indexTip",
2044
+ "middleMcp",
2045
+ "middlePip",
2046
+ "middleDip",
2047
+ "middleTip",
2048
+ "ringMcp",
2049
+ "ringPip",
2050
+ "ringDip",
2051
+ "ringTip",
2052
+ "pinkyMcp",
2053
+ "pinkyPip",
2054
+ "pinkyDip",
2055
+ "pinkyTip"
2056
+ ], ea = Object.fromEntries(
2057
+ fi.map((e, s) => [e, s])
2058
+ ), gi = 200, ge = (e, s) => Math.hypot(e.x - s.x, e.y - s.y), pe = (e) => e === "left" ? "right" : "left", Ye = (e, s, t) => ({
2059
+ handedness: s,
2060
+ score: e.score,
2061
+ world: e.world,
2062
+ image: e.image,
2063
+ timestampMs: t,
2064
+ held: !1
2065
+ }), pi = (e, s, t, {
2066
+ holdMs: n = gi,
2067
+ confidentScore: i = 0.8,
2068
+ continuityMs: r = 500
2069
+ } = {}) => {
2070
+ const a = (l) => !!l && t - l.timestampMs <= r && l.image.length > 0, o = { left: null, right: null }, d = e.filter((l) => l.image.length > 0).slice(0, 2);
2071
+ if (d.length === 2) {
2072
+ const [l, h] = d, u = l.handedness !== void 0 && h.handedness !== void 0 && l.handedness !== h.handedness, p = l.score >= i && h.score >= i;
2073
+ let M;
2074
+ if (u && p)
2075
+ M = l.handedness;
2076
+ else if (a(s.left) && a(s.right)) {
2077
+ const x = ge(l.image[0], s.left.image[0]) + ge(h.image[0], s.right.image[0]), b = ge(l.image[0], s.right.image[0]) + ge(h.image[0], s.left.image[0]);
2078
+ M = x <= b ? "left" : "right";
2079
+ } else if (u)
2080
+ M = l.handedness;
2081
+ else {
2082
+ const x = l.score >= h.score ? l : h, b = x.handedness ?? "right";
2083
+ M = x === l ? b : pe(b);
2084
+ }
2085
+ o[M] = Ye(l, M, t), o[pe(M)] = Ye(h, pe(M), t);
2086
+ } else if (d.length === 1) {
2087
+ const [l] = d;
2088
+ let h = l.handedness ?? "right";
2089
+ if (l.score < i || l.handedness === void 0) {
2090
+ const u = (x) => a(x) ? ge(l.image[0], x.image[0]) : 1 / 0, p = u(s[h]);
2091
+ u(s[pe(h)]) < p && (h = pe(h));
2092
+ }
2093
+ o[h] = Ye(l, h, t);
2094
+ }
2095
+ for (const l of ["left", "right"]) {
2096
+ const h = s[l];
2097
+ o[l] || !h || t - h.timestampMs <= n && (o[l] = { ...h, held: !0 });
2098
+ }
2099
+ return o;
2100
+ }, yi = (e, s) => {
2101
+ const t = e == null ? void 0 : e.toLowerCase();
2102
+ if (!(t !== "left" && t !== "right"))
2103
+ return di(t, s);
2104
+ }, wi = (e, s = { x: 0, y: 0, z: 0 }) => (s.x = e.x * 100, s.y = -e.y * 100, s.z = -e.z * 100, s), vi = 512, xi = Object.freeze({
2105
+ minHandDetectionConfidence: 0.5,
2106
+ minHandPresenceConfidence: 0.65,
2107
+ minTrackingConfidence: 0.5
2108
+ });
2109
+ class Si extends se {
2110
+ constructor() {
2111
+ super();
2112
+ m(this, "landmarker", null);
2113
+ m(this, "processingTime", null);
2114
+ m(this, "hands");
2115
+ m(this, "coordinates");
2116
+ m(this, "gesture");
2117
+ m(this, "handedness");
2118
+ m(this, "poses", { left: null, right: null });
2119
+ m(this, "sourceCanvas");
2120
+ m(this, "getSource");
2121
+ m(this, "downscaler", new we(vi));
2122
+ }
2123
+ async getHandData() {
2124
+ var u, p, M;
2125
+ if (!this.landmarker || !this.sourceCanvas)
2126
+ return;
2127
+ const t = this.downscaler.draw(this.sourceCanvas), n = performance.now(), i = this.landmarker.detectForVideo(t, n), r = performance.now();
2128
+ this.processingTime = r - n, this.recordInference(n, r);
2129
+ const a = [], o = [], d = i.handedness ?? i.handednesses ?? [];
2130
+ this.recordDetections(i.landmarks.length, ((p = (u = d[0]) == null ? void 0 : u[0]) == null ? void 0 : p.score) ?? null);
2131
+ const l = Se((M = this.getSource) == null ? void 0 : M.call(this));
2132
+ if (i.landmarks.forEach((x, b) => {
2133
+ var A, E;
2134
+ if (!x || x.length === 0)
2135
+ return;
2136
+ const T = x.map(
2137
+ (B) => me(B)
2138
+ ), R = (((A = i.worldLandmarks) == null ? void 0 : A[b]) ?? []).map(
2139
+ (B) => wi(B)
2140
+ ), w = (E = d[b]) == null ? void 0 : E[0], g = yi(w == null ? void 0 : w.categoryName, l), y = (w == null ? void 0 : w.score) ?? 0, v = x[0].z < 0 ? "closed_fist" : "open_palm";
2141
+ a.push({ coordinates: T, worldCoordinates: R, gesture: v, handedness: g, handednessScore: y }), o.push({
2142
+ handedness: g,
2143
+ score: y,
2144
+ world: R,
2145
+ image: T
2146
+ });
2147
+ }), this.poses = pi(o, this.poses, n), !a.length)
2148
+ return {
2149
+ hands: void 0,
2150
+ coordinates: void 0,
2151
+ gesture: void 0,
2152
+ handedness: void 0
2153
+ };
2154
+ const h = a[0];
2155
+ return {
2156
+ hands: a,
2157
+ coordinates: h.coordinates,
2158
+ gesture: h.gesture,
2159
+ handedness: h.handedness
2160
+ };
2161
+ }
2162
+ async processHandTracking() {
2163
+ if (!this.disposed) {
2164
+ if (this.shouldRunInference()) {
2165
+ const t = await this.getHandData();
2166
+ t && (this.hands = t.hands, this.coordinates = t.coordinates, this.gesture = t.gesture, this.handedness = t.handedness);
2167
+ }
2168
+ this.disposed || this.paused || (this.rafId = requestAnimationFrame(this.processHandTracking.bind(this)));
2169
+ }
2170
+ }
2171
+ resume() {
2172
+ this.paused && (super.resume(), this.processHandTracking());
2173
+ }
2174
+ dispose() {
2175
+ if (super.dispose(), this.landmarker) {
2176
+ try {
2177
+ this.landmarker.close();
2178
+ } catch {
2179
+ }
2180
+ this.landmarker = null;
2181
+ }
2182
+ this.sourceCanvas = void 0, this.getSource = void 0, this.hands = void 0, this.poses = { left: null, right: null }, this.downscaler.dispose(), this.coordinates = void 0, this.gesture = void 0, this.handedness = void 0;
2183
+ }
2184
+ async initialize() {
2185
+ const t = await $.forVisionTasks(
2186
+ new URL("/assets/xr/wasm", q.assetStorageEndpoint).toString()
2187
+ ), [n] = await Promise.all([
2188
+ ee(
2189
+ new URL("/assets/xr/models/hand_tracking.task", q.assetStorageEndpoint).toString()
2190
+ ),
2191
+ te(t)
2192
+ ]), i = await zs.createFromOptions(t, {
2193
+ baseOptions: {
2194
+ modelAssetBuffer: n,
2195
+ delegate: "GPU"
2196
+ },
2197
+ runningMode: "VIDEO",
2198
+ numHands: 2,
2199
+ ...xi
2200
+ });
2201
+ this.landmarker = i;
2202
+ }
2203
+ async run({
2204
+ sourceCanvas: t,
2205
+ getSource: n,
2206
+ targetFps: i,
2207
+ analysisScale: r
2208
+ }) {
2209
+ this.getSource = n, this.setAnalysisScale(r), this.downscaler.setScale(this.analysisScale), this.sourceCanvas = t, this.setTargetFps(i), this.rafId === null && await this.processHandTracking();
2210
+ }
2211
+ getModelNode() {
2212
+ const t = this;
2213
+ return {
2214
+ get hands() {
2215
+ return t.hands;
2216
+ },
2217
+ get coordinates() {
2218
+ return t.coordinates;
2219
+ },
2220
+ get gesture() {
2221
+ return t.gesture;
2222
+ },
2223
+ get handedness() {
2224
+ return t.handedness;
2225
+ },
2226
+ get poses() {
2227
+ return t.poses;
2228
+ },
2229
+ getHandPose: (n) => t.poses[n]
2230
+ };
2231
+ }
2232
+ async getPerformanceData() {
2233
+ return {
2234
+ name: this.constructor.name,
2235
+ processingTime: this.processingTime
2236
+ };
2237
+ }
2238
+ }
2239
+ const Mi = 24, bi = 720, ki = [
2240
+ [255, 255, 255, 255],
2241
+ // 0: the person → white
2242
+ [0, 0, 0, 0]
2243
+ // 1
2244
+ ];
2245
+ class Ci extends se {
2246
+ constructor() {
2247
+ super();
2248
+ m(this, "segmenter", null);
2249
+ m(this, "processingTime", null);
2250
+ m(this, "sourceCanvas");
2251
+ // input source canvas
2252
+ m(this, "processCanvas");
2253
+ // downscaled canvas of sourceCanvas for processing
2254
+ m(this, "filterCanvas");
2255
+ // post-processing (blur) canvas
2256
+ // Optional high-resolution input override. The shared session feed canvas is
2257
+ // sized to the on-screen display layout (often a small, display-fit crop),
2258
+ // which starves the segmenter of the resolution it needs to capture the whole
2259
+ // body. When a consumer supplies a native-resolution source here (e.g. the raw
2260
+ // <video>/<img>), the segmenter runs on THAT instead — letterboxed into the
2261
+ // process canvas so nothing is cropped. Falls back to `sourceCanvas` when unset.
2262
+ m(this, "inputSource");
2263
+ m(this, "inputSourceSize");
2264
+ // The segmenter's own WebGL2 context. DrawingUtils renders the inverted mask
2265
+ // into this context on the GPU; we then blit that GL canvas straight into the
2266
+ // mask canvas with a single `drawImage` — a GPU→GPU transfer, no CPU readback
2267
+ // and no per-pixel JS loop. (A spike proved `drawImage(glCanvas)` reads the
2268
+ // full DrawingUtils output correctly; the earlier "reads empty" wall that once
2269
+ // forced a readPixels path was a false alarm.)
2270
+ m(this, "glCanvas");
2271
+ m(this, "drawingUtils");
2272
+ m(this, "useGpuMaskPath", !1);
2273
+ // CPU-fallback reused ImageData, allocated on size change only. Used ONLY when
2274
+ // WebGL2 is unavailable and we must read the single-channel mask back by hand.
2275
+ m(this, "maskImageData");
2276
+ m(this, "maskCanvas", null);
2277
+ m(this, "segmentationMaskTexture");
2278
+ m(this, "isMaskSetup", !1);
2279
+ m(this, "isProcessing", !1);
2280
+ // Live clone of the most recent category mask, kept so getRawSegmentationData()
2281
+ // can read the single-channel Uint8Array lazily — that readback is paid ONLY
2282
+ // when a consumer actually asks for raw data. Cloned because the mask returned
2283
+ // by segmentForVideo is invalidated on the next inference call.
2284
+ m(this, "latestMask", null);
2285
+ // Per-frame cache of the read-back array, so repeated getRawSegmentationData()
2286
+ // calls within one frame don't re-run the GPU→CPU transfer.
2287
+ m(this, "rawCache", null);
2288
+ /** When the frame behind `latestMask` was segmented (`performance.now()`). */
2289
+ m(this, "latestMaskTimeMs", 0);
2290
+ m(this, "quality", "medium");
2291
+ m(this, "stagingCanvas");
2292
+ }
2293
+ getQualityScaleFactor() {
2294
+ switch (this.quality) {
2295
+ case "low":
2296
+ return 0.5;
2297
+ case "medium":
2298
+ return 0.75;
2299
+ case "high":
2300
+ return 1;
2301
+ default:
2302
+ return 0.5;
2303
+ }
2304
+ }
2305
+ /**
2306
+ * Set (or clear) a high-resolution input override. Pass the raw <video>/<img>
2307
+ * (or any CanvasImageSource with intrinsic dimensions) to run segmentation on
2308
+ * native-resolution, uncropped frames instead of the small display-fit session
2309
+ * feed. Pass `undefined` to revert to the shared feed canvas.
2310
+ */
2311
+ setInputSource(t) {
2312
+ this.inputSource = t, this.inputSourceSize = t ? this.readIntrinsicSize(t) : void 0;
2313
+ }
2314
+ readIntrinsicSize(t) {
2315
+ if (t instanceof HTMLVideoElement)
2316
+ return t.videoWidth > 0 ? { width: t.videoWidth, height: t.videoHeight } : void 0;
2317
+ if (t instanceof HTMLImageElement)
2318
+ return t.naturalWidth > 0 ? { width: t.naturalWidth, height: t.naturalHeight } : void 0;
2319
+ const n = t.width, i = t.height;
2320
+ return typeof n == "number" && n > 0 && typeof i == "number" && i > 0 ? { width: n, height: i } : void 0;
2321
+ }
2322
+ /**
2323
+ * Size the process canvas to the override input's aspect ratio, bounded by
2324
+ * PROCESS_MAX_DIM on the long edge, and keep the GL canvas in sync so the GPU
2325
+ * mask renders at the same resolution. No-op when there is no override, or when
2326
+ * the intrinsic size hasn't changed since the last frame.
2327
+ */
2328
+ ensureProcessCanvasForInput() {
2329
+ if (!this.processCanvas || !this.inputSource) return;
2330
+ const t = this.readIntrinsicSize(this.inputSource);
2331
+ if (!t) return;
2332
+ this.inputSourceSize = t;
2333
+ const n = Math.min(1, bi / Math.max(t.width, t.height)), i = Math.max(1, Math.round(t.width * n)), r = Math.max(1, Math.round(t.height * n));
2334
+ this.processCanvas.width === i && this.processCanvas.height === r || (this.processCanvas.width = i, this.processCanvas.height = r, this.glCanvas && (this.glCanvas.width = i, this.glCanvas.height = r), this.maskImageData = void 0);
2335
+ }
2336
+ async processSegmentation() {
2337
+ if (this.disposed || !this.isProcessing || !this.maskCanvas || !this.processCanvas)
2338
+ return;
2339
+ if (!this.shouldRunInference()) {
2340
+ if (this.disposed || this.paused) return;
2341
+ this.rafId = requestAnimationFrame(this.processSegmentation.bind(this));
2342
+ return;
2343
+ }
2344
+ const t = this.inputSource ?? this.sourceCanvas;
2345
+ if (!this.segmenter || !t) {
2346
+ if (this.disposed || this.paused) return;
2347
+ this.rafId = requestAnimationFrame(this.processSegmentation.bind(this));
2348
+ return;
2349
+ }
2350
+ const n = performance.now();
2351
+ this.ensureProcessCanvasForInput();
2352
+ const i = this.processCanvas.getContext("2d");
2353
+ if (i) {
2354
+ const d = this.processCanvas.width, l = this.processCanvas.height;
2355
+ if (i.clearRect(0, 0, d, l), this.inputSource && this.inputSourceSize) {
2356
+ const { width: h, height: u } = this.inputSourceSize, p = Math.min(d / h, l / u), M = h * p, x = u * p;
2357
+ i.drawImage(this.inputSource, (d - M) / 2, (l - x) / 2, M, x);
2358
+ } else
2359
+ i.drawImage(t, 0, 0, d, l);
2360
+ }
2361
+ const r = performance.now(), o = this.segmenter.segmentForVideo(this.processCanvas, r).categoryMask;
2362
+ if (!o) {
2363
+ if (this.disposed || this.paused) return;
2364
+ this.rafId = requestAnimationFrame(this.processSegmentation.bind(this));
2365
+ return;
2366
+ }
2367
+ if (this.rawCache = null, this.latestMaskTimeMs = r, this.latestMask && (this.latestMask.close(), this.latestMask = null), this.useGpuMaskPath && this.drawingUtils && this.glCanvas)
2368
+ this.drawingUtils.drawCategoryMask(o, ki), this.latestMask = o.clone(), o.close(), this.blitGlToMask();
2369
+ else {
2370
+ this.latestMask = o.clone();
2371
+ const d = this.readMaskToImageData(o);
2372
+ o.close(), d && this.blitImageDataToMask(d);
2373
+ }
2374
+ this.segmentationMaskTexture && (this.isMaskSetup || (this.segmentationMaskTexture.format = Bt, this.segmentationMaskTexture.minFilter = Ie, this.segmentationMaskTexture.magFilter = Ie, this.segmentationMaskTexture.generateMipmaps = !1, this.isMaskSetup = !0), this.segmentationMaskTexture.needsUpdate = !0), this.processingTime = performance.now() - n, this.recordInference(n), this.recordDetections(1, null), !(this.disposed || this.paused) && (this.rafId = requestAnimationFrame(this.processSegmentation.bind(this)));
2375
+ }
2376
+ /**
2377
+ * Blit the GPU-rendered mask (already RGBA-inverted by drawCategoryMask)
2378
+ * straight from the GL canvas into the mask canvas, cover-fitted through the
2379
+ * soft-edge blur. `drawImage(glCanvas)` is a GPU→GPU transfer — no readPixels,
2380
+ * no CPU array, no ImageData, no row flip (the 2D canvas presents the WebGL
2381
+ * canvas right-side-up). This is the zero-readback path.
2382
+ */
2383
+ blitGlToMask() {
2384
+ if (!this.maskCanvas || !this.filterCanvas || !this.glCanvas) return;
2385
+ const t = this.maskCanvas.getContext("2d"), n = this.filterCanvas.getContext("2d");
2386
+ !t || !n || (n.filter = "blur(0.5px)", n.clearRect(0, 0, this.filterCanvas.width, this.filterCanvas.height), n.drawImage(this.glCanvas, 0, 0, this.filterCanvas.width, this.filterCanvas.height), t.clearRect(0, 0, this.maskCanvas.width, this.maskCanvas.height), t.drawImage(this.filterCanvas, 0, 0, this.maskCanvas.width, this.maskCanvas.height));
2387
+ }
2388
+ /**
2389
+ * CPU-fallback ImageData build (only when the GPU path is off). The
2390
+ * single-channel mask is expanded to RGBA with green and alpha 255 on the
2391
+ * person and 0 on the background, like the GPU path (green carries the
2392
+ * signal for the alphaMap).
2393
+ */
2394
+ readMaskToImageData(t) {
2395
+ const n = t.getAsUint8Array(), { width: i, height: r } = t;
2396
+ if (!n || i <= 0 || r <= 0) return null;
2397
+ (!this.maskImageData || this.maskImageData.width !== i || this.maskImageData.height !== r) && (this.maskImageData = new ImageData(i, r));
2398
+ const a = this.maskImageData.data;
2399
+ for (let o = 0; o < n.length; o += 1) {
2400
+ const d = n[o] === 255 ? 0 : 255;
2401
+ a[o * 4] = 255, a[o * 4 + 1] = d, a[o * 4 + 2] = 255, a[o * 4 + 3] = d;
2402
+ }
2403
+ return this.maskImageData;
2404
+ }
2405
+ /**
2406
+ * CPU-fallback blit: put the inverted-alpha mask ImageData into maskCanvas
2407
+ * with a soft-edge blur, cover-fitted to the render target. Only used when the
2408
+ * GPU path is off; the GPU path blits the GL canvas directly (blitGlToMask).
2409
+ */
2410
+ blitImageDataToMask(t) {
2411
+ if (!this.maskCanvas || !this.filterCanvas) return;
2412
+ const n = this.maskCanvas.getContext("2d"), i = this.filterCanvas.getContext("2d");
2413
+ if (!n || !i) return;
2414
+ const r = this.getStagingCanvas(t.width, t.height), a = r.getContext("2d");
2415
+ a && (a.putImageData(t, 0, 0), i.filter = "blur(0.5px)", i.clearRect(0, 0, this.filterCanvas.width, this.filterCanvas.height), i.drawImage(r, 0, 0, this.filterCanvas.width, this.filterCanvas.height), n.clearRect(0, 0, this.maskCanvas.width, this.maskCanvas.height), n.drawImage(this.filterCanvas, 0, 0, this.maskCanvas.width, this.maskCanvas.height));
2416
+ }
2417
+ getStagingCanvas(t, n) {
2418
+ return this.stagingCanvas || (this.stagingCanvas = document.createElement("canvas")), this.stagingCanvas.width !== t && (this.stagingCanvas.width = t), this.stagingCanvas.height !== n && (this.stagingCanvas.height = n), this.stagingCanvas;
2419
+ }
2420
+ resume() {
2421
+ this.paused && (super.resume(), this.processSegmentation());
2422
+ }
2423
+ dispose() {
2424
+ if (super.dispose(), this.isProcessing = !1, this.latestMask) {
2425
+ try {
2426
+ this.latestMask.close();
2427
+ } catch {
2428
+ }
2429
+ this.latestMask = null;
2430
+ }
2431
+ if (this.rawCache = null, this.segmenter) {
2432
+ try {
2433
+ this.segmenter.close();
2434
+ } catch {
2435
+ }
2436
+ this.segmenter = null;
2437
+ }
2438
+ this.drawingUtils = void 0, this.glCanvas = void 0, this.maskImageData = void 0, this.segmentationMaskTexture && (this.segmentationMaskTexture.dispose(), this.segmentationMaskTexture = void 0), this.sourceCanvas = void 0, this.inputSource = void 0, this.inputSourceSize = void 0, this.processCanvas = void 0, this.filterCanvas = void 0, this.stagingCanvas = void 0, this.maskCanvas = null;
2439
+ }
2440
+ async initialize(t) {
2441
+ this.quality = (t == null ? void 0 : t.quality) ?? "low";
2442
+ const n = await $.forVisionTasks(
2443
+ new URL("/assets/xr/wasm", q.assetStorageEndpoint).toString()
2444
+ ), [i] = await Promise.all([
2445
+ ee(
2446
+ new URL("/assets/xr/models/segmentation.tflite", q.assetStorageEndpoint).toString()
2447
+ ),
2448
+ te(n)
2449
+ ]);
2450
+ this.glCanvas = new OffscreenCanvas(1, 1);
2451
+ const r = this.glCanvas.getContext("webgl2", {
2452
+ preserveDrawingBuffer: !0
2453
+ });
2454
+ this.segmenter = await Nt.createFromOptions(n, {
2455
+ baseOptions: {
2456
+ modelAssetBuffer: i,
2457
+ delegate: "GPU"
2458
+ },
2459
+ ...r ? { canvas: this.glCanvas } : {},
2460
+ outputCategoryMask: !0,
2461
+ outputConfidenceMasks: !1,
2462
+ runningMode: "VIDEO"
2463
+ }), r ? (this.drawingUtils = new Ws(r), this.useGpuMaskPath = !0) : this.useGpuMaskPath = !1;
2464
+ }
2465
+ async run({
2466
+ sourceCanvas: t,
2467
+ renderWidth: n,
2468
+ renderHeight: i,
2469
+ targetFps: r
2470
+ }) {
2471
+ var o;
2472
+ if (!t)
2473
+ return;
2474
+ this.setTargetFps(r ?? Mi), this.isProcessing = !1, this.rafId !== null && (cancelAnimationFrame(this.rafId), this.rafId = null);
2475
+ const a = this.getQualityScaleFactor();
2476
+ this.sourceCanvas = t, this.processCanvas = document.createElement("canvas"), this.processCanvas.width = t.width * a, this.processCanvas.height = t.height * a, this.glCanvas && (this.glCanvas.width = this.processCanvas.width, this.glCanvas.height = this.processCanvas.height), this.maskImageData = void 0, this.maskCanvas = document.createElement("canvas"), this.maskCanvas.width = n, this.maskCanvas.height = i, this.filterCanvas = document.createElement("canvas"), this.filterCanvas.width = n, this.filterCanvas.height = i, (o = this.segmentationMaskTexture) == null || o.dispose(), this.segmentationMaskTexture = new Ht(this.maskCanvas), this.isMaskSetup = !1, this.rawCache = null, this.isProcessing = !0, this.lastInferenceMs = 0, this.rafId = requestAnimationFrame(this.processSegmentation.bind(this));
2477
+ }
2478
+ /**
2479
+ * Lazily read the single-channel mask back to a Uint8Array. Only invoked when
2480
+ * a consumer calls getRawSegmentationData(); the default texture path never
2481
+ * touches it, so apps that only use <VideoBackground> pay no extra readback.
2482
+ */
2483
+ getRawSegmentationData() {
2484
+ if (this.rawCache) return this.rawCache;
2485
+ if (!this.latestMask) return null;
2486
+ const t = this.latestMask.getAsUint8Array();
2487
+ return this.rawCache = {
2488
+ maskData: t,
2489
+ width: this.latestMask.width,
2490
+ height: this.latestMask.height,
2491
+ timestampMs: this.latestMaskTimeMs
2492
+ }, this.rawCache;
2493
+ }
2494
+ getModelNode() {
2495
+ const t = this;
2496
+ return {
2497
+ get backgroundSegmentationMask() {
2498
+ return t.segmentationMaskTexture;
2499
+ },
2500
+ getMaskCanvas: () => t.maskCanvas,
2501
+ getRawSegmentationData: () => t.getRawSegmentationData(),
2502
+ getMaskTimestampMs: () => t.latestMaskTimeMs,
2503
+ setInputSource: (n) => t.setInputSource(n ?? void 0)
2504
+ };
2505
+ }
2506
+ async getPerformanceData() {
2507
+ return {
2508
+ name: this.constructor.name,
2509
+ processingTime: this.processingTime
2510
+ };
2511
+ }
2512
+ }
2513
+ const Ti = (e, s, t, n = "feed") => ({
2514
+ width: Math.max(1, Math.round(e)),
2515
+ height: Math.max(1, Math.round(s)),
2516
+ indices: new Uint8Array(Math.max(1, Math.round(e)) * Math.max(1, Math.round(s))),
2517
+ labels: t,
2518
+ space: n,
2519
+ version: 0
2520
+ }), ta = (e) => {
2521
+ e.indices.fill(0);
2522
+ }, sa = (e, s) => e.labels.indexOf(s), Ei = (e, s, t) => {
2523
+ const { width: n, height: i, indices: r } = e, a = s.length;
2524
+ if (a < 3) return;
2525
+ let o = 1 / 0, d = -1 / 0;
2526
+ for (let p = 0; p < a; p += 1) {
2527
+ const M = s[p].y * i;
2528
+ M < o && (o = M), M > d && (d = M);
2529
+ }
2530
+ const l = Math.max(0, Math.floor(o)), h = Math.min(i - 1, Math.ceil(d)), u = [];
2531
+ for (let p = l; p <= h; p += 1) {
2532
+ const M = p + 0.5;
2533
+ u.length = 0;
2534
+ for (let b = 0; b < a; b += 1) {
2535
+ const T = s[b], R = s[(b + 1) % a], w = T.y * i, g = R.y * i;
2536
+ if (M < w == M < g) continue;
2537
+ const y = (M - w) / (g - w);
2538
+ u.push((T.x + y * (R.x - T.x)) * n);
2539
+ }
2540
+ u.sort((b, T) => b - T);
2541
+ const x = p * n;
2542
+ for (let b = 0; b + 1 < u.length; b += 2) {
2543
+ const T = Math.max(0, Math.round(u[b])), R = Math.min(n, Math.round(u[b + 1]));
2544
+ for (let w = T; w < R; w += 1) r[x + w] = t;
2545
+ }
2546
+ }
2547
+ }, na = (e, s, t, n, i = []) => {
2548
+ i.length = 0;
2549
+ for (let r = 0; r < t.length; r += 1) {
2550
+ const a = s[t[r]];
2551
+ if (!a) return;
2552
+ i.push(a);
2553
+ }
2554
+ Ei(e, i, n);
2555
+ }, Qe = (e) => e, Pt = {
2556
+ hair: {
2557
+ labels: ["bg", "hair"],
2558
+ assetPath: "/assets/xr/models/hair_segmenter.tflite",
2559
+ defaultUrl: "https://storage.googleapis.com/mediapipe-models/image_segmenter/hair_segmenter/float32/latest/hair_segmenter.tflite",
2560
+ decode: Qe
2561
+ },
2562
+ multiclass: {
2563
+ labels: ["bg", "hair", "body_skin", "face_skin", "clothes", "others"],
2564
+ assetPath: "/assets/xr/models/selfie_multiclass_256x256.tflite",
2565
+ defaultUrl: "https://storage.googleapis.com/mediapipe-models/image_segmenter/selfie_multiclass_256x256/float32/latest/selfie_multiclass_256x256.tflite",
2566
+ decode: Qe
2567
+ },
2568
+ // Fingernails: the MIT-licensed tiny U-Net from nngeek195/nail-segmentation-v1
2569
+ // (Hugging Face), re-exported to TFLite float16 with the input normalisation
2570
+ // baked in (0..1 RGB, as MediaPipe feeds it) and a two-class output
2571
+ // (assets-src/nail-segmenter). Fixed input
2572
+ // 128 × 224 (w × h): MediaPipe stretches the feed to it.
2573
+ nails: {
2574
+ labels: ["bg", "nail"],
2575
+ assetPath: "/assets/xr/models/nail_segmenter_v1.tflite",
2576
+ defaultUrl: "https://cdn.vincentt.studio/assets/xr/models/nail_segmenter_v1.tflite",
2577
+ decode: Qe
2578
+ }
2579
+ }, Ri = (e, s, t) => {
2580
+ const n = t.length === e.length ? t : new Uint8Array(e.length);
2581
+ for (let i = 0; i < e.length; i += 1) n[i] = s(e[i]);
2582
+ return n;
2583
+ }, Ai = 15, Ii = { low: 0.5, medium: 0.75, high: 1 };
2584
+ class Fi extends se {
2585
+ constructor() {
2586
+ super();
2587
+ m(this, "segmenter", null);
2588
+ m(this, "preset", "hair");
2589
+ m(this, "quality", "medium");
2590
+ m(this, "status", "loading");
2591
+ m(this, "error", null);
2592
+ m(this, "processingTime", null);
2593
+ m(this, "sourceCanvas");
2594
+ m(this, "processCanvas");
2595
+ m(this, "isProcessing", !1);
2596
+ m(this, "mask", Ti(1, 1, ["bg"]));
2597
+ m(this, "node");
2598
+ this.node = {
2599
+ getMask: () => this.mask,
2600
+ getStatus: () => this.status,
2601
+ getError: () => this.error
2602
+ };
2603
+ }
2604
+ async initialize(t) {
2605
+ this.preset = (t == null ? void 0 : t.preset) ?? "hair", this.quality = (t == null ? void 0 : t.quality) ?? "medium";
2606
+ const n = Pt[this.preset];
2607
+ this.mask.labels = n.labels, this.status = "loading", this.error = null;
2608
+ try {
2609
+ const i = await $.forVisionTasks(
2610
+ new URL("/assets/xr/wasm", q.assetStorageEndpoint).toString()
2611
+ ), r = (t == null ? void 0 : t.modelUrl) ?? n.defaultUrl, [a] = await Promise.all([
2612
+ ee(r),
2613
+ te(i)
2614
+ ]);
2615
+ this.segmenter = await Nt.createFromOptions(i, {
2616
+ baseOptions: { modelAssetBuffer: a, delegate: "GPU" },
2617
+ outputCategoryMask: !0,
2618
+ outputConfidenceMasks: !1,
2619
+ runningMode: "VIDEO"
2620
+ }), this.status = "ready";
2621
+ } catch (i) {
2622
+ throw this.status = "error", this.error = i instanceof Error ? i : new Error(String(i)), this.error;
2623
+ }
2624
+ }
2625
+ async run({ sourceCanvas: t, targetFps: n }) {
2626
+ t && (this.setTargetFps(n ?? Ai), this.isProcessing = !1, this.rafId !== null && (cancelAnimationFrame(this.rafId), this.rafId = null), this.sourceCanvas = t, this.processCanvas = document.createElement("canvas"), this.isProcessing = !0, this.lastInferenceMs = 0, this.rafId = requestAnimationFrame(this.process.bind(this)));
2627
+ }
2628
+ process() {
2629
+ if (this.disposed || this.paused || !this.isProcessing) return;
2630
+ const { segmenter: t, sourceCanvas: n, processCanvas: i } = this;
2631
+ if (!t || !n || !i || !this.shouldRunInference()) {
2632
+ this.rafId = requestAnimationFrame(this.process.bind(this));
2633
+ return;
2634
+ }
2635
+ const r = performance.now(), a = Ii[this.quality], o = Math.max(1, Math.round(n.width * a)), d = Math.max(1, Math.round(n.height * a));
2636
+ (i.width !== o || i.height !== d) && (i.width = o, i.height = d);
2637
+ const l = i.getContext("2d");
2638
+ l && l.drawImage(n, 0, 0, o, d);
2639
+ try {
2640
+ const u = t.segmentForVideo(i, performance.now()).categoryMask;
2641
+ if (u) {
2642
+ const p = u.getAsUint8Array();
2643
+ (this.mask.width !== u.width || this.mask.height !== u.height) && (this.mask.width = u.width, this.mask.height = u.height), this.mask.indices = Ri(
2644
+ p,
2645
+ Pt[this.preset].decode,
2646
+ this.mask.indices
2647
+ ), this.mask.version += 1, this.mask.timestampMs = r, u.close();
2648
+ }
2649
+ this.status === "error" && (this.status = "ready", this.error = null), this.recordInferenceError(null), this.recordDetections(u ? 1 : 0, null);
2650
+ } catch (h) {
2651
+ this.status = "error", this.error = h instanceof Error ? h : new Error(String(h)), this.recordInferenceError(this.error);
2652
+ }
2653
+ this.processingTime = performance.now() - r, this.recordInference(r), !(this.disposed || this.paused) && (this.rafId = requestAnimationFrame(this.process.bind(this)));
2654
+ }
2655
+ resume() {
2656
+ this.paused && (super.resume(), this.isProcessing && (this.rafId = requestAnimationFrame(this.process.bind(this))));
2657
+ }
2658
+ getModelNode() {
2659
+ return this.node;
2660
+ }
2661
+ async getPerformanceData() {
2662
+ return { name: this.constructor.name, processingTime: this.processingTime };
2663
+ }
2664
+ dispose() {
2665
+ var t;
2666
+ super.dispose(), this.isProcessing = !1;
2667
+ try {
2668
+ (t = this.segmenter) == null || t.close();
2669
+ } catch {
2670
+ }
2671
+ this.segmenter = null, this.sourceCanvas = void 0, this.processCanvas = void 0;
2672
+ }
2673
+ }
2674
+ const _t = {
2675
+ [P.BACKGROUND_SEGMENTATION]: Ci,
2676
+ [P.SEMANTIC_SEGMENTATION]: Fi,
2677
+ [P.HAND_TRACKER]: Si,
2678
+ [P.GESTURE_TRACKER]: oi,
2679
+ [P.FACE_TRACKER]: si,
2680
+ [P.BODY_TRACKER]: Yn,
2681
+ [P.HOLISTIC_TRACKER]: ci
2682
+ }, Pi = async (e) => {
2683
+ const s = document.createElement("video");
2684
+ s.srcObject = e, s.muted = !0, s.playsInline = !0, s.autoplay = !0, await new Promise((n) => {
2685
+ s.onloadedmetadata = () => {
2686
+ s.play(), n();
2687
+ };
2688
+ });
2689
+ const t = s;
2690
+ return await new Promise((n) => {
2691
+ const i = setTimeout(n, 150), r = () => {
2692
+ clearTimeout(i), n();
2693
+ };
2694
+ typeof t.requestVideoFrameCallback == "function" ? t.requestVideoFrameCallback(r) : requestAnimationFrame(() => requestAnimationFrame(() => r()));
2695
+ }), s;
2696
+ }, _i = (e) => {
2697
+ const s = new Ht(e);
2698
+ return s.colorSpace = Xs, s.format = Bt, s.minFilter = Ie, s.magFilter = Ie, s.generateMipmaps = !1, s.needsUpdate = !0, s;
2699
+ }, Di = (e, s) => {
2700
+ const t = e.videoWidth, n = e.videoHeight;
2701
+ t > 0 && n > 0 && (s.width !== t && (s.width = t), s.height !== n && (s.height = n));
2702
+ const i = s.getContext("2d", {
2703
+ colorSpace: "srgb"
2704
+ });
2705
+ i.save(), i.scale(-1, 1), i.drawImage(e, -s.width, 0, s.width, s.height), i.restore();
2706
+ }, Oi = (e, s, t = 1) => {
2707
+ const n = s.getContext("2d", {
2708
+ colorSpace: "srgb"
2709
+ }), i = vn({
2710
+ source: { width: e.width, height: e.height },
2711
+ feed: { width: s.width, height: s.height },
2712
+ zoom: t
2713
+ });
2714
+ i && (n.setTransform(1, 0, 0, 1, 0, 0), n.clearRect(0, 0, s.width, s.height), n.drawImage(
2715
+ e,
2716
+ 0,
2717
+ 0,
2718
+ e.width,
2719
+ e.height,
2720
+ i.offsetX,
2721
+ i.offsetY,
2722
+ i.drawWidth,
2723
+ i.drawHeight
2724
+ ));
2725
+ }, Li = (e, s, t) => {
2726
+ const n = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new WeakSet();
2727
+ let r = !1;
2728
+ const a = (w, g) => {
2729
+ const y = e.getSnapshot().modelErrors;
2730
+ if (g === null && !y.has(w)) return;
2731
+ const v = new Map(y);
2732
+ g === null ? v.delete(w) : v.set(w, { model: w, error: g, at: performance.now() }), e.set({ modelErrors: v });
2733
+ }, o = (w, g) => {
2734
+ var y;
2735
+ try {
2736
+ (y = g.dispose) == null || y.call(g);
2737
+ } catch (v) {
2738
+ console.warn(`[xr-sdk registry] dispose threw for ${w}`, v);
2739
+ }
2740
+ };
2741
+ return {
2742
+ acquire: async (w, g, y) => {
2743
+ let v = n.get(w);
2744
+ if (v)
2745
+ return v.refs.add(g), v.activeRefs.add(g), v.initPromise;
2746
+ const A = s[w];
2747
+ if (!A)
2748
+ throw new Error(`Invalid model: ${w}`);
2749
+ const E = new A(), B = /* @__PURE__ */ new Set([g]), K = /* @__PURE__ */ new Set([g]);
2750
+ a(w, null);
2751
+ const L = (async () => {
2752
+ await E.initialize(y);
2753
+ const F = n.get(w);
2754
+ if (!F || F.model !== E || F.refs.size === 0)
2755
+ return o(w, E), E;
2756
+ t && await t(w, E);
2757
+ const G = n.get(w);
2758
+ return G && G.refs.size > 0 && (i.add(E), e.setPipeline((X) => X.set(w, E))), E;
2759
+ })();
2760
+ return v = { model: E, refs: B, activeRefs: K, initPromise: L, options: y }, n.set(w, v), L.catch((F) => {
2761
+ n.get(w) === v && (n.delete(w), e.setPipeline((X) => X.delete(w)), a(w, F instanceof Error ? F : new Error(String(F)))), o(w, E);
2762
+ }), L;
2763
+ },
2764
+ release: (w, g) => {
2765
+ const y = n.get(w);
2766
+ y && (y.refs.delete(g), y.activeRefs.delete(g) && y.refs.size > 0 && y.activeRefs.size === 0 && y.model.pause(), !(y.refs.size > 0) && (n.delete(w), o(w, y.model), e.setPipeline((v) => v.delete(w))));
2767
+ },
2768
+ setActive: (w, g, y) => {
2769
+ const v = n.get(w);
2770
+ if (!v || !v.refs.has(g)) return;
2771
+ const A = v.activeRefs.size > 0;
2772
+ y ? v.activeRefs.add(g) : v.activeRefs.delete(g);
2773
+ const E = v.activeRefs.size > 0;
2774
+ A !== E && (E && !r ? v.model.resume() : v.model.pause());
2775
+ },
2776
+ suspendAll: () => {
2777
+ r = !0;
2778
+ for (const w of n.values())
2779
+ w.model.pause();
2780
+ },
2781
+ resumeActive: () => {
2782
+ r = !1;
2783
+ for (const w of n.values())
2784
+ w.activeRefs.size > 0 && w.model.resume();
2785
+ },
2786
+ get: (w) => {
2787
+ var g;
2788
+ return (g = n.get(w)) == null ? void 0 : g.model;
2789
+ },
2790
+ getOptions: (w) => {
2791
+ var g;
2792
+ return (g = n.get(w)) == null ? void 0 : g.options;
2793
+ },
2794
+ releaseAll: () => {
2795
+ for (const w of Array.from(n.keys())) {
2796
+ const g = n.get(w);
2797
+ g && (g.refs.clear(), n.delete(w), o(w, g.model));
2798
+ }
2799
+ e.setPipeline((w) => w.clear());
2800
+ },
2801
+ getState: (w) => {
2802
+ const g = n.get(w);
2803
+ return g ? i.has(g.model) ? "ready" : "initializing" : e.getSnapshot().modelErrors.has(w) ? "error" : "idle";
2804
+ },
2805
+ getOwners: (w) => {
2806
+ const g = n.get(w);
2807
+ return {
2808
+ refs: g ? Array.from(g.refs) : [],
2809
+ active: g ? Array.from(g.activeRefs) : []
2810
+ };
2811
+ }
2812
+ };
2813
+ }, Ni = {
2814
+ lifecycle: "idle",
2815
+ ready: !1,
2816
+ error: void 0,
2817
+ cameraTexture: void 0,
2818
+ renderWidth: 0,
2819
+ renderHeight: 0,
2820
+ source: void 0,
2821
+ sourceKind: void 0,
2822
+ cameraFacing: null,
2823
+ cameraDeviceId: null,
2824
+ orientation: { type: "portrait", angle: 0 },
2825
+ quality: null,
2826
+ qualityConfig: null,
2827
+ sourceWidth: 0,
2828
+ sourceHeight: 0,
2829
+ cameraZoom: 1.2,
2830
+ pipeline: /* @__PURE__ */ new Map(),
2831
+ modelErrors: /* @__PURE__ */ new Map(),
2832
+ cameraPermission: "unknown",
2833
+ cameraPermissionReason: null,
2834
+ feedFrames: 0
2835
+ }, Bi = () => {
2836
+ let e = { ...Ni, pipeline: /* @__PURE__ */ new Map(), modelErrors: /* @__PURE__ */ new Map() };
2837
+ const s = /* @__PURE__ */ new Set(), t = () => {
2838
+ s.forEach((n) => n());
2839
+ };
2840
+ return {
2841
+ getSnapshot: () => e,
2842
+ set: (n) => {
2843
+ let i = !1;
2844
+ for (const r of Object.keys(n))
2845
+ if (n[r] !== e[r]) {
2846
+ i = !0;
2847
+ break;
2848
+ }
2849
+ i && (e = { ...e, ...n }, t());
2850
+ },
2851
+ setPipeline: (n) => {
2852
+ const i = new Map(e.pipeline);
2853
+ return n(i), e = { ...e, pipeline: i }, t(), i;
2854
+ },
2855
+ subscribe: (n) => (s.add(n), () => {
2856
+ s.delete(n);
2857
+ })
2858
+ };
2859
+ }, Dt = (e, s) => s ?? e === "user", Hi = ({
2860
+ renderHeight: e,
2861
+ renderWidth: s,
2862
+ videoHeight: t,
2863
+ videoWidth: n
2864
+ }) => ({
2865
+ height: e || t,
2866
+ width: s || n
2867
+ }), Ui = (e, s) => {
2868
+ const t = new Sn({ verbose: !0 }), n = Bi();
2869
+ n.set({ cameraZoom: (e == null ? void 0 : e.cameraZoom) ?? 1.2 });
2870
+ let i = s, r = e;
2871
+ const a = (c) => {
2872
+ var S;
2873
+ const f = (S = V.getOptions(c)) == null ? void 0 : S.targetFps;
2874
+ return typeof f == "number" ? f : r == null ? void 0 : r.targetFps;
2875
+ };
2876
+ let o, d, l, h, u, p, M, x, b, T, R, w, g = !1, y = !1, v = !1, A = 0, E, B, K, L = !1, F = 0, G = /* @__PURE__ */ new WeakSet();
2877
+ const X = /* @__PURE__ */ new Set(), be = (c) => {
2878
+ const f = n.getSnapshot().cameraTexture;
2879
+ f && f.dispose();
2880
+ const S = _i(c);
2881
+ return n.set({ cameraTexture: S }), S;
2882
+ }, Pe = async (c, f) => {
2883
+ if (G.has(f) || n.getSnapshot().lifecycle !== "running" || !u) return;
2884
+ G.add(f);
2885
+ const S = F;
2886
+ try {
2887
+ await f.run({
2888
+ sourceCanvas: u,
2889
+ renderWidth: n.getSnapshot().renderWidth,
2890
+ renderHeight: n.getSnapshot().renderHeight,
2891
+ getSource: () => n.getSnapshot().sourceKind,
2892
+ targetFps: a(c),
2893
+ analysisScale: r == null ? void 0 : r.analysisScale
2894
+ }), L && (await new Promise((k) => requestAnimationFrame(() => k())), await new Promise((k) => requestAnimationFrame(() => k())), L && F === S && V.suspendAll());
2895
+ } catch (k) {
2896
+ throw G.delete(f), k;
2897
+ }
2898
+ }, V = Li(n, _t, (c, f) => Pe(c, f));
2899
+ n.subscribe(() => {
2900
+ if (n.getSnapshot().lifecycle !== "running") return;
2901
+ const c = n.getSnapshot().pipeline;
2902
+ for (const [f, S] of c.entries())
2903
+ G.has(S) || Pe(f, S);
2904
+ });
2905
+ const rt = () => {
2906
+ w !== void 0 && (cancelAnimationFrame(w), w = void 0);
2907
+ }, ne = () => {
2908
+ if (rt(), E == null || E(), E = void 0, d) {
2909
+ try {
2910
+ d.pause();
2911
+ } catch {
2912
+ }
2913
+ try {
2914
+ d.srcObject = null;
2915
+ } catch {
2916
+ }
2917
+ d = void 0;
2918
+ }
2919
+ if (l) {
2920
+ try {
2921
+ l.getTracks().forEach((c) => c.stop());
2922
+ } catch {
2923
+ }
2924
+ l = void 0;
2925
+ }
2926
+ }, _e = () => {
2927
+ if (g || !d || !h || !u) return;
2928
+ const c = typeof window < "u" ? window.__xr_debugger_metrics : void 0;
2929
+ if (c != null && c.trackCameraFrame && c.trackCameraFrame(), Se(n.getSnapshot().sourceKind))
2930
+ Di(d, h);
2931
+ else {
2932
+ const C = h.getContext("2d");
2933
+ if (!C) return;
2934
+ const D = d.videoWidth, N = d.videoHeight;
2935
+ h.width !== D && (h.width = D), h.height !== N && (h.height = N), C.setTransform(1, 0, 0, 1, 0, 0), C.clearRect(0, 0, D, N), C.drawImage(d, 0, 0, D, N);
2936
+ }
2937
+ Oi(h, u, (r == null ? void 0 : r.cameraZoom) ?? 1.2);
2938
+ const S = n.getSnapshot();
2939
+ (S.sourceWidth !== d.videoWidth || S.sourceHeight !== d.videoHeight) && n.set({ sourceWidth: d.videoWidth, sourceHeight: d.videoHeight }), A += 1, A % 10 === 0 && n.set({ feedFrames: A });
2940
+ const k = n.getSnapshot().cameraTexture;
2941
+ k && (k.needsUpdate = !0);
2942
+ }, De = () => {
2943
+ if (!d || !h || !u) return;
2944
+ if (L) {
2945
+ _e();
2946
+ return;
2947
+ }
2948
+ const c = () => {
2949
+ w = requestAnimationFrame(c), _e();
2950
+ };
2951
+ w = requestAnimationFrame(c);
2952
+ }, is = async (c, f) => {
2953
+ if (c.source === I.WEBCAM)
2954
+ try {
2955
+ const S = r != null && r.camRes && r.camRes > 0 ? r.camRes : 960;
2956
+ n.set({ cameraPermission: "requesting", cameraPermissionReason: null });
2957
+ const k = c.deviceId ? { deviceId: { exact: c.deviceId } } : { facingMode: { ideal: c.facingMode ?? "user" } }, C = {
2958
+ frameRate: { min: 24, ideal: 30, max: 60 },
2959
+ width: { ideal: S },
2960
+ ...k
2961
+ };
2962
+ let D;
2963
+ try {
2964
+ D = await navigator.mediaDevices.getUserMedia({ video: C });
2965
+ } catch (N) {
2966
+ if (!(N instanceof DOMException && N.name === "OverconstrainedError")) throw N;
2967
+ D = await navigator.mediaDevices.getUserMedia({
2968
+ video: { frameRate: { ideal: 30 }, width: { ideal: S }, ...k }
2969
+ });
2970
+ }
2971
+ return f === F && n.set({ cameraPermission: "granted", cameraPermissionReason: null }), D;
2972
+ } catch (S) {
2973
+ const k = Vt(S), C = kt[k], D = await Kt(), N = Gt(k, D.state);
2974
+ throw f === F && n.set({
2975
+ error: { error: "PermissionError", message: C, reason: k },
2976
+ cameraPermission: N.state,
2977
+ cameraPermissionReason: N.reason
2978
+ }), new O(S instanceof Error ? S.message : "getUserMedia failed");
2979
+ }
2980
+ return c.stream;
2981
+ }, at = (c) => {
2982
+ const { lifecycle: f } = n.getSnapshot();
2983
+ f === "idle" || f === "stopped" || g || (ne(), V.suspendAll(), F += 1, o = void 0, n.set({
2984
+ lifecycle: "stopped",
2985
+ ready: !1,
2986
+ error: { error: "PermissionError", message: kt[c], reason: c },
2987
+ cameraPermission: c === "permission-denied" ? "blocked" : "unavailable",
2988
+ cameraPermissionReason: qt(c)
2989
+ }), t.log("XR session stopped: camera lost.", c));
2990
+ }, rs = (c) => {
2991
+ var k;
2992
+ E == null || E();
2993
+ const f = ((k = c.getVideoTracks) == null ? void 0 : k.call(c)) ?? [], S = () => {
2994
+ l === c && at("camera-lost");
2995
+ };
2996
+ f.forEach((C) => {
2997
+ var D;
2998
+ return (D = C.addEventListener) == null ? void 0 : D.call(C, "ended", S);
2999
+ }), E = () => {
3000
+ f.forEach((C) => {
3001
+ var D;
3002
+ return (D = C.removeEventListener) == null ? void 0 : D.call(C, "ended", S);
3003
+ });
3004
+ };
3005
+ }, as = async () => {
3006
+ if (B || typeof navigator > "u") return;
3007
+ const c = navigator.permissions;
3008
+ if (c != null && c.query)
3009
+ try {
3010
+ const f = await c.query({ name: "camera" });
3011
+ if (y) return;
3012
+ B = f, K = () => {
3013
+ f.state === "denied" && (o == null ? void 0 : o.source) === I.WEBCAM && at("permission-denied");
3014
+ }, f.addEventListener("change", K);
3015
+ } catch {
3016
+ }
3017
+ }, os = () => {
3018
+ var c;
3019
+ B && K && ((c = B.removeEventListener) == null || c.call(B, "change", K)), B = void 0, K = void 0;
3020
+ }, Oe = async (c) => {
3021
+ var yt, ke, wt;
3022
+ const f = F, S = await is(c, f);
3023
+ if (f !== F)
3024
+ throw S.getTracks().forEach((oe) => oe.stop()), new O("Media source superseded by a newer bind");
3025
+ l = S, rs(S);
3026
+ const k = await Pi(S);
3027
+ if (f !== F || y)
3028
+ throw S.getTracks().forEach((oe) => oe.stop()), new O("Media source superseded by a newer bind");
3029
+ d = k, h = new OffscreenCanvas(k.videoWidth, k.videoHeight);
3030
+ const { renderWidth: C, renderHeight: D } = n.getSnapshot(), N = Hi({
3031
+ renderWidth: C,
3032
+ renderHeight: D,
3033
+ videoWidth: k.videoWidth,
3034
+ videoHeight: k.videoHeight
3035
+ });
3036
+ u ? (u.width !== N.width || u.height !== N.height) && (u.width = N.width, u.height = N.height, be(u)) : (u = new OffscreenCanvas(N.width, N.height), be(u));
3037
+ const pt = c.source === I.STREAM ? c.static === !0 : !1;
3038
+ L = pt;
3039
+ const ae = (wt = (ke = (yt = S.getVideoTracks) == null ? void 0 : yt.call(S)[0]) == null ? void 0 : ke.getSettings) == null ? void 0 : wt.call(ke), Ue = ae == null ? void 0 : ae.facingMode, Fs = Ue === "user" || Ue === "environment" ? Ue : null;
3040
+ if (c.source === I.WEBCAM) {
3041
+ const oe = Fs ?? c.facingMode ?? "user", vt = Dt(oe, c.mirrored);
3042
+ o = {
3043
+ source: I.WEBCAM,
3044
+ sourceKind: vt ? "webcam" : "rear-camera",
3045
+ facingMode: oe,
3046
+ deviceId: c.deviceId,
3047
+ mirrored: vt
3048
+ };
3049
+ } else
3050
+ o = {
3051
+ source: I.STREAM,
3052
+ stream: c.stream,
3053
+ static: pt,
3054
+ sourceKind: c.sourceKind ?? "webcam"
3055
+ };
3056
+ n.set({
3057
+ source: c.source,
3058
+ sourceKind: o.sourceKind,
3059
+ cameraFacing: o.source === I.WEBCAM ? o.facingMode : null,
3060
+ cameraDeviceId: o.source === I.WEBCAM ? (ae == null ? void 0 : ae.deviceId) ?? o.deviceId ?? null : null,
3061
+ sourceWidth: k.videoWidth,
3062
+ sourceHeight: k.videoHeight,
3063
+ error: void 0
3064
+ }), c.source === I.WEBCAM && as();
3065
+ }, Le = async (c) => {
3066
+ const f = c.sourceKind ?? "webcam";
3067
+ u = c.canvas;
3068
+ const S = be(u);
3069
+ n.set({
3070
+ cameraTexture: S,
3071
+ source: I.CANVAS,
3072
+ sourceKind: f,
3073
+ cameraFacing: null,
3074
+ cameraDeviceId: null,
3075
+ renderWidth: u.width,
3076
+ renderHeight: u.height,
3077
+ error: void 0
3078
+ }), o = {
3079
+ source: I.CANVAS,
3080
+ canvas: c.canvas,
3081
+ sourceKind: f
3082
+ };
3083
+ }, cs = (c, f) => {
3084
+ if (!f || c.source !== f.source) return !1;
3085
+ if (c.source === I.STREAM && f.source === I.STREAM)
3086
+ return c.stream === f.stream && (c.sourceKind ?? "webcam") === f.sourceKind;
3087
+ if (c.source === I.WEBCAM && f.source === I.WEBCAM) {
3088
+ const S = c.facingMode ?? "user";
3089
+ return S === f.facingMode && c.deviceId === f.deviceId && Dt(S, c.mirrored) === f.mirrored;
3090
+ }
3091
+ return !1;
3092
+ }, ot = async () => {
3093
+ if (!u) return;
3094
+ const c = F, f = n.getSnapshot().pipeline;
3095
+ for (const [, S] of f.entries())
3096
+ S.resume();
3097
+ await new Promise((S) => requestAnimationFrame(() => S())), await new Promise((S) => requestAnimationFrame(() => S())), L && F === c && V.suspendAll();
3098
+ }, ls = (c, f) => !f || f.source !== I.CANVAS ? !1 : c.canvas === f.canvas && (c.sourceKind ?? "webcam") === f.sourceKind, Ne = async (c) => {
3099
+ const f = c.source;
3100
+ if (f !== I.WEBCAM && f !== I.STREAM)
3101
+ throw new O(`Invalid media source: ${String(f)}`);
3102
+ if (y) throw new O("session.setMediaSource() called after the provider unmounted");
3103
+ if (cs(c, o)) {
3104
+ t.log("Media source unchanged, skipping rebind.");
3105
+ return;
3106
+ }
3107
+ F += 1;
3108
+ const { lifecycle: S } = n.getSnapshot();
3109
+ if (S === "idle" || S === "stopped") {
3110
+ await Oe(c), n.set({ lifecycle: "media-bound" }), t.log("Media source set to:", c.source);
3111
+ return;
3112
+ }
3113
+ if (S === "media-bound") {
3114
+ ne(), await Oe(c), t.log("Media source rebound to:", c.source);
3115
+ return;
3116
+ }
3117
+ const k = S === "paused";
3118
+ g = !0, await new Promise((C) => requestAnimationFrame(() => C())), ne();
3119
+ try {
3120
+ await Oe(c);
3121
+ } finally {
3122
+ g = !1;
3123
+ }
3124
+ if (k) {
3125
+ d == null || d.pause(), t.log("Media source swapped (paused) to:", c.source);
3126
+ return;
3127
+ }
3128
+ De(), L ? await ot() : V.resumeActive(), t.log("Media source swapped to:", c.source);
3129
+ }, ds = async (c) => {
3130
+ if (y) throw new O("session.setFrameSource() called after the provider unmounted");
3131
+ if (ls(c, o)) {
3132
+ t.log("Frame source unchanged, skipping rebind.");
3133
+ return;
3134
+ }
3135
+ F += 1;
3136
+ const { lifecycle: f } = n.getSnapshot();
3137
+ if (f === "idle" || f === "stopped") {
3138
+ await Le(c), n.set({ lifecycle: "media-bound" }), t.log("Frame source set to canvas.");
3139
+ return;
3140
+ }
3141
+ if (f === "media-bound") {
3142
+ ne(), await Le(c), t.log("Frame source rebound to canvas.");
3143
+ return;
3144
+ }
3145
+ g = !0, await new Promise((S) => requestAnimationFrame(() => S())), ne();
3146
+ try {
3147
+ await Le(c);
3148
+ } finally {
3149
+ g = !1;
3150
+ }
3151
+ t.log("Frame source swapped to canvas.");
3152
+ }, ct = async () => {
3153
+ if (y) throw new O("session.start() called after the provider unmounted");
3154
+ const { lifecycle: c } = n.getSnapshot();
3155
+ if (c === "running") return;
3156
+ if (c === "paused") {
3157
+ await Be();
3158
+ return;
3159
+ }
3160
+ if (c === "idle")
3161
+ throw new O("session.start() called before setMediaSource — call setMediaSource first");
3162
+ if (!u)
3163
+ throw new O("session.start(): media source not bound");
3164
+ const f = (o == null ? void 0 : o.source) === I.CANVAS;
3165
+ if (!f && (!d || !h))
3166
+ throw c === "stopped" ? new O(
3167
+ "session.start() called from stopped state without a media source — call setMediaSource first"
3168
+ ) : new O("session.start(): media source not bound");
3169
+ f || De(), V.resumeActive(), n.set({ lifecycle: "running" }), await new Promise((k) => requestAnimationFrame(() => k()));
3170
+ const S = n.getSnapshot().pipeline;
3171
+ for (const [k, C] of S.entries())
3172
+ await Pe(k, C);
3173
+ n.set({ ready: !0 }), t.log("XR session started.");
3174
+ }, lt = () => {
3175
+ if (n.getSnapshot().lifecycle === "running") {
3176
+ rt(), V.suspendAll();
3177
+ try {
3178
+ d == null || d.pause();
3179
+ } catch {
3180
+ }
3181
+ n.set({ lifecycle: "paused" }), t.log("XR session paused.");
3182
+ }
3183
+ }, Be = async () => {
3184
+ if (y) throw new O("session.resume() called after the provider unmounted");
3185
+ n.getSnapshot().lifecycle === "paused" && (v = !1, d && d.play().catch(() => {
3186
+ }), (o == null ? void 0 : o.source) !== I.CANVAS && De(), n.set({ lifecycle: "running" }), L ? await ot() : V.resumeActive(), t.log("XR session resumed."));
3187
+ }, hs = async (c = {}) => {
3188
+ await Ne({ source: I.WEBCAM, ...c });
3189
+ const { lifecycle: f } = n.getSnapshot();
3190
+ return (f === "media-bound" || f === "stopped") && await ct(), n.getSnapshot().cameraFacing ?? c.facingMode ?? "user";
3191
+ }, dt = async () => {
3192
+ const { lifecycle: c } = n.getSnapshot();
3193
+ c === "stopped" || c === "idle" || (v = !1, ne(), V.suspendAll(), o = void 0, n.set({ lifecycle: "stopped", ready: !1 }), t.log("XR session stopped."));
3194
+ }, ht = async () => {
3195
+ await dt(), V.releaseAll(), X.clear();
3196
+ const c = n.getSnapshot().cameraTexture;
3197
+ c && c.dispose(), G = /* @__PURE__ */ new WeakSet(), o = void 0, F += 1, u = void 0, h = void 0, M = void 0, L = !1, os(), n.set({
3198
+ lifecycle: "idle",
3199
+ cameraTexture: void 0,
3200
+ source: void 0,
3201
+ sourceKind: void 0,
3202
+ cameraFacing: null,
3203
+ cameraDeviceId: null,
3204
+ error: void 0,
3205
+ modelErrors: /* @__PURE__ */ new Map(),
3206
+ cameraPermission: "unknown",
3207
+ cameraPermissionReason: null
3208
+ }), t.log("XR session reset.");
3209
+ }, us = async () => {
3210
+ y || (y = !0, re == null || re(), re = void 0, ie == null || ie(), ie = void 0, await ht(), t.log("XR session disposed."));
3211
+ }, ms = () => {
3212
+ y && (y = !1, gt(), ft(), t.log("XR session re-armed."));
3213
+ }, fs = () => y, gs = async (c) => {
3214
+ const f = "legacy:registerXRPipeline", S = [];
3215
+ await Promise.all(
3216
+ c.map(async (k) => {
3217
+ const { model: C } = k;
3218
+ if (!_t[C])
3219
+ throw new O(`Invalid model: ${C}`);
3220
+ X.has(C) || S.push(C);
3221
+ const D = "options" in k ? k.options : void 0;
3222
+ await V.acquire(C, f, D);
3223
+ })
3224
+ ), S.length > 0 && (S.forEach((k) => X.add(k)), t.log("XR pipeline registered."));
3225
+ }, ps = (c) => {
3226
+ const f = V.get(c);
3227
+ if (!f)
3228
+ throw new O(`Model ${c} is not registered in the pipeline`);
3229
+ return f.getModelNode();
3230
+ }, ut = async (c, f) => {
3231
+ c <= 0 || f <= 0 || (n.set({ renderWidth: c, renderHeight: f }), u && (u.width !== c || u.height !== f) && (u.width = c, u.height = f, be(u), L && _e()), t.log(`Source canvas set. Render size: ${c}x${f}`));
3232
+ }, ys = async (c) => {
3233
+ var C;
3234
+ p = c;
3235
+ const f = (C = c.getBoundingClientRect) == null ? void 0 : C.call(c), S = f && f.width > 0 ? Math.round(f.width) : c.clientWidth, k = f && f.height > 0 ? Math.round(f.height) : c.clientHeight;
3236
+ await ut(S, k);
3237
+ }, ws = (c) => {
3238
+ M = c;
3239
+ }, He = () => p && x && b && T ? p : M, vs = (c) => {
3240
+ x = c.renderer, b = c.scene, T = c.camera, R = c.renderFrame;
3241
+ }, mt = () => {
3242
+ if (!x || !b || !T)
3243
+ throw new O(
3244
+ "XR frame render requested before the R3F state was bound — make sure <XRScene> is mounted"
3245
+ );
3246
+ R ? R() : x.render(b, T);
3247
+ }, xs = () => {
3248
+ const c = p;
3249
+ if (c && He() === c)
3250
+ return mt(), c.toDataURL("image/png");
3251
+ const f = He();
3252
+ if (f) return f.toDataURL("image/png");
3253
+ throw new O(
3254
+ "session.captureFrame() called before an XRScene or XRMediaSurface capture target was bound"
3255
+ );
3256
+ }, Ss = (c = 30) => {
3257
+ const f = He();
3258
+ if (!(f != null && f.captureStream))
3259
+ throw new O(
3260
+ "session.captureStream() called before an XRScene or XRMediaSurface capture target was bound"
3261
+ );
3262
+ return f.captureStream(c);
3263
+ }, Ms = () => d, bs = () => u ?? null, ks = (c) => {
3264
+ if (r = c, n.set({ cameraZoom: (c == null ? void 0 : c.cameraZoom) ?? 1.2 }), n.getSnapshot().lifecycle !== "running" || !u) return;
3265
+ const f = n.getSnapshot().pipeline;
3266
+ for (const [S, k] of f.entries())
3267
+ k.run({
3268
+ sourceCanvas: u,
3269
+ renderWidth: n.getSnapshot().renderWidth,
3270
+ renderHeight: n.getSnapshot().renderHeight,
3271
+ getSource: () => n.getSnapshot().sourceKind,
3272
+ targetFps: a(S),
3273
+ analysisScale: r == null ? void 0 : r.analysisScale
3274
+ });
3275
+ }, Cs = () => r, Ts = async () => {
3276
+ if (!o || o.source !== I.WEBCAM) return;
3277
+ const { facingMode: c, deviceId: f, mirrored: S } = o;
3278
+ o = void 0, await Ne({ source: I.WEBCAM, facingMode: c, deviceId: f, mirrored: S });
3279
+ }, Es = (c) => {
3280
+ n.set({ quality: c });
3281
+ }, Rs = (c) => {
3282
+ n.set({ qualityConfig: c });
3283
+ }, As = (c) => {
3284
+ i = c;
3285
+ }, Is = () => {
3286
+ var C;
3287
+ if (typeof window > "u") return { type: "portrait", angle: 0 };
3288
+ const c = (C = window.screen) == null ? void 0 : C.orientation, f = (c == null ? void 0 : c.angle) ?? 0, S = f === 90 || f === 180 || f === 270 ? f : 0;
3289
+ return { type: c != null && c.type ? c.type.startsWith("landscape") ? "landscape" : "portrait" : window.innerWidth > window.innerHeight ? "landscape" : "portrait", angle: S };
3290
+ }, fe = () => {
3291
+ const c = Is(), f = n.getSnapshot().orientation, S = f.type !== c.type || f.angle !== c.angle ? { orientation: c } : {};
3292
+ d && d.videoWidth > 0 && (S.sourceWidth = d.videoWidth, S.sourceHeight = d.videoHeight), Object.keys(S).length && n.set(S);
3293
+ };
3294
+ let ie;
3295
+ const ft = () => {
3296
+ var f, S, k;
3297
+ if (ie || typeof window > "u") return;
3298
+ const c = (f = window.screen) == null ? void 0 : f.orientation;
3299
+ (S = c == null ? void 0 : c.addEventListener) == null || S.call(c, "change", fe), (k = window.addEventListener) == null || k.call(window, "resize", fe), ie = () => {
3300
+ var C, D;
3301
+ (C = c == null ? void 0 : c.removeEventListener) == null || C.call(c, "change", fe), (D = window.removeEventListener) == null || D.call(window, "resize", fe);
3302
+ }, fe();
3303
+ };
3304
+ let re;
3305
+ const gt = () => {
3306
+ if (re || typeof document > "u" || typeof document.addEventListener != "function") return;
3307
+ const c = () => {
3308
+ if (!y) {
3309
+ if (document.hidden) {
3310
+ i != null && i.pauseWhenHidden && n.getSnapshot().lifecycle === "running" && (lt(), v = !0);
3311
+ return;
3312
+ }
3313
+ if (v && n.getSnapshot().lifecycle === "paused") {
3314
+ Be();
3315
+ return;
3316
+ }
3317
+ n.getSnapshot().lifecycle === "running" && (d != null && d.paused) && d.play().catch(() => {
3318
+ });
3319
+ }
3320
+ };
3321
+ document.addEventListener("visibilitychange", c), re = () => document.removeEventListener("visibilitychange", c);
3322
+ };
3323
+ return gt(), ft(), {
3324
+ store: n,
3325
+ registry: V,
3326
+ setMediaSource: Ne,
3327
+ start: ct,
3328
+ stop: dt,
3329
+ reset: ht,
3330
+ pause: lt,
3331
+ resume: Be,
3332
+ switchCamera: hs,
3333
+ dispose: us,
3334
+ rearm: ms,
3335
+ isDisposed: fs,
3336
+ setFrameSource: ds,
3337
+ registerXRPipeline: gs,
3338
+ getModelNode: ps,
3339
+ captureFrame: xs,
3340
+ captureStream: Ss,
3341
+ getInputFrame: bs,
3342
+ _setRenderTarget: ys,
3343
+ _setCaptureTarget: ws,
3344
+ _setRenderSize: ut,
3345
+ _setR3FState: vs,
3346
+ _renderFrame: mt,
3347
+ _getVideoElement: Ms,
3348
+ _setPerf: ks,
3349
+ _setLifecycle: As,
3350
+ _rebindMedia: Ts,
3351
+ _setQuality: Es,
3352
+ _setQualityConfig: Rs,
3353
+ _getPerf: Cs
3354
+ };
3355
+ }, zi = (e, s) => {
3356
+ const t = ue(e), n = ue(s), i = xe(
3357
+ () => Ui(t.current, n.current),
3358
+ []
3359
+ ), r = JSON.stringify(s ?? {});
3360
+ de(() => {
3361
+ i._setLifecycle(s);
3362
+ }, [i, r]), de(() => (i.rearm(), () => void i.dispose()), [i]);
3363
+ const a = JSON.stringify(e ?? {});
3364
+ return de(() => {
3365
+ i._setPerf(e);
3366
+ }, [i, a]), i;
3367
+ }, Je = /* @__PURE__ */ new Map(), Wi = () => ({
3368
+ register: (e, s) => {
3369
+ s ? Je.set(e, s) : Je.delete(e);
3370
+ },
3371
+ resolve: (e) => e ? Je.get(e) ?? null : null
3372
+ }), Zt = Wi(), $t = Lt(null), qi = ({ children: e }) => {
3373
+ const s = ue(/* @__PURE__ */ new Map()), t = St((r, a) => {
3374
+ a ? s.current.set(r, a) : s.current.delete(r);
3375
+ }, []), n = St(
3376
+ (r) => r ? s.current.get(r) ?? null : null,
3377
+ []
3378
+ ), i = xe(() => ({ register: t, resolve: n }), [t, n]);
3379
+ return Os($t.Provider, { value: i }, e);
3380
+ }, es = () => et($t) ?? Zt, ia = () => es().register, ra = () => es().resolve;
3381
+ Zt.register;
3382
+ const Vi = {
3383
+ [P.FACE_TRACKER]: "face",
3384
+ [P.HAND_TRACKER]: "hand",
3385
+ [P.GESTURE_TRACKER]: "gesture",
3386
+ [P.BODY_TRACKER]: "body",
3387
+ [P.HOLISTIC_TRACKER]: "holistic",
3388
+ [P.BACKGROUND_SEGMENTATION]: "segmentation",
3389
+ [P.SEMANTIC_SEGMENTATION]: "semantic-seg"
3390
+ }, Ot = Object.values(P), Ki = (e, s) => {
3391
+ var n;
3392
+ const t = (n = e.registry.getOptions(s)) == null ? void 0 : n.targetFps;
3393
+ return typeof t == "number" ? t : null;
3394
+ }, $e = (e, s, t, n = performance.now()) => {
3395
+ const i = e.store.getSnapshot(), r = t ? n - t.sampledAt : 0, a = t && r > 0 ? Math.max(0, (i.feedFrames - t.feedFrames) * 1e3 / r) : 0, o = i.lifecycle === "running", d = s.map((h) => {
3396
+ var T;
3397
+ const u = e.registry.getState(h), p = e.store.getSnapshot().pipeline.get(h), M = ((T = i.modelErrors.get(h)) == null ? void 0 : T.error) ?? null, x = (p == null ? void 0 : p.getDiagnostics()) ?? {
3398
+ inferenceMs: null,
3399
+ inferenceFps: 0,
3400
+ inferences: 0,
3401
+ skippedFrames: 0,
3402
+ detections: null,
3403
+ confidence: null,
3404
+ status: M ? "error" : "ready",
3405
+ error: M,
3406
+ paused: !1,
3407
+ disposed: !1
3408
+ };
3409
+ let b;
3410
+ return u === "error" || x.status === "error" ? b = "error" : u === "idle" ? b = "unavailable" : u === "initializing" ? b = "loading" : x.paused || !o ? b = "paused" : b = "ready", {
3411
+ ...x,
3412
+ error: x.error ?? M,
3413
+ model: h,
3414
+ label: Vi[h] ?? h,
3415
+ state: b,
3416
+ targetFps: Ki(e, h),
3417
+ owners: e.registry.getOwners(h)
3418
+ };
3419
+ }), l = i.quality;
3420
+ return {
3421
+ quality: l ? {
3422
+ tier: l.decision.tier.name,
3423
+ index: l.index,
3424
+ locked: l.locked,
3425
+ reason: l.decision.reason
3426
+ } : null,
3427
+ session: {
3428
+ lifecycle: i.lifecycle,
3429
+ ready: i.ready,
3430
+ error: i.error,
3431
+ source: i.source,
3432
+ sourceKind: i.sourceKind,
3433
+ sourceWidth: i.sourceWidth,
3434
+ sourceHeight: i.sourceHeight,
3435
+ renderWidth: i.renderWidth,
3436
+ renderHeight: i.renderHeight,
3437
+ feedFps: a,
3438
+ feedFrames: i.feedFrames
3439
+ },
3440
+ models: d,
3441
+ inferenceMsTotal: d.reduce(
3442
+ (h, u) => h + (u.state === "ready" ? u.inferenceMs ?? 0 : 0),
3443
+ 0
3444
+ ),
3445
+ sampledAt: n
3446
+ };
3447
+ }, aa = (e = {}) => {
3448
+ const { intervalMs: s = 250, enabled: t = !0 } = e, { session: n } = ns(), i = (e.models ?? Ot).join("|"), r = xe(
3449
+ () => e.models && e.models.length ? e.models : Ot,
3450
+ // modelsKey captures the list by value.
3451
+ // eslint-disable-next-line react-hooks/exhaustive-deps
3452
+ [i]
3453
+ ), a = ue(null), [o, d] = Ls(
3454
+ () => $e(n, r, null)
3455
+ );
3456
+ return de(() => {
3457
+ if (!t) return;
3458
+ const l = () => {
3459
+ const u = $e(n, r, a.current);
3460
+ a.current = { feedFrames: u.session.feedFrames, sampledAt: u.sampledAt }, d(u);
3461
+ };
3462
+ l();
3463
+ const h = window.setInterval(l, Math.max(50, s));
3464
+ return () => window.clearInterval(h);
3465
+ }, [n, r, s, t]), o;
3466
+ }, Gi = [
3467
+ { name: "high", targetFps: 30, renderScale: 1, analysisScale: 1, camRes: 960 },
3468
+ { name: "medium", targetFps: 24, renderScale: 0.8, analysisScale: 0.85, camRes: 720 },
3469
+ { name: "low", targetFps: 15, renderScale: 0.6, analysisScale: 0.7, camRes: 640 }
3470
+ ], Z = {
3471
+ maxFrameMs: 1e3 / 24,
3472
+ maxInferenceMs: 24,
3473
+ maxMemoryMb: null,
3474
+ sampleMs: 1e3,
3475
+ downgradeAfter: 2,
3476
+ upgradeAfter: 6,
3477
+ upgradeHeadroom: 0.75,
3478
+ cooldownMs: 4e3
3479
+ }, ts = {
3480
+ frameMs: null,
3481
+ fps: null,
3482
+ inferenceMs: null,
3483
+ feedFps: null,
3484
+ memoryMb: null,
3485
+ deviceMemoryGb: null,
3486
+ hardwareConcurrency: null,
3487
+ thermal: "unknown"
3488
+ }, ve = (e, s, t) => Math.min(t, Math.max(s, e)), H = (e, s) => typeof e == "number" && Number.isFinite(e) ? e : s, Xi = (e, s) => ({
3489
+ name: typeof e.name == "string" && e.name ? e.name : `tier-${s}`,
3490
+ ...H(e.targetFps, NaN) > 0 ? { targetFps: H(e.targetFps, 0) } : {},
3491
+ ...H(e.renderScale, NaN) > 0 ? { renderScale: ve(H(e.renderScale, 1), 0.25, 1) } : {},
3492
+ ...H(e.analysisScale, NaN) > 0 ? { analysisScale: ve(H(e.analysisScale, 1), 0.25, 1) } : {},
3493
+ ...H(e.camRes, NaN) > 0 ? { camRes: Math.round(H(e.camRes, 0)) } : {},
3494
+ ...e.rebindCamera ? { rebindCamera: !0 } : {}
3495
+ }), ji = (e = {}) => ({
3496
+ maxFrameMs: Math.max(1, H(e.maxFrameMs, Z.maxFrameMs)),
3497
+ maxInferenceMs: Math.max(
3498
+ 0,
3499
+ H(e.maxInferenceMs, Z.maxInferenceMs)
3500
+ ),
3501
+ maxMemoryMb: e.maxMemoryMb === null || e.maxMemoryMb === void 0 ? null : Math.max(1, H(e.maxMemoryMb, 0)) || null,
3502
+ sampleMs: Math.max(100, H(e.sampleMs, Z.sampleMs)),
3503
+ downgradeAfter: Math.max(
3504
+ 1,
3505
+ Math.round(H(e.downgradeAfter, Z.downgradeAfter))
3506
+ ),
3507
+ upgradeAfter: Math.max(
3508
+ 1,
3509
+ Math.round(H(e.upgradeAfter, Z.upgradeAfter))
3510
+ ),
3511
+ upgradeHeadroom: ve(
3512
+ H(e.upgradeHeadroom, Z.upgradeHeadroom),
3513
+ 0.1,
3514
+ 1
3515
+ ),
3516
+ cooldownMs: Math.max(0, H(e.cooldownMs, Z.cooldownMs))
3517
+ }), Q = (e, s, t) => {
3518
+ if (typeof s == "number" && Number.isInteger(s) && s >= 0 && s < e.length)
3519
+ return s;
3520
+ if (typeof s == "string") {
3521
+ const n = e.findIndex((i) => i.name === s);
3522
+ if (n >= 0) return n;
3523
+ }
3524
+ return t;
3525
+ }, Yi = (e = {}) => {
3526
+ const s = e.tiers && e.tiers.length ? e.tiers.map((i, r) => Xi(i, r)) : Gi, t = Q(s, e.maxTier, 0), n = Math.max(t, Q(s, e.minTier, s.length - 1));
3527
+ return {
3528
+ tiers: s,
3529
+ budget: ji(e.budget),
3530
+ ...e.initialTier !== void 0 ? { initialTier: e.initialTier } : {},
3531
+ minTier: n,
3532
+ maxTier: t,
3533
+ adaptive: e.adaptive !== !1,
3534
+ historySize: Math.max(1, Math.round(H(e.historySize, 20)))
3535
+ };
3536
+ }, Qi = (e, s) => {
3537
+ const t = Q(e.tiers, e.maxTier, 0), n = Q(e.tiers, e.minTier, e.tiers.length - 1);
3538
+ if (e.initialTier !== void 0)
3539
+ return ve(Q(e.tiers, e.initialTier, t), t, n);
3540
+ const i = s.deviceMemoryGb !== null && s.deviceMemoryGb <= 4 || s.hardwareConcurrency !== null && s.hardwareConcurrency <= 4;
3541
+ return ve(i ? t + 1 : t, t, n);
3542
+ }, ss = (e, s = ts, t = 0) => {
3543
+ const n = Qi(e, s), i = { index: n, tier: e.tiers[n], reason: "init", at: t };
3544
+ return {
3545
+ index: n,
3546
+ locked: !1,
3547
+ badStreak: 0,
3548
+ goodStreak: 0,
3549
+ lastChangeAt: t,
3550
+ decision: i,
3551
+ history: [i],
3552
+ signals: s
3553
+ };
3554
+ }, Fe = (e, s, t, n, i, r = e.signals) => {
3555
+ const a = { index: t, tier: s.tiers[t], reason: n, at: i };
3556
+ return {
3557
+ ...e,
3558
+ index: t,
3559
+ badStreak: 0,
3560
+ goodStreak: 0,
3561
+ lastChangeAt: i,
3562
+ decision: a,
3563
+ history: [a, ...e.history].slice(0, s.historySize),
3564
+ signals: r
3565
+ };
3566
+ }, Ji = (e, s) => e.thermal === "critical" ? "thermal" : s.maxMemoryMb !== null && e.memoryMb !== null && e.memoryMb > s.maxMemoryMb ? "memory" : e.inferenceMs !== null && e.inferenceMs > s.maxInferenceMs ? "inference" : e.frameMs !== null && e.frameMs > s.maxFrameMs ? "frame-time" : null, Zi = (e, s, t, n) => {
3567
+ const { budget: i } = t, r = Q(t.tiers, t.maxTier, 0), a = Q(t.tiers, t.minTier, t.tiers.length - 1);
3568
+ if (e.locked || !t.adaptive) return { ...e, signals: s };
3569
+ const o = Ji(s, i), d = o === null && s.frameMs !== null && s.frameMs <= i.maxFrameMs * i.upgradeHeadroom && (s.inferenceMs === null || s.inferenceMs <= i.maxInferenceMs * i.upgradeHeadroom), l = o ? e.badStreak + 1 : 0, h = d ? e.goodStreak + 1 : 0, u = n - e.lastChangeAt >= i.cooldownMs;
3570
+ if (o && l >= i.downgradeAfter && u) {
3571
+ if (e.index < a)
3572
+ return Fe(e, t, e.index + 1, o, n, s);
3573
+ const p = o === "frame-time" ? "suspected" : s.thermal;
3574
+ return { ...e, badStreak: l, goodStreak: h, signals: { ...s, thermal: p } };
3575
+ }
3576
+ return d && h >= i.upgradeAfter && u && e.index > r ? Fe(e, t, e.index - 1, "recovered", n, s) : { ...e, badStreak: l, goodStreak: h, signals: s };
3577
+ }, oa = (e, s, t, n) => {
3578
+ const i = Q(s.tiers, t, e.index);
3579
+ return i === e.index ? e : Fe(e, s, i, "manual", n);
3580
+ }, ca = (e, s, t, n) => t === e.locked ? e : { ...Fe(e, s, e.index, t ? "locked" : "manual", n), locked: t }, $i = (e, s) => e.decision.tier === s ? null : e.decision.tier, la = (e, s, t) => {
3581
+ const n = ss(e, s, t);
3582
+ return {
3583
+ ...n,
3584
+ decision: { ...n.decision, reason: "reset" },
3585
+ history: [{ ...n.decision, reason: "reset" }]
3586
+ };
3587
+ }, er = Object.values(P), tr = () => {
3588
+ if (typeof navigator > "u") return { deviceMemoryGb: null, hardwareConcurrency: null };
3589
+ const e = navigator;
3590
+ return {
3591
+ deviceMemoryGb: typeof e.deviceMemory == "number" ? e.deviceMemory : null,
3592
+ hardwareConcurrency: typeof e.hardwareConcurrency == "number" ? e.hardwareConcurrency : null
3593
+ };
3594
+ }, sr = () => {
3595
+ const e = performance.memory;
3596
+ return e ? e.usedJSHeapSize / 1048576 : null;
3597
+ }, nr = ({ config: e, thermal: s, onDecision: t }) => {
3598
+ const { session: n } = ns(), i = JSON.stringify(e ?? {}), r = xe(() => Yi(e), [i]), a = ue(s ?? "unknown");
3599
+ a.current = s ?? "unknown";
3600
+ const o = ue(t);
3601
+ return o.current = t, de(() => {
3602
+ const d = tr();
3603
+ let l = ss(
3604
+ r,
3605
+ { ...ts, ...d },
3606
+ performance.now()
3607
+ );
3608
+ const h = n.store.getSnapshot().quality;
3609
+ h && h.index < r.tiers.length && (l = {
3610
+ ...h,
3611
+ decision: { ...h.decision, tier: r.tiers[h.index] }
3612
+ }), n._setQualityConfig(r), n._setQuality(l);
3613
+ let u = n._getPerf(), p = null;
3614
+ const M = async (y, v) => {
3615
+ const A = {
3616
+ ...u,
3617
+ ...y.targetFps !== void 0 ? { targetFps: y.targetFps } : {},
3618
+ ...y.analysisScale !== void 0 ? { analysisScale: y.analysisScale } : {},
3619
+ ...y.camRes !== void 0 && y.rebindCamera ? { camRes: y.camRes } : {}
3620
+ };
3621
+ n._setPerf(A), y.rebindCamera && y.camRes !== void 0 && y.camRes !== (v == null ? void 0 : v.camRes) && await n._rebindMedia().catch(() => {
3622
+ });
3623
+ };
3624
+ p = l.decision.tier, M(l.decision.tier, null);
3625
+ let x = 0, b = performance.now(), T = 0;
3626
+ const R = () => {
3627
+ x += 1, T = requestAnimationFrame(R);
3628
+ };
3629
+ T = requestAnimationFrame(R);
3630
+ let w = null;
3631
+ const g = window.setInterval(() => {
3632
+ var G;
3633
+ if (typeof document < "u" && document.hidden) {
3634
+ x = 0, b = performance.now();
3635
+ return;
3636
+ }
3637
+ const y = performance.now(), v = y - b, A = $e(n, er, w, y);
3638
+ w = { feedFrames: A.session.feedFrames, sampledAt: y };
3639
+ const E = n.store.getSnapshot().lifecycle === "running", B = {
3640
+ frameMs: x > 0 && v > 0 && E ? v / x : null,
3641
+ fps: x > 0 && v > 0 ? x * 1e3 / v : null,
3642
+ inferenceMs: E ? A.inferenceMsTotal : null,
3643
+ feedFps: A.session.feedFps,
3644
+ memoryMb: sr(),
3645
+ ...d,
3646
+ thermal: a.current
3647
+ };
3648
+ x = 0, b = y;
3649
+ const K = n.store.getSnapshot().quality ?? l, L = Zi(K, B, r, y);
3650
+ l = L, n._setQuality(L);
3651
+ const F = $i(L, p);
3652
+ if (F) {
3653
+ const X = p;
3654
+ p = F, M(F, X), (G = o.current) == null || G.call(o, L);
3655
+ }
3656
+ }, r.budget.sampleMs);
3657
+ return () => {
3658
+ cancelAnimationFrame(T), window.clearInterval(g);
3659
+ const y = (p == null ? void 0 : p.rebindCamera) && p.camRes !== void 0;
3660
+ n._setPerf(u), y && (u == null ? void 0 : u.camRes) !== (p == null ? void 0 : p.camRes) && n._rebindMedia().catch(() => {
3661
+ }), u = void 0, n._setQualityConfig(null);
3662
+ };
3663
+ }, [n, r]), null;
3664
+ }, it = Lt(void 0), ns = () => {
3665
+ const e = et(it);
3666
+ if (!e)
3667
+ throw new O(
3668
+ "XR context can only be used inside XRProvider, did you forget to wrap your app in <XRProvider>?"
3669
+ );
3670
+ return e;
3671
+ }, da = () => et(it) ?? null, ha = ({ children: e, perf: s, lifecycle: t, quality: n }) => {
3672
+ const i = zi(s, t), r = xe(() => ({ session: i }), [i]);
3673
+ return de(() => Js(i), [i]), /* @__PURE__ */ Ds(it.Provider, { value: r, children: [
3674
+ n !== !1 && /* @__PURE__ */ xt(nr, { config: n || void 0 }),
3675
+ /* @__PURE__ */ xt(qi, { children: e })
3676
+ ] });
3677
+ };
3678
+ export {
3679
+ Or as $,
3680
+ di as A,
3681
+ ye as B,
3682
+ me as C,
3683
+ ta as D,
3684
+ ts as E,
3685
+ na as F,
3686
+ Ti as G,
3687
+ fi as H,
3688
+ Zs as I,
3689
+ q as J,
3690
+ Mr as K,
3691
+ z as L,
3692
+ J as M,
3693
+ ra as N,
3694
+ br as O,
3695
+ Ee as P,
3696
+ tt as Q,
3697
+ Kt as R,
3698
+ Pt as S,
3699
+ mr as T,
3700
+ fr as U,
3701
+ gr as V,
3702
+ pr as W,
3703
+ At as X,
3704
+ ha as Y,
3705
+ Pn as Z,
3706
+ Rr as _,
3707
+ oa as a,
3708
+ $i as a$,
3709
+ Yt as a0,
3710
+ Fr as a1,
3711
+ Ir as a2,
3712
+ Pr as a3,
3713
+ _r as a4,
3714
+ kr as a5,
3715
+ Ar as a6,
3716
+ Lr as a7,
3717
+ Dn as a8,
3718
+ Tr as a9,
3719
+ Gi as aA,
3720
+ nr as aB,
3721
+ Ze as aC,
3722
+ gi as aD,
3723
+ Xt as aE,
3724
+ Ut as aF,
3725
+ en as aG,
3726
+ tn as aH,
3727
+ sn as aI,
3728
+ Ln as aJ,
3729
+ Xr as aK,
3730
+ Kr as aL,
3731
+ Bn as aM,
3732
+ $s as aN,
3733
+ $e as aO,
3734
+ Vt as aP,
3735
+ Gt as aQ,
3736
+ aa as aR,
3737
+ Vi as aS,
3738
+ mn as aT,
3739
+ ss as aU,
3740
+ Ji as aV,
3741
+ tr as aW,
3742
+ Qi as aX,
3743
+ ji as aY,
3744
+ Xi as aZ,
3745
+ Zi as a_,
3746
+ Br as aa,
3747
+ Er as ab,
3748
+ Cr as ac,
3749
+ Dr as ad,
3750
+ Nr as ae,
3751
+ Wr as af,
3752
+ xn as ag,
3753
+ Hr as ah,
3754
+ Ur as ai,
3755
+ wr as aj,
3756
+ vr as ak,
3757
+ xr as al,
3758
+ Sr as am,
3759
+ qr as an,
3760
+ yr as ao,
3761
+ On as ap,
3762
+ zr as aq,
3763
+ Yr as ar,
3764
+ Qr as as,
3765
+ li as at,
3766
+ mi as au,
3767
+ zt as av,
3768
+ cn as aw,
3769
+ Wt as ax,
3770
+ hr as ay,
3771
+ Z as az,
3772
+ la as b,
3773
+ Ei as b0,
3774
+ sa as b1,
3775
+ Tn as b2,
3776
+ Fn as b3,
3777
+ Ct as b4,
3778
+ yi as b5,
3779
+ pi as b6,
3780
+ wi as b7,
3781
+ bn as b8,
3782
+ Cn as b9,
3783
+ kn as ba,
3784
+ ia as bb,
3785
+ Jr as bc,
3786
+ Vn as bd,
3787
+ Zn as be,
3788
+ $n as bf,
3789
+ te as bg,
3790
+ vn as c,
3791
+ dr as d,
3792
+ ea as e,
3793
+ Nn as f,
3794
+ Vr as g,
3795
+ Gr as h,
3796
+ Se as i,
3797
+ P as j,
3798
+ Zr as k,
3799
+ ca as l,
3800
+ ur as m,
3801
+ Hn as n,
3802
+ Ge as o,
3803
+ $r as p,
3804
+ Wn as q,
3805
+ Yi as r,
3806
+ qt as s,
3807
+ jr as t,
3808
+ ns as u,
3809
+ qn as v,
3810
+ I as w,
3811
+ da as x,
3812
+ _ as y,
3813
+ wn as z
3814
+ };