@omnidotdev/rdk 0.5.1 → 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 (48) 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 +40 -1
  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 +378 -398
  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/BackendInitArgs.interface.d.ts +4 -4
  29. package/build/lib/types/engine/backend/BackendInitArgs.interface.d.ts.map +1 -1
  30. package/build/lib/types/engine/backend/index.d.ts +2 -1
  31. package/build/lib/types/engine/backend/index.d.ts.map +1 -1
  32. package/build/lib/types/engine/index.d.ts +2 -2
  33. package/build/lib/types/engine/index.d.ts.map +1 -1
  34. package/package.json +17 -19
  35. package/build/lib/types/engine/context/ContextValue.interface.d.ts +0 -16
  36. package/build/lib/types/engine/context/ContextValue.interface.d.ts.map +0 -1
  37. package/build/lib/types/engine/context/index.d.ts +0 -2
  38. package/build/lib/types/engine/context/index.d.ts.map +0 -1
  39. package/build/lib/types/index.d.ts +0 -3
  40. package/build/lib/types/index.d.ts.map +0 -1
  41. package/build/lib/util/immersive/fromWebXRSessionMode.d.ts +0 -7
  42. package/build/lib/util/immersive/fromWebXRSessionMode.d.ts.map +0 -1
  43. package/build/lib/util/immersive/index.d.ts +0 -4
  44. package/build/lib/util/immersive/index.d.ts.map +0 -1
  45. package/build/lib/util/immersive/isImmersiveModeSupported.d.ts +0 -7
  46. package/build/lib/util/immersive/isImmersiveModeSupported.d.ts.map +0 -1
  47. package/build/lib/util/immersive/toWebXRSessionMode.d.ts +0 -7
  48. package/build/lib/util/immersive/toWebXRSessionMode.d.ts.map +0 -1
