@vincentt-xr/sdk 2.0.0-alpha.0

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 (159) hide show
  1. package/GROUNDING.md +537 -0
  2. package/LICENSE +7 -0
  3. package/README.md +85 -0
  4. package/dist/DebuggerUI-CEfdddkZ.cjs +1 -0
  5. package/dist/DebuggerUI-Dgop6Q6o.js +269 -0
  6. package/dist/audio/AudioEngine.d.ts +98 -0
  7. package/dist/audio/index.d.ts +34 -0
  8. package/dist/components/AspectRatioContainer/index.d.ts +10 -0
  9. package/dist/components/BodyTracker/index.d.ts +15 -0
  10. package/dist/components/Debugger/DebuggerProvider.d.ts +22 -0
  11. package/dist/components/Debugger/DebuggerUI.d.ts +13 -0
  12. package/dist/components/Debugger/index.d.ts +38 -0
  13. package/dist/components/Debugger/styles.d.ts +19 -0
  14. package/dist/components/FaceMesh/FaceMesh.d.ts +26 -0
  15. package/dist/components/FaceMesh/canonical/CanonicalFaceMeshRenderer.d.ts +34 -0
  16. package/dist/components/FaceMesh/canonical/parseCanonicalFaceModel.d.ts +16 -0
  17. package/dist/components/FaceMesh/canonical/useCanonicalFaceMesh.d.ts +15 -0
  18. package/dist/components/FaceMesh/deform.d.ts +36 -0
  19. package/dist/components/FaceMesh/index.d.ts +6 -0
  20. package/dist/components/FaceMesh/indices.d.ts +1 -0
  21. package/dist/components/FaceMesh/material/blendModes.d.ts +2 -0
  22. package/dist/components/FaceMesh/material/defaults.d.ts +3 -0
  23. package/dist/components/FaceMesh/material/index.d.ts +5 -0
  24. package/dist/components/FaceMesh/material/options.d.ts +25 -0
  25. package/dist/components/FaceMesh/material/support.d.ts +3 -0
  26. package/dist/components/FaceMesh/material/types.d.ts +23 -0
  27. package/dist/components/FaceMesh/uv.d.ts +1 -0
  28. package/dist/components/FaceRetouch/Background.d.ts +16 -0
  29. package/dist/components/FaceRetouch/index.d.ts +6 -0
  30. package/dist/components/FaceRetouch/landmarkMask.d.ts +23 -0
  31. package/dist/components/FaceRetouch/retouchRegions.d.ts +23 -0
  32. package/dist/components/FaceRetouch/useFaceRetouchMask.d.ts +14 -0
  33. package/dist/components/FaceRetouch/useFaceRetouchRegions.d.ts +12 -0
  34. package/dist/components/FaceTracker/BoundingBoxOverlay.d.ts +20 -0
  35. package/dist/components/FaceTracker/index.d.ts +54 -0
  36. package/dist/components/GestureTracker/index.d.ts +31 -0
  37. package/dist/components/GestureTrigger/index.d.ts +3 -0
  38. package/dist/components/HandTracker/index.d.ts +24 -0
  39. package/dist/components/HeadBinding/index.d.ts +31 -0
  40. package/dist/components/HeadBindingOccluder/index.d.ts +36 -0
  41. package/dist/components/HeadOccluder/index.d.ts +13 -0
  42. package/dist/components/Panel/index.d.ts +71 -0
  43. package/dist/components/PerspectiveCamera/index.d.ts +14 -0
  44. package/dist/components/ScreenSpaceUI/ScreenTransform.d.ts +54 -0
  45. package/dist/components/ScreenSpaceUI/context.d.ts +29 -0
  46. package/dist/components/ScreenSpaceUI/index.d.ts +40 -0
  47. package/dist/components/Segmentation/index.d.ts +44 -0
  48. package/dist/components/SpriteAnimation/index.d.ts +52 -0
  49. package/dist/components/TextLabel/index.d.ts +62 -0
  50. package/dist/components/TrackingAnchor/index.d.ts +74 -0
  51. package/dist/components/VideoBackground/index.d.ts +38 -0
  52. package/dist/components/XRCompositor/index.d.ts +5 -0
  53. package/dist/components/XRDebugView/index.d.ts +6 -0
  54. package/dist/components/XRLayer/index.d.ts +6 -0
  55. package/dist/components/XRMediaSurface/index.d.ts +27 -0
  56. package/dist/components/XRProvider/index.d.ts +13 -0
  57. package/dist/components/XRScene/defaults.d.ts +4 -0
  58. package/dist/components/XRScene/index.d.ts +15 -0
  59. package/dist/components/XRViewport/index.d.ts +101 -0
  60. package/dist/components/index.d.ts +26 -0
  61. package/dist/config/index.d.ts +8 -0
  62. package/dist/constants/index.d.ts +25 -0
  63. package/dist/constants/renderLayers.d.ts +25 -0
  64. package/dist/entries/all.d.ts +15 -0
  65. package/dist/entries/core.d.ts +21 -0
  66. package/dist/entries/face-effects.d.ts +19 -0
  67. package/dist/entries/internal.d.ts +16 -0
  68. package/dist/entries/low-level.d.ts +30 -0
  69. package/dist/entries/tracking.d.ts +15 -0
  70. package/dist/face-effects.cjs +252 -0
  71. package/dist/face-effects.js +3542 -0
  72. package/dist/hasFullUnitUVBounds-BGvcFsQM.js +26 -0
  73. package/dist/hasFullUnitUVBounds-p1Dl0ejX.cjs +1 -0
  74. package/dist/hooks/faceResults.d.ts +39 -0
  75. package/dist/hooks/selectors.d.ts +33 -0
  76. package/dist/hooks/useCalibrationFaceTracker.d.ts +23 -0
  77. package/dist/hooks/useDebugger/index.d.ts +25 -0
  78. package/dist/hooks/useDebugger/types.d.ts +20 -0
  79. package/dist/hooks/useFaceBoundingBox.d.ts +11 -0
  80. package/dist/hooks/useFaceResults.d.ts +31 -0
  81. package/dist/hooks/useGestureEdge.d.ts +53 -0
  82. package/dist/hooks/useMediaRecorder.d.ts +40 -0
  83. package/dist/hooks/useTrackerContext.d.ts +35 -0
  84. package/dist/hooks/useXRModel.d.ts +15 -0
  85. package/dist/hooks/useXRSession/constants.d.ts +4 -0
  86. package/dist/hooks/useXRSession/facade.d.ts +39 -0
  87. package/dist/hooks/useXRSession/fns.d.ts +5 -0
  88. package/dist/hooks/useXRSession/index.d.ts +4 -0
  89. package/dist/hooks/useXRSession/registry.d.ts +52 -0
  90. package/dist/hooks/useXRSession/store.d.ts +40 -0
  91. package/dist/index-B5J4gzn2.cjs +1 -0
  92. package/dist/index-BD-JWMjE.js +1991 -0
  93. package/dist/index-BVBVg96G.cjs +1 -0
  94. package/dist/index-CYMj26Ej.js +1331 -0
  95. package/dist/index-DtwHElmG.js +157 -0
  96. package/dist/index-PtFmD6B8.cjs +1 -0
  97. package/dist/internal-DH5d1Xnq.cjs +1 -0
  98. package/dist/internal-KOKJDxCG.js +519 -0
  99. package/dist/internal.cjs +1 -0
  100. package/dist/internal.js +14 -0
  101. package/dist/low-level.cjs +1 -0
  102. package/dist/low-level.js +941 -0
  103. package/dist/main.cjs +1 -0
  104. package/dist/main.js +612 -0
  105. package/dist/models/Base/index.d.ts +25 -0
  106. package/dist/models/Body/index.d.ts +22 -0
  107. package/dist/models/Face/constants.d.ts +2 -0
  108. package/dist/models/Face/index.d.ts +45 -0
  109. package/dist/models/Face/landmarksData.d.ts +2 -0
  110. package/dist/models/Hand/GestureTracking.d.ts +21 -0
  111. package/dist/models/Hand/HandTracking.d.ts +21 -0
  112. package/dist/models/Segmentation/index.d.ts +75 -0
  113. package/dist/models/index.d.ts +5 -0
  114. package/dist/modules/XRClient/index.d.ts +9 -0
  115. package/dist/modules/index.d.ts +1 -0
  116. package/dist/selectors-BHO6TnoC.js +59 -0
  117. package/dist/selectors-Bub0o3qy.cjs +1 -0
  118. package/dist/services/ApiService.d.ts +12 -0
  119. package/dist/services/MetricsCollector/CameraFPSTracker.d.ts +25 -0
  120. package/dist/services/MetricsCollector/MemoryTracker.d.ts +43 -0
  121. package/dist/services/MetricsCollector/RenderTimeTracker.d.ts +10 -0
  122. package/dist/services/MetricsCollector/ResolutionTracker.d.ts +26 -0
  123. package/dist/services/MetricsCollector/index.d.ts +59 -0
  124. package/dist/services/MetricsCollector/types.d.ts +47 -0
  125. package/dist/services/MetricsCollector/utils.d.ts +65 -0
  126. package/dist/texture/computeContainScale.d.ts +25 -0
  127. package/dist/texture/hasFullUnitUVBounds.d.ts +37 -0
  128. package/dist/texture/types.d.ts +20 -0
  129. package/dist/tracking.cjs +1 -0
  130. package/dist/tracking.js +344 -0
  131. package/dist/types/body.d.ts +3 -0
  132. package/dist/types/client.d.ts +3 -0
  133. package/dist/types/common.d.ts +9 -0
  134. package/dist/types/compositor.d.ts +23 -0
  135. package/dist/types/debugger.d.ts +83 -0
  136. package/dist/types/face.d.ts +67 -0
  137. package/dist/types/gesture-tracking.d.ts +15 -0
  138. package/dist/types/hand-tracking.d.ts +5 -0
  139. package/dist/types/headBinding.d.ts +67 -0
  140. package/dist/types/index.d.ts +12 -0
  141. package/dist/types/logger.d.ts +4 -0
  142. package/dist/types/model.d.ts +46 -0
  143. package/dist/types/nodes.d.ts +35 -0
  144. package/dist/types/segmentation.d.ts +31 -0
  145. package/dist/types/session.d.ts +102 -0
  146. package/dist/types/tracking.d.ts +30 -0
  147. package/dist/types/util-types.d.ts +1 -0
  148. package/dist/useFaceResults-cpsSmKKc.js +81 -0
  149. package/dist/useFaceResults-hVUJYSEY.cjs +1 -0
  150. package/dist/utils/calibrationDebug.d.ts +9 -0
  151. package/dist/utils/dataURL.d.ts +6 -0
  152. package/dist/utils/drawMediaCover.d.ts +18 -0
  153. package/dist/utils/errors.d.ts +3 -0
  154. package/dist/utils/fns.d.ts +48 -0
  155. package/dist/utils/headBinding.d.ts +85 -0
  156. package/dist/utils/integrity.d.ts +43 -0
  157. package/dist/utils/landmarkBounds.d.ts +11 -0
  158. package/dist/utils/logger.d.ts +7 -0
  159. package/package.json +113 -0
