@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.
- package/GROUNDING.md +537 -0
- package/LICENSE +7 -0
- package/README.md +85 -0
- package/dist/DebuggerUI-CEfdddkZ.cjs +1 -0
- package/dist/DebuggerUI-Dgop6Q6o.js +269 -0
- package/dist/audio/AudioEngine.d.ts +98 -0
- package/dist/audio/index.d.ts +34 -0
- package/dist/components/AspectRatioContainer/index.d.ts +10 -0
- package/dist/components/BodyTracker/index.d.ts +15 -0
- package/dist/components/Debugger/DebuggerProvider.d.ts +22 -0
- package/dist/components/Debugger/DebuggerUI.d.ts +13 -0
- package/dist/components/Debugger/index.d.ts +38 -0
- package/dist/components/Debugger/styles.d.ts +19 -0
- package/dist/components/FaceMesh/FaceMesh.d.ts +26 -0
- package/dist/components/FaceMesh/canonical/CanonicalFaceMeshRenderer.d.ts +34 -0
- package/dist/components/FaceMesh/canonical/parseCanonicalFaceModel.d.ts +16 -0
- package/dist/components/FaceMesh/canonical/useCanonicalFaceMesh.d.ts +15 -0
- package/dist/components/FaceMesh/deform.d.ts +36 -0
- package/dist/components/FaceMesh/index.d.ts +6 -0
- package/dist/components/FaceMesh/indices.d.ts +1 -0
- package/dist/components/FaceMesh/material/blendModes.d.ts +2 -0
- package/dist/components/FaceMesh/material/defaults.d.ts +3 -0
- package/dist/components/FaceMesh/material/index.d.ts +5 -0
- package/dist/components/FaceMesh/material/options.d.ts +25 -0
- package/dist/components/FaceMesh/material/support.d.ts +3 -0
- package/dist/components/FaceMesh/material/types.d.ts +23 -0
- package/dist/components/FaceMesh/uv.d.ts +1 -0
- package/dist/components/FaceRetouch/Background.d.ts +16 -0
- package/dist/components/FaceRetouch/index.d.ts +6 -0
- package/dist/components/FaceRetouch/landmarkMask.d.ts +23 -0
- package/dist/components/FaceRetouch/retouchRegions.d.ts +23 -0
- package/dist/components/FaceRetouch/useFaceRetouchMask.d.ts +14 -0
- package/dist/components/FaceRetouch/useFaceRetouchRegions.d.ts +12 -0
- package/dist/components/FaceTracker/BoundingBoxOverlay.d.ts +20 -0
- package/dist/components/FaceTracker/index.d.ts +54 -0
- package/dist/components/GestureTracker/index.d.ts +31 -0
- package/dist/components/GestureTrigger/index.d.ts +3 -0
- package/dist/components/HandTracker/index.d.ts +24 -0
- package/dist/components/HeadBinding/index.d.ts +31 -0
- package/dist/components/HeadBindingOccluder/index.d.ts +36 -0
- package/dist/components/HeadOccluder/index.d.ts +13 -0
- package/dist/components/Panel/index.d.ts +71 -0
- package/dist/components/PerspectiveCamera/index.d.ts +14 -0
- package/dist/components/ScreenSpaceUI/ScreenTransform.d.ts +54 -0
- package/dist/components/ScreenSpaceUI/context.d.ts +29 -0
- package/dist/components/ScreenSpaceUI/index.d.ts +40 -0
- package/dist/components/Segmentation/index.d.ts +44 -0
- package/dist/components/SpriteAnimation/index.d.ts +52 -0
- package/dist/components/TextLabel/index.d.ts +62 -0
- package/dist/components/TrackingAnchor/index.d.ts +74 -0
- package/dist/components/VideoBackground/index.d.ts +38 -0
- package/dist/components/XRCompositor/index.d.ts +5 -0
- package/dist/components/XRDebugView/index.d.ts +6 -0
- package/dist/components/XRLayer/index.d.ts +6 -0
- package/dist/components/XRMediaSurface/index.d.ts +27 -0
- package/dist/components/XRProvider/index.d.ts +13 -0
- package/dist/components/XRScene/defaults.d.ts +4 -0
- package/dist/components/XRScene/index.d.ts +15 -0
- package/dist/components/XRViewport/index.d.ts +101 -0
- package/dist/components/index.d.ts +26 -0
- package/dist/config/index.d.ts +8 -0
- package/dist/constants/index.d.ts +25 -0
- package/dist/constants/renderLayers.d.ts +25 -0
- package/dist/entries/all.d.ts +15 -0
- package/dist/entries/core.d.ts +21 -0
- package/dist/entries/face-effects.d.ts +19 -0
- package/dist/entries/internal.d.ts +16 -0
- package/dist/entries/low-level.d.ts +30 -0
- package/dist/entries/tracking.d.ts +15 -0
- package/dist/face-effects.cjs +252 -0
- package/dist/face-effects.js +3542 -0
- package/dist/hasFullUnitUVBounds-BGvcFsQM.js +26 -0
- package/dist/hasFullUnitUVBounds-p1Dl0ejX.cjs +1 -0
- package/dist/hooks/faceResults.d.ts +39 -0
- package/dist/hooks/selectors.d.ts +33 -0
- package/dist/hooks/useCalibrationFaceTracker.d.ts +23 -0
- package/dist/hooks/useDebugger/index.d.ts +25 -0
- package/dist/hooks/useDebugger/types.d.ts +20 -0
- package/dist/hooks/useFaceBoundingBox.d.ts +11 -0
- package/dist/hooks/useFaceResults.d.ts +31 -0
- package/dist/hooks/useGestureEdge.d.ts +53 -0
- package/dist/hooks/useMediaRecorder.d.ts +40 -0
- package/dist/hooks/useTrackerContext.d.ts +35 -0
- package/dist/hooks/useXRModel.d.ts +15 -0
- package/dist/hooks/useXRSession/constants.d.ts +4 -0
- package/dist/hooks/useXRSession/facade.d.ts +39 -0
- package/dist/hooks/useXRSession/fns.d.ts +5 -0
- package/dist/hooks/useXRSession/index.d.ts +4 -0
- package/dist/hooks/useXRSession/registry.d.ts +52 -0
- package/dist/hooks/useXRSession/store.d.ts +40 -0
- package/dist/index-B5J4gzn2.cjs +1 -0
- package/dist/index-BD-JWMjE.js +1991 -0
- package/dist/index-BVBVg96G.cjs +1 -0
- package/dist/index-CYMj26Ej.js +1331 -0
- package/dist/index-DtwHElmG.js +157 -0
- package/dist/index-PtFmD6B8.cjs +1 -0
- package/dist/internal-DH5d1Xnq.cjs +1 -0
- package/dist/internal-KOKJDxCG.js +519 -0
- package/dist/internal.cjs +1 -0
- package/dist/internal.js +14 -0
- package/dist/low-level.cjs +1 -0
- package/dist/low-level.js +941 -0
- package/dist/main.cjs +1 -0
- package/dist/main.js +612 -0
- package/dist/models/Base/index.d.ts +25 -0
- package/dist/models/Body/index.d.ts +22 -0
- package/dist/models/Face/constants.d.ts +2 -0
- package/dist/models/Face/index.d.ts +45 -0
- package/dist/models/Face/landmarksData.d.ts +2 -0
- package/dist/models/Hand/GestureTracking.d.ts +21 -0
- package/dist/models/Hand/HandTracking.d.ts +21 -0
- package/dist/models/Segmentation/index.d.ts +75 -0
- package/dist/models/index.d.ts +5 -0
- package/dist/modules/XRClient/index.d.ts +9 -0
- package/dist/modules/index.d.ts +1 -0
- package/dist/selectors-BHO6TnoC.js +59 -0
- package/dist/selectors-Bub0o3qy.cjs +1 -0
- package/dist/services/ApiService.d.ts +12 -0
- package/dist/services/MetricsCollector/CameraFPSTracker.d.ts +25 -0
- package/dist/services/MetricsCollector/MemoryTracker.d.ts +43 -0
- package/dist/services/MetricsCollector/RenderTimeTracker.d.ts +10 -0
- package/dist/services/MetricsCollector/ResolutionTracker.d.ts +26 -0
- package/dist/services/MetricsCollector/index.d.ts +59 -0
- package/dist/services/MetricsCollector/types.d.ts +47 -0
- package/dist/services/MetricsCollector/utils.d.ts +65 -0
- package/dist/texture/computeContainScale.d.ts +25 -0
- package/dist/texture/hasFullUnitUVBounds.d.ts +37 -0
- package/dist/texture/types.d.ts +20 -0
- package/dist/tracking.cjs +1 -0
- package/dist/tracking.js +344 -0
- package/dist/types/body.d.ts +3 -0
- package/dist/types/client.d.ts +3 -0
- package/dist/types/common.d.ts +9 -0
- package/dist/types/compositor.d.ts +23 -0
- package/dist/types/debugger.d.ts +83 -0
- package/dist/types/face.d.ts +67 -0
- package/dist/types/gesture-tracking.d.ts +15 -0
- package/dist/types/hand-tracking.d.ts +5 -0
- package/dist/types/headBinding.d.ts +67 -0
- package/dist/types/index.d.ts +12 -0
- package/dist/types/logger.d.ts +4 -0
- package/dist/types/model.d.ts +46 -0
- package/dist/types/nodes.d.ts +35 -0
- package/dist/types/segmentation.d.ts +31 -0
- package/dist/types/session.d.ts +102 -0
- package/dist/types/tracking.d.ts +30 -0
- package/dist/types/util-types.d.ts +1 -0
- package/dist/useFaceResults-cpsSmKKc.js +81 -0
- package/dist/useFaceResults-hVUJYSEY.cjs +1 -0
- package/dist/utils/calibrationDebug.d.ts +9 -0
- package/dist/utils/dataURL.d.ts +6 -0
- package/dist/utils/drawMediaCover.d.ts +18 -0
- package/dist/utils/errors.d.ts +3 -0
- package/dist/utils/fns.d.ts +48 -0
- package/dist/utils/headBinding.d.ts +85 -0
- package/dist/utils/integrity.d.ts +43 -0
- package/dist/utils/landmarkBounds.d.ts +11 -0
- package/dist/utils/logger.d.ts +7 -0
- package/package.json +113 -0
|
@@ -0,0 +1,519 @@
|
|
|
1
|
+
var B = Object.defineProperty;
|
|
2
|
+
var K = (t, e, r) => e in t ? B(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r;
|
|
3
|
+
var s = (t, e, r) => K(t, typeof e != "symbol" ? e + "" : e, r);
|
|
4
|
+
import { jsx as f, jsxs as y } from "react/jsx-runtime";
|
|
5
|
+
import O, { useState as p, useRef as g, useEffect as v, useCallback as T, createContext as W, Suspense as X, lazy as V } from "react";
|
|
6
|
+
import { b as q } from "./selectors-BHO6TnoC.js";
|
|
7
|
+
import { u as J } from "./index-CYMj26Ej.js";
|
|
8
|
+
import { useFrame as G } from "@react-three/fiber";
|
|
9
|
+
import "./hasFullUnitUVBounds-BGvcFsQM.js";
|
|
10
|
+
const fe = ({
|
|
11
|
+
children: t,
|
|
12
|
+
defaultCollapsed: e = !0,
|
|
13
|
+
title: r,
|
|
14
|
+
width: i = 320
|
|
15
|
+
}) => {
|
|
16
|
+
const [n, o] = p(e);
|
|
17
|
+
return n ? /* @__PURE__ */ f(
|
|
18
|
+
"button",
|
|
19
|
+
{
|
|
20
|
+
type: "button",
|
|
21
|
+
onClick: () => o(!1),
|
|
22
|
+
"aria-label": `Open ${r}`,
|
|
23
|
+
title: `Open ${r}`,
|
|
24
|
+
style: {
|
|
25
|
+
position: "absolute",
|
|
26
|
+
right: 16,
|
|
27
|
+
bottom: 16,
|
|
28
|
+
zIndex: 40,
|
|
29
|
+
width: 40,
|
|
30
|
+
height: 40,
|
|
31
|
+
border: "1px solid rgba(255,255,255,0.12)",
|
|
32
|
+
borderRadius: 999,
|
|
33
|
+
background: "rgba(15, 23, 42, 0.72)",
|
|
34
|
+
color: "#e5eefb",
|
|
35
|
+
boxShadow: "0 12px 30px rgba(0,0,0,0.18)",
|
|
36
|
+
backdropFilter: "blur(10px)",
|
|
37
|
+
cursor: "pointer",
|
|
38
|
+
pointerEvents: "auto"
|
|
39
|
+
},
|
|
40
|
+
children: "◫"
|
|
41
|
+
}
|
|
42
|
+
) : /* @__PURE__ */ y(
|
|
43
|
+
"div",
|
|
44
|
+
{
|
|
45
|
+
style: {
|
|
46
|
+
position: "absolute",
|
|
47
|
+
right: 16,
|
|
48
|
+
bottom: 16,
|
|
49
|
+
zIndex: 40,
|
|
50
|
+
width: i,
|
|
51
|
+
maxWidth: "calc(100vw - 32px)",
|
|
52
|
+
padding: 14,
|
|
53
|
+
borderRadius: 14,
|
|
54
|
+
boxShadow: "0 12px 30px rgba(0,0,0,0.26)",
|
|
55
|
+
backdropFilter: "blur(10px)",
|
|
56
|
+
pointerEvents: "auto",
|
|
57
|
+
background: "rgba(15, 23, 42, 0.78)",
|
|
58
|
+
border: "1px solid rgba(255,255,255,0.12)",
|
|
59
|
+
color: "#e5eefb"
|
|
60
|
+
},
|
|
61
|
+
children: [
|
|
62
|
+
/* @__PURE__ */ y(
|
|
63
|
+
"div",
|
|
64
|
+
{
|
|
65
|
+
style: {
|
|
66
|
+
display: "flex",
|
|
67
|
+
alignItems: "center",
|
|
68
|
+
justifyContent: "space-between",
|
|
69
|
+
gap: 12,
|
|
70
|
+
marginBottom: 10
|
|
71
|
+
},
|
|
72
|
+
children: [
|
|
73
|
+
/* @__PURE__ */ f("div", { style: { fontSize: 13, fontWeight: 700 }, children: r }),
|
|
74
|
+
/* @__PURE__ */ f(
|
|
75
|
+
"button",
|
|
76
|
+
{
|
|
77
|
+
type: "button",
|
|
78
|
+
onClick: () => o(!0),
|
|
79
|
+
"aria-label": `Close ${r}`,
|
|
80
|
+
title: `Close ${r}`,
|
|
81
|
+
style: {
|
|
82
|
+
width: 32,
|
|
83
|
+
height: 32,
|
|
84
|
+
border: "1px solid rgba(255,255,255,0.12)",
|
|
85
|
+
borderRadius: 999,
|
|
86
|
+
background: "rgba(255,255,255,0.04)",
|
|
87
|
+
color: "#e5eefb",
|
|
88
|
+
cursor: "pointer",
|
|
89
|
+
flex: "0 0 auto"
|
|
90
|
+
},
|
|
91
|
+
children: "×"
|
|
92
|
+
}
|
|
93
|
+
)
|
|
94
|
+
]
|
|
95
|
+
}
|
|
96
|
+
),
|
|
97
|
+
t
|
|
98
|
+
]
|
|
99
|
+
}
|
|
100
|
+
);
|
|
101
|
+
};
|
|
102
|
+
class Q {
|
|
103
|
+
// 500ms as per PRD
|
|
104
|
+
constructor() {
|
|
105
|
+
s(this, "frameTimestamps", []);
|
|
106
|
+
s(this, "lastUpdateTime", 0);
|
|
107
|
+
s(this, "currentFPS", 0);
|
|
108
|
+
s(this, "updateInterval", 500);
|
|
109
|
+
this.lastUpdateTime = performance.now();
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Track a new frame
|
|
113
|
+
* Should be called on each camera frame from renderVideo loop
|
|
114
|
+
*/
|
|
115
|
+
trackFrame() {
|
|
116
|
+
const e = performance.now();
|
|
117
|
+
this.frameTimestamps.push(e);
|
|
118
|
+
const r = e - this.updateInterval;
|
|
119
|
+
this.frameTimestamps = this.frameTimestamps.filter((i) => i > r), e - this.lastUpdateTime >= this.updateInterval && (this.currentFPS = this.frameTimestamps.length * 2, this.lastUpdateTime = e);
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Get current FPS value
|
|
123
|
+
*/
|
|
124
|
+
getFPS() {
|
|
125
|
+
return this.currentFPS;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Reset tracker state
|
|
129
|
+
*/
|
|
130
|
+
reset() {
|
|
131
|
+
this.frameTimestamps = [], this.lastUpdateTime = performance.now(), this.currentFPS = 0;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
function he(t, e = 1) {
|
|
135
|
+
return t.toFixed(e);
|
|
136
|
+
}
|
|
137
|
+
function _(t) {
|
|
138
|
+
return t / (1024 * 1024);
|
|
139
|
+
}
|
|
140
|
+
function Y(t, e) {
|
|
141
|
+
return e === 0 ? 0 : t / e * 100;
|
|
142
|
+
}
|
|
143
|
+
class Z {
|
|
144
|
+
constructor(e = 1e3) {
|
|
145
|
+
s(this, "intervalId", null);
|
|
146
|
+
s(this, "memoryUsage", null);
|
|
147
|
+
s(this, "updateInterval");
|
|
148
|
+
s(this, "isSupported", !1);
|
|
149
|
+
this.updateInterval = e, this.checkSupport();
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Check if performance.memory is supported
|
|
153
|
+
*/
|
|
154
|
+
checkSupport() {
|
|
155
|
+
const e = performance;
|
|
156
|
+
this.isSupported = "memory" in e && e.memory !== void 0, this.isSupported || console.warn("[MemoryTracker] performance.memory not available (Chrome-only API)");
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Start tracking memory usage
|
|
160
|
+
*/
|
|
161
|
+
start() {
|
|
162
|
+
if (this.intervalId !== null) {
|
|
163
|
+
console.warn("[MemoryTracker] Already running");
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
if (!this.isSupported) {
|
|
167
|
+
this.memoryUsage = null;
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
this.updateMemory(), this.intervalId = window.setInterval(() => {
|
|
171
|
+
this.updateMemory();
|
|
172
|
+
}, this.updateInterval);
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Stop tracking memory usage
|
|
176
|
+
*/
|
|
177
|
+
stop() {
|
|
178
|
+
this.intervalId !== null && (clearInterval(this.intervalId), this.intervalId = null);
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Update memory measurements
|
|
182
|
+
*/
|
|
183
|
+
updateMemory() {
|
|
184
|
+
if (!this.isSupported) return;
|
|
185
|
+
const e = performance;
|
|
186
|
+
if (!e.memory) return;
|
|
187
|
+
const r = e.memory.usedJSHeapSize, i = e.memory.jsHeapSizeLimit;
|
|
188
|
+
this.memoryUsage = {
|
|
189
|
+
used: _(r),
|
|
190
|
+
total: _(i),
|
|
191
|
+
percentage: Y(r, i)
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Get current memory usage
|
|
196
|
+
* Returns null if performance.memory is not supported
|
|
197
|
+
*/
|
|
198
|
+
getMemoryUsage() {
|
|
199
|
+
return this.memoryUsage;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Check if memory tracking is supported
|
|
203
|
+
*/
|
|
204
|
+
isMemorySupported() {
|
|
205
|
+
return this.isSupported;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
class ee {
|
|
209
|
+
constructor() {
|
|
210
|
+
s(this, "resolution", "N/A");
|
|
211
|
+
s(this, "videoElement", null);
|
|
212
|
+
s(this, "metadataListener", null);
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Start tracking resolution from a video element
|
|
216
|
+
*/
|
|
217
|
+
start(e) {
|
|
218
|
+
if (!e) {
|
|
219
|
+
this.resolution = "N/A";
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
this.videoElement = e, e.videoWidth > 0 && e.videoHeight > 0 && this.updateResolution(), this.metadataListener = () => {
|
|
223
|
+
this.updateResolution();
|
|
224
|
+
}, e.addEventListener("loadedmetadata", this.metadataListener);
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Stop tracking and clean up listeners
|
|
228
|
+
*/
|
|
229
|
+
stop() {
|
|
230
|
+
this.videoElement && this.metadataListener && (this.videoElement.removeEventListener("loadedmetadata", this.metadataListener), this.metadataListener = null), this.videoElement = null, this.resolution = "N/A";
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Update resolution from video element
|
|
234
|
+
*/
|
|
235
|
+
updateResolution() {
|
|
236
|
+
if (!this.videoElement) {
|
|
237
|
+
this.resolution = "N/A";
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
const e = this.videoElement.videoWidth, r = this.videoElement.videoHeight;
|
|
241
|
+
e > 0 && r > 0 ? this.resolution = `${e}x${r}` : this.resolution = "N/A";
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Get current resolution string (e.g., "1280x720")
|
|
245
|
+
*/
|
|
246
|
+
getResolution() {
|
|
247
|
+
return this.videoElement && this.updateResolution(), this.resolution;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
class te {
|
|
251
|
+
constructor(e = {}) {
|
|
252
|
+
s(this, "options");
|
|
253
|
+
s(this, "isRunning", !1);
|
|
254
|
+
// Current metrics state
|
|
255
|
+
s(this, "metrics", {
|
|
256
|
+
cameraFPS: 0,
|
|
257
|
+
detectionTime: 0,
|
|
258
|
+
modelPerformance: [],
|
|
259
|
+
renderTime: 0,
|
|
260
|
+
effectiveFPS: 0,
|
|
261
|
+
memory: null,
|
|
262
|
+
resolution: "N/A"
|
|
263
|
+
});
|
|
264
|
+
// Trackers
|
|
265
|
+
s(this, "cameraFPSTracker");
|
|
266
|
+
s(this, "memoryTracker");
|
|
267
|
+
s(this, "resolutionTracker");
|
|
268
|
+
// For effective FPS calculation
|
|
269
|
+
s(this, "frameTimes", []);
|
|
270
|
+
s(this, "lastEffectiveFPSUpdate", 0);
|
|
271
|
+
this.options = {
|
|
272
|
+
enableMemoryTracking: e.enableMemoryTracking ?? !0,
|
|
273
|
+
memoryUpdateInterval: e.memoryUpdateInterval ?? 1e3
|
|
274
|
+
}, this.cameraFPSTracker = new Q(), this.memoryTracker = new Z(this.options.memoryUpdateInterval), this.resolutionTracker = new ee();
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Start collecting metrics
|
|
278
|
+
* @param videoElement Optional video element for resolution tracking
|
|
279
|
+
*/
|
|
280
|
+
start(e) {
|
|
281
|
+
if (this.isRunning) {
|
|
282
|
+
console.warn("[MetricsCollector] Already running");
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
this.isRunning = !0, this.lastEffectiveFPSUpdate = performance.now(), this.options.enableMemoryTracking && this.memoryTracker.start(), e && this.resolutionTracker.start(e), this.setupCameraFPSHook(), console.log("[MetricsCollector] Started");
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Stop collecting metrics and clean up
|
|
289
|
+
*/
|
|
290
|
+
stop() {
|
|
291
|
+
this.isRunning && (this.isRunning = !1, this.memoryTracker.stop(), this.resolutionTracker.stop(), this.cameraFPSTracker.reset(), this.cleanupCameraFPSHook(), console.log("[MetricsCollector] Stopped"));
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Setup global hook for camera FPS tracking
|
|
295
|
+
* This allows useXRSession to call trackFrame() without tight coupling
|
|
296
|
+
*/
|
|
297
|
+
setupCameraFPSHook() {
|
|
298
|
+
const e = window;
|
|
299
|
+
e.__xr_debugger_metrics || (e.__xr_debugger_metrics = {
|
|
300
|
+
trackCameraFrame: () => {
|
|
301
|
+
this.cameraFPSTracker.trackFrame(), this.metrics.cameraFPS = this.cameraFPSTracker.getFPS();
|
|
302
|
+
}
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Cleanup global hook
|
|
307
|
+
*/
|
|
308
|
+
cleanupCameraFPSHook() {
|
|
309
|
+
const e = window;
|
|
310
|
+
e.__xr_debugger_metrics && delete e.__xr_debugger_metrics;
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Get current metrics snapshot
|
|
314
|
+
* Updates metrics from all trackers before returning
|
|
315
|
+
*/
|
|
316
|
+
getMetrics() {
|
|
317
|
+
return this.updateMetricsFromTrackers(), { ...this.metrics };
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* Update metrics from all trackers
|
|
321
|
+
*/
|
|
322
|
+
updateMetricsFromTrackers() {
|
|
323
|
+
this.isRunning && (this.metrics.memory = this.memoryTracker.getMemoryUsage(), this.metrics.resolution = this.resolutionTracker.getResolution(), this.updateEffectiveFPS());
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Update render time (called from RenderTimeTracker component)
|
|
327
|
+
*/
|
|
328
|
+
updateRenderTime(e) {
|
|
329
|
+
this.metrics.renderTime = e, this.updateEffectiveFPS();
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Update detection time from models
|
|
333
|
+
* Aggregates processing time from all active models in the XR pipeline
|
|
334
|
+
*/
|
|
335
|
+
async updateDetectionTime(e) {
|
|
336
|
+
if (!e || !this.isRunning) {
|
|
337
|
+
this.metrics.detectionTime = 0, this.metrics.modelPerformance = [];
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
try {
|
|
341
|
+
const r = Object.values(e).filter(Boolean);
|
|
342
|
+
if (r.length === 0) {
|
|
343
|
+
this.metrics.detectionTime = 0, this.metrics.modelPerformance = [];
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
const i = r.map((a) => a && typeof a.getPerformanceData == "function" ? a.getPerformanceData() : Promise.resolve({ name: "unknown", processingTime: 0 })), n = await Promise.all(i);
|
|
347
|
+
this.metrics.modelPerformance = n.map((a) => ({
|
|
348
|
+
name: a.name,
|
|
349
|
+
processingTime: a.processingTime || 0
|
|
350
|
+
}));
|
|
351
|
+
const o = n.reduce((a, h) => a + (h.processingTime || 0), 0);
|
|
352
|
+
this.metrics.detectionTime = o, this.updateEffectiveFPS();
|
|
353
|
+
} catch (r) {
|
|
354
|
+
console.warn("[MetricsCollector] Error updating detection time:", r), this.metrics.detectionTime = 0, this.metrics.modelPerformance = [];
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* Update effective FPS calculation
|
|
359
|
+
* (will be implemented in Phase 6)
|
|
360
|
+
*/
|
|
361
|
+
updateEffectiveFPS() {
|
|
362
|
+
const e = performance.now(), r = this.metrics.detectionTime + this.metrics.renderTime;
|
|
363
|
+
if (this.frameTimes.push(r), e - this.lastEffectiveFPSUpdate >= 1e3) {
|
|
364
|
+
if (this.frameTimes.length > 0) {
|
|
365
|
+
const i = this.frameTimes.reduce((n, o) => n + o, 0) / this.frameTimes.length;
|
|
366
|
+
this.metrics.effectiveFPS = i > 0 ? 1e3 / i : 0;
|
|
367
|
+
}
|
|
368
|
+
this.frameTimes = [], this.lastEffectiveFPSUpdate = e;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* Check if collector is running
|
|
373
|
+
*/
|
|
374
|
+
isActive() {
|
|
375
|
+
return this.isRunning;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
const re = V(async () => ({ default: (await import("./DebuggerUI-Dgop6Q6o.js")).DebuggerUI })), F = W(null);
|
|
379
|
+
function pe({
|
|
380
|
+
children: t,
|
|
381
|
+
keyboardShortcut: e = "ctrl+shift+d",
|
|
382
|
+
initialEnabled: r = !1,
|
|
383
|
+
position: i = "top-left"
|
|
384
|
+
}) {
|
|
385
|
+
const [n, o] = p(r), [a, h] = p(!1), [S, R] = p({
|
|
386
|
+
cameraFPS: 0,
|
|
387
|
+
detectionTime: 0,
|
|
388
|
+
modelPerformance: [],
|
|
389
|
+
renderTime: 0,
|
|
390
|
+
effectiveFPS: 0,
|
|
391
|
+
memory: null,
|
|
392
|
+
resolution: "N/A"
|
|
393
|
+
}), d = g(null), l = g(null), { session: b } = J(), k = q();
|
|
394
|
+
v(() => (d.current || (d.current = new te(), window.__xr_metrics_collector = d.current), () => {
|
|
395
|
+
d.current && d.current.stop(), l.current && clearInterval(l.current), window.__xr_metrics_collector && delete window.__xr_metrics_collector;
|
|
396
|
+
}), []), v(() => {
|
|
397
|
+
const c = d.current;
|
|
398
|
+
if (c) {
|
|
399
|
+
if (n && k) {
|
|
400
|
+
const u = b._getVideoElement();
|
|
401
|
+
c.start(u), l.current = window.setInterval(async () => {
|
|
402
|
+
const x = Object.fromEntries(b.store.getSnapshot().pipeline);
|
|
403
|
+
await c.updateDetectionTime(x);
|
|
404
|
+
const m = c.getMetrics();
|
|
405
|
+
R(m);
|
|
406
|
+
}, 16);
|
|
407
|
+
} else
|
|
408
|
+
c.stop(), l.current && (clearInterval(l.current), l.current = null);
|
|
409
|
+
return () => {
|
|
410
|
+
l.current && (clearInterval(l.current), l.current = null);
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
}, [n, k, b]), v(() => {
|
|
414
|
+
const c = (u) => {
|
|
415
|
+
const m = e.toLowerCase().split("+"), D = m.includes("ctrl") || m.includes("control"), U = m.includes("shift"), L = m.includes("alt"), A = m[m.length - 1], N = D ? u.ctrlKey || u.metaKey : !0, H = U ? u.shiftKey : !0, z = L ? u.altKey : !0, j = u.key.toLowerCase() === A;
|
|
416
|
+
N && H && z && j && (u.preventDefault(), o(($) => !$));
|
|
417
|
+
};
|
|
418
|
+
return window.addEventListener("keydown", c), () => {
|
|
419
|
+
window.removeEventListener("keydown", c);
|
|
420
|
+
};
|
|
421
|
+
}, [e]);
|
|
422
|
+
const E = T(() => {
|
|
423
|
+
o((c) => !c);
|
|
424
|
+
}, []), M = T(() => {
|
|
425
|
+
o(!0);
|
|
426
|
+
}, []), P = T(() => {
|
|
427
|
+
o(!1);
|
|
428
|
+
}, []), I = {
|
|
429
|
+
state: {
|
|
430
|
+
enabled: n,
|
|
431
|
+
collapsed: a,
|
|
432
|
+
metrics: S
|
|
433
|
+
},
|
|
434
|
+
toggle: E,
|
|
435
|
+
setCollapsed: h,
|
|
436
|
+
enable: M,
|
|
437
|
+
disable: P
|
|
438
|
+
};
|
|
439
|
+
return /* @__PURE__ */ y(F.Provider, { value: I, children: [
|
|
440
|
+
t,
|
|
441
|
+
n && /* @__PURE__ */ f(X, { fallback: null, children: /* @__PURE__ */ f(
|
|
442
|
+
re,
|
|
443
|
+
{
|
|
444
|
+
metrics: S,
|
|
445
|
+
collapsed: a,
|
|
446
|
+
onCollapse: h,
|
|
447
|
+
onClose: P,
|
|
448
|
+
position: i,
|
|
449
|
+
keyboardShortcut: e
|
|
450
|
+
}
|
|
451
|
+
) })
|
|
452
|
+
] });
|
|
453
|
+
}
|
|
454
|
+
function ie() {
|
|
455
|
+
const t = O.useContext(F);
|
|
456
|
+
if (!t)
|
|
457
|
+
throw new Error("useDebuggerContext must be used within a DebuggerProvider");
|
|
458
|
+
return t;
|
|
459
|
+
}
|
|
460
|
+
function se({ onUpdate: t }) {
|
|
461
|
+
const e = g(0), r = g(!0);
|
|
462
|
+
return G(() => {
|
|
463
|
+
if (r.current)
|
|
464
|
+
r.current = !1;
|
|
465
|
+
else {
|
|
466
|
+
const n = performance.now() - e.current;
|
|
467
|
+
t(n);
|
|
468
|
+
}
|
|
469
|
+
e.current = performance.now();
|
|
470
|
+
}, -1e3), null;
|
|
471
|
+
}
|
|
472
|
+
function ne() {
|
|
473
|
+
const t = ie();
|
|
474
|
+
return {
|
|
475
|
+
metrics: t.state.metrics,
|
|
476
|
+
enabled: t.state.enabled,
|
|
477
|
+
collapsed: t.state.collapsed,
|
|
478
|
+
toggle: t.toggle,
|
|
479
|
+
setCollapsed: t.setCollapsed,
|
|
480
|
+
enable: t.enable,
|
|
481
|
+
disable: t.disable
|
|
482
|
+
};
|
|
483
|
+
}
|
|
484
|
+
function ge() {
|
|
485
|
+
const { enabled: t } = ne(), e = (r) => {
|
|
486
|
+
const i = window;
|
|
487
|
+
i.__xr_metrics_collector && i.__xr_metrics_collector.updateRenderTime(r);
|
|
488
|
+
};
|
|
489
|
+
return t ? /* @__PURE__ */ f(se, { onUpdate: e }) : null;
|
|
490
|
+
}
|
|
491
|
+
const w = 600;
|
|
492
|
+
function C() {
|
|
493
|
+
if (typeof window > "u")
|
|
494
|
+
return;
|
|
495
|
+
const t = window;
|
|
496
|
+
return t.__xrCalibrationDebugState || (t.__xrCalibrationDebugState = { events: [] }), t.__xrCalibrationDebugState;
|
|
497
|
+
}
|
|
498
|
+
function be(t, e, r) {
|
|
499
|
+
const i = C();
|
|
500
|
+
i && (i.events.push({
|
|
501
|
+
source: t,
|
|
502
|
+
label: e,
|
|
503
|
+
payload: r,
|
|
504
|
+
ts: performance.now()
|
|
505
|
+
}), i.events.length > w && i.events.splice(0, i.events.length - w));
|
|
506
|
+
}
|
|
507
|
+
function ve(t = w) {
|
|
508
|
+
const e = C();
|
|
509
|
+
return e ? e.events.slice(Math.max(0, e.events.length - t)) : [];
|
|
510
|
+
}
|
|
511
|
+
export {
|
|
512
|
+
pe as D,
|
|
513
|
+
fe as X,
|
|
514
|
+
ge as a,
|
|
515
|
+
be as b,
|
|
516
|
+
he as f,
|
|
517
|
+
ve as r,
|
|
518
|
+
ne as u
|
|
519
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./internal-DH5d1Xnq.cjs"),r=require("./hasFullUnitUVBounds-p1Dl0ejX.cjs"),n=require("./index-PtFmD6B8.cjs");exports.DebuggerOverlay=e.DebuggerOverlay;exports.DebuggerProvider=e.DebuggerProvider;exports.XRDebugView=e.XRDebugView;exports.readCalibrationDebugEvents=e.readCalibrationDebugEvents;exports.recordCalibrationDebugEvent=e.recordCalibrationDebugEvent;exports.useDebugger=e.useDebugger;exports._resetUVBoundsWarnings=r._resetUVBoundsWarnings;exports.logUVBoundsWarningOnce=r.logUVBoundsWarningOnce;exports.RENDER_LAYERS=n.RENDER_LAYERS;
|
package/dist/internal.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { a, D as s, X as o, r as g, b as n, u } from "./internal-KOKJDxCG.js";
|
|
2
|
+
import { _ as i, l as t } from "./hasFullUnitUVBounds-BGvcFsQM.js";
|
|
3
|
+
import { R as d } from "./index-CYMj26Ej.js";
|
|
4
|
+
export {
|
|
5
|
+
a as DebuggerOverlay,
|
|
6
|
+
s as DebuggerProvider,
|
|
7
|
+
d as RENDER_LAYERS,
|
|
8
|
+
o as XRDebugView,
|
|
9
|
+
i as _resetUVBoundsWarnings,
|
|
10
|
+
t as logUVBoundsWarningOnce,
|
|
11
|
+
g as readCalibrationDebugEvents,
|
|
12
|
+
n as recordCalibrationDebugEvent,
|
|
13
|
+
u as useDebugger
|
|
14
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const H=require("./index-B5J4gzn2.cjs"),M=require("./selectors-Bub0o3qy.cjs"),c=require("react"),_=require("./useFaceResults-hVUJYSEY.cjs"),D=require("./index-PtFmD6B8.cjs"),fe=require("./hasFullUnitUVBounds-p1Dl0ejX.cjs"),U=require("./index-BVBVg96G.cjs"),l=require("react/jsx-runtime"),me=require("@react-three/drei"),ge={position:"absolute",top:-28,left:0,background:"rgba(34, 197, 94, 0.9)",color:"#04130a",fontFamily:"Menlo, Monaco, Consolas, monospace",fontSize:12,fontWeight:700,padding:"4px 8px",whiteSpace:"nowrap"},pe=({boundingBox:e,label:t="face bounding box",color:r="#22c55e",style:o,labelStyle:n})=>l.jsx("div",{style:{position:"absolute",left:`${e.left*100}%`,top:`${e.top*100}%`,width:`${e.width*100}%`,height:`${e.height*100}%`,border:`3px solid ${r}`,boxSizing:"border-box",pointerEvents:"none",zIndex:20,...o},children:t!==null&&l.jsx("div",{style:{...ge,...n},children:t})}),be=e=>{const{makeDefault:t=!0,...r}=e,o={position:[0,0,40],fov:30,near:.1,far:1e3,makeDefault:t,...r};return l.jsx(me.PerspectiveCamera,{...o})},xe=({background:e="#000",children:t,style:r})=>l.jsx("div",{style:{position:"fixed",inset:0,overflow:"hidden",background:e,...r},children:t}),T=({children:e,config:t,style:r})=>l.jsx("div",{"data-render-target":t.name,style:{position:"absolute",inset:0,overflow:"hidden",background:t.clearColor,pointerEvents:t.pointerEvents??"none",zIndex:t.zIndex,opacity:t.hidden?0:1,...r},children:e}),K=({canvas:e,layout:t,media:r,mirrored:o,filter:n})=>{const i=Math.round(t.destination.width),s=Math.round(t.destination.height);e.width!==i&&(e.width=i),e.height!==s&&(e.height=s);const a=e.getContext("2d");a&&(a.setTransform(1,0,0,1,0,0),a.clearRect(0,0,i,s),o&&(a.translate(i,0),a.scale(-1,1)),n&&(a.filter=n),a.drawImage(r,t.offsetX,t.offsetY,t.drawWidth,t.drawHeight),n&&(a.filter="none"),a.setTransform(1,0,0,1,0,0))},ne=({canvasRef:e,enabled:t=!0,fps:r=30,imageRef:o,layout:n,mirrored:i,sourceKind:s,videoRef:a})=>{c.useEffect(()=>{if(!t){const b=e.current,u=b==null?void 0:b.getContext("2d");b&&u&&u.clearRect(0,0,b.width,b.height);return}let m=0,g=0;const h=r>0?1e3/r:0,p=b=>{if(m=requestAnimationFrame(p),h>0&&b-g<h)return;g=b;const u=e.current;if(!u||!n)return;if(s==="image"){const w=o.current;if(!w||!w.complete||w.naturalWidth<=0||w.naturalHeight<=0)return;K({canvas:u,layout:n,media:w,mirrored:i});return}const x=a.current;!x||x.readyState<2||x.videoWidth<=0||x.videoHeight<=0||K({canvas:u,layout:n,media:x,mirrored:i})};return m=requestAnimationFrame(p),()=>{cancelAnimationFrame(m)}},[e,t,r,o,n,i,s,a])},re=({canvasRef:e,imageRef:t,layer:r,layout:o,mirrored:n,sourceKind:i,videoRef:s})=>(ne({canvasRef:e,imageRef:t,layout:o,mirrored:n,sourceKind:i,videoRef:s}),l.jsx(T,{config:r,children:l.jsx("canvas",{ref:e,style:{position:"absolute",inset:0,width:"100%",height:"100%",display:"block",background:"#000"}})})),we=({canvasRef:e,controlInsetTop:t,debugVisible:r,fps:o=15,imageRef:n,layer:i,layout:s,mirrored:a,sourceKind:m,videoRef:g,viewportSize:h})=>{ne({canvasRef:e,enabled:r,fps:o,imageRef:n,layout:s,mirrored:a,sourceKind:m,videoRef:g});const p=Math.min(220,Math.max(120,h.width*.22)),b=h.width>0&&h.height>0?h.width/h.height:1,u=Math.min(h.height-24,Math.max(t??16,16));return l.jsx(T,{config:i,children:l.jsx("canvas",{ref:e,style:{position:"absolute",left:16,top:u,width:r?p:1,height:r?"auto":1,aspectRatio:`${b}`,opacity:r?.85:0,borderRadius:10,border:r?"1px solid rgba(255,255,255,0.16)":"none",pointerEvents:"none",objectFit:"contain",background:"#000"}})})},ve=5,Re=1,ie=(e,t)=>t,ye="brightness(2.2) contrast(1.5) saturate(1.25)",ae=({enabled:e,displayMirrored:t,imageRef:r,layout:o,mode:n,numFaces:i,selectedSource:s,sourceStream:a,videoRef:m})=>{const{session:g}=D.useXRContext(),h=c.useRef(null),p=c.useRef(!1),b=c.useRef(document.createElement("canvas")),{ready:u,node:x,error:w}=H.useXRModel(D.XRModel.FACE_TRACKER,{numFaces:i??(n==="head-binding"?Re:ve)}),[E,v]=c.useState("idle"),[k,F]=c.useState(null),I=e&&u&&!!x,z=_.useFaceResults({node:I?x:null,enabled:I,selectedSource:s,onFrame:c.useCallback(()=>{F(null),v("ready")},[])});return c.useEffect(()=>{if(!e||!o)return;const f=()=>{const R=s==="image"?r.current:m.current;if(R){if(R instanceof HTMLImageElement){if(!R.complete||R.naturalWidth<=0||R.naturalHeight<=0)return}else if(R.readyState<2||R.videoWidth<=0||R.videoHeight<=0)return;K({canvas:b.current,layout:o,media:R,mirrored:t,filter:s==="webcam"?ye:void 0})}};if(s==="image"){f();return}let d=0;const y=()=>{d=requestAnimationFrame(y),f()};return d=requestAnimationFrame(y),()=>cancelAnimationFrame(d)},[t,e,r,o,s,m]),c.useEffect(()=>{var j;if(!e){v("idle"),F(null),p.current=!1,h.current=null;return}if(!o){v("initializing");return}const f=(a==null?void 0:a.id)??(((j=m.current)==null?void 0:j.srcObject)instanceof MediaStream?m.current.srcObject.id:"none"),y=s==="webcam"?`webcam:${f}`:s;h.current!==y&&(p.current=!1,h.current=y);let R=!1;return(async()=>{try{if(v("initializing"),p.current||(await g.setFrameSource({canvas:b.current,sourceKind:s}),await g.start(),p.current=!0),R)return;F(null),v("initializing")}catch(C){if(R)return;v("error"),F(C instanceof Error?C.message:"Failed to initialize SDK face tracking")}})(),()=>{R=!0}},[e,o,s,g,a,m]),c.useEffect(()=>{!I&&e&&!w&&v("initializing")},[I,e,w]),c.useEffect(()=>{w&&(v("error"),F(w.message))},[w]),c.useEffect(()=>()=>{p.current=!1,g.stop()},[g]),{activeDelegate:"GPU",faces:z,status:E,error:k}},oe=c.createContext(null),Se={audio:!1,video:{facingMode:"user",frameRate:{ideal:30,max:60}}},Ce={name:"viewport-live",clearColor:"#000000",pointerEvents:"none",zIndex:0},Ee={name:"viewport-ui",clearColor:"transparent",pointerEvents:"auto",zIndex:5},Fe={name:"viewport-scene",clearColor:"transparent",pointerEvents:"auto",zIndex:1},X={webcam:{icon:"◉",label:"Webcam"},image:{icon:"▣",label:"Images"},video:{icon:"▶",label:"Videos"}},O=({children:e})=>l.jsx(l.Fragment,{children:e});O.displayName="XRViewport.Scene";const Y=({children:e})=>l.jsx(l.Fragment,{children:e});Y.displayName="XRViewport.Overlay";const Ie=e=>{if(!e)return{width:0,height:0};const t=e.getBoundingClientRect();return{width:t.width||e.clientWidth,height:t.height||e.clientHeight}},Me=e=>{const[t,r]=c.useState({width:0,height:0});return c.useLayoutEffect(()=>{const o=e.current;if(!o)return;let n=0;const i=()=>{const g=Ie(o);r(h=>h.width===g.width&&h.height===g.height?h:g)};i(),n=requestAnimationFrame(i);const s=new ResizeObserver(()=>{i(),n&&cancelAnimationFrame(n),n=requestAnimationFrame(i)});s.observe(o);const a=window.visualViewport,m=()=>{i(),n&&cancelAnimationFrame(n),n=requestAnimationFrame(i)};return window.addEventListener("resize",m),window.addEventListener("orientationchange",m),a==null||a.addEventListener("resize",m),a==null||a.addEventListener("scroll",m),()=>{n&&cancelAnimationFrame(n),s.disconnect(),window.removeEventListener("resize",m),window.removeEventListener("orientationchange",m),a==null||a.removeEventListener("resize",m),a==null||a.removeEventListener("scroll",m)}},[e]),t},Q=e=>{e&&(e.pause(),e.removeAttribute("src"),e.srcObject=null,e.load())},Z=e=>{e&&e.removeAttribute("src")},je=({enabled:e,imageAsset:t,selectedSource:r,videoAsset:o})=>{const n=c.useRef(null),i=c.useRef(null),[s,a]=c.useState(null),[m,g]=c.useState({width:0,height:0}),[h,p]=c.useState("idle"),[b,u]=c.useState(null);return c.useEffect(()=>{if(!e){Q(n.current),Z(i.current),a(null),g({width:0,height:0}),p("idle"),u(null);return}let x=!1,w=null;const E=(f,d)=>{x||(g({width:f,height:d}),p("ready"),u(null))},v=()=>{Q(n.current),Z(i.current),w==null||w.getTracks().forEach(f=>f.stop()),w=null,a(null)},k=async()=>{p("requesting");const f=await navigator.mediaDevices.getUserMedia(Se);if(x){f.getTracks().forEach(y=>y.stop());return}w=f,a(f);const d=n.current;d&&(d.srcObject=f,d.muted=!0,d.playsInline=!0,d.autoplay=!0,await d.play(),E(d.videoWidth,d.videoHeight))},F=async f=>{p("requesting"),a(null);const d=n.current;d&&(d.src=f,d.muted=!0,d.loop=!0,d.playsInline=!0,d.autoplay=!0,d.crossOrigin="anonymous",await d.play(),E(d.videoWidth,d.videoHeight))},I=async f=>{p("requesting"),a(null);const d=i.current;d&&(await new Promise((y,R)=>{d.onload=()=>y(),d.onerror=()=>R(new Error("Unable to load image")),d.src=f}),E(d.naturalWidth,d.naturalHeight))};return v(),(async()=>{try{if(r==="webcam"){await k();return}if(r==="video"){if(!(o!=null&&o.src))throw new Error("Missing video source");await F(o.src);return}if(!(t!=null&&t.src))throw new Error("Missing image source");await I(t.src)}catch(f){if(x)return;p("error"),u(f instanceof Error?f.message:`Unable to initialize ${r}`)}})(),()=>{x=!0,v()}},[e,t,r,o]),{videoRef:n,imageRef:i,stream:s,mediaSize:m,status:h,error:b}},Xe=(e,t)=>e==="auto"?t==="webcam"?"cover":"contain":e,ke=({imageOptions:e,initialImageId:t,initialSource:r,initialVideoId:o,source:n,videoOptions:i})=>{var h,p,b,u;const s=(n==null?void 0:n.kind)??r??"webcam",a=s==="image"&&e.length===0||s==="video"&&i.length===0?"webcam":s,m=(n==null?void 0:n.kind)==="image"?n.assetId??((h=e[0])==null?void 0:h.id)??"":t??((p=e[0])==null?void 0:p.id)??"",g=(n==null?void 0:n.kind)==="video"?n.assetId??((b=i[0])==null?void 0:b.id)??"":o??((u=i[0])==null?void 0:u.id)??"";return{selectedSource:a,selectedImageId:m,selectedVideoId:g}},Te=(e,t,r)=>{if(e.width<=0||e.height<=0||t.width<=0||t.height<=0)return null;const o=r==="contain"?Math.min(t.width/e.width,t.height/e.height):Math.max(t.width/e.width,t.height/e.height),n=e.width*o,i=e.height*o,s=(t.width-n)*.5,a=(t.height-i)*.5;return{source:e,destination:t,drawWidth:n,drawHeight:i,offsetX:s,offsetY:a,scale:o}},ze=(e,t)=>{if(e==="dom")return{sceneContent:null,overlayContent:t};let r=null,o=null;const n=[];return c.Children.forEach(t,i=>{var a;if(!c.isValidElement(i)){i!=null&&n.push(i);return}const s=(a=i.type)==null?void 0:a.displayName;if(s===O.displayName){r=i.props.children;return}if(s===Y.displayName){o=i.props.children;return}n.push(i)}),!o&&n.length>0&&(o=n),{sceneContent:r,overlayContent:o}},ee=(e,t)=>typeof e=="function"?e(t):e,Ae=()=>c.useContext(oe),Le=({imageRef:e,selectedSource:t,videoRef:r})=>l.jsxs(l.Fragment,{children:[l.jsx("video",{ref:r,style:{position:"absolute",width:1,height:1,opacity:t==="image"?0:.001,pointerEvents:"none"}}),l.jsx("img",{ref:e,alt:"",style:{position:"absolute",width:1,height:1,opacity:t==="image"?.001:0,pointerEvents:"none"}})]}),te=({dock:e,label:t,onChange:r,options:o,value:n})=>l.jsx("div",{style:{position:"absolute",top:e==="top-left"?74:void 0,bottom:e==="bottom-left"?74:void 0,left:16,zIndex:5,maxWidth:"calc(100vw - 32px)",padding:10,borderRadius:14,background:"rgba(15, 23, 42, 0.72)",border:"1px solid rgba(255,255,255,0.12)",boxShadow:"0 12px 30px rgba(0,0,0,0.18)",backdropFilter:"blur(10px)"},children:l.jsxs("label",{style:{display:"grid",gap:6,color:"#e5eefb",fontSize:12,fontWeight:700},children:[l.jsx("span",{children:t}),l.jsx("select",{value:n,onChange:i=>r(i.target.value),style:{minWidth:180,maxWidth:"calc(100vw - 52px)",height:36,borderRadius:10,border:"1px solid rgba(255,255,255,0.12)",background:"rgba(255,255,255,0.06)",color:"#e5eefb",padding:"0 10px"},children:o.map(i=>l.jsx("option",{value:i.id,style:{color:"#111827"},children:i.label},i.id))})]})}),Be=({dock:e,imageOptions:t,selectedImageId:r,selectedSource:o,selectedVideoId:n,setSelectedImageId:i,setSelectedSource:s,setSelectedVideoId:a,showMediaControls:m,videoOptions:g})=>{const[h,p]=c.useState(!1),b=["webcam","image","video"].filter(u=>u==="image"?t.length>0:u==="video"?g.length>0:!0);return m?h?l.jsx("button",{type:"button",onClick:()=>p(!1),"aria-label":"Open media controls",title:"Open media controls",style:{position:"absolute",top:e==="top-left"?16:void 0,bottom:e==="bottom-left"?16:void 0,left:16,zIndex:5,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"},children:"≡"}):l.jsxs(l.Fragment,{children:[l.jsxs("div",{style:{position:"absolute",top:e==="top-left"?16:void 0,bottom:e==="bottom-left"?16:void 0,left:16,zIndex:5,display:"inline-flex",alignItems:"center",gap:8,maxWidth:"calc(100vw - 32px)"},children:[l.jsx("div",{style:{display:"inline-flex",alignItems:"center",gap:8,padding:8,borderRadius:999,background:"rgba(15, 23, 42, 0.72)",border:"1px solid rgba(255,255,255,0.12)",boxShadow:"0 12px 30px rgba(0,0,0,0.18)",backdropFilter:"blur(10px)",overflowX:"auto"},children:b.map(u=>{const x=u===o;return l.jsxs("button",{type:"button",onClick:()=>s(u),"aria-pressed":x,title:X[u].label,style:{border:"none",borderRadius:999,minWidth:42,height:42,padding:"0 12px",display:"inline-flex",alignItems:"center",justifyContent:"center",gap:8,background:x?"rgba(56, 189, 248, 0.18)":"rgba(255,255,255,0.04)",color:x?"#e0f2fe":"rgba(229,238,251,0.82)",cursor:"pointer",flex:"0 0 auto"},children:[l.jsx("span",{style:{fontSize:14,lineHeight:1},children:X[u].icon}),l.jsx("span",{style:{fontSize:12,fontWeight:700,letterSpacing:"0.01em"},children:X[u].label})]},u)})}),l.jsx("button",{type:"button",onClick:()=>p(!0),"aria-label":"Close media controls",title:"Close media controls",style:{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",flex:"0 0 auto"},children:"×"})]}),o==="image"&&t.length>0&&l.jsx(te,{dock:e,label:"Image Asset",options:t,value:r,onChange:i}),o==="video"&&g.length>0&&l.jsx(te,{dock:e,label:"Video Asset",options:g,value:n,onChange:a})]}):null},We=({enabled:e,selectedSource:t})=>{const r=M.useXRModelNode(D.XRModel.FACE_TRACKER);return{faces:_.useFaceResults({node:r,enabled:e,selectedSource:t}),trackerStatus:r?"ready":"idle"}},G=({children:e,fitMode:t="auto",imageOptions:r=[],initialImageId:o,initialMirrored:n=!0,initialSource:i="webcam",initialVideoId:s,mediaStrategy:a="internal",mediaDock:m="bottom-left",mode:g="dom",showMediaControlsByDefault:h=!0,source:p,style:b,videoOptions:u=[]})=>{const x=c.useRef(null),w=c.useRef(null),E=Me(x),v=c.useMemo(()=>ke({imageOptions:r,initialImageId:o,initialSource:i,initialVideoId:s,source:p,videoOptions:u}),[r,o,i,s,p,u]),[k,F]=c.useState(n),[I,z]=c.useState(h),[f,d]=c.useState(v.selectedSource),[y,R]=c.useState(v.selectedImageId),[A,j]=c.useState(v.selectedVideoId),C=a==="internal";c.useEffect(()=>{p&&(d(v.selectedSource),R(v.selectedImageId),j(v.selectedVideoId))},[v,p]);const L=r.find(P=>P.id===y)??r[0],B=u.find(P=>P.id===A)??u[0],S=je({enabled:C,imageAsset:L,selectedSource:f,videoAsset:B}),$=Xe(t,f),W=c.useMemo(()=>Te(S.mediaSize,E,$),[S.mediaSize,$,E]),N=ie(f,k),q=ae({displayMirrored:N,enabled:C&&S.status==="ready"&&W!==null,imageRef:S.imageRef,layout:W,selectedSource:f,sourceStream:S.stream,videoRef:S.videoRef}),J=We({enabled:!C,selectedSource:f}),se=f==="image"?`${X.image.label}: ${(L==null?void 0:L.label)??""}`:f==="video"?`${X.video.label}: ${(B==null?void 0:B.label)??""}`:X.webcam.label,V={activeDelegate:C?q.activeDelegate:null,faces:C?q.faces:J.faces,imageOptions:r,layout:W,mediaError:S.error,mediaFitMode:$,mediaLabel:se,mediaStatus:S.status,mirrored:N,selectedImageId:y,selectedSource:f,selectedVideoId:A,setMirrored:F,setSelectedImageId:R,setSelectedSource:d,setSelectedVideoId:j,setShowMediaControls:z,showMediaControls:I,trackerError:C?q.error:null,trackerStatus:C?q.status:J.trackerStatus,videoOptions:u,viewportSize:E,mediaSize:S.mediaSize},le=typeof e=="function"?e(V):e,{sceneContent:ce,overlayContent:de}=ze(g,le),ue=ee(ce,V),he=ee(de,V);return l.jsx(oe.Provider,{value:V,children:l.jsxs("div",{ref:x,style:{position:"fixed",inset:0,overflow:"hidden",background:"#000",...b},children:[l.jsx(Le,{imageRef:S.imageRef,selectedSource:f,videoRef:S.videoRef}),g==="dom"&&C&&l.jsx(re,{canvasRef:w,imageRef:S.imageRef,videoRef:S.videoRef,layer:Ce,layout:W,mirrored:N,sourceKind:f==="image"?"image":"video"}),(g==="r3f"||g==="hybrid")&&l.jsx(T,{config:Fe,children:l.jsx(U.XRScene,{renderTargetSize:E,style:{width:"100%",height:"100%"},children:ue})}),l.jsxs(T,{config:Ee,children:[C&&l.jsx(Be,{dock:m,imageOptions:r,selectedImageId:y,selectedSource:f,selectedVideoId:A,setSelectedImageId:R,setSelectedSource:d,setSelectedVideoId:j,showMediaControls:I,videoOptions:u}),he]})]})})};G.Scene=O;G.Overlay=Y;const qe=e=>{const[t,r]=c.useState(null);return c.useEffect(()=>{let o=0;const n=()=>{var m,g;o=requestAnimationFrame(n);const i=(g=(m=e==null?void 0:e.detectionResults)==null?void 0:m.faceLandmarks)==null?void 0:g[0];if(!i||i.length===0){r(null);return}const s=_.computeLandmarkBounds(i),a={left:s.minX,top:s.minY,width:s.width,height:s.height};r(h=>h&&h.left===a.left&&h.top===a.top&&h.width===a.width&&h.height===a.height?h:a)};return n(),()=>{cancelAnimationFrame(o)}},[e]),t},Ve=["fill","contain"];exports.HeadTracker=H.HeadTracker;exports.useTrackerContext=H.useTrackerContext;exports.useXRModel=H.useXRModel;exports.useXRCameraTexture=M.useXRCameraTexture;exports.useXRError=M.useXRError;exports.useXRModelNode=M.useXRModelNode;exports.useXRPipelineSnapshot=M.useXRPipelineSnapshot;exports.useXRReady=M.useXRReady;exports.useXRRenderSize=M.useXRRenderSize;exports.computeLandmarkBounds=_.computeLandmarkBounds;exports.useXRContext=D.useXRContext;exports.hasFullUnitUVBounds=fe.hasFullUnitUVBounds;exports.ScreenRectAspectContext=U.ScreenRectAspectContext;exports.computeScreenTransform=U.computeScreenTransform;exports.useScreenSpace=U.useScreenSpace;exports.BoundingBoxOverlay=pe;exports.PerspectiveCamera=be;exports.TEXTURE_FITS=Ve;exports.XRCompositor=xe;exports.XRLayer=T;exports.XRMediaSurface=re;exports.XRTrackingOverlay=we;exports.XRViewport=G;exports.resolveCalibrationFaceDisplayMirrored=ie;exports.useCalibrationFaceTracker=ae;exports.useFaceBoundingBox=qe;exports.useXRViewportState=Ae;
|