package/build/index.js CHANGED
@@ -1,513 +1,493 @@
1
- import O, { useRef as y, 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 * as z from "locar";
7
- import { createXRStore as $, XR as J } from "@react-three/xr";
8
- const N = (e) => {
9
- let t;
10
- const n = /* @__PURE__ */ new Set(), r = (c, A) => {
11
- const s = typeof c == "function" ? c(t) : c;
12
- if (!Object.is(s, t)) {
13
- const l = t;
14
- t = A ?? (typeof s != "object" || s === null) ? s : Object.assign({}, t, s), n.forEach((f) => f(t, l));
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) => {
13
+ let e;
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
- }, u = () => t, i = { setState: r, getState: u, getInitialState: () => d, subscribe: (c) => (n.add(c), () => n.delete(c)) }, d = t = e(r, u, i);
17
- return i;
18
- }, Z = ((e) => e ? N(e) : N), ee = (e) => e;
19
- function te(e, t = ee) {
20
- const n = O.useSyncExternalStore(
21
- e.subscribe,
22
- O.useCallback(() => t(e.getState()), [e, t]),
23
- O.useCallback(() => t(e.getInitialState()), [e, t])
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 O.useDebugValue(n), n;
29
+ return y.useDebugValue(t), t;
26
30
  }
27
- const ne = (e) => {
28
- const t = Z(e), n = (r) => te(t, r);
29
- return Object.assign(n, t), n;
30
- }, re = ((e) => ne), oe = (e) => (t, n, r) => {
31
- const u = r.subscribe;
32
- return r.subscribe = ((a, i, d) => {
33
- let c = a;
34
- if (i) {
35
- const A = d?.equalityFn || Object.is;
36
- let s = a(r.getState());
37
- c = (l) => {
38
- const f = a(l);
39
- if (!A(s, f)) {
40
- const b = s;
41
- i(s = f, b);
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
- }, d?.fireImmediately && i(s, s);
47
+ }, u?.fireImmediately && a(l, l);
44
48
  }
45
- return u(c);
46
- }), e(t, n, r);
47
- }, ie = oe, U = (e) => Symbol.iterator in e, X = (e) => (
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 e
50
- ), H = (e, t) => {
51
- const n = e instanceof Map ? e : new Map(e.entries()), r = t instanceof Map ? t : new Map(t.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 [u, o] of n)
55
- if (!r.has(u) || !Object.is(o, r.get(u)))
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
- }, se = (e, t) => {
59
- const n = e[Symbol.iterator](), r = t[Symbol.iterator]();
60
- let u = n.next(), o = r.next();
61
- for (; !u.done && !o.done; ) {
62
- if (!Object.is(u.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
- u = n.next(), o = r.next();
68
+ c = t.next(), s = r.next();
65
69
  }
66
- return !!u.done && !!o.done;
70
+ return !!c.done && !!s.done;
67
71
  };
68
- function ce(e, t) {
69
- return Object.is(e, t) ? !0 : typeof e != "object" || e === null || typeof t != "object" || t === null || Object.getPrototypeOf(e) !== Object.getPrototypeOf(t) ? !1 : U(e) && U(t) ? X(e) && X(t) ? H(e, t) : se(e, t) : H(
70
- { entries: () => Object.entries(e) },
71
- { 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) },
75
+ { entries: () => Object.entries(e) }
72
76
  );
73
77
  }
74
- function ae(e) {
75
- const t = O.useRef(void 0);
76
- return (n) => {
77
- const r = e(n);
78
- return ce(t.current, r) ? t.current : t.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 h = {
82
- FIDUCIAL: "FiducialSession",
83
- GEOLOCATION: "GeolocationSession",
84
- IMMERSIVE: "ImmersiveSession"
85
- }, G = re()(
86
- ie((e, t) => ({
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, u) => {
92
+ registerBackend: async (t, r) => {
94
93
  try {
95
- if (u) {
96
- const o = t(), a = /* @__PURE__ */ new Set([...o.sessionTypes, u]), i = a.has(h.FIDUCIAL), d = a.has(h.GEOLOCATION);
97
- if (i && d) {
98
- const c = `❌ [RDK] INCOMPATIBLE SESSIONS: ${h.FIDUCIAL} and ${h.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(c), new Error(c);
100
- }
101
- e(() => ({
102
- sessionTypes: a
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
- }), e((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
- e((u) => {
118
- const o = new Set(u.sessionTypes);
119
- r && o.delete(r);
120
- const a = u.backends.filter((i) => i !== 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 (i) {
124
- console.error("[XRStore] Error disposing backend:", i);
116
+ t.dispose?.();
117
+ } catch (s) {
118
+ console.error("[XRStore] Error disposing backend:", s);
125
119
  }
126
- return {
127
- backends: a,
128
- sessionTypes: o
129
- };
120
+ return { backends: c };
130
121
  });
131
122
  },
132
- setVideo: (n) => {
133
- e({ video: n });
123
+ setVideo: (t) => {
124
+ n({ video: t });
134
125
  },
135
- updateBackends: (n) => {
136
- const { backends: r } = t();
137
- r.forEach((u) => {
126
+ updateBackends: (t) => {
127
+ const { backends: r } = e();
128
+ for (const c of r.values())
138
129
  try {
139
- u.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
- e({ immersiveStore: n });
135
+ setImmersiveStore: (t) => {
136
+ n({ immersiveStore: t });
147
137
  }
148
138
  }))
149
- ), le = () => G.getState(), we = G.subscribe, T = (e) => G(
150
- ae((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(h.IMMERSIVE),
154
- immersive: n.immersiveStore || null
142
+ ...t,
143
+ isImmersive: t.backends.has(p.IMMERSIVE),
144
+ immersive: t.immersiveStore || null
155
145
  };
156
- return e ? e(r) : r;
146
+ return n ? n(r) : r;
157
147
  })
158
- ), ye = ({ children: e }) => {
159
- const { updateBackends: t } = T();
160
- return L((n, r) => {
161
- t(r);
162
- }), e;
163
- }, Ie = ({
164
- patternUrl: e,
165
- barcodeValue: t,
166
- params: n,
148
+ ), be = ({ children: n }) => {
149
+ const { updateBackends: e } = I();
150
+ return R((t, r) => {
151
+ e(r);
152
+ }), n;
153
+ }, re = () => I((t) => t.backends).get(p.FIDUCIAL)?.getInternal() ?? null, Se = ({
154
+ patternUrl: n,
155
+ barcodeValue: e,
156
+ params: t,
167
157
  onMarkerFound: r,
168
- onMarkerLost: u,
169
- children: o
158
+ onMarkerLost: c,
159
+ children: s
170
160
  }) => {
171
- const a = y(null), i = T((s) => s.backends), d = y(!1), c = y(!1), A = y(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 f = i.find((w) => w.getInternal?.()?.arContext);
177
- if (!f || s) return;
178
- const I = f.getInternal?.()?.arContext, g = a.current;
179
- if (!I || !g) return;
180
- if (g.visible = !1, c.current = !1, !I.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 (!a.current || s) return;
183
- const S = f.getInternal?.()?.arContext;
184
- if (!S?.arController) return;
185
- const p = new D(S, a.current, {
186
- type: e ? "pattern" : t ? "barcode" : "unknown",
187
- patternUrl: e,
188
- barcodeValue: t,
189
- ...n
190
- });
191
- A.current = p, c.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 k = new D(I, g, {
196
- type: e ? "pattern" : t ? "barcode" : "unknown",
197
- patternUrl: e,
198
- barcodeValue: t,
199
- ...n
187
+ const h = new x(d, b, {
188
+ type: n ? "pattern" : e ? "barcode" : "unknown",
189
+ patternUrl: n,
190
+ barcodeValue: e,
191
+ ...t
200
192
  });
201
- A.current = k, c.current = !0;
202
- } catch (f) {
203
- console.error("Failed to initialize fiducial backend:", f);
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 f = A.current;
208
- typeof f?.dispose == "function" && f.dispose(), c.current = !1;
198
+ l = !0;
199
+ const d = f.current;
200
+ typeof d?.dispose == "function" && d.dispose(), i.current = !1;
209
201
  };
210
- }, [i, e, t, n]), L(() => {
211
- const s = a.current;
212
- if (!s || !c.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 l = s.visible;
217
- l && !d.current ? (d.current = !0, r?.()) : !l && d.current && (d.current = !1, u?.());
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: a,
213
+ ref: A,
222
214
  visible: !1,
223
- children: o
215
+ children: s
224
216
  }
225
217
  );
226
- }, ue = ({ options: e = {}, children: t }) => {
227
- const { scene: n, camera: r, gl: u } = j(), { registerBackend: o, unregisterBackend: a } = T(), i = y(null), d = y(e);
228
- return d.current = e, x(() => {
229
- if (i.current) return;
230
- let c = !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 = de(d.current);
234
- if (c) return;
235
- await o(
236
- s,
237
- { scene: n, camera: r, renderer: u },
238
- h.FIDUCIAL
239
- ), i.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
- c = !0, i.current && (a(i.current, h.FIDUCIAL), i.current = null);
232
+ i = !0, a.current && (A(a.current), a.current = null);
245
233
  };
246
- }, [n, r, u, o, a]), t;
247
- };
248
- ue.sessionType = "FiducialSession";
249
- const de = (e) => {
250
- let t, n, r;
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: a }) {
253
- t = new Q({
254
- sourceType: e.sourceType ?? "webcam"
255
- }), await new Promise((c, A) => {
256
- const s = setTimeout(() => {
257
- A(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
- t.init(() => {
260
- clearTimeout(s);
261
- const l = t.domElement;
262
- l && (l.style.position = "fixed", l.style.top = "0", l.style.left = "0", l.style.width = "100vw", l.style.height = "100vh", l.style.objectFit = "cover", l.style.zIndex = "-1", l.style.pointerEvents = "none"), c();
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 i = {
266
- cameraParametersUrl: e.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: e.detectionMode ?? "mono",
269
- patternRatio: e.patternRatio ?? 0.5,
270
- matrixCodeType: e.matrixCodeType ?? "3x3"
255
+ detectionMode: n?.detectionMode ?? "mono",
256
+ patternRatio: n?.patternRatio ?? 0.5,
257
+ matrixCodeType: n?.matrixCodeType ?? "3x3"
271
258
  };
272
- n = new V(i);
273
- const d = () => {
274
- t.onResizeElement();
275
- const c = window.innerWidth, A = window.innerHeight;
276
- a.setSize(c, A, !1), t.copyElementSizeTo(a.domElement), n?.arController && t.copyElementSizeTo(n.arController.canvas);
259
+ t = new D(a), r = s;
260
+ const u = () => {
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((c, A) => {
279
- const s = setTimeout(() => {
280
- A(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()), d(), c();
286
- } catch (l) {
287
- A(l);
272
+ const o = t?.getProjectionMatrix();
273
+ o && s.projectionMatrix.copy(o), u(), i();
274
+ } catch (o) {
275
+ f(o);
288
276
  }
289
277
  });
290
- }), this._arSource = t, this._arContext = n, this._camera = o, window.addEventListener("resize", d), r = d;
278
+ }), window.addEventListener("resize", u), c = u;
291
279
  },
292
280
  update() {
293
- const o = this._arSource, a = this._arContext, i = this._camera;
294
- if (!(!o || !a) && o.ready !== !1 && o.domElement)
281
+ if (!(!e || !t) && !(!e.ready || !e.domElement))
295
282
  try {
296
- a.update(o.domElement), i && a.getProjectionMatrix && i.projectionMatrix.copy(a.getProjectionMatrix());
297
- } catch (d) {
298
- console.warn("AR.js update error:", d);
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);
299
288
  }
300
289
  },
301
290
  dispose() {
302
- r && (window.removeEventListener("resize", r), r = void 0);
303
- const o = this._arSource, a = this._arContext;
304
- if (a && typeof a.dispose == "function" && a.dispose(), o?.domElement) {
305
- const i = o.domElement.parentNode;
306
- i && i.removeChild(o.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);
307
294
  }
308
- this._arSource = void 0, this._arContext = void 0;
295
+ e = null, t = null, r = null;
309
296
  },
310
- getInternal() {
311
- return {
312
- arSource: this._arSource,
313
- arContext: this._arContext
314
- };
315
- }
297
+ getInternal: () => ({
298
+ arSource: e,
299
+ arContext: t
300
+ })
316
301
  };
317
- }, E = /* @__PURE__ */ new Map();
318
- let M = !1, R = null, C = null;
319
- const ke = ({
320
- latitude: e,
321
- longitude: t,
322
- altitude: n = 0,
302
+ }, ce = () => I((t) => t.backends).get(p.GEOLOCATION)?.getInternal() ?? null, he = ({
303
+ latitude: n,
304
+ longitude: e,
305
+ altitude: t = 0,
323
306
  isBillboard: r = !0,
324
- onAttach: u,
325
- onGpsUpdate: o,
326
- children: a
307
+ onAttach: c,
308
+ onGpsUpdate: s,
309
+ children: A
327
310
  }) => {
328
- const i = T((b) => b.backends), { camera: d } = j(), [c] = B(() => new Y()), [A] = B(() => Math.random().toString(36).slice(2, 11)), s = y(!1), l = P(() => {
329
- u?.();
330
- }, [u]), f = P(
331
- (b, I) => {
332
- o?.(b, I);
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);
333
316
  },
334
- [o]
317
+ [s]
335
318
  );
336
- return x(() => {
337
- let b = !1;
338
- return (async () => {
339
- try {
340
- const g = i.find((m) => m.getInternal?.()?.locar);
341
- if (!g || b) return;
342
- const w = g.getInternal?.()?.locar;
343
- if (!w) return;
344
- const S = (m) => {
345
- try {
346
- w.add(
347
- m.anchor,
348
- m.longitude,
349
- m.latitude,
350
- m.altitude
351
- ), m.isAttached = !0, m.onAttach?.();
352
- } catch (v) {
353
- console.error("❌ Failed to attach anchor:", v);
354
- }
355
- }, p = {
356
- anchor: c,
357
- isAttached: !1,
358
- latitude: e,
359
- longitude: t,
360
- altitude: n || 0,
361
- onAttach: l,
362
- onGpsUpdate: f
363
- };
364
- if (E.set(A, p), !M) {
365
- C = ({
366
- position: v,
367
- distMoved: W
368
- }) => {
369
- R = v, E.forEach((_) => {
370
- _.isAttached || S(_), _.onGpsUpdate?.(v, W);
371
- });
372
- };
373
- const m = w.getLastKnownLocation();
374
- m !== null && (R = {
375
- coords: m,
376
- timestamp: Date.now(),
377
- toJSON: () => m
378
- }), R !== null && !p.isAttached && S(p), w.on?.("gpsupdate", C), M = !0;
379
- }
380
- R !== null && (p.isAttached || S(p), p.onGpsUpdate?.(R, 0)), s.current = !1;
381
- } catch (g) {
382
- console.error("Failed to initialize geolocation backend:", g);
383
- }
384
- })(), () => {
385
- if (b = !0, E.get(A)?.isAttached)
386
- try {
387
- const S = i.find((p) => p.getInternal?.()?.locar)?.getInternal?.()?.locar;
388
- typeof S?.remove == "function" ? S.remove(c) : c.removeFromParent();
389
- } catch (k) {
390
- console.error(`⚠️ Error removing anchor ${A}:`, k);
391
- }
392
- E.delete(A), E.size === 0 && C && (i.find((p) => p.getInternal?.()?.locar)?.getInternal?.()?.locar?.off?.("gpsupdate", C), C = null, M = !1);
393
- };
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
+ };
394
332
  }, [
333
+ a,
395
334
  i,
396
- c,
397
- A,
335
+ f,
336
+ n,
398
337
  e,
399
338
  t,
400
- n,
401
339
  l,
402
- f
403
- ]), L(() => {
404
- !r || !d || !E.get(A)?.isAttached || c.lookAt(d.position);
405
- }), K(/* @__PURE__ */ F("group", { children: a }), c);
406
- }, Ae = ({
407
- options: e = {},
408
- children: t
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 = {},
346
+ children: e
409
347
  }) => {
410
- const { scene: n, camera: r, gl: u } = j(), { registerBackend: o, unregisterBackend: a } = T(), i = y(null), d = y(e);
411
- return d.current = e, x(() => {
412
- if (i.current) return;
413
- let c = !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;
414
352
  return (async () => {
415
353
  try {
416
- const s = fe(d.current);
417
- if (c) return;
418
- await o(
419
- s,
420
- { scene: n, camera: r, renderer: u },
421
- h.GEOLOCATION
422
- ), i.current = s;
423
- } catch (s) {
424
- 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);
425
359
  }
426
360
  })(), () => {
427
- c = !0, i.current && (a(i.current, h.GEOLOCATION), i.current = null);
361
+ i = !0, a.current && (A(a.current), a.current = null);
428
362
  };
429
- }, [n, r, u, o, a]), t;
430
- };
431
- Ae.sessionType = "GeolocationSession";
432
- const fe = (e) => {
433
- let t, n, r, u, o = null, a = 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
+ };
434
376
  return {
435
- async init(i) {
436
- const { camera: d, renderer: c, scene: A } = i;
437
- if (!A)
377
+ type: p.GEOLOCATION,
378
+ async init(o) {
379
+ const { camera: d, renderer: b, scene: h } = o;
380
+ if (!h)
438
381
  throw new Error(
439
382
  "[geolocationBackend] A THREE.Scene is required for location-based AR"
440
383
  );
441
- o = d, a = c, t = new z.LocationBased(A, d), n = new z.Webcam(
442
- e.webcamConstraints ?? {
384
+ A = d, a = b, u = h, e = new X(h, d), t = new U(
385
+ n?.webcamConstraints ?? {
443
386
  video: { facingMode: "environment" }
444
- },
445
- null
446
- ), t.on(
447
- "gpsupdate",
448
- // TODO remove explicit type annotation once LocAR.js converted to TS (https://github.com/AR-js-org/locar.js/pull/27#issuecomment-3487422995)
449
- (l) => {
450
- e.onGpsUpdate?.(l.position, l.distMoved);
387
+ // TODO remove `as any` once fixed upstream (LocAR.js)
451
388
  }
452
- ), n.on("webcamstarted", (l) => {
453
- A.background = l.texture;
454
- }), n.on("webcamerror", (l) => {
455
- console.error("[geolocationBackend] webcam error:", l);
456
- }), r = new z.DeviceOrientationControls(d), r.on("deviceorientationgranted", (l) => {
457
- l.target?.connect?.();
458
- }), r.on("deviceorientationerror", (l) => {
459
- console.error("[geolocationBackend] Device orientation error:", l);
460
- }), r.init?.(), t.on("gpserror", (l) => {
461
- console.error("[geolocationBackend] gps error:", l);
462
- }), t.startGps(), typeof e.fakeLat == "number" && typeof e.fakeLon == "number" && t.fakeGps(e.fakeLon, e.fakeLat);
463
- const s = () => {
464
- if (!a || !o) return;
465
- const l = window.innerWidth, f = window.innerHeight;
466
- a.setSize(l, f, !1), o.aspect = l / f, o.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?.();
467
424
  };
468
- s(), window.addEventListener("resize", s), u = s, this._locar = t, this._webcam = n, this._deviceOrientation = r, this._scene = A, this._camera = d;
425
+ E(), window.addEventListener("resize", E), c = E;
469
426
  },
470
427
  update() {
471
- this._deviceOrientation?.update?.();
428
+ r?.update?.();
472
429
  },
473
430
  dispose() {
474
- const i = this._locar, d = this._webcam, c = this._deviceOrientation;
475
- e?.onGpsUpdate && i?.off("gpsupdate", e.onGpsUpdate), i?.stopGps?.(), d?.stop?.(), c?.dispose?.(), u && (window.removeEventListener("resize", u), u = void 0), this._locar = null, this._webcam = null, this._deviceOrientation = null, this._scene = null, this._camera = 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;
476
440
  },
477
- getInternal() {
478
- return {
479
- // biome-ignore lint/suspicious/noExplicitAny: TODO solve once LocAR.js converted to TS (https://github.com/AR-js-org/locar.js/pull/27#issuecomment-3487422995)
480
- locar: this._locar,
481
- // biome-ignore lint/suspicious/noExplicitAny: TODO solve once LocAR.js converted to TS (https://github.com/AR-js-org/locar.js/pull/27#issuecomment-3487422995)
482
- webcam: this._webcam,
483
- // biome-ignore lint/suspicious/noExplicitAny: TODO solve once LocAR.js converted to TS (https://github.com/AR-js-org/locar.js/pull/27#issuecomment-3487422995)
484
- deviceOrientation: this._deviceOrientation,
485
- // biome-ignore lint/suspicious/noExplicitAny: TODO solve once LocAR.js converted to TS (https://github.com/AR-js-org/locar.js/pull/27#issuecomment-3487422995)
486
- scene: this._scene,
487
- // biome-ignore lint/suspicious/noExplicitAny: TODO solve once LocAR.js converted to TS (https://github.com/AR-js-org/locar.js/pull/27#issuecomment-3487422995)
488
- camera: this._camera
489
- };
490
- }
441
+ getInternal: () => ({
442
+ locar: e,
443
+ webcam: t,
444
+ deviceOrientation: r,
445
+ scene: u,
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)
462
+ })
491
463
  };
492
- }, Ee = ({ children: e }) => {
493
- const t = q(() => $(), []);
494
- return x(() => {
495
- const n = le();
496
- return n.sessionTypes.add(h.IMMERSIVE), n.setImmersiveStore(t), () => {
497
- n.sessionTypes.delete(h.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);
498
475
  };
499
- }, [t]), /* @__PURE__ */ F(J, { store: t, children: e });
476
+ }, [e]), /* @__PURE__ */ C(q, { store: e, children: n });
500
477
  };
501
478
  export {
502
- Ie as FiducialAnchor,
503
- ue as FiducialSession,
504
- ke as GeolocationAnchor,
505
- Ae as GeolocationSession,
506
- Ee as ImmersiveSession,
507
- ye as XR,
508
- de as createFiducialBackend,
509
- fe as createGeolocationBackend,
510
- le as getXRStore,
511
- we as subscribeToXRStore,
512
- 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
513
493
  };