@omnidotdev/rdk 0.5.2 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/build/engine/useXRStore.d.ts +4 -12
  2. package/build/engine/useXRStore.d.ts.map +1 -1
  3. package/build/fiducial/FiducialAnchor.d.ts.map +1 -1
  4. package/build/fiducial/FiducialSession.d.ts +1 -4
  5. package/build/fiducial/FiducialSession.d.ts.map +1 -1
  6. package/build/fiducial/fiducialBackend.d.ts +9 -1
  7. package/build/fiducial/fiducialBackend.d.ts.map +1 -1
  8. package/build/fiducial/index.d.ts +2 -1
  9. package/build/fiducial/index.d.ts.map +1 -1
  10. package/build/fiducial/useFiducialBackend.d.ts +14 -0
  11. package/build/fiducial/useFiducialBackend.d.ts.map +1 -0
  12. package/build/geolocation/GeolocationAnchor.d.ts.map +1 -1
  13. package/build/geolocation/GeolocationSession.d.ts +1 -4
  14. package/build/geolocation/GeolocationSession.d.ts.map +1 -1
  15. package/build/geolocation/geolocationBackend.d.ts +31 -11
  16. package/build/geolocation/geolocationBackend.d.ts.map +1 -1
  17. package/build/geolocation/index.d.ts +2 -1
  18. package/build/geolocation/index.d.ts.map +1 -1
  19. package/build/geolocation/useGeolocationBackend.d.ts +14 -0
  20. package/build/geolocation/useGeolocationBackend.d.ts.map +1 -0
  21. package/build/immersive/ImmersiveSession.d.ts.map +1 -1
  22. package/build/index.cjs +1 -1
  23. package/build/index.d.ts +2 -1
  24. package/build/index.d.ts.map +1 -1
  25. package/build/index.js +364 -374
  26. package/build/lib/types/engine/backend/Backend.interface.d.ts +20 -4
  27. package/build/lib/types/engine/backend/Backend.interface.d.ts.map +1 -1
  28. package/build/lib/types/engine/backend/index.d.ts +2 -1
  29. package/build/lib/types/engine/backend/index.d.ts.map +1 -1
  30. package/build/lib/types/engine/index.d.ts +2 -2
  31. package/build/lib/types/engine/index.d.ts.map +1 -1
  32. package/package.json +14 -16
  33. package/build/lib/types/engine/context/ContextValue.interface.d.ts +0 -16
  34. package/build/lib/types/engine/context/ContextValue.interface.d.ts.map +0 -1
  35. package/build/lib/types/engine/context/index.d.ts +0 -2
  36. package/build/lib/types/engine/context/index.d.ts.map +0 -1
  37. package/build/lib/types/index.d.ts +0 -3
  38. package/build/lib/types/index.d.ts.map +0 -1
  39. package/build/lib/util/immersive/fromWebXRSessionMode.d.ts +0 -7
  40. package/build/lib/util/immersive/fromWebXRSessionMode.d.ts.map +0 -1
  41. package/build/lib/util/immersive/index.d.ts +0 -4
  42. package/build/lib/util/immersive/index.d.ts.map +0 -1
  43. package/build/lib/util/immersive/isImmersiveModeSupported.d.ts +0 -7
  44. package/build/lib/util/immersive/isImmersiveModeSupported.d.ts.map +0 -1
  45. package/build/lib/util/immersive/toWebXRSessionMode.d.ts +0 -7
  46. package/build/lib/util/immersive/toWebXRSessionMode.d.ts.map +0 -1
