@vincentt-xr/sdk 2.0.0-alpha.6 → 2.0.0-alpha.7

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 (77) hide show
  1. package/GROUNDING.md +81 -3
  2. package/dist/{DebuggerUI-DYT_dk1E.cjs → DebuggerUI-B6bP6P9r.cjs} +1 -1
  3. package/dist/{DebuggerUI-C_rbLdkh.js → DebuggerUI-BjOMr8q_.js} +1 -1
  4. package/dist/{FaceMeshRenderer-D1WsrTLA.cjs → FaceMeshRenderer-C5l6VLdO.cjs} +6 -6
  5. package/dist/{FaceMeshRenderer-DSCd1H55.js → FaceMeshRenderer-wjAHrJzP.js} +102 -96
  6. package/dist/{FaceRetouch-DsE0Dbw-.cjs → FaceRetouch-BkJzoA79.cjs} +1 -1
  7. package/dist/{FaceRetouch-CMJbGThL.js → FaceRetouch-DwbKQJAN.js} +4 -4
  8. package/dist/components/FaceMesh/FaceMeshRenderer.d.ts +11 -3
  9. package/dist/components/FaceMesh/canonical/CanonicalFaceMeshRenderer.d.ts +10 -4
  10. package/dist/components/FaceMesh/index.d.ts +2 -2
  11. package/dist/components/SceneObjectRenderer/index.d.ts +9 -2
  12. package/dist/components/XRMediaSurface/index.d.ts +2 -1
  13. package/dist/{contexts-DvQI4PqI.js → contexts-ByhzppYl.js} +3 -3
  14. package/dist/{contexts-h-9TRH0r.cjs → contexts-Dr62It_K.cjs} +1 -1
  15. package/dist/debug-ui/media-source.cjs +1 -1
  16. package/dist/debug-ui/media-source.js +1 -1
  17. package/dist/debug-ui.cjs +1 -1
  18. package/dist/debug-ui.js +10 -10
  19. package/dist/entries/core.d.ts +3 -2
  20. package/dist/entries/face-effects.d.ts +2 -2
  21. package/dist/entries/tracking.d.ts +2 -0
  22. package/dist/face-effects.cjs +1 -1
  23. package/dist/face-effects.js +25 -24
  24. package/dist/{getFaceInfo-B43Cwq4n.js → getFaceInfo-C4QpCQIY.js} +1 -1
  25. package/dist/{getFaceInfo-DEzcL_Ub.cjs → getFaceInfo-fA1bFBub.cjs} +1 -1
  26. package/dist/hooks/useXRSession/facade.d.ts +2 -0
  27. package/dist/{index-I4eF5TKT.js → index-9dlAQAhy.js} +405 -400
  28. package/dist/{index-CY7Z8cHV.cjs → index-BjmTe9eM.cjs} +1 -1
  29. package/dist/{index-D67hHm44.cjs → index-BpEf2BBb.cjs} +1 -1
  30. package/dist/{index-B-s4YbWu.js → index-ByoNj0QP.js} +1 -1
  31. package/dist/{index-CxMEeCRP.cjs → index-CyUUurQT.cjs} +1 -1
  32. package/dist/index-DCiMbxC3.cjs +1 -0
  33. package/dist/{index-G_5h_FJQ.js → index-DXT3WccE.js} +808 -787
  34. package/dist/index-DpI-qo5X.cjs +17 -0
  35. package/dist/{index-DYfY9ljy.js → index-DyVF4vEW.js} +1 -1
  36. package/dist/{index-uE3sKczj.js → index-VJ0SJwmG.js} +1 -1
  37. package/dist/{internal-MvKrz0Nt.cjs → internal-Cq-TEQ5Y.cjs} +1 -1
  38. package/dist/{internal-ldPYiUF0.js → internal-Dmk1cTXq.js} +3 -3
  39. package/dist/internal.cjs +1 -1
  40. package/dist/internal.js +1 -1
  41. package/dist/low-level.cjs +1 -1
  42. package/dist/low-level.js +344 -330
  43. package/dist/main.cjs +1 -1
  44. package/dist/main.js +94 -91
  45. package/dist/{renderGroups-BJsx32q5.cjs → renderGroups-80H3DpTl.cjs} +1 -1
  46. package/dist/{renderGroups-CFt1yYLB.js → renderGroups-KZk6eRiY.js} +1 -1
  47. package/dist/{renderPasses-D-Krl6D0.cjs → renderPasses-BOoBSr8z.cjs} +1 -1
  48. package/dist/{renderPasses-C72MbZ-a.js → renderPasses-BcquyVtu.js} +4 -4
  49. package/dist/scene-object.cjs +1 -1
  50. package/dist/scene-object.js +2 -2
  51. package/dist/screen2d/coordinates.d.ts +20 -0
  52. package/dist/{selectors-ByKNTXeA.js → selectors-B8H97CKA.js} +1 -1
  53. package/dist/{selectors-CAwmL9VW.cjs → selectors-CZLKT2Iv.cjs} +1 -1
  54. package/dist/{session-CANvoLD6.cjs → session-CpkiK5YA.cjs} +1 -1
  55. package/dist/{session-Dhi0OqZo.js → session-DLFN_VII.js} +1 -1
  56. package/dist/tracking/coordinates.d.ts +5 -0
  57. package/dist/tracking.cjs +1 -1
  58. package/dist/tracking.js +69 -66
  59. package/dist/types/common.d.ts +11 -1
  60. package/dist/types/gesture-tracking.d.ts +2 -2
  61. package/dist/types/hand-tracking.d.ts +3 -3
  62. package/dist/types/nodes.d.ts +2 -2
  63. package/dist/types/session.d.ts +7 -1
  64. package/dist/{useFaceInfo-BSZq7AO1.cjs → useFaceInfo-BJ8-_MOs.cjs} +1 -1
  65. package/dist/{useFaceInfo-FVQBBNdY.js → useFaceInfo-Dk426LTu.js} +3 -3
  66. package/dist/{useFaceResults-D62STzT1.js → useFaceResults-CtetsO9M.js} +1 -1
  67. package/dist/{useFaceResults-C3oZkn2Z.cjs → useFaceResults-wBJF3zyp.cjs} +1 -1
  68. package/docs/SDK_DOCUMENTATION.md +3 -0
  69. package/docs/api/capture-recording.mdx +9 -1
  70. package/docs/api/face-mesh.mdx +33 -0
  71. package/docs/api/runtime-3d.mdx +5 -0
  72. package/docs/api/screen-image.mdx +3 -1
  73. package/docs/api/screen-space-coordinates.mdx +31 -0
  74. package/docs/api/trackers.mdx +13 -0
  75. package/package.json +4 -1
  76. package/dist/index-C0-fg1Hk.cjs +0 -1
  77. package/dist/index-DPPpU5By.cjs +0 -17