@@ -0,0 +1,157 @@
1
+ import { jsx as u, jsxs as X } from "react/jsx-runtime";
2
+ import { createContext as b, useContext as E, useMemo as y, useEffect as w, useRef as R, useState as T } from "react";
3
+ import { R as _, u as L } from "./index-CYMj26Ej.js";
4
+ import { Canvas as M } from "@react-three/fiber";
5
+ import * as v from "three";
6
+ import { b as Y, c as D } from "./selectors-BHO6TnoC.js";
7
+ const $ = b(null), I = () => {
8
+ const o = E($);
9
+ if (!o)
10
+ throw new Error("useScreenSpace must be used within ScreenSpaceUI");
11
+ return o;
12
+ }, A = b(null), V = () => E(A) ?? 1, O = (o, i, c, d, l) => {
13
+ const f = o / 2, t = i / 2, e = c.left * f + d.left, a = c.right * f - d.right, r = c.bottom * t + d.bottom, s = c.top * t - d.top, n = a - e, p = s - r, S = (e + a) / 2, m = (r + s) / 2, h = l[0] * n / 2, g = l[1] * p / 2;
14
+ return { centerX: S, centerY: m, width: n, height: p, pivotX: h, pivotY: g };
15
+ }, U = { left: 0, right: 0, top: 0, bottom: 0 }, H = { left: 0, right: 0, top: 0, bottom: 0 }, N = [0, 0], J = ({
16
+ anchors: o,
17
+ offsets: i,
18
+ pivot: c = N,
19
+ children: d
20
+ }) => {
21
+ const { width: l, height: f } = I(), t = y(
22
+ () => ({
23
+ anchors: { ...U, ...o ?? {} },
24
+ offsets: { ...H, ...i ?? {} }
25
+ }),
26
+ [o, i]
27
+ ), e = y(
28
+ () => O(l, f, t.anchors, t.offsets, c),
29
+ [l, f, t, c]
30
+ );
31
+ w(() => {
32
+ const n = t.anchors;
33
+ n.left > n.right && console.warn(
34
+ `[ScreenTransform] inverted X axis: anchors.left (${n.left}) > anchors.right (${n.right})`
35
+ ), n.bottom > n.top && console.warn(
36
+ `[ScreenTransform] inverted Y axis: anchors.bottom (${n.bottom}) > anchors.top (${n.top})`
37
+ ), e.width <= 0 && console.warn(
38
+ `[ScreenTransform] zero or negative width (${e.width.toFixed(3)}) — anchors + offsets collapse the X extent`
39
+ ), e.height <= 0 && console.warn(
40
+ `[ScreenTransform] zero or negative height (${e.height.toFixed(3)}) — anchors + offsets collapse the Y extent`
41
+ );
42
+ }, [t, e.width, e.height]);
43
+ const a = c[0] !== 0 || c[1] !== 0, r = a ? [1, 1, 1] : [e.width, e.height, 1], s = !a && e.width > 0 && e.height > 0 ? e.width / e.height : null;
44
+ return /* @__PURE__ */ u(
45
+ "group",
46
+ {
47
+ position: [e.centerX - e.pivotX, e.centerY - e.pivotY, 0],
48
+ scale: r,
49
+ renderOrder: _.SCREEN_UI,
50
+ children: /* @__PURE__ */ u(A.Provider, { value: s, children: d })
51
+ }
52
+ );
53
+ }, F = {
54
+ display: "flex",
55
+ alignItems: "center",
56
+ justifyContent: "center",
57
+ height: "100%",
58
+ background: "#363636",
59
+ color: "white",
60
+ fontFamily: "monospace"
61
+ }, j = () => /* @__PURE__ */ u("div", { style: F, children: "Loading..." }), B = (o) => /* @__PURE__ */ u("div", { style: F, children: o.error }), C = {
62
+ position: "absolute",
63
+ top: 0,
64
+ left: 0,
65
+ width: "100%",
66
+ height: "100%",
67
+ zIndex: 10
68
+ }, K = ({
69
+ style: o,
70
+ canvasProps: i,
71
+ children: c,
72
+ loadingComponent: d,
73
+ loadingTransitionDuration: l,
74
+ errorComponent: f,
75
+ renderTargetSize: t
76
+ }) => {
77
+ const e = R(null), a = R(null), r = R(null), { session: s } = L(), n = Y(), p = D(), [S, m] = T(!0);
78
+ return w(() => {
79
+ if (t) {
80
+ s._setRenderSize(
81
+ Math.round(t.width),
82
+ Math.round(t.height)
83
+ );
84
+ return;
85
+ }
86
+ const h = () => {
87
+ a.current && s._setRenderTarget(a.current);
88
+ }, g = () => {
89
+ r.current !== null && cancelAnimationFrame(r.current), r.current = requestAnimationFrame(() => {
90
+ r.current = null, h();
91
+ });
92
+ }, x = new ResizeObserver(() => {
93
+ g();
94
+ });
95
+ return e.current && x.observe(e.current), g(), () => {
96
+ x.disconnect(), r.current !== null && (cancelAnimationFrame(r.current), r.current = null);
97
+ };
98
+ }, [t, s]), w(() => {
99
+ n && (l ? setTimeout(() => {
100
+ m(!1);
101
+ }, l) : m(!1));
102
+ }, [n, l]), /* @__PURE__ */ X(
103
+ "div",
104
+ {
105
+ id: "vincentt-xr-container",
106
+ ref: e,
107
+ style: {
108
+ width: "100%",
109
+ height: "100%",
110
+ ...o,
111
+ position: "relative"
112
+ },
113
+ children: [
114
+ S && /* @__PURE__ */ u("div", { style: C, children: d || /* @__PURE__ */ u(j, {}) }),
115
+ p && /* @__PURE__ */ u("div", { style: C, children: f || /* @__PURE__ */ u(B, { error: p.message }) }),
116
+ /* @__PURE__ */ u(
117
+ M,
118
+ {
119
+ id: "vincentt-xr-canvas",
120
+ ref: a,
121
+ dpr: [1, 3],
122
+ gl: {
123
+ alpha: !0,
124
+ preserveDrawingBuffer: !0,
125
+ antialias: !0,
126
+ premultipliedAlpha: !1,
127
+ // Disable alpha premultiplication
128
+ toneMapping: v.NoToneMapping
129
+ // Disable tone mapping for accurate video colors
130
+ },
131
+ ...i,
132
+ onCreated: (h) => {
133
+ t ? s._setRenderSize(
134
+ Math.round(t.width),
135
+ Math.round(t.height)
136
+ ) : s._setRenderTarget(a.current), s._setR3FState({
137
+ renderer: h.gl,
138
+ scene: h.scene,
139
+ camera: h.camera
140
+ }), h.gl.outputColorSpace = v.SRGBColorSpace, i != null && i.onCreated && i.onCreated(h);
141
+ },
142
+ children: c
143
+ }
144
+ )
145
+ ]
146
+ }
147
+ );
148
+ };
149
+ export {
150
+ $ as S,
151
+ K as X,
152
+ J as a,
153
+ I as b,
154
+ A as c,
155
+ O as d,
156
+ V as u
157
+ };
@@ -0,0 +1 @@
1
+ "use strict";var me=Object.defineProperty;var fe=(i,s,e)=>s in i?me(i,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[s]=e;var h=(i,s,e)=>fe(i,typeof s!="symbol"?s+"":s,e);const pe=require("react/jsx-runtime"),N=require("react"),A=require("@mediapipe/tasks-vision"),b=require("three");function we(i){const s=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(i){for(const e in i)if(e!=="default"){const t=Object.getOwnPropertyDescriptor(i,e);Object.defineProperty(s,e,t.get?t:{enumerable:!0,get:()=>i[e]})}}return s.default=i,Object.freeze(s)}const T=we(b);var y=(i=>(i.WEBCAM="webcam",i.STREAM="stream",i.CANVAS="canvas",i))(y||{}),P=(i=>(i.HAND_TRACKER="vincentt.xr.hand-tracker",i.GESTURE_TRACKER="vincentt.xr.gesture-tracker",i.FACE_TRACKER="vincentt.xr.face-tracker",i.BODY_TRACKER="vincentt.xr.body-tracker",i.BACKGROUND_SEGMENTATION="vincentt.xr.background-segmentation",i))(P||{});const ve={BACKGROUND:-1e3,WORLD:0,TRACKED:100,SCREEN_UI:1e3};class x extends Error{constructor(s){super(s),this.name="VincenttXRError"}}const R={assetStorageEndpoint:"https://cdn.vincentt.studio",sdkAssetsBaseUrl:"https://cdn.vincentt.studio/assets/sdk/face/v1",loggerPrefix:"[vincentt-xr]:"};class Ce{constructor(s){h(this,"options");const e={verbose:!1,prefix:R.loggerPrefix};this.options={...e,...s}}log(...s){const{verbose:e,prefix:t}=this.options;e&&console.log(t,...s)}error(...s){const{verbose:e,prefix:t}=this.options;e&&console.error(t,...s)}}const O=i=>i*2-1,W=new T.Vector3,G=new T.Vector3,z=({x:i,y:s,z:e},t,n)=>{W.set((i-.5)*2,(.5-s)*2,-e),W.unproject(t),G.copy(W).sub(t.position).normalize();const r=-t.position.z/G.z;return n.copy(t.position).addScaledVector(G,r),n},Se=(i,s)=>z(i,s,new T.Vector3),ke=(i,s,e=.2)=>e*s+(1-e)*i;class X{constructor(s){h(this,"canvas");this.maxDimension=s}draw(s){const e=s.width,t=s.height,n=Math.min(1,this.maxDimension/Math.max(e,t));if(n>=1)return s;const r=Math.max(1,Math.round(e*n)),c=Math.max(1,Math.round(t*n));(!this.canvas||this.canvas.width!==r||this.canvas.height!==c)&&(this.canvas=new OffscreenCanvas(r,c));const d=this.canvas.getContext("2d");return d?(d.setTransform(1,0,0,1,0,0),d.clearRect(0,0,r,c),d.drawImage(s,0,0,r,c),this.canvas):s}dispose(){this.canvas=void 0}}const ye={};async function te(i){const s=await fetch(i);if(!s.ok)throw new Error(`fetchAndVerify: ${s.status} ${i}`);const e=await s.arrayBuffer(),t=Me(i);if(!t)return console.warn(`[xr-sdk integrity] no SRI hash for ${i} — passing through`),e;const n=await Te(e);if(n!==t)throw new Error(`[xr-sdk integrity] SRI mismatch for ${i}: expected ${t}, got ${n}`);return e}async function V(i){const s=await te(i);return new Uint8Array(s)}function Me(i){try{const s=new URL(i);return ye[s.pathname]}catch{return}}async function Te(i){const s=await crypto.subtle.digest("SHA-384",i),e=new Uint8Array(s);let t="";for(let n=0;n<e.byteLength;n++)t+=String.fromCharCode(e[n]);return`sha384-${btoa(t)}`}class B{constructor(){h(this,"disposed",!1);h(this,"paused",!1);h(this,"rafId",null);h(this,"targetFrameIntervalMs",0);h(this,"lastInferenceMs",0)}setTargetFps(s){this.targetFrameIntervalMs=s&&s>0?1e3/s:0}shouldRunInference(){if(this.targetFrameIntervalMs<=0)return!0;const s=performance.now();return s-this.lastInferenceMs<this.targetFrameIntervalMs?!1:(this.lastInferenceMs=s,!0)}async initialize(s){}async run(s){}getModelNode(){return{}}async getPerformanceData(){return{name:this.constructor.name,processingTime:null}}pause(){this.paused=!0,this.rafId!==null&&(cancelAnimationFrame(this.rafId),this.rafId=null)}resume(){this.paused=!1}dispose(){this.disposed=!0,this.rafId!==null&&(cancelAnimationFrame(this.rafId),this.rafId=null)}}const Re=768;class Fe extends B{constructor(){super();h(this,"landmarker",null);h(this,"processingTime",null);h(this,"coordinates");h(this,"sourceCanvas");h(this,"downscaler",new X(Re))}async getBodyData(){if(!this.landmarker||!this.sourceCanvas)return;const e=this.downscaler.draw(this.sourceCanvas),t=performance.now(),n=this.landmarker.detectForVideo(e,t),r=performance.now();this.processingTime=r-t;const c=n.landmarks,d=[];if(c)return c.forEach((m,u)=>{d[u]||(d[u]=[]),m.forEach(g=>{const f=O(g.x),w=O(1-g.y),p=O(g.z);d[u].push({x:f,y:w,z:p})})}),{coordinatesList:d}}async processBodyTracking(){if(this.disposed||!this.landmarker)return;const e=await this.getBodyData();e&&(this.coordinates=e.coordinatesList),!(this.disposed||this.paused)&&(this.rafId=requestAnimationFrame(this.processBodyTracking.bind(this)))}resume(){this.paused&&(super.resume(),this.processBodyTracking())}dispose(){if(super.dispose(),this.landmarker){try{this.landmarker.close()}catch{}this.landmarker=null}this.sourceCanvas=void 0,this.downscaler.dispose(),this.coordinates=void 0}getLandmarks2D(e=0){if(this.coordinates)return this.coordinates[e]}async initialize(e){const t=await A.FilesetResolver.forVisionTasks(new URL("/assets/xr/wasm",R.assetStorageEndpoint).toString()),n=await V(new URL("/assets/xr/models/body_tracking.task",R.assetStorageEndpoint).toString());this.landmarker=await A.PoseLandmarker.createFromOptions(t,{baseOptions:{modelAssetBuffer:n,delegate:"GPU"},runningMode:"VIDEO",numPoses:(e==null?void 0:e.numPoses)||1})}async run({sourceCanvas:e}){this.sourceCanvas=e,this.rafId===null&&await this.processBodyTracking()}getModelNode(){return{getLandmarks2D:this.getLandmarks2D.bind(this)}}async getPerformanceData(){return{name:this.constructor.name,processingTime:this.processingTime}}}const xe=.11,Ae=.004;class Ee extends B{constructor(){super();h(this,"landmarker",null);h(this,"processingTime",null);h(this,"sourceCanvas");h(this,"analysisCanvas");h(this,"getSource");h(this,"detectionResults");h(this,"numFaces",1);h(this,"cameras",[]);h(this,"faces",[]);h(this,"leftCheekScratch",[]);h(this,"rightCheekScratch",[]);h(this,"landmarkScratch",{x:0,y:0,z:0,visibility:0});h(this,"rotMatrixScratch",new T.Matrix4);h(this,"rotQuatScratch",new T.Quaternion);h(this,"rotEulerScratch",new T.Euler)}landmarkForSource(e,t){return t?(this.landmarkScratch.x=1-e.x,this.landmarkScratch.y=e.y,this.landmarkScratch.z=e.z,this.landmarkScratch.visibility=e.visibility,this.landmarkScratch):e}extractAndUpdateFaceData(e){var n;if(!e.faceLandmarks.length){this.faces=[];return}const t=e.faceLandmarks.length;for(this.faces.length>t&&(this.faces.length=t,this.leftCheekScratch.length=t,this.rightCheekScratch.length=t);this.faces.length<t;)this.faces.push({transform:{position:new T.Vector3,rotation:new T.Vector3,scale:new T.Vector3},gestures:{}}),this.leftCheekScratch.push(new T.Vector3),this.rightCheekScratch.push(new T.Vector3);for(let r=0;r<t;r+=1){if(!this.cameras[r])continue;const c=this.faces[r],d=(n=this.getSource)==null?void 0:n.call(this),m=!(d==="webcam"||!d),u=e.faceLandmarks[r],g=e.facialTransformationMatrixes[r];this.rotMatrixScratch.fromArray(g.data),this.rotQuatScratch.setFromRotationMatrix(this.rotMatrixScratch),this.rotQuatScratch.set(-this.rotQuatScratch.x,this.rotQuatScratch.y,this.rotQuatScratch.z,this.rotQuatScratch.w),this.rotEulerScratch.setFromQuaternion(this.rotQuatScratch,"XYZ"),c.transform.rotation.set(-this.rotEulerScratch.x,this.rotEulerScratch.y,this.rotEulerScratch.z),z(this.landmarkForSource(u[4],m),this.cameras[r],c.transform.position),z(this.landmarkForSource(u[50],m),this.cameras[r],this.leftCheekScratch[r]),z(this.landmarkForSource(u[280],m),this.cameras[r],this.rightCheekScratch[r]);const w=this.leftCheekScratch[r].distanceTo(this.rightCheekScratch[r])*xe,p=Math.abs(T.MathUtils.radToDeg(this.rotEulerScratch.y)),k=w+p*Ae,C=c.transform.scale.x,F=ke(isNaN(C)?0:C,k);c.transform.scale.set(F,F,F);const I=c.gestures,D=e.faceBlendshapes[r].categories;for(const E of D)I[E.categoryName]=E.score}}async processFaceTracking(){if(this.disposed||this.paused||!this.landmarker||!this.sourceCanvas)return null;if(!this.shouldRunInference()){this.rafId=requestAnimationFrame(this.processFaceTracking.bind(this));return}const e=be(this.numFaces),t=this.sourceCanvas.width,n=this.sourceCanvas.height,r=Math.min(1,e/Math.max(t,n)),c=Math.max(1,Math.round(t*r)),d=Math.max(1,Math.round(n*r));(!this.analysisCanvas||this.analysisCanvas.width!==c||this.analysisCanvas.height!==d)&&(this.analysisCanvas=new OffscreenCanvas(c,d));const m=this.analysisCanvas.getContext("2d");if(!m)return;m.setTransform(1,0,0,1,0,0),m.clearRect(0,0,c,d),m.drawImage(this.sourceCanvas,0,0,c,d);const u=performance.now(),g=this.landmarker.detectForVideo(this.analysisCanvas,u),f=performance.now();this.processingTime=f-u,this.detectionResults=g,this.extractAndUpdateFaceData(g),!(this.disposed||this.paused)&&(this.rafId=requestAnimationFrame(this.processFaceTracking.bind(this)))}resume(){this.paused&&(super.resume(),this.processFaceTracking())}getFace(e=0){return this.faces[e]}getDetectionResults(){return this.detectionResults}getRawFaceTrackingData(e=0){var t,n,r,c;if(this.detectionResults)return{landmarks:(t=this.detectionResults.faceLandmarks)==null?void 0:t[e],blendshapes:(r=(n=this.detectionResults.faceBlendshapes)==null?void 0:n[e])==null?void 0:r.categories,transformationMatrix:(c=this.detectionResults.facialTransformationMatrixes)==null?void 0:c[e]}}async initialize(e){this.numFaces=(e==null?void 0:e.numFaces)||1;const t=await A.FilesetResolver.forVisionTasks(new URL("/assets/xr/wasm",R.assetStorageEndpoint).toString()),n=await V(new URL("/assets/xr/models/face_tracking.task",R.assetStorageEndpoint).toString()),r=await A.FaceLandmarker.createFromOptions(t,{baseOptions:{modelAssetBuffer:n,delegate:"GPU"},minFaceDetectionConfidence:.3,minFacePresenceConfidence:.3,minTrackingConfidence:.3,outputFaceBlendshapes:!0,outputFacialTransformationMatrixes:!0,runningMode:"VIDEO",numFaces:this.numFaces});this.landmarker=r}async run({sourceCanvas:e,getSource:t,targetFps:n}){this.sourceCanvas=e,this.getSource=t,this.setTargetFps(n),this.analysisCanvas=void 0,this.rafId===null&&this.processFaceTracking()}getModelNode(){const e=this,t={get detectionResults(){return e.detectionResults},getDetectionResults:this.getDetectionResults.bind(this),getFace:this.getFace.bind(this),getRawFaceTrackingData:this.getRawFaceTrackingData.bind(this)};return Object.assign(t,{_setCamera:(n,r)=>{this.cameras[r]=n}}),t}async getPerformanceData(){return{name:this.constructor.name,processingTime:this.processingTime}}}const be=i=>i>1?1024:512;var _=(i=>(i.ClosedFist="closed_fist",i.OpenPalm="open_palm",i.PointingUp="pointing_up",i.ThumbDown="thumb_down",i.ThumbUp="thumb_up",i.Victory="victory",i.ILoveYou="i_love_you",i.None="none",i))(_||{});const Ie=512,De={Closed_Fist:_.ClosedFist,Open_Palm:_.OpenPalm,Pointing_Up:_.PointingUp,Thumb_Down:_.ThumbDown,Thumb_Up:_.ThumbUp,Victory:_.Victory,ILoveYou:_.ILoveYou,None:_.None},_e=15;class Pe extends B{constructor(){super();h(this,"landmarker",null);h(this,"processingTime",null);h(this,"coordinates");h(this,"gesture");h(this,"sourceCanvas");h(this,"downscaler",new X(Ie))}async getGestureData(){if(!this.landmarker||!this.sourceCanvas)return;const e=this.downscaler.draw(this.sourceCanvas),t=performance.now(),n=this.landmarker.recognizeForVideo(e,t),r=performance.now();this.processingTime=r-t;const c=n.landmarks[0],d=[];if(c){const m=n.gestures[0][0].categoryName;return c.forEach(u=>{d.push({x:O(u.x),y:O(1-u.y),z:-u.z})}),{coordinates:d,gesture:De[m]}}return{coordinates:void 0,gesture:void 0}}async processGestureTracking(){if(!this.disposed){if(this.shouldRunInference()){const e=await this.getGestureData();e&&(this.coordinates=e.coordinates,this.gesture=e.gesture)}this.disposed||this.paused||(this.rafId=requestAnimationFrame(this.processGestureTracking.bind(this)))}}resume(){this.paused&&(super.resume(),this.processGestureTracking())}dispose(){if(super.dispose(),this.landmarker){try{this.landmarker.close()}catch{}this.landmarker=null}this.sourceCanvas=void 0,this.downscaler.dispose(),this.coordinates=void 0,this.gesture=void 0}async initialize(){const e=await A.FilesetResolver.forVisionTasks(new URL("/assets/xr/wasm",R.assetStorageEndpoint).toString()),t=await V(new URL("/assets/xr/models/gesture_tracking.task",R.assetStorageEndpoint).toString()),n=await A.GestureRecognizer.createFromOptions(e,{baseOptions:{modelAssetBuffer:t,delegate:"GPU"},runningMode:"VIDEO",numHands:1});this.landmarker=n}async run({sourceCanvas:e,targetFps:t}){this.sourceCanvas=e,this.setTargetFps(t??_e),this.rafId===null&&await this.processGestureTracking()}getModelNode(){const e=this;return{get coordinates(){return e.coordinates},get gesture(){return e.gesture}}}async getPerformanceData(){return{name:this.constructor.name,processingTime:this.processingTime}}}const Oe=512;class Ue extends B{constructor(){super();h(this,"landmarker",null);h(this,"processingTime",null);h(this,"coordinates");h(this,"gesture");h(this,"sourceCanvas");h(this,"downscaler",new X(Oe))}async getHandData(){if(!this.landmarker||!this.sourceCanvas)return;const e=this.downscaler.draw(this.sourceCanvas),t=performance.now(),n=this.landmarker.detectForVideo(e,t),r=performance.now();this.processingTime=r-t;const c=n.landmarks[0],d=[];if(c){const m=n.landmarks[0][0].z<0?"closed_fist":"open_palm";return c.forEach(u=>{d.push({x:O(u.x),y:O(1-u.y),z:-u.z})}),{coordinates:d,gesture:m}}return{coordinates:void 0,gesture:void 0}}async processHandTracking(){if(!this.disposed){if(this.shouldRunInference()){const e=await this.getHandData();e&&(this.coordinates=e.coordinates,this.gesture=e.gesture)}this.disposed||this.paused||(this.rafId=requestAnimationFrame(this.processHandTracking.bind(this)))}}resume(){this.paused&&(super.resume(),this.processHandTracking())}dispose(){if(super.dispose(),this.landmarker){try{this.landmarker.close()}catch{}this.landmarker=null}this.sourceCanvas=void 0,this.downscaler.dispose(),this.coordinates=void 0,this.gesture=void 0}async initialize(){const e=await A.FilesetResolver.forVisionTasks(new URL("/assets/xr/wasm",R.assetStorageEndpoint).toString()),t=await V(new URL("/assets/xr/models/hand_tracking.task",R.assetStorageEndpoint).toString()),n=await A.HandLandmarker.createFromOptions(e,{baseOptions:{modelAssetBuffer:t,delegate:"GPU"},runningMode:"VIDEO",numHands:1});this.landmarker=n}async run({sourceCanvas:e,targetFps:t}){this.sourceCanvas=e,this.setTargetFps(t),this.rafId===null&&await this.processHandTracking()}getModelNode(){const e=this;return{get coordinates(){return e.coordinates},get gesture(){return e.gesture}}}async getPerformanceData(){return{name:this.constructor.name,processingTime:this.processingTime}}}const Le=24,ze=720,Ne=[[255,255,255,255],[0,0,0,0]];class Ve extends B{constructor(){super();h(this,"segmenter",null);h(this,"processingTime",null);h(this,"sourceCanvas");h(this,"processCanvas");h(this,"filterCanvas");h(this,"inputSource");h(this,"inputSourceSize");h(this,"glCanvas");h(this,"drawingUtils");h(this,"useGpuMaskPath",!1);h(this,"maskImageData");h(this,"maskCanvas",null);h(this,"segmentationMaskTexture");h(this,"isMaskSetup",!1);h(this,"isProcessing",!1);h(this,"latestMask",null);h(this,"rawCache",null);h(this,"quality","medium");h(this,"stagingCanvas")}getQualityScaleFactor(){switch(this.quality){case"low":return .5;case"medium":return .75;case"high":return 1;default:return .5}}setInputSource(e){this.inputSource=e,this.inputSourceSize=e?this.readIntrinsicSize(e):void 0}readIntrinsicSize(e){if(e instanceof HTMLVideoElement)return e.videoWidth>0?{width:e.videoWidth,height:e.videoHeight}:void 0;if(e instanceof HTMLImageElement)return e.naturalWidth>0?{width:e.naturalWidth,height:e.naturalHeight}:void 0;const t=e.width,n=e.height;return typeof t=="number"&&t>0&&typeof n=="number"&&n>0?{width:t,height:n}:void 0}ensureProcessCanvasForInput(){if(!this.processCanvas||!this.inputSource)return;const e=this.readIntrinsicSize(this.inputSource);if(!e)return;this.inputSourceSize=e;const t=Math.min(1,ze/Math.max(e.width,e.height)),n=Math.max(1,Math.round(e.width*t)),r=Math.max(1,Math.round(e.height*t));this.processCanvas.width===n&&this.processCanvas.height===r||(this.processCanvas.width=n,this.processCanvas.height=r,this.glCanvas&&(this.glCanvas.width=n,this.glCanvas.height=r),this.maskImageData=void 0)}async processSegmentation(){if(this.disposed||!this.isProcessing||!this.maskCanvas||!this.processCanvas)return;if(!this.shouldRunInference()){if(this.disposed||this.paused)return;this.rafId=requestAnimationFrame(this.processSegmentation.bind(this));return}const e=this.inputSource??this.sourceCanvas;if(!this.segmenter||!e){if(this.disposed||this.paused)return;this.rafId=requestAnimationFrame(this.processSegmentation.bind(this));return}const t=performance.now();this.ensureProcessCanvasForInput();const n=this.processCanvas.getContext("2d");if(n){const d=this.processCanvas.width,m=this.processCanvas.height;if(n.clearRect(0,0,d,m),this.inputSource&&this.inputSourceSize){const{width:u,height:g}=this.inputSourceSize,f=Math.min(d/u,m/g),w=u*f,p=g*f;n.drawImage(this.inputSource,(d-w)/2,(m-p)/2,w,p)}else n.drawImage(e,0,0,d,m)}const c=this.segmenter.segmentForVideo(this.processCanvas,performance.now()).categoryMask;if(!c){if(this.disposed||this.paused)return;this.rafId=requestAnimationFrame(this.processSegmentation.bind(this));return}if(this.rawCache=null,this.latestMask&&(this.latestMask.close(),this.latestMask=null),this.useGpuMaskPath&&this.drawingUtils&&this.glCanvas)this.drawingUtils.drawCategoryMask(c,Ne),this.latestMask=c.clone(),c.close(),this.blitGlToMask();else{this.latestMask=c.clone();const d=this.readMaskToImageData(c);c.close(),d&&this.blitImageDataToMask(d)}this.segmentationMaskTexture&&(this.isMaskSetup||(this.segmentationMaskTexture.format=b.RGBAFormat,this.segmentationMaskTexture.minFilter=b.LinearFilter,this.segmentationMaskTexture.magFilter=b.LinearFilter,this.segmentationMaskTexture.generateMipmaps=!1,this.isMaskSetup=!0),this.segmentationMaskTexture.needsUpdate=!0),this.processingTime=performance.now()-t,!(this.disposed||this.paused)&&(this.rafId=requestAnimationFrame(this.processSegmentation.bind(this)))}blitGlToMask(){if(!this.maskCanvas||!this.filterCanvas||!this.glCanvas)return;const e=this.maskCanvas.getContext("2d"),t=this.filterCanvas.getContext("2d");!e||!t||(t.filter="blur(0.5px)",t.clearRect(0,0,this.filterCanvas.width,this.filterCanvas.height),t.drawImage(this.glCanvas,0,0,this.filterCanvas.width,this.filterCanvas.height),e.clearRect(0,0,this.maskCanvas.width,this.maskCanvas.height),e.drawImage(this.filterCanvas,0,0,this.maskCanvas.width,this.maskCanvas.height))}readMaskToImageData(e){const t=e.getAsUint8Array(),{width:n,height:r}=e;if(!t||n<=0||r<=0)return null;(!this.maskImageData||this.maskImageData.width!==n||this.maskImageData.height!==r)&&(this.maskImageData=new ImageData(n,r));const c=this.maskImageData.data;for(let d=0;d<t.length;d+=1){const m=t[d]===255?0:255;c[d*4]=255,c[d*4+1]=m,c[d*4+2]=255,c[d*4+3]=m}return this.maskImageData}blitImageDataToMask(e){if(!this.maskCanvas||!this.filterCanvas)return;const t=this.maskCanvas.getContext("2d"),n=this.filterCanvas.getContext("2d");if(!t||!n)return;const r=this.getStagingCanvas(e.width,e.height),c=r.getContext("2d");c&&(c.putImageData(e,0,0),n.filter="blur(0.5px)",n.clearRect(0,0,this.filterCanvas.width,this.filterCanvas.height),n.drawImage(r,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))}getStagingCanvas(e,t){return this.stagingCanvas||(this.stagingCanvas=document.createElement("canvas")),this.stagingCanvas.width!==e&&(this.stagingCanvas.width=e),this.stagingCanvas.height!==t&&(this.stagingCanvas.height=t),this.stagingCanvas}resume(){this.paused&&(super.resume(),this.processSegmentation())}dispose(){if(super.dispose(),this.isProcessing=!1,this.latestMask){try{this.latestMask.close()}catch{}this.latestMask=null}if(this.rawCache=null,this.segmenter){try{this.segmenter.close()}catch{}this.segmenter=null}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}async initialize(e){this.quality=(e==null?void 0:e.quality)??"low";const t=await A.FilesetResolver.forVisionTasks(new URL("/assets/xr/wasm",R.assetStorageEndpoint).toString()),n=await V(new URL("/assets/xr/models/segmentation.tflite",R.assetStorageEndpoint).toString());this.glCanvas=new OffscreenCanvas(1,1);const r=this.glCanvas.getContext("webgl2",{preserveDrawingBuffer:!0});this.segmenter=await A.ImageSegmenter.createFromOptions(t,{baseOptions:{modelAssetBuffer:n,delegate:"GPU"},...r?{canvas:this.glCanvas}:{},outputCategoryMask:!0,outputConfidenceMasks:!1,runningMode:"VIDEO"}),r?(this.drawingUtils=new A.DrawingUtils(r),this.useGpuMaskPath=!0):this.useGpuMaskPath=!1}async run({sourceCanvas:e,renderWidth:t,renderHeight:n,targetFps:r}){if(!e)return;this.setTargetFps(r??Le),this.isProcessing=!1,this.rafId!==null&&(cancelAnimationFrame(this.rafId),this.rafId=null);const c=this.getQualityScaleFactor();this.sourceCanvas=e,this.processCanvas=document.createElement("canvas"),this.processCanvas.width=e.width*c,this.processCanvas.height=e.height*c,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=t,this.maskCanvas.height=n,this.filterCanvas=document.createElement("canvas"),this.filterCanvas.width=t,this.filterCanvas.height=n,this.segmentationMaskTexture=new b.CanvasTexture(this.maskCanvas),this.isMaskSetup=!1,this.rawCache=null,this.isProcessing=!0,this.lastInferenceMs=0,this.rafId=requestAnimationFrame(this.processSegmentation.bind(this))}getRawSegmentationData(){if(this.rawCache)return this.rawCache;if(!this.latestMask)return null;const e=this.latestMask.getAsUint8Array();return this.rawCache={maskData:e,width:this.latestMask.width,height:this.latestMask.height},this.rawCache}getModelNode(){const e=this;return{get backgroundSegmentationMask(){return e.segmentationMaskTexture},getMaskCanvas:()=>e.maskCanvas,getRawSegmentationData:()=>e.getRawSegmentationData(),setInputSource:t=>e.setInputSource(t??void 0)}}async getPerformanceData(){return{name:this.constructor.name,processingTime:this.processingTime}}}const J={[P.BACKGROUND_SEGMENTATION]:Ve,[P.HAND_TRACKER]:Ue,[P.GESTURE_TRACKER]:Pe,[P.FACE_TRACKER]:Ee,[P.BODY_TRACKER]:Fe},Be=async i=>{const s=document.createElement("video");s.srcObject=i,s.muted=!0,s.playsInline=!0,s.autoplay=!0,await new Promise(t=>{s.onloadedmetadata=()=>{s.play(),t()}});const e=s;return await new Promise(t=>{const n=setTimeout(t,150),r=()=>{clearTimeout(n),t()};typeof e.requestVideoFrameCallback=="function"?e.requestVideoFrameCallback(r):requestAnimationFrame(()=>requestAnimationFrame(()=>r()))}),s},ee=i=>{const s=new b.CanvasTexture(i);return s.colorSpace=b.SRGBColorSpace,s.format=b.RGBAFormat,s.minFilter=b.LinearFilter,s.magFilter=b.LinearFilter,s.generateMipmaps=!1,s.needsUpdate=!0,s},He=(i,s)=>{const e=i.videoWidth,t=i.videoHeight;e>0&&t>0&&(s.width!==e&&(s.width=e),s.height!==t&&(s.height=t));const n=s.getContext("2d",{colorSpace:"srgb"});n.save(),n.scale(-1,1),n.drawImage(i,-s.width,0,s.width,s.height),n.restore()},qe=(i,s,e=1)=>{const t=s.getContext("2d",{colorSpace:"srgb"}),n=s.width/s.height,r=i.width/i.height;let c,d;r>n?(d=s.height,c=i.width*(s.height/i.height)):(c=s.width,d=i.height*(s.width/i.width));const m=Number.isFinite(e)&&e>0?e:1;c*=m,d*=m;const u=(s.width-c)/2,g=(s.height-d)/2;t.setTransform(1,0,0,1,0,0),t.clearRect(0,0,s.width,s.height),t.drawImage(i,0,0,i.width,i.height,u,g,c,d)},Ke=(i,s,e)=>{const t=new Map;return{acquire:async(g,f,w)=>{let p=t.get(g);if(p)return p.refs.add(f),p.activeRefs.add(f),p.initPromise;const k=s[g];if(!k)throw new Error(`Invalid model: ${g}`);const C=new k,F=new Set([f]),I=new Set([f]),D=(async()=>{await C.initialize(w),e&&await e(g,C);const E=t.get(g);return E&&E.refs.size>0&&i.setPipeline(H=>H.set(g,C)),C})();return p={model:C,refs:F,activeRefs:I,initPromise:D,options:w},t.set(g,p),D.catch(()=>{t.get(g)===p&&(t.delete(g),i.setPipeline(H=>H.delete(g)))}),D},release:(g,f)=>{var k;const w=t.get(g);if(!w||(w.refs.delete(f),w.activeRefs.delete(f)&&w.refs.size>0&&w.activeRefs.size===0&&w.model.pause(),w.refs.size>0))return;t.delete(g);const p=w.model;try{(k=p.dispose)==null||k.call(p)}catch(C){console.warn(`[xr-sdk registry] dispose threw for ${g}`,C)}i.setPipeline(C=>C.delete(g))},setActive:(g,f,w)=>{const p=t.get(g);if(!p||!p.refs.has(f))return;const k=p.activeRefs.size>0;w?p.activeRefs.add(f):p.activeRefs.delete(f);const C=p.activeRefs.size>0;k!==C&&(C?p.model.resume():p.model.pause())},get:g=>{var f;return(f=t.get(g))==null?void 0:f.model},getOptions:g=>{var f;return(f=t.get(g))==null?void 0:f.options},releaseAll:()=>{var g;for(const f of Array.from(t.keys())){const w=t.get(f);if(!w)continue;w.refs.clear(),t.delete(f);const p=w.model;try{(g=p.dispose)==null||g.call(p)}catch(k){console.warn(`[xr-sdk registry] dispose threw for ${f}`,k)}}i.setPipeline(f=>f.clear())}}},We={lifecycle:"idle",ready:!1,error:void 0,cameraTexture:void 0,renderWidth:0,renderHeight:0,source:void 0,sourceKind:void 0,pipeline:new Map},Ge=()=>{let i={...We,pipeline:new Map};const s=new Set,e=()=>{s.forEach(t=>t())};return{getSnapshot:()=>i,set:t=>{let n=!1;for(const r of Object.keys(t))if(t[r]!==i[r]){n=!0;break}n&&(i={...i,...t},e())},setPipeline:t=>{const n=new Map(i.pipeline);return t(n),i={...i,pipeline:n},e(),n},subscribe:t=>(s.add(t),()=>{s.delete(t)})}},Xe=({renderHeight:i,renderWidth:s,videoHeight:e,videoWidth:t})=>({height:i||e,width:s||t}),je=i=>{const s=new Ce({verbose:!0}),e=Ge();let t=i;const n=a=>{var l;const o=(l=U.getOptions(a))==null?void 0:l.targetFps;return typeof o=="number"?o:t==null?void 0:t.targetFps};let r,c,d,m,u,g,f,w,p,k,C=!1,F=!1;const I=new Set,D=new Set,E=async(a,o)=>{if(!I.has(a)&&e.getSnapshot().lifecycle==="running"&&u){I.add(a);try{await o.run({sourceCanvas:u,renderWidth:e.getSnapshot().renderWidth,renderHeight:e.getSnapshot().renderHeight,getSource:()=>e.getSnapshot().sourceKind,targetFps:n(a)}),F&&(await new Promise(l=>requestAnimationFrame(()=>l())),await new Promise(l=>requestAnimationFrame(()=>l())),o.pause())}catch(l){throw I.delete(a),l}}},U=Ke(e,J,(a,o)=>E(a,o));e.subscribe(()=>{if(e.getSnapshot().lifecycle!=="running")return;const a=e.getSnapshot().pipeline;for(const[o,l]of a.entries())I.has(o)||E(o,l)});const L=()=>{if(k!==void 0&&(cancelAnimationFrame(k),k=void 0),c){try{c.pause()}catch{}try{c.srcObject=null}catch{}c=void 0}if(d){try{d.getTracks().forEach(a=>a.stop())}catch{}d=void 0}},j=()=>{if(C||!c||!m||!u)return;const a=window.__xr_debugger_metrics;if(a!=null&&a.trackCameraFrame&&a.trackCameraFrame(),(e.getSnapshot().sourceKind??"webcam")==="webcam")He(c,m);else{const v=m.getContext("2d");if(!v)return;const S=c.videoWidth,M=c.videoHeight;m.width!==S&&(m.width=S),m.height!==M&&(m.height=M),v.setTransform(1,0,0,1,0,0),v.clearRect(0,0,S,M),v.drawImage(c,0,0,S,M)}qe(m,u,(t==null?void 0:t.cameraZoom)??1.2);const l=e.getSnapshot().cameraTexture;l&&(l.needsUpdate=!0)},Y=()=>{if(!c||!m||!u)return;if(F){j();return}const a=()=>{k=requestAnimationFrame(a),j()};k=requestAnimationFrame(a)},ie=async a=>{if(a.source===y.WEBCAM)try{const o=t!=null&&t.camRes&&t.camRes>0?t.camRes:960;return await navigator.mediaDevices.getUserMedia({video:{facingMode:"user",frameRate:{min:24,ideal:30,max:60},width:{ideal:o}}})}catch(o){const l=o instanceof DOMException?o.name:"",v=l==="NotReadableError"||l==="TrackStartError"?"Camera is already in use by another app or browser tab. Close it and refresh.":l==="NotFoundError"||l==="DevicesNotFoundError"?"No camera was found on this device.":l==="NotAllowedError"||l==="PermissionDeniedError"?"Camera access was blocked. Allow camera permissions in your browser, then refresh.":"Unable to access camera. Allow camera permissions in your browser, then refresh.";throw e.set({error:{error:"PermissionError",message:v}}),new x(o instanceof Error?o.message:"getUserMedia failed")}return a.stream},q=async a=>{const o=await ie(a);d=o;const l=await Be(o);c=l,m=new OffscreenCanvas(l.videoWidth,l.videoHeight);const{renderWidth:v,renderHeight:S}=e.getSnapshot(),M=Xe({renderWidth:v,renderHeight:S,videoWidth:l.videoWidth,videoHeight:l.videoHeight});if(u)(u.width!==M.width||u.height!==M.height)&&(u.width=M.width,u.height=M.height);else{u=new OffscreenCanvas(M.width,M.height);const ge=ee(u);e.set({cameraTexture:ge})}const Z=a.source===y.STREAM?a.static===!0:!1;F=Z,r=a.source===y.WEBCAM?{source:y.WEBCAM,sourceKind:"webcam"}:{source:y.STREAM,stream:a.stream,static:Z,sourceKind:a.sourceKind??"webcam"},e.set({source:a.source,sourceKind:r.sourceKind,error:void 0})},K=async a=>{const o=a.sourceKind??"webcam";u=a.canvas;const l=ee(u);e.set({cameraTexture:l,source:y.CANVAS,sourceKind:o,renderWidth:u.width,renderHeight:u.height,error:void 0}),r={source:y.CANVAS,canvas:a.canvas,sourceKind:o}},ae=(a,o)=>!o||a.source!==o.source?!1:a.source===y.STREAM&&o.source===y.STREAM?a.stream===o.stream&&(a.sourceKind??"webcam")===o.sourceKind:!0,ne=async()=>{if(!u)return;const a=e.getSnapshot().pipeline;for(const[,o]of a.entries())o.resume();await new Promise(o=>requestAnimationFrame(()=>o())),await new Promise(o=>requestAnimationFrame(()=>o()));for(const[,o]of a.entries())o.pause()},re=(a,o)=>!o||o.source!==y.CANVAS?!1:a.canvas===o.canvas&&(a.sourceKind??"webcam")===o.sourceKind,oe=async a=>{const o=a.source;if(o!==y.WEBCAM&&o!==y.STREAM)throw new x(`Invalid media source: ${String(o)}`);if(ae(a,r)){s.log("Media source unchanged, skipping rebind.");return}const{lifecycle:l}=e.getSnapshot();if(l==="idle"||l==="stopped"){await q(a),e.set({lifecycle:"media-bound"}),s.log("Media source set to:",a.source);return}if(l==="media-bound"){L(),await q(a),s.log("Media source rebound to:",a.source);return}if(C=!0,await new Promise(v=>requestAnimationFrame(()=>v())),L(),await q(a),C=!1,Y(),F)await ne();else{const v=e.getSnapshot().pipeline;for(const[,S]of v.entries())S.resume()}s.log("Media source swapped to:",a.source)},ce=async a=>{if(re(a,r)){s.log("Frame source unchanged, skipping rebind.");return}const{lifecycle:o}=e.getSnapshot();if(o==="idle"||o==="stopped"){await K(a),e.set({lifecycle:"media-bound"}),s.log("Frame source set to canvas.");return}if(o==="media-bound"){L(),await K(a),s.log("Frame source rebound to canvas.");return}C=!0,await new Promise(l=>requestAnimationFrame(()=>l())),L(),await K(a),C=!1,s.log("Frame source swapped to canvas.")},he=async()=>{const{lifecycle:a}=e.getSnapshot();if(a==="running")return;if(a==="idle")throw new x("session.start() called before setMediaSource — call setMediaSource first");if(!u)throw new x("session.start(): media source not bound");const o=(r==null?void 0:r.source)===y.CANVAS;if(!o&&(!c||!m))throw a==="stopped"?new x("session.start() called from stopped state without a media source — call setMediaSource first"):new x("session.start(): media source not bound");o||Y(),e.set({lifecycle:"running"}),await new Promise(v=>requestAnimationFrame(()=>v()));const l=e.getSnapshot().pipeline;for(const[v,S]of l.entries())await E(v,S);e.set({ready:!0}),s.log("XR session started.")},$=async()=>{const{lifecycle:a}=e.getSnapshot();a==="stopped"||a==="idle"||(L(),e.set({lifecycle:"stopped",ready:!1}),s.log("XR session stopped."))},de=async()=>{await $(),U.releaseAll(),D.clear(),I.clear(),r=void 0,u=void 0,m=void 0,F=!1,e.set({lifecycle:"idle",cameraTexture:void 0,source:void 0}),s.log("XR session reset.")},ue=async a=>{const o="legacy:registerXRPipeline",l=[];await Promise.all(a.map(async v=>{const{model:S}=v;if(!J[S])throw new x(`Invalid model: ${S}`);D.has(S)||l.push(S);const M="options"in v?v.options:void 0;await U.acquire(S,o,M)})),l.length>0&&(l.forEach(v=>D.add(v)),s.log("XR pipeline registered."))},le=a=>{const o=U.get(a);if(!o)throw new x(`Model ${a} is not registered in the pipeline`);return o.getModelNode()},Q=async(a,o)=>{a<=0||o<=0||(e.set({renderWidth:a,renderHeight:o}),u&&(u.width!==a||u.height!==o)&&(u.width=a,u.height=o),s.log(`Source canvas set. Render size: ${a}x${o}`))};return{store:e,registry:U,setMediaSource:oe,start:he,stop:$,reset:de,setFrameSource:ce,registerXRPipeline:ue,getModelNode:le,captureFrame:()=>{if(!g)throw new x("session.captureFrame() called before the XRScene render target was bound — make sure <XRScene> is mounted");if(!f||!w||!p)throw new x("session.captureFrame() called before the R3F state was bound — make sure <XRScene> is mounted");return f.render(w,p),g.toDataURL("image/png")},_setRenderTarget:async a=>{var S;g=a;const o=(S=a.getBoundingClientRect)==null?void 0:S.call(a),l=o&&o.width>0?Math.round(o.width):a.clientWidth,v=o&&o.height>0?Math.round(o.height):a.clientHeight;await Q(l,v)},_setRenderSize:Q,_setR3FState:a=>{f=a.renderer,w=a.scene,p=a.camera},_getVideoElement:()=>c,_setPerf:a=>{if(t=a,e.getSnapshot().lifecycle!=="running"||!u)return;const o=e.getSnapshot().pipeline;for(const[l,v]of o.entries())v.run({sourceCanvas:u,renderWidth:e.getSnapshot().renderWidth,renderHeight:e.getSnapshot().renderHeight,getSource:()=>e.getSnapshot().sourceKind,targetFps:n(l)})}}},Ye=i=>{const s=N.useMemo(()=>je(i),[]),e=JSON.stringify(i??{});return N.useEffect(()=>{s._setPerf(i)},[s,e]),s},se=N.createContext(void 0),$e=()=>{const i=N.useContext(se);if(!i)throw new x("XR context can only be used inside XRProvider, did you forget to wrap your app in <XRProvider>?");return i},Qe=({children:i,perf:s})=>{const e=Ye(s),t=N.useMemo(()=>({session:e}),[e]);return pe.jsx(se.Provider,{value:t,children:i})};exports.RENDER_LAYERS=ve;exports.XRMediaSource=y;exports.XRModel=P;exports.XRProvider=Qe;exports.fetchAndVerify=te;exports.libConfig=R;exports.unprojectToZZero=Se;exports.unprojectToZZeroInto=z;exports.useXRContext=$e;
@@ -0,0 +1 @@
1
+ "use strict";var N=Object.defineProperty;var H=(t,e,r)=>e in t?N(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var i=(t,e,r)=>H(t,typeof e!="symbol"?e+"":e,r);const m=require("react/jsx-runtime"),n=require("react"),z=require("./selectors-Bub0o3qy.cjs"),O=require("./index-PtFmD6B8.cjs"),$=require("@react-three/fiber");require("./hasFullUnitUVBounds-p1Dl0ejX.cjs");const B=({children:t,defaultCollapsed:e=!0,title:r,width:s=320})=>{const[o,a]=n.useState(e);return o?m.jsx("button",{type:"button",onClick:()=>a(!1),"aria-label":`Open ${r}`,title:`Open ${r}`,style:{position:"absolute",right:16,bottom:16,zIndex:40,width:40,height:40,border:"1px solid rgba(255,255,255,0.12)",borderRadius:999,background:"rgba(15, 23, 42, 0.72)",color:"#e5eefb",boxShadow:"0 12px 30px rgba(0,0,0,0.18)",backdropFilter:"blur(10px)",cursor:"pointer",pointerEvents:"auto"},children:"◫"}):m.jsxs("div",{style:{position:"absolute",right:16,bottom:16,zIndex:40,width:s,maxWidth:"calc(100vw - 32px)",padding:14,borderRadius:14,boxShadow:"0 12px 30px rgba(0,0,0,0.26)",backdropFilter:"blur(10px)",pointerEvents:"auto",background:"rgba(15, 23, 42, 0.78)",border:"1px solid rgba(255,255,255,0.12)",color:"#e5eefb"},children:[m.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12,marginBottom:10},children:[m.jsx("div",{style:{fontSize:13,fontWeight:700},children:r}),m.jsx("button",{type:"button",onClick:()=>a(!0),"aria-label":`Close ${r}`,title:`Close ${r}`,style:{width:32,height:32,border:"1px solid rgba(255,255,255,0.12)",borderRadius:999,background:"rgba(255,255,255,0.04)",color:"#e5eefb",cursor:"pointer",flex:"0 0 auto"},children:"×"})]}),t]})};class K{constructor(){i(this,"frameTimestamps",[]);i(this,"lastUpdateTime",0);i(this,"currentFPS",0);i(this,"updateInterval",500);this.lastUpdateTime=performance.now()}trackFrame(){const e=performance.now();this.frameTimestamps.push(e);const r=e-this.updateInterval;this.frameTimestamps=this.frameTimestamps.filter(s=>s>r),e-this.lastUpdateTime>=this.updateInterval&&(this.currentFPS=this.frameTimestamps.length*2,this.lastUpdateTime=e)}getFPS(){return this.currentFPS}reset(){this.frameTimestamps=[],this.lastUpdateTime=performance.now(),this.currentFPS=0}}function V(t,e=1){return t.toFixed(e)}function S(t){return t/(1024*1024)}function W(t,e){return e===0?0:t/e*100}class X{constructor(e=1e3){i(this,"intervalId",null);i(this,"memoryUsage",null);i(this,"updateInterval");i(this,"isSupported",!1);this.updateInterval=e,this.checkSupport()}checkSupport(){const e=performance;this.isSupported="memory"in e&&e.memory!==void 0,this.isSupported||console.warn("[MemoryTracker] performance.memory not available (Chrome-only API)")}start(){if(this.intervalId!==null){console.warn("[MemoryTracker] Already running");return}if(!this.isSupported){this.memoryUsage=null;return}this.updateMemory(),this.intervalId=window.setInterval(()=>{this.updateMemory()},this.updateInterval)}stop(){this.intervalId!==null&&(clearInterval(this.intervalId),this.intervalId=null)}updateMemory(){if(!this.isSupported)return;const e=performance;if(!e.memory)return;const r=e.memory.usedJSHeapSize,s=e.memory.jsHeapSizeLimit;this.memoryUsage={used:S(r),total:S(s),percentage:W(r,s)}}getMemoryUsage(){return this.memoryUsage}isMemorySupported(){return this.isSupported}}class J{constructor(){i(this,"resolution","N/A");i(this,"videoElement",null);i(this,"metadataListener",null)}start(e){if(!e){this.resolution="N/A";return}this.videoElement=e,e.videoWidth>0&&e.videoHeight>0&&this.updateResolution(),this.metadataListener=()=>{this.updateResolution()},e.addEventListener("loadedmetadata",this.metadataListener)}stop(){this.videoElement&&this.metadataListener&&(this.videoElement.removeEventListener("loadedmetadata",this.metadataListener),this.metadataListener=null),this.videoElement=null,this.resolution="N/A"}updateResolution(){if(!this.videoElement){this.resolution="N/A";return}const e=this.videoElement.videoWidth,r=this.videoElement.videoHeight;e>0&&r>0?this.resolution=`${e}x${r}`:this.resolution="N/A"}getResolution(){return this.videoElement&&this.updateResolution(),this.resolution}}class G{constructor(e={}){i(this,"options");i(this,"isRunning",!1);i(this,"metrics",{cameraFPS:0,detectionTime:0,modelPerformance:[],renderTime:0,effectiveFPS:0,memory:null,resolution:"N/A"});i(this,"cameraFPSTracker");i(this,"memoryTracker");i(this,"resolutionTracker");i(this,"frameTimes",[]);i(this,"lastEffectiveFPSUpdate",0);this.options={enableMemoryTracking:e.enableMemoryTracking??!0,memoryUpdateInterval:e.memoryUpdateInterval??1e3},this.cameraFPSTracker=new K,this.memoryTracker=new X(this.options.memoryUpdateInterval),this.resolutionTracker=new J}start(e){if(this.isRunning){console.warn("[MetricsCollector] Already running");return}this.isRunning=!0,this.lastEffectiveFPSUpdate=performance.now(),this.options.enableMemoryTracking&&this.memoryTracker.start(),e&&this.resolutionTracker.start(e),this.setupCameraFPSHook(),console.log("[MetricsCollector] Started")}stop(){this.isRunning&&(this.isRunning=!1,this.memoryTracker.stop(),this.resolutionTracker.stop(),this.cameraFPSTracker.reset(),this.cleanupCameraFPSHook(),console.log("[MetricsCollector] Stopped"))}setupCameraFPSHook(){const e=window;e.__xr_debugger_metrics||(e.__xr_debugger_metrics={trackCameraFrame:()=>{this.cameraFPSTracker.trackFrame(),this.metrics.cameraFPS=this.cameraFPSTracker.getFPS()}})}cleanupCameraFPSHook(){const e=window;e.__xr_debugger_metrics&&delete e.__xr_debugger_metrics}getMetrics(){return this.updateMetricsFromTrackers(),{...this.metrics}}updateMetricsFromTrackers(){this.isRunning&&(this.metrics.memory=this.memoryTracker.getMemoryUsage(),this.metrics.resolution=this.resolutionTracker.getResolution(),this.updateEffectiveFPS())}updateRenderTime(e){this.metrics.renderTime=e,this.updateEffectiveFPS()}async updateDetectionTime(e){if(!e||!this.isRunning){this.metrics.detectionTime=0,this.metrics.modelPerformance=[];return}try{const r=Object.values(e).filter(Boolean);if(r.length===0){this.metrics.detectionTime=0,this.metrics.modelPerformance=[];return}const s=r.map(c=>c&&typeof c.getPerformanceData=="function"?c.getPerformanceData():Promise.resolve({name:"unknown",processingTime:0})),o=await Promise.all(s);this.metrics.modelPerformance=o.map(c=>({name:c.name,processingTime:c.processingTime||0}));const a=o.reduce((c,p)=>c+(p.processingTime||0),0);this.metrics.detectionTime=a,this.updateEffectiveFPS()}catch(r){console.warn("[MetricsCollector] Error updating detection time:",r),this.metrics.detectionTime=0,this.metrics.modelPerformance=[]}}updateEffectiveFPS(){const e=performance.now(),r=this.metrics.detectionTime+this.metrics.renderTime;if(this.frameTimes.push(r),e-this.lastEffectiveFPSUpdate>=1e3){if(this.frameTimes.length>0){const s=this.frameTimes.reduce((o,a)=>o+a,0)/this.frameTimes.length;this.metrics.effectiveFPS=s>0?1e3/s:0}this.frameTimes=[],this.lastEffectiveFPSUpdate=e}}isActive(){return this.isRunning}}const Q=n.lazy(async()=>({default:(await Promise.resolve().then(()=>require("./DebuggerUI-CEfdddkZ.cjs"))).DebuggerUI})),x=n.createContext(null);function Y({children:t,keyboardShortcut:e="ctrl+shift+d",initialEnabled:r=!1,position:s="top-left"}){const[o,a]=n.useState(r),[c,p]=n.useState(!1),[v,_]=n.useState({cameraFPS:0,detectionTime:0,modelPerformance:[],renderTime:0,effectiveFPS:0,memory:null,resolution:"N/A"}),h=n.useRef(null),u=n.useRef(null),{session:g}=O.useXRContext(),T=z.useXRReady();n.useEffect(()=>(h.current||(h.current=new G,window.__xr_metrics_collector=h.current),()=>{h.current&&h.current.stop(),u.current&&clearInterval(u.current),window.__xr_metrics_collector&&delete window.__xr_metrics_collector}),[]),n.useEffect(()=>{const l=h.current;if(l){if(o&&T){const d=g._getVideoElement();l.start(d),u.current=window.setInterval(async()=>{const w=Object.fromEntries(g.store.getSnapshot().pipeline);await l.updateDetectionTime(w);const f=l.getMetrics();_(f)},16)}else l.stop(),u.current&&(clearInterval(u.current),u.current=null);return()=>{u.current&&(clearInterval(u.current),u.current=null)}}},[o,T,g]),n.useEffect(()=>{const l=d=>{const f=e.toLowerCase().split("+"),E=f.includes("ctrl")||f.includes("control"),M=f.includes("shift"),D=f.includes("alt"),I=f[f.length-1],U=E?d.ctrlKey||d.metaKey:!0,j=M?d.shiftKey:!0,L=D?d.altKey:!0,A=d.key.toLowerCase()===I;U&&j&&L&&A&&(d.preventDefault(),a(q=>!q))};return window.addEventListener("keydown",l),()=>{window.removeEventListener("keydown",l)}},[e]);const C=n.useCallback(()=>{a(l=>!l)},[]),F=n.useCallback(()=>{a(!0)},[]),y=n.useCallback(()=>{a(!1)},[]),R={state:{enabled:o,collapsed:c,metrics:v},toggle:C,setCollapsed:p,enable:F,disable:y};return m.jsxs(x.Provider,{value:R,children:[t,o&&m.jsx(n.Suspense,{fallback:null,children:m.jsx(Q,{metrics:v,collapsed:c,onCollapse:p,onClose:y,position:s,keyboardShortcut:e})})]})}function Z(){const t=n.useContext(x);if(!t)throw new Error("useDebuggerContext must be used within a DebuggerProvider");return t}function ee({onUpdate:t}){const e=n.useRef(0),r=n.useRef(!0);return $.useFrame(()=>{if(r.current)r.current=!1;else{const o=performance.now()-e.current;t(o)}e.current=performance.now()},-1e3),null}function k(){const t=Z();return{metrics:t.state.metrics,enabled:t.state.enabled,collapsed:t.state.collapsed,toggle:t.toggle,setCollapsed:t.setCollapsed,enable:t.enable,disable:t.disable}}function te(){const{enabled:t}=k(),e=r=>{const s=window;s.__xr_metrics_collector&&s.__xr_metrics_collector.updateRenderTime(r)};return t?m.jsx(ee,{onUpdate:e}):null}const b=600;function P(){if(typeof window>"u")return;const t=window;return t.__xrCalibrationDebugState||(t.__xrCalibrationDebugState={events:[]}),t.__xrCalibrationDebugState}function re(t,e,r){const s=P();s&&(s.events.push({source:t,label:e,payload:r,ts:performance.now()}),s.events.length>b&&s.events.splice(0,s.events.length-b))}function se(t=b){const e=P();return e?e.events.slice(Math.max(0,e.events.length-t)):[]}exports.DebuggerOverlay=te;exports.DebuggerProvider=Y;exports.XRDebugView=B;exports.formatNumber=V;exports.readCalibrationDebugEvents=se;exports.recordCalibrationDebugEvent=re;exports.useDebugger=k;