@omnidotdev/rdk 0.5.2 → 0.7.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 +18 -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 +17 -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 +37 -8
  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 +17 -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 +403 -370
  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 +15 -17
  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,536 @@
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 b, useEffect as k, useState as P, useMemo as F, useCallback as M } 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 B, ArToolkitContext as N } from "@ar-js-org/ar.js/three.js/build/ar-threex";
5
+ import { Group as D } from "three";
6
+ import { LocationBased as U, Webcam as X, 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 = (a, f) => {
15
+ const l = typeof a == "function" ? a(e) : a;
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, s = { setState: r, getState: c, getInitialState: () => u, subscribe: (a) => (t.add(a), () => t.delete(a)) }, u = e = n(r, c, s);
21
+ return s;
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
+ }, _ = ((n) => Y), J = (n) => (e, t, r) => {
35
+ const c = r.subscribe;
36
+ return r.subscribe = ((A, s, u) => {
37
+ let a = A;
38
+ if (s) {
39
+ const f = u?.equalityFn || Object.is;
40
+ let l = A(r.getState());
41
+ a = (o) => {
42
+ const d = A(o);
43
+ if (!f(l, d)) {
44
+ const S = l;
45
+ s(l = d, S);
42
46
  }
43
- }, u?.fireImmediately && c(s, s);
47
+ }, u?.fireImmediately && s(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(a);
50
+ }), n(e, t, r);
51
+ }, $ = J, T = (n) => Symbol.iterator in n, j = (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
+ ), z = (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, i] of t)
59
+ if (!r.has(c) || !Object.is(i, 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
+ }, Z = (n, e) => {
63
+ const t = n[Symbol.iterator](), r = e[Symbol.iterator]();
64
+ let c = t.next(), i = r.next();
65
+ for (; !c.done && !i.done; ) {
66
+ if (!Object.is(c.value, i.value))
63
67
  return !1;
64
- i = n.next(), o = r.next();
68
+ c = t.next(), i = r.next();
65
69
  }
66
- return !!i.done && !!o.done;
70
+ return !!c.done && !!i.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 : T(n) && T(e) ? j(n) && j(e) ? z(n, e) : Z(n, e) : z(
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 O = _()(
86
+ $((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(), i = new Set(c.backends.keys()), A = i.has(p.FIDUCIAL) || t.type === p.FIDUCIAL, s = i.has(p.GEOLOCATION) || t.type === p.GEOLOCATION;
95
+ if (A && s) {
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 a = new Map(u.backends);
105
+ return a.set(t.type, t), { backends: a };
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 (i) {
118
+ console.error("[XRStore] Error disposing backend:", i);
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 (i) {
132
+ console.error("[XRStore] Backend update error:", i);
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 = () => O.getState(), be = O.subscribe, I = (n) => O(
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
+ ), ge = ({ 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 = {
154
+ isPending: !0,
155
+ isSuccess: !1,
156
+ arSource: null,
157
+ arContext: null
158
+ }, oe = () => {
159
+ const e = I((t) => t.backends).get(p.FIDUCIAL);
160
+ return e ? {
161
+ ...e.getInternal(),
162
+ isPending: !1,
163
+ isSuccess: !0
164
+ } : re;
165
+ }, he = ({
166
+ patternUrl: n,
165
167
  barcodeValue: e,
166
- params: n,
168
+ params: t,
167
169
  onMarkerFound: r,
168
- onMarkerLost: i,
169
- children: o
170
+ onMarkerLost: c,
171
+ children: i
170
172
  }) => {
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 () => {
173
+ const A = b(null), s = oe(), u = b(!1), a = b(!1), f = b(null);
174
+ return k(() => {
175
+ if (!s.isSuccess) return;
176
+ let l = !1;
177
+ return (() => {
175
178
  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) {
179
+ const { arContext: d } = s, S = A.current;
180
+ if (!d || !S || l) return;
181
+ if (S.visible = !1, a.current = !1, !d.arController) {
181
182
  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;
183
+ if (!A.current || l || !s.arContext?.arController)
184
+ return;
185
+ const g = new x(
186
+ s.arContext,
187
+ A.current,
188
+ {
189
+ type: n ? "pattern" : e ? "barcode" : "unknown",
190
+ patternUrl: n,
191
+ barcodeValue: e,
192
+ ...t
193
+ }
194
+ );
195
+ f.current = g, a.current = !0;
192
196
  });
193
197
  return;
194
198
  }
195
- const E = new D(g, y, {
196
- type: t ? "pattern" : e ? "barcode" : "unknown",
197
- patternUrl: t,
199
+ const h = new x(d, S, {
200
+ type: n ? "pattern" : e ? "barcode" : "unknown",
201
+ patternUrl: n,
198
202
  barcodeValue: e,
199
- ...n
203
+ ...t
200
204
  });
201
- d.current = E, a.current = !0;
202
- } catch (m) {
203
- console.error("Failed to initialize fiducial backend:", m);
205
+ f.current = h, a.current = !0;
206
+ } catch (d) {
207
+ console.error("Failed to initialize fiducial anchor:", d);
204
208
  }
205
209
  })(), () => {
206
- s = !0;
207
- const m = d.current;
208
- typeof m?.dispose == "function" && m.dispose(), a.current = !1;
210
+ l = !0;
211
+ const d = f.current;
212
+ typeof d?.dispose == "function" && d.dispose(), a.current = !1;
209
213
  };
210
- }, [c, t, e, n]), L(() => {
211
- const s = l.current;
212
- if (!s || !a.current) {
213
- s && (s.visible = !1);
214
+ }, [
215
+ s.isSuccess,
216
+ s.arContext,
217
+ n,
218
+ e,
219
+ t,
220
+ s
221
+ ]), R(() => {
222
+ const l = A.current;
223
+ if (!l || !a.current) {
224
+ l && (l.visible = !1);
214
225
  return;
215
226
  }
216
- const A = s.visible;
217
- A && !u.current ? (u.current = !0, r?.()) : !A && u.current && (u.current = !1, i?.());
218
- }), /* @__PURE__ */ F(
227
+ const o = l.visible;
228
+ o && !u.current ? (u.current = !0, r?.()) : !o && u.current && (u.current = !1, c?.());
229
+ }), /* @__PURE__ */ C(
219
230
  "group",
220
231
  {
221
- ref: l,
232
+ ref: A,
222
233
  visible: !1,
223
- children: o
234
+ children: i
224
235
  }
225
236
  );
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;
237
+ }, we = ({ options: n = {}, children: e }) => {
238
+ const { scene: t, camera: r, gl: c } = v(), { registerBackend: i, unregisterBackend: A } = I(), s = b(null), u = b(n);
239
+ return u.current = n, k(() => {
240
+ if (s.current) return;
230
241
  let a = !1;
231
242
  return (async () => {
232
243
  try {
233
- const s = fe(u.current);
244
+ const l = se(u.current);
234
245
  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);
246
+ await i(l, { scene: t, camera: r, renderer: c }), s.current = l;
247
+ } catch (l) {
248
+ console.error("[FiducialSession] Failed to initialize:", l);
242
249
  }
243
250
  })(), () => {
244
- a = !0, c.current && (l(c.current, S.FIDUCIAL), c.current = null);
251
+ a = !0, s.current && (A(s.current), s.current = null);
245
252
  };
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;
253
+ }, [t, r, c, i, A]), e;
254
+ }, se = (n) => {
255
+ let e = null, t = null, r = null, c;
251
256
  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"));
257
+ type: p.FIDUCIAL,
258
+ async init({ camera: i, renderer: A }) {
259
+ e = new B({
260
+ sourceType: n?.sourceType ?? "webcam"
261
+ }), await new Promise((a, f) => {
262
+ const l = setTimeout(() => {
263
+ f(new Error("AR source initialization timeout"));
258
264
  }, 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();
265
+ e?.init(() => {
266
+ clearTimeout(l);
267
+ const o = e?.domElement;
268
+ 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"), a();
263
269
  });
264
270
  });
265
- const c = {
266
- cameraParametersUrl: t?.cameraParametersUrl ?? // default to internal camera parameters
271
+ const s = {
272
+ cameraParametersUrl: n?.cameraParametersUrl ?? // default to internal camera parameters
267
273
  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"
274
+ detectionMode: n?.detectionMode ?? "mono",
275
+ patternRatio: n?.patternRatio ?? 0.5,
276
+ matrixCodeType: n?.matrixCodeType ?? "3x3"
271
277
  };
272
- n = new V(c), r = o;
278
+ t = new N(s), r = i;
273
279
  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);
280
+ e?.onResizeElement();
281
+ const a = window.innerWidth, f = window.innerHeight;
282
+ A.setSize(a, f, !1), e?.copyElementSizeTo(A.domElement), t?.arController && e?.copyElementSizeTo(t.arController.canvas);
277
283
  };
278
- await new Promise((a, d) => {
279
- const s = setTimeout(() => {
280
- d(new Error("AR context initialization timeout"));
284
+ await new Promise((a, f) => {
285
+ const l = setTimeout(() => {
286
+ f(new Error("AR context initialization timeout"));
281
287
  }, 1e4);
282
- n.init(() => {
283
- clearTimeout(s);
288
+ t?.init(() => {
289
+ clearTimeout(l);
284
290
  try {
285
- o.projectionMatrix.copy(n.getProjectionMatrix()), u(), a();
286
- } catch (A) {
287
- d(A);
291
+ const o = t?.getProjectionMatrix();
292
+ o && i.projectionMatrix.copy(o), u(), a();
293
+ } catch (o) {
294
+ f(o);
288
295
  }
289
296
  });
290
- }), window.addEventListener("resize", u), i = u;
297
+ }), window.addEventListener("resize", u), c = u;
291
298
  },
292
299
  update() {
293
- if (!(!e || !n) && !(!e.ready || !e.domElement))
300
+ if (!(!e || !t) && !(!e.ready || !e.domElement))
294
301
  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);
302
+ t.update(e.domElement);
303
+ const i = t.getProjectionMatrix?.();
304
+ r && i && r.projectionMatrix.copy(i);
305
+ } catch (i) {
306
+ console.warn("AR.js update error:", i);
298
307
  }
299
308
  },
300
309
  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);
310
+ if (c && (window.removeEventListener("resize", c), c = void 0), t && typeof t.dispose == "function" && t.dispose(), e?.domElement) {
311
+ const i = e.domElement.parentNode;
312
+ i && i.removeChild(e.domElement);
304
313
  }
305
- e = null, n = null, r = null;
314
+ e = null, t = null, r = null;
306
315
  },
307
- getInternal() {
308
- return {
309
- arSource: e,
310
- arContext: n
311
- };
312
- }
316
+ getInternal: () => ({
317
+ arSource: e,
318
+ arContext: t
319
+ })
313
320
  };
314
- }, k = /* @__PURE__ */ new Map();
315
- let M = !1, O = null, C = null;
316
- const Oe = ({
317
- latitude: t,
321
+ }, ce = {
322
+ isPending: !0,
323
+ isSuccess: !1,
324
+ locar: null,
325
+ webcam: null,
326
+ deviceOrientation: null,
327
+ scene: null,
328
+ camera: null,
329
+ lastPosition: null,
330
+ registerAnchor: () => {
331
+ },
332
+ unregisterAnchor: () => {
333
+ },
334
+ getAnchor: () => {
335
+ }
336
+ }, ie = () => {
337
+ const e = I((t) => t.backends).get(p.GEOLOCATION);
338
+ return e ? {
339
+ ...e.getInternal(),
340
+ isPending: !1,
341
+ isSuccess: !0
342
+ } : ce;
343
+ }, ye = ({
344
+ latitude: n,
318
345
  longitude: e,
319
- altitude: n = 0,
346
+ altitude: t = 0,
320
347
  isBillboard: r = !0,
321
- onAttach: i,
322
- onGpsUpdate: o,
323
- children: l
348
+ onAttach: c,
349
+ onGpsUpdate: i,
350
+ children: A
324
351
  }) => {
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);
352
+ const s = ie(), { camera: u } = v(), [a] = P(() => new D()), f = F(() => Math.random().toString(36).slice(2, 11), []), l = M(() => {
353
+ c?.();
354
+ }, [c]), o = M(
355
+ (d, S) => {
356
+ i?.(d, S);
330
357
  },
331
- [o]
358
+ [i]
332
359
  );
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
- };
360
+ return k(() => {
361
+ if (s.isSuccess)
362
+ return s.registerAnchor(f, {
363
+ anchor: a,
364
+ isAttached: !1,
365
+ latitude: n,
366
+ longitude: e,
367
+ altitude: t,
368
+ onAttach: l,
369
+ onGpsUpdate: o
370
+ }), () => {
371
+ s.unregisterAnchor(f);
372
+ };
396
373
  }, [
397
- c,
374
+ s.isSuccess,
375
+ s.registerAnchor,
376
+ s.unregisterAnchor,
398
377
  a,
399
- d,
400
- t,
401
- e,
378
+ f,
402
379
  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 = {},
380
+ e,
381
+ t,
382
+ l,
383
+ o
384
+ ]), R(() => {
385
+ !r || !u || !s.isSuccess || !s.getAnchor(f)?.isAttached || a.lookAt(u.position);
386
+ }), G(/* @__PURE__ */ C("group", { children: A }), a);
387
+ }, ke = ({
388
+ options: n = {},
410
389
  children: e
411
390
  }) => {
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;
391
+ const { scene: t, camera: r, gl: c } = v(), { registerBackend: i, unregisterBackend: A } = I(), s = b(null), u = b(n);
392
+ return u.current = n, k(() => {
393
+ if (s.current) return;
415
394
  let a = !1;
416
395
  return (async () => {
417
396
  try {
418
- const s = pe(u.current);
397
+ const l = ae(u.current);
419
398
  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);
399
+ await i(l, { scene: t, camera: r, renderer: c }), s.current = l;
400
+ } catch (l) {
401
+ console.error("[GeolocationSession] Failed to initialize:", l);
427
402
  }
428
403
  })(), () => {
429
- a = !0, c.current && (l(c.current, S.GEOLOCATION), c.current = null);
404
+ a = !0, s.current && (A(s.current), s.current = null);
430
405
  };
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;
406
+ }, [t, r, c, i, A]), e;
407
+ }, ae = (n) => {
408
+ let e = null, t = null, r = null, c, i = null, A = null, s = null, u = null;
409
+ const a = /* @__PURE__ */ new Map();
410
+ let f = null;
411
+ const l = (o) => {
412
+ if (!(!e || o.isAttached))
413
+ try {
414
+ e.add(o.anchor, o.longitude, o.latitude, o.altitude), o.isAttached = !0, o.onAttach?.();
415
+ } catch (d) {
416
+ console.error("❌ Failed to attach anchor:", d);
417
+ }
418
+ };
436
419
  return {
437
- async init(a) {
438
- const { camera: d, renderer: s, scene: A } = a;
439
- if (!A)
420
+ type: p.GEOLOCATION,
421
+ async init(o) {
422
+ const { camera: d, renderer: S, scene: h } = o;
423
+ if (!h)
440
424
  throw new Error(
441
425
  "[geolocationBackend] A THREE.Scene is required for location-based AR"
442
426
  );
443
- l = d, c = s, u = A, e = new $(A, d), n = new J(
444
- t?.webcamConstraints ?? {
427
+ A = d, s = S, u = h, e = new U(h, d), t = new X(
428
+ n?.webcamConstraints ?? {
445
429
  video: { facingMode: "environment" }
446
430
  // TODO remove `as any` once fixed upstream (LocAR.js)
447
431
  }
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?.();
432
+ ), i = (m) => {
433
+ f = m.position;
434
+ for (const w of a.values())
435
+ w.isAttached || l(w), w.onGpsUpdate?.(m.position, m.distMoved);
436
+ n?.onGpsUpdate?.(m.position, m.distMoved);
437
+ }, e.on("gpsupdate", i), t.on("webcamstarted", (m) => {
438
+ h.background = m.texture;
439
+ }), t.on("webcamerror", (m) => {
440
+ console.error("[geolocationBackend] webcam error:", m);
441
+ }), r = new H(d), r.on("deviceorientationgranted", (m) => {
442
+ m.target?.connect?.();
443
+ }), r.on("deviceorientationerror", (m) => {
444
+ console.error("[geolocationBackend] Device orientation error:", m);
445
+ }), r.init?.(), e.on("gpserror", (m) => {
446
+ console.error("[geolocationBackend] gps error:", m);
447
+ }), e.startGps(), typeof n?.fakeLat == "number" && typeof n?.fakeLon == "number" && e.fakeGps(n.fakeLon, n.fakeLat);
448
+ const g = e.getLastKnownLocation();
449
+ g !== null && (f = {
450
+ coords: {
451
+ longitude: g.longitude,
452
+ latitude: g.latitude,
453
+ accuracy: 0,
454
+ altitude: null,
455
+ altitudeAccuracy: null,
456
+ heading: null,
457
+ speed: null,
458
+ toJSON: () => g
459
+ },
460
+ timestamp: Date.now(),
461
+ toJSON: () => g
462
+ });
463
+ const E = () => {
464
+ if (!s || !A) return;
465
+ const m = window.innerWidth, w = window.innerHeight;
466
+ s.setSize(m, w, !1), A.aspect = m / w, A.updateProjectionMatrix?.();
465
467
  };
466
- m(), window.addEventListener("resize", m), i = m;
468
+ E(), window.addEventListener("resize", E), c = E;
467
469
  },
468
470
  update() {
469
471
  r?.update?.();
470
472
  },
471
473
  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;
474
+ e && i && e.off("gpsupdate", i), e?.stopGps?.(), t?.stop?.(), r?.dispose?.(), c && (window.removeEventListener("resize", c), c = void 0);
475
+ for (const o of a.values())
476
+ if (o.isAttached)
477
+ try {
478
+ o.anchor.removeFromParent();
479
+ } catch (d) {
480
+ console.error("⚠️ Error removing anchor:", d);
481
+ }
482
+ a.clear(), e = null, t = null, r = null, A = null, s = null, u = null, i = null, f = null;
473
483
  },
474
484
  getInternal: () => ({
475
485
  locar: e,
476
- webcam: n,
486
+ webcam: t,
477
487
  deviceOrientation: r,
478
488
  scene: u,
479
- camera: l
489
+ camera: A,
490
+ lastPosition: f,
491
+ registerAnchor: (o, d) => {
492
+ a.set(o, d), f !== null && !d.isAttached && (l(d), d.onGpsUpdate?.(f, 0));
493
+ },
494
+ unregisterAnchor: (o) => {
495
+ const d = a.get(o);
496
+ if (d?.isAttached)
497
+ try {
498
+ d.anchor.removeFromParent();
499
+ } catch (S) {
500
+ console.error(`⚠️ Error removing anchor ${o}:`, S);
501
+ }
502
+ a.delete(o);
503
+ },
504
+ getAnchor: (o) => a.get(o)
480
505
  })
481
506
  };
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);
507
+ }, le = () => ({
508
+ type: p.IMMERSIVE,
509
+ init: () => {
510
+ },
511
+ getInternal: () => null
512
+ }), Ie = ({ children: n }) => {
513
+ const e = F(() => W(), []);
514
+ return k(() => {
515
+ const t = ne(), r = le();
516
+ return t.backends.set(p.IMMERSIVE, r), t.setImmersiveStore(e), () => {
517
+ t.backends.delete(p.IMMERSIVE), t.setImmersiveStore(null);
488
518
  };
489
- }, [e]), /* @__PURE__ */ F(ee, { store: e, children: t });
519
+ }, [e]), /* @__PURE__ */ C(q, { store: e, children: n });
490
520
  };
491
521
  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
522
+ p as BACKEND_TYPES,
523
+ he as FiducialAnchor,
524
+ we as FiducialSession,
525
+ ye as GeolocationAnchor,
526
+ ke as GeolocationSession,
527
+ Ie as ImmersiveSession,
528
+ ge as XR,
529
+ se as createFiducialBackend,
530
+ ae as createGeolocationBackend,
531
+ ne as getXRStore,
532
+ be as subscribeToXRStore,
533
+ oe as useFiducialBackend,
534
+ ie as useGeolocationBackend,
535
+ I as useXRStore
503
536
  };