@@ -1,19 +1,19 @@
1
- var Ee = Object.defineProperty;
2
- var Ie = (n, s, e) => s in n ? Ee(n, s, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[s] = e;
3
- var h = (n, s, e) => Ie(n, typeof s != "symbol" ? s + "" : s, e);
4
- import { jsx as re } from "react/jsx-runtime";
5
- import { useRef as he, useMemo as J, useEffect as Pe, useContext as de, useCallback as oe, createElement as De, createContext as ue } from "react";
6
- import { FilesetResolver as V, PoseLandmarker as _e, FaceLandmarker as Oe, GestureRecognizer as Ue, HandLandmarker as ze, ImageSegmenter as Le, DrawingUtils as Be } from "@mediapipe/tasks-vision";
1
+ var De = Object.defineProperty;
2
+ var _e = (a, s, e) => s in a ? De(a, s, { enumerable: !0, configurable: !0, writable: !0, value: e }) : a[s] = e;
3
+ var h = (a, s, e) => _e(a, typeof s != "symbol" ? s + "" : s, e);
4
+ import { jsx as ce } from "react/jsx-runtime";
5
+ import { useRef as ue, useMemo as ee, useEffect as Oe, useContext as le, useCallback as he, createElement as Ue, createContext as ge } from "react";
6
+ import { FilesetResolver as V, PoseLandmarker as ze, FaceLandmarker as Le, GestureRecognizer as Be, HandLandmarker as Ve, ImageSegmenter as Ke, DrawingUtils as Ne } from "@mediapipe/tasks-vision";
7
7
  import * as E from "three";
8
- import { RGBAFormat as le, LinearFilter as G, CanvasTexture as ge, SRGBColorSpace as Ve } from "three";
9
- var F = /* @__PURE__ */ ((n) => (n.WEBCAM = "webcam", n.STREAM = "stream", n.CANVAS = "canvas", n))(F || {}), z = /* @__PURE__ */ ((n) => (n.HAND_TRACKER = "vincentt.xr.hand-tracker", n.GESTURE_TRACKER = "vincentt.xr.gesture-tracker", n.FACE_TRACKER = "vincentt.xr.face-tracker", n.BODY_TRACKER = "vincentt.xr.body-tracker", n.BACKGROUND_SEGMENTATION = "vincentt.xr.background-segmentation", n))(z || {});
8
+ import { RGBAFormat as me, LinearFilter as G, CanvasTexture as fe, SRGBColorSpace as He } from "three";
9
+ var T = /* @__PURE__ */ ((a) => (a.WEBCAM = "webcam", a.STREAM = "stream", a.CANVAS = "canvas", a))(T || {}), U = /* @__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))(U || {});
10
10
  class b extends Error {
11
11
  constructor(s) {
12
12
  super(s), this.name = "VincenttXRError";
13
13
  }
14
14
  }
15
- const Ke = (n, s) => s, I = {
16
- apiBaseUrl: Ke(void 0, "https://api.vincentt.studio"),
15
+ const qe = (a, s) => s, I = {
16
+ apiBaseUrl: qe(void 0, "https://api.vincentt.studio"),
17
17
  // Pinned to the CDN, NOT build-env-driven: a stale VITE_ASSET_STORAGE_ENDPOINT
18
18
  // baked a now-deleted CloudFront domain into every published bundle, breaking
19
19
  // WASM/model loads at runtime. The host must never come from a mutable env value.
@@ -23,7 +23,7 @@ const Ke = (n, s) => s, I = {
23
23
  loggerPrefix: "[vincentt-xr]:",
24
24
  sessionCheckInterval: 3e4
25
25
  };
26
- class Ne {
26
+ class Ge {
27
27
  constructor(s) {
28
28
  h(this, "options");
29
29
  const e = {
@@ -41,12 +41,12 @@ class Ne {
41
41
  e && console.error(t, ...s);
42
42
  }
43
43
  }
44
- const O = (n) => n * 2 - 1, Y = new E.Vector3(), Q = new E.Vector3(), q = ({ x: n, y: s, z: e }, t, i) => {
45
- Y.set((n - 0.5) * 2, (0.5 - s) * 2, -e), Y.unproject(t), Q.copy(Y).sub(t.position).normalize();
46
- const r = -t.position.z / Q.z;
47
- return i.copy(t.position).addScaledVector(Q, r), i;
48
- }, Ut = (n, s) => q(n, s, new E.Vector3()), He = (n, s, e = 0.2) => e * s + (1 - e) * n;
49
- class ee {
44
+ const te = (a, s = { x: 0, y: 0, z: 0 }) => (s.x = a.x * 2 - 1, s.y = 1 - a.y * 2, s.z = -a.z, s), Vt = (a, s = { x: 0, y: 0, z: 0 }) => (s.x = (a.x + 1) / 2, s.y = (1 - a.y) / 2, s.z = -a.z, s), Q = new E.Vector3(), $ = new E.Vector3(), q = ({ x: a, y: s, z: e }, t, i) => {
45
+ Q.set((a - 0.5) * 2, (0.5 - s) * 2, -e), Q.unproject(t), $.copy(Q).sub(t.position).normalize();
46
+ const r = -t.position.z / $.z;
47
+ return i.copy(t.position).addScaledVector($, r), i;
48
+ }, Kt = (a, s) => q(a, s, new E.Vector3()), We = (a, s, e = 0.2) => e * s + (1 - e) * a;
49
+ class se {
50
50
  constructor(s) {
51
51
  h(this, "canvas");
52
52
  this.maxDimension = s;
@@ -59,16 +59,16 @@ class ee {
59
59
  draw(s) {
60
60
  const e = s.width, t = s.height, i = Math.min(1, this.maxDimension / Math.max(e, t));
61
61
  if (i >= 1) return s;
62
- const r = Math.max(1, Math.round(e * i)), o = Math.max(1, Math.round(t * i));
63
- (!this.canvas || this.canvas.width !== r || this.canvas.height !== o) && (this.canvas = new OffscreenCanvas(r, o));
64
- const u = this.canvas.getContext("2d");
65
- return u ? (u.setTransform(1, 0, 0, 1, 0, 0), u.clearRect(0, 0, r, o), u.drawImage(s, 0, 0, r, o), this.canvas) : s;
62
+ const r = Math.max(1, Math.round(e * i)), c = Math.max(1, Math.round(t * i));
63
+ (!this.canvas || this.canvas.width !== r || this.canvas.height !== c) && (this.canvas = new OffscreenCanvas(r, c));
64
+ const d = this.canvas.getContext("2d");
65
+ 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;
66
66
  }
67
67
  dispose() {
68
68
  this.canvas = void 0;
69
69
  }
70
70
  }
71
- const qe = {
71
+ const Xe = {
72
72
  "/assets/xr/models/face_tracking.task": "sha384-tYQh+yJE8llY+zO4RviZmWaSKs5W9tsB0ix5rjQVpF5/CLTqmwtP7bYtkUi2w65P",
73
73
  "/assets/xr/models/hand_tracking.task": "sha384-uWvruVKd887ov8k43S+DBHCsi7UXXS+CKvvdM1PX00rjPzx/B0QrAPfJ1U9yKcze",
74
74
  "/assets/xr/models/gesture_tracking.task": "sha384-2zuseP9JKKWAYlWQGKA2N+ooabB8V/yIxu23Mv8mtY7SowcySB+xKiOmqBhVvlUC",
@@ -78,61 +78,61 @@ const qe = {
78
78
  "/assets/sdk/face/v1/canonical_face_model.obj": "sha384-xP8YM/72TXKvbMptXB9a8JUlUf3MZQ8uLurExrsZc05v6/P5RrsaNGMUYS/BZx8A",
79
79
  "/opencv/facial_expression_recognition/resolve/main/facial_expression_recognition_mobilefacenet_2022july_int8.onnx": "sha384-g8mtFubiIc/yhqi591RsxD76AJLw2CfYgKhKbVkIiFlwBmIyG7ZAIVyGPXafrDGB"
80
80
  };
81
- async function Ge(n) {
82
- const s = await fetch(n);
81
+ async function je(a) {
82
+ const s = await fetch(a);
83
83
  if (!s.ok)
84
- throw new Error(`fetchAndVerify: ${s.status} ${n}`);
85
- const e = await s.arrayBuffer(), t = Xe(n);
84
+ throw new Error(`fetchAndVerify: ${s.status} ${a}`);
85
+ const e = await s.arrayBuffer(), t = Qe(a);
86
86
  if (!t) {
87
- if (We(n))
88
- throw new Error(`[xr-sdk integrity] no SRI hash for SDK asset ${n}`);
89
- return console.warn(`[xr-sdk integrity] no SRI hash for ${n} — passing through`), e;
87
+ if (Ye(a))
88
+ throw new Error(`[xr-sdk integrity] no SRI hash for SDK asset ${a}`);
89
+ return console.warn(`[xr-sdk integrity] no SRI hash for ${a} — passing through`), e;
90
90
  }
91
- const i = await je(e);
91
+ const i = await $e(e);
92
92
  if (i !== t)
93
93
  throw new Error(
94
- `[xr-sdk integrity] SRI mismatch for ${n}: expected ${t}, got ${i}`
94
+ `[xr-sdk integrity] SRI mismatch for ${a}: expected ${t}, got ${i}`
95
95
  );
96
96
  return e;
97
97
  }
98
- function We(n) {
98
+ function Ye(a) {
99
99
  try {
100
- return new URL(n).origin === new URL(I.assetStorageEndpoint).origin;
100
+ return new URL(a).origin === new URL(I.assetStorageEndpoint).origin;
101
101
  } catch {
102
102
  return !1;
103
103
  }
104
104
  }
105
- async function K(n) {
106
- const s = await Ge(n);
105
+ async function K(a) {
106
+ const s = await je(a);
107
107
  return new Uint8Array(s);
108
108
  }
109
- function Xe(n) {
109
+ function Qe(a) {
110
110
  try {
111
- const s = new URL(n);
112
- return qe[s.pathname];
111
+ const s = new URL(a);
112
+ return Xe[s.pathname];
113
113
  } catch {
114
114
  return;
115
115
  }
116
116
  }
117
- async function je(n) {
118
- const s = await crypto.subtle.digest("SHA-384", n), e = new Uint8Array(s);
117
+ async function $e(a) {
118
+ const s = await crypto.subtle.digest("SHA-384", a), e = new Uint8Array(s);
119
119
  let t = "";
120
120
  for (let i = 0; i < e.byteLength; i++)
121
121
  t += String.fromCharCode(e[i]);
122
122
  return `sha384-${btoa(t)}`;
123
123
  }
124
- const $ = /* @__PURE__ */ new Map();
125
- function N(n) {
126
- const s = n.wasmBinaryPath;
127
- let e = $.get(s);
128
- return e || (e = Ye(s).catch(() => {
129
- $.delete(s);
130
- }), $.set(s, e)), e;
124
+ const Z = /* @__PURE__ */ new Map();
125
+ function N(a) {
126
+ const s = a.wasmBinaryPath;
127
+ let e = Z.get(s);
128
+ return e || (e = Ze(s).catch(() => {
129
+ Z.delete(s);
130
+ }), Z.set(s, e)), e;
131
131
  }
132
- async function Ye(n) {
133
- const s = await fetch(n, { credentials: "same-origin" });
132
+ async function Ze(a) {
133
+ const s = await fetch(a, { credentials: "same-origin" });
134
134
  if (!s.ok || !s.body)
135
- throw new Error(`warmVisionWasm: ${s.status} ${n}`);
135
+ throw new Error(`warmVisionWasm: ${s.status} ${a}`);
136
136
  const e = s.body.getReader();
137
137
  for (; ; ) {
138
138
  const { done: t } = await e.read();
@@ -201,30 +201,29 @@ class H {
201
201
  this.disposed = !0, this.rafId !== null && (cancelAnimationFrame(this.rafId), this.rafId = null);
202
202
  }
203
203
  }
204
- const Qe = 768;
205
- class $e extends H {
204
+ const Je = 768;
205
+ class et extends H {
206
206
  constructor() {
207
207
  super();
208
208
  h(this, "landmarker", null);
209
209
  h(this, "processingTime", null);
210
210
  h(this, "coordinates");
211
211
  h(this, "sourceCanvas");
212
- h(this, "downscaler", new ee(Qe));
212
+ h(this, "downscaler", new se(Je));
213
213
  }
214
214
  async getBodyData() {
215
215
  if (!this.landmarker || !this.sourceCanvas)
216
216
  return;
217
217
  const e = this.downscaler.draw(this.sourceCanvas), t = performance.now(), i = this.landmarker.detectForVideo(e, t), r = performance.now();
218
218
  this.processingTime = r - t;
219
- const o = i.landmarks, u = [];
220
- if (o)
221
- return o.forEach((m, d) => {
222
- u[d] || (u[d] = []), m.forEach((S) => {
223
- const R = O(S.x), M = O(1 - S.y), x = O(S.z);
224
- u[d].push({ x: R, y: M, z: x });
219
+ const c = i.landmarks, d = [];
220
+ if (c)
221
+ return c.forEach((m, u) => {
222
+ d[u] || (d[u] = []), m.forEach((C) => {
223
+ d[u].push(te(C));
225
224
  });
226
225
  }), {
227
- coordinatesList: u
226
+ coordinatesList: d
228
227
  };
229
228
  }
230
229
  async processBodyTracking() {
@@ -262,7 +261,7 @@ class $e extends H {
262
261
  ),
263
262
  N(t)
264
263
  ]);
265
- this.landmarker = await _e.createFromOptions(t, {
264
+ this.landmarker = await ze.createFromOptions(t, {
266
265
  baseOptions: {
267
266
  modelAssetBuffer: i,
268
267
  delegate: "GPU"
@@ -286,8 +285,8 @@ class $e extends H {
286
285
  };
287
286
  }
288
287
  }
289
- const Ze = 0.11, Je = 4e-3, et = (n, s) => s.set(n.x, -n.y, n.z);
290
- class tt extends H {
288
+ const tt = 0.11, st = 4e-3, at = (a, s) => s.set(a.x, -a.y, a.z);
289
+ class nt extends H {
291
290
  constructor() {
292
291
  super();
293
292
  h(this, "landmarker", null);
@@ -342,33 +341,33 @@ class tt extends H {
342
341
  for (let r = 0; r < t; r += 1) {
343
342
  if (!this.cameras[r])
344
343
  continue;
345
- const o = this.faces[r], u = (i = this.getSource) == null ? void 0 : i.call(this), m = !(u === "webcam" || !u), d = e.faceLandmarks[r], S = e.facialTransformationMatrixes[r];
346
- this.rotMatrixScratch.fromArray(S.data), this.rotQuatScratch.setFromRotationMatrix(this.rotMatrixScratch), this.rotQuatScratch.set(
344
+ const c = this.faces[r], d = (i = this.getSource) == null ? void 0 : i.call(this), m = !(d === "webcam" || !d), u = e.faceLandmarks[r], C = e.facialTransformationMatrixes[r];
345
+ this.rotMatrixScratch.fromArray(C.data), this.rotQuatScratch.setFromRotationMatrix(this.rotMatrixScratch), this.rotQuatScratch.set(
347
346
  -this.rotQuatScratch.x,
348
347
  this.rotQuatScratch.y,
349
348
  this.rotQuatScratch.z,
350
349
  this.rotQuatScratch.w
351
- ), this.rotEulerScratch.setFromQuaternion(this.rotQuatScratch, "XYZ"), et(this.rotEulerScratch, o.transform.rotation), q(
352
- this.landmarkForSource(d[4], m),
350
+ ), this.rotEulerScratch.setFromQuaternion(this.rotQuatScratch, "XYZ"), at(this.rotEulerScratch, c.transform.rotation), q(
351
+ this.landmarkForSource(u[4], m),
353
352
  this.cameras[r],
354
- o.transform.position
353
+ c.transform.position
355
354
  ), q(
356
- this.landmarkForSource(d[50], m),
355
+ this.landmarkForSource(u[50], m),
357
356
  this.cameras[r],
358
357
  this.leftCheekScratch[r]
359
358
  ), q(
360
- this.landmarkForSource(d[280], m),
359
+ this.landmarkForSource(u[280], m),
361
360
  this.cameras[r],
362
361
  this.rightCheekScratch[r]
363
362
  );
364
- const M = this.leftCheekScratch[r].distanceTo(this.rightCheekScratch[r]) * Ze, x = Math.abs(E.MathUtils.radToDeg(this.rotEulerScratch.y)), l = M + x * Je, f = o.transform.scale.x, v = He(
363
+ const M = this.leftCheekScratch[r].distanceTo(this.rightCheekScratch[r]) * tt, F = Math.abs(E.MathUtils.radToDeg(this.rotEulerScratch.y)), l = M + F * st, f = c.transform.scale.x, v = We(
365
364
  isNaN(f) ? 0 : f,
366
365
  l
367
366
  );
368
- o.transform.scale.set(v, v, v);
369
- const p = o.gestures, k = e.faceBlendshapes[r].categories;
370
- for (const C of k)
371
- p[C.categoryName] = C.score;
367
+ c.transform.scale.set(v, v, v);
368
+ const p = c.gestures, k = e.faceBlendshapes[r].categories;
369
+ for (const S of k)
370
+ p[S.categoryName] = S.score;
372
371
  }
373
372
  }
374
373
  async processFaceTracking() {
@@ -378,16 +377,16 @@ class tt extends H {
378
377
  this.rafId = requestAnimationFrame(this.processFaceTracking.bind(this));
379
378
  return;
380
379
  }
381
- const e = st(this.numFaces), t = this.sourceCanvas.width, i = this.sourceCanvas.height, r = Math.min(1, e / Math.max(t, i)), o = Math.max(1, Math.round(t * r)), u = Math.max(1, Math.round(i * r));
382
- (!this.analysisCanvas || this.analysisCanvas.width !== o || this.analysisCanvas.height !== u) && (this.analysisCanvas = new OffscreenCanvas(o, u));
380
+ const e = it(this.numFaces), t = this.sourceCanvas.width, i = this.sourceCanvas.height, r = Math.min(1, e / Math.max(t, i)), c = Math.max(1, Math.round(t * r)), d = Math.max(1, Math.round(i * r));
381
+ (!this.analysisCanvas || this.analysisCanvas.width !== c || this.analysisCanvas.height !== d) && (this.analysisCanvas = new OffscreenCanvas(c, d));
383
382
  const m = this.analysisCanvas.getContext("2d");
384
383
  if (!m) {
385
384
  this.rafId = requestAnimationFrame(this.processFaceTracking.bind(this));
386
385
  return;
387
386
  }
388
- m.setTransform(1, 0, 0, 1, 0, 0), m.clearRect(0, 0, o, u), m.drawImage(this.sourceCanvas, 0, 0, o, u);
389
- const d = performance.now(), S = this.landmarker.detectForVideo(this.analysisCanvas, d), R = performance.now();
390
- this.processingTime = R - d, this.detectionResults = S, this.extractAndUpdateFaceData(S), !(this.disposed || this.paused) && (this.rafId = requestAnimationFrame(this.processFaceTracking.bind(this)));
387
+ m.setTransform(1, 0, 0, 1, 0, 0), m.clearRect(0, 0, c, d), m.drawImage(this.sourceCanvas, 0, 0, c, d);
388
+ const u = performance.now(), C = this.landmarker.detectForVideo(this.analysisCanvas, u), x = performance.now();
389
+ this.processingTime = x - u, this.detectionResults = C, this.extractAndUpdateFaceData(C), !(this.disposed || this.paused) && (this.rafId = requestAnimationFrame(this.processFaceTracking.bind(this)));
391
390
  }
392
391
  resume() {
393
392
  this.paused && (super.resume(), this.processFaceTracking());
@@ -409,12 +408,12 @@ class tt extends H {
409
408
  return this.detectionResults;
410
409
  }
411
410
  getRawFaceTrackingData(e = 0) {
412
- var t, i, r, o;
411
+ var t, i, r, c;
413
412
  if (this.detectionResults)
414
413
  return {
415
414
  landmarks: (t = this.detectionResults.faceLandmarks) == null ? void 0 : t[e],
416
415
  blendshapes: (r = (i = this.detectionResults.faceBlendshapes) == null ? void 0 : i[e]) == null ? void 0 : r.categories,
417
- transformationMatrix: (o = this.detectionResults.facialTransformationMatrixes) == null ? void 0 : o[e]
416
+ transformationMatrix: (c = this.detectionResults.facialTransformationMatrixes) == null ? void 0 : c[e]
418
417
  };
419
418
  }
420
419
  async initialize(e) {
@@ -426,7 +425,7 @@ class tt extends H {
426
425
  new URL("/assets/xr/models/face_tracking.task", I.assetStorageEndpoint).toString()
427
426
  ),
428
427
  N(t)
429
- ]), r = await Oe.createFromOptions(t, {
428
+ ]), r = await Le.createFromOptions(t, {
430
429
  baseOptions: {
431
430
  modelAssetBuffer: i,
432
431
  delegate: "GPU"
@@ -470,9 +469,9 @@ class tt extends H {
470
469
  };
471
470
  }
472
471
  }
473
- const st = (n) => n > 1 ? 1024 : 512;
474
- var P = /* @__PURE__ */ ((n) => (n.ClosedFist = "closed_fist", n.OpenPalm = "open_palm", n.PointingUp = "pointing_up", n.ThumbDown = "thumb_down", n.ThumbUp = "thumb_up", n.Victory = "victory", n.ILoveYou = "i_love_you", n.None = "none", n))(P || {});
475
- const nt = 512, at = {
472
+ const it = (a) => a > 1 ? 1024 : 512;
473
+ var P = /* @__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))(P || {});
474
+ const rt = 512, ot = {
476
475
  Closed_Fist: P.ClosedFist,
477
476
  Open_Palm: P.OpenPalm,
478
477
  Pointing_Up: P.PointingUp,
@@ -481,8 +480,8 @@ const nt = 512, at = {
481
480
  Victory: P.Victory,
482
481
  ILoveYou: P.ILoveYou,
483
482
  None: P.None
484
- }, it = 15;
485
- class rt extends H {
483
+ }, ct = 15;
484
+ class ht extends H {
486
485
  constructor() {
487
486
  super();
488
487
  h(this, "landmarker", null);
@@ -490,25 +489,21 @@ class rt extends H {
490
489
  h(this, "coordinates");
491
490
  h(this, "gesture");
492
491
  h(this, "sourceCanvas");
493
- h(this, "downscaler", new ee(nt));
492
+ h(this, "downscaler", new se(rt));
494
493
  }
495
494
  async getGestureData() {
496
495
  if (!this.landmarker || !this.sourceCanvas)
497
496
  return;
498
497
  const e = this.downscaler.draw(this.sourceCanvas), t = performance.now(), i = this.landmarker.recognizeForVideo(e, t), r = performance.now();
499
498
  this.processingTime = r - t;
500
- const o = i.landmarks[0], u = [];
501
- if (o) {
499
+ const c = i.landmarks[0], d = [];
500
+ if (c) {
502
501
  const m = i.gestures[0][0].categoryName;
503
- return o.forEach((d) => {
504
- u.push({
505
- x: O(d.x),
506
- y: O(1 - d.y),
507
- z: -d.z
508
- });
502
+ return c.forEach((u) => {
503
+ d.push(te(u));
509
504
  }), {
510
- coordinates: u,
511
- gesture: at[m]
505
+ coordinates: d,
506
+ gesture: ot[m]
512
507
  };
513
508
  }
514
509
  return { coordinates: void 0, gesture: void 0 };
@@ -546,7 +541,7 @@ class rt extends H {
546
541
  ).toString()
547
542
  ),
548
543
  N(e)
549
- ]), i = await Ue.createFromOptions(e, {
544
+ ]), i = await Be.createFromOptions(e, {
550
545
  baseOptions: {
551
546
  modelAssetBuffer: t,
552
547
  delegate: "GPU"
@@ -557,7 +552,7 @@ class rt extends H {
557
552
  this.landmarker = i;
558
553
  }
559
554
  async run({ sourceCanvas: e, targetFps: t }) {
560
- this.sourceCanvas = e, this.setTargetFps(t ?? it), this.rafId === null && await this.processGestureTracking();
555
+ this.sourceCanvas = e, this.setTargetFps(t ?? ct), this.rafId === null && await this.processGestureTracking();
561
556
  }
562
557
  getModelNode() {
563
558
  const e = this;
@@ -577,8 +572,8 @@ class rt extends H {
577
572
  };
578
573
  }
579
574
  }
580
- const ot = 512;
581
- class ct extends H {
575
+ const dt = 512;
576
+ class ut extends H {
582
577
  constructor() {
583
578
  super();
584
579
  h(this, "landmarker", null);
@@ -588,34 +583,32 @@ class ct extends H {
588
583
  h(this, "gesture");
589
584
  h(this, "handedness");
590
585
  h(this, "sourceCanvas");
591
- h(this, "downscaler", new ee(ot));
586
+ h(this, "downscaler", new se(dt));
592
587
  }
593
588
  async getHandData() {
594
589
  if (!this.landmarker || !this.sourceCanvas)
595
590
  return;
596
591
  const e = this.downscaler.draw(this.sourceCanvas), t = performance.now(), i = this.landmarker.detectForVideo(e, t), r = performance.now();
597
592
  this.processingTime = r - t;
598
- const o = [], u = i.handedness ?? i.handednesses ?? [];
599
- if (i.landmarks.forEach((d, S) => {
593
+ const c = [], d = i.handedness ?? i.handednesses ?? [];
594
+ if (i.landmarks.forEach((u, C) => {
600
595
  var f, v, p;
601
- if (!d || d.length === 0)
596
+ if (!u || u.length === 0)
602
597
  return;
603
- const R = d.map((k) => ({
604
- x: O(k.x),
605
- y: O(1 - k.y),
606
- z: -k.z
607
- })), M = (p = (v = (f = u[S]) == null ? void 0 : f[0]) == null ? void 0 : v.categoryName) == null ? void 0 : p.toLowerCase(), x = M === "left" || M === "right" ? M : void 0, l = d[0].z < 0 ? "closed_fist" : "open_palm";
608
- o.push({ coordinates: R, gesture: l, handedness: x });
609
- }), !o.length)
598
+ const x = u.map(
599
+ (k) => te(k)
600
+ ), M = (p = (v = (f = d[C]) == null ? void 0 : f[0]) == null ? void 0 : v.categoryName) == null ? void 0 : p.toLowerCase(), F = M === "left" || M === "right" ? M : void 0, l = u[0].z < 0 ? "closed_fist" : "open_palm";
601
+ c.push({ coordinates: x, gesture: l, handedness: F });
602
+ }), !c.length)
610
603
  return {
611
604
  hands: void 0,
612
605
  coordinates: void 0,
613
606
  gesture: void 0,
614
607
  handedness: void 0
615
608
  };
616
- const m = o[0];
609
+ const m = c[0];
617
610
  return {
618
- hands: o,
611
+ hands: c,
619
612
  coordinates: m.coordinates,
620
613
  gesture: m.gesture,
621
614
  handedness: m.handedness
@@ -651,7 +644,7 @@ class ct extends H {
651
644
  new URL("/assets/xr/models/hand_tracking.task", I.assetStorageEndpoint).toString()
652
645
  ),
653
646
  N(e)
654
- ]), i = await ze.createFromOptions(e, {
647
+ ]), i = await Ve.createFromOptions(e, {
655
648
  baseOptions: {
656
649
  modelAssetBuffer: t,
657
650
  delegate: "GPU"
@@ -688,13 +681,13 @@ class ct extends H {
688
681
  };
689
682
  }
690
683
  }
691
- const ht = 24, dt = 720, ut = [
684
+ const lt = 24, gt = 720, mt = [
692
685
  [255, 255, 255, 255],
693
686
  // 0: background → green 255, kept
694
687
  [0, 0, 0, 0]
695
688
  // 1: person → green 0, discarded
696
689
  ];
697
- class lt extends H {
690
+ class ft extends H {
698
691
  constructor() {
699
692
  super();
700
693
  h(this, "segmenter", null);
@@ -780,7 +773,7 @@ class lt extends H {
780
773
  const e = this.readIntrinsicSize(this.inputSource);
781
774
  if (!e) return;
782
775
  this.inputSourceSize = e;
783
- const t = Math.min(1, dt / Math.max(e.width, e.height)), i = Math.max(1, Math.round(e.width * t)), r = Math.max(1, Math.round(e.height * t));
776
+ const t = Math.min(1, gt / Math.max(e.width, e.height)), i = Math.max(1, Math.round(e.width * t)), r = Math.max(1, Math.round(e.height * t));
784
777
  this.processCanvas.width === i && this.processCanvas.height === r || (this.processCanvas.width = i, this.processCanvas.height = r, this.glCanvas && (this.glCanvas.width = i, this.glCanvas.height = r), this.maskImageData = void 0);
785
778
  }
786
779
  async processSegmentation() {
@@ -801,30 +794,30 @@ class lt extends H {
801
794
  this.ensureProcessCanvasForInput();
802
795
  const i = this.processCanvas.getContext("2d");
803
796
  if (i) {
804
- const u = this.processCanvas.width, m = this.processCanvas.height;
805
- if (i.clearRect(0, 0, u, m), this.inputSource && this.inputSourceSize) {
806
- const { width: d, height: S } = this.inputSourceSize, R = Math.min(u / d, m / S), M = d * R, x = S * R;
807
- i.drawImage(this.inputSource, (u - M) / 2, (m - x) / 2, M, x);
797
+ const d = this.processCanvas.width, m = this.processCanvas.height;
798
+ if (i.clearRect(0, 0, d, m), this.inputSource && this.inputSourceSize) {
799
+ const { width: u, height: C } = this.inputSourceSize, x = Math.min(d / u, m / C), M = u * x, F = C * x;
800
+ i.drawImage(this.inputSource, (d - M) / 2, (m - F) / 2, M, F);
808
801
  } else
809
- i.drawImage(e, 0, 0, u, m);
802
+ i.drawImage(e, 0, 0, d, m);
810
803
  }
811
- const o = this.segmenter.segmentForVideo(
804
+ const c = this.segmenter.segmentForVideo(
812
805
  this.processCanvas,
813
806
  performance.now()
814
807
  ).categoryMask;
815
- if (!o) {
808
+ if (!c) {
816
809
  if (this.disposed || this.paused) return;
817
810
  this.rafId = requestAnimationFrame(this.processSegmentation.bind(this));
818
811
  return;
819
812
  }
820
813
  if (this.rawCache = null, this.latestMask && (this.latestMask.close(), this.latestMask = null), this.useGpuMaskPath && this.drawingUtils && this.glCanvas)
821
- this.drawingUtils.drawCategoryMask(o, ut), this.latestMask = o.clone(), o.close(), this.blitGlToMask();
814
+ this.drawingUtils.drawCategoryMask(c, mt), this.latestMask = c.clone(), c.close(), this.blitGlToMask();
822
815
  else {
823
- this.latestMask = o.clone();
824
- const u = this.readMaskToImageData(o);
825
- o.close(), u && this.blitImageDataToMask(u);
816
+ this.latestMask = c.clone();
817
+ const d = this.readMaskToImageData(c);
818
+ c.close(), d && this.blitImageDataToMask(d);
826
819
  }
827
- this.segmentationMaskTexture && (this.isMaskSetup || (this.segmentationMaskTexture.format = le, this.segmentationMaskTexture.minFilter = G, this.segmentationMaskTexture.magFilter = G, 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)));
820
+ this.segmentationMaskTexture && (this.isMaskSetup || (this.segmentationMaskTexture.format = me, this.segmentationMaskTexture.minFilter = G, this.segmentationMaskTexture.magFilter = G, 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)));
828
821
  }
829
822
  /**
830
823
  * Blit the GPU-rendered mask (already RGBA-inverted by drawCategoryMask)
@@ -847,10 +840,10 @@ class lt extends H {
847
840
  const t = e.getAsUint8Array(), { width: i, height: r } = e;
848
841
  if (!t || i <= 0 || r <= 0) return null;
849
842
  (!this.maskImageData || this.maskImageData.width !== i || this.maskImageData.height !== r) && (this.maskImageData = new ImageData(i, r));
850
- const o = this.maskImageData.data;
851
- for (let u = 0; u < t.length; u += 1) {
852
- const m = t[u] === 255 ? 0 : 255;
853
- o[u * 4] = 255, o[u * 4 + 1] = m, o[u * 4 + 2] = 255, o[u * 4 + 3] = m;
843
+ const c = this.maskImageData.data;
844
+ for (let d = 0; d < t.length; d += 1) {
845
+ const m = t[d] === 255 ? 0 : 255;
846
+ c[d * 4] = 255, c[d * 4 + 1] = m, c[d * 4 + 2] = 255, c[d * 4 + 3] = m;
854
847
  }
855
848
  return this.maskImageData;
856
849
  }
@@ -863,8 +856,8 @@ class lt extends H {
863
856
  if (!this.maskCanvas || !this.filterCanvas) return;
864
857
  const t = this.maskCanvas.getContext("2d"), i = this.filterCanvas.getContext("2d");
865
858
  if (!t || !i) return;
866
- const r = this.getStagingCanvas(e.width, e.height), o = r.getContext("2d");
867
- o && (o.putImageData(e, 0, 0), i.filter = "blur(0.5px)", i.clearRect(0, 0, this.filterCanvas.width, this.filterCanvas.height), i.drawImage(r, 0, 0, this.filterCanvas.width, this.filterCanvas.height), t.clearRect(0, 0, this.maskCanvas.width, this.maskCanvas.height), t.drawImage(this.filterCanvas, 0, 0, this.maskCanvas.width, this.maskCanvas.height));
859
+ const r = this.getStagingCanvas(e.width, e.height), c = r.getContext("2d");
860
+ c && (c.putImageData(e, 0, 0), i.filter = "blur(0.5px)", i.clearRect(0, 0, this.filterCanvas.width, this.filterCanvas.height), i.drawImage(r, 0, 0, this.filterCanvas.width, this.filterCanvas.height), t.clearRect(0, 0, this.maskCanvas.width, this.maskCanvas.height), t.drawImage(this.filterCanvas, 0, 0, this.maskCanvas.width, this.maskCanvas.height));
868
861
  }
869
862
  getStagingCanvas(e, t) {
870
863
  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;
@@ -903,7 +896,7 @@ class lt extends H {
903
896
  const r = this.glCanvas.getContext("webgl2", {
904
897
  preserveDrawingBuffer: !0
905
898
  });
906
- this.segmenter = await Le.createFromOptions(t, {
899
+ this.segmenter = await Ke.createFromOptions(t, {
907
900
  baseOptions: {
908
901
  modelAssetBuffer: i,
909
902
  delegate: "GPU"
@@ -912,7 +905,7 @@ class lt extends H {
912
905
  outputCategoryMask: !0,
913
906
  outputConfidenceMasks: !1,
914
907
  runningMode: "VIDEO"
915
- }), r ? (this.drawingUtils = new Be(r), this.useGpuMaskPath = !0) : this.useGpuMaskPath = !1;
908
+ }), r ? (this.drawingUtils = new Ne(r), this.useGpuMaskPath = !0) : this.useGpuMaskPath = !1;
916
909
  }
917
910
  async run({
918
911
  sourceCanvas: e,
@@ -920,12 +913,12 @@ class lt extends H {
920
913
  renderHeight: i,
921
914
  targetFps: r
922
915
  }) {
923
- var u;
916
+ var d;
924
917
  if (!e)
925
918
  return;
926
- this.setTargetFps(r ?? ht), this.isProcessing = !1, this.rafId !== null && (cancelAnimationFrame(this.rafId), this.rafId = null);
927
- const o = this.getQualityScaleFactor();
928
- this.sourceCanvas = e, this.processCanvas = document.createElement("canvas"), this.processCanvas.width = e.width * o, this.processCanvas.height = e.height * o, 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 = i, this.filterCanvas = document.createElement("canvas"), this.filterCanvas.width = t, this.filterCanvas.height = i, (u = this.segmentationMaskTexture) == null || u.dispose(), this.segmentationMaskTexture = new ge(this.maskCanvas), this.isMaskSetup = !1, this.rawCache = null, this.isProcessing = !0, this.lastInferenceMs = 0, this.rafId = requestAnimationFrame(this.processSegmentation.bind(this));
919
+ this.setTargetFps(r ?? lt), this.isProcessing = !1, this.rafId !== null && (cancelAnimationFrame(this.rafId), this.rafId = null);
920
+ const c = this.getQualityScaleFactor();
921
+ 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 = i, this.filterCanvas = document.createElement("canvas"), this.filterCanvas.width = t, this.filterCanvas.height = i, (d = this.segmentationMaskTexture) == null || d.dispose(), this.segmentationMaskTexture = new fe(this.maskCanvas), this.isMaskSetup = !1, this.rawCache = null, this.isProcessing = !0, this.lastInferenceMs = 0, this.rafId = requestAnimationFrame(this.processSegmentation.bind(this));
929
922
  }
930
923
  /**
931
924
  * Lazily read the single-channel mask back to a Uint8Array. Only invoked when
@@ -960,15 +953,15 @@ class lt extends H {
960
953
  };
961
954
  }
962
955
  }
963
- const ce = {
964
- [z.BACKGROUND_SEGMENTATION]: lt,
965
- [z.HAND_TRACKER]: ct,
966
- [z.GESTURE_TRACKER]: rt,
967
- [z.FACE_TRACKER]: tt,
968
- [z.BODY_TRACKER]: $e
969
- }, gt = async (n) => {
956
+ const de = {
957
+ [U.BACKGROUND_SEGMENTATION]: ft,
958
+ [U.HAND_TRACKER]: ut,
959
+ [U.GESTURE_TRACKER]: ht,
960
+ [U.FACE_TRACKER]: nt,
961
+ [U.BODY_TRACKER]: et
962
+ }, pt = async (a) => {
970
963
  const s = document.createElement("video");
971
- s.srcObject = n, s.muted = !0, s.playsInline = !0, s.autoplay = !0, await new Promise((t) => {
964
+ s.srcObject = a, s.muted = !0, s.playsInline = !0, s.autoplay = !0, await new Promise((t) => {
972
965
  s.onloadedmetadata = () => {
973
966
  s.play(), t();
974
967
  };
@@ -980,38 +973,38 @@ const ce = {
980
973
  };
981
974
  typeof e.requestVideoFrameCallback == "function" ? e.requestVideoFrameCallback(r) : requestAnimationFrame(() => requestAnimationFrame(() => r()));
982
975
  }), s;
983
- }, mt = (n) => {
984
- const s = new ge(n);
985
- return s.colorSpace = Ve, s.format = le, s.minFilter = G, s.magFilter = G, s.generateMipmaps = !1, s.needsUpdate = !0, s;
986
- }, ft = (n, s) => {
987
- const e = n.videoWidth, t = n.videoHeight;
976
+ }, wt = (a) => {
977
+ const s = new fe(a);
978
+ return s.colorSpace = He, s.format = me, s.minFilter = G, s.magFilter = G, s.generateMipmaps = !1, s.needsUpdate = !0, s;
979
+ }, vt = (a, s) => {
980
+ const e = a.videoWidth, t = a.videoHeight;
988
981
  e > 0 && t > 0 && (s.width !== e && (s.width = e), s.height !== t && (s.height = t));
989
982
  const i = s.getContext("2d", {
990
983
  colorSpace: "srgb"
991
984
  });
992
- i.save(), i.scale(-1, 1), i.drawImage(n, -s.width, 0, s.width, s.height), i.restore();
993
- }, pt = (n, s, e = 1) => {
985
+ i.save(), i.scale(-1, 1), i.drawImage(a, -s.width, 0, s.width, s.height), i.restore();
986
+ }, St = (a, s, e = 1) => {
994
987
  const t = s.getContext("2d", {
995
988
  colorSpace: "srgb"
996
- }), i = s.width / s.height, r = n.width / n.height;
997
- let o, u;
998
- r > i ? (u = s.height, o = n.width * (s.height / n.height)) : (o = s.width, u = n.height * (s.width / n.width));
989
+ }), i = s.width / s.height, r = a.width / a.height;
990
+ let c, d;
991
+ r > i ? (d = s.height, c = a.width * (s.height / a.height)) : (c = s.width, d = a.height * (s.width / a.width));
999
992
  const m = Number.isFinite(e) && e > 0 ? e : 1;
1000
- o *= m, u *= m;
1001
- const d = (s.width - o) / 2, S = (s.height - u) / 2;
993
+ c *= m, d *= m;
994
+ const u = (s.width - c) / 2, C = (s.height - d) / 2;
1002
995
  t.setTransform(1, 0, 0, 1, 0, 0), t.clearRect(0, 0, s.width, s.height), t.drawImage(
1003
- n,
996
+ a,
1004
997
  0,
1005
998
  0,
1006
- n.width,
1007
- n.height,
1008
- d,
1009
- S,
1010
- o,
1011
- u
999
+ a.width,
1000
+ a.height,
1001
+ u,
1002
+ C,
1003
+ c,
1004
+ d
1012
1005
  );
1013
- }, wt = (n) => {
1014
- switch (n instanceof DOMException ? n.name : "") {
1006
+ }, Ct = (a) => {
1007
+ switch (a instanceof DOMException ? a.name : "") {
1015
1008
  case "NotAllowedError":
1016
1009
  case "PermissionDeniedError":
1017
1010
  return "permission-denied";
@@ -1025,15 +1018,15 @@ const ce = {
1025
1018
  case "SecurityError":
1026
1019
  return "unsupported";
1027
1020
  default:
1028
- return n instanceof TypeError ? "unsupported" : "unknown";
1021
+ return a instanceof TypeError ? "unsupported" : "unknown";
1029
1022
  }
1030
- }, vt = {
1023
+ }, kt = {
1031
1024
  "permission-denied": "Camera access was blocked. Allow camera permissions in your browser, then refresh.",
1032
1025
  "camera-in-use": "Camera is already in use by another app or browser tab. Close it and refresh.",
1033
1026
  "no-camera": "No camera was found on this device.",
1034
1027
  unsupported: "Unable to access camera. Allow camera permissions in your browser, then refresh.",
1035
1028
  unknown: "Unable to access camera. Allow camera permissions in your browser, then refresh."
1036
- }, Ct = (n, s, e) => {
1029
+ }, yt = (a, s, e) => {
1037
1030
  const t = /* @__PURE__ */ new Map();
1038
1031
  let i = !1;
1039
1032
  const r = (l, f) => {
@@ -1051,28 +1044,28 @@ const ce = {
1051
1044
  const k = s[l];
1052
1045
  if (!k)
1053
1046
  throw new Error(`Invalid model: ${l}`);
1054
- const C = new k(), L = /* @__PURE__ */ new Set([f]), U = /* @__PURE__ */ new Set([f]), D = (async () => {
1055
- await C.initialize(v);
1056
- const B = t.get(l);
1057
- if (!B || B.model !== C || B.refs.size === 0)
1058
- return r(l, C), C;
1059
- e && await e(l, C);
1060
- const T = t.get(l);
1061
- return T && T.refs.size > 0 && n.setPipeline((_) => _.set(l, C)), C;
1047
+ const S = new k(), O = /* @__PURE__ */ new Set([f]), z = /* @__PURE__ */ new Set([f]), D = (async () => {
1048
+ await S.initialize(v);
1049
+ const _ = t.get(l);
1050
+ if (!_ || _.model !== S || _.refs.size === 0)
1051
+ return r(l, S), S;
1052
+ e && await e(l, S);
1053
+ const L = t.get(l);
1054
+ return L && L.refs.size > 0 && a.setPipeline((A) => A.set(l, S)), S;
1062
1055
  })();
1063
- return p = { model: C, refs: L, activeRefs: U, initPromise: D, options: v }, t.set(l, p), D.catch(() => {
1064
- t.get(l) === p && (t.delete(l), n.setPipeline((T) => T.delete(l))), r(l, C);
1056
+ return p = { model: S, refs: O, activeRefs: z, initPromise: D, options: v }, t.set(l, p), D.catch(() => {
1057
+ t.get(l) === p && (t.delete(l), a.setPipeline((L) => L.delete(l))), r(l, S);
1065
1058
  }), D;
1066
1059
  }, release: (l, f) => {
1067
1060
  const v = t.get(l);
1068
- v && (v.refs.delete(f), v.activeRefs.delete(f) && v.refs.size > 0 && v.activeRefs.size === 0 && v.model.pause(), !(v.refs.size > 0) && (t.delete(l), r(l, v.model), n.setPipeline((p) => p.delete(l))));
1061
+ v && (v.refs.delete(f), v.activeRefs.delete(f) && v.refs.size > 0 && v.activeRefs.size === 0 && v.model.pause(), !(v.refs.size > 0) && (t.delete(l), r(l, v.model), a.setPipeline((p) => p.delete(l))));
1069
1062
  }, setActive: (l, f, v) => {
1070
1063
  const p = t.get(l);
1071
1064
  if (!p || !p.refs.has(f)) return;
1072
1065
  const k = p.activeRefs.size > 0;
1073
1066
  v ? p.activeRefs.add(f) : p.activeRefs.delete(f);
1074
- const C = p.activeRefs.size > 0;
1075
- k !== C && (C && !i ? p.model.resume() : p.model.pause());
1067
+ const S = p.activeRefs.size > 0;
1068
+ k !== S && (S && !i ? p.model.resume() : p.model.pause());
1076
1069
  }, suspendAll: () => {
1077
1070
  i = !0;
1078
1071
  for (const l of t.values())
@@ -1092,9 +1085,9 @@ const ce = {
1092
1085
  const f = t.get(l);
1093
1086
  f && (f.refs.clear(), t.delete(l), r(l, f.model));
1094
1087
  }
1095
- n.setPipeline((l) => l.clear());
1088
+ a.setPipeline((l) => l.clear());
1096
1089
  } };
1097
- }, St = {
1090
+ }, Mt = {
1098
1091
  lifecycle: "idle",
1099
1092
  ready: !1,
1100
1093
  error: void 0,
@@ -1104,307 +1097,317 @@ const ce = {
1104
1097
  source: void 0,
1105
1098
  sourceKind: void 0,
1106
1099
  pipeline: /* @__PURE__ */ new Map()
1107
- }, kt = () => {
1108
- let n = { ...St, pipeline: /* @__PURE__ */ new Map() };
1100
+ }, Tt = () => {
1101
+ let a = { ...Mt, pipeline: /* @__PURE__ */ new Map() };
1109
1102
  const s = /* @__PURE__ */ new Set(), e = () => {
1110
1103
  s.forEach((t) => t());
1111
1104
  };
1112
1105
  return {
1113
- getSnapshot: () => n,
1106
+ getSnapshot: () => a,
1114
1107
  set: (t) => {
1115
1108
  let i = !1;
1116
1109
  for (const r of Object.keys(t))
1117
- if (t[r] !== n[r]) {
1110
+ if (t[r] !== a[r]) {
1118
1111
  i = !0;
1119
1112
  break;
1120
1113
  }
1121
- i && (n = { ...n, ...t }, e());
1114
+ i && (a = { ...a, ...t }, e());
1122
1115
  },
1123
1116
  setPipeline: (t) => {
1124
- const i = new Map(n.pipeline);
1125
- return t(i), n = { ...n, pipeline: i }, e(), i;
1117
+ const i = new Map(a.pipeline);
1118
+ return t(i), a = { ...a, pipeline: i }, e(), i;
1126
1119
  },
1127
1120
  subscribe: (t) => (s.add(t), () => {
1128
1121
  s.delete(t);
1129
1122
  })
1130
1123
  };
1131
- }, yt = ({
1132
- renderHeight: n,
1124
+ }, Rt = ({
1125
+ renderHeight: a,
1133
1126
  renderWidth: s,
1134
1127
  videoHeight: e,
1135
1128
  videoWidth: t
1136
1129
  }) => ({
1137
- height: n || e,
1130
+ height: a || e,
1138
1131
  width: s || t
1139
- }), Mt = (n) => {
1140
- const s = new Ne({ verbose: !0 }), e = kt();
1141
- let t = n;
1142
- const i = (a) => {
1132
+ }), xt = (a) => {
1133
+ const s = new Ge({ verbose: !0 }), e = Tt();
1134
+ let t = a;
1135
+ const i = (n) => {
1143
1136
  var g;
1144
- const c = (g = T.getOptions(a)) == null ? void 0 : g.targetFps;
1145
- return typeof c == "number" ? c : t == null ? void 0 : t.targetFps;
1137
+ const o = (g = A.getOptions(n)) == null ? void 0 : g.targetFps;
1138
+ return typeof o == "number" ? o : t == null ? void 0 : t.targetFps;
1146
1139
  };
1147
- let r, o, u, m, d, S, R, M, x, l, f, v = !1, p = !1, k = 0;
1148
- const C = /* @__PURE__ */ new Set(), L = /* @__PURE__ */ new Set(), U = (a) => {
1149
- const c = e.getSnapshot().cameraTexture;
1150
- c && c.dispose();
1151
- const g = mt(a);
1140
+ let r, c, d, m, u, C, x, M, F, l, f, v, p = !1, k = !1, S = 0;
1141
+ const O = /* @__PURE__ */ new Set(), z = /* @__PURE__ */ new Set(), D = (n) => {
1142
+ const o = e.getSnapshot().cameraTexture;
1143
+ o && o.dispose();
1144
+ const g = wt(n);
1152
1145
  return e.set({ cameraTexture: g }), g;
1153
- }, D = async (a, c) => {
1154
- if (C.has(a) || e.getSnapshot().lifecycle !== "running" || !d) return;
1155
- C.add(a);
1156
- const g = k;
1146
+ }, _ = async (n, o) => {
1147
+ if (O.has(n) || e.getSnapshot().lifecycle !== "running" || !u) return;
1148
+ O.add(n);
1149
+ const g = S;
1157
1150
  try {
1158
- await c.run({
1159
- sourceCanvas: d,
1151
+ await o.run({
1152
+ sourceCanvas: u,
1160
1153
  renderWidth: e.getSnapshot().renderWidth,
1161
1154
  renderHeight: e.getSnapshot().renderHeight,
1162
1155
  getSource: () => e.getSnapshot().sourceKind,
1163
- targetFps: i(a)
1164
- }), p && (await new Promise((w) => requestAnimationFrame(() => w())), await new Promise((w) => requestAnimationFrame(() => w())), p && k === g && T.suspendAll());
1156
+ targetFps: i(n)
1157
+ }), k && (await new Promise((w) => requestAnimationFrame(() => w())), await new Promise((w) => requestAnimationFrame(() => w())), k && S === g && A.suspendAll());
1165
1158
  } catch (w) {
1166
- throw C.delete(a), w;
1159
+ throw O.delete(n), w;
1167
1160
  }
1168
- }, T = Ct(e, ce, (a, c) => D(a, c));
1161
+ }, A = yt(e, de, (n, o) => _(n, o));
1169
1162
  e.subscribe(() => {
1170
1163
  if (e.getSnapshot().lifecycle !== "running") return;
1171
- const a = e.getSnapshot().pipeline;
1172
- for (const [c, g] of a.entries())
1173
- C.has(c) || D(c, g);
1164
+ const n = e.getSnapshot().pipeline;
1165
+ for (const [o, g] of n.entries())
1166
+ O.has(o) || _(o, g);
1174
1167
  });
1175
- const _ = () => {
1176
- if (f !== void 0 && (cancelAnimationFrame(f), f = void 0), o) {
1168
+ const B = () => {
1169
+ if (v !== void 0 && (cancelAnimationFrame(v), v = void 0), c) {
1177
1170
  try {
1178
- o.pause();
1171
+ c.pause();
1179
1172
  } catch {
1180
1173
  }
1181
1174
  try {
1182
- o.srcObject = null;
1175
+ c.srcObject = null;
1183
1176
  } catch {
1184
1177
  }
1185
- o = void 0;
1178
+ c = void 0;
1186
1179
  }
1187
- if (u) {
1180
+ if (d) {
1188
1181
  try {
1189
- u.getTracks().forEach((a) => a.stop());
1182
+ d.getTracks().forEach((n) => n.stop());
1190
1183
  } catch {
1191
1184
  }
1192
- u = void 0;
1185
+ d = void 0;
1193
1186
  }
1194
1187
  }, W = () => {
1195
- if (v || !o || !m || !d) return;
1196
- const a = window.__xr_debugger_metrics;
1197
- if (a != null && a.trackCameraFrame && a.trackCameraFrame(), (e.getSnapshot().sourceKind ?? "webcam") === "webcam")
1198
- ft(o, m);
1188
+ if (p || !c || !m || !u) return;
1189
+ const n = window.__xr_debugger_metrics;
1190
+ if (n != null && n.trackCameraFrame && n.trackCameraFrame(), (e.getSnapshot().sourceKind ?? "webcam") === "webcam")
1191
+ vt(c, m);
1199
1192
  else {
1200
1193
  const w = m.getContext("2d");
1201
1194
  if (!w) return;
1202
- const y = o.videoWidth, A = o.videoHeight;
1203
- m.width !== y && (m.width = y), m.height !== A && (m.height = A), w.setTransform(1, 0, 0, 1, 0, 0), w.clearRect(0, 0, y, A), w.drawImage(o, 0, 0, y, A);
1195
+ const y = c.videoWidth, R = c.videoHeight;
1196
+ m.width !== y && (m.width = y), m.height !== R && (m.height = R), w.setTransform(1, 0, 0, 1, 0, 0), w.clearRect(0, 0, y, R), w.drawImage(c, 0, 0, y, R);
1204
1197
  }
1205
- pt(m, d, (t == null ? void 0 : t.cameraZoom) ?? 1.2);
1198
+ St(m, u, (t == null ? void 0 : t.cameraZoom) ?? 1.2);
1206
1199
  const g = e.getSnapshot().cameraTexture;
1207
1200
  g && (g.needsUpdate = !0);
1208
- }, te = () => {
1209
- if (!o || !m || !d) return;
1210
- if (p) {
1201
+ }, ae = () => {
1202
+ if (!c || !m || !u) return;
1203
+ if (k) {
1211
1204
  W();
1212
1205
  return;
1213
1206
  }
1214
- const a = () => {
1215
- f = requestAnimationFrame(a), W();
1207
+ const n = () => {
1208
+ v = requestAnimationFrame(n), W();
1216
1209
  };
1217
- f = requestAnimationFrame(a);
1218
- }, ve = async (a) => {
1219
- if (a.source === F.WEBCAM)
1210
+ v = requestAnimationFrame(n);
1211
+ }, Ce = async (n) => {
1212
+ if (n.source === T.WEBCAM)
1220
1213
  try {
1221
- const c = t != null && t.camRes && t.camRes > 0 ? t.camRes : 960;
1214
+ const o = t != null && t.camRes && t.camRes > 0 ? t.camRes : 960;
1222
1215
  return await navigator.mediaDevices.getUserMedia({
1223
1216
  video: {
1224
1217
  facingMode: "user",
1225
1218
  frameRate: { min: 24, ideal: 30, max: 60 },
1226
- width: { ideal: c }
1219
+ width: { ideal: o }
1227
1220
  }
1228
1221
  });
1229
- } catch (c) {
1230
- const g = wt(c), w = vt[g];
1231
- throw e.set({ error: { error: "PermissionError", message: w, reason: g } }), new b(c instanceof Error ? c.message : "getUserMedia failed");
1222
+ } catch (o) {
1223
+ const g = Ct(o), w = kt[g];
1224
+ throw e.set({ error: { error: "PermissionError", message: w, reason: g } }), new b(o instanceof Error ? o.message : "getUserMedia failed");
1232
1225
  }
1233
- return a.stream;
1234
- }, X = async (a) => {
1235
- const c = await ve(a);
1236
- u = c;
1237
- const g = await gt(c);
1238
- o = g, m = new OffscreenCanvas(g.videoWidth, g.videoHeight);
1239
- const { renderWidth: w, renderHeight: y } = e.getSnapshot(), A = yt({
1226
+ return n.stream;
1227
+ }, X = async (n) => {
1228
+ const o = await Ce(n);
1229
+ d = o;
1230
+ const g = await pt(o);
1231
+ c = g, m = new OffscreenCanvas(g.videoWidth, g.videoHeight);
1232
+ const { renderWidth: w, renderHeight: y } = e.getSnapshot(), R = Rt({
1240
1233
  renderWidth: w,
1241
1234
  renderHeight: y,
1242
1235
  videoWidth: g.videoWidth,
1243
1236
  videoHeight: g.videoHeight
1244
1237
  });
1245
- d ? (d.width !== A.width || d.height !== A.height) && (d.width = A.width, d.height = A.height, U(d)) : (d = new OffscreenCanvas(A.width, A.height), U(d));
1246
- const ie = a.source === F.STREAM ? a.static === !0 : !1;
1247
- p = ie, r = a.source === F.WEBCAM ? { source: F.WEBCAM, sourceKind: "webcam" } : {
1248
- source: F.STREAM,
1249
- stream: a.stream,
1250
- static: ie,
1251
- sourceKind: a.sourceKind ?? "webcam"
1238
+ u ? (u.width !== R.width || u.height !== R.height) && (u.width = R.width, u.height = R.height, D(u)) : (u = new OffscreenCanvas(R.width, R.height), D(u));
1239
+ const oe = n.source === T.STREAM ? n.static === !0 : !1;
1240
+ k = oe, r = n.source === T.WEBCAM ? { source: T.WEBCAM, sourceKind: "webcam" } : {
1241
+ source: T.STREAM,
1242
+ stream: n.stream,
1243
+ static: oe,
1244
+ sourceKind: n.sourceKind ?? "webcam"
1252
1245
  }, e.set({
1253
- source: a.source,
1246
+ source: n.source,
1254
1247
  sourceKind: r.sourceKind,
1255
1248
  error: void 0
1256
1249
  });
1257
- }, j = async (a) => {
1258
- const c = a.sourceKind ?? "webcam";
1259
- d = a.canvas;
1260
- const g = U(d);
1250
+ }, j = async (n) => {
1251
+ const o = n.sourceKind ?? "webcam";
1252
+ u = n.canvas;
1253
+ const g = D(u);
1261
1254
  e.set({
1262
1255
  cameraTexture: g,
1263
- source: F.CANVAS,
1264
- sourceKind: c,
1265
- renderWidth: d.width,
1266
- renderHeight: d.height,
1256
+ source: T.CANVAS,
1257
+ sourceKind: o,
1258
+ renderWidth: u.width,
1259
+ renderHeight: u.height,
1267
1260
  error: void 0
1268
1261
  }), r = {
1269
- source: F.CANVAS,
1270
- canvas: a.canvas,
1271
- sourceKind: c
1262
+ source: T.CANVAS,
1263
+ canvas: n.canvas,
1264
+ sourceKind: o
1272
1265
  };
1273
- }, Ce = (a, c) => !c || a.source !== c.source ? !1 : a.source === F.STREAM && c.source === F.STREAM ? a.stream === c.stream && (a.sourceKind ?? "webcam") === c.sourceKind : !0, Se = async () => {
1274
- if (!d) return;
1275
- const a = k, c = e.getSnapshot().pipeline;
1276
- for (const [, g] of c.entries())
1266
+ }, ke = (n, o) => !o || n.source !== o.source ? !1 : n.source === T.STREAM && o.source === T.STREAM ? n.stream === o.stream && (n.sourceKind ?? "webcam") === o.sourceKind : !0, ye = async () => {
1267
+ if (!u) return;
1268
+ const n = S, o = e.getSnapshot().pipeline;
1269
+ for (const [, g] of o.entries())
1277
1270
  g.resume();
1278
- await new Promise((g) => requestAnimationFrame(() => g())), await new Promise((g) => requestAnimationFrame(() => g())), p && k === a && T.suspendAll();
1279
- }, ke = (a, c) => !c || c.source !== F.CANVAS ? !1 : a.canvas === c.canvas && (a.sourceKind ?? "webcam") === c.sourceKind, ye = async (a) => {
1280
- const c = a.source;
1281
- if (c !== F.WEBCAM && c !== F.STREAM)
1282
- throw new b(`Invalid media source: ${String(c)}`);
1283
- if (Ce(a, r)) {
1271
+ await new Promise((g) => requestAnimationFrame(() => g())), await new Promise((g) => requestAnimationFrame(() => g())), k && S === n && A.suspendAll();
1272
+ }, Me = (n, o) => !o || o.source !== T.CANVAS ? !1 : n.canvas === o.canvas && (n.sourceKind ?? "webcam") === o.sourceKind, Te = async (n) => {
1273
+ const o = n.source;
1274
+ if (o !== T.WEBCAM && o !== T.STREAM)
1275
+ throw new b(`Invalid media source: ${String(o)}`);
1276
+ if (ke(n, r)) {
1284
1277
  s.log("Media source unchanged, skipping rebind.");
1285
1278
  return;
1286
1279
  }
1287
- k += 1;
1280
+ S += 1;
1288
1281
  const { lifecycle: g } = e.getSnapshot();
1289
1282
  if (g === "idle" || g === "stopped") {
1290
- await X(a), e.set({ lifecycle: "media-bound" }), s.log("Media source set to:", a.source);
1283
+ await X(n), e.set({ lifecycle: "media-bound" }), s.log("Media source set to:", n.source);
1291
1284
  return;
1292
1285
  }
1293
1286
  if (g === "media-bound") {
1294
- _(), await X(a), s.log("Media source rebound to:", a.source);
1287
+ B(), await X(n), s.log("Media source rebound to:", n.source);
1295
1288
  return;
1296
1289
  }
1297
- v = !0, await new Promise((w) => requestAnimationFrame(() => w())), _(), await X(a), v = !1, te(), p ? await Se() : T.resumeActive(), s.log("Media source swapped to:", a.source);
1298
- }, Me = async (a) => {
1299
- if (ke(a, r)) {
1290
+ p = !0, await new Promise((w) => requestAnimationFrame(() => w())), B(), await X(n), p = !1, ae(), k ? await ye() : A.resumeActive(), s.log("Media source swapped to:", n.source);
1291
+ }, Re = async (n) => {
1292
+ if (Me(n, r)) {
1300
1293
  s.log("Frame source unchanged, skipping rebind.");
1301
1294
  return;
1302
1295
  }
1303
- k += 1;
1304
- const { lifecycle: c } = e.getSnapshot();
1305
- if (c === "idle" || c === "stopped") {
1306
- await j(a), e.set({ lifecycle: "media-bound" }), s.log("Frame source set to canvas.");
1296
+ S += 1;
1297
+ const { lifecycle: o } = e.getSnapshot();
1298
+ if (o === "idle" || o === "stopped") {
1299
+ await j(n), e.set({ lifecycle: "media-bound" }), s.log("Frame source set to canvas.");
1307
1300
  return;
1308
1301
  }
1309
- if (c === "media-bound") {
1310
- _(), await j(a), s.log("Frame source rebound to canvas.");
1302
+ if (o === "media-bound") {
1303
+ B(), await j(n), s.log("Frame source rebound to canvas.");
1311
1304
  return;
1312
1305
  }
1313
- v = !0, await new Promise((g) => requestAnimationFrame(() => g())), _(), await j(a), v = !1, s.log("Frame source swapped to canvas.");
1314
- }, Re = async () => {
1315
- const { lifecycle: a } = e.getSnapshot();
1316
- if (a === "running") return;
1317
- if (a === "idle")
1306
+ p = !0, await new Promise((g) => requestAnimationFrame(() => g())), B(), await j(n), p = !1, s.log("Frame source swapped to canvas.");
1307
+ }, xe = async () => {
1308
+ const { lifecycle: n } = e.getSnapshot();
1309
+ if (n === "running") return;
1310
+ if (n === "idle")
1318
1311
  throw new b("session.start() called before setMediaSource — call setMediaSource first");
1319
- if (!d)
1312
+ if (!u)
1320
1313
  throw new b("session.start(): media source not bound");
1321
- const c = (r == null ? void 0 : r.source) === F.CANVAS;
1322
- if (!c && (!o || !m))
1323
- throw a === "stopped" ? new b(
1314
+ const o = (r == null ? void 0 : r.source) === T.CANVAS;
1315
+ if (!o && (!c || !m))
1316
+ throw n === "stopped" ? new b(
1324
1317
  "session.start() called from stopped state without a media source — call setMediaSource first"
1325
1318
  ) : new b("session.start(): media source not bound");
1326
- c || te(), T.resumeActive(), e.set({ lifecycle: "running" }), await new Promise((w) => requestAnimationFrame(() => w()));
1319
+ o || ae(), A.resumeActive(), e.set({ lifecycle: "running" }), await new Promise((w) => requestAnimationFrame(() => w()));
1327
1320
  const g = e.getSnapshot().pipeline;
1328
1321
  for (const [w, y] of g.entries())
1329
- await D(w, y);
1322
+ await _(w, y);
1330
1323
  e.set({ ready: !0 }), s.log("XR session started.");
1331
- }, se = async () => {
1332
- const { lifecycle: a } = e.getSnapshot();
1333
- a === "stopped" || a === "idle" || (_(), T.suspendAll(), e.set({ lifecycle: "stopped", ready: !1 }), s.log("XR session stopped."));
1334
- }, Te = async () => {
1335
- await se(), T.releaseAll(), L.clear();
1336
- const a = e.getSnapshot().cameraTexture;
1337
- a && a.dispose(), C.clear(), r = void 0, k += 1, d = void 0, m = void 0, p = !1, e.set({
1324
+ }, ne = async () => {
1325
+ const { lifecycle: n } = e.getSnapshot();
1326
+ n === "stopped" || n === "idle" || (B(), A.suspendAll(), e.set({ lifecycle: "stopped", ready: !1 }), s.log("XR session stopped."));
1327
+ }, Fe = async () => {
1328
+ await ne(), A.releaseAll(), z.clear();
1329
+ const n = e.getSnapshot().cameraTexture;
1330
+ n && n.dispose(), O.clear(), r = void 0, S += 1, u = void 0, m = void 0, x = void 0, k = !1, e.set({
1338
1331
  lifecycle: "idle",
1339
1332
  cameraTexture: void 0,
1340
1333
  source: void 0
1341
1334
  }), s.log("XR session reset.");
1342
- }, xe = async (a) => {
1343
- const c = "legacy:registerXRPipeline", g = [];
1335
+ }, Ae = async (n) => {
1336
+ const o = "legacy:registerXRPipeline", g = [];
1344
1337
  await Promise.all(
1345
- a.map(async (w) => {
1338
+ n.map(async (w) => {
1346
1339
  const { model: y } = w;
1347
- if (!ce[y])
1340
+ if (!de[y])
1348
1341
  throw new b(`Invalid model: ${y}`);
1349
- L.has(y) || g.push(y);
1350
- const A = "options" in w ? w.options : void 0;
1351
- await T.acquire(y, c, A);
1342
+ z.has(y) || g.push(y);
1343
+ const R = "options" in w ? w.options : void 0;
1344
+ await A.acquire(y, o, R);
1352
1345
  })
1353
- ), g.length > 0 && (g.forEach((w) => L.add(w)), s.log("XR pipeline registered."));
1354
- }, Fe = (a) => {
1355
- const c = T.get(a);
1356
- if (!c)
1357
- throw new b(`Model ${a} is not registered in the pipeline`);
1358
- return c.getModelNode();
1359
- }, ne = async (a, c) => {
1360
- a <= 0 || c <= 0 || (e.set({ renderWidth: a, renderHeight: c }), d && (d.width !== a || d.height !== c) && (d.width = a, d.height = c, U(d), p && W()), s.log(`Source canvas set. Render size: ${a}x${c}`));
1361
- }, Ae = async (a) => {
1346
+ ), g.length > 0 && (g.forEach((w) => z.add(w)), s.log("XR pipeline registered."));
1347
+ }, be = (n) => {
1348
+ const o = A.get(n);
1349
+ if (!o)
1350
+ throw new b(`Model ${n} is not registered in the pipeline`);
1351
+ return o.getModelNode();
1352
+ }, ie = async (n, o) => {
1353
+ n <= 0 || o <= 0 || (e.set({ renderWidth: n, renderHeight: o }), u && (u.width !== n || u.height !== o) && (u.width = n, u.height = o, D(u), k && W()), s.log(`Source canvas set. Render size: ${n}x${o}`));
1354
+ }, Ee = async (n) => {
1362
1355
  var y;
1363
- S = a;
1364
- const c = (y = a.getBoundingClientRect) == null ? void 0 : y.call(a), g = c && c.width > 0 ? Math.round(c.width) : a.clientWidth, w = c && c.height > 0 ? Math.round(c.height) : a.clientHeight;
1365
- await ne(g, w);
1366
- }, be = (a) => {
1367
- R = a.renderer, M = a.scene, x = a.camera, l = a.renderFrame;
1368
- }, ae = () => {
1369
- if (!R || !M || !x)
1356
+ C = n;
1357
+ const o = (y = n.getBoundingClientRect) == null ? void 0 : y.call(n), g = o && o.width > 0 ? Math.round(o.width) : n.clientWidth, w = o && o.height > 0 ? Math.round(o.height) : n.clientHeight;
1358
+ await ie(g, w);
1359
+ }, Ie = (n) => {
1360
+ x = n;
1361
+ }, Y = () => C && M && F && l ? C : x, Pe = (n) => {
1362
+ M = n.renderer, F = n.scene, l = n.camera, f = n.renderFrame;
1363
+ }, re = () => {
1364
+ if (!M || !F || !l)
1370
1365
  throw new b(
1371
1366
  "XR frame render requested before the R3F state was bound — make sure <XRScene> is mounted"
1372
1367
  );
1373
- l ? l() : R.render(M, x);
1368
+ f ? f() : M.render(F, l);
1374
1369
  };
1375
1370
  return {
1376
1371
  store: e,
1377
- registry: T,
1378
- setMediaSource: ye,
1379
- start: Re,
1380
- stop: se,
1381
- reset: Te,
1382
- setFrameSource: Me,
1383
- registerXRPipeline: xe,
1384
- getModelNode: Fe,
1372
+ registry: A,
1373
+ setMediaSource: Te,
1374
+ start: xe,
1375
+ stop: ne,
1376
+ reset: Fe,
1377
+ setFrameSource: Re,
1378
+ registerXRPipeline: Ae,
1379
+ getModelNode: be,
1385
1380
  captureFrame: () => {
1386
- if (!S)
1387
- throw new b(
1388
- "session.captureFrame() called before the XRScene render target was bound — make sure <XRScene> is mounted"
1389
- );
1390
- if (!R || !M || !x)
1381
+ const n = C;
1382
+ if (n && Y() === n)
1383
+ return re(), n.toDataURL("image/png");
1384
+ const o = Y();
1385
+ if (o) return o.toDataURL("image/png");
1386
+ throw new b(
1387
+ "session.captureFrame() called before an XRScene or XRMediaSurface capture target was bound"
1388
+ );
1389
+ },
1390
+ captureStream: (n = 30) => {
1391
+ const o = Y();
1392
+ if (!(o != null && o.captureStream))
1391
1393
  throw new b(
1392
- "session.captureFrame() called before the R3F state was bound — make sure <XRScene> is mounted"
1394
+ "session.captureStream() called before an XRScene or XRMediaSurface capture target was bound"
1393
1395
  );
1394
- return ae(), S.toDataURL("image/png");
1396
+ return o.captureStream(n);
1395
1397
  },
1396
- getInputFrame: () => d ?? null,
1397
- _setRenderTarget: Ae,
1398
- _setRenderSize: ne,
1399
- _setR3FState: be,
1400
- _renderFrame: ae,
1401
- _getVideoElement: () => o,
1402
- _setPerf: (a) => {
1403
- if (t = a, e.getSnapshot().lifecycle !== "running" || !d) return;
1404
- const c = e.getSnapshot().pipeline;
1405
- for (const [g, w] of c.entries())
1398
+ getInputFrame: () => u ?? null,
1399
+ _setRenderTarget: Ee,
1400
+ _setCaptureTarget: Ie,
1401
+ _setRenderSize: ie,
1402
+ _setR3FState: Pe,
1403
+ _renderFrame: re,
1404
+ _getVideoElement: () => c,
1405
+ _setPerf: (n) => {
1406
+ if (t = n, e.getSnapshot().lifecycle !== "running" || !u) return;
1407
+ const o = e.getSnapshot().pipeline;
1408
+ for (const [g, w] of o.entries())
1406
1409
  w.run({
1407
- sourceCanvas: d,
1410
+ sourceCanvas: u,
1408
1411
  renderWidth: e.getSnapshot().renderWidth,
1409
1412
  renderHeight: e.getSnapshot().renderHeight,
1410
1413
  getSource: () => e.getSnapshot().sourceKind,
@@ -1412,46 +1415,48 @@ const ce = {
1412
1415
  });
1413
1416
  }
1414
1417
  };
1415
- }, Rt = (n) => {
1416
- const s = he(n), e = J(() => Mt(s.current), []), t = JSON.stringify(n ?? {});
1417
- return Pe(() => {
1418
- e._setPerf(n);
1418
+ }, Ft = (a) => {
1419
+ const s = ue(a), e = ee(() => xt(s.current), []), t = JSON.stringify(a ?? {});
1420
+ return Oe(() => {
1421
+ e._setPerf(a);
1419
1422
  }, [e, t]), e;
1420
- }, Z = /* @__PURE__ */ new Map(), Tt = () => ({
1421
- register: (n, s) => {
1422
- s ? Z.set(n, s) : Z.delete(n);
1423
+ }, J = /* @__PURE__ */ new Map(), At = () => ({
1424
+ register: (a, s) => {
1425
+ s ? J.set(a, s) : J.delete(a);
1423
1426
  },
1424
- resolve: (n) => n ? Z.get(n) ?? null : null
1425
- }), me = Tt(), fe = ue(null), xt = ({ children: n }) => {
1426
- const s = he(/* @__PURE__ */ new Map()), e = oe((r, o) => {
1427
- o ? s.current.set(r, o) : s.current.delete(r);
1428
- }, []), t = oe(
1427
+ resolve: (a) => a ? J.get(a) ?? null : null
1428
+ }), pe = At(), we = ge(null), bt = ({ children: a }) => {
1429
+ const s = ue(/* @__PURE__ */ new Map()), e = he((r, c) => {
1430
+ c ? s.current.set(r, c) : s.current.delete(r);
1431
+ }, []), t = he(
1429
1432
  (r) => r ? s.current.get(r) ?? null : null,
1430
1433
  []
1431
- ), i = J(() => ({ register: e, resolve: t }), [e, t]);
1432
- return De(fe.Provider, { value: i }, n);
1433
- }, pe = () => de(fe) ?? me, zt = () => pe().register, Lt = () => pe().resolve;
1434
- me.register;
1435
- const we = ue(void 0), Bt = () => {
1436
- const n = de(we);
1437
- if (!n)
1434
+ ), i = ee(() => ({ register: e, resolve: t }), [e, t]);
1435
+ return Ue(we.Provider, { value: i }, a);
1436
+ }, ve = () => le(we) ?? pe, Nt = () => ve().register, Ht = () => ve().resolve;
1437
+ pe.register;
1438
+ const Se = ge(void 0), qt = () => {
1439
+ const a = le(Se);
1440
+ if (!a)
1438
1441
  throw new b(
1439
1442
  "XR context can only be used inside XRProvider, did you forget to wrap your app in <XRProvider>?"
1440
1443
  );
1441
- return n;
1442
- }, Vt = ({ children: n, perf: s }) => {
1443
- const e = Rt(s), t = J(() => ({ session: e }), [e]);
1444
- return /* @__PURE__ */ re(we.Provider, { value: t, children: /* @__PURE__ */ re(xt, { children: n }) });
1444
+ return a;
1445
+ }, Gt = ({ children: a, perf: s }) => {
1446
+ const e = Ft(s), t = ee(() => ({ session: e }), [e]);
1447
+ return /* @__PURE__ */ ce(Se.Provider, { value: t, children: /* @__PURE__ */ ce(bt, { children: a }) });
1445
1448
  };
1446
1449
  export {
1447
- z as X,
1450
+ U as X,
1448
1451
  q as a,
1449
- Ut as b,
1450
- F as c,
1451
- Vt as d,
1452
- Lt as e,
1453
- Ge as f,
1454
- zt as g,
1452
+ Kt as b,
1453
+ T as c,
1454
+ Gt as d,
1455
+ Ht as e,
1456
+ je as f,
1457
+ Nt as g,
1455
1458
  I as l,
1456
- Bt as u
1459
+ te as n,
1460
+ Vt as t,
1461
+ qt as u
1457
1462
  };