package/build/index.js CHANGED
@@ -1,503 +1,493 @@
1
- import v, { useRef as w, useEffect as x, useState as B, useCallback as P, useMemo as q } from "react";
2
- import { useFrame as L, useThree as j, createPortal as K } from "@react-three/fiber";
3
- import { jsx as F } from "react/jsx-runtime";
4
- import { ArMarkerControls as D, ArToolkitSource as Q, ArToolkitContext as V } from "@ar-js-org/ar.js/three.js/build/ar-threex";
5
- import { Group as Y } from "three";
6
- import { LocationBased as $, Webcam as J, DeviceOrientationControls as Z } from "locar";
7
- import { createXRStore as _, XR as ee } from "@react-three/xr";
8
- const N = (t) => {
1
+ import y, { useRef as S, useEffect as k, useState as B, useMemo as T, useCallback as O } from "react";
2
+ import { useFrame as R, useThree as v, createPortal as G } from "@react-three/fiber";
3
+ import { jsx as C } from "react/jsx-runtime";
4
+ import { ArMarkerControls as x, ArToolkitSource as P, ArToolkitContext as D } from "@ar-js-org/ar.js/three.js/build/ar-threex";
5
+ import { Group as N } from "three";
6
+ import { LocationBased as X, Webcam as U, DeviceOrientationControls as H } from "locar";
7
+ import { createXRStore as W, XR as q } from "@react-three/xr";
8
+ const p = {
9
+ FIDUCIAL: "fiducial",
10
+ GEOLOCATION: "geolocation",
11
+ IMMERSIVE: "immersive"
12
+ }, L = (n) => {
9
13
  let e;
10
- const n = /* @__PURE__ */ new Set(), r = (a, d) => {
11
- const s = typeof a == "function" ? a(e) : a;
12
- if (!Object.is(s, e)) {
13
- const A = e;
14
- e = d ?? (typeof s != "object" || s === null) ? s : Object.assign({}, e, s), n.forEach((m) => m(e, A));
14
+ const t = /* @__PURE__ */ new Set(), r = (i, f) => {
15
+ const l = typeof i == "function" ? i(e) : i;
16
+ if (!Object.is(l, e)) {
17
+ const o = e;
18
+ e = f ?? (typeof l != "object" || l === null) ? l : Object.assign({}, e, l), t.forEach((d) => d(e, o));
15
19
  }
16
- }, i = () => e, c = { setState: r, getState: i, getInitialState: () => u, subscribe: (a) => (n.add(a), () => n.delete(a)) }, u = e = t(r, i, c);
17
- return c;
18
- }, te = ((t) => t ? N(t) : N), ne = (t) => t;
19
- function re(t, e = ne) {
20
- const n = v.useSyncExternalStore(
21
- t.subscribe,
22
- v.useCallback(() => e(t.getState()), [t, e]),
23
- v.useCallback(() => e(t.getInitialState()), [t, e])
20
+ }, c = () => e, a = { setState: r, getState: c, getInitialState: () => u, subscribe: (i) => (t.add(i), () => t.delete(i)) }, u = e = n(r, c, a);
21
+ return a;
22
+ }, K = ((n) => n ? L(n) : L), V = (n) => n;
23
+ function Q(n, e = V) {
24
+ const t = y.useSyncExternalStore(
25
+ n.subscribe,
26
+ y.useCallback(() => e(n.getState()), [n, e]),
27
+ y.useCallback(() => e(n.getInitialState()), [n, e])
24
28
  );
25
- return v.useDebugValue(n), n;
29
+ return y.useDebugValue(t), t;
26
30
  }
27
- const oe = (t) => {
28
- const e = te(t), n = (r) => re(e, r);
29
- return Object.assign(n, e), n;
30
- }, ie = ((t) => oe), se = (t) => (e, n, r) => {
31
- const i = r.subscribe;
32
- return r.subscribe = ((l, c, u) => {
33
- let a = l;
34
- if (c) {
35
- const d = u?.equalityFn || Object.is;
36
- let s = l(r.getState());
37
- a = (A) => {
38
- const m = l(A);
39
- if (!d(s, m)) {
40
- const f = s;
41
- c(s = m, f);
31
+ const Y = (n) => {
32
+ const e = K(n), t = (r) => Q(e, r);
33
+ return Object.assign(t, e), t;
34
+ }, J = ((n) => Y), $ = (n) => (e, t, r) => {
35
+ const c = r.subscribe;
36
+ return r.subscribe = ((A, a, u) => {
37
+ let i = A;
38
+ if (a) {
39
+ const f = u?.equalityFn || Object.is;
40
+ let l = A(r.getState());
41
+ i = (o) => {
42
+ const d = A(o);
43
+ if (!f(l, d)) {
44
+ const b = l;
45
+ a(l = d, b);
42
46
  }
43
- }, u?.fireImmediately && c(s, s);
47
+ }, u?.fireImmediately && a(l, l);
44
48
  }
45
- return i(a);
46
- }), t(e, n, r);
47
- }, ce = se, X = (t) => Symbol.iterator in t, U = (t) => (
49
+ return c(i);
50
+ }), n(e, t, r);
51
+ }, Z = $, j = (n) => Symbol.iterator in n, z = (n) => (
48
52
  // HACK: avoid checking entries type
49
- "entries" in t
50
- ), H = (t, e) => {
51
- const n = t instanceof Map ? t : new Map(t.entries()), r = e instanceof Map ? e : new Map(e.entries());
52
- if (n.size !== r.size)
53
+ "entries" in n
54
+ ), F = (n, e) => {
55
+ const t = n instanceof Map ? n : new Map(n.entries()), r = e instanceof Map ? e : new Map(e.entries());
56
+ if (t.size !== r.size)
53
57
  return !1;
54
- for (const [i, o] of n)
55
- if (!r.has(i) || !Object.is(o, r.get(i)))
58
+ for (const [c, s] of t)
59
+ if (!r.has(c) || !Object.is(s, r.get(c)))
56
60
  return !1;
57
61
  return !0;
58
- }, ae = (t, e) => {
59
- const n = t[Symbol.iterator](), r = e[Symbol.iterator]();
60
- let i = n.next(), o = r.next();
61
- for (; !i.done && !o.done; ) {
62
- if (!Object.is(i.value, o.value))
62
+ }, _ = (n, e) => {
63
+ const t = n[Symbol.iterator](), r = e[Symbol.iterator]();
64
+ let c = t.next(), s = r.next();
65
+ for (; !c.done && !s.done; ) {
66
+ if (!Object.is(c.value, s.value))
63
67
  return !1;
64
- i = n.next(), o = r.next();
68
+ c = t.next(), s = r.next();
65
69
  }
66
- return !!i.done && !!o.done;
70
+ return !!c.done && !!s.done;
67
71
  };
68
- function le(t, e) {
69
- return Object.is(t, e) ? !0 : typeof t != "object" || t === null || typeof e != "object" || e === null || Object.getPrototypeOf(t) !== Object.getPrototypeOf(e) ? !1 : X(t) && X(e) ? U(t) && U(e) ? H(t, e) : ae(t, e) : H(
70
- { entries: () => Object.entries(t) },
72
+ function ee(n, e) {
73
+ return Object.is(n, e) ? !0 : typeof n != "object" || n === null || typeof e != "object" || e === null || Object.getPrototypeOf(n) !== Object.getPrototypeOf(e) ? !1 : j(n) && j(e) ? z(n) && z(e) ? F(n, e) : _(n, e) : F(
74
+ { entries: () => Object.entries(n) },
71
75
  { entries: () => Object.entries(e) }
72
76
  );
73
77
  }
74
- function ue(t) {
75
- const e = v.useRef(void 0);
76
- return (n) => {
77
- const r = t(n);
78
- return le(e.current, r) ? e.current : e.current = r;
78
+ function te(n) {
79
+ const e = y.useRef(void 0);
80
+ return (t) => {
81
+ const r = n(t);
82
+ return ee(e.current, r) ? e.current : e.current = r;
79
83
  };
80
84
  }
81
- const S = {
82
- FIDUCIAL: "FiducialSession",
83
- GEOLOCATION: "GeolocationSession",
84
- IMMERSIVE: "ImmersiveSession"
85
- }, G = ie()(
86
- ce((t, e) => ({
85
+ const M = J()(
86
+ Z((n, e) => ({
87
87
  // initial state
88
88
  video: null,
89
- backends: [],
90
- sessionTypes: /* @__PURE__ */ new Set(),
89
+ backends: /* @__PURE__ */ new Map(),
91
90
  immersiveStore: null,
92
91
  // actions
93
- registerBackend: async (n, r, i) => {
92
+ registerBackend: async (t, r) => {
94
93
  try {
95
- if (i) {
96
- const o = e(), l = /* @__PURE__ */ new Set([...o.sessionTypes, i]), c = l.has(S.FIDUCIAL), u = l.has(S.GEOLOCATION);
97
- if (c && u) {
98
- const a = `❌ [RDK] INCOMPATIBLE SESSIONS: ${S.FIDUCIAL} and ${S.GEOLOCATION} cannot be used together due to camera/video conflicts between AR.js and LocAR.js libraries. Use only one session type per app.`;
99
- throw console.error(a), new Error(a);
100
- }
101
- t(() => ({
102
- sessionTypes: l
103
- }));
94
+ const c = e(), s = new Set(c.backends.keys()), A = s.has(p.FIDUCIAL) || t.type === p.FIDUCIAL, a = s.has(p.GEOLOCATION) || t.type === p.GEOLOCATION;
95
+ if (A && a) {
96
+ const u = "❌ [RDK] INCOMPATIBLE SESSIONS: fiducial and geolocation backends cannot be used together due to camera/video conflicts between AR.js and LocAR.js libraries. Use only one session type per app.";
97
+ throw console.error(u), new Error(u);
104
98
  }
105
- await n.init({
99
+ await t.init({
106
100
  scene: r.scene,
107
101
  camera: r.camera,
108
102
  renderer: r.renderer
109
- }), t((o) => ({
110
- backends: [...o.backends, n]
111
- }));
112
- } catch (o) {
113
- throw console.error("[XRStore] Failed to register backend:", o), o;
103
+ }), n((u) => {
104
+ const i = new Map(u.backends);
105
+ return i.set(t.type, t), { backends: i };
106
+ });
107
+ } catch (c) {
108
+ throw console.error("[XRStore] Failed to register backend:", c), c;
114
109
  }
115
110
  },
116
- unregisterBackend: (n, r) => {
117
- t((i) => {
118
- const o = new Set(i.sessionTypes);
119
- r && o.delete(r);
120
- const l = i.backends.filter((c) => c !== n);
111
+ unregisterBackend: (t) => {
112
+ n((r) => {
113
+ const c = new Map(r.backends);
114
+ c.delete(t.type);
121
115
  try {
122
- n.dispose?.();
123
- } catch (c) {
124
- console.error("[XRStore] Error disposing backend:", c);
116
+ t.dispose?.();
117
+ } catch (s) {
118
+ console.error("[XRStore] Error disposing backend:", s);
125
119
  }
126
- return {
127
- backends: l,
128
- sessionTypes: o
129
- };
120
+ return { backends: c };
130
121
  });
131
122
  },
132
- setVideo: (n) => {
133
- t({ video: n });
123
+ setVideo: (t) => {
124
+ n({ video: t });
134
125
  },
135
- updateBackends: (n) => {
126
+ updateBackends: (t) => {
136
127
  const { backends: r } = e();
137
- r.forEach((i) => {
128
+ for (const c of r.values())
138
129
  try {
139
- i.update?.(n);
140
- } catch (o) {
141
- console.error("[XRStore] Backend update error:", o);
130
+ c.update?.(t);
131
+ } catch (s) {
132
+ console.error("[XRStore] Backend update error:", s);
142
133
  }
143
- });
144
134
  },
145
- setImmersiveStore: (n) => {
146
- t({ immersiveStore: n });
135
+ setImmersiveStore: (t) => {
136
+ n({ immersiveStore: t });
147
137
  }
148
138
  }))
149
- ), de = () => G.getState(), ke = G.subscribe, T = (t) => G(
150
- ue((n) => {
139
+ ), ne = () => M.getState(), pe = M.subscribe, I = (n) => M(
140
+ te((t) => {
151
141
  const r = {
152
- ...n,
153
- isImmersive: n.sessionTypes.has(S.IMMERSIVE),
154
- immersive: n.immersiveStore || null
142
+ ...t,
143
+ isImmersive: t.backends.has(p.IMMERSIVE),
144
+ immersive: t.immersiveStore || null
155
145
  };
156
- return t ? t(r) : r;
146
+ return n ? n(r) : r;
157
147
  })
158
- ), Ee = ({ children: t }) => {
159
- const { updateBackends: e } = T();
160
- return L((n, r) => {
148
+ ), be = ({ children: n }) => {
149
+ const { updateBackends: e } = I();
150
+ return R((t, r) => {
161
151
  e(r);
162
- }), t;
163
- }, Re = ({
164
- patternUrl: t,
152
+ }), n;
153
+ }, re = () => I((t) => t.backends).get(p.FIDUCIAL)?.getInternal() ?? null, Se = ({
154
+ patternUrl: n,
165
155
  barcodeValue: e,
166
- params: n,
156
+ params: t,
167
157
  onMarkerFound: r,
168
- onMarkerLost: i,
169
- children: o
158
+ onMarkerLost: c,
159
+ children: s
170
160
  }) => {
171
- const l = w(null), c = T((s) => s.backends), u = w(!1), a = w(!1), d = w(null);
172
- return x(() => {
173
- let s = !1;
174
- return (async () => {
161
+ const A = S(null), a = re(), u = S(!1), i = S(!1), f = S(null);
162
+ return k(() => {
163
+ if (!a) return;
164
+ let l = !1;
165
+ return (() => {
175
166
  try {
176
- const m = c.find((h) => h.getInternal?.()?.arContext);
177
- if (!m || s) return;
178
- const g = m.getInternal?.()?.arContext, y = l.current;
179
- if (!g || !y) return;
180
- if (y.visible = !1, a.current = !1, !g.arController) {
167
+ const { arContext: d } = a, b = A.current;
168
+ if (!d || !b || l) return;
169
+ if (b.visible = !1, i.current = !1, !d.arController) {
181
170
  requestAnimationFrame(() => {
182
- if (!l.current || s) return;
183
- const I = m.getInternal?.()?.arContext;
184
- if (!I?.arController) return;
185
- const b = new D(I, l.current, {
186
- type: t ? "pattern" : e ? "barcode" : "unknown",
187
- patternUrl: t,
188
- barcodeValue: e,
189
- ...n
190
- });
191
- d.current = b, a.current = !0;
171
+ if (!A.current || l || !a.arContext?.arController)
172
+ return;
173
+ const g = new x(
174
+ a.arContext,
175
+ A.current,
176
+ {
177
+ type: n ? "pattern" : e ? "barcode" : "unknown",
178
+ patternUrl: n,
179
+ barcodeValue: e,
180
+ ...t
181
+ }
182
+ );
183
+ f.current = g, i.current = !0;
192
184
  });
193
185
  return;
194
186
  }
195
- const E = new D(g, y, {
196
- type: t ? "pattern" : e ? "barcode" : "unknown",
197
- patternUrl: t,
187
+ const h = new x(d, b, {
188
+ type: n ? "pattern" : e ? "barcode" : "unknown",
189
+ patternUrl: n,
198
190
  barcodeValue: e,
199
- ...n
191
+ ...t
200
192
  });
201
- d.current = E, a.current = !0;
202
- } catch (m) {
203
- console.error("Failed to initialize fiducial backend:", m);
193
+ f.current = h, i.current = !0;
194
+ } catch (d) {
195
+ console.error("Failed to initialize fiducial anchor:", d);
204
196
  }
205
197
  })(), () => {
206
- s = !0;
207
- const m = d.current;
208
- typeof m?.dispose == "function" && m.dispose(), a.current = !1;
198
+ l = !0;
199
+ const d = f.current;
200
+ typeof d?.dispose == "function" && d.dispose(), i.current = !1;
209
201
  };
210
- }, [c, t, e, n]), L(() => {
211
- const s = l.current;
212
- if (!s || !a.current) {
213
- s && (s.visible = !1);
202
+ }, [a, n, e, t]), R(() => {
203
+ const l = A.current;
204
+ if (!l || !i.current) {
205
+ l && (l.visible = !1);
214
206
  return;
215
207
  }
216
- const A = s.visible;
217
- A && !u.current ? (u.current = !0, r?.()) : !A && u.current && (u.current = !1, i?.());
218
- }), /* @__PURE__ */ F(
208
+ const o = l.visible;
209
+ o && !u.current ? (u.current = !0, r?.()) : !o && u.current && (u.current = !1, c?.());
210
+ }), /* @__PURE__ */ C(
219
211
  "group",
220
212
  {
221
- ref: l,
213
+ ref: A,
222
214
  visible: !1,
223
- children: o
215
+ children: s
224
216
  }
225
217
  );
226
- }, Ae = ({ options: t = {}, children: e }) => {
227
- const { scene: n, camera: r, gl: i } = j(), { registerBackend: o, unregisterBackend: l } = T(), c = w(null), u = w(t);
228
- return u.current = t, x(() => {
229
- if (c.current) return;
230
- let a = !1;
218
+ }, ge = ({ options: n = {}, children: e }) => {
219
+ const { scene: t, camera: r, gl: c } = v(), { registerBackend: s, unregisterBackend: A } = I(), a = S(null), u = S(n);
220
+ return u.current = n, k(() => {
221
+ if (a.current) return;
222
+ let i = !1;
231
223
  return (async () => {
232
224
  try {
233
- const s = fe(u.current);
234
- if (a) return;
235
- await o(
236
- s,
237
- { scene: n, camera: r, renderer: i },
238
- S.FIDUCIAL
239
- ), c.current = s;
240
- } catch (s) {
241
- console.error("[FiducialSession] Failed to initialize:", s);
225
+ const l = oe(u.current);
226
+ if (i) return;
227
+ await s(l, { scene: t, camera: r, renderer: c }), a.current = l;
228
+ } catch (l) {
229
+ console.error("[FiducialSession] Failed to initialize:", l);
242
230
  }
243
231
  })(), () => {
244
- a = !0, c.current && (l(c.current, S.FIDUCIAL), c.current = null);
232
+ i = !0, a.current && (A(a.current), a.current = null);
245
233
  };
246
- }, [n, r, i, o, l]), e;
247
- };
248
- Ae.sessionType = "FiducialSession";
249
- const fe = (t) => {
250
- let e = null, n = null, r = null, i;
234
+ }, [t, r, c, s, A]), e;
235
+ }, oe = (n) => {
236
+ let e = null, t = null, r = null, c;
251
237
  return {
252
- async init({ camera: o, renderer: l }) {
253
- e = new Q({
254
- sourceType: t?.sourceType ?? "webcam"
255
- }), await new Promise((a, d) => {
256
- const s = setTimeout(() => {
257
- d(new Error("AR source initialization timeout"));
238
+ type: p.FIDUCIAL,
239
+ async init({ camera: s, renderer: A }) {
240
+ e = new P({
241
+ sourceType: n?.sourceType ?? "webcam"
242
+ }), await new Promise((i, f) => {
243
+ const l = setTimeout(() => {
244
+ f(new Error("AR source initialization timeout"));
258
245
  }, 1e4);
259
- e.init(() => {
260
- clearTimeout(s);
261
- const A = e.domElement;
262
- A && (A.style.position = "fixed", A.style.top = "0", A.style.left = "0", A.style.width = "100vw", A.style.height = "100vh", A.style.objectFit = "cover", A.style.zIndex = "-1", A.style.pointerEvents = "none"), a();
246
+ e?.init(() => {
247
+ clearTimeout(l);
248
+ const o = e?.domElement;
249
+ o && (o.style.position = "fixed", o.style.top = "0", o.style.left = "0", o.style.width = "100vw", o.style.height = "100vh", o.style.objectFit = "cover", o.style.zIndex = "-1", o.style.pointerEvents = "none"), i();
263
250
  });
264
251
  });
265
- const c = {
266
- cameraParametersUrl: t?.cameraParametersUrl ?? // default to internal camera parameters
252
+ const a = {
253
+ cameraParametersUrl: n?.cameraParametersUrl ?? // default to internal camera parameters
267
254
  new URL("data:application/octet-stream;base64,AAACgAAAAeBAgwrsW6bUSwAAAAAAAAAAQHQ3KqAAAAAAAAAAAAAAAAAAAAAAAAAAQIL0K3dHyf9AbbNowAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD/wAAAAAAAAAAAAAAAAAAA/uWNa4AAAAL+3lTLAAAAAv17YFWAAAAA/VYLXIAAAAECCe0YgAAAAQIJlMOAAAABAdDcqoAAAAEBts2jAAAAAP+8OmzqkDy4=", import.meta.url).toString(),
268
- detectionMode: t?.detectionMode ?? "mono",
269
- patternRatio: t?.patternRatio ?? 0.5,
270
- matrixCodeType: t?.matrixCodeType ?? "3x3"
255
+ detectionMode: n?.detectionMode ?? "mono",
256
+ patternRatio: n?.patternRatio ?? 0.5,
257
+ matrixCodeType: n?.matrixCodeType ?? "3x3"
271
258
  };
272
- n = new V(c), r = o;
259
+ t = new D(a), r = s;
273
260
  const u = () => {
274
- e.onResizeElement();
275
- const a = window.innerWidth, d = window.innerHeight;
276
- l.setSize(a, d, !1), e.copyElementSizeTo(l.domElement), n?.arController && e.copyElementSizeTo(n.arController.canvas);
261
+ e?.onResizeElement();
262
+ const i = window.innerWidth, f = window.innerHeight;
263
+ A.setSize(i, f, !1), e?.copyElementSizeTo(A.domElement), t?.arController && e?.copyElementSizeTo(t.arController.canvas);
277
264
  };
278
- await new Promise((a, d) => {
279
- const s = setTimeout(() => {
280
- d(new Error("AR context initialization timeout"));
265
+ await new Promise((i, f) => {
266
+ const l = setTimeout(() => {
267
+ f(new Error("AR context initialization timeout"));
281
268
  }, 1e4);
282
- n.init(() => {
283
- clearTimeout(s);
269
+ t?.init(() => {
270
+ clearTimeout(l);
284
271
  try {
285
- o.projectionMatrix.copy(n.getProjectionMatrix()), u(), a();
286
- } catch (A) {
287
- d(A);
272
+ const o = t?.getProjectionMatrix();
273
+ o && s.projectionMatrix.copy(o), u(), i();
274
+ } catch (o) {
275
+ f(o);
288
276
  }
289
277
  });
290
- }), window.addEventListener("resize", u), i = u;
278
+ }), window.addEventListener("resize", u), c = u;
291
279
  },
292
280
  update() {
293
- if (!(!e || !n) && !(!e.ready || !e.domElement))
281
+ if (!(!e || !t) && !(!e.ready || !e.domElement))
294
282
  try {
295
- n.update(e.domElement), r && n.getProjectionMatrix && r.projectionMatrix.copy(n.getProjectionMatrix());
296
- } catch (o) {
297
- console.warn("AR.js update error:", o);
283
+ t.update(e.domElement);
284
+ const s = t.getProjectionMatrix?.();
285
+ r && s && r.projectionMatrix.copy(s);
286
+ } catch (s) {
287
+ console.warn("AR.js update error:", s);
298
288
  }
299
289
  },
300
290
  dispose() {
301
- if (i && (window.removeEventListener("resize", i), i = void 0), n && typeof n.dispose == "function" && n.dispose(), e?.domElement) {
302
- const o = e.domElement.parentNode;
303
- o && o.removeChild(e.domElement);
291
+ if (c && (window.removeEventListener("resize", c), c = void 0), t && typeof t.dispose == "function" && t.dispose(), e?.domElement) {
292
+ const s = e.domElement.parentNode;
293
+ s && s.removeChild(e.domElement);
304
294
  }
305
- e = null, n = null, r = null;
295
+ e = null, t = null, r = null;
306
296
  },
307
- getInternal() {
308
- return {
309
- arSource: e,
310
- arContext: n
311
- };
312
- }
297
+ getInternal: () => ({
298
+ arSource: e,
299
+ arContext: t
300
+ })
313
301
  };
314
- }, k = /* @__PURE__ */ new Map();
315
- let M = !1, O = null, C = null;
316
- const Oe = ({
317
- latitude: t,
302
+ }, ce = () => I((t) => t.backends).get(p.GEOLOCATION)?.getInternal() ?? null, he = ({
303
+ latitude: n,
318
304
  longitude: e,
319
- altitude: n = 0,
305
+ altitude: t = 0,
320
306
  isBillboard: r = !0,
321
- onAttach: i,
322
- onGpsUpdate: o,
323
- children: l
307
+ onAttach: c,
308
+ onGpsUpdate: s,
309
+ children: A
324
310
  }) => {
325
- const c = T((f) => f.backends), { camera: u } = j(), [a] = B(() => new Y()), [d] = B(() => Math.random().toString(36).slice(2, 11)), s = w(!1), A = P(() => {
326
- i?.();
327
- }, [i]), m = P(
328
- (f, g) => {
329
- o?.(f, g);
311
+ const a = ce(), { camera: u } = v(), [i] = B(() => new N()), f = T(() => Math.random().toString(36).slice(2, 11), []), l = O(() => {
312
+ c?.();
313
+ }, [c]), o = O(
314
+ (d, b) => {
315
+ s?.(d, b);
330
316
  },
331
- [o]
317
+ [s]
332
318
  );
333
- return x(() => {
334
- let f = !1;
335
- return (async () => {
336
- try {
337
- const y = c.find((p) => p.getInternal?.()?.locar);
338
- if (!y || f) return;
339
- const h = y.getInternal?.()?.locar;
340
- if (!h) return;
341
- const I = (p) => {
342
- try {
343
- h.add(
344
- p.anchor,
345
- p.longitude,
346
- p.latitude,
347
- p.altitude
348
- ), p.isAttached = !0, p.onAttach?.();
349
- } catch (R) {
350
- console.error("❌ Failed to attach anchor:", R);
351
- }
352
- }, b = {
353
- anchor: a,
354
- isAttached: !1,
355
- latitude: t,
356
- longitude: e,
357
- altitude: n || 0,
358
- onAttach: A,
359
- onGpsUpdate: m
360
- };
361
- if (k.set(d, b), !M) {
362
- C = ({ position: R, distMoved: W }) => {
363
- O = R, k.forEach((z) => {
364
- z.isAttached || I(z), z.onGpsUpdate?.(R, W);
365
- });
366
- };
367
- const p = h.getLastKnownLocation();
368
- p !== null && (O = {
369
- coords: {
370
- longitude: p.longitude,
371
- latitude: p.latitude,
372
- accuracy: 0,
373
- altitude: null,
374
- altitudeAccuracy: null,
375
- heading: null,
376
- speed: null,
377
- toJSON: () => p
378
- },
379
- timestamp: Date.now(),
380
- toJSON: () => p
381
- }), O !== null && !b.isAttached && I(b), h.on?.("gpsupdate", C), M = !0;
382
- }
383
- O !== null && (b.isAttached || I(b), b.onGpsUpdate?.(O, 0)), s.current = !1;
384
- } catch (y) {
385
- console.error("Failed to initialize geolocation backend:", y);
386
- }
387
- })(), () => {
388
- if (f = !0, k.get(d)?.isAttached)
389
- try {
390
- a.removeFromParent();
391
- } catch (E) {
392
- console.error(`⚠️ Error removing anchor ${d}:`, E);
393
- }
394
- k.delete(d), k.size === 0 && C && (c.find((b) => b.getInternal?.()?.locar)?.getInternal?.()?.locar?.off?.("gpsupdate", C), C = null, M = !1);
395
- };
319
+ return k(() => {
320
+ if (a)
321
+ return a.registerAnchor(f, {
322
+ anchor: i,
323
+ isAttached: !1,
324
+ latitude: n,
325
+ longitude: e,
326
+ altitude: t,
327
+ onAttach: l,
328
+ onGpsUpdate: o
329
+ }), () => {
330
+ a.unregisterAnchor(f);
331
+ };
396
332
  }, [
397
- c,
398
333
  a,
399
- d,
400
- t,
401
- e,
334
+ i,
335
+ f,
402
336
  n,
403
- A,
404
- m
405
- ]), L(() => {
406
- !r || !u || !k.get(d)?.isAttached || a.lookAt(u.position);
407
- }), K(/* @__PURE__ */ F("group", { children: l }), a);
408
- }, me = ({
409
- options: t = {},
337
+ e,
338
+ t,
339
+ l,
340
+ o
341
+ ]), R(() => {
342
+ !r || !u || !a || !a.getAnchor(f)?.isAttached || i.lookAt(u.position);
343
+ }), G(/* @__PURE__ */ C("group", { children: A }), i);
344
+ }, we = ({
345
+ options: n = {},
410
346
  children: e
411
347
  }) => {
412
- const { scene: n, camera: r, gl: i } = j(), { registerBackend: o, unregisterBackend: l } = T(), c = w(null), u = w(t);
413
- return u.current = t, x(() => {
414
- if (c.current) return;
415
- let a = !1;
348
+ const { scene: t, camera: r, gl: c } = v(), { registerBackend: s, unregisterBackend: A } = I(), a = S(null), u = S(n);
349
+ return u.current = n, k(() => {
350
+ if (a.current) return;
351
+ let i = !1;
416
352
  return (async () => {
417
353
  try {
418
- const s = pe(u.current);
419
- if (a) return;
420
- await o(
421
- s,
422
- { scene: n, camera: r, renderer: i },
423
- S.GEOLOCATION
424
- ), c.current = s;
425
- } catch (s) {
426
- console.error("[GeolocationSession] Failed to initialize:", s);
354
+ const l = se(u.current);
355
+ if (i) return;
356
+ await s(l, { scene: t, camera: r, renderer: c }), a.current = l;
357
+ } catch (l) {
358
+ console.error("[GeolocationSession] Failed to initialize:", l);
427
359
  }
428
360
  })(), () => {
429
- a = !0, c.current && (l(c.current, S.GEOLOCATION), c.current = null);
361
+ i = !0, a.current && (A(a.current), a.current = null);
430
362
  };
431
- }, [n, r, i, o, l]), e;
432
- };
433
- me.sessionType = "GeolocationSession";
434
- const pe = (t) => {
435
- let e = null, n = null, r = null, i, o = null, l = null, c = null, u = null;
363
+ }, [t, r, c, s, A]), e;
364
+ }, se = (n) => {
365
+ let e = null, t = null, r = null, c, s = null, A = null, a = null, u = null;
366
+ const i = /* @__PURE__ */ new Map();
367
+ let f = null;
368
+ const l = (o) => {
369
+ if (!(!e || o.isAttached))
370
+ try {
371
+ e.add(o.anchor, o.longitude, o.latitude, o.altitude), o.isAttached = !0, o.onAttach?.();
372
+ } catch (d) {
373
+ console.error("❌ Failed to attach anchor:", d);
374
+ }
375
+ };
436
376
  return {
437
- async init(a) {
438
- const { camera: d, renderer: s, scene: A } = a;
439
- if (!A)
377
+ type: p.GEOLOCATION,
378
+ async init(o) {
379
+ const { camera: d, renderer: b, scene: h } = o;
380
+ if (!h)
440
381
  throw new Error(
441
382
  "[geolocationBackend] A THREE.Scene is required for location-based AR"
442
383
  );
443
- l = d, c = s, u = A, e = new $(A, d), n = new J(
444
- t?.webcamConstraints ?? {
384
+ A = d, a = b, u = h, e = new X(h, d), t = new U(
385
+ n?.webcamConstraints ?? {
445
386
  video: { facingMode: "environment" }
446
387
  // TODO remove `as any` once fixed upstream (LocAR.js)
447
388
  }
448
- ), o = (f) => {
449
- t?.onGpsUpdate?.(f.position, f.distMoved);
450
- }, e.on("gpsupdate", o), n.on("webcamstarted", (f) => {
451
- A.background = f.texture;
452
- }), n.on("webcamerror", (f) => {
453
- console.error("[geolocationBackend] webcam error:", f);
454
- }), r = new Z(d), r.on("deviceorientationgranted", (f) => {
455
- f.target?.connect?.();
456
- }), r.on("deviceorientationerror", (f) => {
457
- console.error("[geolocationBackend] Device orientation error:", f);
458
- }), r.init?.(), e.on("gpserror", (f) => {
459
- console.error("[geolocationBackend] gps error:", f);
460
- }), e.startGps(), typeof t?.fakeLat == "number" && typeof t?.fakeLon == "number" && e.fakeGps(t.fakeLon, t.fakeLat);
461
- const m = () => {
462
- if (!c || !l) return;
463
- const f = window.innerWidth, g = window.innerHeight;
464
- c.setSize(f, g, !1), l.aspect = f / g, l.updateProjectionMatrix?.();
389
+ ), s = (m) => {
390
+ f = m.position;
391
+ for (const w of i.values())
392
+ w.isAttached || l(w), w.onGpsUpdate?.(m.position, m.distMoved);
393
+ n?.onGpsUpdate?.(m.position, m.distMoved);
394
+ }, e.on("gpsupdate", s), t.on("webcamstarted", (m) => {
395
+ h.background = m.texture;
396
+ }), t.on("webcamerror", (m) => {
397
+ console.error("[geolocationBackend] webcam error:", m);
398
+ }), r = new H(d), r.on("deviceorientationgranted", (m) => {
399
+ m.target?.connect?.();
400
+ }), r.on("deviceorientationerror", (m) => {
401
+ console.error("[geolocationBackend] Device orientation error:", m);
402
+ }), r.init?.(), e.on("gpserror", (m) => {
403
+ console.error("[geolocationBackend] gps error:", m);
404
+ }), e.startGps(), typeof n?.fakeLat == "number" && typeof n?.fakeLon == "number" && e.fakeGps(n.fakeLon, n.fakeLat);
405
+ const g = e.getLastKnownLocation();
406
+ g !== null && (f = {
407
+ coords: {
408
+ longitude: g.longitude,
409
+ latitude: g.latitude,
410
+ accuracy: 0,
411
+ altitude: null,
412
+ altitudeAccuracy: null,
413
+ heading: null,
414
+ speed: null,
415
+ toJSON: () => g
416
+ },
417
+ timestamp: Date.now(),
418
+ toJSON: () => g
419
+ });
420
+ const E = () => {
421
+ if (!a || !A) return;
422
+ const m = window.innerWidth, w = window.innerHeight;
423
+ a.setSize(m, w, !1), A.aspect = m / w, A.updateProjectionMatrix?.();
465
424
  };
466
- m(), window.addEventListener("resize", m), i = m;
425
+ E(), window.addEventListener("resize", E), c = E;
467
426
  },
468
427
  update() {
469
428
  r?.update?.();
470
429
  },
471
430
  dispose() {
472
- e && o && e.off("gpsupdate", o), e?.stopGps?.(), n?.stop?.(), r?.dispose?.(), i && (window.removeEventListener("resize", i), i = void 0), e = null, n = null, r = null, l = null, c = null, u = null, o = null;
431
+ e && s && e.off("gpsupdate", s), e?.stopGps?.(), t?.stop?.(), r?.dispose?.(), c && (window.removeEventListener("resize", c), c = void 0);
432
+ for (const o of i.values())
433
+ if (o.isAttached)
434
+ try {
435
+ o.anchor.removeFromParent();
436
+ } catch (d) {
437
+ console.error("⚠️ Error removing anchor:", d);
438
+ }
439
+ i.clear(), e = null, t = null, r = null, A = null, a = null, u = null, s = null, f = null;
473
440
  },
474
441
  getInternal: () => ({
475
442
  locar: e,
476
- webcam: n,
443
+ webcam: t,
477
444
  deviceOrientation: r,
478
445
  scene: u,
479
- camera: l
446
+ camera: A,
447
+ lastPosition: f,
448
+ registerAnchor: (o, d) => {
449
+ i.set(o, d), f !== null && !d.isAttached && (l(d), d.onGpsUpdate?.(f, 0));
450
+ },
451
+ unregisterAnchor: (o) => {
452
+ const d = i.get(o);
453
+ if (d?.isAttached)
454
+ try {
455
+ d.anchor.removeFromParent();
456
+ } catch (b) {
457
+ console.error(`⚠️ Error removing anchor ${o}:`, b);
458
+ }
459
+ i.delete(o);
460
+ },
461
+ getAnchor: (o) => i.get(o)
480
462
  })
481
463
  };
482
- }, Ce = ({ children: t }) => {
483
- const e = q(() => _(), []);
484
- return x(() => {
485
- const n = de();
486
- return n.sessionTypes.add(S.IMMERSIVE), n.setImmersiveStore(e), () => {
487
- n.sessionTypes.delete(S.IMMERSIVE), n.setImmersiveStore(null);
464
+ }, ie = () => ({
465
+ type: p.IMMERSIVE,
466
+ init: () => {
467
+ },
468
+ getInternal: () => null
469
+ }), ye = ({ children: n }) => {
470
+ const e = T(() => W(), []);
471
+ return k(() => {
472
+ const t = ne(), r = ie();
473
+ return t.backends.set(p.IMMERSIVE, r), t.setImmersiveStore(e), () => {
474
+ t.backends.delete(p.IMMERSIVE), t.setImmersiveStore(null);
488
475
  };
489
- }, [e]), /* @__PURE__ */ F(ee, { store: e, children: t });
476
+ }, [e]), /* @__PURE__ */ C(q, { store: e, children: n });
490
477
  };
491
478
  export {
492
- Re as FiducialAnchor,
493
- Ae as FiducialSession,
494
- Oe as GeolocationAnchor,
495
- me as GeolocationSession,
496
- Ce as ImmersiveSession,
497
- Ee as XR,
498
- fe as createFiducialBackend,
499
- pe as createGeolocationBackend,
500
- de as getXRStore,
501
- ke as subscribeToXRStore,
502
- T as useXRStore
479
+ p as BACKEND_TYPES,
480
+ Se as FiducialAnchor,
481
+ ge as FiducialSession,
482
+ he as GeolocationAnchor,
483
+ we as GeolocationSession,
484
+ ye as ImmersiveSession,
485
+ be as XR,
486
+ oe as createFiducialBackend,
487
+ se as createGeolocationBackend,
488
+ ne as getXRStore,
489
+ pe as subscribeToXRStore,
490
+ re as useFiducialBackend,
491
+ ce as useGeolocationBackend,
492
+ I as useXRStore
503
493
  };