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

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 (106) hide show
  1. package/GROUNDING.md +232 -14
  2. package/dist/{DebuggerUI-CEfdddkZ.cjs → DebuggerUI-CatYc-RG.cjs} +1 -1
  3. package/dist/{DebuggerUI-Dgop6Q6o.js → DebuggerUI-gLMKiVwJ.js} +1 -1
  4. package/dist/MediaSourceSwitcher-C-xYg0nQ.js +317 -0
  5. package/dist/MediaSourceSwitcher-Cq3g4IKw.cjs +31 -0
  6. package/dist/components/FaceMesh/canonical/CanonicalFaceMeshRenderer.d.ts +6 -1
  7. package/dist/components/FaceMesh/material/defaults.d.ts +4 -0
  8. package/dist/components/FaceMesh/material/types.d.ts +2 -0
  9. package/dist/components/FaceRetouch/Background.d.ts +6 -1
  10. package/dist/components/FaceRetouch/defaults.d.ts +13 -0
  11. package/dist/components/FaceRetouch/index.d.ts +3 -1
  12. package/dist/components/FaceRetouch/landmarkMask.d.ts +4 -1
  13. package/dist/components/FaceRetouch/useFaceRetouchMask.d.ts +2 -1
  14. package/dist/components/FaceWarp3D/FaceWarp3DHead.d.ts +15 -0
  15. package/dist/components/FaceWarp3D/defaults.d.ts +37 -0
  16. package/dist/components/FaceWarp3D/index.d.ts +3 -0
  17. package/dist/components/FaceWarp3D/warp.d.ts +13 -0
  18. package/dist/components/HandJoints2D/index.d.ts +6 -0
  19. package/dist/components/HandTracker/index.d.ts +2 -2
  20. package/dist/components/HandTracking2D/HandVisual.d.ts +12 -0
  21. package/dist/components/HandTracking2D/index.d.ts +5 -0
  22. package/dist/components/HandTracking2DController/index.d.ts +5 -0
  23. package/dist/components/HandTracking3D/index.d.ts +6 -0
  24. package/dist/components/ScreenImage/index.d.ts +87 -0
  25. package/dist/components/ScreenText/index.d.ts +20 -0
  26. package/dist/components/TextLabel/index.d.ts +99 -0
  27. package/dist/components/XRScene/index.d.ts +14 -3
  28. package/dist/components/XRViewport/index.d.ts +17 -0
  29. package/dist/components/index.d.ts +7 -0
  30. package/dist/debug-ui/default-setting/index.d.ts +37 -0
  31. package/dist/debug-ui/default-setting.cjs +21 -0
  32. package/dist/debug-ui/default-setting.js +777 -0
  33. package/dist/debug-ui/face-warp-3d/index.d.ts +6 -0
  34. package/dist/debug-ui/hand-joints-2d/index.d.ts +6 -0
  35. package/dist/debug-ui/hand-tracking-2d/index.d.ts +6 -0
  36. package/dist/debug-ui/hand-tracking-2d-controller/index.d.ts +6 -0
  37. package/dist/debug-ui/hand-tracking-3d/index.d.ts +6 -0
  38. package/dist/debug-ui/index.d.ts +23 -0
  39. package/dist/debug-ui/layer-panel/index.d.ts +17 -0
  40. package/dist/debug-ui/media-source/MediaSourceSwitcher.d.ts +10 -0
  41. package/dist/debug-ui/media-source/index.d.ts +4 -0
  42. package/dist/debug-ui/media-source/media-preset.d.ts +9 -0
  43. package/dist/debug-ui/media-source.cjs +1 -0
  44. package/dist/debug-ui/media-source.js +7 -0
  45. package/dist/debug-ui/screen-image-settings/index.d.ts +7 -0
  46. package/dist/debug-ui/screen-text-settings/index.d.ts +122 -0
  47. package/dist/debug-ui/settings-panel/index.d.ts +38 -0
  48. package/dist/debug-ui/shared/MaterialSection.d.ts +13 -0
  49. package/dist/debug-ui/shared/ScreenTransformSection.d.ts +29 -0
  50. package/dist/debug-ui.cjs +20 -0
  51. package/dist/debug-ui.js +6063 -0
  52. package/dist/defaults-BLpcN3pG.cjs +1 -0
  53. package/dist/defaults-LtY4M7dg.js +55 -0
  54. package/dist/entries/core.d.ts +5 -1
  55. package/dist/entries/face-effects.d.ts +2 -0
  56. package/dist/entries/low-level.d.ts +3 -0
  57. package/dist/face-effects.cjs +113 -23
  58. package/dist/face-effects.js +1566 -1399
  59. package/dist/handJoints2d.d.ts +49 -0
  60. package/dist/handTracking2d.d.ts +33 -0
  61. package/dist/handTracking2dController.d.ts +65 -0
  62. package/dist/handTracking3d.d.ts +52 -0
  63. package/dist/{index-BD-JWMjE.js → index-BGNbrc4C.js} +113 -137
  64. package/dist/index-BXyObVHF.cjs +1 -0
  65. package/dist/index-CY3bUAcW.js +12 -0
  66. package/dist/index-C_Duh13c.cjs +1 -0
  67. package/dist/index-D8fpPQkC.cjs +1 -0
  68. package/dist/index-DxshgBu0.cjs +1 -0
  69. package/dist/index-O-2crZ3M.js +1102 -0
  70. package/dist/{index-CYMj26Ej.js → index-safCs_af.js} +426 -416
  71. package/dist/{internal-DH5d1Xnq.cjs → internal-BjyhBP8i.cjs} +1 -1
  72. package/dist/{internal-KOKJDxCG.js → internal-Cae1ps15.js} +3 -3
  73. package/dist/internal.cjs +1 -1
  74. package/dist/internal.js +2 -2
  75. package/dist/layerStack.d.ts +29 -0
  76. package/dist/low-level.cjs +1 -1
  77. package/dist/low-level.js +74 -890
  78. package/dist/main.cjs +73 -1
  79. package/dist/main.js +1656 -407
  80. package/dist/models/Hand/HandTracking.d.ts +2 -0
  81. package/dist/screen2d/index.d.ts +4 -0
  82. package/dist/screen2d/material-runtime.d.ts +32 -0
  83. package/dist/screen2d/texture.d.ts +10 -0
  84. package/dist/screen2d/transform.d.ts +25 -0
  85. package/dist/screen2d/types.d.ts +90 -0
  86. package/dist/screenImagePresets.d.ts +13 -0
  87. package/dist/screenImageSettings-6NRg4cx9.js +39 -0
  88. package/dist/screenImageSettings-y_B4_767.cjs +1 -0
  89. package/dist/screenImageSettings.d.ts +50 -0
  90. package/dist/screenTextPresets.d.ts +6 -0
  91. package/dist/screenTextSettings.d.ts +131 -0
  92. package/dist/{selectors-Bub0o3qy.cjs → selectors-BLl2JUWW.cjs} +1 -1
  93. package/dist/{selectors-BHO6TnoC.js → selectors-CXd_x-6t.js} +6 -6
  94. package/dist/tracking.cjs +1 -1
  95. package/dist/tracking.js +193 -168
  96. package/dist/types/hand-tracking.d.ts +8 -0
  97. package/dist/types/nodes.d.ts +2 -0
  98. package/dist/useXRModel-3DcUa28n.cjs +1 -0
  99. package/dist/useXRModel-BMJE1hrk.js +28 -0
  100. package/dist/x-Co8jPhP0.js +127 -0
  101. package/dist/x-KC8E4Gaj.cjs +41 -0
  102. package/package.json +19 -1
  103. package/dist/index-B5J4gzn2.cjs +0 -1
  104. package/dist/index-BVBVg96G.cjs +0 -1
  105. package/dist/index-DtwHElmG.js +0 -157
  106. package/dist/index-PtFmD6B8.cjs +0 -1
@@ -1,13 +1,14 @@
1
- var fe = Object.defineProperty;
2
- var pe = (i, s, e) => s in i ? fe(i, s, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[s] = e;
3
- var h = (i, s, e) => pe(i, typeof s != "symbol" ? s + "" : s, e);
4
- import { jsx as we } from "react/jsx-runtime";
5
- import { useMemo as ee, useEffect as ve, createContext as Ce, useContext as Se } from "react";
6
- import { FilesetResolver as U, PoseLandmarker as ke, FaceLandmarker as ye, GestureRecognizer as Me, HandLandmarker as Te, ImageSegmenter as Re, DrawingUtils as Fe } from "@mediapipe/tasks-vision";
7
- import * as T from "three";
8
- import { RGBAFormat as te, LinearFilter as B, CanvasTexture as se, SRGBColorSpace as xe } from "three";
9
- var y = /* @__PURE__ */ ((i) => (i.WEBCAM = "webcam", i.STREAM = "stream", i.CANVAS = "canvas", i))(y || {}), _ = /* @__PURE__ */ ((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))(_ || {});
10
- const ft = {
1
+ var ge = Object.defineProperty;
2
+ var me = (a, s, e) => s in a ? ge(a, s, { enumerable: !0, configurable: !0, writable: !0, value: e }) : a[s] = e;
3
+ var h = (a, s, e) => me(a, typeof s != "symbol" ? s + "" : s, e);
4
+ import { jsx as fe } from "react/jsx-runtime";
5
+ import { useMemo as J, useEffect as pe, createContext as we, useContext as ve } from "react";
6
+ import { l as b } from "./index-CY3bUAcW.js";
7
+ import { FilesetResolver as L, PoseLandmarker as Ce, FaceLandmarker as Se, GestureRecognizer as ke, HandLandmarker as ye, ImageSegmenter as Me, DrawingUtils as Te } from "@mediapipe/tasks-vision";
8
+ import * as x from "three";
9
+ import { RGBAFormat as ee, LinearFilter as B, CanvasTexture as te, SRGBColorSpace as Re } from "three";
10
+ var M = /* @__PURE__ */ ((a) => (a.WEBCAM = "webcam", a.STREAM = "stream", a.CANVAS = "canvas", a))(M || {}), P = /* @__PURE__ */ ((a) => (a.HAND_TRACKER = "vincentt.xr.hand-tracker", a.GESTURE_TRACKER = "vincentt.xr.gesture-tracker", a.FACE_TRACKER = "vincentt.xr.face-tracker", a.BODY_TRACKER = "vincentt.xr.body-tracker", a.BACKGROUND_SEGMENTATION = "vincentt.xr.background-segmentation", a))(P || {});
11
+ const pt = {
11
12
  /** Camera background and segmentation mask. `depthTest` disabled. */
12
13
  BACKGROUND: -1e3,
13
14
  /** Free world-space content. `depthTest` enabled. */
@@ -17,26 +18,17 @@ const ft = {
17
18
  /** Descendants of `ScreenSpaceUI`. `depthTest` disabled. */
18
19
  SCREEN_UI: 1e3
19
20
  };
20
- class F extends Error {
21
+ class E extends Error {
21
22
  constructor(s) {
22
23
  super(s), this.name = "VincenttXRError";
23
24
  }
24
25
  }
25
- const x = {
26
- // Pinned to the CDN, NOT build-env-driven: a stale VITE_ASSET_STORAGE_ENDPOINT
27
- // baked a now-deleted CloudFront domain into every published bundle, breaking
28
- // WASM/model loads at runtime. The host must never come from a mutable env value.
29
- assetStorageEndpoint: "https://cdn.vincentt.studio",
30
- // Versioned bucket for SDK-shipped reference assets (canonical face model, face textures, etc.).
31
- sdkAssetsBaseUrl: "https://cdn.vincentt.studio/assets/sdk/face/v1",
32
- loggerPrefix: "[vincentt-xr]:"
33
- };
34
- class Ae {
26
+ class Fe {
35
27
  constructor(s) {
36
28
  h(this, "options");
37
29
  const e = {
38
30
  verbose: !1,
39
- prefix: x.loggerPrefix
31
+ prefix: b.loggerPrefix
40
32
  };
41
33
  this.options = { ...e, ...s };
42
34
  }
@@ -49,12 +41,12 @@ class Ae {
49
41
  e && console.error(t, ...s);
50
42
  }
51
43
  }
52
- const D = (i) => i * 2 - 1, K = new T.Vector3(), W = new T.Vector3(), V = ({ x: i, y: s, z: e }, t, n) => {
53
- K.set((i - 0.5) * 2, (0.5 - s) * 2, -e), K.unproject(t), W.copy(K).sub(t.position).normalize();
54
- const r = -t.position.z / W.z;
55
- return n.copy(t.position).addScaledVector(W, r), n;
56
- }, pt = (i, s) => V(i, s, new T.Vector3()), Ee = (i, s, e = 0.2) => e * s + (1 - e) * i;
57
- class G {
44
+ const _ = (a) => a * 2 - 1, W = new x.Vector3(), G = new x.Vector3(), V = ({ x: a, y: s, z: e }, t, n) => {
45
+ W.set((a - 0.5) * 2, (0.5 - s) * 2, -e), W.unproject(t), G.copy(W).sub(t.position).normalize();
46
+ const o = -t.position.z / G.z;
47
+ return n.copy(t.position).addScaledVector(G, o), n;
48
+ }, wt = (a, s) => V(a, s, new x.Vector3()), xe = (a, s, e = 0.2) => e * s + (1 - e) * a;
49
+ class X {
58
50
  constructor(s) {
59
51
  h(this, "canvas");
60
52
  this.maxDimension = s;
@@ -67,50 +59,50 @@ class G {
67
59
  draw(s) {
68
60
  const e = s.width, t = s.height, n = Math.min(1, this.maxDimension / Math.max(e, t));
69
61
  if (n >= 1) return s;
70
- const r = Math.max(1, Math.round(e * n)), c = Math.max(1, Math.round(t * n));
71
- (!this.canvas || this.canvas.width !== r || this.canvas.height !== c) && (this.canvas = new OffscreenCanvas(r, c));
72
- const d = this.canvas.getContext("2d");
73
- 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;
62
+ const o = Math.max(1, Math.round(e * n)), c = Math.max(1, Math.round(t * n));
63
+ (!this.canvas || this.canvas.width !== o || this.canvas.height !== c) && (this.canvas = new OffscreenCanvas(o, c));
64
+ const u = this.canvas.getContext("2d");
65
+ return u ? (u.setTransform(1, 0, 0, 1, 0, 0), u.clearRect(0, 0, o, c), u.drawImage(s, 0, 0, o, c), this.canvas) : s;
74
66
  }
75
67
  dispose() {
76
68
  this.canvas = void 0;
77
69
  }
78
70
  }
79
- const be = {};
80
- async function Ie(i) {
81
- const s = await fetch(i);
71
+ const Ae = {};
72
+ async function Ee(a) {
73
+ const s = await fetch(a);
82
74
  if (!s.ok)
83
- throw new Error(`fetchAndVerify: ${s.status} ${i}`);
84
- const e = await s.arrayBuffer(), t = De(i);
75
+ throw new Error(`fetchAndVerify: ${s.status} ${a}`);
76
+ const e = await s.arrayBuffer(), t = be(a);
85
77
  if (!t)
86
- return console.warn(`[xr-sdk integrity] no SRI hash for ${i} — passing through`), e;
87
- const n = await _e(e);
78
+ return console.warn(`[xr-sdk integrity] no SRI hash for ${a} — passing through`), e;
79
+ const n = await Ie(e);
88
80
  if (n !== t)
89
81
  throw new Error(
90
- `[xr-sdk integrity] SRI mismatch for ${i}: expected ${t}, got ${n}`
82
+ `[xr-sdk integrity] SRI mismatch for ${a}: expected ${t}, got ${n}`
91
83
  );
92
84
  return e;
93
85
  }
94
- async function z(i) {
95
- const s = await Ie(i);
86
+ async function z(a) {
87
+ const s = await Ee(a);
96
88
  return new Uint8Array(s);
97
89
  }
98
- function De(i) {
90
+ function be(a) {
99
91
  try {
100
- const s = new URL(i);
101
- return be[s.pathname];
92
+ const s = new URL(a);
93
+ return Ae[s.pathname];
102
94
  } catch {
103
95
  return;
104
96
  }
105
97
  }
106
- async function _e(i) {
107
- const s = await crypto.subtle.digest("SHA-384", i), e = new Uint8Array(s);
98
+ async function Ie(a) {
99
+ const s = await crypto.subtle.digest("SHA-384", a), e = new Uint8Array(s);
108
100
  let t = "";
109
101
  for (let n = 0; n < e.byteLength; n++)
110
102
  t += String.fromCharCode(e[n]);
111
103
  return `sha384-${btoa(t)}`;
112
104
  }
113
- class L {
105
+ class N {
114
106
  constructor() {
115
107
  h(this, "disposed", !1);
116
108
  h(this, "paused", !1);
@@ -172,30 +164,30 @@ class L {
172
164
  this.disposed = !0, this.rafId !== null && (cancelAnimationFrame(this.rafId), this.rafId = null);
173
165
  }
174
166
  }
175
- const Pe = 768;
176
- class Oe extends L {
167
+ const De = 768;
168
+ class _e extends N {
177
169
  constructor() {
178
170
  super();
179
171
  h(this, "landmarker", null);
180
172
  h(this, "processingTime", null);
181
173
  h(this, "coordinates");
182
174
  h(this, "sourceCanvas");
183
- h(this, "downscaler", new G(Pe));
175
+ h(this, "downscaler", new X(De));
184
176
  }
185
177
  async getBodyData() {
186
178
  if (!this.landmarker || !this.sourceCanvas)
187
179
  return;
188
- const e = this.downscaler.draw(this.sourceCanvas), t = performance.now(), n = this.landmarker.detectForVideo(e, t), r = performance.now();
189
- this.processingTime = r - t;
190
- const c = n.landmarks, d = [];
180
+ const e = this.downscaler.draw(this.sourceCanvas), t = performance.now(), n = this.landmarker.detectForVideo(e, t), o = performance.now();
181
+ this.processingTime = o - t;
182
+ const c = n.landmarks, u = [];
191
183
  if (c)
192
- return c.forEach((m, u) => {
193
- d[u] || (d[u] = []), m.forEach((g) => {
194
- const f = D(g.x), w = D(1 - g.y), p = D(g.z);
195
- d[u].push({ x: f, y: w, z: p });
184
+ return c.forEach((m, d) => {
185
+ u[d] || (u[d] = []), m.forEach((g) => {
186
+ const f = _(g.x), w = _(1 - g.y), p = _(g.z);
187
+ u[d].push({ x: f, y: w, z: p });
196
188
  });
197
189
  }), {
198
- coordinatesList: d
190
+ coordinatesList: u
199
191
  };
200
192
  }
201
193
  async processBodyTracking() {
@@ -222,12 +214,12 @@ class Oe extends L {
222
214
  return this.coordinates[e];
223
215
  }
224
216
  async initialize(e) {
225
- const t = await U.forVisionTasks(
226
- new URL("/assets/xr/wasm", x.assetStorageEndpoint).toString()
217
+ const t = await L.forVisionTasks(
218
+ new URL("/assets/xr/wasm", b.assetStorageEndpoint).toString()
227
219
  ), n = await z(
228
- new URL("/assets/xr/models/body_tracking.task", x.assetStorageEndpoint).toString()
220
+ new URL("/assets/xr/models/body_tracking.task", b.assetStorageEndpoint).toString()
229
221
  );
230
- this.landmarker = await ke.createFromOptions(t, {
222
+ this.landmarker = await Ce.createFromOptions(t, {
231
223
  baseOptions: {
232
224
  modelAssetBuffer: n,
233
225
  delegate: "GPU"
@@ -251,8 +243,8 @@ class Oe extends L {
251
243
  };
252
244
  }
253
245
  }
254
- const Ue = 0.11, ze = 4e-3;
255
- class Le extends L {
246
+ const Pe = 0.11, Oe = 4e-3;
247
+ class Ue extends N {
256
248
  constructor() {
257
249
  super();
258
250
  h(this, "landmarker", null);
@@ -277,9 +269,9 @@ class Le extends L {
277
269
  h(this, "landmarkScratch", { x: 0, y: 0, z: 0, visibility: 0 });
278
270
  // Reused per-frame rotation scratch (matrix -> quaternion -> mirror -> euler),
279
271
  // allocated once to avoid per-frame churn at 30+ fps.
280
- h(this, "rotMatrixScratch", new T.Matrix4());
281
- h(this, "rotQuatScratch", new T.Quaternion());
282
- h(this, "rotEulerScratch", new T.Euler());
272
+ h(this, "rotMatrixScratch", new x.Matrix4());
273
+ h(this, "rotQuatScratch", new x.Quaternion());
274
+ h(this, "rotEulerScratch", new x.Euler());
283
275
  }
284
276
  // For non-webcam sources MediaPipe landmarks read as mirrored; flip x in
285
277
  // place into the reused scratch so downstream unprojection sees the
@@ -298,16 +290,16 @@ class Le extends L {
298
290
  for (this.faces.length > t && (this.faces.length = t, this.leftCheekScratch.length = t, this.rightCheekScratch.length = t); this.faces.length < t; )
299
291
  this.faces.push({
300
292
  transform: {
301
- position: new T.Vector3(),
302
- rotation: new T.Vector3(),
303
- scale: new T.Vector3()
293
+ position: new x.Vector3(),
294
+ rotation: new x.Vector3(),
295
+ scale: new x.Vector3()
304
296
  },
305
297
  gestures: {}
306
- }), this.leftCheekScratch.push(new T.Vector3()), this.rightCheekScratch.push(new T.Vector3());
307
- for (let r = 0; r < t; r += 1) {
308
- if (!this.cameras[r])
298
+ }), this.leftCheekScratch.push(new x.Vector3()), this.rightCheekScratch.push(new x.Vector3());
299
+ for (let o = 0; o < t; o += 1) {
300
+ if (!this.cameras[o])
309
301
  continue;
310
- 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];
302
+ const c = this.faces[o], u = (n = this.getSource) == null ? void 0 : n.call(this), m = !(u === "webcam" || !u), d = e.faceLandmarks[o], g = e.facialTransformationMatrixes[o];
311
303
  this.rotMatrixScratch.fromArray(g.data), this.rotQuatScratch.setFromRotationMatrix(this.rotMatrixScratch), this.rotQuatScratch.set(
312
304
  -this.rotQuatScratch.x,
313
305
  this.rotQuatScratch.y,
@@ -318,26 +310,26 @@ class Le extends L {
318
310
  this.rotEulerScratch.y,
319
311
  this.rotEulerScratch.z
320
312
  ), V(
321
- this.landmarkForSource(u[4], m),
322
- this.cameras[r],
313
+ this.landmarkForSource(d[4], m),
314
+ this.cameras[o],
323
315
  c.transform.position
324
316
  ), V(
325
- this.landmarkForSource(u[50], m),
326
- this.cameras[r],
327
- this.leftCheekScratch[r]
317
+ this.landmarkForSource(d[50], m),
318
+ this.cameras[o],
319
+ this.leftCheekScratch[o]
328
320
  ), V(
329
- this.landmarkForSource(u[280], m),
330
- this.cameras[r],
331
- this.rightCheekScratch[r]
321
+ this.landmarkForSource(d[280], m),
322
+ this.cameras[o],
323
+ this.rightCheekScratch[o]
332
324
  );
333
- const w = this.leftCheekScratch[r].distanceTo(this.rightCheekScratch[r]) * Ue, p = Math.abs(T.MathUtils.radToDeg(this.rotEulerScratch.y)), k = w + p * ze, C = c.transform.scale.x, R = Ee(
325
+ const w = this.leftCheekScratch[o].distanceTo(this.rightCheekScratch[o]) * Pe, p = Math.abs(x.MathUtils.radToDeg(this.rotEulerScratch.y)), S = w + p * Oe, C = c.transform.scale.x, y = xe(
334
326
  isNaN(C) ? 0 : C,
335
- k
327
+ S
336
328
  );
337
- c.transform.scale.set(R, R, R);
338
- const E = c.gestures, b = e.faceBlendshapes[r].categories;
339
- for (const A of b)
340
- E[A.categoryName] = A.score;
329
+ c.transform.scale.set(y, y, y);
330
+ const F = c.gestures, T = e.faceBlendshapes[o].categories;
331
+ for (const A of T)
332
+ F[A.categoryName] = A.score;
341
333
  }
342
334
  }
343
335
  async processFaceTracking() {
@@ -347,14 +339,14 @@ class Le extends L {
347
339
  this.rafId = requestAnimationFrame(this.processFaceTracking.bind(this));
348
340
  return;
349
341
  }
350
- const e = Ne(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));
351
- (!this.analysisCanvas || this.analysisCanvas.width !== c || this.analysisCanvas.height !== d) && (this.analysisCanvas = new OffscreenCanvas(c, d));
342
+ const e = Le(this.numFaces), t = this.sourceCanvas.width, n = this.sourceCanvas.height, o = Math.min(1, e / Math.max(t, n)), c = Math.max(1, Math.round(t * o)), u = Math.max(1, Math.round(n * o));
343
+ (!this.analysisCanvas || this.analysisCanvas.width !== c || this.analysisCanvas.height !== u) && (this.analysisCanvas = new OffscreenCanvas(c, u));
352
344
  const m = this.analysisCanvas.getContext("2d");
353
345
  if (!m)
354
346
  return;
355
- m.setTransform(1, 0, 0, 1, 0, 0), m.clearRect(0, 0, c, d), m.drawImage(this.sourceCanvas, 0, 0, c, d);
356
- const u = performance.now(), g = this.landmarker.detectForVideo(this.analysisCanvas, u), f = performance.now();
357
- this.processingTime = f - u, this.detectionResults = g, this.extractAndUpdateFaceData(g), !(this.disposed || this.paused) && (this.rafId = requestAnimationFrame(this.processFaceTracking.bind(this)));
347
+ m.setTransform(1, 0, 0, 1, 0, 0), m.clearRect(0, 0, c, u), m.drawImage(this.sourceCanvas, 0, 0, c, u);
348
+ const d = performance.now(), g = this.landmarker.detectForVideo(this.analysisCanvas, d), f = performance.now();
349
+ this.processingTime = f - d, this.detectionResults = g, this.extractAndUpdateFaceData(g), !(this.disposed || this.paused) && (this.rafId = requestAnimationFrame(this.processFaceTracking.bind(this)));
358
350
  }
359
351
  resume() {
360
352
  this.paused && (super.resume(), this.processFaceTracking());
@@ -366,21 +358,21 @@ class Le extends L {
366
358
  return this.detectionResults;
367
359
  }
368
360
  getRawFaceTrackingData(e = 0) {
369
- var t, n, r, c;
361
+ var t, n, o, c;
370
362
  if (this.detectionResults)
371
363
  return {
372
364
  landmarks: (t = this.detectionResults.faceLandmarks) == null ? void 0 : t[e],
373
- blendshapes: (r = (n = this.detectionResults.faceBlendshapes) == null ? void 0 : n[e]) == null ? void 0 : r.categories,
365
+ blendshapes: (o = (n = this.detectionResults.faceBlendshapes) == null ? void 0 : n[e]) == null ? void 0 : o.categories,
374
366
  transformationMatrix: (c = this.detectionResults.facialTransformationMatrixes) == null ? void 0 : c[e]
375
367
  };
376
368
  }
377
369
  async initialize(e) {
378
370
  this.numFaces = (e == null ? void 0 : e.numFaces) || 1;
379
- const t = await U.forVisionTasks(
380
- new URL("/assets/xr/wasm", x.assetStorageEndpoint).toString()
371
+ const t = await L.forVisionTasks(
372
+ new URL("/assets/xr/wasm", b.assetStorageEndpoint).toString()
381
373
  ), n = await z(
382
- new URL("/assets/xr/models/face_tracking.task", x.assetStorageEndpoint).toString()
383
- ), r = await ye.createFromOptions(t, {
374
+ new URL("/assets/xr/models/face_tracking.task", b.assetStorageEndpoint).toString()
375
+ ), o = await Se.createFromOptions(t, {
384
376
  baseOptions: {
385
377
  modelAssetBuffer: n,
386
378
  delegate: "GPU"
@@ -394,7 +386,7 @@ class Le extends L {
394
386
  runningMode: "VIDEO",
395
387
  numFaces: this.numFaces
396
388
  });
397
- this.landmarker = r;
389
+ this.landmarker = o;
398
390
  }
399
391
  async run({ sourceCanvas: e, getSource: t, targetFps: n }) {
400
392
  this.sourceCanvas = e, this.getSource = t, this.setTargetFps(n), this.analysisCanvas = void 0, this.rafId === null && this.processFaceTracking();
@@ -409,8 +401,8 @@ class Le extends L {
409
401
  getRawFaceTrackingData: this.getRawFaceTrackingData.bind(this)
410
402
  };
411
403
  return Object.assign(t, {
412
- _setCamera: (n, r) => {
413
- this.cameras[r] = n;
404
+ _setCamera: (n, o) => {
405
+ this.cameras[o] = n;
414
406
  }
415
407
  }), t;
416
408
  }
@@ -421,9 +413,9 @@ class Le extends L {
421
413
  };
422
414
  }
423
415
  }
424
- const Ne = (i) => i > 1 ? 1024 : 512;
425
- var I = /* @__PURE__ */ ((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))(I || {});
426
- const Ve = 512, Be = {
416
+ const Le = (a) => a > 1 ? 1024 : 512;
417
+ var I = /* @__PURE__ */ ((a) => (a.ClosedFist = "closed_fist", a.OpenPalm = "open_palm", a.PointingUp = "pointing_up", a.ThumbDown = "thumb_down", a.ThumbUp = "thumb_up", a.Victory = "victory", a.ILoveYou = "i_love_you", a.None = "none", a))(I || {});
418
+ const ze = 512, Ne = {
427
419
  Closed_Fist: I.ClosedFist,
428
420
  Open_Palm: I.OpenPalm,
429
421
  Pointing_Up: I.PointingUp,
@@ -432,8 +424,8 @@ const Ve = 512, Be = {
432
424
  Victory: I.Victory,
433
425
  ILoveYou: I.ILoveYou,
434
426
  None: I.None
435
- }, He = 15;
436
- class qe extends L {
427
+ }, Ve = 15;
428
+ class Be extends N {
437
429
  constructor() {
438
430
  super();
439
431
  h(this, "landmarker", null);
@@ -441,25 +433,25 @@ class qe extends L {
441
433
  h(this, "coordinates");
442
434
  h(this, "gesture");
443
435
  h(this, "sourceCanvas");
444
- h(this, "downscaler", new G(Ve));
436
+ h(this, "downscaler", new X(ze));
445
437
  }
446
438
  async getGestureData() {
447
439
  if (!this.landmarker || !this.sourceCanvas)
448
440
  return;
449
- const e = this.downscaler.draw(this.sourceCanvas), t = performance.now(), n = this.landmarker.recognizeForVideo(e, t), r = performance.now();
450
- this.processingTime = r - t;
451
- const c = n.landmarks[0], d = [];
441
+ const e = this.downscaler.draw(this.sourceCanvas), t = performance.now(), n = this.landmarker.recognizeForVideo(e, t), o = performance.now();
442
+ this.processingTime = o - t;
443
+ const c = n.landmarks[0], u = [];
452
444
  if (c) {
453
445
  const m = n.gestures[0][0].categoryName;
454
- return c.forEach((u) => {
455
- d.push({
456
- x: D(u.x),
457
- y: D(1 - u.y),
458
- z: -u.z
446
+ return c.forEach((d) => {
447
+ u.push({
448
+ x: _(d.x),
449
+ y: _(1 - d.y),
450
+ z: -d.z
459
451
  });
460
452
  }), {
461
- coordinates: d,
462
- gesture: Be[m]
453
+ coordinates: u,
454
+ gesture: Ne[m]
463
455
  };
464
456
  }
465
457
  return { coordinates: void 0, gesture: void 0 };
@@ -487,11 +479,11 @@ class qe extends L {
487
479
  this.sourceCanvas = void 0, this.downscaler.dispose(), this.coordinates = void 0, this.gesture = void 0;
488
480
  }
489
481
  async initialize() {
490
- const e = await U.forVisionTasks(
491
- new URL("/assets/xr/wasm", x.assetStorageEndpoint).toString()
482
+ const e = await L.forVisionTasks(
483
+ new URL("/assets/xr/wasm", b.assetStorageEndpoint).toString()
492
484
  ), t = await z(
493
- new URL("/assets/xr/models/gesture_tracking.task", x.assetStorageEndpoint).toString()
494
- ), n = await Me.createFromOptions(e, {
485
+ new URL("/assets/xr/models/gesture_tracking.task", b.assetStorageEndpoint).toString()
486
+ ), n = await ke.createFromOptions(e, {
495
487
  baseOptions: {
496
488
  modelAssetBuffer: t,
497
489
  delegate: "GPU"
@@ -502,7 +494,7 @@ class qe extends L {
502
494
  this.landmarker = n;
503
495
  }
504
496
  async run({ sourceCanvas: e, targetFps: t }) {
505
- this.sourceCanvas = e, this.setTargetFps(t ?? He), this.rafId === null && await this.processGestureTracking();
497
+ this.sourceCanvas = e, this.setTargetFps(t ?? Ve), this.rafId === null && await this.processGestureTracking();
506
498
  }
507
499
  getModelNode() {
508
500
  const e = this;
@@ -522,43 +514,55 @@ class qe extends L {
522
514
  };
523
515
  }
524
516
  }
525
- const Ke = 512;
526
- class We extends L {
517
+ const He = 512;
518
+ class qe extends N {
527
519
  constructor() {
528
520
  super();
529
521
  h(this, "landmarker", null);
530
522
  h(this, "processingTime", null);
523
+ h(this, "hands");
531
524
  h(this, "coordinates");
532
525
  h(this, "gesture");
526
+ h(this, "handedness");
533
527
  h(this, "sourceCanvas");
534
- h(this, "downscaler", new G(Ke));
528
+ h(this, "downscaler", new X(He));
535
529
  }
536
530
  async getHandData() {
537
531
  if (!this.landmarker || !this.sourceCanvas)
538
532
  return;
539
- const e = this.downscaler.draw(this.sourceCanvas), t = performance.now(), n = this.landmarker.detectForVideo(e, t), r = performance.now();
540
- this.processingTime = r - t;
541
- const c = n.landmarks[0], d = [];
542
- if (c) {
543
- const m = n.landmarks[0][0].z < 0 ? "closed_fist" : "open_palm";
544
- return c.forEach((u) => {
545
- d.push({
546
- x: D(u.x),
547
- y: D(1 - u.y),
548
- z: -u.z
549
- });
550
- }), {
551
- coordinates: d,
552
- gesture: m
533
+ const e = this.downscaler.draw(this.sourceCanvas), t = performance.now(), n = this.landmarker.detectForVideo(e, t), o = performance.now();
534
+ this.processingTime = o - t;
535
+ const c = [], u = n.handedness ?? n.handednesses ?? [];
536
+ if (n.landmarks.forEach((d, g) => {
537
+ var C, y, F;
538
+ if (!d || d.length === 0)
539
+ return;
540
+ const f = d.map((T) => ({
541
+ x: _(T.x),
542
+ y: _(1 - T.y),
543
+ z: -T.z
544
+ })), w = (F = (y = (C = u[g]) == null ? void 0 : C[0]) == null ? void 0 : y.categoryName) == null ? void 0 : F.toLowerCase(), p = w === "left" || w === "right" ? w : void 0, S = d[0].z < 0 ? "closed_fist" : "open_palm";
545
+ c.push({ coordinates: f, gesture: S, handedness: p });
546
+ }), !c.length)
547
+ return {
548
+ hands: void 0,
549
+ coordinates: void 0,
550
+ gesture: void 0,
551
+ handedness: void 0
553
552
  };
554
- }
555
- return { coordinates: void 0, gesture: void 0 };
553
+ const m = c[0];
554
+ return {
555
+ hands: c,
556
+ coordinates: m.coordinates,
557
+ gesture: m.gesture,
558
+ handedness: m.handedness
559
+ };
556
560
  }
557
561
  async processHandTracking() {
558
562
  if (!this.disposed) {
559
563
  if (this.shouldRunInference()) {
560
564
  const e = await this.getHandData();
561
- e && (this.coordinates = e.coordinates, this.gesture = e.gesture);
565
+ e && (this.hands = e.hands, this.coordinates = e.coordinates, this.gesture = e.gesture, this.handedness = e.handedness);
562
566
  }
563
567
  this.disposed || this.paused || (this.rafId = requestAnimationFrame(this.processHandTracking.bind(this)));
564
568
  }
@@ -574,20 +578,20 @@ class We extends L {
574
578
  }
575
579
  this.landmarker = null;
576
580
  }
577
- this.sourceCanvas = void 0, this.downscaler.dispose(), this.coordinates = void 0, this.gesture = void 0;
581
+ this.sourceCanvas = void 0, this.hands = void 0, this.downscaler.dispose(), this.coordinates = void 0, this.gesture = void 0, this.handedness = void 0;
578
582
  }
579
583
  async initialize() {
580
- const e = await U.forVisionTasks(
581
- new URL("/assets/xr/wasm", x.assetStorageEndpoint).toString()
584
+ const e = await L.forVisionTasks(
585
+ new URL("/assets/xr/wasm", b.assetStorageEndpoint).toString()
582
586
  ), t = await z(
583
- new URL("/assets/xr/models/hand_tracking.task", x.assetStorageEndpoint).toString()
584
- ), n = await Te.createFromOptions(e, {
587
+ new URL("/assets/xr/models/hand_tracking.task", b.assetStorageEndpoint).toString()
588
+ ), n = await ye.createFromOptions(e, {
585
589
  baseOptions: {
586
590
  modelAssetBuffer: t,
587
591
  delegate: "GPU"
588
592
  },
589
593
  runningMode: "VIDEO",
590
- numHands: 1
594
+ numHands: 2
591
595
  });
592
596
  this.landmarker = n;
593
597
  }
@@ -597,11 +601,17 @@ class We extends L {
597
601
  getModelNode() {
598
602
  const e = this;
599
603
  return {
604
+ get hands() {
605
+ return e.hands;
606
+ },
600
607
  get coordinates() {
601
608
  return e.coordinates;
602
609
  },
603
610
  get gesture() {
604
611
  return e.gesture;
612
+ },
613
+ get handedness() {
614
+ return e.handedness;
605
615
  }
606
616
  };
607
617
  }
@@ -612,13 +622,13 @@ class We extends L {
612
622
  };
613
623
  }
614
624
  }
615
- const Ge = 24, Xe = 720, $e = [
625
+ const Ke = 24, We = 720, Ge = [
616
626
  [255, 255, 255, 255],
617
627
  // 0: background → green 255, kept
618
628
  [0, 0, 0, 0]
619
629
  // 1: person → green 0, discarded
620
630
  ];
621
- class Ye extends L {
631
+ class Xe extends N {
622
632
  constructor() {
623
633
  super();
624
634
  h(this, "segmenter", null);
@@ -704,8 +714,8 @@ class Ye extends L {
704
714
  const e = this.readIntrinsicSize(this.inputSource);
705
715
  if (!e) return;
706
716
  this.inputSourceSize = e;
707
- const t = Math.min(1, Xe / Math.max(e.width, e.height)), n = Math.max(1, Math.round(e.width * t)), r = Math.max(1, Math.round(e.height * t));
708
- 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);
717
+ const t = Math.min(1, We / Math.max(e.width, e.height)), n = Math.max(1, Math.round(e.width * t)), o = Math.max(1, Math.round(e.height * t));
718
+ this.processCanvas.width === n && this.processCanvas.height === o || (this.processCanvas.width = n, this.processCanvas.height = o, this.glCanvas && (this.glCanvas.width = n, this.glCanvas.height = o), this.maskImageData = void 0);
709
719
  }
710
720
  async processSegmentation() {
711
721
  if (this.disposed || !this.isProcessing || !this.maskCanvas || !this.processCanvas)
@@ -725,12 +735,12 @@ class Ye extends L {
725
735
  this.ensureProcessCanvasForInput();
726
736
  const n = this.processCanvas.getContext("2d");
727
737
  if (n) {
728
- const d = this.processCanvas.width, m = this.processCanvas.height;
729
- if (n.clearRect(0, 0, d, m), this.inputSource && this.inputSourceSize) {
730
- const { width: u, height: g } = this.inputSourceSize, f = Math.min(d / u, m / g), w = u * f, p = g * f;
731
- n.drawImage(this.inputSource, (d - w) / 2, (m - p) / 2, w, p);
738
+ const u = this.processCanvas.width, m = this.processCanvas.height;
739
+ if (n.clearRect(0, 0, u, m), this.inputSource && this.inputSourceSize) {
740
+ const { width: d, height: g } = this.inputSourceSize, f = Math.min(u / d, m / g), w = d * f, p = g * f;
741
+ n.drawImage(this.inputSource, (u - w) / 2, (m - p) / 2, w, p);
732
742
  } else
733
- n.drawImage(e, 0, 0, d, m);
743
+ n.drawImage(e, 0, 0, u, m);
734
744
  }
735
745
  const c = this.segmenter.segmentForVideo(
736
746
  this.processCanvas,
@@ -742,13 +752,13 @@ class Ye extends L {
742
752
  return;
743
753
  }
744
754
  if (this.rawCache = null, this.latestMask && (this.latestMask.close(), this.latestMask = null), this.useGpuMaskPath && this.drawingUtils && this.glCanvas)
745
- this.drawingUtils.drawCategoryMask(c, $e), this.latestMask = c.clone(), c.close(), this.blitGlToMask();
755
+ this.drawingUtils.drawCategoryMask(c, Ge), this.latestMask = c.clone(), c.close(), this.blitGlToMask();
746
756
  else {
747
757
  this.latestMask = c.clone();
748
- const d = this.readMaskToImageData(c);
749
- c.close(), d && this.blitImageDataToMask(d);
758
+ const u = this.readMaskToImageData(c);
759
+ c.close(), u && this.blitImageDataToMask(u);
750
760
  }
751
- this.segmentationMaskTexture && (this.isMaskSetup || (this.segmentationMaskTexture.format = te, this.segmentationMaskTexture.minFilter = B, this.segmentationMaskTexture.magFilter = B, 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)));
761
+ this.segmentationMaskTexture && (this.isMaskSetup || (this.segmentationMaskTexture.format = ee, this.segmentationMaskTexture.minFilter = B, this.segmentationMaskTexture.magFilter = B, 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)));
752
762
  }
753
763
  /**
754
764
  * Blit the GPU-rendered mask (already RGBA-inverted by drawCategoryMask)
@@ -768,13 +778,13 @@ class Ye extends L {
768
778
  * background→opaque convention (green carries the signal for the alphaMap).
769
779
  */
770
780
  readMaskToImageData(e) {
771
- const t = e.getAsUint8Array(), { width: n, height: r } = e;
772
- if (!t || n <= 0 || r <= 0) return null;
773
- (!this.maskImageData || this.maskImageData.width !== n || this.maskImageData.height !== r) && (this.maskImageData = new ImageData(n, r));
781
+ const t = e.getAsUint8Array(), { width: n, height: o } = e;
782
+ if (!t || n <= 0 || o <= 0) return null;
783
+ (!this.maskImageData || this.maskImageData.width !== n || this.maskImageData.height !== o) && (this.maskImageData = new ImageData(n, o));
774
784
  const c = this.maskImageData.data;
775
- for (let d = 0; d < t.length; d += 1) {
776
- const m = t[d] === 255 ? 0 : 255;
777
- c[d * 4] = 255, c[d * 4 + 1] = m, c[d * 4 + 2] = 255, c[d * 4 + 3] = m;
785
+ for (let u = 0; u < t.length; u += 1) {
786
+ const m = t[u] === 255 ? 0 : 255;
787
+ c[u * 4] = 255, c[u * 4 + 1] = m, c[u * 4 + 2] = 255, c[u * 4 + 3] = m;
778
788
  }
779
789
  return this.maskImageData;
780
790
  }
@@ -787,8 +797,8 @@ class Ye extends L {
787
797
  if (!this.maskCanvas || !this.filterCanvas) return;
788
798
  const t = this.maskCanvas.getContext("2d"), n = this.filterCanvas.getContext("2d");
789
799
  if (!t || !n) return;
790
- const r = this.getStagingCanvas(e.width, e.height), c = r.getContext("2d");
791
- 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));
800
+ const o = this.getStagingCanvas(e.width, e.height), c = o.getContext("2d");
801
+ c && (c.putImageData(e, 0, 0), n.filter = "blur(0.5px)", n.clearRect(0, 0, this.filterCanvas.width, this.filterCanvas.height), n.drawImage(o, 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));
792
802
  }
793
803
  getStagingCanvas(e, t) {
794
804
  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;
@@ -815,37 +825,37 @@ class Ye extends L {
815
825
  }
816
826
  async initialize(e) {
817
827
  this.quality = (e == null ? void 0 : e.quality) ?? "low";
818
- const t = await U.forVisionTasks(
819
- new URL("/assets/xr/wasm", x.assetStorageEndpoint).toString()
828
+ const t = await L.forVisionTasks(
829
+ new URL("/assets/xr/wasm", b.assetStorageEndpoint).toString()
820
830
  ), n = await z(
821
- new URL("/assets/xr/models/segmentation.tflite", x.assetStorageEndpoint).toString()
831
+ new URL("/assets/xr/models/segmentation.tflite", b.assetStorageEndpoint).toString()
822
832
  );
823
833
  this.glCanvas = new OffscreenCanvas(1, 1);
824
- const r = this.glCanvas.getContext("webgl2", {
834
+ const o = this.glCanvas.getContext("webgl2", {
825
835
  preserveDrawingBuffer: !0
826
836
  });
827
- this.segmenter = await Re.createFromOptions(t, {
837
+ this.segmenter = await Me.createFromOptions(t, {
828
838
  baseOptions: {
829
839
  modelAssetBuffer: n,
830
840
  delegate: "GPU"
831
841
  },
832
- ...r ? { canvas: this.glCanvas } : {},
842
+ ...o ? { canvas: this.glCanvas } : {},
833
843
  outputCategoryMask: !0,
834
844
  outputConfidenceMasks: !1,
835
845
  runningMode: "VIDEO"
836
- }), r ? (this.drawingUtils = new Fe(r), this.useGpuMaskPath = !0) : this.useGpuMaskPath = !1;
846
+ }), o ? (this.drawingUtils = new Te(o), this.useGpuMaskPath = !0) : this.useGpuMaskPath = !1;
837
847
  }
838
848
  async run({
839
849
  sourceCanvas: e,
840
850
  renderWidth: t,
841
851
  renderHeight: n,
842
- targetFps: r
852
+ targetFps: o
843
853
  }) {
844
854
  if (!e)
845
855
  return;
846
- this.setTargetFps(r ?? Ge), this.isProcessing = !1, this.rafId !== null && (cancelAnimationFrame(this.rafId), this.rafId = null);
856
+ this.setTargetFps(o ?? Ke), this.isProcessing = !1, this.rafId !== null && (cancelAnimationFrame(this.rafId), this.rafId = null);
847
857
  const c = this.getQualityScaleFactor();
848
- 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 se(this.maskCanvas), this.isMaskSetup = !1, this.rawCache = null, this.isProcessing = !0, this.lastInferenceMs = 0, this.rafId = requestAnimationFrame(this.processSegmentation.bind(this));
858
+ 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 te(this.maskCanvas), this.isMaskSetup = !1, this.rawCache = null, this.isProcessing = !0, this.lastInferenceMs = 0, this.rafId = requestAnimationFrame(this.processSegmentation.bind(this));
849
859
  }
850
860
  /**
851
861
  * Lazily read the single-channel mask back to a Uint8Array. Only invoked when
@@ -881,91 +891,91 @@ class Ye extends L {
881
891
  }
882
892
  }
883
893
  const Z = {
884
- [_.BACKGROUND_SEGMENTATION]: Ye,
885
- [_.HAND_TRACKER]: We,
886
- [_.GESTURE_TRACKER]: qe,
887
- [_.FACE_TRACKER]: Le,
888
- [_.BODY_TRACKER]: Oe
889
- }, Qe = async (i) => {
894
+ [P.BACKGROUND_SEGMENTATION]: Xe,
895
+ [P.HAND_TRACKER]: qe,
896
+ [P.GESTURE_TRACKER]: Be,
897
+ [P.FACE_TRACKER]: Ue,
898
+ [P.BODY_TRACKER]: _e
899
+ }, $e = async (a) => {
890
900
  const s = document.createElement("video");
891
- s.srcObject = i, s.muted = !0, s.playsInline = !0, s.autoplay = !0, await new Promise((t) => {
901
+ s.srcObject = a, s.muted = !0, s.playsInline = !0, s.autoplay = !0, await new Promise((t) => {
892
902
  s.onloadedmetadata = () => {
893
903
  s.play(), t();
894
904
  };
895
905
  });
896
906
  const e = s;
897
907
  return await new Promise((t) => {
898
- const n = setTimeout(t, 150), r = () => {
908
+ const n = setTimeout(t, 150), o = () => {
899
909
  clearTimeout(n), t();
900
910
  };
901
- typeof e.requestVideoFrameCallback == "function" ? e.requestVideoFrameCallback(r) : requestAnimationFrame(() => requestAnimationFrame(() => r()));
911
+ typeof e.requestVideoFrameCallback == "function" ? e.requestVideoFrameCallback(o) : requestAnimationFrame(() => requestAnimationFrame(() => o()));
902
912
  }), s;
903
- }, J = (i) => {
904
- const s = new se(i);
905
- return s.colorSpace = xe, s.format = te, s.minFilter = B, s.magFilter = B, s.generateMipmaps = !1, s.needsUpdate = !0, s;
906
- }, je = (i, s) => {
907
- const e = i.videoWidth, t = i.videoHeight;
913
+ }, Ye = (a) => {
914
+ const s = new te(a);
915
+ return s.colorSpace = Re, s.format = ee, s.minFilter = B, s.magFilter = B, s.generateMipmaps = !1, s.needsUpdate = !0, s;
916
+ }, Qe = (a, s) => {
917
+ const e = a.videoWidth, t = a.videoHeight;
908
918
  e > 0 && t > 0 && (s.width !== e && (s.width = e), s.height !== t && (s.height = t));
909
919
  const n = s.getContext("2d", {
910
920
  colorSpace: "srgb"
911
921
  });
912
- n.save(), n.scale(-1, 1), n.drawImage(i, -s.width, 0, s.width, s.height), n.restore();
913
- }, Ze = (i, s, e = 1) => {
922
+ n.save(), n.scale(-1, 1), n.drawImage(a, -s.width, 0, s.width, s.height), n.restore();
923
+ }, je = (a, s, e = 1) => {
914
924
  const t = s.getContext("2d", {
915
925
  colorSpace: "srgb"
916
- }), n = s.width / s.height, r = i.width / i.height;
917
- let c, d;
918
- r > n ? (d = s.height, c = i.width * (s.height / i.height)) : (c = s.width, d = i.height * (s.width / i.width));
926
+ }), n = s.width / s.height, o = a.width / a.height;
927
+ let c, u;
928
+ o > n ? (u = s.height, c = a.width * (s.height / a.height)) : (c = s.width, u = a.height * (s.width / a.width));
919
929
  const m = Number.isFinite(e) && e > 0 ? e : 1;
920
- c *= m, d *= m;
921
- const u = (s.width - c) / 2, g = (s.height - d) / 2;
930
+ c *= m, u *= m;
931
+ const d = (s.width - c) / 2, g = (s.height - u) / 2;
922
932
  t.setTransform(1, 0, 0, 1, 0, 0), t.clearRect(0, 0, s.width, s.height), t.drawImage(
923
- i,
933
+ a,
924
934
  0,
925
935
  0,
926
- i.width,
927
- i.height,
928
- u,
936
+ a.width,
937
+ a.height,
938
+ d,
929
939
  g,
930
940
  c,
931
- d
941
+ u
932
942
  );
933
- }, Je = (i, s, e) => {
943
+ }, Ze = (a, s, e) => {
934
944
  const t = /* @__PURE__ */ new Map();
935
945
  return { acquire: async (g, f, w) => {
936
946
  let p = t.get(g);
937
947
  if (p)
938
948
  return p.refs.add(f), p.activeRefs.add(f), p.initPromise;
939
- const k = s[g];
940
- if (!k)
949
+ const S = s[g];
950
+ if (!S)
941
951
  throw new Error(`Invalid model: ${g}`);
942
- const C = new k(), R = /* @__PURE__ */ new Set([f]), E = /* @__PURE__ */ new Set([f]), b = (async () => {
952
+ const C = new S(), y = /* @__PURE__ */ new Set([f]), F = /* @__PURE__ */ new Set([f]), T = (async () => {
943
953
  await C.initialize(w), e && await e(g, C);
944
954
  const A = t.get(g);
945
- return A && A.refs.size > 0 && i.setPipeline((N) => N.set(g, C)), C;
955
+ return A && A.refs.size > 0 && a.setPipeline((D) => D.set(g, C)), C;
946
956
  })();
947
- return p = { model: C, refs: R, activeRefs: E, initPromise: b, options: w }, t.set(g, p), b.catch(() => {
948
- t.get(g) === p && (t.delete(g), i.setPipeline((N) => N.delete(g)));
949
- }), b;
957
+ return p = { model: C, refs: y, activeRefs: F, initPromise: T, options: w }, t.set(g, p), T.catch(() => {
958
+ t.get(g) === p && (t.delete(g), a.setPipeline((D) => D.delete(g)));
959
+ }), T;
950
960
  }, release: (g, f) => {
951
- var k;
961
+ var S;
952
962
  const w = t.get(g);
953
963
  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;
954
964
  t.delete(g);
955
965
  const p = w.model;
956
966
  try {
957
- (k = p.dispose) == null || k.call(p);
967
+ (S = p.dispose) == null || S.call(p);
958
968
  } catch (C) {
959
969
  console.warn(`[xr-sdk registry] dispose threw for ${g}`, C);
960
970
  }
961
- i.setPipeline((C) => C.delete(g));
971
+ a.setPipeline((C) => C.delete(g));
962
972
  }, setActive: (g, f, w) => {
963
973
  const p = t.get(g);
964
974
  if (!p || !p.refs.has(f)) return;
965
- const k = p.activeRefs.size > 0;
975
+ const S = p.activeRefs.size > 0;
966
976
  w ? p.activeRefs.add(f) : p.activeRefs.delete(f);
967
977
  const C = p.activeRefs.size > 0;
968
- k !== C && (C ? p.model.resume() : p.model.pause());
978
+ S !== C && (C ? p.model.resume() : p.model.pause());
969
979
  }, get: (g) => {
970
980
  var f;
971
981
  return (f = t.get(g)) == null ? void 0 : f.model;
@@ -981,13 +991,13 @@ const Z = {
981
991
  const p = w.model;
982
992
  try {
983
993
  (g = p.dispose) == null || g.call(p);
984
- } catch (k) {
985
- console.warn(`[xr-sdk registry] dispose threw for ${f}`, k);
994
+ } catch (S) {
995
+ console.warn(`[xr-sdk registry] dispose threw for ${f}`, S);
986
996
  }
987
997
  }
988
- i.setPipeline((f) => f.clear());
998
+ a.setPipeline((f) => f.clear());
989
999
  } };
990
- }, et = {
1000
+ }, Je = {
991
1001
  lifecycle: "idle",
992
1002
  ready: !1,
993
1003
  error: void 0,
@@ -997,71 +1007,76 @@ const Z = {
997
1007
  source: void 0,
998
1008
  sourceKind: void 0,
999
1009
  pipeline: /* @__PURE__ */ new Map()
1000
- }, tt = () => {
1001
- let i = { ...et, pipeline: /* @__PURE__ */ new Map() };
1010
+ }, et = () => {
1011
+ let a = { ...Je, pipeline: /* @__PURE__ */ new Map() };
1002
1012
  const s = /* @__PURE__ */ new Set(), e = () => {
1003
1013
  s.forEach((t) => t());
1004
1014
  };
1005
1015
  return {
1006
- getSnapshot: () => i,
1016
+ getSnapshot: () => a,
1007
1017
  set: (t) => {
1008
1018
  let n = !1;
1009
- for (const r of Object.keys(t))
1010
- if (t[r] !== i[r]) {
1019
+ for (const o of Object.keys(t))
1020
+ if (t[o] !== a[o]) {
1011
1021
  n = !0;
1012
1022
  break;
1013
1023
  }
1014
- n && (i = { ...i, ...t }, e());
1024
+ n && (a = { ...a, ...t }, e());
1015
1025
  },
1016
1026
  setPipeline: (t) => {
1017
- const n = new Map(i.pipeline);
1018
- return t(n), i = { ...i, pipeline: n }, e(), n;
1027
+ const n = new Map(a.pipeline);
1028
+ return t(n), a = { ...a, pipeline: n }, e(), n;
1019
1029
  },
1020
1030
  subscribe: (t) => (s.add(t), () => {
1021
1031
  s.delete(t);
1022
1032
  })
1023
1033
  };
1024
- }, st = ({
1025
- renderHeight: i,
1034
+ }, tt = ({
1035
+ renderHeight: a,
1026
1036
  renderWidth: s,
1027
1037
  videoHeight: e,
1028
1038
  videoWidth: t
1029
1039
  }) => ({
1030
- height: i || e,
1040
+ height: a || e,
1031
1041
  width: s || t
1032
- }), it = (i) => {
1033
- const s = new Ae({ verbose: !0 }), e = tt();
1034
- let t = i;
1035
- const n = (a) => {
1042
+ }), st = (a) => {
1043
+ const s = new Fe({ verbose: !0 }), e = et();
1044
+ let t = a;
1045
+ const n = (i) => {
1036
1046
  var l;
1037
- const o = (l = P.getOptions(a)) == null ? void 0 : l.targetFps;
1038
- return typeof o == "number" ? o : t == null ? void 0 : t.targetFps;
1047
+ const r = (l = O.getOptions(i)) == null ? void 0 : l.targetFps;
1048
+ return typeof r == "number" ? r : t == null ? void 0 : t.targetFps;
1039
1049
  };
1040
- let r, c, d, m, u, g, f, w, p, k, C = !1, R = !1;
1041
- const E = /* @__PURE__ */ new Set(), b = /* @__PURE__ */ new Set(), A = async (a, o) => {
1042
- if (!E.has(a) && e.getSnapshot().lifecycle === "running" && u) {
1043
- E.add(a);
1050
+ let o, c, u, m, d, g, f, w, p, S, C = !1, y = !1;
1051
+ const F = /* @__PURE__ */ new Set(), T = /* @__PURE__ */ new Set(), A = (i) => {
1052
+ const r = e.getSnapshot().cameraTexture;
1053
+ r && r.dispose();
1054
+ const l = Ye(i);
1055
+ return e.set({ cameraTexture: l }), l;
1056
+ }, D = async (i, r) => {
1057
+ if (!F.has(i) && e.getSnapshot().lifecycle === "running" && d) {
1058
+ F.add(i);
1044
1059
  try {
1045
- await o.run({
1046
- sourceCanvas: u,
1060
+ await r.run({
1061
+ sourceCanvas: d,
1047
1062
  renderWidth: e.getSnapshot().renderWidth,
1048
1063
  renderHeight: e.getSnapshot().renderHeight,
1049
1064
  getSource: () => e.getSnapshot().sourceKind,
1050
- targetFps: n(a)
1051
- }), R && (await new Promise((l) => requestAnimationFrame(() => l())), await new Promise((l) => requestAnimationFrame(() => l())), o.pause());
1065
+ targetFps: n(i)
1066
+ }), y && (await new Promise((l) => requestAnimationFrame(() => l())), await new Promise((l) => requestAnimationFrame(() => l())), r.pause());
1052
1067
  } catch (l) {
1053
- throw E.delete(a), l;
1068
+ throw F.delete(i), l;
1054
1069
  }
1055
1070
  }
1056
- }, P = Je(e, Z, (a, o) => A(a, o));
1071
+ }, O = Ze(e, Z, (i, r) => D(i, r));
1057
1072
  e.subscribe(() => {
1058
1073
  if (e.getSnapshot().lifecycle !== "running") return;
1059
- const a = e.getSnapshot().pipeline;
1060
- for (const [o, l] of a.entries())
1061
- E.has(o) || A(o, l);
1074
+ const i = e.getSnapshot().pipeline;
1075
+ for (const [r, l] of i.entries())
1076
+ F.has(r) || D(r, l);
1062
1077
  });
1063
- const O = () => {
1064
- if (k !== void 0 && (cancelAnimationFrame(k), k = void 0), c) {
1078
+ const U = () => {
1079
+ if (S !== void 0 && (cancelAnimationFrame(S), S = void 0), c) {
1065
1080
  try {
1066
1081
  c.pause();
1067
1082
  } catch {
@@ -1072,229 +1087,225 @@ const Z = {
1072
1087
  }
1073
1088
  c = void 0;
1074
1089
  }
1075
- if (d) {
1090
+ if (u) {
1076
1091
  try {
1077
- d.getTracks().forEach((a) => a.stop());
1092
+ u.getTracks().forEach((i) => i.stop());
1078
1093
  } catch {
1079
1094
  }
1080
- d = void 0;
1095
+ u = void 0;
1081
1096
  }
1082
- }, X = () => {
1083
- if (C || !c || !m || !u) return;
1084
- const a = window.__xr_debugger_metrics;
1085
- if (a != null && a.trackCameraFrame && a.trackCameraFrame(), (e.getSnapshot().sourceKind ?? "webcam") === "webcam")
1086
- je(c, m);
1097
+ }, H = () => {
1098
+ if (C || !c || !m || !d) return;
1099
+ const i = window.__xr_debugger_metrics;
1100
+ if (i != null && i.trackCameraFrame && i.trackCameraFrame(), (e.getSnapshot().sourceKind ?? "webcam") === "webcam")
1101
+ Qe(c, m);
1087
1102
  else {
1088
1103
  const v = m.getContext("2d");
1089
1104
  if (!v) return;
1090
- const S = c.videoWidth, M = c.videoHeight;
1091
- 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);
1105
+ const k = c.videoWidth, R = c.videoHeight;
1106
+ m.width !== k && (m.width = k), m.height !== R && (m.height = R), v.setTransform(1, 0, 0, 1, 0, 0), v.clearRect(0, 0, k, R), v.drawImage(c, 0, 0, k, R);
1092
1107
  }
1093
- Ze(m, u, (t == null ? void 0 : t.cameraZoom) ?? 1.2);
1108
+ je(m, d, (t == null ? void 0 : t.cameraZoom) ?? 1.2);
1094
1109
  const l = e.getSnapshot().cameraTexture;
1095
1110
  l && (l.needsUpdate = !0);
1096
1111
  }, $ = () => {
1097
- if (!c || !m || !u) return;
1098
- if (R) {
1099
- X();
1112
+ if (!c || !m || !d) return;
1113
+ if (y) {
1114
+ H();
1100
1115
  return;
1101
1116
  }
1102
- const a = () => {
1103
- k = requestAnimationFrame(a), X();
1117
+ const i = () => {
1118
+ S = requestAnimationFrame(i), H();
1104
1119
  };
1105
- k = requestAnimationFrame(a);
1106
- }, ae = async (a) => {
1107
- if (a.source === y.WEBCAM)
1120
+ S = requestAnimationFrame(i);
1121
+ }, ae = async (i) => {
1122
+ if (i.source === M.WEBCAM)
1108
1123
  try {
1109
- const o = t != null && t.camRes && t.camRes > 0 ? t.camRes : 960;
1124
+ const r = t != null && t.camRes && t.camRes > 0 ? t.camRes : 960;
1110
1125
  return await navigator.mediaDevices.getUserMedia({
1111
1126
  video: {
1112
1127
  facingMode: "user",
1113
1128
  frameRate: { min: 24, ideal: 30, max: 60 },
1114
- width: { ideal: o }
1129
+ width: { ideal: r }
1115
1130
  }
1116
1131
  });
1117
- } catch (o) {
1118
- 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.";
1119
- throw e.set({ error: { error: "PermissionError", message: v } }), new F(o instanceof Error ? o.message : "getUserMedia failed");
1132
+ } catch (r) {
1133
+ const l = r instanceof DOMException ? r.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.";
1134
+ throw e.set({ error: { error: "PermissionError", message: v } }), new E(r instanceof Error ? r.message : "getUserMedia failed");
1120
1135
  }
1121
- return a.stream;
1122
- }, H = async (a) => {
1123
- const o = await ae(a);
1124
- d = o;
1125
- const l = await Qe(o);
1136
+ return i.stream;
1137
+ }, q = async (i) => {
1138
+ const r = await ae(i);
1139
+ u = r;
1140
+ const l = await $e(r);
1126
1141
  c = l, m = new OffscreenCanvas(l.videoWidth, l.videoHeight);
1127
- const { renderWidth: v, renderHeight: S } = e.getSnapshot(), M = st({
1142
+ const { renderWidth: v, renderHeight: k } = e.getSnapshot(), R = tt({
1128
1143
  renderWidth: v,
1129
- renderHeight: S,
1144
+ renderHeight: k,
1130
1145
  videoWidth: l.videoWidth,
1131
1146
  videoHeight: l.videoHeight
1132
1147
  });
1133
- if (u)
1134
- (u.width !== M.width || u.height !== M.height) && (u.width = M.width, u.height = M.height);
1135
- else {
1136
- u = new OffscreenCanvas(M.width, M.height);
1137
- const me = J(u);
1138
- e.set({ cameraTexture: me });
1139
- }
1140
- const j = a.source === y.STREAM ? a.static === !0 : !1;
1141
- R = j, r = a.source === y.WEBCAM ? { source: y.WEBCAM, sourceKind: "webcam" } : {
1142
- source: y.STREAM,
1143
- stream: a.stream,
1148
+ d ? (d.width !== R.width || d.height !== R.height) && (d.width = R.width, d.height = R.height, A(d)) : (d = new OffscreenCanvas(R.width, R.height), A(d));
1149
+ const j = i.source === M.STREAM ? i.static === !0 : !1;
1150
+ y = j, o = i.source === M.WEBCAM ? { source: M.WEBCAM, sourceKind: "webcam" } : {
1151
+ source: M.STREAM,
1152
+ stream: i.stream,
1144
1153
  static: j,
1145
- sourceKind: a.sourceKind ?? "webcam"
1154
+ sourceKind: i.sourceKind ?? "webcam"
1146
1155
  }, e.set({
1147
- source: a.source,
1148
- sourceKind: r.sourceKind,
1156
+ source: i.source,
1157
+ sourceKind: o.sourceKind,
1149
1158
  error: void 0
1150
1159
  });
1151
- }, q = async (a) => {
1152
- const o = a.sourceKind ?? "webcam";
1153
- u = a.canvas;
1154
- const l = J(u);
1160
+ }, K = async (i) => {
1161
+ const r = i.sourceKind ?? "webcam";
1162
+ d = i.canvas;
1163
+ const l = A(d);
1155
1164
  e.set({
1156
1165
  cameraTexture: l,
1157
- source: y.CANVAS,
1158
- sourceKind: o,
1159
- renderWidth: u.width,
1160
- renderHeight: u.height,
1166
+ source: M.CANVAS,
1167
+ sourceKind: r,
1168
+ renderWidth: d.width,
1169
+ renderHeight: d.height,
1161
1170
  error: void 0
1162
- }), r = {
1163
- source: y.CANVAS,
1164
- canvas: a.canvas,
1165
- sourceKind: o
1171
+ }), o = {
1172
+ source: M.CANVAS,
1173
+ canvas: i.canvas,
1174
+ sourceKind: r
1166
1175
  };
1167
- }, ne = (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, re = async () => {
1168
- if (!u) return;
1169
- const a = e.getSnapshot().pipeline;
1170
- for (const [, o] of a.entries())
1171
- o.resume();
1172
- await new Promise((o) => requestAnimationFrame(() => o())), await new Promise((o) => requestAnimationFrame(() => o()));
1173
- for (const [, o] of a.entries())
1174
- o.pause();
1175
- }, oe = (a, o) => !o || o.source !== y.CANVAS ? !1 : a.canvas === o.canvas && (a.sourceKind ?? "webcam") === o.sourceKind, ce = async (a) => {
1176
- const o = a.source;
1177
- if (o !== y.WEBCAM && o !== y.STREAM)
1178
- throw new F(`Invalid media source: ${String(o)}`);
1179
- if (ne(a, r)) {
1176
+ }, ie = (i, r) => !r || i.source !== r.source ? !1 : i.source === M.STREAM && r.source === M.STREAM ? i.stream === r.stream && (i.sourceKind ?? "webcam") === r.sourceKind : !0, ne = async () => {
1177
+ if (!d) return;
1178
+ const i = e.getSnapshot().pipeline;
1179
+ for (const [, r] of i.entries())
1180
+ r.resume();
1181
+ await new Promise((r) => requestAnimationFrame(() => r())), await new Promise((r) => requestAnimationFrame(() => r()));
1182
+ for (const [, r] of i.entries())
1183
+ r.pause();
1184
+ }, re = (i, r) => !r || r.source !== M.CANVAS ? !1 : i.canvas === r.canvas && (i.sourceKind ?? "webcam") === r.sourceKind, oe = async (i) => {
1185
+ const r = i.source;
1186
+ if (r !== M.WEBCAM && r !== M.STREAM)
1187
+ throw new E(`Invalid media source: ${String(r)}`);
1188
+ if (ie(i, o)) {
1180
1189
  s.log("Media source unchanged, skipping rebind.");
1181
1190
  return;
1182
1191
  }
1183
1192
  const { lifecycle: l } = e.getSnapshot();
1184
1193
  if (l === "idle" || l === "stopped") {
1185
- await H(a), e.set({ lifecycle: "media-bound" }), s.log("Media source set to:", a.source);
1194
+ await q(i), e.set({ lifecycle: "media-bound" }), s.log("Media source set to:", i.source);
1186
1195
  return;
1187
1196
  }
1188
1197
  if (l === "media-bound") {
1189
- O(), await H(a), s.log("Media source rebound to:", a.source);
1198
+ U(), await q(i), s.log("Media source rebound to:", i.source);
1190
1199
  return;
1191
1200
  }
1192
- if (C = !0, await new Promise((v) => requestAnimationFrame(() => v())), O(), await H(a), C = !1, $(), R)
1193
- await re();
1201
+ if (C = !0, await new Promise((v) => requestAnimationFrame(() => v())), U(), await q(i), C = !1, $(), y)
1202
+ await ne();
1194
1203
  else {
1195
1204
  const v = e.getSnapshot().pipeline;
1196
- for (const [, S] of v.entries()) S.resume();
1205
+ for (const [, k] of v.entries()) k.resume();
1197
1206
  }
1198
- s.log("Media source swapped to:", a.source);
1199
- }, he = async (a) => {
1200
- if (oe(a, r)) {
1207
+ s.log("Media source swapped to:", i.source);
1208
+ }, ce = async (i) => {
1209
+ if (re(i, o)) {
1201
1210
  s.log("Frame source unchanged, skipping rebind.");
1202
1211
  return;
1203
1212
  }
1204
- const { lifecycle: o } = e.getSnapshot();
1205
- if (o === "idle" || o === "stopped") {
1206
- await q(a), e.set({ lifecycle: "media-bound" }), s.log("Frame source set to canvas.");
1213
+ const { lifecycle: r } = e.getSnapshot();
1214
+ if (r === "idle" || r === "stopped") {
1215
+ await K(i), e.set({ lifecycle: "media-bound" }), s.log("Frame source set to canvas.");
1207
1216
  return;
1208
1217
  }
1209
- if (o === "media-bound") {
1210
- O(), await q(a), s.log("Frame source rebound to canvas.");
1218
+ if (r === "media-bound") {
1219
+ U(), await K(i), s.log("Frame source rebound to canvas.");
1211
1220
  return;
1212
1221
  }
1213
- C = !0, await new Promise((l) => requestAnimationFrame(() => l())), O(), await q(a), C = !1, s.log("Frame source swapped to canvas.");
1214
- }, de = async () => {
1215
- const { lifecycle: a } = e.getSnapshot();
1216
- if (a === "running") return;
1217
- if (a === "idle")
1218
- throw new F("session.start() called before setMediaSource — call setMediaSource first");
1219
- if (!u)
1220
- throw new F("session.start(): media source not bound");
1221
- const o = (r == null ? void 0 : r.source) === y.CANVAS;
1222
- if (!o && (!c || !m))
1223
- throw a === "stopped" ? new F(
1222
+ C = !0, await new Promise((l) => requestAnimationFrame(() => l())), U(), await K(i), C = !1, s.log("Frame source swapped to canvas.");
1223
+ }, he = async () => {
1224
+ const { lifecycle: i } = e.getSnapshot();
1225
+ if (i === "running") return;
1226
+ if (i === "idle")
1227
+ throw new E("session.start() called before setMediaSource — call setMediaSource first");
1228
+ if (!d)
1229
+ throw new E("session.start(): media source not bound");
1230
+ const r = (o == null ? void 0 : o.source) === M.CANVAS;
1231
+ if (!r && (!c || !m))
1232
+ throw i === "stopped" ? new E(
1224
1233
  "session.start() called from stopped state without a media source — call setMediaSource first"
1225
- ) : new F("session.start(): media source not bound");
1226
- o || $(), e.set({ lifecycle: "running" }), await new Promise((v) => requestAnimationFrame(() => v()));
1234
+ ) : new E("session.start(): media source not bound");
1235
+ r || $(), e.set({ lifecycle: "running" }), await new Promise((v) => requestAnimationFrame(() => v()));
1227
1236
  const l = e.getSnapshot().pipeline;
1228
- for (const [v, S] of l.entries())
1229
- await A(v, S);
1237
+ for (const [v, k] of l.entries())
1238
+ await D(v, k);
1230
1239
  e.set({ ready: !0 }), s.log("XR session started.");
1231
1240
  }, Y = async () => {
1232
- const { lifecycle: a } = e.getSnapshot();
1233
- a === "stopped" || a === "idle" || (O(), e.set({ lifecycle: "stopped", ready: !1 }), s.log("XR session stopped."));
1234
- }, ue = async () => {
1235
- await Y(), P.releaseAll(), b.clear(), E.clear(), r = void 0, u = void 0, m = void 0, R = !1, e.set({
1241
+ const { lifecycle: i } = e.getSnapshot();
1242
+ i === "stopped" || i === "idle" || (U(), e.set({ lifecycle: "stopped", ready: !1 }), s.log("XR session stopped."));
1243
+ }, de = async () => {
1244
+ await Y(), O.releaseAll(), T.clear();
1245
+ const i = e.getSnapshot().cameraTexture;
1246
+ i && i.dispose(), F.clear(), o = void 0, d = void 0, m = void 0, y = !1, e.set({
1236
1247
  lifecycle: "idle",
1237
1248
  cameraTexture: void 0,
1238
1249
  source: void 0
1239
1250
  }), s.log("XR session reset.");
1240
- }, le = async (a) => {
1241
- const o = "legacy:registerXRPipeline", l = [];
1251
+ }, ue = async (i) => {
1252
+ const r = "legacy:registerXRPipeline", l = [];
1242
1253
  await Promise.all(
1243
- a.map(async (v) => {
1244
- const { model: S } = v;
1245
- if (!Z[S])
1246
- throw new F(`Invalid model: ${S}`);
1247
- b.has(S) || l.push(S);
1248
- const M = "options" in v ? v.options : void 0;
1249
- await P.acquire(S, o, M);
1254
+ i.map(async (v) => {
1255
+ const { model: k } = v;
1256
+ if (!Z[k])
1257
+ throw new E(`Invalid model: ${k}`);
1258
+ T.has(k) || l.push(k);
1259
+ const R = "options" in v ? v.options : void 0;
1260
+ await O.acquire(k, r, R);
1250
1261
  })
1251
- ), l.length > 0 && (l.forEach((v) => b.add(v)), s.log("XR pipeline registered."));
1252
- }, ge = (a) => {
1253
- const o = P.get(a);
1254
- if (!o)
1255
- throw new F(`Model ${a} is not registered in the pipeline`);
1256
- return o.getModelNode();
1257
- }, Q = async (a, o) => {
1258
- 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}`));
1262
+ ), l.length > 0 && (l.forEach((v) => T.add(v)), s.log("XR pipeline registered."));
1263
+ }, le = (i) => {
1264
+ const r = O.get(i);
1265
+ if (!r)
1266
+ throw new E(`Model ${i} is not registered in the pipeline`);
1267
+ return r.getModelNode();
1268
+ }, Q = async (i, r) => {
1269
+ i <= 0 || r <= 0 || (e.set({ renderWidth: i, renderHeight: r }), d && (d.width !== i || d.height !== r) && (d.width = i, d.height = r, A(d), y && H()), s.log(`Source canvas set. Render size: ${i}x${r}`));
1259
1270
  };
1260
1271
  return {
1261
1272
  store: e,
1262
- registry: P,
1263
- setMediaSource: ce,
1264
- start: de,
1273
+ registry: O,
1274
+ setMediaSource: oe,
1275
+ start: he,
1265
1276
  stop: Y,
1266
- reset: ue,
1267
- setFrameSource: he,
1268
- registerXRPipeline: le,
1269
- getModelNode: ge,
1277
+ reset: de,
1278
+ setFrameSource: ce,
1279
+ registerXRPipeline: ue,
1280
+ getModelNode: le,
1270
1281
  captureFrame: () => {
1271
1282
  if (!g)
1272
- throw new F(
1283
+ throw new E(
1273
1284
  "session.captureFrame() called before the XRScene render target was bound — make sure <XRScene> is mounted"
1274
1285
  );
1275
1286
  if (!f || !w || !p)
1276
- throw new F(
1287
+ throw new E(
1277
1288
  "session.captureFrame() called before the R3F state was bound — make sure <XRScene> is mounted"
1278
1289
  );
1279
1290
  return f.render(w, p), g.toDataURL("image/png");
1280
1291
  },
1281
- _setRenderTarget: async (a) => {
1282
- var S;
1283
- g = a;
1284
- 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;
1292
+ _setRenderTarget: async (i) => {
1293
+ var k;
1294
+ g = i;
1295
+ const r = (k = i.getBoundingClientRect) == null ? void 0 : k.call(i), l = r && r.width > 0 ? Math.round(r.width) : i.clientWidth, v = r && r.height > 0 ? Math.round(r.height) : i.clientHeight;
1285
1296
  await Q(l, v);
1286
1297
  },
1287
1298
  _setRenderSize: Q,
1288
- _setR3FState: (a) => {
1289
- f = a.renderer, w = a.scene, p = a.camera;
1299
+ _setR3FState: (i) => {
1300
+ f = i.renderer, w = i.scene, p = i.camera;
1290
1301
  },
1291
1302
  _getVideoElement: () => c,
1292
- _setPerf: (a) => {
1293
- if (t = a, e.getSnapshot().lifecycle !== "running" || !u) return;
1294
- const o = e.getSnapshot().pipeline;
1295
- for (const [l, v] of o.entries())
1303
+ _setPerf: (i) => {
1304
+ if (t = i, e.getSnapshot().lifecycle !== "running" || !d) return;
1305
+ const r = e.getSnapshot().pipeline;
1306
+ for (const [l, v] of r.entries())
1296
1307
  v.run({
1297
- sourceCanvas: u,
1308
+ sourceCanvas: d,
1298
1309
  renderWidth: e.getSnapshot().renderWidth,
1299
1310
  renderHeight: e.getSnapshot().renderHeight,
1300
1311
  getSource: () => e.getSnapshot().sourceKind,
@@ -1302,30 +1313,29 @@ const Z = {
1302
1313
  });
1303
1314
  }
1304
1315
  };
1305
- }, at = (i) => {
1306
- const s = ee(() => it(i), []), e = JSON.stringify(i ?? {});
1307
- return ve(() => {
1308
- s._setPerf(i);
1316
+ }, at = (a) => {
1317
+ const s = J(() => st(a), []), e = JSON.stringify(a ?? {});
1318
+ return pe(() => {
1319
+ s._setPerf(a);
1309
1320
  }, [s, e]), s;
1310
- }, ie = Ce(void 0), wt = () => {
1311
- const i = Se(ie);
1312
- if (!i)
1313
- throw new F(
1321
+ }, se = we(void 0), vt = () => {
1322
+ const a = ve(se);
1323
+ if (!a)
1324
+ throw new E(
1314
1325
  "XR context can only be used inside XRProvider, did you forget to wrap your app in <XRProvider>?"
1315
1326
  );
1316
- return i;
1317
- }, vt = ({ children: i, perf: s }) => {
1318
- const e = at(s), t = ee(() => ({ session: e }), [e]);
1319
- return /* @__PURE__ */ we(ie.Provider, { value: t, children: i });
1327
+ return a;
1328
+ }, Ct = ({ children: a, perf: s }) => {
1329
+ const e = at(s), t = J(() => ({ session: e }), [e]);
1330
+ return /* @__PURE__ */ fe(se.Provider, { value: t, children: a });
1320
1331
  };
1321
1332
  export {
1322
- ft as R,
1323
- _ as X,
1324
- vt as a,
1325
- y as b,
1326
- V as c,
1327
- pt as d,
1328
- Ie as f,
1329
- x as l,
1330
- wt as u
1333
+ pt as R,
1334
+ P as X,
1335
+ V as a,
1336
+ wt as b,
1337
+ Ct as c,
1338
+ M as d,
1339
+ Ee as f,
1340
+ vt as u
1331
1341
  };